[ Index ]

PHP Cross Reference of Textpattern 4.0.8

title

Body

[close]

/textpattern/publish/ -> search.php (source)

   1  <?php
   2  
   3  /*
   4      This is Textpattern
   5      Copyright 2005 by Dean Allen - all rights reserved.
   6  
   7      Use of this software denotes acceptance of the Textpattern license agreement
   8  
   9  $HeadURL: https://textpattern.googlecode.com/svn/releases/4.0.8/source/textpattern/publish/search.php $
  10  $LastChangedRevision: 2812 $
  11  
  12  */
  13  
  14  
  15  // -------------------------------------------------------------
  16  // DEPRECATED
  17  // this is now performed by doArticles()
  18  	function search($q)
  19      {
  20          global $prefs;
  21          $url = $prefs['siteurl'];
  22          extract($prefs);
  23  
  24          $s_filter = filterSearch();
  25  
  26          $form = fetch('form','txp_form','name','search_results');
  27  
  28              // lose this eventually - only used if search_results form is missing
  29          $form = (!$form) ? legacy_form() : $form;
  30  
  31          $rs = safe_rows(
  32              "*, ID as thisid, unix_timestamp(Posted) as posted, Title as title,
  33              match (Title,Body) against ('$q') as score",
  34              "textpattern",
  35              "(Title rlike '$q' or Body rlike '$q') $s_filter
  36              and Status = 4 and Posted <=now() order by score desc limit 40");
  37  
  38          if($rs) {
  39              $result_rows = count($rs);
  40              $text = ($result_rows == 1) ? gTxt('article_found') : gTxt('articles_found');
  41          } else {
  42              $result_rows = 0;
  43              $text = gTxt('articles_found');
  44          }
  45  
  46          $results[] = graf($result_rows.' '.$text);
  47          if($result_rows > 0) {
  48              foreach($rs as $a) {
  49                  extract($a);
  50  
  51                  $result_date = safe_strftime($archive_dateformat,$posted);
  52                  $uTitle = ($url_title) ? $url_title : stripSpace($Title);
  53                  $hurl = permlinkurl($a);
  54                  $result_url = '<a href="'.$hurl.'">'.$hurl.'</a>';
  55                  $result_title = '<a href="'.$hurl.'">'.$Title.'</a>';
  56  
  57                  $result = preg_replace("/>\s*</","> <",$Body_html);
  58                  preg_match_all("/\s.{1,50}".preg_quote($q).".{1,50}\s/i",$result,$concat);
  59  
  60                      $concat = join(" ... ",$concat[0]);
  61  
  62                      $concat = strip_tags($concat);
  63                      $concat = preg_replace('/^[^>]+>/U',"",$concat);
  64                      $concat = preg_replace("/($q)/i","<strong>$1</strong>",$concat);
  65                      $result_excerpt = ($concat) ? "... ".$concat." ..." : '';
  66  
  67                      $glob['search_result_title']   = $result_title;
  68                      $glob['search_result_excerpt'] = $result_excerpt;
  69                      $glob['search_result_url']     = $result_url;
  70                      $glob['search_result_date']    = $result_date;
  71  
  72                      $GLOBALS['this_result'] = $glob;
  73  
  74                      $thisresult = $form;
  75  
  76                      $results[] = parse($thisresult);
  77              }
  78          }
  79          return (is_array($results)) ? join('',$results) : '';
  80      }
  81  
  82  // -------------------------------------------------------------
  83  	function filterSearch()
  84      {
  85          $rs = safe_column("name", "txp_section", "searchable != '1'");
  86          if ($rs) {
  87              foreach($rs as $name) $filters[] = "and Section != '".doSlash($name)."'";
  88              return join(' ',$filters);
  89          }
  90          return false;
  91      }
  92  
  93  // -------------------------------------------------------------
  94  // DEPRECATED
  95  	function legacy_form()
  96      {    // lose this eventually
  97          return '<h2><txp:search_result_title /></h2>
  98  <p><txp:search_result_excerpt /><br/>
  99  <small><txp:search_result_url /> &middot; <txp:search_result_date /></small></p>';
 100      }
 101  
 102  ?>


Generated: Thu May 21 23:03:01 2009 Cross-referenced by PHPXref 0.7