PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_search/views/search/view.html.php

https://gitlab.com/endomorphosis/greenrenaissancejoomla
PHP | 159 lines | 98 code | 30 blank | 31 comment | 11 complexity | 11049b5c3fb1ef4c511a8800a2c03a62 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: view.html.php 10094 2008-03-02 04:35:10Z instance $
  4. * @package Joomla
  5. * @subpackage Weblinks
  6. * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // Check to ensure this file is included in Joomla!
  15. defined('_JEXEC') or die( 'Restricted access' );
  16. jimport( 'joomla.application.component.view');
  17. /**
  18. * HTML View class for the WebLinks component
  19. *
  20. * @static
  21. * @package Joomla
  22. * @subpackage Weblinks
  23. * @since 1.0
  24. */
  25. class SearchViewSearch extends JView
  26. {
  27. function display($tpl = null)
  28. {
  29. global $mainframe;
  30. require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers'.DS.'search.php' );
  31. // Initialize some variables
  32. $pathway =& $mainframe->getPathway();
  33. $uri =& JFactory::getURI();
  34. $error = '';
  35. $rows = null;
  36. $total = 0;
  37. // Get some data from the model
  38. $areas = &$this->get('areas');
  39. $state = &$this->get('state');
  40. $searchword = $state->get('keyword');
  41. // Get the parameters of the active menu item
  42. $params = &$mainframe->getParams();
  43. // built select lists
  44. $orders = array();
  45. $orders[] = JHTML::_('select.option', 'newest', JText::_( 'Newest first' ) );
  46. $orders[] = JHTML::_('select.option', 'oldest', JText::_( 'Oldest first' ) );
  47. $orders[] = JHTML::_('select.option', 'popular', JText::_( 'Most popular' ) );
  48. $orders[] = JHTML::_('select.option', 'alpha', JText::_( 'Alphabetical' ) );
  49. $orders[] = JHTML::_('select.option', 'category', JText::_( 'Section/Category' ) );
  50. $lists = array();
  51. $lists['ordering'] = JHTML::_('select.genericlist', $orders, 'ordering', 'class="inputbox"', 'value', 'text', $state->get('ordering') );
  52. $searchphrases = array();
  53. $searchphrases[] = JHTML::_('select.option', 'all', JText::_( 'All words' ) );
  54. $searchphrases[] = JHTML::_('select.option', 'any', JText::_( 'Any words' ) );
  55. $searchphrases[] = JHTML::_('select.option', 'exact', JText::_( 'Exact phrase' ) );
  56. $lists['searchphrase' ]= JHTML::_('select.radiolist', $searchphrases, 'searchphrase', '', 'value', 'text', $state->get('match') );
  57. // log the search
  58. SearchHelper::logSearch( $searchword);
  59. //limit searchword
  60. if(SearchHelper::limitSearchWord($searchword)) {
  61. $error = JText::_( 'SEARCH_MESSAGE' );
  62. }
  63. //sanatise searchword
  64. if(SearchHelper::santiseSearchWord($searchword, $state->get('match'))) {
  65. $error = JText::_( 'IGNOREKEYWORD' );
  66. }
  67. if (!$searchword && count( JRequest::get('post') ) ) {
  68. //$error = JText::_( 'Enter a search keyword' );
  69. }
  70. // put the filtered results back into the model
  71. // for next release, the checks should be done in the model perhaps...
  72. $state->set('keyword', $searchword);
  73. if(!$error)
  74. {
  75. $results = &$this->get('data' );
  76. $total = &$this->get('total');
  77. $pagination = &$this->get('pagination');
  78. require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
  79. for ($i=0; $i < count($results); $i++)
  80. {
  81. $row = &$results[$i]->text;
  82. if ($state->get('match') == 'exact')
  83. {
  84. $searchwords = array($searchword);
  85. $needle = $searchword;
  86. }
  87. else
  88. {
  89. $searchwords = preg_split("/\s+/", $searchword);
  90. $needle = $searchwords[0];
  91. }
  92. $row = SearchHelper::prepareSearchContent( $row, 200, $needle );
  93. $searchwords = array_unique( $searchwords );
  94. $searchRegex = '#(';
  95. $x = 0;
  96. foreach ($searchwords as $k => $hlword)
  97. {
  98. $searchRegex .= ($x == 0 ? '' : '|');
  99. $searchRegex .= preg_quote($hlword, '#');
  100. $x++;
  101. }
  102. $searchRegex .= ')#iu';
  103. $row = preg_replace($searchRegex, '<span class="highlight">\0</span>', $row );
  104. $result =& $results[$i];
  105. if ($result->created) {
  106. $created = JHTML::Date ( $result->created );
  107. }
  108. else {
  109. $created = '';
  110. }
  111. $result->created = $created;
  112. $result->count = $i + 1;
  113. }
  114. }
  115. $this->result = JText::sprintf( 'TOTALRESULTSFOUND', $total );
  116. $this->assignRef('pagination', $pagination);
  117. $this->assignRef('results', $results);
  118. $this->assignRef('lists', $lists);
  119. $this->assignRef('params', $params);
  120. $this->assign('ordering', $state->get('ordering'));
  121. $this->assign('searchword', $searchword);
  122. $this->assign('searchphrase', $state->get('match'));
  123. $this->assign('searchareas', $areas);
  124. $this->assign('total', $total);
  125. $this->assign('error', $error);
  126. $this->assign('action', $uri->toString());
  127. parent::display($tpl);
  128. }
  129. }