Return to Snippet

Revision: 20709
at November 23, 2009 14:14 by svenkaemper


Initial Code
<form id="xsearch_form" action="index.php" method="get">
    <input type="hidden" name="article_id" value="REX_ARTICLE_ID" />
    <input type="hidden" name="clang" value="REX_CLANG_ID" />
    <input type="text" size="20" name="xsearch" value="<?php if(!empty($_GET['xsearch'])) echo htmlspecialchars($_GET['xsearch']); ?>" />
	<button class="btn" type="submit"><span><span>OK</span></span></button>
</form>

<?php
 if(!empty($_REQUEST['xsearch']))
 {
   $xsearch = new XSearch();
	$showmax = 10;
	$xsearch->setLimit($start = isset($_GET['start'])?intval($_GET['start']):0, $showmax);
   if(count($result = $xsearch->search($_REQUEST['xsearch'])))
   {
     echo '<div class="searchresults">';
     $ids = array();

     foreach($result['hits'] as $hit)
     {
       if(!in_array($hit['fid'], $ids))
       {
         $article = OOArticle::getArticleById($hit['fid']);

         if($hit['type'] == 'db_column' AND $hit['table'] == $REX['TABLE_PREFIX'].'article')
           $text = $hit['article_teaser'];
         else
           $text = $hit['highlightedtext'];

         $ids[] = $hit['fid'];
         echo '<div class="result">
   <h3><strong><a href="'.($url = htmlspecialchars($article->getUrl())).'">'.$article->getName().'</a></strong></h3>
     <p class="highlightedtext">'.$text.'</p>
     <p class="url">'.$REX['SERVER'].rex_getUrl($hit['fid'], $hit['clang']).'</p>
	</div>';
       }

       if(count($ids) >= 10)
         break;
     }
     echo '</div>';

	 // Pagination
	      if($result['count'] > $showmax)
	      {
	        $self = OOArticle::getArticleById(REX_ARTICLE_ID);
	        echo '<p class="pagination">';
	        for($i = 0; ($i*$showmax) <= $result['count']; $i++)
	        {
	          if(($i*$showmax) == $start)
	            echo '<span class="selected">'.($i+1).'</span>';
	          else
	            echo '<a href="'.$self->getUrl(array('xsearch' => $_REQUEST['xsearch'], 'start' => $i*$showmax)).'">'.($i+1).'</a>';
	        }
	        echo '</p>';
	      }
   }
 }
 ?>

Initial URL


Initial Description


Initial Title
xsearch search results

Initial Tags
textmate

Initial Language
Other