[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage com_finder 6 * 7 * @copyright (C) 2011 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Finder\Site\View\Search; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Filesystem\Path; 15 use Joomla\CMS\HTML\HTMLHelper; 16 use Joomla\CMS\Language\Text; 17 use Joomla\CMS\MVC\View\GenericDataException; 18 use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; 19 use Joomla\CMS\Pagination\Pagination; 20 use Joomla\CMS\Plugin\PluginHelper; 21 use Joomla\CMS\Profiler\Profiler; 22 use Joomla\CMS\Router\Route; 23 use Joomla\CMS\Router\SiteRouterAwareInterface; 24 use Joomla\CMS\Router\SiteRouterAwareTrait; 25 use Joomla\CMS\Uri\Uri; 26 use Joomla\Component\Finder\Administrator\Indexer\Query; 27 use Joomla\Component\Finder\Site\Helper\FinderHelper; 28 29 // phpcs:disable PSR1.Files.SideEffects 30 \defined('_JEXEC') or die; 31 // phpcs:enable PSR1.Files.SideEffects 32 33 /** 34 * Search HTML view class for the Finder package. 35 * 36 * @since 2.5 37 */ 38 class HtmlView extends BaseHtmlView implements SiteRouterAwareInterface 39 { 40 use SiteRouterAwareTrait; 41 42 /** 43 * The query indexer object 44 * 45 * @var Query 46 * 47 * @since 4.0.0 48 */ 49 protected $query; 50 51 /** 52 * The page parameters 53 * 54 * @var \Joomla\Registry\Registry|null 55 */ 56 protected $params = null; 57 58 /** 59 * The model state 60 * 61 * @var \Joomla\CMS\Object\CMSObject 62 */ 63 protected $state; 64 65 /** 66 * The logged in user 67 * 68 * @var \Joomla\CMS\User\User|null 69 */ 70 protected $user = null; 71 72 /** 73 * The suggested search query 74 * 75 * @var string|false 76 * 77 * @since 4.0.0 78 */ 79 protected $suggested = false; 80 81 /** 82 * The explained (human-readable) search query 83 * 84 * @var string|null 85 * 86 * @since 4.0.0 87 */ 88 protected $explained = null; 89 90 /** 91 * The page class suffix 92 * 93 * @var string 94 * 95 * @since 4.0.0 96 */ 97 protected $pageclass_sfx = ''; 98 99 /** 100 * An array of results 101 * 102 * @var array 103 * 104 * @since 3.8.0 105 */ 106 protected $results; 107 108 /** 109 * The total number of items 110 * 111 * @var integer 112 * 113 * @since 3.8.0 114 */ 115 protected $total; 116 117 /** 118 * The pagination object 119 * 120 * @var Pagination 121 * 122 * @since 3.8.0 123 */ 124 protected $pagination; 125 126 /** 127 * Method to display the view. 128 * 129 * @param string $tpl A template file to load. [optional] 130 * 131 * @return void 132 * 133 * @since 2.5 134 */ 135 public function display($tpl = null) 136 { 137 $app = Factory::getApplication(); 138 $this->params = $app->getParams(); 139 140 // Get view data. 141 $this->state = $this->get('State'); 142 $this->query = $this->get('Query'); 143 \JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderQuery') : null; 144 $this->results = $this->get('Items'); 145 \JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderResults') : null; 146 $this->total = $this->get('Total'); 147 \JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderTotal') : null; 148 $this->pagination = $this->get('Pagination'); 149 \JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderPagination') : null; 150 151 // Flag indicates to not add limitstart=0 to URL 152 $this->pagination->hideEmptyLimitstart = true; 153 154 // Check for errors. 155 if (count($errors = $this->get('Errors'))) { 156 throw new GenericDataException(implode("\n", $errors), 500); 157 } 158 159 // Configure the pathway. 160 if (!empty($this->query->input)) { 161 $app->getPathway()->addItem($this->escape($this->query->input)); 162 } 163 164 // Check for a double quote in the query string. 165 if (strpos($this->query->input, '"')) { 166 $router = $this->getSiteRouter(); 167 168 // Fix the q variable in the URL. 169 if ($router->getVar('q') !== $this->query->input) { 170 $router->setVar('q', $this->query->input); 171 } 172 } 173 174 // Run an event on each result item 175 if (is_array($this->results)) { 176 // Import Finder plugins 177 PluginHelper::importPlugin('finder'); 178 179 foreach ($this->results as $result) { 180 $app->triggerEvent('onFinderResult', array(&$result, &$this->query)); 181 } 182 } 183 184 // Log the search 185 FinderHelper::logSearch($this->query, $this->total); 186 187 // Push out the query data. 188 $this->suggested = HTMLHelper::_('query.suggested', $this->query); 189 $this->explained = HTMLHelper::_('query.explained', $this->query); 190 191 // Escape strings for HTML output 192 $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx', '')); 193 194 // Check for layout override only if this is not the active menu item 195 // If it is the active menu item, then the view and category id will match 196 $active = $app->getMenu()->getActive(); 197 198 if (isset($active->query['layout'])) { 199 // We need to set the layout in case this is an alternative menu item (with an alternative layout) 200 $this->setLayout($active->query['layout']); 201 } 202 203 $this->prepareDocument(); 204 205 \JDEBUG ? Profiler::getInstance('Application')->mark('beforeFinderLayout') : null; 206 207 parent::display($tpl); 208 209 \JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderLayout') : null; 210 } 211 212 /** 213 * Method to get hidden input fields for a get form so that control variables 214 * are not lost upon form submission 215 * 216 * @return string A string of hidden input form fields 217 * 218 * @since 2.5 219 */ 220 protected function getFields() 221 { 222 $fields = null; 223 224 // Get the URI. 225 $uri = Uri::getInstance(Route::_($this->query->toUri())); 226 $uri->delVar('q'); 227 $uri->delVar('o'); 228 $uri->delVar('t'); 229 $uri->delVar('d1'); 230 $uri->delVar('d2'); 231 $uri->delVar('w1'); 232 $uri->delVar('w2'); 233 $elements = $uri->getQuery(true); 234 235 // Create hidden input elements for each part of the URI. 236 foreach ($elements as $n => $v) { 237 if (is_scalar($v)) { 238 $fields .= '<input type="hidden" name="' . $n . '" value="' . $v . '">'; 239 } 240 } 241 242 return $fields; 243 } 244 245 /** 246 * Method to get the layout file for a search result object. 247 * 248 * @param string $layout The layout file to check. [optional] 249 * 250 * @return string The layout file to use. 251 * 252 * @since 2.5 253 */ 254 protected function getLayoutFile($layout = null) 255 { 256 // Create and sanitize the file name. 257 $file = $this->_layout . '_' . preg_replace('/[^A-Z0-9_\.-]/i', '', $layout); 258 259 // Check if the file exists. 260 $filetofind = $this->_createFileName('template', array('name' => $file)); 261 $exists = Path::find($this->_path['template'], $filetofind); 262 263 return ($exists ? $layout : 'result'); 264 } 265 266 /** 267 * Prepares the document 268 * 269 * @return void 270 * 271 * @since 2.5 272 */ 273 protected function prepareDocument() 274 { 275 $app = Factory::getApplication(); 276 277 // Because the application sets a default page title, 278 // we need to get it from the menu item itself 279 $menu = $app->getMenu()->getActive(); 280 281 if ($menu) { 282 $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); 283 } else { 284 $this->params->def('page_heading', Text::_('COM_FINDER_DEFAULT_PAGE_TITLE')); 285 } 286 287 $this->setDocumentTitle($this->params->get('page_title', '')); 288 289 if ($layout = $this->params->get('article_layout')) { 290 $this->setLayout($layout); 291 } 292 293 // Configure the document meta-description. 294 if (!empty($this->explained)) { 295 $explained = $this->escape(html_entity_decode(strip_tags($this->explained), ENT_QUOTES, 'UTF-8')); 296 $this->document->setDescription($explained); 297 } elseif ($this->params->get('menu-meta_description')) { 298 $this->document->setDescription($this->params->get('menu-meta_description')); 299 } 300 301 if ($this->params->get('robots')) { 302 $this->document->setMetaData('robots', $this->params->get('robots')); 303 } 304 305 // Check for OpenSearch 306 if ($this->params->get('opensearch', 1)) { 307 $ostitle = $this->params->get( 308 'opensearch_name', 309 Text::_('COM_FINDER_OPENSEARCH_NAME') . ' ' . $app->get('sitename') 310 ); 311 $this->document->addHeadLink( 312 Uri::getInstance()->toString(array('scheme', 'host', 'port')) . Route::_('index.php?option=com_finder&view=search&format=opensearch'), 313 'search', 314 'rel', 315 array('title' => $ostitle, 'type' => 'application/opensearchdescription+xml') 316 ); 317 } 318 319 // Add feed link to the document head. 320 if ($this->params->get('show_feed_link', 1) == 1) { 321 // Add the RSS link. 322 $props = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); 323 $route = Route::_($this->query->toUri() . '&format=feed&type=rss'); 324 $this->document->addHeadLink($route, 'alternate', 'rel', $props); 325 326 // Add the ATOM link. 327 $props = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0'); 328 $route = Route::_($this->query->toUri() . '&format=feed&type=atom'); 329 $this->document->addHeadLink($route, 'alternate', 'rel', $props); 330 } 331 } 332 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |