Skip to content
Extraits de code Groupes Projets
Valider 4d343bae rédigé par Fil's avatar Fil
Parcourir les fichiers

quelques optimisations perfs / lisibilité (muetdhiver)

parent 85f8ee8b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -37,8 +37,6 @@ if ($spip_display != 4) { ...@@ -37,8 +37,6 @@ if ($spip_display != 4) {
icone_horizontale( $texte , "../spip_cookie.php3?cookie_admin=non&url=".rawurlencode(_DIR_RESTREINT_ABS), "cookie-24.gif", ""); icone_horizontale( $texte , "../spip_cookie.php3?cookie_admin=non&url=".rawurlencode(_DIR_RESTREINT_ABS), "cookie-24.gif", "");
} }
$nom_site_spip = propre(lire_meta("nom_site")); $nom_site_spip = propre(lire_meta("nom_site"));
if (!$nom_site_spip) $nom_site_spip="SPIP"; if (!$nom_site_spip) $nom_site_spip="SPIP";
...@@ -59,36 +57,35 @@ if ($spip_display != 4) { ...@@ -59,36 +57,35 @@ if ($spip_display != 4) {
} }
} }
echo "<div class='verdana1'>"; echo "<div class='verdana1'>";
$query = "SELECT count(*) AS cnt FROM spip_articles where statut='publie'";
$result = spip_fetch_array(spip_query($query)); $query = "SELECT count(*) AS cnt, statut FROM spip_articles GROUP BY statut";
$nb_art_publie = $result['cnt']; $res = spip_query($query);
$query = "SELECT count(*) AS cnt FROM spip_articles where statut='prop'";
$result = spip_fetch_array(spip_query($query)); while($row = spip_fetch_array($res)) {
$nb_art_prop = $result['cnt']; $var = 'nb_art_'.$row['statut'];
$query = "SELECT count(*) AS cnt FROM spip_articles where statut='prepa'"; $$var = $row['cnt'];
$result = spip_fetch_array(spip_query($query)); }
$nb_art_redac= $result['cnt'];
if ($nb_art_prepa OR $nb_art_prop OR $nb_art_publie) {
if ($nb_art_redac OR $nb_art_prop OR $nb_art_publie)
{
echo afficher_plus("articles_page.php3")."<b>"._T('info_articles')."</b>"; echo afficher_plus("articles_page.php3")."<b>"._T('info_articles')."</b>";
echo "<ul style='margin:0px; padding-$spip_lang_left: 20px; margin-bottom: 5px;'>"; echo "<ul style='margin:0px; padding-$spip_lang_left: 20px; margin-bottom: 5px;'>";
if ($nb_art_redac) echo "<li>"._T("texte_statut_en_cours_redaction").": ".$nb_art_redac; if ($nb_art_prepa) echo "<li>"._T("texte_statut_en_cours_redaction").": ".$nb_art_prepa;
if ($nb_art_prop) echo "<li>"._T("texte_statut_attente_validation").": ".$nb_art_prop; if ($nb_art_prop) echo "<li>"._T("texte_statut_attente_validation").": ".$nb_art_prop;
if ($nb_art_publie) echo "<li><b>"._T("texte_statut_publies").": ".$nb_art_publie."</b>"; if ($nb_art_publie) echo "<li><b>"._T("texte_statut_publies").": ".$nb_art_publie."</b>";
echo "</ul>"; echo "</ul>";
} }
$query = "SELECT count(*) AS cnt FROM spip_breves where statut='publie'"; $query = "SELECT count(*) AS cnt, statut FROM spip_breves GROUP BY statut";
$result = spip_fetch_array(spip_query($query)); $res = spip_query($query);
$nb_bre_publie = $result['cnt'];
$query = "SELECT count(*) AS cnt FROM spip_breves where statut='prop'"; while($row = spip_fetch_array($res)) {
$result = spip_fetch_array(spip_query($query)); $var = 'nb_bre_'.$row['statut'];
$nb_bre_prop = $result['cnt']; $$var = $row['cnt'];
}
if ($nb_bre_prop OR $nb_bre_publie) if ($nb_bre_prop OR $nb_bre_publie) {
{
echo afficher_plus("breves.php3")."<b>"._T('info_breves_02')."</b>"; echo afficher_plus("breves.php3")."<b>"._T('info_breves_02')."</b>";
echo "<ul style='margin:0px; padding-$spip_lang_left: 20px; margin-bottom: 5px;'>"; echo "<ul style='margin:0px; padding-$spip_lang_left: 20px; margin-bottom: 5px;'>";
if ($nb_bre_prop) echo "<li>"._T("texte_statut_attente_validation").": ".$nb_bre_prop; if ($nb_bre_prop) echo "<li>"._T("texte_statut_attente_validation").": ".$nb_bre_prop;
...@@ -108,32 +105,25 @@ if ($spip_display != 4) { ...@@ -108,32 +105,25 @@ if ($spip_display != 4) {
echo "</ul>"; echo "</ul>";
} }
$query = "SELECT count(*) AS cnt FROM spip_auteurs where statut='0minirezo'"; $query = "SELECT count(*) AS cnt, statut FROM spip_auteurs GROUP BY statut";
$result = spip_fetch_array(spip_query($query)); $res = spip_query($query);
$nb_admin = $result['cnt'];
$query = "SELECT count(*) AS cnt FROM spip_auteurs where statut='1comite'";
$result = spip_fetch_array(spip_query($query));
$nb_redac = $result['cnt'];
$query = "SELECT count(*) AS cnt FROM spip_auteurs where statut='6forum'"; while($row = spip_fetch_array($res)) {
$result = spip_fetch_array(spip_query($query)); $var = 'nb_aut_'.$row['statut'];
$nb_abonn = $result['cnt']; $$var = $row['cnt'];
}
if ($nb_admin OR $nb_redac OR $nb_abonn) if ($nb_aut_0minirezo OR $nb_aut_1comite OR $nb_aut_6forum) {
{
echo afficher_plus("auteurs.php3")."<b>"._T('icone_auteurs')."</b>"; echo afficher_plus("auteurs.php3")."<b>"._T('icone_auteurs')."</b>";
echo "<ul style='margin:0px; padding-$spip_lang_left: 20px; margin-bottom: 5px;'>"; echo "<ul style='margin:0px; padding-$spip_lang_left: 20px; margin-bottom: 5px;'>";
if ($nb_admin) echo "<li>"._T("info_administrateurs").": ".$nb_admin; if ($nb_aut_0minirezo) echo "<li>"._T("info_administrateurs").": ".$nb_aut_0minirezo;
if ($nb_redac) echo "<li>"._T("info_redacteurs").": ".$nb_redac; if ($nb_aut_1comite) echo "<li>"._T("info_redacteurs").": ".$nb_aut_1comite;
if ($nb_abonn) echo "<li>"._T("info_visiteurs").": ".$nb_abonn; if ($nb_aut_6forum) echo "<li>"._T("info_visiteurs").": ".$nb_aut_6forum;
echo "</ul>"; echo "</ul>";
} }
echo "</div>"; echo "</div>";
echo fin_cadre_relief(); echo fin_cadre_relief();
......
<?php <?php
include ("inc.php3"); include_once("inc.php3");
// Gestion d'expiration de ce jaja // Gestion d'expiration de ce jaja
$expire = $date + 3600*24; $expire = $date + 3600*24;
$headers_only = http_last_modified($expire); $headers_only = http_last_modified($expire);
$date = gmdate("D, d M Y H:i:s", $date); $date = gmdate("D, d M Y H:i:s", $date);
$expire = gmdate("D, d M Y H:i:s", $expire); $expire = gmdate("D, d M Y H:i:s", $expire);
@Header ("Content-Type: text/javascript"); @Header ("Content-Type: text/javascript");
...@@ -16,57 +14,79 @@ if ($headers_only) exit; ...@@ -16,57 +14,79 @@ if ($headers_only) exit;
@Header ("Last-Modified: ".$date." GMT"); @Header ("Last-Modified: ".$date." GMT");
@Header ("Expires: ".$expire." GMT"); @Header ("Expires: ".$expire." GMT");
function extraire_article($id_p) {
if (array_key_exists($id_p, $GLOBALS['db_art_cache'])) {
return $GLOBALS['db_art_cache'][$id_p];
} else {
return array();
}
}
function gen_liste_rubriques() {
$q = "SELECT id_rubrique, id_parent, titre
FROM spip_rubriques
ORDER BY id_parent, titre";
$res = spip_query($q);
$GLOBALS['db_art_cache'] = array();
if (spip_num_rows($res) > 0) {
while ($row = spip_fetch_array($res)) {
$parent = $row['id_parent'];
$id = $row['id_rubrique'];
$GLOBALS['db_art_cache'][$parent][$id] = $row['titre'];
}
}
}
function bandeau_menu() { function bandeau_menu() {
global $spip_ecran; global $spip_ecran;
$result_racine = spip_query("SELECT * FROM spip_rubriques WHERE id_parent=0 ORDER BY titre");
$i = spip_num_rows($result_racine); gen_liste_rubriques();
$arr_low = extraire_article(0);
$total_lignes = $i;
if ($spip_ecran == "large") $max_lignes = 20; $i = sizeof($arr_low);
else $max_lignes = 15;
$total_lignes = $i;
$nb_col = ceil($total_lignes / $max_lignes); if ($spip_ecran == "large") $max_lignes = 20;
if ($nb_col < 1) $nb_col = 1; else $max_lignes = 15;
$max_lignes = ceil($total_lignes / $nb_col);
$nb_col = ceil($total_lignes / $max_lignes);
if ($nb_col < 1) $nb_col = 1;
$count_lignes = 0; $max_lignes = ceil($total_lignes / $nb_col);
if ($i > 0) { $count_lignes = 0;
$ret = "<div>&nbsp;</div>";
$ret .= "<div class='bandeau_rubriques' style='z-index: 1;'>"; if ($i > 0) {
while ($row = spip_fetch_array($result_racine)) { $ret = "<div>&nbsp;</div>";
$ret .= "<div class='bandeau_rubriques' style='z-index: 1;'>";
if ($count_lignes == $max_lignes) { foreach( $arr_low as $id_rubrique => $titre_rubrique) {
$count_lignes = 0;
$ret .= "</div></td><td valign='top' width='200'><div>&nbsp;</div><div class='bandeau_rubriques' style='z-index: 1;'>"; if ($count_lignes == $max_lignes) {
} $count_lignes = 0;
$count_lignes ++; $ret .= "</div></td><td valign='top' width='200'><div>&nbsp;</div><div class='bandeau_rubriques' style='z-index: 1;'>";
$id_rubrique = $row["id_rubrique"];
$titre_rubrique = supprimer_numero(typo($row["titre"]));
$ret .= bandeau_rubrique ($id_rubrique, $titre_rubrique, $i);
$i = $i - 1;
} }
$ret .= "</div>"; $count_lignes ++;
$titre_rubrique = supprimer_numero(typo($titre_rubrique));
$ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i);
$i = $i - 1;
} }
$ret .= "</div>";
return $ret; }
unset($GLOBALS['db_art_cache']); // On libre la mmoire
return $ret;
} }
function bandeau_rubrique ($id_rubrique, $titre_rubrique, $z = 1) { function bandeau_rubrique($id_rubrique, $titre_rubrique, $z = 1) {
global $zdecal; global $zdecal;
global $spip_ecran, $spip_display; global $spip_ecran, $spip_display;
global $spip_lang, $spip_lang_rtl, $spip_lang_left, $spip_lang_right; global $spip_lang, $spip_lang_rtl, $spip_lang_left, $spip_lang_right;
$titre_rubrique = preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique); $titre_rubrique = preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique);
// Calcul du nombre max de sous-menus // Calcul du nombre max de sous-menus
$zdecal = $zdecal + 1; $zdecal = $zdecal + 1;
if ($spip_ecran == "large") $zmax = 8; if ($spip_ecran == "large") $zmax = 8;
...@@ -81,18 +101,18 @@ function bandeau_rubrique ($id_rubrique, $titre_rubrique, $z = 1) { ...@@ -81,18 +101,18 @@ function bandeau_rubrique ($id_rubrique, $titre_rubrique, $z = 1) {
else $image = ''; else $image = '';
if (strlen($image) > 1) $image = " style='background-image:url(" . _DIR_IMG_PACK . $image .");'"; if (strlen($image) > 1) $image = " style='background-image:url(" . _DIR_IMG_PACK . $image .");'";
$result_rub = spip_query("SELECT * FROM spip_rubriques WHERE id_parent=$id_rubrique ORDER BY titre");
$i = spip_num_rows($result_rub);
$arr_rub = extraire_article($id_rubrique);
$i = sizeof($arr_rub);
if ($i > 0 AND $zdecal < $zmax) { if ($i > 0 AND $zdecal < $zmax) {
$ret .= '<div class=\"pos_r\" style=\"z-index: '.$z.';\" onMouseOver=\"montrer(\'b_'.$id_rubrique.'\');\" onMouseOut=\"cacher(\'b_'.$id_rubrique.'\');\">'; $ret .= '<div class=\"pos_r\" style=\"z-index: '.$z.';\" onMouseOver=\"montrer(\'b_'.$id_rubrique.'\');\" onMouseOut=\"cacher(\'b_'.$id_rubrique.'\');\">';
$ret .= '<div class=\"brt\"><a href=\"naviguer.php3?coll='.$id_rubrique.'\" class=\"bandeau_rub\"'.$image.'>'.addslashes(supprimer_tags($titre_rubrique)).'</a></div>'; $ret .= '<div class=\"brt\"><a href=\"naviguer.php3?coll='.$id_rubrique.'\" class=\"bandeau_rub\"'.$image.'>'.addslashes(supprimer_tags($titre_rubrique)).'</a></div>';
$ret .= '<div class=\"bandeau_rub\" style=\"z-index: '.($z+1).';\" id=\"b_'.$id_rubrique.'\">'; $ret .= '<div class=\"bandeau_rub\" style=\"z-index: '.($z+1).';\" id=\"b_'.$id_rubrique.'\">';
while ($row_rub = spip_fetch_array($result_rub)) { foreach( $arr_rub as $id_rub => $titre_rub) {
$id_rub = $row_rub["id_rubrique"]; $titre_rub = supprimer_numero(typo($titre_rub));
$titre_rub = supprimer_numero(typo($row_rub["titre"])); $ret .= bandeau_rubrique($id_rub, $titre_rub, ($z+$i));
$ret .= bandeau_rubrique ($id_rub, $titre_rub, ($z+$i));
$i = $i - 1; $i = $i - 1;
} }
$ret .= "</div></div>"; $ret .= "</div></div>";
...@@ -109,4 +129,4 @@ echo bandeau_menu(); ...@@ -109,4 +129,4 @@ echo bandeau_menu();
echo "</td></tr></table>"; echo "</td></tr></table>";
echo "\");\n"; echo "\");\n";
?> ?>
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter