[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/exec/ -> recherche.php (source)

   1  <?php
   2  
   3  /***************************************************************************\
   4   *  SPIP, Systeme de publication pour l'internet                           *
   5   *                                                                         *
   6   *  Copyright (c) 2001-2007                                                *
   7   *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
   8   *                                                                         *
   9   *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
  10   *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
  11  \***************************************************************************/
  12  
  13  
  14  if (!defined("_ECRIRE_INC_VERSION")) return;
  15  include_spip('inc/presentation');
  16  include_spip('inc/sites_voir');
  17  
  18  // http://doc.spip.org/@exec_recherche_dist
  19  function exec_recherche_dist()
  20  {
  21      global $couleur_foncee, $recherche;
  22  
  23      $recherche_aff = entites_html($recherche);
  24  
  25      $commencer_page = charger_fonction('commencer_page', 'inc');
  26      echo $commencer_page(_T('titre_page_recherche', array('recherche' => $recherche_aff)));
  27   
  28      debut_gauche();
  29  
  30      if ($recherche) {
  31        $onfocus = "this.value='" . addslashes($recherche) . "';";
  32      } else {
  33        $recherche_aff = _T('info_rechercher');
  34        $onfocus = "this.value='';";
  35      }
  36      echo "<form method='get' style='margin: 0px;' action='" . generer_url_ecrire("recherche","") . "'><div>";
  37      echo "<input type='hidden' name='exec' value='recherche' />";
  38      echo '<input type="text" size="10" value="'.$recherche_aff.'" name="recherche" class="spip_recherche" accesskey="r" onfocus="'.$onfocus . '" />';
  39      echo "</div></form>";
  40  
  41      debut_droite();
  42  
  43      if (strlen($recherche) > 0) {
  44  
  45      echo "<span class='verdana1'><b>"._T('info_resultat_recherche')."</b></span><br />";
  46      echo "<span style='color: $couleur_foncee' class='verdana1 spip_large'><b>$recherche_aff</b></span>";
  47  
  48      $query_articles['FROM'] = 'spip_articles AS articles';
  49      $query_breves['FROM'] = 'spip_breves';
  50      $query_rubriques['FROM'] = 'spip_rubriques';
  51      $query_sites['FROM'] = 'spip_syndic';
  52      $testnum = ereg("^[0-9]+$", $recherche);
  53  
  54      // Eviter les symboles '%', caracteres SQL speciaux
  55  
  56      $where = split("[[:space:]]+", $recherche);
  57      if ($where) {
  58          foreach ($where as $k => $v) 
  59            $where[$k] = "'%" . substr(str_replace("%","\%", _q($v)),1,-1) . "%'";
  60          $where = ($testnum ? "OR " : '') .
  61            ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
  62      }
  63  
  64      $query_articles['WHERE']= ($testnum ? "(articles.id_article = $recherche)" :'') . $where;
  65      $query_breves['WHERE']= ($testnum ? "(id_breve = $recherche)" : '') . $where;
  66      $query_rubriques['WHERE']= ($testnum ? "(id_rubrique = $recherche)" : '') . $where;
  67      $query_sites['WHERE']= ($testnum ? "(id_syndic = $recherche)" : '') . ereg_replace("titre LIKE", "nom_site LIKE",$where);
  68  
  69      $query_articles['ORDER BY']= "date_modif DESC";
  70      $query_breves['ORDER BY']= "maj DESC";
  71      $query_rubriques['ORDER BY']= "maj DESC";
  72      $query_sites['ORDER BY']= "maj DESC";
  73      
  74      $activer_moteur = ($GLOBALS['meta']['activer_moteur'] == 'oui');
  75  
  76      if ($activer_moteur) {    // texte integral
  77          include_spip('inc/indexation');
  78          list($hash_recherche,) = requete_hash(str_replace("%","\%",$recherche));
  79          $query_articles_int = requete_txt_integral('spip_articles', $hash_recherche);
  80          $query_breves_int = requete_txt_integral('spip_breves', $hash_recherche);
  81          $query_rubriques_int = requete_txt_integral('spip_rubriques', $hash_recherche);
  82          $query_sites_int = requete_txt_integral('spip_syndic', $hash_recherche);
  83          $query_auteurs_int = requete_txt_integral('spip_auteurs', $hash_recherche);
  84      }
  85      
  86      $nba = afficher_articles (_T('info_articles_trouves'), $query_articles);
  87      echo $nba;
  88  
  89      if ($activer_moteur) {
  90          if ($nba) 
  91              $query_articles_int['WHERE'] .= " AND NOT (" . $query_articles['WHERE'] . ")";
  92  
  93          $nba1 = afficher_articles (_T('info_articles_trouves_dans_texte'), $query_articles_int);
  94          echo $nba1;
  95      }
  96      
  97      $nbb = afficher_breves ('<b>' . _T('info_breves_touvees') . '</b>', $query_breves, true);
  98      echo $nbb;
  99      if ($activer_moteur) {
 100          if ($nbb) {
 101              $query_breves_int["WHERE"].= " AND NOT (" . $query_breves['WHERE'] . ")";
 102          }
 103          $nbb1 = afficher_breves ('<b>' . _T('info_breves_touvees_dans_texte') . '</b>', $query_breves_int, true);
 104          echo $nbb1;
 105      }
 106  
 107      $nbr = afficher_rubriques ('<b>' . _T('info_rubriques_trouvees') . '</b>', $query_rubriques);
 108      echo $nbr;
 109      if ($activer_moteur) {
 110          if ($nbr) {
 111              $query_rubriques_int["WHERE"].= " AND NOT (" . $query_rubriques['WHERE'] . ")";
 112          }
 113          $nbr1 = afficher_rubriques ('<b>' . _T('info_rubriques_trouvees_dans_texte') . '</b>', $query_rubriques_int);
 114          echo $nbr1;
 115      }
 116      
 117      $nbt = afficher_auteurs (_T('info_auteurs_trouves'), $query_auteurs_int);
 118      
 119      $nbs = afficher_sites ('<b>' . _T('info_sites_trouves') . '</b>', $query_sites);
 120      echo $nbs;
 121      if ($activer_moteur) {
 122          if ($nbs) {
 123              $query_sites_int["WHERE"].=  " AND NOT (" . $query_sites['WHERE'] . ")";
 124          }
 125          $nbs1 = afficher_sites ('<b>' . _T('info_sites_trouves_dans_texte') . '</b>', $query_sites_int);
 126          echo $nbs1;
 127      }
 128      
 129      if (!$nba AND !$nba1 AND !$nbb AND !$nbb1 AND !$nbr AND !$nbr1 AND !$nbt AND !$nbs AND !$nbs1) {
 130          echo "<p class='verdana1'>"._T('avis_aucun_resultat')."</p>";
 131      }
 132      }
 133  echo fin_gauche(), fin_page();
 134  }
 135  
 136  
 137  // http://doc.spip.org/@afficher_auteurs
 138  function afficher_auteurs ($titre_table, $requete) {
 139  
 140      if (!$requete['SELECT']) $requete['SELECT'] = '*' ;
 141  
 142      $tous_id = array();
 143      $cpt = spip_fetch_array(spip_query("SELECT COUNT(*) AS n FROM " . $requete['FROM'] . ($requete['WHERE'] ? (' WHERE ' . $requete['WHERE']) : '') . ($requete['GROUP BY'] ? (' GROUP BY ' . $requete['GROUP BY']) : '')));
 144      if (! ($cpt = $cpt['n'])) return 0 ;
 145      if ($requete['LIMIT']) $cpt = min($requete['LIMIT'], $cpt);
 146  
 147      $tmp_var = 't_' . substr(md5(join('', $requete)), 0, 4);
 148      $nb_aff = floor(1.5 * _TRANCHES);
 149      $deb_aff = intval(_request($tmp_var));
 150      $tranches = '';
 151      if ($cpt > $nb_aff) {
 152          $nb_aff = (_TRANCHES); 
 153          $tranches = afficher_tranches_requete($cpt, $tmp_var, '', $nb_aff);
 154      }
 155  
 156      debut_cadre_relief("auteur-24.gif");
 157  
 158      if ($titre_table) {
 159              echo "<p><table width='100%' cellpadding='0' cellspacing='0' border='0'>";
 160              echo "<tr><td style='width: 100%'>";
 161              echo "<table width='100%' cellpadding='3' cellspacing='0' border='0'>";
 162              echo "<tr style='background-color: #333333'><td style='width: 100%' colspan='5'><span style='color: #FFFFFF;' class='verdana1 spip_medium'><b>$titre_table</b></span></td></tr>";
 163          }
 164      else {
 165              echo "<p><table width='100%' cellpadding='3' cellspacing='0' border='0'>";
 166          }
 167  
 168      echo $tranches;
 169  
 170      $result = spip_query("SELECT " . $requete['SELECT'] . " FROM " . $requete['FROM'] . ($requete['WHERE'] ? (' WHERE ' . $requete['WHERE']) : '') . ($requete['GROUP BY'] ? (' GROUP BY ' . $requete['GROUP BY']) : '') . ($requete['ORDER BY'] ? (' ORDER BY ' . $requete['ORDER BY']) : '') . " LIMIT " . ($deb_aff >= 0 ? "$deb_aff, $nb_aff" : ($requete['LIMIT'] ? $requete['LIMIT'] : "99999")));
 171  
 172      $table = array();
 173      while ($row = spip_fetch_array($result)) {
 174          $tous_id[] = $row['id_auteur'];
 175          $formater_auteur = charger_fonction('formater_auteur', 'inc');
 176          $table[]= $formater_auteur($row['id_auteur']);
 177      }
 178      spip_free_result($result);
 179      $largeurs = array(20, 20, 200, 20, 50);
 180      $styles = array('','','arial2','arial1','arial1');
 181      echo afficher_liste($largeurs, $table, $styles);
 182  
 183      if ($titre_table) echo "</table></td></tr>";
 184      echo "</table>";
 185      fin_cadre_relief();
 186  
 187      return $cpt;
 188  }
 189  ?>


Généré le : Wed Nov 21 10:20:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics