[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/exec/ -> rechercher.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  if (!defined("_ECRIRE_INC_VERSION")) return;
  14  
  15  // http://doc.spip.org/@exec_rechercher_dist
  16  function exec_rechercher_dist()
  17  {
  18      global $id, $exclus, $type, $rac;
  19  
  20      $id = intval($id);
  21      $exclus = intval($exclus);
  22      $rac = htmlentities($rac);
  23  
  24      include_spip('inc/texte');
  25      $where = split("[[:space:]]+", $type);
  26      if ($where) {
  27          foreach ($where as $k => $v) 
  28              $where[$k] = "'%" . substr(str_replace("%","\%", _q($v)),1,-1) . "%'";
  29          $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
  30          $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
  31          $where_id = ("(id_rubrique = " . join(" AND id_rubrique = ", $where) . ")");
  32      } else {
  33          $where_titre = " 1=2";
  34          $where_desc = " 1=2";
  35          $where_id = " 1=2";
  36      }
  37  
  38      if ($exclus) {
  39          include_spip('inc/rubriques');
  40          $where_exclus = " AND id_rubrique NOT IN (".calcul_branche($exclus).")";
  41      } else
  42          $where_exclus = '';
  43  
  44      $res = spip_query("SELECT id_rubrique, id_parent, titre FROM spip_rubriques WHERE $where_id$where_exclus");
  45  
  46      $points = $rub = array();
  47  
  48      while ($row = spip_fetch_array($res)) {
  49          $id_rubrique = $row["id_rubrique"];
  50          $rub[$id_rubrique]["titre"] = typo ($row["titre"]);
  51          $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
  52          $points[$id_rubrique] = $points[$id_rubrique] + 3;
  53      }
  54      $res = spip_query("SELECT id_rubrique, id_parent, titre FROM spip_rubriques WHERE $where_titre$where_exclus");
  55      while ($row = spip_fetch_array($res)) {
  56          $id_rubrique = $row["id_rubrique"];
  57          $rub[$id_rubrique]["titre"] = typo ($row["titre"]);
  58          $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
  59          $points[$id_rubrique] = $points[$id_rubrique] + 2;
  60      }
  61      $res = spip_query("SELECT id_rubrique, id_parent, titre FROM spip_rubriques WHERE $where_desc$where_exclus");
  62      while ($row = spip_fetch_array($res)) {
  63          $id_rubrique = $row["id_rubrique"];
  64          $rub[$id_rubrique]["titre"] = typo ($row["titre"]);
  65          $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
  66          $points[$id_rubrique] = $points[$id_rubrique] + 1;
  67      }
  68          
  69  
  70      if ($points) {
  71          arsort($points);
  72          $style = " style='background-image: url(" . _DIR_IMG_PACK . "secteur-12.gif)'";
  73          foreach($rub as $k => $v) {
  74              $rub[$k]['atts'] = ($v["id_parent"] ? $style : '')
  75              . " class='arial11 petite-rubrique'";
  76          }
  77      }
  78  
  79      ajax_retour(proposer_item($points, $rub, $rac, $type));
  80  
  81  }
  82  
  83  // Resultat de la recherche interactive demandee par la fonction JS
  84  // onkey_rechercher qui testera s'il comporte une seule balise au premier niveau
  85  // car cela qui indique qu'un seul resultat a ete trouve.
  86  // ==> attention a composer le message d'erreur avec au moins 2 balises
  87  
  88  // http://doc.spip.org/@proposer_item
  89  function proposer_item ($ids, $titles, $rac, $type)
  90  {
  91  
  92      if (!$ids)
  93          return "<br /><br /><div style='padding: 5px; color: red;'><b>"
  94          .htmlentities($type)
  95          ."</b> :  "._T('avis_aucun_resultat')."</div>";
  96  
  97      $ret = '';
  98      $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
  99  
 100      $onClick = "aff_selection(this.firstChild.title,'$rac". "_selection','$info', event)";
 101  
 102      $ondbClick = "aff_selection_titre(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
 103  
 104      foreach($ids as $id => $bof) {
 105                  
 106          $titre = strtr(str_replace("'", "&#8217;", str_replace('"', "&#34;", textebrut($titles[$id]["titre"]))), "\n\r", "  ");
 107  
 108          $ret .= "<div class='pashighlight'\nonclick=\"changerhighlight(this); "
 109          . $onClick
 110          . "\"\nondblclick=\""
 111          . $ondbClick
 112          . $onClick
 113          . " \"><div"
 114          . $titles[$id]["atts"]
 115          . " title='$id'>&nbsp; "
 116          . $titre
 117          . "</div></div>";
 118      }
 119      return $ret;
 120  }
 121  
 122  ?>


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