Joomla! PHP Cross Reference Web Portals

Source: /components/com_contact/views/contact/view.html.php - 271 lines - 8930 bytes - Summary - Text - Print

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

title

Description

title

Description

title

Description

title

title

Body