[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/components/com_contact/views/category/ -> view.html.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Site
   4   * @subpackage    com_contact
   5   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   6   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  // No direct access
  10  defined('_JEXEC') or die;
  11  
  12  jimport('joomla.application.component.view');
  13  
  14  /**
  15   * HTML View class for the Contacts component
  16   *
  17   * @package        Joomla.Site
  18   * @subpackage    com_contact
  19   * @since        1.5
  20   */
  21  class ContactViewCategory extends JView
  22  {
  23      protected $state;
  24      protected $items;
  25      protected $category;
  26      protected $categories;
  27      protected $pagination;
  28  
  29  	function display($tpl = null)
  30      {
  31          $app        = JFactory::getApplication();
  32          $params        = $app->getParams();
  33  
  34          // Get some data from the models
  35          $state        = $this->get('State');
  36          $items        = $this->get('Items');
  37          $category    = $this->get('Category');
  38          $children    = $this->get('Children');
  39          $parent     = $this->get('Parent');
  40          $pagination    = $this->get('Pagination');
  41  
  42          // Check for errors.
  43          if (count($errors = $this->get('Errors'))) {
  44              JError::raiseError(500, implode("\n", $errors));
  45              return false;
  46          }
  47  
  48          if ($category == false) {
  49              return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
  50          }
  51  
  52          if ($parent == false) {
  53              return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
  54          }
  55  
  56          // Check whether category access level allows access.
  57          $user    = JFactory::getUser();
  58          $groups    = $user->getAuthorisedViewLevels();
  59          if (!in_array($category->access, $groups)) {
  60              return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
  61          }
  62  
  63          // Prepare the data.
  64          // Compute the contact slug.
  65          for ($i = 0, $n = count($items); $i < $n; $i++)
  66          {
  67              $item        = &$items[$i];
  68              $item->slug    = $item->alias ? ($item->id.':'.$item->alias) : $item->id;
  69              $temp        = new JRegistry();
  70              $temp->loadString($item->params);
  71              $item->params = clone($params);
  72              $item->params->merge($temp);
  73  
  74              if ($item->params->get('show_email', 0) == 1) {
  75                  $item->email_to = trim($item->email_to);
  76  
  77                  if (!empty($item->email_to) && JMailHelper::isEmailAddress($item->email_to)) {
  78                      $item->email_to = JHtml::_('email.cloak', $item->email_to);
  79                  }
  80                  else {
  81                      $item->email_to = '';
  82                  }
  83              }
  84          }
  85  
  86          // Setup the category parameters.
  87          $cparams = $category->getParams();
  88          $category->params = clone($params);
  89          $category->params->merge($cparams);
  90          $children = array($category->id => $children);
  91  
  92          $maxLevel = $params->get('maxLevel', -1);
  93          $this->assignRef('maxLevel',    $maxLevel);
  94          $this->assignRef('state',        $state);
  95          $this->assignRef('items',        $items);
  96          $this->assignRef('category',    $category);
  97          $this->assignRef('children',    $children);
  98          $this->assignRef('params',        $params);
  99          $this->assignRef('parent',        $parent);
 100          $this->assignRef('pagination',    $pagination);
 101  
 102          //Escape strings for HTML output
 103          $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx'));
 104  
 105          // Check for layout override only if this is not the active menu item
 106          // If it is the active menu item, then the view and category id will match
 107          $active    = $app->getMenu()->getActive();
 108          if ((!$active) || ((strpos($active->link, 'view=category') === false) || (strpos($active->link, '&id=' . (string) $this->category->id) === false))) {
 109              if ($layout = $category->params->get('category_layout')) {
 110                  $this->setLayout($layout);
 111              }
 112          }
 113          elseif (isset($active->query['layout'])) {
 114              // We need to set the layout in case this is an alternative menu item (with an alternative layout)
 115              $this->setLayout($active->query['layout']);
 116          }
 117  
 118          $this->_prepareDocument();
 119  
 120          parent::display($tpl);
 121      }
 122  
 123      /**
 124       * Prepares the document
 125       */
 126  	protected function _prepareDocument()
 127      {
 128          $app        = JFactory::getApplication();
 129          $menus        = $app->getMenu();
 130          $pathway    = $app->getPathway();
 131          $title         = null;
 132  
 133          // Because the application sets a default page title,
 134          // we need to get it from the menu item itself
 135          $menu = $menus->getActive();
 136  
 137          if ($menu) {
 138              $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
 139          }
 140          else {
 141              $this->params->def('page_heading', JText::_('COM_CONTACT_DEFAULT_PAGE_TITLE'));
 142          }
 143  
 144          $id = (int) @$menu->query['id'];
 145  
 146          if ($menu && ($menu->query['option'] != 'com_contact' || $menu->query['view'] == 'contact' || $id != $this->category->id)) {
 147              $path = array(array('title' => $this->category->title, 'link' => ''));
 148              $category = $this->category->getParent();
 149  
 150              while (($menu->query['option'] != 'com_contact' || $menu->query['view'] == 'contact' || $id != $category->id) && $category->id > 1)
 151              {
 152                  $path[] = array('title' => $category->title, 'link' => ContactHelperRoute::getCategoryRoute($category->id));
 153                  $category = $category->getParent();
 154              }
 155  
 156              $path = array_reverse($path);
 157  
 158              foreach ($path as $item)
 159              {
 160                  $pathway->addItem($item['title'], $item['link']);
 161              }
 162          }
 163  
 164          $title = $this->params->get('page_title', '');
 165  
 166          if (empty($title)) {
 167              $title = $app->getCfg('sitename');
 168          }
 169          elseif ($app->getCfg('sitename_pagetitles', 0) == 1) {
 170              $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
 171          }
 172          elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
 173              $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
 174          }
 175  
 176          $this->document->setTitle($title);
 177  
 178          if ($this->category->metadesc)
 179          {
 180              $this->document->setDescription($this->category->metadesc);
 181          }
 182          elseif (!$this->category->metadesc && $this->params->get('menu-meta_description'))
 183          {
 184              $this->document->setDescription($this->params->get('menu-meta_description'));
 185          }
 186  
 187          if ($this->category->metakey)
 188          {
 189              $this->document->setMetadata('keywords', $this->category->metakey);
 190          }
 191          elseif (!$this->category->metakey && $this->params->get('menu-meta_keywords'))
 192          {
 193              $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
 194          }
 195  
 196          if ($this->params->get('robots'))
 197          {
 198              $this->document->setMetadata('robots', $this->params->get('robots'));
 199          }
 200  
 201          if ($app->getCfg('MetaAuthor') == '1') {
 202              $this->document->setMetaData('author', $this->category->getMetadata()->get('author'));
 203          }
 204  
 205          $mdata = $this->category->getMetadata()->toArray();
 206  
 207          foreach ($mdata as $k => $v)
 208          {
 209              if ($v) {
 210                  $this->document->setMetadata($k, $v);
 211              }
 212          }
 213  
 214          // Add alternative feed link
 215          if ($this->params->get('show_feed_link', 1) == 1)
 216          {
 217              $link    = '&format=feed&limitstart=';
 218              $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
 219              $this->document->addHeadLink(JRoute::_($link.'&type=rss'), 'alternate', 'rel', $attribs);
 220              $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
 221              $this->document->addHeadLink(JRoute::_($link.'&type=atom'), 'alternate', 'rel', $attribs);
 222          }
 223      }
 224  }


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