@@ -75,11 +75,19 @@ |
||
| 75 | 75 | // vraiment n'importe quoi la gestion des chemins des plugins |
| 76 | 76 | // une fonction pour aider... |
| 77 | 77 | // https://code.spip.net/@chemin_plug |
| 78 | +/** |
|
| 79 | + * @param string $racine |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 78 | 83 | function chemin_plug($racine, $plug) { |
| 79 | 84 | return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | 87 | // https://code.spip.net/@tree_open_close_dir |
| 88 | +/** |
|
| 89 | + * @param string $target |
|
| 90 | + */ |
|
| 83 | 91 | function tree_open_close_dir(&$current, $target, $deplie = array()) { |
| 84 | 92 | if ($current == $target) { |
| 85 | 93 | return ""; |
@@ -11,64 +11,64 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // https://code.spip.net/@affiche_arbre_plugins |
| 18 | 18 | function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) { |
| 19 | - $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 20 | - $racine = basename(_DIR_PLUGINS); |
|
| 21 | - $init_dir = $current_dir = ""; |
|
| 22 | - // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 23 | - // des qu'un path est deja note deplie on s'arrete |
|
| 24 | - $deplie = array($racine => true); |
|
| 25 | - $fast_liste_plugins_actifs = array(); |
|
| 26 | - foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 27 | - $chemin_plug = chemin_plug($racine, $plug); |
|
| 28 | - $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 29 | - $dir = dirname($chemin_plug); |
|
| 30 | - $maxiter = 100; |
|
| 31 | - while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) { |
|
| 32 | - $deplie[$dir] = true; |
|
| 33 | - $dir = dirname($dir); |
|
| 34 | - } |
|
| 35 | - } |
|
| 19 | + $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 20 | + $racine = basename(_DIR_PLUGINS); |
|
| 21 | + $init_dir = $current_dir = ""; |
|
| 22 | + // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 23 | + // des qu'un path est deja note deplie on s'arrete |
|
| 24 | + $deplie = array($racine => true); |
|
| 25 | + $fast_liste_plugins_actifs = array(); |
|
| 26 | + foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 27 | + $chemin_plug = chemin_plug($racine, $plug); |
|
| 28 | + $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 29 | + $dir = dirname($chemin_plug); |
|
| 30 | + $maxiter = 100; |
|
| 31 | + while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) { |
|
| 32 | + $deplie[$dir] = true; |
|
| 33 | + $dir = dirname($dir); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // index repertoires --> plugin |
|
| 38 | - $dir_index = array(); |
|
| 39 | - foreach ($liste_plugins as $key => $plug) { |
|
| 40 | - $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 41 | - $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 42 | - } |
|
| 37 | + // index repertoires --> plugin |
|
| 38 | + $dir_index = array(); |
|
| 39 | + foreach ($liste_plugins as $key => $plug) { |
|
| 40 | + $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 41 | + $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $visible = @isset($deplie[$current_dir]); |
|
| 45 | - $maxiter = 1000; |
|
| 44 | + $visible = @isset($deplie[$current_dir]); |
|
| 45 | + $maxiter = 1000; |
|
| 46 | 46 | |
| 47 | - $res = ''; |
|
| 48 | - while (count($liste_plugins) && $maxiter--) { |
|
| 49 | - // le rep suivant |
|
| 50 | - $dir = dirname(reset($liste_plugins)); |
|
| 51 | - if ($dir != $current_dir) { |
|
| 52 | - $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 53 | - } |
|
| 47 | + $res = ''; |
|
| 48 | + while (count($liste_plugins) && $maxiter--) { |
|
| 49 | + // le rep suivant |
|
| 50 | + $dir = dirname(reset($liste_plugins)); |
|
| 51 | + if ($dir != $current_dir) { |
|
| 52 | + $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // d'abord tous les plugins du rep courant |
|
| 56 | - if (isset($dir_index[$current_dir])) { |
|
| 57 | - foreach ($dir_index[$current_dir] as $key) { |
|
| 58 | - $plug = $liste_plugins[$key]; |
|
| 59 | - $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 60 | - $id = substr(md5($plug), 0, 16); |
|
| 61 | - $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | - 'menu-entree') . "\n"; |
|
| 63 | - unset($liste_plugins[$key]); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 55 | + // d'abord tous les plugins du rep courant |
|
| 56 | + if (isset($dir_index[$current_dir])) { |
|
| 57 | + foreach ($dir_index[$current_dir] as $key) { |
|
| 58 | + $plug = $liste_plugins[$key]; |
|
| 59 | + $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 60 | + $id = substr(md5($plug), 0, 16); |
|
| 61 | + $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | + 'menu-entree') . "\n"; |
|
| 63 | + unset($liste_plugins[$key]); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 68 | 68 | |
| 69 | - return "<ul class='menu-liste plugins'>" |
|
| 70 | - . $res |
|
| 71 | - . "</ul>"; |
|
| 69 | + return "<ul class='menu-liste plugins'>" |
|
| 70 | + . $res |
|
| 71 | + . "</ul>"; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -76,44 +76,44 @@ discard block |
||
| 76 | 76 | // une fonction pour aider... |
| 77 | 77 | // https://code.spip.net/@chemin_plug |
| 78 | 78 | function chemin_plug($racine, $plug) { |
| 79 | - return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 79 | + return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // https://code.spip.net/@tree_open_close_dir |
| 83 | 83 | function tree_open_close_dir(&$current, $target, $deplie = array()) { |
| 84 | - if ($current == $target) { |
|
| 85 | - return ""; |
|
| 86 | - } |
|
| 87 | - $tcur = explode("/", $current); |
|
| 88 | - $ttarg = explode("/", $target); |
|
| 89 | - $tcom = array(); |
|
| 90 | - $output = ""; |
|
| 91 | - // la partie commune |
|
| 92 | - while (reset($tcur) == reset($ttarg)) { |
|
| 93 | - $tcom[] = array_shift($tcur); |
|
| 94 | - array_shift($ttarg); |
|
| 95 | - } |
|
| 96 | - // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | - while ($close = array_pop($tcur)) { |
|
| 98 | - $output .= "</ul>\n"; |
|
| 99 | - $output .= fin_block(); |
|
| 100 | - $output .= "</li>\n"; |
|
| 101 | - } |
|
| 102 | - $chemin = ""; |
|
| 103 | - if (count($tcom)) { |
|
| 104 | - $chemin .= implode("/", $tcom) . "/"; |
|
| 105 | - } |
|
| 106 | - // ouvrir les repertoires jusqu'a la cible |
|
| 107 | - while ($open = array_shift($ttarg)) { |
|
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . "/"; |
|
| 110 | - $output .= "<li>"; |
|
| 111 | - $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | - $output .= debut_block_depliable($visible); |
|
| 84 | + if ($current == $target) { |
|
| 85 | + return ""; |
|
| 86 | + } |
|
| 87 | + $tcur = explode("/", $current); |
|
| 88 | + $ttarg = explode("/", $target); |
|
| 89 | + $tcom = array(); |
|
| 90 | + $output = ""; |
|
| 91 | + // la partie commune |
|
| 92 | + while (reset($tcur) == reset($ttarg)) { |
|
| 93 | + $tcom[] = array_shift($tcur); |
|
| 94 | + array_shift($ttarg); |
|
| 95 | + } |
|
| 96 | + // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | + while ($close = array_pop($tcur)) { |
|
| 98 | + $output .= "</ul>\n"; |
|
| 99 | + $output .= fin_block(); |
|
| 100 | + $output .= "</li>\n"; |
|
| 101 | + } |
|
| 102 | + $chemin = ""; |
|
| 103 | + if (count($tcom)) { |
|
| 104 | + $chemin .= implode("/", $tcom) . "/"; |
|
| 105 | + } |
|
| 106 | + // ouvrir les repertoires jusqu'a la cible |
|
| 107 | + while ($open = array_shift($ttarg)) { |
|
| 108 | + $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | + $chemin .= $open . "/"; |
|
| 110 | + $output .= "<li>"; |
|
| 111 | + $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | + $output .= debut_block_depliable($visible); |
|
| 113 | 113 | |
| 114 | - $output .= "<ul>\n"; |
|
| 115 | - } |
|
| 116 | - $current = $target; |
|
| 114 | + $output .= "<ul>\n"; |
|
| 115 | + } |
|
| 116 | + $current = $target; |
|
| 117 | 117 | |
| 118 | - return $output; |
|
| 118 | + return $output; |
|
| 119 | 119 | } |
@@ -59,6 +59,10 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | // https://code.spip.net/@argumenter_inclure |
| 62 | +/** |
|
| 63 | + * @param boolean $rejet_filtres |
|
| 64 | + * @param string $id_boucle |
|
| 65 | + */ |
|
| 62 | 66 | function argumenter_inclure( |
| 63 | 67 | $params, |
| 64 | 68 | $rejet_filtres, |
@@ -751,7 +755,7 @@ discard block |
||
| 751 | 755 | * Nom de la commande |
| 752 | 756 | * @param string $val |
| 753 | 757 | * Code PHP décrivant la valeur à affecter |
| 754 | - * @return array |
|
| 758 | + * @return string[] |
|
| 755 | 759 | * |
| 756 | 760 | * - index 0 : Code pour une affectation statique. Si non rempli, la propriété devra |
| 757 | 761 | * être ré-affectée à chaque appel de la boucle. |
@@ -859,6 +863,9 @@ discard block |
||
| 859 | 863 | } |
| 860 | 864 | |
| 861 | 865 | // https://code.spip.net/@calculer_order |
| 866 | +/** |
|
| 867 | + * @param Boucle $boucle |
|
| 868 | + */ |
|
| 862 | 869 | function calculer_order(&$boucle) { |
| 863 | 870 | if (!$order = $boucle->order |
| 864 | 871 | and !$order = $boucle->default_order |
@@ -944,6 +951,9 @@ discard block |
||
| 944 | 951 | define('_REGEXP_CONCAT_NON_VIDE', "/^(.*)[.]\s*'[^']+'\s*$/"); |
| 945 | 952 | |
| 946 | 953 | // https://code.spip.net/@compile_cas |
| 954 | +/** |
|
| 955 | + * @param string $id_boucle |
|
| 956 | + */ |
|
| 947 | 957 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 948 | 958 | |
| 949 | 959 | $codes = array(); |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
@@ -60,91 +60,91 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | // https://code.spip.net/@argumenter_inclure |
| 62 | 62 | function argumenter_inclure( |
| 63 | - $params, |
|
| 64 | - $rejet_filtres, |
|
| 65 | - $p, |
|
| 66 | - &$boucles, |
|
| 67 | - $id_boucle, |
|
| 68 | - $echap = true, |
|
| 69 | - $lang = '', |
|
| 70 | - $fond1 = false |
|
| 63 | + $params, |
|
| 64 | + $rejet_filtres, |
|
| 65 | + $p, |
|
| 66 | + &$boucles, |
|
| 67 | + $id_boucle, |
|
| 68 | + $echap = true, |
|
| 69 | + $lang = '', |
|
| 70 | + $fond1 = false |
|
| 71 | 71 | ) { |
| 72 | - $l = array(); |
|
| 73 | - $erreur_p_i_i = ''; |
|
| 74 | - if (!is_array($params)) { |
|
| 75 | - return $l; |
|
| 76 | - } |
|
| 77 | - foreach ($params as $k => $couple) { |
|
| 78 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 79 | - $filtre = array_shift($couple); |
|
| 80 | - if ($filtre) { |
|
| 81 | - break; |
|
| 82 | - } |
|
| 83 | - foreach ($couple as $n => $val) { |
|
| 84 | - $var = $val[0]; |
|
| 85 | - if ($var->type != 'texte') { |
|
| 86 | - if ($n or $k or $fond1) { |
|
| 87 | - $erreur_p_i_i = array( |
|
| 88 | - 'zbug_parametres_inclus_incorrects', |
|
| 89 | - array('param' => $var->nom_champ) |
|
| 90 | - ); |
|
| 91 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 92 | - break; |
|
| 93 | - } else { |
|
| 94 | - $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 95 | - } |
|
| 96 | - } else { |
|
| 97 | - preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
|
| 98 | - $m = array_pad($m, 3, null); |
|
| 99 | - $var = $m[1]; |
|
| 100 | - $auto = false;; |
|
| 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; |
|
| 72 | + $l = array(); |
|
| 73 | + $erreur_p_i_i = ''; |
|
| 74 | + if (!is_array($params)) { |
|
| 75 | + return $l; |
|
| 76 | + } |
|
| 77 | + foreach ($params as $k => $couple) { |
|
| 78 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 79 | + $filtre = array_shift($couple); |
|
| 80 | + if ($filtre) { |
|
| 81 | + break; |
|
| 82 | + } |
|
| 83 | + foreach ($couple as $n => $val) { |
|
| 84 | + $var = $val[0]; |
|
| 85 | + if ($var->type != 'texte') { |
|
| 86 | + if ($n or $k or $fond1) { |
|
| 87 | + $erreur_p_i_i = array( |
|
| 88 | + 'zbug_parametres_inclus_incorrects', |
|
| 89 | + array('param' => $var->nom_champ) |
|
| 90 | + ); |
|
| 91 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 92 | + break; |
|
| 93 | + } else { |
|
| 94 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 95 | + } |
|
| 96 | + } else { |
|
| 97 | + preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
|
| 98 | + $m = array_pad($m, 3, null); |
|
| 99 | + $var = $m[1]; |
|
| 100 | + $auto = false;; |
|
| 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,71 +168,71 @@ 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 | - |
|
| 176 | - } else { |
|
| 177 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 178 | - if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 179 | - $fichier = $r[1]; |
|
| 180 | - } else { |
|
| 181 | - $fichier = ''; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - if (!$code or $code === '""') { |
|
| 185 | - $erreur_p_i_i = array( |
|
| 186 | - 'zbug_parametres_inclus_incorrects', |
|
| 187 | - array('param' => $code) |
|
| 188 | - ); |
|
| 189 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 190 | - |
|
| 191 | - return false; |
|
| 192 | - } |
|
| 193 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 194 | - |
|
| 195 | - if (is_array($_contexte)) { |
|
| 196 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 197 | - if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 198 | - unset($_contexte['env']); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // noter les doublons dans l'appel a public.php |
|
| 202 | - if (isset($_contexte['doublons'])) { |
|
| 203 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($ajax = isset($_contexte['ajax'])) { |
|
| 207 | - $ajax = preg_replace(",=>(.*)$,ims", '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 208 | - unset($_contexte['ajax']); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - $_contexte = join(",\n\t", $_contexte); |
|
| 212 | - } else { |
|
| 213 | - return false; |
|
| 214 | - } // j'aurais voulu toucher le fond ... |
|
| 215 | - |
|
| 216 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 217 | - |
|
| 218 | - if ($env) { |
|
| 219 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 223 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 224 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 225 | - } else { |
|
| 226 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 227 | - if ($ajax) { |
|
| 228 | - $_options[] = $ajax; |
|
| 229 | - } |
|
| 230 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 231 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | - "_request(\"connect\")") . ';'; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - 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 | + |
|
| 176 | + } else { |
|
| 177 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 178 | + if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 179 | + $fichier = $r[1]; |
|
| 180 | + } else { |
|
| 181 | + $fichier = ''; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + if (!$code or $code === '""') { |
|
| 185 | + $erreur_p_i_i = array( |
|
| 186 | + 'zbug_parametres_inclus_incorrects', |
|
| 187 | + array('param' => $code) |
|
| 188 | + ); |
|
| 189 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 193 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 194 | + |
|
| 195 | + if (is_array($_contexte)) { |
|
| 196 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 197 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 198 | + unset($_contexte['env']); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // noter les doublons dans l'appel a public.php |
|
| 202 | + if (isset($_contexte['doublons'])) { |
|
| 203 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 207 | + $ajax = preg_replace(",=>(.*)$,ims", '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 208 | + unset($_contexte['ajax']); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + $_contexte = join(",\n\t", $_contexte); |
|
| 212 | + } else { |
|
| 213 | + return false; |
|
| 214 | + } // j'aurais voulu toucher le fond ... |
|
| 215 | + |
|
| 216 | + $contexte = 'array(' . $_contexte . ')'; |
|
| 217 | + |
|
| 218 | + if ($env) { |
|
| 219 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 223 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 224 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 225 | + } else { |
|
| 226 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 227 | + if ($ajax) { |
|
| 228 | + $_options[] = $ajax; |
|
| 229 | + } |
|
| 230 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 231 | + $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | + "_request(\"connect\")") . ';'; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 251 | 251 | */ |
| 252 | 252 | function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
| 253 | - /* |
|
| 253 | + /* |
|
| 254 | 254 | $show['statut'][] = array( |
| 255 | 255 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 256 | 256 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -274,71 +274,71 @@ discard block |
||
| 274 | 274 | champstatut est alors le champ statut sur la tablen |
| 275 | 275 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 276 | 276 | */ |
| 277 | - $id_table = $boucle->id_table; |
|
| 278 | - $show = $boucle->show; |
|
| 279 | - if (isset($show['statut']) and $show['statut']) { |
|
| 280 | - foreach ($show['statut'] as $k => $s) { |
|
| 281 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 282 | - $filtrer = true; |
|
| 283 | - if (isset($s['exception'])) { |
|
| 284 | - foreach (is_array($s['exception']) ? $s['exception'] : array($s['exception']) as $m) { |
|
| 285 | - if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 286 | - $filtrer = false; |
|
| 287 | - break; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if ($filtrer) { |
|
| 293 | - if (is_array($s['champ'])) { |
|
| 294 | - $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 295 | - $jointures = array(); |
|
| 296 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 297 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 298 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 299 | - foreach ($s['champ'] as $j) { |
|
| 300 | - $id = reset($j); |
|
| 301 | - $def = $trouver_table($id); |
|
| 302 | - $jointures[] = array('', array($id, $def), end($j)); |
|
| 303 | - } |
|
| 304 | - $jointures[0][0] = $id_table; |
|
| 305 | - if (!array_search($id, $boucle->from)) { |
|
| 306 | - include_spip('public/jointures'); |
|
| 307 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 308 | - } |
|
| 309 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 310 | - $id = array_search($id, $boucle->from); |
|
| 311 | - } else { |
|
| 312 | - $id = $id_table; |
|
| 313 | - $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 314 | - } |
|
| 315 | - $mstatut = $id . '.' . $statut; |
|
| 316 | - |
|
| 317 | - $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
|
| 318 | - include_spip('public/quete'); |
|
| 319 | - if (isset($s['post_date']) and $s['post_date'] |
|
| 320 | - and $GLOBALS['meta']["post_dates"] == 'non' |
|
| 321 | - ) { |
|
| 322 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | - array_unshift($boucle->where, |
|
| 324 | - $echapper ? |
|
| 325 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 326 | - : |
|
| 327 | - quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 328 | - ); |
|
| 329 | - } |
|
| 330 | - array_unshift($boucle->where, |
|
| 331 | - $echapper ? |
|
| 332 | - "\nquete_condition_statut('$mstatut'," |
|
| 333 | - . _q($s['previsu']) . "," |
|
| 334 | - . _q($s['publie']) . "," |
|
| 335 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 336 | - : |
|
| 337 | - quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 338 | - ); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 277 | + $id_table = $boucle->id_table; |
|
| 278 | + $show = $boucle->show; |
|
| 279 | + if (isset($show['statut']) and $show['statut']) { |
|
| 280 | + foreach ($show['statut'] as $k => $s) { |
|
| 281 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 282 | + $filtrer = true; |
|
| 283 | + if (isset($s['exception'])) { |
|
| 284 | + foreach (is_array($s['exception']) ? $s['exception'] : array($s['exception']) as $m) { |
|
| 285 | + if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 286 | + $filtrer = false; |
|
| 287 | + break; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if ($filtrer) { |
|
| 293 | + if (is_array($s['champ'])) { |
|
| 294 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 295 | + $jointures = array(); |
|
| 296 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 297 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 298 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 299 | + foreach ($s['champ'] as $j) { |
|
| 300 | + $id = reset($j); |
|
| 301 | + $def = $trouver_table($id); |
|
| 302 | + $jointures[] = array('', array($id, $def), end($j)); |
|
| 303 | + } |
|
| 304 | + $jointures[0][0] = $id_table; |
|
| 305 | + if (!array_search($id, $boucle->from)) { |
|
| 306 | + include_spip('public/jointures'); |
|
| 307 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 308 | + } |
|
| 309 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 310 | + $id = array_search($id, $boucle->from); |
|
| 311 | + } else { |
|
| 312 | + $id = $id_table; |
|
| 313 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 314 | + } |
|
| 315 | + $mstatut = $id . '.' . $statut; |
|
| 316 | + |
|
| 317 | + $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
|
| 318 | + include_spip('public/quete'); |
|
| 319 | + if (isset($s['post_date']) and $s['post_date'] |
|
| 320 | + and $GLOBALS['meta']["post_dates"] == 'non' |
|
| 321 | + ) { |
|
| 322 | + $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | + array_unshift($boucle->where, |
|
| 324 | + $echapper ? |
|
| 325 | + "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 326 | + : |
|
| 327 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 328 | + ); |
|
| 329 | + } |
|
| 330 | + array_unshift($boucle->where, |
|
| 331 | + $echapper ? |
|
| 332 | + "\nquete_condition_statut('$mstatut'," |
|
| 333 | + . _q($s['previsu']) . "," |
|
| 334 | + . _q($s['publie']) . "," |
|
| 335 | + . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 336 | + : |
|
| 337 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -357,29 +357,29 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | function calculer_boucle($id_boucle, &$boucles) { |
| 359 | 359 | |
| 360 | - $boucle = &$boucles[$id_boucle]; |
|
| 361 | - instituer_boucle($boucle); |
|
| 362 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 363 | - |
|
| 364 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 365 | - // mais pas tous, sinon ca pete. |
|
| 366 | - if (_request('var_mode_affiche') != 'resultat') { |
|
| 367 | - $trace = ''; |
|
| 368 | - } else { |
|
| 369 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 370 | - $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 371 | - $trace = " |
|
| 360 | + $boucle = &$boucles[$id_boucle]; |
|
| 361 | + instituer_boucle($boucle); |
|
| 362 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 363 | + |
|
| 364 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 365 | + // mais pas tous, sinon ca pete. |
|
| 366 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 367 | + $trace = ''; |
|
| 368 | + } else { |
|
| 369 | + $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 370 | + $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 371 | + $trace = " |
|
| 372 | 372 | if (empty($_trace)) { |
| 373 | 373 | $_trace = []; |
| 374 | 374 | } |
| 375 | 375 | if (count($_trace) < 3) { |
| 376 | 376 | $_trace" . "[] = \$t0; |
| 377 | 377 | }"; |
| 378 | - } |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 381 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 382 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 380 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 381 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 382 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | |
@@ -402,15 +402,15 @@ discard block |
||
| 402 | 402 | * Code PHP compilé de la boucle récursive |
| 403 | 403 | **/ |
| 404 | 404 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 405 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 406 | - |
|
| 407 | - return |
|
| 408 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 409 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 410 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 411 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 412 | - . $trace |
|
| 413 | - . "\n\treturn \$t0;"; |
|
| 405 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 406 | + |
|
| 407 | + return |
|
| 408 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 409 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 410 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 411 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 412 | + . $trace |
|
| 413 | + . "\n\treturn \$t0;"; |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -464,169 +464,169 @@ discard block |
||
| 464 | 464 | **/ |
| 465 | 465 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 466 | 466 | |
| 467 | - $boucle = &$boucles[$id_boucle]; |
|
| 468 | - $return = $boucle->return; |
|
| 469 | - $type_boucle = $boucle->type_requete; |
|
| 470 | - $primary = $boucle->primary; |
|
| 471 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 472 | - $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 473 | - $corps = ''; |
|
| 474 | - |
|
| 475 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 476 | - // et puis faire un [] plutot qu'un "','." |
|
| 477 | - if ($boucle->doublons) { |
|
| 478 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 479 | - index_pile($id_boucle, $primary, $boucles) |
|
| 480 | - . "; // doublons\n"; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - // La boucle doit-elle selectionner la langue ? |
|
| 484 | - // - par defaut, les boucles suivantes le font |
|
| 485 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 486 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 487 | - if (!$constant && $boucle->lang_select != 'non' && |
|
| 488 | - (($boucle->lang_select == 'oui') || |
|
| 489 | - in_array($type_boucle, array( |
|
| 490 | - 'articles', |
|
| 491 | - 'rubriques', |
|
| 492 | - 'hierarchie', |
|
| 493 | - 'breves' |
|
| 494 | - ))) |
|
| 495 | - ) { |
|
| 496 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 497 | - // afin que le corps de boucle affecte la globale directement |
|
| 498 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 499 | - $fin_lang = "lang_select();\n\t"; |
|
| 500 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 501 | - |
|
| 502 | - $corps .= |
|
| 503 | - "\n\t\tlang_select_public(" |
|
| 504 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 505 | - . ", '" . $boucle->lang_select . "'" |
|
| 506 | - . (in_array($type_boucle, array( |
|
| 507 | - 'articles', |
|
| 508 | - 'rubriques', |
|
| 509 | - 'hierarchie', |
|
| 510 | - 'breves' |
|
| 511 | - )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 512 | - . ');'; |
|
| 513 | - } else { |
|
| 514 | - $init_lang = ''; |
|
| 515 | - $fin_lang = ''; |
|
| 516 | - $fin_lang_select_public = ''; |
|
| 517 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 518 | - if (strpos($return, '?php') === false |
|
| 519 | - and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 520 | - ) { |
|
| 521 | - $i = 1; |
|
| 522 | - foreach ($r[1] as $t) { |
|
| 523 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 524 | - $return = str_replace($t, "\$l$i", $return); |
|
| 525 | - $i++; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - // gestion optimale des separateurs et des boucles constantes |
|
| 531 | - if (count($boucle->separateur)) { |
|
| 532 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - $corps .= |
|
| 536 | - ((!$boucle->separateur) ? |
|
| 537 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 538 | - (($return === "''") ? '' : |
|
| 539 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 540 | - ("\n\t\t\$t1 " . |
|
| 541 | - ((strpos($return, '$t1.') === 0) ? |
|
| 542 | - (".=" . substr($return, 4)) : |
|
| 543 | - ('= ' . $return)) . |
|
| 544 | - ";\n\t\t" . |
|
| 545 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 546 | - |
|
| 547 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 548 | - // souhaite invalider ces elements |
|
| 549 | - if (!$constant and $primary) { |
|
| 550 | - include_spip('inc/invalideur'); |
|
| 551 | - $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - // gerer le compteur de boucle |
|
| 555 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 556 | - |
|
| 557 | - if ($boucle->partie or $boucle->cptrows) { |
|
| 558 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 559 | - . $boucle->partie |
|
| 560 | - . $corps; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - // depiler la lang de la boucle si besoin |
|
| 564 | - $corps .= $fin_lang_select_public; |
|
| 565 | - |
|
| 566 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 567 | - |
|
| 568 | - if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 569 | - if (!isset($r[2]) or (!$r[2])) { |
|
| 570 | - if (!$boucle->numrows) { |
|
| 571 | - return "\n\t\$t0 = '';"; |
|
| 572 | - } else { |
|
| 573 | - $corps = ""; |
|
| 574 | - } |
|
| 575 | - } else { |
|
| 576 | - $boucle->numrows = true; |
|
| 577 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 578 | - } |
|
| 579 | - } else { |
|
| 580 | - $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - $count = ''; |
|
| 584 | - if (!$boucle->select) { |
|
| 585 | - if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 586 | - $count = '1'; |
|
| 587 | - } else { |
|
| 588 | - $count = 'count(*)'; |
|
| 589 | - } |
|
| 590 | - $boucles[$id_boucle]->select[] = $count; |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - if ($flag_cpt) { |
|
| 594 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 595 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 596 | - } else { |
|
| 597 | - $nums = ''; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - if ($boucle->numrows or $boucle->mode_partie) { |
|
| 601 | - $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 602 | - . $boucle->mode_partie |
|
| 603 | - . "\n\t"; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - // Ne calculer la requete que maintenant |
|
| 607 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 608 | - |
|
| 609 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 610 | - ? ("\n\t$init = array();") : '') |
|
| 611 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 612 | - |
|
| 613 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 614 | - |
|
| 615 | - $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 616 | - $init, |
|
| 617 | - $boucle->iterateur, |
|
| 618 | - "\$command", |
|
| 619 | - $contexte, |
|
| 620 | - $nums, |
|
| 621 | - $init_lang, |
|
| 622 | - $corps, |
|
| 623 | - $fin_lang, |
|
| 624 | - $trace, |
|
| 625 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 626 | - ); |
|
| 467 | + $boucle = &$boucles[$id_boucle]; |
|
| 468 | + $return = $boucle->return; |
|
| 469 | + $type_boucle = $boucle->type_requete; |
|
| 470 | + $primary = $boucle->primary; |
|
| 471 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 472 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 473 | + $corps = ''; |
|
| 474 | + |
|
| 475 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 476 | + // et puis faire un [] plutot qu'un "','." |
|
| 477 | + if ($boucle->doublons) { |
|
| 478 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 479 | + index_pile($id_boucle, $primary, $boucles) |
|
| 480 | + . "; // doublons\n"; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + // La boucle doit-elle selectionner la langue ? |
|
| 484 | + // - par defaut, les boucles suivantes le font |
|
| 485 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 486 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 487 | + if (!$constant && $boucle->lang_select != 'non' && |
|
| 488 | + (($boucle->lang_select == 'oui') || |
|
| 489 | + in_array($type_boucle, array( |
|
| 490 | + 'articles', |
|
| 491 | + 'rubriques', |
|
| 492 | + 'hierarchie', |
|
| 493 | + 'breves' |
|
| 494 | + ))) |
|
| 495 | + ) { |
|
| 496 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 497 | + // afin que le corps de boucle affecte la globale directement |
|
| 498 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 499 | + $fin_lang = "lang_select();\n\t"; |
|
| 500 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 501 | + |
|
| 502 | + $corps .= |
|
| 503 | + "\n\t\tlang_select_public(" |
|
| 504 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 505 | + . ", '" . $boucle->lang_select . "'" |
|
| 506 | + . (in_array($type_boucle, array( |
|
| 507 | + 'articles', |
|
| 508 | + 'rubriques', |
|
| 509 | + 'hierarchie', |
|
| 510 | + 'breves' |
|
| 511 | + )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 512 | + . ');'; |
|
| 513 | + } else { |
|
| 514 | + $init_lang = ''; |
|
| 515 | + $fin_lang = ''; |
|
| 516 | + $fin_lang_select_public = ''; |
|
| 517 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 518 | + if (strpos($return, '?php') === false |
|
| 519 | + and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 520 | + ) { |
|
| 521 | + $i = 1; |
|
| 522 | + foreach ($r[1] as $t) { |
|
| 523 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 524 | + $return = str_replace($t, "\$l$i", $return); |
|
| 525 | + $i++; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + // gestion optimale des separateurs et des boucles constantes |
|
| 531 | + if (count($boucle->separateur)) { |
|
| 532 | + $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + $corps .= |
|
| 536 | + ((!$boucle->separateur) ? |
|
| 537 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 538 | + (($return === "''") ? '' : |
|
| 539 | + ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 540 | + ("\n\t\t\$t1 " . |
|
| 541 | + ((strpos($return, '$t1.') === 0) ? |
|
| 542 | + (".=" . substr($return, 4)) : |
|
| 543 | + ('= ' . $return)) . |
|
| 544 | + ";\n\t\t" . |
|
| 545 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 546 | + |
|
| 547 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 548 | + // souhaite invalider ces elements |
|
| 549 | + if (!$constant and $primary) { |
|
| 550 | + include_spip('inc/invalideur'); |
|
| 551 | + $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + // gerer le compteur de boucle |
|
| 555 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 556 | + |
|
| 557 | + if ($boucle->partie or $boucle->cptrows) { |
|
| 558 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 559 | + . $boucle->partie |
|
| 560 | + . $corps; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + // depiler la lang de la boucle si besoin |
|
| 564 | + $corps .= $fin_lang_select_public; |
|
| 565 | + |
|
| 566 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 567 | + |
|
| 568 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 569 | + if (!isset($r[2]) or (!$r[2])) { |
|
| 570 | + if (!$boucle->numrows) { |
|
| 571 | + return "\n\t\$t0 = '';"; |
|
| 572 | + } else { |
|
| 573 | + $corps = ""; |
|
| 574 | + } |
|
| 575 | + } else { |
|
| 576 | + $boucle->numrows = true; |
|
| 577 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 578 | + } |
|
| 579 | + } else { |
|
| 580 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + $count = ''; |
|
| 584 | + if (!$boucle->select) { |
|
| 585 | + if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 586 | + $count = '1'; |
|
| 587 | + } else { |
|
| 588 | + $count = 'count(*)'; |
|
| 589 | + } |
|
| 590 | + $boucles[$id_boucle]->select[] = $count; |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + if ($flag_cpt) { |
|
| 594 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 595 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 596 | + } else { |
|
| 597 | + $nums = ''; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + if ($boucle->numrows or $boucle->mode_partie) { |
|
| 601 | + $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 602 | + . $boucle->mode_partie |
|
| 603 | + . "\n\t"; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + // Ne calculer la requete que maintenant |
|
| 607 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 608 | + |
|
| 609 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 610 | + ? ("\n\t$init = array();") : '') |
|
| 611 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 612 | + |
|
| 613 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 614 | + |
|
| 615 | + $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 616 | + $init, |
|
| 617 | + $boucle->iterateur, |
|
| 618 | + "\$command", |
|
| 619 | + $contexte, |
|
| 620 | + $nums, |
|
| 621 | + $init_lang, |
|
| 622 | + $corps, |
|
| 623 | + $fin_lang, |
|
| 624 | + $trace, |
|
| 625 | + 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 626 | + ); |
|
| 627 | 627 | |
| 628 | 628 | # var_dump($a);exit; |
| 629 | - return $a; |
|
| 629 | + return $a; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | |
@@ -642,43 +642,43 @@ discard block |
||
| 642 | 642 | * Code PHP compilé définissant les informations de requête |
| 643 | 643 | **/ |
| 644 | 644 | function calculer_requete_sql($boucle) { |
| 645 | - $init = array(); |
|
| 646 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 647 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 648 | - # En absence de champ c'est un decompte : |
|
| 649 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 650 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 651 | - $init[] = calculer_dec('groupby', |
|
| 652 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 653 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 654 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 655 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 656 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 657 | - $init[] = calculer_dec('limit', |
|
| 658 | - (strpos($boucle->limit, 'intval') === false ? |
|
| 659 | - "'" . $boucle->limit . "'" |
|
| 660 | - : |
|
| 661 | - $boucle->limit)); |
|
| 662 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 663 | - $s = $d = ""; |
|
| 664 | - // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 665 | - // ou recalculée à chaque passage (vide) |
|
| 666 | - foreach ($init as $i) { |
|
| 667 | - if (reset($i)) { |
|
| 668 | - $s .= "\n\t\t" . end($i); |
|
| 669 | - } # statique |
|
| 670 | - else { |
|
| 671 | - $d .= "\n\t" . end($i); |
|
| 672 | - } # dynamique |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 676 | - . $boucle->in |
|
| 677 | - . $boucle->hash |
|
| 678 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 679 | - . $s |
|
| 680 | - . "\n\t}" |
|
| 681 | - . $d; |
|
| 645 | + $init = array(); |
|
| 646 | + $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 647 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 648 | + # En absence de champ c'est un decompte : |
|
| 649 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 650 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 651 | + $init[] = calculer_dec('groupby', |
|
| 652 | + 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 653 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 654 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 655 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 656 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 657 | + $init[] = calculer_dec('limit', |
|
| 658 | + (strpos($boucle->limit, 'intval') === false ? |
|
| 659 | + "'" . $boucle->limit . "'" |
|
| 660 | + : |
|
| 661 | + $boucle->limit)); |
|
| 662 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 663 | + $s = $d = ""; |
|
| 664 | + // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 665 | + // ou recalculée à chaque passage (vide) |
|
| 666 | + foreach ($init as $i) { |
|
| 667 | + if (reset($i)) { |
|
| 668 | + $s .= "\n\t\t" . end($i); |
|
| 669 | + } # statique |
|
| 670 | + else { |
|
| 671 | + $d .= "\n\t" . end($i); |
|
| 672 | + } # dynamique |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 676 | + . $boucle->in |
|
| 677 | + . $boucle->hash |
|
| 678 | + . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 679 | + . $s |
|
| 680 | + . "\n\t}" |
|
| 681 | + . $d; |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | /** |
@@ -696,13 +696,13 @@ discard block |
||
| 696 | 696 | * qui peut être utilisé pour la production d'un tableau array() |
| 697 | 697 | **/ |
| 698 | 698 | function memoriser_contexte_compil($p) { |
| 699 | - return join(',', array( |
|
| 700 | - _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 701 | - _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 702 | - _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 703 | - intval($p->ligne), |
|
| 704 | - '$GLOBALS[\'spip_lang\']' |
|
| 705 | - )); |
|
| 699 | + return join(',', array( |
|
| 700 | + _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 701 | + _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 702 | + _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 703 | + intval($p->ligne), |
|
| 704 | + '$GLOBALS[\'spip_lang\']' |
|
| 705 | + )); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -720,19 +720,19 @@ discard block |
||
| 720 | 720 | * Objet Contexte |
| 721 | 721 | **/ |
| 722 | 722 | function reconstruire_contexte_compil($context_compil) { |
| 723 | - if (!is_array($context_compil)) { |
|
| 724 | - return $context_compil; |
|
| 725 | - } |
|
| 726 | - $p = new Contexte; |
|
| 727 | - $p->descr = array( |
|
| 728 | - 'sourcefile' => $context_compil[0], |
|
| 729 | - 'nom' => $context_compil[1] |
|
| 730 | - ); |
|
| 731 | - $p->id_boucle = $context_compil[2]; |
|
| 732 | - $p->ligne = $context_compil[3]; |
|
| 733 | - $p->lang = $context_compil[4]; |
|
| 734 | - |
|
| 735 | - return $p; |
|
| 723 | + if (!is_array($context_compil)) { |
|
| 724 | + return $context_compil; |
|
| 725 | + } |
|
| 726 | + $p = new Contexte; |
|
| 727 | + $p->descr = array( |
|
| 728 | + 'sourcefile' => $context_compil[0], |
|
| 729 | + 'nom' => $context_compil[1] |
|
| 730 | + ); |
|
| 731 | + $p->id_boucle = $context_compil[2]; |
|
| 732 | + $p->ligne = $context_compil[3]; |
|
| 733 | + $p->lang = $context_compil[4]; |
|
| 734 | + |
|
| 735 | + return $p; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | /** |
@@ -758,12 +758,12 @@ discard block |
||
| 758 | 758 | * - index 1 : Code de l'affectation |
| 759 | 759 | **/ |
| 760 | 760 | function calculer_dec($nom, $val) { |
| 761 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 762 | - // si une variable apparait dans le calcul de la clause |
|
| 763 | - // il faut la re-evaluer a chaque passage |
|
| 764 | - if ( |
|
| 765 | - strpos($val, '$') !== false |
|
| 766 | - /* |
|
| 761 | + $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 762 | + // si une variable apparait dans le calcul de la clause |
|
| 763 | + // il faut la re-evaluer a chaque passage |
|
| 764 | + if ( |
|
| 765 | + strpos($val, '$') !== false |
|
| 766 | + /* |
|
| 767 | 767 | OR strpos($val, 'sql_') !== false |
| 768 | 768 | OR ( |
| 769 | 769 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -771,11 +771,11 @@ discard block |
||
| 771 | 771 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 772 | 772 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 773 | 773 | )*/ |
| 774 | - ) { |
|
| 775 | - $static = ""; |
|
| 776 | - } |
|
| 774 | + ) { |
|
| 775 | + $static = ""; |
|
| 776 | + } |
|
| 777 | 777 | |
| 778 | - return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 778 | + return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | /** |
@@ -795,32 +795,32 @@ discard block |
||
| 795 | 795 | * Expression PHP décrivant un texte ou un tableau |
| 796 | 796 | **/ |
| 797 | 797 | function calculer_dump_array($a) { |
| 798 | - if (!is_array($a)) { |
|
| 799 | - return $a; |
|
| 800 | - } |
|
| 801 | - $res = ""; |
|
| 802 | - if ($a and $a[0] == "'?'") { |
|
| 803 | - return ("(" . calculer_dump_array($a[1]) . |
|
| 804 | - " ? " . calculer_dump_array($a[2]) . |
|
| 805 | - " : " . calculer_dump_array($a[3]) . |
|
| 806 | - ")"); |
|
| 807 | - } else { |
|
| 808 | - foreach ($a as $v) { |
|
| 809 | - $res .= ", " . calculer_dump_array($v); |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 813 | - } |
|
| 798 | + if (!is_array($a)) { |
|
| 799 | + return $a; |
|
| 800 | + } |
|
| 801 | + $res = ""; |
|
| 802 | + if ($a and $a[0] == "'?'") { |
|
| 803 | + return ("(" . calculer_dump_array($a[1]) . |
|
| 804 | + " ? " . calculer_dump_array($a[2]) . |
|
| 805 | + " : " . calculer_dump_array($a[3]) . |
|
| 806 | + ")"); |
|
| 807 | + } else { |
|
| 808 | + foreach ($a as $v) { |
|
| 809 | + $res .= ", " . calculer_dump_array($v); |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 813 | + } |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | // https://code.spip.net/@calculer_dump_join |
| 817 | 817 | function calculer_dump_join($a) { |
| 818 | - $res = ""; |
|
| 819 | - foreach ($a as $k => $v) { |
|
| 820 | - $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 821 | - } |
|
| 818 | + $res = ""; |
|
| 819 | + foreach ($a as $k => $v) { |
|
| 820 | + $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 821 | + } |
|
| 822 | 822 | |
| 823 | - return 'array(' . substr($res, 2) . ')'; |
|
| 823 | + return 'array(' . substr($res, 2) . ')'; |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | /** |
@@ -832,12 +832,12 @@ discard block |
||
| 832 | 832 | * Code PHP construisant un tableau des alias et noms des tables du FROM |
| 833 | 833 | **/ |
| 834 | 834 | function calculer_from(&$boucle) { |
| 835 | - $res = ""; |
|
| 836 | - foreach ($boucle->from as $k => $v) { |
|
| 837 | - $res .= ",'$k' => '$v'"; |
|
| 838 | - } |
|
| 835 | + $res = ""; |
|
| 836 | + foreach ($boucle->from as $k => $v) { |
|
| 837 | + $res .= ",'$k' => '$v'"; |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | - return 'array(' . substr($res, 1) . ')'; |
|
| 840 | + return 'array(' . substr($res, 1) . ')'; |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | /** |
@@ -850,30 +850,30 @@ discard block |
||
| 850 | 850 | * Code PHP construisant un tableau des alias et type de jointure du FROM |
| 851 | 851 | **/ |
| 852 | 852 | function calculer_from_type(&$boucle) { |
| 853 | - $res = ""; |
|
| 854 | - foreach ($boucle->from_type as $k => $v) { |
|
| 855 | - $res .= ",'$k' => '$v'"; |
|
| 856 | - } |
|
| 853 | + $res = ""; |
|
| 854 | + foreach ($boucle->from_type as $k => $v) { |
|
| 855 | + $res .= ",'$k' => '$v'"; |
|
| 856 | + } |
|
| 857 | 857 | |
| 858 | - return 'array(' . substr($res, 1) . ')'; |
|
| 858 | + return 'array(' . substr($res, 1) . ')'; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | // https://code.spip.net/@calculer_order |
| 862 | 862 | function calculer_order(&$boucle) { |
| 863 | - if (!$order = $boucle->order |
|
| 864 | - and !$order = $boucle->default_order |
|
| 865 | - ) { |
|
| 866 | - $order = array(); |
|
| 867 | - } |
|
| 863 | + if (!$order = $boucle->order |
|
| 864 | + and !$order = $boucle->default_order |
|
| 865 | + ) { |
|
| 866 | + $order = array(); |
|
| 867 | + } |
|
| 868 | 868 | |
| 869 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 869 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 870 | 870 | $col = "." . $boucle->modificateur['collate']; |
| 871 | 871 | foreach($order as $k=>$o) |
| 872 | 872 | if (strpos($order[$k],'COLLATE')===false) |
| 873 | 873 | $order[$k].= $col; |
| 874 | 874 | }*/ |
| 875 | 875 | |
| 876 | - return join(', ', $order); |
|
| 876 | + return join(', ', $order); |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -883,59 +883,59 @@ discard block |
||
| 883 | 883 | |
| 884 | 884 | // https://code.spip.net/@calculer_liste |
| 885 | 885 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
| 886 | - if (!$tableau) { |
|
| 887 | - return "''"; |
|
| 888 | - } |
|
| 889 | - if (is_string($descr)) { |
|
| 890 | - if (isset($boucles[$descr])) { |
|
| 891 | - $idb = $descr; |
|
| 892 | - $descr = []; |
|
| 893 | - if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 894 | - $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 895 | - } |
|
| 896 | - if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 897 | - $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - else { |
|
| 901 | - $descr = array(); |
|
| 902 | - } |
|
| 903 | - } |
|
| 904 | - if (!isset($descr['niv'])) { |
|
| 905 | - $descr['niv'] = 0; |
|
| 906 | - } |
|
| 907 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 908 | - if ($codes === false) { |
|
| 909 | - return false; |
|
| 910 | - } |
|
| 911 | - $n = count($codes); |
|
| 912 | - if (!$n) { |
|
| 913 | - return "''"; |
|
| 914 | - } |
|
| 915 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 916 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 917 | - if ($n == 1) { |
|
| 918 | - return $codes[0]; |
|
| 919 | - } else { |
|
| 920 | - $res = ''; |
|
| 921 | - foreach ($codes as $code) { |
|
| 922 | - if (!preg_match("/^'[^']*'$/", $code) |
|
| 923 | - or substr($res, -1, 1) !== "'" |
|
| 924 | - ) { |
|
| 925 | - $res .= " .\n$tab$code"; |
|
| 926 | - } else { |
|
| 927 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 932 | - } |
|
| 933 | - } else { |
|
| 934 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 935 | - |
|
| 936 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 937 | - $codes) . ")))"; |
|
| 938 | - } |
|
| 886 | + if (!$tableau) { |
|
| 887 | + return "''"; |
|
| 888 | + } |
|
| 889 | + if (is_string($descr)) { |
|
| 890 | + if (isset($boucles[$descr])) { |
|
| 891 | + $idb = $descr; |
|
| 892 | + $descr = []; |
|
| 893 | + if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 894 | + $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 895 | + } |
|
| 896 | + if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 897 | + $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + else { |
|
| 901 | + $descr = array(); |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | + if (!isset($descr['niv'])) { |
|
| 905 | + $descr['niv'] = 0; |
|
| 906 | + } |
|
| 907 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 908 | + if ($codes === false) { |
|
| 909 | + return false; |
|
| 910 | + } |
|
| 911 | + $n = count($codes); |
|
| 912 | + if (!$n) { |
|
| 913 | + return "''"; |
|
| 914 | + } |
|
| 915 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 916 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 917 | + if ($n == 1) { |
|
| 918 | + return $codes[0]; |
|
| 919 | + } else { |
|
| 920 | + $res = ''; |
|
| 921 | + foreach ($codes as $code) { |
|
| 922 | + if (!preg_match("/^'[^']*'$/", $code) |
|
| 923 | + or substr($res, -1, 1) !== "'" |
|
| 924 | + ) { |
|
| 925 | + $res .= " .\n$tab$code"; |
|
| 926 | + } else { |
|
| 927 | + $res = substr($res, 0, -1) . substr($code, 1); |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 932 | + } |
|
| 933 | + } else { |
|
| 934 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 935 | + |
|
| 936 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 937 | + $codes) . ")))"; |
|
| 938 | + } |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | |
@@ -946,203 +946,203 @@ discard block |
||
| 946 | 946 | // https://code.spip.net/@compile_cas |
| 947 | 947 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 948 | 948 | |
| 949 | - $codes = array(); |
|
| 950 | - // cas de la boucle recursive |
|
| 951 | - if (is_array($id_boucle)) { |
|
| 952 | - $id_boucle = $id_boucle[0]; |
|
| 953 | - } |
|
| 954 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 955 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 956 | - $mode = _request('var_mode_affiche'); |
|
| 957 | - $err_e_c = ''; |
|
| 958 | - // chaque commentaire introduit dans le code doit commencer |
|
| 959 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 960 | - foreach ($tableau as $p) { |
|
| 961 | - |
|
| 962 | - switch ($p->type) { |
|
| 963 | - // texte seul |
|
| 964 | - case 'texte': |
|
| 965 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 966 | - $commentaire = strlen($p->texte) . " signes"; |
|
| 967 | - $avant = ''; |
|
| 968 | - $apres = ''; |
|
| 969 | - $altern = "''"; |
|
| 970 | - break; |
|
| 971 | - |
|
| 972 | - case 'polyglotte': |
|
| 973 | - $code = ""; |
|
| 974 | - foreach ($p->traductions as $k => $v) { |
|
| 975 | - $code .= ",'" . |
|
| 976 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 977 | - "' => '" . |
|
| 978 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 979 | - "'"; |
|
| 980 | - } |
|
| 981 | - $code = "choisir_traduction(array(" . |
|
| 982 | - substr($code, 1) . |
|
| 983 | - "))"; |
|
| 984 | - $commentaire = '&'; |
|
| 985 | - $avant = ''; |
|
| 986 | - $apres = ''; |
|
| 987 | - $altern = "''"; |
|
| 988 | - break; |
|
| 989 | - |
|
| 990 | - // inclure |
|
| 991 | - case 'include': |
|
| 992 | - $p->descr = $descr; |
|
| 993 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 994 | - if ($code === false) { |
|
| 995 | - $err_e_c = true; |
|
| 996 | - $code = "''"; |
|
| 997 | - } else { |
|
| 998 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 999 | - $avant = ''; |
|
| 1000 | - $apres = ''; |
|
| 1001 | - $altern = "''"; |
|
| 1002 | - } |
|
| 1003 | - break; |
|
| 1004 | - |
|
| 1005 | - // boucle |
|
| 1006 | - case TYPE_RECURSIF: |
|
| 1007 | - $nom = $p->id_boucle; |
|
| 1008 | - $newdescr = $descr; |
|
| 1009 | - $newdescr['id_mere'] = $nom; |
|
| 1010 | - $newdescr['niv']++; |
|
| 1011 | - $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1012 | - $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1013 | - $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1014 | - $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1015 | - $newdescr['niv']--; |
|
| 1016 | - $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1017 | - if ($preaff === false |
|
| 1018 | - or $avant === false |
|
| 1019 | - or $apres === false |
|
| 1020 | - or $altern === false |
|
| 1021 | - or $postaff === false) { |
|
| 1022 | - $err_e_c = true; |
|
| 1023 | - $code = "''"; |
|
| 1024 | - } else { |
|
| 1025 | - $code = 'BOUCLE' . |
|
| 1026 | - str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 1027 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1028 | - $commentaire = "?$nom"; |
|
| 1029 | - if (!$boucles[$nom]->milieu |
|
| 1030 | - and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1031 | - ) { |
|
| 1032 | - if ($preaff != "''") { |
|
| 1033 | - $code .= "\n. $preaff"; |
|
| 1034 | - } |
|
| 1035 | - if ($altern != "''") { |
|
| 1036 | - $code .= "\n. $altern"; |
|
| 1037 | - } |
|
| 1038 | - if ($postaff != "''") { |
|
| 1039 | - $code .= "\n. $postaff"; |
|
| 1040 | - } |
|
| 1041 | - if ($avant <> "''" or $apres <> "''") { |
|
| 1042 | - spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1043 | - } |
|
| 1044 | - $avant = $apres = $altern = "''"; |
|
| 1045 | - } else { |
|
| 1046 | - if ($preaff != "''") { |
|
| 1047 | - $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1048 | - $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1049 | - } |
|
| 1050 | - if ($postaff != "''") { |
|
| 1051 | - $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1052 | - $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1053 | - } |
|
| 1054 | - if ($altern != "''") { |
|
| 1055 | - $altern = "($altern)"; |
|
| 1056 | - } |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - break; |
|
| 1060 | - |
|
| 1061 | - case 'idiome': |
|
| 1062 | - $l = array(); |
|
| 1063 | - $code = ''; |
|
| 1064 | - foreach ($p->arg as $k => $v) { |
|
| 1065 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1066 | - if ($k) { |
|
| 1067 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1068 | - } else { |
|
| 1069 | - $code = $_v; |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1073 | - if ($p->module) { |
|
| 1074 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1075 | - } elseif ($p->nom_champ) { |
|
| 1076 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1077 | - } else { |
|
| 1078 | - $m = ''; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - $code = (!$code ? "'$m'" : |
|
| 1082 | - ($m ? "'$m' . $code" : |
|
| 1083 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1084 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1085 | - $code = "_T($code)"; |
|
| 1086 | - if ($p->param) { |
|
| 1087 | - $p->id_boucle = $id_boucle; |
|
| 1088 | - $p->boucles = &$boucles; |
|
| 1089 | - $code = compose_filtres($p, $code); |
|
| 1090 | - } |
|
| 1091 | - $commentaire = ":"; |
|
| 1092 | - $avant = ''; |
|
| 1093 | - $apres = ''; |
|
| 1094 | - $altern = "''"; |
|
| 1095 | - break; |
|
| 1096 | - |
|
| 1097 | - case 'champ': |
|
| 1098 | - |
|
| 1099 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1100 | - $p->id_boucle = $id_boucle; |
|
| 1101 | - $p->boucles = &$boucles; |
|
| 1102 | - $p->descr = $descr; |
|
| 1103 | - #$p->interdire_scripts = true; |
|
| 1104 | - $p->type_requete = $type; |
|
| 1105 | - |
|
| 1106 | - $code = calculer_champ($p); |
|
| 1107 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1108 | - $avant = calculer_liste($p->avant, |
|
| 1109 | - $descr, $boucles, $id_boucle); |
|
| 1110 | - $apres = calculer_liste($p->apres, |
|
| 1111 | - $descr, $boucles, $id_boucle); |
|
| 1112 | - $altern = "''"; |
|
| 1113 | - // Si la valeur est destinee a une comparaison a '' |
|
| 1114 | - // forcer la conversion en une chaine par strval |
|
| 1115 | - // si ca peut etre autre chose qu'une chaine |
|
| 1116 | - if (($avant != "''" or $apres != "''") |
|
| 1117 | - and $code[0] != "'" |
|
| 949 | + $codes = array(); |
|
| 950 | + // cas de la boucle recursive |
|
| 951 | + if (is_array($id_boucle)) { |
|
| 952 | + $id_boucle = $id_boucle[0]; |
|
| 953 | + } |
|
| 954 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 955 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 956 | + $mode = _request('var_mode_affiche'); |
|
| 957 | + $err_e_c = ''; |
|
| 958 | + // chaque commentaire introduit dans le code doit commencer |
|
| 959 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 960 | + foreach ($tableau as $p) { |
|
| 961 | + |
|
| 962 | + switch ($p->type) { |
|
| 963 | + // texte seul |
|
| 964 | + case 'texte': |
|
| 965 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 966 | + $commentaire = strlen($p->texte) . " signes"; |
|
| 967 | + $avant = ''; |
|
| 968 | + $apres = ''; |
|
| 969 | + $altern = "''"; |
|
| 970 | + break; |
|
| 971 | + |
|
| 972 | + case 'polyglotte': |
|
| 973 | + $code = ""; |
|
| 974 | + foreach ($p->traductions as $k => $v) { |
|
| 975 | + $code .= ",'" . |
|
| 976 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 977 | + "' => '" . |
|
| 978 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 979 | + "'"; |
|
| 980 | + } |
|
| 981 | + $code = "choisir_traduction(array(" . |
|
| 982 | + substr($code, 1) . |
|
| 983 | + "))"; |
|
| 984 | + $commentaire = '&'; |
|
| 985 | + $avant = ''; |
|
| 986 | + $apres = ''; |
|
| 987 | + $altern = "''"; |
|
| 988 | + break; |
|
| 989 | + |
|
| 990 | + // inclure |
|
| 991 | + case 'include': |
|
| 992 | + $p->descr = $descr; |
|
| 993 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 994 | + if ($code === false) { |
|
| 995 | + $err_e_c = true; |
|
| 996 | + $code = "''"; |
|
| 997 | + } else { |
|
| 998 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 999 | + $avant = ''; |
|
| 1000 | + $apres = ''; |
|
| 1001 | + $altern = "''"; |
|
| 1002 | + } |
|
| 1003 | + break; |
|
| 1004 | + |
|
| 1005 | + // boucle |
|
| 1006 | + case TYPE_RECURSIF: |
|
| 1007 | + $nom = $p->id_boucle; |
|
| 1008 | + $newdescr = $descr; |
|
| 1009 | + $newdescr['id_mere'] = $nom; |
|
| 1010 | + $newdescr['niv']++; |
|
| 1011 | + $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1012 | + $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1013 | + $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1014 | + $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1015 | + $newdescr['niv']--; |
|
| 1016 | + $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1017 | + if ($preaff === false |
|
| 1018 | + or $avant === false |
|
| 1019 | + or $apres === false |
|
| 1020 | + or $altern === false |
|
| 1021 | + or $postaff === false) { |
|
| 1022 | + $err_e_c = true; |
|
| 1023 | + $code = "''"; |
|
| 1024 | + } else { |
|
| 1025 | + $code = 'BOUCLE' . |
|
| 1026 | + str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 1027 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1028 | + $commentaire = "?$nom"; |
|
| 1029 | + if (!$boucles[$nom]->milieu |
|
| 1030 | + and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1031 | + ) { |
|
| 1032 | + if ($preaff != "''") { |
|
| 1033 | + $code .= "\n. $preaff"; |
|
| 1034 | + } |
|
| 1035 | + if ($altern != "''") { |
|
| 1036 | + $code .= "\n. $altern"; |
|
| 1037 | + } |
|
| 1038 | + if ($postaff != "''") { |
|
| 1039 | + $code .= "\n. $postaff"; |
|
| 1040 | + } |
|
| 1041 | + if ($avant <> "''" or $apres <> "''") { |
|
| 1042 | + spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1043 | + } |
|
| 1044 | + $avant = $apres = $altern = "''"; |
|
| 1045 | + } else { |
|
| 1046 | + if ($preaff != "''") { |
|
| 1047 | + $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1048 | + $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1049 | + } |
|
| 1050 | + if ($postaff != "''") { |
|
| 1051 | + $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1052 | + $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1053 | + } |
|
| 1054 | + if ($altern != "''") { |
|
| 1055 | + $altern = "($altern)"; |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + break; |
|
| 1060 | + |
|
| 1061 | + case 'idiome': |
|
| 1062 | + $l = array(); |
|
| 1063 | + $code = ''; |
|
| 1064 | + foreach ($p->arg as $k => $v) { |
|
| 1065 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1066 | + if ($k) { |
|
| 1067 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 1068 | + } else { |
|
| 1069 | + $code = $_v; |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1073 | + if ($p->module) { |
|
| 1074 | + $m = $p->module . ':' . $p->nom_champ; |
|
| 1075 | + } elseif ($p->nom_champ) { |
|
| 1076 | + $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1077 | + } else { |
|
| 1078 | + $m = ''; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + $code = (!$code ? "'$m'" : |
|
| 1082 | + ($m ? "'$m' . $code" : |
|
| 1083 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1084 | + . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1085 | + $code = "_T($code)"; |
|
| 1086 | + if ($p->param) { |
|
| 1087 | + $p->id_boucle = $id_boucle; |
|
| 1088 | + $p->boucles = &$boucles; |
|
| 1089 | + $code = compose_filtres($p, $code); |
|
| 1090 | + } |
|
| 1091 | + $commentaire = ":"; |
|
| 1092 | + $avant = ''; |
|
| 1093 | + $apres = ''; |
|
| 1094 | + $altern = "''"; |
|
| 1095 | + break; |
|
| 1096 | + |
|
| 1097 | + case 'champ': |
|
| 1098 | + |
|
| 1099 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1100 | + $p->id_boucle = $id_boucle; |
|
| 1101 | + $p->boucles = &$boucles; |
|
| 1102 | + $p->descr = $descr; |
|
| 1103 | + #$p->interdire_scripts = true; |
|
| 1104 | + $p->type_requete = $type; |
|
| 1105 | + |
|
| 1106 | + $code = calculer_champ($p); |
|
| 1107 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1108 | + $avant = calculer_liste($p->avant, |
|
| 1109 | + $descr, $boucles, $id_boucle); |
|
| 1110 | + $apres = calculer_liste($p->apres, |
|
| 1111 | + $descr, $boucles, $id_boucle); |
|
| 1112 | + $altern = "''"; |
|
| 1113 | + // Si la valeur est destinee a une comparaison a '' |
|
| 1114 | + // forcer la conversion en une chaine par strval |
|
| 1115 | + // si ca peut etre autre chose qu'une chaine |
|
| 1116 | + if (($avant != "''" or $apres != "''") |
|
| 1117 | + and $code[0] != "'" |
|
| 1118 | 1118 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 1119 | - and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1120 | - and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1121 | - and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1122 | - ) { |
|
| 1123 | - $code = "strval($code)"; |
|
| 1124 | - } |
|
| 1125 | - break; |
|
| 1126 | - |
|
| 1127 | - default: |
|
| 1128 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1129 | - $code = "''"; |
|
| 1130 | - $p->descr = $descr; |
|
| 1131 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1132 | - erreur_squelette($err_e_c, $p); |
|
| 1133 | - } // switch |
|
| 1134 | - |
|
| 1135 | - if ($code != "''") { |
|
| 1136 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1137 | - $codes[] = (($mode == 'validation') ? |
|
| 1138 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1139 | - : (($mode == 'code') ? |
|
| 1140 | - "\n// $commentaire\n$code" : |
|
| 1141 | - $code)); |
|
| 1142 | - } |
|
| 1143 | - } // foreach |
|
| 1144 | - |
|
| 1145 | - return $err_e_c ? false : $codes; |
|
| 1119 | + and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1120 | + and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1121 | + and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1122 | + ) { |
|
| 1123 | + $code = "strval($code)"; |
|
| 1124 | + } |
|
| 1125 | + break; |
|
| 1126 | + |
|
| 1127 | + default: |
|
| 1128 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1129 | + $code = "''"; |
|
| 1130 | + $p->descr = $descr; |
|
| 1131 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1132 | + erreur_squelette($err_e_c, $p); |
|
| 1133 | + } // switch |
|
| 1134 | + |
|
| 1135 | + if ($code != "''") { |
|
| 1136 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1137 | + $codes[] = (($mode == 'validation') ? |
|
| 1138 | + "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1139 | + : (($mode == 'code') ? |
|
| 1140 | + "\n// $commentaire\n$code" : |
|
| 1141 | + $code)); |
|
| 1142 | + } |
|
| 1143 | + } // foreach |
|
| 1144 | + |
|
| 1145 | + return $err_e_c ? false : $codes; |
|
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 1148 | 1148 | /** |
@@ -1152,13 +1152,13 @@ discard block |
||
| 1152 | 1152 | * @return string |
| 1153 | 1153 | */ |
| 1154 | 1154 | function compile_concatene_parties_codes($partie1, $partie2) { |
| 1155 | - if ($partie1 === "''") { |
|
| 1156 | - return $partie2; |
|
| 1157 | - } |
|
| 1158 | - if ($partie2 === "''") { |
|
| 1159 | - return $partie1; |
|
| 1160 | - } |
|
| 1161 | - return "$partie1\n. $partie2"; |
|
| 1155 | + if ($partie1 === "''") { |
|
| 1156 | + return $partie2; |
|
| 1157 | + } |
|
| 1158 | + if ($partie2 === "''") { |
|
| 1159 | + return $partie1; |
|
| 1160 | + } |
|
| 1161 | + return "$partie1\n. $partie2"; |
|
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | 1164 | |
@@ -1183,57 +1183,57 @@ discard block |
||
| 1183 | 1183 | * @return mixed|string |
| 1184 | 1184 | */ |
| 1185 | 1185 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1186 | - if ($avant === "''") { |
|
| 1187 | - $avant = ''; |
|
| 1188 | - } |
|
| 1189 | - if ($apres === "''") { |
|
| 1190 | - $apres = ''; |
|
| 1191 | - } |
|
| 1192 | - if ($avant or $apres or ($altern !== "''")){ |
|
| 1193 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)){ |
|
| 1194 | - $t = $code; |
|
| 1195 | - $cond = ''; |
|
| 1196 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1197 | - $t = $r[2]; |
|
| 1198 | - $cond = '!' . $r[1]; |
|
| 1199 | - } else { |
|
| 1200 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)){ |
|
| 1201 | - $t = $r[2]; |
|
| 1202 | - $cond = $r[1]; |
|
| 1203 | - } else { |
|
| 1204 | - $t = '$t' . $n; |
|
| 1205 | - $cond = "($t = $code)!==''"; |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 1210 | - $t . |
|
| 1211 | - (!$apres ? "" : " . $apres"); |
|
| 1212 | - |
|
| 1213 | - if ($res!==$t){ |
|
| 1214 | - $res = "($res)"; |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - return $code; |
|
| 1186 | + if ($avant === "''") { |
|
| 1187 | + $avant = ''; |
|
| 1188 | + } |
|
| 1189 | + if ($apres === "''") { |
|
| 1190 | + $apres = ''; |
|
| 1191 | + } |
|
| 1192 | + if ($avant or $apres or ($altern !== "''")){ |
|
| 1193 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)){ |
|
| 1194 | + $t = $code; |
|
| 1195 | + $cond = ''; |
|
| 1196 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1197 | + $t = $r[2]; |
|
| 1198 | + $cond = '!' . $r[1]; |
|
| 1199 | + } else { |
|
| 1200 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)){ |
|
| 1201 | + $t = $r[2]; |
|
| 1202 | + $cond = $r[1]; |
|
| 1203 | + } else { |
|
| 1204 | + $t = '$t' . $n; |
|
| 1205 | + $cond = "($t = $code)!==''"; |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + $res = (!$avant ? "" : "$avant . ") . |
|
| 1210 | + $t . |
|
| 1211 | + (!$apres ? "" : " . $apres"); |
|
| 1212 | + |
|
| 1213 | + if ($res!==$t){ |
|
| 1214 | + $res = "($res)"; |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + return $code; |
|
| 1221 | 1221 | |
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | 1224 | |
| 1225 | 1225 | function compile_inclure_doublons($lexemes) { |
| 1226 | - foreach ($lexemes as $v) { |
|
| 1227 | - if ($v->type === 'include' and $v->param) { |
|
| 1228 | - foreach ($v->param as $r) { |
|
| 1229 | - if (trim($r[0]) === 'doublons') { |
|
| 1230 | - return true; |
|
| 1231 | - } |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - return false; |
|
| 1226 | + foreach ($lexemes as $v) { |
|
| 1227 | + if ($v->type === 'include' and $v->param) { |
|
| 1228 | + foreach ($v->param as $r) { |
|
| 1229 | + if (trim($r[0]) === 'doublons') { |
|
| 1230 | + return true; |
|
| 1231 | + } |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + return false; |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1253,348 +1253,348 @@ discard block |
||
| 1253 | 1253 | |
| 1254 | 1254 | // https://code.spip.net/@public_compiler_dist |
| 1255 | 1255 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, $connect = '') { |
| 1256 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1257 | - // Bonus : supprime le BOM |
|
| 1258 | - include_spip('inc/charsets'); |
|
| 1259 | - $squelette = transcoder_page($squelette); |
|
| 1260 | - |
|
| 1261 | - // rendre inertes les echappements de #[](){}<> |
|
| 1262 | - $i = 0; |
|
| 1263 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1264 | - $i++; |
|
| 1265 | - } |
|
| 1266 | - $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1267 | - function($a) use ($inerte) { |
|
| 1268 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1269 | - }, |
|
| 1270 | - $squelette, |
|
| 1271 | - -1, |
|
| 1272 | - $esc |
|
| 1273 | - ); |
|
| 1274 | - |
|
| 1275 | - $descr = array( |
|
| 1276 | - 'nom' => $nom, |
|
| 1277 | - 'gram' => $gram, |
|
| 1278 | - 'sourcefile' => $sourcefile, |
|
| 1279 | - 'squelette' => $squelette |
|
| 1280 | - ); |
|
| 1281 | - |
|
| 1282 | - // Phraser le squelette, selon sa grammaire |
|
| 1283 | - |
|
| 1284 | - $boucles = array(); |
|
| 1285 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1286 | - |
|
| 1287 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1288 | - |
|
| 1289 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1290 | - |
|
| 1291 | - // restituer les echappements |
|
| 1292 | - if ($esc) { |
|
| 1293 | - foreach ($boucles as $i => $boucle) { |
|
| 1294 | - $boucles[$i]->return = preg_replace_callback( |
|
| 1295 | - ",$inerte-(\d+)-,", |
|
| 1296 | - function($a) { |
|
| 1297 | - return chr($a[1]); |
|
| 1298 | - }, |
|
| 1299 | - $boucle->return |
|
| 1300 | - ); |
|
| 1301 | - $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1302 | - ",$inerte-(\d+)-,", |
|
| 1303 | - function($a) { |
|
| 1304 | - return "\\\\" . chr($a[1]); |
|
| 1305 | - }, |
|
| 1306 | - $boucle->descr['squelette'] |
|
| 1307 | - ); |
|
| 1308 | - } |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1312 | - if ($debug) { |
|
| 1313 | - include_spip('public/decompiler'); |
|
| 1314 | - foreach ($boucles as $id => $boucle) { |
|
| 1315 | - if ($id) { |
|
| 1316 | - $decomp = "\n/* BOUCLE " . |
|
| 1317 | - $boucle->type_requete . |
|
| 1318 | - " " . |
|
| 1319 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1320 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1321 | - " */\n"; |
|
| 1322 | - } else { |
|
| 1323 | - $decomp = ("\n/*\n" . |
|
| 1324 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1325 | - . "\n*/"); |
|
| 1326 | - } |
|
| 1327 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1328 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1329 | - } |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - return $boucles; |
|
| 1256 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1257 | + // Bonus : supprime le BOM |
|
| 1258 | + include_spip('inc/charsets'); |
|
| 1259 | + $squelette = transcoder_page($squelette); |
|
| 1260 | + |
|
| 1261 | + // rendre inertes les echappements de #[](){}<> |
|
| 1262 | + $i = 0; |
|
| 1263 | + while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1264 | + $i++; |
|
| 1265 | + } |
|
| 1266 | + $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1267 | + function($a) use ($inerte) { |
|
| 1268 | + return "$inerte-" . ord($a[1]) . '-'; |
|
| 1269 | + }, |
|
| 1270 | + $squelette, |
|
| 1271 | + -1, |
|
| 1272 | + $esc |
|
| 1273 | + ); |
|
| 1274 | + |
|
| 1275 | + $descr = array( |
|
| 1276 | + 'nom' => $nom, |
|
| 1277 | + 'gram' => $gram, |
|
| 1278 | + 'sourcefile' => $sourcefile, |
|
| 1279 | + 'squelette' => $squelette |
|
| 1280 | + ); |
|
| 1281 | + |
|
| 1282 | + // Phraser le squelette, selon sa grammaire |
|
| 1283 | + |
|
| 1284 | + $boucles = array(); |
|
| 1285 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1286 | + |
|
| 1287 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1288 | + |
|
| 1289 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1290 | + |
|
| 1291 | + // restituer les echappements |
|
| 1292 | + if ($esc) { |
|
| 1293 | + foreach ($boucles as $i => $boucle) { |
|
| 1294 | + $boucles[$i]->return = preg_replace_callback( |
|
| 1295 | + ",$inerte-(\d+)-,", |
|
| 1296 | + function($a) { |
|
| 1297 | + return chr($a[1]); |
|
| 1298 | + }, |
|
| 1299 | + $boucle->return |
|
| 1300 | + ); |
|
| 1301 | + $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1302 | + ",$inerte-(\d+)-,", |
|
| 1303 | + function($a) { |
|
| 1304 | + return "\\\\" . chr($a[1]); |
|
| 1305 | + }, |
|
| 1306 | + $boucle->descr['squelette'] |
|
| 1307 | + ); |
|
| 1308 | + } |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1312 | + if ($debug) { |
|
| 1313 | + include_spip('public/decompiler'); |
|
| 1314 | + foreach ($boucles as $id => $boucle) { |
|
| 1315 | + if ($id) { |
|
| 1316 | + $decomp = "\n/* BOUCLE " . |
|
| 1317 | + $boucle->type_requete . |
|
| 1318 | + " " . |
|
| 1319 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1320 | + ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1321 | + " */\n"; |
|
| 1322 | + } else { |
|
| 1323 | + $decomp = ("\n/*\n" . |
|
| 1324 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1325 | + . "\n*/"); |
|
| 1326 | + } |
|
| 1327 | + $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1328 | + $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1329 | + } |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + return $boucles; |
|
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 1335 | 1335 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1336 | 1336 | // Autres specifications comme ci-dessus |
| 1337 | 1337 | |
| 1338 | 1338 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect = '') { |
| 1339 | - static $trouver_table; |
|
| 1340 | - spip_timer('calcul_skel'); |
|
| 1341 | - |
|
| 1342 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1343 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1344 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1345 | - |
|
| 1346 | - if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1347 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1348 | - } |
|
| 1349 | - } |
|
| 1350 | - foreach ($boucles as $id => $boucle) { |
|
| 1351 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1352 | - } |
|
| 1353 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1354 | - |
|
| 1355 | - // Demander la description des tables une fois pour toutes |
|
| 1356 | - if (!$trouver_table) { |
|
| 1357 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - // reperer si les doublons sont demandes |
|
| 1361 | - // pour un inclure ou une boucle document |
|
| 1362 | - // c'est utile a la fonction champs_traitements |
|
| 1363 | - foreach ($boucles as $id => $boucle) { |
|
| 1364 | - if (!($type = $boucle->type_requete)) { |
|
| 1365 | - continue; |
|
| 1366 | - } |
|
| 1367 | - if (!$descr['documents'] and ( |
|
| 1368 | - (($type == 'documents') and $boucle->doublons) or |
|
| 1369 | - compile_inclure_doublons($boucle->avant) or |
|
| 1370 | - compile_inclure_doublons($boucle->apres) or |
|
| 1371 | - compile_inclure_doublons($boucle->milieu) or |
|
| 1372 | - compile_inclure_doublons($boucle->altern)) |
|
| 1373 | - ) { |
|
| 1374 | - $descr['documents'] = true; |
|
| 1375 | - } |
|
| 1376 | - if ($type != TYPE_RECURSIF) { |
|
| 1377 | - if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1378 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1379 | - } |
|
| 1380 | - |
|
| 1381 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1382 | - if ($g = charger_fonction( |
|
| 1383 | - preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true) |
|
| 1384 | - ) { |
|
| 1385 | - $boucles[$id] = $g($boucle); |
|
| 1386 | - |
|
| 1387 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1388 | - // utiliser les informations donnees par le requeteur |
|
| 1389 | - // cas "php:xx" et "data:xx". |
|
| 1390 | - } else { |
|
| 1391 | - if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1392 | - $requeteur($boucles, $boucle, $id); |
|
| 1393 | - |
|
| 1394 | - // utiliser la description des champs transmis |
|
| 1395 | - } else { |
|
| 1396 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1397 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1398 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1399 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1400 | - if (!$show |
|
| 1401 | - and $show = $trouver_table($type, strtolower($type)) |
|
| 1402 | - ) { |
|
| 1403 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1404 | - } |
|
| 1405 | - if ($show) { |
|
| 1406 | - $boucles[$id]->show = $show; |
|
| 1407 | - // recopie les infos les plus importantes |
|
| 1408 | - $boucles[$id]->primary = isset($show['key']["PRIMARY KEY"]) ? $show['key']["PRIMARY KEY"] : ''; |
|
| 1409 | - $boucles[$id]->id_table = $x = preg_replace(",^spip_,", "", $show['id_table']); |
|
| 1410 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1411 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1412 | - |
|
| 1413 | - if (empty($boucles[$id]->descr)) { |
|
| 1414 | - $boucles[$id]->descr = &$descr; |
|
| 1415 | - } |
|
| 1416 | - if ((!$boucles[$id]->jointures) |
|
| 1417 | - and is_array($show['tables_jointures']) |
|
| 1418 | - and count($x = $show['tables_jointures']) |
|
| 1419 | - ) { |
|
| 1420 | - $boucles[$id]->jointures = $x; |
|
| 1421 | - } |
|
| 1422 | - if ($boucles[$id]->jointures_explicites) { |
|
| 1423 | - $jointures = preg_split("/\s+/", $boucles[$id]->jointures_explicites); |
|
| 1424 | - while ($j = array_pop($jointures)) { |
|
| 1425 | - array_unshift($boucles[$id]->jointures, $j); |
|
| 1426 | - } |
|
| 1427 | - } |
|
| 1428 | - } else { |
|
| 1429 | - // Pas une erreur si la table est optionnelle |
|
| 1430 | - if ($boucles[$id]->table_optionnelle) { |
|
| 1431 | - $boucles[$id]->type_requete = ''; |
|
| 1432 | - } else { |
|
| 1433 | - $boucles[$id]->type_requete = false; |
|
| 1434 | - $boucle = $boucles[$id]; |
|
| 1435 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1436 | - ($boucle->sql_serveur . ":")) . |
|
| 1437 | - $type; |
|
| 1438 | - $msg = array( |
|
| 1439 | - 'zbug_table_inconnue', |
|
| 1440 | - array('table' => $x) |
|
| 1441 | - ); |
|
| 1442 | - erreur_squelette($msg, $boucle); |
|
| 1443 | - } |
|
| 1444 | - } |
|
| 1445 | - } |
|
| 1446 | - } |
|
| 1447 | - } |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1451 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1452 | - foreach ($boucles as $id => $boucle) { |
|
| 1453 | - if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1454 | - $boucles[$id]->descr = &$descr; |
|
| 1455 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1456 | - if (!$rec) { |
|
| 1457 | - $msg = array( |
|
| 1458 | - 'zbug_boucle_recursive_undef', |
|
| 1459 | - array('nom' => $boucle->param[0]) |
|
| 1460 | - ); |
|
| 1461 | - erreur_squelette($msg, $boucle); |
|
| 1462 | - $boucles[$id]->type_requete = false; |
|
| 1463 | - } else { |
|
| 1464 | - $rec->externe = $id; |
|
| 1465 | - $descr['id_mere'] = $id; |
|
| 1466 | - $boucles[$id]->return = |
|
| 1467 | - calculer_liste(array($rec), |
|
| 1468 | - $descr, |
|
| 1469 | - $boucles, |
|
| 1470 | - $boucle->param); |
|
| 1471 | - } |
|
| 1472 | - } |
|
| 1473 | - } |
|
| 1474 | - foreach ($boucles as $id => $boucle) { |
|
| 1475 | - $id = strval($id); // attention au type dans index_pile |
|
| 1476 | - $type = $boucle->type_requete; |
|
| 1477 | - if ($type and $type != TYPE_RECURSIF) { |
|
| 1478 | - $res = ''; |
|
| 1479 | - if ($boucle->param) { |
|
| 1480 | - // retourne un tableau en cas d'erreur |
|
| 1481 | - $res = calculer_criteres($id, $boucles); |
|
| 1482 | - } |
|
| 1483 | - $descr['id_mere'] = $id; |
|
| 1484 | - $boucles[$id]->return = |
|
| 1485 | - calculer_liste($boucle->milieu, |
|
| 1486 | - $descr, |
|
| 1487 | - $boucles, |
|
| 1488 | - $id); |
|
| 1489 | - // Si les criteres se sont mal compiles |
|
| 1490 | - // ne pas tenter d'assembler le code final |
|
| 1491 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1492 | - if (is_array($res)) { |
|
| 1493 | - $boucles[$id]->type_requete = false; |
|
| 1494 | - } |
|
| 1495 | - } |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - // idem pour la racine |
|
| 1499 | - $descr['id_mere'] = ''; |
|
| 1500 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1501 | - |
|
| 1502 | - |
|
| 1503 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1504 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1505 | - // de'terminables seulement maintenant |
|
| 1506 | - |
|
| 1507 | - foreach ($boucles as $id => $boucle) { |
|
| 1508 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1509 | - if ($boucle->return === false) { |
|
| 1510 | - $corps = false; |
|
| 1511 | - continue; |
|
| 1512 | - } |
|
| 1513 | - // appeler la fonction de definition de la boucle |
|
| 1514 | - |
|
| 1515 | - if ($req = $boucle->type_requete) { |
|
| 1516 | - // boucle personnalisée ? |
|
| 1517 | - $table = strtoupper($boucle->type_requete); |
|
| 1518 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1519 | - if ( |
|
| 1520 | - // fonction de boucle avec serveur & table |
|
| 1521 | - (!$serveur or |
|
| 1522 | - ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1523 | - and (!function_exists($f = $f . "_dist")) |
|
| 1524 | - ) |
|
| 1525 | - ) |
|
| 1526 | - // fonction de boucle avec table |
|
| 1527 | - and (!function_exists($f = "boucle_" . $table)) |
|
| 1528 | - and (!function_exists($f = $f . "_dist")) |
|
| 1529 | - ) { |
|
| 1530 | - // fonction de boucle standard |
|
| 1531 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1532 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1533 | - } |
|
| 1534 | - } |
|
| 1535 | - |
|
| 1536 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1537 | - "static \$connect;\n\t" . |
|
| 1538 | - "\$command['connect'] = \$connect = " . |
|
| 1539 | - _q($boucle->sql_serveur) . |
|
| 1540 | - ";" . |
|
| 1541 | - $f($id, $boucles); |
|
| 1542 | - } else { |
|
| 1543 | - $req = ("\n\treturn '';"); |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - $boucles[$id]->return = |
|
| 1547 | - "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1548 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1549 | - $req . |
|
| 1550 | - "\n}\n"; |
|
| 1551 | - } |
|
| 1552 | - |
|
| 1553 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1554 | - // retourner False, sinon inserer leur decompilation |
|
| 1555 | - if (is_bool($corps)) { |
|
| 1556 | - return false; |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1339 | + static $trouver_table; |
|
| 1340 | + spip_timer('calcul_skel'); |
|
| 1341 | + |
|
| 1342 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1343 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1344 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1345 | + |
|
| 1346 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1347 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1348 | + } |
|
| 1349 | + } |
|
| 1350 | + foreach ($boucles as $id => $boucle) { |
|
| 1351 | + $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1352 | + } |
|
| 1353 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1354 | + |
|
| 1355 | + // Demander la description des tables une fois pour toutes |
|
| 1356 | + if (!$trouver_table) { |
|
| 1357 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + // reperer si les doublons sont demandes |
|
| 1361 | + // pour un inclure ou une boucle document |
|
| 1362 | + // c'est utile a la fonction champs_traitements |
|
| 1363 | + foreach ($boucles as $id => $boucle) { |
|
| 1364 | + if (!($type = $boucle->type_requete)) { |
|
| 1365 | + continue; |
|
| 1366 | + } |
|
| 1367 | + if (!$descr['documents'] and ( |
|
| 1368 | + (($type == 'documents') and $boucle->doublons) or |
|
| 1369 | + compile_inclure_doublons($boucle->avant) or |
|
| 1370 | + compile_inclure_doublons($boucle->apres) or |
|
| 1371 | + compile_inclure_doublons($boucle->milieu) or |
|
| 1372 | + compile_inclure_doublons($boucle->altern)) |
|
| 1373 | + ) { |
|
| 1374 | + $descr['documents'] = true; |
|
| 1375 | + } |
|
| 1376 | + if ($type != TYPE_RECURSIF) { |
|
| 1377 | + if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1378 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1379 | + } |
|
| 1380 | + |
|
| 1381 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1382 | + if ($g = charger_fonction( |
|
| 1383 | + preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true) |
|
| 1384 | + ) { |
|
| 1385 | + $boucles[$id] = $g($boucle); |
|
| 1386 | + |
|
| 1387 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1388 | + // utiliser les informations donnees par le requeteur |
|
| 1389 | + // cas "php:xx" et "data:xx". |
|
| 1390 | + } else { |
|
| 1391 | + if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1392 | + $requeteur($boucles, $boucle, $id); |
|
| 1393 | + |
|
| 1394 | + // utiliser la description des champs transmis |
|
| 1395 | + } else { |
|
| 1396 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1397 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1398 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1399 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1400 | + if (!$show |
|
| 1401 | + and $show = $trouver_table($type, strtolower($type)) |
|
| 1402 | + ) { |
|
| 1403 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1404 | + } |
|
| 1405 | + if ($show) { |
|
| 1406 | + $boucles[$id]->show = $show; |
|
| 1407 | + // recopie les infos les plus importantes |
|
| 1408 | + $boucles[$id]->primary = isset($show['key']["PRIMARY KEY"]) ? $show['key']["PRIMARY KEY"] : ''; |
|
| 1409 | + $boucles[$id]->id_table = $x = preg_replace(",^spip_,", "", $show['id_table']); |
|
| 1410 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1411 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1412 | + |
|
| 1413 | + if (empty($boucles[$id]->descr)) { |
|
| 1414 | + $boucles[$id]->descr = &$descr; |
|
| 1415 | + } |
|
| 1416 | + if ((!$boucles[$id]->jointures) |
|
| 1417 | + and is_array($show['tables_jointures']) |
|
| 1418 | + and count($x = $show['tables_jointures']) |
|
| 1419 | + ) { |
|
| 1420 | + $boucles[$id]->jointures = $x; |
|
| 1421 | + } |
|
| 1422 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1423 | + $jointures = preg_split("/\s+/", $boucles[$id]->jointures_explicites); |
|
| 1424 | + while ($j = array_pop($jointures)) { |
|
| 1425 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1426 | + } |
|
| 1427 | + } |
|
| 1428 | + } else { |
|
| 1429 | + // Pas une erreur si la table est optionnelle |
|
| 1430 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1431 | + $boucles[$id]->type_requete = ''; |
|
| 1432 | + } else { |
|
| 1433 | + $boucles[$id]->type_requete = false; |
|
| 1434 | + $boucle = $boucles[$id]; |
|
| 1435 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1436 | + ($boucle->sql_serveur . ":")) . |
|
| 1437 | + $type; |
|
| 1438 | + $msg = array( |
|
| 1439 | + 'zbug_table_inconnue', |
|
| 1440 | + array('table' => $x) |
|
| 1441 | + ); |
|
| 1442 | + erreur_squelette($msg, $boucle); |
|
| 1443 | + } |
|
| 1444 | + } |
|
| 1445 | + } |
|
| 1446 | + } |
|
| 1447 | + } |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1451 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1452 | + foreach ($boucles as $id => $boucle) { |
|
| 1453 | + if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1454 | + $boucles[$id]->descr = &$descr; |
|
| 1455 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1456 | + if (!$rec) { |
|
| 1457 | + $msg = array( |
|
| 1458 | + 'zbug_boucle_recursive_undef', |
|
| 1459 | + array('nom' => $boucle->param[0]) |
|
| 1460 | + ); |
|
| 1461 | + erreur_squelette($msg, $boucle); |
|
| 1462 | + $boucles[$id]->type_requete = false; |
|
| 1463 | + } else { |
|
| 1464 | + $rec->externe = $id; |
|
| 1465 | + $descr['id_mere'] = $id; |
|
| 1466 | + $boucles[$id]->return = |
|
| 1467 | + calculer_liste(array($rec), |
|
| 1468 | + $descr, |
|
| 1469 | + $boucles, |
|
| 1470 | + $boucle->param); |
|
| 1471 | + } |
|
| 1472 | + } |
|
| 1473 | + } |
|
| 1474 | + foreach ($boucles as $id => $boucle) { |
|
| 1475 | + $id = strval($id); // attention au type dans index_pile |
|
| 1476 | + $type = $boucle->type_requete; |
|
| 1477 | + if ($type and $type != TYPE_RECURSIF) { |
|
| 1478 | + $res = ''; |
|
| 1479 | + if ($boucle->param) { |
|
| 1480 | + // retourne un tableau en cas d'erreur |
|
| 1481 | + $res = calculer_criteres($id, $boucles); |
|
| 1482 | + } |
|
| 1483 | + $descr['id_mere'] = $id; |
|
| 1484 | + $boucles[$id]->return = |
|
| 1485 | + calculer_liste($boucle->milieu, |
|
| 1486 | + $descr, |
|
| 1487 | + $boucles, |
|
| 1488 | + $id); |
|
| 1489 | + // Si les criteres se sont mal compiles |
|
| 1490 | + // ne pas tenter d'assembler le code final |
|
| 1491 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1492 | + if (is_array($res)) { |
|
| 1493 | + $boucles[$id]->type_requete = false; |
|
| 1494 | + } |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + // idem pour la racine |
|
| 1499 | + $descr['id_mere'] = ''; |
|
| 1500 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1501 | + |
|
| 1502 | + |
|
| 1503 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1504 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1505 | + // de'terminables seulement maintenant |
|
| 1506 | + |
|
| 1507 | + foreach ($boucles as $id => $boucle) { |
|
| 1508 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1509 | + if ($boucle->return === false) { |
|
| 1510 | + $corps = false; |
|
| 1511 | + continue; |
|
| 1512 | + } |
|
| 1513 | + // appeler la fonction de definition de la boucle |
|
| 1514 | + |
|
| 1515 | + if ($req = $boucle->type_requete) { |
|
| 1516 | + // boucle personnalisée ? |
|
| 1517 | + $table = strtoupper($boucle->type_requete); |
|
| 1518 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1519 | + if ( |
|
| 1520 | + // fonction de boucle avec serveur & table |
|
| 1521 | + (!$serveur or |
|
| 1522 | + ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1523 | + and (!function_exists($f = $f . "_dist")) |
|
| 1524 | + ) |
|
| 1525 | + ) |
|
| 1526 | + // fonction de boucle avec table |
|
| 1527 | + and (!function_exists($f = "boucle_" . $table)) |
|
| 1528 | + and (!function_exists($f = $f . "_dist")) |
|
| 1529 | + ) { |
|
| 1530 | + // fonction de boucle standard |
|
| 1531 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1532 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1533 | + } |
|
| 1534 | + } |
|
| 1535 | + |
|
| 1536 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1537 | + "static \$connect;\n\t" . |
|
| 1538 | + "\$command['connect'] = \$connect = " . |
|
| 1539 | + _q($boucle->sql_serveur) . |
|
| 1540 | + ";" . |
|
| 1541 | + $f($id, $boucles); |
|
| 1542 | + } else { |
|
| 1543 | + $req = ("\n\treturn '';"); |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + $boucles[$id]->return = |
|
| 1547 | + "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1548 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1549 | + $req . |
|
| 1550 | + "\n}\n"; |
|
| 1551 | + } |
|
| 1552 | + |
|
| 1553 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1554 | + // retourner False, sinon inserer leur decompilation |
|
| 1555 | + if (is_bool($corps)) { |
|
| 1556 | + return false; |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1560 | 1560 | ' |
| 1561 | - // reporter de maniere securisee les doublons inclus |
|
| 1562 | - . ' |
|
| 1561 | + // reporter de maniere securisee les doublons inclus |
|
| 1562 | + . ' |
|
| 1563 | 1563 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1564 | 1564 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1565 | 1565 | |
| 1566 | 1566 | $connect = ' . |
| 1567 | - _q($connect) . '; |
|
| 1567 | + _q($connect) . '; |
|
| 1568 | 1568 | $page = ' . |
| 1569 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1570 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1571 | - // avant de referencer $Cache |
|
| 1572 | - $corps . "; |
|
| 1569 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1570 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1571 | + // avant de referencer $Cache |
|
| 1572 | + $corps . "; |
|
| 1573 | 1573 | |
| 1574 | 1574 | return analyse_resultat_skel(" . var_export($nom, true) |
| 1575 | - . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1575 | + . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1576 | 1576 | }"; |
| 1577 | 1577 | |
| 1578 | - $secondes = spip_timer('calcul_skel'); |
|
| 1579 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1580 | - // $connect n'est pas sûr : on nettoie |
|
| 1581 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1578 | + $secondes = spip_timer('calcul_skel'); |
|
| 1579 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1580 | + // $connect n'est pas sûr : on nettoie |
|
| 1581 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1582 | 1582 | |
| 1583 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1584 | - $code = new Boucle; |
|
| 1585 | - $code->descr = $descr; |
|
| 1586 | - $code->return = ' |
|
| 1583 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1584 | + $code = new Boucle; |
|
| 1585 | + $code->descr = $descr; |
|
| 1586 | + $code->return = ' |
|
| 1587 | 1587 | // |
| 1588 | 1588 | // Fonction principale du squelette ' . |
| 1589 | - $sourcefile . |
|
| 1590 | - ($connect ? " pour $connect" : '') . |
|
| 1591 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1592 | - "\n//\n" . |
|
| 1593 | - $principal; |
|
| 1589 | + $sourcefile . |
|
| 1590 | + ($connect ? " pour $connect" : '') . |
|
| 1591 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1592 | + "\n//\n" . |
|
| 1593 | + $principal; |
|
| 1594 | 1594 | |
| 1595 | - $boucles[''] = $code; |
|
| 1595 | + $boucles[''] = $code; |
|
| 1596 | 1596 | |
| 1597 | - return $boucles; |
|
| 1597 | + return $boucles; |
|
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | 1600 | |
@@ -1611,18 +1611,18 @@ discard block |
||
| 1611 | 1611 | * |
| 1612 | 1612 | **/ |
| 1613 | 1613 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1614 | - if (class_exists($boucle->type_requete)) { |
|
| 1615 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1616 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1617 | - } else { |
|
| 1618 | - $x = $boucle->type_requete; |
|
| 1619 | - $boucle->type_requete = false; |
|
| 1620 | - $msg = array( |
|
| 1621 | - 'zbug_iterateur_inconnu', |
|
| 1622 | - array('iterateur' => $x) |
|
| 1623 | - ); |
|
| 1624 | - erreur_squelette($msg, $boucle); |
|
| 1625 | - } |
|
| 1614 | + if (class_exists($boucle->type_requete)) { |
|
| 1615 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1616 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1617 | + } else { |
|
| 1618 | + $x = $boucle->type_requete; |
|
| 1619 | + $boucle->type_requete = false; |
|
| 1620 | + $msg = array( |
|
| 1621 | + 'zbug_iterateur_inconnu', |
|
| 1622 | + array('iterateur' => $x) |
|
| 1623 | + ); |
|
| 1624 | + erreur_squelette($msg, $boucle); |
|
| 1625 | + } |
|
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | |
@@ -1640,23 +1640,23 @@ discard block |
||
| 1640 | 1640 | * |
| 1641 | 1641 | **/ |
| 1642 | 1642 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1643 | - include_spip('iterateur/data'); |
|
| 1644 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1645 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1646 | - $boucles[$id] = $g($boucle); |
|
| 1647 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1648 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1649 | - |
|
| 1650 | - } else { |
|
| 1651 | - $x = $boucle->type_requete; |
|
| 1652 | - $boucle->type_requete = false; |
|
| 1653 | - $msg = array( |
|
| 1654 | - 'zbug_requeteur_inconnu', |
|
| 1655 | - array( |
|
| 1656 | - 'requeteur' => 'data', |
|
| 1657 | - 'type' => $x |
|
| 1658 | - ) |
|
| 1659 | - ); |
|
| 1660 | - erreur_squelette($msg, $boucle); |
|
| 1661 | - } |
|
| 1643 | + include_spip('iterateur/data'); |
|
| 1644 | + if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1645 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1646 | + $boucles[$id] = $g($boucle); |
|
| 1647 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1648 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1649 | + |
|
| 1650 | + } else { |
|
| 1651 | + $x = $boucle->type_requete; |
|
| 1652 | + $boucle->type_requete = false; |
|
| 1653 | + $msg = array( |
|
| 1654 | + 'zbug_requeteur_inconnu', |
|
| 1655 | + array( |
|
| 1656 | + 'requeteur' => 'data', |
|
| 1657 | + 'type' => $x |
|
| 1658 | + ) |
|
| 1659 | + ); |
|
| 1660 | + erreur_squelette($msg, $boucle); |
|
| 1661 | + } |
|
| 1662 | 1662 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
| 98 | 98 | $m = array_pad($m, 3, null); |
| 99 | 99 | $var = $m[1]; |
| 100 | - $auto = false;; |
|
| 100 | + $auto = false; ; |
|
| 101 | 101 | if ($m[2]) { |
| 102 | 102 | $v = $m[3]; |
| 103 | 103 | if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
@@ -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 | |
| 176 | 176 | } else { |
| 177 | 177 | $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | return false; |
| 214 | 214 | } // j'aurais voulu toucher le fond ... |
| 215 | 215 | |
| 216 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 216 | + $contexte = 'array('.$_contexte.')'; |
|
| 217 | 217 | |
| 218 | 218 | if ($env) { |
| 219 | 219 | $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
@@ -228,11 +228,11 @@ discard block |
||
| 228 | 228 | $_options[] = $ajax; |
| 229 | 229 | } |
| 230 | 230 | $code = " ' . argumenter_squelette($code) . '"; |
| 231 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | - "_request(\"connect\")") . ';'; |
|
| 231 | + $code = "echo ".sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | + "_request(\"connect\")").';'; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; |
|
| 235 | + return "\n'<'.'"."?php ".$code."\n?'."."'>'"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -312,17 +312,17 @@ discard block |
||
| 312 | 312 | $id = $id_table; |
| 313 | 313 | $statut = preg_replace(',\W,', '', $s['champ']); // securite |
| 314 | 314 | } |
| 315 | - $mstatut = $id . '.' . $statut; |
|
| 315 | + $mstatut = $id.'.'.$statut; |
|
| 316 | 316 | |
| 317 | 317 | $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
| 318 | 318 | include_spip('public/quete'); |
| 319 | 319 | if (isset($s['post_date']) and $s['post_date'] |
| 320 | 320 | and $GLOBALS['meta']["post_dates"] == 'non' |
| 321 | 321 | ) { |
| 322 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 322 | + $date = $id.'.'.preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | 323 | array_unshift($boucle->where, |
| 324 | 324 | $echapper ? |
| 325 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 325 | + "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 326 | 326 | : |
| 327 | 327 | quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
| 328 | 328 | ); |
@@ -330,9 +330,9 @@ discard block |
||
| 330 | 330 | array_unshift($boucle->where, |
| 331 | 331 | $echapper ? |
| 332 | 332 | "\nquete_condition_statut('$mstatut'," |
| 333 | - . _q($s['previsu']) . "," |
|
| 334 | - . _q($s['publie']) . "," |
|
| 335 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 333 | + . _q($s['previsu'])."," |
|
| 334 | + . _q($s['publie'])."," |
|
| 335 | + . _q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 336 | 336 | : |
| 337 | 337 | quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
| 338 | 338 | ); |
@@ -366,14 +366,14 @@ discard block |
||
| 366 | 366 | if (_request('var_mode_affiche') != 'resultat') { |
| 367 | 367 | $trace = ''; |
| 368 | 368 | } else { |
| 369 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 369 | + $_trace = $boucles[$id_boucle]->descr['nom'].$id_boucle; |
|
| 370 | 370 | $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
| 371 | 371 | $trace = " |
| 372 | 372 | if (empty($_trace)) { |
| 373 | 373 | $_trace = []; |
| 374 | 374 | } |
| 375 | 375 | if (count($_trace) < 3) { |
| 376 | - $_trace" . "[] = \$t0; |
|
| 376 | + $_trace"."[] = \$t0; |
|
| 377 | 377 | }"; |
| 378 | 378 | } |
| 379 | 379 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | return |
| 408 | 408 | // Numrows[$nom] peut ne pas être encore defini |
| 409 | 409 | "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
| 410 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 410 | + . "\n\t\$t0 = ".$boucles[$id_boucle]->return.";" |
|
| 411 | 411 | . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
| 412 | 412 | . $trace |
| 413 | 413 | . "\n\treturn \$t0;"; |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
| 476 | 476 | // et puis faire un [] plutot qu'un "','." |
| 477 | 477 | if ($boucle->doublons) { |
| 478 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 478 | + $corps .= "\n\t\t\tforeach(".$boucle->doublons.' as $k) $doublons[$k] .= "," . '. |
|
| 479 | 479 | index_pile($id_boucle, $primary, $boucles) |
| 480 | 480 | . "; // doublons\n"; |
| 481 | 481 | } |
@@ -502,13 +502,13 @@ discard block |
||
| 502 | 502 | $corps .= |
| 503 | 503 | "\n\t\tlang_select_public(" |
| 504 | 504 | . index_pile($id_boucle, 'lang', $boucles) |
| 505 | - . ", '" . $boucle->lang_select . "'" |
|
| 505 | + . ", '".$boucle->lang_select."'" |
|
| 506 | 506 | . (in_array($type_boucle, array( |
| 507 | 507 | 'articles', |
| 508 | 508 | 'rubriques', |
| 509 | 509 | 'hierarchie', |
| 510 | 510 | 'breves' |
| 511 | - )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 511 | + )) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 512 | 512 | . ');'; |
| 513 | 513 | } else { |
| 514 | 514 | $init_lang = ''; |
@@ -529,26 +529,22 @@ discard block |
||
| 529 | 529 | |
| 530 | 530 | // gestion optimale des separateurs et des boucles constantes |
| 531 | 531 | if (count($boucle->separateur)) { |
| 532 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 532 | + $code_sep = ("'".str_replace("'", "\'", join('', $boucle->separateur))."'"); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | $corps .= |
| 536 | 536 | ((!$boucle->separateur) ? |
| 537 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 538 | - (($return === "''") ? '' : |
|
| 539 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 540 | - ("\n\t\t\$t1 " . |
|
| 537 | + (($constant && !$corps && !$flag_cpt) ? $return : (($return === "''") ? '' : ("\n\t\t".'$t0 .= '.$return.";"))) : ("\n\t\t\$t1 ". |
|
| 541 | 538 | ((strpos($return, '$t1.') === 0) ? |
| 542 | - (".=" . substr($return, 4)) : |
|
| 543 | - ('= ' . $return)) . |
|
| 544 | - ";\n\t\t" . |
|
| 545 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 539 | + (".=".substr($return, 4)) : ('= '.$return)). |
|
| 540 | + ";\n\t\t". |
|
| 541 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? '.$code_sep." : '') . \$t1;")); |
|
| 546 | 542 | |
| 547 | 543 | // Calculer les invalideurs si c'est une boucle non constante et si on |
| 548 | 544 | // souhaite invalider ces elements |
| 549 | 545 | if (!$constant and $primary) { |
| 550 | 546 | include_spip('inc/invalideur'); |
| 551 | - $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 547 | + $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 552 | 548 | } |
| 553 | 549 | |
| 554 | 550 | // gerer le compteur de boucle |
@@ -622,7 +618,7 @@ discard block |
||
| 622 | 618 | $corps, |
| 623 | 619 | $fin_lang, |
| 624 | 620 | $trace, |
| 625 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 621 | + 'BOUCLE'.$id_boucle.' @ '.($boucle->descr['sourcefile']) |
|
| 626 | 622 | ); |
| 627 | 623 | |
| 628 | 624 | # var_dump($a);exit; |
@@ -643,20 +639,20 @@ discard block |
||
| 643 | 639 | **/ |
| 644 | 640 | function calculer_requete_sql($boucle) { |
| 645 | 641 | $init = array(); |
| 646 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 647 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 642 | + $init[] = calculer_dec('table', "'".$boucle->id_table."'"); |
|
| 643 | + $init[] = calculer_dec('id', "'".$boucle->id_boucle."'"); |
|
| 648 | 644 | # En absence de champ c'est un decompte : |
| 649 | 645 | $init[] = calculer_dec('from', calculer_from($boucle)); |
| 650 | 646 | $init[] = calculer_dec('type', calculer_from_type($boucle)); |
| 651 | 647 | $init[] = calculer_dec('groupby', |
| 652 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 653 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 654 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 648 | + 'array('.(($g = join("\",\n\t\t\"", $boucle->group)) ? '"'.$g.'"' : '').")"); |
|
| 649 | + $init[] = calculer_dec('select', 'array("'.join("\",\n\t\t\"", $boucle->select)."\")"); |
|
| 650 | + $init[] = calculer_dec('orderby', 'array('.calculer_order($boucle).")"); |
|
| 655 | 651 | $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
| 656 | 652 | $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
| 657 | 653 | $init[] = calculer_dec('limit', |
| 658 | 654 | (strpos($boucle->limit, 'intval') === false ? |
| 659 | - "'" . $boucle->limit . "'" |
|
| 655 | + "'".$boucle->limit."'" |
|
| 660 | 656 | : |
| 661 | 657 | $boucle->limit)); |
| 662 | 658 | $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
@@ -665,17 +661,17 @@ discard block |
||
| 665 | 661 | // ou recalculée à chaque passage (vide) |
| 666 | 662 | foreach ($init as $i) { |
| 667 | 663 | if (reset($i)) { |
| 668 | - $s .= "\n\t\t" . end($i); |
|
| 664 | + $s .= "\n\t\t".end($i); |
|
| 669 | 665 | } # statique |
| 670 | 666 | else { |
| 671 | - $d .= "\n\t" . end($i); |
|
| 667 | + $d .= "\n\t".end($i); |
|
| 672 | 668 | } # dynamique |
| 673 | 669 | } |
| 674 | 670 | |
| 675 | 671 | return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
| 676 | 672 | . $boucle->in |
| 677 | 673 | . $boucle->hash |
| 678 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 674 | + . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 679 | 675 | . $s |
| 680 | 676 | . "\n\t}" |
| 681 | 677 | . $d; |
@@ -758,7 +754,7 @@ discard block |
||
| 758 | 754 | * - index 1 : Code de l'affectation |
| 759 | 755 | **/ |
| 760 | 756 | function calculer_dec($nom, $val) { |
| 761 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 757 | + $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 762 | 758 | // si une variable apparait dans le calcul de la clause |
| 763 | 759 | // il faut la re-evaluer a chaque passage |
| 764 | 760 | if ( |
@@ -775,7 +771,7 @@ discard block |
||
| 775 | 771 | $static = ""; |
| 776 | 772 | } |
| 777 | 773 | |
| 778 | - return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 774 | + return array($static, '$command[\''.$nom.'\'] = '.$val.';'); |
|
| 779 | 775 | } |
| 780 | 776 | |
| 781 | 777 | /** |
@@ -800,16 +796,16 @@ discard block |
||
| 800 | 796 | } |
| 801 | 797 | $res = ""; |
| 802 | 798 | if ($a and $a[0] == "'?'") { |
| 803 | - return ("(" . calculer_dump_array($a[1]) . |
|
| 804 | - " ? " . calculer_dump_array($a[2]) . |
|
| 805 | - " : " . calculer_dump_array($a[3]) . |
|
| 799 | + return ("(".calculer_dump_array($a[1]). |
|
| 800 | + " ? ".calculer_dump_array($a[2]). |
|
| 801 | + " : ".calculer_dump_array($a[3]). |
|
| 806 | 802 | ")"); |
| 807 | 803 | } else { |
| 808 | 804 | foreach ($a as $v) { |
| 809 | - $res .= ", " . calculer_dump_array($v); |
|
| 805 | + $res .= ", ".calculer_dump_array($v); |
|
| 810 | 806 | } |
| 811 | 807 | |
| 812 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 808 | + return "\n\t\t\tarray(".substr($res, 2).')'; |
|
| 813 | 809 | } |
| 814 | 810 | } |
| 815 | 811 | |
@@ -817,10 +813,10 @@ discard block |
||
| 817 | 813 | function calculer_dump_join($a) { |
| 818 | 814 | $res = ""; |
| 819 | 815 | foreach ($a as $k => $v) { |
| 820 | - $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 816 | + $res .= ", '$k' => array(".implode(',', $v).")"; |
|
| 821 | 817 | } |
| 822 | 818 | |
| 823 | - return 'array(' . substr($res, 2) . ')'; |
|
| 819 | + return 'array('.substr($res, 2).')'; |
|
| 824 | 820 | } |
| 825 | 821 | |
| 826 | 822 | /** |
@@ -837,7 +833,7 @@ discard block |
||
| 837 | 833 | $res .= ",'$k' => '$v'"; |
| 838 | 834 | } |
| 839 | 835 | |
| 840 | - return 'array(' . substr($res, 1) . ')'; |
|
| 836 | + return 'array('.substr($res, 1).')'; |
|
| 841 | 837 | } |
| 842 | 838 | |
| 843 | 839 | /** |
@@ -855,7 +851,7 @@ discard block |
||
| 855 | 851 | $res .= ",'$k' => '$v'"; |
| 856 | 852 | } |
| 857 | 853 | |
| 858 | - return 'array(' . substr($res, 1) . ')'; |
|
| 854 | + return 'array('.substr($res, 1).')'; |
|
| 859 | 855 | } |
| 860 | 856 | |
| 861 | 857 | // https://code.spip.net/@calculer_order |
@@ -924,17 +920,17 @@ discard block |
||
| 924 | 920 | ) { |
| 925 | 921 | $res .= " .\n$tab$code"; |
| 926 | 922 | } else { |
| 927 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 923 | + $res = substr($res, 0, -1).substr($code, 1); |
|
| 928 | 924 | } |
| 929 | 925 | } |
| 930 | 926 | |
| 931 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 927 | + return '('.substr($res, 2 + $descr['niv']).')'; |
|
| 932 | 928 | } |
| 933 | 929 | } else { |
| 934 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 930 | + $nom = $descr['nom'].$id_boucle.($descr['niv'] ? $descr['niv'] : ''); |
|
| 935 | 931 | |
| 936 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 937 | - $codes) . ")))"; |
|
| 932 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(".join(" ,\n$tab", |
|
| 933 | + $codes).")))"; |
|
| 938 | 934 | } |
| 939 | 935 | } |
| 940 | 936 | |
@@ -963,7 +959,7 @@ discard block |
||
| 963 | 959 | // texte seul |
| 964 | 960 | case 'texte': |
| 965 | 961 | $code = sandbox_composer_texte($p->texte, $p); |
| 966 | - $commentaire = strlen($p->texte) . " signes"; |
|
| 962 | + $commentaire = strlen($p->texte)." signes"; |
|
| 967 | 963 | $avant = ''; |
| 968 | 964 | $apres = ''; |
| 969 | 965 | $altern = "''"; |
@@ -972,14 +968,14 @@ discard block |
||
| 972 | 968 | case 'polyglotte': |
| 973 | 969 | $code = ""; |
| 974 | 970 | foreach ($p->traductions as $k => $v) { |
| 975 | - $code .= ",'" . |
|
| 976 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 977 | - "' => '" . |
|
| 978 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 971 | + $code .= ",'". |
|
| 972 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $k). |
|
| 973 | + "' => '". |
|
| 974 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $v). |
|
| 979 | 975 | "'"; |
| 980 | 976 | } |
| 981 | - $code = "choisir_traduction(array(" . |
|
| 982 | - substr($code, 1) . |
|
| 977 | + $code = "choisir_traduction(array(". |
|
| 978 | + substr($code, 1). |
|
| 983 | 979 | "))"; |
| 984 | 980 | $commentaire = '&'; |
| 985 | 981 | $avant = ''; |
@@ -995,7 +991,7 @@ discard block |
||
| 995 | 991 | $err_e_c = true; |
| 996 | 992 | $code = "''"; |
| 997 | 993 | } else { |
| 998 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 994 | + $commentaire = '<INCLURE '.addslashes(str_replace("\n", ' ', $code)).'>'; |
|
| 999 | 995 | $avant = ''; |
| 1000 | 996 | $apres = ''; |
| 1001 | 997 | $altern = "''"; |
@@ -1022,8 +1018,8 @@ discard block |
||
| 1022 | 1018 | $err_e_c = true; |
| 1023 | 1019 | $code = "''"; |
| 1024 | 1020 | } else { |
| 1025 | - $code = 'BOUCLE' . |
|
| 1026 | - str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 1021 | + $code = 'BOUCLE'. |
|
| 1022 | + str_replace("-", "_", $nom).$descr['nom']. |
|
| 1027 | 1023 | '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
| 1028 | 1024 | $commentaire = "?$nom"; |
| 1029 | 1025 | if (!$boucles[$nom]->milieu |
@@ -1064,24 +1060,22 @@ discard block |
||
| 1064 | 1060 | foreach ($p->arg as $k => $v) { |
| 1065 | 1061 | $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
| 1066 | 1062 | if ($k) { |
| 1067 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1063 | + $l[] = _q($k).' => '.$_v; |
|
| 1068 | 1064 | } else { |
| 1069 | 1065 | $code = $_v; |
| 1070 | 1066 | } |
| 1071 | 1067 | } |
| 1072 | 1068 | // Si le module n'est pas fourni, l'expliciter sauf si calculé |
| 1073 | 1069 | if ($p->module) { |
| 1074 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1070 | + $m = $p->module.':'.$p->nom_champ; |
|
| 1075 | 1071 | } elseif ($p->nom_champ) { |
| 1076 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1072 | + $m = MODULES_IDIOMES.':'.$p->nom_champ; |
|
| 1077 | 1073 | } else { |
| 1078 | 1074 | $m = ''; |
| 1079 | 1075 | } |
| 1080 | 1076 | |
| 1081 | - $code = (!$code ? "'$m'" : |
|
| 1082 | - ($m ? "'$m' . $code" : |
|
| 1083 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1084 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1077 | + $code = (!$code ? "'$m'" : ($m ? "'$m' . $code" : ("(strpos(\$x=$code, ':') ? \$x : ('".MODULES_IDIOMES.":' . \$x))"))) |
|
| 1078 | + . (!$l ? '' : (", array(".implode(",\n", $l).")")); |
|
| 1085 | 1079 | $code = "_T($code)"; |
| 1086 | 1080 | if ($p->param) { |
| 1087 | 1081 | $p->id_boucle = $id_boucle; |
@@ -1104,7 +1098,7 @@ discard block |
||
| 1104 | 1098 | $p->type_requete = $type; |
| 1105 | 1099 | |
| 1106 | 1100 | $code = calculer_champ($p); |
| 1107 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1101 | + $commentaire = '#'.$p->nom_champ.$p->etoile; |
|
| 1108 | 1102 | $avant = calculer_liste($p->avant, |
| 1109 | 1103 | $descr, $boucles, $id_boucle); |
| 1110 | 1104 | $apres = calculer_liste($p->apres, |
@@ -1135,10 +1129,9 @@ discard block |
||
| 1135 | 1129 | if ($code != "''") { |
| 1136 | 1130 | $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
| 1137 | 1131 | $codes[] = (($mode == 'validation') ? |
| 1138 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1132 | + "array($code, '$commentaire', ".$p->ligne.")" |
|
| 1139 | 1133 | : (($mode == 'code') ? |
| 1140 | - "\n// $commentaire\n$code" : |
|
| 1141 | - $code)); |
|
| 1134 | + "\n// $commentaire\n$code" : $code)); |
|
| 1142 | 1135 | } |
| 1143 | 1136 | } // foreach |
| 1144 | 1137 | |
@@ -1189,28 +1182,28 @@ discard block |
||
| 1189 | 1182 | if ($apres === "''") { |
| 1190 | 1183 | $apres = ''; |
| 1191 | 1184 | } |
| 1192 | - if ($avant or $apres or ($altern !== "''")){ |
|
| 1193 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)){ |
|
| 1185 | + if ($avant or $apres or ($altern !== "''")) { |
|
| 1186 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1194 | 1187 | $t = $code; |
| 1195 | 1188 | $cond = ''; |
| 1196 | 1189 | } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
| 1197 | 1190 | $t = $r[2]; |
| 1198 | - $cond = '!' . $r[1]; |
|
| 1191 | + $cond = '!'.$r[1]; |
|
| 1199 | 1192 | } else { |
| 1200 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)){ |
|
| 1193 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1201 | 1194 | $t = $r[2]; |
| 1202 | 1195 | $cond = $r[1]; |
| 1203 | 1196 | } else { |
| 1204 | - $t = '$t' . $n; |
|
| 1197 | + $t = '$t'.$n; |
|
| 1205 | 1198 | $cond = "($t = $code)!==''"; |
| 1206 | 1199 | } |
| 1207 | 1200 | } |
| 1208 | 1201 | |
| 1209 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 1210 | - $t . |
|
| 1202 | + $res = (!$avant ? "" : "$avant . "). |
|
| 1203 | + $t. |
|
| 1211 | 1204 | (!$apres ? "" : " . $apres"); |
| 1212 | 1205 | |
| 1213 | - if ($res!==$t){ |
|
| 1206 | + if ($res !== $t) { |
|
| 1214 | 1207 | $res = "($res)"; |
| 1215 | 1208 | } |
| 1216 | 1209 | |
@@ -1260,12 +1253,12 @@ discard block |
||
| 1260 | 1253 | |
| 1261 | 1254 | // rendre inertes les echappements de #[](){}<> |
| 1262 | 1255 | $i = 0; |
| 1263 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1256 | + while (false !== strpos($squelette, $inerte = '-INERTE'.$i)) { |
|
| 1264 | 1257 | $i++; |
| 1265 | 1258 | } |
| 1266 | 1259 | $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
| 1267 | 1260 | function($a) use ($inerte) { |
| 1268 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1261 | + return "$inerte-".ord($a[1]).'-'; |
|
| 1269 | 1262 | }, |
| 1270 | 1263 | $squelette, |
| 1271 | 1264 | -1, |
@@ -1282,7 +1275,7 @@ discard block |
||
| 1282 | 1275 | // Phraser le squelette, selon sa grammaire |
| 1283 | 1276 | |
| 1284 | 1277 | $boucles = array(); |
| 1285 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1278 | + $f = charger_fonction('phraser_'.$gram, 'public'); |
|
| 1286 | 1279 | |
| 1287 | 1280 | $squelette = $f($squelette, '', $boucles, $descr); |
| 1288 | 1281 | |
@@ -1301,7 +1294,7 @@ discard block |
||
| 1301 | 1294 | $boucles[$i]->descr['squelette'] = preg_replace_callback( |
| 1302 | 1295 | ",$inerte-(\d+)-,", |
| 1303 | 1296 | function($a) { |
| 1304 | - return "\\\\" . chr($a[1]); |
|
| 1297 | + return "\\\\".chr($a[1]); |
|
| 1305 | 1298 | }, |
| 1306 | 1299 | $boucle->descr['squelette'] |
| 1307 | 1300 | ); |
@@ -1313,19 +1306,19 @@ discard block |
||
| 1313 | 1306 | include_spip('public/decompiler'); |
| 1314 | 1307 | foreach ($boucles as $id => $boucle) { |
| 1315 | 1308 | if ($id) { |
| 1316 | - $decomp = "\n/* BOUCLE " . |
|
| 1317 | - $boucle->type_requete . |
|
| 1318 | - " " . |
|
| 1319 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1320 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1309 | + $decomp = "\n/* BOUCLE ". |
|
| 1310 | + $boucle->type_requete. |
|
| 1311 | + " ". |
|
| 1312 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')). |
|
| 1313 | + ($boucle->debug ? "\n *\n * ".implode("\n * ", $boucle->debug)."\n" : ''). |
|
| 1321 | 1314 | " */\n"; |
| 1322 | 1315 | } else { |
| 1323 | - $decomp = ("\n/*\n" . |
|
| 1316 | + $decomp = ("\n/*\n". |
|
| 1324 | 1317 | str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
| 1325 | 1318 | . "\n*/"); |
| 1326 | 1319 | } |
| 1327 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1328 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1320 | + $boucles[$id]->return = $decomp.$boucle->return; |
|
| 1321 | + $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1329 | 1322 | } |
| 1330 | 1323 | } |
| 1331 | 1324 | |
@@ -1348,7 +1341,7 @@ discard block |
||
| 1348 | 1341 | } |
| 1349 | 1342 | } |
| 1350 | 1343 | foreach ($boucles as $id => $boucle) { |
| 1351 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1344 | + $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1352 | 1345 | } |
| 1353 | 1346 | $descr['documents'] = compile_inclure_doublons($squelette); |
| 1354 | 1347 | |
@@ -1432,8 +1425,7 @@ discard block |
||
| 1432 | 1425 | } else { |
| 1433 | 1426 | $boucles[$id]->type_requete = false; |
| 1434 | 1427 | $boucle = $boucles[$id]; |
| 1435 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1436 | - ($boucle->sql_serveur . ":")) . |
|
| 1428 | + $x = (!$boucle->sql_serveur ? '' : ($boucle->sql_serveur.":")). |
|
| 1437 | 1429 | $type; |
| 1438 | 1430 | $msg = array( |
| 1439 | 1431 | 'zbug_table_inconnue', |
@@ -1519,13 +1511,13 @@ discard block |
||
| 1519 | 1511 | if ( |
| 1520 | 1512 | // fonction de boucle avec serveur & table |
| 1521 | 1513 | (!$serveur or |
| 1522 | - ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1523 | - and (!function_exists($f = $f . "_dist")) |
|
| 1514 | + ((!function_exists($f = "boucle_".$serveur."_".$table)) |
|
| 1515 | + and (!function_exists($f = $f."_dist")) |
|
| 1524 | 1516 | ) |
| 1525 | 1517 | ) |
| 1526 | 1518 | // fonction de boucle avec table |
| 1527 | - and (!function_exists($f = "boucle_" . $table)) |
|
| 1528 | - and (!function_exists($f = $f . "_dist")) |
|
| 1519 | + and (!function_exists($f = "boucle_".$table)) |
|
| 1520 | + and (!function_exists($f = $f."_dist")) |
|
| 1529 | 1521 | ) { |
| 1530 | 1522 | // fonction de boucle standard |
| 1531 | 1523 | if (!function_exists($f = 'boucle_DEFAUT')) { |
@@ -1533,20 +1525,20 @@ discard block |
||
| 1533 | 1525 | } |
| 1534 | 1526 | } |
| 1535 | 1527 | |
| 1536 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1537 | - "static \$connect;\n\t" . |
|
| 1538 | - "\$command['connect'] = \$connect = " . |
|
| 1539 | - _q($boucle->sql_serveur) . |
|
| 1540 | - ";" . |
|
| 1528 | + $req = "\n\n\tstatic \$command = array();\n\t". |
|
| 1529 | + "static \$connect;\n\t". |
|
| 1530 | + "\$command['connect'] = \$connect = ". |
|
| 1531 | + _q($boucle->sql_serveur). |
|
| 1532 | + ";". |
|
| 1541 | 1533 | $f($id, $boucles); |
| 1542 | 1534 | } else { |
| 1543 | 1535 | $req = ("\n\treturn '';"); |
| 1544 | 1536 | } |
| 1545 | 1537 | |
| 1546 | 1538 | $boucles[$id]->return = |
| 1547 | - "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1548 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1549 | - $req . |
|
| 1539 | + "\n\nfunction BOUCLE".strtr($id, "-", "_").$nom. |
|
| 1540 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {'. |
|
| 1541 | + $req. |
|
| 1550 | 1542 | "\n}\n"; |
| 1551 | 1543 | } |
| 1552 | 1544 | |
@@ -1556,7 +1548,7 @@ discard block |
||
| 1556 | 1548 | return false; |
| 1557 | 1549 | } |
| 1558 | 1550 | |
| 1559 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1551 | + $principal = "\nfunction ".$nom.'($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1560 | 1552 | ' |
| 1561 | 1553 | // reporter de maniere securisee les doublons inclus |
| 1562 | 1554 | . ' |
@@ -1564,15 +1556,15 @@ discard block |
||
| 1564 | 1556 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1565 | 1557 | |
| 1566 | 1558 | $connect = ' . |
| 1567 | - _q($connect) . '; |
|
| 1559 | + _q($connect).'; |
|
| 1568 | 1560 | $page = ' . |
| 1569 | 1561 | // ATTENTION, le calcul de l'expression $corps affectera $Cache |
| 1570 | 1562 | // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
| 1571 | 1563 | // avant de referencer $Cache |
| 1572 | - $corps . "; |
|
| 1564 | + $corps."; |
|
| 1573 | 1565 | |
| 1574 | 1566 | return analyse_resultat_skel(" . var_export($nom, true) |
| 1575 | - . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1567 | + . ", \$Cache, \$page, ".var_export($sourcefile, true)."); |
|
| 1576 | 1568 | }"; |
| 1577 | 1569 | |
| 1578 | 1570 | $secondes = spip_timer('calcul_skel'); |
@@ -1586,10 +1578,10 @@ discard block |
||
| 1586 | 1578 | $code->return = ' |
| 1587 | 1579 | // |
| 1588 | 1580 | // Fonction principale du squelette ' . |
| 1589 | - $sourcefile . |
|
| 1590 | - ($connect ? " pour $connect" : '') . |
|
| 1591 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1592 | - "\n//\n" . |
|
| 1581 | + $sourcefile. |
|
| 1582 | + ($connect ? " pour $connect" : ''). |
|
| 1583 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes"). |
|
| 1584 | + "\n//\n". |
|
| 1593 | 1585 | $principal; |
| 1594 | 1586 | |
| 1595 | 1587 | $boucles[''] = $code; |
@@ -1641,7 +1633,7 @@ discard block |
||
| 1641 | 1633 | **/ |
| 1642 | 1634 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1643 | 1635 | include_spip('iterateur/data'); |
| 1644 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1636 | + if ($h = charger_fonction($boucle->type_requete.'_to_array', 'inc', true)) { |
|
| 1645 | 1637 | $g = charger_fonction('data', 'iterateur'); |
| 1646 | 1638 | $boucles[$id] = $g($boucle); |
| 1647 | 1639 | // from[0] stocke le type de data (rss, yql, ...) |
@@ -148,6 +148,10 @@ discard block |
||
| 148 | 148 | return $nom ? $nom : false; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | +/** |
|
| 152 | + * @param string $squelette |
|
| 153 | + * @param string $phpfile |
|
| 154 | + */ |
|
| 151 | 155 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 152 | 156 | |
| 153 | 157 | // Le dernier index est '' (fonction principale) |
@@ -172,6 +176,9 @@ discard block |
||
| 172 | 176 | |
| 173 | 177 | // Le squelette compile est-il trop vieux ? |
| 174 | 178 | // https://code.spip.net/@squelette_obsolete |
| 179 | +/** |
|
| 180 | + * @param string $skel |
|
| 181 | + */ |
|
| 175 | 182 | function squelette_obsolete($skel, $squelette) { |
| 176 | 183 | static $date_change = null; |
| 177 | 184 | // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte'); |
@@ -43,239 +43,239 @@ discard block |
||
| 43 | 43 | // https://code.spip.net/@public_composer_dist |
| 44 | 44 | function public_composer_dist($squelette, $mime_type, $gram, $source, $connect = '') { |
| 45 | 45 | |
| 46 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | - |
|
| 48 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | - if (function_exists($nom)) { |
|
| 50 | - return $nom; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | - |
|
| 59 | - // si squelette est deja compile et perenne, le charger |
|
| 60 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | - include_once $phpfile; |
|
| 62 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | - ## eval('?'.'>'.$skel_code); |
|
| 66 | - # spip_log($skel_code, 'comp') |
|
| 67 | - #} |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | - include_once $lib; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | - |
|
| 76 | - if (function_exists($nom)) { |
|
| 77 | - return $nom; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // charger le source, si possible, et compiler |
|
| 81 | - $skel_code = ''; |
|
| 82 | - if (lire_fichier($source, $skel)) { |
|
| 83 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | - if (!$skel_code) { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - foreach ($skel_code as $id => $boucle) { |
|
| 93 | - $f = $boucle->return; |
|
| 94 | - try { |
|
| 95 | - // @todo : a remplacer quand _PHP_MIN >= 7 |
|
| 96 | - // eval("return true; $f ;"); |
|
| 97 | - // PHP 5.x compat |
|
| 98 | - if ($ok = @eval("return true; $f ;") === false) { |
|
| 99 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 100 | - $msg = _T('zbug_erreur_compilation'); |
|
| 101 | - erreur_squelette($msg, $boucle); |
|
| 102 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 103 | - // mais prevenir que c'est mort |
|
| 104 | - $nom = ''; |
|
| 105 | - } |
|
| 106 | - } catch (\ParseError $e) { |
|
| 107 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 108 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 109 | - erreur_squelette($msg, $boucle); |
|
| 110 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 111 | - // mais prevenir que c'est mort |
|
| 112 | - $nom = ''; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Contexte de compil inutile a present |
|
| 116 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 117 | - $skel_code[$id] = $f; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $code = ''; |
|
| 121 | - if ($nom) { |
|
| 122 | - // Si le code est bon, concatener et mettre en cache |
|
| 123 | - if (function_exists($nom)) { |
|
| 124 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 125 | - } else { |
|
| 126 | - // code semantiquement faux: bug du compilateur |
|
| 127 | - // $boucle est en fait ici la fct principale du squelette |
|
| 128 | - $msg = _T('zbug_erreur_compilation'); |
|
| 129 | - erreur_squelette($msg, $boucle); |
|
| 130 | - $nom = ''; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 135 | - |
|
| 136 | - // Tracer ce qui vient d'etre compile |
|
| 137 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 138 | - |
|
| 139 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 140 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 141 | - and (_request('var_mode_objet') == $nom) |
|
| 142 | - and (_request('var_mode_affiche') == 'code') |
|
| 143 | - ) { |
|
| 144 | - erreur_squelette(); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return $nom ? $nom : false; |
|
| 46 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | + |
|
| 48 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | + if (function_exists($nom)) { |
|
| 50 | + return $nom; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | + |
|
| 59 | + // si squelette est deja compile et perenne, le charger |
|
| 60 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | + include_once $phpfile; |
|
| 62 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | + ## eval('?'.'>'.$skel_code); |
|
| 66 | + # spip_log($skel_code, 'comp') |
|
| 67 | + #} |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | + include_once $lib; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | + |
|
| 76 | + if (function_exists($nom)) { |
|
| 77 | + return $nom; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // charger le source, si possible, et compiler |
|
| 81 | + $skel_code = ''; |
|
| 82 | + if (lire_fichier($source, $skel)) { |
|
| 83 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | + if (!$skel_code) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + foreach ($skel_code as $id => $boucle) { |
|
| 93 | + $f = $boucle->return; |
|
| 94 | + try { |
|
| 95 | + // @todo : a remplacer quand _PHP_MIN >= 7 |
|
| 96 | + // eval("return true; $f ;"); |
|
| 97 | + // PHP 5.x compat |
|
| 98 | + if ($ok = @eval("return true; $f ;") === false) { |
|
| 99 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 100 | + $msg = _T('zbug_erreur_compilation'); |
|
| 101 | + erreur_squelette($msg, $boucle); |
|
| 102 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 103 | + // mais prevenir que c'est mort |
|
| 104 | + $nom = ''; |
|
| 105 | + } |
|
| 106 | + } catch (\ParseError $e) { |
|
| 107 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 108 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 109 | + erreur_squelette($msg, $boucle); |
|
| 110 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 111 | + // mais prevenir que c'est mort |
|
| 112 | + $nom = ''; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Contexte de compil inutile a present |
|
| 116 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 117 | + $skel_code[$id] = $f; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $code = ''; |
|
| 121 | + if ($nom) { |
|
| 122 | + // Si le code est bon, concatener et mettre en cache |
|
| 123 | + if (function_exists($nom)) { |
|
| 124 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 125 | + } else { |
|
| 126 | + // code semantiquement faux: bug du compilateur |
|
| 127 | + // $boucle est en fait ici la fct principale du squelette |
|
| 128 | + $msg = _T('zbug_erreur_compilation'); |
|
| 129 | + erreur_squelette($msg, $boucle); |
|
| 130 | + $nom = ''; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 135 | + |
|
| 136 | + // Tracer ce qui vient d'etre compile |
|
| 137 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 138 | + |
|
| 139 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 140 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 141 | + and (_request('var_mode_objet') == $nom) |
|
| 142 | + and (_request('var_mode_affiche') == 'code') |
|
| 143 | + ) { |
|
| 144 | + erreur_squelette(); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return $nom ? $nom : false; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 152 | 152 | |
| 153 | - // Le dernier index est '' (fonction principale) |
|
| 154 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 155 | - if (CODE_COMMENTE) { |
|
| 156 | - $code = " |
|
| 153 | + // Le dernier index est '' (fonction principale) |
|
| 154 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 155 | + if (CODE_COMMENTE) { |
|
| 156 | + $code = " |
|
| 157 | 157 | /* |
| 158 | 158 | * Squelette : $sourcefile |
| 159 | 159 | * Date : " . gmdate("D, d M Y H:i:s", @filemtime($sourcefile)) . " GMT |
| 160 | 160 | * Compile : " . gmdate("D, d M Y H:i:s", time()) . " GMT |
| 161 | 161 | * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) . " |
| 162 | 162 | */ "; |
| 163 | - } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 166 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 167 | - ecrire_fichier($phpfile, $code); |
|
| 168 | - } |
|
| 165 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 166 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 167 | + ecrire_fichier($phpfile, $code); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - return $code; |
|
| 170 | + return $code; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // Le squelette compile est-il trop vieux ? |
| 174 | 174 | // https://code.spip.net/@squelette_obsolete |
| 175 | 175 | function squelette_obsolete($skel, $squelette) { |
| 176 | - static $date_change = null; |
|
| 177 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 178 | - // par hit |
|
| 179 | - if (is_null($date_change)) { |
|
| 180 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 181 | - $date_change = @filemtime($fonc); |
|
| 182 | - } # compatibilite |
|
| 183 | - if (defined('_FILE_OPTIONS')) { |
|
| 184 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return ( |
|
| 189 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 190 | - or !@file_exists($skel) |
|
| 191 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 192 | - > ($date = @filemtime($skel))) |
|
| 193 | - or ($date_change > $date) |
|
| 194 | - ); |
|
| 176 | + static $date_change = null; |
|
| 177 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 178 | + // par hit |
|
| 179 | + if (is_null($date_change)) { |
|
| 180 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 181 | + $date_change = @filemtime($fonc); |
|
| 182 | + } # compatibilite |
|
| 183 | + if (defined('_FILE_OPTIONS')) { |
|
| 184 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return ( |
|
| 189 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 190 | + or !@file_exists($skel) |
|
| 191 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 192 | + > ($date = @filemtime($skel))) |
|
| 193 | + or ($date_change > $date) |
|
| 194 | + ); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | // Activer l'invalideur de session |
| 198 | 198 | // https://code.spip.net/@invalideur_session |
| 199 | 199 | function invalideur_session(&$Cache, $code = null) { |
| 200 | - $Cache['session'] = spip_session(); |
|
| 200 | + $Cache['session'] = spip_session(); |
|
| 201 | 201 | |
| 202 | - return $code; |
|
| 202 | + return $code; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | // https://code.spip.net/@analyse_resultat_skel |
| 207 | 207 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 208 | - static $filtres = array(); |
|
| 209 | - $headers = array(); |
|
| 210 | - |
|
| 211 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 212 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 213 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 214 | - if (stripos($corps, 'header') !== false |
|
| 215 | - and preg_match_all( |
|
| 216 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 217 | - $corps, $regs, PREG_SET_ORDER) |
|
| 218 | - ) { |
|
| 219 | - foreach ($regs as $r) { |
|
| 220 | - $corps = str_replace($r[0], '', $corps); |
|
| 221 | - # $j = Content-Type, et pas content-TYPE. |
|
| 222 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 223 | - |
|
| 224 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 225 | - $headers[$j] .= "|" . $r[3]; |
|
| 226 | - } else { |
|
| 227 | - $headers[$j] = $r[3]; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 232 | - $process_ins = ( |
|
| 233 | - strpos($corps, '<' . '?') === false |
|
| 234 | - or |
|
| 235 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 236 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 237 | - ) |
|
| 238 | - ? 'html' |
|
| 239 | - : 'php'; |
|
| 240 | - |
|
| 241 | - $skel = array( |
|
| 242 | - 'squelette' => $nom, |
|
| 243 | - 'source' => $source, |
|
| 244 | - 'process_ins' => $process_ins, |
|
| 245 | - 'invalideurs' => $cache, |
|
| 246 | - 'entetes' => $headers, |
|
| 247 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 248 | - ); |
|
| 249 | - |
|
| 250 | - // traiter #FILTRE{} et filtres |
|
| 251 | - if (!isset($filtres[$nom])) { |
|
| 252 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 253 | - } |
|
| 254 | - $filtres_headers = array(); |
|
| 255 | - if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 256 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 257 | - unset($headers['X-Spip-Filtre']); |
|
| 258 | - } |
|
| 259 | - if (count($filtres[$nom]) or count($filtres_headers)) { |
|
| 260 | - include_spip('public/sandbox'); |
|
| 261 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 262 | - |
|
| 263 | - if ($process_ins == 'html') { |
|
| 264 | - $skel['process_ins'] = ( |
|
| 265 | - strpos($corps, '<' . '?') === false |
|
| 266 | - or |
|
| 267 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 268 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 269 | - ) |
|
| 270 | - ? 'html' |
|
| 271 | - : 'php'; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $skel['entetes'] = $headers; |
|
| 276 | - $skel['texte'] = $corps; |
|
| 277 | - |
|
| 278 | - return $skel; |
|
| 208 | + static $filtres = array(); |
|
| 209 | + $headers = array(); |
|
| 210 | + |
|
| 211 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 212 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 213 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 214 | + if (stripos($corps, 'header') !== false |
|
| 215 | + and preg_match_all( |
|
| 216 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 217 | + $corps, $regs, PREG_SET_ORDER) |
|
| 218 | + ) { |
|
| 219 | + foreach ($regs as $r) { |
|
| 220 | + $corps = str_replace($r[0], '', $corps); |
|
| 221 | + # $j = Content-Type, et pas content-TYPE. |
|
| 222 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 223 | + |
|
| 224 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 225 | + $headers[$j] .= "|" . $r[3]; |
|
| 226 | + } else { |
|
| 227 | + $headers[$j] = $r[3]; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 232 | + $process_ins = ( |
|
| 233 | + strpos($corps, '<' . '?') === false |
|
| 234 | + or |
|
| 235 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 236 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 237 | + ) |
|
| 238 | + ? 'html' |
|
| 239 | + : 'php'; |
|
| 240 | + |
|
| 241 | + $skel = array( |
|
| 242 | + 'squelette' => $nom, |
|
| 243 | + 'source' => $source, |
|
| 244 | + 'process_ins' => $process_ins, |
|
| 245 | + 'invalideurs' => $cache, |
|
| 246 | + 'entetes' => $headers, |
|
| 247 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 248 | + ); |
|
| 249 | + |
|
| 250 | + // traiter #FILTRE{} et filtres |
|
| 251 | + if (!isset($filtres[$nom])) { |
|
| 252 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 253 | + } |
|
| 254 | + $filtres_headers = array(); |
|
| 255 | + if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 256 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 257 | + unset($headers['X-Spip-Filtre']); |
|
| 258 | + } |
|
| 259 | + if (count($filtres[$nom]) or count($filtres_headers)) { |
|
| 260 | + include_spip('public/sandbox'); |
|
| 261 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 262 | + |
|
| 263 | + if ($process_ins == 'html') { |
|
| 264 | + $skel['process_ins'] = ( |
|
| 265 | + strpos($corps, '<' . '?') === false |
|
| 266 | + or |
|
| 267 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 268 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 269 | + ) |
|
| 270 | + ? 'html' |
|
| 271 | + : 'php'; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $skel['entetes'] = $headers; |
|
| 276 | + $skel['texte'] = $corps; |
|
| 277 | + |
|
| 278 | + return $skel; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 290 | 290 | if ($lang_select) lang_select(); |
| 291 | 291 | ?' |
| 292 | - . '>'); |
|
| 292 | + . '>'); |
|
| 293 | 293 | |
| 294 | 294 | /** |
| 295 | 295 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -309,17 +309,17 @@ discard block |
||
| 309 | 309 | * Code PHP pour inclure le squelette de la balise dynamique |
| 310 | 310 | **/ |
| 311 | 311 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 312 | - if (strncmp($file, "/", 1) !== 0) { |
|
| 313 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 314 | - } |
|
| 315 | - $r = sprintf(CODE_INCLURE_BALISE, |
|
| 316 | - $file, |
|
| 317 | - $context_compil[4] ? $context_compil[4] : '', |
|
| 318 | - $nom, |
|
| 319 | - join(', ', array_map('argumenter_squelette', $args)), |
|
| 320 | - join(', ', array_map('_q', $context_compil))); |
|
| 321 | - |
|
| 322 | - return $r; |
|
| 312 | + if (strncmp($file, "/", 1) !== 0) { |
|
| 313 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 314 | + } |
|
| 315 | + $r = sprintf(CODE_INCLURE_BALISE, |
|
| 316 | + $file, |
|
| 317 | + $context_compil[4] ? $context_compil[4] : '', |
|
| 318 | + $nom, |
|
| 319 | + join(', ', array_map('argumenter_squelette', $args)), |
|
| 320 | + join(', ', array_map('_q', $context_compil))); |
|
| 321 | + |
|
| 322 | + return $r; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -337,21 +337,21 @@ discard block |
||
| 337 | 337 | **/ |
| 338 | 338 | function argumenter_squelette($v) { |
| 339 | 339 | |
| 340 | - if (is_object($v)) { |
|
| 341 | - if (PHP_VERSION_ID < 73000 and $v instanceof \stdClass) { |
|
| 342 | - return "(object) " . var_export((array) $v, true); |
|
| 343 | - } |
|
| 344 | - return var_export($v, true); |
|
| 345 | - } elseif (!is_array($v)) { |
|
| 346 | - return "'" . texte_script($v) . "'"; |
|
| 347 | - } else { |
|
| 348 | - $out = array(); |
|
| 349 | - foreach ($v as $k => $val) { |
|
| 350 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - return 'array(' . join(", ", $out) . ')'; |
|
| 354 | - } |
|
| 340 | + if (is_object($v)) { |
|
| 341 | + if (PHP_VERSION_ID < 73000 and $v instanceof \stdClass) { |
|
| 342 | + return "(object) " . var_export((array) $v, true); |
|
| 343 | + } |
|
| 344 | + return var_export($v, true); |
|
| 345 | + } elseif (!is_array($v)) { |
|
| 346 | + return "'" . texte_script($v) . "'"; |
|
| 347 | + } else { |
|
| 348 | + $out = array(); |
|
| 349 | + foreach ($v as $k => $val) { |
|
| 350 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + return 'array(' . join(", ", $out) . ')'; |
|
| 354 | + } |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | |
@@ -382,69 +382,69 @@ discard block |
||
| 382 | 382 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 383 | 383 | **/ |
| 384 | 384 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 385 | - $nomfonction = $nom; |
|
| 386 | - $nomfonction_generique = ""; |
|
| 387 | - |
|
| 388 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 389 | - if (false !== ($p = strpos($nom, "_"))) { |
|
| 390 | - $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 394 | - if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 395 | - // et injecter en premier arg le nom de la balise |
|
| 396 | - array_unshift($args, $nom); |
|
| 397 | - $nomfonction = $nomfonction_generique; |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - if (!$fonction_balise) { |
|
| 402 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 403 | - erreur_squelette($msg, $context_compil); |
|
| 404 | - |
|
| 405 | - return ''; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - // retrouver le fichier qui a déclaré la fonction |
|
| 409 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 410 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 411 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 412 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 413 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 414 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 418 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 419 | - |
|
| 420 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 421 | - |
|
| 422 | - if (!is_array($r)) { |
|
| 423 | - return $r; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - // verifier que la fonction dyn est la, |
|
| 427 | - // sinon se replier sur la generique si elle existe |
|
| 428 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 429 | - if ($nomfonction_generique |
|
| 430 | - and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 431 | - and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 432 | - ) { |
|
| 433 | - // et lui injecter en premier arg le nom de la balise |
|
| 434 | - array_unshift($r, $nom); |
|
| 435 | - $nomfonction = $nomfonction_generique; |
|
| 436 | - if (!_DIR_RESTREINT) { |
|
| 437 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 438 | - } |
|
| 439 | - } else { |
|
| 440 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 441 | - erreur_squelette($msg, $context_compil); |
|
| 442 | - |
|
| 443 | - return ''; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 385 | + $nomfonction = $nom; |
|
| 386 | + $nomfonction_generique = ""; |
|
| 387 | + |
|
| 388 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 389 | + if (false !== ($p = strpos($nom, "_"))) { |
|
| 390 | + $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 394 | + if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 395 | + // et injecter en premier arg le nom de la balise |
|
| 396 | + array_unshift($args, $nom); |
|
| 397 | + $nomfonction = $nomfonction_generique; |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + if (!$fonction_balise) { |
|
| 402 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 403 | + erreur_squelette($msg, $context_compil); |
|
| 404 | + |
|
| 405 | + return ''; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + // retrouver le fichier qui a déclaré la fonction |
|
| 409 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 410 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 411 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 412 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 413 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 414 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 418 | + $f = 'balise_' . $nomfonction . '_stat'; |
|
| 419 | + |
|
| 420 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 421 | + |
|
| 422 | + if (!is_array($r)) { |
|
| 423 | + return $r; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + // verifier que la fonction dyn est la, |
|
| 427 | + // sinon se replier sur la generique si elle existe |
|
| 428 | + if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 429 | + if ($nomfonction_generique |
|
| 430 | + and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 431 | + and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 432 | + ) { |
|
| 433 | + // et lui injecter en premier arg le nom de la balise |
|
| 434 | + array_unshift($r, $nom); |
|
| 435 | + $nomfonction = $nomfonction_generique; |
|
| 436 | + if (!_DIR_RESTREINT) { |
|
| 437 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 438 | + } |
|
| 439 | + } else { |
|
| 440 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 441 | + erreur_squelette($msg, $context_compil); |
|
| 442 | + |
|
| 443 | + return ''; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 448 | 448 | |
| 449 | 449 | } |
| 450 | 450 | |
@@ -469,27 +469,27 @@ discard block |
||
| 469 | 469 | * @return null; |
| 470 | 470 | **/ |
| 471 | 471 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 472 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 473 | - if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 474 | - and $lang_select !== 'oui' |
|
| 475 | - ) { |
|
| 476 | - $lang = $GLOBALS['spip_lang']; |
|
| 477 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 478 | - elseif (!strlen($lang)) { |
|
| 479 | - $lang = $GLOBALS['spip_lang']; |
|
| 480 | - } // Cas 3. l'objet est multilingue ! |
|
| 481 | - elseif ($lang_select !== 'oui' |
|
| 482 | - and strlen($titre) > 10 |
|
| 483 | - and strpos($titre, '<multi>') !== false |
|
| 484 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 485 | - ) { |
|
| 486 | - $lang = $GLOBALS['spip_lang']; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 490 | - lang_select($lang); |
|
| 491 | - |
|
| 492 | - return; |
|
| 472 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 473 | + if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 474 | + and $lang_select !== 'oui' |
|
| 475 | + ) { |
|
| 476 | + $lang = $GLOBALS['spip_lang']; |
|
| 477 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 478 | + elseif (!strlen($lang)) { |
|
| 479 | + $lang = $GLOBALS['spip_lang']; |
|
| 480 | + } // Cas 3. l'objet est multilingue ! |
|
| 481 | + elseif ($lang_select !== 'oui' |
|
| 482 | + and strlen($titre) > 10 |
|
| 483 | + and strpos($titre, '<multi>') !== false |
|
| 484 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 485 | + ) { |
|
| 486 | + $lang = $GLOBALS['spip_lang']; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 490 | + lang_select($lang); |
|
| 491 | + |
|
| 492 | + return; |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | |
@@ -497,21 +497,21 @@ discard block |
||
| 497 | 497 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 498 | 498 | // https://code.spip.net/@nettoyer_env_doublons |
| 499 | 499 | function nettoyer_env_doublons($envd) { |
| 500 | - foreach ($envd as $table => $liste) { |
|
| 501 | - $n = ''; |
|
| 502 | - foreach (explode(',', $liste) as $val) { |
|
| 503 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 504 | - $n .= ',' . $val; |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - if (strlen($n)) { |
|
| 508 | - $envd[$table] = $n; |
|
| 509 | - } else { |
|
| 510 | - unset($envd[$table]); |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - return $envd; |
|
| 500 | + foreach ($envd as $table => $liste) { |
|
| 501 | + $n = ''; |
|
| 502 | + foreach (explode(',', $liste) as $val) { |
|
| 503 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 504 | + $n .= ',' . $val; |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + if (strlen($n)) { |
|
| 508 | + $envd[$table] = $n; |
|
| 509 | + } else { |
|
| 510 | + unset($envd[$table]); |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + return $envd; |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | /** |
@@ -530,21 +530,21 @@ discard block |
||
| 530 | 530 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 531 | 531 | **/ |
| 532 | 532 | function match_self($w) { |
| 533 | - if (is_string($w)) { |
|
| 534 | - return false; |
|
| 535 | - } |
|
| 536 | - if (is_array($w)) { |
|
| 537 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 538 | - return $w; |
|
| 539 | - } |
|
| 540 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 541 | - if ($m = match_self($sw)) { |
|
| 542 | - return $m; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - return false; |
|
| 533 | + if (is_string($w)) { |
|
| 534 | + return false; |
|
| 535 | + } |
|
| 536 | + if (is_array($w)) { |
|
| 537 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 538 | + return $w; |
|
| 539 | + } |
|
| 540 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 541 | + if ($m = match_self($sw)) { |
|
| 542 | + return $m; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + return false; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | /** |
@@ -560,16 +560,16 @@ discard block |
||
| 560 | 560 | * est remplacée par son code. |
| 561 | 561 | **/ |
| 562 | 562 | function remplace_sous_requete($w, $sousrequete) { |
| 563 | - if (is_array($w)) { |
|
| 564 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 565 | - return $sousrequete; |
|
| 566 | - } |
|
| 567 | - foreach ($w as $k => $sw) { |
|
| 568 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - return $w; |
|
| 563 | + if (is_array($w)) { |
|
| 564 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 565 | + return $sousrequete; |
|
| 566 | + } |
|
| 567 | + foreach ($w as $k => $sw) { |
|
| 568 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return $w; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -583,17 +583,17 @@ discard block |
||
| 583 | 583 | * - Conditions avec des sous requêtes |
| 584 | 584 | **/ |
| 585 | 585 | function trouver_sous_requetes($where) { |
| 586 | - $where_simples = array(); |
|
| 587 | - $where_sous = array(); |
|
| 588 | - foreach ($where as $k => $w) { |
|
| 589 | - if (match_self($w)) { |
|
| 590 | - $where_sous[$k] = $w; |
|
| 591 | - } else { |
|
| 592 | - $where_simples[$k] = $w; |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return array($where_simples, $where_sous); |
|
| 586 | + $where_simples = array(); |
|
| 587 | + $where_sous = array(); |
|
| 588 | + foreach ($where as $k => $w) { |
|
| 589 | + if (match_self($w)) { |
|
| 590 | + $where_sous[$k] = $w; |
|
| 591 | + } else { |
|
| 592 | + $where_simples[$k] = $w; |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return array($where_simples, $where_sous); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | |
@@ -619,258 +619,258 @@ discard block |
||
| 619 | 619 | * @return resource |
| 620 | 620 | */ |
| 621 | 621 | function calculer_select( |
| 622 | - $select = array(), |
|
| 623 | - $from = array(), |
|
| 624 | - $from_type = array(), |
|
| 625 | - $where = array(), |
|
| 626 | - $join = array(), |
|
| 627 | - $groupby = array(), |
|
| 628 | - $orderby = array(), |
|
| 629 | - $limit = '', |
|
| 630 | - $having = array(), |
|
| 631 | - $table = '', |
|
| 632 | - $id = '', |
|
| 633 | - $serveur = '', |
|
| 634 | - $requeter = true |
|
| 622 | + $select = array(), |
|
| 623 | + $from = array(), |
|
| 624 | + $from_type = array(), |
|
| 625 | + $where = array(), |
|
| 626 | + $join = array(), |
|
| 627 | + $groupby = array(), |
|
| 628 | + $orderby = array(), |
|
| 629 | + $limit = '', |
|
| 630 | + $having = array(), |
|
| 631 | + $table = '', |
|
| 632 | + $id = '', |
|
| 633 | + $serveur = '', |
|
| 634 | + $requeter = true |
|
| 635 | 635 | ) { |
| 636 | 636 | |
| 637 | - // retirer les criteres vides: |
|
| 638 | - // {X ?} avec X absent de l'URL |
|
| 639 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 640 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 641 | - $menage = false; |
|
| 642 | - foreach ($where as $k => $v) { |
|
| 643 | - if (is_array($v)) { |
|
| 644 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 645 | - $op = false; |
|
| 646 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 647 | - $op = false; |
|
| 648 | - } else { |
|
| 649 | - $op = $v[0] ? $v[0] : $v; |
|
| 650 | - } |
|
| 651 | - } else { |
|
| 652 | - $op = $v; |
|
| 653 | - } |
|
| 654 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 655 | - unset($where[$k]); |
|
| 656 | - $menage = true; |
|
| 657 | - } |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 661 | - $groupby = array_diff($groupby, array('')); |
|
| 662 | - |
|
| 663 | - // remplacer les sous requetes recursives au calcul |
|
| 664 | - list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 665 | - foreach ($where_sous as $k => $w) { |
|
| 666 | - $menage = true; |
|
| 667 | - // on recupere la sous requete |
|
| 668 | - $sous = match_self($w); |
|
| 669 | - if ($sous[0] == 'SELF') { |
|
| 670 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 671 | - array_push($where_simples, $sous[2]); |
|
| 672 | - $wheresub = array( |
|
| 673 | - $sous[2], |
|
| 674 | - '0=0' |
|
| 675 | - ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 676 | - $jsub = $join; |
|
| 677 | - // trouver les jointures utiles a |
|
| 678 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 679 | - // ie L1.objet='article' |
|
| 680 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 681 | - $i = 0; |
|
| 682 | - do { |
|
| 683 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 684 | - array($sous[1] . " AS id"), |
|
| 685 | - $from, |
|
| 686 | - $from_type, |
|
| 687 | - $wheresub, |
|
| 688 | - $jsub, |
|
| 689 | - array(), array(), '', |
|
| 690 | - $having, $table, $id, $serveur, false) . ")"); |
|
| 691 | - if (!$i) { |
|
| 692 | - $i = 1; |
|
| 693 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 694 | - foreach ($join as $cle => $wj) { |
|
| 695 | - if (count($wj) == 4 |
|
| 696 | - and strpos($wherestring, "{$cle}.") !== false |
|
| 697 | - ) { |
|
| 698 | - $i = 0; |
|
| 699 | - $wheresub[] = $wj[3]; |
|
| 700 | - unset($jsub[$cle][3]); |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - } |
|
| 704 | - } while ($i++ < 1); |
|
| 705 | - } |
|
| 706 | - if ($sous[0] == 'SUBSELECT') { |
|
| 707 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 708 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 709 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 710 | - $sous[1], # select |
|
| 711 | - $sous[2], #from |
|
| 712 | - array(), #from_type |
|
| 713 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 714 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 715 | - array(), #join |
|
| 716 | - $sous[4] ? $sous[4] : array(), #groupby |
|
| 717 | - $sous[5] ? $sous[5] : array(), #orderby |
|
| 718 | - $sous[6], #limit |
|
| 719 | - $sous[7] ? $sous[7] : array(), #having |
|
| 720 | - $table, $id, $serveur, false |
|
| 721 | - ) . ")"); |
|
| 722 | - } |
|
| 723 | - array_pop($where_simples); |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - foreach ($having as $k => $v) { |
|
| 727 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 728 | - unset($having[$k]); |
|
| 729 | - } |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - // Installer les jointures. |
|
| 733 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 734 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 735 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 736 | - |
|
| 737 | - $afrom = array(); |
|
| 738 | - $equiv = array(); |
|
| 739 | - $k = count($join); |
|
| 740 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 741 | - $cle = $cledef; |
|
| 742 | - // le format de join est : |
|
| 743 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 744 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 745 | - if (count($join[$cle]) == 2) { |
|
| 746 | - $join[$cle][] = $join[$cle][1]; |
|
| 747 | - } |
|
| 748 | - if (count($join[$cle]) == 3) { |
|
| 749 | - $join[$cle][] = ''; |
|
| 750 | - } |
|
| 751 | - list($t, $c, $carr, $and) = $join[$cle]; |
|
| 752 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 753 | - // pour compat avec ancienne convention |
|
| 754 | - if (is_numeric($cle)) { |
|
| 755 | - $cle = "L$k"; |
|
| 756 | - } |
|
| 757 | - if (!$menage |
|
| 758 | - or isset($afrom[$cle]) |
|
| 759 | - or calculer_jointnul($cle, $select) |
|
| 760 | - or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 761 | - or calculer_jointnul($cle, $having) |
|
| 762 | - or calculer_jointnul($cle, $where_simples) |
|
| 763 | - ) { |
|
| 764 | - // corriger les references non explicites dans select |
|
| 765 | - // ou groupby |
|
| 766 | - foreach ($select as $i => $s) { |
|
| 767 | - if ($s == $c) { |
|
| 768 | - $select[$i] = "$cle.$c AS $c"; |
|
| 769 | - break; |
|
| 770 | - } |
|
| 771 | - } |
|
| 772 | - foreach ($groupby as $i => $g) { |
|
| 773 | - if ($g == $c) { |
|
| 774 | - $groupby[$i] = "$cle.$c"; |
|
| 775 | - break; |
|
| 776 | - } |
|
| 777 | - } |
|
| 778 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 779 | - // sans recours a preg_match |
|
| 780 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 781 | - $afrom[$t][$cle] = array( |
|
| 782 | - "\n" . |
|
| 783 | - (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 784 | - $from[$cle], |
|
| 785 | - "AS $cle", |
|
| 786 | - "ON (", |
|
| 787 | - "$cle.$c", |
|
| 788 | - "=", |
|
| 789 | - "$t.$carr", |
|
| 790 | - ($and ? "AND " . $and : "") . |
|
| 791 | - ")" |
|
| 792 | - ); |
|
| 793 | - if (isset($afrom[$cle])) { |
|
| 794 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 795 | - unset($afrom[$cle]); |
|
| 796 | - } |
|
| 797 | - $equiv[] = $carr; |
|
| 798 | - } else { |
|
| 799 | - unset($join[$cledef]); |
|
| 800 | - } |
|
| 801 | - unset($from[$cle]); |
|
| 802 | - $k--; |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - if (count($afrom)) { |
|
| 806 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 807 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 808 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 809 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 810 | - // ou dans |
|
| 811 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 812 | - // qui comporte plusieurs jointures |
|
| 813 | - // ou dans |
|
| 814 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 815 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 816 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 817 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 818 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 819 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 820 | - |
|
| 821 | - $t = key($from); |
|
| 822 | - $c = current($from); |
|
| 823 | - reset($from); |
|
| 824 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 825 | - if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 826 | - calculer_jointnul($t, $select, $e) or |
|
| 827 | - calculer_jointnul($t, $join, $e) or |
|
| 828 | - calculer_jointnul($t, $where, $e) or |
|
| 829 | - calculer_jointnul($t, $orderby, $e) or |
|
| 830 | - calculer_jointnul($t, $groupby, $e) or |
|
| 831 | - calculer_jointnul($t, $having, $e)) |
|
| 832 | - && count($afrom[$t]) |
|
| 833 | - ) { |
|
| 834 | - $nfrom = reset($afrom[$t]); |
|
| 835 | - $nt = key($afrom[$t]); |
|
| 836 | - unset($from[$t]); |
|
| 837 | - $from[$nt] = $nfrom[1]; |
|
| 838 | - unset($afrom[$t][$nt]); |
|
| 839 | - $afrom[$nt] = $afrom[$t]; |
|
| 840 | - unset($afrom[$t]); |
|
| 841 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 842 | - $t = $nfrom[4]; |
|
| 843 | - $alias = ""; |
|
| 844 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 845 | - $oldcle = explode('.', $nfrom[6]); |
|
| 846 | - $oldcle = end($oldcle); |
|
| 847 | - $newcle = explode('.', $nfrom[4]); |
|
| 848 | - $newcle = end($newcle); |
|
| 849 | - if ($newcle != $oldcle) { |
|
| 850 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 851 | - // reprendre simplement ce AS |
|
| 852 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 853 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 854 | - $alias = ""; |
|
| 855 | - } else { |
|
| 856 | - $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 860 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 861 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 862 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 863 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 864 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 865 | - } |
|
| 866 | - $from = reinjecte_joint($afrom, $from); |
|
| 867 | - } |
|
| 868 | - $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 869 | - $r = sql_select($select, $from, $where, |
|
| 870 | - $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 871 | - unset($GLOBALS['debug']['aucasou']); |
|
| 872 | - |
|
| 873 | - return $r; |
|
| 637 | + // retirer les criteres vides: |
|
| 638 | + // {X ?} avec X absent de l'URL |
|
| 639 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 640 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 641 | + $menage = false; |
|
| 642 | + foreach ($where as $k => $v) { |
|
| 643 | + if (is_array($v)) { |
|
| 644 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 645 | + $op = false; |
|
| 646 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 647 | + $op = false; |
|
| 648 | + } else { |
|
| 649 | + $op = $v[0] ? $v[0] : $v; |
|
| 650 | + } |
|
| 651 | + } else { |
|
| 652 | + $op = $v; |
|
| 653 | + } |
|
| 654 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 655 | + unset($where[$k]); |
|
| 656 | + $menage = true; |
|
| 657 | + } |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 661 | + $groupby = array_diff($groupby, array('')); |
|
| 662 | + |
|
| 663 | + // remplacer les sous requetes recursives au calcul |
|
| 664 | + list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 665 | + foreach ($where_sous as $k => $w) { |
|
| 666 | + $menage = true; |
|
| 667 | + // on recupere la sous requete |
|
| 668 | + $sous = match_self($w); |
|
| 669 | + if ($sous[0] == 'SELF') { |
|
| 670 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 671 | + array_push($where_simples, $sous[2]); |
|
| 672 | + $wheresub = array( |
|
| 673 | + $sous[2], |
|
| 674 | + '0=0' |
|
| 675 | + ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 676 | + $jsub = $join; |
|
| 677 | + // trouver les jointures utiles a |
|
| 678 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 679 | + // ie L1.objet='article' |
|
| 680 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 681 | + $i = 0; |
|
| 682 | + do { |
|
| 683 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 684 | + array($sous[1] . " AS id"), |
|
| 685 | + $from, |
|
| 686 | + $from_type, |
|
| 687 | + $wheresub, |
|
| 688 | + $jsub, |
|
| 689 | + array(), array(), '', |
|
| 690 | + $having, $table, $id, $serveur, false) . ")"); |
|
| 691 | + if (!$i) { |
|
| 692 | + $i = 1; |
|
| 693 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 694 | + foreach ($join as $cle => $wj) { |
|
| 695 | + if (count($wj) == 4 |
|
| 696 | + and strpos($wherestring, "{$cle}.") !== false |
|
| 697 | + ) { |
|
| 698 | + $i = 0; |
|
| 699 | + $wheresub[] = $wj[3]; |
|
| 700 | + unset($jsub[$cle][3]); |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + } |
|
| 704 | + } while ($i++ < 1); |
|
| 705 | + } |
|
| 706 | + if ($sous[0] == 'SUBSELECT') { |
|
| 707 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 708 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 709 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 710 | + $sous[1], # select |
|
| 711 | + $sous[2], #from |
|
| 712 | + array(), #from_type |
|
| 713 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 714 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 715 | + array(), #join |
|
| 716 | + $sous[4] ? $sous[4] : array(), #groupby |
|
| 717 | + $sous[5] ? $sous[5] : array(), #orderby |
|
| 718 | + $sous[6], #limit |
|
| 719 | + $sous[7] ? $sous[7] : array(), #having |
|
| 720 | + $table, $id, $serveur, false |
|
| 721 | + ) . ")"); |
|
| 722 | + } |
|
| 723 | + array_pop($where_simples); |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + foreach ($having as $k => $v) { |
|
| 727 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 728 | + unset($having[$k]); |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + // Installer les jointures. |
|
| 733 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 734 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 735 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 736 | + |
|
| 737 | + $afrom = array(); |
|
| 738 | + $equiv = array(); |
|
| 739 | + $k = count($join); |
|
| 740 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 741 | + $cle = $cledef; |
|
| 742 | + // le format de join est : |
|
| 743 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 744 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 745 | + if (count($join[$cle]) == 2) { |
|
| 746 | + $join[$cle][] = $join[$cle][1]; |
|
| 747 | + } |
|
| 748 | + if (count($join[$cle]) == 3) { |
|
| 749 | + $join[$cle][] = ''; |
|
| 750 | + } |
|
| 751 | + list($t, $c, $carr, $and) = $join[$cle]; |
|
| 752 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 753 | + // pour compat avec ancienne convention |
|
| 754 | + if (is_numeric($cle)) { |
|
| 755 | + $cle = "L$k"; |
|
| 756 | + } |
|
| 757 | + if (!$menage |
|
| 758 | + or isset($afrom[$cle]) |
|
| 759 | + or calculer_jointnul($cle, $select) |
|
| 760 | + or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 761 | + or calculer_jointnul($cle, $having) |
|
| 762 | + or calculer_jointnul($cle, $where_simples) |
|
| 763 | + ) { |
|
| 764 | + // corriger les references non explicites dans select |
|
| 765 | + // ou groupby |
|
| 766 | + foreach ($select as $i => $s) { |
|
| 767 | + if ($s == $c) { |
|
| 768 | + $select[$i] = "$cle.$c AS $c"; |
|
| 769 | + break; |
|
| 770 | + } |
|
| 771 | + } |
|
| 772 | + foreach ($groupby as $i => $g) { |
|
| 773 | + if ($g == $c) { |
|
| 774 | + $groupby[$i] = "$cle.$c"; |
|
| 775 | + break; |
|
| 776 | + } |
|
| 777 | + } |
|
| 778 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 779 | + // sans recours a preg_match |
|
| 780 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 781 | + $afrom[$t][$cle] = array( |
|
| 782 | + "\n" . |
|
| 783 | + (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 784 | + $from[$cle], |
|
| 785 | + "AS $cle", |
|
| 786 | + "ON (", |
|
| 787 | + "$cle.$c", |
|
| 788 | + "=", |
|
| 789 | + "$t.$carr", |
|
| 790 | + ($and ? "AND " . $and : "") . |
|
| 791 | + ")" |
|
| 792 | + ); |
|
| 793 | + if (isset($afrom[$cle])) { |
|
| 794 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 795 | + unset($afrom[$cle]); |
|
| 796 | + } |
|
| 797 | + $equiv[] = $carr; |
|
| 798 | + } else { |
|
| 799 | + unset($join[$cledef]); |
|
| 800 | + } |
|
| 801 | + unset($from[$cle]); |
|
| 802 | + $k--; |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + if (count($afrom)) { |
|
| 806 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 807 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 808 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 809 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 810 | + // ou dans |
|
| 811 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 812 | + // qui comporte plusieurs jointures |
|
| 813 | + // ou dans |
|
| 814 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 815 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 816 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 817 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 818 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 819 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 820 | + |
|
| 821 | + $t = key($from); |
|
| 822 | + $c = current($from); |
|
| 823 | + reset($from); |
|
| 824 | + $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 825 | + if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 826 | + calculer_jointnul($t, $select, $e) or |
|
| 827 | + calculer_jointnul($t, $join, $e) or |
|
| 828 | + calculer_jointnul($t, $where, $e) or |
|
| 829 | + calculer_jointnul($t, $orderby, $e) or |
|
| 830 | + calculer_jointnul($t, $groupby, $e) or |
|
| 831 | + calculer_jointnul($t, $having, $e)) |
|
| 832 | + && count($afrom[$t]) |
|
| 833 | + ) { |
|
| 834 | + $nfrom = reset($afrom[$t]); |
|
| 835 | + $nt = key($afrom[$t]); |
|
| 836 | + unset($from[$t]); |
|
| 837 | + $from[$nt] = $nfrom[1]; |
|
| 838 | + unset($afrom[$t][$nt]); |
|
| 839 | + $afrom[$nt] = $afrom[$t]; |
|
| 840 | + unset($afrom[$t]); |
|
| 841 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 842 | + $t = $nfrom[4]; |
|
| 843 | + $alias = ""; |
|
| 844 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 845 | + $oldcle = explode('.', $nfrom[6]); |
|
| 846 | + $oldcle = end($oldcle); |
|
| 847 | + $newcle = explode('.', $nfrom[4]); |
|
| 848 | + $newcle = end($newcle); |
|
| 849 | + if ($newcle != $oldcle) { |
|
| 850 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 851 | + // reprendre simplement ce AS |
|
| 852 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 853 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 854 | + $alias = ""; |
|
| 855 | + } else { |
|
| 856 | + $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 860 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 861 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 862 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 863 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 864 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 865 | + } |
|
| 866 | + $from = reinjecte_joint($afrom, $from); |
|
| 867 | + } |
|
| 868 | + $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 869 | + $r = sql_select($select, $from, $where, |
|
| 870 | + $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 871 | + unset($GLOBALS['debug']['aucasou']); |
|
| 872 | + |
|
| 873 | + return $r; |
|
| 874 | 874 | } |
| 875 | 875 | |
| 876 | 876 | /** |
@@ -881,20 +881,20 @@ discard block |
||
| 881 | 881 | * @return string |
| 882 | 882 | */ |
| 883 | 883 | function calculer_where_to_string($v, $join = 'AND') { |
| 884 | - if (empty($v)) { |
|
| 885 | - return ''; |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - if (!is_array($v)) { |
|
| 889 | - return $v; |
|
| 890 | - } else { |
|
| 891 | - $exp = ""; |
|
| 892 | - if (strtoupper($join) === 'AND') { |
|
| 893 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 894 | - } else { |
|
| 895 | - return $exp . join($join, $v); |
|
| 896 | - } |
|
| 897 | - } |
|
| 884 | + if (empty($v)) { |
|
| 885 | + return ''; |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + if (!is_array($v)) { |
|
| 889 | + return $v; |
|
| 890 | + } else { |
|
| 891 | + $exp = ""; |
|
| 892 | + if (strtoupper($join) === 'AND') { |
|
| 893 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 894 | + } else { |
|
| 895 | + return $exp . join($join, $v); |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | |
@@ -902,62 +902,62 @@ discard block |
||
| 902 | 902 | |
| 903 | 903 | // https://code.spip.net/@calculer_jointnul |
| 904 | 904 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 905 | - if (!is_array($exp)) { |
|
| 906 | - if ($equiv) { |
|
| 907 | - $exp = preg_replace($equiv, '', $exp); |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 911 | - } else { |
|
| 912 | - foreach ($exp as $v) { |
|
| 913 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 914 | - return true; |
|
| 915 | - } |
|
| 916 | - } |
|
| 917 | - |
|
| 918 | - return false; |
|
| 919 | - } |
|
| 905 | + if (!is_array($exp)) { |
|
| 906 | + if ($equiv) { |
|
| 907 | + $exp = preg_replace($equiv, '', $exp); |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 911 | + } else { |
|
| 912 | + foreach ($exp as $v) { |
|
| 913 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 914 | + return true; |
|
| 915 | + } |
|
| 916 | + } |
|
| 917 | + |
|
| 918 | + return false; |
|
| 919 | + } |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | // https://code.spip.net/@reinjecte_joint |
| 923 | 923 | function reinjecte_joint($afrom, $from) { |
| 924 | - $from_synth = array(); |
|
| 925 | - foreach ($from as $k => $v) { |
|
| 926 | - $from_synth[$k] = $from[$k]; |
|
| 927 | - if (isset($afrom[$k])) { |
|
| 928 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 929 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 930 | - } |
|
| 931 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 932 | - unset($afrom[$k]); |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - return $from_synth; |
|
| 924 | + $from_synth = array(); |
|
| 925 | + foreach ($from as $k => $v) { |
|
| 926 | + $from_synth[$k] = $from[$k]; |
|
| 927 | + if (isset($afrom[$k])) { |
|
| 928 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 929 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 930 | + } |
|
| 931 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 932 | + unset($afrom[$k]); |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + return $from_synth; |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | // https://code.spip.net/@remplacer_jointnul |
| 940 | 940 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 941 | - if (!is_array($exp)) { |
|
| 942 | - return preg_replace($equiv, $cle, $exp); |
|
| 943 | - } else { |
|
| 944 | - foreach ($exp as $k => $v) { |
|
| 945 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - return $exp; |
|
| 949 | - } |
|
| 941 | + if (!is_array($exp)) { |
|
| 942 | + return preg_replace($equiv, $cle, $exp); |
|
| 943 | + } else { |
|
| 944 | + foreach ($exp as $k => $v) { |
|
| 945 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + return $exp; |
|
| 949 | + } |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | // calcul du nom du squelette |
| 953 | 953 | // https://code.spip.net/@calculer_nom_fonction_squel |
| 954 | 954 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', $connect = '') { |
| 955 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 956 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 957 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - return $mime_type |
|
| 961 | - . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 962 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 955 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 956 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 957 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + return $mime_type |
|
| 961 | + . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 962 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 963 | 963 | } |
@@ -654,6 +654,11 @@ discard block |
||
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | // https://code.spip.net/@calculer_critere_arg_dynamique |
| 657 | +/** |
|
| 658 | + * @param string $idb |
|
| 659 | + * |
|
| 660 | + * @return string |
|
| 661 | + */ |
|
| 657 | 662 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 658 | 663 | $boucle = $boucles[$idb]; |
| 659 | 664 | $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
@@ -1503,6 +1508,10 @@ discard block |
||
| 1503 | 1508 | } |
| 1504 | 1509 | |
| 1505 | 1510 | // https://code.spip.net/@critere_IN_cas |
| 1511 | +/** |
|
| 1512 | + * @param string $idb |
|
| 1513 | + * @param string $crit2 |
|
| 1514 | + */ |
|
| 1506 | 1515 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1507 | 1516 | static $num = array(); |
| 1508 | 1517 | $descr = $boucles[$idb]->descr; |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | + 'id_parent'; |
|
| 51 | 51 | |
| 52 | - $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 53 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 52 | + $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 53 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return void |
| 68 | 68 | **/ |
| 69 | 69 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 70 | - $not = $crit->not; |
|
| 71 | - $boucle = &$boucles[$idb]; |
|
| 72 | - $id = $boucle->primary; |
|
| 73 | - |
|
| 74 | - if ($not or !$id) { |
|
| 75 | - return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 76 | - } |
|
| 77 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | - $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 70 | + $not = $crit->not; |
|
| 71 | + $boucle = &$boucles[$idb]; |
|
| 72 | + $id = $boucle->primary; |
|
| 73 | + |
|
| 74 | + if ($not or !$id) { |
|
| 75 | + return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 76 | + } |
|
| 77 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | + $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -95,73 +95,73 @@ discard block |
||
| 95 | 95 | * @return void |
| 96 | 96 | **/ |
| 97 | 97 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 98 | - $boucle = &$boucles[$idb]; |
|
| 99 | - $primary = $boucle->primary; |
|
| 100 | - |
|
| 101 | - // la table nécessite une clé primaire, non composée |
|
| 102 | - if (!$primary or strpos($primary, ',')) { |
|
| 103 | - return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | - |
|
| 108 | - // le doublon s'applique sur un type de boucle (article) |
|
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | - |
|
| 111 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | - // on obtient $nom = "'article' . 'nom'" |
|
| 113 | - if (isset($crit->param[0])) { |
|
| 114 | - $nom .= "." . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | - |
|
| 121 | - // on crée un sql_in avec la clé primaire de la table |
|
| 122 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | - // $doublons et son index, ici $nom |
|
| 124 | - |
|
| 125 | - // debut du code "sql_in('articles.id_article', " |
|
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 130 | - |
|
| 131 | - // le debut complet du code des doublons |
|
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 133 | - |
|
| 134 | - // nom du doublon "('article' . 'nom')]" |
|
| 135 | - $fin_doub = "($nom)]"; |
|
| 136 | - |
|
| 137 | - // si on trouve un autre critère doublon, |
|
| 138 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | - foreach ($boucle->where as $k => $w) { |
|
| 140 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | - // fusionner le sql_in (du where) |
|
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | - $x = strpos($boucle->hash, $init_comment); |
|
| 145 | - $len = strlen($init_comment); |
|
| 146 | - $boucle->hash = |
|
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | - |
|
| 149 | - return; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | - $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 155 | - |
|
| 156 | - // déclarer le doublon s'il n'existe pas encore |
|
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | - # {!doublons A}{doublons B} |
|
| 163 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 98 | + $boucle = &$boucles[$idb]; |
|
| 99 | + $primary = $boucle->primary; |
|
| 100 | + |
|
| 101 | + // la table nécessite une clé primaire, non composée |
|
| 102 | + if (!$primary or strpos($primary, ',')) { |
|
| 103 | + return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | + |
|
| 108 | + // le doublon s'applique sur un type de boucle (article) |
|
| 109 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | + |
|
| 111 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | + // on obtient $nom = "'article' . 'nom'" |
|
| 113 | + if (isset($crit->param[0])) { |
|
| 114 | + $nom .= "." . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | + |
|
| 121 | + // on crée un sql_in avec la clé primaire de la table |
|
| 122 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | + // $doublons et son index, ici $nom |
|
| 124 | + |
|
| 125 | + // debut du code "sql_in('articles.id_article', " |
|
| 126 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 130 | + |
|
| 131 | + // le debut complet du code des doublons |
|
| 132 | + $debut_doub = $debut_in . $debut_doub; |
|
| 133 | + |
|
| 134 | + // nom du doublon "('article' . 'nom')]" |
|
| 135 | + $fin_doub = "($nom)]"; |
|
| 136 | + |
|
| 137 | + // si on trouve un autre critère doublon, |
|
| 138 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | + foreach ($boucle->where as $k => $w) { |
|
| 140 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | + // fusionner le sql_in (du where) |
|
| 142 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | + $x = strpos($boucle->hash, $init_comment); |
|
| 145 | + $len = strlen($init_comment); |
|
| 146 | + $boucle->hash = |
|
| 147 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | + |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | + $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 155 | + |
|
| 156 | + // déclarer le doublon s'il n'existe pas encore |
|
| 157 | + $boucle->hash .= $init_comment . $init_code; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | + # {!doublons A}{doublons B} |
|
| 163 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | * @return void |
| 183 | 183 | **/ |
| 184 | 184 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 185 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | - $param = 'oui'; |
|
| 187 | - } |
|
| 188 | - if ($crit->not) { |
|
| 189 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | - } |
|
| 191 | - $boucle = &$boucles[$idb]; |
|
| 192 | - $boucle->lang_select = $param; |
|
| 185 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | + $param = 'oui'; |
|
| 187 | + } |
|
| 188 | + if ($crit->not) { |
|
| 189 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | + } |
|
| 191 | + $boucle = &$boucles[$idb]; |
|
| 192 | + $boucle->lang_select = $param; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -211,18 +211,18 @@ discard block |
||
| 211 | 211 | * @return void |
| 212 | 212 | **/ |
| 213 | 213 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 214 | - list($un, $deux) = $crit->param; |
|
| 215 | - $un = $un[0]->texte; |
|
| 216 | - $deux = $deux[0]->texte; |
|
| 217 | - if ($deux) { |
|
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 222 | - '"'; |
|
| 223 | - } else { |
|
| 224 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | - } |
|
| 214 | + list($un, $deux) = $crit->param; |
|
| 215 | + $un = $un[0]->texte; |
|
| 216 | + $deux = $deux[0]->texte; |
|
| 217 | + if ($deux) { |
|
| 218 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | + $un . |
|
| 220 | + '"]) . ",' . |
|
| 221 | + $deux . |
|
| 222 | + '"'; |
|
| 223 | + } else { |
|
| 224 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
@@ -256,57 +256,57 @@ discard block |
||
| 256 | 256 | **/ |
| 257 | 257 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 258 | 258 | |
| 259 | - $boucle = &$boucles[$idb]; |
|
| 260 | - // definition de la taille de la page |
|
| 261 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | - : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 263 | - |
|
| 264 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | - } else { |
|
| 267 | - $r = intval($r[2]); |
|
| 268 | - $pas = strval($r ? $r : 10); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Calcul du nommage de la pagination si il existe. |
|
| 272 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | - $type = "'$idb'"; |
|
| 275 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | - // Syntaxe {pagination 20, nom} |
|
| 277 | - if (isset($crit->param[0][1])) { |
|
| 278 | - $type = calculer_liste(array($crit->param[0][1]), $idb, $boucles, $boucle->id_parent); |
|
| 279 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | - elseif (isset($crit->param[1][0])) { |
|
| 281 | - $type = calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | - $partie = |
|
| 287 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | - . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | - . "\t}\n" |
|
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | - |
|
| 295 | - $boucle->hash .= ' |
|
| 259 | + $boucle = &$boucles[$idb]; |
|
| 260 | + // definition de la taille de la page |
|
| 261 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | + : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 263 | + |
|
| 264 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | + } else { |
|
| 267 | + $r = intval($r[2]); |
|
| 268 | + $pas = strval($r ? $r : 10); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Calcul du nommage de la pagination si il existe. |
|
| 272 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | + $type = "'$idb'"; |
|
| 275 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | + // Syntaxe {pagination 20, nom} |
|
| 277 | + if (isset($crit->param[0][1])) { |
|
| 278 | + $type = calculer_liste(array($crit->param[0][1]), $idb, $boucles, $boucle->id_parent); |
|
| 279 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | + elseif (isset($crit->param[1][0])) { |
|
| 281 | + $type = calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | + $partie = |
|
| 287 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | + . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | + . "\t}\n" |
|
| 293 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | + |
|
| 295 | + $boucle->hash .= ' |
|
| 296 | 296 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 297 | 297 | |
| 298 | - $boucle->total_parties = $pas; |
|
| 299 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | - // sauf si pas de primaire, ou si primaire composee |
|
| 302 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | - if ($boucle->primary |
|
| 305 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | - and !in_array($t, $boucle->select) |
|
| 307 | - ) { |
|
| 308 | - $boucle->select[] = $t; |
|
| 309 | - } |
|
| 298 | + $boucle->total_parties = $pas; |
|
| 299 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | + // sauf si pas de primaire, ou si primaire composee |
|
| 302 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | + if ($boucle->primary |
|
| 305 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | + and !in_array($t, $boucle->select) |
|
| 307 | + ) { |
|
| 308 | + $boucle->select[] = $t; |
|
| 309 | + } |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | |
@@ -328,24 +328,24 @@ discard block |
||
| 328 | 328 | **/ |
| 329 | 329 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 330 | 330 | |
| 331 | - $boucle = &$boucles[$idb]; |
|
| 331 | + $boucle = &$boucles[$idb]; |
|
| 332 | 332 | |
| 333 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere' => 'recherche')), $boucle); |
|
| 333 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere' => 'recherche')), $boucle); |
|
| 335 | 335 | |
| 336 | - return; |
|
| 337 | - } |
|
| 336 | + return; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if (isset($crit->param[0])) { |
|
| 340 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | - } else { |
|
| 342 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | - } |
|
| 339 | + if (isset($crit->param[0])) { |
|
| 340 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | + } else { |
|
| 342 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | - $boucle->hash .= ' |
|
| 345 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | + $boucle->hash .= ' |
|
| 347 | 347 | // RECHERCHE' |
| 348 | - . ($crit->cond ? ' |
|
| 348 | + . ($crit->cond ? ' |
|
| 349 | 349 | if (!strlen(' . $quoi . ')){ |
| 350 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | 351 | } else' : '') . ' |
@@ -356,21 +356,21 @@ discard block |
||
| 356 | 356 | '; |
| 357 | 357 | |
| 358 | 358 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | - $boucle->select[] = $t; |
|
| 362 | - } # pour postgres, neuneu ici |
|
| 363 | - // jointure uniquement sur le serveur principal |
|
| 364 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | - if (!$boucle->sql_serveur) { |
|
| 366 | - $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 367 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | - } |
|
| 369 | - $boucle->select[] = '$rech_select'; |
|
| 370 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | - |
|
| 372 | - // et la recherche trouve |
|
| 373 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 359 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | + $boucle->select[] = $t; |
|
| 362 | + } # pour postgres, neuneu ici |
|
| 363 | + // jointure uniquement sur le serveur principal |
|
| 364 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | + if (!$boucle->sql_serveur) { |
|
| 366 | + $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 367 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | + } |
|
| 369 | + $boucle->select[] = '$rech_select'; |
|
| 370 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | + |
|
| 372 | + // et la recherche trouve |
|
| 373 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -387,25 +387,25 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | **/ |
| 389 | 389 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 390 | - $boucle = &$boucles[$idb]; |
|
| 391 | - $prim = $boucle->primary; |
|
| 392 | - $table = $boucle->id_table; |
|
| 393 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | - $boucle->where[] = |
|
| 396 | - array( |
|
| 397 | - "'OR'", |
|
| 398 | - array( |
|
| 399 | - "'AND'", |
|
| 400 | - array("'='", "'$table.id_trad'", 0), |
|
| 401 | - array("'='", "'$table.$prim'", $dprim) |
|
| 402 | - ), |
|
| 403 | - array( |
|
| 404 | - "'AND'", |
|
| 405 | - array("'>'", "'$table.id_trad'", 0), |
|
| 406 | - array("'='", "'$table.id_trad'", $arg) |
|
| 407 | - ) |
|
| 408 | - ); |
|
| 390 | + $boucle = &$boucles[$idb]; |
|
| 391 | + $prim = $boucle->primary; |
|
| 392 | + $table = $boucle->id_table; |
|
| 393 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | + $boucle->where[] = |
|
| 396 | + array( |
|
| 397 | + "'OR'", |
|
| 398 | + array( |
|
| 399 | + "'AND'", |
|
| 400 | + array("'='", "'$table.id_trad'", 0), |
|
| 401 | + array("'='", "'$table.$prim'", $dprim) |
|
| 402 | + ), |
|
| 403 | + array( |
|
| 404 | + "'AND'", |
|
| 405 | + array("'>'", "'$table.id_trad'", 0), |
|
| 406 | + array("'='", "'$table.id_trad'", $arg) |
|
| 407 | + ) |
|
| 408 | + ); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return void |
| 424 | 424 | **/ |
| 425 | 425 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 426 | - $boucle = &$boucles[$idb]; |
|
| 427 | - $prim = $boucle->primary; |
|
| 428 | - $table = $boucle->id_table; |
|
| 429 | - |
|
| 430 | - $c = |
|
| 431 | - array( |
|
| 432 | - "'OR'", |
|
| 433 | - array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 434 | - array("'='", "'$table.id_trad'", "'0'") |
|
| 435 | - ); |
|
| 436 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 426 | + $boucle = &$boucles[$idb]; |
|
| 427 | + $prim = $boucle->primary; |
|
| 428 | + $table = $boucle->id_table; |
|
| 429 | + |
|
| 430 | + $c = |
|
| 431 | + array( |
|
| 432 | + "'OR'", |
|
| 433 | + array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 434 | + array("'='", "'$table.id_trad'", "'0'") |
|
| 435 | + ); |
|
| 436 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -450,20 +450,20 @@ discard block |
||
| 450 | 450 | **/ |
| 451 | 451 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 452 | 452 | |
| 453 | - $boucle = &$boucles[$idb]; |
|
| 454 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 456 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | - 'id_parent'; |
|
| 458 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + $boucle = &$boucles[$idb]; |
|
| 454 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 456 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | + 'id_parent'; |
|
| 458 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 459 | 459 | |
| 460 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 461 | - $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 460 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 461 | + $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 462 | 462 | |
| 463 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | - else { |
|
| 465 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 466 | - } |
|
| 463 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | + else { |
|
| 465 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -494,37 +494,37 @@ discard block |
||
| 494 | 494 | **/ |
| 495 | 495 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 496 | 496 | |
| 497 | - $not = $crit->not; |
|
| 498 | - $boucle = &$boucles[$idb]; |
|
| 499 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | - if (isset($crit->param[0])) { |
|
| 501 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 502 | - // sinon on le prend chez une boucle parente |
|
| 503 | - } else { |
|
| 504 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - //Trouver une jointure |
|
| 508 | - $champ = "id_rubrique"; |
|
| 509 | - $desc = $boucle->show; |
|
| 510 | - //Seulement si necessaire |
|
| 511 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | - $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 514 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | - $decompose = decompose_champ_id_objet($champ); |
|
| 517 | - $champ = array_shift($decompose); |
|
| 518 | - $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 519 | - } |
|
| 520 | - } else { |
|
| 521 | - $cle = $boucle->id_table; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 497 | + $not = $crit->not; |
|
| 498 | + $boucle = &$boucles[$idb]; |
|
| 499 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | + if (isset($crit->param[0])) { |
|
| 501 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 502 | + // sinon on le prend chez une boucle parente |
|
| 503 | + } else { |
|
| 504 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + //Trouver une jointure |
|
| 508 | + $champ = "id_rubrique"; |
|
| 509 | + $desc = $boucle->show; |
|
| 510 | + //Seulement si necessaire |
|
| 511 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | + $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 514 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | + $decompose = decompose_champ_id_objet($champ); |
|
| 517 | + $champ = array_shift($decompose); |
|
| 518 | + $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 519 | + } |
|
| 520 | + } else { |
|
| 521 | + $cle = $boucle->id_table; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | + . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -540,15 +540,15 @@ discard block |
||
| 540 | 540 | **/ |
| 541 | 541 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 542 | 542 | |
| 543 | - $boucle = &$boucles[$idb]; |
|
| 544 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | - $serveur = $boucle->sql_serveur; |
|
| 543 | + $boucle = &$boucles[$idb]; |
|
| 544 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | + $serveur = $boucle->sql_serveur; |
|
| 546 | 546 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 547 | + $c = "sql_in('" . |
|
| 548 | + $boucle->id_table . '.' . $boucle->primary |
|
| 549 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 550 | 550 | |
| 551 | - $boucle->where[] = $c; |
|
| 551 | + $boucle->where[] = $c; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -570,31 +570,31 @@ discard block |
||
| 570 | 570 | * @return void |
| 571 | 571 | **/ |
| 572 | 572 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 573 | - if ($t = isset($crit->param[0])) { |
|
| 574 | - $t = $crit->param[0]; |
|
| 575 | - if ($t[0]->type == 'texte') { |
|
| 576 | - $t = $t[0]->texte; |
|
| 577 | - if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 578 | - $t = table_objet_sql($r[1]); |
|
| 579 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | - if ($t) { |
|
| 581 | - $t .= '.' . $r[2]; |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - } else { |
|
| 585 | - $t = '".' |
|
| 586 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | - . '."'; |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - if ($t) { |
|
| 591 | - $boucles[$idb]->group[] = $t; |
|
| 592 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | - $boucles[$idb]->select[] = $t; |
|
| 594 | - } |
|
| 595 | - } else { |
|
| 596 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 597 | - } |
|
| 573 | + if ($t = isset($crit->param[0])) { |
|
| 574 | + $t = $crit->param[0]; |
|
| 575 | + if ($t[0]->type == 'texte') { |
|
| 576 | + $t = $t[0]->texte; |
|
| 577 | + if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 578 | + $t = table_objet_sql($r[1]); |
|
| 579 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | + if ($t) { |
|
| 581 | + $t .= '.' . $r[2]; |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + } else { |
|
| 585 | + $t = '".' |
|
| 586 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | + . '."'; |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + if ($t) { |
|
| 591 | + $boucles[$idb]->group[] = $t; |
|
| 592 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | + $boucles[$idb]->select[] = $t; |
|
| 594 | + } |
|
| 595 | + } else { |
|
| 596 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 597 | + } |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -631,45 +631,45 @@ discard block |
||
| 631 | 631 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 632 | 632 | */ |
| 633 | 633 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 634 | - if (isset($crit->param[0])) { |
|
| 635 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 636 | - $boucle = $boucles[$idb]; |
|
| 637 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 638 | - $n = count($boucle->order); |
|
| 639 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 640 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 641 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 642 | - if ( |
|
| 643 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 644 | - OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 645 | - ) { |
|
| 646 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 647 | - } else { |
|
| 648 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } else { |
|
| 652 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 653 | - } |
|
| 634 | + if (isset($crit->param[0])) { |
|
| 635 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 636 | + $boucle = $boucles[$idb]; |
|
| 637 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 638 | + $n = count($boucle->order); |
|
| 639 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 640 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 641 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 642 | + if ( |
|
| 643 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 644 | + OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 645 | + ) { |
|
| 646 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 647 | + } else { |
|
| 648 | + $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } else { |
|
| 652 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 653 | + } |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | // https://code.spip.net/@calculer_critere_arg_dynamique |
| 657 | 657 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 658 | - $boucle = $boucles[$idb]; |
|
| 659 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | - $var = '$champs_' . $idb; |
|
| 661 | - $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 662 | - if (!$desc) { |
|
| 663 | - $desc = $boucle->show['field']; |
|
| 664 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 665 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 666 | - } |
|
| 667 | - if ($desc) { |
|
| 668 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 669 | - } |
|
| 670 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 671 | - |
|
| 672 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 658 | + $boucle = $boucles[$idb]; |
|
| 659 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | + $var = '$champs_' . $idb; |
|
| 661 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 662 | + if (!$desc) { |
|
| 663 | + $desc = $boucle->show['field']; |
|
| 664 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 665 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 666 | + } |
|
| 667 | + if ($desc) { |
|
| 668 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 669 | + } |
|
| 670 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 671 | + |
|
| 672 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 709 | 709 | */ |
| 710 | 710 | function critere_par_dist($idb, &$boucles, $crit) { |
| 711 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 711 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | /** |
@@ -730,93 +730,93 @@ discard block |
||
| 730 | 730 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 731 | 731 | */ |
| 732 | 732 | function critere_parinverse($idb, &$boucles, $crit) { |
| 733 | - $boucle = &$boucles[$idb]; |
|
| 734 | - |
|
| 735 | - $sens = $collecte = ''; |
|
| 736 | - if ($crit->not) { |
|
| 737 | - $sens = " . ' DESC'"; |
|
| 738 | - } |
|
| 739 | - if (isset($boucle->modificateur['collate'])) { |
|
| 740 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // Pour chaque paramètre du critère |
|
| 744 | - foreach ($crit->param as $tri) { |
|
| 745 | - $order = $fct = ''; |
|
| 746 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 747 | - if ($tri[0]->type != 'texte') { |
|
| 748 | - // calculer le order dynamique qui verifie les champs |
|
| 749 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 750 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 751 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 752 | - } |
|
| 753 | - // tris textuels {par titre} |
|
| 754 | - else { |
|
| 755 | - $par = array_shift($tri); |
|
| 756 | - $par = $par->texte; |
|
| 757 | - |
|
| 758 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 759 | - if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 760 | - $expression = trim($m[1]); |
|
| 761 | - $champ = trim($m[2]); |
|
| 762 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 763 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 764 | - } else { |
|
| 765 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 769 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 770 | - // {par FONCTION(champ)} |
|
| 771 | - if (count($match) > 2) { |
|
| 772 | - $par = substr($match[2], 1, -1); |
|
| 773 | - $fct = $match[1]; |
|
| 774 | - } |
|
| 775 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 776 | - if ($par == 'hasard') { |
|
| 777 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 778 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 779 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 780 | - } else { |
|
| 781 | - // cas général {par champ}, {par table.champ}, ... |
|
| 782 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - // on ne sait pas traiter… |
|
| 787 | - else { |
|
| 788 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 792 | - if (is_array($order)) { |
|
| 793 | - return $order; |
|
| 794 | - } |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 798 | - $t = $m[1]; |
|
| 799 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 800 | - $boucle->select[] = $t; |
|
| 801 | - } |
|
| 802 | - } else { |
|
| 803 | - $sens = ''; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - if ($fct) { |
|
| 807 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 808 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 809 | - } else { |
|
| 810 | - $order = "'$fct(' . $order . ')'"; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - $t = $order . $collecte . $sens; |
|
| 814 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 815 | - $t = $r[1] . $r[2]; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - $boucle->order[] = $t; |
|
| 819 | - } |
|
| 733 | + $boucle = &$boucles[$idb]; |
|
| 734 | + |
|
| 735 | + $sens = $collecte = ''; |
|
| 736 | + if ($crit->not) { |
|
| 737 | + $sens = " . ' DESC'"; |
|
| 738 | + } |
|
| 739 | + if (isset($boucle->modificateur['collate'])) { |
|
| 740 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // Pour chaque paramètre du critère |
|
| 744 | + foreach ($crit->param as $tri) { |
|
| 745 | + $order = $fct = ''; |
|
| 746 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 747 | + if ($tri[0]->type != 'texte') { |
|
| 748 | + // calculer le order dynamique qui verifie les champs |
|
| 749 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 750 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 751 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 752 | + } |
|
| 753 | + // tris textuels {par titre} |
|
| 754 | + else { |
|
| 755 | + $par = array_shift($tri); |
|
| 756 | + $par = $par->texte; |
|
| 757 | + |
|
| 758 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 759 | + if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 760 | + $expression = trim($m[1]); |
|
| 761 | + $champ = trim($m[2]); |
|
| 762 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 763 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 764 | + } else { |
|
| 765 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 769 | + } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 770 | + // {par FONCTION(champ)} |
|
| 771 | + if (count($match) > 2) { |
|
| 772 | + $par = substr($match[2], 1, -1); |
|
| 773 | + $fct = $match[1]; |
|
| 774 | + } |
|
| 775 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 776 | + if ($par == 'hasard') { |
|
| 777 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 778 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 779 | + $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 780 | + } else { |
|
| 781 | + // cas général {par champ}, {par table.champ}, ... |
|
| 782 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + // on ne sait pas traiter… |
|
| 787 | + else { |
|
| 788 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 792 | + if (is_array($order)) { |
|
| 793 | + return $order; |
|
| 794 | + } |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 798 | + $t = $m[1]; |
|
| 799 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 800 | + $boucle->select[] = $t; |
|
| 801 | + } |
|
| 802 | + } else { |
|
| 803 | + $sens = ''; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + if ($fct) { |
|
| 807 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 808 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 809 | + } else { |
|
| 810 | + $order = "'$fct(' . $order . ')'"; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + $t = $order . $collecte . $sens; |
|
| 814 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 815 | + $t = $r[1] . $r[2]; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + $boucle->order[] = $t; |
|
| 819 | + } |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -830,13 +830,13 @@ discard block |
||
| 830 | 830 | * @return string Clause pour le Order by |
| 831 | 831 | */ |
| 832 | 832 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 833 | - $boucle = &$boucles[$idb]; |
|
| 834 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 835 | - $parha = "rand() AS hasard"; |
|
| 836 | - if (!in_array($parha, $boucle->select)) { |
|
| 837 | - $boucle->select[] = $parha; |
|
| 838 | - } |
|
| 839 | - return "'hasard'"; |
|
| 833 | + $boucle = &$boucles[$idb]; |
|
| 834 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 835 | + $parha = "rand() AS hasard"; |
|
| 836 | + if (!in_array($parha, $boucle->select)) { |
|
| 837 | + $boucle->select[] = $parha; |
|
| 838 | + } |
|
| 839 | + return "'hasard'"; |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -860,20 +860,20 @@ discard block |
||
| 860 | 860 | * @return string Clause pour le Order by |
| 861 | 861 | */ |
| 862 | 862 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 863 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 864 | - if (is_array($_champ)) { |
|
| 865 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 866 | - } |
|
| 867 | - $boucle = &$boucles[$idb]; |
|
| 868 | - $texte = '0+' . $_champ; |
|
| 869 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 870 | - if ($suite !== "''") { |
|
| 871 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 872 | - } |
|
| 873 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | - $boucle->select[] = $texte . " AS $as"; |
|
| 875 | - $order = "'$as'"; |
|
| 876 | - return $order; |
|
| 863 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 864 | + if (is_array($_champ)) { |
|
| 865 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 866 | + } |
|
| 867 | + $boucle = &$boucles[$idb]; |
|
| 868 | + $texte = '0+' . $_champ; |
|
| 869 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 870 | + if ($suite !== "''") { |
|
| 871 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 872 | + } |
|
| 873 | + $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | + $boucle->select[] = $texte . " AS $as"; |
|
| 875 | + $order = "'$as'"; |
|
| 876 | + return $order; |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | /** |
@@ -894,20 +894,20 @@ discard block |
||
| 894 | 894 | * @return string Clause pour le Order by |
| 895 | 895 | */ |
| 896 | 896 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 897 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 898 | - if (is_array($_champ)) { |
|
| 899 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 900 | - } |
|
| 901 | - $boucle = &$boucles[$idb]; |
|
| 902 | - $texte = '0+' . $_champ; |
|
| 903 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 904 | - if ($suite !== "''") { |
|
| 905 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 906 | - } |
|
| 907 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 909 | - $order = "'$as'"; |
|
| 910 | - return $order; |
|
| 897 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 898 | + if (is_array($_champ)) { |
|
| 899 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 900 | + } |
|
| 901 | + $boucle = &$boucles[$idb]; |
|
| 902 | + $texte = '0+' . $_champ; |
|
| 903 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 904 | + if ($suite !== "''") { |
|
| 905 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 906 | + } |
|
| 907 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | + $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 909 | + $order = "'$as'"; |
|
| 910 | + return $order; |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | |
@@ -927,14 +927,14 @@ discard block |
||
| 927 | 927 | * @return string Clause pour le Order by |
| 928 | 928 | */ |
| 929 | 929 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 930 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 931 | - if (is_array($_champ)) { |
|
| 932 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 933 | - } |
|
| 934 | - $boucle = &$boucles[$idb]; |
|
| 935 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 936 | - $order = "'multi'"; |
|
| 937 | - return $order; |
|
| 930 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 931 | + if (is_array($_champ)) { |
|
| 932 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 933 | + } |
|
| 934 | + $boucle = &$boucles[$idb]; |
|
| 935 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 936 | + $order = "'multi'"; |
|
| 937 | + return $order; |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | /** |
@@ -953,56 +953,56 @@ discard block |
||
| 953 | 953 | * @return array|string |
| 954 | 954 | */ |
| 955 | 955 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 956 | - $boucle = &$boucles[$idb]; |
|
| 957 | - $desc = $boucle->show; |
|
| 958 | - |
|
| 959 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 960 | - if (isset($desc['field'][$par])) { |
|
| 961 | - $par = $boucle->id_table . "." . $par; |
|
| 962 | - } |
|
| 963 | - // le champ est peut être une jointure |
|
| 964 | - else { |
|
| 965 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 966 | - $champ = $par; |
|
| 967 | - |
|
| 968 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 969 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 970 | - list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 971 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 972 | - elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 973 | - list(, $table, $champ) = $r; |
|
| 974 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 975 | - $table = table_objet_sql($table); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 979 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 980 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 981 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 982 | - $par = $infos['alias'] . "." . $champ; |
|
| 983 | - } elseif ( |
|
| 984 | - $boucle->jointures_explicites |
|
| 985 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 986 | - ) { |
|
| 987 | - $par = $alias . "." . $champ; |
|
| 988 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 989 | - $par = $alias . "." . $champ; |
|
| 990 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 991 | - } elseif ( |
|
| 992 | - $table_alias |
|
| 993 | - and isset($boucle->from[$table_alias]) |
|
| 994 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 995 | - ) { |
|
| 996 | - $par = $infos['alias'] . "." . $champ; |
|
| 997 | - } elseif ($table) { |
|
| 998 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 999 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1000 | - } else { |
|
| 1001 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - return $raw ? $par : "'$par'"; |
|
| 956 | + $boucle = &$boucles[$idb]; |
|
| 957 | + $desc = $boucle->show; |
|
| 958 | + |
|
| 959 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 960 | + if (isset($desc['field'][$par])) { |
|
| 961 | + $par = $boucle->id_table . "." . $par; |
|
| 962 | + } |
|
| 963 | + // le champ est peut être une jointure |
|
| 964 | + else { |
|
| 965 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 966 | + $champ = $par; |
|
| 967 | + |
|
| 968 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 969 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 970 | + list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 971 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 972 | + elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 973 | + list(, $table, $champ) = $r; |
|
| 974 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 975 | + $table = table_objet_sql($table); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 979 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 980 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 981 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 982 | + $par = $infos['alias'] . "." . $champ; |
|
| 983 | + } elseif ( |
|
| 984 | + $boucle->jointures_explicites |
|
| 985 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 986 | + ) { |
|
| 987 | + $par = $alias . "." . $champ; |
|
| 988 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 989 | + $par = $alias . "." . $champ; |
|
| 990 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 991 | + } elseif ( |
|
| 992 | + $table_alias |
|
| 993 | + and isset($boucle->from[$table_alias]) |
|
| 994 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 995 | + ) { |
|
| 996 | + $par = $infos['alias'] . "." . $champ; |
|
| 997 | + } elseif ($table) { |
|
| 998 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 999 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1000 | + } else { |
|
| 1001 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + return $raw ? $par : "'$par'"; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
@@ -1016,11 +1016,11 @@ discard block |
||
| 1016 | 1016 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1017 | 1017 | */ |
| 1018 | 1018 | function critere_par_joint($table, $champ, &$boucle) { |
| 1019 | - $t = array_search($table, $boucle->from); |
|
| 1020 | - if (!$t) { |
|
| 1021 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1022 | - } |
|
| 1023 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1019 | + $t = array_search($table, $boucle->from); |
|
| 1020 | + if (!$t) { |
|
| 1021 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1022 | + } |
|
| 1023 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /** |
@@ -1045,143 +1045,143 @@ discard block |
||
| 1045 | 1045 | */ |
| 1046 | 1046 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1047 | 1047 | |
| 1048 | - $boucle = &$boucles[$idb]; |
|
| 1049 | - // Classement par ordre inverse |
|
| 1050 | - if ($crit->not) { |
|
| 1051 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1052 | - } else { |
|
| 1053 | - $order = "' DESC'"; |
|
| 1054 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1055 | - if (isset($crit->param[0])) { |
|
| 1056 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1057 | - $order = "(($critere)?' DESC':'')"; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - $n = count($boucle->order); |
|
| 1061 | - if (!$n) { |
|
| 1062 | - if (isset($boucle->default_order[0])) { |
|
| 1063 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1064 | - } else { |
|
| 1065 | - $boucle->default_order[] = ' DESC'; |
|
| 1066 | - } |
|
| 1067 | - } else { |
|
| 1068 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1069 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1070 | - $t = $r[1] . $r[2]; |
|
| 1071 | - } |
|
| 1072 | - $boucle->order[$n - 1] = $t; |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1048 | + $boucle = &$boucles[$idb]; |
|
| 1049 | + // Classement par ordre inverse |
|
| 1050 | + if ($crit->not) { |
|
| 1051 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1052 | + } else { |
|
| 1053 | + $order = "' DESC'"; |
|
| 1054 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1055 | + if (isset($crit->param[0])) { |
|
| 1056 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1057 | + $order = "(($critere)?' DESC':'')"; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + $n = count($boucle->order); |
|
| 1061 | + if (!$n) { |
|
| 1062 | + if (isset($boucle->default_order[0])) { |
|
| 1063 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1064 | + } else { |
|
| 1065 | + $boucle->default_order[] = ' DESC'; |
|
| 1066 | + } |
|
| 1067 | + } else { |
|
| 1068 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1069 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1070 | + $t = $r[1] . $r[2]; |
|
| 1071 | + } |
|
| 1072 | + $boucle->order[$n - 1] = $t; |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | // https://code.spip.net/@critere_agenda_dist |
| 1078 | 1078 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1079 | - $params = $crit->param; |
|
| 1080 | - |
|
| 1081 | - if (count($params) < 1) { |
|
| 1082 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - $boucle = &$boucles[$idb]; |
|
| 1086 | - $parent = $boucle->id_parent; |
|
| 1087 | - $fields = $boucle->show['field']; |
|
| 1088 | - |
|
| 1089 | - $date = array_shift($params); |
|
| 1090 | - $type = array_shift($params); |
|
| 1091 | - |
|
| 1092 | - // la valeur $type doit etre connue a la compilation |
|
| 1093 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1094 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1095 | - |
|
| 1096 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1097 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1098 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1099 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1100 | - if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1101 | - $date = $date[0]->texte; |
|
| 1102 | - if (!isset($fields[$date])) { |
|
| 1103 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1104 | - } |
|
| 1105 | - } else { |
|
| 1106 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1107 | - $noms = array_keys($fields); |
|
| 1108 | - $defaut = $noms[0]; |
|
| 1109 | - $noms = join(" ", $noms); |
|
| 1110 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1111 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1112 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1113 | - } |
|
| 1114 | - $annee = $params ? array_shift($params) : ""; |
|
| 1115 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1117 | - ') ? $x : date("Y"))'; |
|
| 1118 | - |
|
| 1119 | - $mois = $params ? array_shift($params) : ""; |
|
| 1120 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1122 | - ') ? $x : date("m"))'; |
|
| 1123 | - |
|
| 1124 | - $jour = $params ? array_shift($params) : ""; |
|
| 1125 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1127 | - ') ? $x : date("d"))'; |
|
| 1128 | - |
|
| 1129 | - $annee2 = $params ? array_shift($params) : ""; |
|
| 1130 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1132 | - ') ? $x : date("Y"))'; |
|
| 1133 | - |
|
| 1134 | - $mois2 = $params ? array_shift($params) : ""; |
|
| 1135 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1137 | - ') ? $x : date("m"))'; |
|
| 1138 | - |
|
| 1139 | - $jour2 = $params ? array_shift($params) : ""; |
|
| 1140 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1142 | - ') ? $x : date("d"))'; |
|
| 1143 | - |
|
| 1144 | - $date = $boucle->id_table . ".$date"; |
|
| 1145 | - |
|
| 1146 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1147 | - if ($type == 'jour') { |
|
| 1148 | - $boucle->where[] = array( |
|
| 1149 | - "'='", |
|
| 1150 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1151 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1152 | - ); |
|
| 1153 | - } elseif ($type == 'mois') { |
|
| 1154 | - $boucle->where[] = array( |
|
| 1155 | - "'='", |
|
| 1156 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1157 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1158 | - ); |
|
| 1159 | - } elseif ($type == 'semaine') { |
|
| 1160 | - $boucle->where[] = array( |
|
| 1161 | - "'AND'", |
|
| 1162 | - array( |
|
| 1163 | - "'>='", |
|
| 1164 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1165 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1166 | - ), |
|
| 1167 | - array( |
|
| 1168 | - "'<='", |
|
| 1169 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1170 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1171 | - ) |
|
| 1172 | - ); |
|
| 1173 | - } elseif (count($crit->param) > 2) { |
|
| 1174 | - $boucle->where[] = array( |
|
| 1175 | - "'AND'", |
|
| 1176 | - array( |
|
| 1177 | - "'>='", |
|
| 1178 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1179 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1180 | - ), |
|
| 1181 | - array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1182 | - ); |
|
| 1183 | - } |
|
| 1184 | - // sinon on prend tout |
|
| 1079 | + $params = $crit->param; |
|
| 1080 | + |
|
| 1081 | + if (count($params) < 1) { |
|
| 1082 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + $boucle = &$boucles[$idb]; |
|
| 1086 | + $parent = $boucle->id_parent; |
|
| 1087 | + $fields = $boucle->show['field']; |
|
| 1088 | + |
|
| 1089 | + $date = array_shift($params); |
|
| 1090 | + $type = array_shift($params); |
|
| 1091 | + |
|
| 1092 | + // la valeur $type doit etre connue a la compilation |
|
| 1093 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1094 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1095 | + |
|
| 1096 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1097 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1098 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1099 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1100 | + if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1101 | + $date = $date[0]->texte; |
|
| 1102 | + if (!isset($fields[$date])) { |
|
| 1103 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1104 | + } |
|
| 1105 | + } else { |
|
| 1106 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1107 | + $noms = array_keys($fields); |
|
| 1108 | + $defaut = $noms[0]; |
|
| 1109 | + $noms = join(" ", $noms); |
|
| 1110 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1111 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1112 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1113 | + } |
|
| 1114 | + $annee = $params ? array_shift($params) : ""; |
|
| 1115 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1117 | + ') ? $x : date("Y"))'; |
|
| 1118 | + |
|
| 1119 | + $mois = $params ? array_shift($params) : ""; |
|
| 1120 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1122 | + ') ? $x : date("m"))'; |
|
| 1123 | + |
|
| 1124 | + $jour = $params ? array_shift($params) : ""; |
|
| 1125 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1127 | + ') ? $x : date("d"))'; |
|
| 1128 | + |
|
| 1129 | + $annee2 = $params ? array_shift($params) : ""; |
|
| 1130 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1132 | + ') ? $x : date("Y"))'; |
|
| 1133 | + |
|
| 1134 | + $mois2 = $params ? array_shift($params) : ""; |
|
| 1135 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1137 | + ') ? $x : date("m"))'; |
|
| 1138 | + |
|
| 1139 | + $jour2 = $params ? array_shift($params) : ""; |
|
| 1140 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1142 | + ') ? $x : date("d"))'; |
|
| 1143 | + |
|
| 1144 | + $date = $boucle->id_table . ".$date"; |
|
| 1145 | + |
|
| 1146 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1147 | + if ($type == 'jour') { |
|
| 1148 | + $boucle->where[] = array( |
|
| 1149 | + "'='", |
|
| 1150 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1151 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1152 | + ); |
|
| 1153 | + } elseif ($type == 'mois') { |
|
| 1154 | + $boucle->where[] = array( |
|
| 1155 | + "'='", |
|
| 1156 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1157 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1158 | + ); |
|
| 1159 | + } elseif ($type == 'semaine') { |
|
| 1160 | + $boucle->where[] = array( |
|
| 1161 | + "'AND'", |
|
| 1162 | + array( |
|
| 1163 | + "'>='", |
|
| 1164 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1165 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1166 | + ), |
|
| 1167 | + array( |
|
| 1168 | + "'<='", |
|
| 1169 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1170 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1171 | + ) |
|
| 1172 | + ); |
|
| 1173 | + } elseif (count($crit->param) > 2) { |
|
| 1174 | + $boucle->where[] = array( |
|
| 1175 | + "'AND'", |
|
| 1176 | + array( |
|
| 1177 | + "'>='", |
|
| 1178 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1179 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1180 | + ), |
|
| 1181 | + array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1182 | + ); |
|
| 1183 | + } |
|
| 1184 | + // sinon on prend tout |
|
| 1185 | 1185 | } |
| 1186 | 1186 | |
| 1187 | 1187 | |
@@ -1206,33 +1206,33 @@ discard block |
||
| 1206 | 1206 | * @return void |
| 1207 | 1207 | **/ |
| 1208 | 1208 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1209 | - $boucle = &$boucles[$idb]; |
|
| 1210 | - $a1 = $crit->param[0]; |
|
| 1211 | - $a2 = $crit->param[1]; |
|
| 1212 | - $op = $crit->op; |
|
| 1213 | - |
|
| 1214 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1215 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1216 | - |
|
| 1217 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1218 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1219 | - } else { |
|
| 1220 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1221 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1222 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1223 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1224 | - $mode = (($op == '/') ? '/' : |
|
| 1225 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1226 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1227 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1228 | - $boucle->limit = |
|
| 1229 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1230 | - . ".','." |
|
| 1231 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1232 | - } else { |
|
| 1233 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1234 | - } |
|
| 1235 | - } |
|
| 1209 | + $boucle = &$boucles[$idb]; |
|
| 1210 | + $a1 = $crit->param[0]; |
|
| 1211 | + $a2 = $crit->param[1]; |
|
| 1212 | + $op = $crit->op; |
|
| 1213 | + |
|
| 1214 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1215 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1216 | + |
|
| 1217 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1218 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1219 | + } else { |
|
| 1220 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1221 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1222 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1223 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1224 | + $mode = (($op == '/') ? '/' : |
|
| 1225 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1226 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1227 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1228 | + $boucle->limit = |
|
| 1229 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1230 | + . ".','." |
|
| 1231 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1232 | + } else { |
|
| 1233 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1234 | + } |
|
| 1235 | + } |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | /** |
@@ -1260,63 +1260,63 @@ discard block |
||
| 1260 | 1260 | * @return void |
| 1261 | 1261 | **/ |
| 1262 | 1262 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1263 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1264 | - |
|
| 1265 | - preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1266 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1267 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1268 | - // {1/3} |
|
| 1269 | - if ($op1 == '/') { |
|
| 1270 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1271 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | - "($total_parties ? $total_parties : 1)"; |
|
| 1273 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1274 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1275 | - } else { |
|
| 1276 | - // cas {n-1,x} |
|
| 1277 | - if ($op1 == '-') { |
|
| 1278 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - // cas {x,n-1} |
|
| 1282 | - if ($op2 == '-') { |
|
| 1283 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | - ($total_parties . ' - 1')); |
|
| 1286 | - } else { |
|
| 1287 | - // {x,1} ou {pagination} |
|
| 1288 | - $fin = '$debut_boucle' |
|
| 1289 | - . (is_numeric($total_parties) ? |
|
| 1290 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | - ('+' . $total_parties . ' - 1')); |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1295 | - if ($op1 == 'p') { |
|
| 1296 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1297 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1298 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1299 | - } |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - // Notes : |
|
| 1303 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1304 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1305 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1306 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1307 | - |
|
| 1308 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1309 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1310 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1311 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1312 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1313 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1314 | - . "\n\tif (\$debut_boucle>0" |
|
| 1315 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1316 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1317 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1318 | - |
|
| 1319 | - $boucles[$id_boucle]->partie = " |
|
| 1263 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1264 | + |
|
| 1265 | + preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1266 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1267 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1268 | + // {1/3} |
|
| 1269 | + if ($op1 == '/') { |
|
| 1270 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1271 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | + "($total_parties ? $total_parties : 1)"; |
|
| 1273 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1274 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1275 | + } else { |
|
| 1276 | + // cas {n-1,x} |
|
| 1277 | + if ($op1 == '-') { |
|
| 1278 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + // cas {x,n-1} |
|
| 1282 | + if ($op2 == '-') { |
|
| 1283 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | + ($total_parties . ' - 1')); |
|
| 1286 | + } else { |
|
| 1287 | + // {x,1} ou {pagination} |
|
| 1288 | + $fin = '$debut_boucle' |
|
| 1289 | + . (is_numeric($total_parties) ? |
|
| 1290 | + (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | + ('+' . $total_parties . ' - 1')); |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1295 | + if ($op1 == 'p') { |
|
| 1296 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1297 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1298 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1299 | + } |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + // Notes : |
|
| 1303 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1304 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1305 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1306 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1307 | + |
|
| 1308 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1309 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1310 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1311 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1312 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1313 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1314 | + . "\n\tif (\$debut_boucle>0" |
|
| 1315 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1316 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1317 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1318 | + |
|
| 1319 | + $boucles[$id_boucle]->partie = " |
|
| 1320 | 1320 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1321 | 1321 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1322 | 1322 | } |
@@ -1333,26 +1333,26 @@ discard block |
||
| 1333 | 1333 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1334 | 1334 | **/ |
| 1335 | 1335 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1336 | - if ($param[0]->type != 'texte') { |
|
| 1337 | - $a1 = calculer_liste(array($param[0]), $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1338 | - if (isset($param[1]->texte)) { |
|
| 1339 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1340 | - |
|
| 1341 | - return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1342 | - } else { |
|
| 1343 | - return array("intval($a1)", 0); |
|
| 1344 | - } |
|
| 1345 | - } else { |
|
| 1346 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1347 | - $a1 = $m[1]; |
|
| 1348 | - if (empty($m[3])) { |
|
| 1349 | - return array($a1, 0); |
|
| 1350 | - } elseif (!empty($m[4])) { |
|
| 1351 | - return array($a1, $m[4]); |
|
| 1352 | - } else { |
|
| 1353 | - return array($a1, calculer_liste(array($param[1]), $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1336 | + if ($param[0]->type != 'texte') { |
|
| 1337 | + $a1 = calculer_liste(array($param[0]), $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1338 | + if (isset($param[1]->texte)) { |
|
| 1339 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1340 | + |
|
| 1341 | + return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1342 | + } else { |
|
| 1343 | + return array("intval($a1)", 0); |
|
| 1344 | + } |
|
| 1345 | + } else { |
|
| 1346 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1347 | + $a1 = $m[1]; |
|
| 1348 | + if (empty($m[3])) { |
|
| 1349 | + return array($a1, 0); |
|
| 1350 | + } elseif (!empty($m[4])) { |
|
| 1351 | + return array($a1, $m[4]); |
|
| 1352 | + } else { |
|
| 1353 | + return array($a1, calculer_liste(array($param[1]), $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | 1358 | |
@@ -1379,47 +1379,47 @@ discard block |
||
| 1379 | 1379 | * array : Erreur sur un des critères |
| 1380 | 1380 | **/ |
| 1381 | 1381 | function calculer_criteres($idb, &$boucles) { |
| 1382 | - $msg = ''; |
|
| 1383 | - $boucle = $boucles[$idb]; |
|
| 1384 | - $table = strtoupper($boucle->type_requete); |
|
| 1385 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1386 | - |
|
| 1387 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1388 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1389 | - if (!is_array($boucle->criteres)) { |
|
| 1390 | - return array(); |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - foreach ($boucle->criteres as $crit) { |
|
| 1394 | - $critere = $crit->op; |
|
| 1395 | - // critere personnalise ? |
|
| 1396 | - if ( |
|
| 1397 | - (!$serveur or |
|
| 1398 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1399 | - and (!function_exists($f = $f . "_dist")) |
|
| 1400 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1401 | - and (!function_exists($f = $f . "_dist")) |
|
| 1402 | - ) |
|
| 1403 | - ) |
|
| 1404 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1405 | - and (!function_exists($f = $f . "_dist")) |
|
| 1406 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1407 | - and (!function_exists($f = $f . "_dist")) |
|
| 1408 | - ) { |
|
| 1409 | - // fonction critere standard |
|
| 1410 | - $f = $defaut; |
|
| 1411 | - } |
|
| 1412 | - // compile le critere |
|
| 1413 | - $res = $f($idb, $boucles, $crit); |
|
| 1414 | - |
|
| 1415 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1416 | - if (is_array($res)) { |
|
| 1417 | - $msg = $res; |
|
| 1418 | - erreur_squelette($msg, $boucle); |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - return $msg; |
|
| 1382 | + $msg = ''; |
|
| 1383 | + $boucle = $boucles[$idb]; |
|
| 1384 | + $table = strtoupper($boucle->type_requete); |
|
| 1385 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1386 | + |
|
| 1387 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1388 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1389 | + if (!is_array($boucle->criteres)) { |
|
| 1390 | + return array(); |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + foreach ($boucle->criteres as $crit) { |
|
| 1394 | + $critere = $crit->op; |
|
| 1395 | + // critere personnalise ? |
|
| 1396 | + if ( |
|
| 1397 | + (!$serveur or |
|
| 1398 | + ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1399 | + and (!function_exists($f = $f . "_dist")) |
|
| 1400 | + and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1401 | + and (!function_exists($f = $f . "_dist")) |
|
| 1402 | + ) |
|
| 1403 | + ) |
|
| 1404 | + and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1405 | + and (!function_exists($f = $f . "_dist")) |
|
| 1406 | + and (!function_exists($f = "critere_" . $critere)) |
|
| 1407 | + and (!function_exists($f = $f . "_dist")) |
|
| 1408 | + ) { |
|
| 1409 | + // fonction critere standard |
|
| 1410 | + $f = $defaut; |
|
| 1411 | + } |
|
| 1412 | + // compile le critere |
|
| 1413 | + $res = $f($idb, $boucles, $crit); |
|
| 1414 | + |
|
| 1415 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1416 | + if (is_array($res)) { |
|
| 1417 | + $msg = $res; |
|
| 1418 | + erreur_squelette($msg, $boucle); |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + return $msg; |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
@@ -1436,11 +1436,11 @@ discard block |
||
| 1436 | 1436 | * @return string Code compilé rééchappé |
| 1437 | 1437 | */ |
| 1438 | 1438 | function kwote($lisp, $serveur = '', $type = '') { |
| 1439 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1440 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1441 | - } else { |
|
| 1442 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1443 | - } |
|
| 1439 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1440 | + return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1441 | + } else { |
|
| 1442 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1443 | + } |
|
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | |
@@ -1459,85 +1459,85 @@ discard block |
||
| 1459 | 1459 | * @return void |
| 1460 | 1460 | **/ |
| 1461 | 1461 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1462 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1463 | - if (!$r) { |
|
| 1464 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1465 | - } |
|
| 1466 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1467 | - |
|
| 1468 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1469 | - |
|
| 1470 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1471 | - $where = $in; |
|
| 1472 | - if ($crit->cond) { |
|
| 1473 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1474 | - $where = array("'?'", $pred, $where, "''"); |
|
| 1475 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1476 | - { |
|
| 1477 | - $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1478 | - } |
|
| 1479 | - } |
|
| 1480 | - if ($crit->exclus) { |
|
| 1481 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1482 | - $where = array("'NOT'", $where); |
|
| 1483 | - } else |
|
| 1484 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1485 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1486 | - { |
|
| 1487 | - $where = array( |
|
| 1488 | - "'NOT'", |
|
| 1489 | - array( |
|
| 1490 | - "'IN'", |
|
| 1491 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1493 | - ) |
|
| 1494 | - ); |
|
| 1495 | - } |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - $boucles[$idb]->where[] = $where; |
|
| 1499 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1500 | - { |
|
| 1501 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1502 | - } |
|
| 1462 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1463 | + if (!$r) { |
|
| 1464 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1465 | + } |
|
| 1466 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1467 | + |
|
| 1468 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1469 | + |
|
| 1470 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1471 | + $where = $in; |
|
| 1472 | + if ($crit->cond) { |
|
| 1473 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1474 | + $where = array("'?'", $pred, $where, "''"); |
|
| 1475 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1476 | + { |
|
| 1477 | + $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | + if ($crit->exclus) { |
|
| 1481 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1482 | + $where = array("'NOT'", $where); |
|
| 1483 | + } else |
|
| 1484 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1485 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1486 | + { |
|
| 1487 | + $where = array( |
|
| 1488 | + "'NOT'", |
|
| 1489 | + array( |
|
| 1490 | + "'IN'", |
|
| 1491 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1493 | + ) |
|
| 1494 | + ); |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + $boucles[$idb]->where[] = $where; |
|
| 1499 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1500 | + { |
|
| 1501 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1502 | + } |
|
| 1503 | 1503 | } |
| 1504 | 1504 | |
| 1505 | 1505 | // https://code.spip.net/@critere_IN_cas |
| 1506 | 1506 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1507 | - static $num = array(); |
|
| 1508 | - $descr = $boucles[$idb]->descr; |
|
| 1509 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1510 | - |
|
| 1511 | - $var = '$in' . $cpt++; |
|
| 1512 | - $x = "\n\t$var = array();"; |
|
| 1513 | - foreach ($val as $k => $v) { |
|
| 1514 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1515 | - // optimiser le traitement des constantes |
|
| 1516 | - if (is_numeric($r[2])) { |
|
| 1517 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1518 | - } else { |
|
| 1519 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1520 | - } |
|
| 1521 | - } else { |
|
| 1522 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1523 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1524 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1525 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1526 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | - } |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - $boucles[$idb]->in .= $x; |
|
| 1531 | - |
|
| 1532 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1533 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1534 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1535 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1536 | - if (!$crit2) { |
|
| 1537 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1507 | + static $num = array(); |
|
| 1508 | + $descr = $boucles[$idb]->descr; |
|
| 1509 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1510 | + |
|
| 1511 | + $var = '$in' . $cpt++; |
|
| 1512 | + $x = "\n\t$var = array();"; |
|
| 1513 | + foreach ($val as $k => $v) { |
|
| 1514 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1515 | + // optimiser le traitement des constantes |
|
| 1516 | + if (is_numeric($r[2])) { |
|
| 1517 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1518 | + } else { |
|
| 1519 | + $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1520 | + } |
|
| 1521 | + } else { |
|
| 1522 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1523 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1524 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1525 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1526 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | + } |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + $boucles[$idb]->in .= $x; |
|
| 1531 | + |
|
| 1532 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1533 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1534 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1535 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1536 | + if (!$crit2) { |
|
| 1537 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1538 | + } |
|
| 1539 | + |
|
| 1540 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1541 | 1541 | } |
| 1542 | 1542 | |
| 1543 | 1543 | /** |
@@ -1553,22 +1553,22 @@ discard block |
||
| 1553 | 1553 | * @return void |
| 1554 | 1554 | */ |
| 1555 | 1555 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1556 | - $boucle = &$boucles[$idb]; |
|
| 1557 | - if (isset($crit->param[0])) { |
|
| 1558 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1559 | - } else { |
|
| 1560 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - if ($crit->cond) { |
|
| 1564 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - if ($crit->not) { |
|
| 1568 | - $_where = "array('NOT',$_where)"; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - $boucle->where[] = $_where; |
|
| 1556 | + $boucle = &$boucles[$idb]; |
|
| 1557 | + if (isset($crit->param[0])) { |
|
| 1558 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1559 | + } else { |
|
| 1560 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1561 | + } |
|
| 1562 | + |
|
| 1563 | + if ($crit->cond) { |
|
| 1564 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + if ($crit->not) { |
|
| 1568 | + $_where = "array('NOT',$_where)"; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + $boucle->where[] = $_where; |
|
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | 1574 | /** |
@@ -1596,31 +1596,31 @@ discard block |
||
| 1596 | 1596 | * @return void |
| 1597 | 1597 | */ |
| 1598 | 1598 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1599 | - /** @var Boucle $boucle */ |
|
| 1600 | - $boucle = $boucles[$idb]; |
|
| 1601 | - |
|
| 1602 | - $champs = lister_champs_id_conditionnel( |
|
| 1603 | - $boucle->show['table'], |
|
| 1604 | - $boucle->show, |
|
| 1605 | - $boucle->sql_serveur |
|
| 1606 | - ); |
|
| 1607 | - |
|
| 1608 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1609 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1610 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1611 | - } |
|
| 1612 | - // nous aider en mode debug. |
|
| 1613 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1614 | - $boucle->modificateur['id_'] = $champs; |
|
| 1615 | - |
|
| 1616 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1617 | - foreach ($champs as $champ) { |
|
| 1618 | - $critere_id_table = new Critere; |
|
| 1619 | - $critere_id_table->op = $champ; |
|
| 1620 | - $critere_id_table->cond = '?'; |
|
| 1621 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1622 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1623 | - } |
|
| 1599 | + /** @var Boucle $boucle */ |
|
| 1600 | + $boucle = $boucles[$idb]; |
|
| 1601 | + |
|
| 1602 | + $champs = lister_champs_id_conditionnel( |
|
| 1603 | + $boucle->show['table'], |
|
| 1604 | + $boucle->show, |
|
| 1605 | + $boucle->sql_serveur |
|
| 1606 | + ); |
|
| 1607 | + |
|
| 1608 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1609 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1610 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1611 | + } |
|
| 1612 | + // nous aider en mode debug. |
|
| 1613 | + $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1614 | + $boucle->modificateur['id_'] = $champs; |
|
| 1615 | + |
|
| 1616 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1617 | + foreach ($champs as $champ) { |
|
| 1618 | + $critere_id_table = new Critere; |
|
| 1619 | + $critere_id_table->op = $champ; |
|
| 1620 | + $critere_id_table->cond = '?'; |
|
| 1621 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1622 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1623 | + } |
|
| 1624 | 1624 | } |
| 1625 | 1625 | |
| 1626 | 1626 | /** |
@@ -1640,79 +1640,79 @@ discard block |
||
| 1640 | 1640 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1641 | 1641 | */ |
| 1642 | 1642 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1643 | - // calculer la description de la table |
|
| 1644 | - if (!is_array($desc)) { |
|
| 1645 | - $desc = description_table($table, $serveur); |
|
| 1646 | - } |
|
| 1647 | - if (!$desc) { |
|
| 1648 | - return []; |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - // Les champs id_xx de la table demandée |
|
| 1652 | - $champs = array_filter( |
|
| 1653 | - array_keys($desc['field']), |
|
| 1654 | - function($champ){ |
|
| 1655 | - return |
|
| 1656 | - strpos($champ, 'id_') === 0 |
|
| 1657 | - or (in_array($champ, array('objet'))); |
|
| 1658 | - } |
|
| 1659 | - ); |
|
| 1660 | - |
|
| 1661 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1662 | - if ( |
|
| 1663 | - in_array('id_rubrique', $champs) |
|
| 1664 | - and !in_array('id_secteur', $champs) |
|
| 1665 | - ) { |
|
| 1666 | - $champs[] = 'id_secteur'; |
|
| 1667 | - } |
|
| 1668 | - |
|
| 1669 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1670 | - if ($serveur) { |
|
| 1671 | - return $champs; |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - $primary = false; |
|
| 1675 | - $associable = false; |
|
| 1676 | - include_spip('action/editer_liens'); |
|
| 1677 | - |
|
| 1678 | - if (isset($desc['type'])) { |
|
| 1679 | - $primary = id_table_objet($desc['type']); |
|
| 1680 | - $associable = objet_associable($desc['type']); |
|
| 1681 | - } |
|
| 1682 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1683 | - $associable = true; |
|
| 1684 | - } |
|
| 1685 | - |
|
| 1686 | - // liste de toutes les tables principales, sauf la notre |
|
| 1687 | - $tables = lister_tables_objets_sql(); |
|
| 1688 | - unset($tables[$table]); |
|
| 1689 | - |
|
| 1690 | - foreach ($tables as $_table => $_desc) { |
|
| 1691 | - if ( |
|
| 1692 | - $associable |
|
| 1693 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1694 | - or objet_associable($_desc['type']) |
|
| 1695 | - ) { |
|
| 1696 | - $champs[] = id_table_objet($_table); |
|
| 1697 | - } |
|
| 1698 | - } |
|
| 1699 | - $champs = array_values(array_unique($champs)); |
|
| 1700 | - |
|
| 1701 | - // Exclusions de certains id |
|
| 1702 | - $exclusions = pipeline( |
|
| 1703 | - 'exclure_id_conditionnel', |
|
| 1704 | - array( |
|
| 1705 | - 'args' => array( |
|
| 1706 | - 'table' => $table, |
|
| 1707 | - 'id_table_objet' => $primary, |
|
| 1708 | - 'associable' => $associable, |
|
| 1709 | - ), |
|
| 1710 | - 'data' => array(), |
|
| 1711 | - ) |
|
| 1712 | - ); |
|
| 1713 | - $champs = array_diff($champs, $exclusions); |
|
| 1714 | - |
|
| 1715 | - return $champs; |
|
| 1643 | + // calculer la description de la table |
|
| 1644 | + if (!is_array($desc)) { |
|
| 1645 | + $desc = description_table($table, $serveur); |
|
| 1646 | + } |
|
| 1647 | + if (!$desc) { |
|
| 1648 | + return []; |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + // Les champs id_xx de la table demandée |
|
| 1652 | + $champs = array_filter( |
|
| 1653 | + array_keys($desc['field']), |
|
| 1654 | + function($champ){ |
|
| 1655 | + return |
|
| 1656 | + strpos($champ, 'id_') === 0 |
|
| 1657 | + or (in_array($champ, array('objet'))); |
|
| 1658 | + } |
|
| 1659 | + ); |
|
| 1660 | + |
|
| 1661 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1662 | + if ( |
|
| 1663 | + in_array('id_rubrique', $champs) |
|
| 1664 | + and !in_array('id_secteur', $champs) |
|
| 1665 | + ) { |
|
| 1666 | + $champs[] = 'id_secteur'; |
|
| 1667 | + } |
|
| 1668 | + |
|
| 1669 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1670 | + if ($serveur) { |
|
| 1671 | + return $champs; |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + $primary = false; |
|
| 1675 | + $associable = false; |
|
| 1676 | + include_spip('action/editer_liens'); |
|
| 1677 | + |
|
| 1678 | + if (isset($desc['type'])) { |
|
| 1679 | + $primary = id_table_objet($desc['type']); |
|
| 1680 | + $associable = objet_associable($desc['type']); |
|
| 1681 | + } |
|
| 1682 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1683 | + $associable = true; |
|
| 1684 | + } |
|
| 1685 | + |
|
| 1686 | + // liste de toutes les tables principales, sauf la notre |
|
| 1687 | + $tables = lister_tables_objets_sql(); |
|
| 1688 | + unset($tables[$table]); |
|
| 1689 | + |
|
| 1690 | + foreach ($tables as $_table => $_desc) { |
|
| 1691 | + if ( |
|
| 1692 | + $associable |
|
| 1693 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1694 | + or objet_associable($_desc['type']) |
|
| 1695 | + ) { |
|
| 1696 | + $champs[] = id_table_objet($_table); |
|
| 1697 | + } |
|
| 1698 | + } |
|
| 1699 | + $champs = array_values(array_unique($champs)); |
|
| 1700 | + |
|
| 1701 | + // Exclusions de certains id |
|
| 1702 | + $exclusions = pipeline( |
|
| 1703 | + 'exclure_id_conditionnel', |
|
| 1704 | + array( |
|
| 1705 | + 'args' => array( |
|
| 1706 | + 'table' => $table, |
|
| 1707 | + 'id_table_objet' => $primary, |
|
| 1708 | + 'associable' => $associable, |
|
| 1709 | + ), |
|
| 1710 | + 'data' => array(), |
|
| 1711 | + ) |
|
| 1712 | + ); |
|
| 1713 | + $champs = array_diff($champs, $exclusions); |
|
| 1714 | + |
|
| 1715 | + return $champs; |
|
| 1716 | 1716 | } |
| 1717 | 1717 | |
| 1718 | 1718 | /** |
@@ -1767,27 +1767,27 @@ discard block |
||
| 1767 | 1767 | * @return void |
| 1768 | 1768 | */ |
| 1769 | 1769 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1770 | - $boucle = &$boucles[$idb]; |
|
| 1771 | - |
|
| 1772 | - // definition du champ par defaut |
|
| 1773 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1774 | - : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1775 | - $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1776 | - : calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1777 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1778 | - : calculer_liste(array($crit->param[2][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1779 | - |
|
| 1780 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1781 | - |
|
| 1782 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1783 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1784 | - |
|
| 1785 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1786 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1787 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1788 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1789 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1790 | - $boucle->hash .= " |
|
| 1770 | + $boucle = &$boucles[$idb]; |
|
| 1771 | + |
|
| 1772 | + // definition du champ par defaut |
|
| 1773 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1774 | + : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1775 | + $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1776 | + : calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1777 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1778 | + : calculer_liste(array($crit->param[2][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1779 | + |
|
| 1780 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1781 | + |
|
| 1782 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1783 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1784 | + |
|
| 1785 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1786 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1787 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1788 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1789 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1790 | + $boucle->hash .= " |
|
| 1791 | 1791 | \$senstri = ''; |
| 1792 | 1792 | \$tri = $_tri; |
| 1793 | 1793 | if (\$tri){ |
@@ -1795,8 +1795,8 @@ discard block |
||
| 1795 | 1795 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1796 | 1796 | }; |
| 1797 | 1797 | "; |
| 1798 | - $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1799 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1798 | + $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1799 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1800 | 1800 | } |
| 1801 | 1801 | |
| 1802 | 1802 | # Criteres de comparaison |
@@ -1813,20 +1813,20 @@ discard block |
||
| 1813 | 1813 | * @return void |
| 1814 | 1814 | **/ |
| 1815 | 1815 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1816 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1817 | - if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1818 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1819 | - } |
|
| 1820 | - |
|
| 1821 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1822 | - if (!$r) { |
|
| 1823 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1824 | - # if (!$crit->cond) { |
|
| 1825 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1826 | - # } |
|
| 1827 | - } else { |
|
| 1828 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1829 | - } |
|
| 1816 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1817 | + if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1818 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1819 | + } |
|
| 1820 | + |
|
| 1821 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1822 | + if (!$r) { |
|
| 1823 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1824 | + # if (!$crit->cond) { |
|
| 1825 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1826 | + # } |
|
| 1827 | + } else { |
|
| 1828 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1829 | + } |
|
| 1830 | 1830 | } |
| 1831 | 1831 | |
| 1832 | 1832 | |
@@ -1846,63 +1846,63 @@ discard block |
||
| 1846 | 1846 | * @return void |
| 1847 | 1847 | **/ |
| 1848 | 1848 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1849 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1850 | - |
|
| 1851 | - $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1852 | - |
|
| 1853 | - // inserer la negation (cf !...) |
|
| 1854 | - |
|
| 1855 | - if ($crit->not) { |
|
| 1856 | - $where = array("'NOT'", $where); |
|
| 1857 | - } |
|
| 1858 | - if ($crit->exclus) { |
|
| 1859 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1860 | - $where = array("'NOT'", $where); |
|
| 1861 | - } else |
|
| 1862 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1863 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1864 | - { |
|
| 1865 | - $where = array( |
|
| 1866 | - "'NOT'", |
|
| 1867 | - array( |
|
| 1868 | - "'IN'", |
|
| 1869 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1870 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1871 | - ) |
|
| 1872 | - ); |
|
| 1873 | - } |
|
| 1874 | - } |
|
| 1875 | - |
|
| 1876 | - // inserer la condition (cf {lang?}) |
|
| 1877 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1878 | - if ($crit->cond) { |
|
| 1879 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1880 | - if ($col == "date" or $col == "date_redac") { |
|
| 1881 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1882 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1883 | - } |
|
| 1884 | - } |
|
| 1885 | - |
|
| 1886 | - if ($op == '=' and !$crit->not) { |
|
| 1887 | - $where = array( |
|
| 1888 | - "'?'", |
|
| 1889 | - "(is_array($pred))", |
|
| 1890 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1891 | - $where |
|
| 1892 | - ); |
|
| 1893 | - } |
|
| 1894 | - $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1895 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1896 | - { |
|
| 1897 | - $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1898 | - } |
|
| 1899 | - } |
|
| 1900 | - |
|
| 1901 | - $boucles[$idb]->where[] = $where; |
|
| 1902 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1903 | - { |
|
| 1904 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1905 | - } |
|
| 1849 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1850 | + |
|
| 1851 | + $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1852 | + |
|
| 1853 | + // inserer la negation (cf !...) |
|
| 1854 | + |
|
| 1855 | + if ($crit->not) { |
|
| 1856 | + $where = array("'NOT'", $where); |
|
| 1857 | + } |
|
| 1858 | + if ($crit->exclus) { |
|
| 1859 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1860 | + $where = array("'NOT'", $where); |
|
| 1861 | + } else |
|
| 1862 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1863 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1864 | + { |
|
| 1865 | + $where = array( |
|
| 1866 | + "'NOT'", |
|
| 1867 | + array( |
|
| 1868 | + "'IN'", |
|
| 1869 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1870 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1871 | + ) |
|
| 1872 | + ); |
|
| 1873 | + } |
|
| 1874 | + } |
|
| 1875 | + |
|
| 1876 | + // inserer la condition (cf {lang?}) |
|
| 1877 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1878 | + if ($crit->cond) { |
|
| 1879 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1880 | + if ($col == "date" or $col == "date_redac") { |
|
| 1881 | + if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1882 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1883 | + } |
|
| 1884 | + } |
|
| 1885 | + |
|
| 1886 | + if ($op == '=' and !$crit->not) { |
|
| 1887 | + $where = array( |
|
| 1888 | + "'?'", |
|
| 1889 | + "(is_array($pred))", |
|
| 1890 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1891 | + $where |
|
| 1892 | + ); |
|
| 1893 | + } |
|
| 1894 | + $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1895 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1896 | + { |
|
| 1897 | + $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1898 | + } |
|
| 1899 | + } |
|
| 1900 | + |
|
| 1901 | + $boucles[$idb]->where[] = $where; |
|
| 1902 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1903 | + { |
|
| 1904 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1905 | + } |
|
| 1906 | 1906 | } |
| 1907 | 1907 | |
| 1908 | 1908 | |
@@ -1943,167 +1943,167 @@ discard block |
||
| 1943 | 1943 | **/ |
| 1944 | 1944 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1945 | 1945 | |
| 1946 | - $boucle = &$boucles[$idb]; |
|
| 1947 | - $type = $boucle->type_requete; |
|
| 1948 | - $table = $boucle->id_table; |
|
| 1949 | - $desc = $boucle->show; |
|
| 1950 | - $col_vraie = null; |
|
| 1951 | - |
|
| 1952 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 1953 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1954 | - |
|
| 1955 | - $col_alias = $col; |
|
| 1956 | - $where_complement = false; |
|
| 1957 | - |
|
| 1958 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1959 | - if ($col == 'id_enfant') { |
|
| 1960 | - $col = $boucle->primary; |
|
| 1961 | - } |
|
| 1962 | - |
|
| 1963 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1964 | - if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1965 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1966 | - ) { |
|
| 1967 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1968 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1969 | - else { |
|
| 1970 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1971 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1972 | - } |
|
| 1973 | - |
|
| 1974 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1975 | - // sauf si exception declaree : sauter cette etape |
|
| 1976 | - else { |
|
| 1977 | - if ( |
|
| 1978 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1979 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1980 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1981 | - ) { |
|
| 1982 | - $e = decompose_champ_id_objet($col); |
|
| 1983 | - $col = array_shift($e); |
|
| 1984 | - $where_complement = primary_doublee($e, $table); |
|
| 1985 | - } // Cas particulier : expressions de date |
|
| 1986 | - else { |
|
| 1987 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1988 | - list($col, $col_vraie) = $c; |
|
| 1989 | - $table = ''; |
|
| 1990 | - } // table explicitée {mots.titre} |
|
| 1991 | - else { |
|
| 1992 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1993 | - list(, $table, $col) = $r; |
|
| 1994 | - $col_alias = $col; |
|
| 1995 | - |
|
| 1996 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1997 | - if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1998 | - and isset($desc['field'][$col]) |
|
| 1999 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2000 | - ) { |
|
| 2001 | - $table = $cle; |
|
| 2002 | - } else { |
|
| 2003 | - $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 2004 | - } |
|
| 2005 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2006 | - if (!$table) { |
|
| 2007 | - return ''; |
|
| 2008 | - } |
|
| 2009 | - } |
|
| 2010 | - // si le champ n'est pas trouvé dans la table, |
|
| 2011 | - // on cherche si une jointure peut l'obtenir |
|
| 2012 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2013 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2014 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2015 | - $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2016 | - } |
|
| 2017 | - else { |
|
| 2018 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2019 | - if (!$r) { |
|
| 2020 | - return ''; |
|
| 2021 | - } |
|
| 2022 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2023 | - } |
|
| 2024 | - } |
|
| 2025 | - } |
|
| 2026 | - } |
|
| 2027 | - } |
|
| 2028 | - } |
|
| 2029 | - |
|
| 2030 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2031 | - // Dans tous les cas, |
|
| 2032 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2033 | - // et passer dans sql_quote avec le type si connu |
|
| 2034 | - // et int sinon si la valeur est numerique |
|
| 2035 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2036 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2037 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2038 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2039 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2040 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2041 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2042 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2043 | - } |
|
| 2044 | - // sinon expliciter les |
|
| 2045 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2046 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2047 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2048 | - // sans toucher aux |
|
| 2049 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2050 | - // sql_quote(truc,'','varchar') |
|
| 2051 | - elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2052 | - // si pas deja un type |
|
| 2053 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2054 | - ) { |
|
| 2055 | - $r = $r[1] |
|
| 2056 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2057 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2058 | - $val[0] = "sql_quote($r)"; |
|
| 2059 | - } |
|
| 2060 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2061 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2062 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2063 | - } |
|
| 2064 | - } |
|
| 2065 | - |
|
| 2066 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2067 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2068 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2069 | - } |
|
| 2070 | - |
|
| 2071 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2072 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2073 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2074 | - if ($table === $boucle->id_table) { |
|
| 2075 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2076 | - if ($col_alias != $col_vraie) { |
|
| 2077 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2078 | - } |
|
| 2079 | - } |
|
| 2080 | - |
|
| 2081 | - // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2082 | - // il faut alors interdire a la fonction de boucle |
|
| 2083 | - // de mettre ses propres criteres de statut |
|
| 2084 | - // https://www.spip.net/@statut (a documenter) |
|
| 2085 | - // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2086 | - if ($col == 'statut') { |
|
| 2087 | - $boucles[$idb]->statut = true; |
|
| 2088 | - } |
|
| 2089 | - |
|
| 2090 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2091 | - if ($table) { |
|
| 2092 | - if ($col[0] == "`") { |
|
| 2093 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2094 | - } else { |
|
| 2095 | - $arg = "$table.$col"; |
|
| 2096 | - } |
|
| 2097 | - } else { |
|
| 2098 | - $arg = $col; |
|
| 2099 | - } |
|
| 2100 | - |
|
| 2101 | - // inserer la fonction SQL |
|
| 2102 | - if ($fct) { |
|
| 2103 | - $arg = "$fct($arg$args_sql)"; |
|
| 2104 | - } |
|
| 2105 | - |
|
| 2106 | - return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1946 | + $boucle = &$boucles[$idb]; |
|
| 1947 | + $type = $boucle->type_requete; |
|
| 1948 | + $table = $boucle->id_table; |
|
| 1949 | + $desc = $boucle->show; |
|
| 1950 | + $col_vraie = null; |
|
| 1951 | + |
|
| 1952 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 1953 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1954 | + |
|
| 1955 | + $col_alias = $col; |
|
| 1956 | + $where_complement = false; |
|
| 1957 | + |
|
| 1958 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1959 | + if ($col == 'id_enfant') { |
|
| 1960 | + $col = $boucle->primary; |
|
| 1961 | + } |
|
| 1962 | + |
|
| 1963 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1964 | + if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1965 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1966 | + ) { |
|
| 1967 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1968 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1969 | + else { |
|
| 1970 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1971 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1972 | + } |
|
| 1973 | + |
|
| 1974 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1975 | + // sauf si exception declaree : sauter cette etape |
|
| 1976 | + else { |
|
| 1977 | + if ( |
|
| 1978 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1979 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1980 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1981 | + ) { |
|
| 1982 | + $e = decompose_champ_id_objet($col); |
|
| 1983 | + $col = array_shift($e); |
|
| 1984 | + $where_complement = primary_doublee($e, $table); |
|
| 1985 | + } // Cas particulier : expressions de date |
|
| 1986 | + else { |
|
| 1987 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1988 | + list($col, $col_vraie) = $c; |
|
| 1989 | + $table = ''; |
|
| 1990 | + } // table explicitée {mots.titre} |
|
| 1991 | + else { |
|
| 1992 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1993 | + list(, $table, $col) = $r; |
|
| 1994 | + $col_alias = $col; |
|
| 1995 | + |
|
| 1996 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1997 | + if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1998 | + and isset($desc['field'][$col]) |
|
| 1999 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2000 | + ) { |
|
| 2001 | + $table = $cle; |
|
| 2002 | + } else { |
|
| 2003 | + $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 2004 | + } |
|
| 2005 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2006 | + if (!$table) { |
|
| 2007 | + return ''; |
|
| 2008 | + } |
|
| 2009 | + } |
|
| 2010 | + // si le champ n'est pas trouvé dans la table, |
|
| 2011 | + // on cherche si une jointure peut l'obtenir |
|
| 2012 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2013 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2014 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2015 | + $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2016 | + } |
|
| 2017 | + else { |
|
| 2018 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2019 | + if (!$r) { |
|
| 2020 | + return ''; |
|
| 2021 | + } |
|
| 2022 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2023 | + } |
|
| 2024 | + } |
|
| 2025 | + } |
|
| 2026 | + } |
|
| 2027 | + } |
|
| 2028 | + } |
|
| 2029 | + |
|
| 2030 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2031 | + // Dans tous les cas, |
|
| 2032 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2033 | + // et passer dans sql_quote avec le type si connu |
|
| 2034 | + // et int sinon si la valeur est numerique |
|
| 2035 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2036 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2037 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2038 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2039 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2040 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2041 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2042 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2043 | + } |
|
| 2044 | + // sinon expliciter les |
|
| 2045 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2046 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2047 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2048 | + // sans toucher aux |
|
| 2049 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2050 | + // sql_quote(truc,'','varchar') |
|
| 2051 | + elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2052 | + // si pas deja un type |
|
| 2053 | + and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2054 | + ) { |
|
| 2055 | + $r = $r[1] |
|
| 2056 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2057 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2058 | + $val[0] = "sql_quote($r)"; |
|
| 2059 | + } |
|
| 2060 | + elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2061 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2062 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2063 | + } |
|
| 2064 | + } |
|
| 2065 | + |
|
| 2066 | + if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2067 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2068 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2069 | + } |
|
| 2070 | + |
|
| 2071 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2072 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2073 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2074 | + if ($table === $boucle->id_table) { |
|
| 2075 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2076 | + if ($col_alias != $col_vraie) { |
|
| 2077 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2078 | + } |
|
| 2079 | + } |
|
| 2080 | + |
|
| 2081 | + // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2082 | + // il faut alors interdire a la fonction de boucle |
|
| 2083 | + // de mettre ses propres criteres de statut |
|
| 2084 | + // https://www.spip.net/@statut (a documenter) |
|
| 2085 | + // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2086 | + if ($col == 'statut') { |
|
| 2087 | + $boucles[$idb]->statut = true; |
|
| 2088 | + } |
|
| 2089 | + |
|
| 2090 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2091 | + if ($table) { |
|
| 2092 | + if ($col[0] == "`") { |
|
| 2093 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2094 | + } else { |
|
| 2095 | + $arg = "$table.$col"; |
|
| 2096 | + } |
|
| 2097 | + } else { |
|
| 2098 | + $arg = $col; |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + // inserer la fonction SQL |
|
| 2102 | + if ($fct) { |
|
| 2103 | + $arg = "$fct($arg$args_sql)"; |
|
| 2104 | + } |
|
| 2105 | + |
|
| 2106 | + return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 2107 | 2107 | } |
| 2108 | 2108 | |
| 2109 | 2109 | |
@@ -2132,77 +2132,77 @@ discard block |
||
| 2132 | 2132 | **/ |
| 2133 | 2133 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2134 | 2134 | |
| 2135 | - $where = ''; |
|
| 2136 | - |
|
| 2137 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2138 | - // gestion par les plugins des jointures tordues |
|
| 2139 | - // pas automatiques mais necessaires |
|
| 2140 | - $table_sql = table_objet_sql($table); |
|
| 2141 | - if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2142 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2143 | - and |
|
| 2144 | - ( |
|
| 2145 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2146 | - or |
|
| 2147 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2148 | - ) |
|
| 2149 | - ) { |
|
| 2150 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2151 | - $index = isset($t[$col]) |
|
| 2152 | - ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2153 | - |
|
| 2154 | - if (count($index) == 3) { |
|
| 2155 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2156 | - } elseif (count($index) == 2) { |
|
| 2157 | - list($t, $col) = $t[$col]; |
|
| 2158 | - } elseif (count($index) == 1) { |
|
| 2159 | - list($calculer_critere_externe) = $index; |
|
| 2160 | - $t = $table; |
|
| 2161 | - } else { |
|
| 2162 | - $t = ''; |
|
| 2163 | - } // jointure non declaree. La trouver. |
|
| 2164 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2165 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2166 | - } else { |
|
| 2167 | - $t = ''; |
|
| 2168 | - } // jointure non declaree. La trouver. |
|
| 2169 | - |
|
| 2170 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2171 | - |
|
| 2172 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2173 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2174 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2175 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2176 | - $table = ""; |
|
| 2177 | - if ($boucle->jointures_explicites) { |
|
| 2178 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2179 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2180 | - } |
|
| 2181 | - |
|
| 2182 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2183 | - if (!$table) { |
|
| 2184 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2185 | - } |
|
| 2186 | - |
|
| 2187 | - if (!$table) { |
|
| 2188 | - return ''; |
|
| 2189 | - } |
|
| 2190 | - |
|
| 2191 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2192 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2193 | - |
|
| 2194 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2195 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2196 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2197 | - $e = decompose_champ_id_objet($col); |
|
| 2198 | - $col = array_shift($e); |
|
| 2199 | - $where = primary_doublee($e, $table); |
|
| 2200 | - } else { |
|
| 2201 | - $col = reset($cle); |
|
| 2202 | - } |
|
| 2203 | - } |
|
| 2204 | - |
|
| 2205 | - return array($col, $col_alias, $table, $where, $desc); |
|
| 2135 | + $where = ''; |
|
| 2136 | + |
|
| 2137 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2138 | + // gestion par les plugins des jointures tordues |
|
| 2139 | + // pas automatiques mais necessaires |
|
| 2140 | + $table_sql = table_objet_sql($table); |
|
| 2141 | + if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2142 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2143 | + and |
|
| 2144 | + ( |
|
| 2145 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2146 | + or |
|
| 2147 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2148 | + ) |
|
| 2149 | + ) { |
|
| 2150 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2151 | + $index = isset($t[$col]) |
|
| 2152 | + ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2153 | + |
|
| 2154 | + if (count($index) == 3) { |
|
| 2155 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2156 | + } elseif (count($index) == 2) { |
|
| 2157 | + list($t, $col) = $t[$col]; |
|
| 2158 | + } elseif (count($index) == 1) { |
|
| 2159 | + list($calculer_critere_externe) = $index; |
|
| 2160 | + $t = $table; |
|
| 2161 | + } else { |
|
| 2162 | + $t = ''; |
|
| 2163 | + } // jointure non declaree. La trouver. |
|
| 2164 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2165 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2166 | + } else { |
|
| 2167 | + $t = ''; |
|
| 2168 | + } // jointure non declaree. La trouver. |
|
| 2169 | + |
|
| 2170 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2171 | + |
|
| 2172 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2173 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2174 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2175 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2176 | + $table = ""; |
|
| 2177 | + if ($boucle->jointures_explicites) { |
|
| 2178 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2179 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2180 | + } |
|
| 2181 | + |
|
| 2182 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2183 | + if (!$table) { |
|
| 2184 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2185 | + } |
|
| 2186 | + |
|
| 2187 | + if (!$table) { |
|
| 2188 | + return ''; |
|
| 2189 | + } |
|
| 2190 | + |
|
| 2191 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2192 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2193 | + |
|
| 2194 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2195 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2196 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2197 | + $e = decompose_champ_id_objet($col); |
|
| 2198 | + $col = array_shift($e); |
|
| 2199 | + $where = primary_doublee($e, $table); |
|
| 2200 | + } else { |
|
| 2201 | + $col = reset($cle); |
|
| 2202 | + } |
|
| 2203 | + } |
|
| 2204 | + |
|
| 2205 | + return array($col, $col_alias, $table, $where, $desc); |
|
| 2206 | 2206 | } |
| 2207 | 2207 | |
| 2208 | 2208 | |
@@ -2223,10 +2223,10 @@ discard block |
||
| 2223 | 2223 | * - valeur |
| 2224 | 2224 | **/ |
| 2225 | 2225 | function primary_doublee($decompose, $table) { |
| 2226 | - $e1 = reset($decompose); |
|
| 2227 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2226 | + $e1 = reset($decompose); |
|
| 2227 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2228 | 2228 | |
| 2229 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2229 | + return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | 2232 | /** |
@@ -2257,56 +2257,56 @@ discard block |
||
| 2257 | 2257 | * Vide sinon. |
| 2258 | 2258 | */ |
| 2259 | 2259 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2260 | - // si on demande un truc du genre spip_mots |
|
| 2261 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2262 | - // et qu'on est la |
|
| 2263 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2264 | - if ($checkarrivee |
|
| 2265 | - and is_string($checkarrivee) |
|
| 2266 | - and $a = table_objet($checkarrivee) |
|
| 2267 | - and in_array($a . '_liens', $joints) |
|
| 2268 | - ) { |
|
| 2269 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2270 | - return $res; |
|
| 2271 | - } |
|
| 2272 | - } |
|
| 2273 | - foreach ($joints as $joint) { |
|
| 2274 | - if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2275 | - // alias de table dans le from |
|
| 2276 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2277 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2278 | - $cols = $arrivee[2]; |
|
| 2279 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2280 | - if (count($cols) > 2) { |
|
| 2281 | - array_pop($cols); |
|
| 2282 | - } |
|
| 2283 | - if ($t) { |
|
| 2284 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2285 | - $joindre = false; |
|
| 2286 | - foreach ($cols as $col) { |
|
| 2287 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2288 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2289 | - $joindre = true; |
|
| 2290 | - } else { |
|
| 2291 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2292 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2293 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2294 | - $joindre = true; |
|
| 2295 | - } |
|
| 2296 | - } |
|
| 2297 | - } |
|
| 2298 | - if (!$joindre) { |
|
| 2299 | - return $t; |
|
| 2300 | - } |
|
| 2301 | - } |
|
| 2302 | - array_pop($arrivee); |
|
| 2303 | - if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2304 | - return $res; |
|
| 2305 | - } |
|
| 2306 | - } |
|
| 2307 | - } |
|
| 2308 | - |
|
| 2309 | - return ''; |
|
| 2260 | + // si on demande un truc du genre spip_mots |
|
| 2261 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2262 | + // et qu'on est la |
|
| 2263 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2264 | + if ($checkarrivee |
|
| 2265 | + and is_string($checkarrivee) |
|
| 2266 | + and $a = table_objet($checkarrivee) |
|
| 2267 | + and in_array($a . '_liens', $joints) |
|
| 2268 | + ) { |
|
| 2269 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2270 | + return $res; |
|
| 2271 | + } |
|
| 2272 | + } |
|
| 2273 | + foreach ($joints as $joint) { |
|
| 2274 | + if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2275 | + // alias de table dans le from |
|
| 2276 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2277 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2278 | + $cols = $arrivee[2]; |
|
| 2279 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2280 | + if (count($cols) > 2) { |
|
| 2281 | + array_pop($cols); |
|
| 2282 | + } |
|
| 2283 | + if ($t) { |
|
| 2284 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2285 | + $joindre = false; |
|
| 2286 | + foreach ($cols as $col) { |
|
| 2287 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2288 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2289 | + $joindre = true; |
|
| 2290 | + } else { |
|
| 2291 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2292 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2293 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2294 | + $joindre = true; |
|
| 2295 | + } |
|
| 2296 | + } |
|
| 2297 | + } |
|
| 2298 | + if (!$joindre) { |
|
| 2299 | + return $t; |
|
| 2300 | + } |
|
| 2301 | + } |
|
| 2302 | + array_pop($arrivee); |
|
| 2303 | + if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2304 | + return $res; |
|
| 2305 | + } |
|
| 2306 | + } |
|
| 2307 | + } |
|
| 2308 | + |
|
| 2309 | + return ''; |
|
| 2310 | 2310 | |
| 2311 | 2311 | } |
| 2312 | 2312 | |
@@ -2333,29 +2333,29 @@ discard block |
||
| 2333 | 2333 | * Alias de la table de jointure (Lx) |
| 2334 | 2334 | */ |
| 2335 | 2335 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2336 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2337 | - |
|
| 2338 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2339 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2340 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2341 | - |
|
| 2342 | - if (!$intermediaire or !$arrivee) { |
|
| 2343 | - return ''; |
|
| 2344 | - } |
|
| 2345 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2346 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2347 | - |
|
| 2348 | - $res = fabrique_jointures($boucle, |
|
| 2349 | - array( |
|
| 2350 | - array( |
|
| 2351 | - $boucle->id_table, |
|
| 2352 | - $intermediaire, |
|
| 2353 | - array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2354 | - ), |
|
| 2355 | - array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2356 | - ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2357 | - |
|
| 2358 | - return $res; |
|
| 2336 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2337 | + |
|
| 2338 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2339 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2340 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2341 | + |
|
| 2342 | + if (!$intermediaire or !$arrivee) { |
|
| 2343 | + return ''; |
|
| 2344 | + } |
|
| 2345 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2346 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2347 | + |
|
| 2348 | + $res = fabrique_jointures($boucle, |
|
| 2349 | + array( |
|
| 2350 | + array( |
|
| 2351 | + $boucle->id_table, |
|
| 2352 | + $intermediaire, |
|
| 2353 | + array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2354 | + ), |
|
| 2355 | + array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2356 | + ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2357 | + |
|
| 2358 | + return $res; |
|
| 2359 | 2359 | } |
| 2360 | 2360 | |
| 2361 | 2361 | |
@@ -2372,17 +2372,17 @@ discard block |
||
| 2372 | 2372 | * false sinon. |
| 2373 | 2373 | **/ |
| 2374 | 2374 | function trouver_champ($champ, $where) { |
| 2375 | - if (!is_array($where)) { |
|
| 2376 | - return preg_match($champ, $where); |
|
| 2377 | - } else { |
|
| 2378 | - foreach ($where as $clause) { |
|
| 2379 | - if (trouver_champ($champ, $clause)) { |
|
| 2380 | - return true; |
|
| 2381 | - } |
|
| 2382 | - } |
|
| 2383 | - |
|
| 2384 | - return false; |
|
| 2385 | - } |
|
| 2375 | + if (!is_array($where)) { |
|
| 2376 | + return preg_match($champ, $where); |
|
| 2377 | + } else { |
|
| 2378 | + foreach ($where as $clause) { |
|
| 2379 | + if (trouver_champ($champ, $clause)) { |
|
| 2380 | + return true; |
|
| 2381 | + } |
|
| 2382 | + } |
|
| 2383 | + |
|
| 2384 | + return false; |
|
| 2385 | + } |
|
| 2386 | 2386 | } |
| 2387 | 2387 | |
| 2388 | 2388 | |
@@ -2408,128 +2408,128 @@ discard block |
||
| 2408 | 2408 | * - string $args_sql Suite des arguments du critère. ? |
| 2409 | 2409 | **/ |
| 2410 | 2410 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2411 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2412 | - if (count($crit->param) == 0) { |
|
| 2413 | - $op = '='; |
|
| 2414 | - $col = $val = $crit->op; |
|
| 2415 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2416 | - $val = $r[2]; |
|
| 2417 | - } |
|
| 2418 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2419 | - if ($val == 'lang') { |
|
| 2420 | - $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2421 | - } else { |
|
| 2422 | - $defaut = null; |
|
| 2423 | - if ($val == 'id_parent') { |
|
| 2424 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2425 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2426 | - // pour eviter l'erreur SQL |
|
| 2427 | - $val = $boucles[$idb]->primary; |
|
| 2428 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2429 | - $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2430 | - } elseif ($val == 'id_enfant') { |
|
| 2431 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2432 | - // de la boucle superieure |
|
| 2433 | - $val = 'id_parent'; |
|
| 2434 | - } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2435 | - // un critere conditionnel sur date est traite a part |
|
| 2436 | - // car la date est mise d'office par SPIP, |
|
| 2437 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2438 | - } |
|
| 2439 | - |
|
| 2440 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2441 | - $val = array(kwote($val)); |
|
| 2442 | - } |
|
| 2443 | - } else { |
|
| 2444 | - // comparaison explicite |
|
| 2445 | - // le phraseur impose que le premier param soit du texte |
|
| 2446 | - $params = $crit->param; |
|
| 2447 | - $op = $crit->op; |
|
| 2448 | - if ($op == '==') { |
|
| 2449 | - $op = 'REGEXP'; |
|
| 2450 | - } |
|
| 2451 | - $col = array_shift($params); |
|
| 2452 | - $col = $col[0]->texte; |
|
| 2453 | - |
|
| 2454 | - $val = array(); |
|
| 2455 | - $parent = $boucles[$idb]->id_parent; |
|
| 2456 | - |
|
| 2457 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2458 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2459 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2460 | - if (count($params) == 1 |
|
| 2461 | - and count($params[0]) == 3 |
|
| 2462 | - and $params[0][0]->type == 'texte' |
|
| 2463 | - and $params[0][2]->type == 'texte' |
|
| 2464 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2465 | - and (($p == "'") or ($p == '"')) |
|
| 2466 | - and $params[0][1]->type == 'champ' |
|
| 2467 | - ) { |
|
| 2468 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2469 | - } else { |
|
| 2470 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2471 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2472 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2473 | - $val[] = $a; |
|
| 2474 | - } else { |
|
| 2475 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2476 | - } // toujours quoter en char ici |
|
| 2477 | - } |
|
| 2478 | - } |
|
| 2479 | - } |
|
| 2480 | - |
|
| 2481 | - $fct = $args_sql = ''; |
|
| 2482 | - // fonction SQL ? |
|
| 2483 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2484 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2485 | - $fct = $m[1]; |
|
| 2486 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2487 | - $col = $a[1]; |
|
| 2488 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2489 | - $col = $m[1]; |
|
| 2490 | - $args_sql = $m[2]; |
|
| 2491 | - } |
|
| 2492 | - $args_sql .= $a[2]; |
|
| 2493 | - } |
|
| 2494 | - |
|
| 2495 | - return array($fct, $col, $op, $val, $args_sql); |
|
| 2411 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2412 | + if (count($crit->param) == 0) { |
|
| 2413 | + $op = '='; |
|
| 2414 | + $col = $val = $crit->op; |
|
| 2415 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2416 | + $val = $r[2]; |
|
| 2417 | + } |
|
| 2418 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2419 | + if ($val == 'lang') { |
|
| 2420 | + $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2421 | + } else { |
|
| 2422 | + $defaut = null; |
|
| 2423 | + if ($val == 'id_parent') { |
|
| 2424 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2425 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2426 | + // pour eviter l'erreur SQL |
|
| 2427 | + $val = $boucles[$idb]->primary; |
|
| 2428 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2429 | + $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2430 | + } elseif ($val == 'id_enfant') { |
|
| 2431 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2432 | + // de la boucle superieure |
|
| 2433 | + $val = 'id_parent'; |
|
| 2434 | + } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2435 | + // un critere conditionnel sur date est traite a part |
|
| 2436 | + // car la date est mise d'office par SPIP, |
|
| 2437 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2438 | + } |
|
| 2439 | + |
|
| 2440 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2441 | + $val = array(kwote($val)); |
|
| 2442 | + } |
|
| 2443 | + } else { |
|
| 2444 | + // comparaison explicite |
|
| 2445 | + // le phraseur impose que le premier param soit du texte |
|
| 2446 | + $params = $crit->param; |
|
| 2447 | + $op = $crit->op; |
|
| 2448 | + if ($op == '==') { |
|
| 2449 | + $op = 'REGEXP'; |
|
| 2450 | + } |
|
| 2451 | + $col = array_shift($params); |
|
| 2452 | + $col = $col[0]->texte; |
|
| 2453 | + |
|
| 2454 | + $val = array(); |
|
| 2455 | + $parent = $boucles[$idb]->id_parent; |
|
| 2456 | + |
|
| 2457 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2458 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2459 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2460 | + if (count($params) == 1 |
|
| 2461 | + and count($params[0]) == 3 |
|
| 2462 | + and $params[0][0]->type == 'texte' |
|
| 2463 | + and $params[0][2]->type == 'texte' |
|
| 2464 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2465 | + and (($p == "'") or ($p == '"')) |
|
| 2466 | + and $params[0][1]->type == 'champ' |
|
| 2467 | + ) { |
|
| 2468 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2469 | + } else { |
|
| 2470 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2471 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2472 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2473 | + $val[] = $a; |
|
| 2474 | + } else { |
|
| 2475 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2476 | + } // toujours quoter en char ici |
|
| 2477 | + } |
|
| 2478 | + } |
|
| 2479 | + } |
|
| 2480 | + |
|
| 2481 | + $fct = $args_sql = ''; |
|
| 2482 | + // fonction SQL ? |
|
| 2483 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2484 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2485 | + $fct = $m[1]; |
|
| 2486 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2487 | + $col = $a[1]; |
|
| 2488 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2489 | + $col = $m[1]; |
|
| 2490 | + $args_sql = $m[2]; |
|
| 2491 | + } |
|
| 2492 | + $args_sql .= $a[2]; |
|
| 2493 | + } |
|
| 2494 | + |
|
| 2495 | + return array($fct, $col, $op, $val, $args_sql); |
|
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | // compatibilite ancienne version |
| 2499 | 2499 | |
| 2500 | 2500 | // https://code.spip.net/@calculer_vieux_in |
| 2501 | 2501 | function calculer_vieux_in($params) { |
| 2502 | - $deb = $params[0][0]; |
|
| 2503 | - $k = count($params) - 1; |
|
| 2504 | - $last = $params[$k]; |
|
| 2505 | - $j = count($last) - 1; |
|
| 2506 | - $last = $last[$j]; |
|
| 2507 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2508 | - |
|
| 2509 | - if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2510 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2511 | - ) { |
|
| 2512 | - return $params; |
|
| 2513 | - } |
|
| 2514 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2515 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2516 | - $last = $params[$k][$j]; |
|
| 2517 | - $n = strlen($last->texte); |
|
| 2518 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2519 | - $newp = array(); |
|
| 2520 | - foreach ($params as $v) { |
|
| 2521 | - if ($v[0]->type != 'texte') { |
|
| 2522 | - $newp[] = $v; |
|
| 2523 | - } else { |
|
| 2524 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2525 | - $t = new Texte; |
|
| 2526 | - $t->texte = $x; |
|
| 2527 | - $newp[] = array($t); |
|
| 2528 | - } |
|
| 2529 | - } |
|
| 2530 | - } |
|
| 2531 | - |
|
| 2532 | - return $newp; |
|
| 2502 | + $deb = $params[0][0]; |
|
| 2503 | + $k = count($params) - 1; |
|
| 2504 | + $last = $params[$k]; |
|
| 2505 | + $j = count($last) - 1; |
|
| 2506 | + $last = $last[$j]; |
|
| 2507 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2508 | + |
|
| 2509 | + if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2510 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2511 | + ) { |
|
| 2512 | + return $params; |
|
| 2513 | + } |
|
| 2514 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2515 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2516 | + $last = $params[$k][$j]; |
|
| 2517 | + $n = strlen($last->texte); |
|
| 2518 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2519 | + $newp = array(); |
|
| 2520 | + foreach ($params as $v) { |
|
| 2521 | + if ($v[0]->type != 'texte') { |
|
| 2522 | + $newp[] = $v; |
|
| 2523 | + } else { |
|
| 2524 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2525 | + $t = new Texte; |
|
| 2526 | + $t->texte = $x; |
|
| 2527 | + $newp[] = array($t); |
|
| 2528 | + } |
|
| 2529 | + } |
|
| 2530 | + } |
|
| 2531 | + |
|
| 2532 | + return $newp; |
|
| 2533 | 2533 | } |
| 2534 | 2534 | |
| 2535 | 2535 | /** |
@@ -2548,89 +2548,89 @@ discard block |
||
| 2548 | 2548 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2549 | 2549 | **/ |
| 2550 | 2550 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2551 | - if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,", $col, $regs)) { |
|
| 2552 | - return ''; |
|
| 2553 | - } |
|
| 2554 | - |
|
| 2555 | - $boucle = $boucles[$idb]; |
|
| 2556 | - $table = $boucle->show; |
|
| 2557 | - |
|
| 2558 | - // si c'est une colonne de la table, ne rien faire |
|
| 2559 | - if (isset($table['field'][$col])) { |
|
| 2560 | - return ''; |
|
| 2561 | - } |
|
| 2562 | - |
|
| 2563 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2564 | - return ''; |
|
| 2565 | - } |
|
| 2566 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2567 | - |
|
| 2568 | - $col = $regs[1]; |
|
| 2569 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2570 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2571 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2572 | - |
|
| 2573 | - if (isset($table['field']["date$suite"])) { |
|
| 2574 | - $date_orig = 'date' . $suite; |
|
| 2575 | - } else { |
|
| 2576 | - $date_orig = substr($suite, 1); |
|
| 2577 | - } |
|
| 2578 | - $pred = $date_orig; |
|
| 2579 | - } else { |
|
| 2580 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2581 | - $pred = 'date'; |
|
| 2582 | - } |
|
| 2583 | - } |
|
| 2584 | - |
|
| 2585 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2586 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2587 | - ") . '\""; |
|
| 2588 | - |
|
| 2589 | - $col_vraie = $date_orig; |
|
| 2590 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2591 | - |
|
| 2592 | - switch ($col) { |
|
| 2593 | - case 'date': |
|
| 2594 | - $col = $date_orig; |
|
| 2595 | - break; |
|
| 2596 | - case 'jour': |
|
| 2597 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2598 | - break; |
|
| 2599 | - case 'mois': |
|
| 2600 | - $col = "MONTH($date_orig)"; |
|
| 2601 | - break; |
|
| 2602 | - case 'annee': |
|
| 2603 | - $col = "YEAR($date_orig)"; |
|
| 2604 | - break; |
|
| 2605 | - case 'heure': |
|
| 2606 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2607 | - break; |
|
| 2608 | - case 'age': |
|
| 2609 | - $col = calculer_param_date("NOW()", $date_orig); |
|
| 2610 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2611 | - break; |
|
| 2612 | - case 'age_relatif': |
|
| 2613 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2614 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2615 | - break; |
|
| 2616 | - case 'jour_relatif': |
|
| 2617 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2618 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2619 | - break; |
|
| 2620 | - case 'mois_relatif': |
|
| 2621 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2622 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2623 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2624 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2625 | - break; |
|
| 2626 | - case 'annee_relatif': |
|
| 2627 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2628 | - $date_orig . ")"; |
|
| 2629 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2630 | - break; |
|
| 2631 | - } |
|
| 2632 | - |
|
| 2633 | - return array($col, $col_vraie); |
|
| 2551 | + if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,", $col, $regs)) { |
|
| 2552 | + return ''; |
|
| 2553 | + } |
|
| 2554 | + |
|
| 2555 | + $boucle = $boucles[$idb]; |
|
| 2556 | + $table = $boucle->show; |
|
| 2557 | + |
|
| 2558 | + // si c'est une colonne de la table, ne rien faire |
|
| 2559 | + if (isset($table['field'][$col])) { |
|
| 2560 | + return ''; |
|
| 2561 | + } |
|
| 2562 | + |
|
| 2563 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2564 | + return ''; |
|
| 2565 | + } |
|
| 2566 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2567 | + |
|
| 2568 | + $col = $regs[1]; |
|
| 2569 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2570 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2571 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2572 | + |
|
| 2573 | + if (isset($table['field']["date$suite"])) { |
|
| 2574 | + $date_orig = 'date' . $suite; |
|
| 2575 | + } else { |
|
| 2576 | + $date_orig = substr($suite, 1); |
|
| 2577 | + } |
|
| 2578 | + $pred = $date_orig; |
|
| 2579 | + } else { |
|
| 2580 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2581 | + $pred = 'date'; |
|
| 2582 | + } |
|
| 2583 | + } |
|
| 2584 | + |
|
| 2585 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2586 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2587 | + ") . '\""; |
|
| 2588 | + |
|
| 2589 | + $col_vraie = $date_orig; |
|
| 2590 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2591 | + |
|
| 2592 | + switch ($col) { |
|
| 2593 | + case 'date': |
|
| 2594 | + $col = $date_orig; |
|
| 2595 | + break; |
|
| 2596 | + case 'jour': |
|
| 2597 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2598 | + break; |
|
| 2599 | + case 'mois': |
|
| 2600 | + $col = "MONTH($date_orig)"; |
|
| 2601 | + break; |
|
| 2602 | + case 'annee': |
|
| 2603 | + $col = "YEAR($date_orig)"; |
|
| 2604 | + break; |
|
| 2605 | + case 'heure': |
|
| 2606 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2607 | + break; |
|
| 2608 | + case 'age': |
|
| 2609 | + $col = calculer_param_date("NOW()", $date_orig); |
|
| 2610 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2611 | + break; |
|
| 2612 | + case 'age_relatif': |
|
| 2613 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2614 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2615 | + break; |
|
| 2616 | + case 'jour_relatif': |
|
| 2617 | + $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2618 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2619 | + break; |
|
| 2620 | + case 'mois_relatif': |
|
| 2621 | + $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2622 | + $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2623 | + ")-YEAR(" . $date_orig . "))"; |
|
| 2624 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2625 | + break; |
|
| 2626 | + case 'annee_relatif': |
|
| 2627 | + $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2628 | + $date_orig . ")"; |
|
| 2629 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2630 | + break; |
|
| 2631 | + } |
|
| 2632 | + |
|
| 2633 | + return array($col, $col_vraie); |
|
| 2634 | 2634 | } |
| 2635 | 2635 | |
| 2636 | 2636 | /** |
@@ -2649,16 +2649,16 @@ discard block |
||
| 2649 | 2649 | * de colonne SQL et une date. |
| 2650 | 2650 | **/ |
| 2651 | 2651 | function calculer_param_date($date_compare, $date_orig) { |
| 2652 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2653 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2654 | - $date_compare = '\'$x\''; |
|
| 2655 | - } else { |
|
| 2656 | - $init = $date_compare; |
|
| 2657 | - } |
|
| 2658 | - |
|
| 2659 | - return |
|
| 2660 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2661 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2652 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2653 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2654 | + $date_compare = '\'$x\''; |
|
| 2655 | + } else { |
|
| 2656 | + $init = $date_compare; |
|
| 2657 | + } |
|
| 2658 | + |
|
| 2659 | + return |
|
| 2660 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2661 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2662 | 2662 | } |
| 2663 | 2663 | |
| 2664 | 2664 | /** |
@@ -2676,18 +2676,18 @@ discard block |
||
| 2676 | 2676 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2677 | 2677 | */ |
| 2678 | 2678 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2679 | - $boucle = &$boucles[$idb]; |
|
| 2679 | + $boucle = &$boucles[$idb]; |
|
| 2680 | 2680 | |
| 2681 | - $args = array(); |
|
| 2682 | - foreach ($crit->param as &$param) { |
|
| 2683 | - array_push($args, |
|
| 2684 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 2685 | - } |
|
| 2681 | + $args = array(); |
|
| 2682 | + foreach ($crit->param as &$param) { |
|
| 2683 | + array_push($args, |
|
| 2684 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 2685 | + } |
|
| 2686 | 2686 | |
| 2687 | - $boucle->hash .= ' |
|
| 2687 | + $boucle->hash .= ' |
|
| 2688 | 2688 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2689 | 2689 | |
| 2690 | - $boucle->hash .= ' |
|
| 2690 | + $boucle->hash .= ' |
|
| 2691 | 2691 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2692 | 2692 | } |
| 2693 | 2693 | |
@@ -2704,8 +2704,8 @@ discard block |
||
| 2704 | 2704 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2705 | 2705 | */ |
| 2706 | 2706 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2707 | - $boucle = &$boucles[$idb]; |
|
| 2708 | - $boucle->hash .= ' |
|
| 2707 | + $boucle = &$boucles[$idb]; |
|
| 2708 | + $boucle->hash .= ' |
|
| 2709 | 2709 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2710 | 2710 | $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2711 | 2711 | } |
@@ -2725,8 +2725,8 @@ discard block |
||
| 2725 | 2725 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2726 | 2726 | */ |
| 2727 | 2727 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2728 | - $boucle = &$boucles[$idb]; |
|
| 2729 | - $boucle->hash .= ' |
|
| 2728 | + $boucle = &$boucles[$idb]; |
|
| 2729 | + $boucle->hash .= ' |
|
| 2730 | 2730 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2731 | 2731 | } |
| 2732 | 2732 | |
@@ -2742,12 +2742,12 @@ discard block |
||
| 2742 | 2742 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2743 | 2743 | */ |
| 2744 | 2744 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2745 | - $boucle = &$boucles[$idb]; |
|
| 2746 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2747 | - foreach ($crit->param as $param) { |
|
| 2748 | - $boucle->hash .= ' |
|
| 2745 | + $boucle = &$boucles[$idb]; |
|
| 2746 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2747 | + foreach ($crit->param as $param) { |
|
| 2748 | + $boucle->hash .= ' |
|
| 2749 | 2749 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2750 | - } |
|
| 2750 | + } |
|
| 2751 | 2751 | } |
| 2752 | 2752 | |
| 2753 | 2753 | /** |
@@ -2764,12 +2764,12 @@ discard block |
||
| 2764 | 2764 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2765 | 2765 | */ |
| 2766 | 2766 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2767 | - $boucle = &$boucles[$idb]; |
|
| 2768 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2769 | - foreach ($crit->param as $param) { |
|
| 2770 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2771 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2772 | - } |
|
| 2767 | + $boucle = &$boucles[$idb]; |
|
| 2768 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2769 | + foreach ($crit->param as $param) { |
|
| 2770 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2771 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2772 | + } |
|
| 2773 | 2773 | } |
| 2774 | 2774 | |
| 2775 | 2775 | /** |
@@ -2794,12 +2794,12 @@ discard block |
||
| 2794 | 2794 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2795 | 2795 | */ |
| 2796 | 2796 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2797 | - $boucle = &$boucles[$idb]; |
|
| 2798 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2799 | - foreach ($crit->param as $param) { |
|
| 2800 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2801 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2802 | - } |
|
| 2797 | + $boucle = &$boucles[$idb]; |
|
| 2798 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2799 | + foreach ($crit->param as $param) { |
|
| 2800 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2801 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2802 | + } |
|
| 2803 | 2803 | } |
| 2804 | 2804 | |
| 2805 | 2805 | /** |
@@ -2814,11 +2814,11 @@ discard block |
||
| 2814 | 2814 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2815 | 2815 | */ |
| 2816 | 2816 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2817 | - $boucle = &$boucles[$idb]; |
|
| 2818 | - foreach ($crit->param as $param) { |
|
| 2819 | - $boucle->hash .= ' |
|
| 2817 | + $boucle = &$boucles[$idb]; |
|
| 2818 | + foreach ($crit->param as $param) { |
|
| 2819 | + $boucle->hash .= ' |
|
| 2820 | 2820 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2821 | - } |
|
| 2821 | + } |
|
| 2822 | 2822 | } |
| 2823 | 2823 | |
| 2824 | 2824 | |
@@ -2850,20 +2850,20 @@ discard block |
||
| 2850 | 2850 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2851 | 2851 | */ |
| 2852 | 2852 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2853 | - $boucle = &$boucles[$idb]; |
|
| 2854 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2855 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2856 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2857 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2858 | - if ($crit->param) { |
|
| 2859 | - foreach ($crit->param as $param) { |
|
| 2860 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2861 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2862 | - } |
|
| 2863 | - // interdire {si 0} aussi ! |
|
| 2864 | - } else { |
|
| 2865 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2866 | - } |
|
| 2853 | + $boucle = &$boucles[$idb]; |
|
| 2854 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2855 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2856 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2857 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2858 | + if ($crit->param) { |
|
| 2859 | + foreach ($crit->param as $param) { |
|
| 2860 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2861 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2862 | + } |
|
| 2863 | + // interdire {si 0} aussi ! |
|
| 2864 | + } else { |
|
| 2865 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2866 | + } |
|
| 2867 | 2867 | } |
| 2868 | 2868 | |
| 2869 | 2869 | /** |
@@ -2879,8 +2879,8 @@ discard block |
||
| 2879 | 2879 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2880 | 2880 | */ |
| 2881 | 2881 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2882 | - $boucle = &$boucles[$idb]; |
|
| 2883 | - $boucle->hash .= ' |
|
| 2882 | + $boucle = &$boucles[$idb]; |
|
| 2883 | + $boucle->hash .= ' |
|
| 2884 | 2884 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2885 | 2885 | $command[\'sourcemode\'] = \'table\';'; |
| 2886 | 2886 | } |
@@ -2901,29 +2901,29 @@ discard block |
||
| 2901 | 2901 | */ |
| 2902 | 2902 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2903 | 2903 | |
| 2904 | - $not = $crit->not; |
|
| 2905 | - $boucle = &$boucles[$idb]; |
|
| 2906 | - $primary = $boucle->primary; |
|
| 2904 | + $not = $crit->not; |
|
| 2905 | + $boucle = &$boucles[$idb]; |
|
| 2906 | + $primary = $boucle->primary; |
|
| 2907 | 2907 | |
| 2908 | - if (!$primary or strpos($primary, ',')) { |
|
| 2909 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2908 | + if (!$primary or strpos($primary, ',')) { |
|
| 2909 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2910 | 2910 | |
| 2911 | - return; |
|
| 2912 | - } |
|
| 2913 | - $table = $boucle->type_requete; |
|
| 2914 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2911 | + return; |
|
| 2912 | + } |
|
| 2913 | + $table = $boucle->type_requete; |
|
| 2914 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2915 | 2915 | |
| 2916 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2917 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2918 | - 'id_parent'; |
|
| 2916 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2917 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2918 | + 'id_parent'; |
|
| 2919 | 2919 | |
| 2920 | - $in = "IN"; |
|
| 2921 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2922 | - if ($not) { |
|
| 2923 | - $where = array("'NOT'", $where); |
|
| 2924 | - } |
|
| 2920 | + $in = "IN"; |
|
| 2921 | + $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2922 | + if ($not) { |
|
| 2923 | + $where = array("'NOT'", $where); |
|
| 2924 | + } |
|
| 2925 | 2925 | |
| 2926 | - $boucle->where[] = $where; |
|
| 2926 | + $boucle->where[] = $where; |
|
| 2927 | 2927 | } |
| 2928 | 2928 | |
| 2929 | 2929 | /** |
@@ -2939,8 +2939,8 @@ discard block |
||
| 2939 | 2939 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2940 | 2940 | */ |
| 2941 | 2941 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2942 | - $not = $crit->not; |
|
| 2943 | - $crit->not = $not ? false : true; |
|
| 2944 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2945 | - $crit->not = $not; |
|
| 2942 | + $not = $crit->not; |
|
| 2943 | + $crit->not = $not ? false : true; |
|
| 2944 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2945 | + $crit->not = $not; |
|
| 2946 | 2946 | } |
@@ -46,10 +46,9 @@ discard block |
||
| 46 | 46 | $not = $crit->not; |
| 47 | 47 | $boucle = &$boucles[$idb]; |
| 48 | 48 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 51 | 50 | |
| 52 | - $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 51 | + $c = array("'='", "'$boucle->id_table."."$id_parent'", 0); |
|
| 53 | 52 | $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
| 54 | 53 | } |
| 55 | 54 | |
@@ -72,10 +71,10 @@ discard block |
||
| 72 | 71 | $id = $boucle->primary; |
| 73 | 72 | |
| 74 | 73 | if ($not or !$id) { |
| 75 | - return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 74 | + return (array('zbug_critere_inconnu', array('critere' => $not.$crit->op))); |
|
| 76 | 75 | } |
| 77 | 76 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 78 | - $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 77 | + $boucle->where[] = array("'!='", "'$boucle->id_table."."$id'", $arg); |
|
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | |
@@ -106,12 +105,12 @@ discard block |
||
| 106 | 105 | $not = ($crit->not ? '' : 'NOT'); |
| 107 | 106 | |
| 108 | 107 | // le doublon s'applique sur un type de boucle (article) |
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + $nom = "'".$boucle->type_requete."'"; |
|
| 110 | 109 | |
| 111 | 110 | // compléter le nom avec un nom précisé {doublons nom} |
| 112 | 111 | // on obtient $nom = "'article' . 'nom'" |
| 113 | 112 | if (isset($crit->param[0])) { |
| 114 | - $nom .= "." . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + $nom .= ".".calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | 114 | } |
| 116 | 115 | |
| 117 | 116 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -123,13 +122,13 @@ discard block |
||
| 123 | 122 | // $doublons et son index, ici $nom |
| 124 | 123 | |
| 125 | 124 | // debut du code "sql_in('articles.id_article', " |
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 127 | 126 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 128 | 127 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 128 | + $debut_doub = '$doublons['.(!$not ? '' : ($boucle->doublons."[]= ")); |
|
| 130 | 129 | |
| 131 | 130 | // le debut complet du code des doublons |
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + $debut_doub = $debut_in.$debut_doub; |
|
| 133 | 132 | |
| 134 | 133 | // nom du doublon "('article' . 'nom')]" |
| 135 | 134 | $fin_doub = "($nom)]"; |
@@ -139,22 +138,22 @@ discard block |
||
| 139 | 138 | foreach ($boucle->where as $k => $w) { |
| 140 | 139 | if (strpos($w[0], $debut_doub) === 0) { |
| 141 | 140 | // fusionner le sql_in (du where) |
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 143 | 142 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 144 | 143 | $x = strpos($boucle->hash, $init_comment); |
| 145 | 144 | $len = strlen($init_comment); |
| 146 | 145 | $boucle->hash = |
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + substr($boucle->hash, 0, $x + $len).$init_code.substr($boucle->hash, $x + $len); |
|
| 148 | 147 | |
| 149 | 148 | return; |
| 150 | 149 | } |
| 151 | 150 | } |
| 152 | 151 | |
| 153 | 152 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 154 | - $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 153 | + $boucle->where[] = array($debut_doub.$fin_doub.", '".$not."')"); |
|
| 155 | 154 | |
| 156 | 155 | // déclarer le doublon s'il n'existe pas encore |
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + $boucle->hash .= $init_comment.$init_code; |
|
| 158 | 157 | |
| 159 | 158 | |
| 160 | 159 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -215,10 +214,10 @@ discard block |
||
| 215 | 214 | $un = $un[0]->texte; |
| 216 | 215 | $deux = $deux[0]->texte; |
| 217 | 216 | if ($deux) { |
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 217 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut'. |
|
| 218 | + $un. |
|
| 219 | + '"]) . ",'. |
|
| 220 | + $deux. |
|
| 222 | 221 | '"'; |
| 223 | 222 | } else { |
| 224 | 223 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
@@ -281,26 +280,26 @@ discard block |
||
| 281 | 280 | $type = calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
| 282 | 281 | } |
| 283 | 282 | |
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr($type, 1)); |
|
| 285 | 284 | $boucle->modificateur['debut_nom'] = $type; |
| 286 | 285 | $partie = |
| 287 | 286 | // tester si le numero de page demande est de la forme '@yyy' |
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 287 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 289 | 288 | . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 289 | + . "\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 290 | + . "\t\t".'$iter->seek(0);'."\n" |
|
| 292 | 291 | . "\t}\n" |
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 292 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 294 | 293 | |
| 295 | 294 | $boucle->hash .= ' |
| 296 | - $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
|
| 295 | + $command[\'pagination\'] = array((isset($Pile[0][' . $debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 297 | 296 | |
| 298 | 297 | $boucle->total_parties = $pas; |
| 299 | 298 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 300 | 299 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 301 | 300 | // sauf si pas de primaire, ou si primaire composee |
| 302 | 301 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 302 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 304 | 303 | if ($boucle->primary |
| 305 | 304 | and !preg_match('/[,\s]/', $boucle->primary) |
| 306 | 305 | and !in_array($t, $boucle->select) |
@@ -346,24 +345,24 @@ discard block |
||
| 346 | 345 | $boucle->hash .= ' |
| 347 | 346 | // RECHERCHE' |
| 348 | 347 | . ($crit->cond ? ' |
| 349 | - if (!strlen(' . $quoi . ')){ |
|
| 348 | + if (!strlen(' . $quoi.')){ |
|
| 350 | 349 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | - } else' : '') . ' |
|
| 350 | + } else' : '').' |
|
| 352 | 351 | { |
| 353 | 352 | $prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\'); |
| 354 | - list($rech_select, $rech_where) = $prepare_recherche(' . $quoi . ', "' . $boucle->id_table . '", "' . $crit->cond . '","' . $boucle->sql_serveur . '",' . $_modificateur . ',"' . $boucle->primary . '"); |
|
| 353 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 355 | 354 | } |
| 356 | 355 | '; |
| 357 | 356 | |
| 358 | 357 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 358 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 360 | 359 | if (!in_array($t, $boucles[$idb]->select)) { |
| 361 | 360 | $boucle->select[] = $t; |
| 362 | 361 | } # pour postgres, neuneu ici |
| 363 | 362 | // jointure uniquement sur le serveur principal |
| 364 | 363 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 365 | 364 | if (!$boucle->sql_serveur) { |
| 366 | - $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 365 | + $boucle->join['resultats'] = array("'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"); |
|
| 367 | 366 | $boucle->from['resultats'] = 'spip_resultats'; |
| 368 | 367 | } |
| 369 | 368 | $boucle->select[] = '$rech_select'; |
@@ -430,7 +429,7 @@ discard block |
||
| 430 | 429 | $c = |
| 431 | 430 | array( |
| 432 | 431 | "'OR'", |
| 433 | - array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 432 | + array("'='", "'$table."."id_trad'", "'$table.$prim'"), |
|
| 434 | 433 | array("'='", "'$table.id_trad'", "'0'") |
| 435 | 434 | ); |
| 436 | 435 | $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
@@ -453,16 +452,15 @@ discard block |
||
| 453 | 452 | $boucle = &$boucles[$idb]; |
| 454 | 453 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 455 | 454 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 456 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | - 'id_parent'; |
|
| 458 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 455 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 456 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 459 | 457 | |
| 460 | 458 | if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 461 | 459 | $boucle->where[] = array("'='", "'$mparent'", $arg); |
| 462 | 460 | |
| 463 | 461 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 464 | 462 | else { |
| 465 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 463 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' '.$boucle->type_requete))); |
|
| 466 | 464 | } |
| 467 | 465 | } |
| 468 | 466 | |
@@ -515,16 +513,15 @@ discard block |
||
| 515 | 513 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 516 | 514 | $decompose = decompose_champ_id_objet($champ); |
| 517 | 515 | $champ = array_shift($decompose); |
| 518 | - $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 516 | + $boucle->where[] = array("'='", _q($cle.".".reset($decompose)), '"'.sql_quote(end($decompose)).'"'); |
|
| 519 | 517 | } |
| 520 | 518 | } else { |
| 521 | 519 | $cle = $boucle->id_table; |
| 522 | 520 | } |
| 523 | 521 | |
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 522 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 523 | + . ($not ? ", 'NOT'" : '').")"; |
|
| 524 | + $boucle->where[] = !$crit->cond ? $c : ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 528 | 525 | } |
| 529 | 526 | |
| 530 | 527 | /** |
@@ -544,9 +541,9 @@ discard block |
||
| 544 | 541 | $not = ($crit->not ? 'NOT' : ''); |
| 545 | 542 | $serveur = $boucle->sql_serveur; |
| 546 | 543 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 544 | + $c = "sql_in('". |
|
| 545 | + $boucle->id_table.'.'.$boucle->primary |
|
| 546 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '$not', '$serveur')"; |
|
| 550 | 547 | |
| 551 | 548 | $boucle->where[] = $c; |
| 552 | 549 | } |
@@ -578,7 +575,7 @@ discard block |
||
| 578 | 575 | $t = table_objet_sql($r[1]); |
| 579 | 576 | $t = array_search($t, $boucles[$idb]->from); |
| 580 | 577 | if ($t) { |
| 581 | - $t .= '.' . $r[2]; |
|
| 578 | + $t .= '.'.$r[2]; |
|
| 582 | 579 | } |
| 583 | 580 | } |
| 584 | 581 | } else { |
@@ -593,7 +590,7 @@ discard block |
||
| 593 | 590 | $boucles[$idb]->select[] = $t; |
| 594 | 591 | } |
| 595 | 592 | } else { |
| 596 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 593 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 597 | 594 | } |
| 598 | 595 | } |
| 599 | 596 | |
@@ -643,26 +640,26 @@ discard block |
||
| 643 | 640 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 644 | 641 | OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 645 | 642 | ) { |
| 646 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 643 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 647 | 644 | } else { |
| 648 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 645 | + $boucle->order[$n - 1] .= " . ".$boucle->modificateur['collate']; |
|
| 649 | 646 | } |
| 650 | 647 | } |
| 651 | 648 | } else { |
| 652 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 649 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 653 | 650 | } |
| 654 | 651 | } |
| 655 | 652 | |
| 656 | 653 | // https://code.spip.net/@calculer_critere_arg_dynamique |
| 657 | 654 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 658 | 655 | $boucle = $boucles[$idb]; |
| 659 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | - $var = '$champs_' . $idb; |
|
| 656 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 657 | + $var = '$champs_'.$idb; |
|
| 661 | 658 | $desc = (strpos($boucle->in, "static $var =") !== false); |
| 662 | 659 | if (!$desc) { |
| 663 | 660 | $desc = $boucle->show['field']; |
| 664 | 661 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 665 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 662 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
|
| 666 | 663 | } |
| 667 | 664 | if ($desc) { |
| 668 | 665 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -737,7 +734,7 @@ discard block |
||
| 737 | 734 | $sens = " . ' DESC'"; |
| 738 | 735 | } |
| 739 | 736 | if (isset($boucle->modificateur['collate'])) { |
| 740 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 737 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 741 | 738 | } |
| 742 | 739 | |
| 743 | 740 | // Pour chaque paramètre du critère |
@@ -759,14 +756,14 @@ discard block |
||
| 759 | 756 | if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
| 760 | 757 | $expression = trim($m[1]); |
| 761 | 758 | $champ = trim($m[2]); |
| 762 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 759 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 763 | 760 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 764 | 761 | } else { |
| 765 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 762 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 766 | 763 | } |
| 767 | 764 | |
| 768 | 765 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 769 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 766 | + } elseif (preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 770 | 767 | // {par FONCTION(champ)} |
| 771 | 768 | if (count($match) > 2) { |
| 772 | 769 | $par = substr($match[2], 1, -1); |
@@ -776,7 +773,7 @@ discard block |
||
| 776 | 773 | if ($par == 'hasard') { |
| 777 | 774 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 778 | 775 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 779 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 776 | + $order = "'".$boucle->id_table.".".$boucle->show['date']."'"; |
|
| 780 | 777 | } else { |
| 781 | 778 | // cas général {par champ}, {par table.champ}, ... |
| 782 | 779 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -785,7 +782,7 @@ discard block |
||
| 785 | 782 | |
| 786 | 783 | // on ne sait pas traiter… |
| 787 | 784 | else { |
| 788 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 785 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 789 | 786 | } |
| 790 | 787 | |
| 791 | 788 | // En cas d'erreur de squelette retournée par une fonction |
@@ -805,14 +802,14 @@ discard block |
||
| 805 | 802 | |
| 806 | 803 | if ($fct) { |
| 807 | 804 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 808 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 805 | + $order = "'$fct(".$r[1].")'"; |
|
| 809 | 806 | } else { |
| 810 | 807 | $order = "'$fct(' . $order . ')'"; |
| 811 | 808 | } |
| 812 | 809 | } |
| 813 | - $t = $order . $collecte . $sens; |
|
| 810 | + $t = $order.$collecte.$sens; |
|
| 814 | 811 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 815 | - $t = $r[1] . $r[2]; |
|
| 812 | + $t = $r[1].$r[2]; |
|
| 816 | 813 | } |
| 817 | 814 | |
| 818 | 815 | $boucle->order[] = $t; |
@@ -862,16 +859,16 @@ discard block |
||
| 862 | 859 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 863 | 860 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 864 | 861 | if (is_array($_champ)) { |
| 865 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 862 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." num $champ")); |
|
| 866 | 863 | } |
| 867 | 864 | $boucle = &$boucles[$idb]; |
| 868 | - $texte = '0+' . $_champ; |
|
| 865 | + $texte = '0+'.$_champ; |
|
| 869 | 866 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 870 | 867 | if ($suite !== "''") { |
| 871 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 868 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 872 | 869 | } |
| 873 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | - $boucle->select[] = $texte . " AS $as"; |
|
| 870 | + $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
|
| 871 | + $boucle->select[] = $texte." AS $as"; |
|
| 875 | 872 | $order = "'$as'"; |
| 876 | 873 | return $order; |
| 877 | 874 | } |
@@ -896,16 +893,16 @@ discard block |
||
| 896 | 893 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 897 | 894 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 898 | 895 | if (is_array($_champ)) { |
| 899 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 896 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." sinum $champ")); |
|
| 900 | 897 | } |
| 901 | 898 | $boucle = &$boucles[$idb]; |
| 902 | - $texte = '0+' . $_champ; |
|
| 899 | + $texte = '0+'.$_champ; |
|
| 903 | 900 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 904 | 901 | if ($suite !== "''") { |
| 905 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 902 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 906 | 903 | } |
| 907 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 904 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ""); |
|
| 905 | + $boucle->select[] = 'CASE ('.$texte.') WHEN 0 THEN 1 ELSE 0 END AS '.$as; |
|
| 909 | 906 | $order = "'$as'"; |
| 910 | 907 | return $order; |
| 911 | 908 | } |
@@ -929,10 +926,10 @@ discard block |
||
| 929 | 926 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 930 | 927 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 931 | 928 | if (is_array($_champ)) { |
| 932 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 929 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." multi $champ")); |
|
| 933 | 930 | } |
| 934 | 931 | $boucle = &$boucles[$idb]; |
| 935 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 932 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 936 | 933 | $order = "'multi'"; |
| 937 | 934 | return $order; |
| 938 | 935 | } |
@@ -952,13 +949,13 @@ discard block |
||
| 952 | 949 | * @param bool $raw Retourne le champ pour le compilateur ("'alias.champ'") ou brut ('alias.champ') |
| 953 | 950 | * @return array|string |
| 954 | 951 | */ |
| 955 | -function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 952 | +function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 956 | 953 | $boucle = &$boucles[$idb]; |
| 957 | 954 | $desc = $boucle->show; |
| 958 | 955 | |
| 959 | 956 | // le champ existe dans la table, pas de souci (le plus commun) |
| 960 | 957 | if (isset($desc['field'][$par])) { |
| 961 | - $par = $boucle->id_table . "." . $par; |
|
| 958 | + $par = $boucle->id_table.".".$par; |
|
| 962 | 959 | } |
| 963 | 960 | // le champ est peut être une jointure |
| 964 | 961 | else { |
@@ -979,24 +976,24 @@ discard block |
||
| 979 | 976 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 980 | 977 | // Si la table est déjà dans le from, on la réutilise. |
| 981 | 978 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 982 | - $par = $infos['alias'] . "." . $champ; |
|
| 979 | + $par = $infos['alias'].".".$champ; |
|
| 983 | 980 | } elseif ( |
| 984 | 981 | $boucle->jointures_explicites |
| 985 | 982 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 986 | 983 | ) { |
| 987 | - $par = $alias . "." . $champ; |
|
| 984 | + $par = $alias.".".$champ; |
|
| 988 | 985 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 989 | - $par = $alias . "." . $champ; |
|
| 986 | + $par = $alias.".".$champ; |
|
| 990 | 987 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 991 | 988 | } elseif ( |
| 992 | 989 | $table_alias |
| 993 | 990 | and isset($boucle->from[$table_alias]) |
| 994 | 991 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 995 | 992 | ) { |
| 996 | - $par = $infos['alias'] . "." . $champ; |
|
| 993 | + $par = $infos['alias'].".".$champ; |
|
| 997 | 994 | } elseif ($table) { |
| 998 | 995 | // On avait table + champ, mais on ne les a pas trouvés |
| 999 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 996 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 1000 | 997 | } else { |
| 1001 | 998 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1002 | 999 | } |
@@ -1020,7 +1017,7 @@ discard block |
||
| 1020 | 1017 | if (!$t) { |
| 1021 | 1018 | $t = trouver_jointure_champ($champ, $boucle); |
| 1022 | 1019 | } |
| 1023 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1020 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1024 | 1021 | } |
| 1025 | 1022 | |
| 1026 | 1023 | /** |
@@ -1065,9 +1062,9 @@ discard block |
||
| 1065 | 1062 | $boucle->default_order[] = ' DESC'; |
| 1066 | 1063 | } |
| 1067 | 1064 | } else { |
| 1068 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1065 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1069 | 1066 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1070 | - $t = $r[1] . $r[2]; |
|
| 1067 | + $t = $r[1].$r[2]; |
|
| 1071 | 1068 | } |
| 1072 | 1069 | $boucle->order[$n - 1] = $t; |
| 1073 | 1070 | } |
@@ -1079,7 +1076,7 @@ discard block |
||
| 1079 | 1076 | $params = $crit->param; |
| 1080 | 1077 | |
| 1081 | 1078 | if (count($params) < 1) { |
| 1082 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1079 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ?")); |
|
| 1083 | 1080 | } |
| 1084 | 1081 | |
| 1085 | 1082 | $boucle = &$boucles[$idb]; |
@@ -1100,7 +1097,7 @@ discard block |
||
| 1100 | 1097 | if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
| 1101 | 1098 | $date = $date[0]->texte; |
| 1102 | 1099 | if (!isset($fields[$date])) { |
| 1103 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1100 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ".$date)); |
|
| 1104 | 1101 | } |
| 1105 | 1102 | } else { |
| 1106 | 1103 | $a = calculer_liste($date, $idb, $boucles, $parent); |
@@ -1112,38 +1109,38 @@ discard block |
||
| 1112 | 1109 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1113 | 1110 | } |
| 1114 | 1111 | $annee = $params ? array_shift($params) : ""; |
| 1115 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1112 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1113 | + calculer_liste($annee, $idb, $boucles, $parent). |
|
| 1117 | 1114 | ') ? $x : date("Y"))'; |
| 1118 | 1115 | |
| 1119 | 1116 | $mois = $params ? array_shift($params) : ""; |
| 1120 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1117 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1118 | + calculer_liste($mois, $idb, $boucles, $parent). |
|
| 1122 | 1119 | ') ? $x : date("m"))'; |
| 1123 | 1120 | |
| 1124 | 1121 | $jour = $params ? array_shift($params) : ""; |
| 1125 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1122 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1123 | + calculer_liste($jour, $idb, $boucles, $parent). |
|
| 1127 | 1124 | ') ? $x : date("d"))'; |
| 1128 | 1125 | |
| 1129 | 1126 | $annee2 = $params ? array_shift($params) : ""; |
| 1130 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1127 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1128 | + calculer_liste($annee2, $idb, $boucles, $parent). |
|
| 1132 | 1129 | ') ? $x : date("Y"))'; |
| 1133 | 1130 | |
| 1134 | 1131 | $mois2 = $params ? array_shift($params) : ""; |
| 1135 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1132 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1133 | + calculer_liste($mois2, $idb, $boucles, $parent). |
|
| 1137 | 1134 | ') ? $x : date("m"))'; |
| 1138 | 1135 | |
| 1139 | 1136 | $jour2 = $params ? array_shift($params) : ""; |
| 1140 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1137 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1138 | + calculer_liste($jour2, $idb, $boucles, $parent). |
|
| 1142 | 1139 | ') ? $x : date("d"))'; |
| 1143 | 1140 | |
| 1144 | - $date = $boucle->id_table . ".$date"; |
|
| 1141 | + $date = $boucle->id_table.".$date"; |
|
| 1145 | 1142 | |
| 1146 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1143 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1147 | 1144 | if ($type == 'jour') { |
| 1148 | 1145 | $boucle->where[] = array( |
| 1149 | 1146 | "'='", |
@@ -1215,14 +1212,13 @@ discard block |
||
| 1215 | 1212 | list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1216 | 1213 | |
| 1217 | 1214 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1218 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1215 | + $boucle->limit = $a11.','.$a21; |
|
| 1219 | 1216 | } else { |
| 1220 | 1217 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1221 | 1218 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1222 | 1219 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1223 | 1220 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1224 | - $mode = (($op == '/') ? '/' : |
|
| 1225 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1221 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1226 | 1222 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1227 | 1223 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
| 1228 | 1224 | $boucle->limit = |
@@ -1268,8 +1264,7 @@ discard block |
||
| 1268 | 1264 | // {1/3} |
| 1269 | 1265 | if ($op1 == '/') { |
| 1270 | 1266 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1271 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | - "($total_parties ? $total_parties : 1)"; |
|
| 1267 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1273 | 1268 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1274 | 1269 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1275 | 1270 | } else { |
@@ -1280,15 +1275,13 @@ discard block |
||
| 1280 | 1275 | |
| 1281 | 1276 | // cas {x,n-1} |
| 1282 | 1277 | if ($op2 == '-') { |
| 1283 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | - ($total_parties . ' - 1')); |
|
| 1278 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1279 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1286 | 1280 | } else { |
| 1287 | 1281 | // {x,1} ou {pagination} |
| 1288 | 1282 | $fin = '$debut_boucle' |
| 1289 | 1283 | . (is_numeric($total_parties) ? |
| 1290 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | - ('+' . $total_parties . ' - 1')); |
|
| 1284 | + (($total_parties == 1) ? "" : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1292 | 1285 | } |
| 1293 | 1286 | |
| 1294 | 1287 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1306,11 +1299,11 @@ discard block |
||
| 1306 | 1299 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1307 | 1300 | |
| 1308 | 1301 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1309 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1302 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1310 | 1303 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1311 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1312 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1313 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1304 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1305 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1306 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1314 | 1307 | . "\n\tif (\$debut_boucle>0" |
| 1315 | 1308 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1316 | 1309 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1395,16 +1388,16 @@ discard block |
||
| 1395 | 1388 | // critere personnalise ? |
| 1396 | 1389 | if ( |
| 1397 | 1390 | (!$serveur or |
| 1398 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1399 | - and (!function_exists($f = $f . "_dist")) |
|
| 1400 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1401 | - and (!function_exists($f = $f . "_dist")) |
|
| 1391 | + ((!function_exists($f = "critere_".$serveur."_".$table."_".$critere)) |
|
| 1392 | + and (!function_exists($f = $f."_dist")) |
|
| 1393 | + and (!function_exists($f = "critere_".$serveur."_".$critere)) |
|
| 1394 | + and (!function_exists($f = $f."_dist")) |
|
| 1402 | 1395 | ) |
| 1403 | 1396 | ) |
| 1404 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1405 | - and (!function_exists($f = $f . "_dist")) |
|
| 1406 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1407 | - and (!function_exists($f = $f . "_dist")) |
|
| 1397 | + and (!function_exists($f = "critere_".$table."_".$critere)) |
|
| 1398 | + and (!function_exists($f = $f."_dist")) |
|
| 1399 | + and (!function_exists($f = "critere_".$critere)) |
|
| 1400 | + and (!function_exists($f = $f."_dist")) |
|
| 1408 | 1401 | ) { |
| 1409 | 1402 | // fonction critere standard |
| 1410 | 1403 | $f = $defaut; |
@@ -1437,9 +1430,9 @@ discard block |
||
| 1437 | 1430 | */ |
| 1438 | 1431 | function kwote($lisp, $serveur = '', $type = '') { |
| 1439 | 1432 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1440 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1433 | + return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type)."\""; |
|
| 1441 | 1434 | } else { |
| 1442 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1435 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1443 | 1436 | } |
| 1444 | 1437 | } |
| 1445 | 1438 | |
@@ -1461,7 +1454,7 @@ discard block |
||
| 1461 | 1454 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1462 | 1455 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1463 | 1456 | if (!$r) { |
| 1464 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1457 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 1465 | 1458 | } |
| 1466 | 1459 | list($arg, $op, $val, $col, $where_complement) = $r; |
| 1467 | 1460 | |
@@ -1488,8 +1481,8 @@ discard block |
||
| 1488 | 1481 | "'NOT'", |
| 1489 | 1482 | array( |
| 1490 | 1483 | "'IN'", |
| 1491 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1484 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1485 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1493 | 1486 | ) |
| 1494 | 1487 | ); |
| 1495 | 1488 | } |
@@ -1508,22 +1501,22 @@ discard block |
||
| 1508 | 1501 | $descr = $boucles[$idb]->descr; |
| 1509 | 1502 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1510 | 1503 | |
| 1511 | - $var = '$in' . $cpt++; |
|
| 1504 | + $var = '$in'.$cpt++; |
|
| 1512 | 1505 | $x = "\n\t$var = array();"; |
| 1513 | 1506 | foreach ($val as $k => $v) { |
| 1514 | 1507 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1515 | 1508 | // optimiser le traitement des constantes |
| 1516 | 1509 | if (is_numeric($r[2])) { |
| 1517 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1510 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1518 | 1511 | } else { |
| 1519 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1512 | + $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 1520 | 1513 | } |
| 1521 | 1514 | } else { |
| 1522 | 1515 | // Pour permettre de passer des tableaux de valeurs |
| 1523 | 1516 | // on repere l'utilisation brute de #ENV**{X}, |
| 1524 | 1517 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1525 | 1518 | // et on deballe mais en rajoutant l'anti XSS |
| 1526 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1519 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | 1520 | } |
| 1528 | 1521 | } |
| 1529 | 1522 | |
@@ -1537,7 +1530,7 @@ discard block |
||
| 1537 | 1530 | $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
| 1538 | 1531 | } |
| 1539 | 1532 | |
| 1540 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1533 | + return "sql_in('$arg', $var".($crit2 == 'NOT' ? ",'NOT'" : "").")"; |
|
| 1541 | 1534 | } |
| 1542 | 1535 | |
| 1543 | 1536 | /** |
@@ -1610,7 +1603,7 @@ discard block |
||
| 1610 | 1603 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1611 | 1604 | } |
| 1612 | 1605 | // nous aider en mode debug. |
| 1613 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1606 | + $boucle->debug[] = "id_ : ".implode(', ', $champs); |
|
| 1614 | 1607 | $boucle->modificateur['id_'] = $champs; |
| 1615 | 1608 | |
| 1616 | 1609 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1651,7 +1644,7 @@ discard block |
||
| 1651 | 1644 | // Les champs id_xx de la table demandée |
| 1652 | 1645 | $champs = array_filter( |
| 1653 | 1646 | array_keys($desc['field']), |
| 1654 | - function($champ){ |
|
| 1647 | + function($champ) { |
|
| 1655 | 1648 | return |
| 1656 | 1649 | strpos($champ, 'id_') === 0 |
| 1657 | 1650 | or (in_array($champ, array('objet'))); |
@@ -1866,8 +1859,8 @@ discard block |
||
| 1866 | 1859 | "'NOT'", |
| 1867 | 1860 | array( |
| 1868 | 1861 | "'IN'", |
| 1869 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1870 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1862 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1863 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1871 | 1864 | ) |
| 1872 | 1865 | ); |
| 1873 | 1866 | } |
@@ -1878,7 +1871,7 @@ discard block |
||
| 1878 | 1871 | if ($crit->cond) { |
| 1879 | 1872 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1880 | 1873 | if ($col == "date" or $col == "date_redac") { |
| 1881 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1874 | + if ($pred == "\$Pile[0]['".$col."']") { |
|
| 1882 | 1875 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1883 | 1876 | } |
| 1884 | 1877 | } |
@@ -2039,7 +2032,7 @@ discard block |
||
| 2039 | 2032 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2040 | 2033 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2041 | 2034 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2042 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2035 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2043 | 2036 | } |
| 2044 | 2037 | // sinon expliciter les |
| 2045 | 2038 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2050,22 +2043,22 @@ discard block |
||
| 2050 | 2043 | // sql_quote(truc,'','varchar') |
| 2051 | 2044 | elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
| 2052 | 2045 | // si pas deja un type |
| 2053 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2046 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2054 | 2047 | ) { |
| 2055 | 2048 | $r = $r[1] |
| 2056 | 2049 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2057 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2050 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2058 | 2051 | $val[0] = "sql_quote($r)"; |
| 2059 | 2052 | } |
| 2060 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2053 | + elseif (strpos($val[0], '@@defaultcast@@') !== false |
|
| 2061 | 2054 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2062 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2055 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2063 | 2056 | } |
| 2064 | 2057 | } |
| 2065 | 2058 | |
| 2066 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2059 | + if (strpos($val[0], '@@defaultcast@@') !== false |
|
| 2067 | 2060 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2068 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2061 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2069 | 2062 | } |
| 2070 | 2063 | |
| 2071 | 2064 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2090,7 +2083,7 @@ discard block |
||
| 2090 | 2083 | // inserer le nom de la table SQL devant le nom du champ |
| 2091 | 2084 | if ($table) { |
| 2092 | 2085 | if ($col[0] == "`") { |
| 2093 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2086 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2094 | 2087 | } else { |
| 2095 | 2088 | $arg = "$table.$col"; |
| 2096 | 2089 | } |
@@ -2224,9 +2217,9 @@ discard block |
||
| 2224 | 2217 | **/ |
| 2225 | 2218 | function primary_doublee($decompose, $table) { |
| 2226 | 2219 | $e1 = reset($decompose); |
| 2227 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2220 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2228 | 2221 | |
| 2229 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2222 | + return array("'='", "'$table.".$e1."'", $e2); |
|
| 2230 | 2223 | } |
| 2231 | 2224 | |
| 2232 | 2225 | /** |
@@ -2264,7 +2257,7 @@ discard block |
||
| 2264 | 2257 | if ($checkarrivee |
| 2265 | 2258 | and is_string($checkarrivee) |
| 2266 | 2259 | and $a = table_objet($checkarrivee) |
| 2267 | - and in_array($a . '_liens', $joints) |
|
| 2260 | + and in_array($a.'_liens', $joints) |
|
| 2268 | 2261 | ) { |
| 2269 | 2262 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2270 | 2263 | return $res; |
@@ -2284,12 +2277,12 @@ discard block |
||
| 2284 | 2277 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2285 | 2278 | $joindre = false; |
| 2286 | 2279 | foreach ($cols as $col) { |
| 2287 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2280 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2288 | 2281 | if (trouver_champ($c, $boucle->where)) { |
| 2289 | 2282 | $joindre = true; |
| 2290 | 2283 | } else { |
| 2291 | 2284 | // mais ca peut etre dans le FIELD pour le Having |
| 2292 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2285 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2293 | 2286 | if (trouver_champ($c, $boucle->select)) { |
| 2294 | 2287 | $joindre = true; |
| 2295 | 2288 | } |
@@ -2336,7 +2329,7 @@ discard block |
||
| 2336 | 2329 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2337 | 2330 | |
| 2338 | 2331 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2339 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2332 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
|
| 2340 | 2333 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2341 | 2334 | |
| 2342 | 2335 | if (!$intermediaire or !$arrivee) { |
@@ -2434,7 +2427,7 @@ discard block |
||
| 2434 | 2427 | } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
| 2435 | 2428 | // un critere conditionnel sur date est traite a part |
| 2436 | 2429 | // car la date est mise d'office par SPIP, |
| 2437 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2430 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2438 | 2431 | } |
| 2439 | 2432 | |
| 2440 | 2433 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2465,7 +2458,7 @@ discard block |
||
| 2465 | 2458 | and (($p == "'") or ($p == '"')) |
| 2466 | 2459 | and $params[0][1]->type == 'champ' |
| 2467 | 2460 | ) { |
| 2468 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2461 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2469 | 2462 | } else { |
| 2470 | 2463 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2471 | 2464 | $a = calculer_liste($p, $idb, $boucles, $parent); |
@@ -2481,7 +2474,7 @@ discard block |
||
| 2481 | 2474 | $fct = $args_sql = ''; |
| 2482 | 2475 | // fonction SQL ? |
| 2483 | 2476 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2484 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2477 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2485 | 2478 | $fct = $m[1]; |
| 2486 | 2479 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2487 | 2480 | $col = $a[1]; |
@@ -2571,7 +2564,7 @@ discard block |
||
| 2571 | 2564 | # si oui choisir ce champ, sinon choisir xxxx |
| 2572 | 2565 | |
| 2573 | 2566 | if (isset($table['field']["date$suite"])) { |
| 2574 | - $date_orig = 'date' . $suite; |
|
| 2567 | + $date_orig = 'date'.$suite; |
|
| 2575 | 2568 | } else { |
| 2576 | 2569 | $date_orig = substr($suite, 1); |
| 2577 | 2570 | } |
@@ -2582,12 +2575,12 @@ discard block |
||
| 2582 | 2575 | } |
| 2583 | 2576 | } |
| 2584 | 2577 | |
| 2585 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2586 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2578 | + $date_compare = "\"' . normaliser_date(". |
|
| 2579 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2587 | 2580 | ") . '\""; |
| 2588 | 2581 | |
| 2589 | 2582 | $col_vraie = $date_orig; |
| 2590 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2583 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2591 | 2584 | |
| 2592 | 2585 | switch ($col) { |
| 2593 | 2586 | case 'date': |
@@ -2607,26 +2600,26 @@ discard block |
||
| 2607 | 2600 | break; |
| 2608 | 2601 | case 'age': |
| 2609 | 2602 | $col = calculer_param_date("NOW()", $date_orig); |
| 2610 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2603 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2611 | 2604 | break; |
| 2612 | 2605 | case 'age_relatif': |
| 2613 | 2606 | $col = calculer_param_date($date_compare, $date_orig); |
| 2614 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2607 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2615 | 2608 | break; |
| 2616 | 2609 | case 'jour_relatif': |
| 2617 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2618 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2610 | + $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
|
| 2611 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2619 | 2612 | break; |
| 2620 | 2613 | case 'mois_relatif': |
| 2621 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2622 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2623 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2624 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2614 | + $col = "MONTH(".$date_compare.")-MONTH(". |
|
| 2615 | + $date_orig.")+12*(YEAR(".$date_compare. |
|
| 2616 | + ")-YEAR(".$date_orig."))"; |
|
| 2617 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2625 | 2618 | break; |
| 2626 | 2619 | case 'annee_relatif': |
| 2627 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2628 | - $date_orig . ")"; |
|
| 2629 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2620 | + $col = "YEAR(".$date_compare.")-YEAR(". |
|
| 2621 | + $date_orig.")"; |
|
| 2622 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2630 | 2623 | break; |
| 2631 | 2624 | } |
| 2632 | 2625 | |
@@ -2685,10 +2678,10 @@ discard block |
||
| 2685 | 2678 | } |
| 2686 | 2679 | |
| 2687 | 2680 | $boucle->hash .= ' |
| 2688 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2681 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2689 | 2682 | |
| 2690 | 2683 | $boucle->hash .= ' |
| 2691 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2684 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2692 | 2685 | } |
| 2693 | 2686 | |
| 2694 | 2687 | |
@@ -2706,8 +2699,8 @@ discard block |
||
| 2706 | 2699 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2707 | 2700 | $boucle = &$boucles[$idb]; |
| 2708 | 2701 | $boucle->hash .= ' |
| 2709 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2710 | - $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2702 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).'); |
|
| 2703 | + $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2711 | 2704 | } |
| 2712 | 2705 | |
| 2713 | 2706 | |
@@ -2727,7 +2720,7 @@ discard block |
||
| 2727 | 2720 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2728 | 2721 | $boucle = &$boucles[$idb]; |
| 2729 | 2722 | $boucle->hash .= ' |
| 2730 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2723 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2731 | 2724 | } |
| 2732 | 2725 | |
| 2733 | 2726 | |
@@ -2746,7 +2739,7 @@ discard block |
||
| 2746 | 2739 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2747 | 2740 | foreach ($crit->param as $param) { |
| 2748 | 2741 | $boucle->hash .= ' |
| 2749 | - $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2742 | + $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2750 | 2743 | } |
| 2751 | 2744 | } |
| 2752 | 2745 | |
@@ -2765,10 +2758,10 @@ discard block |
||
| 2765 | 2758 | */ |
| 2766 | 2759 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2767 | 2760 | $boucle = &$boucles[$idb]; |
| 2768 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2761 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2769 | 2762 | foreach ($crit->param as $param) { |
| 2770 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2771 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2763 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, $idb, $boucles, |
|
| 2764 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2772 | 2765 | } |
| 2773 | 2766 | } |
| 2774 | 2767 | |
@@ -2795,10 +2788,10 @@ discard block |
||
| 2795 | 2788 | */ |
| 2796 | 2789 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2797 | 2790 | $boucle = &$boucles[$idb]; |
| 2798 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2791 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2799 | 2792 | foreach ($crit->param as $param) { |
| 2800 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2801 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2793 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, $idb, $boucles, |
|
| 2794 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2802 | 2795 | } |
| 2803 | 2796 | } |
| 2804 | 2797 | |
@@ -2817,7 +2810,7 @@ discard block |
||
| 2817 | 2810 | $boucle = &$boucles[$idb]; |
| 2818 | 2811 | foreach ($crit->param as $param) { |
| 2819 | 2812 | $boucle->hash .= ' |
| 2820 | - $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2813 | + $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2821 | 2814 | } |
| 2822 | 2815 | } |
| 2823 | 2816 | |
@@ -2858,7 +2851,7 @@ discard block |
||
| 2858 | 2851 | if ($crit->param) { |
| 2859 | 2852 | foreach ($crit->param as $param) { |
| 2860 | 2853 | $boucle->hash .= "\t\$command['si'][] = " |
| 2861 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2854 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2862 | 2855 | } |
| 2863 | 2856 | // interdire {si 0} aussi ! |
| 2864 | 2857 | } else { |
@@ -2881,7 +2874,7 @@ discard block |
||
| 2881 | 2874 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2882 | 2875 | $boucle = &$boucles[$idb]; |
| 2883 | 2876 | $boucle->hash .= ' |
| 2884 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2877 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).'); |
|
| 2885 | 2878 | $command[\'sourcemode\'] = \'table\';'; |
| 2886 | 2879 | } |
| 2887 | 2880 | |
@@ -2914,11 +2907,10 @@ discard block |
||
| 2914 | 2907 | $table_sql = table_objet_sql(objet_type($table)); |
| 2915 | 2908 | |
| 2916 | 2909 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 2917 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2918 | - 'id_parent'; |
|
| 2910 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 2919 | 2911 | |
| 2920 | 2912 | $in = "IN"; |
| 2921 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2913 | + $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2922 | 2914 | if ($not) { |
| 2923 | 2915 | $where = array("'NOT'", $where); |
| 2924 | 2916 | } |
@@ -1472,10 +1472,12 @@ discard block |
||
| 1472 | 1472 | if ($crit->cond) { |
| 1473 | 1473 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1474 | 1474 | $where = array("'?'", $pred, $where, "''"); |
| 1475 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1475 | + if ($where_complement) { |
|
| 1476 | + // condition annexe du type "AND (objet='article')" |
|
| 1476 | 1477 | { |
| 1477 | 1478 | $where_complement = array("'?'", $pred, $where_complement, "''"); |
| 1478 | 1479 | } |
| 1480 | + } |
|
| 1479 | 1481 | } |
| 1480 | 1482 | if ($crit->exclus) { |
| 1481 | 1483 | if (!preg_match(",^L[0-9]+[.],", $arg)) { |
@@ -1496,10 +1498,12 @@ discard block |
||
| 1496 | 1498 | } |
| 1497 | 1499 | |
| 1498 | 1500 | $boucles[$idb]->where[] = $where; |
| 1499 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1501 | + if ($where_complement) { |
|
| 1502 | + // condition annexe du type "AND (objet='article')" |
|
| 1500 | 1503 | { |
| 1501 | 1504 | $boucles[$idb]->where[] = $where_complement; |
| 1502 | 1505 | } |
| 1506 | + } |
|
| 1503 | 1507 | } |
| 1504 | 1508 | |
| 1505 | 1509 | // https://code.spip.net/@critere_IN_cas |
@@ -1892,17 +1896,21 @@ discard block |
||
| 1892 | 1896 | ); |
| 1893 | 1897 | } |
| 1894 | 1898 | $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
| 1895 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1899 | + if ($where_complement) { |
|
| 1900 | + // condition annexe du type "AND (objet='article')" |
|
| 1896 | 1901 | { |
| 1897 | 1902 | $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
| 1898 | 1903 | } |
| 1904 | + } |
|
| 1899 | 1905 | } |
| 1900 | 1906 | |
| 1901 | 1907 | $boucles[$idb]->where[] = $where; |
| 1902 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1908 | + if ($where_complement) { |
|
| 1909 | + // condition annexe du type "AND (objet='article')" |
|
| 1903 | 1910 | { |
| 1904 | 1911 | $boucles[$idb]->where[] = $where_complement; |
| 1905 | 1912 | } |
| 1913 | + } |
|
| 1906 | 1914 | } |
| 1907 | 1915 | |
| 1908 | 1916 | |
@@ -2013,8 +2021,7 @@ discard block |
||
| 2013 | 2021 | // Champ joker * des iterateurs DATA qui accepte tout |
| 2014 | 2022 | if (@array_key_exists('*', $desc['field'])) { |
| 2015 | 2023 | $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
| 2016 | - } |
|
| 2017 | - else { |
|
| 2024 | + } else { |
|
| 2018 | 2025 | $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
| 2019 | 2026 | if (!$r) { |
| 2020 | 2027 | return ''; |
@@ -2056,8 +2063,7 @@ discard block |
||
| 2056 | 2063 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2057 | 2064 | . ",'" . addslashes($type_cast_quote) . "'"; |
| 2058 | 2065 | $val[0] = "sql_quote($r)"; |
| 2059 | - } |
|
| 2060 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2066 | + } elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2061 | 2067 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2062 | 2068 | $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
| 2063 | 2069 | } |
@@ -432,6 +432,10 @@ discard block |
||
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | // https://code.spip.net/@reference_boucle_debug |
| 435 | +/** |
|
| 436 | + * @param string $nom |
|
| 437 | + * @param string $self |
|
| 438 | + */ |
|
| 435 | 439 | function reference_boucle_debug($n, $nom, $self) { |
| 436 | 440 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 437 | 441 | |
@@ -820,6 +824,9 @@ discard block |
||
| 820 | 824 | } |
| 821 | 825 | |
| 822 | 826 | // https://code.spip.net/@debusquer_entete |
| 827 | +/** |
|
| 828 | + * @param string $corps |
|
| 829 | + */ |
|
| 823 | 830 | function debusquer_entete($titre, $corps) { |
| 824 | 831 | |
| 825 | 832 | include_spip('balise/formulaire_admin'); |
@@ -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,135 +66,135 @@ discard block |
||
| 66 | 66 | * - string si $message à false. |
| 67 | 67 | **/ |
| 68 | 68 | function public_debusquer_dist($message = '', $lieu = '', $opt = array()) { |
| 69 | - static $tableau_des_erreurs = array(); |
|
| 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 = array(); |
|
| 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[] = array($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 (ob_get_length() |
|
| 119 | - and |
|
| 120 | - !in_array('ob_gzhandler', ob_get_status()) |
|
| 121 | - ) { |
|
| 122 | - ob_end_clean(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 126 | - $fonc = _request('var_mode_objet'); |
|
| 127 | - $mode = _request('var_mode_affiche'); |
|
| 128 | - $self = str_replace("\\'", ''', self()); |
|
| 129 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | - |
|
| 131 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | - . '<br />' |
|
| 133 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | - |
|
| 135 | - if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | - return $res; |
|
| 137 | - } |
|
| 138 | - if ($tableau_des_erreurs) { |
|
| 139 | - http_status(503); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - http_no_cache(); |
|
| 143 | - if (isset($_GET['var_profile'])) { |
|
| 144 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | - } else { |
|
| 147 | - if (!$fonc) { |
|
| 148 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | - } |
|
| 150 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | - } |
|
| 152 | - if ($message === false) { |
|
| 153 | - lang_select(); |
|
| 154 | - |
|
| 155 | - return debusquer_entete($titre, $res); |
|
| 156 | - } else { |
|
| 157 | - echo debusquer_entete($titre, $res); |
|
| 158 | - } |
|
| 159 | - exit; |
|
| 69 | + static $tableau_des_erreurs = array(); |
|
| 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 = array(); |
|
| 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[] = array($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 (ob_get_length() |
|
| 119 | + and |
|
| 120 | + !in_array('ob_gzhandler', ob_get_status()) |
|
| 121 | + ) { |
|
| 122 | + ob_end_clean(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 126 | + $fonc = _request('var_mode_objet'); |
|
| 127 | + $mode = _request('var_mode_affiche'); |
|
| 128 | + $self = str_replace("\\'", ''', self()); |
|
| 129 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | + |
|
| 131 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | + . '<br />' |
|
| 133 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | + |
|
| 135 | + if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | + return $res; |
|
| 137 | + } |
|
| 138 | + if ($tableau_des_erreurs) { |
|
| 139 | + http_status(503); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + http_no_cache(); |
|
| 143 | + if (isset($_GET['var_profile'])) { |
|
| 144 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | + } else { |
|
| 147 | + if (!$fonc) { |
|
| 148 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | + } |
|
| 150 | + $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | + } |
|
| 152 | + if ($message === false) { |
|
| 153 | + lang_select(); |
|
| 154 | + |
|
| 155 | + return debusquer_entete($titre, $res); |
|
| 156 | + } else { |
|
| 157 | + echo debusquer_entete($titre, $res); |
|
| 158 | + } |
|
| 159 | + exit; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | function debusquer_compose_message($msg) { |
| 163 | - if (is_array($msg)) { |
|
| 164 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | - if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | - // message avec argument: instancier |
|
| 168 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | - } else { |
|
| 170 | - // message SQL: interpreter |
|
| 171 | - $msg = debusquer_requete($msg); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | - $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 177 | - // une erreur critique sort $message en array |
|
| 178 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | - spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 180 | - |
|
| 181 | - return $msg; |
|
| 163 | + if (is_array($msg)) { |
|
| 164 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | + if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | + // message avec argument: instancier |
|
| 168 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | + } else { |
|
| 170 | + // message SQL: interpreter |
|
| 171 | + $msg = debusquer_requete($msg); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | + $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 177 | + // une erreur critique sort $message en array |
|
| 178 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | + spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 180 | + |
|
| 181 | + return $msg; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function debusquer_bandeau($erreurs) { |
| 185 | 185 | |
| 186 | - if (!empty($erreurs)) { |
|
| 187 | - $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 186 | + if (!empty($erreurs)) { |
|
| 187 | + $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 188 | 188 | |
| 189 | - return debusquer_navigation($erreurs, $n); |
|
| 190 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | - include_spip('public/tracer'); |
|
| 192 | - list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 189 | + return debusquer_navigation($erreurs, $n); |
|
| 190 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | + include_spip('public/tracer'); |
|
| 192 | + list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 193 | 193 | |
| 194 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | - } else { |
|
| 196 | - return ''; |
|
| 197 | - } |
|
| 194 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | + } else { |
|
| 196 | + return ''; |
|
| 197 | + } |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -205,42 +205,42 @@ discard block |
||
| 205 | 205 | **/ |
| 206 | 206 | function debusquer_contexte($env) { |
| 207 | 207 | |
| 208 | - if (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 = array(); |
|
| 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>#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 208 | + if (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 = array(); |
|
| 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>#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,67 +248,67 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | function debusquer_navigation($tableau, $caption = array(), $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 = $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 | - |
|
| 291 | - return "\n<table id='$id'>" |
|
| 292 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 293 | - . $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 = $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 | + |
|
| 291 | + return "\n<table id='$id'>" |
|
| 292 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 293 | + . $caption[0] |
|
| 294 | 294 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 295 | 295 | # aider('erreur_compilation'), |
| 296 | - . "</caption>" |
|
| 297 | - // fausse caption du chrono (mais vraie nav) |
|
| 298 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 299 | - . "<tr><th>" |
|
| 300 | - . _T('numero') |
|
| 301 | - . "</th><th>" |
|
| 302 | - . _T('public:message') |
|
| 303 | - . "</th><th>" |
|
| 304 | - . _T('squelette') |
|
| 305 | - . "</th><th>" |
|
| 306 | - . _T('zbug_boucle') |
|
| 307 | - . "</th><th>" |
|
| 308 | - . _T('ligne') |
|
| 309 | - . "</th></tr>" |
|
| 310 | - . $res |
|
| 311 | - . "</table>"; |
|
| 296 | + . "</caption>" |
|
| 297 | + // fausse caption du chrono (mais vraie nav) |
|
| 298 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 299 | + . "<tr><th>" |
|
| 300 | + . _T('numero') |
|
| 301 | + . "</th><th>" |
|
| 302 | + . _T('public:message') |
|
| 303 | + . "</th><th>" |
|
| 304 | + . _T('squelette') |
|
| 305 | + . "</th><th>" |
|
| 306 | + . _T('zbug_boucle') |
|
| 307 | + . "</th><th>" |
|
| 308 | + . _T('ligne') |
|
| 309 | + . "</th></tr>" |
|
| 310 | + . $res |
|
| 311 | + . "</table>"; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | |
@@ -328,125 +328,125 @@ discard block |
||
| 328 | 328 | * ou un tableau si l'erreur est critique |
| 329 | 329 | **/ |
| 330 | 330 | function debusquer_requete($message) { |
| 331 | - list($errno, $msg, $query) = $message; |
|
| 332 | - |
|
| 333 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 334 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 335 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 336 | - $errno = $regs[2]; |
|
| 337 | - } elseif (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', array('errsys' => $errno)) |
|
| 347 | - . "</blink><br />\n<b>" |
|
| 348 | - . _T('info_erreur_systeme2', |
|
| 349 | - array('script' => generer_url_ecrire('base_repair'))) |
|
| 350 | - . '</b><br />'; |
|
| 351 | - spip_log("Erreur systeme $errno"); |
|
| 352 | - |
|
| 353 | - return array($retour, ''); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - // Requete erronee |
|
| 357 | - $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 358 | - . spip_htmlspecialchars($msg) |
|
| 359 | - . "\n<br /><span style='color: red'><b>" |
|
| 360 | - . spip_htmlspecialchars($query) |
|
| 361 | - . "</b></span></tt><br />"; |
|
| 362 | - |
|
| 363 | - //. aider('erreur_mysql'); |
|
| 364 | - |
|
| 365 | - return $err; |
|
| 331 | + list($errno, $msg, $query) = $message; |
|
| 332 | + |
|
| 333 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 334 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 335 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 336 | + $errno = $regs[2]; |
|
| 337 | + } elseif (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', array('errsys' => $errno)) |
|
| 347 | + . "</blink><br />\n<b>" |
|
| 348 | + . _T('info_erreur_systeme2', |
|
| 349 | + array('script' => generer_url_ecrire('base_repair'))) |
|
| 350 | + . '</b><br />'; |
|
| 351 | + spip_log("Erreur systeme $errno"); |
|
| 352 | + |
|
| 353 | + return array($retour, ''); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + // Requete erronee |
|
| 357 | + $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 358 | + . spip_htmlspecialchars($msg) |
|
| 359 | + . "\n<br /><span style='color: red'><b>" |
|
| 360 | + . spip_htmlspecialchars($query) |
|
| 361 | + . "</b></span></tt><br />"; |
|
| 362 | + |
|
| 363 | + //. aider('erreur_mysql'); |
|
| 364 | + |
|
| 365 | + return $err; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | |
| 369 | 369 | // https://code.spip.net/@trouve_boucle_debug |
| 370 | 370 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = "") { |
| 371 | 371 | |
| 372 | - $id = $nom . $boucle; |
|
| 373 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 374 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 375 | - |
|
| 376 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 377 | - $y = substr_count($v[0], "\n"); |
|
| 378 | - } else { |
|
| 379 | - if ($v[1][0] == '#') // balise dynamique |
|
| 380 | - { |
|
| 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 array($nom, $boucle, $v[2] - 1 + $n - $debut); |
|
| 400 | - } |
|
| 401 | - $debut += $y; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return array($nom, $boucle, $n - $debut); |
|
| 372 | + $id = $nom . $boucle; |
|
| 373 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 374 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 375 | + |
|
| 376 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 377 | + $y = substr_count($v[0], "\n"); |
|
| 378 | + } else { |
|
| 379 | + if ($v[1][0] == '#') // balise dynamique |
|
| 380 | + { |
|
| 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 array($nom, $boucle, $v[2] - 1 + $n - $debut); |
|
| 400 | + } |
|
| 401 | + $debut += $y; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return array($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 | - { |
|
| 416 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) // a defaut on cherche le param 'page' |
|
| 417 | - { |
|
| 418 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 419 | - $reg[1] = "inconnu"; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 424 | - |
|
| 425 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 426 | - if (preg_match($incl, $v)) { |
|
| 427 | - return $k; |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - 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 | + { |
|
| 416 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) // a defaut on cherche le param 'page' |
|
| 417 | + { |
|
| 418 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 419 | + $reg[1] = "inconnu"; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 424 | + |
|
| 425 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 426 | + if (preg_match($incl, $v)) { |
|
| 427 | + return $k; |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return ""; |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | // https://code.spip.net/@reference_boucle_debug |
| 435 | 435 | function reference_boucle_debug($n, $nom, $self) { |
| 436 | - list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 437 | - |
|
| 438 | - if (!$boucle) { |
|
| 439 | - return !$ligne ? "" : |
|
| 440 | - (" (" . |
|
| 441 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 442 | - _T('squelette_ligne')) . |
|
| 443 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 444 | - } else { |
|
| 445 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 446 | - |
|
| 447 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 448 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 449 | - } |
|
| 436 | + list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 437 | + |
|
| 438 | + if (!$boucle) { |
|
| 439 | + return !$ligne ? "" : |
|
| 440 | + (" (" . |
|
| 441 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 442 | + _T('squelette_ligne')) . |
|
| 443 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 444 | + } else { |
|
| 445 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 446 | + |
|
| 447 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 448 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 449 | + } |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | // affiche un texte avec numero de ligne et ancre. |
@@ -454,395 +454,395 @@ discard block |
||
| 454 | 454 | // https://code.spip.net/@ancre_texte |
| 455 | 455 | function ancre_texte($texte, $fautifs = array(), $nocpt = false) { |
| 456 | 456 | |
| 457 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 458 | - if ($var_mode_ligne) { |
|
| 459 | - $fautifs[] = array($var_mode_ligne); |
|
| 460 | - } |
|
| 461 | - $res = ''; |
|
| 462 | - |
|
| 463 | - $s = highlight_string($texte, true); |
|
| 464 | - if (substr($s, 0, 6) == '<code>') { |
|
| 465 | - $s = substr($s, 6); |
|
| 466 | - $res = '<code>'; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 470 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 471 | - $s); |
|
| 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 = array(); |
|
| 482 | - $loc = array(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> |
|
| 457 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 458 | + if ($var_mode_ligne) { |
|
| 459 | + $fautifs[] = array($var_mode_ligne); |
|
| 460 | + } |
|
| 461 | + $res = ''; |
|
| 462 | + |
|
| 463 | + $s = highlight_string($texte, true); |
|
| 464 | + if (substr($s, 0, 6) == '<code>') { |
|
| 465 | + $s = substr($s, 6); |
|
| 466 | + $res = '<code>'; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 470 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 471 | + $s); |
|
| 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 = array(); |
|
| 482 | + $loc = array(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, array('', '')); |
|
| 545 | - } |
|
| 546 | - } else { |
|
| 547 | - if (strlen(trim($res))) { |
|
| 548 | - return "<img src='" . chemin_image('compat-16.png') . "' 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('compat-16.png') . "' 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, array('', '')); |
|
| 545 | + } |
|
| 546 | + } else { |
|
| 547 | + if (strlen(trim($res))) { |
|
| 548 | + return "<img src='" . chemin_image('compat-16.png') . "' 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('compat-16.png') . "' 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 array(ancre_texte('', array('', '')), false); |
|
| 592 | - } |
|
| 593 | - if (!$errs) { |
|
| 594 | - return array(ancre_texte($texte, array('', '')), true); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 598 | - |
|
| 599 | - $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 600 | - $encore = count_occ($errs); |
|
| 601 | - $encore2 = array(); |
|
| 602 | - $fautifs = array(); |
|
| 603 | - |
|
| 604 | - $err = '<tr><th>' |
|
| 605 | - . _T('numero') |
|
| 606 | - . "</th><th>" |
|
| 607 | - . _T('occurence') |
|
| 608 | - . "</th><th>" |
|
| 609 | - . _T('ligne') |
|
| 610 | - . "</th><th>" |
|
| 611 | - . _T('colonne') |
|
| 612 | - . "</th><th>" |
|
| 613 | - . _T('erreur') |
|
| 614 | - . "</th></tr>"; |
|
| 615 | - |
|
| 616 | - $i = 0; |
|
| 617 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 618 | - foreach ($errs as $r) { |
|
| 619 | - $i++; |
|
| 620 | - list($msg, $ligne, $col) = $r; |
|
| 621 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 622 | - if (isset($encore2[$msg])) { |
|
| 623 | - $ref = ++$encore2[$msg]; |
|
| 624 | - } else { |
|
| 625 | - $encore2[$msg] = $ref = 1; |
|
| 626 | - } |
|
| 627 | - $err .= "<tr style='background-color: " |
|
| 628 | - . $colors[$i % 2] |
|
| 629 | - . "'><td $style><a href='#debut_err'>" |
|
| 630 | - . $i |
|
| 631 | - . "</a></td><td $style>" |
|
| 632 | - . "$ref/$encore[$msg]</td>" |
|
| 633 | - . "<td $style><a href='#L" |
|
| 634 | - . $ligne |
|
| 635 | - . "' id='T$i'>" |
|
| 636 | - . $ligne |
|
| 637 | - . "</a></td><td $style>" |
|
| 638 | - . $col |
|
| 639 | - . "</td><td>$msg</td></tr>\n"; |
|
| 640 | - $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 641 | - } |
|
| 642 | - $err = "<h2 style='text-align: center'>" |
|
| 643 | - . $i |
|
| 644 | - . "<a href='#fin_err'>" |
|
| 645 | - . " " . _T('erreur_texte') |
|
| 646 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 647 | - . $err |
|
| 648 | - . " </table><a id='fin_err'></a>"; |
|
| 649 | - |
|
| 650 | - return array(ancre_texte($texte, $fautifs), $err); |
|
| 651 | - } else { |
|
| 652 | - list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 653 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 654 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 655 | - $err = $msg . |
|
| 656 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 657 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 658 | - |
|
| 659 | - return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 660 | - } |
|
| 587 | + $errs = $res->err; |
|
| 588 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 589 | + |
|
| 590 | + if (!$texte and !$errs) { |
|
| 591 | + return array(ancre_texte('', array('', '')), false); |
|
| 592 | + } |
|
| 593 | + if (!$errs) { |
|
| 594 | + return array(ancre_texte($texte, array('', '')), true); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 598 | + |
|
| 599 | + $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 600 | + $encore = count_occ($errs); |
|
| 601 | + $encore2 = array(); |
|
| 602 | + $fautifs = array(); |
|
| 603 | + |
|
| 604 | + $err = '<tr><th>' |
|
| 605 | + . _T('numero') |
|
| 606 | + . "</th><th>" |
|
| 607 | + . _T('occurence') |
|
| 608 | + . "</th><th>" |
|
| 609 | + . _T('ligne') |
|
| 610 | + . "</th><th>" |
|
| 611 | + . _T('colonne') |
|
| 612 | + . "</th><th>" |
|
| 613 | + . _T('erreur') |
|
| 614 | + . "</th></tr>"; |
|
| 615 | + |
|
| 616 | + $i = 0; |
|
| 617 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 618 | + foreach ($errs as $r) { |
|
| 619 | + $i++; |
|
| 620 | + list($msg, $ligne, $col) = $r; |
|
| 621 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 622 | + if (isset($encore2[$msg])) { |
|
| 623 | + $ref = ++$encore2[$msg]; |
|
| 624 | + } else { |
|
| 625 | + $encore2[$msg] = $ref = 1; |
|
| 626 | + } |
|
| 627 | + $err .= "<tr style='background-color: " |
|
| 628 | + . $colors[$i % 2] |
|
| 629 | + . "'><td $style><a href='#debut_err'>" |
|
| 630 | + . $i |
|
| 631 | + . "</a></td><td $style>" |
|
| 632 | + . "$ref/$encore[$msg]</td>" |
|
| 633 | + . "<td $style><a href='#L" |
|
| 634 | + . $ligne |
|
| 635 | + . "' id='T$i'>" |
|
| 636 | + . $ligne |
|
| 637 | + . "</a></td><td $style>" |
|
| 638 | + . $col |
|
| 639 | + . "</td><td>$msg</td></tr>\n"; |
|
| 640 | + $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 641 | + } |
|
| 642 | + $err = "<h2 style='text-align: center'>" |
|
| 643 | + . $i |
|
| 644 | + . "<a href='#fin_err'>" |
|
| 645 | + . " " . _T('erreur_texte') |
|
| 646 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 647 | + . $err |
|
| 648 | + . " </table><a id='fin_err'></a>"; |
|
| 649 | + |
|
| 650 | + return array(ancre_texte($texte, $fautifs), $err); |
|
| 651 | + } else { |
|
| 652 | + list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 653 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 654 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 655 | + $err = $msg . |
|
| 656 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 657 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 658 | + |
|
| 659 | + return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 660 | + } |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | // https://code.spip.net/@count_occ |
| 664 | 664 | function count_occ($regs) { |
| 665 | - $encore = array(); |
|
| 666 | - foreach ($regs as $r) { |
|
| 667 | - if (isset($encore[$r[0]])) { |
|
| 668 | - $encore[$r[0]]++; |
|
| 669 | - } else { |
|
| 670 | - $encore[$r[0]] = 1; |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - return $encore; |
|
| 665 | + $encore = array(); |
|
| 666 | + foreach ($regs as $r) { |
|
| 667 | + if (isset($encore[$r[0]])) { |
|
| 668 | + $encore[$r[0]]++; |
|
| 669 | + } else { |
|
| 670 | + $encore[$r[0]] = 1; |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + return $encore; |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | function debusquer_navigation_squelettes($self) { |
| 678 | 678 | |
| 679 | - $res = ''; |
|
| 680 | - $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 681 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 682 | - $t_skel = _T('squelette'); |
|
| 683 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 684 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 685 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 686 | - $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
|
| 687 | - array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
|
| 688 | - |
|
| 689 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 690 | - . $t_skel |
|
| 691 | - . ' ' |
|
| 692 | - . $sourcefile |
|
| 693 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 694 | - . $t_skel |
|
| 695 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 696 | - . _T('zbug_resultat') |
|
| 697 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 698 | - . _T('zbug_code') |
|
| 699 | - . "</a>\n<a href='" |
|
| 700 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 701 | - . "'>" |
|
| 702 | - . _T('zbug_calcul') |
|
| 703 | - . "</a></legend>" |
|
| 704 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 705 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 706 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 707 | - . "</fieldset>\n"; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return $res; |
|
| 679 | + $res = ''; |
|
| 680 | + $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 681 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 682 | + $t_skel = _T('squelette'); |
|
| 683 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 684 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 685 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 686 | + $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
|
| 687 | + array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
|
| 688 | + |
|
| 689 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 690 | + . $t_skel |
|
| 691 | + . ' ' |
|
| 692 | + . $sourcefile |
|
| 693 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 694 | + . $t_skel |
|
| 695 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 696 | + . _T('zbug_resultat') |
|
| 697 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 698 | + . _T('zbug_code') |
|
| 699 | + . "</a>\n<a href='" |
|
| 700 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 701 | + . "'>" |
|
| 702 | + . _T('zbug_calcul') |
|
| 703 | + . "</a></legend>" |
|
| 704 | + . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 705 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 706 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 707 | + . "</fieldset>\n"; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return $res; |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 714 | - $i = 0; |
|
| 715 | - $res = ''; |
|
| 716 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 717 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 718 | - |
|
| 719 | - foreach ($boucles as $objet => $boucle) { |
|
| 720 | - if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 721 | - $i++; |
|
| 722 | - $nom = $boucle->id_boucle; |
|
| 723 | - $req = $boucle->type_requete; |
|
| 724 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 725 | - $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 726 | - |
|
| 727 | - $res .= "\n<tr style='background-color: " . |
|
| 728 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 729 | - "'><td align='right'>$i</td><td>\n" . |
|
| 730 | - "<a class='debug_link_boucle' href='" . |
|
| 731 | - $self2 . |
|
| 732 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 733 | - _T('zbug_boucle') . |
|
| 734 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 735 | - $self2 . |
|
| 736 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 737 | - _T('zbug_resultat') . |
|
| 738 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 739 | - $self2 . |
|
| 740 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 741 | - _T('zbug_code') . |
|
| 742 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 743 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 744 | - "'>" . |
|
| 745 | - _T('zbug_calcul') . |
|
| 746 | - "</a></td><td>\n" . |
|
| 747 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 748 | - "</td><td>\n" . |
|
| 749 | - $req . |
|
| 750 | - "</td><td>\n" . |
|
| 751 | - spip_htmlspecialchars($crit) . |
|
| 752 | - "</td></tr>"; |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - return $res; |
|
| 714 | + $i = 0; |
|
| 715 | + $res = ''; |
|
| 716 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 717 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 718 | + |
|
| 719 | + foreach ($boucles as $objet => $boucle) { |
|
| 720 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 721 | + $i++; |
|
| 722 | + $nom = $boucle->id_boucle; |
|
| 723 | + $req = $boucle->type_requete; |
|
| 724 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 725 | + $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 726 | + |
|
| 727 | + $res .= "\n<tr style='background-color: " . |
|
| 728 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 729 | + "'><td align='right'>$i</td><td>\n" . |
|
| 730 | + "<a class='debug_link_boucle' href='" . |
|
| 731 | + $self2 . |
|
| 732 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 733 | + _T('zbug_boucle') . |
|
| 734 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 735 | + $self2 . |
|
| 736 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 737 | + _T('zbug_resultat') . |
|
| 738 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 739 | + $self2 . |
|
| 740 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 741 | + _T('zbug_code') . |
|
| 742 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 743 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 744 | + "'>" . |
|
| 745 | + _T('zbug_calcul') . |
|
| 746 | + "</a></td><td>\n" . |
|
| 747 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 748 | + "</td><td>\n" . |
|
| 749 | + $req . |
|
| 750 | + "</td><td>\n" . |
|
| 751 | + spip_htmlspecialchars($crit) . |
|
| 752 | + "</td></tr>"; |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + return $res; |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | function debusquer_source($objet, $affiche) { |
| 760 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 761 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 762 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 763 | - } else { |
|
| 764 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 765 | - } |
|
| 766 | - $res2 = ""; |
|
| 767 | - |
|
| 768 | - if ($affiche == 'resultat') { |
|
| 769 | - $legend = $nom; |
|
| 770 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 771 | - if (function_exists('_mysql_traite_query')) { |
|
| 772 | - $c = strtolower(_request('connect')); |
|
| 773 | - $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 774 | - $req = _mysql_traite_query($req, '', $c); |
|
| 775 | - } |
|
| 776 | - // permettre le copier/coller facile |
|
| 777 | - // $res = ancre_texte($req, array(), true); |
|
| 778 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 779 | - // formatage et affichage des resultats bruts de la requete |
|
| 780 | - $ress_req = spip_query($req); |
|
| 781 | - $brut_sql = ''; |
|
| 782 | - $num = 1; |
|
| 783 | - // eviter l'affichage de milliers de lignes |
|
| 784 | - // personnalisation possible dans mes_options |
|
| 785 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 786 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 787 | - if ($num <= $max_aff) { |
|
| 788 | - $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 789 | - $brut_sql .= "<p>"; |
|
| 790 | - foreach ($retours_sql as $key => $val) { |
|
| 791 | - $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 792 | - } |
|
| 793 | - $brut_sql .= "</p>"; |
|
| 794 | - } |
|
| 795 | - $num++; |
|
| 796 | - } |
|
| 797 | - $res2 = interdire_scripts($brut_sql); |
|
| 798 | - foreach ($quoi as $view) { |
|
| 799 | - // ne pas afficher les $contexte_inclus |
|
| 800 | - $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 801 | - if ($view) { |
|
| 802 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 803 | - } |
|
| 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 array($legend, $res, $res2); |
|
| 760 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 761 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 762 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 763 | + } else { |
|
| 764 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 765 | + } |
|
| 766 | + $res2 = ""; |
|
| 767 | + |
|
| 768 | + if ($affiche == 'resultat') { |
|
| 769 | + $legend = $nom; |
|
| 770 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 771 | + if (function_exists('_mysql_traite_query')) { |
|
| 772 | + $c = strtolower(_request('connect')); |
|
| 773 | + $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 774 | + $req = _mysql_traite_query($req, '', $c); |
|
| 775 | + } |
|
| 776 | + // permettre le copier/coller facile |
|
| 777 | + // $res = ancre_texte($req, array(), true); |
|
| 778 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 779 | + // formatage et affichage des resultats bruts de la requete |
|
| 780 | + $ress_req = spip_query($req); |
|
| 781 | + $brut_sql = ''; |
|
| 782 | + $num = 1; |
|
| 783 | + // eviter l'affichage de milliers de lignes |
|
| 784 | + // personnalisation possible dans mes_options |
|
| 785 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 786 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 787 | + if ($num <= $max_aff) { |
|
| 788 | + $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 789 | + $brut_sql .= "<p>"; |
|
| 790 | + foreach ($retours_sql as $key => $val) { |
|
| 791 | + $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 792 | + } |
|
| 793 | + $brut_sql .= "</p>"; |
|
| 794 | + } |
|
| 795 | + $num++; |
|
| 796 | + } |
|
| 797 | + $res2 = interdire_scripts($brut_sql); |
|
| 798 | + foreach ($quoi as $view) { |
|
| 799 | + // ne pas afficher les $contexte_inclus |
|
| 800 | + $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 801 | + if ($view) { |
|
| 802 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 803 | + } |
|
| 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 array($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 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | if (!$fonc) { |
| 148 | 148 | $fonc = $GLOBALS['debug_objets']['principal']; |
| 149 | 149 | } |
| 150 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 150 | + $titre = !$mode ? $fonc : ($mode.(isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " ".$GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | 151 | } |
| 152 | 152 | if ($message === false) { |
| 153 | 153 | lang_select(); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
| 177 | 177 | // une erreur critique sort $message en array |
| 178 | 178 | $debug = is_array($msg) ? $msg[1] : $msg; |
| 179 | - spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 179 | + spip_log("Debug: ".$debug." (".$fond.")"); |
|
| 180 | 180 | |
| 181 | 181 | return $msg; |
| 182 | 182 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | function debusquer_bandeau($erreurs) { |
| 185 | 185 | |
| 186 | 186 | if (!empty($erreurs)) { |
| 187 | - $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 187 | + $n = array(count($erreurs).' '._T('zbug_erreur_squelette')); |
|
| 188 | 188 | |
| 189 | 189 | return debusquer_navigation($erreurs, $n); |
| 190 | 190 | } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
@@ -218,25 +218,25 @@ discard block |
||
| 218 | 218 | $valeur_simple = array(); |
| 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 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // Requete erronee |
| 357 | - $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 357 | + $err = "<b>"._T('avis_erreur_mysql')." $errno</b><br /><tt>\n" |
|
| 358 | 358 | . spip_htmlspecialchars($msg) |
| 359 | 359 | . "\n<br /><span style='color: red'><b>" |
| 360 | 360 | . spip_htmlspecialchars($query) |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | // https://code.spip.net/@trouve_boucle_debug |
| 370 | 370 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = "") { |
| 371 | 371 | |
| 372 | - $id = $nom . $boucle; |
|
| 372 | + $id = $nom.$boucle; |
|
| 373 | 373 | if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
| 374 | 374 | foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
| 375 | 375 | |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 423 | + $incl = ','.$reg[1].'[.]\w$,'; |
|
| 424 | 424 | |
| 425 | 425 | foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
| 426 | 426 | if (preg_match($incl, $v)) { |
@@ -436,16 +436,13 @@ discard block |
||
| 436 | 436 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 437 | 437 | |
| 438 | 438 | if (!$boucle) { |
| 439 | - return !$ligne ? "" : |
|
| 440 | - (" (" . |
|
| 441 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 442 | - _T('squelette_ligne')) . |
|
| 439 | + return !$ligne ? "" : (" (". |
|
| 440 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : _T('squelette_ligne')). |
|
| 443 | 441 | " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
| 444 | 442 | } else { |
| 445 | 443 | $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
| 446 | 444 | |
| 447 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 448 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 445 | + 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>)"; |
|
| 449 | 446 | } |
| 450 | 447 | } |
| 451 | 448 | |
@@ -467,13 +464,13 @@ discard block |
||
| 467 | 464 | } |
| 468 | 465 | |
| 469 | 466 | $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
| 470 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 467 | + '<\1>\2</\1><br />'."\n".'<\1>\3</\1>', |
|
| 471 | 468 | $s); |
| 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, array('', '')); |
| 545 | 542 | } |
| 546 | 543 | } else { |
| 547 | 544 | if (strlen(trim($res))) { |
| 548 | - return "<img src='" . chemin_image('compat-16.png') . "' 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('compat-16.png')."' 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('compat-16.png') . "' 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('compat-16.png')."' 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 array(ancre_texte('', array('', '')), false); |
@@ -642,7 +639,7 @@ discard block |
||
| 642 | 639 | $err = "<h2 style='text-align: center'>" |
| 643 | 640 | . $i |
| 644 | 641 | . "<a href='#fin_err'>" |
| 645 | - . " " . _T('erreur_texte') |
|
| 642 | + . " "._T('erreur_texte') |
|
| 646 | 643 | . "</a></h2><table id='debut_err' style='width: 100%'>" |
| 647 | 644 | . $err |
| 648 | 645 | . " </table><a id='fin_err'></a>"; |
@@ -652,9 +649,9 @@ discard block |
||
| 652 | 649 | list($msg, $fermant, $ouvrant) = $errs[0]; |
| 653 | 650 | $rf = reference_boucle_debug($fermant, $fonc, $self); |
| 654 | 651 | $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
| 655 | - $err = $msg . |
|
| 656 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 657 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 652 | + $err = $msg. |
|
| 653 | + "<a href='#L".$fermant."'>$fermant</a>$rf<br />". |
|
| 654 | + "<a href='#L".$ouvrant."'>$ouvrant</a>$ro"; |
|
| 658 | 655 | |
| 659 | 656 | return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
| 660 | 657 | } |
@@ -686,7 +683,7 @@ discard block |
||
| 686 | 683 | $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
| 687 | 684 | array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
| 688 | 685 | |
| 689 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 686 | + $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 690 | 687 | . $t_skel |
| 691 | 688 | . ' ' |
| 692 | 689 | . $sourcefile |
@@ -701,7 +698,7 @@ discard block |
||
| 701 | 698 | . "'>" |
| 702 | 699 | . _T('zbug_calcul') |
| 703 | 700 | . "</a></legend>" |
| 704 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 701 | + . (!$temps ? '' : ("\n<span style='display:block;float:".$GLOBALS['spip_lang_right']."'>$temps</span><br />")) |
|
| 705 | 702 | . debusquer_contexte($contexte[$sourcefile]) |
| 706 | 703 | . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
| 707 | 704 | . "</fieldset>\n"; |
@@ -722,33 +719,33 @@ discard block |
||
| 722 | 719 | $nom = $boucle->id_boucle; |
| 723 | 720 | $req = $boucle->type_requete; |
| 724 | 721 | $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
| 725 | - $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 726 | - |
|
| 727 | - $res .= "\n<tr style='background-color: " . |
|
| 728 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 729 | - "'><td align='right'>$i</td><td>\n" . |
|
| 730 | - "<a class='debug_link_boucle' href='" . |
|
| 731 | - $self2 . |
|
| 732 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 733 | - _T('zbug_boucle') . |
|
| 734 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 735 | - $self2 . |
|
| 736 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 737 | - _T('zbug_resultat') . |
|
| 738 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 739 | - $self2 . |
|
| 740 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 741 | - _T('zbug_code') . |
|
| 742 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 743 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 744 | - "'>" . |
|
| 745 | - _T('zbug_calcul') . |
|
| 746 | - "</a></td><td>\n" . |
|
| 747 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 748 | - "</td><td>\n" . |
|
| 749 | - $req . |
|
| 750 | - "</td><td>\n" . |
|
| 751 | - spip_htmlspecialchars($crit) . |
|
| 722 | + $self2 = $self."&var_mode_objet=".$objet; |
|
| 723 | + |
|
| 724 | + $res .= "\n<tr style='background-color: ". |
|
| 725 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff'). |
|
| 726 | + "'><td align='right'>$i</td><td>\n". |
|
| 727 | + "<a class='debug_link_boucle' href='". |
|
| 728 | + $self2. |
|
| 729 | + "&var_mode_affiche=boucle#f_$nom_skel'>". |
|
| 730 | + _T('zbug_boucle'). |
|
| 731 | + "</a></td><td>\n<a class='debug_link_boucle' href='". |
|
| 732 | + $self2. |
|
| 733 | + "&var_mode_affiche=resultat#f_$nom_skel'>". |
|
| 734 | + _T('zbug_resultat'). |
|
| 735 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 736 | + $self2. |
|
| 737 | + "&var_mode_affiche=code#f_$nom_skel'>". |
|
| 738 | + _T('zbug_code'). |
|
| 739 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 740 | + str_replace('var_mode=', 'var_profile=', $self2). |
|
| 741 | + "'>". |
|
| 742 | + _T('zbug_calcul'). |
|
| 743 | + "</a></td><td>\n". |
|
| 744 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom). |
|
| 745 | + "</td><td>\n". |
|
| 746 | + $req. |
|
| 747 | + "</td><td>\n". |
|
| 748 | + spip_htmlspecialchars($crit). |
|
| 752 | 749 | "</td></tr>"; |
| 753 | 750 | } |
| 754 | 751 | } |
@@ -775,7 +772,7 @@ discard block |
||
| 775 | 772 | } |
| 776 | 773 | // permettre le copier/coller facile |
| 777 | 774 | // $res = ancre_texte($req, array(), true); |
| 778 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 775 | + $res = "<div id='T".md5($req)."'>\n<pre>\n".$req."</pre>\n</div>\n"; |
|
| 779 | 776 | // formatage et affichage des resultats bruts de la requete |
| 780 | 777 | $ress_req = spip_query($req); |
| 781 | 778 | $brut_sql = ''; |
@@ -785,10 +782,10 @@ discard block |
||
| 785 | 782 | $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
| 786 | 783 | while ($retours_sql = sql_fetch($ress_req)) { |
| 787 | 784 | if ($num <= $max_aff) { |
| 788 | - $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 785 | + $brut_sql .= "<h3>".($num == 1 ? $num." sur ".sql_count($ress_req) : $num)."</h3>"; |
|
| 789 | 786 | $brut_sql .= "<p>"; |
| 790 | 787 | foreach ($retours_sql as $key => $val) { |
| 791 | - $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 788 | + $brut_sql .= "<strong>".$key."</strong> => ".spip_htmlspecialchars(couper($val, 150))."<br />\n"; |
|
| 792 | 789 | } |
| 793 | 790 | $brut_sql .= "</p>"; |
| 794 | 791 | } |
@@ -799,15 +796,15 @@ discard block |
||
| 799 | 796 | // ne pas afficher les $contexte_inclus |
| 800 | 797 | $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
| 801 | 798 | if ($view) { |
| 802 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 799 | + $res2 .= "\n<br /><fieldset>".interdire_scripts($view)."</fieldset>"; |
|
| 803 | 800 | } |
| 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 | } |
@@ -102,6 +102,10 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // https://code.spip.net/@phraser_polyglotte |
| 105 | +/** |
|
| 106 | + * @param string $texte |
|
| 107 | + * @param integer $ligne |
|
| 108 | + */ |
|
| 105 | 109 | function phraser_polyglotte($texte, $ligne, $result) { |
| 106 | 110 | |
| 107 | 111 | if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
@@ -264,6 +268,9 @@ discard block |
||
| 264 | 268 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 265 | 269 | |
| 266 | 270 | // https://code.spip.net/@phraser_champs_etendus |
| 271 | +/** |
|
| 272 | + * @param integer $ligne |
|
| 273 | + */ |
|
| 267 | 274 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 268 | 275 | if ($texte === "") { |
| 269 | 276 | return $result; |
@@ -286,7 +293,7 @@ discard block |
||
| 286 | 293 | * https://code.spip.net/@phraser_args |
| 287 | 294 | * |
| 288 | 295 | * @param $texte |
| 289 | - * @param $fin |
|
| 296 | + * @param string $fin |
|
| 290 | 297 | * @param $sep |
| 291 | 298 | * @param $result |
| 292 | 299 | * @param $pointeur_champ |
@@ -306,6 +313,9 @@ discard block |
||
| 306 | 313 | } |
| 307 | 314 | |
| 308 | 315 | // https://code.spip.net/@phraser_arg |
| 316 | +/** |
|
| 317 | + * @param string $texte |
|
| 318 | + */ |
|
| 309 | 319 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 310 | 320 | preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
| 311 | 321 | $suite = ltrim($match[2]); |
@@ -443,6 +453,9 @@ discard block |
||
| 443 | 453 | |
| 444 | 454 | |
| 445 | 455 | // https://code.spip.net/@phraser_champs_exterieurs |
| 456 | +/** |
|
| 457 | + * @param string $texte |
|
| 458 | + */ |
|
| 446 | 459 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 447 | 460 | $res = array(); |
| 448 | 461 | while (($p = strpos($texte, "%$sep")) !== false) { |
@@ -462,6 +475,9 @@ discard block |
||
| 462 | 475 | } |
| 463 | 476 | |
| 464 | 477 | // https://code.spip.net/@phraser_champs_interieurs |
| 478 | +/** |
|
| 479 | + * @param string $sep |
|
| 480 | + */ |
|
| 465 | 481 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 466 | 482 | $i = 0; // en fait count($result) |
| 467 | 483 | $x = ""; |
@@ -755,6 +771,10 @@ discard block |
||
| 755 | 771 | } |
| 756 | 772 | |
| 757 | 773 | // https://code.spip.net/@phraser_critere_infixe |
| 774 | +/** |
|
| 775 | + * @param string $arg1 |
|
| 776 | + * @param string $arg2 |
|
| 777 | + */ |
|
| 758 | 778 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 759 | 779 | $args[0] = new Texte; |
| 760 | 780 | $args[0]->texte = $arg1; |
@@ -795,7 +815,7 @@ discard block |
||
| 795 | 815 | * @param $texte |
| 796 | 816 | * @param $id_parent |
| 797 | 817 | * @param $descr |
| 798 | - * @return array|null |
|
| 818 | + * @return string |
|
| 799 | 819 | */ |
| 800 | 820 | function public_trouver_premiere_boucle($texte, $id_parent, $descr) { |
| 801 | 821 | $premiere_boucle = null; |
@@ -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 | - phraser_args($texte, "/>", "", $result, $champ); |
|
| 89 | - if (!$champ->texte or count($champ->param) > 1) { |
|
| 90 | - if (!function_exists('normaliser_inclure')) { |
|
| 91 | - include_spip('public/normaliser'); |
|
| 92 | - } |
|
| 93 | - normaliser_inclure($champ); |
|
| 94 | - } |
|
| 95 | - $texte = substr($champ->apres, strpos($champ->apres, '>') + 1); |
|
| 96 | - $champ->apres = ""; |
|
| 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 | + phraser_args($texte, "/>", "", $result, $champ); |
|
| 89 | + if (!$champ->texte or count($champ->param) > 1) { |
|
| 90 | + if (!function_exists('normaliser_inclure')) { |
|
| 91 | + include_spip('public/normaliser'); |
|
| 92 | + } |
|
| 93 | + normaliser_inclure($champ); |
|
| 94 | + } |
|
| 95 | + $texte = substr($champ->apres, strpos($champ->apres, '>') + 1); |
|
| 96 | + $champ->apres = ""; |
|
| 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,41 +163,41 @@ 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 = array(); |
|
| 184 | - $largs = $match[5]; |
|
| 185 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | - $args[$r[1]] = phraser_champs($r[2], 0, array()); |
|
| 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 | - phraser_args($match[7], ":", '', array(), $champ); |
|
| 194 | - $result[] = $champ; |
|
| 195 | - } |
|
| 196 | - if ($texte !== "") { |
|
| 197 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - 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 = array(); |
|
| 184 | + $largs = $match[5]; |
|
| 185 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | + $args[$r[1]] = phraser_champs($r[2], 0, array()); |
|
| 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 | + phraser_args($match[7], ":", '', array(), $champ); |
|
| 194 | + $result[] = $champ; |
|
| 195 | + } |
|
| 196 | + if ($texte !== "") { |
|
| 197 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $result; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -215,47 +215,47 @@ discard block |
||
| 215 | 215 | * @return array |
| 216 | 216 | **/ |
| 217 | 217 | function phraser_champs($texte, $ligne, $result) { |
| 218 | - while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)) { |
|
| 219 | - $p = strpos($texte, $match[0]); |
|
| 220 | - // texte après la balise |
|
| 221 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 222 | - |
|
| 223 | - $debut = substr($texte, 0, $p); |
|
| 224 | - if ($p) { |
|
| 225 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 226 | - } |
|
| 227 | - $ligne += substr_count($debut, "\n"); |
|
| 228 | - $champ = new Champ; |
|
| 229 | - $champ->ligne = $ligne; |
|
| 230 | - $ligne += substr_count($match[0], "\n"); |
|
| 231 | - $champ->nom_boucle = $match[2]; |
|
| 232 | - $champ->nom_champ = $match[3]; |
|
| 233 | - $champ->etoile = $match[5]; |
|
| 234 | - |
|
| 235 | - if ($suite and $suite[0] == '{') { |
|
| 236 | - phraser_arg($suite, '', array(), $champ); |
|
| 237 | - // ce ltrim est une ereur de conception |
|
| 238 | - // mais on le conserve par souci de compatibilite |
|
| 239 | - $texte = ltrim($suite); |
|
| 240 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 241 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 242 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 218 | + while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)) { |
|
| 219 | + $p = strpos($texte, $match[0]); |
|
| 220 | + // texte après la balise |
|
| 221 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 222 | + |
|
| 223 | + $debut = substr($texte, 0, $p); |
|
| 224 | + if ($p) { |
|
| 225 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 226 | + } |
|
| 227 | + $ligne += substr_count($debut, "\n"); |
|
| 228 | + $champ = new Champ; |
|
| 229 | + $champ->ligne = $ligne; |
|
| 230 | + $ligne += substr_count($match[0], "\n"); |
|
| 231 | + $champ->nom_boucle = $match[2]; |
|
| 232 | + $champ->nom_champ = $match[3]; |
|
| 233 | + $champ->etoile = $match[5]; |
|
| 234 | + |
|
| 235 | + if ($suite and $suite[0] == '{') { |
|
| 236 | + phraser_arg($suite, '', array(), $champ); |
|
| 237 | + // ce ltrim est une ereur de conception |
|
| 238 | + // mais on le conserve par souci de compatibilite |
|
| 239 | + $texte = ltrim($suite); |
|
| 240 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 241 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 242 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 243 | 243 | if ($n = (strlen($suite) - strlen($texte))) { |
| 244 | 244 | $champ->apres = array(new Texte); |
| 245 | 245 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 246 | 246 | } |
| 247 | 247 | */ |
| 248 | - } else { |
|
| 249 | - $texte = $suite; |
|
| 250 | - } |
|
| 251 | - phraser_vieux($champ); |
|
| 252 | - $result[] = $champ; |
|
| 253 | - } |
|
| 254 | - if ($texte !== "") { |
|
| 255 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $result; |
|
| 248 | + } else { |
|
| 249 | + $texte = $suite; |
|
| 250 | + } |
|
| 251 | + phraser_vieux($champ); |
|
| 252 | + $result[] = $champ; |
|
| 253 | + } |
|
| 254 | + if ($texte !== "") { |
|
| 255 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $result; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Gestion des imbrications: |
@@ -265,15 +265,15 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | // https://code.spip.net/@phraser_champs_etendus |
| 267 | 267 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 268 | - if ($texte === "") { |
|
| 269 | - return $result; |
|
| 270 | - } |
|
| 271 | - $sep = '##'; |
|
| 272 | - while (strpos($texte, $sep) !== false) { |
|
| 273 | - $sep .= '#'; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
|
| 268 | + if ($texte === "") { |
|
| 269 | + return $result; |
|
| 270 | + } |
|
| 271 | + $sep = '##'; |
|
| 272 | + while (strpos($texte, $sep) !== false) { |
|
| 273 | + $sep .= '#'; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -293,270 +293,270 @@ discard block |
||
| 293 | 293 | * @return array |
| 294 | 294 | */ |
| 295 | 295 | function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ) { |
| 296 | - $texte = ltrim($texte); |
|
| 297 | - while (($texte !== "") && strpos($fin, $texte[0]) === false) { |
|
| 298 | - $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
|
| 299 | - $texte = ltrim($texte); |
|
| 300 | - } |
|
| 296 | + $texte = ltrim($texte); |
|
| 297 | + while (($texte !== "") && strpos($fin, $texte[0]) === false) { |
|
| 298 | + $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
|
| 299 | + $texte = ltrim($texte); |
|
| 300 | + } |
|
| 301 | 301 | # mettre ici la suite du texte, |
| 302 | 302 | # notamment pour que l'appelant vire le caractere fermant si besoin |
| 303 | - $pointeur_champ->apres = $texte; |
|
| 303 | + $pointeur_champ->apres = $texte; |
|
| 304 | 304 | |
| 305 | - return $result; |
|
| 305 | + return $result; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | // https://code.spip.net/@phraser_arg |
| 309 | 309 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 310 | - preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
|
| 311 | - $suite = ltrim($match[2]); |
|
| 312 | - $fonc = trim($match[1]); |
|
| 313 | - if ($fonc && $fonc[0] == "|") { |
|
| 314 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 315 | - } |
|
| 316 | - $res = array($fonc); |
|
| 317 | - $err_f = ''; |
|
| 318 | - // cas du filtre sans argument ou du critere / |
|
| 319 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 320 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 321 | - if (!$match[1]) { |
|
| 322 | - $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
|
| 323 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 324 | - $texte = ''; |
|
| 325 | - } else { |
|
| 326 | - $texte = $suite; |
|
| 327 | - } |
|
| 328 | - if ($err_f) { |
|
| 329 | - $pointeur_champ->param = false; |
|
| 330 | - } elseif ($fonc !== '') { |
|
| 331 | - $pointeur_champ->param[] = $res; |
|
| 332 | - } |
|
| 333 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 334 | - $pointeur_champ->fonctions[] = array($fonc, ''); |
|
| 335 | - |
|
| 336 | - return $result; |
|
| 337 | - } |
|
| 338 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 339 | - $collecte = array(); |
|
| 340 | - while ($args && $args[0] != '}') { |
|
| 341 | - if ($args[0] == '"') { |
|
| 342 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 343 | - } elseif ($args[0] == "'") { |
|
| 344 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 345 | - } else { |
|
| 346 | - preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
|
| 347 | - if (!strlen($regs[2])) { |
|
| 348 | - $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
|
| 349 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 350 | - $champ = new Texte; |
|
| 351 | - $champ->apres = $champ->avant = $args = ""; |
|
| 352 | - break; |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - $arg = $regs[2]; |
|
| 356 | - if (trim($regs[1])) { |
|
| 357 | - $champ = new Texte; |
|
| 358 | - $champ->texte = $arg; |
|
| 359 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 360 | - $result[] = $champ; |
|
| 361 | - $collecte[] = $champ; |
|
| 362 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 363 | - } else { |
|
| 364 | - if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)) { |
|
| 365 | - // 0 est un aveu d'impuissance. A completer |
|
| 366 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 367 | - |
|
| 368 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 369 | - $collecte = array_merge($collecte, $arg); |
|
| 370 | - $result = array_merge($result, $arg); |
|
| 371 | - } else { |
|
| 372 | - $n = strpos($args, $r[0]); |
|
| 373 | - $pred = substr($args, 0, $n); |
|
| 374 | - $par = ',}'; |
|
| 375 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 376 | - $pred = $m[1]; |
|
| 377 | - $par = ')'; |
|
| 378 | - } |
|
| 379 | - if ($pred) { |
|
| 380 | - $champ = new Texte; |
|
| 381 | - $champ->texte = $pred; |
|
| 382 | - $champ->apres = $champ->avant = ""; |
|
| 383 | - $result[] = $champ; |
|
| 384 | - $collecte[] = $champ; |
|
| 385 | - } |
|
| 386 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 387 | - $champ = new Champ; |
|
| 388 | - $champ->nom_boucle = $r[2]; |
|
| 389 | - $champ->nom_champ = $r[3]; |
|
| 390 | - $champ->etoile = $r[5]; |
|
| 391 | - $next = $r[6]; |
|
| 392 | - while ($next == '{') { |
|
| 393 | - phraser_arg($rec, $sep, array(), $champ); |
|
| 394 | - $args = ltrim($rec); |
|
| 395 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 396 | - } |
|
| 397 | - while ($next == '|') { |
|
| 398 | - phraser_args($rec, $par, $sep, array(), $champ); |
|
| 399 | - $args = $champ->apres; |
|
| 400 | - $champ->apres = ''; |
|
| 401 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 402 | - } |
|
| 403 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 404 | - if ($champ->param === false) { |
|
| 405 | - $err_f = true; |
|
| 406 | - } else { |
|
| 407 | - phraser_vieux($champ); |
|
| 408 | - } |
|
| 409 | - if ($par == ')') { |
|
| 410 | - $args = substr($args, 1); |
|
| 411 | - } |
|
| 412 | - $collecte[] = $champ; |
|
| 413 | - $result[] = $champ; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 417 | - $args = ltrim(substr($args, 1)); |
|
| 418 | - if ($collecte) { |
|
| 419 | - $res[] = $collecte; |
|
| 420 | - $collecte = array(); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - if ($collecte) { |
|
| 425 | - $res[] = $collecte; |
|
| 426 | - $collecte = array(); |
|
| 427 | - } |
|
| 428 | - $texte = substr($args, 1); |
|
| 429 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 430 | - // propager les erreurs, et ignorer les param vides |
|
| 431 | - if ($pointeur_champ->param !== false) { |
|
| 432 | - if ($err_f) { |
|
| 433 | - $pointeur_champ->param = false; |
|
| 434 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 435 | - $pointeur_champ->param[] = $res; |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 439 | - $pointeur_champ->fonctions[] = array($fonc, $source); |
|
| 440 | - |
|
| 441 | - return $result; |
|
| 310 | + preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
|
| 311 | + $suite = ltrim($match[2]); |
|
| 312 | + $fonc = trim($match[1]); |
|
| 313 | + if ($fonc && $fonc[0] == "|") { |
|
| 314 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 315 | + } |
|
| 316 | + $res = array($fonc); |
|
| 317 | + $err_f = ''; |
|
| 318 | + // cas du filtre sans argument ou du critere / |
|
| 319 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 320 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 321 | + if (!$match[1]) { |
|
| 322 | + $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
|
| 323 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 324 | + $texte = ''; |
|
| 325 | + } else { |
|
| 326 | + $texte = $suite; |
|
| 327 | + } |
|
| 328 | + if ($err_f) { |
|
| 329 | + $pointeur_champ->param = false; |
|
| 330 | + } elseif ($fonc !== '') { |
|
| 331 | + $pointeur_champ->param[] = $res; |
|
| 332 | + } |
|
| 333 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 334 | + $pointeur_champ->fonctions[] = array($fonc, ''); |
|
| 335 | + |
|
| 336 | + return $result; |
|
| 337 | + } |
|
| 338 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 339 | + $collecte = array(); |
|
| 340 | + while ($args && $args[0] != '}') { |
|
| 341 | + if ($args[0] == '"') { |
|
| 342 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 343 | + } elseif ($args[0] == "'") { |
|
| 344 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 345 | + } else { |
|
| 346 | + preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
|
| 347 | + if (!strlen($regs[2])) { |
|
| 348 | + $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
|
| 349 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 350 | + $champ = new Texte; |
|
| 351 | + $champ->apres = $champ->avant = $args = ""; |
|
| 352 | + break; |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + $arg = $regs[2]; |
|
| 356 | + if (trim($regs[1])) { |
|
| 357 | + $champ = new Texte; |
|
| 358 | + $champ->texte = $arg; |
|
| 359 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 360 | + $result[] = $champ; |
|
| 361 | + $collecte[] = $champ; |
|
| 362 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 363 | + } else { |
|
| 364 | + if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)) { |
|
| 365 | + // 0 est un aveu d'impuissance. A completer |
|
| 366 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 367 | + |
|
| 368 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 369 | + $collecte = array_merge($collecte, $arg); |
|
| 370 | + $result = array_merge($result, $arg); |
|
| 371 | + } else { |
|
| 372 | + $n = strpos($args, $r[0]); |
|
| 373 | + $pred = substr($args, 0, $n); |
|
| 374 | + $par = ',}'; |
|
| 375 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 376 | + $pred = $m[1]; |
|
| 377 | + $par = ')'; |
|
| 378 | + } |
|
| 379 | + if ($pred) { |
|
| 380 | + $champ = new Texte; |
|
| 381 | + $champ->texte = $pred; |
|
| 382 | + $champ->apres = $champ->avant = ""; |
|
| 383 | + $result[] = $champ; |
|
| 384 | + $collecte[] = $champ; |
|
| 385 | + } |
|
| 386 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 387 | + $champ = new Champ; |
|
| 388 | + $champ->nom_boucle = $r[2]; |
|
| 389 | + $champ->nom_champ = $r[3]; |
|
| 390 | + $champ->etoile = $r[5]; |
|
| 391 | + $next = $r[6]; |
|
| 392 | + while ($next == '{') { |
|
| 393 | + phraser_arg($rec, $sep, array(), $champ); |
|
| 394 | + $args = ltrim($rec); |
|
| 395 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 396 | + } |
|
| 397 | + while ($next == '|') { |
|
| 398 | + phraser_args($rec, $par, $sep, array(), $champ); |
|
| 399 | + $args = $champ->apres; |
|
| 400 | + $champ->apres = ''; |
|
| 401 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 402 | + } |
|
| 403 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 404 | + if ($champ->param === false) { |
|
| 405 | + $err_f = true; |
|
| 406 | + } else { |
|
| 407 | + phraser_vieux($champ); |
|
| 408 | + } |
|
| 409 | + if ($par == ')') { |
|
| 410 | + $args = substr($args, 1); |
|
| 411 | + } |
|
| 412 | + $collecte[] = $champ; |
|
| 413 | + $result[] = $champ; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 417 | + $args = ltrim(substr($args, 1)); |
|
| 418 | + if ($collecte) { |
|
| 419 | + $res[] = $collecte; |
|
| 420 | + $collecte = array(); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + if ($collecte) { |
|
| 425 | + $res[] = $collecte; |
|
| 426 | + $collecte = array(); |
|
| 427 | + } |
|
| 428 | + $texte = substr($args, 1); |
|
| 429 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 430 | + // propager les erreurs, et ignorer les param vides |
|
| 431 | + if ($pointeur_champ->param !== false) { |
|
| 432 | + if ($err_f) { |
|
| 433 | + $pointeur_champ->param = false; |
|
| 434 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 435 | + $pointeur_champ->param[] = $res; |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 439 | + $pointeur_champ->fonctions[] = array($fonc, $source); |
|
| 440 | + |
|
| 441 | + return $result; |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | |
| 445 | 445 | // https://code.spip.net/@phraser_champs_exterieurs |
| 446 | 446 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 447 | - $res = array(); |
|
| 448 | - while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 449 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 450 | - break; |
|
| 451 | - } |
|
| 452 | - $debut = substr($texte, 0, $p); |
|
| 453 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 454 | - if ($p) { |
|
| 455 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 456 | - } |
|
| 457 | - $ligne += substr_count($debut, "\n"); |
|
| 458 | - $res[] = $nested[$m[1]]; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 447 | + $res = array(); |
|
| 448 | + while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 449 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 450 | + break; |
|
| 451 | + } |
|
| 452 | + $debut = substr($texte, 0, $p); |
|
| 453 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 454 | + if ($p) { |
|
| 455 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 456 | + } |
|
| 457 | + $ligne += substr_count($debut, "\n"); |
|
| 458 | + $res[] = $nested[$m[1]]; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // https://code.spip.net/@phraser_champs_interieurs |
| 465 | 465 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 466 | - $i = 0; // en fait count($result) |
|
| 467 | - $x = ""; |
|
| 468 | - |
|
| 469 | - while (true) { |
|
| 470 | - $j = $i; |
|
| 471 | - $n = $ligne; |
|
| 472 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 473 | - $p = strpos($texte, $match[0]); |
|
| 474 | - $debut = substr($texte, 0, $p); |
|
| 475 | - if ($p) { |
|
| 476 | - $result[$i] = $debut; |
|
| 477 | - $i++; |
|
| 478 | - } |
|
| 479 | - $nom = $match[4]; |
|
| 480 | - $champ = new Champ; |
|
| 481 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 482 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 483 | - $champ->nom_boucle = $match[3]; |
|
| 484 | - $champ->nom_champ = $nom; |
|
| 485 | - $champ->etoile = $match[6]; |
|
| 486 | - // phraser_args indiquera ou commence apres |
|
| 487 | - $result = phraser_args($match[7], ")", $sep, $result, $champ); |
|
| 488 | - phraser_vieux($champ); |
|
| 489 | - $champ->avant = |
|
| 490 | - phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | - $debut = substr($champ->apres, 1); |
|
| 492 | - if (!empty($debut)) { |
|
| 493 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 494 | - } |
|
| 495 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 496 | - |
|
| 497 | - $result[$i] = $champ; |
|
| 498 | - $i++; |
|
| 499 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 500 | - } |
|
| 501 | - if ($texte !== "") { |
|
| 502 | - $result[$i] = $texte; |
|
| 503 | - $i++; |
|
| 504 | - } |
|
| 505 | - $x = ''; |
|
| 506 | - |
|
| 507 | - while ($j < $i) { |
|
| 508 | - $z = $result[$j]; |
|
| 509 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 510 | - if (is_object($z)) { |
|
| 511 | - $x .= "%$sep$j@"; |
|
| 512 | - } else { |
|
| 513 | - $x .= $z; |
|
| 514 | - } |
|
| 515 | - $j++; |
|
| 516 | - } |
|
| 517 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 518 | - $texte = $x; |
|
| 519 | - } else { |
|
| 520 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 521 | - } |
|
| 522 | - } |
|
| 466 | + $i = 0; // en fait count($result) |
|
| 467 | + $x = ""; |
|
| 468 | + |
|
| 469 | + while (true) { |
|
| 470 | + $j = $i; |
|
| 471 | + $n = $ligne; |
|
| 472 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 473 | + $p = strpos($texte, $match[0]); |
|
| 474 | + $debut = substr($texte, 0, $p); |
|
| 475 | + if ($p) { |
|
| 476 | + $result[$i] = $debut; |
|
| 477 | + $i++; |
|
| 478 | + } |
|
| 479 | + $nom = $match[4]; |
|
| 480 | + $champ = new Champ; |
|
| 481 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 482 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 483 | + $champ->nom_boucle = $match[3]; |
|
| 484 | + $champ->nom_champ = $nom; |
|
| 485 | + $champ->etoile = $match[6]; |
|
| 486 | + // phraser_args indiquera ou commence apres |
|
| 487 | + $result = phraser_args($match[7], ")", $sep, $result, $champ); |
|
| 488 | + phraser_vieux($champ); |
|
| 489 | + $champ->avant = |
|
| 490 | + phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | + $debut = substr($champ->apres, 1); |
|
| 492 | + if (!empty($debut)) { |
|
| 493 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 494 | + } |
|
| 495 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 496 | + |
|
| 497 | + $result[$i] = $champ; |
|
| 498 | + $i++; |
|
| 499 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 500 | + } |
|
| 501 | + if ($texte !== "") { |
|
| 502 | + $result[$i] = $texte; |
|
| 503 | + $i++; |
|
| 504 | + } |
|
| 505 | + $x = ''; |
|
| 506 | + |
|
| 507 | + while ($j < $i) { |
|
| 508 | + $z = $result[$j]; |
|
| 509 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 510 | + if (is_object($z)) { |
|
| 511 | + $x .= "%$sep$j@"; |
|
| 512 | + } else { |
|
| 513 | + $x .= $z; |
|
| 514 | + } |
|
| 515 | + $j++; |
|
| 516 | + } |
|
| 517 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 518 | + $texte = $x; |
|
| 519 | + } else { |
|
| 520 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | function phraser_vieux(&$champ) { |
| 526 | - $nom = $champ->nom_champ; |
|
| 527 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 528 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 529 | - include_spip('public/normaliser'); |
|
| 530 | - } |
|
| 531 | - phraser_vieux_emb($champ); |
|
| 532 | - } elseif ($nom == 'EXPOSER') { |
|
| 533 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 534 | - include_spip('public/normaliser'); |
|
| 535 | - } |
|
| 536 | - phraser_vieux_exposer($champ); |
|
| 537 | - } elseif ($champ->param) { |
|
| 538 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 539 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 540 | - include_spip('public/normaliser'); |
|
| 541 | - } |
|
| 542 | - phraser_vieux_recherche($champ); |
|
| 543 | - } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
|
| 544 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 545 | - include_spip('public/normaliser'); |
|
| 546 | - } |
|
| 547 | - phraser_vieux_logos($champ); |
|
| 548 | - } elseif ($nom == 'MODELE') { |
|
| 549 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 550 | - include_spip('public/normaliser'); |
|
| 551 | - } |
|
| 552 | - phraser_vieux_modele($champ); |
|
| 553 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 554 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 555 | - include_spip('public/normaliser'); |
|
| 556 | - } |
|
| 557 | - phraser_vieux_inclu($champ); |
|
| 558 | - } |
|
| 559 | - } |
|
| 526 | + $nom = $champ->nom_champ; |
|
| 527 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 528 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 529 | + include_spip('public/normaliser'); |
|
| 530 | + } |
|
| 531 | + phraser_vieux_emb($champ); |
|
| 532 | + } elseif ($nom == 'EXPOSER') { |
|
| 533 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 534 | + include_spip('public/normaliser'); |
|
| 535 | + } |
|
| 536 | + phraser_vieux_exposer($champ); |
|
| 537 | + } elseif ($champ->param) { |
|
| 538 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 539 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 540 | + include_spip('public/normaliser'); |
|
| 541 | + } |
|
| 542 | + phraser_vieux_recherche($champ); |
|
| 543 | + } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
|
| 544 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 545 | + include_spip('public/normaliser'); |
|
| 546 | + } |
|
| 547 | + phraser_vieux_logos($champ); |
|
| 548 | + } elseif ($nom == 'MODELE') { |
|
| 549 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 550 | + include_spip('public/normaliser'); |
|
| 551 | + } |
|
| 552 | + phraser_vieux_modele($champ); |
|
| 553 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 554 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 555 | + include_spip('public/normaliser'); |
|
| 556 | + } |
|
| 557 | + phraser_vieux_inclu($champ); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | |
@@ -584,190 +584,190 @@ discard block |
||
| 584 | 584 | **/ |
| 585 | 585 | function phraser_criteres($params, &$result) { |
| 586 | 586 | |
| 587 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 588 | - $args = array(); |
|
| 589 | - $type = $result->type_requete; |
|
| 590 | - $doublons = array(); |
|
| 591 | - foreach ($params as $v) { |
|
| 592 | - $var = $v[1][0]; |
|
| 593 | - $param = ($var->type != 'texte') ? "" : $var->texte; |
|
| 594 | - if ((count($v) > 2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))) { |
|
| 595 | - // plus d'un argument et pas le critere IN: |
|
| 596 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 597 | - if ($var->type != 'texte' |
|
| 598 | - or preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
|
| 599 | - ) { |
|
| 600 | - $op = ','; |
|
| 601 | - $not = ""; |
|
| 602 | - $cond = false; |
|
| 603 | - } else { |
|
| 604 | - // Le debut du premier argument est l'operateur |
|
| 605 | - preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m); |
|
| 606 | - $op = $m[2]; |
|
| 607 | - $not = $m[1]; |
|
| 608 | - $cond = $m[3]; |
|
| 609 | - // virer le premier argument, |
|
| 610 | - // et mettre son reliquat eventuel |
|
| 611 | - // Recopier pour ne pas alterer le texte source |
|
| 612 | - // utile au debusqueur |
|
| 613 | - if ($m[4]) { |
|
| 614 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 615 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 616 | - $c = null; |
|
| 617 | - eval('$c = ' . $m[4] . ';'); |
|
| 618 | - if (isset($c)) { |
|
| 619 | - $m[4] = $c; |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - $texte = new Texte; |
|
| 623 | - $texte->texte = $m[4]; |
|
| 624 | - $v[1][0] = $texte; |
|
| 625 | - } else { |
|
| 626 | - array_shift($v[1]); |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - array_shift($v); // $v[O] est vide |
|
| 630 | - $crit = new Critere; |
|
| 631 | - $crit->op = $op; |
|
| 632 | - $crit->not = $not; |
|
| 633 | - $crit->cond = $cond; |
|
| 634 | - $crit->exclus = ""; |
|
| 635 | - $crit->param = $v; |
|
| 636 | - $args[] = $crit; |
|
| 637 | - } else { |
|
| 638 | - if ($var->type != 'texte') { |
|
| 639 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 640 | - // erreur ou critere infixe "/" |
|
| 641 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 642 | - $err_ci = array( |
|
| 643 | - 'zbug_critere_inconnu', |
|
| 644 | - array('critere' => $var->nom_champ) |
|
| 645 | - ); |
|
| 646 | - erreur_squelette($err_ci, $result); |
|
| 647 | - } else { |
|
| 648 | - $crit = new Critere; |
|
| 649 | - $crit->op = '/'; |
|
| 650 | - $crit->not = ""; |
|
| 651 | - $crit->exclus = ""; |
|
| 652 | - $crit->param = array(array($v[1][0]), array($v[1][2])); |
|
| 653 | - $args[] = $crit; |
|
| 654 | - } |
|
| 655 | - } else { |
|
| 656 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 657 | - // les separateurs |
|
| 658 | - if ($var->apres) { |
|
| 659 | - $result->separateur[] = $param; |
|
| 660 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 661 | - $result->modificateur['tout'] = true; |
|
| 662 | - } elseif ($param == 'plat') { |
|
| 663 | - $result->modificateur['plat'] = true; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 667 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 668 | - // ceux-ci pour avoir la rubrique mere... |
|
| 669 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 670 | - // traités normalement. |
|
| 671 | - elseif (strcasecmp($type, 'hierarchie') == 0 |
|
| 672 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 673 | - and preg_match(",^id_\w+\s*$,", $param) |
|
| 674 | - ) { |
|
| 675 | - $result->modificateur['tout'] = true; |
|
| 676 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == "id_rubrique") { |
|
| 677 | - // rien a faire sur {id_rubrique} tout seul |
|
| 678 | - } else { |
|
| 679 | - // pas d'emplacement statique, faut un dynamique |
|
| 680 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 681 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 682 | - // cette variable sera inseree dans le code |
|
| 683 | - // et son nom sert d'indicateur des maintenant |
|
| 684 | - $result->doublons = '$doublons_index'; |
|
| 685 | - if ($param == 'unique') { |
|
| 686 | - $param = 'doublons'; |
|
| 687 | - } |
|
| 688 | - } elseif ($param == 'recherche') { |
|
| 689 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 690 | - $result->hash = ' '; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 694 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 695 | - } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 696 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
|
| 697 | - $a2 = trim($m[8]); |
|
| 698 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 699 | - $a2 = substr($a2, 1, -1); |
|
| 700 | - } |
|
| 701 | - $crit = phraser_critere_infixe($m[2], $a2, $v, |
|
| 702 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 703 | - $m[6], $m[5]); |
|
| 704 | - $crit->exclus = $m[1]; |
|
| 705 | - } elseif (preg_match("/^([!]?)\s*(" . |
|
| 706 | - CHAMP_SQL_PLUS_FONC . |
|
| 707 | - ")\s*(\??)(.*)$/is", $param, $m)) { |
|
| 708 | - // contient aussi les comparaisons implicites ! |
|
| 709 | - // Comme ci-dessus: |
|
| 710 | - // le premier arg contient l'operateur |
|
| 711 | - array_shift($v); |
|
| 712 | - if ($m[6]) { |
|
| 713 | - $v[0][0] = new Texte; |
|
| 714 | - $v[0][0]->texte = $m[6]; |
|
| 715 | - } else { |
|
| 716 | - array_shift($v[0]); |
|
| 717 | - if (!$v[0]) { |
|
| 718 | - array_shift($v); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - $crit = new Critere; |
|
| 722 | - $crit->op = $m[2]; |
|
| 723 | - $crit->param = $v; |
|
| 724 | - $crit->not = $m[1]; |
|
| 725 | - $crit->cond = $m[5]; |
|
| 726 | - } else { |
|
| 727 | - $err_ci = array( |
|
| 728 | - 'zbug_critere_inconnu', |
|
| 729 | - array('critere' => $param) |
|
| 730 | - ); |
|
| 731 | - erreur_squelette($err_ci, $result); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 735 | - $args[] = $crit; |
|
| 736 | - } else { |
|
| 737 | - $doublons[] = $crit; |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - // les doublons non nies doivent etre le dernier critere |
|
| 745 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 746 | - // cf critere_doublon |
|
| 747 | - if ($doublons) { |
|
| 748 | - $args = array_merge($args, $doublons); |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 752 | - if (!$err_ci) { |
|
| 753 | - $result->criteres = $args; |
|
| 754 | - } |
|
| 587 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 588 | + $args = array(); |
|
| 589 | + $type = $result->type_requete; |
|
| 590 | + $doublons = array(); |
|
| 591 | + foreach ($params as $v) { |
|
| 592 | + $var = $v[1][0]; |
|
| 593 | + $param = ($var->type != 'texte') ? "" : $var->texte; |
|
| 594 | + if ((count($v) > 2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))) { |
|
| 595 | + // plus d'un argument et pas le critere IN: |
|
| 596 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 597 | + if ($var->type != 'texte' |
|
| 598 | + or preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
|
| 599 | + ) { |
|
| 600 | + $op = ','; |
|
| 601 | + $not = ""; |
|
| 602 | + $cond = false; |
|
| 603 | + } else { |
|
| 604 | + // Le debut du premier argument est l'operateur |
|
| 605 | + preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m); |
|
| 606 | + $op = $m[2]; |
|
| 607 | + $not = $m[1]; |
|
| 608 | + $cond = $m[3]; |
|
| 609 | + // virer le premier argument, |
|
| 610 | + // et mettre son reliquat eventuel |
|
| 611 | + // Recopier pour ne pas alterer le texte source |
|
| 612 | + // utile au debusqueur |
|
| 613 | + if ($m[4]) { |
|
| 614 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 615 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 616 | + $c = null; |
|
| 617 | + eval('$c = ' . $m[4] . ';'); |
|
| 618 | + if (isset($c)) { |
|
| 619 | + $m[4] = $c; |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + $texte = new Texte; |
|
| 623 | + $texte->texte = $m[4]; |
|
| 624 | + $v[1][0] = $texte; |
|
| 625 | + } else { |
|
| 626 | + array_shift($v[1]); |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + array_shift($v); // $v[O] est vide |
|
| 630 | + $crit = new Critere; |
|
| 631 | + $crit->op = $op; |
|
| 632 | + $crit->not = $not; |
|
| 633 | + $crit->cond = $cond; |
|
| 634 | + $crit->exclus = ""; |
|
| 635 | + $crit->param = $v; |
|
| 636 | + $args[] = $crit; |
|
| 637 | + } else { |
|
| 638 | + if ($var->type != 'texte') { |
|
| 639 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 640 | + // erreur ou critere infixe "/" |
|
| 641 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 642 | + $err_ci = array( |
|
| 643 | + 'zbug_critere_inconnu', |
|
| 644 | + array('critere' => $var->nom_champ) |
|
| 645 | + ); |
|
| 646 | + erreur_squelette($err_ci, $result); |
|
| 647 | + } else { |
|
| 648 | + $crit = new Critere; |
|
| 649 | + $crit->op = '/'; |
|
| 650 | + $crit->not = ""; |
|
| 651 | + $crit->exclus = ""; |
|
| 652 | + $crit->param = array(array($v[1][0]), array($v[1][2])); |
|
| 653 | + $args[] = $crit; |
|
| 654 | + } |
|
| 655 | + } else { |
|
| 656 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 657 | + // les separateurs |
|
| 658 | + if ($var->apres) { |
|
| 659 | + $result->separateur[] = $param; |
|
| 660 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 661 | + $result->modificateur['tout'] = true; |
|
| 662 | + } elseif ($param == 'plat') { |
|
| 663 | + $result->modificateur['plat'] = true; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 667 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 668 | + // ceux-ci pour avoir la rubrique mere... |
|
| 669 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 670 | + // traités normalement. |
|
| 671 | + elseif (strcasecmp($type, 'hierarchie') == 0 |
|
| 672 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 673 | + and preg_match(",^id_\w+\s*$,", $param) |
|
| 674 | + ) { |
|
| 675 | + $result->modificateur['tout'] = true; |
|
| 676 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == "id_rubrique") { |
|
| 677 | + // rien a faire sur {id_rubrique} tout seul |
|
| 678 | + } else { |
|
| 679 | + // pas d'emplacement statique, faut un dynamique |
|
| 680 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 681 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 682 | + // cette variable sera inseree dans le code |
|
| 683 | + // et son nom sert d'indicateur des maintenant |
|
| 684 | + $result->doublons = '$doublons_index'; |
|
| 685 | + if ($param == 'unique') { |
|
| 686 | + $param = 'doublons'; |
|
| 687 | + } |
|
| 688 | + } elseif ($param == 'recherche') { |
|
| 689 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 690 | + $result->hash = ' '; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 694 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 695 | + } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 696 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
|
| 697 | + $a2 = trim($m[8]); |
|
| 698 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 699 | + $a2 = substr($a2, 1, -1); |
|
| 700 | + } |
|
| 701 | + $crit = phraser_critere_infixe($m[2], $a2, $v, |
|
| 702 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 703 | + $m[6], $m[5]); |
|
| 704 | + $crit->exclus = $m[1]; |
|
| 705 | + } elseif (preg_match("/^([!]?)\s*(" . |
|
| 706 | + CHAMP_SQL_PLUS_FONC . |
|
| 707 | + ")\s*(\??)(.*)$/is", $param, $m)) { |
|
| 708 | + // contient aussi les comparaisons implicites ! |
|
| 709 | + // Comme ci-dessus: |
|
| 710 | + // le premier arg contient l'operateur |
|
| 711 | + array_shift($v); |
|
| 712 | + if ($m[6]) { |
|
| 713 | + $v[0][0] = new Texte; |
|
| 714 | + $v[0][0]->texte = $m[6]; |
|
| 715 | + } else { |
|
| 716 | + array_shift($v[0]); |
|
| 717 | + if (!$v[0]) { |
|
| 718 | + array_shift($v); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + $crit = new Critere; |
|
| 722 | + $crit->op = $m[2]; |
|
| 723 | + $crit->param = $v; |
|
| 724 | + $crit->not = $m[1]; |
|
| 725 | + $crit->cond = $m[5]; |
|
| 726 | + } else { |
|
| 727 | + $err_ci = array( |
|
| 728 | + 'zbug_critere_inconnu', |
|
| 729 | + array('critere' => $param) |
|
| 730 | + ); |
|
| 731 | + erreur_squelette($err_ci, $result); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 735 | + $args[] = $crit; |
|
| 736 | + } else { |
|
| 737 | + $doublons[] = $crit; |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + // les doublons non nies doivent etre le dernier critere |
|
| 745 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 746 | + // cf critere_doublon |
|
| 747 | + if ($doublons) { |
|
| 748 | + $args = array_merge($args, $doublons); |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 752 | + if (!$err_ci) { |
|
| 753 | + $result->criteres = $args; |
|
| 754 | + } |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | // https://code.spip.net/@phraser_critere_infixe |
| 758 | 758 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 759 | - $args[0] = new Texte; |
|
| 760 | - $args[0]->texte = $arg1; |
|
| 761 | - $args[0] = array($args[0]); |
|
| 762 | - $args[1][0] = new Texte; |
|
| 763 | - $args[1][0]->texte = $arg2; |
|
| 764 | - $crit = new Critere; |
|
| 765 | - $crit->op = $op; |
|
| 766 | - $crit->not = $not; |
|
| 767 | - $crit->cond = $cond; |
|
| 768 | - $crit->param = $args; |
|
| 769 | - |
|
| 770 | - return $crit; |
|
| 759 | + $args[0] = new Texte; |
|
| 760 | + $args[0]->texte = $arg1; |
|
| 761 | + $args[0] = array($args[0]); |
|
| 762 | + $args[1][0] = new Texte; |
|
| 763 | + $args[1][0]->texte = $arg2; |
|
| 764 | + $crit = new Critere; |
|
| 765 | + $crit->op = $op; |
|
| 766 | + $crit->not = $not; |
|
| 767 | + $crit->cond = $cond; |
|
| 768 | + $crit->param = $args; |
|
| 769 | + |
|
| 770 | + return $crit; |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | /** |
@@ -778,12 +778,12 @@ discard block |
||
| 778 | 778 | * @return int |
| 779 | 779 | */ |
| 780 | 780 | function public_compte_ligne($texte, $debut = 0, $longueur = null) { |
| 781 | - if (is_null($longueur)) { |
|
| 782 | - return substr_count($texte, "\n", $debut); |
|
| 783 | - } |
|
| 784 | - else { |
|
| 785 | - return substr_count($texte, "\n", $debut, $longueur); |
|
| 786 | - } |
|
| 781 | + if (is_null($longueur)) { |
|
| 782 | + return substr_count($texte, "\n", $debut); |
|
| 783 | + } |
|
| 784 | + else { |
|
| 785 | + return substr_count($texte, "\n", $debut, $longueur); |
|
| 786 | + } |
|
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | |
@@ -798,284 +798,284 @@ discard block |
||
| 798 | 798 | * @return array|null |
| 799 | 799 | */ |
| 800 | 800 | function public_trouver_premiere_boucle($texte, $id_parent, $descr) { |
| 801 | - $premiere_boucle = null; |
|
| 802 | - $current_pos = 0; |
|
| 803 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 804 | - $current_pos = $pos_boucle + 1; |
|
| 805 | - $pos_parent = strpos($texte,'(', $pos_boucle); |
|
| 806 | - if ($pos_parent === false |
|
| 807 | - or !$id_boucle = trim(substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))) |
|
| 808 | - or !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) { |
|
| 809 | - |
|
| 810 | - $result = new Boucle; |
|
| 811 | - $result->id_parent = $id_parent; |
|
| 812 | - $result->descr = $descr; |
|
| 813 | - |
|
| 814 | - // un id_boucle pour l'affichage de l'erreur |
|
| 815 | - if (!$id_boucle) { |
|
| 816 | - $id_boucle = substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 817 | - } |
|
| 818 | - $result->id_boucle = $id_boucle; |
|
| 819 | - $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 820 | - erreur_squelette($err_b, $result); |
|
| 821 | - |
|
| 822 | - continue; |
|
| 823 | - } |
|
| 824 | - else { |
|
| 825 | - $boucle = [ |
|
| 826 | - 'id_boucle' => $id_boucle, |
|
| 827 | - 'debut_boucle' => $pos_boucle, |
|
| 828 | - 'pos_boucle' => $pos_boucle, |
|
| 829 | - 'pos_parent' => $pos_parent, |
|
| 830 | - 'pos_precond' => false, |
|
| 831 | - 'pos_precond_inside' => false, |
|
| 832 | - 'pos_preaff' => false, |
|
| 833 | - 'pos_preaff_inside' => false, |
|
| 834 | - ]; |
|
| 835 | - |
|
| 836 | - // trouver sa position de depart reelle : au <B_ ou au <BB_ |
|
| 837 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 838 | - $pos_precond = strpos($texte, $precond_boucle); |
|
| 839 | - if ($pos_precond !== false and $pos_precond < $boucle['debut_boucle']) { |
|
| 840 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 841 | - $boucle['pos_precond'] = $pos_precond; |
|
| 842 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 846 | - $pos_preaff = strpos($texte, $preaff_boucle); |
|
| 847 | - if ($pos_preaff !== false and $pos_preaff < $boucle['debut_boucle']) { |
|
| 848 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 849 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 850 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 854 | - $premiere_boucle = $boucle; |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - return $premiere_boucle; |
|
| 801 | + $premiere_boucle = null; |
|
| 802 | + $current_pos = 0; |
|
| 803 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 804 | + $current_pos = $pos_boucle + 1; |
|
| 805 | + $pos_parent = strpos($texte,'(', $pos_boucle); |
|
| 806 | + if ($pos_parent === false |
|
| 807 | + or !$id_boucle = trim(substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))) |
|
| 808 | + or !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) { |
|
| 809 | + |
|
| 810 | + $result = new Boucle; |
|
| 811 | + $result->id_parent = $id_parent; |
|
| 812 | + $result->descr = $descr; |
|
| 813 | + |
|
| 814 | + // un id_boucle pour l'affichage de l'erreur |
|
| 815 | + if (!$id_boucle) { |
|
| 816 | + $id_boucle = substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 817 | + } |
|
| 818 | + $result->id_boucle = $id_boucle; |
|
| 819 | + $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 820 | + erreur_squelette($err_b, $result); |
|
| 821 | + |
|
| 822 | + continue; |
|
| 823 | + } |
|
| 824 | + else { |
|
| 825 | + $boucle = [ |
|
| 826 | + 'id_boucle' => $id_boucle, |
|
| 827 | + 'debut_boucle' => $pos_boucle, |
|
| 828 | + 'pos_boucle' => $pos_boucle, |
|
| 829 | + 'pos_parent' => $pos_parent, |
|
| 830 | + 'pos_precond' => false, |
|
| 831 | + 'pos_precond_inside' => false, |
|
| 832 | + 'pos_preaff' => false, |
|
| 833 | + 'pos_preaff_inside' => false, |
|
| 834 | + ]; |
|
| 835 | + |
|
| 836 | + // trouver sa position de depart reelle : au <B_ ou au <BB_ |
|
| 837 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 838 | + $pos_precond = strpos($texte, $precond_boucle); |
|
| 839 | + if ($pos_precond !== false and $pos_precond < $boucle['debut_boucle']) { |
|
| 840 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 841 | + $boucle['pos_precond'] = $pos_precond; |
|
| 842 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 846 | + $pos_preaff = strpos($texte, $preaff_boucle); |
|
| 847 | + if ($pos_preaff !== false and $pos_preaff < $boucle['debut_boucle']) { |
|
| 848 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 849 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 850 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 854 | + $premiere_boucle = $boucle; |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + return $premiere_boucle; |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | |
| 863 | 863 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne = 1) { |
| 864 | 864 | |
| 865 | - $all_res = array(); |
|
| 866 | - |
|
| 867 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr)) { |
|
| 868 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 869 | - $result = new Boucle; |
|
| 870 | - $result->id_parent = $id_parent; |
|
| 871 | - $result->descr = $descr; |
|
| 872 | - |
|
| 873 | - $pos_boucle = $boucle['pos_boucle']; |
|
| 874 | - $id_boucle = $boucle['id_boucle']; |
|
| 875 | - $pos_parent = $boucle['pos_parent']; |
|
| 876 | - |
|
| 877 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne + public_compte_ligne($texte, 0, $pos_parent); |
|
| 878 | - $pos_debut_boucle = $pos_boucle; |
|
| 879 | - $milieu = substr($texte, $pos_parent); |
|
| 880 | - |
|
| 881 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 882 | - if ($boucle['pos_precond'] !== false) { |
|
| 883 | - |
|
| 884 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 885 | - |
|
| 886 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 887 | - $result->avant = substr($texte, $pos_avant, $pos_boucle - $pos_avant); |
|
| 888 | - $ligne_avant = $ligne + public_compte_ligne($texte,0, $pos_avant); |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 892 | - if ($boucle['pos_preaff'] !== false) { |
|
| 893 | - |
|
| 894 | - $end_preaff = $pos_debut_boucle; |
|
| 895 | - |
|
| 896 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 897 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 898 | - $ligne_preaff = $ligne + public_compte_ligne($texte,0, $pos_preaff); |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - $debut = substr($texte, 0, $boucle['debut_boucle']); |
|
| 902 | - |
|
| 903 | - $result->id_boucle = $id_boucle; |
|
| 904 | - |
|
| 905 | - if (!preg_match(SPEC_BOUCLE, $milieu, $match)) { |
|
| 906 | - $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 907 | - erreur_squelette($err_b, $result); |
|
| 908 | - |
|
| 909 | - $ligne += public_compte_ligne($texte, 0, $pos_boucle + 1); |
|
| 910 | - $texte = substr($texte, $pos_boucle + 1); |
|
| 911 | - continue; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - $result->type_requete = $match[0]; |
|
| 915 | - $milieu = substr($milieu, strlen($match[0])); |
|
| 916 | - $pos_boucle = $pos_parent + strlen($match[0]); // on s'en sert pour compter les lignes plus precisemment |
|
| 917 | - |
|
| 918 | - $type = $match[1]; |
|
| 919 | - $jointures = trim($match[2]); |
|
| 920 | - $table_optionnelle = ($match[3]); |
|
| 921 | - if ($jointures) { |
|
| 922 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 923 | - // ou elles seront completees des jointures declarees |
|
| 924 | - $result->jointures_explicites = $jointures; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - if ($table_optionnelle) { |
|
| 928 | - $result->table_optionnelle = $type; |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 932 | - // Resultat mis dans result->param |
|
| 933 | - phraser_args($milieu, "/>", "", $all_res, $result); |
|
| 934 | - |
|
| 935 | - // En 2e passe result->criteres contiendra un tableau |
|
| 936 | - // pour l'instant on met le source (chaine) : |
|
| 937 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 938 | - $pos_fin_criteres = strpos($milieu, $result->apres); |
|
| 939 | - $pos_boucle += $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 940 | - $result->criteres = substr($milieu, 0, $pos_fin_criteres); |
|
| 941 | - $milieu = $result->apres; |
|
| 942 | - $result->apres = ""; |
|
| 943 | - |
|
| 944 | - // |
|
| 945 | - // Recuperer la fin : |
|
| 946 | - // |
|
| 947 | - if ($milieu[0] === '/') { |
|
| 948 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 949 | - $suite = substr($milieu, 2); |
|
| 950 | - $pos_boucle += 2; |
|
| 951 | - $milieu = ''; |
|
| 952 | - } else { |
|
| 953 | - $milieu = substr($milieu, 1); |
|
| 954 | - $pos_boucle += 1; |
|
| 955 | - |
|
| 956 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 957 | - $pos_fin = strpos($milieu, $fin_boucle); |
|
| 958 | - if ($pos_fin === false) { |
|
| 959 | - $err_b = array( |
|
| 960 | - 'zbug_erreur_boucle_fermant', |
|
| 961 | - array('id' => $id_boucle) |
|
| 962 | - ); |
|
| 963 | - erreur_squelette($err_b, $result); |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - $pos_boucle += $pos_fin + strlen($fin_boucle); |
|
| 967 | - $suite = substr($milieu, $pos_fin + strlen($fin_boucle)); |
|
| 968 | - $milieu = substr($milieu, 0, $pos_fin); |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - $result->milieu = $milieu; |
|
| 972 | - $ligne_suite = $ligne_apres = $ligne + public_compte_ligne($texte, 0, $pos_boucle); |
|
| 973 | - |
|
| 974 | - // |
|
| 975 | - // 1. Recuperer la partie conditionnelle apres |
|
| 976 | - // |
|
| 977 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . ">"; |
|
| 978 | - $pos_apres = strpos($suite, $apres_boucle); |
|
| 979 | - if ($pos_apres !== false) { |
|
| 980 | - $result->apres = substr($suite, 0, $pos_apres); |
|
| 981 | - $pos_apres += strlen($apres_boucle); |
|
| 982 | - $suite = substr($suite, $pos_apres); |
|
| 983 | - $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_apres); |
|
| 984 | - $pos_boucle += $pos_apres ; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - // |
|
| 989 | - // 2. Recuperer la partie alternative |
|
| 990 | - // |
|
| 991 | - $ligne_altern = $ligne_suite; |
|
| 992 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 993 | - $pos_altern = strpos($suite, $altern_boucle); |
|
| 994 | - if ($pos_altern !== false) { |
|
| 995 | - $result->altern = substr($suite, 0, $pos_altern); |
|
| 996 | - $pos_altern += strlen($altern_boucle); |
|
| 997 | - $suite = substr($suite, $pos_altern); |
|
| 998 | - $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_altern); |
|
| 999 | - $pos_boucle += $pos_altern; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - // |
|
| 1003 | - // 3. Recuperer la partie footer non alternative |
|
| 1004 | - // |
|
| 1005 | - $ligne_postaff = $ligne_suite; |
|
| 1006 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . ">"; |
|
| 1007 | - $pos_postaff = strpos($suite, $postaff_boucle); |
|
| 1008 | - if ($pos_postaff !== false) { |
|
| 1009 | - $result->postaff = substr($suite, 0, $pos_postaff); |
|
| 1010 | - $pos_postaff += strlen($postaff_boucle); |
|
| 1011 | - $suite = substr($suite, $pos_postaff); |
|
| 1012 | - $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_postaff); |
|
| 1013 | - $pos_boucle += $pos_postaff ; |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - $result->ligne = $ligne_preaff; |
|
| 1017 | - |
|
| 1018 | - if ($p = strpos($type, ':')) { |
|
| 1019 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1020 | - $type = substr($type, $p + 1); |
|
| 1021 | - } |
|
| 1022 | - $soustype = strtolower($type); |
|
| 1023 | - |
|
| 1024 | - if (!isset($GLOBALS["table_des_tables"][$soustype])) { |
|
| 1025 | - $soustype = $type; |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - $result->type_requete = $soustype; |
|
| 1029 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1030 | - if (!is_array($result->param)) { |
|
| 1031 | - $err_b = true; |
|
| 1032 | - } else { |
|
| 1033 | - phraser_criteres($result->param, $result); |
|
| 1034 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1035 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1036 | - $args = $result->param; |
|
| 1037 | - array_unshift($args, |
|
| 1038 | - substr($type, strlen(TYPE_RECURSIF))); |
|
| 1039 | - $result->param = $args; |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1044 | - $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $ligne_milieu); |
|
| 1045 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1046 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1047 | - $boucles[$id_boucle] = null; |
|
| 1048 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff); |
|
| 1049 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant); |
|
| 1050 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres); |
|
| 1051 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern); |
|
| 1052 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff); |
|
| 1053 | - |
|
| 1054 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1055 | - if ($err_b) { |
|
| 1056 | - $result->type_requete = false; |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - // Verifier qu'il n'y a pas double definition |
|
| 1060 | - // apres analyse des sous-parties (pas avant). |
|
| 1061 | - |
|
| 1062 | - if (!empty($boucles[$id_boucle])) { |
|
| 1063 | - $err_b_d = array( |
|
| 1064 | - 'zbug_erreur_boucle_double', |
|
| 1065 | - array('id' => $id_boucle) |
|
| 1066 | - ); |
|
| 1067 | - erreur_squelette($err_b_d, $result); |
|
| 1068 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1069 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1070 | - } else { |
|
| 1071 | - $boucles[$id_boucle] = $result; |
|
| 1072 | - } |
|
| 1073 | - $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
|
| 1074 | - $all_res[] = &$boucles[$id_boucle]; |
|
| 1075 | - |
|
| 1076 | - $ligne = $ligne_suite; |
|
| 1077 | - $texte = $suite; |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - return phraser_champs_etendus($texte, $ligne, $all_res); |
|
| 865 | + $all_res = array(); |
|
| 866 | + |
|
| 867 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr)) { |
|
| 868 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 869 | + $result = new Boucle; |
|
| 870 | + $result->id_parent = $id_parent; |
|
| 871 | + $result->descr = $descr; |
|
| 872 | + |
|
| 873 | + $pos_boucle = $boucle['pos_boucle']; |
|
| 874 | + $id_boucle = $boucle['id_boucle']; |
|
| 875 | + $pos_parent = $boucle['pos_parent']; |
|
| 876 | + |
|
| 877 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne + public_compte_ligne($texte, 0, $pos_parent); |
|
| 878 | + $pos_debut_boucle = $pos_boucle; |
|
| 879 | + $milieu = substr($texte, $pos_parent); |
|
| 880 | + |
|
| 881 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 882 | + if ($boucle['pos_precond'] !== false) { |
|
| 883 | + |
|
| 884 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 885 | + |
|
| 886 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 887 | + $result->avant = substr($texte, $pos_avant, $pos_boucle - $pos_avant); |
|
| 888 | + $ligne_avant = $ligne + public_compte_ligne($texte,0, $pos_avant); |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 892 | + if ($boucle['pos_preaff'] !== false) { |
|
| 893 | + |
|
| 894 | + $end_preaff = $pos_debut_boucle; |
|
| 895 | + |
|
| 896 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 897 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 898 | + $ligne_preaff = $ligne + public_compte_ligne($texte,0, $pos_preaff); |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + $debut = substr($texte, 0, $boucle['debut_boucle']); |
|
| 902 | + |
|
| 903 | + $result->id_boucle = $id_boucle; |
|
| 904 | + |
|
| 905 | + if (!preg_match(SPEC_BOUCLE, $milieu, $match)) { |
|
| 906 | + $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 907 | + erreur_squelette($err_b, $result); |
|
| 908 | + |
|
| 909 | + $ligne += public_compte_ligne($texte, 0, $pos_boucle + 1); |
|
| 910 | + $texte = substr($texte, $pos_boucle + 1); |
|
| 911 | + continue; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + $result->type_requete = $match[0]; |
|
| 915 | + $milieu = substr($milieu, strlen($match[0])); |
|
| 916 | + $pos_boucle = $pos_parent + strlen($match[0]); // on s'en sert pour compter les lignes plus precisemment |
|
| 917 | + |
|
| 918 | + $type = $match[1]; |
|
| 919 | + $jointures = trim($match[2]); |
|
| 920 | + $table_optionnelle = ($match[3]); |
|
| 921 | + if ($jointures) { |
|
| 922 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 923 | + // ou elles seront completees des jointures declarees |
|
| 924 | + $result->jointures_explicites = $jointures; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + if ($table_optionnelle) { |
|
| 928 | + $result->table_optionnelle = $type; |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 932 | + // Resultat mis dans result->param |
|
| 933 | + phraser_args($milieu, "/>", "", $all_res, $result); |
|
| 934 | + |
|
| 935 | + // En 2e passe result->criteres contiendra un tableau |
|
| 936 | + // pour l'instant on met le source (chaine) : |
|
| 937 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 938 | + $pos_fin_criteres = strpos($milieu, $result->apres); |
|
| 939 | + $pos_boucle += $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 940 | + $result->criteres = substr($milieu, 0, $pos_fin_criteres); |
|
| 941 | + $milieu = $result->apres; |
|
| 942 | + $result->apres = ""; |
|
| 943 | + |
|
| 944 | + // |
|
| 945 | + // Recuperer la fin : |
|
| 946 | + // |
|
| 947 | + if ($milieu[0] === '/') { |
|
| 948 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 949 | + $suite = substr($milieu, 2); |
|
| 950 | + $pos_boucle += 2; |
|
| 951 | + $milieu = ''; |
|
| 952 | + } else { |
|
| 953 | + $milieu = substr($milieu, 1); |
|
| 954 | + $pos_boucle += 1; |
|
| 955 | + |
|
| 956 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 957 | + $pos_fin = strpos($milieu, $fin_boucle); |
|
| 958 | + if ($pos_fin === false) { |
|
| 959 | + $err_b = array( |
|
| 960 | + 'zbug_erreur_boucle_fermant', |
|
| 961 | + array('id' => $id_boucle) |
|
| 962 | + ); |
|
| 963 | + erreur_squelette($err_b, $result); |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + $pos_boucle += $pos_fin + strlen($fin_boucle); |
|
| 967 | + $suite = substr($milieu, $pos_fin + strlen($fin_boucle)); |
|
| 968 | + $milieu = substr($milieu, 0, $pos_fin); |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + $result->milieu = $milieu; |
|
| 972 | + $ligne_suite = $ligne_apres = $ligne + public_compte_ligne($texte, 0, $pos_boucle); |
|
| 973 | + |
|
| 974 | + // |
|
| 975 | + // 1. Recuperer la partie conditionnelle apres |
|
| 976 | + // |
|
| 977 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . ">"; |
|
| 978 | + $pos_apres = strpos($suite, $apres_boucle); |
|
| 979 | + if ($pos_apres !== false) { |
|
| 980 | + $result->apres = substr($suite, 0, $pos_apres); |
|
| 981 | + $pos_apres += strlen($apres_boucle); |
|
| 982 | + $suite = substr($suite, $pos_apres); |
|
| 983 | + $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_apres); |
|
| 984 | + $pos_boucle += $pos_apres ; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + // |
|
| 989 | + // 2. Recuperer la partie alternative |
|
| 990 | + // |
|
| 991 | + $ligne_altern = $ligne_suite; |
|
| 992 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 993 | + $pos_altern = strpos($suite, $altern_boucle); |
|
| 994 | + if ($pos_altern !== false) { |
|
| 995 | + $result->altern = substr($suite, 0, $pos_altern); |
|
| 996 | + $pos_altern += strlen($altern_boucle); |
|
| 997 | + $suite = substr($suite, $pos_altern); |
|
| 998 | + $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_altern); |
|
| 999 | + $pos_boucle += $pos_altern; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + // |
|
| 1003 | + // 3. Recuperer la partie footer non alternative |
|
| 1004 | + // |
|
| 1005 | + $ligne_postaff = $ligne_suite; |
|
| 1006 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . ">"; |
|
| 1007 | + $pos_postaff = strpos($suite, $postaff_boucle); |
|
| 1008 | + if ($pos_postaff !== false) { |
|
| 1009 | + $result->postaff = substr($suite, 0, $pos_postaff); |
|
| 1010 | + $pos_postaff += strlen($postaff_boucle); |
|
| 1011 | + $suite = substr($suite, $pos_postaff); |
|
| 1012 | + $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_postaff); |
|
| 1013 | + $pos_boucle += $pos_postaff ; |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + $result->ligne = $ligne_preaff; |
|
| 1017 | + |
|
| 1018 | + if ($p = strpos($type, ':')) { |
|
| 1019 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1020 | + $type = substr($type, $p + 1); |
|
| 1021 | + } |
|
| 1022 | + $soustype = strtolower($type); |
|
| 1023 | + |
|
| 1024 | + if (!isset($GLOBALS["table_des_tables"][$soustype])) { |
|
| 1025 | + $soustype = $type; |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + $result->type_requete = $soustype; |
|
| 1029 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1030 | + if (!is_array($result->param)) { |
|
| 1031 | + $err_b = true; |
|
| 1032 | + } else { |
|
| 1033 | + phraser_criteres($result->param, $result); |
|
| 1034 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1035 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1036 | + $args = $result->param; |
|
| 1037 | + array_unshift($args, |
|
| 1038 | + substr($type, strlen(TYPE_RECURSIF))); |
|
| 1039 | + $result->param = $args; |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1044 | + $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $ligne_milieu); |
|
| 1045 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1046 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1047 | + $boucles[$id_boucle] = null; |
|
| 1048 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff); |
|
| 1049 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant); |
|
| 1050 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres); |
|
| 1051 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern); |
|
| 1052 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff); |
|
| 1053 | + |
|
| 1054 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1055 | + if ($err_b) { |
|
| 1056 | + $result->type_requete = false; |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + // Verifier qu'il n'y a pas double definition |
|
| 1060 | + // apres analyse des sous-parties (pas avant). |
|
| 1061 | + |
|
| 1062 | + if (!empty($boucles[$id_boucle])) { |
|
| 1063 | + $err_b_d = array( |
|
| 1064 | + 'zbug_erreur_boucle_double', |
|
| 1065 | + array('id' => $id_boucle) |
|
| 1066 | + ); |
|
| 1067 | + erreur_squelette($err_b_d, $result); |
|
| 1068 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1069 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1070 | + } else { |
|
| 1071 | + $boucles[$id_boucle] = $result; |
|
| 1072 | + } |
|
| 1073 | + $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
|
| 1074 | + $all_res[] = &$boucles[$id_boucle]; |
|
| 1075 | + |
|
| 1076 | + $ligne = $ligne_suite; |
|
| 1077 | + $texte = $suite; |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + return phraser_champs_etendus($texte, $ligne, $all_res); |
|
| 1081 | 1081 | } |
@@ -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) { |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @return array |
| 216 | 216 | **/ |
| 217 | 217 | function phraser_champs($texte, $ligne, $result) { |
| 218 | - while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)) { |
|
| 218 | + while (preg_match("/".NOM_DE_CHAMP."/S", $texte, $match)) { |
|
| 219 | 219 | $p = strpos($texte, $match[0]); |
| 220 | 220 | // texte après la balise |
| 221 | 221 | $suite = substr($texte, $p + strlen($match[0])); |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | $collecte[] = $champ; |
| 362 | 362 | $args = ltrim($regs[count($regs) - 1]); |
| 363 | 363 | } else { |
| 364 | - if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)) { |
|
| 364 | + if (!preg_match("/".NOM_DE_CHAMP."([{|])/", $arg, $r)) { |
|
| 365 | 365 | // 0 est un aveu d'impuissance. A completer |
| 366 | 366 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 367 | 367 | |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 447 | 447 | $res = array(); |
| 448 | 448 | while (($p = strpos($texte, "%$sep")) !== false) { |
| 449 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 449 | + if (!preg_match(',^%'.preg_quote($sep).'([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 450 | 450 | break; |
| 451 | 451 | } |
| 452 | 452 | $debut = substr($texte, 0, $p); |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 615 | 615 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
| 616 | 616 | $c = null; |
| 617 | - eval('$c = ' . $m[4] . ';'); |
|
| 617 | + eval('$c = '.$m[4].';'); |
|
| 618 | 618 | if (isset($c)) { |
| 619 | 619 | $m[4] = $c; |
| 620 | 620 | } |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | |
| 693 | 693 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
| 694 | 694 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 695 | - } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 695 | + } elseif (preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 696 | 696 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
| 697 | 697 | $a2 = trim($m[8]); |
| 698 | 698 | if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
@@ -702,8 +702,8 @@ discard block |
||
| 702 | 702 | (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
| 703 | 703 | $m[6], $m[5]); |
| 704 | 704 | $crit->exclus = $m[1]; |
| 705 | - } elseif (preg_match("/^([!]?)\s*(" . |
|
| 706 | - CHAMP_SQL_PLUS_FONC . |
|
| 705 | + } elseif (preg_match("/^([!]?)\s*(". |
|
| 706 | + CHAMP_SQL_PLUS_FONC. |
|
| 707 | 707 | ")\s*(\??)(.*)$/is", $param, $m)) { |
| 708 | 708 | // contient aussi les comparaisons implicites ! |
| 709 | 709 | // Comme ci-dessus: |
@@ -802,9 +802,9 @@ discard block |
||
| 802 | 802 | $current_pos = 0; |
| 803 | 803 | while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
| 804 | 804 | $current_pos = $pos_boucle + 1; |
| 805 | - $pos_parent = strpos($texte,'(', $pos_boucle); |
|
| 805 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 806 | 806 | if ($pos_parent === false |
| 807 | - or !$id_boucle = trim(substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))) |
|
| 807 | + or !$id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))) |
|
| 808 | 808 | or !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) { |
| 809 | 809 | |
| 810 | 810 | $result = new Boucle; |
@@ -813,7 +813,7 @@ discard block |
||
| 813 | 813 | |
| 814 | 814 | // un id_boucle pour l'affichage de l'erreur |
| 815 | 815 | if (!$id_boucle) { |
| 816 | - $id_boucle = substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 816 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 817 | 817 | } |
| 818 | 818 | $result->id_boucle = $id_boucle; |
| 819 | 819 | $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | ]; |
| 835 | 835 | |
| 836 | 836 | // trouver sa position de depart reelle : au <B_ ou au <BB_ |
| 837 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 837 | + $precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>'; |
|
| 838 | 838 | $pos_precond = strpos($texte, $precond_boucle); |
| 839 | 839 | if ($pos_precond !== false and $pos_precond < $boucle['debut_boucle']) { |
| 840 | 840 | $boucle['debut_boucle'] = $pos_precond; |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
| 843 | 843 | } |
| 844 | 844 | |
| 845 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 845 | + $preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>'; |
|
| 846 | 846 | $pos_preaff = strpos($texte, $preaff_boucle); |
| 847 | 847 | if ($pos_preaff !== false and $pos_preaff < $boucle['debut_boucle']) { |
| 848 | 848 | $boucle['debut_boucle'] = $pos_preaff; |
@@ -885,7 +885,7 @@ discard block |
||
| 885 | 885 | |
| 886 | 886 | $pos_avant = $boucle['pos_precond_inside']; |
| 887 | 887 | $result->avant = substr($texte, $pos_avant, $pos_boucle - $pos_avant); |
| 888 | - $ligne_avant = $ligne + public_compte_ligne($texte,0, $pos_avant); |
|
| 888 | + $ligne_avant = $ligne + public_compte_ligne($texte, 0, $pos_avant); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | |
| 896 | 896 | $pos_preaff = $boucle['pos_preaff_inside']; |
| 897 | 897 | $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
| 898 | - $ligne_preaff = $ligne + public_compte_ligne($texte,0, $pos_preaff); |
|
| 898 | + $ligne_preaff = $ligne + public_compte_ligne($texte, 0, $pos_preaff); |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | $debut = substr($texte, 0, $boucle['debut_boucle']); |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | $milieu = substr($milieu, 1); |
| 954 | 954 | $pos_boucle += 1; |
| 955 | 955 | |
| 956 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 956 | + $fin_boucle = BALISE_FIN_BOUCLE.$id_boucle.">"; |
|
| 957 | 957 | $pos_fin = strpos($milieu, $fin_boucle); |
| 958 | 958 | if ($pos_fin === false) { |
| 959 | 959 | $err_b = array( |
@@ -974,14 +974,14 @@ discard block |
||
| 974 | 974 | // |
| 975 | 975 | // 1. Recuperer la partie conditionnelle apres |
| 976 | 976 | // |
| 977 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . ">"; |
|
| 977 | + $apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.">"; |
|
| 978 | 978 | $pos_apres = strpos($suite, $apres_boucle); |
| 979 | 979 | if ($pos_apres !== false) { |
| 980 | 980 | $result->apres = substr($suite, 0, $pos_apres); |
| 981 | 981 | $pos_apres += strlen($apres_boucle); |
| 982 | 982 | $suite = substr($suite, $pos_apres); |
| 983 | 983 | $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_apres); |
| 984 | - $pos_boucle += $pos_apres ; |
|
| 984 | + $pos_boucle += $pos_apres; |
|
| 985 | 985 | } |
| 986 | 986 | |
| 987 | 987 | |
@@ -989,7 +989,7 @@ discard block |
||
| 989 | 989 | // 2. Recuperer la partie alternative |
| 990 | 990 | // |
| 991 | 991 | $ligne_altern = $ligne_suite; |
| 992 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 992 | + $altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.">"; |
|
| 993 | 993 | $pos_altern = strpos($suite, $altern_boucle); |
| 994 | 994 | if ($pos_altern !== false) { |
| 995 | 995 | $result->altern = substr($suite, 0, $pos_altern); |
@@ -1003,14 +1003,14 @@ discard block |
||
| 1003 | 1003 | // 3. Recuperer la partie footer non alternative |
| 1004 | 1004 | // |
| 1005 | 1005 | $ligne_postaff = $ligne_suite; |
| 1006 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . ">"; |
|
| 1006 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.">"; |
|
| 1007 | 1007 | $pos_postaff = strpos($suite, $postaff_boucle); |
| 1008 | 1008 | if ($pos_postaff !== false) { |
| 1009 | 1009 | $result->postaff = substr($suite, 0, $pos_postaff); |
| 1010 | 1010 | $pos_postaff += strlen($postaff_boucle); |
| 1011 | 1011 | $suite = substr($suite, $pos_postaff); |
| 1012 | 1012 | $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_postaff); |
| 1013 | - $pos_boucle += $pos_postaff ; |
|
| 1013 | + $pos_boucle += $pos_postaff; |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | $result->ligne = $ligne_preaff; |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * est dans une autre table et construit la jointure dessus |
| 323 | 323 | * - liste (table, champ, fonction) idem, mais en passant un |
| 324 | 324 | * nom de fonction qui s'occupera de créer la jointure. |
| 325 | - * @return array |
|
| 325 | + * @return string[] |
|
| 326 | 326 | * Liste (nom du champ alias, nom du champ). Le nom du champ alias |
| 327 | 327 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 328 | 328 | **/ |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | * Nom de la balise |
| 501 | 501 | * @param Champ $p |
| 502 | 502 | * AST au niveau de la balise |
| 503 | - * @return string |
|
| 503 | + * @return Champ |
|
| 504 | 504 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 505 | 505 | **/ |
| 506 | 506 | function calculer_balise_DEFAUT_dist($nom, $p) { |
@@ -784,6 +784,9 @@ discard block |
||
| 784 | 784 | // - deux etoiles => pas de securite non plus ! |
| 785 | 785 | // |
| 786 | 786 | // https://code.spip.net/@applique_filtres |
| 787 | +/** |
|
| 788 | + * @param Champ $p |
|
| 789 | + */ |
|
| 787 | 790 | function applique_filtres($p) { |
| 788 | 791 | |
| 789 | 792 | // Traitements standards (cf. supra) |
@@ -858,6 +861,9 @@ discard block |
||
| 858 | 861 | |
| 859 | 862 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 860 | 863 | // et comparateurs |
| 864 | +/** |
|
| 865 | + * @param string $arg |
|
| 866 | + */ |
|
| 861 | 867 | function filtre_logique($fonc, $code, $arg) { |
| 862 | 868 | |
| 863 | 869 | switch (true) { |
@@ -881,6 +887,9 @@ discard block |
||
| 881 | 887 | } |
| 882 | 888 | |
| 883 | 889 | // https://code.spip.net/@compose_filtres_args |
| 890 | +/** |
|
| 891 | + * @param string $sep |
|
| 892 | + */ |
|
| 884 | 893 | function compose_filtres_args($p, $args, $sep) { |
| 885 | 894 | $arglist = ""; |
| 886 | 895 | foreach ($args as $arg) { |
@@ -928,6 +937,11 @@ discard block |
||
| 928 | 937 | // |
| 929 | 938 | |
| 930 | 939 | // https://code.spip.net/@rindex_pile |
| 940 | +/** |
|
| 941 | + * @param Champ $p |
|
| 942 | + * @param string $champ |
|
| 943 | + * @param string $motif |
|
| 944 | + */ |
|
| 931 | 945 | function rindex_pile($p, $champ, $motif) { |
| 932 | 946 | $n = 0; |
| 933 | 947 | $b = $p->id_boucle; |
@@ -957,7 +971,7 @@ discard block |
||
| 957 | 971 | |
| 958 | 972 | /** |
| 959 | 973 | * Retourne le nom de la balise indiquée pour les messages d’erreurs |
| 960 | - * @param Pile $p Description de la balise |
|
| 974 | + * @param Champ $p Description de la balise |
|
| 961 | 975 | * @param string $champ Nom du champ |
| 962 | 976 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 963 | 977 | */ |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Compilateur\References |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * - '' si une référence explicite incorrecte est envoyée |
| 42 | 42 | */ |
| 43 | 43 | function index_boucle($p) { |
| 44 | - if (strlen($p->nom_boucle)) { |
|
| 45 | - // retourne l’index explicite demandé s’il existe |
|
| 46 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | - return $p->nom_boucle; |
|
| 48 | - } |
|
| 49 | - return ''; |
|
| 50 | - } |
|
| 51 | - return $p->id_boucle; |
|
| 44 | + if (strlen($p->nom_boucle)) { |
|
| 45 | + // retourne l’index explicite demandé s’il existe |
|
| 46 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | + return $p->nom_boucle; |
|
| 48 | + } |
|
| 49 | + return ''; |
|
| 50 | + } |
|
| 51 | + return $p->id_boucle; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | * - '' si une référence explicite incorrecte est envoyée |
| 72 | 72 | */ |
| 73 | 73 | function index_boucle_mere($p) { |
| 74 | - if (strlen($p->nom_boucle)) { |
|
| 75 | - // retourne l’index explicite demandé s’il existe |
|
| 76 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | - return $p->nom_boucle; |
|
| 78 | - } |
|
| 79 | - return ''; |
|
| 80 | - } |
|
| 81 | - if (!empty($p->descr['id_mere'])) { |
|
| 82 | - return $p->descr['id_mere']; |
|
| 83 | - } |
|
| 84 | - return ''; |
|
| 74 | + if (strlen($p->nom_boucle)) { |
|
| 75 | + // retourne l’index explicite demandé s’il existe |
|
| 76 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | + return $p->nom_boucle; |
|
| 78 | + } |
|
| 79 | + return ''; |
|
| 80 | + } |
|
| 81 | + if (!empty($p->descr['id_mere'])) { |
|
| 82 | + return $p->descr['id_mere']; |
|
| 83 | + } |
|
| 84 | + return ''; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -115,69 +115,69 @@ discard block |
||
| 115 | 115 | * Code PHP pour obtenir le champ SQL |
| 116 | 116 | */ |
| 117 | 117 | function index_pile( |
| 118 | - $idb, |
|
| 119 | - $nom_champ, |
|
| 120 | - &$boucles, |
|
| 121 | - $explicite = '', |
|
| 122 | - $defaut = null, |
|
| 123 | - $remonte_pile = true, |
|
| 124 | - $select = true |
|
| 118 | + $idb, |
|
| 119 | + $nom_champ, |
|
| 120 | + &$boucles, |
|
| 121 | + $explicite = '', |
|
| 122 | + $defaut = null, |
|
| 123 | + $remonte_pile = true, |
|
| 124 | + $select = true |
|
| 125 | 125 | ) { |
| 126 | - if (!is_string($defaut)) { |
|
| 127 | - $defaut = '@$Pile[0][\'' . strtolower($nom_champ) . '\']'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $i = 0; |
|
| 131 | - if (strlen($explicite)) { |
|
| 132 | - // Recherche d'un champ dans un etage superieur |
|
| 133 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 134 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 135 | - $i++; |
|
| 136 | - $idb = $boucles[$idb]->id_parent; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 141 | - $nom_champ = strtolower($nom_champ); |
|
| 142 | - $conditionnel = array(); |
|
| 143 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 144 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 145 | - while (isset($boucles[$idb])) { |
|
| 146 | - $joker = true; |
|
| 147 | - // modifie $joker si tous les champs sont autorisés. |
|
| 148 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 149 | - // $c = le nom du champ demandé |
|
| 150 | - list($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 151 | - if ($t) { |
|
| 152 | - if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 153 | - $boucles[$idb]->select[] = $t; |
|
| 154 | - } |
|
| 155 | - $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
|
| 156 | - if (!$joker) { |
|
| 157 | - return index_compose($conditionnel, $champ); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 161 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 162 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 163 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 164 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - if ($remonte_pile) { |
|
| 168 | - # spip_log("On remonte vers $i"); |
|
| 169 | - // Sinon on remonte d'un cran |
|
| 170 | - $idb = $boucles[$idb]->id_parent; |
|
| 171 | - $i++; |
|
| 172 | - } else { |
|
| 173 | - $idb = null; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - # spip_log("Pas vu $nom_champ"); |
|
| 178 | - // esperons qu'il y sera |
|
| 179 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 180 | - return index_compose($conditionnel, $defaut); |
|
| 126 | + if (!is_string($defaut)) { |
|
| 127 | + $defaut = '@$Pile[0][\'' . strtolower($nom_champ) . '\']'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $i = 0; |
|
| 131 | + if (strlen($explicite)) { |
|
| 132 | + // Recherche d'un champ dans un etage superieur |
|
| 133 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 134 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 135 | + $i++; |
|
| 136 | + $idb = $boucles[$idb]->id_parent; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 141 | + $nom_champ = strtolower($nom_champ); |
|
| 142 | + $conditionnel = array(); |
|
| 143 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 144 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 145 | + while (isset($boucles[$idb])) { |
|
| 146 | + $joker = true; |
|
| 147 | + // modifie $joker si tous les champs sont autorisés. |
|
| 148 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 149 | + // $c = le nom du champ demandé |
|
| 150 | + list($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 151 | + if ($t) { |
|
| 152 | + if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 153 | + $boucles[$idb]->select[] = $t; |
|
| 154 | + } |
|
| 155 | + $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
|
| 156 | + if (!$joker) { |
|
| 157 | + return index_compose($conditionnel, $champ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 161 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 162 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 163 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 164 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + if ($remonte_pile) { |
|
| 168 | + # spip_log("On remonte vers $i"); |
|
| 169 | + // Sinon on remonte d'un cran |
|
| 170 | + $idb = $boucles[$idb]->id_parent; |
|
| 171 | + $i++; |
|
| 172 | + } else { |
|
| 173 | + $idb = null; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + # spip_log("Pas vu $nom_champ"); |
|
| 178 | + // esperons qu'il y sera |
|
| 179 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 180 | + return index_compose($conditionnel, $defaut); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -191,12 +191,12 @@ discard block |
||
| 191 | 191 | * @return string Code PHP complet de recherche d'un champ |
| 192 | 192 | */ |
| 193 | 193 | function index_compose($conditionnel, $defaut) { |
| 194 | - while ($c = array_pop($conditionnel)) { |
|
| 195 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 196 | - $defaut = "($c:(" . ($defaut ? $defaut : "''") . "))"; |
|
| 197 | - } |
|
| 194 | + while ($c = array_pop($conditionnel)) { |
|
| 195 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 196 | + $defaut = "($c:(" . ($defaut ? $defaut : "''") . "))"; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return $defaut; |
|
| 199 | + return $defaut; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -232,74 +232,74 @@ discard block |
||
| 232 | 232 | **/ |
| 233 | 233 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 234 | 234 | |
| 235 | - $r = $boucles[$idb]->type_requete; |
|
| 236 | - // boucle recursive, c'est foutu... |
|
| 237 | - if ($r == TYPE_RECURSIF) { |
|
| 238 | - return array(); |
|
| 239 | - } |
|
| 240 | - if (!$r) { |
|
| 241 | - $joker = false; // indiquer a l'appelant |
|
| 242 | - # continuer pour chercher l'erreur suivante |
|
| 243 | - return array("'#" . $r . ':' . $nom_champ . "'", ''); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $desc = $boucles[$idb]->show; |
|
| 247 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 248 | - $excep = isset($GLOBALS['exceptions_des_tables'][$r]) ? $GLOBALS['exceptions_des_tables'][$r] : ''; |
|
| 249 | - if ($excep) { |
|
| 250 | - $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 251 | - } |
|
| 252 | - if ($excep) { |
|
| 253 | - $joker = false; // indiquer a l'appelant |
|
| 254 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 255 | - } // pas d'alias. Le champ existe t'il ? |
|
| 256 | - else { |
|
| 257 | - // le champ est réellement présent, on le prend. |
|
| 258 | - if (isset($desc['field'][$nom_champ])) { |
|
| 259 | - $t = $boucles[$idb]->id_table; |
|
| 260 | - $joker = false; // indiquer a l'appelant |
|
| 261 | - return array("$t.$nom_champ", $nom_champ); |
|
| 262 | - } |
|
| 263 | - // Tous les champs sont-ils acceptés ? |
|
| 264 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 265 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 266 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 267 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 268 | - elseif (/*$joker AND */ |
|
| 269 | - isset($desc['field']['*']) |
|
| 270 | - ) { |
|
| 271 | - $joker = true; // indiquer a l'appelant |
|
| 272 | - return array($nom_champ, $nom_champ); |
|
| 273 | - } |
|
| 274 | - // pas d'alias, pas de champ, pas de joker... |
|
| 275 | - // tenter via une jointure... |
|
| 276 | - else { |
|
| 277 | - $joker = false; // indiquer a l'appelant |
|
| 278 | - // regarder si le champ est deja dans une jointure existante |
|
| 279 | - // sinon, si il y a des joitures explicites, la construire |
|
| 280 | - if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 281 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 282 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 283 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 284 | - // mais est-ce ce qu'on veut ? |
|
| 285 | - $jointures = preg_split("/\s+/", $boucles[$idb]->jointures_explicites); |
|
| 286 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 287 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - if ($t) { |
|
| 292 | - // si on a trouvé une jointure possible, on fait comme |
|
| 293 | - // si c'était une exception pour le champ demandé |
|
| 294 | - return index_exception($boucles[$idb], |
|
| 295 | - $desc, |
|
| 296 | - $nom_champ, |
|
| 297 | - array($t[1]['id_table'], reset($t[2]))); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - return array('', ''); |
|
| 301 | - } |
|
| 302 | - } |
|
| 235 | + $r = $boucles[$idb]->type_requete; |
|
| 236 | + // boucle recursive, c'est foutu... |
|
| 237 | + if ($r == TYPE_RECURSIF) { |
|
| 238 | + return array(); |
|
| 239 | + } |
|
| 240 | + if (!$r) { |
|
| 241 | + $joker = false; // indiquer a l'appelant |
|
| 242 | + # continuer pour chercher l'erreur suivante |
|
| 243 | + return array("'#" . $r . ':' . $nom_champ . "'", ''); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $desc = $boucles[$idb]->show; |
|
| 247 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 248 | + $excep = isset($GLOBALS['exceptions_des_tables'][$r]) ? $GLOBALS['exceptions_des_tables'][$r] : ''; |
|
| 249 | + if ($excep) { |
|
| 250 | + $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 251 | + } |
|
| 252 | + if ($excep) { |
|
| 253 | + $joker = false; // indiquer a l'appelant |
|
| 254 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 255 | + } // pas d'alias. Le champ existe t'il ? |
|
| 256 | + else { |
|
| 257 | + // le champ est réellement présent, on le prend. |
|
| 258 | + if (isset($desc['field'][$nom_champ])) { |
|
| 259 | + $t = $boucles[$idb]->id_table; |
|
| 260 | + $joker = false; // indiquer a l'appelant |
|
| 261 | + return array("$t.$nom_champ", $nom_champ); |
|
| 262 | + } |
|
| 263 | + // Tous les champs sont-ils acceptés ? |
|
| 264 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 265 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 266 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 267 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 268 | + elseif (/*$joker AND */ |
|
| 269 | + isset($desc['field']['*']) |
|
| 270 | + ) { |
|
| 271 | + $joker = true; // indiquer a l'appelant |
|
| 272 | + return array($nom_champ, $nom_champ); |
|
| 273 | + } |
|
| 274 | + // pas d'alias, pas de champ, pas de joker... |
|
| 275 | + // tenter via une jointure... |
|
| 276 | + else { |
|
| 277 | + $joker = false; // indiquer a l'appelant |
|
| 278 | + // regarder si le champ est deja dans une jointure existante |
|
| 279 | + // sinon, si il y a des joitures explicites, la construire |
|
| 280 | + if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 281 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 282 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 283 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 284 | + // mais est-ce ce qu'on veut ? |
|
| 285 | + $jointures = preg_split("/\s+/", $boucles[$idb]->jointures_explicites); |
|
| 286 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 287 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + if ($t) { |
|
| 292 | + // si on a trouvé une jointure possible, on fait comme |
|
| 293 | + // si c'était une exception pour le champ demandé |
|
| 294 | + return index_exception($boucles[$idb], |
|
| 295 | + $desc, |
|
| 296 | + $nom_champ, |
|
| 297 | + array($t[1]['id_table'], reset($t[2]))); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + return array('', ''); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -327,52 +327,52 @@ discard block |
||
| 327 | 327 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 328 | 328 | **/ |
| 329 | 329 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 330 | - static $trouver_table; |
|
| 331 | - if (!$trouver_table) { |
|
| 332 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - if (is_array($excep)) { |
|
| 336 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 337 | - $t = null; |
|
| 338 | - if (count($excep) == 3) { |
|
| 339 | - $index_exception_derogatoire = array_pop($excep); |
|
| 340 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 341 | - } |
|
| 342 | - if ($t == null) { |
|
| 343 | - list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 344 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 345 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 346 | - if (!$j) { |
|
| 347 | - return array('', ''); |
|
| 348 | - } |
|
| 349 | - $e = $j['table']; |
|
| 350 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 351 | - $k = $j['key']['PRIMARY KEY']; |
|
| 352 | - if (strpos($k, ',')) { |
|
| 353 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 354 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 355 | - if (!in_array($k, $l)) { |
|
| 356 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 357 | - |
|
| 358 | - return array('', ''); |
|
| 359 | - } |
|
| 360 | - } |
|
| 361 | - $k = array($boucle->id_table, array($e), $k); |
|
| 362 | - fabrique_jointures($boucle, array($k)); |
|
| 363 | - $t = array_search($e, $boucle->from); |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - } else { |
|
| 367 | - $t = $boucle->id_table; |
|
| 368 | - } |
|
| 369 | - // demander a SQL de gerer le synonyme |
|
| 370 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 371 | - if ($excep != $nom_champ) { |
|
| 372 | - $excep .= ' AS ' . $nom_champ; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return array("$t.$excep", $nom_champ); |
|
| 330 | + static $trouver_table; |
|
| 331 | + if (!$trouver_table) { |
|
| 332 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + if (is_array($excep)) { |
|
| 336 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 337 | + $t = null; |
|
| 338 | + if (count($excep) == 3) { |
|
| 339 | + $index_exception_derogatoire = array_pop($excep); |
|
| 340 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 341 | + } |
|
| 342 | + if ($t == null) { |
|
| 343 | + list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 344 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 345 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 346 | + if (!$j) { |
|
| 347 | + return array('', ''); |
|
| 348 | + } |
|
| 349 | + $e = $j['table']; |
|
| 350 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 351 | + $k = $j['key']['PRIMARY KEY']; |
|
| 352 | + if (strpos($k, ',')) { |
|
| 353 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 354 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 355 | + if (!in_array($k, $l)) { |
|
| 356 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 357 | + |
|
| 358 | + return array('', ''); |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | + $k = array($boucle->id_table, array($e), $k); |
|
| 362 | + fabrique_jointures($boucle, array($k)); |
|
| 363 | + $t = array_search($e, $boucle->from); |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + } else { |
|
| 367 | + $t = $boucle->id_table; |
|
| 368 | + } |
|
| 369 | + // demander a SQL de gerer le synonyme |
|
| 370 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 371 | + if ($excep != $nom_champ) { |
|
| 372 | + $excep .= ' AS ' . $nom_champ; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return array("$t.$excep", $nom_champ); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | * Code PHP pour retrouver le champ |
| 398 | 398 | */ |
| 399 | 399 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 400 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 400 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | |
@@ -417,9 +417,9 @@ discard block |
||
| 417 | 417 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 418 | 418 | **/ |
| 419 | 419 | function calculer_champ($p) { |
| 420 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 420 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 421 | 421 | |
| 422 | - return applique_filtres($p); |
|
| 422 | + return applique_filtres($p); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | |
@@ -456,28 +456,28 @@ discard block |
||
| 456 | 456 | **/ |
| 457 | 457 | function calculer_balise($nom, $p) { |
| 458 | 458 | |
| 459 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 460 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 461 | - $p->balise_calculee = true; |
|
| 462 | - $res = $f($p); |
|
| 463 | - if ($res !== null and is_object($res)) { |
|
| 464 | - return $res; |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // Certaines des balises comportant un _ sont generiques |
|
| 469 | - if ($f = strpos($nom, '_') |
|
| 470 | - and $f = charger_fonction(substr($nom, 0, $f + 1), 'balise', true) |
|
| 471 | - ) { |
|
| 472 | - $res = $f($p); |
|
| 473 | - if ($res !== null and is_object($res)) { |
|
| 474 | - return $res; |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 479 | - |
|
| 480 | - return $f($nom, $p); |
|
| 459 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 460 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 461 | + $p->balise_calculee = true; |
|
| 462 | + $res = $f($p); |
|
| 463 | + if ($res !== null and is_object($res)) { |
|
| 464 | + return $res; |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // Certaines des balises comportant un _ sont generiques |
|
| 469 | + if ($f = strpos($nom, '_') |
|
| 470 | + and $f = charger_fonction(substr($nom, 0, $f + 1), 'balise', true) |
|
| 471 | + ) { |
|
| 472 | + $res = $f($p); |
|
| 473 | + if ($res !== null and is_object($res)) { |
|
| 474 | + return $res; |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 479 | + |
|
| 480 | + return $f($nom, $p); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | |
@@ -505,36 +505,36 @@ discard block |
||
| 505 | 505 | **/ |
| 506 | 506 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 507 | 507 | |
| 508 | - // ca pourrait etre un champ SQL homonyme, |
|
| 509 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 510 | - |
|
| 511 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 512 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 513 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 514 | - $code = addslashes($p->fonctions[0][1]); |
|
| 515 | - $p->code .= " . '$code'"; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 519 | - if (strpos($nom, 'ID_') === 0) { |
|
| 520 | - $p->interdire_scripts = false; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 524 | - // SI le champ SQL n'est pas trouve |
|
| 525 | - // ET si la balise a une forme de couleur |
|
| 526 | - // ET s'il n'y a ni filtre ni etoile |
|
| 527 | - // ALORS retourner la couleur. |
|
| 528 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 529 | - if (preg_match("/^[A-F]{1,6}$/i", $nom) |
|
| 530 | - and !$p->etoile |
|
| 531 | - and !$p->fonctions |
|
| 532 | - ) { |
|
| 533 | - $p->code = "'#$nom'"; |
|
| 534 | - $p->interdire_scripts = false; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - return $p; |
|
| 508 | + // ca pourrait etre un champ SQL homonyme, |
|
| 509 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 510 | + |
|
| 511 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 512 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 513 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 514 | + $code = addslashes($p->fonctions[0][1]); |
|
| 515 | + $p->code .= " . '$code'"; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 519 | + if (strpos($nom, 'ID_') === 0) { |
|
| 520 | + $p->interdire_scripts = false; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 524 | + // SI le champ SQL n'est pas trouve |
|
| 525 | + // ET si la balise a une forme de couleur |
|
| 526 | + // ET s'il n'y a ni filtre ni etoile |
|
| 527 | + // ALORS retourner la couleur. |
|
| 528 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 529 | + if (preg_match("/^[A-F]{1,6}$/i", $nom) |
|
| 530 | + and !$p->etoile |
|
| 531 | + and !$p->fonctions |
|
| 532 | + ) { |
|
| 533 | + $p->code = "'#$nom'"; |
|
| 534 | + $p->interdire_scripts = false; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + return $p; |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | |
@@ -577,36 +577,36 @@ discard block |
||
| 577 | 577 | **/ |
| 578 | 578 | function calculer_balise_dynamique($p, $nom, $l, $supp = array()) { |
| 579 | 579 | |
| 580 | - if (!balise_distante_interdite($p)) { |
|
| 581 | - $p->code = "''"; |
|
| 582 | - |
|
| 583 | - return $p; |
|
| 584 | - } |
|
| 585 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 586 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 587 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 588 | - $p->fonctions = null; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - if ($p->param and ($c = $p->param[0])) { |
|
| 592 | - // liste d'arguments commence toujours par la chaine vide |
|
| 593 | - array_shift($c); |
|
| 594 | - // construire la liste d'arguments comme pour un filtre |
|
| 595 | - $param = compose_filtres_args($p, $c, ','); |
|
| 596 | - } else { |
|
| 597 | - $param = ""; |
|
| 598 | - } |
|
| 599 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 600 | - |
|
| 601 | - $p->code = sprintf(CODE_EXECUTER_BALISE, $nom, |
|
| 602 | - join(',', $collecte), |
|
| 603 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 604 | - memoriser_contexte_compil($p), |
|
| 605 | - (!$supp ? '' : (', ' . join(',', $supp)))); |
|
| 606 | - |
|
| 607 | - $p->interdire_scripts = false; |
|
| 608 | - |
|
| 609 | - return $p; |
|
| 580 | + if (!balise_distante_interdite($p)) { |
|
| 581 | + $p->code = "''"; |
|
| 582 | + |
|
| 583 | + return $p; |
|
| 584 | + } |
|
| 585 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 586 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 587 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 588 | + $p->fonctions = null; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + if ($p->param and ($c = $p->param[0])) { |
|
| 592 | + // liste d'arguments commence toujours par la chaine vide |
|
| 593 | + array_shift($c); |
|
| 594 | + // construire la liste d'arguments comme pour un filtre |
|
| 595 | + $param = compose_filtres_args($p, $c, ','); |
|
| 596 | + } else { |
|
| 597 | + $param = ""; |
|
| 598 | + } |
|
| 599 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 600 | + |
|
| 601 | + $p->code = sprintf(CODE_EXECUTER_BALISE, $nom, |
|
| 602 | + join(',', $collecte), |
|
| 603 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 604 | + memoriser_contexte_compil($p), |
|
| 605 | + (!$supp ? '' : (', ' . join(',', $supp)))); |
|
| 606 | + |
|
| 607 | + $p->interdire_scripts = false; |
|
| 608 | + |
|
| 609 | + return $p; |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | |
@@ -636,13 +636,13 @@ discard block |
||
| 636 | 636 | * Liste des codes PHP d'éxecution des balises collectées |
| 637 | 637 | **/ |
| 638 | 638 | function collecter_balise_dynamique($l, &$p, $nom) { |
| 639 | - $args = array(); |
|
| 640 | - foreach ($l as $c) { |
|
| 641 | - $x = calculer_balise($c, $p); |
|
| 642 | - $args[] = $x->code; |
|
| 643 | - } |
|
| 639 | + $args = array(); |
|
| 640 | + foreach ($l as $c) { |
|
| 641 | + $x = calculer_balise($c, $p); |
|
| 642 | + $args[] = $x->code; |
|
| 643 | + } |
|
| 644 | 644 | |
| 645 | - return $args; |
|
| 645 | + return $args; |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | |
@@ -657,20 +657,20 @@ discard block |
||
| 657 | 657 | * Nom de la connexion |
| 658 | 658 | **/ |
| 659 | 659 | function trouver_nom_serveur_distant($p) { |
| 660 | - $nom = $p->id_boucle; |
|
| 661 | - if ($nom |
|
| 662 | - and isset($p->boucles[$nom]) |
|
| 663 | - ) { |
|
| 664 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 665 | - if (strlen($s) |
|
| 666 | - and strlen($serveur = strtolower($s)) |
|
| 667 | - and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 668 | - ) { |
|
| 669 | - return $serveur; |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - return ""; |
|
| 660 | + $nom = $p->id_boucle; |
|
| 661 | + if ($nom |
|
| 662 | + and isset($p->boucles[$nom]) |
|
| 663 | + ) { |
|
| 664 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 665 | + if (strlen($s) |
|
| 666 | + and strlen($serveur = strtolower($s)) |
|
| 667 | + and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 668 | + ) { |
|
| 669 | + return $serveur; |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + return ""; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | |
@@ -694,15 +694,15 @@ discard block |
||
| 694 | 694 | * - false : La balise est interdite car le serveur est distant |
| 695 | 695 | **/ |
| 696 | 696 | function balise_distante_interdite($p) { |
| 697 | - $nom = $p->id_boucle; |
|
| 697 | + $nom = $p->id_boucle; |
|
| 698 | 698 | |
| 699 | - if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 700 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 699 | + if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 700 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 701 | 701 | |
| 702 | - return false; |
|
| 703 | - } |
|
| 702 | + return false; |
|
| 703 | + } |
|
| 704 | 704 | |
| 705 | - return true; |
|
| 705 | + return true; |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | |
@@ -713,67 +713,67 @@ discard block |
||
| 713 | 713 | // https://code.spip.net/@champs_traitements |
| 714 | 714 | function champs_traitements($p) { |
| 715 | 715 | |
| 716 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 717 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 718 | - } else { |
|
| 719 | - // quand on utilise un traitement catch-all * |
|
| 720 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 721 | - // leur propre securite |
|
| 722 | - if (!$p->balise_calculee) { |
|
| 723 | - $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 724 | - } else { |
|
| 725 | - $ps = false; |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - if (is_array($ps)) { |
|
| 730 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 731 | - $idb = index_boucle($p); |
|
| 732 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 733 | - $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
|
| 734 | - $table_sql = isset($p->boucles[$idb]->show['table_sql']) ? $p->boucles[$idb]->show['table_sql'] : false; |
|
| 735 | - |
|
| 736 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 737 | - if ($table_sql and isset($ps[$table_sql])) { |
|
| 738 | - $ps = $ps[$table_sql]; |
|
| 739 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 740 | - elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 741 | - $ps = $ps[$type_requete]; |
|
| 742 | - } // ou pour indiferrement quelle que soit la boucle |
|
| 743 | - elseif (isset($ps[0])) { |
|
| 744 | - $ps = $ps[0]; |
|
| 745 | - } else { |
|
| 746 | - $ps = false; |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - if (!$ps) { |
|
| 751 | - return $p->code; |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 755 | - // ou si in INCLURE contient {doublons} |
|
| 756 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 757 | - // dans les filtres propre() ou typo() |
|
| 758 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 759 | - |
|
| 760 | - if (isset($p->descr['documents']) |
|
| 761 | - and |
|
| 762 | - $p->descr['documents'] |
|
| 763 | - and ( |
|
| 764 | - (strpos($ps, 'propre') !== false) |
|
| 765 | - or |
|
| 766 | - (strpos($ps, 'typo') !== false) |
|
| 767 | - ) |
|
| 768 | - ) { |
|
| 769 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 773 | - // dans la declaration des traitements des champs sensibles |
|
| 774 | - |
|
| 775 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 776 | - return str_replace('%s', $p->code, $ps); |
|
| 716 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 717 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 718 | + } else { |
|
| 719 | + // quand on utilise un traitement catch-all * |
|
| 720 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 721 | + // leur propre securite |
|
| 722 | + if (!$p->balise_calculee) { |
|
| 723 | + $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 724 | + } else { |
|
| 725 | + $ps = false; |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + if (is_array($ps)) { |
|
| 730 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 731 | + $idb = index_boucle($p); |
|
| 732 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 733 | + $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
|
| 734 | + $table_sql = isset($p->boucles[$idb]->show['table_sql']) ? $p->boucles[$idb]->show['table_sql'] : false; |
|
| 735 | + |
|
| 736 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 737 | + if ($table_sql and isset($ps[$table_sql])) { |
|
| 738 | + $ps = $ps[$table_sql]; |
|
| 739 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 740 | + elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 741 | + $ps = $ps[$type_requete]; |
|
| 742 | + } // ou pour indiferrement quelle que soit la boucle |
|
| 743 | + elseif (isset($ps[0])) { |
|
| 744 | + $ps = $ps[0]; |
|
| 745 | + } else { |
|
| 746 | + $ps = false; |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + if (!$ps) { |
|
| 751 | + return $p->code; |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 755 | + // ou si in INCLURE contient {doublons} |
|
| 756 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 757 | + // dans les filtres propre() ou typo() |
|
| 758 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 759 | + |
|
| 760 | + if (isset($p->descr['documents']) |
|
| 761 | + and |
|
| 762 | + $p->descr['documents'] |
|
| 763 | + and ( |
|
| 764 | + (strpos($ps, 'propre') !== false) |
|
| 765 | + or |
|
| 766 | + (strpos($ps, 'typo') !== false) |
|
| 767 | + ) |
|
| 768 | + ) { |
|
| 769 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 773 | + // dans la declaration des traitements des champs sensibles |
|
| 774 | + |
|
| 775 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 776 | + return str_replace('%s', $p->code, $ps); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | |
@@ -786,109 +786,109 @@ discard block |
||
| 786 | 786 | // https://code.spip.net/@applique_filtres |
| 787 | 787 | function applique_filtres($p) { |
| 788 | 788 | |
| 789 | - // Traitements standards (cf. supra) |
|
| 790 | - if ($p->etoile == '') { |
|
| 791 | - $code = champs_traitements($p); |
|
| 792 | - } else { |
|
| 793 | - $code = $p->code; |
|
| 794 | - } |
|
| 789 | + // Traitements standards (cf. supra) |
|
| 790 | + if ($p->etoile == '') { |
|
| 791 | + $code = champs_traitements($p); |
|
| 792 | + } else { |
|
| 793 | + $code = $p->code; |
|
| 794 | + } |
|
| 795 | 795 | |
| 796 | - // Appliquer les filtres perso |
|
| 797 | - if ($p->param) { |
|
| 798 | - $code = compose_filtres($p, $code); |
|
| 799 | - } |
|
| 796 | + // Appliquer les filtres perso |
|
| 797 | + if ($p->param) { |
|
| 798 | + $code = compose_filtres($p, $code); |
|
| 799 | + } |
|
| 800 | 800 | |
| 801 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 802 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 803 | - if (isset($p->descr['session'])) { |
|
| 804 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 805 | - } |
|
| 801 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 802 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 803 | + if (isset($p->descr['session'])) { |
|
| 804 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 805 | + } |
|
| 806 | 806 | |
| 807 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 807 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 808 | 808 | |
| 809 | - return $code; |
|
| 809 | + return $code; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 813 | 813 | // https://code.spip.net/@compose_filtres |
| 814 | 814 | function compose_filtres(&$p, $code) { |
| 815 | 815 | |
| 816 | - $image_miette = false; |
|
| 817 | - foreach ($p->param as $filtre) { |
|
| 818 | - $fonc = array_shift($filtre); |
|
| 819 | - if (!$fonc) { |
|
| 820 | - continue; |
|
| 821 | - } // normalement qu'au premier tour. |
|
| 822 | - $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 823 | - if ($image_miette and !$is_filtre_image) { |
|
| 824 | - // il faut graver maintenant car apres le filtre en cours |
|
| 825 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 826 | - $code = "filtrer('image_graver', $code)"; |
|
| 827 | - $image_miette = false; |
|
| 828 | - } |
|
| 829 | - // recuperer les arguments du filtre, |
|
| 830 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 831 | - if ($fonc !== '?') { |
|
| 832 | - $sep = ','; |
|
| 833 | - } else { |
|
| 834 | - $sep = ':'; |
|
| 835 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 836 | - if (count($filtre) != 2) { |
|
| 837 | - $filtre = array(isset($filtre[0]) ? $filtre[0] : "", isset($filtre[1]) ? $filtre[1] : ""); |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 841 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 842 | - if ($logique) { |
|
| 843 | - $code = $logique; |
|
| 844 | - } else { |
|
| 845 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p); |
|
| 846 | - if ($is_filtre_image) { |
|
| 847 | - $image_miette = true; |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 852 | - if ($image_miette) { |
|
| 853 | - $code = "filtrer('image_graver',$code)"; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - return $code; |
|
| 816 | + $image_miette = false; |
|
| 817 | + foreach ($p->param as $filtre) { |
|
| 818 | + $fonc = array_shift($filtre); |
|
| 819 | + if (!$fonc) { |
|
| 820 | + continue; |
|
| 821 | + } // normalement qu'au premier tour. |
|
| 822 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 823 | + if ($image_miette and !$is_filtre_image) { |
|
| 824 | + // il faut graver maintenant car apres le filtre en cours |
|
| 825 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 826 | + $code = "filtrer('image_graver', $code)"; |
|
| 827 | + $image_miette = false; |
|
| 828 | + } |
|
| 829 | + // recuperer les arguments du filtre, |
|
| 830 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 831 | + if ($fonc !== '?') { |
|
| 832 | + $sep = ','; |
|
| 833 | + } else { |
|
| 834 | + $sep = ':'; |
|
| 835 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 836 | + if (count($filtre) != 2) { |
|
| 837 | + $filtre = array(isset($filtre[0]) ? $filtre[0] : "", isset($filtre[1]) ? $filtre[1] : ""); |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 841 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 842 | + if ($logique) { |
|
| 843 | + $code = $logique; |
|
| 844 | + } else { |
|
| 845 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p); |
|
| 846 | + if ($is_filtre_image) { |
|
| 847 | + $image_miette = true; |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 852 | + if ($image_miette) { |
|
| 853 | + $code = "filtrer('image_graver',$code)"; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + return $code; |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 860 | 860 | // et comparateurs |
| 861 | 861 | function filtre_logique($fonc, $code, $arg) { |
| 862 | 862 | |
| 863 | - switch (true) { |
|
| 864 | - case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 865 | - return "($code $fonc $arg)"; |
|
| 866 | - case ($fonc == 'and') or ($fonc == 'et'): |
|
| 867 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 868 | - case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 869 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 870 | - case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 871 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 872 | - case ($fonc == 'sinon'): |
|
| 873 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 874 | - case ($fonc == 'not') or ($fonc == 'non'): |
|
| 875 | - return "(($code) ?'' :' ')"; |
|
| 876 | - case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 877 | - return "(($code) ?' ' :'')"; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - return ''; |
|
| 863 | + switch (true) { |
|
| 864 | + case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 865 | + return "($code $fonc $arg)"; |
|
| 866 | + case ($fonc == 'and') or ($fonc == 'et'): |
|
| 867 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 868 | + case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 869 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 870 | + case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 871 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 872 | + case ($fonc == 'sinon'): |
|
| 873 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 874 | + case ($fonc == 'not') or ($fonc == 'non'): |
|
| 875 | + return "(($code) ?'' :' ')"; |
|
| 876 | + case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 877 | + return "(($code) ?' ' :'')"; |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + return ''; |
|
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | // https://code.spip.net/@compose_filtres_args |
| 884 | 884 | function compose_filtres_args($p, $args, $sep) { |
| 885 | - $arglist = ""; |
|
| 886 | - foreach ($args as $arg) { |
|
| 887 | - $arglist .= $sep . |
|
| 888 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 889 | - } |
|
| 885 | + $arglist = ""; |
|
| 886 | + foreach ($args as $arg) { |
|
| 887 | + $arglist .= $sep . |
|
| 888 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 889 | + } |
|
| 890 | 890 | |
| 891 | - return $arglist; |
|
| 891 | + return $arglist; |
|
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | |
@@ -906,15 +906,15 @@ discard block |
||
| 906 | 906 | **/ |
| 907 | 907 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 908 | 908 | |
| 909 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 910 | - if ($boucles[$idb]->externe) { |
|
| 911 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 912 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 913 | - // on ignore le defaut fourni dans ce cas |
|
| 914 | - $defaut = "@\$Pile[\$SP]['$nom_champ']"; |
|
| 915 | - } |
|
| 909 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 910 | + if ($boucles[$idb]->externe) { |
|
| 911 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 912 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 913 | + // on ignore le defaut fourni dans ce cas |
|
| 914 | + $defaut = "@\$Pile[\$SP]['$nom_champ']"; |
|
| 915 | + } |
|
| 916 | 916 | |
| 917 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 917 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | // |
@@ -929,30 +929,30 @@ discard block |
||
| 929 | 929 | |
| 930 | 930 | // https://code.spip.net/@rindex_pile |
| 931 | 931 | function rindex_pile($p, $champ, $motif) { |
| 932 | - $n = 0; |
|
| 933 | - $b = $p->id_boucle; |
|
| 934 | - $p->code = ''; |
|
| 935 | - while ($b != '') { |
|
| 936 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 937 | - if ($critere->op == $motif) { |
|
| 938 | - $p->code = '$Pile[$SP' . (($n == 0) ? "" : "-$n") . |
|
| 939 | - "]['$champ']"; |
|
| 940 | - $b = ''; |
|
| 941 | - break 2; |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - $n++; |
|
| 945 | - $b = $p->boucles[$b]->id_parent; |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 949 | - if (!$p->code) { |
|
| 950 | - $p->code = "''"; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - $p->interdire_scripts = false; |
|
| 954 | - |
|
| 955 | - return $p; |
|
| 932 | + $n = 0; |
|
| 933 | + $b = $p->id_boucle; |
|
| 934 | + $p->code = ''; |
|
| 935 | + while ($b != '') { |
|
| 936 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 937 | + if ($critere->op == $motif) { |
|
| 938 | + $p->code = '$Pile[$SP' . (($n == 0) ? "" : "-$n") . |
|
| 939 | + "]['$champ']"; |
|
| 940 | + $b = ''; |
|
| 941 | + break 2; |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + $n++; |
|
| 945 | + $b = $p->boucles[$b]->id_parent; |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 949 | + if (!$p->code) { |
|
| 950 | + $p->code = "''"; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + $p->interdire_scripts = false; |
|
| 954 | + |
|
| 955 | + return $p; |
|
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | /** |
@@ -962,7 +962,7 @@ discard block |
||
| 962 | 962 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 963 | 963 | */ |
| 964 | 964 | function zbug_presenter_champ($p, $champ = "") { |
| 965 | - $balise = $champ ? $champ : $p->nom_champ; |
|
| 966 | - $explicite = $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 967 | - return "#{$explicite}{$balise}"; |
|
| 965 | + $balise = $champ ? $champ : $p->nom_champ; |
|
| 966 | + $explicite = $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 967 | + return "#{$explicite}{$balise}"; |
|
| 968 | 968 | } |
| 969 | 969 | \ No newline at end of file |
@@ -132,6 +132,11 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | // Par ou ca passe une fois les traductions faites |
| 134 | 134 | // https://code.spip.net/@spip_pg_trace_query |
| 135 | +/** |
|
| 136 | + * @param string $query |
|
| 137 | + * |
|
| 138 | + * @return resource |
|
| 139 | + */ |
|
| 135 | 140 | function spip_pg_trace_query($query, $serveur = '') { |
| 136 | 141 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 137 | 142 | $prefixe = $connexion['prefixe']; |
@@ -291,6 +296,9 @@ discard block |
||
| 291 | 296 | } |
| 292 | 297 | |
| 293 | 298 | // https://code.spip.net/@spip_pg_alter_change |
| 299 | +/** |
|
| 300 | + * @param string $arg |
|
| 301 | + */ |
|
| 294 | 302 | function spip_pg_alter_change($table, $arg, $serveur = '', $requeter = true) { |
| 295 | 303 | if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) { |
| 296 | 304 | spip_log("alter change: $arg incompris", 'pg.' . _LOG_ERREUR); |
@@ -417,6 +425,7 @@ discard block |
||
| 417 | 425 | * @param string /array $champs : liste de champs sur lesquels s'applique l'index |
| 418 | 426 | * @param string $serveur : nom de la connexion sql utilisee |
| 419 | 427 | * @param bool $requeter : true pour executer la requete ou false pour retourner le texte de la requete |
| 428 | + * @param string $champs |
|
| 420 | 429 | * |
| 421 | 430 | * @return bool ou requete |
| 422 | 431 | */ |
@@ -592,6 +601,9 @@ discard block |
||
| 592 | 601 | } |
| 593 | 602 | |
| 594 | 603 | // https://code.spip.net/@spip_pg_orderby |
| 604 | +/** |
|
| 605 | + * @param string $order |
|
| 606 | + */ |
|
| 595 | 607 | function spip_pg_orderby($order, $select) { |
| 596 | 608 | $res = array(); |
| 597 | 609 | $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order)); |
@@ -766,6 +778,9 @@ discard block |
||
| 766 | 778 | } |
| 767 | 779 | |
| 768 | 780 | // https://code.spip.net/@calculer_pg_where |
| 781 | +/** |
|
| 782 | + * @param string $v |
|
| 783 | + */ |
|
| 769 | 784 | function calculer_pg_where($v) { |
| 770 | 785 | if (!is_array($v)) { |
| 771 | 786 | return spip_pg_frommysql($v); |
@@ -791,6 +806,9 @@ discard block |
||
| 791 | 806 | |
| 792 | 807 | |
| 793 | 808 | // https://code.spip.net/@calculer_pg_expression |
| 809 | +/** |
|
| 810 | + * @param string $expression |
|
| 811 | + */ |
|
| 794 | 812 | function calculer_pg_expression($expression, $v, $join = 'AND') { |
| 795 | 813 | if (empty($v)) { |
| 796 | 814 | return ''; |
@@ -842,6 +860,9 @@ discard block |
||
| 842 | 860 | } |
| 843 | 861 | |
| 844 | 862 | // https://code.spip.net/@spip_pg_fetch |
| 863 | +/** |
|
| 864 | + * @param resource $res |
|
| 865 | + */ |
|
| 845 | 866 | function spip_pg_fetch($res, $t = '', $serveur = '', $requeter = true) { |
| 846 | 867 | |
| 847 | 868 | if ($res) { |
@@ -913,6 +934,10 @@ discard block |
||
| 913 | 934 | } |
| 914 | 935 | |
| 915 | 936 | // https://code.spip.net/@spip_pg_insert |
| 937 | +/** |
|
| 938 | + * @param string $champs |
|
| 939 | + * @param string $valeurs |
|
| 940 | + */ |
|
| 916 | 941 | function spip_pg_insert($table, $champs, $valeurs, $desc = array(), $serveur = '', $requeter = true) { |
| 917 | 942 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 918 | 943 | $prefixe = $connexion['prefixe']; |
@@ -1149,6 +1174,9 @@ discard block |
||
| 1149 | 1174 | // Pas extensible pour le moment, |
| 1150 | 1175 | |
| 1151 | 1176 | // https://code.spip.net/@spip_pg_sequence |
| 1177 | +/** |
|
| 1178 | + * @return string |
|
| 1179 | + */ |
|
| 1152 | 1180 | function spip_pg_sequence($table, $raw = false) { |
| 1153 | 1181 | |
| 1154 | 1182 | include_spip('base/serial'); |
@@ -1312,7 +1340,7 @@ discard block |
||
| 1312 | 1340 | * @param bool $requeter |
| 1313 | 1341 | * true pour éxecuter la requête |
| 1314 | 1342 | * false pour retourner le texte de la requête. |
| 1315 | - * @return ressource |
|
| 1343 | + * @return resource |
|
| 1316 | 1344 | * Ressource à utiliser avec sql_fetch() |
| 1317 | 1345 | **/ |
| 1318 | 1346 | function spip_pg_showbase($match, $serveur = '', $requeter = true) { |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | define('_DEFAULT_DB', 'spip'); |
@@ -32,128 +32,128 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | // https://code.spip.net/@req_pg_dist |
| 34 | 34 | function req_pg_dist($addr, $port, $login, $pass, $db = '', $prefixe = '') { |
| 35 | - static $last_connect = array(); |
|
| 36 | - if (!extension_loaded('pgsql')) { |
|
| 37 | - return false; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // si provient de selectdb |
|
| 41 | - if (empty($addr) && empty($port) && empty($login) && empty($pass)) { |
|
| 42 | - foreach (array('addr', 'port', 'login', 'pass', 'prefixe') as $a) { |
|
| 43 | - $$a = $last_connect[$a]; |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - @list($host, $p) = explode(';', $addr); |
|
| 47 | - if ($p > 0) { |
|
| 48 | - $port = " port=$p"; |
|
| 49 | - } else { |
|
| 50 | - $port = ''; |
|
| 51 | - } |
|
| 52 | - $erreurs = array(); |
|
| 53 | - if ($db) { |
|
| 54 | - @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 55 | - } elseif (!@$link = pg_connect("host=$host$port user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 56 | - $erreurs[] = pg_last_error(); |
|
| 57 | - if (@$link = pg_connect("host=$host$port dbname=$login user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 58 | - $db = $login; |
|
| 59 | - } else { |
|
| 60 | - $erreurs[] = pg_last_error(); |
|
| 61 | - $db = _DEFAULT_DB; |
|
| 62 | - $link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - if (!$link) { |
|
| 66 | - $erreurs[] = pg_last_error(); |
|
| 67 | - foreach ($erreurs as $e) { |
|
| 68 | - spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - return false; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if ($link) { |
|
| 75 | - $last_connect = array( |
|
| 76 | - 'addr' => $addr, |
|
| 77 | - 'port' => $port, |
|
| 78 | - 'login' => $login, |
|
| 79 | - 'pass' => $pass, |
|
| 80 | - 'db' => $db, |
|
| 81 | - 'prefixe' => $prefixe, |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'), |
|
| 86 | - 'pg.' . _LOG_DEBUG); |
|
| 87 | - |
|
| 88 | - return !$link ? false : array( |
|
| 89 | - 'db' => $db, |
|
| 90 | - 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 91 | - 'link' => $link, |
|
| 92 | - ); |
|
| 35 | + static $last_connect = array(); |
|
| 36 | + if (!extension_loaded('pgsql')) { |
|
| 37 | + return false; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // si provient de selectdb |
|
| 41 | + if (empty($addr) && empty($port) && empty($login) && empty($pass)) { |
|
| 42 | + foreach (array('addr', 'port', 'login', 'pass', 'prefixe') as $a) { |
|
| 43 | + $$a = $last_connect[$a]; |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + @list($host, $p) = explode(';', $addr); |
|
| 47 | + if ($p > 0) { |
|
| 48 | + $port = " port=$p"; |
|
| 49 | + } else { |
|
| 50 | + $port = ''; |
|
| 51 | + } |
|
| 52 | + $erreurs = array(); |
|
| 53 | + if ($db) { |
|
| 54 | + @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 55 | + } elseif (!@$link = pg_connect("host=$host$port user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 56 | + $erreurs[] = pg_last_error(); |
|
| 57 | + if (@$link = pg_connect("host=$host$port dbname=$login user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) { |
|
| 58 | + $db = $login; |
|
| 59 | + } else { |
|
| 60 | + $erreurs[] = pg_last_error(); |
|
| 61 | + $db = _DEFAULT_DB; |
|
| 62 | + $link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + if (!$link) { |
|
| 66 | + $erreurs[] = pg_last_error(); |
|
| 67 | + foreach ($erreurs as $e) { |
|
| 68 | + spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if ($link) { |
|
| 75 | + $last_connect = array( |
|
| 76 | + 'addr' => $addr, |
|
| 77 | + 'port' => $port, |
|
| 78 | + 'login' => $login, |
|
| 79 | + 'pass' => $pass, |
|
| 80 | + 'db' => $db, |
|
| 81 | + 'prefixe' => $prefixe, |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'), |
|
| 86 | + 'pg.' . _LOG_DEBUG); |
|
| 87 | + |
|
| 88 | + return !$link ? false : array( |
|
| 89 | + 'db' => $db, |
|
| 90 | + 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 91 | + 'link' => $link, |
|
| 92 | + ); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $GLOBALS['spip_pg_functions_1'] = array( |
| 96 | - 'alter' => 'spip_pg_alter', |
|
| 97 | - 'count' => 'spip_pg_count', |
|
| 98 | - 'countsel' => 'spip_pg_countsel', |
|
| 99 | - 'create' => 'spip_pg_create', |
|
| 100 | - 'create_base' => 'spip_pg_create_base', |
|
| 101 | - 'create_view' => 'spip_pg_create_view', |
|
| 102 | - 'date_proche' => 'spip_pg_date_proche', |
|
| 103 | - 'delete' => 'spip_pg_delete', |
|
| 104 | - 'drop_table' => 'spip_pg_drop_table', |
|
| 105 | - 'drop_view' => 'spip_pg_drop_view', |
|
| 106 | - 'errno' => 'spip_pg_errno', |
|
| 107 | - 'error' => 'spip_pg_error', |
|
| 108 | - 'explain' => 'spip_pg_explain', |
|
| 109 | - 'fetch' => 'spip_pg_fetch', |
|
| 110 | - 'seek' => 'spip_pg_seek', |
|
| 111 | - 'free' => 'spip_pg_free', |
|
| 112 | - 'hex' => 'spip_pg_hex', |
|
| 113 | - 'in' => 'spip_pg_in', |
|
| 114 | - 'insert' => 'spip_pg_insert', |
|
| 115 | - 'insertq' => 'spip_pg_insertq', |
|
| 116 | - 'insertq_multi' => 'spip_pg_insertq_multi', |
|
| 117 | - 'listdbs' => 'spip_pg_listdbs', |
|
| 118 | - 'multi' => 'spip_pg_multi', |
|
| 119 | - 'optimize' => 'spip_pg_optimize', |
|
| 120 | - 'query' => 'spip_pg_query', |
|
| 121 | - 'quote' => 'spip_pg_quote', |
|
| 122 | - 'replace' => 'spip_pg_replace', |
|
| 123 | - 'replace_multi' => 'spip_pg_replace_multi', |
|
| 124 | - 'select' => 'spip_pg_select', |
|
| 125 | - 'selectdb' => 'spip_pg_selectdb', |
|
| 126 | - 'set_connect_charset' => 'spip_pg_set_connect_charset', |
|
| 127 | - 'showbase' => 'spip_pg_showbase', |
|
| 128 | - 'showtable' => 'spip_pg_showtable', |
|
| 129 | - 'update' => 'spip_pg_update', |
|
| 130 | - 'updateq' => 'spip_pg_updateq', |
|
| 96 | + 'alter' => 'spip_pg_alter', |
|
| 97 | + 'count' => 'spip_pg_count', |
|
| 98 | + 'countsel' => 'spip_pg_countsel', |
|
| 99 | + 'create' => 'spip_pg_create', |
|
| 100 | + 'create_base' => 'spip_pg_create_base', |
|
| 101 | + 'create_view' => 'spip_pg_create_view', |
|
| 102 | + 'date_proche' => 'spip_pg_date_proche', |
|
| 103 | + 'delete' => 'spip_pg_delete', |
|
| 104 | + 'drop_table' => 'spip_pg_drop_table', |
|
| 105 | + 'drop_view' => 'spip_pg_drop_view', |
|
| 106 | + 'errno' => 'spip_pg_errno', |
|
| 107 | + 'error' => 'spip_pg_error', |
|
| 108 | + 'explain' => 'spip_pg_explain', |
|
| 109 | + 'fetch' => 'spip_pg_fetch', |
|
| 110 | + 'seek' => 'spip_pg_seek', |
|
| 111 | + 'free' => 'spip_pg_free', |
|
| 112 | + 'hex' => 'spip_pg_hex', |
|
| 113 | + 'in' => 'spip_pg_in', |
|
| 114 | + 'insert' => 'spip_pg_insert', |
|
| 115 | + 'insertq' => 'spip_pg_insertq', |
|
| 116 | + 'insertq_multi' => 'spip_pg_insertq_multi', |
|
| 117 | + 'listdbs' => 'spip_pg_listdbs', |
|
| 118 | + 'multi' => 'spip_pg_multi', |
|
| 119 | + 'optimize' => 'spip_pg_optimize', |
|
| 120 | + 'query' => 'spip_pg_query', |
|
| 121 | + 'quote' => 'spip_pg_quote', |
|
| 122 | + 'replace' => 'spip_pg_replace', |
|
| 123 | + 'replace_multi' => 'spip_pg_replace_multi', |
|
| 124 | + 'select' => 'spip_pg_select', |
|
| 125 | + 'selectdb' => 'spip_pg_selectdb', |
|
| 126 | + 'set_connect_charset' => 'spip_pg_set_connect_charset', |
|
| 127 | + 'showbase' => 'spip_pg_showbase', |
|
| 128 | + 'showtable' => 'spip_pg_showtable', |
|
| 129 | + 'update' => 'spip_pg_update', |
|
| 130 | + 'updateq' => 'spip_pg_updateq', |
|
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | 133 | // Par ou ca passe une fois les traductions faites |
| 134 | 134 | // https://code.spip.net/@spip_pg_trace_query |
| 135 | 135 | function spip_pg_trace_query($query, $serveur = '') { |
| 136 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 137 | - $prefixe = $connexion['prefixe']; |
|
| 138 | - $link = $connexion['link']; |
|
| 139 | - $db = $connexion['db']; |
|
| 140 | - |
|
| 141 | - if (isset($_GET['var_profile'])) { |
|
| 142 | - include_spip('public/tracer'); |
|
| 143 | - $t = trace_query_start(); |
|
| 144 | - $e = ''; |
|
| 145 | - } else { |
|
| 146 | - $t = 0; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $connexion['last'] = $query; |
|
| 150 | - $r = spip_pg_query_simple($link, $query); |
|
| 151 | - |
|
| 152 | - // Log de l'erreur eventuelle |
|
| 153 | - if ($e = spip_pg_errno($serveur)) { |
|
| 154 | - $e .= spip_pg_error($query, $serveur); |
|
| 155 | - } // et du fautif |
|
| 156 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 136 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 137 | + $prefixe = $connexion['prefixe']; |
|
| 138 | + $link = $connexion['link']; |
|
| 139 | + $db = $connexion['db']; |
|
| 140 | + |
|
| 141 | + if (isset($_GET['var_profile'])) { |
|
| 142 | + include_spip('public/tracer'); |
|
| 143 | + $t = trace_query_start(); |
|
| 144 | + $e = ''; |
|
| 145 | + } else { |
|
| 146 | + $t = 0; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $connexion['last'] = $query; |
|
| 150 | + $r = spip_pg_query_simple($link, $query); |
|
| 151 | + |
|
| 152 | + // Log de l'erreur eventuelle |
|
| 153 | + if ($e = spip_pg_errno($serveur)) { |
|
| 154 | + $e .= spip_pg_error($query, $serveur); |
|
| 155 | + } // et du fautif |
|
| 156 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // Fonction de requete generale quand on est sur que c'est SQL standard. |
@@ -161,30 +161,30 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | // https://code.spip.net/@spip_pg_query |
| 163 | 163 | function spip_pg_query($query, $serveur = '', $requeter = true) { |
| 164 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 165 | - $prefixe = $connexion['prefixe']; |
|
| 166 | - $link = $connexion['link']; |
|
| 167 | - $db = $connexion['db']; |
|
| 168 | - |
|
| 169 | - if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 170 | - $suite = strstr($query, $regs[0]); |
|
| 171 | - $query = substr($query, 0, -strlen($suite)); |
|
| 172 | - } else { |
|
| 173 | - $suite = ''; |
|
| 174 | - } |
|
| 175 | - $query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 176 | - |
|
| 177 | - // renvoyer la requete inerte si demandee |
|
| 178 | - if (!$requeter) { |
|
| 179 | - return $query; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return spip_pg_trace_query($query, $serveur); |
|
| 164 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 165 | + $prefixe = $connexion['prefixe']; |
|
| 166 | + $link = $connexion['link']; |
|
| 167 | + $db = $connexion['db']; |
|
| 168 | + |
|
| 169 | + if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 170 | + $suite = strstr($query, $regs[0]); |
|
| 171 | + $query = substr($query, 0, -strlen($suite)); |
|
| 172 | + } else { |
|
| 173 | + $suite = ''; |
|
| 174 | + } |
|
| 175 | + $query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 176 | + |
|
| 177 | + // renvoyer la requete inerte si demandee |
|
| 178 | + if (!$requeter) { |
|
| 179 | + return $query; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return spip_pg_trace_query($query, $serveur); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function spip_pg_query_simple($link, $query) { |
| 186 | - #spip_log(var_export($query,true), 'pg.'._LOG_DEBUG); |
|
| 187 | - return pg_query($link, $query); |
|
| 186 | + #spip_log(var_export($query,true), 'pg.'._LOG_DEBUG); |
|
| 187 | + return pg_query($link, $query); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /* |
@@ -196,198 +196,198 @@ discard block |
||
| 196 | 196 | * de requetes showtable intempestives |
| 197 | 197 | */ |
| 198 | 198 | function spip_pg_ajouter_champs_timestamp($table, $couples, $desc = '', $serveur = '') { |
| 199 | - static $tables = array(); |
|
| 200 | - |
|
| 201 | - if (!isset($tables[$table])) { |
|
| 202 | - |
|
| 203 | - if (!$desc) { |
|
| 204 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 205 | - $desc = $trouver_table($table, $serveur); |
|
| 206 | - // si pas de description, on ne fait rien, ou on die() ? |
|
| 207 | - if (!$desc) { |
|
| 208 | - return $couples; |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // recherche des champs avec simplement 'TIMESTAMP' |
|
| 213 | - // cependant, il faudra peut etre etendre |
|
| 214 | - // avec la gestion de DEFAULT et ON UPDATE |
|
| 215 | - // mais ceux-ci ne sont pas utilises dans le core |
|
| 216 | - $tables[$table] = array(); |
|
| 217 | - foreach ($desc['field'] as $k => $v) { |
|
| 218 | - $v = strtolower(ltrim($v)); |
|
| 219 | - // ne pas ajouter de timestamp now() si un default est specifie |
|
| 220 | - if (strpos($v, 'timestamp') === 0 and strpos($v, 'default') === false) { |
|
| 221 | - $tables[$table][] = $k; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // ajout des champs type 'timestamp' absents |
|
| 227 | - foreach ($tables[$table] as $maj) { |
|
| 228 | - if (!array_key_exists($maj, $couples)) { |
|
| 229 | - $couples[$maj] = "NOW()"; |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return $couples; |
|
| 199 | + static $tables = array(); |
|
| 200 | + |
|
| 201 | + if (!isset($tables[$table])) { |
|
| 202 | + |
|
| 203 | + if (!$desc) { |
|
| 204 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 205 | + $desc = $trouver_table($table, $serveur); |
|
| 206 | + // si pas de description, on ne fait rien, ou on die() ? |
|
| 207 | + if (!$desc) { |
|
| 208 | + return $couples; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // recherche des champs avec simplement 'TIMESTAMP' |
|
| 213 | + // cependant, il faudra peut etre etendre |
|
| 214 | + // avec la gestion de DEFAULT et ON UPDATE |
|
| 215 | + // mais ceux-ci ne sont pas utilises dans le core |
|
| 216 | + $tables[$table] = array(); |
|
| 217 | + foreach ($desc['field'] as $k => $v) { |
|
| 218 | + $v = strtolower(ltrim($v)); |
|
| 219 | + // ne pas ajouter de timestamp now() si un default est specifie |
|
| 220 | + if (strpos($v, 'timestamp') === 0 and strpos($v, 'default') === false) { |
|
| 221 | + $tables[$table][] = $k; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // ajout des champs type 'timestamp' absents |
|
| 227 | + foreach ($tables[$table] as $maj) { |
|
| 228 | + if (!array_key_exists($maj, $couples)) { |
|
| 229 | + $couples[$maj] = "NOW()"; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return $couples; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | // Alter en PG ne traite pas les index |
| 238 | 238 | // https://code.spip.net/@spip_pg_alter |
| 239 | 239 | function spip_pg_alter($query, $serveur = '', $requeter = true) { |
| 240 | - // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
|
| 241 | - // tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... |
|
| 242 | - // ou revoir l'api de sql_alter en creant un |
|
| 243 | - // sql_alter_table($table,array($actions)); |
|
| 244 | - if (!preg_match("/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is", $query, $regs)) { |
|
| 245 | - spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR); |
|
| 246 | - |
|
| 247 | - return false; |
|
| 248 | - } |
|
| 249 | - $debut = $regs[1]; |
|
| 250 | - $table = $regs[3]; |
|
| 251 | - $suite = $regs[4]; |
|
| 252 | - $todo = explode(',', $suite); |
|
| 253 | - // on remet les morceaux dechires ensembles... que c'est laid ! |
|
| 254 | - $todo2 = array(); |
|
| 255 | - $i = 0; |
|
| 256 | - $ouverte = false; |
|
| 257 | - while ($do = array_shift($todo)) { |
|
| 258 | - $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . "," . $do : $do; |
|
| 259 | - $o = (false !== strpos($do, "(")); |
|
| 260 | - $f = (false !== strpos($do, ")")); |
|
| 261 | - if ($o and !$f) { |
|
| 262 | - $ouverte = true; |
|
| 263 | - } elseif ($f) { |
|
| 264 | - $ouverte = false; |
|
| 265 | - } |
|
| 266 | - if (!$ouverte) { |
|
| 267 | - $i++; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - $todo = $todo2; |
|
| 271 | - $query = $debut . ' ' . array_shift($todo); |
|
| 272 | - |
|
| 273 | - if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
|
| 274 | - spip_log("$query incompris", 'pg.' . _LOG_ERREUR); |
|
| 275 | - } else { |
|
| 276 | - if ($r[1]) { |
|
| 277 | - spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 278 | - } |
|
| 279 | - $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 280 | - if (function_exists($f)) { |
|
| 281 | - $f($r[2], $r[4], $serveur, $requeter); |
|
| 282 | - } else { |
|
| 283 | - spip_log("$query non prevu", 'pg.' . _LOG_ERREUR); |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - // Alter a plusieurs args. Faudrait optimiser. |
|
| 287 | - if ($todo) { |
|
| 288 | - spip_pg_alter("TABLE $table " . join(',', $todo)); |
|
| 289 | - } |
|
| 240 | + // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB) |
|
| 241 | + // tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"... |
|
| 242 | + // ou revoir l'api de sql_alter en creant un |
|
| 243 | + // sql_alter_table($table,array($actions)); |
|
| 244 | + if (!preg_match("/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is", $query, $regs)) { |
|
| 245 | + spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR); |
|
| 246 | + |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | + $debut = $regs[1]; |
|
| 250 | + $table = $regs[3]; |
|
| 251 | + $suite = $regs[4]; |
|
| 252 | + $todo = explode(',', $suite); |
|
| 253 | + // on remet les morceaux dechires ensembles... que c'est laid ! |
|
| 254 | + $todo2 = array(); |
|
| 255 | + $i = 0; |
|
| 256 | + $ouverte = false; |
|
| 257 | + while ($do = array_shift($todo)) { |
|
| 258 | + $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . "," . $do : $do; |
|
| 259 | + $o = (false !== strpos($do, "(")); |
|
| 260 | + $f = (false !== strpos($do, ")")); |
|
| 261 | + if ($o and !$f) { |
|
| 262 | + $ouverte = true; |
|
| 263 | + } elseif ($f) { |
|
| 264 | + $ouverte = false; |
|
| 265 | + } |
|
| 266 | + if (!$ouverte) { |
|
| 267 | + $i++; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + $todo = $todo2; |
|
| 271 | + $query = $debut . ' ' . array_shift($todo); |
|
| 272 | + |
|
| 273 | + if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
|
| 274 | + spip_log("$query incompris", 'pg.' . _LOG_ERREUR); |
|
| 275 | + } else { |
|
| 276 | + if ($r[1]) { |
|
| 277 | + spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 278 | + } |
|
| 279 | + $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 280 | + if (function_exists($f)) { |
|
| 281 | + $f($r[2], $r[4], $serveur, $requeter); |
|
| 282 | + } else { |
|
| 283 | + spip_log("$query non prevu", 'pg.' . _LOG_ERREUR); |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + // Alter a plusieurs args. Faudrait optimiser. |
|
| 287 | + if ($todo) { |
|
| 288 | + spip_pg_alter("TABLE $table " . join(',', $todo)); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | // https://code.spip.net/@spip_pg_alter_change |
| 294 | 294 | function spip_pg_alter_change($table, $arg, $serveur = '', $requeter = true) { |
| 295 | - if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) { |
|
| 296 | - spip_log("alter change: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 297 | - } else { |
|
| 298 | - list(, $old, $new, $type, $default, $null, $def2) = $r; |
|
| 299 | - $actions = array("ALTER $old TYPE " . mysql2pg_type($type)); |
|
| 300 | - if ($null) { |
|
| 301 | - $actions[] = "ALTER $old SET NOT NULL"; |
|
| 302 | - } else { |
|
| 303 | - $actions[] = "ALTER $old DROP NOT NULL"; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - if ($d = ($default ? $default : $def2)) { |
|
| 307 | - $actions[] = "ALTER $old SET $d"; |
|
| 308 | - } else { |
|
| 309 | - $actions[] = "ALTER $old DROP DEFAULT"; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - spip_pg_query("ALTER TABLE $table " . join(', ', $actions)); |
|
| 313 | - |
|
| 314 | - if ($old != $new) { |
|
| 315 | - spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
|
| 316 | - } |
|
| 317 | - } |
|
| 295 | + if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) { |
|
| 296 | + spip_log("alter change: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 297 | + } else { |
|
| 298 | + list(, $old, $new, $type, $default, $null, $def2) = $r; |
|
| 299 | + $actions = array("ALTER $old TYPE " . mysql2pg_type($type)); |
|
| 300 | + if ($null) { |
|
| 301 | + $actions[] = "ALTER $old SET NOT NULL"; |
|
| 302 | + } else { |
|
| 303 | + $actions[] = "ALTER $old DROP NOT NULL"; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + if ($d = ($default ? $default : $def2)) { |
|
| 307 | + $actions[] = "ALTER $old SET $d"; |
|
| 308 | + } else { |
|
| 309 | + $actions[] = "ALTER $old DROP DEFAULT"; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + spip_pg_query("ALTER TABLE $table " . join(', ', $actions)); |
|
| 313 | + |
|
| 314 | + if ($old != $new) { |
|
| 315 | + spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | // https://code.spip.net/@spip_pg_alter_add |
| 321 | 321 | function spip_pg_alter_add($table, $arg, $serveur = '', $requeter = true) { |
| 322 | - if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
|
| 323 | - spip_log("alter add $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 324 | - |
|
| 325 | - return null; |
|
| 326 | - } |
|
| 327 | - if (!$r[1] or $r[1] == 'COLUMN') { |
|
| 328 | - preg_match('/`?(\w+)`?(.*)/', $r[2], $m); |
|
| 329 | - if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) { |
|
| 330 | - $m[2] = $n[1]; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 334 | - } elseif ($r[1][0] == 'P') { |
|
| 335 | - // la primary peut etre sur plusieurs champs |
|
| 336 | - $r[2] = trim(str_replace('`', '', $r[2])); |
|
| 337 | - $m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2]; |
|
| 338 | - |
|
| 339 | - return spip_pg_query("ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')', $serveur, |
|
| 340 | - $requeter); |
|
| 341 | - } else { |
|
| 342 | - preg_match('/([^\s,]*)\s*(.*)?/', $r[2], $m); |
|
| 343 | - // peut etre "(colonne)" ou "nom_index (colonnes)" |
|
| 344 | - // bug potentiel si qqn met "(colonne, colonne)" |
|
| 345 | - // |
|
| 346 | - // nom_index (colonnes) |
|
| 347 | - if ($m[2]) { |
|
| 348 | - $colonnes = substr($m[2], 1, -1); |
|
| 349 | - $nom_index = $m[1]; |
|
| 350 | - } else { |
|
| 351 | - // (colonne) |
|
| 352 | - if ($m[1][0] == "(") { |
|
| 353 | - $colonnes = substr($m[1], 1, -1); |
|
| 354 | - if (false !== strpos(",", $colonnes)) { |
|
| 355 | - spip_log("PG : Erreur, impossible de creer un index sur plusieurs colonnes" |
|
| 356 | - . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR); |
|
| 357 | - } else { |
|
| 358 | - $nom_index = $colonnes; |
|
| 359 | - } |
|
| 360 | - } // nom_index |
|
| 361 | - else { |
|
| 362 | - $nom_index = $colonnes = $m[1]; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - return spip_pg_create_index($nom_index, $table, $colonnes, $serveur, $requeter); |
|
| 367 | - } |
|
| 322 | + if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
|
| 323 | + spip_log("alter add $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 324 | + |
|
| 325 | + return null; |
|
| 326 | + } |
|
| 327 | + if (!$r[1] or $r[1] == 'COLUMN') { |
|
| 328 | + preg_match('/`?(\w+)`?(.*)/', $r[2], $m); |
|
| 329 | + if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) { |
|
| 330 | + $m[2] = $n[1]; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 334 | + } elseif ($r[1][0] == 'P') { |
|
| 335 | + // la primary peut etre sur plusieurs champs |
|
| 336 | + $r[2] = trim(str_replace('`', '', $r[2])); |
|
| 337 | + $m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2]; |
|
| 338 | + |
|
| 339 | + return spip_pg_query("ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')', $serveur, |
|
| 340 | + $requeter); |
|
| 341 | + } else { |
|
| 342 | + preg_match('/([^\s,]*)\s*(.*)?/', $r[2], $m); |
|
| 343 | + // peut etre "(colonne)" ou "nom_index (colonnes)" |
|
| 344 | + // bug potentiel si qqn met "(colonne, colonne)" |
|
| 345 | + // |
|
| 346 | + // nom_index (colonnes) |
|
| 347 | + if ($m[2]) { |
|
| 348 | + $colonnes = substr($m[2], 1, -1); |
|
| 349 | + $nom_index = $m[1]; |
|
| 350 | + } else { |
|
| 351 | + // (colonne) |
|
| 352 | + if ($m[1][0] == "(") { |
|
| 353 | + $colonnes = substr($m[1], 1, -1); |
|
| 354 | + if (false !== strpos(",", $colonnes)) { |
|
| 355 | + spip_log("PG : Erreur, impossible de creer un index sur plusieurs colonnes" |
|
| 356 | + . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR); |
|
| 357 | + } else { |
|
| 358 | + $nom_index = $colonnes; |
|
| 359 | + } |
|
| 360 | + } // nom_index |
|
| 361 | + else { |
|
| 362 | + $nom_index = $colonnes = $m[1]; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + return spip_pg_create_index($nom_index, $table, $colonnes, $serveur, $requeter); |
|
| 367 | + } |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | // https://code.spip.net/@spip_pg_alter_drop |
| 371 | 371 | function spip_pg_alter_drop($table, $arg, $serveur = '', $requeter = true) { |
| 372 | - if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 373 | - spip_log("alter drop: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 374 | - } else { |
|
| 375 | - if (!$r[1] or $r[1] == 'COLUMN') { |
|
| 376 | - return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 377 | - } elseif ($r[1][0] == 'P') { |
|
| 378 | - return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 379 | - } else { |
|
| 380 | - return spip_pg_query("DROP INDEX " . $table . '_' . $r[2], $serveur); |
|
| 381 | - } |
|
| 382 | - } |
|
| 372 | + if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 373 | + spip_log("alter drop: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 374 | + } else { |
|
| 375 | + if (!$r[1] or $r[1] == 'COLUMN') { |
|
| 376 | + return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 377 | + } elseif ($r[1][0] == 'P') { |
|
| 378 | + return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 379 | + } else { |
|
| 380 | + return spip_pg_query("DROP INDEX " . $table . '_' . $r[2], $serveur); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | function spip_pg_alter_modify($table, $arg, $serveur = '', $requeter = true) { |
| 386 | - if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) { |
|
| 387 | - spip_log("alter modify: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 388 | - } else { |
|
| 389 | - return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true); |
|
| 390 | - } |
|
| 386 | + if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) { |
|
| 387 | + spip_log("alter modify: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 388 | + } else { |
|
| 389 | + return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true); |
|
| 390 | + } |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | // attention (en pg) : |
@@ -395,17 +395,17 @@ discard block |
||
| 395 | 395 | // - alter table A rename X to Y = changer le nom de la colonne X en Y |
| 396 | 396 | // pour l'instant, traiter simplement RENAME TO X |
| 397 | 397 | function spip_pg_alter_rename($table, $arg, $serveur = '', $requeter = true) { |
| 398 | - $rename = ""; |
|
| 399 | - // si TO, mais pas au debut |
|
| 400 | - if (!stripos($arg, 'TO ')) { |
|
| 401 | - $rename = $arg; |
|
| 402 | - } elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 403 | - $rename = $r[2]; |
|
| 404 | - } else { |
|
| 405 | - spip_log("alter rename: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false; |
|
| 398 | + $rename = ""; |
|
| 399 | + // si TO, mais pas au debut |
|
| 400 | + if (!stripos($arg, 'TO ')) { |
|
| 401 | + $rename = $arg; |
|
| 402 | + } elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
|
| 403 | + $rename = $r[2]; |
|
| 404 | + } else { |
|
| 405 | + spip_log("alter rename: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false; |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -421,58 +421,58 @@ discard block |
||
| 421 | 421 | * @return bool ou requete |
| 422 | 422 | */ |
| 423 | 423 | function spip_pg_create_index($nom, $table, $champs, $serveur = '', $requeter = true) { |
| 424 | - if (!($nom or $table or $champs)) { |
|
| 425 | - spip_log("Champ manquant pour creer un index pg ($nom, $table, (" . @join(',', $champs) . "))", |
|
| 426 | - 'pg.' . _LOG_ERREUR); |
|
| 427 | - |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - $nom = str_replace("`", "", $nom); |
|
| 432 | - $champs = str_replace("`", "", $champs); |
|
| 433 | - |
|
| 434 | - // PG ne differentie pas noms des index en fonction des tables |
|
| 435 | - // il faut donc creer des noms uniques d'index pour une base pg |
|
| 436 | - $nom = $table . '_' . $nom; |
|
| 437 | - // enlever d'eventuelles parentheses deja presentes sur champs |
|
| 438 | - if (!is_array($champs)) { |
|
| 439 | - if ($champs[0] == "(") { |
|
| 440 | - $champs = substr($champs, 1, -1); |
|
| 441 | - } |
|
| 442 | - $champs = array($champs); |
|
| 443 | - } |
|
| 444 | - $query = "CREATE INDEX $nom ON $table (" . join(',', $champs) . ")"; |
|
| 445 | - if (!$requeter) { |
|
| 446 | - return $query; |
|
| 447 | - } |
|
| 448 | - $res = spip_pg_query($query, $serveur, $requeter); |
|
| 449 | - |
|
| 450 | - return $res; |
|
| 424 | + if (!($nom or $table or $champs)) { |
|
| 425 | + spip_log("Champ manquant pour creer un index pg ($nom, $table, (" . @join(',', $champs) . "))", |
|
| 426 | + 'pg.' . _LOG_ERREUR); |
|
| 427 | + |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + $nom = str_replace("`", "", $nom); |
|
| 432 | + $champs = str_replace("`", "", $champs); |
|
| 433 | + |
|
| 434 | + // PG ne differentie pas noms des index en fonction des tables |
|
| 435 | + // il faut donc creer des noms uniques d'index pour une base pg |
|
| 436 | + $nom = $table . '_' . $nom; |
|
| 437 | + // enlever d'eventuelles parentheses deja presentes sur champs |
|
| 438 | + if (!is_array($champs)) { |
|
| 439 | + if ($champs[0] == "(") { |
|
| 440 | + $champs = substr($champs, 1, -1); |
|
| 441 | + } |
|
| 442 | + $champs = array($champs); |
|
| 443 | + } |
|
| 444 | + $query = "CREATE INDEX $nom ON $table (" . join(',', $champs) . ")"; |
|
| 445 | + if (!$requeter) { |
|
| 446 | + return $query; |
|
| 447 | + } |
|
| 448 | + $res = spip_pg_query($query, $serveur, $requeter); |
|
| 449 | + |
|
| 450 | + return $res; |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | |
| 454 | 454 | // https://code.spip.net/@spip_pg_explain |
| 455 | 455 | function spip_pg_explain($query, $serveur = '', $requeter = true) { |
| 456 | - if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 457 | - return array(); |
|
| 458 | - } |
|
| 459 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 460 | - $prefixe = $connexion['prefixe']; |
|
| 461 | - $link = $connexion['link']; |
|
| 462 | - if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) { |
|
| 463 | - $suite = strstr($query, $regs[0]); |
|
| 464 | - $query = substr($query, 0, -strlen($suite)); |
|
| 465 | - } else { |
|
| 466 | - $suite = ''; |
|
| 467 | - } |
|
| 468 | - $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 469 | - |
|
| 470 | - if (!$requeter) { |
|
| 471 | - return $query; |
|
| 472 | - } |
|
| 473 | - $r = spip_pg_query_simple($link, $query); |
|
| 474 | - |
|
| 475 | - return spip_pg_fetch($r, null, $serveur); |
|
| 456 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 457 | + return array(); |
|
| 458 | + } |
|
| 459 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 460 | + $prefixe = $connexion['prefixe']; |
|
| 461 | + $link = $connexion['link']; |
|
| 462 | + if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) { |
|
| 463 | + $suite = strstr($query, $regs[0]); |
|
| 464 | + $query = substr($query, 0, -strlen($suite)); |
|
| 465 | + } else { |
|
| 466 | + $suite = ''; |
|
| 467 | + } |
|
| 468 | + $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 469 | + |
|
| 470 | + if (!$requeter) { |
|
| 471 | + return $query; |
|
| 472 | + } |
|
| 473 | + $r = spip_pg_query_simple($link, $query); |
|
| 474 | + |
|
| 475 | + return spip_pg_fetch($r, null, $serveur); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | |
@@ -491,92 +491,92 @@ discard block |
||
| 491 | 491 | * - False en cas d'erreur. |
| 492 | 492 | **/ |
| 493 | 493 | function spip_pg_selectdb($db, $serveur = '', $requeter = true) { |
| 494 | - // se connecter a la base indiquee |
|
| 495 | - // avec les identifiants connus |
|
| 496 | - $index = $serveur ? strtolower($serveur) : 0; |
|
| 497 | - |
|
| 498 | - if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')) { |
|
| 499 | - if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) { |
|
| 500 | - return $db; |
|
| 501 | - } |
|
| 502 | - } else { |
|
| 503 | - return false; |
|
| 504 | - } |
|
| 494 | + // se connecter a la base indiquee |
|
| 495 | + // avec les identifiants connus |
|
| 496 | + $index = $serveur ? strtolower($serveur) : 0; |
|
| 497 | + |
|
| 498 | + if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')) { |
|
| 499 | + if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) { |
|
| 500 | + return $db; |
|
| 501 | + } |
|
| 502 | + } else { |
|
| 503 | + return false; |
|
| 504 | + } |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | // Qu'une seule base pour le moment |
| 508 | 508 | |
| 509 | 509 | // https://code.spip.net/@spip_pg_listdbs |
| 510 | 510 | function spip_pg_listdbs($serveur) { |
| 511 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 512 | - $link = $connexion['link']; |
|
| 513 | - $dbs = array(); |
|
| 514 | - $res = spip_pg_query_simple($link, "select * From pg_database"); |
|
| 515 | - while ($row = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 516 | - $dbs[] = reset($row); |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - return $dbs; |
|
| 511 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 512 | + $link = $connexion['link']; |
|
| 513 | + $dbs = array(); |
|
| 514 | + $res = spip_pg_query_simple($link, "select * From pg_database"); |
|
| 515 | + while ($row = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 516 | + $dbs[] = reset($row); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + return $dbs; |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | // https://code.spip.net/@spip_pg_select |
| 523 | 523 | function spip_pg_select( |
| 524 | - $select, |
|
| 525 | - $from, |
|
| 526 | - $where = '', |
|
| 527 | - $groupby = array(), |
|
| 528 | - $orderby = '', |
|
| 529 | - $limit = '', |
|
| 530 | - $having = '', |
|
| 531 | - $serveur = '', |
|
| 532 | - $requeter = true |
|
| 524 | + $select, |
|
| 525 | + $from, |
|
| 526 | + $where = '', |
|
| 527 | + $groupby = array(), |
|
| 528 | + $orderby = '', |
|
| 529 | + $limit = '', |
|
| 530 | + $having = '', |
|
| 531 | + $serveur = '', |
|
| 532 | + $requeter = true |
|
| 533 | 533 | ) { |
| 534 | 534 | |
| 535 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 536 | - $prefixe = $connexion['prefixe']; |
|
| 537 | - $link = $connexion['link']; |
|
| 538 | - $db = $connexion['db']; |
|
| 539 | - |
|
| 540 | - $limit = preg_match("/^\s*(([0-9]+),)?\s*([0-9]+)\s*$/", $limit, $limatch); |
|
| 541 | - if ($limit) { |
|
| 542 | - $offset = $limatch[2]; |
|
| 543 | - $count = $limatch[3]; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - $select = spip_pg_frommysql($select); |
|
| 547 | - |
|
| 548 | - // si pas de tri explicitement demande, le GROUP BY ne |
|
| 549 | - // contient que la clef primaire. |
|
| 550 | - // lui ajouter alors le champ de tri par defaut |
|
| 551 | - if (preg_match("/FIELD\(([a-z]+\.[a-z]+),/i", $orderby[0], $groupbyplus)) { |
|
| 552 | - $groupby[] = $groupbyplus[1]; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - $orderby = spip_pg_orderby($orderby, $select); |
|
| 556 | - |
|
| 557 | - if ($having) { |
|
| 558 | - if (is_array($having)) { |
|
| 559 | - $having = join("\n\tAND ", array_map('calculer_pg_where', $having)); |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - $from = spip_pg_from($from, $prefixe); |
|
| 563 | - $query = "SELECT " . $select |
|
| 564 | - . (!$from ? '' : "\nFROM $from") |
|
| 565 | - . (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join("\n\tAND ", |
|
| 566 | - array_map('calculer_pg_where', $where)))))) |
|
| 567 | - . spip_pg_groupby($groupby, $from, $select) |
|
| 568 | - . (!$having ? '' : "\nHAVING $having") |
|
| 569 | - . ($orderby ? ("\nORDER BY $orderby") : '') |
|
| 570 | - . (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset"))); |
|
| 571 | - |
|
| 572 | - // renvoyer la requete inerte si demandee |
|
| 573 | - if ($requeter === false) { |
|
| 574 | - return $query; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - $r = spip_pg_trace_query($query, $serveur); |
|
| 578 | - |
|
| 579 | - return $r ? $r : $query;; |
|
| 535 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 536 | + $prefixe = $connexion['prefixe']; |
|
| 537 | + $link = $connexion['link']; |
|
| 538 | + $db = $connexion['db']; |
|
| 539 | + |
|
| 540 | + $limit = preg_match("/^\s*(([0-9]+),)?\s*([0-9]+)\s*$/", $limit, $limatch); |
|
| 541 | + if ($limit) { |
|
| 542 | + $offset = $limatch[2]; |
|
| 543 | + $count = $limatch[3]; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + $select = spip_pg_frommysql($select); |
|
| 547 | + |
|
| 548 | + // si pas de tri explicitement demande, le GROUP BY ne |
|
| 549 | + // contient que la clef primaire. |
|
| 550 | + // lui ajouter alors le champ de tri par defaut |
|
| 551 | + if (preg_match("/FIELD\(([a-z]+\.[a-z]+),/i", $orderby[0], $groupbyplus)) { |
|
| 552 | + $groupby[] = $groupbyplus[1]; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + $orderby = spip_pg_orderby($orderby, $select); |
|
| 556 | + |
|
| 557 | + if ($having) { |
|
| 558 | + if (is_array($having)) { |
|
| 559 | + $having = join("\n\tAND ", array_map('calculer_pg_where', $having)); |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + $from = spip_pg_from($from, $prefixe); |
|
| 563 | + $query = "SELECT " . $select |
|
| 564 | + . (!$from ? '' : "\nFROM $from") |
|
| 565 | + . (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join("\n\tAND ", |
|
| 566 | + array_map('calculer_pg_where', $where)))))) |
|
| 567 | + . spip_pg_groupby($groupby, $from, $select) |
|
| 568 | + . (!$having ? '' : "\nHAVING $having") |
|
| 569 | + . ($orderby ? ("\nORDER BY $orderby") : '') |
|
| 570 | + . (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset"))); |
|
| 571 | + |
|
| 572 | + // renvoyer la requete inerte si demandee |
|
| 573 | + if ($requeter === false) { |
|
| 574 | + return $query; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + $r = spip_pg_trace_query($query, $serveur); |
|
| 578 | + |
|
| 579 | + return $r ? $r : $query;; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | // Le traitement des prefixes de table dans un Select se limite au FROM |
@@ -584,28 +584,28 @@ discard block |
||
| 584 | 584 | |
| 585 | 585 | // https://code.spip.net/@spip_pg_from |
| 586 | 586 | function spip_pg_from($from, $prefixe) { |
| 587 | - if (is_array($from)) { |
|
| 588 | - $from = spip_pg_select_as($from); |
|
| 589 | - } |
|
| 587 | + if (is_array($from)) { |
|
| 588 | + $from = spip_pg_select_as($from); |
|
| 589 | + } |
|
| 590 | 590 | |
| 591 | - return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from); |
|
| 591 | + return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | // https://code.spip.net/@spip_pg_orderby |
| 595 | 595 | function spip_pg_orderby($order, $select) { |
| 596 | - $res = array(); |
|
| 597 | - $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order)); |
|
| 596 | + $res = array(); |
|
| 597 | + $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order)); |
|
| 598 | 598 | |
| 599 | - foreach ($arg as $v) { |
|
| 600 | - if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m)) { |
|
| 599 | + foreach ($arg as $v) { |
|
| 600 | + if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m)) { |
|
| 601 | 601 | |
| 602 | - $res[] = $m[1]; |
|
| 603 | - } else { |
|
| 604 | - $res[] = $v; |
|
| 605 | - } |
|
| 606 | - } |
|
| 602 | + $res[] = $m[1]; |
|
| 603 | + } else { |
|
| 604 | + $res[] = $v; |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | 607 | |
| 608 | - return spip_pg_frommysql(join(',', $res)); |
|
| 608 | + return spip_pg_frommysql(join(',', $res)); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | // Conversion a l'arrach' des jointures MySQL en jointures PG |
@@ -614,57 +614,57 @@ discard block |
||
| 614 | 614 | |
| 615 | 615 | // https://code.spip.net/@spip_pg_groupby |
| 616 | 616 | function spip_pg_groupby($groupby, $from, $select) { |
| 617 | - $join = strpos($from, ","); |
|
| 618 | - // ismplifier avant de decouper |
|
| 619 | - if (is_string($select)) // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 620 | - { |
|
| 621 | - $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $select); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - if ($join or $groupby) { |
|
| 625 | - $join = is_array($select) ? $select : explode(", ", $select); |
|
| 626 | - } |
|
| 627 | - if ($join) { |
|
| 628 | - // enlever les 0 as points, '', ... |
|
| 629 | - foreach ($join as $k => $v) { |
|
| 630 | - $v = str_replace('DISTINCT ', '', $v); |
|
| 631 | - // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 632 | - $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $v); |
|
| 633 | - $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/', '\\1', $v); |
|
| 634 | - // resultat d'agregat ne sont pas a mettre dans le groupby |
|
| 635 | - $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i', '', $v); |
|
| 636 | - // idem sans AS (fetch numerique) |
|
| 637 | - $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i', '', $v); |
|
| 638 | - // des AS simples : on garde le cote droit du AS |
|
| 639 | - $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i', '\\1', $v); |
|
| 640 | - // ne reste plus que les vrais colonnes, ou des constantes a virer |
|
| 641 | - if (preg_match(',^[\'"],', $v) or is_numeric($v)) { |
|
| 642 | - unset($join[$k]); |
|
| 643 | - } else { |
|
| 644 | - $join[$k] = trim($v); |
|
| 645 | - } |
|
| 646 | - } |
|
| 647 | - $join = array_diff($join, array('')); |
|
| 648 | - $join = implode(',', $join); |
|
| 649 | - } |
|
| 650 | - if (is_array($groupby)) { |
|
| 651 | - $groupby = join(',', $groupby); |
|
| 652 | - } |
|
| 653 | - if ($join) { |
|
| 654 | - $groupby = $groupby ? "$groupby, $join" : $join; |
|
| 655 | - } |
|
| 656 | - if (!$groupby) { |
|
| 657 | - return ''; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - $groupby = spip_pg_frommysql($groupby); |
|
| 661 | - // Ne pas mettre dans le Group-By des valeurs numeriques |
|
| 662 | - // issue de prepare_recherche |
|
| 663 | - $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i', '', $groupby); |
|
| 664 | - $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 665 | - $groupby = preg_replace('/\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 666 | - |
|
| 667 | - return "\nGROUP BY $groupby"; |
|
| 617 | + $join = strpos($from, ","); |
|
| 618 | + // ismplifier avant de decouper |
|
| 619 | + if (is_string($select)) // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 620 | + { |
|
| 621 | + $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $select); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + if ($join or $groupby) { |
|
| 625 | + $join = is_array($select) ? $select : explode(", ", $select); |
|
| 626 | + } |
|
| 627 | + if ($join) { |
|
| 628 | + // enlever les 0 as points, '', ... |
|
| 629 | + foreach ($join as $k => $v) { |
|
| 630 | + $v = str_replace('DISTINCT ', '', $v); |
|
| 631 | + // fct SQL sur colonne et constante apostrophee ==> la colonne |
|
| 632 | + $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $v); |
|
| 633 | + $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/', '\\1', $v); |
|
| 634 | + // resultat d'agregat ne sont pas a mettre dans le groupby |
|
| 635 | + $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i', '', $v); |
|
| 636 | + // idem sans AS (fetch numerique) |
|
| 637 | + $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i', '', $v); |
|
| 638 | + // des AS simples : on garde le cote droit du AS |
|
| 639 | + $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i', '\\1', $v); |
|
| 640 | + // ne reste plus que les vrais colonnes, ou des constantes a virer |
|
| 641 | + if (preg_match(',^[\'"],', $v) or is_numeric($v)) { |
|
| 642 | + unset($join[$k]); |
|
| 643 | + } else { |
|
| 644 | + $join[$k] = trim($v); |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + $join = array_diff($join, array('')); |
|
| 648 | + $join = implode(',', $join); |
|
| 649 | + } |
|
| 650 | + if (is_array($groupby)) { |
|
| 651 | + $groupby = join(',', $groupby); |
|
| 652 | + } |
|
| 653 | + if ($join) { |
|
| 654 | + $groupby = $groupby ? "$groupby, $join" : $join; |
|
| 655 | + } |
|
| 656 | + if (!$groupby) { |
|
| 657 | + return ''; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + $groupby = spip_pg_frommysql($groupby); |
|
| 661 | + // Ne pas mettre dans le Group-By des valeurs numeriques |
|
| 662 | + // issue de prepare_recherche |
|
| 663 | + $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i', '', $groupby); |
|
| 664 | + $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 665 | + $groupby = preg_replace('/\s+AS\s+\w+\s*/i', '', $groupby); |
|
| 666 | + |
|
| 667 | + return "\nGROUP BY $groupby"; |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | // Conversion des operateurs MySQL en PG |
@@ -676,472 +676,472 @@ discard block |
||
| 676 | 676 | |
| 677 | 677 | // https://code.spip.net/@spip_pg_frommysql |
| 678 | 678 | function spip_pg_frommysql($arg) { |
| 679 | - if (is_array($arg)) { |
|
| 680 | - $arg = join(", ", $arg); |
|
| 681 | - } |
|
| 679 | + if (is_array($arg)) { |
|
| 680 | + $arg = join(", ", $arg); |
|
| 681 | + } |
|
| 682 | 682 | |
| 683 | - $res = spip_pg_fromfield($arg); |
|
| 683 | + $res = spip_pg_fromfield($arg); |
|
| 684 | 684 | |
| 685 | - $res = preg_replace('/\brand[(][)]/i', 'random()', $res); |
|
| 685 | + $res = preg_replace('/\brand[(][)]/i', 'random()', $res); |
|
| 686 | 686 | |
| 687 | - $res = preg_replace('/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 688 | - 'CAST(substring(\1, \'^ *[0-9.]+\') as float)', |
|
| 689 | - $res); |
|
| 690 | - $res = preg_replace('/\b0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 691 | - 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 692 | - $res); |
|
| 693 | - $res = preg_replace('/\bconv[(]([^,]*)[^)]*[)]/i', |
|
| 694 | - 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 695 | - $res); |
|
| 687 | + $res = preg_replace('/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 688 | + 'CAST(substring(\1, \'^ *[0-9.]+\') as float)', |
|
| 689 | + $res); |
|
| 690 | + $res = preg_replace('/\b0[+]([a-zA-Z0-9_.]+)\s*/', |
|
| 691 | + 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 692 | + $res); |
|
| 693 | + $res = preg_replace('/\bconv[(]([^,]*)[^)]*[)]/i', |
|
| 694 | + 'CAST(substring(\1, \'^ *[0-9]+\') as int)', |
|
| 695 | + $res); |
|
| 696 | 696 | |
| 697 | - $res = preg_replace('/UNIX_TIMESTAMP\s*[(]\s*[)]/', |
|
| 698 | - ' EXTRACT(epoch FROM NOW())', $res); |
|
| 697 | + $res = preg_replace('/UNIX_TIMESTAMP\s*[(]\s*[)]/', |
|
| 698 | + ' EXTRACT(epoch FROM NOW())', $res); |
|
| 699 | 699 | |
| 700 | - // la fonction md5(integer) n'est pas connu en pg |
|
| 701 | - // il faut donc forcer les types en text (cas de md5(id_article)) |
|
| 702 | - $res = preg_replace('/md5\s*[(]([^)]*)[)]/i', |
|
| 703 | - 'MD5(CAST(\1 AS text))', $res); |
|
| 700 | + // la fonction md5(integer) n'est pas connu en pg |
|
| 701 | + // il faut donc forcer les types en text (cas de md5(id_article)) |
|
| 702 | + $res = preg_replace('/md5\s*[(]([^)]*)[)]/i', |
|
| 703 | + 'MD5(CAST(\1 AS text))', $res); |
|
| 704 | 704 | |
| 705 | - $res = preg_replace('/UNIX_TIMESTAMP\s*[(]([^)]*)[)]/', |
|
| 706 | - ' EXTRACT(epoch FROM \1)', $res); |
|
| 705 | + $res = preg_replace('/UNIX_TIMESTAMP\s*[(]([^)]*)[)]/', |
|
| 706 | + ' EXTRACT(epoch FROM \1)', $res); |
|
| 707 | 707 | |
| 708 | - $res = preg_replace('/\bDAYOFMONTH\s*[(]([^()]*([(][^()]*[)][^()]*)*[^)]*)[)]/', |
|
| 709 | - ' EXTRACT(day FROM \1)', |
|
| 710 | - $res); |
|
| 708 | + $res = preg_replace('/\bDAYOFMONTH\s*[(]([^()]*([(][^()]*[)][^()]*)*[^)]*)[)]/', |
|
| 709 | + ' EXTRACT(day FROM \1)', |
|
| 710 | + $res); |
|
| 711 | 711 | |
| 712 | - $res = preg_replace('/\bMONTH\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 713 | - ' EXTRACT(month FROM \1)', |
|
| 714 | - $res); |
|
| 712 | + $res = preg_replace('/\bMONTH\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 713 | + ' EXTRACT(month FROM \1)', |
|
| 714 | + $res); |
|
| 715 | 715 | |
| 716 | - $res = preg_replace('/\bYEAR\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 717 | - ' EXTRACT(year FROM \1)', |
|
| 718 | - $res); |
|
| 716 | + $res = preg_replace('/\bYEAR\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/', |
|
| 717 | + ' EXTRACT(year FROM \1)', |
|
| 718 | + $res); |
|
| 719 | 719 | |
| 720 | - $res = preg_replace('/TO_DAYS\s*[(]([^()]*([(][^)]*[)][()]*)*)[)]/', |
|
| 721 | - ' EXTRACT(day FROM \1 - \'0001-01-01\')', |
|
| 722 | - $res); |
|
| 720 | + $res = preg_replace('/TO_DAYS\s*[(]([^()]*([(][^)]*[)][()]*)*)[)]/', |
|
| 721 | + ' EXTRACT(day FROM \1 - \'0001-01-01\')', |
|
| 722 | + $res); |
|
| 723 | 723 | |
| 724 | - $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)\"([^\"]*)\"/", '\1\'\2\'', $res); |
|
| 724 | + $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)\"([^\"]*)\"/", '\1\'\2\'', $res); |
|
| 725 | 725 | |
| 726 | - $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m%d\'[)]/', 'to_char(\1, \'YYYYMMDD\')', $res); |
|
| 726 | + $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m%d\'[)]/', 'to_char(\1, \'YYYYMMDD\')', $res); |
|
| 727 | 727 | |
| 728 | - $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m\'[)]/', 'to_char(\1, \'YYYYMM\')', $res); |
|
| 728 | + $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m\'[)]/', 'to_char(\1, \'YYYYMM\')', $res); |
|
| 729 | 729 | |
| 730 | - $res = preg_replace('/DATE_SUB\s*[(]([^,]*),/', '(\1 -', $res); |
|
| 731 | - $res = preg_replace('/DATE_ADD\s*[(]([^,]*),/', '(\1 +', $res); |
|
| 732 | - $res = preg_replace('/INTERVAL\s+(\d+\s+\w+)/', 'INTERVAL \'\1\'', $res); |
|
| 733 | - $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\s+\d+:\d+(:\d+)\')/', '\1 timestamp \2', $res); |
|
| 734 | - $res = preg_replace('/(\'\d+-\d+-\d+\s+\d+:\d+:\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 730 | + $res = preg_replace('/DATE_SUB\s*[(]([^,]*),/', '(\1 -', $res); |
|
| 731 | + $res = preg_replace('/DATE_ADD\s*[(]([^,]*),/', '(\1 +', $res); |
|
| 732 | + $res = preg_replace('/INTERVAL\s+(\d+\s+\w+)/', 'INTERVAL \'\1\'', $res); |
|
| 733 | + $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\s+\d+:\d+(:\d+)\')/', '\1 timestamp \2', $res); |
|
| 734 | + $res = preg_replace('/(\'\d+-\d+-\d+\s+\d+:\d+:\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 735 | 735 | |
| 736 | - $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res); |
|
| 737 | - $res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 736 | + $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res); |
|
| 737 | + $res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res); |
|
| 738 | 738 | |
| 739 | - $res = preg_replace('/(timestamp .\d+)-00-/', '\1-01-', $res); |
|
| 740 | - $res = preg_replace('/(timestamp .\d+-\d+)-00/', '\1-01', $res); |
|
| 739 | + $res = preg_replace('/(timestamp .\d+)-00-/', '\1-01-', $res); |
|
| 740 | + $res = preg_replace('/(timestamp .\d+-\d+)-00/', '\1-01', $res); |
|
| 741 | 741 | # correct en theorie mais produit des debordements arithmetiques |
| 742 | 742 | # $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)(timestamp *'[^']*' *[+-] *timestamp *'[^']*') *[)]/", '\2', $res); |
| 743 | - $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res); |
|
| 744 | - $res = preg_replace("/\sLIKE\s+/", ' ILIKE ', $res); |
|
| 743 | + $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res); |
|
| 744 | + $res = preg_replace("/\sLIKE\s+/", ' ILIKE ', $res); |
|
| 745 | 745 | |
| 746 | - return str_replace('REGEXP', '~', $res); |
|
| 746 | + return str_replace('REGEXP', '~', $res); |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | // https://code.spip.net/@spip_pg_fromfield |
| 750 | 750 | function spip_pg_fromfield($arg) { |
| 751 | - while (preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) { |
|
| 752 | - |
|
| 753 | - preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER); |
|
| 754 | - $res = ''; |
|
| 755 | - $n = 0; |
|
| 756 | - $index = $m[2]; |
|
| 757 | - foreach ($r[1] as $v) { |
|
| 758 | - $n++; |
|
| 759 | - $res .= "\nwhen $index=$v then $n"; |
|
| 760 | - } |
|
| 761 | - $arg = $m[1] . "case $res else 0 end " |
|
| 762 | - . substr($arg, strlen($m[0])); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - return $arg; |
|
| 751 | + while (preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) { |
|
| 752 | + |
|
| 753 | + preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER); |
|
| 754 | + $res = ''; |
|
| 755 | + $n = 0; |
|
| 756 | + $index = $m[2]; |
|
| 757 | + foreach ($r[1] as $v) { |
|
| 758 | + $n++; |
|
| 759 | + $res .= "\nwhen $index=$v then $n"; |
|
| 760 | + } |
|
| 761 | + $arg = $m[1] . "case $res else 0 end " |
|
| 762 | + . substr($arg, strlen($m[0])); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + return $arg; |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | // https://code.spip.net/@calculer_pg_where |
| 769 | 769 | function calculer_pg_where($v) { |
| 770 | - if (!is_array($v)) { |
|
| 771 | - return spip_pg_frommysql($v); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - $op = str_replace('REGEXP', '~', array_shift($v)); |
|
| 775 | - if (!($n = count($v))) { |
|
| 776 | - return $op; |
|
| 777 | - } else { |
|
| 778 | - $arg = calculer_pg_where(array_shift($v)); |
|
| 779 | - if ($n == 1) { |
|
| 780 | - return "$op($arg)"; |
|
| 781 | - } else { |
|
| 782 | - $arg2 = calculer_pg_where(array_shift($v)); |
|
| 783 | - if ($n == 2) { |
|
| 784 | - return "($arg $op $arg2)"; |
|
| 785 | - } else { |
|
| 786 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - } |
|
| 770 | + if (!is_array($v)) { |
|
| 771 | + return spip_pg_frommysql($v); |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + $op = str_replace('REGEXP', '~', array_shift($v)); |
|
| 775 | + if (!($n = count($v))) { |
|
| 776 | + return $op; |
|
| 777 | + } else { |
|
| 778 | + $arg = calculer_pg_where(array_shift($v)); |
|
| 779 | + if ($n == 1) { |
|
| 780 | + return "$op($arg)"; |
|
| 781 | + } else { |
|
| 782 | + $arg2 = calculer_pg_where(array_shift($v)); |
|
| 783 | + if ($n == 2) { |
|
| 784 | + return "($arg $op $arg2)"; |
|
| 785 | + } else { |
|
| 786 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | |
| 793 | 793 | // https://code.spip.net/@calculer_pg_expression |
| 794 | 794 | function calculer_pg_expression($expression, $v, $join = 'AND') { |
| 795 | - if (empty($v)) { |
|
| 796 | - return ''; |
|
| 797 | - } |
|
| 795 | + if (empty($v)) { |
|
| 796 | + return ''; |
|
| 797 | + } |
|
| 798 | 798 | |
| 799 | - $exp = "\n$expression "; |
|
| 799 | + $exp = "\n$expression "; |
|
| 800 | 800 | |
| 801 | - if (!is_array($v)) { |
|
| 802 | - $v = array($v); |
|
| 803 | - } |
|
| 801 | + if (!is_array($v)) { |
|
| 802 | + $v = array($v); |
|
| 803 | + } |
|
| 804 | 804 | |
| 805 | - if (strtoupper($join) === 'AND') { |
|
| 806 | - return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 807 | - } else { |
|
| 808 | - return $exp . join($join, $v); |
|
| 809 | - } |
|
| 805 | + if (strtoupper($join) === 'AND') { |
|
| 806 | + return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 807 | + } else { |
|
| 808 | + return $exp . join($join, $v); |
|
| 809 | + } |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | // https://code.spip.net/@spip_pg_select_as |
| 813 | 813 | function spip_pg_select_as($args) { |
| 814 | - $argsas = ""; |
|
| 815 | - foreach ($args as $k => $v) { |
|
| 816 | - if (substr($k, -1) == '@') { |
|
| 817 | - // c'est une jointure qui se refere au from precedent |
|
| 818 | - // pas de virgule |
|
| 819 | - $argsas .= ' ' . $v; |
|
| 820 | - } else { |
|
| 821 | - $as = ''; |
|
| 822 | - // spip_log("$k : $v", _LOG_DEBUG); |
|
| 823 | - if (!is_numeric($k)) { |
|
| 824 | - if (preg_match('/\.(.*)$/', $k, $r)) { |
|
| 825 | - $v = $k; |
|
| 826 | - } elseif ($v != $k) { |
|
| 827 | - $p = strpos($v, " "); |
|
| 828 | - if ($p) { |
|
| 829 | - $v = substr($v, 0, $p) . " AS $k" . substr($v, $p); |
|
| 830 | - } else { |
|
| 831 | - $as = " AS $k"; |
|
| 832 | - } |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
|
| 836 | - // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
|
| 837 | - $argsas .= ', ' . $v . $as; |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - return substr($argsas, 2); |
|
| 814 | + $argsas = ""; |
|
| 815 | + foreach ($args as $k => $v) { |
|
| 816 | + if (substr($k, -1) == '@') { |
|
| 817 | + // c'est une jointure qui se refere au from precedent |
|
| 818 | + // pas de virgule |
|
| 819 | + $argsas .= ' ' . $v; |
|
| 820 | + } else { |
|
| 821 | + $as = ''; |
|
| 822 | + // spip_log("$k : $v", _LOG_DEBUG); |
|
| 823 | + if (!is_numeric($k)) { |
|
| 824 | + if (preg_match('/\.(.*)$/', $k, $r)) { |
|
| 825 | + $v = $k; |
|
| 826 | + } elseif ($v != $k) { |
|
| 827 | + $p = strpos($v, " "); |
|
| 828 | + if ($p) { |
|
| 829 | + $v = substr($v, 0, $p) . " AS $k" . substr($v, $p); |
|
| 830 | + } else { |
|
| 831 | + $as = " AS $k"; |
|
| 832 | + } |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
|
| 836 | + // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
|
| 837 | + $argsas .= ', ' . $v . $as; |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + return substr($argsas, 2); |
|
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | // https://code.spip.net/@spip_pg_fetch |
| 845 | 845 | function spip_pg_fetch($res, $t = '', $serveur = '', $requeter = true) { |
| 846 | 846 | |
| 847 | - if ($res) { |
|
| 848 | - $res = pg_fetch_array($res, null, PGSQL_ASSOC); |
|
| 849 | - } |
|
| 847 | + if ($res) { |
|
| 848 | + $res = pg_fetch_array($res, null, PGSQL_ASSOC); |
|
| 849 | + } |
|
| 850 | 850 | |
| 851 | - return $res; |
|
| 851 | + return $res; |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | function spip_pg_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 855 | - if ($r) { |
|
| 856 | - return pg_result_seek($r, $row_number); |
|
| 857 | - } |
|
| 855 | + if ($r) { |
|
| 856 | + return pg_result_seek($r, $row_number); |
|
| 857 | + } |
|
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | |
| 861 | 861 | // https://code.spip.net/@spip_pg_countsel |
| 862 | 862 | function spip_pg_countsel( |
| 863 | - $from = array(), |
|
| 864 | - $where = array(), |
|
| 865 | - $groupby = array(), |
|
| 866 | - $having = array(), |
|
| 867 | - $serveur = '', |
|
| 868 | - $requeter = true |
|
| 863 | + $from = array(), |
|
| 864 | + $where = array(), |
|
| 865 | + $groupby = array(), |
|
| 866 | + $having = array(), |
|
| 867 | + $serveur = '', |
|
| 868 | + $requeter = true |
|
| 869 | 869 | ) { |
| 870 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 871 | - $r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 872 | - if (!$requeter) { |
|
| 873 | - return $r; |
|
| 874 | - } |
|
| 875 | - if (!is_resource($r)) { |
|
| 876 | - return 0; |
|
| 877 | - } |
|
| 878 | - list($c) = pg_fetch_array($r, null, PGSQL_NUM); |
|
| 879 | - |
|
| 880 | - return $c; |
|
| 870 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 871 | + $r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 872 | + if (!$requeter) { |
|
| 873 | + return $r; |
|
| 874 | + } |
|
| 875 | + if (!is_resource($r)) { |
|
| 876 | + return 0; |
|
| 877 | + } |
|
| 878 | + list($c) = pg_fetch_array($r, null, PGSQL_NUM); |
|
| 879 | + |
|
| 880 | + return $c; |
|
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | // https://code.spip.net/@spip_pg_count |
| 884 | 884 | function spip_pg_count($res, $serveur = '', $requeter = true) { |
| 885 | - return !$res ? 0 : pg_numrows($res); |
|
| 885 | + return !$res ? 0 : pg_numrows($res); |
|
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | // https://code.spip.net/@spip_pg_free |
| 889 | 889 | function spip_pg_free($res, $serveur = '', $requeter = true) { |
| 890 | - // rien a faire en postgres |
|
| 890 | + // rien a faire en postgres |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | // https://code.spip.net/@spip_pg_delete |
| 894 | 894 | function spip_pg_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 895 | 895 | |
| 896 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 897 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 896 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 897 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 898 | 898 | |
| 899 | - $query = calculer_pg_expression('DELETE FROM', $table, ',') |
|
| 900 | - . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 899 | + $query = calculer_pg_expression('DELETE FROM', $table, ',') |
|
| 900 | + . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 901 | 901 | |
| 902 | - // renvoyer la requete inerte si demandee |
|
| 903 | - if (!$requeter) { |
|
| 904 | - return $query; |
|
| 905 | - } |
|
| 902 | + // renvoyer la requete inerte si demandee |
|
| 903 | + if (!$requeter) { |
|
| 904 | + return $query; |
|
| 905 | + } |
|
| 906 | 906 | |
| 907 | - $res = spip_pg_trace_query($query, $serveur); |
|
| 908 | - if ($res) { |
|
| 909 | - return pg_affected_rows($res); |
|
| 910 | - } else { |
|
| 911 | - return false; |
|
| 912 | - } |
|
| 907 | + $res = spip_pg_trace_query($query, $serveur); |
|
| 908 | + if ($res) { |
|
| 909 | + return pg_affected_rows($res); |
|
| 910 | + } else { |
|
| 911 | + return false; |
|
| 912 | + } |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | // https://code.spip.net/@spip_pg_insert |
| 916 | 916 | function spip_pg_insert($table, $champs, $valeurs, $desc = array(), $serveur = '', $requeter = true) { |
| 917 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 918 | - $prefixe = $connexion['prefixe']; |
|
| 919 | - $link = $connexion['link']; |
|
| 920 | - |
|
| 921 | - if (!$desc) { |
|
| 922 | - $desc = description_table($table, $serveur); |
|
| 923 | - } |
|
| 924 | - $seq = spip_pg_sequence($table, true); |
|
| 925 | - // si pas de cle primaire dans l'insertion, renvoyer curval |
|
| 926 | - if (!preg_match(",\b$seq\b,", $champs)) { |
|
| 927 | - $seq = spip_pg_sequence($table); |
|
| 928 | - $seq = prefixer_table_spip($seq, $prefixe); |
|
| 929 | - $seq = "currval('$seq')"; |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - $table = prefixer_table_spip($table, $prefixe); |
|
| 933 | - $ret = !$seq ? '' : (" RETURNING $seq"); |
|
| 934 | - $ins = (strlen($champs) < 3) |
|
| 935 | - ? " DEFAULT VALUES" |
|
| 936 | - : "$champs VALUES $valeurs"; |
|
| 937 | - $q = "INSERT INTO $table $ins $ret"; |
|
| 938 | - if (!$requeter) { |
|
| 939 | - return $q; |
|
| 940 | - } |
|
| 941 | - $connexion['last'] = $q; |
|
| 942 | - $r = spip_pg_query_simple($link, $q); |
|
| 917 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 918 | + $prefixe = $connexion['prefixe']; |
|
| 919 | + $link = $connexion['link']; |
|
| 920 | + |
|
| 921 | + if (!$desc) { |
|
| 922 | + $desc = description_table($table, $serveur); |
|
| 923 | + } |
|
| 924 | + $seq = spip_pg_sequence($table, true); |
|
| 925 | + // si pas de cle primaire dans l'insertion, renvoyer curval |
|
| 926 | + if (!preg_match(",\b$seq\b,", $champs)) { |
|
| 927 | + $seq = spip_pg_sequence($table); |
|
| 928 | + $seq = prefixer_table_spip($seq, $prefixe); |
|
| 929 | + $seq = "currval('$seq')"; |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + $table = prefixer_table_spip($table, $prefixe); |
|
| 933 | + $ret = !$seq ? '' : (" RETURNING $seq"); |
|
| 934 | + $ins = (strlen($champs) < 3) |
|
| 935 | + ? " DEFAULT VALUES" |
|
| 936 | + : "$champs VALUES $valeurs"; |
|
| 937 | + $q = "INSERT INTO $table $ins $ret"; |
|
| 938 | + if (!$requeter) { |
|
| 939 | + return $q; |
|
| 940 | + } |
|
| 941 | + $connexion['last'] = $q; |
|
| 942 | + $r = spip_pg_query_simple($link, $q); |
|
| 943 | 943 | # spip_log($q,'pg.'._LOG_DEBUG); |
| 944 | - if ($r) { |
|
| 945 | - if (!$ret) { |
|
| 946 | - return 0; |
|
| 947 | - } |
|
| 948 | - if ($r2 = pg_fetch_array($r, null, PGSQL_NUM)) { |
|
| 949 | - return $r2[0]; |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - return false; |
|
| 944 | + if ($r) { |
|
| 945 | + if (!$ret) { |
|
| 946 | + return 0; |
|
| 947 | + } |
|
| 948 | + if ($r2 = pg_fetch_array($r, null, PGSQL_NUM)) { |
|
| 949 | + return $r2[0]; |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + return false; |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | // https://code.spip.net/@spip_pg_insertq |
| 957 | 957 | function spip_pg_insertq($table, $couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
| 958 | 958 | |
| 959 | - if (!$desc) { |
|
| 960 | - $desc = description_table($table, $serveur); |
|
| 961 | - } |
|
| 962 | - if (!$desc) { |
|
| 963 | - die("$table insertion sans description"); |
|
| 964 | - } |
|
| 965 | - $fields = $desc['field']; |
|
| 959 | + if (!$desc) { |
|
| 960 | + $desc = description_table($table, $serveur); |
|
| 961 | + } |
|
| 962 | + if (!$desc) { |
|
| 963 | + die("$table insertion sans description"); |
|
| 964 | + } |
|
| 965 | + $fields = $desc['field']; |
|
| 966 | 966 | |
| 967 | - foreach ($couples as $champ => $val) { |
|
| 968 | - $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 969 | - } |
|
| 967 | + foreach ($couples as $champ => $val) { |
|
| 968 | + $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 969 | + } |
|
| 970 | 970 | |
| 971 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 972 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 971 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 972 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 973 | 973 | |
| 974 | - return spip_pg_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 975 | - $serveur, $requeter); |
|
| 974 | + return spip_pg_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 975 | + $serveur, $requeter); |
|
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | |
| 979 | 979 | // https://code.spip.net/@spip_pg_insertq_multi |
| 980 | 980 | function spip_pg_insertq_multi($table, $tab_couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
| 981 | 981 | |
| 982 | - if (!$desc) { |
|
| 983 | - $desc = description_table($table, $serveur); |
|
| 984 | - } |
|
| 985 | - if (!$desc) { |
|
| 986 | - die("$table insertion sans description"); |
|
| 987 | - } |
|
| 988 | - $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 989 | - |
|
| 990 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 991 | - // une premiere fois pour ajouter maj dans les cles |
|
| 992 | - $c = isset($tab_couples[0]) ? $tab_couples[0] : array(); |
|
| 993 | - $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
|
| 994 | - |
|
| 995 | - $cles = "(" . join(',', array_keys($les_cles)) . ')'; |
|
| 996 | - $valeurs = array(); |
|
| 997 | - foreach ($tab_couples as $couples) { |
|
| 998 | - foreach ($couples as $champ => $val) { |
|
| 999 | - $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 1000 | - } |
|
| 1001 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1002 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1003 | - |
|
| 1004 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1005 | - } |
|
| 1006 | - $valeurs = implode(', ', $valeurs); |
|
| 1007 | - |
|
| 1008 | - return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
|
| 982 | + if (!$desc) { |
|
| 983 | + $desc = description_table($table, $serveur); |
|
| 984 | + } |
|
| 985 | + if (!$desc) { |
|
| 986 | + die("$table insertion sans description"); |
|
| 987 | + } |
|
| 988 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 989 | + |
|
| 990 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 991 | + // une premiere fois pour ajouter maj dans les cles |
|
| 992 | + $c = isset($tab_couples[0]) ? $tab_couples[0] : array(); |
|
| 993 | + $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
|
| 994 | + |
|
| 995 | + $cles = "(" . join(',', array_keys($les_cles)) . ')'; |
|
| 996 | + $valeurs = array(); |
|
| 997 | + foreach ($tab_couples as $couples) { |
|
| 998 | + foreach ($couples as $champ => $val) { |
|
| 999 | + $couples[$champ] = spip_pg_cite($val, $fields[$champ]); |
|
| 1000 | + } |
|
| 1001 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1002 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1003 | + |
|
| 1004 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1005 | + } |
|
| 1006 | + $valeurs = implode(', ', $valeurs); |
|
| 1007 | + |
|
| 1008 | + return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter); |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | |
| 1012 | 1012 | // https://code.spip.net/@spip_pg_update |
| 1013 | 1013 | function spip_pg_update($table, $couples, $where = '', $desc = '', $serveur = '', $requeter = true) { |
| 1014 | 1014 | |
| 1015 | - if (!$couples) { |
|
| 1016 | - return; |
|
| 1017 | - } |
|
| 1018 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1019 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1015 | + if (!$couples) { |
|
| 1016 | + return; |
|
| 1017 | + } |
|
| 1018 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1019 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1020 | 1020 | |
| 1021 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1022 | - $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1021 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1022 | + $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
|
| 1023 | 1023 | |
| 1024 | - $set = array(); |
|
| 1025 | - foreach ($couples as $champ => $val) { |
|
| 1026 | - $set[] = $champ . '=' . $val; |
|
| 1027 | - } |
|
| 1024 | + $set = array(); |
|
| 1025 | + foreach ($couples as $champ => $val) { |
|
| 1026 | + $set[] = $champ . '=' . $val; |
|
| 1027 | + } |
|
| 1028 | 1028 | |
| 1029 | - $query = calculer_pg_expression('UPDATE', $table, ',') |
|
| 1030 | - . calculer_pg_expression('SET', $set, ',') |
|
| 1031 | - . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 1029 | + $query = calculer_pg_expression('UPDATE', $table, ',') |
|
| 1030 | + . calculer_pg_expression('SET', $set, ',') |
|
| 1031 | + . calculer_pg_expression('WHERE', $where, 'AND'); |
|
| 1032 | 1032 | |
| 1033 | - // renvoyer la requete inerte si demandee |
|
| 1034 | - if (!$requeter) { |
|
| 1035 | - return $query; |
|
| 1036 | - } |
|
| 1033 | + // renvoyer la requete inerte si demandee |
|
| 1034 | + if (!$requeter) { |
|
| 1035 | + return $query; |
|
| 1036 | + } |
|
| 1037 | 1037 | |
| 1038 | - return spip_pg_trace_query($query, $serveur); |
|
| 1038 | + return spip_pg_trace_query($query, $serveur); |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | // idem, mais les valeurs sont des constantes a mettre entre apostrophes |
| 1042 | 1042 | // sauf les expressions de date lorsqu'il s'agit de fonctions SQL (NOW etc) |
| 1043 | 1043 | // https://code.spip.net/@spip_pg_updateq |
| 1044 | 1044 | function spip_pg_updateq($table, $couples, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1045 | - if (!$couples) { |
|
| 1046 | - return; |
|
| 1047 | - } |
|
| 1048 | - if (!$desc) { |
|
| 1049 | - $desc = description_table($table, $serveur); |
|
| 1050 | - } |
|
| 1051 | - $fields = $desc['field']; |
|
| 1052 | - foreach ($couples as $k => $val) { |
|
| 1053 | - $couples[$k] = spip_pg_cite($val, $fields[$k]); |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - return spip_pg_update($table, $couples, $where, $desc, $serveur, $requeter); |
|
| 1045 | + if (!$couples) { |
|
| 1046 | + return; |
|
| 1047 | + } |
|
| 1048 | + if (!$desc) { |
|
| 1049 | + $desc = description_table($table, $serveur); |
|
| 1050 | + } |
|
| 1051 | + $fields = $desc['field']; |
|
| 1052 | + foreach ($couples as $k => $val) { |
|
| 1053 | + $couples[$k] = spip_pg_cite($val, $fields[$k]); |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + return spip_pg_update($table, $couples, $where, $desc, $serveur, $requeter); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | |
| 1060 | 1060 | // https://code.spip.net/@spip_pg_replace |
| 1061 | 1061 | function spip_pg_replace($table, $values, $desc, $serveur = '', $requeter = true) { |
| 1062 | - if (!$values) { |
|
| 1063 | - spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1064 | - |
|
| 1065 | - return 0; |
|
| 1066 | - } |
|
| 1067 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1068 | - $prefixe = $connexion['prefixe']; |
|
| 1069 | - $link = $connexion['link']; |
|
| 1070 | - |
|
| 1071 | - if (!$desc) { |
|
| 1072 | - $desc = description_table($table, $serveur); |
|
| 1073 | - } |
|
| 1074 | - if (!$desc) { |
|
| 1075 | - die("$table insertion sans description"); |
|
| 1076 | - } |
|
| 1077 | - $prim = $desc['key']['PRIMARY KEY']; |
|
| 1078 | - $ids = preg_split('/,\s*/', $prim); |
|
| 1079 | - $noprims = $prims = array(); |
|
| 1080 | - foreach ($values as $k => $v) { |
|
| 1081 | - $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); |
|
| 1082 | - |
|
| 1083 | - if (!in_array($k, $ids)) { |
|
| 1084 | - $noprims[$k] = "$k=$v"; |
|
| 1085 | - } else { |
|
| 1086 | - $prims[$k] = "$k=$v"; |
|
| 1087 | - } |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1091 | - $values = spip_pg_ajouter_champs_timestamp($table, $values, $desc, $serveur); |
|
| 1092 | - |
|
| 1093 | - $where = join(' AND ', $prims); |
|
| 1094 | - if (!$where) { |
|
| 1095 | - return spip_pg_insert($table, "(" . join(',', array_keys($values)) . ")", "(" . join(',', $values) . ")", $desc, |
|
| 1096 | - $serveur); |
|
| 1097 | - } |
|
| 1098 | - $couples = join(',', $noprims); |
|
| 1099 | - |
|
| 1100 | - $seq = spip_pg_sequence($table); |
|
| 1101 | - $table = prefixer_table_spip($table, $prefixe); |
|
| 1102 | - $seq = prefixer_table_spip($seq, $prefixe); |
|
| 1103 | - |
|
| 1104 | - $connexion['last'] = $q = "UPDATE $table SET $couples WHERE $where"; |
|
| 1105 | - if ($couples) { |
|
| 1106 | - $couples = spip_pg_query_simple($link, $q); |
|
| 1062 | + if (!$values) { |
|
| 1063 | + spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1064 | + |
|
| 1065 | + return 0; |
|
| 1066 | + } |
|
| 1067 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1068 | + $prefixe = $connexion['prefixe']; |
|
| 1069 | + $link = $connexion['link']; |
|
| 1070 | + |
|
| 1071 | + if (!$desc) { |
|
| 1072 | + $desc = description_table($table, $serveur); |
|
| 1073 | + } |
|
| 1074 | + if (!$desc) { |
|
| 1075 | + die("$table insertion sans description"); |
|
| 1076 | + } |
|
| 1077 | + $prim = $desc['key']['PRIMARY KEY']; |
|
| 1078 | + $ids = preg_split('/,\s*/', $prim); |
|
| 1079 | + $noprims = $prims = array(); |
|
| 1080 | + foreach ($values as $k => $v) { |
|
| 1081 | + $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]); |
|
| 1082 | + |
|
| 1083 | + if (!in_array($k, $ids)) { |
|
| 1084 | + $noprims[$k] = "$k=$v"; |
|
| 1085 | + } else { |
|
| 1086 | + $prims[$k] = "$k=$v"; |
|
| 1087 | + } |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
|
| 1091 | + $values = spip_pg_ajouter_champs_timestamp($table, $values, $desc, $serveur); |
|
| 1092 | + |
|
| 1093 | + $where = join(' AND ', $prims); |
|
| 1094 | + if (!$where) { |
|
| 1095 | + return spip_pg_insert($table, "(" . join(',', array_keys($values)) . ")", "(" . join(',', $values) . ")", $desc, |
|
| 1096 | + $serveur); |
|
| 1097 | + } |
|
| 1098 | + $couples = join(',', $noprims); |
|
| 1099 | + |
|
| 1100 | + $seq = spip_pg_sequence($table); |
|
| 1101 | + $table = prefixer_table_spip($table, $prefixe); |
|
| 1102 | + $seq = prefixer_table_spip($seq, $prefixe); |
|
| 1103 | + |
|
| 1104 | + $connexion['last'] = $q = "UPDATE $table SET $couples WHERE $where"; |
|
| 1105 | + if ($couples) { |
|
| 1106 | + $couples = spip_pg_query_simple($link, $q); |
|
| 1107 | 1107 | # spip_log($q,'pg.'._LOG_DEBUG); |
| 1108 | - if (!$couples) { |
|
| 1109 | - return false; |
|
| 1110 | - } |
|
| 1111 | - $couples = pg_affected_rows($couples); |
|
| 1112 | - } |
|
| 1113 | - if (!$couples) { |
|
| 1114 | - $ret = !$seq ? '' : |
|
| 1115 | - (" RETURNING nextval('$seq') < $prim"); |
|
| 1116 | - $connexion['last'] = $q = "INSERT INTO $table (" . join(',', array_keys($values)) . ') VALUES (' . join(',', |
|
| 1117 | - $values) . ")$ret"; |
|
| 1118 | - $couples = spip_pg_query_simple($link, $q); |
|
| 1119 | - if (!$couples) { |
|
| 1120 | - return false; |
|
| 1121 | - } elseif ($ret) { |
|
| 1122 | - $r = pg_fetch_array($couples, null, PGSQL_NUM); |
|
| 1123 | - if ($r[0]) { |
|
| 1124 | - $connexion['last'] = $q = "SELECT setval('$seq', $prim) from $table"; |
|
| 1125 | - // Le code de SPIP met parfois la sequence a 0 (dans l'import) |
|
| 1126 | - // MySQL n'en dit rien, on fait pareil pour PG |
|
| 1127 | - $r = @pg_query($link, $q); |
|
| 1128 | - } |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - return $couples; |
|
| 1108 | + if (!$couples) { |
|
| 1109 | + return false; |
|
| 1110 | + } |
|
| 1111 | + $couples = pg_affected_rows($couples); |
|
| 1112 | + } |
|
| 1113 | + if (!$couples) { |
|
| 1114 | + $ret = !$seq ? '' : |
|
| 1115 | + (" RETURNING nextval('$seq') < $prim"); |
|
| 1116 | + $connexion['last'] = $q = "INSERT INTO $table (" . join(',', array_keys($values)) . ') VALUES (' . join(',', |
|
| 1117 | + $values) . ")$ret"; |
|
| 1118 | + $couples = spip_pg_query_simple($link, $q); |
|
| 1119 | + if (!$couples) { |
|
| 1120 | + return false; |
|
| 1121 | + } elseif ($ret) { |
|
| 1122 | + $r = pg_fetch_array($couples, null, PGSQL_NUM); |
|
| 1123 | + if ($r[0]) { |
|
| 1124 | + $connexion['last'] = $q = "SELECT setval('$seq', $prim) from $table"; |
|
| 1125 | + // Le code de SPIP met parfois la sequence a 0 (dans l'import) |
|
| 1126 | + // MySQL n'en dit rien, on fait pareil pour PG |
|
| 1127 | + $r = @pg_query($link, $q); |
|
| 1128 | + } |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + return $couples; |
|
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | |
| 1136 | 1136 | // https://code.spip.net/@spip_pg_replace_multi |
| 1137 | 1137 | function spip_pg_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1138 | - // boucler pour traiter chaque requete independemment |
|
| 1139 | - foreach ($tab_couples as $couples) { |
|
| 1140 | - $retour = spip_pg_replace($table, $couples, $desc, $serveur, $requeter); |
|
| 1141 | - } |
|
| 1138 | + // boucler pour traiter chaque requete independemment |
|
| 1139 | + foreach ($tab_couples as $couples) { |
|
| 1140 | + $retour = spip_pg_replace($table, $couples, $desc, $serveur, $requeter); |
|
| 1141 | + } |
|
| 1142 | 1142 | |
| 1143 | - // renvoie le dernier id |
|
| 1144 | - return $retour; |
|
| 1143 | + // renvoie le dernier id |
|
| 1144 | + return $retour; |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | |
@@ -1151,19 +1151,19 @@ discard block |
||
| 1151 | 1151 | // https://code.spip.net/@spip_pg_sequence |
| 1152 | 1152 | function spip_pg_sequence($table, $raw = false) { |
| 1153 | 1153 | |
| 1154 | - include_spip('base/serial'); |
|
| 1155 | - if (!isset($GLOBALS['tables_principales'][$table])) { |
|
| 1156 | - return false; |
|
| 1157 | - } |
|
| 1158 | - $desc = $GLOBALS['tables_principales'][$table]; |
|
| 1159 | - $prim = @$desc['key']['PRIMARY KEY']; |
|
| 1160 | - if (!preg_match('/^\w+$/', $prim) |
|
| 1161 | - or strpos($desc['field'][$prim], 'int') === false |
|
| 1162 | - ) { |
|
| 1163 | - return ''; |
|
| 1164 | - } else { |
|
| 1165 | - return $raw ? $prim : $table . '_' . $prim . "_seq"; |
|
| 1166 | - } |
|
| 1154 | + include_spip('base/serial'); |
|
| 1155 | + if (!isset($GLOBALS['tables_principales'][$table])) { |
|
| 1156 | + return false; |
|
| 1157 | + } |
|
| 1158 | + $desc = $GLOBALS['tables_principales'][$table]; |
|
| 1159 | + $prim = @$desc['key']['PRIMARY KEY']; |
|
| 1160 | + if (!preg_match('/^\w+$/', $prim) |
|
| 1161 | + or strpos($desc['field'][$prim], 'int') === false |
|
| 1162 | + ) { |
|
| 1163 | + return ''; |
|
| 1164 | + } else { |
|
| 1165 | + return $raw ? $prim : $table . '_' . $prim . "_seq"; |
|
| 1166 | + } |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | // Explicite les conversions de Mysql d'une valeur $v de type $t |
@@ -1171,65 +1171,65 @@ discard block |
||
| 1171 | 1171 | |
| 1172 | 1172 | // https://code.spip.net/@spip_pg_cite |
| 1173 | 1173 | function spip_pg_cite($v, $t) { |
| 1174 | - if (is_null($v)) { |
|
| 1175 | - return 'NULL'; |
|
| 1176 | - } // null php se traduit en NULL SQL |
|
| 1177 | - |
|
| 1178 | - if (sql_test_date($t)) { |
|
| 1179 | - if ($v and (strpos("0123456789", $v[0]) === false)) { |
|
| 1180 | - return spip_pg_frommysql($v); |
|
| 1181 | - } else { |
|
| 1182 | - if (strncmp($v, '0000', 4) == 0) { |
|
| 1183 | - $v = "0001" . substr($v, 4); |
|
| 1184 | - } |
|
| 1185 | - if (strpos($v, "-00-00") === 4) { |
|
| 1186 | - $v = substr($v, 0, 4) . "-01-01" . substr($v, 10); |
|
| 1187 | - } |
|
| 1188 | - |
|
| 1189 | - return "timestamp '$v'"; |
|
| 1190 | - } |
|
| 1191 | - } elseif (!sql_test_int($t)) { |
|
| 1192 | - return ("'" . pg_escape_string($v) . "'"); |
|
| 1193 | - } elseif (is_numeric($v) or (strpos($v, 'CAST(') === 0)) { |
|
| 1194 | - return $v; |
|
| 1195 | - } elseif ($v[0] == '0' and $v[1] !== 'x' and ctype_xdigit(substr($v, 1))) { |
|
| 1196 | - return substr($v, 1); |
|
| 1197 | - } else { |
|
| 1198 | - spip_log("Warning: '$v' n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1199 | - |
|
| 1200 | - return intval($v); |
|
| 1201 | - } |
|
| 1174 | + if (is_null($v)) { |
|
| 1175 | + return 'NULL'; |
|
| 1176 | + } // null php se traduit en NULL SQL |
|
| 1177 | + |
|
| 1178 | + if (sql_test_date($t)) { |
|
| 1179 | + if ($v and (strpos("0123456789", $v[0]) === false)) { |
|
| 1180 | + return spip_pg_frommysql($v); |
|
| 1181 | + } else { |
|
| 1182 | + if (strncmp($v, '0000', 4) == 0) { |
|
| 1183 | + $v = "0001" . substr($v, 4); |
|
| 1184 | + } |
|
| 1185 | + if (strpos($v, "-00-00") === 4) { |
|
| 1186 | + $v = substr($v, 0, 4) . "-01-01" . substr($v, 10); |
|
| 1187 | + } |
|
| 1188 | + |
|
| 1189 | + return "timestamp '$v'"; |
|
| 1190 | + } |
|
| 1191 | + } elseif (!sql_test_int($t)) { |
|
| 1192 | + return ("'" . pg_escape_string($v) . "'"); |
|
| 1193 | + } elseif (is_numeric($v) or (strpos($v, 'CAST(') === 0)) { |
|
| 1194 | + return $v; |
|
| 1195 | + } elseif ($v[0] == '0' and $v[1] !== 'x' and ctype_xdigit(substr($v, 1))) { |
|
| 1196 | + return substr($v, 1); |
|
| 1197 | + } else { |
|
| 1198 | + spip_log("Warning: '$v' n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1199 | + |
|
| 1200 | + return intval($v); |
|
| 1201 | + } |
|
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | // https://code.spip.net/@spip_pg_hex |
| 1205 | 1205 | function spip_pg_hex($v) { |
| 1206 | - return "CAST(x'" . $v . "' as bigint)"; |
|
| 1206 | + return "CAST(x'" . $v . "' as bigint)"; |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | function spip_pg_quote($v, $type = '') { |
| 1210 | - if (!is_array($v)) { |
|
| 1211 | - return spip_pg_cite($v, $type); |
|
| 1212 | - } |
|
| 1213 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1214 | - foreach ($v as $k => $r) { |
|
| 1215 | - $v[$k] = spip_pg_quote($r, $type); |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - return join(",", $v); |
|
| 1210 | + if (!is_array($v)) { |
|
| 1211 | + return spip_pg_cite($v, $type); |
|
| 1212 | + } |
|
| 1213 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1214 | + foreach ($v as $k => $r) { |
|
| 1215 | + $v[$k] = spip_pg_quote($r, $type); |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + return join(",", $v); |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | 1221 | function spip_pg_date_proche($champ, $interval, $unite) { |
| 1222 | - return '(' |
|
| 1223 | - . $champ |
|
| 1224 | - . (($interval <= 0) ? '>' : '<') |
|
| 1225 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1226 | - . '(' |
|
| 1227 | - . sql_quote(date('Y-m-d H:i:s')) |
|
| 1228 | - . ', INTERVAL ' |
|
| 1229 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1230 | - . ' ' |
|
| 1231 | - . $unite |
|
| 1232 | - . '))'; |
|
| 1222 | + return '(' |
|
| 1223 | + . $champ |
|
| 1224 | + . (($interval <= 0) ? '>' : '<') |
|
| 1225 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1226 | + . '(' |
|
| 1227 | + . sql_quote(date('Y-m-d H:i:s')) |
|
| 1228 | + . ', INTERVAL ' |
|
| 1229 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1230 | + . ' ' |
|
| 1231 | + . $unite |
|
| 1232 | + . '))'; |
|
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | 1235 | // https://code.spip.net/@spip_pg_in |
@@ -1237,69 +1237,69 @@ discard block |
||
| 1237 | 1237 | // |
| 1238 | 1238 | // IN (...) souvent limite a 255 elements, d'ou cette fonction assistante |
| 1239 | 1239 | // |
| 1240 | - // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale. |
|
| 1241 | - if (!$valeurs) { |
|
| 1242 | - return $not ? '0=0' : '0=1'; |
|
| 1243 | - } |
|
| 1244 | - if (strpos($valeurs, "CAST(x'") !== false) { |
|
| 1245 | - return "($val=" . join("OR $val=", explode(',', $valeurs)) . ')'; |
|
| 1246 | - } |
|
| 1247 | - $n = $i = 0; |
|
| 1248 | - $in_sql = ""; |
|
| 1249 | - while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1250 | - if ((++$i) >= 255) { |
|
| 1251 | - $in_sql .= "($val $not IN (" . |
|
| 1252 | - substr($valeurs, 0, $n) . |
|
| 1253 | - "))\n" . |
|
| 1254 | - ($not ? "AND\t" : "OR\t"); |
|
| 1255 | - $valeurs = substr($valeurs, $n + 1); |
|
| 1256 | - $i = $n = 0; |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1260 | - |
|
| 1261 | - return "($in_sql)"; |
|
| 1240 | + // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale. |
|
| 1241 | + if (!$valeurs) { |
|
| 1242 | + return $not ? '0=0' : '0=1'; |
|
| 1243 | + } |
|
| 1244 | + if (strpos($valeurs, "CAST(x'") !== false) { |
|
| 1245 | + return "($val=" . join("OR $val=", explode(',', $valeurs)) . ')'; |
|
| 1246 | + } |
|
| 1247 | + $n = $i = 0; |
|
| 1248 | + $in_sql = ""; |
|
| 1249 | + while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1250 | + if ((++$i) >= 255) { |
|
| 1251 | + $in_sql .= "($val $not IN (" . |
|
| 1252 | + substr($valeurs, 0, $n) . |
|
| 1253 | + "))\n" . |
|
| 1254 | + ($not ? "AND\t" : "OR\t"); |
|
| 1255 | + $valeurs = substr($valeurs, $n + 1); |
|
| 1256 | + $i = $n = 0; |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1260 | + |
|
| 1261 | + return "($in_sql)"; |
|
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | 1264 | // https://code.spip.net/@spip_pg_error |
| 1265 | 1265 | function spip_pg_error($query = '', $serveur = '', $requeter = true) { |
| 1266 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1267 | - $s = $link ? pg_last_error($link) : pg_last_error(); |
|
| 1268 | - if ($s) { |
|
| 1269 | - $s = str_replace('ERROR', 'errcode: 1000 ', $s); |
|
| 1270 | - spip_log("$s - $query", 'pg.' . _LOG_ERREUR); |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - return $s; |
|
| 1266 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1267 | + $s = $link ? pg_last_error($link) : pg_last_error(); |
|
| 1268 | + if ($s) { |
|
| 1269 | + $s = str_replace('ERROR', 'errcode: 1000 ', $s); |
|
| 1270 | + spip_log("$s - $query", 'pg.' . _LOG_ERREUR); |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + return $s; |
|
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | 1276 | // https://code.spip.net/@spip_pg_errno |
| 1277 | 1277 | function spip_pg_errno($serveur = '') { |
| 1278 | - // il faudrait avoir la derniere ressource retournee et utiliser |
|
| 1279 | - // http://fr2.php.net/manual/fr/function.pg-result-error.php |
|
| 1280 | - return 0; |
|
| 1278 | + // il faudrait avoir la derniere ressource retournee et utiliser |
|
| 1279 | + // http://fr2.php.net/manual/fr/function.pg-result-error.php |
|
| 1280 | + return 0; |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | // https://code.spip.net/@spip_pg_drop_table |
| 1284 | 1284 | function spip_pg_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 1285 | - if ($exist) { |
|
| 1286 | - $exist = " IF EXISTS"; |
|
| 1287 | - } |
|
| 1288 | - if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) { |
|
| 1289 | - return true; |
|
| 1290 | - } else { |
|
| 1291 | - return false; |
|
| 1292 | - } |
|
| 1285 | + if ($exist) { |
|
| 1286 | + $exist = " IF EXISTS"; |
|
| 1287 | + } |
|
| 1288 | + if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) { |
|
| 1289 | + return true; |
|
| 1290 | + } else { |
|
| 1291 | + return false; |
|
| 1292 | + } |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | // supprime une vue |
| 1296 | 1296 | // https://code.spip.net/@spip_pg_drop_view |
| 1297 | 1297 | function spip_pg_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 1298 | - if ($exist) { |
|
| 1299 | - $exist = " IF EXISTS"; |
|
| 1300 | - } |
|
| 1298 | + if ($exist) { |
|
| 1299 | + $exist = " IF EXISTS"; |
|
| 1300 | + } |
|
| 1301 | 1301 | |
| 1302 | - return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 1302 | + return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | /** |
@@ -1316,41 +1316,41 @@ discard block |
||
| 1316 | 1316 | * Ressource à utiliser avec sql_fetch() |
| 1317 | 1317 | **/ |
| 1318 | 1318 | function spip_pg_showbase($match, $serveur = '', $requeter = true) { |
| 1319 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1320 | - $link = $connexion['link']; |
|
| 1321 | - $connexion['last'] = $q = "SELECT tablename FROM pg_tables WHERE tablename ILIKE " . _q($match); |
|
| 1319 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1320 | + $link = $connexion['link']; |
|
| 1321 | + $connexion['last'] = $q = "SELECT tablename FROM pg_tables WHERE tablename ILIKE " . _q($match); |
|
| 1322 | 1322 | |
| 1323 | - return spip_pg_query_simple($link, $q); |
|
| 1323 | + return spip_pg_query_simple($link, $q); |
|
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | // https://code.spip.net/@spip_pg_showtable |
| 1327 | 1327 | function spip_pg_showtable($nom_table, $serveur = '', $requeter = true) { |
| 1328 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1329 | - $link = $connexion['link']; |
|
| 1330 | - $connexion['last'] = $q = "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE " . _q($nom_table); |
|
| 1331 | - |
|
| 1332 | - $res = spip_pg_query_simple($link, $q); |
|
| 1333 | - if (!$res) { |
|
| 1334 | - return false; |
|
| 1335 | - } |
|
| 1336 | - |
|
| 1337 | - // etrangement, $res peut ne rien contenir, mais arriver ici... |
|
| 1338 | - // il faut en tenir compte dans le return |
|
| 1339 | - $fields = array(); |
|
| 1340 | - while ($field = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1341 | - $fields[$field[0]] = $field[2] . (!$field[1] ? '' : (" DEFAULT " . $field[1])); |
|
| 1342 | - } |
|
| 1343 | - $connexion['last'] = $q = "SELECT indexdef FROM pg_indexes WHERE tablename ILIKE " . _q($nom_table); |
|
| 1344 | - $res = spip_pg_query_simple($link, $q); |
|
| 1345 | - $keys = array(); |
|
| 1346 | - while ($index = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1347 | - if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) { |
|
| 1348 | - $nom = str_replace($nom_table . '_', '', $r[2]); |
|
| 1349 | - $keys[($r[1] ? "PRIMARY KEY" : ("KEY " . $nom))] = $r[3]; |
|
| 1350 | - } |
|
| 1351 | - } |
|
| 1352 | - |
|
| 1353 | - return count($fields) ? array('field' => $fields, 'key' => $keys) : false; |
|
| 1328 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1329 | + $link = $connexion['link']; |
|
| 1330 | + $connexion['last'] = $q = "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE " . _q($nom_table); |
|
| 1331 | + |
|
| 1332 | + $res = spip_pg_query_simple($link, $q); |
|
| 1333 | + if (!$res) { |
|
| 1334 | + return false; |
|
| 1335 | + } |
|
| 1336 | + |
|
| 1337 | + // etrangement, $res peut ne rien contenir, mais arriver ici... |
|
| 1338 | + // il faut en tenir compte dans le return |
|
| 1339 | + $fields = array(); |
|
| 1340 | + while ($field = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1341 | + $fields[$field[0]] = $field[2] . (!$field[1] ? '' : (" DEFAULT " . $field[1])); |
|
| 1342 | + } |
|
| 1343 | + $connexion['last'] = $q = "SELECT indexdef FROM pg_indexes WHERE tablename ILIKE " . _q($nom_table); |
|
| 1344 | + $res = spip_pg_query_simple($link, $q); |
|
| 1345 | + $keys = array(); |
|
| 1346 | + while ($index = pg_fetch_array($res, null, PGSQL_NUM)) { |
|
| 1347 | + if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) { |
|
| 1348 | + $nom = str_replace($nom_table . '_', '', $r[2]); |
|
| 1349 | + $keys[($r[1] ? "PRIMARY KEY" : ("KEY " . $nom))] = $r[3]; |
|
| 1350 | + } |
|
| 1351 | + } |
|
| 1352 | + |
|
| 1353 | + return count($fields) ? array('field' => $fields, 'key' => $keys) : false; |
|
| 1354 | 1354 | } |
| 1355 | 1355 | |
| 1356 | 1356 | // Fonction de creation d'une table SQL nommee $nom |
@@ -1362,118 +1362,118 @@ discard block |
||
| 1362 | 1362 | // https://code.spip.net/@spip_pg_create |
| 1363 | 1363 | function spip_pg_create($nom, $champs, $cles, $autoinc = false, $temporary = false, $serveur = '', $requeter = true) { |
| 1364 | 1364 | |
| 1365 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1366 | - $link = $connexion['link']; |
|
| 1367 | - $nom = prefixer_table_spip($nom, $connexion['prefixe']); |
|
| 1368 | - |
|
| 1369 | - $query = $prim = $prim_name = $v = $s = $p = ''; |
|
| 1370 | - $keys = array(); |
|
| 1371 | - |
|
| 1372 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 1373 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 1374 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 1375 | - return; |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - foreach ($cles as $k => $v) { |
|
| 1379 | - if (strpos($k, "KEY ") === 0) { |
|
| 1380 | - $n = str_replace('`', '', $k); |
|
| 1381 | - $v = str_replace('`', '"', $v); |
|
| 1382 | - $i = $nom . preg_replace("/KEY +/", '_', $n); |
|
| 1383 | - if ($k != $n) { |
|
| 1384 | - $i = "\"$i\""; |
|
| 1385 | - } |
|
| 1386 | - $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
|
| 1387 | - } elseif (strpos($k, "UNIQUE ") === 0) { |
|
| 1388 | - $k = preg_replace("/^UNIQUE +/", '', $k); |
|
| 1389 | - $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)"; |
|
| 1390 | - } else { |
|
| 1391 | - $prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)"; |
|
| 1392 | - } |
|
| 1393 | - if ($k == "PRIMARY KEY") { |
|
| 1394 | - $prim_name = $v; |
|
| 1395 | - } |
|
| 1396 | - $s = ","; |
|
| 1397 | - } |
|
| 1398 | - $s = ''; |
|
| 1399 | - |
|
| 1400 | - $character_set = ""; |
|
| 1401 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 1402 | - $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 1403 | - } |
|
| 1404 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 1405 | - $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1406 | - } |
|
| 1407 | - |
|
| 1408 | - foreach ($champs as $k => $v) { |
|
| 1409 | - $k = str_replace('`', '"', $k); |
|
| 1410 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 1411 | - if (preg_match(',(char|text),i', $defs[1]) and !preg_match(',binary,i', $defs[1])) { |
|
| 1412 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 1413 | - } |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - $query .= "$s\n\t\t$k " |
|
| 1417 | - . (($autoinc && ($prim_name == $k) && preg_match(',\b(big|small|medium|tiny)?int\b,i', $v)) |
|
| 1418 | - ? " bigserial" |
|
| 1419 | - : mysql2pg_type($v) |
|
| 1420 | - ); |
|
| 1421 | - $s = ","; |
|
| 1422 | - } |
|
| 1423 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 1424 | - |
|
| 1425 | - // En l'absence de "if not exists" en PG, on neutralise les erreurs |
|
| 1426 | - |
|
| 1427 | - $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ")" . |
|
| 1428 | - ($character_set ? " DEFAULT $character_set" : "") |
|
| 1429 | - . "\n"; |
|
| 1430 | - |
|
| 1431 | - if (!$requeter) { |
|
| 1432 | - return $q; |
|
| 1433 | - } |
|
| 1434 | - $connexion['last'] = $q; |
|
| 1435 | - $r = @pg_query($link, $q); |
|
| 1436 | - |
|
| 1437 | - if (!$r) { |
|
| 1438 | - spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR); |
|
| 1439 | - } else { |
|
| 1440 | - foreach ($keys as $index) { |
|
| 1441 | - pg_query($link, $index); |
|
| 1442 | - } |
|
| 1443 | - } |
|
| 1444 | - |
|
| 1445 | - return $r; |
|
| 1365 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1366 | + $link = $connexion['link']; |
|
| 1367 | + $nom = prefixer_table_spip($nom, $connexion['prefixe']); |
|
| 1368 | + |
|
| 1369 | + $query = $prim = $prim_name = $v = $s = $p = ''; |
|
| 1370 | + $keys = array(); |
|
| 1371 | + |
|
| 1372 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 1373 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 1374 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 1375 | + return; |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + foreach ($cles as $k => $v) { |
|
| 1379 | + if (strpos($k, "KEY ") === 0) { |
|
| 1380 | + $n = str_replace('`', '', $k); |
|
| 1381 | + $v = str_replace('`', '"', $v); |
|
| 1382 | + $i = $nom . preg_replace("/KEY +/", '_', $n); |
|
| 1383 | + if ($k != $n) { |
|
| 1384 | + $i = "\"$i\""; |
|
| 1385 | + } |
|
| 1386 | + $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
|
| 1387 | + } elseif (strpos($k, "UNIQUE ") === 0) { |
|
| 1388 | + $k = preg_replace("/^UNIQUE +/", '', $k); |
|
| 1389 | + $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)"; |
|
| 1390 | + } else { |
|
| 1391 | + $prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)"; |
|
| 1392 | + } |
|
| 1393 | + if ($k == "PRIMARY KEY") { |
|
| 1394 | + $prim_name = $v; |
|
| 1395 | + } |
|
| 1396 | + $s = ","; |
|
| 1397 | + } |
|
| 1398 | + $s = ''; |
|
| 1399 | + |
|
| 1400 | + $character_set = ""; |
|
| 1401 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 1402 | + $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 1403 | + } |
|
| 1404 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 1405 | + $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1406 | + } |
|
| 1407 | + |
|
| 1408 | + foreach ($champs as $k => $v) { |
|
| 1409 | + $k = str_replace('`', '"', $k); |
|
| 1410 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 1411 | + if (preg_match(',(char|text),i', $defs[1]) and !preg_match(',binary,i', $defs[1])) { |
|
| 1412 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 1413 | + } |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + $query .= "$s\n\t\t$k " |
|
| 1417 | + . (($autoinc && ($prim_name == $k) && preg_match(',\b(big|small|medium|tiny)?int\b,i', $v)) |
|
| 1418 | + ? " bigserial" |
|
| 1419 | + : mysql2pg_type($v) |
|
| 1420 | + ); |
|
| 1421 | + $s = ","; |
|
| 1422 | + } |
|
| 1423 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 1424 | + |
|
| 1425 | + // En l'absence de "if not exists" en PG, on neutralise les erreurs |
|
| 1426 | + |
|
| 1427 | + $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ")" . |
|
| 1428 | + ($character_set ? " DEFAULT $character_set" : "") |
|
| 1429 | + . "\n"; |
|
| 1430 | + |
|
| 1431 | + if (!$requeter) { |
|
| 1432 | + return $q; |
|
| 1433 | + } |
|
| 1434 | + $connexion['last'] = $q; |
|
| 1435 | + $r = @pg_query($link, $q); |
|
| 1436 | + |
|
| 1437 | + if (!$r) { |
|
| 1438 | + spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR); |
|
| 1439 | + } else { |
|
| 1440 | + foreach ($keys as $index) { |
|
| 1441 | + pg_query($link, $index); |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | + |
|
| 1445 | + return $r; |
|
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | |
| 1449 | 1449 | function spip_pg_create_base($nom, $serveur = '', $requeter = true) { |
| 1450 | - return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter); |
|
| 1450 | + return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter); |
|
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | // Fonction de creation d'une vue SQL nommee $nom |
| 1454 | 1454 | // https://code.spip.net/@spip_pg_create_view |
| 1455 | 1455 | function spip_pg_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 1456 | - if (!$query_select) { |
|
| 1457 | - return false; |
|
| 1458 | - } |
|
| 1459 | - // vue deja presente |
|
| 1460 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 1461 | - if ($requeter) { |
|
| 1462 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR); |
|
| 1463 | - } |
|
| 1456 | + if (!$query_select) { |
|
| 1457 | + return false; |
|
| 1458 | + } |
|
| 1459 | + // vue deja presente |
|
| 1460 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 1461 | + if ($requeter) { |
|
| 1462 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR); |
|
| 1463 | + } |
|
| 1464 | 1464 | |
| 1465 | - return false; |
|
| 1466 | - } |
|
| 1465 | + return false; |
|
| 1466 | + } |
|
| 1467 | 1467 | |
| 1468 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 1468 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 1469 | 1469 | |
| 1470 | - return spip_pg_query($query, $serveur, $requeter); |
|
| 1470 | + return spip_pg_query($query, $serveur, $requeter); |
|
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | 1473 | |
| 1474 | 1474 | // https://code.spip.net/@spip_pg_set_connect_charset |
| 1475 | 1475 | function spip_pg_set_connect_charset($charset, $serveur = '', $requeter = true) { |
| 1476 | - spip_log("changement de charset sql a ecrire en PG", 'pg.' . _LOG_ERREUR); |
|
| 1476 | + spip_log("changement de charset sql a ecrire en PG", 'pg.' . _LOG_ERREUR); |
|
| 1477 | 1477 | } |
| 1478 | 1478 | |
| 1479 | 1479 | |
@@ -1487,7 +1487,7 @@ discard block |
||
| 1487 | 1487 | **/ |
| 1488 | 1488 | // https://code.spip.net/@spip_sqlite_optimize |
| 1489 | 1489 | function spip_pg_optimize($table, $serveur = '', $requeter = true) { |
| 1490 | - return spip_pg_query("VACUUM " . $table, $serveur, $requeter); |
|
| 1490 | + return spip_pg_query("VACUUM " . $table, $serveur, $requeter); |
|
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | 1493 | // Selectionner la sous-chaine dans $objet |
@@ -1495,13 +1495,13 @@ discard block |
||
| 1495 | 1495 | |
| 1496 | 1496 | // https://code.spip.net/@spip_pg_multi |
| 1497 | 1497 | function spip_pg_multi($objet, $lang) { |
| 1498 | - $r = "regexp_replace(" |
|
| 1499 | - . $objet |
|
| 1500 | - . ",'<multi>.*[[]" |
|
| 1501 | - . $lang |
|
| 1502 | - . "[]]([^[]*).*</multi>', E'\\\\1') AS multi"; |
|
| 1498 | + $r = "regexp_replace(" |
|
| 1499 | + . $objet |
|
| 1500 | + . ",'<multi>.*[[]" |
|
| 1501 | + . $lang |
|
| 1502 | + . "[]]([^[]*).*</multi>', E'\\\\1') AS multi"; |
|
| 1503 | 1503 | |
| 1504 | - return $r; |
|
| 1504 | + return $r; |
|
| 1505 | 1505 | } |
| 1506 | 1506 | |
| 1507 | 1507 | // Palanquee d'idiosyncrasies MySQL dans les creations de table |
@@ -1509,31 +1509,31 @@ discard block |
||
| 1509 | 1509 | |
| 1510 | 1510 | // https://code.spip.net/@mysql2pg_type |
| 1511 | 1511 | function mysql2pg_type($v) { |
| 1512 | - $remplace = array( |
|
| 1513 | - '/auto_increment/i' => '', // non reconnu |
|
| 1514 | - '/bigint/i' => 'bigint', |
|
| 1515 | - '/mediumint/i' => 'mediumint', |
|
| 1516 | - '/smallint/i' => 'smallint', |
|
| 1517 | - "/tinyint/i" => 'int', |
|
| 1518 | - '/int\s*[(]\s*\d+\s*[)]/i' => 'int', |
|
| 1519 | - "/longtext/i" => 'text', |
|
| 1520 | - "/mediumtext/i" => 'text', |
|
| 1521 | - "/tinytext/i" => 'text', |
|
| 1522 | - "/longblob/i" => 'text', |
|
| 1523 | - "/0000-00-00/" => '0001-01-01', |
|
| 1524 | - "/datetime/i" => 'timestamp', |
|
| 1525 | - "/unsigned/i" => '', |
|
| 1526 | - "/double/i" => 'double precision', |
|
| 1527 | - '/VARCHAR\((\d+)\)\s+BINARY/i' => 'varchar(\1)', |
|
| 1528 | - "/ENUM *[(][^)]*[)]/i" => "varchar(255)", |
|
| 1529 | - '/(timestamp .* )ON .*$/is' => '\\1', |
|
| 1530 | - ); |
|
| 1531 | - |
|
| 1532 | - return preg_replace(array_keys($remplace), array_values($remplace), $v); |
|
| 1512 | + $remplace = array( |
|
| 1513 | + '/auto_increment/i' => '', // non reconnu |
|
| 1514 | + '/bigint/i' => 'bigint', |
|
| 1515 | + '/mediumint/i' => 'mediumint', |
|
| 1516 | + '/smallint/i' => 'smallint', |
|
| 1517 | + "/tinyint/i" => 'int', |
|
| 1518 | + '/int\s*[(]\s*\d+\s*[)]/i' => 'int', |
|
| 1519 | + "/longtext/i" => 'text', |
|
| 1520 | + "/mediumtext/i" => 'text', |
|
| 1521 | + "/tinytext/i" => 'text', |
|
| 1522 | + "/longblob/i" => 'text', |
|
| 1523 | + "/0000-00-00/" => '0001-01-01', |
|
| 1524 | + "/datetime/i" => 'timestamp', |
|
| 1525 | + "/unsigned/i" => '', |
|
| 1526 | + "/double/i" => 'double precision', |
|
| 1527 | + '/VARCHAR\((\d+)\)\s+BINARY/i' => 'varchar(\1)', |
|
| 1528 | + "/ENUM *[(][^)]*[)]/i" => "varchar(255)", |
|
| 1529 | + '/(timestamp .* )ON .*$/is' => '\\1', |
|
| 1530 | + ); |
|
| 1531 | + |
|
| 1532 | + return preg_replace(array_keys($remplace), array_values($remplace), $v); |
|
| 1533 | 1533 | } |
| 1534 | 1534 | |
| 1535 | 1535 | // Renvoie false si on n'a pas les fonctions pg (pour l'install) |
| 1536 | 1536 | // https://code.spip.net/@spip_versions_pg |
| 1537 | 1537 | function spip_versions_pg() { |
| 1538 | - return function_exists('pg_connect'); |
|
| 1538 | + return function_exists('pg_connect'); |
|
| 1539 | 1539 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | if (!$link) { |
| 66 | 66 | $erreurs[] = pg_last_error(); |
| 67 | 67 | foreach ($erreurs as $e) { |
| 68 | - spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS); |
|
| 68 | + spip_log('Echec pg_connect. Erreur : '.$e, 'pg.'._LOG_HS); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | return false; |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | ); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - spip_log("Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'), |
|
| 86 | - 'pg.' . _LOG_DEBUG); |
|
| 85 | + spip_log("Connexion vers $host, base $db, prefixe $prefixe ".($link ? 'operationnelle' : 'impossible'), |
|
| 86 | + 'pg.'._LOG_DEBUG); |
|
| 87 | 87 | |
| 88 | 88 | return !$link ? false : array( |
| 89 | 89 | 'db' => $db, |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | } else { |
| 173 | 173 | $suite = ''; |
| 174 | 174 | } |
| 175 | - $query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 175 | + $query = preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query).$suite; |
|
| 176 | 176 | |
| 177 | 177 | // renvoyer la requete inerte si demandee |
| 178 | 178 | if (!$requeter) { |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | // ou revoir l'api de sql_alter en creant un |
| 243 | 243 | // sql_alter_table($table,array($actions)); |
| 244 | 244 | if (!preg_match("/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is", $query, $regs)) { |
| 245 | - spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR); |
|
| 245 | + spip_log("$query mal comprise", 'pg.'._LOG_ERREUR); |
|
| 246 | 246 | |
| 247 | 247 | return false; |
| 248 | 248 | } |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | $i = 0; |
| 256 | 256 | $ouverte = false; |
| 257 | 257 | while ($do = array_shift($todo)) { |
| 258 | - $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . "," . $do : $do; |
|
| 258 | + $todo2[$i] = isset($todo2[$i]) ? $todo2[$i].",".$do : $do; |
|
| 259 | 259 | $o = (false !== strpos($do, "(")); |
| 260 | 260 | $f = (false !== strpos($do, ")")); |
| 261 | 261 | if ($o and !$f) { |
@@ -268,24 +268,24 @@ discard block |
||
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | $todo = $todo2; |
| 271 | - $query = $debut . ' ' . array_shift($todo); |
|
| 271 | + $query = $debut.' '.array_shift($todo); |
|
| 272 | 272 | |
| 273 | 273 | if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) { |
| 274 | - spip_log("$query incompris", 'pg.' . _LOG_ERREUR); |
|
| 274 | + spip_log("$query incompris", 'pg.'._LOG_ERREUR); |
|
| 275 | 275 | } else { |
| 276 | 276 | if ($r[1]) { |
| 277 | - spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 277 | + spip_log("j'ignore IGNORE dans $query", 'pg.'._LOG_AVERTISSEMENT); |
|
| 278 | 278 | } |
| 279 | - $f = 'spip_pg_alter_' . strtolower($r[3]); |
|
| 279 | + $f = 'spip_pg_alter_'.strtolower($r[3]); |
|
| 280 | 280 | if (function_exists($f)) { |
| 281 | 281 | $f($r[2], $r[4], $serveur, $requeter); |
| 282 | 282 | } else { |
| 283 | - spip_log("$query non prevu", 'pg.' . _LOG_ERREUR); |
|
| 283 | + spip_log("$query non prevu", 'pg.'._LOG_ERREUR); |
|
| 284 | 284 | } |
| 285 | 285 | } |
| 286 | 286 | // Alter a plusieurs args. Faudrait optimiser. |
| 287 | 287 | if ($todo) { |
| 288 | - spip_pg_alter("TABLE $table " . join(',', $todo)); |
|
| 288 | + spip_pg_alter("TABLE $table ".join(',', $todo)); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | } |
@@ -293,10 +293,10 @@ discard block |
||
| 293 | 293 | // https://code.spip.net/@spip_pg_alter_change |
| 294 | 294 | function spip_pg_alter_change($table, $arg, $serveur = '', $requeter = true) { |
| 295 | 295 | if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) { |
| 296 | - spip_log("alter change: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 296 | + spip_log("alter change: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 297 | 297 | } else { |
| 298 | 298 | list(, $old, $new, $type, $default, $null, $def2) = $r; |
| 299 | - $actions = array("ALTER $old TYPE " . mysql2pg_type($type)); |
|
| 299 | + $actions = array("ALTER $old TYPE ".mysql2pg_type($type)); |
|
| 300 | 300 | if ($null) { |
| 301 | 301 | $actions[] = "ALTER $old SET NOT NULL"; |
| 302 | 302 | } else { |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | $actions[] = "ALTER $old DROP DEFAULT"; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - spip_pg_query("ALTER TABLE $table " . join(', ', $actions)); |
|
| 312 | + spip_pg_query("ALTER TABLE $table ".join(', ', $actions)); |
|
| 313 | 313 | |
| 314 | 314 | if ($old != $new) { |
| 315 | 315 | spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur); |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | // https://code.spip.net/@spip_pg_alter_add |
| 321 | 321 | function spip_pg_alter_add($table, $arg, $serveur = '', $requeter = true) { |
| 322 | 322 | if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) { |
| 323 | - spip_log("alter add $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 323 | + spip_log("alter add $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 324 | 324 | |
| 325 | 325 | return null; |
| 326 | 326 | } |
@@ -330,13 +330,13 @@ discard block |
||
| 330 | 330 | $m[2] = $n[1]; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 333 | + return spip_pg_query("ALTER TABLE $table ADD ".$m[1].' '.mysql2pg_type($m[2]), $serveur, $requeter); |
|
| 334 | 334 | } elseif ($r[1][0] == 'P') { |
| 335 | 335 | // la primary peut etre sur plusieurs champs |
| 336 | 336 | $r[2] = trim(str_replace('`', '', $r[2])); |
| 337 | 337 | $m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2]; |
| 338 | 338 | |
| 339 | - return spip_pg_query("ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')', $serveur, |
|
| 339 | + return spip_pg_query("ALTER TABLE $table ADD CONSTRAINT $table".'_pkey PRIMARY KEY ('.$m.')', $serveur, |
|
| 340 | 340 | $requeter); |
| 341 | 341 | } else { |
| 342 | 342 | preg_match('/([^\s,]*)\s*(.*)?/', $r[2], $m); |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | $colonnes = substr($m[1], 1, -1); |
| 354 | 354 | if (false !== strpos(",", $colonnes)) { |
| 355 | 355 | spip_log("PG : Erreur, impossible de creer un index sur plusieurs colonnes" |
| 356 | - . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR); |
|
| 356 | + . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.'._LOG_ERREUR); |
|
| 357 | 357 | } else { |
| 358 | 358 | $nom_index = $colonnes; |
| 359 | 359 | } |
@@ -370,23 +370,23 @@ discard block |
||
| 370 | 370 | // https://code.spip.net/@spip_pg_alter_drop |
| 371 | 371 | function spip_pg_alter_drop($table, $arg, $serveur = '', $requeter = true) { |
| 372 | 372 | if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) { |
| 373 | - spip_log("alter drop: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 373 | + spip_log("alter drop: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 374 | 374 | } else { |
| 375 | 375 | if (!$r[1] or $r[1] == 'COLUMN') { |
| 376 | - return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur); |
|
| 376 | + return spip_pg_query("ALTER TABLE $table DROP ".$r[2], $serveur); |
|
| 377 | 377 | } elseif ($r[1][0] == 'P') { |
| 378 | - return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur); |
|
| 378 | + return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table".'_pkey', $serveur); |
|
| 379 | 379 | } else { |
| 380 | - return spip_pg_query("DROP INDEX " . $table . '_' . $r[2], $serveur); |
|
| 380 | + return spip_pg_query("DROP INDEX ".$table.'_'.$r[2], $serveur); |
|
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | function spip_pg_alter_modify($table, $arg, $serveur = '', $requeter = true) { |
| 386 | 386 | if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) { |
| 387 | - spip_log("alter modify: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 387 | + spip_log("alter modify: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 388 | 388 | } else { |
| 389 | - return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true); |
|
| 389 | + return spip_pg_alter_change($table, $r[1].' '.$arg, $serveur = '', $requeter = true); |
|
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | } elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) { |
| 403 | 403 | $rename = $r[2]; |
| 404 | 404 | } else { |
| 405 | - spip_log("alter rename: $arg incompris", 'pg.' . _LOG_ERREUR); |
|
| 405 | + spip_log("alter rename: $arg incompris", 'pg.'._LOG_ERREUR); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false; |
@@ -422,8 +422,8 @@ discard block |
||
| 422 | 422 | */ |
| 423 | 423 | function spip_pg_create_index($nom, $table, $champs, $serveur = '', $requeter = true) { |
| 424 | 424 | if (!($nom or $table or $champs)) { |
| 425 | - spip_log("Champ manquant pour creer un index pg ($nom, $table, (" . @join(',', $champs) . "))", |
|
| 426 | - 'pg.' . _LOG_ERREUR); |
|
| 425 | + spip_log("Champ manquant pour creer un index pg ($nom, $table, (".@join(',', $champs)."))", |
|
| 426 | + 'pg.'._LOG_ERREUR); |
|
| 427 | 427 | |
| 428 | 428 | return false; |
| 429 | 429 | } |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | |
| 434 | 434 | // PG ne differentie pas noms des index en fonction des tables |
| 435 | 435 | // il faut donc creer des noms uniques d'index pour une base pg |
| 436 | - $nom = $table . '_' . $nom; |
|
| 436 | + $nom = $table.'_'.$nom; |
|
| 437 | 437 | // enlever d'eventuelles parentheses deja presentes sur champs |
| 438 | 438 | if (!is_array($champs)) { |
| 439 | 439 | if ($champs[0] == "(") { |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | } |
| 442 | 442 | $champs = array($champs); |
| 443 | 443 | } |
| 444 | - $query = "CREATE INDEX $nom ON $table (" . join(',', $champs) . ")"; |
|
| 444 | + $query = "CREATE INDEX $nom ON $table (".join(',', $champs).")"; |
|
| 445 | 445 | if (!$requeter) { |
| 446 | 446 | return $query; |
| 447 | 447 | } |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | } else { |
| 466 | 466 | $suite = ''; |
| 467 | 467 | } |
| 468 | - $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite; |
|
| 468 | + $query = 'EXPLAIN '.preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query).$suite; |
|
| 469 | 469 | |
| 470 | 470 | if (!$requeter) { |
| 471 | 471 | return $query; |
@@ -560,14 +560,14 @@ discard block |
||
| 560 | 560 | } |
| 561 | 561 | } |
| 562 | 562 | $from = spip_pg_from($from, $prefixe); |
| 563 | - $query = "SELECT " . $select |
|
| 563 | + $query = "SELECT ".$select |
|
| 564 | 564 | . (!$from ? '' : "\nFROM $from") |
| 565 | - . (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join("\n\tAND ", |
|
| 565 | + . (!$where ? '' : ("\nWHERE ".(!is_array($where) ? calculer_pg_where($where) : (join("\n\tAND ", |
|
| 566 | 566 | array_map('calculer_pg_where', $where)))))) |
| 567 | 567 | . spip_pg_groupby($groupby, $from, $select) |
| 568 | 568 | . (!$having ? '' : "\nHAVING $having") |
| 569 | 569 | . ($orderby ? ("\nORDER BY $orderby") : '') |
| 570 | - . (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset"))); |
|
| 570 | + . (!$limit ? '' : (" LIMIT $count".(!$offset ? '' : " OFFSET $offset"))); |
|
| 571 | 571 | |
| 572 | 572 | // renvoyer la requete inerte si demandee |
| 573 | 573 | if ($requeter === false) { |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | |
| 577 | 577 | $r = spip_pg_trace_query($query, $serveur); |
| 578 | 578 | |
| 579 | - return $r ? $r : $query;; |
|
| 579 | + return $r ? $r : $query; ; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | // Le traitement des prefixes de table dans un Select se limite au FROM |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | $from = spip_pg_select_as($from); |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from); |
|
| 591 | + return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1'.$prefixe.'_', $from); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | // https://code.spip.net/@spip_pg_orderby |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order)); |
| 598 | 598 | |
| 599 | 599 | foreach ($arg as $v) { |
| 600 | - if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m)) { |
|
| 600 | + if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+'.$v.'/', $select, $m)) { |
|
| 601 | 601 | |
| 602 | 602 | $res[] = $m[1]; |
| 603 | 603 | } else { |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | $n++; |
| 759 | 759 | $res .= "\nwhen $index=$v then $n"; |
| 760 | 760 | } |
| 761 | - $arg = $m[1] . "case $res else 0 end " |
|
| 761 | + $arg = $m[1]."case $res else 0 end " |
|
| 762 | 762 | . substr($arg, strlen($m[0])); |
| 763 | 763 | } |
| 764 | 764 | |
@@ -803,9 +803,9 @@ discard block |
||
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | if (strtoupper($join) === 'AND') { |
| 806 | - return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 806 | + return $exp.join("\n\t$join ", array_map('calculer_pg_where', $v)); |
|
| 807 | 807 | } else { |
| 808 | - return $exp . join($join, $v); |
|
| 808 | + return $exp.join($join, $v); |
|
| 809 | 809 | } |
| 810 | 810 | } |
| 811 | 811 | |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | if (substr($k, -1) == '@') { |
| 817 | 817 | // c'est une jointure qui se refere au from precedent |
| 818 | 818 | // pas de virgule |
| 819 | - $argsas .= ' ' . $v; |
|
| 819 | + $argsas .= ' '.$v; |
|
| 820 | 820 | } else { |
| 821 | 821 | $as = ''; |
| 822 | 822 | // spip_log("$k : $v", _LOG_DEBUG); |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | } elseif ($v != $k) { |
| 827 | 827 | $p = strpos($v, " "); |
| 828 | 828 | if ($p) { |
| 829 | - $v = substr($v, 0, $p) . " AS $k" . substr($v, $p); |
|
| 829 | + $v = substr($v, 0, $p)." AS $k".substr($v, $p); |
|
| 830 | 830 | } else { |
| 831 | 831 | $as = " AS $k"; |
| 832 | 832 | } |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | // spip_log("subs $k : $v avec $as", _LOG_DEBUG); |
| 836 | 836 | // if (strpos($v, 'JOIN') === false) $argsas .= ', '; |
| 837 | - $argsas .= ', ' . $v . $as; |
|
| 837 | + $argsas .= ', '.$v.$as; |
|
| 838 | 838 | } |
| 839 | 839 | } |
| 840 | 840 | |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | $serveur = '', |
| 868 | 868 | $requeter = true |
| 869 | 869 | ) { |
| 870 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 870 | + $c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 871 | 871 | $r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
| 872 | 872 | if (!$requeter) { |
| 873 | 873 | return $r; |
@@ -971,7 +971,7 @@ discard block |
||
| 971 | 971 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
| 972 | 972 | $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
| 973 | 973 | |
| 974 | - return spip_pg_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 974 | + return spip_pg_insert($table, "(".join(',', array_keys($couples)).")", "(".join(',', $couples).")", $desc, |
|
| 975 | 975 | $serveur, $requeter); |
| 976 | 976 | } |
| 977 | 977 | |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | $c = isset($tab_couples[0]) ? $tab_couples[0] : array(); |
| 993 | 993 | $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur); |
| 994 | 994 | |
| 995 | - $cles = "(" . join(',', array_keys($les_cles)) . ')'; |
|
| 995 | + $cles = "(".join(',', array_keys($les_cles)).')'; |
|
| 996 | 996 | $valeurs = array(); |
| 997 | 997 | foreach ($tab_couples as $couples) { |
| 998 | 998 | foreach ($couples as $champ => $val) { |
@@ -1001,7 +1001,7 @@ discard block |
||
| 1001 | 1001 | // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci |
| 1002 | 1002 | $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur); |
| 1003 | 1003 | |
| 1004 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1004 | + $valeurs[] = '('.join(',', $couples).')'; |
|
| 1005 | 1005 | } |
| 1006 | 1006 | $valeurs = implode(', ', $valeurs); |
| 1007 | 1007 | |
@@ -1023,7 +1023,7 @@ discard block |
||
| 1023 | 1023 | |
| 1024 | 1024 | $set = array(); |
| 1025 | 1025 | foreach ($couples as $champ => $val) { |
| 1026 | - $set[] = $champ . '=' . $val; |
|
| 1026 | + $set[] = $champ.'='.$val; |
|
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | 1029 | $query = calculer_pg_expression('UPDATE', $table, ',') |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | // https://code.spip.net/@spip_pg_replace |
| 1061 | 1061 | function spip_pg_replace($table, $values, $desc, $serveur = '', $requeter = true) { |
| 1062 | 1062 | if (!$values) { |
| 1063 | - spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1063 | + spip_log("replace vide $table", 'pg.'._LOG_AVERTISSEMENT); |
|
| 1064 | 1064 | |
| 1065 | 1065 | return 0; |
| 1066 | 1066 | } |
@@ -1092,7 +1092,7 @@ discard block |
||
| 1092 | 1092 | |
| 1093 | 1093 | $where = join(' AND ', $prims); |
| 1094 | 1094 | if (!$where) { |
| 1095 | - return spip_pg_insert($table, "(" . join(',', array_keys($values)) . ")", "(" . join(',', $values) . ")", $desc, |
|
| 1095 | + return spip_pg_insert($table, "(".join(',', array_keys($values)).")", "(".join(',', $values).")", $desc, |
|
| 1096 | 1096 | $serveur); |
| 1097 | 1097 | } |
| 1098 | 1098 | $couples = join(',', $noprims); |
@@ -1111,10 +1111,9 @@ discard block |
||
| 1111 | 1111 | $couples = pg_affected_rows($couples); |
| 1112 | 1112 | } |
| 1113 | 1113 | if (!$couples) { |
| 1114 | - $ret = !$seq ? '' : |
|
| 1115 | - (" RETURNING nextval('$seq') < $prim"); |
|
| 1116 | - $connexion['last'] = $q = "INSERT INTO $table (" . join(',', array_keys($values)) . ') VALUES (' . join(',', |
|
| 1117 | - $values) . ")$ret"; |
|
| 1114 | + $ret = !$seq ? '' : (" RETURNING nextval('$seq') < $prim"); |
|
| 1115 | + $connexion['last'] = $q = "INSERT INTO $table (".join(',', array_keys($values)).') VALUES ('.join(',', |
|
| 1116 | + $values).")$ret"; |
|
| 1118 | 1117 | $couples = spip_pg_query_simple($link, $q); |
| 1119 | 1118 | if (!$couples) { |
| 1120 | 1119 | return false; |
@@ -1162,7 +1161,7 @@ discard block |
||
| 1162 | 1161 | ) { |
| 1163 | 1162 | return ''; |
| 1164 | 1163 | } else { |
| 1165 | - return $raw ? $prim : $table . '_' . $prim . "_seq"; |
|
| 1164 | + return $raw ? $prim : $table.'_'.$prim."_seq"; |
|
| 1166 | 1165 | } |
| 1167 | 1166 | } |
| 1168 | 1167 | |
@@ -1180,22 +1179,22 @@ discard block |
||
| 1180 | 1179 | return spip_pg_frommysql($v); |
| 1181 | 1180 | } else { |
| 1182 | 1181 | if (strncmp($v, '0000', 4) == 0) { |
| 1183 | - $v = "0001" . substr($v, 4); |
|
| 1182 | + $v = "0001".substr($v, 4); |
|
| 1184 | 1183 | } |
| 1185 | 1184 | if (strpos($v, "-00-00") === 4) { |
| 1186 | - $v = substr($v, 0, 4) . "-01-01" . substr($v, 10); |
|
| 1185 | + $v = substr($v, 0, 4)."-01-01".substr($v, 10); |
|
| 1187 | 1186 | } |
| 1188 | 1187 | |
| 1189 | 1188 | return "timestamp '$v'"; |
| 1190 | 1189 | } |
| 1191 | 1190 | } elseif (!sql_test_int($t)) { |
| 1192 | - return ("'" . pg_escape_string($v) . "'"); |
|
| 1191 | + return ("'".pg_escape_string($v)."'"); |
|
| 1193 | 1192 | } elseif (is_numeric($v) or (strpos($v, 'CAST(') === 0)) { |
| 1194 | 1193 | return $v; |
| 1195 | 1194 | } elseif ($v[0] == '0' and $v[1] !== 'x' and ctype_xdigit(substr($v, 1))) { |
| 1196 | 1195 | return substr($v, 1); |
| 1197 | 1196 | } else { |
| 1198 | - spip_log("Warning: '$v' n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT); |
|
| 1197 | + spip_log("Warning: '$v' n'est pas de type $t", 'pg.'._LOG_AVERTISSEMENT); |
|
| 1199 | 1198 | |
| 1200 | 1199 | return intval($v); |
| 1201 | 1200 | } |
@@ -1203,7 +1202,7 @@ discard block |
||
| 1203 | 1202 | |
| 1204 | 1203 | // https://code.spip.net/@spip_pg_hex |
| 1205 | 1204 | function spip_pg_hex($v) { |
| 1206 | - return "CAST(x'" . $v . "' as bigint)"; |
|
| 1205 | + return "CAST(x'".$v."' as bigint)"; |
|
| 1207 | 1206 | } |
| 1208 | 1207 | |
| 1209 | 1208 | function spip_pg_quote($v, $type = '') { |
@@ -1242,15 +1241,15 @@ discard block |
||
| 1242 | 1241 | return $not ? '0=0' : '0=1'; |
| 1243 | 1242 | } |
| 1244 | 1243 | if (strpos($valeurs, "CAST(x'") !== false) { |
| 1245 | - return "($val=" . join("OR $val=", explode(',', $valeurs)) . ')'; |
|
| 1244 | + return "($val=".join("OR $val=", explode(',', $valeurs)).')'; |
|
| 1246 | 1245 | } |
| 1247 | 1246 | $n = $i = 0; |
| 1248 | 1247 | $in_sql = ""; |
| 1249 | 1248 | while ($n = strpos($valeurs, ',', $n + 1)) { |
| 1250 | 1249 | if ((++$i) >= 255) { |
| 1251 | - $in_sql .= "($val $not IN (" . |
|
| 1252 | - substr($valeurs, 0, $n) . |
|
| 1253 | - "))\n" . |
|
| 1250 | + $in_sql .= "($val $not IN (". |
|
| 1251 | + substr($valeurs, 0, $n). |
|
| 1252 | + "))\n". |
|
| 1254 | 1253 | ($not ? "AND\t" : "OR\t"); |
| 1255 | 1254 | $valeurs = substr($valeurs, $n + 1); |
| 1256 | 1255 | $i = $n = 0; |
@@ -1267,7 +1266,7 @@ discard block |
||
| 1267 | 1266 | $s = $link ? pg_last_error($link) : pg_last_error(); |
| 1268 | 1267 | if ($s) { |
| 1269 | 1268 | $s = str_replace('ERROR', 'errcode: 1000 ', $s); |
| 1270 | - spip_log("$s - $query", 'pg.' . _LOG_ERREUR); |
|
| 1269 | + spip_log("$s - $query", 'pg.'._LOG_ERREUR); |
|
| 1271 | 1270 | } |
| 1272 | 1271 | |
| 1273 | 1272 | return $s; |
@@ -1318,7 +1317,7 @@ discard block |
||
| 1318 | 1317 | function spip_pg_showbase($match, $serveur = '', $requeter = true) { |
| 1319 | 1318 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 1320 | 1319 | $link = $connexion['link']; |
| 1321 | - $connexion['last'] = $q = "SELECT tablename FROM pg_tables WHERE tablename ILIKE " . _q($match); |
|
| 1320 | + $connexion['last'] = $q = "SELECT tablename FROM pg_tables WHERE tablename ILIKE "._q($match); |
|
| 1322 | 1321 | |
| 1323 | 1322 | return spip_pg_query_simple($link, $q); |
| 1324 | 1323 | } |
@@ -1327,7 +1326,7 @@ discard block |
||
| 1327 | 1326 | function spip_pg_showtable($nom_table, $serveur = '', $requeter = true) { |
| 1328 | 1327 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 1329 | 1328 | $link = $connexion['link']; |
| 1330 | - $connexion['last'] = $q = "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE " . _q($nom_table); |
|
| 1329 | + $connexion['last'] = $q = "SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE "._q($nom_table); |
|
| 1331 | 1330 | |
| 1332 | 1331 | $res = spip_pg_query_simple($link, $q); |
| 1333 | 1332 | if (!$res) { |
@@ -1338,15 +1337,15 @@ discard block |
||
| 1338 | 1337 | // il faut en tenir compte dans le return |
| 1339 | 1338 | $fields = array(); |
| 1340 | 1339 | while ($field = pg_fetch_array($res, null, PGSQL_NUM)) { |
| 1341 | - $fields[$field[0]] = $field[2] . (!$field[1] ? '' : (" DEFAULT " . $field[1])); |
|
| 1340 | + $fields[$field[0]] = $field[2].(!$field[1] ? '' : (" DEFAULT ".$field[1])); |
|
| 1342 | 1341 | } |
| 1343 | - $connexion['last'] = $q = "SELECT indexdef FROM pg_indexes WHERE tablename ILIKE " . _q($nom_table); |
|
| 1342 | + $connexion['last'] = $q = "SELECT indexdef FROM pg_indexes WHERE tablename ILIKE "._q($nom_table); |
|
| 1344 | 1343 | $res = spip_pg_query_simple($link, $q); |
| 1345 | 1344 | $keys = array(); |
| 1346 | 1345 | while ($index = pg_fetch_array($res, null, PGSQL_NUM)) { |
| 1347 | 1346 | if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) { |
| 1348 | - $nom = str_replace($nom_table . '_', '', $r[2]); |
|
| 1349 | - $keys[($r[1] ? "PRIMARY KEY" : ("KEY " . $nom))] = $r[3]; |
|
| 1347 | + $nom = str_replace($nom_table.'_', '', $r[2]); |
|
| 1348 | + $keys[($r[1] ? "PRIMARY KEY" : ("KEY ".$nom))] = $r[3]; |
|
| 1350 | 1349 | } |
| 1351 | 1350 | } |
| 1352 | 1351 | |
@@ -1379,16 +1378,16 @@ discard block |
||
| 1379 | 1378 | if (strpos($k, "KEY ") === 0) { |
| 1380 | 1379 | $n = str_replace('`', '', $k); |
| 1381 | 1380 | $v = str_replace('`', '"', $v); |
| 1382 | - $i = $nom . preg_replace("/KEY +/", '_', $n); |
|
| 1381 | + $i = $nom.preg_replace("/KEY +/", '_', $n); |
|
| 1383 | 1382 | if ($k != $n) { |
| 1384 | 1383 | $i = "\"$i\""; |
| 1385 | 1384 | } |
| 1386 | 1385 | $keys[] = "CREATE INDEX $i ON $nom ($v);"; |
| 1387 | 1386 | } elseif (strpos($k, "UNIQUE ") === 0) { |
| 1388 | 1387 | $k = preg_replace("/^UNIQUE +/", '', $k); |
| 1389 | - $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)"; |
|
| 1388 | + $prim .= "$s\n\t\tCONSTRAINT ".str_replace('`', '"', $k)." UNIQUE ($v)"; |
|
| 1390 | 1389 | } else { |
| 1391 | - $prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)"; |
|
| 1390 | + $prim .= "$s\n\t\t".str_replace('`', '"', $k)." ($v)"; |
|
| 1392 | 1391 | } |
| 1393 | 1392 | if ($k == "PRIMARY KEY") { |
| 1394 | 1393 | $prim_name = $v; |
@@ -1399,17 +1398,17 @@ discard block |
||
| 1399 | 1398 | |
| 1400 | 1399 | $character_set = ""; |
| 1401 | 1400 | if (@$GLOBALS['meta']['charset_sql_base']) { |
| 1402 | - $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 1401 | + $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 1403 | 1402 | } |
| 1404 | 1403 | if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
| 1405 | - $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1404 | + $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 1406 | 1405 | } |
| 1407 | 1406 | |
| 1408 | 1407 | foreach ($champs as $k => $v) { |
| 1409 | 1408 | $k = str_replace('`', '"', $k); |
| 1410 | 1409 | if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
| 1411 | 1410 | if (preg_match(',(char|text),i', $defs[1]) and !preg_match(',binary,i', $defs[1])) { |
| 1412 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 1411 | + $v = $defs[1].$character_set.' '.substr($v, strlen($defs[1])); |
|
| 1413 | 1412 | } |
| 1414 | 1413 | } |
| 1415 | 1414 | |
@@ -1424,7 +1423,7 @@ discard block |
||
| 1424 | 1423 | |
| 1425 | 1424 | // En l'absence de "if not exists" en PG, on neutralise les erreurs |
| 1426 | 1425 | |
| 1427 | - $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ")" . |
|
| 1426 | + $q = "CREATE $temporary TABLE $nom ($query".($prim ? ",$prim" : '').")". |
|
| 1428 | 1427 | ($character_set ? " DEFAULT $character_set" : "") |
| 1429 | 1428 | . "\n"; |
| 1430 | 1429 | |
@@ -1435,7 +1434,7 @@ discard block |
||
| 1435 | 1434 | $r = @pg_query($link, $q); |
| 1436 | 1435 | |
| 1437 | 1436 | if (!$r) { |
| 1438 | - spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR); |
|
| 1437 | + spip_log("Impossible de creer cette table: $q", 'pg.'._LOG_ERREUR); |
|
| 1439 | 1438 | } else { |
| 1440 | 1439 | foreach ($keys as $index) { |
| 1441 | 1440 | pg_query($link, $index); |
@@ -1459,13 +1458,13 @@ discard block |
||
| 1459 | 1458 | // vue deja presente |
| 1460 | 1459 | if (sql_showtable($nom, false, $serveur)) { |
| 1461 | 1460 | if ($requeter) { |
| 1462 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR); |
|
| 1461 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.'._LOG_ERREUR); |
|
| 1463 | 1462 | } |
| 1464 | 1463 | |
| 1465 | 1464 | return false; |
| 1466 | 1465 | } |
| 1467 | 1466 | |
| 1468 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 1467 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 1469 | 1468 | |
| 1470 | 1469 | return spip_pg_query($query, $serveur, $requeter); |
| 1471 | 1470 | } |
@@ -1473,7 +1472,7 @@ discard block |
||
| 1473 | 1472 | |
| 1474 | 1473 | // https://code.spip.net/@spip_pg_set_connect_charset |
| 1475 | 1474 | function spip_pg_set_connect_charset($charset, $serveur = '', $requeter = true) { |
| 1476 | - spip_log("changement de charset sql a ecrire en PG", 'pg.' . _LOG_ERREUR); |
|
| 1475 | + spip_log("changement de charset sql a ecrire en PG", 'pg.'._LOG_ERREUR); |
|
| 1477 | 1476 | } |
| 1478 | 1477 | |
| 1479 | 1478 | |
@@ -1487,7 +1486,7 @@ discard block |
||
| 1487 | 1486 | **/ |
| 1488 | 1487 | // https://code.spip.net/@spip_sqlite_optimize |
| 1489 | 1488 | function spip_pg_optimize($table, $serveur = '', $requeter = true) { |
| 1490 | - return spip_pg_query("VACUUM " . $table, $serveur, $requeter); |
|
| 1489 | + return spip_pg_query("VACUUM ".$table, $serveur, $requeter); |
|
| 1491 | 1490 | } |
| 1492 | 1491 | |
| 1493 | 1492 | // Selectionner la sous-chaine dans $objet |
@@ -167,6 +167,9 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // https://code.spip.net/@analyser_dtd_comment |
| 170 | +/** |
|
| 171 | + * @param string $dtd |
|
| 172 | + */ |
|
| 170 | 173 | function analyser_dtd_comment($dtd, &$dtc, $grammaire) { |
| 171 | 174 | // ejecter les commentaires, surtout quand ils contiennent du code. |
| 172 | 175 | // Option /s car sur plusieurs lignes parfois |
@@ -179,6 +182,9 @@ discard block |
||
| 179 | 182 | } |
| 180 | 183 | |
| 181 | 184 | // https://code.spip.net/@analyser_dtd_pi |
| 185 | +/** |
|
| 186 | + * @param string $dtd |
|
| 187 | + */ |
|
| 182 | 188 | function analyser_dtd_pi($dtd, &$dtc, $grammaire) { |
| 183 | 189 | if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
| 184 | 190 | return -10; |
@@ -188,6 +194,9 @@ discard block |
||
| 188 | 194 | } |
| 189 | 195 | |
| 190 | 196 | // https://code.spip.net/@analyser_dtd_lexeme |
| 197 | +/** |
|
| 198 | + * @param string $dtd |
|
| 199 | + */ |
|
| 191 | 200 | function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) { |
| 192 | 201 | |
| 193 | 202 | if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
@@ -215,6 +224,9 @@ discard block |
||
| 215 | 224 | // ca ne depasse pas 3 ici. |
| 216 | 225 | |
| 217 | 226 | // https://code.spip.net/@analyser_dtd_data |
| 227 | +/** |
|
| 228 | + * @param string $dtd |
|
| 229 | + */ |
|
| 218 | 230 | function analyser_dtd_data($dtd, &$dtc, $grammaire) { |
| 219 | 231 | |
| 220 | 232 | if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
@@ -236,6 +248,9 @@ discard block |
||
| 236 | 248 | } |
| 237 | 249 | |
| 238 | 250 | // https://code.spip.net/@analyser_dtd_notation |
| 251 | +/** |
|
| 252 | + * @param string $dtd |
|
| 253 | + */ |
|
| 239 | 254 | function analyser_dtd_notation($dtd, &$dtc, $grammaire) { |
| 240 | 255 | if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
| 241 | 256 | return -8; |
@@ -246,6 +261,9 @@ discard block |
||
| 246 | 261 | } |
| 247 | 262 | |
| 248 | 263 | // https://code.spip.net/@analyser_dtd_entity |
| 264 | +/** |
|
| 265 | + * @param string $dtd |
|
| 266 | + */ |
|
| 249 | 267 | function analyser_dtd_entity($dtd, &$dtc, $grammaire) { |
| 250 | 268 | if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
| 251 | 269 | return -2; |
@@ -303,6 +321,9 @@ discard block |
||
| 303 | 321 | // Fin du controle en finElement |
| 304 | 322 | |
| 305 | 323 | // https://code.spip.net/@analyser_dtd_element |
| 324 | +/** |
|
| 325 | + * @param string $dtd |
|
| 326 | + */ |
|
| 306 | 327 | function analyser_dtd_element($dtd, &$dtc, $grammaire) { |
| 307 | 328 | if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
| 308 | 329 | return -3; |
@@ -351,6 +372,9 @@ discard block |
||
| 351 | 372 | |
| 352 | 373 | |
| 353 | 374 | // https://code.spip.net/@analyser_dtd_attlist |
| 375 | +/** |
|
| 376 | + * @param string $dtd |
|
| 377 | + */ |
|
| 354 | 378 | function analyser_dtd_attlist($dtd, &$dtc, $grammaire) { |
| 355 | 379 | if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
| 356 | 380 | return -5; |
@@ -11,59 +11,59 @@ 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('xml/interfaces'); |
| 18 | 18 | |
| 19 | 19 | // https://code.spip.net/@charger_dtd |
| 20 | 20 | function charger_dtd($grammaire, $avail, $rotlvl) { |
| 21 | - static $dtd = array(); # cache bien utile pour le validateur en boucle |
|
| 22 | - |
|
| 23 | - if (isset($dtd[$grammaire])) { |
|
| 24 | - return $dtd[$grammaire]; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - if ($avail == 'SYSTEM') { |
|
| 28 | - $grammaire = find_in_path($grammaire); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | - |
|
| 33 | - if (lire_fichier($file, $r)) { |
|
| 34 | - if (!$grammaire) { |
|
| 35 | - return array(); |
|
| 36 | - } |
|
| 37 | - if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | - $r = false; |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if ($r) { |
|
| 43 | - $dtc = unserialize($r); |
|
| 44 | - } else { |
|
| 45 | - spip_timer('dtd'); |
|
| 46 | - $dtc = new DTC; |
|
| 47 | - // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | - // Retourner vide en cas d'echec |
|
| 49 | - if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | - $dtc = array(); |
|
| 51 | - } else { |
|
| 52 | - // tri final pour presenter les suggestions de corrections |
|
| 53 | - foreach ($dtc->peres as $k => $v) { |
|
| 54 | - asort($v); |
|
| 55 | - $dtc->peres[$k] = $v; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ") " . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . " entites"); |
|
| 59 | - # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | - ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - } |
|
| 64 | - $dtd[$grammaire] = $dtc; |
|
| 65 | - |
|
| 66 | - return $dtc; |
|
| 21 | + static $dtd = array(); # cache bien utile pour le validateur en boucle |
|
| 22 | + |
|
| 23 | + if (isset($dtd[$grammaire])) { |
|
| 24 | + return $dtd[$grammaire]; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + if ($avail == 'SYSTEM') { |
|
| 28 | + $grammaire = find_in_path($grammaire); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | + |
|
| 33 | + if (lire_fichier($file, $r)) { |
|
| 34 | + if (!$grammaire) { |
|
| 35 | + return array(); |
|
| 36 | + } |
|
| 37 | + if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | + $r = false; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if ($r) { |
|
| 43 | + $dtc = unserialize($r); |
|
| 44 | + } else { |
|
| 45 | + spip_timer('dtd'); |
|
| 46 | + $dtc = new DTC; |
|
| 47 | + // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | + // Retourner vide en cas d'echec |
|
| 49 | + if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | + $dtc = array(); |
|
| 51 | + } else { |
|
| 52 | + // tri final pour presenter les suggestions de corrections |
|
| 53 | + foreach ($dtc->peres as $k => $v) { |
|
| 54 | + asort($v); |
|
| 55 | + $dtc->peres[$k] = $v; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ") " . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . " entites"); |
|
| 59 | + # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | + ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + } |
|
| 64 | + $dtd[$grammaire] = $dtc; |
|
| 65 | + |
|
| 66 | + return $dtc; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // Compiler une regle de production en une Regexp qu'on appliquera sur la |
@@ -76,139 +76,139 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | // https://code.spip.net/@compilerRegle |
| 78 | 78 | function compilerRegle($val) { |
| 79 | - $x = str_replace('()', '', |
|
| 80 | - preg_replace('/\s*,\s*/', '', |
|
| 81 | - preg_replace('/(\w+)\s*/', '(?:\1 )', |
|
| 82 | - preg_replace('/\s*\)/', ')', |
|
| 83 | - preg_replace('/\s*([(+*|?])\s*/', '\1', |
|
| 84 | - preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val)))))); |
|
| 85 | - |
|
| 86 | - return $x; |
|
| 79 | + $x = str_replace('()', '', |
|
| 80 | + preg_replace('/\s*,\s*/', '', |
|
| 81 | + preg_replace('/(\w+)\s*/', '(?:\1 )', |
|
| 82 | + preg_replace('/\s*\)/', ')', |
|
| 83 | + preg_replace('/\s*([(+*|?])\s*/', '\1', |
|
| 84 | + preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val)))))); |
|
| 85 | + |
|
| 86 | + return $x; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | // https://code.spip.net/@analyser_dtd |
| 91 | 91 | function analyser_dtd($loc, $avail, &$dtc) { |
| 92 | - // creer le repertoire de cache si ce n'est fait |
|
| 93 | - // (utile aussi pour le resultat de la compil) |
|
| 94 | - $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 95 | - // si DTD locale, ignorer ce repertoire pour le moment |
|
| 96 | - if ($avail == 'SYSTEM') { |
|
| 97 | - $file = $loc; |
|
| 98 | - if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 99 | - $file = substr($file, strlen(_DIR_RACINE)); |
|
| 100 | - } |
|
| 101 | - $file = find_in_path($file); |
|
| 102 | - } else { |
|
| 103 | - $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $dtd = ''; |
|
| 107 | - if (@is_readable($file)) { |
|
| 108 | - lire_fichier($file, $dtd); |
|
| 109 | - } else { |
|
| 110 | - if ($avail == 'PUBLIC') { |
|
| 111 | - include_spip('inc/distant'); |
|
| 112 | - if ($dtd = trim(recuperer_page($loc))) { |
|
| 113 | - ecrire_fichier($file, $dtd, true); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $dtd = ltrim($dtd); |
|
| 119 | - if (!$dtd) { |
|
| 120 | - spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 121 | - |
|
| 122 | - return false; |
|
| 123 | - } else { |
|
| 124 | - spip_log("analyse de la DTD $loc "); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - while ($dtd) { |
|
| 128 | - if ($dtd[0] != '<') { |
|
| 129 | - $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 130 | - } elseif ($dtd[1] != '!') { |
|
| 131 | - $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 132 | - } elseif ($dtd[2] == '[') { |
|
| 133 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 134 | - } else { |
|
| 135 | - switch ($dtd[3]) { |
|
| 136 | - case '%' : |
|
| 137 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 138 | - break; |
|
| 139 | - case 'T' : |
|
| 140 | - $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 141 | - break; |
|
| 142 | - case 'L' : |
|
| 143 | - $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 144 | - break; |
|
| 145 | - case 'N' : |
|
| 146 | - $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 147 | - break; |
|
| 148 | - case 'O' : |
|
| 149 | - $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 150 | - break; |
|
| 151 | - case '-' : |
|
| 152 | - $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 153 | - break; |
|
| 154 | - default: |
|
| 155 | - $r = -1; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - if (!is_string($r)) { |
|
| 159 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . "....."); |
|
| 160 | - |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - $dtd = $r; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - return true; |
|
| 92 | + // creer le repertoire de cache si ce n'est fait |
|
| 93 | + // (utile aussi pour le resultat de la compil) |
|
| 94 | + $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 95 | + // si DTD locale, ignorer ce repertoire pour le moment |
|
| 96 | + if ($avail == 'SYSTEM') { |
|
| 97 | + $file = $loc; |
|
| 98 | + if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 99 | + $file = substr($file, strlen(_DIR_RACINE)); |
|
| 100 | + } |
|
| 101 | + $file = find_in_path($file); |
|
| 102 | + } else { |
|
| 103 | + $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $dtd = ''; |
|
| 107 | + if (@is_readable($file)) { |
|
| 108 | + lire_fichier($file, $dtd); |
|
| 109 | + } else { |
|
| 110 | + if ($avail == 'PUBLIC') { |
|
| 111 | + include_spip('inc/distant'); |
|
| 112 | + if ($dtd = trim(recuperer_page($loc))) { |
|
| 113 | + ecrire_fichier($file, $dtd, true); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $dtd = ltrim($dtd); |
|
| 119 | + if (!$dtd) { |
|
| 120 | + spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 121 | + |
|
| 122 | + return false; |
|
| 123 | + } else { |
|
| 124 | + spip_log("analyse de la DTD $loc "); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + while ($dtd) { |
|
| 128 | + if ($dtd[0] != '<') { |
|
| 129 | + $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 130 | + } elseif ($dtd[1] != '!') { |
|
| 131 | + $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 132 | + } elseif ($dtd[2] == '[') { |
|
| 133 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 134 | + } else { |
|
| 135 | + switch ($dtd[3]) { |
|
| 136 | + case '%' : |
|
| 137 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 138 | + break; |
|
| 139 | + case 'T' : |
|
| 140 | + $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 141 | + break; |
|
| 142 | + case 'L' : |
|
| 143 | + $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 144 | + break; |
|
| 145 | + case 'N' : |
|
| 146 | + $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 147 | + break; |
|
| 148 | + case 'O' : |
|
| 149 | + $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 150 | + break; |
|
| 151 | + case '-' : |
|
| 152 | + $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 153 | + break; |
|
| 154 | + default: |
|
| 155 | + $r = -1; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + if (!is_string($r)) { |
|
| 159 | + spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . "....."); |
|
| 160 | + |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + $dtd = $r; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + return true; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // https://code.spip.net/@analyser_dtd_comment |
| 170 | 170 | function analyser_dtd_comment($dtd, &$dtc, $grammaire) { |
| 171 | - // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 172 | - // Option /s car sur plusieurs lignes parfois |
|
| 171 | + // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 172 | + // Option /s car sur plusieurs lignes parfois |
|
| 173 | 173 | |
| 174 | - if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 175 | - return -6; |
|
| 176 | - } |
|
| 174 | + if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 175 | + return -6; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - return $m[1]; |
|
| 178 | + return $m[1]; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // https://code.spip.net/@analyser_dtd_pi |
| 182 | 182 | function analyser_dtd_pi($dtd, &$dtc, $grammaire) { |
| 183 | - if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 184 | - return -10; |
|
| 185 | - } |
|
| 183 | + if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 184 | + return -10; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - return $m[1]; |
|
| 187 | + return $m[1]; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // https://code.spip.net/@analyser_dtd_lexeme |
| 191 | 191 | function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) { |
| 192 | 192 | |
| 193 | - if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 194 | - return -9; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - list(, $s) = $m; |
|
| 198 | - $n = $dtc->macros[$s]; |
|
| 199 | - |
|
| 200 | - if (is_array($n)) { |
|
| 201 | - // en cas d'inclusion, l'espace de nom est le meme |
|
| 202 | - // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 203 | - if (($n[0] == 'PUBLIC') |
|
| 204 | - and !tester_url_absolue($n[1]) |
|
| 205 | - ) { |
|
| 206 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 207 | - } |
|
| 208 | - analyser_dtd($n[1], $n[0], $dtc); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return ltrim(substr($dtd, strlen($m[0]))); |
|
| 193 | + if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 194 | + return -9; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + list(, $s) = $m; |
|
| 198 | + $n = $dtc->macros[$s]; |
|
| 199 | + |
|
| 200 | + if (is_array($n)) { |
|
| 201 | + // en cas d'inclusion, l'espace de nom est le meme |
|
| 202 | + // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 203 | + if (($n[0] == 'PUBLIC') |
|
| 204 | + and !tester_url_absolue($n[1]) |
|
| 205 | + ) { |
|
| 206 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 207 | + } |
|
| 208 | + analyser_dtd($n[1], $n[0], $dtc); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return ltrim(substr($dtd, strlen($m[0]))); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | // il faudrait gerer plus proprement les niveaux d'inclusion: |
@@ -217,80 +217,80 @@ discard block |
||
| 217 | 217 | // https://code.spip.net/@analyser_dtd_data |
| 218 | 218 | function analyser_dtd_data($dtd, &$dtc, $grammaire) { |
| 219 | 219 | |
| 220 | - if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 221 | - return -11; |
|
| 222 | - } |
|
| 223 | - if (!preg_match('/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', $m[2], |
|
| 224 | - $r) |
|
| 225 | - ) { |
|
| 226 | - return -12; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 230 | - $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 231 | - } else { |
|
| 232 | - $retour = substr($m[2], strlen($r[0])); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return $retour; |
|
| 220 | + if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 221 | + return -11; |
|
| 222 | + } |
|
| 223 | + if (!preg_match('/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', $m[2], |
|
| 224 | + $r) |
|
| 225 | + ) { |
|
| 226 | + return -12; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 230 | + $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 231 | + } else { |
|
| 232 | + $retour = substr($m[2], strlen($r[0])); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return $retour; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // https://code.spip.net/@analyser_dtd_notation |
| 239 | 239 | function analyser_dtd_notation($dtd, &$dtc, $grammaire) { |
| 240 | - if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 241 | - return -8; |
|
| 242 | - } |
|
| 243 | - spip_log("analyser_dtd_notation a ecrire"); |
|
| 240 | + if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 241 | + return -8; |
|
| 242 | + } |
|
| 243 | + spip_log("analyser_dtd_notation a ecrire"); |
|
| 244 | 244 | |
| 245 | - return $m[1]; |
|
| 245 | + return $m[1]; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // https://code.spip.net/@analyser_dtd_entity |
| 249 | 249 | function analyser_dtd_entity($dtd, &$dtc, $grammaire) { |
| 250 | - if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 251 | - return -2; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - list($t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd) = $m; |
|
| 255 | - |
|
| 256 | - if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 257 | - return $dtd; |
|
| 258 | - } |
|
| 259 | - if (isset($dtc->entites[$nom])) { |
|
| 260 | - spip_log("redefinition de l'entite $nom"); |
|
| 261 | - } |
|
| 262 | - if ($k6) { |
|
| 263 | - return $k6 . $dtd; |
|
| 264 | - } // cas du synonyme complet |
|
| 265 | - $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 266 | - |
|
| 267 | - // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 268 | - if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 269 | - list($t, $type, $val, $q, $alt) = $r; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - if (!$term) { |
|
| 273 | - $dtc->entites[$nom] = $val; |
|
| 274 | - } elseif (!$type) { |
|
| 275 | - $dtc->macros[$nom] = $val; |
|
| 276 | - } else { |
|
| 277 | - if (($type == 'SYSTEM') and !$alt) { |
|
| 278 | - $alt = $val; |
|
| 279 | - } |
|
| 280 | - if (!$alt) { |
|
| 281 | - $dtc->macros[$nom] = $val; |
|
| 282 | - } else { |
|
| 283 | - if (($type == 'PUBLIC') |
|
| 284 | - and (strpos($alt, '/') === false) |
|
| 285 | - ) { |
|
| 286 | - $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 287 | - . $alt; |
|
| 288 | - } |
|
| 289 | - $dtc->macros[$nom] = array($type, $alt); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - return $dtd; |
|
| 250 | + if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 251 | + return -2; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + list($t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd) = $m; |
|
| 255 | + |
|
| 256 | + if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 257 | + return $dtd; |
|
| 258 | + } |
|
| 259 | + if (isset($dtc->entites[$nom])) { |
|
| 260 | + spip_log("redefinition de l'entite $nom"); |
|
| 261 | + } |
|
| 262 | + if ($k6) { |
|
| 263 | + return $k6 . $dtd; |
|
| 264 | + } // cas du synonyme complet |
|
| 265 | + $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 266 | + |
|
| 267 | + // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 268 | + if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 269 | + list($t, $type, $val, $q, $alt) = $r; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + if (!$term) { |
|
| 273 | + $dtc->entites[$nom] = $val; |
|
| 274 | + } elseif (!$type) { |
|
| 275 | + $dtc->macros[$nom] = $val; |
|
| 276 | + } else { |
|
| 277 | + if (($type == 'SYSTEM') and !$alt) { |
|
| 278 | + $alt = $val; |
|
| 279 | + } |
|
| 280 | + if (!$alt) { |
|
| 281 | + $dtc->macros[$nom] = $val; |
|
| 282 | + } else { |
|
| 283 | + if (($type == 'PUBLIC') |
|
| 284 | + and (strpos($alt, '/') === false) |
|
| 285 | + ) { |
|
| 286 | + $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 287 | + . $alt; |
|
| 288 | + } |
|
| 289 | + $dtc->macros[$nom] = array($type, $alt); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + return $dtd; |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | // Dresser le tableau des filles potentielles de l'element |
@@ -304,76 +304,76 @@ discard block |
||
| 304 | 304 | |
| 305 | 305 | // https://code.spip.net/@analyser_dtd_element |
| 306 | 306 | function analyser_dtd_element($dtd, &$dtc, $grammaire) { |
| 307 | - if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 308 | - return -3; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - list(, $nom, $contenu, $dtd) = $m; |
|
| 312 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 313 | - |
|
| 314 | - if (isset($dtc->elements[$nom])) { |
|
| 315 | - spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 316 | - |
|
| 317 | - return -4; |
|
| 318 | - } |
|
| 319 | - $filles = array(); |
|
| 320 | - $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 321 | - $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 322 | - if ($val == '(?:EMPTY )') { |
|
| 323 | - $dtc->regles[$nom] = 'EMPTY'; |
|
| 324 | - } elseif ($val == '(?:ANY )') { |
|
| 325 | - $dtc->regles[$nom] = 'ANY'; |
|
| 326 | - } else { |
|
| 327 | - $last = substr($val, -1); |
|
| 328 | - if (preg_match('/ \w/', $val) |
|
| 329 | - or (!empty($last) and strpos('*+?', $last) === false) |
|
| 330 | - ) { |
|
| 331 | - $dtc->regles[$nom] = "/^$val$/"; |
|
| 332 | - } else { |
|
| 333 | - $dtc->regles[$nom] = $last; |
|
| 334 | - } |
|
| 335 | - $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 336 | - |
|
| 337 | - foreach ($filles as $k) { |
|
| 338 | - if (!isset($dtc->peres[$k])) { |
|
| 339 | - $dtc->peres[$k] = array(); |
|
| 340 | - } |
|
| 341 | - if (!in_array($nom, $dtc->peres[$k])) { |
|
| 342 | - $dtc->peres[$k][] = $nom; |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 347 | - $dtc->elements[$nom] = $filles; |
|
| 348 | - |
|
| 349 | - return $dtd; |
|
| 307 | + if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 308 | + return -3; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + list(, $nom, $contenu, $dtd) = $m; |
|
| 312 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 313 | + |
|
| 314 | + if (isset($dtc->elements[$nom])) { |
|
| 315 | + spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 316 | + |
|
| 317 | + return -4; |
|
| 318 | + } |
|
| 319 | + $filles = array(); |
|
| 320 | + $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 321 | + $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 322 | + if ($val == '(?:EMPTY )') { |
|
| 323 | + $dtc->regles[$nom] = 'EMPTY'; |
|
| 324 | + } elseif ($val == '(?:ANY )') { |
|
| 325 | + $dtc->regles[$nom] = 'ANY'; |
|
| 326 | + } else { |
|
| 327 | + $last = substr($val, -1); |
|
| 328 | + if (preg_match('/ \w/', $val) |
|
| 329 | + or (!empty($last) and strpos('*+?', $last) === false) |
|
| 330 | + ) { |
|
| 331 | + $dtc->regles[$nom] = "/^$val$/"; |
|
| 332 | + } else { |
|
| 333 | + $dtc->regles[$nom] = $last; |
|
| 334 | + } |
|
| 335 | + $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 336 | + |
|
| 337 | + foreach ($filles as $k) { |
|
| 338 | + if (!isset($dtc->peres[$k])) { |
|
| 339 | + $dtc->peres[$k] = array(); |
|
| 340 | + } |
|
| 341 | + if (!in_array($nom, $dtc->peres[$k])) { |
|
| 342 | + $dtc->peres[$k][] = $nom; |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 347 | + $dtc->elements[$nom] = $filles; |
|
| 348 | + |
|
| 349 | + return $dtd; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | |
| 353 | 353 | // https://code.spip.net/@analyser_dtd_attlist |
| 354 | 354 | function analyser_dtd_attlist($dtd, &$dtc, $grammaire) { |
| 355 | - if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 356 | - return -5; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - list(, $nom, $val, $dtd) = $m; |
|
| 360 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 361 | - $val = expanserEntite($val, $dtc->macros); |
|
| 362 | - if (!isset($dtc->attributs[$nom])) { |
|
| 363 | - $dtc->attributs[$nom] = array(); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 367 | - foreach ($r2 as $m2) { |
|
| 368 | - $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 369 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 370 | - $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 371 | - $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 372 | - $dtc->attributs[$nom][$m21] = array($v, $m25); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - return $dtd; |
|
| 355 | + if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 356 | + return -5; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + list(, $nom, $val, $dtd) = $m; |
|
| 360 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 361 | + $val = expanserEntite($val, $dtc->macros); |
|
| 362 | + if (!isset($dtc->attributs[$nom])) { |
|
| 363 | + $dtc->attributs[$nom] = array(); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 367 | + foreach ($r2 as $m2) { |
|
| 368 | + $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 369 | + : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 370 | + $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 371 | + $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 372 | + $dtc->attributs[$nom][$m21] = array($v, $m25); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + return $dtd; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | |
@@ -389,26 +389,26 @@ discard block |
||
| 389 | 389 | * @return string|array |
| 390 | 390 | **/ |
| 391 | 391 | function expanserEntite($val, $macros = array()) { |
| 392 | - static $vu = array(); |
|
| 393 | - if (!is_string($val)) { |
|
| 394 | - return $vu; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 398 | - foreach ($r as $m) { |
|
| 399 | - $ent = $m[1]; |
|
| 400 | - // il peut valoir "" |
|
| 401 | - if (!isset($macros[$ent])) { |
|
| 402 | - spip_log("Entite $ent inconnu"); |
|
| 403 | - } else { |
|
| 404 | - if (!isset($vu[$ent])) { |
|
| 405 | - $vu[$ent] = 0; |
|
| 406 | - } |
|
| 407 | - ++$vu[$ent]; |
|
| 408 | - $val = str_replace($m[0], $macros[$ent], $val); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 392 | + static $vu = array(); |
|
| 393 | + if (!is_string($val)) { |
|
| 394 | + return $vu; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 398 | + foreach ($r as $m) { |
|
| 399 | + $ent = $m[1]; |
|
| 400 | + // il peut valoir "" |
|
| 401 | + if (!isset($macros[$ent])) { |
|
| 402 | + spip_log("Entite $ent inconnu"); |
|
| 403 | + } else { |
|
| 404 | + if (!isset($vu[$ent])) { |
|
| 405 | + $vu[$ent] = 0; |
|
| 406 | + } |
|
| 407 | + ++$vu[$ent]; |
|
| 408 | + $val = str_replace($m[0], $macros[$ent], $val); |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 414 | 414 | } |