diff --git a/ecrire/exec/memoriser.php b/ecrire/exec/memoriser.php index 0e75618dfc05ca8569cbf348ea1d0a23e8068192..5def63e1e51c24fed615638edf73321979e03d98 100644 --- a/ecrire/exec/memoriser.php +++ b/ecrire/exec/memoriser.php @@ -20,19 +20,21 @@ function exec_memoriser_dist() $hash = _request('hash'); $order = _request('order'); $by = _request('by'); + $trad = _request('trad'); lire_fichier(_DIR_SESSIONS.'ajax_fonctions.txt', $ajax_fonctions); $ajax_fonctions = @unserialize($ajax_fonctions); if ($res = $ajax_fonctions[$hash]) { - list(,$t,$r,$p,$f) = $res; + include_spip('inc/afficher_objets'); + list(,$t,$r,$f) = $res; if (preg_match('/^[a-z0-9+.,]+$/', $by) - AND preg_match('/^\w*$/', $order)) + AND preg_match('/^\w*$/', $order)) { $r['ORDER BY'] = str_replace(',', " $order, ", $by) . " $order"; + sauver_requete($t, $r, $f); + } $cpt = sql_countsel($r['FROM'], $r['WHERE'], $r['GROUP BY']); include_spip('inc/presentation'); - include_spip('inc/afficher_objets'); - $res = afficher_articles_trad($t, $r, $f, $p, $hash, $cpt, _request('trad')); - + $res = afficher_articles_trad($t, $r, $f, $hash, $cpt, $trad); } else spip_log("memoriser $q vide"); ajax_retour($res); } diff --git a/ecrire/inc/afficher_objets.php b/ecrire/inc/afficher_objets.php index 073b365d645764e45c8884aa23a96ca6b36da265..a1a649966dd58af6608aac5c2a84b75bc458d20d 100644 --- a/ecrire/inc/afficher_objets.php +++ b/ecrire/inc/afficher_objets.php @@ -370,20 +370,29 @@ function inc_afficher_articles_dist($titre, $requete, $formater='') { // memorisation des arguments pour gerer l'affichage par tranche // et/ou par langues. - $hash = substr(md5(serialize($requete) . $GLOBALS['meta']['gerer_trad'] . $titre), 0, 31); - $tmp_var = 't' . substr($hash, 0, 7); - // - // Stocke la fonction ajax dans le fichier temp pour exec=memoriser - // + $hash = sauver_requete($titre, $requete, $formater); + + if (isset($requete['LIMIT'])) $cpt = min($requete['LIMIT'], $cpt); + return afficher_articles_trad($titre, $requete, $formater, $hash, $cpt); +} + +// +// Stocke la fonction ajax dans le fichier temp pour exec=memoriser +// + +function sauver_requete($titre, $requete, $formater) +{ + $r = $requete; + unset($r['ORDER BY']); + $hash = substr(md5(serialize($r) . $GLOBALS['meta']['gerer_trad'] . $titre), 0, 31); // on lit l'existant lire_fichier(_DIR_SESSIONS.'ajax_fonctions.txt', $ajax_fonctions); $ajax_fonctions = @unserialize($ajax_fonctions); // on ajoute notre fonction - - $v = array(time(), $titre, $requete, $tmp_var, $formater); + $v = array(time(), $titre, $requete, $formater); $ajax_fonctions[$hash] = $v; // supprime les fonctions trop vieilles @@ -395,15 +404,16 @@ function inc_afficher_articles_dist($titre, $requete, $formater='') { ecrire_fichier(_DIR_SESSIONS.'ajax_fonctions.txt', serialize($ajax_fonctions)); - if (isset($requete['LIMIT'])) $cpt = min($requete['LIMIT'], $cpt); - return afficher_articles_trad($titre, $requete, $formater, $tmp_var, $hash, $cpt); -} + return $hash; +} // http://doc.spip.org/@afficher_articles_trad -function afficher_articles_trad($titre_table, $requete, $formater, $tmp_var, $hash, $cpt, $trad=0) { +function afficher_articles_trad($titre_table, $requete, $formater, $hash, $cpt, $trad=0) { global $spip_lang_right; + $tmp_var = 't' . substr($hash, 0, 7); + if ($trad) { $formater = 'afficher_articles_trad_boucle'; $icone = "langues-off-12.gif"; @@ -417,8 +427,12 @@ function afficher_articles_trad($titre_table, $requete, $formater, $tmp_var, $ha $texte = '<b>' . $titre_table . '</b>'; + // Le parametre o sert a empecher le navigateur de reutiliser + // un cache de tranche issu d'un autre tri + + $arg = "hash=$hash&o=" . $requete['ORDER BY']; if (($GLOBALS['meta']['gerer_trad'] == "oui")) { - $url = generer_url_ecrire('memoriser',"hash=$hash&trad=" . (1-$trad)); + $url = generer_url_ecrire('memoriser',"$arg&trad=" . (1-$trad)); $texte .= "\n<span style='float: $spip_lang_right;'><a href=\"#\"" . generer_onclic_ajax($url, $tmp_var, 0) @@ -434,7 +448,7 @@ function afficher_articles_trad($titre_table, $requete, $formater, $tmp_var, $ha $presenter_liste = charger_fonction('presenter_liste', 'inc'); $styles = array(array('', 11), array('arial2','', $url_t), array('arial1', 80), array('arial1', 100, $url_d), array('arial1', 50)); $tableau = array(); - $url = generer_url_ecrire('memoriser', "hash=$hash&trad=$trad"); + $url = generer_url_ecrire('memoriser', "$arg&trad=$trad"); $res = $presenter_liste($requete, $formater, $tableau, array(), false, $styles, $tmp_var, $texte, "article-24.gif", $url, $cpt); return ajax_action_greffe($tmp_var, '', $res);