@@ -10,110 +10,110 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) { |
| 17 | - $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 18 | - $racine = basename((string) _DIR_PLUGINS); |
|
| 19 | - $init_dir = $current_dir = ''; |
|
| 20 | - // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 21 | - // des qu'un path est deja note deplie on s'arrete |
|
| 22 | - $deplie = [$racine => true]; |
|
| 23 | - $fast_liste_plugins_actifs = []; |
|
| 24 | - foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 25 | - $chemin_plug = chemin_plug($racine, $plug); |
|
| 26 | - $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 27 | - $dir = dirname((string) $chemin_plug); |
|
| 28 | - $maxiter = 100; |
|
| 29 | - while (strlen($dir) && !isset($deplie[$dir]) && $dir !== $racine && $maxiter-- > 0) { |
|
| 30 | - $deplie[$dir] = true; |
|
| 31 | - $dir = dirname($dir); |
|
| 32 | - } |
|
| 33 | - } |
|
| 17 | + $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 18 | + $racine = basename((string) _DIR_PLUGINS); |
|
| 19 | + $init_dir = $current_dir = ''; |
|
| 20 | + // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 21 | + // des qu'un path est deja note deplie on s'arrete |
|
| 22 | + $deplie = [$racine => true]; |
|
| 23 | + $fast_liste_plugins_actifs = []; |
|
| 24 | + foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 25 | + $chemin_plug = chemin_plug($racine, $plug); |
|
| 26 | + $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 27 | + $dir = dirname((string) $chemin_plug); |
|
| 28 | + $maxiter = 100; |
|
| 29 | + while (strlen($dir) && !isset($deplie[$dir]) && $dir !== $racine && $maxiter-- > 0) { |
|
| 30 | + $deplie[$dir] = true; |
|
| 31 | + $dir = dirname($dir); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - // index repertoires --> plugin |
|
| 36 | - $dir_index = []; |
|
| 37 | - foreach ($liste_plugins as $key => $plug) { |
|
| 38 | - $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 39 | - $dir_index[dirname((string) $liste_plugins[$key])][] = $key; |
|
| 40 | - } |
|
| 35 | + // index repertoires --> plugin |
|
| 36 | + $dir_index = []; |
|
| 37 | + foreach ($liste_plugins as $key => $plug) { |
|
| 38 | + $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 39 | + $dir_index[dirname((string) $liste_plugins[$key])][] = $key; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $visible = @isset($deplie[$current_dir]); |
|
| 43 | - $maxiter = 1000; |
|
| 42 | + $visible = @isset($deplie[$current_dir]); |
|
| 43 | + $maxiter = 1000; |
|
| 44 | 44 | |
| 45 | - $res = ''; |
|
| 46 | - while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) { |
|
| 47 | - // le rep suivant |
|
| 48 | - $dir = dirname((string) reset($liste_plugins)); |
|
| 49 | - if ($dir != $current_dir) { |
|
| 50 | - $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 51 | - } |
|
| 45 | + $res = ''; |
|
| 46 | + while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) { |
|
| 47 | + // le rep suivant |
|
| 48 | + $dir = dirname((string) reset($liste_plugins)); |
|
| 49 | + if ($dir != $current_dir) { |
|
| 50 | + $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // d'abord tous les plugins du rep courant |
|
| 54 | - if (isset($dir_index[$current_dir])) { |
|
| 55 | - foreach ($dir_index[$current_dir] as $key) { |
|
| 56 | - $plug = $liste_plugins[$key]; |
|
| 57 | - $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 58 | - $id = substr(md5((string) $plug), 0, 16); |
|
| 59 | - $res .= $ligne_plug( |
|
| 60 | - $url_page, |
|
| 61 | - str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), |
|
| 62 | - $actif, |
|
| 63 | - 'menu-entree' |
|
| 64 | - ) . "\n"; |
|
| 65 | - unset($liste_plugins[$key]); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 53 | + // d'abord tous les plugins du rep courant |
|
| 54 | + if (isset($dir_index[$current_dir])) { |
|
| 55 | + foreach ($dir_index[$current_dir] as $key) { |
|
| 56 | + $plug = $liste_plugins[$key]; |
|
| 57 | + $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 58 | + $id = substr(md5((string) $plug), 0, 16); |
|
| 59 | + $res .= $ligne_plug( |
|
| 60 | + $url_page, |
|
| 61 | + str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), |
|
| 62 | + $actif, |
|
| 63 | + 'menu-entree' |
|
| 64 | + ) . "\n"; |
|
| 65 | + unset($liste_plugins[$key]); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 70 | 70 | |
| 71 | - return "<ul class='menu-liste plugins'>" |
|
| 72 | - . $res |
|
| 73 | - . '</ul>'; |
|
| 71 | + return "<ul class='menu-liste plugins'>" |
|
| 72 | + . $res |
|
| 73 | + . '</ul>'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | |
| 77 | 77 | // vraiment n'importe quoi la gestion des chemins des plugins |
| 78 | 78 | // une fonction pour aider... |
| 79 | 79 | function chemin_plug($racine, $plug) { |
| 80 | - return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 80 | + return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | function tree_open_close_dir(&$current, $target, $deplie = []) { |
| 84 | - if ($current == $target) { |
|
| 85 | - return ''; |
|
| 86 | - } |
|
| 87 | - $tcur = explode('/', (string) $current); |
|
| 88 | - $ttarg = explode('/', (string) $target); |
|
| 89 | - $tcom = []; |
|
| 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 ($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('/', (string) $current); |
|
| 88 | + $ttarg = explode('/', (string) $target); |
|
| 89 | + $tcom = []; |
|
| 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 ($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 | } |
@@ -58,10 +58,10 @@ discard block |
||
| 58 | 58 | $id = substr(md5((string) $plug), 0, 16); |
| 59 | 59 | $res .= $ligne_plug( |
| 60 | 60 | $url_page, |
| 61 | - str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), |
|
| 61 | + str_replace(_DIR_PLUGINS, '', _DIR_RACINE.$plug), |
|
| 62 | 62 | $actif, |
| 63 | 63 | 'menu-entree' |
| 64 | - ) . "\n"; |
|
| 64 | + )."\n"; |
|
| 65 | 65 | unset($liste_plugins[$key]); |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | $chemin = ''; |
| 103 | 103 | if ($tcom !== []) { |
| 104 | - $chemin .= implode('/', $tcom) . '/'; |
|
| 104 | + $chemin .= implode('/', $tcom).'/'; |
|
| 105 | 105 | } |
| 106 | 106 | // ouvrir les repertoires jusqu'a la cible |
| 107 | 107 | while ($open = array_shift($ttarg)) { |
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . '/'; |
|
| 108 | + $visible = @isset($deplie[$chemin.$open]); |
|
| 109 | + $chemin .= $open.'/'; |
|
| 110 | 110 | $output .= '<li>'; |
| 111 | 111 | $output .= bouton_block_depliable($chemin, $visible); |
| 112 | 112 | $output .= debut_block_depliable($visible); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -33,37 +33,37 @@ discard block |
||
| 33 | 33 | * Contenu HTML, avec boutons d'administrations et sa CSS |
| 34 | 34 | **/ |
| 35 | 35 | function affiche_boutons_admin($contenu) { |
| 36 | - include_spip('inc/filtres'); |
|
| 36 | + include_spip('inc/filtres'); |
|
| 37 | 37 | |
| 38 | - // Inserer le css d'admin |
|
| 39 | - $css = "<link rel='stylesheet' href='" . url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 40 | - . "' type='text/css' />\n"; |
|
| 41 | - if ($f = find_in_path('spip_admin_perso.css')) { |
|
| 42 | - $css .= "<link rel='stylesheet' href='" |
|
| 43 | - . url_absolue(direction_css($f)) . "' type='text/css' />\n"; |
|
| 44 | - } |
|
| 38 | + // Inserer le css d'admin |
|
| 39 | + $css = "<link rel='stylesheet' href='" . url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 40 | + . "' type='text/css' />\n"; |
|
| 41 | + if ($f = find_in_path('spip_admin_perso.css')) { |
|
| 42 | + $css .= "<link rel='stylesheet' href='" |
|
| 43 | + . url_absolue(direction_css($f)) . "' type='text/css' />\n"; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if ( |
|
| 47 | - !($pos = stripos($contenu, '</head>')) |
|
| 48 | - && !($pos = stripos($contenu, '<body>')) |
|
| 49 | - ) { |
|
| 50 | - $pos = 0; |
|
| 51 | - } |
|
| 52 | - $contenu = substr_replace($contenu, $css, $pos, 0); |
|
| 46 | + if ( |
|
| 47 | + !($pos = stripos($contenu, '</head>')) |
|
| 48 | + && !($pos = stripos($contenu, '<body>')) |
|
| 49 | + ) { |
|
| 50 | + $pos = 0; |
|
| 51 | + } |
|
| 52 | + $contenu = substr_replace($contenu, $css, $pos, 0); |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - // Inserer la balise #FORMULAIRE_ADMIN, en float |
|
| 56 | - $boutons_admin = inclure_balise_dynamique( |
|
| 57 | - balise_FORMULAIRE_ADMIN_dyn('spip-admin-float'), |
|
| 58 | - false |
|
| 59 | - ); |
|
| 60 | - if ( |
|
| 61 | - !($pos = strripos($contenu, '</body>')) |
|
| 62 | - && !($pos = strripos($contenu, '</html>')) |
|
| 63 | - ) { |
|
| 64 | - $pos = strlen($contenu); |
|
| 65 | - } |
|
| 55 | + // Inserer la balise #FORMULAIRE_ADMIN, en float |
|
| 56 | + $boutons_admin = inclure_balise_dynamique( |
|
| 57 | + balise_FORMULAIRE_ADMIN_dyn('spip-admin-float'), |
|
| 58 | + false |
|
| 59 | + ); |
|
| 60 | + if ( |
|
| 61 | + !($pos = strripos($contenu, '</body>')) |
|
| 62 | + && !($pos = strripos($contenu, '</html>')) |
|
| 63 | + ) { |
|
| 64 | + $pos = strlen($contenu); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | - return substr_replace($contenu, (string) $boutons_admin, $pos, 0); |
|
| 68 | + return substr_replace($contenu, (string) $boutons_admin, $pos, 0); |
|
| 69 | 69 | } |
@@ -36,11 +36,11 @@ |
||
| 36 | 36 | include_spip('inc/filtres'); |
| 37 | 37 | |
| 38 | 38 | // Inserer le css d'admin |
| 39 | - $css = "<link rel='stylesheet' href='" . url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 39 | + $css = "<link rel='stylesheet' href='".url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 40 | 40 | . "' type='text/css' />\n"; |
| 41 | 41 | if ($f = find_in_path('spip_admin_perso.css')) { |
| 42 | 42 | $css .= "<link rel='stylesheet' href='" |
| 43 | - . url_absolue(direction_css($f)) . "' type='text/css' />\n"; |
|
| 43 | + . url_absolue(direction_css($f))."' type='text/css' />\n"; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | if ( |
@@ -10,123 +10,123 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 17 | - $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 18 | - $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 19 | - $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 20 | - $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 21 | - $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 22 | - $corps = $corps ? ">$corps</BOUCLE$nom>" : ' />'; |
|
| 23 | - |
|
| 24 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 17 | + $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 18 | + $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 19 | + $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 20 | + $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 21 | + $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 22 | + $corps = $corps ? ">$corps</BOUCLE$nom>" : ' />'; |
|
| 23 | + |
|
| 24 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | function format_inclure_html($file, $args, $prof) { |
| 28 | - if (!str_contains((string) $file, '#')) { |
|
| 29 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 30 | - } else { |
|
| 31 | - $t = '{fond=' . $file . '}'; |
|
| 32 | - } |
|
| 33 | - $args = $args ? '{' . implode(', ', $args) . '}' : (''); |
|
| 34 | - |
|
| 35 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 28 | + if (!str_contains((string) $file, '#')) { |
|
| 29 | + $t = $file ? ('(' . $file . ')') : ''; |
|
| 30 | + } else { |
|
| 31 | + $t = '{fond=' . $file . '}'; |
|
| 32 | + } |
|
| 33 | + $args = $args ? '{' . implode(', ', $args) . '}' : (''); |
|
| 34 | + |
|
| 35 | + return ('<INCLURE' . $t . $args . '>'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function format_polyglotte_html($args, $prof) { |
| 39 | - $contenu = []; |
|
| 40 | - foreach ($args as $l => $t) { |
|
| 41 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 42 | - } |
|
| 39 | + $contenu = []; |
|
| 40 | + foreach ($args as $l => $t) { |
|
| 41 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - return ('<multi>' . implode(' ', $contenu) . '</multi>'); |
|
| 44 | + return ('<multi>' . implode(' ', $contenu) . '</multi>'); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 48 | - foreach ($args as $k => $v) { |
|
| 49 | - $args[$k] = "$k=$v"; |
|
| 50 | - } |
|
| 51 | - $args = ($args ? '{' . implode(',', $args) . '}' : ('')); |
|
| 48 | + foreach ($args as $k => $v) { |
|
| 49 | + $args[$k] = "$k=$v"; |
|
| 50 | + } |
|
| 51 | + $args = ($args ? '{' . implode(',', $args) . '}' : ('')); |
|
| 52 | 52 | |
| 53 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 53 | + return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 57 | - $nom = '#' |
|
| 58 | - . ($boucle ? ($boucle . ':') : '') |
|
| 59 | - . $nom |
|
| 60 | - . $etoile |
|
| 61 | - . $args |
|
| 62 | - . $filtres; |
|
| 57 | + $nom = '#' |
|
| 58 | + . ($boucle ? ($boucle . ':') : '') |
|
| 59 | + . $nom |
|
| 60 | + . $etoile |
|
| 61 | + . $args |
|
| 62 | + . $filtres; |
|
| 63 | 63 | |
| 64 | - // Determiner si c'est un champ etendu, |
|
| 64 | + // Determiner si c'est un champ etendu, |
|
| 65 | 65 | |
| 66 | - $s = ($avant || $apres || $filtres || str_contains((string) $args, '(#')); |
|
| 66 | + $s = ($avant || $apres || $filtres || str_contains((string) $args, '(#')); |
|
| 67 | 67 | |
| 68 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 68 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function format_critere_html($critere) { |
| 72 | - foreach ($critere as $k => $crit) { |
|
| 73 | - $crit_s = ''; |
|
| 74 | - foreach ($crit as $operande) { |
|
| 75 | - [$type, $valeur] = $operande; |
|
| 76 | - if ($type == 'champ' && $valeur[0] == '[') { |
|
| 77 | - $valeur = substr((string) $valeur, 1, -1); |
|
| 78 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 79 | - $valeur = substr($valeur, 1, -1); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - $crit_s .= $valeur; |
|
| 83 | - } |
|
| 84 | - $critere[$k] = $crit_s; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - return ($critere ? '{' . implode(',', $critere) . '}' : ('')); |
|
| 72 | + foreach ($critere as $k => $crit) { |
|
| 73 | + $crit_s = ''; |
|
| 74 | + foreach ($crit as $operande) { |
|
| 75 | + [$type, $valeur] = $operande; |
|
| 76 | + if ($type == 'champ' && $valeur[0] == '[') { |
|
| 77 | + $valeur = substr((string) $valeur, 1, -1); |
|
| 78 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 79 | + $valeur = substr($valeur, 1, -1); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + $crit_s .= $valeur; |
|
| 83 | + } |
|
| 84 | + $critere[$k] = $crit_s; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + return ($critere ? '{' . implode(',', $critere) . '}' : ('')); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function format_liste_html($fonc, $args, $prof) { |
| 91 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 92 | - . ($args ? '{' . implode(',', $args) . '}' : (''))); |
|
| 91 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 92 | + . ($args ? '{' . implode(',', $args) . '}' : (''))); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 96 | 96 | function format_suite_html($args) { |
| 97 | - $argsCount = is_countable($args) ? count($args) : 0; |
|
| 98 | - for ($i = 0; $i < $argsCount - 1; $i++) { |
|
| 99 | - [$texte, $type] = $args[$i]; |
|
| 100 | - [$texte2, $type2] = $args[$i + 1]; |
|
| 101 | - if (!$texte || !$texte2) { |
|
| 102 | - continue; |
|
| 103 | - } |
|
| 104 | - $c1 = substr((string) $texte, -1); |
|
| 105 | - if ($type2 !== 'texte') { |
|
| 106 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 107 | - // ou assimiles, forcer la notation pleine |
|
| 108 | - if ($c1 == '(' && str_starts_with((string) $texte2, '#')) { |
|
| 109 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 110 | - } |
|
| 111 | - } else { |
|
| 112 | - if ($type == 'texte') { |
|
| 113 | - continue; |
|
| 114 | - } |
|
| 115 | - // si un champ ou assimiles est suivi d'un texte |
|
| 116 | - // et si celui-ci commence par un caractere de champ |
|
| 117 | - // forcer la notation pleine |
|
| 118 | - if ( |
|
| 119 | - $c1 == '}' && str_starts_with(ltrim((string) $texte2), '|') |
|
| 120 | - || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', (string) $texte2) |
|
| 121 | - ) { |
|
| 122 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return implode('', array_map(fn($arg) => reset($arg), $args)); |
|
| 97 | + $argsCount = is_countable($args) ? count($args) : 0; |
|
| 98 | + for ($i = 0; $i < $argsCount - 1; $i++) { |
|
| 99 | + [$texte, $type] = $args[$i]; |
|
| 100 | + [$texte2, $type2] = $args[$i + 1]; |
|
| 101 | + if (!$texte || !$texte2) { |
|
| 102 | + continue; |
|
| 103 | + } |
|
| 104 | + $c1 = substr((string) $texte, -1); |
|
| 105 | + if ($type2 !== 'texte') { |
|
| 106 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 107 | + // ou assimiles, forcer la notation pleine |
|
| 108 | + if ($c1 == '(' && str_starts_with((string) $texte2, '#')) { |
|
| 109 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 110 | + } |
|
| 111 | + } else { |
|
| 112 | + if ($type == 'texte') { |
|
| 113 | + continue; |
|
| 114 | + } |
|
| 115 | + // si un champ ou assimiles est suivi d'un texte |
|
| 116 | + // et si celui-ci commence par un caractere de champ |
|
| 117 | + // forcer la notation pleine |
|
| 118 | + if ( |
|
| 119 | + $c1 == '}' && str_starts_with(ltrim((string) $texte2), '|') |
|
| 120 | + || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', (string) $texte2) |
|
| 121 | + ) { |
|
| 122 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return implode('', array_map(fn($arg) => reset($arg), $args)); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | function format_texte_html($texte) { |
| 131 | - return $texte; |
|
| 131 | + return $texte; |
|
| 132 | 132 | } |
@@ -26,36 +26,36 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | function format_inclure_html($file, $args, $prof) { |
| 28 | 28 | if (!str_contains((string) $file, '#')) { |
| 29 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 29 | + $t = $file ? ('('.$file.')') : ''; |
|
| 30 | 30 | } else { |
| 31 | - $t = '{fond=' . $file . '}'; |
|
| 31 | + $t = '{fond='.$file.'}'; |
|
| 32 | 32 | } |
| 33 | - $args = $args ? '{' . implode(', ', $args) . '}' : (''); |
|
| 33 | + $args = $args ? '{'.implode(', ', $args).'}' : (''); |
|
| 34 | 34 | |
| 35 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 35 | + return ('<INCLURE'.$t.$args.'>'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function format_polyglotte_html($args, $prof) { |
| 39 | 39 | $contenu = []; |
| 40 | 40 | foreach ($args as $l => $t) { |
| 41 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 41 | + $contenu[] = ($l ? "[$l]" : '').$t; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - return ('<multi>' . implode(' ', $contenu) . '</multi>'); |
|
| 44 | + return ('<multi>'.implode(' ', $contenu).'</multi>'); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 48 | 48 | foreach ($args as $k => $v) { |
| 49 | 49 | $args[$k] = "$k=$v"; |
| 50 | 50 | } |
| 51 | - $args = ($args ? '{' . implode(',', $args) . '}' : ('')); |
|
| 51 | + $args = ($args ? '{'.implode(',', $args).'}' : ('')); |
|
| 52 | 52 | |
| 53 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 53 | + return ('<:'.($module ? "$module:" : '').$nom.$args.$filtres.':>'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 57 | 57 | $nom = '#' |
| 58 | - . ($boucle ? ($boucle . ':') : '') |
|
| 58 | + . ($boucle ? ($boucle.':') : '') |
|
| 59 | 59 | . $nom |
| 60 | 60 | . $etoile |
| 61 | 61 | . $args |
@@ -84,12 +84,12 @@ discard block |
||
| 84 | 84 | $critere[$k] = $crit_s; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - return ($critere ? '{' . implode(',', $critere) . '}' : ('')); |
|
| 87 | + return ($critere ? '{'.implode(',', $critere).'}' : ('')); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function format_liste_html($fonc, $args, $prof) { |
| 91 | 91 | return ((($fonc !== '') ? "|$fonc" : $fonc) |
| 92 | - . ($args ? '{' . implode(',', $args) . '}' : (''))); |
|
| 92 | + . ($args ? '{'.implode(',', $args).'}' : (''))); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | // si un texte se termine par ( et est suivi d'un champ |
| 107 | 107 | // ou assimiles, forcer la notation pleine |
| 108 | 108 | if ($c1 == '(' && str_starts_with((string) $texte2, '#')) { |
| 109 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 109 | + $args[$i + 1][0] = '[('.$texte2.')]'; |
|
| 110 | 110 | } |
| 111 | 111 | } else { |
| 112 | 112 | if ($type == 'texte') { |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $c1 == '}' && str_starts_with(ltrim((string) $texte2), '|') |
| 120 | 120 | || preg_match('/[\w\d_*]/', $c1) && preg_match('/^[\w\d_*{|]/', (string) $texte2) |
| 121 | 121 | ) { |
| 122 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 122 | + $args[$i][0] = '[('.$texte.')]'; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * texte |
| 41 | 41 | */ |
| 42 | 42 | function sandbox_composer_texte($texte, &$p) { |
| 43 | - return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 43 | + return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -56,38 +56,38 @@ discard block |
||
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | 58 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string { |
| 59 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 60 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 64 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 65 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 66 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 67 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 68 | - $refl = strpbrk((string) $f, ':') ? new ReflectionMethod($f) : new ReflectionFunction($f); |
|
| 69 | - $refs = $refl->getParameters(); |
|
| 70 | - if (isset($refs[0]) && $refs[0]->name == 'Pile') { |
|
| 71 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 72 | - $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 73 | - } else { |
|
| 74 | - $code = "$f($code$arglist)"; |
|
| 75 | - $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 76 | - } |
|
| 77 | - $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 78 | - $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 79 | - if (($nb_args_f < $min_f)) { |
|
| 80 | - $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 81 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - // le filtre n'existe pas, |
|
| 85 | - // on le notifie |
|
| 86 | - else { |
|
| 87 | - erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return $code; |
|
| 59 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 60 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 64 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 65 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 66 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 67 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 68 | + $refl = strpbrk((string) $f, ':') ? new ReflectionMethod($f) : new ReflectionFunction($f); |
|
| 69 | + $refs = $refl->getParameters(); |
|
| 70 | + if (isset($refs[0]) && $refs[0]->name == 'Pile') { |
|
| 71 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 72 | + $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 73 | + } else { |
|
| 74 | + $code = "$f($code$arglist)"; |
|
| 75 | + $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 76 | + } |
|
| 77 | + $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 78 | + $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 79 | + if (($nb_args_f < $min_f)) { |
|
| 80 | + $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 81 | + erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + // le filtre n'existe pas, |
|
| 85 | + // on le notifie |
|
| 86 | + else { |
|
| 87 | + erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return $code; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Calculer un <INCLURE(xx.php)> |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 113 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 114 | - // si inexistant, on essaiera a l'execution |
|
| 115 | - $path = ($path = find_in_path($fichier)) ? "\"$path\"" : "find_in_path(\"$fichier\")"; |
|
| 113 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 114 | + // si inexistant, on essaiera a l'execution |
|
| 115 | + $path = ($path = find_in_path($fichier)) ? "\"$path\"" : "find_in_path(\"$fichier\")"; |
|
| 116 | 116 | |
| 117 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 117 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -126,20 +126,20 @@ discard block |
||
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | 128 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 129 | - // Securite |
|
| 130 | - if ( |
|
| 131 | - $p->interdire_scripts |
|
| 132 | - && $p->etoile != '**' |
|
| 133 | - ) { |
|
| 134 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 135 | - $code = "interdire_scripts($code)"; |
|
| 136 | - } else { |
|
| 137 | - $code = interdire_scripts($r[2]); |
|
| 138 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $code; |
|
| 129 | + // Securite |
|
| 130 | + if ( |
|
| 131 | + $p->interdire_scripts |
|
| 132 | + && $p->etoile != '**' |
|
| 133 | + ) { |
|
| 134 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 135 | + $code = "interdire_scripts($code)"; |
|
| 136 | + } else { |
|
| 137 | + $code = interdire_scripts($r[2]); |
|
| 138 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $code; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -158,30 +158,30 @@ discard block |
||
| 158 | 158 | * @return mixed|string |
| 159 | 159 | */ |
| 160 | 160 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 161 | - $series_filtres = func_get_args(); |
|
| 162 | - array_shift($series_filtres);// skel |
|
| 163 | - array_shift($series_filtres);// corps |
|
| 164 | - |
|
| 165 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 166 | - if ($skel['process_ins'] == 'php') { |
|
| 167 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // recuperer les couples de remplacement |
|
| 171 | - $replace = echapper_php_callback(); |
|
| 172 | - |
|
| 173 | - foreach ($series_filtres as $filtres) { |
|
| 174 | - if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 175 | - foreach ($filtres as $filtre) { |
|
| 176 | - if ($filtre && ($f = chercher_filtre($filtre))) { |
|
| 177 | - $corps = $f($corps); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // restaurer les echappements |
|
| 184 | - return str_replace($replace[0], $replace[1], (string) $corps); |
|
| 161 | + $series_filtres = func_get_args(); |
|
| 162 | + array_shift($series_filtres);// skel |
|
| 163 | + array_shift($series_filtres);// corps |
|
| 164 | + |
|
| 165 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 166 | + if ($skel['process_ins'] == 'php') { |
|
| 167 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // recuperer les couples de remplacement |
|
| 171 | + $replace = echapper_php_callback(); |
|
| 172 | + |
|
| 173 | + foreach ($series_filtres as $filtres) { |
|
| 174 | + if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 175 | + foreach ($filtres as $filtre) { |
|
| 176 | + if ($filtre && ($f = chercher_filtre($filtre))) { |
|
| 177 | + $corps = $f($corps); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // restaurer les echappements |
|
| 184 | + return str_replace($replace[0], $replace[1], (string) $corps); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
@@ -200,21 +200,21 @@ discard block |
||
| 200 | 200 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 201 | 201 | **/ |
| 202 | 202 | function echapper_php_callback($r = null) { |
| 203 | - static $src = []; |
|
| 204 | - static $dst = []; |
|
| 203 | + static $src = []; |
|
| 204 | + static $dst = []; |
|
| 205 | 205 | |
| 206 | - // si on recoit un tableau, on est en mode echappement |
|
| 207 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 208 | - if (is_array($r)) { |
|
| 209 | - $dst[] = $r[0]; |
|
| 206 | + // si on recoit un tableau, on est en mode echappement |
|
| 207 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 208 | + if (is_array($r)) { |
|
| 209 | + $dst[] = $r[0]; |
|
| 210 | 210 | |
| 211 | - return $src[] = '___' . md5((string) $r[0]) . '___'; |
|
| 212 | - } |
|
| 211 | + return $src[] = '___' . md5((string) $r[0]) . '___'; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 215 | - // et on RAZ les remplacements |
|
| 216 | - $r = [$src, $dst]; |
|
| 217 | - $src = $dst = []; |
|
| 214 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 215 | + // et on RAZ les remplacements |
|
| 216 | + $r = [$src, $dst]; |
|
| 217 | + $src = $dst = []; |
|
| 218 | 218 | |
| 219 | - return $r; |
|
| 219 | + return $r; |
|
| 220 | 220 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * texte |
| 41 | 41 | */ |
| 42 | 42 | function sandbox_composer_texte($texte, &$p) { |
| 43 | - return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 43 | + return "'".str_replace(['\\', "'"], ['\\\\', "\\'"], $texte)."'"; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $min_f = $refl->getNumberOfRequiredParameters(); |
| 79 | 79 | if (($nb_args_f < $min_f)) { |
| 80 | 80 | $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
| 81 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 81 | + erreur_squelette(['zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | // le filtre n'existe pas, |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 161 | 161 | $series_filtres = func_get_args(); |
| 162 | - array_shift($series_filtres);// skel |
|
| 163 | - array_shift($series_filtres);// corps |
|
| 162 | + array_shift($series_filtres); // skel |
|
| 163 | + array_shift($series_filtres); // corps |
|
| 164 | 164 | |
| 165 | 165 | // proteger les <INCLUDE> et tous les morceaux de php licites |
| 166 | 166 | if ($skel['process_ins'] == 'php') { |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | if (is_array($r)) { |
| 209 | 209 | $dst[] = $r[0]; |
| 210 | 210 | |
| 211 | - return $src[] = '___' . md5((string) $r[0]) . '___'; |
|
| 211 | + return $src[] = '___'.md5((string) $r[0]).'___'; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | // si on recoit pas un tableau, on renvoit les couples de substitution |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -38,59 +38,59 @@ discard block |
||
| 38 | 38 | * @return array |
| 39 | 39 | */ |
| 40 | 40 | function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') { |
| 41 | - static $styliser_par_z; |
|
| 42 | - |
|
| 43 | - // s'assurer que le fond est licite |
|
| 44 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 45 | - if (str_contains($fond, '../') || str_starts_with($fond, '/')) { |
|
| 46 | - $fond = '404'; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if (str_starts_with($fond, 'modeles/')) { |
|
| 50 | - $modele = substr($fond, 8); |
|
| 51 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 52 | - $fond = "modeles/$modele"; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 56 | - $id_rubrique = 0; |
|
| 57 | - // Chercher le fond qui va servir de squelette |
|
| 58 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 59 | - [$id_rubrique, $lang] = $r; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // trouver un squelette du nom demande |
|
| 63 | - // ne rien dire si on ne trouve pas, |
|
| 64 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 65 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 66 | - $squelette = trouver_fond($fond, '', true); |
|
| 67 | - $ext = $squelette['extension']; |
|
| 68 | - |
|
| 69 | - $flux = [ |
|
| 70 | - 'args' => [ |
|
| 71 | - 'id_rubrique' => $id_rubrique, |
|
| 72 | - 'ext' => $ext, |
|
| 73 | - 'fond' => $fond, |
|
| 74 | - 'lang' => $lang, |
|
| 75 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 76 | - 'connect' => $connect |
|
| 77 | - ], |
|
| 78 | - 'data' => $squelette['fond'], |
|
| 79 | - ]; |
|
| 80 | - |
|
| 81 | - if (test_espace_prive() || defined('_ZPIP')) { |
|
| 82 | - if (!$styliser_par_z) { |
|
| 83 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 84 | - } |
|
| 85 | - $flux = $styliser_par_z($flux); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $flux = styliser_par_objets($flux); |
|
| 89 | - |
|
| 90 | - // pipeline styliser |
|
| 91 | - $squelette = pipeline('styliser', $flux); |
|
| 92 | - |
|
| 93 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 41 | + static $styliser_par_z; |
|
| 42 | + |
|
| 43 | + // s'assurer que le fond est licite |
|
| 44 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 45 | + if (str_contains($fond, '../') || str_starts_with($fond, '/')) { |
|
| 46 | + $fond = '404'; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if (str_starts_with($fond, 'modeles/')) { |
|
| 50 | + $modele = substr($fond, 8); |
|
| 51 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 52 | + $fond = "modeles/$modele"; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 56 | + $id_rubrique = 0; |
|
| 57 | + // Chercher le fond qui va servir de squelette |
|
| 58 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 59 | + [$id_rubrique, $lang] = $r; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // trouver un squelette du nom demande |
|
| 63 | + // ne rien dire si on ne trouve pas, |
|
| 64 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 65 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 66 | + $squelette = trouver_fond($fond, '', true); |
|
| 67 | + $ext = $squelette['extension']; |
|
| 68 | + |
|
| 69 | + $flux = [ |
|
| 70 | + 'args' => [ |
|
| 71 | + 'id_rubrique' => $id_rubrique, |
|
| 72 | + 'ext' => $ext, |
|
| 73 | + 'fond' => $fond, |
|
| 74 | + 'lang' => $lang, |
|
| 75 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 76 | + 'connect' => $connect |
|
| 77 | + ], |
|
| 78 | + 'data' => $squelette['fond'], |
|
| 79 | + ]; |
|
| 80 | + |
|
| 81 | + if (test_espace_prive() || defined('_ZPIP')) { |
|
| 82 | + if (!$styliser_par_z) { |
|
| 83 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 84 | + } |
|
| 85 | + $flux = $styliser_par_z($flux); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $flux = styliser_par_objets($flux); |
|
| 89 | + |
|
| 90 | + // pipeline styliser |
|
| 91 | + $squelette = pipeline('styliser', $flux); |
|
| 92 | + |
|
| 93 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -109,32 +109,32 @@ discard block |
||
| 109 | 109 | * Données du pipeline styliser |
| 110 | 110 | **/ |
| 111 | 111 | function styliser_par_objets($flux) { |
| 112 | - if ( |
|
| 113 | - test_espace_prive() |
|
| 114 | - && !($squelette = $flux['data']) |
|
| 115 | - && str_starts_with((string) $flux['args']['fond'], 'prive/objets/') |
|
| 116 | - && ($echafauder = charger_fonction('echafauder', 'prive', true)) |
|
| 117 | - ) { |
|
| 118 | - if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/liste/')) { |
|
| 119 | - $table = table_objet(substr((string) $flux['args']['fond'], 19)); |
|
| 120 | - $table_sql = table_objet_sql($table); |
|
| 121 | - $objets = lister_tables_objets_sql(); |
|
| 122 | - if (isset($objets[$table_sql])) { |
|
| 123 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/contenu/')) { |
|
| 127 | - $type = substr((string) $flux['args']['fond'], 21); |
|
| 128 | - $table = table_objet($type); |
|
| 129 | - $table_sql = table_objet_sql($table); |
|
| 130 | - $objets = lister_tables_objets_sql(); |
|
| 131 | - if (isset($objets[$table_sql])) { |
|
| 132 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $flux; |
|
| 112 | + if ( |
|
| 113 | + test_espace_prive() |
|
| 114 | + && !($squelette = $flux['data']) |
|
| 115 | + && str_starts_with((string) $flux['args']['fond'], 'prive/objets/') |
|
| 116 | + && ($echafauder = charger_fonction('echafauder', 'prive', true)) |
|
| 117 | + ) { |
|
| 118 | + if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/liste/')) { |
|
| 119 | + $table = table_objet(substr((string) $flux['args']['fond'], 19)); |
|
| 120 | + $table_sql = table_objet_sql($table); |
|
| 121 | + $objets = lister_tables_objets_sql(); |
|
| 122 | + if (isset($objets[$table_sql])) { |
|
| 123 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + if (str_starts_with((string) $flux['args']['fond'], 'prive/objets/contenu/')) { |
|
| 127 | + $type = substr((string) $flux['args']['fond'], 21); |
|
| 128 | + $table = table_objet($type); |
|
| 129 | + $table_sql = table_objet_sql($table); |
|
| 130 | + $objets = lister_tables_objets_sql(); |
|
| 131 | + if (isset($objets[$table_sql])) { |
|
| 132 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $flux; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -150,47 +150,47 @@ discard block |
||
| 150 | 150 | * @return array|false |
| 151 | 151 | */ |
| 152 | 152 | function quete_rubrique_fond($contexte) { |
| 153 | - static $liste_objets = null; |
|
| 154 | - static $quete = []; |
|
| 155 | - if (is_null($liste_objets)) { |
|
| 156 | - $liste_objets = []; |
|
| 157 | - include_spip('inc/urls'); |
|
| 158 | - include_spip('public/quete'); |
|
| 159 | - $l = urls_liste_objets(false); |
|
| 160 | - // placer la rubrique en tete des objets |
|
| 161 | - $l = array_diff($l, ['rubrique']); |
|
| 162 | - array_unshift($l, 'rubrique'); |
|
| 163 | - foreach ($l as $objet) { |
|
| 164 | - $id = id_table_objet($objet); |
|
| 165 | - if (!isset($liste_objets[$id])) { |
|
| 166 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 171 | - if ($c === []) { |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $c = array_map('intval', $c); |
|
| 176 | - $s = serialize($c); |
|
| 177 | - if (isset($quete[$s])) { |
|
| 178 | - return $quete[$s]; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if (isset($c['id_rubrique']) && ($r = $c['id_rubrique'])) { |
|
| 182 | - unset($c['id_rubrique']); |
|
| 183 | - $c = ['id_rubrique' => $r] + $c; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - foreach ($c as $_id => $id) { |
|
| 187 | - if ($id && ($row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id))) { |
|
| 188 | - $lang = $row['lang'] ?? ''; |
|
| 189 | - if ($_id == 'id_rubrique' || isset($row['id_rubrique']) && ($id = $row['id_rubrique'])) { |
|
| 190 | - return $quete[$s] = [$id, $lang]; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return $quete[$s] = false; |
|
| 153 | + static $liste_objets = null; |
|
| 154 | + static $quete = []; |
|
| 155 | + if (is_null($liste_objets)) { |
|
| 156 | + $liste_objets = []; |
|
| 157 | + include_spip('inc/urls'); |
|
| 158 | + include_spip('public/quete'); |
|
| 159 | + $l = urls_liste_objets(false); |
|
| 160 | + // placer la rubrique en tete des objets |
|
| 161 | + $l = array_diff($l, ['rubrique']); |
|
| 162 | + array_unshift($l, 'rubrique'); |
|
| 163 | + foreach ($l as $objet) { |
|
| 164 | + $id = id_table_objet($objet); |
|
| 165 | + if (!isset($liste_objets[$id])) { |
|
| 166 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 171 | + if ($c === []) { |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $c = array_map('intval', $c); |
|
| 176 | + $s = serialize($c); |
|
| 177 | + if (isset($quete[$s])) { |
|
| 178 | + return $quete[$s]; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if (isset($c['id_rubrique']) && ($r = $c['id_rubrique'])) { |
|
| 182 | + unset($c['id_rubrique']); |
|
| 183 | + $c = ['id_rubrique' => $r] + $c; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + foreach ($c as $_id => $id) { |
|
| 187 | + if ($id && ($row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id))) { |
|
| 188 | + $lang = $row['lang'] ?? ''; |
|
| 189 | + if ($_id == 'id_rubrique' || isset($row['id_rubrique']) && ($id = $row['id_rubrique'])) { |
|
| 190 | + return $quete[$s] = [$id, $lang]; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return $quete[$s] = false; |
|
| 196 | 196 | } |
@@ -2069,8 +2069,7 @@ discard block |
||
| 2069 | 2069 | // Champ joker * des iterateurs DATA qui accepte tout |
| 2070 | 2070 | if (@array_key_exists('*', $desc['field'])) { |
| 2071 | 2071 | $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
| 2072 | - } |
|
| 2073 | - else { |
|
| 2072 | + } else { |
|
| 2074 | 2073 | $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
| 2075 | 2074 | if (!$r) { |
| 2076 | 2075 | return ''; |
@@ -2112,8 +2111,7 @@ discard block |
||
| 2112 | 2111 | . ((isset($r[2]) && $r[2]) ? $r[2] : ",''") |
| 2113 | 2112 | . ",'" . addslashes((string) $type_cast_quote) . "'"; |
| 2114 | 2113 | $val[0] = "sql_quote($r)"; |
| 2115 | - } |
|
| 2116 | - elseif ( |
|
| 2114 | + } elseif ( |
|
| 2117 | 2115 | str_contains((string) $val[0], '@@defaultcast@@') |
| 2118 | 2116 | && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
| 2119 | 2117 | ) { |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $boucle = &$boucles[$idb]; |
| 51 | 51 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 52 | 52 | |
| 53 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 53 | + $c = ["'='", "'$boucle->id_table."."$id_parent'", 0]; |
|
| 54 | 54 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | $id = $boucle->primary; |
| 74 | 74 | |
| 75 | 75 | if ($not || !$id) { |
| 76 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 76 | + return ['zbug_critere_inconnu', ['critere' => $not.$crit->op]]; |
|
| 77 | 77 | } |
| 78 | 78 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 79 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 79 | + $boucle->where[] = ["'!='", "'$boucle->id_table."."$id'", $arg]; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | $not = ($crit->not ? '' : 'NOT'); |
| 108 | 108 | |
| 109 | 109 | // le doublon s'applique sur un type de boucle (article) |
| 110 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | + $nom = "'".$boucle->type_requete."'"; |
|
| 111 | 111 | |
| 112 | 112 | // compléter le nom avec un nom précisé {doublons nom} |
| 113 | 113 | // on obtient $nom = "'article' . 'nom'" |
| 114 | 114 | if (isset($crit->param[0])) { |
| 115 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | + $nom .= '.'.calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -124,13 +124,13 @@ discard block |
||
| 124 | 124 | // $doublons et son index, ici $nom |
| 125 | 125 | |
| 126 | 126 | // debut du code "sql_in('articles.id_article', " |
| 127 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 128 | 128 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 129 | 129 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 130 | - $debut_doub = '$doublons[' . ($not ? $boucle->doublons . '[]= ' : ('')); |
|
| 130 | + $debut_doub = '$doublons['.($not ? $boucle->doublons.'[]= ' : ('')); |
|
| 131 | 131 | |
| 132 | 132 | // le debut complet du code des doublons |
| 133 | - $debut_doub = $debut_in . $debut_doub; |
|
| 133 | + $debut_doub = $debut_in.$debut_doub; |
|
| 134 | 134 | |
| 135 | 135 | // nom du doublon "('article' . 'nom')]" |
| 136 | 136 | $fin_doub = "($nom)]"; |
@@ -140,22 +140,22 @@ discard block |
||
| 140 | 140 | foreach ($boucle->where as $k => $w) { |
| 141 | 141 | if (str_starts_with((string) $w[0], $debut_doub)) { |
| 142 | 142 | // fusionner le sql_in (du where) |
| 143 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr((string) $w[0], strlen($debut_in)); |
|
| 143 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr((string) $w[0], strlen($debut_in)); |
|
| 144 | 144 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 145 | 145 | $x = strpos((string) $boucle->hash, $init_comment); |
| 146 | 146 | $len = strlen($init_comment); |
| 147 | 147 | $boucle->hash = |
| 148 | - substr((string) $boucle->hash, 0, $x + $len) . $init_code . substr((string) $boucle->hash, $x + $len); |
|
| 148 | + substr((string) $boucle->hash, 0, $x + $len).$init_code.substr((string) $boucle->hash, $x + $len); |
|
| 149 | 149 | |
| 150 | 150 | return; |
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 155 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 155 | + $boucle->where[] = [$debut_doub.$fin_doub.", '".$not."')"]; |
|
| 156 | 156 | |
| 157 | 157 | // déclarer le doublon s'il n'existe pas encore |
| 158 | - $boucle->hash .= $init_comment . $init_code; |
|
| 158 | + $boucle->hash .= $init_comment.$init_code; |
|
| 159 | 159 | |
| 160 | 160 | |
| 161 | 161 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $deux = $deux[0]->texte; |
| 218 | 218 | if ($deux) { |
| 219 | 219 | $boucles[$idb]->limit = |
| 220 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 220 | + 'intval($Pile[0]["debut'.$un.'"]) . ",'.$deux.'"'; |
|
| 221 | 221 | } else { |
| 222 | 222 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
| 223 | 223 | } |
@@ -280,26 +280,26 @@ discard block |
||
| 280 | 280 | $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr((string) $type, 1)); |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr((string) $type, 1)); |
|
| 284 | 284 | $boucle->modificateur['debut_nom'] = $type; |
| 285 | 285 | $partie = |
| 286 | 286 | // tester si le numero de page demande est de la forme '@yyy' |
| 287 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 287 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 288 | 288 | . "\tif (\$debut_boucle && \$debut_boucle[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" |
|
| 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" |
|
| 291 | 291 | . "\t}\n" |
| 292 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 292 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 293 | 293 | |
| 294 | 294 | $boucle->hash .= ' |
| 295 | - $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.');'; |
|
| 296 | 296 | |
| 297 | 297 | $boucle->total_parties = $pas; |
| 298 | 298 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 299 | 299 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 300 | 300 | // sauf si pas de primaire, ou si primaire composee |
| 301 | 301 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 302 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 302 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 303 | 303 | if ( |
| 304 | 304 | $boucle->primary |
| 305 | 305 | && !preg_match('/[,\s]/', (string) $boucle->primary) |
@@ -346,24 +346,24 @@ discard block |
||
| 346 | 346 | $boucle->hash .= ' |
| 347 | 347 | // RECHERCHE' |
| 348 | 348 | . ($crit->cond ? ' |
| 349 | - if (!strlen(' . $quoi . ')){ |
|
| 349 | + if (!strlen(' . $quoi.')){ |
|
| 350 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | - } else' : '') . ' |
|
| 351 | + } else' : '').' |
|
| 352 | 352 | { |
| 353 | 353 | $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 . '"); |
|
| 354 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 355 | 355 | } |
| 356 | 356 | '; |
| 357 | 357 | |
| 358 | 358 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 359 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 360 | 360 | if (!in_array($t, $boucles[$idb]->select)) { |
| 361 | 361 | $boucle->select[] = $t; |
| 362 | 362 | } # pour postgres, neuneu ici |
| 363 | 363 | // jointure uniquement sur le serveur principal |
| 364 | 364 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 365 | 365 | if (!$boucle->sql_serveur) { |
| 366 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 366 | + $boucle->join['resultats'] = ["'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"]; |
|
| 367 | 367 | $boucle->from['resultats'] = 'spip_resultats'; |
| 368 | 368 | } |
| 369 | 369 | $boucle->select[] = '$rech_select'; |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | $c = |
| 431 | 431 | [ |
| 432 | 432 | "'OR'", |
| 433 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 433 | + ["'='", "'$table."."id_trad'", "'$table.$prim'"], |
|
| 434 | 434 | ["'='", "'$table.id_trad'", "'0'"] |
| 435 | 435 | ]; |
| 436 | 436 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
@@ -453,13 +453,13 @@ discard block |
||
| 453 | 453 | $boucle = &$boucles[$idb]; |
| 454 | 454 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 455 | 455 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 456 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 456 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 457 | 457 | |
| 458 | 458 | if ($boucle->type_requete == 'rubriques' || isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 459 | 459 | $boucle->where[] = ["'='", "'$mparent'", $arg]; |
| 460 | 460 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 461 | 461 | else { |
| 462 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 462 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$boucle->type_requete]]; |
|
| 463 | 463 | } |
| 464 | 464 | } |
| 465 | 465 | |
@@ -512,16 +512,16 @@ discard block |
||
| 512 | 512 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 513 | 513 | $decompose = decompose_champ_id_objet($champ); |
| 514 | 514 | $champ = array_shift($decompose); |
| 515 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 515 | + $boucle->where[] = ["'='", _q($cle.'.'.reset($decompose)), '"'.sql_quote(end($decompose)).'"']; |
|
| 516 | 516 | } |
| 517 | 517 | } else { |
| 518 | 518 | $cle = $boucle->id_table; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 521 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 522 | + . ($not ? ", 'NOT'" : '').')'; |
|
| 523 | 523 | $boucle->where[] = $crit->cond |
| 524 | - ? "($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')' |
|
| 524 | + ? "($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')' |
|
| 525 | 525 | : $c; |
| 526 | 526 | } |
| 527 | 527 | |
@@ -542,9 +542,9 @@ discard block |
||
| 542 | 542 | $not = ($crit->not ? 'NOT' : ''); |
| 543 | 543 | $serveur = $boucle->sql_serveur; |
| 544 | 544 | |
| 545 | - $c = "sql_in('" . |
|
| 546 | - $boucle->id_table . '.' . $boucle->primary |
|
| 547 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 545 | + $c = "sql_in('". |
|
| 546 | + $boucle->id_table.'.'.$boucle->primary |
|
| 547 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '$not', '$serveur')"; |
|
| 548 | 548 | |
| 549 | 549 | $boucle->where[] = $c; |
| 550 | 550 | } |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | $t = table_objet_sql($r[1]); |
| 577 | 577 | $t = array_search($t, $boucles[$idb]->from); |
| 578 | 578 | if ($t) { |
| 579 | - $t .= '.' . $r[2]; |
|
| 579 | + $t .= '.'.$r[2]; |
|
| 580 | 580 | } |
| 581 | 581 | } |
| 582 | 582 | } else { |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | $boucles[$idb]->select[] = $t; |
| 592 | 592 | } |
| 593 | 593 | } else { |
| 594 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 594 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 595 | 595 | } |
| 596 | 596 | } |
| 597 | 597 | |
@@ -661,25 +661,25 @@ discard block |
||
| 661 | 661 | (false !== $i = strpos((string) $boucle->order[$n - 1], 'ASC')) |
| 662 | 662 | || (false !== $i = strpos((string) $boucle->order[$n - 1], 'DESC')) |
| 663 | 663 | ) { |
| 664 | - $boucle->order[$n - 1] = substr_replace((string) $boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 664 | + $boucle->order[$n - 1] = substr_replace((string) $boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 665 | 665 | } else { |
| 666 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 666 | + $boucle->order[$n - 1] .= ' . '.$boucle->modificateur['collate']; |
|
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | } else { |
| 670 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 670 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' '.(is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 675 | 675 | $boucle = $boucles[$idb]; |
| 676 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 677 | - $var = '$champs_' . $idb; |
|
| 676 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 677 | + $var = '$champs_'.$idb; |
|
| 678 | 678 | $desc = (str_contains((string) $boucle->in, (string) "static $var =")); |
| 679 | 679 | if (!$desc) { |
| 680 | 680 | $desc = $boucle->show['field']; |
| 681 | 681 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 682 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 682 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.');'; |
|
| 683 | 683 | } |
| 684 | 684 | if ($desc) { |
| 685 | 685 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | $sens = " . ' DESC'"; |
| 755 | 755 | } |
| 756 | 756 | if (isset($boucle->modificateur['collate'])) { |
| 757 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 757 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | // Pour chaque paramètre du critère |
@@ -776,14 +776,14 @@ discard block |
||
| 776 | 776 | if (preg_match(',^(\w+)[\s]+(.*)$,', (string) $par, $m)) { |
| 777 | 777 | $expression = trim($m[1]); |
| 778 | 778 | $champ = trim($m[2]); |
| 779 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 779 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 780 | 780 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 781 | 781 | } else { |
| 782 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 782 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 786 | - } elseif ($boucle->type_requete == 'DATA' || preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', (string) $par, $match)) { |
|
| 786 | + } elseif ($boucle->type_requete == 'DATA' || preg_match(',^'.CHAMP_SQL_PLUS_FONC.'$,is', (string) $par, $match)) { |
|
| 787 | 787 | // {par FONCTION(champ)} |
| 788 | 788 | if (isset($match) && count($match) > 2) { |
| 789 | 789 | $par = substr($match[2], 1, -1); |
@@ -793,7 +793,7 @@ discard block |
||
| 793 | 793 | if ($par == 'hasard') { |
| 794 | 794 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 795 | 795 | } elseif ($par == 'date' && !empty($boucle->show['date'])) { |
| 796 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 796 | + $order = "'".$boucle->id_table.'.'.$boucle->show['date']."'"; |
|
| 797 | 797 | } else { |
| 798 | 798 | // cas général {par champ}, {par table.champ}, ... |
| 799 | 799 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | |
| 803 | 803 | // on ne sait pas traiter… |
| 804 | 804 | else { |
| 805 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 805 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | // En cas d'erreur de squelette retournée par une fonction |
@@ -822,12 +822,12 @@ discard block |
||
| 822 | 822 | |
| 823 | 823 | if ($fct) { |
| 824 | 824 | $order = preg_match("/^\s*'(.*)'\s*$/", (string) $order, $r) |
| 825 | - ? "'$fct(" . $r[1] . ")'" |
|
| 825 | + ? "'$fct(".$r[1].")'" |
|
| 826 | 826 | : "'$fct(' . $order . ')'"; |
| 827 | 827 | } |
| 828 | - $t = $order . $collecte . $sens; |
|
| 828 | + $t = $order.$collecte.$sens; |
|
| 829 | 829 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 830 | - $t = $r[1] . $r[2]; |
|
| 830 | + $t = $r[1].$r[2]; |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | $boucle->order[] = $t; |
@@ -877,16 +877,16 @@ discard block |
||
| 877 | 877 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 878 | 878 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 879 | 879 | if (is_array($_champ)) { |
| 880 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 880 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." num $champ"]]; |
|
| 881 | 881 | } |
| 882 | 882 | $boucle = &$boucles[$idb]; |
| 883 | - $texte = '0+' . $_champ; |
|
| 883 | + $texte = '0+'.$_champ; |
|
| 884 | 884 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 885 | 885 | if ($suite !== "''") { |
| 886 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 886 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 887 | 887 | } |
| 888 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 889 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 888 | + $asnum = 'num'.($boucle->order ? count($boucle->order) : ''); |
|
| 889 | + $boucle->select[] = $texte." AS $asnum"; |
|
| 890 | 890 | |
| 891 | 891 | $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
| 892 | 892 | $orderassinum = trim($orderassinum, "'"); |
@@ -913,13 +913,13 @@ discard block |
||
| 913 | 913 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 914 | 914 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 915 | 915 | if (is_array($_champ)) { |
| 916 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." sinum $champ"]]; |
|
| 917 | 917 | } |
| 918 | 918 | $boucle = &$boucles[$idb]; |
| 919 | - $texte = '0+' . $_champ; |
|
| 919 | + $texte = '0+'.$_champ; |
|
| 920 | 920 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 921 | 921 | if ($suite !== "''") { |
| 922 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | $as = false; |
@@ -935,8 +935,8 @@ discard block |
||
| 935 | 935 | } |
| 936 | 936 | |
| 937 | 937 | if (!$as) { |
| 938 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 939 | - $boucle->select[] = $select . $as; |
|
| 938 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ''); |
|
| 939 | + $boucle->select[] = $select.$as; |
|
| 940 | 940 | } |
| 941 | 941 | return "'$as'"; |
| 942 | 942 | } |
@@ -960,10 +960,10 @@ discard block |
||
| 960 | 960 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | 961 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 962 | 962 | if (is_array($_champ)) { |
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 963 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." multi $champ"]]; |
|
| 964 | 964 | } |
| 965 | 965 | $boucle = &$boucles[$idb]; |
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 966 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 967 | 967 | return "'multi'"; |
| 968 | 968 | } |
| 969 | 969 | |
@@ -988,7 +988,7 @@ discard block |
||
| 988 | 988 | |
| 989 | 989 | // le champ existe dans la table, pas de souci (le plus commun) |
| 990 | 990 | if (isset($desc['field'][$par])) { |
| 991 | - $par = $boucle->id_table . '.' . $par; |
|
| 991 | + $par = $boucle->id_table.'.'.$par; |
|
| 992 | 992 | } |
| 993 | 993 | // le champ est peut être une jointure |
| 994 | 994 | else { |
@@ -1009,24 +1009,24 @@ discard block |
||
| 1009 | 1009 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 1010 | 1010 | // Si la table est déjà dans le from, on la réutilise. |
| 1011 | 1011 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 1012 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1012 | + $par = $infos['alias'].'.'.$champ; |
|
| 1013 | 1013 | } elseif ( |
| 1014 | 1014 | $boucle->jointures_explicites |
| 1015 | 1015 | && ($alias = trouver_jointure_champ($champ, $boucle, explode(' ', (string) $boucle->jointures_explicites), false, $table)) |
| 1016 | 1016 | ) { |
| 1017 | - $par = $alias . '.' . $champ; |
|
| 1017 | + $par = $alias.'.'.$champ; |
|
| 1018 | 1018 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 1019 | - $par = $alias . '.' . $champ; |
|
| 1019 | + $par = $alias.'.'.$champ; |
|
| 1020 | 1020 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 1021 | 1021 | } elseif ( |
| 1022 | 1022 | $table_alias |
| 1023 | 1023 | && isset($boucle->from[$table_alias]) |
| 1024 | 1024 | && ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias])) |
| 1025 | 1025 | ) { |
| 1026 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1026 | + $par = $infos['alias'].'.'.$champ; |
|
| 1027 | 1027 | } elseif ($table) { |
| 1028 | 1028 | // On avait table + champ, mais on ne les a pas trouvés |
| 1029 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1029 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 1030 | 1030 | } else { |
| 1031 | 1031 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1032 | 1032 | } |
@@ -1077,9 +1077,9 @@ discard block |
||
| 1077 | 1077 | $boucle->default_order[] = ' DESC'; |
| 1078 | 1078 | } |
| 1079 | 1079 | } else { |
| 1080 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1080 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1081 | 1081 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1082 | - $t = $r[1] . $r[2]; |
|
| 1082 | + $t = $r[1].$r[2]; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | $boucle->order[$n - 1] = $t; |
| 1085 | 1085 | } |
@@ -1116,7 +1116,7 @@ discard block |
||
| 1116 | 1116 | |
| 1117 | 1117 | $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
| 1118 | 1118 | |
| 1119 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1119 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'".$boucle->sql_serveur."')) ? \$zl : '0').')'$sens"; |
|
| 1120 | 1120 | $boucle->order[] = $order; |
| 1121 | 1121 | } |
| 1122 | 1122 | |
@@ -1125,7 +1125,7 @@ discard block |
||
| 1125 | 1125 | $params = $crit->param; |
| 1126 | 1126 | |
| 1127 | 1127 | if ((is_countable($params) ? count($params) : 0) < 1) { |
| 1128 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1128 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | $boucle = &$boucles[$idb]; |
@@ -1146,7 +1146,7 @@ discard block |
||
| 1146 | 1146 | if ((is_countable($date) ? count($date) : 0) == 1 && $date[0]->type == 'texte') { |
| 1147 | 1147 | $date = $date[0]->texte; |
| 1148 | 1148 | if (!isset($fields[$date])) { |
| 1149 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1149 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$date]]; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | } else { |
| 1152 | 1152 | $a = calculer_liste($date, $idb, $boucles, $parent); |
@@ -1158,38 +1158,38 @@ discard block |
||
| 1158 | 1158 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1159 | 1159 | } |
| 1160 | 1160 | $annee = $params ? array_shift($params) : ''; |
| 1161 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1162 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1161 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1162 | + calculer_liste($annee, $idb, $boucles, $parent). |
|
| 1163 | 1163 | ') ? $x : date("Y"))'; |
| 1164 | 1164 | |
| 1165 | 1165 | $mois = $params ? array_shift($params) : ''; |
| 1166 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1167 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1166 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1167 | + calculer_liste($mois, $idb, $boucles, $parent). |
|
| 1168 | 1168 | ') ? $x : date("m"))'; |
| 1169 | 1169 | |
| 1170 | 1170 | $jour = $params ? array_shift($params) : ''; |
| 1171 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1172 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1171 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1172 | + calculer_liste($jour, $idb, $boucles, $parent). |
|
| 1173 | 1173 | ') ? $x : date("d"))'; |
| 1174 | 1174 | |
| 1175 | 1175 | $annee2 = $params ? array_shift($params) : ''; |
| 1176 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1177 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1176 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1177 | + calculer_liste($annee2, $idb, $boucles, $parent). |
|
| 1178 | 1178 | ') ? $x : date("Y"))'; |
| 1179 | 1179 | |
| 1180 | 1180 | $mois2 = $params ? array_shift($params) : ''; |
| 1181 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1182 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1181 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1182 | + calculer_liste($mois2, $idb, $boucles, $parent). |
|
| 1183 | 1183 | ') ? $x : date("m"))'; |
| 1184 | 1184 | |
| 1185 | 1185 | $jour2 = $params ? array_shift($params) : ''; |
| 1186 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1187 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1186 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1187 | + calculer_liste($jour2, $idb, $boucles, $parent). |
|
| 1188 | 1188 | ') ? $x : date("d"))'; |
| 1189 | 1189 | |
| 1190 | - $date = $boucle->id_table . ".$date"; |
|
| 1190 | + $date = $boucle->id_table.".$date"; |
|
| 1191 | 1191 | |
| 1192 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1192 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1193 | 1193 | if ($type == 'jour') { |
| 1194 | 1194 | $boucle->where[] = [ |
| 1195 | 1195 | "'='", |
@@ -1261,14 +1261,13 @@ discard block |
||
| 1261 | 1261 | [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1262 | 1262 | |
| 1263 | 1263 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1264 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1264 | + $boucle->limit = $a11.','.$a21; |
|
| 1265 | 1265 | } else { |
| 1266 | 1266 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1267 | 1267 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1268 | 1268 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1269 | 1269 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1270 | - $mode = (($op == '/') ? '/' : |
|
| 1271 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1270 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1272 | 1271 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1273 | 1272 | if ($a11 !== 'n' && $a21 !== 'n' && $mode == '++' && $op == ',') { |
| 1274 | 1273 | $boucle->limit = |
@@ -1314,8 +1313,7 @@ discard block |
||
| 1314 | 1313 | // {1/3} |
| 1315 | 1314 | if ($op1 == '/') { |
| 1316 | 1315 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1317 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1318 | - "($total_parties ? $total_parties : 1)"; |
|
| 1316 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1319 | 1317 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1320 | 1318 | $debut = $pmoins1 ? "ceil(($nombre_boucle * $pmoins1)/$totpos);" : 0; |
| 1321 | 1319 | } else { |
@@ -1326,15 +1324,13 @@ discard block |
||
| 1326 | 1324 | |
| 1327 | 1325 | // cas {x,n-1} |
| 1328 | 1326 | if ($op2 == '-') { |
| 1329 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1330 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1331 | - ($total_parties . ' - 1')); |
|
| 1327 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1328 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1332 | 1329 | } else { |
| 1333 | 1330 | // {x,1} ou {pagination} |
| 1334 | 1331 | $fin = '$debut_boucle' |
| 1335 | 1332 | . (is_numeric($total_parties) ? |
| 1336 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1337 | - ('+' . $total_parties . ' - 1')); |
|
| 1333 | + (($total_parties == 1) ? '' : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1338 | 1334 | } |
| 1339 | 1335 | |
| 1340 | 1336 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1352,11 +1348,11 @@ discard block |
||
| 1352 | 1348 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1353 | 1349 | |
| 1354 | 1350 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1355 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1351 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1356 | 1352 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1357 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1358 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1359 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1353 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1354 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1355 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1360 | 1356 | . "\n\tif (\$debut_boucle>0" |
| 1361 | 1357 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1362 | 1358 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1441,14 +1437,14 @@ discard block |
||
| 1441 | 1437 | // critere personnalise ? |
| 1442 | 1438 | if ( |
| 1443 | 1439 | (!$serveur |
| 1444 | - || !function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere) |
|
| 1440 | + || !function_exists($f = 'critere_'.$serveur.'_'.$table.'_'.$critere) |
|
| 1445 | 1441 | && !function_exists($f .= '_dist') |
| 1446 | - && !function_exists($f = 'critere_' . $serveur . '_' . $critere) |
|
| 1442 | + && !function_exists($f = 'critere_'.$serveur.'_'.$critere) |
|
| 1447 | 1443 | && !function_exists($f .= '_dist') |
| 1448 | 1444 | ) |
| 1449 | - && !function_exists($f = 'critere_' . $table . '_' . $critere) |
|
| 1445 | + && !function_exists($f = 'critere_'.$table.'_'.$critere) |
|
| 1450 | 1446 | && !function_exists($f .= '_dist') |
| 1451 | - && !function_exists($f = 'critere_' . $critere) |
|
| 1447 | + && !function_exists($f = 'critere_'.$critere) |
|
| 1452 | 1448 | && !function_exists($f .= '_dist') |
| 1453 | 1449 | ) { |
| 1454 | 1450 | // fonction critere standard |
@@ -1480,9 +1476,9 @@ discard block |
||
| 1480 | 1476 | */ |
| 1481 | 1477 | function kwote($lisp, $serveur = '', $type = '') { |
| 1482 | 1478 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1483 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1479 | + return $r[1].'"'.sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type).'"'; |
|
| 1484 | 1480 | } else { |
| 1485 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1481 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1486 | 1482 | } |
| 1487 | 1483 | } |
| 1488 | 1484 | |
@@ -1504,7 +1500,7 @@ discard block |
||
| 1504 | 1500 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1505 | 1501 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1506 | 1502 | if (!$r) { |
| 1507 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1503 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1508 | 1504 | } |
| 1509 | 1505 | [$arg, $op, $val, $col, $where_complement] = $r; |
| 1510 | 1506 | |
@@ -1529,8 +1525,8 @@ discard block |
||
| 1529 | 1525 | "'NOT'", |
| 1530 | 1526 | [ |
| 1531 | 1527 | "'IN'", |
| 1532 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1533 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1528 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1529 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1534 | 1530 | ] |
| 1535 | 1531 | ]; |
| 1536 | 1532 | } |
@@ -1547,22 +1543,22 @@ discard block |
||
| 1547 | 1543 | $descr = $boucles[$idb]->descr; |
| 1548 | 1544 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1549 | 1545 | |
| 1550 | - $var = '$in' . $cpt++; |
|
| 1546 | + $var = '$in'.$cpt++; |
|
| 1551 | 1547 | $x = "\n\t$var = array();"; |
| 1552 | 1548 | foreach ($val as $k => $v) { |
| 1553 | 1549 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", (string) $v, $r)) { |
| 1554 | 1550 | // optimiser le traitement des constantes |
| 1555 | 1551 | if (is_numeric($r[2])) { |
| 1556 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1552 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1557 | 1553 | } else { |
| 1558 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1554 | + $x .= "\n\t$var".'[]= '.sql_quote($r[2]).';'; |
|
| 1559 | 1555 | } |
| 1560 | 1556 | } else { |
| 1561 | 1557 | // Pour permettre de passer des tableaux de valeurs |
| 1562 | 1558 | // on repere l'utilisation brute de #ENV**{X}, |
| 1563 | 1559 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1564 | 1560 | // et on deballe mais en rajoutant l'anti XSS |
| 1565 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1561 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1566 | 1562 | } |
| 1567 | 1563 | } |
| 1568 | 1564 | |
@@ -1576,7 +1572,7 @@ discard block |
||
| 1576 | 1572 | $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
| 1577 | 1573 | } |
| 1578 | 1574 | |
| 1579 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1575 | + return "sql_in('$arg', $var".($crit2 == 'NOT' ? ",'NOT'" : '').')'; |
|
| 1580 | 1576 | } |
| 1581 | 1577 | |
| 1582 | 1578 | /** |
@@ -1649,7 +1645,7 @@ discard block |
||
| 1649 | 1645 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1650 | 1646 | } |
| 1651 | 1647 | // nous aider en mode debug. |
| 1652 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1648 | + $boucle->debug[] = 'id_ : '.implode(', ', $champs); |
|
| 1653 | 1649 | $boucle->modificateur['id_'] = $champs; |
| 1654 | 1650 | |
| 1655 | 1651 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1904,8 +1900,8 @@ discard block |
||
| 1904 | 1900 | "'NOT'", |
| 1905 | 1901 | [ |
| 1906 | 1902 | "'IN'", |
| 1907 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1908 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1903 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1904 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1909 | 1905 | ] |
| 1910 | 1906 | ]; |
| 1911 | 1907 | } |
@@ -1915,7 +1911,7 @@ discard block |
||
| 1915 | 1911 | // traiter a part la date, elle est mise d'office par SPIP, |
| 1916 | 1912 | if ($crit->cond) { |
| 1917 | 1913 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1918 | - if (($col === 'date' || $col === 'date_redac') && $pred === "\$Pile[0]['" . $col . "']") { |
|
| 1914 | + if (($col === 'date' || $col === 'date_redac') && $pred === "\$Pile[0]['".$col."']") { |
|
| 1919 | 1915 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1920 | 1916 | } |
| 1921 | 1917 | |
@@ -2077,7 +2073,7 @@ discard block |
||
| 2077 | 2073 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2078 | 2074 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2079 | 2075 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", (string) $val[0], $r)) { |
| 2080 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2076 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2081 | 2077 | } |
| 2082 | 2078 | // sinon expliciter les |
| 2083 | 2079 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2092,14 +2088,14 @@ discard block |
||
| 2092 | 2088 | ) { |
| 2093 | 2089 | $r = $r[1] |
| 2094 | 2090 | . ((isset($r[2]) && $r[2]) ? $r[2] : ",''") |
| 2095 | - . ",'" . addslashes((string) $type_cast_quote) . "'"; |
|
| 2091 | + . ",'".addslashes((string) $type_cast_quote)."'"; |
|
| 2096 | 2092 | $val[0] = "sql_quote($r)"; |
| 2097 | 2093 | } |
| 2098 | 2094 | elseif ( |
| 2099 | 2095 | str_contains((string) $val[0], '@@defaultcast@@') |
| 2100 | 2096 | && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
| 2101 | 2097 | ) { |
| 2102 | - $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'" . addslashes((string) $type_cast_quote) . "')"; |
|
| 2098 | + $val[0] = substr((string) $val[0], 0, -strlen($r[0]))."'".addslashes((string) $type_cast_quote)."')"; |
|
| 2103 | 2099 | } |
| 2104 | 2100 | } |
| 2105 | 2101 | |
@@ -2107,7 +2103,7 @@ discard block |
||
| 2107 | 2103 | str_contains((string) $val[0], '@@defaultcast@@') |
| 2108 | 2104 | && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
| 2109 | 2105 | ) { |
| 2110 | - $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2106 | + $val[0] = substr((string) $val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2111 | 2107 | } |
| 2112 | 2108 | |
| 2113 | 2109 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2122,7 +2118,7 @@ discard block |
||
| 2122 | 2118 | |
| 2123 | 2119 | // inserer le nom de la table SQL devant le nom du champ |
| 2124 | 2120 | if ($table) { |
| 2125 | - $arg = $col[0] == '`' ? "$table." . substr((string) $col, 1, -1) : "$table.$col"; |
|
| 2121 | + $arg = $col[0] == '`' ? "$table.".substr((string) $col, 1, -1) : "$table.$col"; |
|
| 2126 | 2122 | } else { |
| 2127 | 2123 | $arg = $col; |
| 2128 | 2124 | } |
@@ -2251,9 +2247,9 @@ discard block |
||
| 2251 | 2247 | **/ |
| 2252 | 2248 | function primary_doublee($decompose, $table) { |
| 2253 | 2249 | $e1 = reset($decompose); |
| 2254 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2250 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2255 | 2251 | |
| 2256 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2252 | + return ["'='", "'$table.".$e1."'", $e2]; |
|
| 2257 | 2253 | } |
| 2258 | 2254 | |
| 2259 | 2255 | /** |
@@ -2292,7 +2288,7 @@ discard block |
||
| 2292 | 2288 | $checkarrivee |
| 2293 | 2289 | && is_string($checkarrivee) |
| 2294 | 2290 | && ($a = table_objet($checkarrivee)) |
| 2295 | - && in_array($a . '_liens', $joints) |
|
| 2291 | + && in_array($a.'_liens', $joints) |
|
| 2296 | 2292 | && ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) |
| 2297 | 2293 | ) { |
| 2298 | 2294 | return $res; |
@@ -2311,12 +2307,12 @@ discard block |
||
| 2311 | 2307 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2312 | 2308 | $joindre = false; |
| 2313 | 2309 | foreach ($cols as $col) { |
| 2314 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2310 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2315 | 2311 | if (trouver_champ($c, $boucle->where)) { |
| 2316 | 2312 | $joindre = true; |
| 2317 | 2313 | } else { |
| 2318 | 2314 | // mais ca peut etre dans le FIELD pour le Having |
| 2319 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2315 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2320 | 2316 | if (trouver_champ($c, $boucle->select)) { |
| 2321 | 2317 | $joindre = true; |
| 2322 | 2318 | } |
@@ -2362,7 +2358,7 @@ discard block |
||
| 2362 | 2358 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2363 | 2359 | |
| 2364 | 2360 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2365 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2361 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee.'_liens'); |
|
| 2366 | 2362 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2367 | 2363 | |
| 2368 | 2364 | if (!$intermediaire || !$arrivee) { |
@@ -2466,7 +2462,7 @@ discard block |
||
| 2466 | 2462 | } elseif ($crit->cond && ($col == 'date' || $col == 'date_redac')) { |
| 2467 | 2463 | // un critere conditionnel sur date est traite a part |
| 2468 | 2464 | // car la date est mise d'office par SPIP, |
| 2469 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2465 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2470 | 2466 | } |
| 2471 | 2467 | |
| 2472 | 2468 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2498,7 +2494,7 @@ discard block |
||
| 2498 | 2494 | && ($p == "'" || $p == '"') |
| 2499 | 2495 | && $params[0][1]->type == 'champ' |
| 2500 | 2496 | ) { |
| 2501 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2497 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2502 | 2498 | } else { |
| 2503 | 2499 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2504 | 2500 | $a = calculer_liste($p, $idb, $boucles, $parent); |
@@ -2513,7 +2509,7 @@ discard block |
||
| 2513 | 2509 | $fct = $args_sql = ''; |
| 2514 | 2510 | // fonction SQL ? |
| 2515 | 2511 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2516 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', (string) $col, $m)) { |
|
| 2512 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', (string) $col, $m)) { |
|
| 2517 | 2513 | $fct = $m[1]; |
| 2518 | 2514 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2519 | 2515 | $col = $a[1]; |
@@ -2599,7 +2595,7 @@ discard block |
||
| 2599 | 2595 | if (isset($regs[3]) && ($suite = $regs[3])) { |
| 2600 | 2596 | # Recherche de l'existence du champ date_xxxx, |
| 2601 | 2597 | # si oui choisir ce champ, sinon choisir xxxx |
| 2602 | - $date_orig = isset($table['field']["date$suite"]) ? 'date' . $suite : substr($suite, 1); |
|
| 2598 | + $date_orig = isset($table['field']["date$suite"]) ? 'date'.$suite : substr($suite, 1); |
|
| 2603 | 2599 | |
| 2604 | 2600 | $pred = $date_orig; |
| 2605 | 2601 | } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
@@ -2616,12 +2612,12 @@ discard block |
||
| 2616 | 2612 | } |
| 2617 | 2613 | } |
| 2618 | 2614 | |
| 2619 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2620 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2615 | + $date_compare = "\"' . normaliser_date(". |
|
| 2616 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2621 | 2617 | ") . '\""; |
| 2622 | 2618 | |
| 2623 | 2619 | $col_vraie = $date_orig; |
| 2624 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2620 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2625 | 2621 | |
| 2626 | 2622 | switch ($col) { |
| 2627 | 2623 | case 'date': |
@@ -2641,26 +2637,26 @@ discard block |
||
| 2641 | 2637 | break; |
| 2642 | 2638 | case 'age': |
| 2643 | 2639 | $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
| 2644 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2640 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2645 | 2641 | break; |
| 2646 | 2642 | case 'age_relatif': |
| 2647 | 2643 | $col = calculer_param_date($date_compare, $date_orig); |
| 2648 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2644 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2649 | 2645 | break; |
| 2650 | 2646 | case 'jour_relatif': |
| 2651 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2652 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2647 | + $col = '(TO_DAYS('.$date_compare.')-TO_DAYS('.$date_orig.'))'; |
|
| 2648 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2653 | 2649 | break; |
| 2654 | 2650 | case 'mois_relatif': |
| 2655 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2656 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2657 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2658 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2651 | + $col = 'MONTH('.$date_compare.')-MONTH('. |
|
| 2652 | + $date_orig.')+12*(YEAR('.$date_compare. |
|
| 2653 | + ')-YEAR('.$date_orig.'))'; |
|
| 2654 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2659 | 2655 | break; |
| 2660 | 2656 | case 'annee_relatif': |
| 2661 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2662 | - $date_orig . ')'; |
|
| 2663 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2657 | + $col = 'YEAR('.$date_compare.')-YEAR('. |
|
| 2658 | + $date_orig.')'; |
|
| 2659 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2664 | 2660 | break; |
| 2665 | 2661 | } |
| 2666 | 2662 | |
@@ -2718,10 +2714,10 @@ discard block |
||
| 2718 | 2714 | } |
| 2719 | 2715 | |
| 2720 | 2716 | $boucle->hash .= ' |
| 2721 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2717 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2722 | 2718 | |
| 2723 | 2719 | $boucle->hash .= ' |
| 2724 | - $command[\'source\'] = array(' . implode(', ', $args) . ");\n"; |
|
| 2720 | + $command[\'source\'] = array(' . implode(', ', $args).");\n"; |
|
| 2725 | 2721 | } |
| 2726 | 2722 | |
| 2727 | 2723 | /** |
@@ -2740,7 +2736,7 @@ discard block |
||
| 2740 | 2736 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2741 | 2737 | $boucle = &$boucles[$idb]; |
| 2742 | 2738 | $boucle->hash .= ' |
| 2743 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2739 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2744 | 2740 | } |
| 2745 | 2741 | |
| 2746 | 2742 | |
@@ -2759,7 +2755,7 @@ discard block |
||
| 2759 | 2755 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2760 | 2756 | foreach ($crit->param as $param) { |
| 2761 | 2757 | $boucle->hash .= ' |
| 2762 | - $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2758 | + $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2763 | 2759 | } |
| 2764 | 2760 | } |
| 2765 | 2761 | |
@@ -2778,14 +2774,14 @@ discard block |
||
| 2778 | 2774 | */ |
| 2779 | 2775 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2780 | 2776 | $boucle = &$boucles[$idb]; |
| 2781 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2777 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2782 | 2778 | foreach ($crit->param as $param) { |
| 2783 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2779 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste( |
|
| 2784 | 2780 | $param, |
| 2785 | 2781 | $idb, |
| 2786 | 2782 | $boucles, |
| 2787 | 2783 | $boucles[$idb]->id_parent |
| 2788 | - ) . ";\n"; |
|
| 2784 | + ).";\n"; |
|
| 2789 | 2785 | } |
| 2790 | 2786 | } |
| 2791 | 2787 | |
@@ -2812,14 +2808,14 @@ discard block |
||
| 2812 | 2808 | */ |
| 2813 | 2809 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2814 | 2810 | $boucle = &$boucles[$idb]; |
| 2815 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2811 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2816 | 2812 | foreach ($crit->param as $param) { |
| 2817 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2813 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste( |
|
| 2818 | 2814 | $param, |
| 2819 | 2815 | $idb, |
| 2820 | 2816 | $boucles, |
| 2821 | 2817 | $boucles[$idb]->id_parent |
| 2822 | - ) . ";\n"; |
|
| 2818 | + ).";\n"; |
|
| 2823 | 2819 | } |
| 2824 | 2820 | } |
| 2825 | 2821 | |
@@ -2838,7 +2834,7 @@ discard block |
||
| 2838 | 2834 | $boucle = &$boucles[$idb]; |
| 2839 | 2835 | foreach ($crit->param as $param) { |
| 2840 | 2836 | $boucle->hash .= ' |
| 2841 | - $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2837 | + $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2842 | 2838 | } |
| 2843 | 2839 | } |
| 2844 | 2840 | |
@@ -2879,7 +2875,7 @@ discard block |
||
| 2879 | 2875 | if ($crit->param) { |
| 2880 | 2876 | foreach ($crit->param as $param) { |
| 2881 | 2877 | $boucle->hash .= "\t\$command['si'][] = " |
| 2882 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2878 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2883 | 2879 | } |
| 2884 | 2880 | // interdire {si 0} aussi ! |
| 2885 | 2881 | } else { |
@@ -2917,7 +2913,7 @@ discard block |
||
| 2917 | 2913 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 2918 | 2914 | |
| 2919 | 2915 | $in = 'IN'; |
| 2920 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2916 | + $where = ["'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2921 | 2917 | if ($not) { |
| 2922 | 2918 | $where = ["'NOT'", $where]; |
| 2923 | 2919 | } |
@@ -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 | /** |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | **/ |
| 47 | 47 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 48 | 48 | |
| 49 | - $not = $crit->not; |
|
| 50 | - $boucle = &$boucles[$idb]; |
|
| 51 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 49 | + $not = $crit->not; |
|
| 50 | + $boucle = &$boucles[$idb]; |
|
| 51 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 52 | 52 | |
| 53 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 54 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 53 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 54 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | * @return void|array |
| 69 | 69 | **/ |
| 70 | 70 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 71 | - $not = $crit->not; |
|
| 72 | - $boucle = &$boucles[$idb]; |
|
| 73 | - $id = $boucle->primary; |
|
| 74 | - |
|
| 75 | - if ($not || !$id) { |
|
| 76 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 77 | - } |
|
| 78 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 79 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 71 | + $not = $crit->not; |
|
| 72 | + $boucle = &$boucles[$idb]; |
|
| 73 | + $id = $boucle->primary; |
|
| 74 | + |
|
| 75 | + if ($not || !$id) { |
|
| 76 | + return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 77 | + } |
|
| 78 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 79 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -96,73 +96,73 @@ discard block |
||
| 96 | 96 | * @return void|array |
| 97 | 97 | **/ |
| 98 | 98 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 99 | - $boucle = &$boucles[$idb]; |
|
| 100 | - $primary = $boucle->primary; |
|
| 101 | - |
|
| 102 | - // la table nécessite une clé primaire, non composée |
|
| 103 | - if (!$primary || strpos((string) $primary, ',')) { |
|
| 104 | - return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 108 | - |
|
| 109 | - // le doublon s'applique sur un type de boucle (article) |
|
| 110 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 111 | - |
|
| 112 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 113 | - // on obtient $nom = "'article' . 'nom'" |
|
| 114 | - if (isset($crit->param[0])) { |
|
| 115 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 119 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 120 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 121 | - |
|
| 122 | - // on crée un sql_in avec la clé primaire de la table |
|
| 123 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 124 | - // $doublons et son index, ici $nom |
|
| 125 | - |
|
| 126 | - // debut du code "sql_in('articles.id_article', " |
|
| 127 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 128 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 129 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 130 | - $debut_doub = '$doublons[' . ($not ? $boucle->doublons . '[]= ' : ('')); |
|
| 131 | - |
|
| 132 | - // le debut complet du code des doublons |
|
| 133 | - $debut_doub = $debut_in . $debut_doub; |
|
| 134 | - |
|
| 135 | - // nom du doublon "('article' . 'nom')]" |
|
| 136 | - $fin_doub = "($nom)]"; |
|
| 137 | - |
|
| 138 | - // si on trouve un autre critère doublon, |
|
| 139 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 140 | - foreach ($boucle->where as $k => $w) { |
|
| 141 | - if (str_starts_with((string) $w[0], $debut_doub)) { |
|
| 142 | - // fusionner le sql_in (du where) |
|
| 143 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr((string) $w[0], strlen($debut_in)); |
|
| 144 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 145 | - $x = strpos((string) $boucle->hash, $init_comment); |
|
| 146 | - $len = strlen($init_comment); |
|
| 147 | - $boucle->hash = |
|
| 148 | - substr((string) $boucle->hash, 0, $x + $len) . $init_code . substr((string) $boucle->hash, $x + $len); |
|
| 149 | - |
|
| 150 | - return; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 155 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 156 | - |
|
| 157 | - // déclarer le doublon s'il n'existe pas encore |
|
| 158 | - $boucle->hash .= $init_comment . $init_code; |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 162 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 163 | - # {!doublons A}{doublons B} |
|
| 164 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 165 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 99 | + $boucle = &$boucles[$idb]; |
|
| 100 | + $primary = $boucle->primary; |
|
| 101 | + |
|
| 102 | + // la table nécessite une clé primaire, non composée |
|
| 103 | + if (!$primary || strpos((string) $primary, ',')) { |
|
| 104 | + return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 108 | + |
|
| 109 | + // le doublon s'applique sur un type de boucle (article) |
|
| 110 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 111 | + |
|
| 112 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 113 | + // on obtient $nom = "'article' . 'nom'" |
|
| 114 | + if (isset($crit->param[0])) { |
|
| 115 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 119 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 120 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 121 | + |
|
| 122 | + // on crée un sql_in avec la clé primaire de la table |
|
| 123 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 124 | + // $doublons et son index, ici $nom |
|
| 125 | + |
|
| 126 | + // debut du code "sql_in('articles.id_article', " |
|
| 127 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 128 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 129 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 130 | + $debut_doub = '$doublons[' . ($not ? $boucle->doublons . '[]= ' : ('')); |
|
| 131 | + |
|
| 132 | + // le debut complet du code des doublons |
|
| 133 | + $debut_doub = $debut_in . $debut_doub; |
|
| 134 | + |
|
| 135 | + // nom du doublon "('article' . 'nom')]" |
|
| 136 | + $fin_doub = "($nom)]"; |
|
| 137 | + |
|
| 138 | + // si on trouve un autre critère doublon, |
|
| 139 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 140 | + foreach ($boucle->where as $k => $w) { |
|
| 141 | + if (str_starts_with((string) $w[0], $debut_doub)) { |
|
| 142 | + // fusionner le sql_in (du where) |
|
| 143 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr((string) $w[0], strlen($debut_in)); |
|
| 144 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 145 | + $x = strpos((string) $boucle->hash, $init_comment); |
|
| 146 | + $len = strlen($init_comment); |
|
| 147 | + $boucle->hash = |
|
| 148 | + substr((string) $boucle->hash, 0, $x + $len) . $init_code . substr((string) $boucle->hash, $x + $len); |
|
| 149 | + |
|
| 150 | + return; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 155 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 156 | + |
|
| 157 | + // déclarer le doublon s'il n'existe pas encore |
|
| 158 | + $boucle->hash .= $init_comment . $init_code; |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 162 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 163 | + # {!doublons A}{doublons B} |
|
| 164 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 165 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | |
@@ -183,14 +183,14 @@ discard block |
||
| 183 | 183 | * @return void |
| 184 | 184 | **/ |
| 185 | 185 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 186 | - if (!isset($crit->param[1][0]) || !($param = $crit->param[1][0]->texte)) { |
|
| 187 | - $param = 'oui'; |
|
| 188 | - } |
|
| 189 | - if ($crit->not) { |
|
| 190 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 191 | - } |
|
| 192 | - $boucle = &$boucles[$idb]; |
|
| 193 | - $boucle->lang_select = $param; |
|
| 186 | + if (!isset($crit->param[1][0]) || !($param = $crit->param[1][0]->texte)) { |
|
| 187 | + $param = 'oui'; |
|
| 188 | + } |
|
| 189 | + if ($crit->not) { |
|
| 190 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 191 | + } |
|
| 192 | + $boucle = &$boucles[$idb]; |
|
| 193 | + $boucle->lang_select = $param; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
@@ -212,15 +212,15 @@ discard block |
||
| 212 | 212 | * @return void |
| 213 | 213 | **/ |
| 214 | 214 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 215 | - [$un, $deux] = $crit->param; |
|
| 216 | - $un = $un[0]->texte; |
|
| 217 | - $deux = $deux[0]->texte; |
|
| 218 | - if ($deux) { |
|
| 219 | - $boucles[$idb]->limit = |
|
| 220 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 221 | - } else { |
|
| 222 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 223 | - } |
|
| 215 | + [$un, $deux] = $crit->param; |
|
| 216 | + $un = $un[0]->texte; |
|
| 217 | + $deux = $deux[0]->texte; |
|
| 218 | + if ($deux) { |
|
| 219 | + $boucles[$idb]->limit = |
|
| 220 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 221 | + } else { |
|
| 222 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 223 | + } |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -254,59 +254,59 @@ discard block |
||
| 254 | 254 | **/ |
| 255 | 255 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 256 | 256 | |
| 257 | - $boucle = &$boucles[$idb]; |
|
| 258 | - // definition de la taille de la page |
|
| 259 | - $pas = isset($crit->param[0][0]) |
|
| 260 | - ? calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent) |
|
| 261 | - : "''"; |
|
| 262 | - |
|
| 263 | - if (!preg_match(_CODE_QUOTE, (string) $pas, $r)) { |
|
| 264 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 265 | - } else { |
|
| 266 | - $r = (int) $r[2]; |
|
| 267 | - $pas = (string) ($r ?: 10); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Calcul du nommage de la pagination si il existe. |
|
| 271 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 272 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 273 | - $type = "'$idb'"; |
|
| 274 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 275 | - // Syntaxe {pagination 20, nom} |
|
| 276 | - if (isset($crit->param[0][1])) { |
|
| 277 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 278 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 279 | - elseif (isset($crit->param[1][0])) { |
|
| 280 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr((string) $type, 1)); |
|
| 284 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 285 | - $partie = |
|
| 286 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 287 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 288 | - . "\tif (\$debut_boucle && \$debut_boucle[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" |
|
| 291 | - . "\t}\n" |
|
| 292 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 293 | - |
|
| 294 | - $boucle->hash .= ' |
|
| 257 | + $boucle = &$boucles[$idb]; |
|
| 258 | + // definition de la taille de la page |
|
| 259 | + $pas = isset($crit->param[0][0]) |
|
| 260 | + ? calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent) |
|
| 261 | + : "''"; |
|
| 262 | + |
|
| 263 | + if (!preg_match(_CODE_QUOTE, (string) $pas, $r)) { |
|
| 264 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 265 | + } else { |
|
| 266 | + $r = (int) $r[2]; |
|
| 267 | + $pas = (string) ($r ?: 10); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Calcul du nommage de la pagination si il existe. |
|
| 271 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 272 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 273 | + $type = "'$idb'"; |
|
| 274 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 275 | + // Syntaxe {pagination 20, nom} |
|
| 276 | + if (isset($crit->param[0][1])) { |
|
| 277 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 278 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 279 | + elseif (isset($crit->param[1][0])) { |
|
| 280 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr((string) $type, 1)); |
|
| 284 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 285 | + $partie = |
|
| 286 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 287 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 288 | + . "\tif (\$debut_boucle && \$debut_boucle[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" |
|
| 291 | + . "\t}\n" |
|
| 292 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 293 | + |
|
| 294 | + $boucle->hash .= ' |
|
| 295 | 295 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 296 | 296 | |
| 297 | - $boucle->total_parties = $pas; |
|
| 298 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 299 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 300 | - // sauf si pas de primaire, ou si primaire composee |
|
| 301 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 302 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 303 | - if ( |
|
| 304 | - $boucle->primary |
|
| 305 | - && !preg_match('/[,\s]/', (string) $boucle->primary) |
|
| 306 | - && !in_array($t, $boucle->select) |
|
| 307 | - ) { |
|
| 308 | - $boucle->select[] = $t; |
|
| 309 | - } |
|
| 297 | + $boucle->total_parties = $pas; |
|
| 298 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 299 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 300 | + // sauf si pas de primaire, ou si primaire composee |
|
| 301 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 302 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 303 | + if ( |
|
| 304 | + $boucle->primary |
|
| 305 | + && !preg_match('/[,\s]/', (string) $boucle->primary) |
|
| 306 | + && !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 || strpos((string) $boucle->primary, ',')) { |
|
| 334 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 333 | + if (!$boucle->primary || strpos((string) $boucle->primary, ',')) { |
|
| 334 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['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'] = ["'" . $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'] = ["'" . $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 | - [ |
|
| 397 | - "'OR'", |
|
| 398 | - [ |
|
| 399 | - "'AND'", |
|
| 400 | - ["'='", "'$table.id_trad'", 0], |
|
| 401 | - ["'='", "'$table.$prim'", $dprim] |
|
| 402 | - ], |
|
| 403 | - [ |
|
| 404 | - "'AND'", |
|
| 405 | - ["'>'", "'$table.id_trad'", 0], |
|
| 406 | - ["'='", "'$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 | + [ |
|
| 397 | + "'OR'", |
|
| 398 | + [ |
|
| 399 | + "'AND'", |
|
| 400 | + ["'='", "'$table.id_trad'", 0], |
|
| 401 | + ["'='", "'$table.$prim'", $dprim] |
|
| 402 | + ], |
|
| 403 | + [ |
|
| 404 | + "'AND'", |
|
| 405 | + ["'>'", "'$table.id_trad'", 0], |
|
| 406 | + ["'='", "'$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 | - [ |
|
| 432 | - "'OR'", |
|
| 433 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 434 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 435 | - ]; |
|
| 436 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 426 | + $boucle = &$boucles[$idb]; |
|
| 427 | + $prim = $boucle->primary; |
|
| 428 | + $table = $boucle->id_table; |
|
| 429 | + |
|
| 430 | + $c = |
|
| 431 | + [ |
|
| 432 | + "'OR'", |
|
| 433 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 434 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 435 | + ]; |
|
| 436 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -450,17 +450,17 @@ 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 = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 456 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 457 | - |
|
| 458 | - if ($boucle->type_requete == 'rubriques' || isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 459 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 460 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 461 | - else { |
|
| 462 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 463 | - } |
|
| 453 | + $boucle = &$boucles[$idb]; |
|
| 454 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 456 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 457 | + |
|
| 458 | + if ($boucle->type_requete == 'rubriques' || isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 459 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 460 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 461 | + else { |
|
| 462 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 463 | + } |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -491,38 +491,38 @@ discard block |
||
| 491 | 491 | **/ |
| 492 | 492 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 493 | 493 | |
| 494 | - $not = $crit->not; |
|
| 495 | - $boucle = &$boucles[$idb]; |
|
| 496 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 497 | - if (isset($crit->param[0])) { |
|
| 498 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 499 | - // sinon on le prend chez une boucle parente |
|
| 500 | - } else { |
|
| 501 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - //Trouver une jointure |
|
| 505 | - $champ = 'id_rubrique'; |
|
| 506 | - $desc = $boucle->show; |
|
| 507 | - //Seulement si necessaire |
|
| 508 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 509 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 510 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 511 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 512 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 513 | - $decompose = decompose_champ_id_objet($champ); |
|
| 514 | - $champ = array_shift($decompose); |
|
| 515 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | - } |
|
| 517 | - } else { |
|
| 518 | - $cle = $boucle->id_table; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | - $boucle->where[] = $crit->cond |
|
| 524 | - ? "($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')' |
|
| 525 | - : $c; |
|
| 494 | + $not = $crit->not; |
|
| 495 | + $boucle = &$boucles[$idb]; |
|
| 496 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 497 | + if (isset($crit->param[0])) { |
|
| 498 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 499 | + // sinon on le prend chez une boucle parente |
|
| 500 | + } else { |
|
| 501 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + //Trouver une jointure |
|
| 505 | + $champ = 'id_rubrique'; |
|
| 506 | + $desc = $boucle->show; |
|
| 507 | + //Seulement si necessaire |
|
| 508 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 509 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 510 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 511 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 512 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 513 | + $decompose = decompose_champ_id_objet($champ); |
|
| 514 | + $champ = array_shift($decompose); |
|
| 515 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | + } |
|
| 517 | + } else { |
|
| 518 | + $cle = $boucle->id_table; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | + $boucle->where[] = $crit->cond |
|
| 524 | + ? "($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')' |
|
| 525 | + : $c; |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
@@ -538,15 +538,15 @@ discard block |
||
| 538 | 538 | **/ |
| 539 | 539 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 540 | 540 | |
| 541 | - $boucle = &$boucles[$idb]; |
|
| 542 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 543 | - $serveur = $boucle->sql_serveur; |
|
| 541 | + $boucle = &$boucles[$idb]; |
|
| 542 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 543 | + $serveur = $boucle->sql_serveur; |
|
| 544 | 544 | |
| 545 | - $c = "sql_in('" . |
|
| 546 | - $boucle->id_table . '.' . $boucle->primary |
|
| 547 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 545 | + $c = "sql_in('" . |
|
| 546 | + $boucle->id_table . '.' . $boucle->primary |
|
| 547 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 548 | 548 | |
| 549 | - $boucle->where[] = $c; |
|
| 549 | + $boucle->where[] = $c; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -569,31 +569,31 @@ discard block |
||
| 569 | 569 | * @return void|array |
| 570 | 570 | */ |
| 571 | 571 | function critere_groupby_dist($idb, &$boucles, $crit) { |
| 572 | - if ($t = isset($crit->param[0])) { |
|
| 573 | - $t = $crit->param[0]; |
|
| 574 | - if ($t[0]->type == 'texte') { |
|
| 575 | - $t = $t[0]->texte; |
|
| 576 | - if (preg_match('/^(.*)\.(.*)$/', (string) $t, $r)) { |
|
| 577 | - $t = table_objet_sql($r[1]); |
|
| 578 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 579 | - if ($t) { |
|
| 580 | - $t .= '.' . $r[2]; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - } else { |
|
| 584 | - $t = '".' |
|
| 585 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 586 | - . '."'; |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - if ($t) { |
|
| 590 | - $boucles[$idb]->group[] = $t; |
|
| 591 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 592 | - $boucles[$idb]->select[] = $t; |
|
| 593 | - } |
|
| 594 | - } else { |
|
| 595 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 596 | - } |
|
| 572 | + if ($t = isset($crit->param[0])) { |
|
| 573 | + $t = $crit->param[0]; |
|
| 574 | + if ($t[0]->type == 'texte') { |
|
| 575 | + $t = $t[0]->texte; |
|
| 576 | + if (preg_match('/^(.*)\.(.*)$/', (string) $t, $r)) { |
|
| 577 | + $t = table_objet_sql($r[1]); |
|
| 578 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 579 | + if ($t) { |
|
| 580 | + $t .= '.' . $r[2]; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + } else { |
|
| 584 | + $t = '".' |
|
| 585 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 586 | + . '."'; |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + if ($t) { |
|
| 590 | + $boucles[$idb]->group[] = $t; |
|
| 591 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 592 | + $boucles[$idb]->select[] = $t; |
|
| 593 | + } |
|
| 594 | + } else { |
|
| 595 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 596 | + } |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | * @return void |
| 617 | 617 | */ |
| 618 | 618 | function critere_groupby_supprimer_dist($idb, &$boucles, $crit): void { |
| 619 | - $boucles[$idb]->group = []; |
|
| 619 | + $boucles[$idb]->group = []; |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -630,8 +630,8 @@ discard block |
||
| 630 | 630 | * @return void|array |
| 631 | 631 | */ |
| 632 | 632 | function critere_fusion_dist(...$args) { |
| 633 | - trigger_deprecation('spip', '5.0', 'Using "%s" criteria is deprecated, use "%s" criteria instead', 'fusion', 'groupby'); |
|
| 634 | - return critere_groupby_dist(...$args); |
|
| 633 | + trigger_deprecation('spip', '5.0', 'Using "%s" criteria is deprecated, use "%s" criteria instead', 'fusion', 'groupby'); |
|
| 634 | + return critere_groupby_dist(...$args); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -644,8 +644,8 @@ discard block |
||
| 644 | 644 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 645 | 645 | */ |
| 646 | 646 | function critere_fusion_supprimer_dist(...$args): void { |
| 647 | - trigger_deprecation('spip', '5.0', 'Using "%s" criteria is deprecated, use "%s" criteria instead', 'fusion_supprimer', 'groupby_supprimer'); |
|
| 648 | - critere_groupby_supprimer_dist(...$args); |
|
| 647 | + trigger_deprecation('spip', '5.0', 'Using "%s" criteria is deprecated, use "%s" criteria instead', 'fusion_supprimer', 'groupby_supprimer'); |
|
| 648 | + critere_groupby_supprimer_dist(...$args); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | /** |
@@ -683,26 +683,26 @@ discard block |
||
| 683 | 683 | * @return void|array |
| 684 | 684 | */ |
| 685 | 685 | function critere_collate_dist($idb, &$boucles, $crit) { |
| 686 | - if (isset($crit->param[0])) { |
|
| 687 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 688 | - $boucle = $boucles[$idb]; |
|
| 689 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 690 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 691 | - if ($n && (!str_contains((string) $boucle->order[$n - 1], 'COLLATE'))) { |
|
| 692 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 693 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 694 | - if ( |
|
| 695 | - (false !== $i = strpos((string) $boucle->order[$n - 1], 'ASC')) |
|
| 696 | - || (false !== $i = strpos((string) $boucle->order[$n - 1], 'DESC')) |
|
| 697 | - ) { |
|
| 698 | - $boucle->order[$n - 1] = substr_replace((string) $boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 699 | - } else { |
|
| 700 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - } else { |
|
| 704 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 705 | - } |
|
| 686 | + if (isset($crit->param[0])) { |
|
| 687 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 688 | + $boucle = $boucles[$idb]; |
|
| 689 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 690 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 691 | + if ($n && (!str_contains((string) $boucle->order[$n - 1], 'COLLATE'))) { |
|
| 692 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 693 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 694 | + if ( |
|
| 695 | + (false !== $i = strpos((string) $boucle->order[$n - 1], 'ASC')) |
|
| 696 | + || (false !== $i = strpos((string) $boucle->order[$n - 1], 'DESC')) |
|
| 697 | + ) { |
|
| 698 | + $boucle->order[$n - 1] = substr_replace((string) $boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 699 | + } else { |
|
| 700 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + } else { |
|
| 704 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 705 | + } |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -717,26 +717,26 @@ discard block |
||
| 717 | 717 | * @return void|array |
| 718 | 718 | */ |
| 719 | 719 | function critere_collecte_dist(...$args) { |
| 720 | - trigger_deprecation('spip', '5.0', 'Using "%s" criteria is deprecated, use "%s" criteria instead', 'collecte', 'collate'); |
|
| 721 | - return critere_collate_dist(...$args); |
|
| 720 | + trigger_deprecation('spip', '5.0', 'Using "%s" criteria is deprecated, use "%s" criteria instead', 'collecte', 'collate'); |
|
| 721 | + return critere_collate_dist(...$args); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 725 | - $boucle = $boucles[$idb]; |
|
| 726 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 727 | - $var = '$champs_' . $idb; |
|
| 728 | - $desc = (str_contains((string) $boucle->in, (string) "static $var =")); |
|
| 729 | - if (!$desc) { |
|
| 730 | - $desc = $boucle->show['field']; |
|
| 731 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 732 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 733 | - } |
|
| 734 | - if ($desc) { |
|
| 735 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 736 | - } |
|
| 737 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 738 | - |
|
| 739 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 725 | + $boucle = $boucles[$idb]; |
|
| 726 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 727 | + $var = '$champs_' . $idb; |
|
| 728 | + $desc = (str_contains((string) $boucle->in, (string) "static $var =")); |
|
| 729 | + if (!$desc) { |
|
| 730 | + $desc = $boucle->show['field']; |
|
| 731 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 732 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 733 | + } |
|
| 734 | + if ($desc) { |
|
| 735 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 736 | + } |
|
| 737 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 738 | + |
|
| 739 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | /** |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 776 | 776 | */ |
| 777 | 777 | function critere_par_dist($idb, &$boucles, $crit) { |
| 778 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 778 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | /** |
@@ -797,91 +797,91 @@ discard block |
||
| 797 | 797 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 798 | 798 | */ |
| 799 | 799 | function critere_parinverse($idb, &$boucles, $crit) { |
| 800 | - $boucle = &$boucles[$idb]; |
|
| 801 | - |
|
| 802 | - $sens = $collecte = ''; |
|
| 803 | - if ($crit->not) { |
|
| 804 | - $sens = " . ' DESC'"; |
|
| 805 | - } |
|
| 806 | - if (isset($boucle->modificateur['collate'])) { |
|
| 807 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - // Pour chaque paramètre du critère |
|
| 811 | - foreach ($crit->param as $tri) { |
|
| 812 | - $order = $fct = ''; |
|
| 813 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 814 | - if ($tri[0]->type != 'texte') { |
|
| 815 | - // calculer le order dynamique qui verifie les champs |
|
| 816 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 817 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 818 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 819 | - } |
|
| 820 | - // tris textuels {par titre} |
|
| 821 | - else { |
|
| 822 | - $par = array_shift($tri); |
|
| 823 | - $par = $par->texte; |
|
| 824 | - |
|
| 825 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 826 | - if (preg_match(',^(\w+)[\s]+(.*)$,', (string) $par, $m)) { |
|
| 827 | - $expression = trim($m[1]); |
|
| 828 | - $champ = trim($m[2]); |
|
| 829 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 830 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 831 | - } else { |
|
| 832 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 836 | - } elseif ($boucle->type_requete == 'DATA' || preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', (string) $par, $match)) { |
|
| 837 | - // {par FONCTION(champ)} |
|
| 838 | - if (isset($match) && count($match) > 2) { |
|
| 839 | - $par = substr($match[2], 1, -1); |
|
| 840 | - $fct = $match[1]; |
|
| 841 | - } |
|
| 842 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 843 | - if ($par == 'hasard') { |
|
| 844 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 845 | - } elseif ($par == 'date' && !empty($boucle->show['date'])) { |
|
| 846 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 847 | - } else { |
|
| 848 | - // cas général {par champ}, {par table.champ}, ... |
|
| 849 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 850 | - } |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - // on ne sait pas traiter… |
|
| 854 | - else { |
|
| 855 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 859 | - if (is_array($order)) { |
|
| 860 | - return $order; |
|
| 861 | - } |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - if (preg_match('/^\'([^"]*)\'$/', (string) $order, $m)) { |
|
| 865 | - $t = $m[1]; |
|
| 866 | - if (strpos($t, '.') && !in_array($t, $boucle->select)) { |
|
| 867 | - $boucle->select[] = $t; |
|
| 868 | - } |
|
| 869 | - } else { |
|
| 870 | - $sens = ''; |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - if ($fct) { |
|
| 874 | - $order = preg_match("/^\s*'(.*)'\s*$/", (string) $order, $r) |
|
| 875 | - ? "'$fct(" . $r[1] . ")'" |
|
| 876 | - : "'$fct(' . $order . ')'"; |
|
| 877 | - } |
|
| 878 | - $t = $order . $collecte . $sens; |
|
| 879 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 880 | - $t = $r[1] . $r[2]; |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - $boucle->order[] = $t; |
|
| 884 | - } |
|
| 800 | + $boucle = &$boucles[$idb]; |
|
| 801 | + |
|
| 802 | + $sens = $collecte = ''; |
|
| 803 | + if ($crit->not) { |
|
| 804 | + $sens = " . ' DESC'"; |
|
| 805 | + } |
|
| 806 | + if (isset($boucle->modificateur['collate'])) { |
|
| 807 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + // Pour chaque paramètre du critère |
|
| 811 | + foreach ($crit->param as $tri) { |
|
| 812 | + $order = $fct = ''; |
|
| 813 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 814 | + if ($tri[0]->type != 'texte') { |
|
| 815 | + // calculer le order dynamique qui verifie les champs |
|
| 816 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 817 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 818 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 819 | + } |
|
| 820 | + // tris textuels {par titre} |
|
| 821 | + else { |
|
| 822 | + $par = array_shift($tri); |
|
| 823 | + $par = $par->texte; |
|
| 824 | + |
|
| 825 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 826 | + if (preg_match(',^(\w+)[\s]+(.*)$,', (string) $par, $m)) { |
|
| 827 | + $expression = trim($m[1]); |
|
| 828 | + $champ = trim($m[2]); |
|
| 829 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 830 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 831 | + } else { |
|
| 832 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 836 | + } elseif ($boucle->type_requete == 'DATA' || preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', (string) $par, $match)) { |
|
| 837 | + // {par FONCTION(champ)} |
|
| 838 | + if (isset($match) && count($match) > 2) { |
|
| 839 | + $par = substr($match[2], 1, -1); |
|
| 840 | + $fct = $match[1]; |
|
| 841 | + } |
|
| 842 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 843 | + if ($par == 'hasard') { |
|
| 844 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 845 | + } elseif ($par == 'date' && !empty($boucle->show['date'])) { |
|
| 846 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 847 | + } else { |
|
| 848 | + // cas général {par champ}, {par table.champ}, ... |
|
| 849 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 850 | + } |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + // on ne sait pas traiter… |
|
| 854 | + else { |
|
| 855 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 859 | + if (is_array($order)) { |
|
| 860 | + return $order; |
|
| 861 | + } |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + if (preg_match('/^\'([^"]*)\'$/', (string) $order, $m)) { |
|
| 865 | + $t = $m[1]; |
|
| 866 | + if (strpos($t, '.') && !in_array($t, $boucle->select)) { |
|
| 867 | + $boucle->select[] = $t; |
|
| 868 | + } |
|
| 869 | + } else { |
|
| 870 | + $sens = ''; |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + if ($fct) { |
|
| 874 | + $order = preg_match("/^\s*'(.*)'\s*$/", (string) $order, $r) |
|
| 875 | + ? "'$fct(" . $r[1] . ")'" |
|
| 876 | + : "'$fct(' . $order . ')'"; |
|
| 877 | + } |
|
| 878 | + $t = $order . $collecte . $sens; |
|
| 879 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 880 | + $t = $r[1] . $r[2]; |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + $boucle->order[] = $t; |
|
| 884 | + } |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | /** |
@@ -895,13 +895,13 @@ discard block |
||
| 895 | 895 | * @return string Clause pour le Order by |
| 896 | 896 | */ |
| 897 | 897 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 898 | - $boucle = &$boucles[$idb]; |
|
| 899 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 900 | - $parha = 'rand() AS hasard'; |
|
| 901 | - if (!in_array($parha, $boucle->select)) { |
|
| 902 | - $boucle->select[] = $parha; |
|
| 903 | - } |
|
| 904 | - return "'hasard'"; |
|
| 898 | + $boucle = &$boucles[$idb]; |
|
| 899 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 900 | + $parha = 'rand() AS hasard'; |
|
| 901 | + if (!in_array($parha, $boucle->select)) { |
|
| 902 | + $boucle->select[] = $parha; |
|
| 903 | + } |
|
| 904 | + return "'hasard'"; |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -925,22 +925,22 @@ discard block |
||
| 925 | 925 | * @return string|array Clause pour le Order by (array si erreur) |
| 926 | 926 | */ |
| 927 | 927 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 928 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 929 | - if (is_array($_champ)) { |
|
| 930 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 931 | - } |
|
| 932 | - $boucle = &$boucles[$idb]; |
|
| 933 | - $texte = '0+' . $_champ; |
|
| 934 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 935 | - if ($suite !== "''") { |
|
| 936 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 937 | - } |
|
| 938 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 939 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 940 | - |
|
| 941 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 942 | - $orderassinum = trim($orderassinum, "'"); |
|
| 943 | - return "'$orderassinum, $asnum'"; |
|
| 928 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 929 | + if (is_array($_champ)) { |
|
| 930 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 931 | + } |
|
| 932 | + $boucle = &$boucles[$idb]; |
|
| 933 | + $texte = '0+' . $_champ; |
|
| 934 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 935 | + if ($suite !== "''") { |
|
| 936 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 937 | + } |
|
| 938 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 939 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 940 | + |
|
| 941 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 942 | + $orderassinum = trim($orderassinum, "'"); |
|
| 943 | + return "'$orderassinum, $asnum'"; |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | /** |
@@ -961,34 +961,34 @@ discard block |
||
| 961 | 961 | * @return string|array Clause pour le Order by (array si erreur) |
| 962 | 962 | */ |
| 963 | 963 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 964 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 965 | - if (is_array($_champ)) { |
|
| 966 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 967 | - } |
|
| 968 | - $boucle = &$boucles[$idb]; |
|
| 969 | - $texte = '0+' . $_champ; |
|
| 970 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 971 | - if ($suite !== "''") { |
|
| 972 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - $as = false; |
|
| 976 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 977 | - foreach ($boucle->select as $s) { |
|
| 978 | - if (str_starts_with((string) $s, $select)) { |
|
| 979 | - $as = trim(substr((string) $s, strlen($select))); |
|
| 980 | - if (!preg_match(',\W,', $as)) { |
|
| 981 | - break; |
|
| 982 | - } |
|
| 983 | - $as = false; |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - if (!$as) { |
|
| 988 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 989 | - $boucle->select[] = $select . $as; |
|
| 990 | - } |
|
| 991 | - return "'$as'"; |
|
| 964 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 965 | + if (is_array($_champ)) { |
|
| 966 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 967 | + } |
|
| 968 | + $boucle = &$boucles[$idb]; |
|
| 969 | + $texte = '0+' . $_champ; |
|
| 970 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 971 | + if ($suite !== "''") { |
|
| 972 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + $as = false; |
|
| 976 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 977 | + foreach ($boucle->select as $s) { |
|
| 978 | + if (str_starts_with((string) $s, $select)) { |
|
| 979 | + $as = trim(substr((string) $s, strlen($select))); |
|
| 980 | + if (!preg_match(',\W,', $as)) { |
|
| 981 | + break; |
|
| 982 | + } |
|
| 983 | + $as = false; |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + if (!$as) { |
|
| 988 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 989 | + $boucle->select[] = $select . $as; |
|
| 990 | + } |
|
| 991 | + return "'$as'"; |
|
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | |
@@ -1008,13 +1008,13 @@ discard block |
||
| 1008 | 1008 | * @return string|array Clause pour le Order by (array si erreur) |
| 1009 | 1009 | */ |
| 1010 | 1010 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 1011 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 1012 | - if (is_array($_champ)) { |
|
| 1013 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 1014 | - } |
|
| 1015 | - $boucle = &$boucles[$idb]; |
|
| 1016 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 1017 | - return "'multi'"; |
|
| 1011 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 1012 | + if (is_array($_champ)) { |
|
| 1013 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 1014 | + } |
|
| 1015 | + $boucle = &$boucles[$idb]; |
|
| 1016 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 1017 | + return "'multi'"; |
|
| 1018 | 1018 | } |
| 1019 | 1019 | |
| 1020 | 1020 | /** |
@@ -1033,56 +1033,56 @@ discard block |
||
| 1033 | 1033 | * @return array|string |
| 1034 | 1034 | */ |
| 1035 | 1035 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 1036 | - $boucle = &$boucles[$idb]; |
|
| 1037 | - $desc = $boucle->show; |
|
| 1038 | - |
|
| 1039 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 1040 | - if (isset($desc['field'][$par])) { |
|
| 1041 | - $par = $boucle->id_table . '.' . $par; |
|
| 1042 | - } |
|
| 1043 | - // le champ est peut être une jointure |
|
| 1044 | - else { |
|
| 1045 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1046 | - $champ = $par; |
|
| 1047 | - |
|
| 1048 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1049 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1050 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1051 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1052 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1053 | - [, $table, $champ] = $r; |
|
| 1054 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1055 | - $table = table_objet_sql($table); |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1059 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1060 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1061 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1062 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1063 | - } elseif ( |
|
| 1064 | - $boucle->jointures_explicites |
|
| 1065 | - && ($alias = trouver_jointure_champ($champ, $boucle, explode(' ', (string) $boucle->jointures_explicites), false, $table)) |
|
| 1066 | - ) { |
|
| 1067 | - $par = $alias . '.' . $champ; |
|
| 1068 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1069 | - $par = $alias . '.' . $champ; |
|
| 1070 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1071 | - } elseif ( |
|
| 1072 | - $table_alias |
|
| 1073 | - && isset($boucle->from[$table_alias]) |
|
| 1074 | - && ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias])) |
|
| 1075 | - ) { |
|
| 1076 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1077 | - } elseif ($table) { |
|
| 1078 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1079 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1080 | - } else { |
|
| 1081 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1082 | - } |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - return $raw ? $par : "'$par'"; |
|
| 1036 | + $boucle = &$boucles[$idb]; |
|
| 1037 | + $desc = $boucle->show; |
|
| 1038 | + |
|
| 1039 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 1040 | + if (isset($desc['field'][$par])) { |
|
| 1041 | + $par = $boucle->id_table . '.' . $par; |
|
| 1042 | + } |
|
| 1043 | + // le champ est peut être une jointure |
|
| 1044 | + else { |
|
| 1045 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1046 | + $champ = $par; |
|
| 1047 | + |
|
| 1048 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1049 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1050 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1051 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1052 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1053 | + [, $table, $champ] = $r; |
|
| 1054 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1055 | + $table = table_objet_sql($table); |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1059 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1060 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1061 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1062 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1063 | + } elseif ( |
|
| 1064 | + $boucle->jointures_explicites |
|
| 1065 | + && ($alias = trouver_jointure_champ($champ, $boucle, explode(' ', (string) $boucle->jointures_explicites), false, $table)) |
|
| 1066 | + ) { |
|
| 1067 | + $par = $alias . '.' . $champ; |
|
| 1068 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1069 | + $par = $alias . '.' . $champ; |
|
| 1070 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1071 | + } elseif ( |
|
| 1072 | + $table_alias |
|
| 1073 | + && isset($boucle->from[$table_alias]) |
|
| 1074 | + && ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias])) |
|
| 1075 | + ) { |
|
| 1076 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1077 | + } elseif ($table) { |
|
| 1078 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1079 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1080 | + } else { |
|
| 1081 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1082 | + } |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + return $raw ? $par : "'$par'"; |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | /** |
@@ -1107,33 +1107,33 @@ discard block |
||
| 1107 | 1107 | */ |
| 1108 | 1108 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1109 | 1109 | |
| 1110 | - $boucle = &$boucles[$idb]; |
|
| 1111 | - // Classement par ordre inverse |
|
| 1112 | - if ($crit->not) { |
|
| 1113 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1114 | - } else { |
|
| 1115 | - $order = "' DESC'"; |
|
| 1116 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1117 | - if (isset($crit->param[0])) { |
|
| 1118 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1119 | - $order = "(($critere)?' DESC':'')"; |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1123 | - if (!$n) { |
|
| 1124 | - if (isset($boucle->default_order[0])) { |
|
| 1125 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1126 | - } else { |
|
| 1127 | - $boucle->default_order[] = ' DESC'; |
|
| 1128 | - } |
|
| 1129 | - } else { |
|
| 1130 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1131 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1132 | - $t = $r[1] . $r[2]; |
|
| 1133 | - } |
|
| 1134 | - $boucle->order[$n - 1] = $t; |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1110 | + $boucle = &$boucles[$idb]; |
|
| 1111 | + // Classement par ordre inverse |
|
| 1112 | + if ($crit->not) { |
|
| 1113 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1114 | + } else { |
|
| 1115 | + $order = "' DESC'"; |
|
| 1116 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1117 | + if (isset($crit->param[0])) { |
|
| 1118 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1119 | + $order = "(($critere)?' DESC':'')"; |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1123 | + if (!$n) { |
|
| 1124 | + if (isset($boucle->default_order[0])) { |
|
| 1125 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1126 | + } else { |
|
| 1127 | + $boucle->default_order[] = ' DESC'; |
|
| 1128 | + } |
|
| 1129 | + } else { |
|
| 1130 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1131 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1132 | + $t = $r[1] . $r[2]; |
|
| 1133 | + } |
|
| 1134 | + $boucle->order[$n - 1] = $t; |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | /** |
@@ -1145,139 +1145,139 @@ discard block |
||
| 1145 | 1145 | * @return void|array |
| 1146 | 1146 | */ |
| 1147 | 1147 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1148 | - $boucle = &$boucles[$idb]; |
|
| 1148 | + $boucle = &$boucles[$idb]; |
|
| 1149 | 1149 | |
| 1150 | - $sens = $collecte = ''; |
|
| 1151 | - if ($crit->not) { |
|
| 1152 | - $sens = " . ' DESC'"; |
|
| 1153 | - } |
|
| 1150 | + $sens = $collecte = ''; |
|
| 1151 | + if ($crit->not) { |
|
| 1152 | + $sens = " . ' DESC'"; |
|
| 1153 | + } |
|
| 1154 | 1154 | |
| 1155 | - $crit2 = clone $crit; |
|
| 1156 | - $crit2->not = false; |
|
| 1157 | - $crit2->param = [reset($crit->param)]; |
|
| 1158 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1155 | + $crit2 = clone $crit; |
|
| 1156 | + $crit2->not = false; |
|
| 1157 | + $crit2->param = [reset($crit->param)]; |
|
| 1158 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1159 | 1159 | |
| 1160 | - // erreur ? |
|
| 1161 | - if (is_array($res)) { |
|
| 1162 | - return $res; |
|
| 1163 | - } |
|
| 1160 | + // erreur ? |
|
| 1161 | + if (is_array($res)) { |
|
| 1162 | + return $res; |
|
| 1163 | + } |
|
| 1164 | 1164 | |
| 1165 | - $_order = array_pop($boucle->order); |
|
| 1165 | + $_order = array_pop($boucle->order); |
|
| 1166 | 1166 | |
| 1167 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1167 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1168 | 1168 | |
| 1169 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1170 | - $boucle->order[] = $order; |
|
| 1169 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1170 | + $boucle->order[] = $order; |
|
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | 1173 | |
| 1174 | 1174 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1175 | - $params = $crit->param; |
|
| 1176 | - |
|
| 1177 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1178 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - $boucle = &$boucles[$idb]; |
|
| 1182 | - $parent = $boucle->id_parent; |
|
| 1183 | - $fields = $boucle->show['field']; |
|
| 1184 | - |
|
| 1185 | - $date = array_shift($params); |
|
| 1186 | - $type = array_shift($params); |
|
| 1187 | - |
|
| 1188 | - // la valeur $type doit etre connue a la compilation |
|
| 1189 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1190 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1191 | - |
|
| 1192 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1193 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1194 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1195 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1196 | - if ((is_countable($date) ? count($date) : 0) == 1 && $date[0]->type == 'texte') { |
|
| 1197 | - $date = $date[0]->texte; |
|
| 1198 | - if (!isset($fields[$date])) { |
|
| 1199 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1200 | - } |
|
| 1201 | - } else { |
|
| 1202 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1203 | - $noms = array_keys($fields); |
|
| 1204 | - $defaut = $noms[0]; |
|
| 1205 | - $noms = implode(' ', $noms); |
|
| 1206 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1207 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1208 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1209 | - } |
|
| 1210 | - $annee = $params ? array_shift($params) : ''; |
|
| 1211 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1212 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1213 | - ') ? $x : date("Y"))'; |
|
| 1214 | - |
|
| 1215 | - $mois = $params ? array_shift($params) : ''; |
|
| 1216 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1217 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1218 | - ') ? $x : date("m"))'; |
|
| 1219 | - |
|
| 1220 | - $jour = $params ? array_shift($params) : ''; |
|
| 1221 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1222 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1223 | - ') ? $x : date("d"))'; |
|
| 1224 | - |
|
| 1225 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1226 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1227 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1228 | - ') ? $x : date("Y"))'; |
|
| 1229 | - |
|
| 1230 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1231 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1232 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1233 | - ') ? $x : date("m"))'; |
|
| 1234 | - |
|
| 1235 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1236 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1237 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1238 | - ') ? $x : date("d"))'; |
|
| 1239 | - |
|
| 1240 | - $date = $boucle->id_table . ".$date"; |
|
| 1241 | - |
|
| 1242 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1243 | - if ($type == 'jour') { |
|
| 1244 | - $boucle->where[] = [ |
|
| 1245 | - "'='", |
|
| 1246 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1247 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1248 | - ]; |
|
| 1249 | - } elseif ($type == 'mois') { |
|
| 1250 | - $boucle->where[] = [ |
|
| 1251 | - "'='", |
|
| 1252 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1253 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1254 | - ]; |
|
| 1255 | - } elseif ($type == 'semaine') { |
|
| 1256 | - $boucle->where[] = [ |
|
| 1257 | - "'AND'", |
|
| 1258 | - [ |
|
| 1259 | - "'>='", |
|
| 1260 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1261 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1262 | - ], |
|
| 1263 | - [ |
|
| 1264 | - "'<='", |
|
| 1265 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1266 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1267 | - ] |
|
| 1268 | - ]; |
|
| 1269 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1270 | - $boucle->where[] = [ |
|
| 1271 | - "'AND'", |
|
| 1272 | - [ |
|
| 1273 | - "'>='", |
|
| 1274 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1275 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1276 | - ], |
|
| 1277 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1278 | - ]; |
|
| 1279 | - } |
|
| 1280 | - // sinon on prend tout |
|
| 1175 | + $params = $crit->param; |
|
| 1176 | + |
|
| 1177 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1178 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + $boucle = &$boucles[$idb]; |
|
| 1182 | + $parent = $boucle->id_parent; |
|
| 1183 | + $fields = $boucle->show['field']; |
|
| 1184 | + |
|
| 1185 | + $date = array_shift($params); |
|
| 1186 | + $type = array_shift($params); |
|
| 1187 | + |
|
| 1188 | + // la valeur $type doit etre connue a la compilation |
|
| 1189 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1190 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1191 | + |
|
| 1192 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1193 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1194 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1195 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1196 | + if ((is_countable($date) ? count($date) : 0) == 1 && $date[0]->type == 'texte') { |
|
| 1197 | + $date = $date[0]->texte; |
|
| 1198 | + if (!isset($fields[$date])) { |
|
| 1199 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1200 | + } |
|
| 1201 | + } else { |
|
| 1202 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1203 | + $noms = array_keys($fields); |
|
| 1204 | + $defaut = $noms[0]; |
|
| 1205 | + $noms = implode(' ', $noms); |
|
| 1206 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1207 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1208 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1209 | + } |
|
| 1210 | + $annee = $params ? array_shift($params) : ''; |
|
| 1211 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1212 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1213 | + ') ? $x : date("Y"))'; |
|
| 1214 | + |
|
| 1215 | + $mois = $params ? array_shift($params) : ''; |
|
| 1216 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1217 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1218 | + ') ? $x : date("m"))'; |
|
| 1219 | + |
|
| 1220 | + $jour = $params ? array_shift($params) : ''; |
|
| 1221 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1222 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1223 | + ') ? $x : date("d"))'; |
|
| 1224 | + |
|
| 1225 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1226 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1227 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1228 | + ') ? $x : date("Y"))'; |
|
| 1229 | + |
|
| 1230 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1231 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1232 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1233 | + ') ? $x : date("m"))'; |
|
| 1234 | + |
|
| 1235 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1236 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1237 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1238 | + ') ? $x : date("d"))'; |
|
| 1239 | + |
|
| 1240 | + $date = $boucle->id_table . ".$date"; |
|
| 1241 | + |
|
| 1242 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1243 | + if ($type == 'jour') { |
|
| 1244 | + $boucle->where[] = [ |
|
| 1245 | + "'='", |
|
| 1246 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1247 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1248 | + ]; |
|
| 1249 | + } elseif ($type == 'mois') { |
|
| 1250 | + $boucle->where[] = [ |
|
| 1251 | + "'='", |
|
| 1252 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1253 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1254 | + ]; |
|
| 1255 | + } elseif ($type == 'semaine') { |
|
| 1256 | + $boucle->where[] = [ |
|
| 1257 | + "'AND'", |
|
| 1258 | + [ |
|
| 1259 | + "'>='", |
|
| 1260 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1261 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1262 | + ], |
|
| 1263 | + [ |
|
| 1264 | + "'<='", |
|
| 1265 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1266 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1267 | + ] |
|
| 1268 | + ]; |
|
| 1269 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1270 | + $boucle->where[] = [ |
|
| 1271 | + "'AND'", |
|
| 1272 | + [ |
|
| 1273 | + "'>='", |
|
| 1274 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1275 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1276 | + ], |
|
| 1277 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1278 | + ]; |
|
| 1279 | + } |
|
| 1280 | + // sinon on prend tout |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | |
@@ -1302,33 +1302,33 @@ discard block |
||
| 1302 | 1302 | * @return void |
| 1303 | 1303 | **/ |
| 1304 | 1304 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1305 | - $boucle = &$boucles[$idb]; |
|
| 1306 | - $a1 = $crit->param[0]; |
|
| 1307 | - $a2 = $crit->param[1]; |
|
| 1308 | - $op = $crit->op; |
|
| 1309 | - |
|
| 1310 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1311 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1312 | - |
|
| 1313 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1314 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1315 | - } else { |
|
| 1316 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1317 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1318 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1319 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1320 | - $mode = (($op == '/') ? '/' : |
|
| 1321 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1322 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1323 | - if ($a11 !== 'n' && $a21 !== 'n' && $mode == '++' && $op == ',') { |
|
| 1324 | - $boucle->limit = |
|
| 1325 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1326 | - . ".','." |
|
| 1327 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1328 | - } else { |
|
| 1329 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1330 | - } |
|
| 1331 | - } |
|
| 1305 | + $boucle = &$boucles[$idb]; |
|
| 1306 | + $a1 = $crit->param[0]; |
|
| 1307 | + $a2 = $crit->param[1]; |
|
| 1308 | + $op = $crit->op; |
|
| 1309 | + |
|
| 1310 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1311 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1312 | + |
|
| 1313 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1314 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1315 | + } else { |
|
| 1316 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1317 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1318 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1319 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1320 | + $mode = (($op == '/') ? '/' : |
|
| 1321 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1322 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1323 | + if ($a11 !== 'n' && $a21 !== 'n' && $mode == '++' && $op == ',') { |
|
| 1324 | + $boucle->limit = |
|
| 1325 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1326 | + . ".','." |
|
| 1327 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1328 | + } else { |
|
| 1329 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1330 | + } |
|
| 1331 | + } |
|
| 1332 | 1332 | } |
| 1333 | 1333 | |
| 1334 | 1334 | /** |
@@ -1356,63 +1356,63 @@ discard block |
||
| 1356 | 1356 | * @return void |
| 1357 | 1357 | **/ |
| 1358 | 1358 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1359 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1360 | - |
|
| 1361 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1362 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1363 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1364 | - // {1/3} |
|
| 1365 | - if ($op1 == '/') { |
|
| 1366 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1367 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1368 | - "($total_parties ? $total_parties : 1)"; |
|
| 1369 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1370 | - $debut = $pmoins1 ? "ceil(($nombre_boucle * $pmoins1)/$totpos);" : 0; |
|
| 1371 | - } else { |
|
| 1372 | - // cas {n-1,x} |
|
| 1373 | - if ($op1 == '-') { |
|
| 1374 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - // cas {x,n-1} |
|
| 1378 | - if ($op2 == '-') { |
|
| 1379 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1380 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1381 | - ($total_parties . ' - 1')); |
|
| 1382 | - } else { |
|
| 1383 | - // {x,1} ou {pagination} |
|
| 1384 | - $fin = '$debut_boucle' |
|
| 1385 | - . (is_numeric($total_parties) ? |
|
| 1386 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1387 | - ('+' . $total_parties . ' - 1')); |
|
| 1388 | - } |
|
| 1389 | - |
|
| 1390 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1391 | - if ($op1 == 'p') { |
|
| 1392 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1393 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1394 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - // Notes : |
|
| 1399 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1400 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1401 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1402 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1403 | - |
|
| 1404 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1405 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1406 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1407 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1408 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1409 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1410 | - . "\n\tif (\$debut_boucle>0" |
|
| 1411 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1412 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1413 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1414 | - |
|
| 1415 | - $boucles[$id_boucle]->partie = " |
|
| 1359 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1360 | + |
|
| 1361 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1362 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1363 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1364 | + // {1/3} |
|
| 1365 | + if ($op1 == '/') { |
|
| 1366 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1367 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1368 | + "($total_parties ? $total_parties : 1)"; |
|
| 1369 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1370 | + $debut = $pmoins1 ? "ceil(($nombre_boucle * $pmoins1)/$totpos);" : 0; |
|
| 1371 | + } else { |
|
| 1372 | + // cas {n-1,x} |
|
| 1373 | + if ($op1 == '-') { |
|
| 1374 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + // cas {x,n-1} |
|
| 1378 | + if ($op2 == '-') { |
|
| 1379 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1380 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1381 | + ($total_parties . ' - 1')); |
|
| 1382 | + } else { |
|
| 1383 | + // {x,1} ou {pagination} |
|
| 1384 | + $fin = '$debut_boucle' |
|
| 1385 | + . (is_numeric($total_parties) ? |
|
| 1386 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1387 | + ('+' . $total_parties . ' - 1')); |
|
| 1388 | + } |
|
| 1389 | + |
|
| 1390 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1391 | + if ($op1 == 'p') { |
|
| 1392 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1393 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1394 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + // Notes : |
|
| 1399 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1400 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1401 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1402 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1403 | + |
|
| 1404 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1405 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1406 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1407 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1408 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1409 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1410 | + . "\n\tif (\$debut_boucle>0" |
|
| 1411 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1412 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1413 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1414 | + |
|
| 1415 | + $boucles[$id_boucle]->partie = " |
|
| 1416 | 1416 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1417 | 1417 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1418 | 1418 | } |
@@ -1429,26 +1429,26 @@ discard block |
||
| 1429 | 1429 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1430 | 1430 | **/ |
| 1431 | 1431 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1432 | - if ($param[0]->type != 'texte') { |
|
| 1433 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1434 | - if (isset($param[1]->texte)) { |
|
| 1435 | - preg_match(',^\s*(-(\d+))?\s*$,', (string) $param[1]->texte, $m); |
|
| 1436 | - |
|
| 1437 | - return ["intval($a1)", ((isset($m[2]) && $m[2]) ? $m[2] : 0)]; |
|
| 1438 | - } else { |
|
| 1439 | - return ["intval($a1)", 0]; |
|
| 1440 | - } |
|
| 1441 | - } else { |
|
| 1442 | - preg_match(',^\s*((\d+)|n)\s*(-\s*(\d+)?\s*)?$,', (string) $param[0]->texte, $m); |
|
| 1443 | - $a1 = $m[1]; |
|
| 1444 | - if (empty($m[3])) { |
|
| 1445 | - return [$a1, 0]; |
|
| 1446 | - } elseif (!empty($m[4])) { |
|
| 1447 | - return [$a1, $m[4]]; |
|
| 1448 | - } else { |
|
| 1449 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1450 | - } |
|
| 1451 | - } |
|
| 1432 | + if ($param[0]->type != 'texte') { |
|
| 1433 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1434 | + if (isset($param[1]->texte)) { |
|
| 1435 | + preg_match(',^\s*(-(\d+))?\s*$,', (string) $param[1]->texte, $m); |
|
| 1436 | + |
|
| 1437 | + return ["intval($a1)", ((isset($m[2]) && $m[2]) ? $m[2] : 0)]; |
|
| 1438 | + } else { |
|
| 1439 | + return ["intval($a1)", 0]; |
|
| 1440 | + } |
|
| 1441 | + } else { |
|
| 1442 | + preg_match(',^\s*((\d+)|n)\s*(-\s*(\d+)?\s*)?$,', (string) $param[0]->texte, $m); |
|
| 1443 | + $a1 = $m[1]; |
|
| 1444 | + if (empty($m[3])) { |
|
| 1445 | + return [$a1, 0]; |
|
| 1446 | + } elseif (!empty($m[4])) { |
|
| 1447 | + return [$a1, $m[4]]; |
|
| 1448 | + } else { |
|
| 1449 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1450 | + } |
|
| 1451 | + } |
|
| 1452 | 1452 | } |
| 1453 | 1453 | |
| 1454 | 1454 | |
@@ -1475,46 +1475,46 @@ discard block |
||
| 1475 | 1475 | * array : Erreur sur un des critères |
| 1476 | 1476 | **/ |
| 1477 | 1477 | function calculer_criteres($idb, &$boucles) { |
| 1478 | - $msg = ''; |
|
| 1479 | - $boucle = $boucles[$idb]; |
|
| 1480 | - $table = strtoupper((string) $boucle->type_requete); |
|
| 1481 | - $serveur = strtolower((string) $boucle->sql_serveur); |
|
| 1482 | - |
|
| 1483 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1484 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1485 | - if (!is_array($boucle->criteres)) { |
|
| 1486 | - return []; |
|
| 1487 | - } |
|
| 1488 | - |
|
| 1489 | - foreach ($boucle->criteres as $crit) { |
|
| 1490 | - $critere = $crit->op; |
|
| 1491 | - // critere personnalise ? |
|
| 1492 | - if ( |
|
| 1493 | - (!$serveur |
|
| 1494 | - || !function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere) |
|
| 1495 | - && !function_exists($f .= '_dist') |
|
| 1496 | - && !function_exists($f = 'critere_' . $serveur . '_' . $critere) |
|
| 1497 | - && !function_exists($f .= '_dist') |
|
| 1498 | - ) |
|
| 1499 | - && !function_exists($f = 'critere_' . $table . '_' . $critere) |
|
| 1500 | - && !function_exists($f .= '_dist') |
|
| 1501 | - && !function_exists($f = 'critere_' . $critere) |
|
| 1502 | - && !function_exists($f .= '_dist') |
|
| 1503 | - ) { |
|
| 1504 | - // fonction critere standard |
|
| 1505 | - $f = $defaut; |
|
| 1506 | - } |
|
| 1507 | - // compile le critere |
|
| 1508 | - $res = $f($idb, $boucles, $crit); |
|
| 1509 | - |
|
| 1510 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1511 | - if (is_array($res)) { |
|
| 1512 | - $msg = $res; |
|
| 1513 | - erreur_squelette($msg, $boucle); |
|
| 1514 | - } |
|
| 1515 | - } |
|
| 1516 | - |
|
| 1517 | - return $msg; |
|
| 1478 | + $msg = ''; |
|
| 1479 | + $boucle = $boucles[$idb]; |
|
| 1480 | + $table = strtoupper((string) $boucle->type_requete); |
|
| 1481 | + $serveur = strtolower((string) $boucle->sql_serveur); |
|
| 1482 | + |
|
| 1483 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1484 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1485 | + if (!is_array($boucle->criteres)) { |
|
| 1486 | + return []; |
|
| 1487 | + } |
|
| 1488 | + |
|
| 1489 | + foreach ($boucle->criteres as $crit) { |
|
| 1490 | + $critere = $crit->op; |
|
| 1491 | + // critere personnalise ? |
|
| 1492 | + if ( |
|
| 1493 | + (!$serveur |
|
| 1494 | + || !function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere) |
|
| 1495 | + && !function_exists($f .= '_dist') |
|
| 1496 | + && !function_exists($f = 'critere_' . $serveur . '_' . $critere) |
|
| 1497 | + && !function_exists($f .= '_dist') |
|
| 1498 | + ) |
|
| 1499 | + && !function_exists($f = 'critere_' . $table . '_' . $critere) |
|
| 1500 | + && !function_exists($f .= '_dist') |
|
| 1501 | + && !function_exists($f = 'critere_' . $critere) |
|
| 1502 | + && !function_exists($f .= '_dist') |
|
| 1503 | + ) { |
|
| 1504 | + // fonction critere standard |
|
| 1505 | + $f = $defaut; |
|
| 1506 | + } |
|
| 1507 | + // compile le critere |
|
| 1508 | + $res = $f($idb, $boucles, $crit); |
|
| 1509 | + |
|
| 1510 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1511 | + if (is_array($res)) { |
|
| 1512 | + $msg = $res; |
|
| 1513 | + erreur_squelette($msg, $boucle); |
|
| 1514 | + } |
|
| 1515 | + } |
|
| 1516 | + |
|
| 1517 | + return $msg; |
|
| 1518 | 1518 | } |
| 1519 | 1519 | |
| 1520 | 1520 | /** |
@@ -1529,11 +1529,11 @@ discard block |
||
| 1529 | 1529 | * @return string Code compilé rééchappé |
| 1530 | 1530 | */ |
| 1531 | 1531 | function kwote($lisp, $serveur = '', $type = '') { |
| 1532 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1533 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1534 | - } else { |
|
| 1535 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1536 | - } |
|
| 1532 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1533 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1534 | + } else { |
|
| 1535 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1536 | + } |
|
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | |
@@ -1552,81 +1552,81 @@ discard block |
||
| 1552 | 1552 | * @return void|array |
| 1553 | 1553 | **/ |
| 1554 | 1554 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1555 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1556 | - if (!$r) { |
|
| 1557 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1558 | - } |
|
| 1559 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1560 | - |
|
| 1561 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1562 | - |
|
| 1563 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1564 | - $where = $in; |
|
| 1565 | - if ($crit->cond) { |
|
| 1566 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1567 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1568 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1569 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1570 | - } |
|
| 1571 | - } |
|
| 1572 | - if ($crit->exclus) { |
|
| 1573 | - if (!preg_match(',^L\d+[.],', (string) $arg)) { |
|
| 1574 | - $where = ["'NOT'", $where]; |
|
| 1575 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1576 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1577 | - { |
|
| 1578 | - $where = [ |
|
| 1579 | - "'NOT'", |
|
| 1580 | - [ |
|
| 1581 | - "'IN'", |
|
| 1582 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1583 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1584 | - ] |
|
| 1585 | - ]; |
|
| 1586 | - } |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - $boucles[$idb]->where[] = $where; |
|
| 1590 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1591 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1592 | - } |
|
| 1555 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1556 | + if (!$r) { |
|
| 1557 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1558 | + } |
|
| 1559 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1560 | + |
|
| 1561 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1562 | + |
|
| 1563 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1564 | + $where = $in; |
|
| 1565 | + if ($crit->cond) { |
|
| 1566 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1567 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1568 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1569 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1570 | + } |
|
| 1571 | + } |
|
| 1572 | + if ($crit->exclus) { |
|
| 1573 | + if (!preg_match(',^L\d+[.],', (string) $arg)) { |
|
| 1574 | + $where = ["'NOT'", $where]; |
|
| 1575 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1576 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1577 | + { |
|
| 1578 | + $where = [ |
|
| 1579 | + "'NOT'", |
|
| 1580 | + [ |
|
| 1581 | + "'IN'", |
|
| 1582 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1583 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1584 | + ] |
|
| 1585 | + ]; |
|
| 1586 | + } |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + $boucles[$idb]->where[] = $where; |
|
| 1590 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1591 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1592 | + } |
|
| 1593 | 1593 | } |
| 1594 | 1594 | |
| 1595 | 1595 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1596 | - static $num = []; |
|
| 1597 | - $descr = $boucles[$idb]->descr; |
|
| 1598 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1599 | - |
|
| 1600 | - $var = '$in' . $cpt++; |
|
| 1601 | - $x = "\n\t$var = array();"; |
|
| 1602 | - foreach ($val as $k => $v) { |
|
| 1603 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", (string) $v, $r)) { |
|
| 1604 | - // optimiser le traitement des constantes |
|
| 1605 | - if (is_numeric($r[2])) { |
|
| 1606 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1607 | - } else { |
|
| 1608 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1609 | - } |
|
| 1610 | - } else { |
|
| 1611 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1612 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1613 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1614 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1615 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1616 | - } |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - $boucles[$idb]->in .= $x; |
|
| 1620 | - |
|
| 1621 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1622 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1623 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1624 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1625 | - if (!$crit2) { |
|
| 1626 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1596 | + static $num = []; |
|
| 1597 | + $descr = $boucles[$idb]->descr; |
|
| 1598 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1599 | + |
|
| 1600 | + $var = '$in' . $cpt++; |
|
| 1601 | + $x = "\n\t$var = array();"; |
|
| 1602 | + foreach ($val as $k => $v) { |
|
| 1603 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", (string) $v, $r)) { |
|
| 1604 | + // optimiser le traitement des constantes |
|
| 1605 | + if (is_numeric($r[2])) { |
|
| 1606 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1607 | + } else { |
|
| 1608 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1609 | + } |
|
| 1610 | + } else { |
|
| 1611 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1612 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1613 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1614 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1615 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1616 | + } |
|
| 1617 | + } |
|
| 1618 | + |
|
| 1619 | + $boucles[$idb]->in .= $x; |
|
| 1620 | + |
|
| 1621 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1622 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1623 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1624 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1625 | + if (!$crit2) { |
|
| 1626 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1630 | 1630 | } |
| 1631 | 1631 | |
| 1632 | 1632 | /** |
@@ -1642,22 +1642,22 @@ discard block |
||
| 1642 | 1642 | * @return void |
| 1643 | 1643 | */ |
| 1644 | 1644 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1645 | - $boucle = &$boucles[$idb]; |
|
| 1646 | - if (isset($crit->param[0])) { |
|
| 1647 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1648 | - } else { |
|
| 1649 | - $_where = "spip_sanitize_from_request(\$Pile[0]['where'] ?? null, 'where', 'vide')"; |
|
| 1650 | - } |
|
| 1651 | - |
|
| 1652 | - if ($crit->cond) { |
|
| 1653 | - $_where = "$_where ?: ''"; |
|
| 1654 | - } |
|
| 1655 | - |
|
| 1656 | - if ($crit->not) { |
|
| 1657 | - $_where = "['NOT', $_where]"; |
|
| 1658 | - } |
|
| 1659 | - |
|
| 1660 | - $boucle->where[] = $_where; |
|
| 1645 | + $boucle = &$boucles[$idb]; |
|
| 1646 | + if (isset($crit->param[0])) { |
|
| 1647 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1648 | + } else { |
|
| 1649 | + $_where = "spip_sanitize_from_request(\$Pile[0]['where'] ?? null, 'where', 'vide')"; |
|
| 1650 | + } |
|
| 1651 | + |
|
| 1652 | + if ($crit->cond) { |
|
| 1653 | + $_where = "$_where ?: ''"; |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + if ($crit->not) { |
|
| 1657 | + $_where = "['NOT', $_where]"; |
|
| 1658 | + } |
|
| 1659 | + |
|
| 1660 | + $boucle->where[] = $_where; |
|
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | /** |
@@ -1673,22 +1673,22 @@ discard block |
||
| 1673 | 1673 | * @return void |
| 1674 | 1674 | */ |
| 1675 | 1675 | function critere_having_dist($idb, &$boucles, $crit) { |
| 1676 | - $boucle = &$boucles[$idb]; |
|
| 1677 | - if (isset($crit->param[0])) { |
|
| 1678 | - $_having = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1679 | - } else { |
|
| 1680 | - $_having = "spip_sanitize_from_request(\$Pile[0]['having'] ?? null, 'having', 'vide')"; |
|
| 1681 | - } |
|
| 1682 | - |
|
| 1683 | - if ($crit->cond) { |
|
| 1684 | - $_having = "$_having ?: ''"; |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - if ($crit->not) { |
|
| 1688 | - $_having = "['NOT', $_having]"; |
|
| 1689 | - } |
|
| 1690 | - |
|
| 1691 | - $boucle->having[] = $_having; |
|
| 1676 | + $boucle = &$boucles[$idb]; |
|
| 1677 | + if (isset($crit->param[0])) { |
|
| 1678 | + $_having = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1679 | + } else { |
|
| 1680 | + $_having = "spip_sanitize_from_request(\$Pile[0]['having'] ?? null, 'having', 'vide')"; |
|
| 1681 | + } |
|
| 1682 | + |
|
| 1683 | + if ($crit->cond) { |
|
| 1684 | + $_having = "$_having ?: ''"; |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + if ($crit->not) { |
|
| 1688 | + $_having = "['NOT', $_having]"; |
|
| 1689 | + } |
|
| 1690 | + |
|
| 1691 | + $boucle->having[] = $_having; |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | 1694 | /** |
@@ -1716,31 +1716,31 @@ discard block |
||
| 1716 | 1716 | * @return void |
| 1717 | 1717 | */ |
| 1718 | 1718 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1719 | - /** @var Boucle $boucle */ |
|
| 1720 | - $boucle = $boucles[$idb]; |
|
| 1721 | - |
|
| 1722 | - $champs = lister_champs_id_conditionnel( |
|
| 1723 | - $boucle->show['table'], |
|
| 1724 | - $boucle->show, |
|
| 1725 | - $boucle->sql_serveur |
|
| 1726 | - ); |
|
| 1727 | - |
|
| 1728 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1729 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1730 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1731 | - } |
|
| 1732 | - // nous aider en mode debug. |
|
| 1733 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1734 | - $boucle->modificateur['id_'] = $champs; |
|
| 1735 | - |
|
| 1736 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1737 | - foreach ($champs as $champ) { |
|
| 1738 | - $critere_id_table = new Critere(); |
|
| 1739 | - $critere_id_table->op = $champ; |
|
| 1740 | - $critere_id_table->cond = true; |
|
| 1741 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1742 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1743 | - } |
|
| 1719 | + /** @var Boucle $boucle */ |
|
| 1720 | + $boucle = $boucles[$idb]; |
|
| 1721 | + |
|
| 1722 | + $champs = lister_champs_id_conditionnel( |
|
| 1723 | + $boucle->show['table'], |
|
| 1724 | + $boucle->show, |
|
| 1725 | + $boucle->sql_serveur |
|
| 1726 | + ); |
|
| 1727 | + |
|
| 1728 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1729 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1730 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1731 | + } |
|
| 1732 | + // nous aider en mode debug. |
|
| 1733 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1734 | + $boucle->modificateur['id_'] = $champs; |
|
| 1735 | + |
|
| 1736 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1737 | + foreach ($champs as $champ) { |
|
| 1738 | + $critere_id_table = new Critere(); |
|
| 1739 | + $critere_id_table->op = $champ; |
|
| 1740 | + $critere_id_table->cond = true; |
|
| 1741 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1742 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1743 | + } |
|
| 1744 | 1744 | } |
| 1745 | 1745 | |
| 1746 | 1746 | /** |
@@ -1760,74 +1760,74 @@ discard block |
||
| 1760 | 1760 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1761 | 1761 | */ |
| 1762 | 1762 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1763 | - // calculer la description de la table |
|
| 1764 | - if (!is_array($desc)) { |
|
| 1765 | - $desc = description_table($table, $serveur); |
|
| 1766 | - } |
|
| 1767 | - if (!$desc) { |
|
| 1768 | - return []; |
|
| 1769 | - } |
|
| 1770 | - |
|
| 1771 | - // Les champs id_xx de la table demandée |
|
| 1772 | - $champs = array_filter( |
|
| 1773 | - array_keys($desc['field']), |
|
| 1774 | - fn($champ) => str_starts_with($champ, 'id_') || $champ == 'objet' |
|
| 1775 | - ); |
|
| 1776 | - |
|
| 1777 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1778 | - if ( |
|
| 1779 | - in_array('id_rubrique', $champs) |
|
| 1780 | - && !in_array('id_secteur', $champs) |
|
| 1781 | - ) { |
|
| 1782 | - $champs[] = 'id_secteur'; |
|
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1786 | - if ($serveur) { |
|
| 1787 | - return $champs; |
|
| 1788 | - } |
|
| 1789 | - |
|
| 1790 | - $primary = false; |
|
| 1791 | - $associable = false; |
|
| 1792 | - include_spip('action/editer_liens'); |
|
| 1793 | - |
|
| 1794 | - if (isset($desc['type'])) { |
|
| 1795 | - $primary = id_table_objet($desc['type']); |
|
| 1796 | - $associable = objet_associable($desc['type']); |
|
| 1797 | - } |
|
| 1798 | - if (isset($desc['field']['id_objet']) && isset($desc['field']['objet'])) { |
|
| 1799 | - $associable = true; |
|
| 1800 | - } |
|
| 1801 | - |
|
| 1802 | - // liste de toutes les tables principales, sauf la notre |
|
| 1803 | - $tables = lister_tables_objets_sql(); |
|
| 1804 | - unset($tables[$table]); |
|
| 1805 | - |
|
| 1806 | - foreach ($tables as $_table => $_desc) { |
|
| 1807 | - if ( |
|
| 1808 | - $associable |
|
| 1809 | - || $primary && array_key_exists($primary, $_desc['field']) |
|
| 1810 | - || objet_associable($_desc['type']) |
|
| 1811 | - ) { |
|
| 1812 | - $champs[] = id_table_objet($_table); |
|
| 1813 | - } |
|
| 1814 | - } |
|
| 1815 | - $champs = array_values(array_unique($champs)); |
|
| 1816 | - |
|
| 1817 | - // Exclusions de certains id |
|
| 1818 | - $exclusions = pipeline( |
|
| 1819 | - 'exclure_id_conditionnel', |
|
| 1820 | - [ |
|
| 1821 | - 'args' => [ |
|
| 1822 | - 'table' => $table, |
|
| 1823 | - 'id_table_objet' => $primary, |
|
| 1824 | - 'associable' => $associable, |
|
| 1825 | - ], |
|
| 1826 | - 'data' => [], |
|
| 1827 | - ] |
|
| 1828 | - ); |
|
| 1829 | - |
|
| 1830 | - return array_diff($champs, $exclusions); |
|
| 1763 | + // calculer la description de la table |
|
| 1764 | + if (!is_array($desc)) { |
|
| 1765 | + $desc = description_table($table, $serveur); |
|
| 1766 | + } |
|
| 1767 | + if (!$desc) { |
|
| 1768 | + return []; |
|
| 1769 | + } |
|
| 1770 | + |
|
| 1771 | + // Les champs id_xx de la table demandée |
|
| 1772 | + $champs = array_filter( |
|
| 1773 | + array_keys($desc['field']), |
|
| 1774 | + fn($champ) => str_starts_with($champ, 'id_') || $champ == 'objet' |
|
| 1775 | + ); |
|
| 1776 | + |
|
| 1777 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1778 | + if ( |
|
| 1779 | + in_array('id_rubrique', $champs) |
|
| 1780 | + && !in_array('id_secteur', $champs) |
|
| 1781 | + ) { |
|
| 1782 | + $champs[] = 'id_secteur'; |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1786 | + if ($serveur) { |
|
| 1787 | + return $champs; |
|
| 1788 | + } |
|
| 1789 | + |
|
| 1790 | + $primary = false; |
|
| 1791 | + $associable = false; |
|
| 1792 | + include_spip('action/editer_liens'); |
|
| 1793 | + |
|
| 1794 | + if (isset($desc['type'])) { |
|
| 1795 | + $primary = id_table_objet($desc['type']); |
|
| 1796 | + $associable = objet_associable($desc['type']); |
|
| 1797 | + } |
|
| 1798 | + if (isset($desc['field']['id_objet']) && isset($desc['field']['objet'])) { |
|
| 1799 | + $associable = true; |
|
| 1800 | + } |
|
| 1801 | + |
|
| 1802 | + // liste de toutes les tables principales, sauf la notre |
|
| 1803 | + $tables = lister_tables_objets_sql(); |
|
| 1804 | + unset($tables[$table]); |
|
| 1805 | + |
|
| 1806 | + foreach ($tables as $_table => $_desc) { |
|
| 1807 | + if ( |
|
| 1808 | + $associable |
|
| 1809 | + || $primary && array_key_exists($primary, $_desc['field']) |
|
| 1810 | + || objet_associable($_desc['type']) |
|
| 1811 | + ) { |
|
| 1812 | + $champs[] = id_table_objet($_table); |
|
| 1813 | + } |
|
| 1814 | + } |
|
| 1815 | + $champs = array_values(array_unique($champs)); |
|
| 1816 | + |
|
| 1817 | + // Exclusions de certains id |
|
| 1818 | + $exclusions = pipeline( |
|
| 1819 | + 'exclure_id_conditionnel', |
|
| 1820 | + [ |
|
| 1821 | + 'args' => [ |
|
| 1822 | + 'table' => $table, |
|
| 1823 | + 'id_table_objet' => $primary, |
|
| 1824 | + 'associable' => $associable, |
|
| 1825 | + ], |
|
| 1826 | + 'data' => [], |
|
| 1827 | + ] |
|
| 1828 | + ); |
|
| 1829 | + |
|
| 1830 | + return array_diff($champs, $exclusions); |
|
| 1831 | 1831 | } |
| 1832 | 1832 | |
| 1833 | 1833 | /** |
@@ -1882,31 +1882,31 @@ discard block |
||
| 1882 | 1882 | * @return void |
| 1883 | 1883 | */ |
| 1884 | 1884 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1885 | - $boucle = &$boucles[$idb]; |
|
| 1886 | - |
|
| 1887 | - // definition du champ par defaut |
|
| 1888 | - $_champ_defaut = isset($crit->param[0][0]) |
|
| 1889 | - ? calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1890 | - : "''"; |
|
| 1891 | - $_liste_sens_defaut = isset($crit->param[1][0]) |
|
| 1892 | - ? calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1893 | - : '1'; |
|
| 1894 | - $_variable = isset($crit->param[2][0]) |
|
| 1895 | - ? calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1896 | - : "'$idb'"; |
|
| 1897 | - |
|
| 1898 | - $_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):'')"; |
|
| 1899 | - |
|
| 1900 | - $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1901 | - $_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)"; |
|
| 1902 | - |
|
| 1903 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1904 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1905 | - $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1906 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1907 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1908 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1909 | - $boucle->hash .= " |
|
| 1885 | + $boucle = &$boucles[$idb]; |
|
| 1886 | + |
|
| 1887 | + // definition du champ par defaut |
|
| 1888 | + $_champ_defaut = isset($crit->param[0][0]) |
|
| 1889 | + ? calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1890 | + : "''"; |
|
| 1891 | + $_liste_sens_defaut = isset($crit->param[1][0]) |
|
| 1892 | + ? calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1893 | + : '1'; |
|
| 1894 | + $_variable = isset($crit->param[2][0]) |
|
| 1895 | + ? calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent) |
|
| 1896 | + : "'$idb'"; |
|
| 1897 | + |
|
| 1898 | + $_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):'')"; |
|
| 1899 | + |
|
| 1900 | + $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1901 | + $_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)"; |
|
| 1902 | + |
|
| 1903 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1904 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1905 | + $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1906 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1907 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1908 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1909 | + $boucle->hash .= " |
|
| 1910 | 1910 | \$senstri = ''; |
| 1911 | 1911 | \$tri = $_tri; |
| 1912 | 1912 | if (\$tri){ |
@@ -1914,8 +1914,8 @@ discard block |
||
| 1914 | 1914 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1915 | 1915 | }; |
| 1916 | 1916 | "; |
| 1917 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1918 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1917 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1918 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1919 | 1919 | } |
| 1920 | 1920 | |
| 1921 | 1921 | # criteres de comparaison |
@@ -1932,21 +1932,21 @@ discard block |
||
| 1932 | 1932 | * @return void|array |
| 1933 | 1933 | **/ |
| 1934 | 1934 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1935 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1936 | - if ($crit->op == ',' || $crit->op == '/') { |
|
| 1937 | - calculer_critere_parties($idb, $boucles, $crit); |
|
| 1938 | - return; |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1942 | - if (!$r) { |
|
| 1943 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1944 | - # if (!$crit->cond) { |
|
| 1945 | - return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1946 | - # } |
|
| 1947 | - } else { |
|
| 1948 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1949 | - } |
|
| 1935 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1936 | + if ($crit->op == ',' || $crit->op == '/') { |
|
| 1937 | + calculer_critere_parties($idb, $boucles, $crit); |
|
| 1938 | + return; |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1942 | + if (!$r) { |
|
| 1943 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1944 | + # if (!$crit->cond) { |
|
| 1945 | + return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1946 | + # } |
|
| 1947 | + } else { |
|
| 1948 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1949 | + } |
|
| 1950 | 1950 | } |
| 1951 | 1951 | |
| 1952 | 1952 | |
@@ -1966,60 +1966,60 @@ discard block |
||
| 1966 | 1966 | * @return void |
| 1967 | 1967 | **/ |
| 1968 | 1968 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1969 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1970 | - |
|
| 1971 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1972 | - |
|
| 1973 | - // inserer la negation (cf !...) |
|
| 1974 | - |
|
| 1975 | - if ($crit->not) { |
|
| 1976 | - $where = ["'NOT'", $where]; |
|
| 1977 | - } |
|
| 1978 | - if ($crit->exclus) { |
|
| 1979 | - if (!preg_match(',^L\d+[.],', (string) $arg)) { |
|
| 1980 | - $where = ["'NOT'", $where]; |
|
| 1981 | - } else { |
|
| 1982 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1983 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1984 | - $where = [ |
|
| 1985 | - "'NOT'", |
|
| 1986 | - [ |
|
| 1987 | - "'IN'", |
|
| 1988 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1989 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1990 | - ] |
|
| 1991 | - ]; |
|
| 1992 | - } |
|
| 1993 | - } |
|
| 1994 | - |
|
| 1995 | - // inserer la condition (cf {lang?}) |
|
| 1996 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1997 | - if ($crit->cond) { |
|
| 1998 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1999 | - if (($col === 'date' || $col === 'date_redac') && $pred === "\$Pile[0]['" . $col . "']") { |
|
| 2000 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 2001 | - } |
|
| 2002 | - |
|
| 2003 | - if ($op === '=' && !$crit->not) { |
|
| 2004 | - $where = [ |
|
| 2005 | - "'?'", |
|
| 2006 | - "(is_array($pred))", |
|
| 2007 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 2008 | - $where |
|
| 2009 | - ]; |
|
| 2010 | - } |
|
| 2011 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 2012 | - if ($where_complement) { |
|
| 2013 | - // condition annexe du type "AND (objet='article')" |
|
| 2014 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 2015 | - } |
|
| 2016 | - } |
|
| 2017 | - |
|
| 2018 | - $boucles[$idb]->where[] = $where; |
|
| 2019 | - if ($where_complement) { |
|
| 2020 | - // condition annexe du type "AND (objet='article')" |
|
| 2021 | - $boucles[$idb]->where[] = $where_complement; |
|
| 2022 | - } |
|
| 1969 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1970 | + |
|
| 1971 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1972 | + |
|
| 1973 | + // inserer la negation (cf !...) |
|
| 1974 | + |
|
| 1975 | + if ($crit->not) { |
|
| 1976 | + $where = ["'NOT'", $where]; |
|
| 1977 | + } |
|
| 1978 | + if ($crit->exclus) { |
|
| 1979 | + if (!preg_match(',^L\d+[.],', (string) $arg)) { |
|
| 1980 | + $where = ["'NOT'", $where]; |
|
| 1981 | + } else { |
|
| 1982 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1983 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1984 | + $where = [ |
|
| 1985 | + "'NOT'", |
|
| 1986 | + [ |
|
| 1987 | + "'IN'", |
|
| 1988 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1989 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1990 | + ] |
|
| 1991 | + ]; |
|
| 1992 | + } |
|
| 1993 | + } |
|
| 1994 | + |
|
| 1995 | + // inserer la condition (cf {lang?}) |
|
| 1996 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1997 | + if ($crit->cond) { |
|
| 1998 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1999 | + if (($col === 'date' || $col === 'date_redac') && $pred === "\$Pile[0]['" . $col . "']") { |
|
| 2000 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 2001 | + } |
|
| 2002 | + |
|
| 2003 | + if ($op === '=' && !$crit->not) { |
|
| 2004 | + $where = [ |
|
| 2005 | + "'?'", |
|
| 2006 | + "(is_array($pred))", |
|
| 2007 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 2008 | + $where |
|
| 2009 | + ]; |
|
| 2010 | + } |
|
| 2011 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 2012 | + if ($where_complement) { |
|
| 2013 | + // condition annexe du type "AND (objet='article')" |
|
| 2014 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 2015 | + } |
|
| 2016 | + } |
|
| 2017 | + |
|
| 2018 | + $boucles[$idb]->where[] = $where; |
|
| 2019 | + if ($where_complement) { |
|
| 2020 | + // condition annexe du type "AND (objet='article')" |
|
| 2021 | + $boucles[$idb]->where[] = $where_complement; |
|
| 2022 | + } |
|
| 2023 | 2023 | } |
| 2024 | 2024 | |
| 2025 | 2025 | |
@@ -2060,160 +2060,160 @@ discard block |
||
| 2060 | 2060 | **/ |
| 2061 | 2061 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 2062 | 2062 | |
| 2063 | - $boucle = &$boucles[$idb]; |
|
| 2064 | - $type = $boucle->type_requete; |
|
| 2065 | - $table = $boucle->id_table; |
|
| 2066 | - $desc = $boucle->show; |
|
| 2067 | - $col_vraie = null; |
|
| 2068 | - |
|
| 2069 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 2070 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2071 | - |
|
| 2072 | - $col_alias = $col; |
|
| 2073 | - $where_complement = false; |
|
| 2074 | - |
|
| 2075 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2076 | - if ($col == 'id_enfant') { |
|
| 2077 | - $col = $boucle->primary; |
|
| 2078 | - } |
|
| 2079 | - |
|
| 2080 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2081 | - if ( |
|
| 2082 | - in_array($col, ['id_parent', 'id_secteur']) |
|
| 2083 | - && isset($GLOBALS['exceptions_des_tables'][$table][$col]) || isset($GLOBALS['exceptions_des_tables'][$table][$col]) && is_string($GLOBALS['exceptions_des_tables'][$table][$col]) |
|
| 2084 | - ) { |
|
| 2085 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2086 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2087 | - else { |
|
| 2088 | - if ($col == 'id_secteur' && ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2089 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2090 | - } |
|
| 2091 | - |
|
| 2092 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2093 | - // sauf si exception declaree : sauter cette etape |
|
| 2094 | - else { |
|
| 2095 | - if ( |
|
| 2096 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2097 | - && !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2098 | - && count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2099 | - ) { |
|
| 2100 | - $e = decompose_champ_id_objet($col); |
|
| 2101 | - $col = array_shift($e); |
|
| 2102 | - $where_complement = primary_doublee($e, $table); |
|
| 2103 | - } // Cas particulier : expressions de date |
|
| 2104 | - else { |
|
| 2105 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2106 | - [$col, $col_vraie] = $c; |
|
| 2107 | - $table = ''; |
|
| 2108 | - } // table explicitée {mots.titre} |
|
| 2109 | - else { |
|
| 2110 | - if (preg_match('/^(.*)\.(.*)$/', (string) $col, $r)) { |
|
| 2111 | - [, $table, $col] = $r; |
|
| 2112 | - $col_alias = $col; |
|
| 2113 | - |
|
| 2114 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2115 | - if ( |
|
| 2116 | - ($desc = $trouver_table($table, $boucle->sql_serveur)) |
|
| 2117 | - && isset($desc['field'][$col]) |
|
| 2118 | - && ($cle = array_search($desc['table'], $boucle->from)) |
|
| 2119 | - ) { |
|
| 2120 | - $table = $cle; |
|
| 2121 | - } else { |
|
| 2122 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond || $op != '=')); |
|
| 2123 | - } |
|
| 2124 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2125 | - if (!$table) { |
|
| 2126 | - return ''; |
|
| 2127 | - } |
|
| 2128 | - } |
|
| 2129 | - // si le champ n'est pas trouvé dans la table, |
|
| 2130 | - // on cherche si une jointure peut l'obtenir |
|
| 2131 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2132 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2133 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2134 | - $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2135 | - } |
|
| 2136 | - else { |
|
| 2137 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2138 | - if (!$r) { |
|
| 2139 | - return ''; |
|
| 2140 | - } |
|
| 2141 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2142 | - } |
|
| 2143 | - } |
|
| 2144 | - } |
|
| 2145 | - } |
|
| 2146 | - } |
|
| 2147 | - } |
|
| 2148 | - |
|
| 2149 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2150 | - // Dans tous les cas, |
|
| 2151 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2152 | - // et passer dans sql_quote avec le type si connu |
|
| 2153 | - // et int sinon si la valeur est numerique |
|
| 2154 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2155 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2156 | - if ($op == '=' || in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2157 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2158 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2159 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2160 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", (string) $val[0], $r)) { |
|
| 2161 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2162 | - } |
|
| 2163 | - // sinon expliciter les |
|
| 2164 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2165 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2166 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2167 | - // sans toucher aux |
|
| 2168 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2169 | - // sql_quote(truc,'','varchar') |
|
| 2170 | - elseif ( |
|
| 2171 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', (string) $val[0], $r) |
|
| 2172 | - && (!isset($r[3]) || !$r[3] || !trim($r[3], ", '")) |
|
| 2173 | - ) { |
|
| 2174 | - $r = $r[1] |
|
| 2175 | - . ((isset($r[2]) && $r[2]) ? $r[2] : ",''") |
|
| 2176 | - . ",'" . addslashes((string) $type_cast_quote) . "'"; |
|
| 2177 | - $val[0] = "sql_quote($r)"; |
|
| 2178 | - } |
|
| 2179 | - elseif ( |
|
| 2180 | - str_contains((string) $val[0], '@@defaultcast@@') |
|
| 2181 | - && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
|
| 2182 | - ) { |
|
| 2183 | - $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'" . addslashes((string) $type_cast_quote) . "')"; |
|
| 2184 | - } |
|
| 2185 | - } |
|
| 2186 | - |
|
| 2187 | - if ( |
|
| 2188 | - str_contains((string) $val[0], '@@defaultcast@@') |
|
| 2189 | - && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
|
| 2190 | - ) { |
|
| 2191 | - $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2192 | - } |
|
| 2193 | - |
|
| 2194 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2195 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2196 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2197 | - if ($table === $boucle->id_table) { |
|
| 2198 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2199 | - if ($col_alias != $col_vraie) { |
|
| 2200 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2201 | - } |
|
| 2202 | - } |
|
| 2203 | - |
|
| 2204 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2205 | - if ($table) { |
|
| 2206 | - $arg = $col[0] == '`' ? "$table." . substr((string) $col, 1, -1) : "$table.$col"; |
|
| 2207 | - } else { |
|
| 2208 | - $arg = $col; |
|
| 2209 | - } |
|
| 2210 | - |
|
| 2211 | - // inserer la fonction SQL |
|
| 2212 | - if ($fct) { |
|
| 2213 | - $arg = "$fct($arg$args_sql)"; |
|
| 2214 | - } |
|
| 2215 | - |
|
| 2216 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2063 | + $boucle = &$boucles[$idb]; |
|
| 2064 | + $type = $boucle->type_requete; |
|
| 2065 | + $table = $boucle->id_table; |
|
| 2066 | + $desc = $boucle->show; |
|
| 2067 | + $col_vraie = null; |
|
| 2068 | + |
|
| 2069 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 2070 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2071 | + |
|
| 2072 | + $col_alias = $col; |
|
| 2073 | + $where_complement = false; |
|
| 2074 | + |
|
| 2075 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2076 | + if ($col == 'id_enfant') { |
|
| 2077 | + $col = $boucle->primary; |
|
| 2078 | + } |
|
| 2079 | + |
|
| 2080 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2081 | + if ( |
|
| 2082 | + in_array($col, ['id_parent', 'id_secteur']) |
|
| 2083 | + && isset($GLOBALS['exceptions_des_tables'][$table][$col]) || isset($GLOBALS['exceptions_des_tables'][$table][$col]) && is_string($GLOBALS['exceptions_des_tables'][$table][$col]) |
|
| 2084 | + ) { |
|
| 2085 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2086 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2087 | + else { |
|
| 2088 | + if ($col == 'id_secteur' && ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2089 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2090 | + } |
|
| 2091 | + |
|
| 2092 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2093 | + // sauf si exception declaree : sauter cette etape |
|
| 2094 | + else { |
|
| 2095 | + if ( |
|
| 2096 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2097 | + && !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2098 | + && count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2099 | + ) { |
|
| 2100 | + $e = decompose_champ_id_objet($col); |
|
| 2101 | + $col = array_shift($e); |
|
| 2102 | + $where_complement = primary_doublee($e, $table); |
|
| 2103 | + } // Cas particulier : expressions de date |
|
| 2104 | + else { |
|
| 2105 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2106 | + [$col, $col_vraie] = $c; |
|
| 2107 | + $table = ''; |
|
| 2108 | + } // table explicitée {mots.titre} |
|
| 2109 | + else { |
|
| 2110 | + if (preg_match('/^(.*)\.(.*)$/', (string) $col, $r)) { |
|
| 2111 | + [, $table, $col] = $r; |
|
| 2112 | + $col_alias = $col; |
|
| 2113 | + |
|
| 2114 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2115 | + if ( |
|
| 2116 | + ($desc = $trouver_table($table, $boucle->sql_serveur)) |
|
| 2117 | + && isset($desc['field'][$col]) |
|
| 2118 | + && ($cle = array_search($desc['table'], $boucle->from)) |
|
| 2119 | + ) { |
|
| 2120 | + $table = $cle; |
|
| 2121 | + } else { |
|
| 2122 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond || $op != '=')); |
|
| 2123 | + } |
|
| 2124 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2125 | + if (!$table) { |
|
| 2126 | + return ''; |
|
| 2127 | + } |
|
| 2128 | + } |
|
| 2129 | + // si le champ n'est pas trouvé dans la table, |
|
| 2130 | + // on cherche si une jointure peut l'obtenir |
|
| 2131 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2132 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2133 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2134 | + $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2135 | + } |
|
| 2136 | + else { |
|
| 2137 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2138 | + if (!$r) { |
|
| 2139 | + return ''; |
|
| 2140 | + } |
|
| 2141 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2142 | + } |
|
| 2143 | + } |
|
| 2144 | + } |
|
| 2145 | + } |
|
| 2146 | + } |
|
| 2147 | + } |
|
| 2148 | + |
|
| 2149 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2150 | + // Dans tous les cas, |
|
| 2151 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2152 | + // et passer dans sql_quote avec le type si connu |
|
| 2153 | + // et int sinon si la valeur est numerique |
|
| 2154 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2155 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2156 | + if ($op == '=' || in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2157 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2158 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2159 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2160 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", (string) $val[0], $r)) { |
|
| 2161 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2162 | + } |
|
| 2163 | + // sinon expliciter les |
|
| 2164 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2165 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2166 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2167 | + // sans toucher aux |
|
| 2168 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2169 | + // sql_quote(truc,'','varchar') |
|
| 2170 | + elseif ( |
|
| 2171 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', (string) $val[0], $r) |
|
| 2172 | + && (!isset($r[3]) || !$r[3] || !trim($r[3], ", '")) |
|
| 2173 | + ) { |
|
| 2174 | + $r = $r[1] |
|
| 2175 | + . ((isset($r[2]) && $r[2]) ? $r[2] : ",''") |
|
| 2176 | + . ",'" . addslashes((string) $type_cast_quote) . "'"; |
|
| 2177 | + $val[0] = "sql_quote($r)"; |
|
| 2178 | + } |
|
| 2179 | + elseif ( |
|
| 2180 | + str_contains((string) $val[0], '@@defaultcast@@') |
|
| 2181 | + && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
|
| 2182 | + ) { |
|
| 2183 | + $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'" . addslashes((string) $type_cast_quote) . "')"; |
|
| 2184 | + } |
|
| 2185 | + } |
|
| 2186 | + |
|
| 2187 | + if ( |
|
| 2188 | + str_contains((string) $val[0], '@@defaultcast@@') |
|
| 2189 | + && preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", (string) $val[0], $r) |
|
| 2190 | + ) { |
|
| 2191 | + $val[0] = substr((string) $val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2192 | + } |
|
| 2193 | + |
|
| 2194 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2195 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2196 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2197 | + if ($table === $boucle->id_table) { |
|
| 2198 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2199 | + if ($col_alias != $col_vraie) { |
|
| 2200 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2201 | + } |
|
| 2202 | + } |
|
| 2203 | + |
|
| 2204 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2205 | + if ($table) { |
|
| 2206 | + $arg = $col[0] == '`' ? "$table." . substr((string) $col, 1, -1) : "$table.$col"; |
|
| 2207 | + } else { |
|
| 2208 | + $arg = $col; |
|
| 2209 | + } |
|
| 2210 | + |
|
| 2211 | + // inserer la fonction SQL |
|
| 2212 | + if ($fct) { |
|
| 2213 | + $arg = "$fct($arg$args_sql)"; |
|
| 2214 | + } |
|
| 2215 | + |
|
| 2216 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2217 | 2217 | } |
| 2218 | 2218 | |
| 2219 | 2219 | |
@@ -2242,75 +2242,75 @@ discard block |
||
| 2242 | 2242 | **/ |
| 2243 | 2243 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2244 | 2244 | |
| 2245 | - $where = ''; |
|
| 2246 | - |
|
| 2247 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2248 | - // gestion par les plugins des jointures tordues |
|
| 2249 | - // pas automatiques mais necessaires |
|
| 2250 | - $table_sql = table_objet_sql($table); |
|
| 2251 | - if ( |
|
| 2252 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2253 | - && is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2254 | - && ( |
|
| 2255 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2256 | - || isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2257 | - ) |
|
| 2258 | - ) { |
|
| 2259 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2260 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2261 | - |
|
| 2262 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2263 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2264 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2265 | - [$t, $col] = $t[$col]; |
|
| 2266 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2267 | - [$calculer_critere_externe] = $index; |
|
| 2268 | - $t = $table; |
|
| 2269 | - } else { |
|
| 2270 | - $t = ''; |
|
| 2271 | - } // jointure non declaree. La trouver. |
|
| 2272 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2273 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2274 | - } else { |
|
| 2275 | - $t = ''; |
|
| 2276 | - } // jointure non declaree. La trouver. |
|
| 2277 | - |
|
| 2278 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2279 | - |
|
| 2280 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2281 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2282 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2283 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2284 | - $table = ''; |
|
| 2285 | - if ($boucle->jointures_explicites) { |
|
| 2286 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2287 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond || $op != '='), $t); |
|
| 2288 | - } |
|
| 2289 | - |
|
| 2290 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2291 | - if (!$table) { |
|
| 2292 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond || $op != '='), $t); |
|
| 2293 | - } |
|
| 2294 | - |
|
| 2295 | - if (!$table) { |
|
| 2296 | - return ''; |
|
| 2297 | - } |
|
| 2298 | - |
|
| 2299 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2300 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2301 | - |
|
| 2302 | - if ((is_countable($cle) ? count($cle) : 0) > 1 || reset($cle) !== $col) { |
|
| 2303 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2304 | - if ((is_countable($cle) ? count($cle) : 0) > 1 && reset($cle) == 'id_objet') { |
|
| 2305 | - $e = decompose_champ_id_objet($col); |
|
| 2306 | - $col = array_shift($e); |
|
| 2307 | - $where = primary_doublee($e, $table); |
|
| 2308 | - } else { |
|
| 2309 | - $col = reset($cle); |
|
| 2310 | - } |
|
| 2311 | - } |
|
| 2312 | - |
|
| 2313 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2245 | + $where = ''; |
|
| 2246 | + |
|
| 2247 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2248 | + // gestion par les plugins des jointures tordues |
|
| 2249 | + // pas automatiques mais necessaires |
|
| 2250 | + $table_sql = table_objet_sql($table); |
|
| 2251 | + if ( |
|
| 2252 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2253 | + && is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2254 | + && ( |
|
| 2255 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2256 | + || isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2257 | + ) |
|
| 2258 | + ) { |
|
| 2259 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2260 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2261 | + |
|
| 2262 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2263 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2264 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2265 | + [$t, $col] = $t[$col]; |
|
| 2266 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2267 | + [$calculer_critere_externe] = $index; |
|
| 2268 | + $t = $table; |
|
| 2269 | + } else { |
|
| 2270 | + $t = ''; |
|
| 2271 | + } // jointure non declaree. La trouver. |
|
| 2272 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2273 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2274 | + } else { |
|
| 2275 | + $t = ''; |
|
| 2276 | + } // jointure non declaree. La trouver. |
|
| 2277 | + |
|
| 2278 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2279 | + |
|
| 2280 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2281 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2282 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2283 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2284 | + $table = ''; |
|
| 2285 | + if ($boucle->jointures_explicites) { |
|
| 2286 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2287 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond || $op != '='), $t); |
|
| 2288 | + } |
|
| 2289 | + |
|
| 2290 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2291 | + if (!$table) { |
|
| 2292 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond || $op != '='), $t); |
|
| 2293 | + } |
|
| 2294 | + |
|
| 2295 | + if (!$table) { |
|
| 2296 | + return ''; |
|
| 2297 | + } |
|
| 2298 | + |
|
| 2299 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2300 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2301 | + |
|
| 2302 | + if ((is_countable($cle) ? count($cle) : 0) > 1 || reset($cle) !== $col) { |
|
| 2303 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2304 | + if ((is_countable($cle) ? count($cle) : 0) > 1 && reset($cle) == 'id_objet') { |
|
| 2305 | + $e = decompose_champ_id_objet($col); |
|
| 2306 | + $col = array_shift($e); |
|
| 2307 | + $where = primary_doublee($e, $table); |
|
| 2308 | + } else { |
|
| 2309 | + $col = reset($cle); |
|
| 2310 | + } |
|
| 2311 | + } |
|
| 2312 | + |
|
| 2313 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2314 | 2314 | } |
| 2315 | 2315 | |
| 2316 | 2316 | |
@@ -2331,10 +2331,10 @@ discard block |
||
| 2331 | 2331 | * - valeur |
| 2332 | 2332 | **/ |
| 2333 | 2333 | function primary_doublee($decompose, $table) { |
| 2334 | - $e1 = reset($decompose); |
|
| 2335 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2334 | + $e1 = reset($decompose); |
|
| 2335 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2336 | 2336 | |
| 2337 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2337 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2338 | 2338 | } |
| 2339 | 2339 | |
| 2340 | 2340 | /** |
@@ -2365,56 +2365,56 @@ discard block |
||
| 2365 | 2365 | * Vide sinon. |
| 2366 | 2366 | */ |
| 2367 | 2367 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2368 | - // si on demande un truc du genre spip_mots |
|
| 2369 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2370 | - // et qu'on est la |
|
| 2371 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2372 | - if ( |
|
| 2373 | - $checkarrivee |
|
| 2374 | - && is_string($checkarrivee) |
|
| 2375 | - && ($a = table_objet($checkarrivee)) |
|
| 2376 | - && in_array($a . '_liens', $joints) |
|
| 2377 | - && ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) |
|
| 2378 | - ) { |
|
| 2379 | - return $res; |
|
| 2380 | - } |
|
| 2381 | - foreach ($joints as $joint) { |
|
| 2382 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2383 | - // alias de table dans le from |
|
| 2384 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2385 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2386 | - $cols = $arrivee[2]; |
|
| 2387 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2388 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2389 | - array_pop($cols); |
|
| 2390 | - } |
|
| 2391 | - if ($t) { |
|
| 2392 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2393 | - $joindre = false; |
|
| 2394 | - foreach ($cols as $col) { |
|
| 2395 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2396 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2397 | - $joindre = true; |
|
| 2398 | - } else { |
|
| 2399 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2400 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2401 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2402 | - $joindre = true; |
|
| 2403 | - } |
|
| 2404 | - } |
|
| 2405 | - } |
|
| 2406 | - if (!$joindre) { |
|
| 2407 | - return $t; |
|
| 2408 | - } |
|
| 2409 | - } |
|
| 2410 | - array_pop($arrivee); |
|
| 2411 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2412 | - return $res; |
|
| 2413 | - } |
|
| 2414 | - } |
|
| 2415 | - } |
|
| 2416 | - |
|
| 2417 | - return ''; |
|
| 2368 | + // si on demande un truc du genre spip_mots |
|
| 2369 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2370 | + // et qu'on est la |
|
| 2371 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2372 | + if ( |
|
| 2373 | + $checkarrivee |
|
| 2374 | + && is_string($checkarrivee) |
|
| 2375 | + && ($a = table_objet($checkarrivee)) |
|
| 2376 | + && in_array($a . '_liens', $joints) |
|
| 2377 | + && ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) |
|
| 2378 | + ) { |
|
| 2379 | + return $res; |
|
| 2380 | + } |
|
| 2381 | + foreach ($joints as $joint) { |
|
| 2382 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2383 | + // alias de table dans le from |
|
| 2384 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2385 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2386 | + $cols = $arrivee[2]; |
|
| 2387 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2388 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2389 | + array_pop($cols); |
|
| 2390 | + } |
|
| 2391 | + if ($t) { |
|
| 2392 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2393 | + $joindre = false; |
|
| 2394 | + foreach ($cols as $col) { |
|
| 2395 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2396 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2397 | + $joindre = true; |
|
| 2398 | + } else { |
|
| 2399 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2400 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2401 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2402 | + $joindre = true; |
|
| 2403 | + } |
|
| 2404 | + } |
|
| 2405 | + } |
|
| 2406 | + if (!$joindre) { |
|
| 2407 | + return $t; |
|
| 2408 | + } |
|
| 2409 | + } |
|
| 2410 | + array_pop($arrivee); |
|
| 2411 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2412 | + return $res; |
|
| 2413 | + } |
|
| 2414 | + } |
|
| 2415 | + } |
|
| 2416 | + |
|
| 2417 | + return ''; |
|
| 2418 | 2418 | } |
| 2419 | 2419 | |
| 2420 | 2420 | /** |
@@ -2440,35 +2440,35 @@ discard block |
||
| 2440 | 2440 | * Alias de la table de jointure (Lx) |
| 2441 | 2441 | */ |
| 2442 | 2442 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2443 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2444 | - |
|
| 2445 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2446 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2447 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2448 | - |
|
| 2449 | - if (!$intermediaire || !$arrivee) { |
|
| 2450 | - return ''; |
|
| 2451 | - } |
|
| 2452 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2453 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2454 | - |
|
| 2455 | - $res = fabrique_jointures( |
|
| 2456 | - $boucle, |
|
| 2457 | - [ |
|
| 2458 | - [ |
|
| 2459 | - $boucle->id_table, |
|
| 2460 | - $intermediaire, |
|
| 2461 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2462 | - ], |
|
| 2463 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2464 | - ], |
|
| 2465 | - $cond, |
|
| 2466 | - $desc, |
|
| 2467 | - $boucle->id_table, |
|
| 2468 | - [$col] |
|
| 2469 | - ); |
|
| 2470 | - |
|
| 2471 | - return $res; |
|
| 2443 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2444 | + |
|
| 2445 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2446 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2447 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2448 | + |
|
| 2449 | + if (!$intermediaire || !$arrivee) { |
|
| 2450 | + return ''; |
|
| 2451 | + } |
|
| 2452 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2453 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2454 | + |
|
| 2455 | + $res = fabrique_jointures( |
|
| 2456 | + $boucle, |
|
| 2457 | + [ |
|
| 2458 | + [ |
|
| 2459 | + $boucle->id_table, |
|
| 2460 | + $intermediaire, |
|
| 2461 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2462 | + ], |
|
| 2463 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2464 | + ], |
|
| 2465 | + $cond, |
|
| 2466 | + $desc, |
|
| 2467 | + $boucle->id_table, |
|
| 2468 | + [$col] |
|
| 2469 | + ); |
|
| 2470 | + |
|
| 2471 | + return $res; |
|
| 2472 | 2472 | } |
| 2473 | 2473 | |
| 2474 | 2474 | |
@@ -2485,17 +2485,17 @@ discard block |
||
| 2485 | 2485 | * false sinon. |
| 2486 | 2486 | **/ |
| 2487 | 2487 | function trouver_champ($champ, $where) { |
| 2488 | - if (!is_array($where)) { |
|
| 2489 | - return preg_match($champ, $where); |
|
| 2490 | - } else { |
|
| 2491 | - foreach ($where as $clause) { |
|
| 2492 | - if (trouver_champ($champ, $clause)) { |
|
| 2493 | - return true; |
|
| 2494 | - } |
|
| 2495 | - } |
|
| 2496 | - |
|
| 2497 | - return false; |
|
| 2498 | - } |
|
| 2488 | + if (!is_array($where)) { |
|
| 2489 | + return preg_match($champ, $where); |
|
| 2490 | + } else { |
|
| 2491 | + foreach ($where as $clause) { |
|
| 2492 | + if (trouver_champ($champ, $clause)) { |
|
| 2493 | + return true; |
|
| 2494 | + } |
|
| 2495 | + } |
|
| 2496 | + |
|
| 2497 | + return false; |
|
| 2498 | + } |
|
| 2499 | 2499 | } |
| 2500 | 2500 | |
| 2501 | 2501 | |
@@ -2521,128 +2521,128 @@ discard block |
||
| 2521 | 2521 | * - string $args_sql Suite des arguments du critère. ? |
| 2522 | 2522 | **/ |
| 2523 | 2523 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2524 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2525 | - if ((is_countable($crit->param) ? count($crit->param) : 0) == 0) { |
|
| 2526 | - $op = '='; |
|
| 2527 | - $col = $val = $crit->op; |
|
| 2528 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2529 | - $val = $r[2]; |
|
| 2530 | - } |
|
| 2531 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2532 | - if ($val == 'lang') { |
|
| 2533 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2534 | - } else { |
|
| 2535 | - $defaut = null; |
|
| 2536 | - if ($val == 'id_parent') { |
|
| 2537 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2538 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2539 | - // pour eviter l'erreur SQL |
|
| 2540 | - $val = $boucles[$idb]->primary; |
|
| 2541 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2542 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2543 | - } elseif ($val == 'id_enfant') { |
|
| 2544 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2545 | - // de la boucle superieure |
|
| 2546 | - $val = 'id_parent'; |
|
| 2547 | - } elseif ($crit->cond && ($col == 'date' || $col == 'date_redac')) { |
|
| 2548 | - // un critere conditionnel sur date est traite a part |
|
| 2549 | - // car la date est mise d'office par SPIP, |
|
| 2550 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2551 | - } |
|
| 2552 | - |
|
| 2553 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2554 | - $val = [kwote($val)]; |
|
| 2555 | - } |
|
| 2556 | - } else { |
|
| 2557 | - // comparaison explicite |
|
| 2558 | - // le phraseur impose que le premier param soit du texte |
|
| 2559 | - $params = $crit->param; |
|
| 2560 | - $op = $crit->op; |
|
| 2561 | - if ($op == '==') { |
|
| 2562 | - $op = 'REGEXP'; |
|
| 2563 | - } |
|
| 2564 | - $col = array_shift($params); |
|
| 2565 | - $col = $col[0]->texte; |
|
| 2566 | - |
|
| 2567 | - $val = []; |
|
| 2568 | - $parent = $boucles[$idb]->id_parent; |
|
| 2569 | - |
|
| 2570 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2571 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2572 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2573 | - if ( |
|
| 2574 | - (is_countable($params) ? count($params) : 0) == 1 |
|
| 2575 | - && (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2576 | - && $params[0][0]->type == 'texte' |
|
| 2577 | - && $params[0][2]->type == 'texte' |
|
| 2578 | - && ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2579 | - && ($p == "'" || $p == '"') |
|
| 2580 | - && $params[0][1]->type == 'champ' |
|
| 2581 | - ) { |
|
| 2582 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2583 | - } else { |
|
| 2584 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2585 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2586 | - $val[] = strcasecmp($op, 'IN') == 0 |
|
| 2587 | - ? $a |
|
| 2588 | - // toujours quoter en char ici |
|
| 2589 | - : kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2590 | - } |
|
| 2591 | - } |
|
| 2592 | - } |
|
| 2593 | - |
|
| 2594 | - $fct = $args_sql = ''; |
|
| 2595 | - // fonction SQL ? |
|
| 2596 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2597 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', (string) $col, $m)) { |
|
| 2598 | - $fct = $m[1]; |
|
| 2599 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2600 | - $col = $a[1]; |
|
| 2601 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2602 | - $col = $m[1]; |
|
| 2603 | - $args_sql = $m[2]; |
|
| 2604 | - } |
|
| 2605 | - $args_sql .= $a[2]; |
|
| 2606 | - } |
|
| 2607 | - |
|
| 2608 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2524 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2525 | + if ((is_countable($crit->param) ? count($crit->param) : 0) == 0) { |
|
| 2526 | + $op = '='; |
|
| 2527 | + $col = $val = $crit->op; |
|
| 2528 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2529 | + $val = $r[2]; |
|
| 2530 | + } |
|
| 2531 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2532 | + if ($val == 'lang') { |
|
| 2533 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2534 | + } else { |
|
| 2535 | + $defaut = null; |
|
| 2536 | + if ($val == 'id_parent') { |
|
| 2537 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2538 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2539 | + // pour eviter l'erreur SQL |
|
| 2540 | + $val = $boucles[$idb]->primary; |
|
| 2541 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2542 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2543 | + } elseif ($val == 'id_enfant') { |
|
| 2544 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2545 | + // de la boucle superieure |
|
| 2546 | + $val = 'id_parent'; |
|
| 2547 | + } elseif ($crit->cond && ($col == 'date' || $col == 'date_redac')) { |
|
| 2548 | + // un critere conditionnel sur date est traite a part |
|
| 2549 | + // car la date est mise d'office par SPIP, |
|
| 2550 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2551 | + } |
|
| 2552 | + |
|
| 2553 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2554 | + $val = [kwote($val)]; |
|
| 2555 | + } |
|
| 2556 | + } else { |
|
| 2557 | + // comparaison explicite |
|
| 2558 | + // le phraseur impose que le premier param soit du texte |
|
| 2559 | + $params = $crit->param; |
|
| 2560 | + $op = $crit->op; |
|
| 2561 | + if ($op == '==') { |
|
| 2562 | + $op = 'REGEXP'; |
|
| 2563 | + } |
|
| 2564 | + $col = array_shift($params); |
|
| 2565 | + $col = $col[0]->texte; |
|
| 2566 | + |
|
| 2567 | + $val = []; |
|
| 2568 | + $parent = $boucles[$idb]->id_parent; |
|
| 2569 | + |
|
| 2570 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2571 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2572 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2573 | + if ( |
|
| 2574 | + (is_countable($params) ? count($params) : 0) == 1 |
|
| 2575 | + && (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2576 | + && $params[0][0]->type == 'texte' |
|
| 2577 | + && $params[0][2]->type == 'texte' |
|
| 2578 | + && ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2579 | + && ($p == "'" || $p == '"') |
|
| 2580 | + && $params[0][1]->type == 'champ' |
|
| 2581 | + ) { |
|
| 2582 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2583 | + } else { |
|
| 2584 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2585 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2586 | + $val[] = strcasecmp($op, 'IN') == 0 |
|
| 2587 | + ? $a |
|
| 2588 | + // toujours quoter en char ici |
|
| 2589 | + : kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2590 | + } |
|
| 2591 | + } |
|
| 2592 | + } |
|
| 2593 | + |
|
| 2594 | + $fct = $args_sql = ''; |
|
| 2595 | + // fonction SQL ? |
|
| 2596 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2597 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', (string) $col, $m)) { |
|
| 2598 | + $fct = $m[1]; |
|
| 2599 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2600 | + $col = $a[1]; |
|
| 2601 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2602 | + $col = $m[1]; |
|
| 2603 | + $args_sql = $m[2]; |
|
| 2604 | + } |
|
| 2605 | + $args_sql .= $a[2]; |
|
| 2606 | + } |
|
| 2607 | + |
|
| 2608 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2609 | 2609 | } |
| 2610 | 2610 | |
| 2611 | 2611 | // compatibilite ancienne version |
| 2612 | 2612 | |
| 2613 | 2613 | function calculer_vieux_in($params) { |
| 2614 | - $deb = $params[0][0]; |
|
| 2615 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2616 | - $last = $params[$k]; |
|
| 2617 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2618 | - $last = $last[$j]; |
|
| 2619 | - $n = isset($last->texte) ? strlen((string) $last->texte) : 0; |
|
| 2620 | - |
|
| 2621 | - if ( |
|
| 2622 | - !((isset($deb->texte[0]) && $deb->texte[0] == '(') |
|
| 2623 | - && (isset($last->texte[$n - 1]) && $last->texte[$n - 1] == ')')) |
|
| 2624 | - ) { |
|
| 2625 | - return $params; |
|
| 2626 | - } |
|
| 2627 | - $params[0][0]->texte = substr((string) $deb->texte, 1); |
|
| 2628 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2629 | - $last = $params[$k][$j]; |
|
| 2630 | - $n = strlen((string) $last->texte); |
|
| 2631 | - $params[$k][$j]->texte = substr((string) $last->texte, 0, $n - 1); |
|
| 2632 | - $newp = []; |
|
| 2633 | - foreach ($params as $v) { |
|
| 2634 | - if ($v[0]->type != 'texte') { |
|
| 2635 | - $newp[] = $v; |
|
| 2636 | - } else { |
|
| 2637 | - foreach (explode(',', (string) $v[0]->texte) as $x) { |
|
| 2638 | - $t = new Texte(); |
|
| 2639 | - $t->texte = $x; |
|
| 2640 | - $newp[] = [$t]; |
|
| 2641 | - } |
|
| 2642 | - } |
|
| 2643 | - } |
|
| 2644 | - |
|
| 2645 | - return $newp; |
|
| 2614 | + $deb = $params[0][0]; |
|
| 2615 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2616 | + $last = $params[$k]; |
|
| 2617 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2618 | + $last = $last[$j]; |
|
| 2619 | + $n = isset($last->texte) ? strlen((string) $last->texte) : 0; |
|
| 2620 | + |
|
| 2621 | + if ( |
|
| 2622 | + !((isset($deb->texte[0]) && $deb->texte[0] == '(') |
|
| 2623 | + && (isset($last->texte[$n - 1]) && $last->texte[$n - 1] == ')')) |
|
| 2624 | + ) { |
|
| 2625 | + return $params; |
|
| 2626 | + } |
|
| 2627 | + $params[0][0]->texte = substr((string) $deb->texte, 1); |
|
| 2628 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2629 | + $last = $params[$k][$j]; |
|
| 2630 | + $n = strlen((string) $last->texte); |
|
| 2631 | + $params[$k][$j]->texte = substr((string) $last->texte, 0, $n - 1); |
|
| 2632 | + $newp = []; |
|
| 2633 | + foreach ($params as $v) { |
|
| 2634 | + if ($v[0]->type != 'texte') { |
|
| 2635 | + $newp[] = $v; |
|
| 2636 | + } else { |
|
| 2637 | + foreach (explode(',', (string) $v[0]->texte) as $x) { |
|
| 2638 | + $t = new Texte(); |
|
| 2639 | + $t->texte = $x; |
|
| 2640 | + $newp[] = [$t]; |
|
| 2641 | + } |
|
| 2642 | + } |
|
| 2643 | + } |
|
| 2644 | + |
|
| 2645 | + return $newp; |
|
| 2646 | 2646 | } |
| 2647 | 2647 | |
| 2648 | 2648 | /** |
@@ -2661,91 +2661,91 @@ discard block |
||
| 2661 | 2661 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2662 | 2662 | **/ |
| 2663 | 2663 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2664 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2665 | - return ''; |
|
| 2666 | - } |
|
| 2667 | - |
|
| 2668 | - $boucle = $boucles[$idb]; |
|
| 2669 | - $table = $boucle->show; |
|
| 2670 | - |
|
| 2671 | - // si c'est une colonne de la table, ne rien faire |
|
| 2672 | - if (isset($table['field'][$col])) { |
|
| 2673 | - return ''; |
|
| 2674 | - } |
|
| 2675 | - |
|
| 2676 | - // Le type de critère à prendre en compte |
|
| 2677 | - $col = $regs[1]; |
|
| 2678 | - |
|
| 2679 | - // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2680 | - if (isset($regs[3]) && ($suite = $regs[3])) { |
|
| 2681 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2682 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2683 | - $date_orig = isset($table['field']["date$suite"]) ? 'date' . $suite : substr($suite, 1); |
|
| 2684 | - |
|
| 2685 | - $pred = $date_orig; |
|
| 2686 | - } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2687 | - // Si aucune déclaration trouvée, on quitte |
|
| 2688 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2689 | - return ''; |
|
| 2690 | - } |
|
| 2691 | - // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2692 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2693 | - |
|
| 2694 | - // Si c'est pour du relatif |
|
| 2695 | - if (isset($regs[2]) && ($rel = $regs[2])) { |
|
| 2696 | - $pred = 'date'; |
|
| 2697 | - } |
|
| 2698 | - } |
|
| 2699 | - |
|
| 2700 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2701 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2702 | - ") . '\""; |
|
| 2703 | - |
|
| 2704 | - $col_vraie = $date_orig; |
|
| 2705 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2706 | - |
|
| 2707 | - switch ($col) { |
|
| 2708 | - case 'date': |
|
| 2709 | - $col = $date_orig; |
|
| 2710 | - break; |
|
| 2711 | - case 'jour': |
|
| 2712 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2713 | - break; |
|
| 2714 | - case 'mois': |
|
| 2715 | - $col = "MONTH($date_orig)"; |
|
| 2716 | - break; |
|
| 2717 | - case 'annee': |
|
| 2718 | - $col = "YEAR($date_orig)"; |
|
| 2719 | - break; |
|
| 2720 | - case 'heure': |
|
| 2721 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2722 | - break; |
|
| 2723 | - case 'age': |
|
| 2724 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2725 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2726 | - break; |
|
| 2727 | - case 'age_relatif': |
|
| 2728 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2729 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2730 | - break; |
|
| 2731 | - case 'jour_relatif': |
|
| 2732 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2733 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2734 | - break; |
|
| 2735 | - case 'mois_relatif': |
|
| 2736 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2737 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2738 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2739 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2740 | - break; |
|
| 2741 | - case 'annee_relatif': |
|
| 2742 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2743 | - $date_orig . ')'; |
|
| 2744 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2745 | - break; |
|
| 2746 | - } |
|
| 2747 | - |
|
| 2748 | - return [$col, $col_vraie]; |
|
| 2664 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2665 | + return ''; |
|
| 2666 | + } |
|
| 2667 | + |
|
| 2668 | + $boucle = $boucles[$idb]; |
|
| 2669 | + $table = $boucle->show; |
|
| 2670 | + |
|
| 2671 | + // si c'est une colonne de la table, ne rien faire |
|
| 2672 | + if (isset($table['field'][$col])) { |
|
| 2673 | + return ''; |
|
| 2674 | + } |
|
| 2675 | + |
|
| 2676 | + // Le type de critère à prendre en compte |
|
| 2677 | + $col = $regs[1]; |
|
| 2678 | + |
|
| 2679 | + // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2680 | + if (isset($regs[3]) && ($suite = $regs[3])) { |
|
| 2681 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2682 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2683 | + $date_orig = isset($table['field']["date$suite"]) ? 'date' . $suite : substr($suite, 1); |
|
| 2684 | + |
|
| 2685 | + $pred = $date_orig; |
|
| 2686 | + } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2687 | + // Si aucune déclaration trouvée, on quitte |
|
| 2688 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2689 | + return ''; |
|
| 2690 | + } |
|
| 2691 | + // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2692 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2693 | + |
|
| 2694 | + // Si c'est pour du relatif |
|
| 2695 | + if (isset($regs[2]) && ($rel = $regs[2])) { |
|
| 2696 | + $pred = 'date'; |
|
| 2697 | + } |
|
| 2698 | + } |
|
| 2699 | + |
|
| 2700 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2701 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2702 | + ") . '\""; |
|
| 2703 | + |
|
| 2704 | + $col_vraie = $date_orig; |
|
| 2705 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2706 | + |
|
| 2707 | + switch ($col) { |
|
| 2708 | + case 'date': |
|
| 2709 | + $col = $date_orig; |
|
| 2710 | + break; |
|
| 2711 | + case 'jour': |
|
| 2712 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2713 | + break; |
|
| 2714 | + case 'mois': |
|
| 2715 | + $col = "MONTH($date_orig)"; |
|
| 2716 | + break; |
|
| 2717 | + case 'annee': |
|
| 2718 | + $col = "YEAR($date_orig)"; |
|
| 2719 | + break; |
|
| 2720 | + case 'heure': |
|
| 2721 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2722 | + break; |
|
| 2723 | + case 'age': |
|
| 2724 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2725 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2726 | + break; |
|
| 2727 | + case 'age_relatif': |
|
| 2728 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2729 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2730 | + break; |
|
| 2731 | + case 'jour_relatif': |
|
| 2732 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2733 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2734 | + break; |
|
| 2735 | + case 'mois_relatif': |
|
| 2736 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2737 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2738 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2739 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2740 | + break; |
|
| 2741 | + case 'annee_relatif': |
|
| 2742 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2743 | + $date_orig . ')'; |
|
| 2744 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2745 | + break; |
|
| 2746 | + } |
|
| 2747 | + |
|
| 2748 | + return [$col, $col_vraie]; |
|
| 2749 | 2749 | } |
| 2750 | 2750 | |
| 2751 | 2751 | /** |
@@ -2764,16 +2764,16 @@ discard block |
||
| 2764 | 2764 | * de colonne SQL et une date. |
| 2765 | 2765 | **/ |
| 2766 | 2766 | function calculer_param_date($date_compare, $date_orig) { |
| 2767 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2768 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2769 | - $date_compare = '\'$x\''; |
|
| 2770 | - } else { |
|
| 2771 | - $init = $date_compare; |
|
| 2772 | - } |
|
| 2773 | - |
|
| 2774 | - return |
|
| 2775 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2776 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2767 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2768 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2769 | + $date_compare = '\'$x\''; |
|
| 2770 | + } else { |
|
| 2771 | + $init = $date_compare; |
|
| 2772 | + } |
|
| 2773 | + |
|
| 2774 | + return |
|
| 2775 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2776 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2777 | 2777 | } |
| 2778 | 2778 | |
| 2779 | 2779 | /** |
@@ -2791,17 +2791,17 @@ discard block |
||
| 2791 | 2791 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2792 | 2792 | */ |
| 2793 | 2793 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2794 | - $boucle = &$boucles[$idb]; |
|
| 2794 | + $boucle = &$boucles[$idb]; |
|
| 2795 | 2795 | |
| 2796 | - $args = []; |
|
| 2797 | - foreach ($crit->param as &$param) { |
|
| 2798 | - $args[] = calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 2799 | - } |
|
| 2796 | + $args = []; |
|
| 2797 | + foreach ($crit->param as &$param) { |
|
| 2798 | + $args[] = calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 2799 | + } |
|
| 2800 | 2800 | |
| 2801 | - $boucle->hash .= ' |
|
| 2801 | + $boucle->hash .= ' |
|
| 2802 | 2802 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2803 | 2803 | |
| 2804 | - $boucle->hash .= ' |
|
| 2804 | + $boucle->hash .= ' |
|
| 2805 | 2805 | $command[\'source\'] = array(' . implode(', ', $args) . ");\n"; |
| 2806 | 2806 | } |
| 2807 | 2807 | |
@@ -2819,8 +2819,8 @@ discard block |
||
| 2819 | 2819 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2820 | 2820 | */ |
| 2821 | 2821 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2822 | - $boucle = &$boucles[$idb]; |
|
| 2823 | - $boucle->hash .= ' |
|
| 2822 | + $boucle = &$boucles[$idb]; |
|
| 2823 | + $boucle->hash .= ' |
|
| 2824 | 2824 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2825 | 2825 | } |
| 2826 | 2826 | |
@@ -2836,12 +2836,12 @@ discard block |
||
| 2836 | 2836 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2837 | 2837 | */ |
| 2838 | 2838 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2839 | - $boucle = &$boucles[$idb]; |
|
| 2840 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2841 | - foreach ($crit->param as $param) { |
|
| 2842 | - $boucle->hash .= ' |
|
| 2839 | + $boucle = &$boucles[$idb]; |
|
| 2840 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2841 | + foreach ($crit->param as $param) { |
|
| 2842 | + $boucle->hash .= ' |
|
| 2843 | 2843 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2844 | - } |
|
| 2844 | + } |
|
| 2845 | 2845 | } |
| 2846 | 2846 | |
| 2847 | 2847 | /** |
@@ -2858,16 +2858,16 @@ discard block |
||
| 2858 | 2858 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2859 | 2859 | */ |
| 2860 | 2860 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2861 | - $boucle = &$boucles[$idb]; |
|
| 2862 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2863 | - foreach ($crit->param as $param) { |
|
| 2864 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2865 | - $param, |
|
| 2866 | - $idb, |
|
| 2867 | - $boucles, |
|
| 2868 | - $boucles[$idb]->id_parent |
|
| 2869 | - ) . ";\n"; |
|
| 2870 | - } |
|
| 2861 | + $boucle = &$boucles[$idb]; |
|
| 2862 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2863 | + foreach ($crit->param as $param) { |
|
| 2864 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2865 | + $param, |
|
| 2866 | + $idb, |
|
| 2867 | + $boucles, |
|
| 2868 | + $boucles[$idb]->id_parent |
|
| 2869 | + ) . ";\n"; |
|
| 2870 | + } |
|
| 2871 | 2871 | } |
| 2872 | 2872 | |
| 2873 | 2873 | /** |
@@ -2892,16 +2892,16 @@ discard block |
||
| 2892 | 2892 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2893 | 2893 | */ |
| 2894 | 2894 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2895 | - $boucle = &$boucles[$idb]; |
|
| 2896 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2897 | - foreach ($crit->param as $param) { |
|
| 2898 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2899 | - $param, |
|
| 2900 | - $idb, |
|
| 2901 | - $boucles, |
|
| 2902 | - $boucles[$idb]->id_parent |
|
| 2903 | - ) . ";\n"; |
|
| 2904 | - } |
|
| 2895 | + $boucle = &$boucles[$idb]; |
|
| 2896 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2897 | + foreach ($crit->param as $param) { |
|
| 2898 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2899 | + $param, |
|
| 2900 | + $idb, |
|
| 2901 | + $boucles, |
|
| 2902 | + $boucles[$idb]->id_parent |
|
| 2903 | + ) . ";\n"; |
|
| 2904 | + } |
|
| 2905 | 2905 | } |
| 2906 | 2906 | |
| 2907 | 2907 | /** |
@@ -2916,11 +2916,11 @@ discard block |
||
| 2916 | 2916 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2917 | 2917 | */ |
| 2918 | 2918 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2919 | - $boucle = &$boucles[$idb]; |
|
| 2920 | - foreach ($crit->param as $param) { |
|
| 2921 | - $boucle->hash .= ' |
|
| 2919 | + $boucle = &$boucles[$idb]; |
|
| 2920 | + foreach ($crit->param as $param) { |
|
| 2921 | + $boucle->hash .= ' |
|
| 2922 | 2922 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2923 | - } |
|
| 2923 | + } |
|
| 2924 | 2924 | } |
| 2925 | 2925 | |
| 2926 | 2926 | |
@@ -2952,20 +2952,20 @@ discard block |
||
| 2952 | 2952 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2953 | 2953 | */ |
| 2954 | 2954 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2955 | - $boucle = &$boucles[$idb]; |
|
| 2956 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2957 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2958 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2959 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2960 | - if ($crit->param) { |
|
| 2961 | - foreach ($crit->param as $param) { |
|
| 2962 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2963 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2964 | - } |
|
| 2965 | - // interdire {si 0} aussi ! |
|
| 2966 | - } else { |
|
| 2967 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2968 | - } |
|
| 2955 | + $boucle = &$boucles[$idb]; |
|
| 2956 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2957 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2958 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2959 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2960 | + if ($crit->param) { |
|
| 2961 | + foreach ($crit->param as $param) { |
|
| 2962 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2963 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2964 | + } |
|
| 2965 | + // interdire {si 0} aussi ! |
|
| 2966 | + } else { |
|
| 2967 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2968 | + } |
|
| 2969 | 2969 | } |
| 2970 | 2970 | |
| 2971 | 2971 | /** |
@@ -2983,27 +2983,27 @@ discard block |
||
| 2983 | 2983 | */ |
| 2984 | 2984 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2985 | 2985 | |
| 2986 | - $not = $crit->not; |
|
| 2987 | - $boucle = &$boucles[$idb]; |
|
| 2988 | - $primary = $boucle->primary; |
|
| 2986 | + $not = $crit->not; |
|
| 2987 | + $boucle = &$boucles[$idb]; |
|
| 2988 | + $primary = $boucle->primary; |
|
| 2989 | 2989 | |
| 2990 | - if (!$primary || strpos((string) $primary, ',')) { |
|
| 2991 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2990 | + if (!$primary || strpos((string) $primary, ',')) { |
|
| 2991 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2992 | 2992 | |
| 2993 | - return; |
|
| 2994 | - } |
|
| 2995 | - $table = $boucle->type_requete; |
|
| 2996 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2993 | + return; |
|
| 2994 | + } |
|
| 2995 | + $table = $boucle->type_requete; |
|
| 2996 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2997 | 2997 | |
| 2998 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2998 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2999 | 2999 | |
| 3000 | - $in = 'IN'; |
|
| 3001 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 3002 | - if ($not) { |
|
| 3003 | - $where = ["'NOT'", $where]; |
|
| 3004 | - } |
|
| 3000 | + $in = 'IN'; |
|
| 3001 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 3002 | + if ($not) { |
|
| 3003 | + $where = ["'NOT'", $where]; |
|
| 3004 | + } |
|
| 3005 | 3005 | |
| 3006 | - $boucle->where[] = $where; |
|
| 3006 | + $boucle->where[] = $where; |
|
| 3007 | 3007 | } |
| 3008 | 3008 | |
| 3009 | 3009 | /** |
@@ -3019,8 +3019,8 @@ discard block |
||
| 3019 | 3019 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 3020 | 3020 | */ |
| 3021 | 3021 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 3022 | - $not = $crit->not; |
|
| 3023 | - $crit->not = !$not; |
|
| 3024 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 3025 | - $crit->not = $not; |
|
| 3022 | + $not = $crit->not; |
|
| 3023 | + $crit->not = !$not; |
|
| 3024 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 3025 | + $crit->not = $not; |
|
| 3026 | 3026 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | return sql_getfetsel( |
| 36 | 36 | 'virtuel', |
| 37 | 37 | 'spip_articles', |
| 38 | - ['id_article=' . (int) $id_article, "statut='publie'"], |
|
| 38 | + ['id_article='.(int) $id_article, "statut='publie'"], |
|
| 39 | 39 | '', |
| 40 | 40 | '', |
| 41 | 41 | '', |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $cache_quete[$connect][$table][$id] = sql_fetsel( |
| 79 | 79 | $cache_quete[$connect][$table]['_select'], |
| 80 | 80 | $table, |
| 81 | - $cache_quete[$connect][$table]['_id'] . '=' . (int) $id, |
|
| 81 | + $cache_quete[$connect][$table]['_id'].'='.(int) $id, |
|
| 82 | 82 | '', |
| 83 | 83 | '', |
| 84 | 84 | '', |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | return |
| 170 | 170 | (isset($GLOBALS['meta']['date_prochain_postdate']) |
| 171 | 171 | && $GLOBALS['meta']['date_prochain_postdate'] > time()) |
| 172 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 172 | + ? "$champ_date<".sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 173 | 173 | : '1=1'; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | && ($id_table = reset($objet)) |
| 229 | 229 | && ($objet = objet_type($id_table)) |
| 230 | 230 | ) { |
| 231 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 231 | + $w = "$mstatut<>".sql_quote($v); |
|
| 232 | 232 | |
| 233 | 233 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 234 | 234 | // sinon l’auteur en session |
@@ -242,22 +242,22 @@ discard block |
||
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 245 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 245 | + if (!autoriser('previsualiser'.$v, $objet, '', $id_auteur)) { |
|
| 246 | 246 | // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
| 247 | 247 | if (!$id_auteur) { |
| 248 | 248 | $where[] = $w; |
| 249 | 249 | } else { |
| 250 | 250 | $primary = id_table_objet($objet); |
| 251 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 251 | + $where[] = "($w OR $id_table.$primary IN (".sql_get_select( |
|
| 252 | 252 | 'ssss.id_objet', |
| 253 | 253 | 'spip_auteurs_liens AS ssss', |
| 254 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . (int) $id_auteur, |
|
| 254 | + 'ssss.objet='.sql_quote($objet).' AND ssss.id_auteur='.(int) $id_auteur, |
|
| 255 | 255 | '', |
| 256 | 256 | '', |
| 257 | 257 | '', |
| 258 | 258 | '', |
| 259 | 259 | $serveur |
| 260 | - ) . '))'; |
|
| 260 | + ).'))'; |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | } // ignorer ce statut si on ne sait pas comment le filtrer |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @return array|bool|null |
| 296 | 296 | */ |
| 297 | 297 | function quete_fichier($id_document, $serveur = '') { |
| 298 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . (int) $id_document), '', [], '', '', $serveur); |
|
| 298 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document='.(int) $id_document), '', [], '', '', $serveur); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * @return array|bool |
| 307 | 307 | */ |
| 308 | 308 | function quete_document($id_document, $serveur = '') { |
| 309 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . (int) $id_document), '', [], '', '', $serveur); |
|
| 309 | + return sql_fetsel('*', 'spip_documents', ('id_document='.(int) $id_document), '', [], '', '', $serveur); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * @return array|bool|null |
| 318 | 318 | */ |
| 319 | 319 | function quete_meta($nom, $serveur) { |
| 320 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 320 | + return sql_getfetsel('valeur', 'spip_meta', 'nom='.sql_quote($nom), '', '', '', '', $serveur); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -368,9 +368,9 @@ discard block |
||
| 368 | 368 | // qui permet de distinguer le changement de logo |
| 369 | 369 | // et placer un expire sur le dossier IMG/ |
| 370 | 370 | $res = [ |
| 371 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 372 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 373 | - ($taille ? ' ' . $taille[3] : ('')) |
|
| 371 | + $on['chemin'].($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 372 | + ($off ? $off['chemin'].($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 373 | + ($taille ? ' '.$taille[3] : ('')) |
|
| 374 | 374 | ]; |
| 375 | 375 | $res['src'] = $res[0]; |
| 376 | 376 | $res['logo_on'] = $res[0]; |
@@ -480,7 +480,7 @@ discard block |
||
| 480 | 480 | if ( |
| 481 | 481 | strcmp((string) $logo, (string) _DIR_PLUGINS) == 0 |
| 482 | 482 | || strcmp((string) $logo, (string) _DIR_PLUGINS_DIST) == 0 |
| 483 | - || strcmp((string) $logo, _DIR_RACINE . 'prive/') == 0 |
|
| 483 | + || strcmp((string) $logo, _DIR_RACINE.'prive/') == 0 |
|
| 484 | 484 | ) { |
| 485 | 485 | return $logo; |
| 486 | 486 | } |
@@ -656,7 +656,7 @@ discard block |
||
| 656 | 656 | $exposer[$m][$type][$principal] = true; |
| 657 | 657 | if ($type == 'id_mot') { |
| 658 | 658 | if (!$parent) { |
| 659 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . (int) $principal, '', '', '', '', $connect); |
|
| 659 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot='.(int) $principal, '', '', '', '', $connect); |
|
| 660 | 660 | } |
| 661 | 661 | if ($parent) { |
| 662 | 662 | $exposer[$m]['id_groupe'][$parent] = 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 | |
@@ -32,16 +32,16 @@ discard block |
||
| 32 | 32 | * @return array|bool|null |
| 33 | 33 | */ |
| 34 | 34 | function quete_virtuel($id_article, $connect) { |
| 35 | - return sql_getfetsel( |
|
| 36 | - 'virtuel', |
|
| 37 | - 'spip_articles', |
|
| 38 | - ['id_article=' . (int) $id_article, "statut='publie'"], |
|
| 39 | - '', |
|
| 40 | - '', |
|
| 41 | - '', |
|
| 42 | - '', |
|
| 43 | - $connect |
|
| 44 | - ); |
|
| 35 | + return sql_getfetsel( |
|
| 36 | + 'virtuel', |
|
| 37 | + 'spip_articles', |
|
| 38 | + ['id_article=' . (int) $id_article, "statut='publie'"], |
|
| 39 | + '', |
|
| 40 | + '', |
|
| 41 | + '', |
|
| 42 | + '', |
|
| 43 | + $connect |
|
| 44 | + ); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -56,39 +56,39 @@ discard block |
||
| 56 | 56 | * @return array |
| 57 | 57 | */ |
| 58 | 58 | function quete_parent_lang($table, $id, string $connect = '') { |
| 59 | - static $cache_quete = []; |
|
| 60 | - |
|
| 61 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 62 | - if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 63 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 64 | - if ( |
|
| 65 | - !($desc = $trouver_table($table, $connect)) |
|
| 66 | - || !isset($desc['field']['id_rubrique']) |
|
| 67 | - ) { |
|
| 68 | - // pas de parent rubrique, on passe |
|
| 69 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 70 | - } else { |
|
| 71 | - $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 72 | - $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 73 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 74 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - if ($cache_quete[$connect][$table]['_select']) { |
|
| 78 | - $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 79 | - $cache_quete[$connect][$table]['_select'], |
|
| 80 | - $table, |
|
| 81 | - $cache_quete[$connect][$table]['_id'] . '=' . (int) $id, |
|
| 82 | - '', |
|
| 83 | - '', |
|
| 84 | - '', |
|
| 85 | - '', |
|
| 86 | - $connect |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return $cache_quete[$connect][$table][$id] ?? null; |
|
| 59 | + static $cache_quete = []; |
|
| 60 | + |
|
| 61 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 62 | + if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 63 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 64 | + if ( |
|
| 65 | + !($desc = $trouver_table($table, $connect)) |
|
| 66 | + || !isset($desc['field']['id_rubrique']) |
|
| 67 | + ) { |
|
| 68 | + // pas de parent rubrique, on passe |
|
| 69 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 70 | + } else { |
|
| 71 | + $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 72 | + $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 73 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 74 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + if ($cache_quete[$connect][$table]['_select']) { |
|
| 78 | + $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 79 | + $cache_quete[$connect][$table]['_select'], |
|
| 80 | + $table, |
|
| 81 | + $cache_quete[$connect][$table]['_id'] . '=' . (int) $id, |
|
| 82 | + '', |
|
| 83 | + '', |
|
| 84 | + '', |
|
| 85 | + '', |
|
| 86 | + $connect |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return $cache_quete[$connect][$table][$id] ?? null; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | |
@@ -105,11 +105,11 @@ discard block |
||
| 105 | 105 | * @return int |
| 106 | 106 | */ |
| 107 | 107 | function quete_parent($id_rubrique, string $connect = '') { |
| 108 | - if (!$id_rubrique = (int) $id_rubrique) { |
|
| 109 | - return 0; |
|
| 110 | - } |
|
| 111 | - $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 112 | - return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 108 | + if (!$id_rubrique = (int) $id_rubrique) { |
|
| 109 | + return 0; |
|
| 110 | + } |
|
| 111 | + $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 112 | + return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | * @return int |
| 126 | 126 | */ |
| 127 | 127 | function quete_rubrique($id_article, $serveur) { |
| 128 | - $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 128 | + $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 129 | 129 | |
| 130 | - return $id_parent['id_rubrique'] ?? 0; |
|
| 130 | + return $id_parent['id_rubrique'] ?? 0; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -140,13 +140,13 @@ discard block |
||
| 140 | 140 | * @return int |
| 141 | 141 | */ |
| 142 | 142 | function quete_profondeur($id, string $connect = '') { |
| 143 | - $n = 0; |
|
| 144 | - while ($id) { |
|
| 145 | - $n++; |
|
| 146 | - $id = quete_parent($id, $connect); |
|
| 147 | - } |
|
| 143 | + $n = 0; |
|
| 144 | + while ($id) { |
|
| 145 | + $n++; |
|
| 146 | + $id = quete_parent($id, $connect); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return $n; |
|
| 149 | + return $n; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | * Morceau de la requête SQL testant la date |
| 163 | 163 | */ |
| 164 | 164 | function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) { |
| 165 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && !$ignore_previsu) { |
|
| 166 | - return '1=1'; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - return |
|
| 170 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 171 | - && $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 172 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 173 | - : '1=1'; |
|
| 165 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && !$ignore_previsu) { |
|
| 166 | + return '1=1'; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + return |
|
| 170 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 171 | + && $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 172 | + ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 173 | + : '1=1'; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
@@ -190,101 +190,101 @@ discard block |
||
| 190 | 190 | * @return array|string |
| 191 | 191 | */ |
| 192 | 192 | function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) { |
| 193 | - static $cond = []; |
|
| 194 | - $key = func_get_args(); |
|
| 195 | - $key = implode('-', $key); |
|
| 196 | - if (isset($cond[$key])) { |
|
| 197 | - return $cond[$key]; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $liste_statuts = $publie; |
|
| 201 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && !$ignore_previsu) { |
|
| 202 | - $liste_statuts = $previsu; |
|
| 203 | - } |
|
| 204 | - $not = false; |
|
| 205 | - if (str_starts_with($liste_statuts, '!')) { |
|
| 206 | - $not = true; |
|
| 207 | - $liste_statuts = substr($liste_statuts, 1); |
|
| 208 | - } |
|
| 209 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 210 | - if (!strlen($liste_statuts)) { |
|
| 211 | - return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $liste_statuts = explode(',', $liste_statuts); |
|
| 215 | - $where = []; |
|
| 216 | - foreach ($liste_statuts as $k => $v) { |
|
| 217 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 218 | - // a ceux de l'auteur identifie |
|
| 219 | - if (str_contains($v, '/')) { |
|
| 220 | - $v = explode('/', $v); |
|
| 221 | - $filtre = end($v); |
|
| 222 | - $v = reset($v); |
|
| 223 | - $v = preg_replace(',\W,', '', $v); |
|
| 224 | - if ( |
|
| 225 | - $filtre == 'auteur' |
|
| 226 | - && str_contains($mstatut, '.') |
|
| 227 | - && ($objet = explode('.', $mstatut)) |
|
| 228 | - && ($id_table = reset($objet)) |
|
| 229 | - && ($objet = objet_type($id_table)) |
|
| 230 | - ) { |
|
| 231 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 232 | - |
|
| 233 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 234 | - // sinon l’auteur en session |
|
| 235 | - include_spip('inc/securiser_action'); |
|
| 236 | - if ($desc = decrire_token_previsu()) { |
|
| 237 | - $id_auteur = $desc['id_auteur']; |
|
| 238 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 239 | - $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 240 | - } else { |
|
| 241 | - $id_auteur = null; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 245 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 246 | - // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 247 | - if (!$id_auteur) { |
|
| 248 | - $where[] = $w; |
|
| 249 | - } else { |
|
| 250 | - $primary = id_table_objet($objet); |
|
| 251 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 252 | - 'ssss.id_objet', |
|
| 253 | - 'spip_auteurs_liens AS ssss', |
|
| 254 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . (int) $id_auteur, |
|
| 255 | - '', |
|
| 256 | - '', |
|
| 257 | - '', |
|
| 258 | - '', |
|
| 259 | - $serveur |
|
| 260 | - ) . '))'; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 264 | - else { |
|
| 265 | - $v = ''; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - // securite |
|
| 269 | - $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 270 | - } |
|
| 271 | - $liste_statuts = array_filter($liste_statuts); |
|
| 272 | - if (count($liste_statuts) == 1) { |
|
| 273 | - $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 274 | - } else { |
|
| 275 | - $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - while (count($where) > 1) { |
|
| 279 | - $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 280 | - $where[] = $and; |
|
| 281 | - } |
|
| 282 | - $cond[$key] = reset($where); |
|
| 283 | - if ($not) { |
|
| 284 | - $cond[$key] = ['NOT', $cond[$key]]; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - return $cond[$key]; |
|
| 193 | + static $cond = []; |
|
| 194 | + $key = func_get_args(); |
|
| 195 | + $key = implode('-', $key); |
|
| 196 | + if (isset($cond[$key])) { |
|
| 197 | + return $cond[$key]; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $liste_statuts = $publie; |
|
| 201 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && !$ignore_previsu) { |
|
| 202 | + $liste_statuts = $previsu; |
|
| 203 | + } |
|
| 204 | + $not = false; |
|
| 205 | + if (str_starts_with($liste_statuts, '!')) { |
|
| 206 | + $not = true; |
|
| 207 | + $liste_statuts = substr($liste_statuts, 1); |
|
| 208 | + } |
|
| 209 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 210 | + if (!strlen($liste_statuts)) { |
|
| 211 | + return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $liste_statuts = explode(',', $liste_statuts); |
|
| 215 | + $where = []; |
|
| 216 | + foreach ($liste_statuts as $k => $v) { |
|
| 217 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 218 | + // a ceux de l'auteur identifie |
|
| 219 | + if (str_contains($v, '/')) { |
|
| 220 | + $v = explode('/', $v); |
|
| 221 | + $filtre = end($v); |
|
| 222 | + $v = reset($v); |
|
| 223 | + $v = preg_replace(',\W,', '', $v); |
|
| 224 | + if ( |
|
| 225 | + $filtre == 'auteur' |
|
| 226 | + && str_contains($mstatut, '.') |
|
| 227 | + && ($objet = explode('.', $mstatut)) |
|
| 228 | + && ($id_table = reset($objet)) |
|
| 229 | + && ($objet = objet_type($id_table)) |
|
| 230 | + ) { |
|
| 231 | + $w = "$mstatut<>" . sql_quote($v); |
|
| 232 | + |
|
| 233 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 234 | + // sinon l’auteur en session |
|
| 235 | + include_spip('inc/securiser_action'); |
|
| 236 | + if ($desc = decrire_token_previsu()) { |
|
| 237 | + $id_auteur = $desc['id_auteur']; |
|
| 238 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 239 | + $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 240 | + } else { |
|
| 241 | + $id_auteur = null; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 245 | + if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 246 | + // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 247 | + if (!$id_auteur) { |
|
| 248 | + $where[] = $w; |
|
| 249 | + } else { |
|
| 250 | + $primary = id_table_objet($objet); |
|
| 251 | + $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 252 | + 'ssss.id_objet', |
|
| 253 | + 'spip_auteurs_liens AS ssss', |
|
| 254 | + 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . (int) $id_auteur, |
|
| 255 | + '', |
|
| 256 | + '', |
|
| 257 | + '', |
|
| 258 | + '', |
|
| 259 | + $serveur |
|
| 260 | + ) . '))'; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 264 | + else { |
|
| 265 | + $v = ''; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + // securite |
|
| 269 | + $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 270 | + } |
|
| 271 | + $liste_statuts = array_filter($liste_statuts); |
|
| 272 | + if (count($liste_statuts) == 1) { |
|
| 273 | + $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 274 | + } else { |
|
| 275 | + $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + while (count($where) > 1) { |
|
| 279 | + $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 280 | + $where[] = $and; |
|
| 281 | + } |
|
| 282 | + $cond[$key] = reset($where); |
|
| 283 | + if ($not) { |
|
| 284 | + $cond[$key] = ['NOT', $cond[$key]]; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + return $cond[$key]; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @return array|bool|null |
| 296 | 296 | */ |
| 297 | 297 | function quete_fichier($id_document, $serveur = '') { |
| 298 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . (int) $id_document), '', [], '', '', $serveur); |
|
| 298 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . (int) $id_document), '', [], '', '', $serveur); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * @return array|bool |
| 307 | 307 | */ |
| 308 | 308 | function quete_document($id_document, $serveur = '') { |
| 309 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . (int) $id_document), '', [], '', '', $serveur); |
|
| 309 | + return sql_fetsel('*', 'spip_documents', ('id_document=' . (int) $id_document), '', [], '', '', $serveur); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * @return array|bool|null |
| 318 | 318 | */ |
| 319 | 319 | function quete_meta($nom, $serveur) { |
| 320 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 320 | + return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -343,67 +343,67 @@ discard block |
||
| 343 | 343 | * Retourne soit un tableau, soit le chemin du fichier. |
| 344 | 344 | */ |
| 345 | 345 | function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag = false) { |
| 346 | - include_spip('base/objets'); |
|
| 347 | - $nom = strtolower($onoff); |
|
| 348 | - |
|
| 349 | - $cle_objet = id_table_objet($cle_objet); |
|
| 350 | - |
|
| 351 | - while (1) { |
|
| 352 | - $objet = objet_type($cle_objet); |
|
| 353 | - |
|
| 354 | - $on = quete_logo_objet($id, $objet, $nom); |
|
| 355 | - |
|
| 356 | - if ($on) { |
|
| 357 | - if ($flag) { |
|
| 358 | - return $on['fichier']; |
|
| 359 | - } else { |
|
| 360 | - $taille = @spip_getimagesize($on['chemin']); |
|
| 361 | - |
|
| 362 | - // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 363 | - // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 364 | - // alors on ne cherche pas du tout le survol ici |
|
| 365 | - $off = $onoff != 'ON' ? '' : quete_logo_objet($id, $objet, 'off'); |
|
| 366 | - |
|
| 367 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 368 | - // qui permet de distinguer le changement de logo |
|
| 369 | - // et placer un expire sur le dossier IMG/ |
|
| 370 | - $res = [ |
|
| 371 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 372 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 373 | - ($taille ? ' ' . $taille[3] : ('')) |
|
| 374 | - ]; |
|
| 375 | - $res['src'] = $res[0]; |
|
| 376 | - $res['logo_on'] = $res[0]; |
|
| 377 | - $res['logo_off'] = $res[1]; |
|
| 378 | - $res['width'] = ($taille ? $taille[0] : ''); |
|
| 379 | - $res['height'] = ($taille ? $taille[1] : ''); |
|
| 380 | - $res['fichier'] = $on['fichier']; |
|
| 381 | - $res['titre'] = ($on['titre'] ?? ''); |
|
| 382 | - $res['descriptif'] = ($on['descriptif'] ?? ''); |
|
| 383 | - $res['credits'] = ($on['credits'] ?? ''); |
|
| 384 | - $res['alt'] = ($on['alt'] ?? ''); |
|
| 385 | - $res['id'] = ($on['id_document'] ?? 0); |
|
| 386 | - |
|
| 387 | - return $res; |
|
| 388 | - } |
|
| 389 | - } else { |
|
| 390 | - if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 391 | - return ''; |
|
| 392 | - } else { |
|
| 393 | - if ($id_rubrique) { |
|
| 394 | - $cle_objet = 'id_rubrique'; |
|
| 395 | - $id = $id_rubrique; |
|
| 396 | - $id_rubrique = 0; |
|
| 397 | - } else { |
|
| 398 | - if ($id && $cle_objet == 'id_rubrique') { |
|
| 399 | - $id = quete_parent($id); |
|
| 400 | - } else { |
|
| 401 | - return ''; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - } |
|
| 346 | + include_spip('base/objets'); |
|
| 347 | + $nom = strtolower($onoff); |
|
| 348 | + |
|
| 349 | + $cle_objet = id_table_objet($cle_objet); |
|
| 350 | + |
|
| 351 | + while (1) { |
|
| 352 | + $objet = objet_type($cle_objet); |
|
| 353 | + |
|
| 354 | + $on = quete_logo_objet($id, $objet, $nom); |
|
| 355 | + |
|
| 356 | + if ($on) { |
|
| 357 | + if ($flag) { |
|
| 358 | + return $on['fichier']; |
|
| 359 | + } else { |
|
| 360 | + $taille = @spip_getimagesize($on['chemin']); |
|
| 361 | + |
|
| 362 | + // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 363 | + // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 364 | + // alors on ne cherche pas du tout le survol ici |
|
| 365 | + $off = $onoff != 'ON' ? '' : quete_logo_objet($id, $objet, 'off'); |
|
| 366 | + |
|
| 367 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 368 | + // qui permet de distinguer le changement de logo |
|
| 369 | + // et placer un expire sur le dossier IMG/ |
|
| 370 | + $res = [ |
|
| 371 | + $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 372 | + ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 373 | + ($taille ? ' ' . $taille[3] : ('')) |
|
| 374 | + ]; |
|
| 375 | + $res['src'] = $res[0]; |
|
| 376 | + $res['logo_on'] = $res[0]; |
|
| 377 | + $res['logo_off'] = $res[1]; |
|
| 378 | + $res['width'] = ($taille ? $taille[0] : ''); |
|
| 379 | + $res['height'] = ($taille ? $taille[1] : ''); |
|
| 380 | + $res['fichier'] = $on['fichier']; |
|
| 381 | + $res['titre'] = ($on['titre'] ?? ''); |
|
| 382 | + $res['descriptif'] = ($on['descriptif'] ?? ''); |
|
| 383 | + $res['credits'] = ($on['credits'] ?? ''); |
|
| 384 | + $res['alt'] = ($on['alt'] ?? ''); |
|
| 385 | + $res['id'] = ($on['id_document'] ?? 0); |
|
| 386 | + |
|
| 387 | + return $res; |
|
| 388 | + } |
|
| 389 | + } else { |
|
| 390 | + if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 391 | + return ''; |
|
| 392 | + } else { |
|
| 393 | + if ($id_rubrique) { |
|
| 394 | + $cle_objet = 'id_rubrique'; |
|
| 395 | + $id = $id_rubrique; |
|
| 396 | + $id_rubrique = 0; |
|
| 397 | + } else { |
|
| 398 | + if ($id && $cle_objet == 'id_rubrique') { |
|
| 399 | + $id = quete_parent($id); |
|
| 400 | + } else { |
|
| 401 | + return ''; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
@@ -418,43 +418,43 @@ discard block |
||
| 418 | 418 | * @return bool|array |
| 419 | 419 | **/ |
| 420 | 420 | function quete_logo_objet($id_objet, $objet, $mode) { |
| 421 | - static $chercher_logo; |
|
| 422 | - if (is_null($chercher_logo)) { |
|
| 423 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 424 | - } |
|
| 425 | - $cle_objet = id_table_objet($objet); |
|
| 426 | - |
|
| 427 | - // On cherche pas la méthode classique |
|
| 428 | - $infos_logo = $chercher_logo((int) $id_objet, $cle_objet, $mode); |
|
| 429 | - |
|
| 430 | - // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 431 | - if (!empty($infos_logo)) { |
|
| 432 | - $infos = [ |
|
| 433 | - 'chemin' => $infos_logo[0], |
|
| 434 | - 'timestamp' => $infos_logo[4], |
|
| 435 | - 'id_document' => ($infos_logo[5]['id_document'] ?? ''), |
|
| 436 | - ]; |
|
| 437 | - foreach (['fichier', 'titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 438 | - $infos[$champ] = ($infos_logo[5][$champ] ?? ''); |
|
| 439 | - } |
|
| 440 | - $infos_logo = $infos; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - // On passe cette recherche de logo dans un pipeline |
|
| 444 | - $infos_logo = pipeline( |
|
| 445 | - 'quete_logo_objet', |
|
| 446 | - [ |
|
| 447 | - 'args' => [ |
|
| 448 | - 'id_objet' => $id_objet, |
|
| 449 | - 'objet' => $objet, |
|
| 450 | - 'cle_objet' => $cle_objet, |
|
| 451 | - 'mode' => $mode, |
|
| 452 | - ], |
|
| 453 | - 'data' => $infos_logo, |
|
| 454 | - ] |
|
| 455 | - ); |
|
| 456 | - |
|
| 457 | - return $infos_logo; |
|
| 421 | + static $chercher_logo; |
|
| 422 | + if (is_null($chercher_logo)) { |
|
| 423 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 424 | + } |
|
| 425 | + $cle_objet = id_table_objet($objet); |
|
| 426 | + |
|
| 427 | + // On cherche pas la méthode classique |
|
| 428 | + $infos_logo = $chercher_logo((int) $id_objet, $cle_objet, $mode); |
|
| 429 | + |
|
| 430 | + // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 431 | + if (!empty($infos_logo)) { |
|
| 432 | + $infos = [ |
|
| 433 | + 'chemin' => $infos_logo[0], |
|
| 434 | + 'timestamp' => $infos_logo[4], |
|
| 435 | + 'id_document' => ($infos_logo[5]['id_document'] ?? ''), |
|
| 436 | + ]; |
|
| 437 | + foreach (['fichier', 'titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 438 | + $infos[$champ] = ($infos_logo[5][$champ] ?? ''); |
|
| 439 | + } |
|
| 440 | + $infos_logo = $infos; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + // On passe cette recherche de logo dans un pipeline |
|
| 444 | + $infos_logo = pipeline( |
|
| 445 | + 'quete_logo_objet', |
|
| 446 | + [ |
|
| 447 | + 'args' => [ |
|
| 448 | + 'id_objet' => $id_objet, |
|
| 449 | + 'objet' => $objet, |
|
| 450 | + 'cle_objet' => $cle_objet, |
|
| 451 | + 'mode' => $mode, |
|
| 452 | + ], |
|
| 453 | + 'data' => $infos_logo, |
|
| 454 | + ] |
|
| 455 | + ); |
|
| 456 | + |
|
| 457 | + return $infos_logo; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -467,25 +467,25 @@ discard block |
||
| 467 | 467 | * @return bool|string |
| 468 | 468 | */ |
| 469 | 469 | function quete_logo_file($row, $connect = null) { |
| 470 | - include_spip('inc/documents'); |
|
| 471 | - $logo = vignette_logo_document($row, $connect); |
|
| 472 | - if (!$logo) { |
|
| 473 | - $logo = image_du_document($row, $connect); |
|
| 474 | - } |
|
| 475 | - if (!$logo) { |
|
| 476 | - $f = charger_fonction('vignette', 'inc'); |
|
| 477 | - $logo = $f($row['extension'], false); |
|
| 478 | - } |
|
| 479 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 480 | - if ( |
|
| 481 | - strcmp((string) $logo, (string) _DIR_PLUGINS) == 0 |
|
| 482 | - || strcmp((string) $logo, (string) _DIR_PLUGINS_DIST) == 0 |
|
| 483 | - || strcmp((string) $logo, _DIR_RACINE . 'prive/') == 0 |
|
| 484 | - ) { |
|
| 485 | - return $logo; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - return get_spip_doc($logo); |
|
| 470 | + include_spip('inc/documents'); |
|
| 471 | + $logo = vignette_logo_document($row, $connect); |
|
| 472 | + if (!$logo) { |
|
| 473 | + $logo = image_du_document($row, $connect); |
|
| 474 | + } |
|
| 475 | + if (!$logo) { |
|
| 476 | + $f = charger_fonction('vignette', 'inc'); |
|
| 477 | + $logo = $f($row['extension'], false); |
|
| 478 | + } |
|
| 479 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 480 | + if ( |
|
| 481 | + strcmp((string) $logo, (string) _DIR_PLUGINS) == 0 |
|
| 482 | + || strcmp((string) $logo, (string) _DIR_PLUGINS_DIST) == 0 |
|
| 483 | + || strcmp((string) $logo, _DIR_RACINE . 'prive/') == 0 |
|
| 484 | + ) { |
|
| 485 | + return $logo; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + return get_spip_doc($logo); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | /** |
@@ -513,20 +513,20 @@ discard block |
||
| 513 | 513 | */ |
| 514 | 514 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, string $connect = '') { |
| 515 | 515 | |
| 516 | - include_spip('inc/documents'); |
|
| 517 | - $logo = ''; |
|
| 518 | - if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 519 | - $logo = vignette_logo_document($row, $connect); |
|
| 520 | - } |
|
| 521 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 522 | - if ($mode_logo == 'vignette' && !$logo) { |
|
| 523 | - return ''; |
|
| 524 | - } |
|
| 525 | - if ($mode_logo == 'icone') { |
|
| 526 | - $row['fichier'] = ''; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 516 | + include_spip('inc/documents'); |
|
| 517 | + $logo = ''; |
|
| 518 | + if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 519 | + $logo = vignette_logo_document($row, $connect); |
|
| 520 | + } |
|
| 521 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 522 | + if ($mode_logo == 'vignette' && !$logo) { |
|
| 523 | + return ''; |
|
| 524 | + } |
|
| 525 | + if ($mode_logo == 'icone') { |
|
| 526 | + $row['fichier'] = ''; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | /** |
@@ -538,26 +538,26 @@ discard block |
||
| 538 | 538 | */ |
| 539 | 539 | function quete_html_logo($logo, $align, $lien) { |
| 540 | 540 | |
| 541 | - if (!is_array($logo)) { |
|
| 542 | - return ''; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - $contexte = []; |
|
| 546 | - foreach ($logo as $k => $v) { |
|
| 547 | - if (!is_numeric($k)) { |
|
| 548 | - $contexte[$k] = $v; |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - foreach (['titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 553 | - if (!empty($contexte[$champ])) { |
|
| 554 | - $contexte[$champ] = appliquer_traitement_champ($contexte[$champ], $champ, 'document'); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - $contexte['align'] = $align; |
|
| 559 | - $contexte['lien'] = $lien; |
|
| 560 | - return recuperer_fond('modeles/logo', $contexte); |
|
| 541 | + if (!is_array($logo)) { |
|
| 542 | + return ''; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + $contexte = []; |
|
| 546 | + foreach ($logo as $k => $v) { |
|
| 547 | + if (!is_numeric($k)) { |
|
| 548 | + $contexte[$k] = $v; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + foreach (['titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 553 | + if (!empty($contexte[$champ])) { |
|
| 554 | + $contexte[$champ] = appliquer_traitement_champ($contexte[$champ], $champ, 'document'); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + $contexte['align'] = $align; |
|
| 559 | + $contexte['lien'] = $lien; |
|
| 560 | + return recuperer_fond('modeles/logo', $contexte); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
@@ -571,14 +571,14 @@ discard block |
||
| 571 | 571 | * @return string|false |
| 572 | 572 | */ |
| 573 | 573 | function document_spip_externe($fichier, $connect) { |
| 574 | - if ($connect) { |
|
| 575 | - $site = quete_meta('adresse_site', $connect); |
|
| 576 | - if ($site) { |
|
| 577 | - $dir = quete_meta('dir_img', $connect); |
|
| 578 | - return "$site/$dir$fichier"; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - return false; |
|
| 574 | + if ($connect) { |
|
| 575 | + $site = quete_meta('adresse_site', $connect); |
|
| 576 | + if ($site) { |
|
| 577 | + $dir = quete_meta('dir_img', $connect); |
|
| 578 | + return "$site/$dir$fichier"; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + return false; |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -591,23 +591,23 @@ discard block |
||
| 591 | 591 | */ |
| 592 | 592 | function vignette_logo_document($row, string $connect = '') { |
| 593 | 593 | |
| 594 | - if (!$row || empty($row['id_vignette'])) { |
|
| 595 | - return ''; |
|
| 596 | - } |
|
| 597 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 598 | - if ($url = document_spip_externe($fichier, $connect)) { |
|
| 599 | - return $url; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - $f = get_spip_doc($fichier); |
|
| 603 | - if ($f && @file_exists($f)) { |
|
| 604 | - return $f; |
|
| 605 | - } |
|
| 606 | - if ($row['mode'] !== 'vignette') { |
|
| 607 | - return ''; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect); |
|
| 594 | + if (!$row || empty($row['id_vignette'])) { |
|
| 595 | + return ''; |
|
| 596 | + } |
|
| 597 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 598 | + if ($url = document_spip_externe($fichier, $connect)) { |
|
| 599 | + return $url; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + $f = get_spip_doc($fichier); |
|
| 603 | + if ($f && @file_exists($f)) { |
|
| 604 | + return $f; |
|
| 605 | + } |
|
| 606 | + if ($row['mode'] !== 'vignette') { |
|
| 607 | + return ''; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect); |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -622,66 +622,66 @@ discard block |
||
| 622 | 622 | * @return bool|string |
| 623 | 623 | */ |
| 624 | 624 | function calcul_exposer($id, $prim, $reference, $parent, $type, string $connect = '') { |
| 625 | - static $exposer = []; |
|
| 626 | - |
|
| 627 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 628 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 629 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 630 | - // en static. |
|
| 631 | - if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 632 | - $principal = $reference[$type] ?? $reference["@$type"] ?? ''; |
|
| 633 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 634 | - // il n'est donc pas utile |
|
| 635 | - $parent = 0; |
|
| 636 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 637 | - $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 638 | - if (isset($enfants[$type])) { |
|
| 639 | - foreach ($enfants[$type] as $t) { |
|
| 640 | - if ( |
|
| 641 | - isset($reference[$t]) |
|
| 642 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 643 | - || isset($reference["@$t"]) |
|
| 644 | - ) { |
|
| 645 | - $type = $t; |
|
| 646 | - $principal = $reference[$type] ?? $reference["@$type"]; |
|
| 647 | - continue; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - $exposer[$m][$type] = []; |
|
| 653 | - if ($principal) { |
|
| 654 | - $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 655 | - foreach ($principaux as $principal) { |
|
| 656 | - $exposer[$m][$type][$principal] = true; |
|
| 657 | - if ($type == 'id_mot') { |
|
| 658 | - if (!$parent) { |
|
| 659 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . (int) $principal, '', '', '', '', $connect); |
|
| 660 | - } |
|
| 661 | - if ($parent) { |
|
| 662 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - if ($type != 'id_groupe') { |
|
| 666 | - if (!$parent) { |
|
| 667 | - if ($type == 'id_rubrique') { |
|
| 668 | - $parent = $principal; |
|
| 669 | - } |
|
| 670 | - if ($type == 'id_article') { |
|
| 671 | - $parent = quete_rubrique($principal, $connect); |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - do { |
|
| 675 | - $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 676 | - } while ($parent = quete_parent($parent, $connect)); |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - } |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - // And the winner is... |
|
| 684 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 625 | + static $exposer = []; |
|
| 626 | + |
|
| 627 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 628 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 629 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 630 | + // en static. |
|
| 631 | + if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 632 | + $principal = $reference[$type] ?? $reference["@$type"] ?? ''; |
|
| 633 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 634 | + // il n'est donc pas utile |
|
| 635 | + $parent = 0; |
|
| 636 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 637 | + $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 638 | + if (isset($enfants[$type])) { |
|
| 639 | + foreach ($enfants[$type] as $t) { |
|
| 640 | + if ( |
|
| 641 | + isset($reference[$t]) |
|
| 642 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 643 | + || isset($reference["@$t"]) |
|
| 644 | + ) { |
|
| 645 | + $type = $t; |
|
| 646 | + $principal = $reference[$type] ?? $reference["@$type"]; |
|
| 647 | + continue; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + $exposer[$m][$type] = []; |
|
| 653 | + if ($principal) { |
|
| 654 | + $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 655 | + foreach ($principaux as $principal) { |
|
| 656 | + $exposer[$m][$type][$principal] = true; |
|
| 657 | + if ($type == 'id_mot') { |
|
| 658 | + if (!$parent) { |
|
| 659 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . (int) $principal, '', '', '', '', $connect); |
|
| 660 | + } |
|
| 661 | + if ($parent) { |
|
| 662 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + if ($type != 'id_groupe') { |
|
| 666 | + if (!$parent) { |
|
| 667 | + if ($type == 'id_rubrique') { |
|
| 668 | + $parent = $principal; |
|
| 669 | + } |
|
| 670 | + if ($type == 'id_article') { |
|
| 671 | + $parent = quete_rubrique($principal, $connect); |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + do { |
|
| 675 | + $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 676 | + } while ($parent = quete_parent($parent, $connect)); |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + } |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + // And the winner is... |
|
| 684 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -696,23 +696,23 @@ discard block |
||
| 696 | 696 | * @return int |
| 697 | 697 | */ |
| 698 | 698 | function quete_debut_pagination($primary, $valeur, $pas, $iter) { |
| 699 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 700 | - // ou composee, mais verifions |
|
| 701 | - if (!$primary || preg_match('/[,\s]/', $primary)) { |
|
| 702 | - return 0; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - $pos = 0; |
|
| 706 | - while (($row = $iter->fetch()) && $row[$primary] != $valeur) { |
|
| 707 | - $pos++; |
|
| 708 | - } |
|
| 709 | - // si on a pas trouve |
|
| 710 | - if (!$row || $row[$primary] != $valeur) { |
|
| 711 | - return 0; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - // sinon, calculer le bon numero de page |
|
| 715 | - return floor($pos / $pas) * $pas; |
|
| 699 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 700 | + // ou composee, mais verifions |
|
| 701 | + if (!$primary || preg_match('/[,\s]/', $primary)) { |
|
| 702 | + return 0; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + $pos = 0; |
|
| 706 | + while (($row = $iter->fetch()) && $row[$primary] != $valeur) { |
|
| 707 | + $pos++; |
|
| 708 | + } |
|
| 709 | + // si on a pas trouve |
|
| 710 | + if (!$row || $row[$primary] != $valeur) { |
|
| 711 | + return 0; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + // sinon, calculer le bon numero de page |
|
| 715 | + return floor($pos / $pas) * $pas; |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | /** |
@@ -722,8 +722,8 @@ discard block |
||
| 722 | 722 | * @return boolean |
| 723 | 723 | */ |
| 724 | 724 | function is_whereable(mixed $value): bool { |
| 725 | - if (is_array($value) && count($value)) { |
|
| 726 | - return true; |
|
| 727 | - } |
|
| 728 | - return is_scalar($value) && strlen($value); |
|
| 725 | + if (is_array($value) && count($value)) { |
|
| 726 | + return true; |
|
| 727 | + } |
|
| 728 | + return is_scalar($value) && strlen($value); |
|
| 729 | 729 | } |
@@ -10,35 +10,35 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // rien sauf les "~" et "-," |
| 17 | 17 | |
| 18 | 18 | function typographie_en_dist($letexte) { |
| 19 | 19 | |
| 20 | - // zouli apostrophe |
|
| 21 | - $letexte = str_replace("'", '’', (string) $letexte); |
|
| 22 | - |
|
| 23 | - $cherche1 = [ |
|
| 24 | - '/ --?,/S' |
|
| 25 | - ]; |
|
| 26 | - $remplace1 = [ |
|
| 27 | - '~\0' |
|
| 28 | - ]; |
|
| 29 | - $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 30 | - |
|
| 31 | - $letexte = str_replace(' ', '~', $letexte); |
|
| 32 | - $letexte = preg_replace('/ *~+ */', '~', $letexte); |
|
| 33 | - |
|
| 34 | - $cherche2 = [ |
|
| 35 | - '/([^-\n]|^)--([^-]|$)/', |
|
| 36 | - '/~/' |
|
| 37 | - ]; |
|
| 38 | - $remplace2 = [ |
|
| 39 | - '\1—\2', |
|
| 40 | - ' ' |
|
| 41 | - ]; |
|
| 42 | - |
|
| 43 | - return preg_replace($cherche2, $remplace2, $letexte); |
|
| 20 | + // zouli apostrophe |
|
| 21 | + $letexte = str_replace("'", '’', (string) $letexte); |
|
| 22 | + |
|
| 23 | + $cherche1 = [ |
|
| 24 | + '/ --?,/S' |
|
| 25 | + ]; |
|
| 26 | + $remplace1 = [ |
|
| 27 | + '~\0' |
|
| 28 | + ]; |
|
| 29 | + $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 30 | + |
|
| 31 | + $letexte = str_replace(' ', '~', $letexte); |
|
| 32 | + $letexte = preg_replace('/ *~+ */', '~', $letexte); |
|
| 33 | + |
|
| 34 | + $cherche2 = [ |
|
| 35 | + '/([^-\n]|^)--([^-]|$)/', |
|
| 36 | + '/~/' |
|
| 37 | + ]; |
|
| 38 | + $remplace2 = [ |
|
| 39 | + '\1—\2', |
|
| 40 | + ' ' |
|
| 41 | + ]; |
|
| 42 | + |
|
| 43 | + return preg_replace($cherche2, $remplace2, $letexte); |
|
| 44 | 44 | } |
@@ -107,8 +107,8 @@ |
||
| 107 | 107 | function message_crash_tables() { |
| 108 | 108 | if ($crash = verifier_crash_tables()) { |
| 109 | 109 | return |
| 110 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 111 | - . ' <tt>' . implode(', ', $crash) . '</tt><br />' |
|
| 110 | + '<strong>'._T('texte_recuperer_base').'</strong><br />' |
|
| 111 | + . ' <tt>'.implode(', ', $crash).'</tt><br />' |
|
| 112 | 112 | . generer_form_ecrire( |
| 113 | 113 | 'base_repair', |
| 114 | 114 | _T('texte_crash_base'), |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -34,19 +34,19 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function genie_maintenance_dist($t) { |
| 36 | 36 | |
| 37 | - // (re)mettre .htaccess avec deny from all |
|
| 38 | - // dans les deux repertoires dits inaccessibles par http |
|
| 39 | - include_spip('inc/acces'); |
|
| 40 | - verifier_htaccess(_DIR_ETC); |
|
| 41 | - verifier_htaccess(_DIR_TMP); |
|
| 42 | - verifier_htaccess(_DIR_VENDOR); |
|
| 37 | + // (re)mettre .htaccess avec deny from all |
|
| 38 | + // dans les deux repertoires dits inaccessibles par http |
|
| 39 | + include_spip('inc/acces'); |
|
| 40 | + verifier_htaccess(_DIR_ETC); |
|
| 41 | + verifier_htaccess(_DIR_TMP); |
|
| 42 | + verifier_htaccess(_DIR_VENDOR); |
|
| 43 | 43 | |
| 44 | - // Verifier qu'aucune table n'est crashee |
|
| 45 | - if (!_request('reinstall')) { |
|
| 46 | - verifier_crash_tables(); |
|
| 47 | - } |
|
| 44 | + // Verifier qu'aucune table n'est crashee |
|
| 45 | + if (!_request('reinstall')) { |
|
| 46 | + verifier_crash_tables(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return 1; |
|
| 49 | + return 1; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | |
@@ -63,34 +63,34 @@ discard block |
||
| 63 | 63 | * des tables qui ont crashé. |
| 64 | 64 | */ |
| 65 | 65 | function verifier_crash_tables() { |
| 66 | - if (spip_connect()) { |
|
| 67 | - include_spip('base/serial'); |
|
| 68 | - include_spip('base/auxiliaires'); |
|
| 69 | - $crash = []; |
|
| 70 | - foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 71 | - foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 72 | - if ( |
|
| 73 | - !sql_select('*', $table, '', '', '', 1) |
|
| 74 | - && !defined('spip_interdire_cache') |
|
| 75 | - ) { # cas "LOST CONNECTION" |
|
| 76 | - $crash[] = $table; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - #$crash[] = 'test'; |
|
| 81 | - if ($crash) { |
|
| 82 | - ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 83 | - $logger = spip_logger('err'); |
|
| 84 | - $logger->info('crash des tables'); |
|
| 85 | - $logger->info($crash); |
|
| 86 | - } else { |
|
| 87 | - effacer_meta('message_crash_tables'); |
|
| 88 | - } |
|
| 66 | + if (spip_connect()) { |
|
| 67 | + include_spip('base/serial'); |
|
| 68 | + include_spip('base/auxiliaires'); |
|
| 69 | + $crash = []; |
|
| 70 | + foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 71 | + foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 72 | + if ( |
|
| 73 | + !sql_select('*', $table, '', '', '', 1) |
|
| 74 | + && !defined('spip_interdire_cache') |
|
| 75 | + ) { # cas "LOST CONNECTION" |
|
| 76 | + $crash[] = $table; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + #$crash[] = 'test'; |
|
| 81 | + if ($crash) { |
|
| 82 | + ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 83 | + $logger = spip_logger('err'); |
|
| 84 | + $logger->info('crash des tables'); |
|
| 85 | + $logger->info($crash); |
|
| 86 | + } else { |
|
| 87 | + effacer_meta('message_crash_tables'); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - return $crash; |
|
| 91 | - } |
|
| 90 | + return $crash; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return false; |
|
| 93 | + return false; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | 108 | function message_crash_tables() { |
| 109 | - if ($crash = verifier_crash_tables()) { |
|
| 110 | - return |
|
| 111 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 112 | - . ' <tt>' . implode(', ', $crash) . '</tt><br />' |
|
| 113 | - . generer_form_ecrire( |
|
| 114 | - 'base_repair', |
|
| 115 | - _T('texte_crash_base'), |
|
| 116 | - '', |
|
| 117 | - _T('bouton_tenter_recuperation') |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - return ''; |
|
| 109 | + if ($crash = verifier_crash_tables()) { |
|
| 110 | + return |
|
| 111 | + '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 112 | + . ' <tt>' . implode(', ', $crash) . '</tt><br />' |
|
| 113 | + . generer_form_ecrire( |
|
| 114 | + 'base_repair', |
|
| 115 | + _T('texte_crash_base'), |
|
| 116 | + '', |
|
| 117 | + _T('bouton_tenter_recuperation') |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + return ''; |
|
| 121 | 121 | } |