[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/components/com_finder/views/search/ -> view.html.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Site
   4   * @subpackage  com_finder
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   7   * @license     GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  defined('_JEXEC') or die;
  11  
  12  jimport('joomla.application.component.view');
  13  
  14  /**
  15   * Search HTML view class for the Finder package.
  16   *
  17   * @package     Joomla.Site
  18   * @subpackage  com_finder
  19   * @since       2.5
  20   */
  21  class FinderViewSearch extends JView
  22  {
  23      protected $query;
  24      protected $params;
  25      protected $state;
  26      protected $user;
  27  
  28      /**
  29       * Method to display the view.
  30       *
  31       * @param   string  $tpl  A template file to load. [optional]
  32       *
  33       * @return  mixed  JError object on failure, void on success.
  34       *
  35       * @since   2.5
  36       */
  37  	public function display($tpl = null)
  38      {
  39          $app = JFactory::getApplication();
  40          $params = $app->getParams();
  41  
  42          // Get view data.
  43          $state = $this->get('State');
  44          $query = $this->get('Query');
  45          JDEBUG ? $GLOBALS['_PROFILER']->mark('afterFinderQuery') : null;
  46          $results = $this->get('Results');
  47          JDEBUG ? $GLOBALS['_PROFILER']->mark('afterFinderResults') : null;
  48          $total = $this->get('Total');
  49          JDEBUG ? $GLOBALS['_PROFILER']->mark('afterFinderTotal') : null;
  50          $pagination = $this->get('Pagination');
  51          JDEBUG ? $GLOBALS['_PROFILER']->mark('afterFinderPagination') : null;
  52  
  53          // Check for errors.
  54          if (count($errors = $this->get('Errors')))
  55          {
  56              JError::raiseError(500, implode("\n", $errors));
  57              return false;
  58          }
  59  
  60          // Configure the pathway.
  61          if (!empty($query->input))
  62          {
  63              $app->getPathWay()->addItem($this->escape($query->input));
  64          }
  65  
  66          // Push out the view data.
  67          $this->assignRef('state', $state);
  68          $this->assignRef('params', $params);
  69          $this->assignRef('query', $query);
  70          $this->assignRef('results', $results);
  71          $this->assignRef('total', $total);
  72          $this->assignRef('pagination', $pagination);
  73  
  74          // Check for a double quote in the query string.
  75          if (strpos($this->query->input, '"'))
  76          {
  77              // Get the application router.
  78              $router =& $app->getRouter();
  79  
  80              // Fix the q variable in the URL.
  81              if ($router->getVar('q') !== $this->query->input)
  82              {
  83                  $router->setVar('q', $this->query->input);
  84              }
  85          }
  86  
  87          // Push out the query data.
  88          JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
  89          $this->assign('suggested', JHtml::_('query.suggested', $query));
  90          $this->assign('explained', JHtml::_('query.explained', $query));
  91  
  92          // Escape strings for HTML output
  93          $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
  94  
  95          // Check for layout override only if this is not the active menu item
  96          // If it is the active menu item, then the view and category id will match
  97          $active = $app->getMenu()->getActive();
  98          if (isset($active->query['layout']))
  99          {
 100              // We need to set the layout in case this is an alternative menu item (with an alternative layout)
 101              $this->setLayout($active->query['layout']);
 102          }
 103  
 104          $this->prepareDocument($query);
 105  
 106          JDEBUG ? $GLOBALS['_PROFILER']->mark('beforeFinderLayout') : null;
 107  
 108          parent::display($tpl);
 109  
 110          JDEBUG ? $GLOBALS['_PROFILER']->mark('afterFinderLayout') : null;
 111      }
 112  
 113      /**
 114       * Method to get hidden input fields for a get form so that control variables
 115       * are not lost upon form submission
 116       *
 117       * @return  string  A string of hidden input form fields
 118       *
 119       * @since   2.5
 120       */
 121  	protected function getFields()
 122      {
 123          $fields = null;
 124  
 125          // Get the URI.
 126          $uri = JURI::getInstance(JRoute::_($this->query->toURI()));
 127          $uri->delVar('q');
 128          $uri->delVar('o');
 129          $uri->delVar('t');
 130          $uri->delVar('d1');
 131          $uri->delVar('d2');
 132          $uri->delVar('w1');
 133          $uri->delVar('w2');
 134  
 135          // Create hidden input elements for each part of the URI.
 136          foreach ($uri->getQuery(true) as $n => $v)
 137          {
 138              if (is_scalar($v))
 139              {
 140                  $fields .= '<input type="hidden" name="' . $n . '" value="' . $v . '" />';
 141              }
 142          }
 143  
 144          return $fields;
 145      }
 146  
 147      /**
 148       * Method to get the layout file for a search result object.
 149       *
 150       * @param   string  $layout  The layout file to check. [optional]
 151       *
 152       * @return  string  The layout file to use.
 153       *
 154       * @since   2.5
 155       */
 156  	protected function getLayoutFile($layout = null)
 157      {
 158          // Create and sanitize the file name.
 159          $file = $this->_layout . '_' . preg_replace('/[^A-Z0-9_\.-]/i', '', $layout);
 160  
 161          // Check if the file exists.
 162          jimport('joomla.filesystem.path');
 163          $filetofind = $this->_createFileName('template', array('name' => $file));
 164          $exists = JPath::find($this->_path['template'], $filetofind);
 165  
 166          return ($exists ? $layout : 'result');
 167      }
 168  
 169      /**
 170       * Prepares the document
 171       *
 172       * @param   FinderIndexerQuery  $query  The search query
 173       *
 174       * @return  void
 175       *
 176       * @since   2.5
 177       */
 178  	protected function prepareDocument($query)
 179      {
 180          $app = JFactory::getApplication();
 181          $menus = $app->getMenu();
 182          $pathway = $app->getPathway();
 183          $title = null;
 184  
 185          // Because the application sets a default page title,
 186          // we need to get it from the menu item itself
 187          $menu = $menus->getActive();
 188  
 189          if ($menu)
 190          {
 191              $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
 192          }
 193          else
 194          {
 195              $this->params->def('page_heading', JText::_('COM_FINDER_DEFAULT_PAGE_TITLE'));
 196          }
 197  
 198          $id = (int) @$menu->query['id'];
 199  
 200          $title = $this->params->get('page_title', '');
 201  
 202          if (empty($title))
 203          {
 204              $title = $app->getCfg('sitename');
 205          }
 206          elseif ($app->getCfg('sitename_pagetitles', 0) == 1)
 207          {
 208              $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
 209          }
 210          elseif ($app->getCfg('sitename_pagetitles', 0) == 2)
 211          {
 212              $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
 213          }
 214  
 215          $this->document->setTitle($title);
 216  
 217          if ($layout = $this->params->get('article_layout'))
 218          {
 219              $this->setLayout($layout);
 220          }
 221  
 222          // Configure the document meta-description.
 223          if (!empty($this->explained))
 224          {
 225              $explained = $this->escape(html_entity_decode(strip_tags($this->explained), ENT_QUOTES, 'UTF-8'));
 226              $this->document->setDescription($explained);
 227          }
 228  
 229          // Configure the document meta-keywords.
 230          if (!empty($query->highlight))
 231          {
 232              $this->document->setMetadata('keywords', implode(', ', $query->highlight));
 233          }
 234  
 235          if ($this->params->get('robots'))
 236          {
 237              $this->document->setMetadata('robots', $this->params->get('robots'));
 238          }
 239  
 240          // Add feed link to the document head.
 241          if ($this->params->get('show_feed_link', 1) == 1)
 242          {
 243              // Add the RSS link.
 244              $props = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
 245              $route = JRoute::_($this->query->toURI() . '&format=feed&type=rss');
 246              $this->document->addHeadLink($route, 'alternate', 'rel', $props);
 247  
 248              // Add the ATOM link.
 249              $props = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
 250              $route = JRoute::_($this->query->toURI() . '&format=feed&type=atom');
 251              $this->document->addHeadLink($route, 'alternate', 'rel', $props);
 252          }
 253      }
 254  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1