PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/endomorphosis/OLAAaction
PHP | 178 lines | 111 code | 34 blank | 33 comment | 14 complexity | e8451cf4ab3528eb7c52edba085db958 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: view.html.php 14401 2010-01-26 14:10:00Z louis $
  4. * @package Joomla
  5. * @subpackage Weblinks
  6. * @copyright Copyright (C) 2005 - 2010 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. $params = &$mainframe->getParams();
  42. $menus = &JSite::getMenu();
  43. $menu = $menus->getActive();
  44. // because the application sets a default page title, we need to get it
  45. // right from the menu item itself
  46. if (is_object( $menu )) {
  47. $menu_params = new JParameter( $menu->params );
  48. if (!$menu_params->get( 'page_title')) {
  49. $params->set('page_title', JText::_( 'Search' ));
  50. }
  51. } else {
  52. $params->set('page_title', JText::_( 'Search' ));
  53. }
  54. $document = &JFactory::getDocument();
  55. $document->setTitle( $params->get( 'page_title' ) );
  56. // Get the parameters of the active menu item
  57. $params = &$mainframe->getParams();
  58. // built select lists
  59. $orders = array();
  60. $orders[] = JHTML::_('select.option', 'newest', JText::_( 'Newest first' ) );
  61. $orders[] = JHTML::_('select.option', 'oldest', JText::_( 'Oldest first' ) );
  62. $orders[] = JHTML::_('select.option', 'popular', JText::_( 'Most popular' ) );
  63. $orders[] = JHTML::_('select.option', 'alpha', JText::_( 'Alphabetical' ) );
  64. $orders[] = JHTML::_('select.option', 'category', JText::_( 'Section/Category' ) );
  65. $lists = array();
  66. $lists['ordering'] = JHTML::_('select.genericlist', $orders, 'ordering', 'class="inputbox"', 'value', 'text', $state->get('ordering') );
  67. $searchphrases = array();
  68. $searchphrases[] = JHTML::_('select.option', 'all', JText::_( 'All words' ) );
  69. $searchphrases[] = JHTML::_('select.option', 'any', JText::_( 'Any words' ) );
  70. $searchphrases[] = JHTML::_('select.option', 'exact', JText::_( 'Exact phrase' ) );
  71. $lists['searchphrase' ]= JHTML::_('select.radiolist', $searchphrases, 'searchphrase', '', 'value', 'text', $state->get('match') );
  72. // log the search
  73. SearchHelper::logSearch( $searchword);
  74. //limit searchword
  75. if(SearchHelper::limitSearchWord($searchword)) {
  76. $error = JText::_( 'SEARCH_MESSAGE' );
  77. }
  78. //sanatise searchword
  79. if(SearchHelper::santiseSearchWord($searchword, $state->get('match'))) {
  80. $error = JText::_( 'IGNOREKEYWORD' );
  81. }
  82. if (!$searchword && count( JRequest::get('post') ) ) {
  83. //$error = JText::_( 'Enter a search keyword' );
  84. }
  85. // put the filtered results back into the model
  86. // for next release, the checks should be done in the model perhaps...
  87. $state->set('keyword', $searchword);
  88. if(!$error)
  89. {
  90. $results = &$this->get('data' );
  91. $total = &$this->get('total');
  92. $pagination = &$this->get('pagination');
  93. require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
  94. for ($i=0; $i < count($results); $i++)
  95. {
  96. $row = &$results[$i]->text;
  97. if ($state->get('match') == 'exact')
  98. {
  99. $searchwords = array($searchword);
  100. $needle = $searchword;
  101. }
  102. else
  103. {
  104. $searchwords = preg_split("/\s+/u", $searchword);
  105. $needle = $searchwords[0];
  106. }
  107. $row = SearchHelper::prepareSearchContent( $row, 200, $needle );
  108. $searchwords = array_unique( $searchwords );
  109. $searchRegex = '#(';
  110. $x = 0;
  111. foreach ($searchwords as $k => $hlword)
  112. {
  113. $searchRegex .= ($x == 0 ? '' : '|');
  114. $searchRegex .= preg_quote($hlword, '#');
  115. $x++;
  116. }
  117. $searchRegex .= ')#iu';
  118. $row = preg_replace($searchRegex, '<span class="highlight">\0</span>', $row );
  119. $result =& $results[$i];
  120. if ($result->created) {
  121. $created = JHTML::Date ( $result->created );
  122. }
  123. else {
  124. $created = '';
  125. }
  126. $result->created = $created;
  127. $result->count = $i + 1;
  128. }
  129. }
  130. $this->result = JText::sprintf( 'TOTALRESULTSFOUND', $total );
  131. $this->assignRef('pagination', $pagination);
  132. $this->assignRef('results', $results);
  133. $this->assignRef('lists', $lists);
  134. $this->assignRef('params', $params);
  135. $this->assign('ordering', $state->get('ordering'));
  136. $this->assign('searchword', $searchword);
  137. $this->assign('searchphrase', $state->get('match'));
  138. $this->assign('searchareas', $areas);
  139. $this->assign('total', $total);
  140. $this->assign('error', $error);
  141. $this->assign('action', $uri->toString());
  142. parent::display($tpl);
  143. }
  144. }