Posted By

svenkaemper on 11/23/09


Tagged

textmate Redaxo


Versions (?)

xsearch search results


 / Published in: Other
 

  1. <form id="xsearch_form" action="index.php" method="get">
  2. <input type="hidden" name="article_id" value="REX_ARTICLE_ID" />
  3. <input type="hidden" name="clang" value="REX_CLANG_ID" />
  4. <input type="text" size="20" name="xsearch" value="<?php if(!empty($_GET['xsearch'])) echo htmlspecialchars($_GET['xsearch']); ?>" />
  5. <button class="btn" type="submit"><span><span>OK</span></span></button>
  6. </form>
  7.  
  8. <?php
  9. if(!empty($_REQUEST['xsearch']))
  10. {
  11. $xsearch = new XSearch();
  12. $showmax = 10;
  13. $xsearch->setLimit($start = isset($_GET['start'])?intval($_GET['start']):0, $showmax);
  14. if(count($result = $xsearch->search($_REQUEST['xsearch'])))
  15. {
  16. echo '<div class="searchresults">';
  17. $ids = array();
  18.  
  19. foreach($result['hits'] as $hit)
  20. {
  21. if(!in_array($hit['fid'], $ids))
  22. {
  23. $article = OOArticle::getArticleById($hit['fid']);
  24.  
  25. if($hit['type'] == 'db_column' AND $hit['table'] == $REX['TABLE_PREFIX'].'article')
  26. $text = $hit['article_teaser'];
  27. else
  28. $text = $hit['highlightedtext'];
  29.  
  30. $ids[] = $hit['fid'];
  31. echo '<div class="result">
  32. <h3><strong><a href="'.($url = htmlspecialchars($article->getUrl())).'">'.$article->getName().'</a></strong></h3>
  33. <p class="highlightedtext">'.$text.'</p>
  34. <p class="url">'.$REX['SERVER'].rex_getUrl($hit['fid'], $hit['clang']).'</p>
  35. </div>';
  36. }
  37.  
  38. if(count($ids) >= 10)
  39. break;
  40. }
  41. echo '</div>';
  42.  
  43. // Pagination
  44. if($result['count'] > $showmax)
  45. {
  46. $self = OOArticle::getArticleById(REX_ARTICLE_ID);
  47. echo '<p class="pagination">';
  48. for($i = 0; ($i*$showmax) <= $result['count']; $i++)
  49. {
  50. if(($i*$showmax) == $start)
  51. echo '<span class="selected">'.($i+1).'</span>';
  52. else
  53. echo '<a href="'.$self->getUrl(array('xsearch' => $_REQUEST['xsearch'], 'start' => $i*$showmax)).'">'.($i+1).'</a>';
  54. }
  55. echo '</p>';
  56. }
  57. }
  58. }
  59. ?>

Report this snippet  

You need to login to post a comment.