From 2cbcdefeb3c82b31b96e683ff87d61c1b322fbfd Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Thu, 8 May 2008 14:08:05 +0000 Subject: [PATCH] =?UTF-8?q?Suite=20de=20[11593]:=20la=20fonction=20{{{xhtm?= =?UTF-8?q?l=5Ftable=5Fid=5Ftype}}}=20admet=20=C3=A0=20pr=C3=A9sent=20en?= =?UTF-8?q?=20argument=20le=20r=C3=A9sultat=20d'un=20{{{sql=5Fselect}}}=20?= =?UTF-8?q?et=20effectue=20le=20{{{while-fetch}}},=20plus=20besoin=20de=20?= =?UTF-8?q?tableau=20auxiliaire.=20Elle=20prend=20aussi=20en=20argument=20?= =?UTF-8?q?une=20autre=20valeur=20et=20une=20fonction=20=C3=A0=20appliquer?= =?UTF-8?q?=20sur=20le=20r=C3=A9sultat=20du=20fetch=20et=20cette=20valeur.?= =?UTF-8?q?=20Cette=20fonction=20et=20cette=20valeur=20forment=20le=20sque?= =?UTF-8?q?lette=20sous-jacent.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecrire/inc/afficher_objets.php | 44 +++++++++++++++------------- ecrire/inc/editer_auteurs.php | 13 +++----- ecrire/inc/editer_mots.php | 17 +++++------ ecrire/inc/formater_article.php | 2 +- ecrire/inc/grouper_mots.php | 11 +++---- ecrire/inc/message_select.php | 16 ++++------ ecrire/inc/presentation.php | 25 +++++++++++----- ecrire/inc/referencer_traduction.php | 16 +++++----- 8 files changed, 70 insertions(+), 74 deletions(-) diff --git a/ecrire/inc/afficher_objets.php b/ecrire/inc/afficher_objets.php index d0c3250773..af2ff5bc18 100644 --- a/ecrire/inc/afficher_objets.php +++ b/ecrire/inc/afficher_objets.php @@ -246,28 +246,31 @@ function inc_afficher_objets_dist($type, $titre,$requete,$formater='', $force=fa $result = sql_select((isset($requete["SELECT"]) ? $requete["SELECT"] : "*"), $requete['FROM'], $requete['WHERE'], $requete['GROUP BY'], $requete['ORDER BY'], ($deb_aff > 0 ? "$deb_aff, $nb_aff" : ($requete['LIMIT'] ? $requete['LIMIT'] : "99999"))); - $voir_logo = ($spip_display != 1 AND $spip_display != 4 AND isset($GLOBALS['meta']['image_process'])) ? ($GLOBALS['meta']['image_process'] != "non") : false; - $table = $tous_id = array(); // $tous_id obsolete. - while ($row = sql_fetch($result)) { - if ($a = $skel($row, $tous_id, $voir_logo, $arg)) - $table[] = $a; - } - sql_free($result); + $tableau = array(); // ne sert pas ici + return xhtml_table_id_type($result, $skel, $tableau, $arg, $force, $largeurs, $styles, $tranches, $titre, $icone); +} + +function charger_fonction_logo_if() +{ + global $spip_display; - return !($table OR $force) ? '' : - xhtml_table_id_type($table, $largeurs, $styles, $tranches, $titre, $icone); + if ($spip_display == 1 OR $spip_display == 4 OR !isset($GLOBALS['meta']['image_process'])) + return false; + if ($GLOBALS['meta']['image_process'] == "non") return false; + return charger_fonction('chercher_logo', 'inc'); } // http://doc.spip.org/@afficher_objet_boucle -function afficher_objet_boucle($row, &$tous_id, $voir_logo, $own) +function afficher_objet_boucle($row, $own) { global $connect_statut, $spip_lang_right; + static $chercher_logo = true; + list($type,$primary,$afficher_langue, $affrub, $langue_defaut) = $own; $vals = array(); $id_objet = $row[$primary]; if (autoriser('voir',$type,$id_objet)){ - $tous_id[] = $id_objet; $date_heure = isset($row['date'])?$row['date']:(isset($row['date_heure'])?$row['date_heure']:""); @@ -283,16 +286,17 @@ function afficher_objet_boucle($row, &$tous_id, $voir_logo, $own) list($titre,$suite) = afficher_titre_objet($type,$row); $s = "\n<div>"; - if ($voir_logo) { - $chercher_logo = charger_fonction('chercher_logo', 'inc'); - if ($logo = $chercher_logo($id_objet, $primary, 'on')) { + if ($chercher_logo) { + if ($chercher_logo !== true + OR $chercher_logo = charger_fonction_logo_if()) + if ($logo = $chercher_logo($id_objet, $primary, 'on')) { list($fid, $dir, $nom, $format) = $logo; include_spip('inc/filtres_images'); $logo = image_reduire("<img src='$fid' alt='' />", 26, 20); if ($logo) $s .= "\n<span style='float: $spip_lang_right; margin-top: -2px; margin-bottom: -2px;'>$logo</span>"; - } + } } if (strlen($titre)){ $s .= "<a href='" @@ -441,20 +445,18 @@ function afficher_articles_trad($titre_table, $requete, $formater, $tmp_var, $ha $largeurs = array(11, '', 80, 100, 50); $styles = array('', 'arial2', 'arial1', 'arial1', 'arial1'); - $table = array(); - while ($r = sql_fetch($q)) if ($a = $formater($r)) $table[] = $a; - sql_free($q); + $tableau = array(); $tranches = ($cpt <= $nb_aff) ? '' : afficher_tranches_requete($cpt, $tmp_var, generer_url_ecrire('memoriser', "hash=$hash&trad=$trad"), $nb_aff); - $res = xhtml_table_id_type($table, $largeurs, $styles, $tranches, $texte, "article-24.gif"); + $res = xhtml_table_id_type($q, $formater, $tableau, array(), false, $largeurs, $styles, $tranches, $texte, "article-24.gif"); return ajax_action_greffe($tmp_var, '', $res); } // http://doc.spip.org/@afficher_articles_trad_boucle -function afficher_articles_trad_boucle($row) +function afficher_articles_trad_boucle($row, $own='') { global $spip_lang_right, $spip_display; @@ -536,7 +538,7 @@ function afficher_articles_trad_boucle($row) } // http://doc.spip.org/@afficher_auteurs_boucle -function afficher_auteurs_boucle($row, &$tous_id, $voir_logo, $own){ +function afficher_auteurs_boucle($row, $own){ $vals = array(); $formater_auteur = charger_fonction('formater_auteur', 'inc'); if ($row['statut'] == '0minirezo') diff --git a/ecrire/inc/editer_auteurs.php b/ecrire/inc/editer_auteurs.php index 30cdf55513..784e8ea87f 100644 --- a/ecrire/inc/editer_auteurs.php +++ b/ecrire/inc/editer_auteurs.php @@ -218,24 +218,19 @@ function afficher_auteurs_objet($type, $id, $flag_editable, $cond_les_auteurs, $ if (!sql_count($result)) return ''; - $table = array(); - $retirer = array(_T('lien_retirer_auteur')." ". http_img_pack('croix-rouge.gif', "X", " class='puce' style='vertical-align: bottom;'")); - while ($row = sql_fetch($result)) { - $table[] = ajouter_auteur_un($row, $formater, $retirer, $arg_ajax, $flag, $id, $type, $script_edit); - } - $largeurs = array('14', '', '', '', '', ''); $styles = array('arial11', 'arial2', 'arial11', 'arial11', 'arial11', 'arial1'); - return xhtml_table_id_type($table, $largeurs, $styles, $tranche); + $tableau = array(); // ne sert pas + return xhtml_table_id_type($result, 'ajouter_auteur_un', $tableau, array($formater, $retirer, $arg_ajax, $flag, $id, $type, $script_edit), false, $largeurs, $styles, $tranche); } // http://doc.spip.org/@ajouter_auteur_un -function ajouter_auteur_un($row, $formater, $retirer, $arg_ajax, $flag, $id, $type, $script_edit) -{ +function ajouter_auteur_un($row, $own) { global $connect_statut, $connect_id_auteur; + list($formater, $retirer, $arg_ajax, $flag, $id, $type, $script_edit) = $own; $id_auteur = $row['id_auteur']; $vals = $formater($id_auteur); diff --git a/ecrire/inc/editer_mots.php b/ecrire/inc/editer_mots.php index f1bb73efeb..c410ae5fe7 100644 --- a/ecrire/inc/editer_mots.php +++ b/ecrire/inc/editer_mots.php @@ -159,21 +159,17 @@ function recherche_mot_cle($cherche_mots, $id_groupe, $objet, $id_objet, $table, // http://doc.spip.org/@afficher_mots_cles function afficher_mots_cles($flag_editable, $objet, $id_objet, $table, $table_id, $url_base, $visible) { - $les_mots = array(); $result = sql_select("mots.id_mot, mots.titre, mots.id_groupe", "spip_mots AS mots, spip_mots_$table AS lien", "lien.$table_id=$id_objet AND mots.id_mot=lien.id_mot", "mots.type, mots.titre", "mots.type, mots.titre"); if (sql_count($result)) { - $tableau= array(); $cle = http_img_pack('petite-cle.gif', "", "width='23' height='12'"); $ret = generer_url_retour($url_base, "$table_id=$id_objet#mots"); - while ($row = sql_fetch($result)) { - $tableau[] = editer_mots_un($row, $cle, $flag_editable, $id_objet, $objet, $ret, $table, $table_id, $url_base, $les_mots); - } - $largeurs = array('25', '', '', ''); $styles = array('arial11', 'arial2', 'arial2', 'arial1'); - $res = xhtml_table_id_type($tableau, $largeurs, $styles); + // cette variable est passe par reference et recevra les valeurs du champ indique + $les_mots = 'id_mot'; + $res = xhtml_table_id_type($result, 'editer_mots_un', $les_mots, array($cle, $flag_editable, $id_objet, $objet, $ret, $table, $table_id, $url_base), false, $largeurs, $styles); } else $res =''; @@ -184,11 +180,12 @@ function afficher_mots_cles($flag_editable, $objet, $id_objet, $table, $table_id } // http://doc.spip.org/@editer_mots_un -function editer_mots_un($row, $cle, $flag_editable, $id_objet, $objet, $ret, $table, $table_id, $url_base, &$les_mots) +function editer_mots_un($row, $own) { + list ($cle, $flag_editable, $id_objet, $objet, $ret, $table, $table_id, $url_base) = $own; + $id_mot = $row['id_mot']; $titre_mot = $row['titre']; - $les_mots[] = $row['id_mot']; $id_groupe = $row['id_groupe']; $url = generer_url_ecrire('mots_edit', "id_mot=$id_mot&redirect=$ret"); @@ -291,7 +288,7 @@ function formulaire_mots_cles($id_objet, $les_mots, $table, $table_id, $url_base (" AND " . sql_in('id_mot', $les_mots, 'NOT')); while ($row = sql_fetch($result)) { - if ($menu = menu_mots($row, $id_groupes_vus, $cond_mots_vu)) { + if ($menu = menu_mots($row, $id_groupes_vus, $cond_mots_vus)) { $id_groupe = $row['id_groupe']; list($corps, $clic) = $menu; diff --git a/ecrire/inc/formater_article.php b/ecrire/inc/formater_article.php index ccf4ea5694..2233b1b8b9 100644 --- a/ecrire/inc/formater_article.php +++ b/ecrire/inc/formater_article.php @@ -15,7 +15,7 @@ include_spip('inc/afficher_objets'); // Fonction appelee dans une boucle, calculer les invariants au premier appel. // http://doc.spip.org/@inc_formater_article_dist -function inc_formater_article_dist($row) +function inc_formater_article_dist($row, $own='') { global $options, $spip_lang_right, $spip_display; static $pret = false; diff --git a/ecrire/inc/grouper_mots.php b/ecrire/inc/grouper_mots.php index 1046e2bf33..1b3b1b6505 100644 --- a/ecrire/inc/grouper_mots.php +++ b/ecrire/inc/grouper_mots.php @@ -41,12 +41,8 @@ function inc_grouper_mots_dist($id_groupe, $cpt) { $result = sql_select($select, 'spip_mots', "id_groupe=$id_groupe", '', 'multi', (($deb_aff < 0) ? '' : "$deb_aff, $nb_aff")); - $table = array(); + $tableau = array(); $occurrences = calculer_liens_mots($id_groupe); - while ($row = sql_fetch($result)) { - $table[] = afficher_groupe_mots_boucle($row, $occurrences, $cpt, "$tmp_var=$deb_aff"); - } - if ($connect_statut=="0minirezo") { $largeurs = array('', 100, 130); $styles = array('arial11', 'arial1', 'arial1'); @@ -56,14 +52,15 @@ function inc_grouper_mots_dist($id_groupe, $cpt) { } return http_img_pack("searching.gif", "*", "style='visibility: hidden; position: absolute; $spip_lang_right: 0px; top: -20px;' id='img_$tmp_var'") - . xhtml_table_id_type($table, $largeurs, $styles, $tranches); + . xhtml_table_id_type($result, 'afficher_groupe_mots_boucle', $tableau, array($occurrences, $total, $deb_aff), false, $largeurs, $styles, $tranches); } // http://doc.spip.org/@afficher_groupe_mots_boucle -function afficher_groupe_mots_boucle($row, $occurrences, $total, $deb_aff) +function afficher_groupe_mots_boucle($row, $own) { global $connect_statut; + list($occurrences, $total, $deb_aff) = $own; $id_mot = $row['id_mot']; $id_groupe = $row['id_groupe']; $titre = typo($row['titre']); diff --git a/ecrire/inc/message_select.php b/ecrire/inc/message_select.php index 5d75a74792..d9c4fa8f20 100644 --- a/ecrire/inc/message_select.php +++ b/ecrire/inc/message_select.php @@ -34,15 +34,12 @@ function afficher_messages($titre, $from, $where, &$messages_vus, $afficher_aute $result = sql_select((isset($requete["SELECT"]) ? $requete["SELECT"] : "*"), $requete['FROM'], $requete['WHERE'], $requete['GROUP BY'], $requete['ORDER BY'], ($deb_aff > 0 ? "$deb_aff, $nb_aff" : ($requete['LIMIT'] ? $requete['LIMIT'] : "99999"))); - $table = array(); - while ($row = sql_fetch($result)) { - $table[]= afficher_message_boucles($row, $messages_vus, $afficher_auteurs); - } - sql_free($result); - - $res = xhtml_table_id_type($table, $largeurs, $styles, $tranches, $titre, "messagerie-24.gif"); + // cette variable est passe par reference et recevra les valeurs du champ indique + $les_messages = 'id_message'; + $res = xhtml_table_id_type($result, 'afficher_message_boucles', $les_messages, $afficher_auteur, $important, $largeurs, $styles, $tranches, $titre, "messagerie-24.gif"); + $messages_vus = array_merge($messages_vus, $les_messages); - if (!$important AND !$table) return ''; + if (!$res) return ''; else return (debut_cadre_couleur('',true) @@ -51,7 +48,7 @@ function afficher_messages($titre, $from, $where, &$messages_vus, $afficher_aute } // http://doc.spip.org/@afficher_message_boucles -function afficher_message_boucles($row, &$messages_vus, $afficher_auteurs) +function afficher_message_boucles($row, $afficher_auteurs) { global $connect_id_auteur, $spip_lang_left, $spip_lang_rtl; @@ -63,7 +60,6 @@ function afficher_message_boucles($row, &$messages_vus, $afficher_auteurs) $titre = sinon($row['titre'], _T('ecrire:info_sans_titre')); $type = $row["type"]; $rv = $row["rv"]; - $messages_vus[$id_message] = $id_message; // // Titre diff --git a/ecrire/inc/presentation.php b/ecrire/inc/presentation.php index d7030056c7..6dd86cb090 100644 --- a/ecrire/inc/presentation.php +++ b/ecrire/inc/presentation.php @@ -446,18 +446,24 @@ function affiche_tranche_bandeau($requete, $tmp_var, $force, $skel, $own='') } // http://doc.spip.org/@xhtml_table_id_type -function xhtml_table_id_type($table, $largeurs, $styles, $tranches = '', $title='', $icone='') +function xhtml_table_id_type($req, $fonc, &$prims, $own, $force, $largeurs, $styles, $tranches = '', $title='', $icone='') { global $spip_display, $spip_lang_left; - if ($table) { + $prim = $prims; + $prims = array(); + if (!sql_count($req)) { + if (!$force) return ''; + } else { if ($spip_display != 4) { $evt = !preg_match(",msie,i", $GLOBALS['browser_name']) ? '' : " onmouseover=\"changeclass(this,'tr_liste_over');\" onmouseout=\"changeclass(this,'tr_liste');\"" ; - foreach ($table as $vals) { + while ($r = sql_fetch($req)) { + if ($prim) $prims[]= $r[$prim]; + if ($vals = $fonc($r, $own)) { reset($largeurs); reset($styles); $res = ''; @@ -470,19 +476,24 @@ function xhtml_table_id_type($table, $largeurs, $styles, $tranches = '', $title= $res .= "\n<td$class$style>$t</td>"; } $tranches .= "\n<tr class='tr_liste'$evt>$res</tr>"; + } } $tranches = "<table width='100%' cellpadding='2' cellspacing='0' border='0'>$tranches</table>"; - } - else { - foreach ($table as $t) - if ($t) + } else { + while ($r = sql_fetch($req)) { + if ($prim) $prims[]= $r[$prim]; + if ($t = $fonc($r, $own)) { $tranches = '<li>' . join('</li><li>', $t) . '</li>'; $tranches = "\n<ul style='text-align: $spip_lang_left; background-color: white;'>" . $tranches . "</ul>"; + } + } } + sql_free($req); } + $id = 't'.substr(md5($title),0,8); $bouton = !$icone ? '' : bouton_block_depliable($title, true, $id); diff --git a/ecrire/inc/referencer_traduction.php b/ecrire/inc/referencer_traduction.php index 496a9dd5f0..443395abb8 100644 --- a/ecrire/inc/referencer_traduction.php +++ b/ecrire/inc/referencer_traduction.php @@ -59,19 +59,17 @@ function inc_referencer_traduction_dist($id_article, $flag, $id_rubrique, $id_tr if ($trad_err) $reponse .= "<div><span style='color: red' size='2' face='Verdana, Geneva, helvetica, sans-serif'>"._T('trad_deja_traduit'). "</span></div>"; - // Afficher la liste des traductions - $table = array(); + // Afficher la liste des traductions + if ($id_trad) { $result = sql_select("id_article, id_rubrique, titre, lang, statut, id_trad", "spip_articles", "id_trad = $id_trad"); - while ($row = sql_fetch($result)) { - $table[] = articles_traduction($row, $id_article); - } } // bloc traductions - if (count($table) > 0) { + if (sql_count($result)) { $largeurs = array(7, 12, '', 100); $styles = array('', '', 'arial2', 'arial2'); - $liste = xhtml_table_id_type($table, $largeurs, $styles, '',_T('trad_article_traduction')); + $tableau = array(); + $liste = xhtml_table_id_type($result, 'articles_traduction', $tableau, $id_article, false, $largeurs, $styles, '',_T('trad_article_traduction')); } else $liste = ''; // changer les globales de direction de langue @@ -81,7 +79,7 @@ function inc_referencer_traduction_dist($id_article, $flag, $id_rubrique, $id_tr if ($spip_display == 4) $form =''; else { $form = "<table width='100%'><tr>"; - if ($flag AND !$table) { + if ($flag AND !$liste) { // Formulaire pour lier a un article $form .= "<td style='width: 60%' class='arial2'>" . ajax_action_post("referencer_traduction", @@ -102,7 +100,7 @@ function inc_referencer_traduction_dist($id_article, $flag, $id_rubrique, $id_tr . icone_horizontale(_T('trad_new'), generer_url_ecrire("articles_edit","new=oui&lier_trad=$id_article&id_rubrique=$id_rubrique"), "traductions-24.gif", "creer.gif", false) . "</td>"; - if ($flag AND $table) { + if ($flag AND $tableau) { $clic = _T('trad_delier'); $form .= "<td style='width: 10px'> </td>" . "<td style='width: 2px; background: url(" . chemin_image("tirets-separation.gif") . ")'>". http_img_pack('rien.gif', " ", "width='2' height='2'") . "</td>" -- GitLab