[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/components/com_contact/views/contact/ -> 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  require_once JPATH_COMPONENT.'/models/category.php';
  14  
  15  /**
  16   * HTML Contact View class for the Contact component
  17   *
  18   * @package        Joomla.Site
  19   * @subpackage    com_contact
  20   * @since         1.5
  21   */
  22  class ContactViewContact extends JView
  23  {
  24      protected $state;
  25      protected $form;
  26      protected $item;
  27      protected $return_page;
  28  
  29  	function display($tpl = null)
  30      {
  31          // Initialise variables.
  32          $app        = JFactory::getApplication();
  33          $user        = JFactory::getUser();
  34          $dispatcher = JDispatcher::getInstance();
  35          $state        = $this->get('State');
  36          $item        = $this->get('Item');
  37          $this->form    = $this->get('Form');
  38  
  39          // Get the parameters
  40          $params = JComponentHelper::getParams('com_contact');
  41  
  42          if ($item) {
  43              // If we found an item, merge the item parameters
  44              $params->merge($item->params);
  45  
  46              // Get Category Model data
  47              $categoryModel = JModel::getInstance('Category', 'ContactModel', array('ignore_request' => true));
  48              $categoryModel->setState('category.id', $item->catid);
  49              $categoryModel->setState('list.ordering', 'a.name');
  50              $categoryModel->setState('list.direction', 'asc');
  51              $categoryModel->setState('filter.published', 1);
  52  
  53              $contacts = $categoryModel->getItems();
  54          }
  55  
  56          // Check for errors.
  57          if (count($errors = $this->get('Errors'))) {
  58              JError::raiseWarning(500, implode("\n", $errors));
  59  
  60              return false;
  61          }
  62  
  63          // check if access is not public
  64          $groups    = $user->getAuthorisedViewLevels();
  65  
  66          $return = '';
  67  
  68          if ((!in_array($item->access, $groups)) || (!in_array($item->category_access, $groups))) {
  69              $uri        = JFactory::getURI();
  70              $return        = (string)$uri;
  71  
  72              JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
  73              return;
  74          }
  75  
  76          $options['category_id']    = $item->catid;
  77          $options['order by']    = 'a.default_con DESC, a.ordering ASC';
  78  
  79  
  80          // Handle email cloaking
  81          if ($item->email_to && $params->get('show_email')) {
  82              $item->email_to = JHtml::_('email.cloak', $item->email_to);
  83          }
  84              if ($params->get('show_street_address') || $params->get('show_suburb') || $params->get('show_state') || $params->get('show_postcode') || $params->get('show_country')) {
  85              if (!empty ($item->address) || !empty ($item->suburb) || !empty ($item->state) || !empty ($item->country) || !empty ($item->postcode)) {
  86                  $params->set('address_check', 1);
  87              }
  88          }
  89          else {
  90              $params->set('address_check', 0);
  91          }
  92  
  93  
  94          // Manage the display mode for contact detail groups
  95          switch ($params->get('contact_icons'))
  96          {
  97              case 1 :
  98                  // text
  99                  $params->set('marker_address',    JText::_('COM_CONTACT_ADDRESS').": ");
 100                  $params->set('marker_email',        JText::_('JGLOBAL_EMAIL').": ");
 101                  $params->set('marker_telephone',    JText::_('COM_CONTACT_TELEPHONE').": ");
 102                  $params->set('marker_fax',        JText::_('COM_CONTACT_FAX').": ");
 103                  $params->set('marker_mobile',        JText::_('COM_CONTACT_MOBILE').": ");
 104                  $params->set('marker_misc',        JText::_('COM_CONTACT_OTHER_INFORMATION').": ");
 105                  $params->set('marker_class',        'jicons-text');
 106                  break;
 107  
 108              case 2 :
 109                  // none
 110                  $params->set('marker_address',    '');
 111                  $params->set('marker_email',        '');
 112                  $params->set('marker_telephone',    '');
 113                  $params->set('marker_mobile',    '');
 114                  $params->set('marker_fax',        '');
 115                  $params->set('marker_misc',        '');
 116                  $params->set('marker_class',        'jicons-none');
 117                  break;
 118  
 119              default :
 120                  // icons
 121                  $image1 = JHtml::_('image', 'contacts/'.$params->get('icon_address', 'con_address.png'), JText::_('COM_CONTACT_ADDRESS').": ", NULL, true);
 122                  $image2 = JHtml::_('image', 'contacts/'.$params->get('icon_email', 'emailButton.png'), JText::_('JGLOBAL_EMAIL').": ", NULL, true);
 123                  $image3 = JHtml::_('image', 'contacts/'.$params->get('icon_telephone', 'con_tel.png'), JText::_('COM_CONTACT_TELEPHONE').": ", NULL, true);
 124                  $image4 = JHtml::_('image', 'contacts/'.$params->get('icon_fax', 'con_fax.png'), JText::_('COM_CONTACT_FAX').": ", NULL, true);
 125                  $image5 = JHtml::_('image', 'contacts/'.$params->get('icon_misc', 'con_info.png'), JText::_('COM_CONTACT_OTHER_INFORMATION').": ", NULL, true);
 126                  $image6 = JHtml::_('image', 'contacts/'.$params->get('icon_mobile', 'con_mobile.png'), JText::_('COM_CONTACT_MOBILE').": ", NULL, true);
 127  
 128                  $params->set('marker_address',    $image1);
 129                  $params->set('marker_email',        $image2);
 130                  $params->set('marker_telephone',    $image3);
 131                  $params->set('marker_fax',        $image4);
 132                  $params->set('marker_misc',        $image5);
 133                  $params->set('marker_mobile',        $image6);
 134                  $params->set('marker_class',        'jicons-icons');
 135                  break;
 136          }
 137  
 138          // Add links to contacts
 139          if ($params->get('show_contact_list') && count($contacts) > 1) {
 140              foreach($contacts as &$contact)
 141              {
 142                  $contact->link = JRoute::_(ContactHelperRoute::getContactRoute($contact->slug, $contact->catid));
 143              }
 144              $item->link = JRoute::_(ContactHelperRoute::getContactRoute($item->slug, $item->catid));
 145          }
 146  
 147          JHtml::_('behavior.formvalidation');
 148  
 149          //Escape strings for HTML output
 150          $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
 151  
 152          $this->assignRef('contact',        $item);
 153          $this->assignRef('params',        $params);
 154          $this->assignRef('return',        $return);
 155          $this->assignRef('state',         $state);
 156          $this->assignRef('item',         $item);
 157          $this->assignRef('user',         $user);
 158          $this->assignRef('contacts',     $contacts);
 159  
 160          // Override the layout only if this is not the active menu item
 161          // If it is the active menu item, then the view and item id will match
 162          $active    = $app->getMenu()->getActive();
 163          if ((!$active) || ((strpos($active->link, 'view=contact') === false) || (strpos($active->link, '&id=' . (string) $this->item->id) === false))) {
 164              if ($layout = $params->get('contact_layout')) {
 165                  $this->setLayout($layout);
 166              }
 167          }
 168          elseif (isset($active->query['layout'])) {
 169              // We need to set the layout in case this is an alternative menu item (with an alternative layout)
 170              $this->setLayout($active->query['layout']);
 171          }
 172  
 173          $this->_prepareDocument();
 174  
 175          parent::display($tpl);
 176      }
 177  
 178      /**
 179       * Prepares the document
 180       */
 181  	protected function _prepareDocument()
 182      {
 183          $app        = JFactory::getApplication();
 184          $menus        = $app->getMenu();
 185          $pathway    = $app->getPathway();
 186          $title         = null;
 187  
 188          // Because the application sets a default page title,
 189          // we need to get it from the menu item itself
 190          $menu = $menus->getActive();
 191  
 192          if ($menu) {
 193              $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
 194          }
 195          else {
 196              $this->params->def('page_heading', JText::_('COM_CONTACT_DEFAULT_PAGE_TITLE'));
 197          }
 198  
 199          $title = $this->params->get('page_title', '');
 200  
 201          $id = (int) @$menu->query['id'];
 202  
 203          // if the menu item does not concern this contact
 204          if ($menu && ($menu->query['option'] != 'com_contact' || $menu->query['view'] != 'contact' || $id != $this->item->id))
 205          {
 206  
 207              // If this is not a single contact menu item, set the page title to the contact title
 208              if ($this->item->name) {
 209                  $title = $this->item->name;
 210              }
 211              $path = array(array('title' => $this->contact->name, 'link' => ''));
 212              $category = JCategories::getInstance('Contact')->get($this->contact->catid);
 213  
 214              while ($category && ($menu->query['option'] != 'com_contact' || $menu->query['view'] == 'contact' || $id != $category->id) && $category->id > 1)
 215              {
 216                  $path[] = array('title' => $category->title, 'link' => ContactHelperRoute::getCategoryRoute($this->contact->catid));
 217                  $category = $category->getParent();
 218              }
 219  
 220              $path = array_reverse($path);
 221  
 222              foreach($path as $item)
 223              {
 224                  $pathway->addItem($item['title'], $item['link']);
 225              }
 226          }
 227  
 228          if (empty($title)) {
 229              $title = $app->getCfg('sitename');
 230          }
 231          elseif ($app->getCfg('sitename_pagetitles', 0) == 1) {
 232              $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
 233          }
 234          elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
 235              $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
 236          }
 237  
 238          if (empty($title)) {
 239              $title = $this->item->name;
 240          }
 241          $this->document->setTitle($title);
 242  
 243          if ($this->item->metadesc)
 244          {
 245              $this->document->setDescription($this->item->metadesc);
 246          }
 247          elseif (!$this->item->metadesc && $this->params->get('menu-meta_description'))
 248          {
 249              $this->document->setDescription($this->params->get('menu-meta_description'));
 250          }
 251  
 252          if ($this->item->metakey)
 253          {
 254              $this->document->setMetadata('keywords', $this->item->metakey);
 255          }
 256          elseif (!$this->item->metakey && $this->params->get('menu-meta_keywords'))
 257          {
 258              $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
 259          }
 260  
 261          if ($this->params->get('robots'))
 262          {
 263              $this->document->setMetadata('robots', $this->params->get('robots'));
 264          }
 265  
 266          $mdata = $this->item->metadata->toArray();
 267  
 268          foreach ($mdata as $k => $v)
 269          {
 270              if ($v) {
 271                  $this->document->setMetadata($k, $v);
 272              }
 273          }
 274      }
 275  }


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