Source for file view.html.php

Documentation is available at view.html.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_contact
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 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. {
  22.     protected $state;
  23.  
  24.     protected $form;
  25.  
  26.     protected $item;
  27.  
  28.     protected $return_page;
  29.  
  30.     /**
  31.      * Execute and display a template script.
  32.      *
  33.      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  34.      *
  35.      * @return  mixed  A string if successful, otherwise a Error object.
  36.      */
  37.     public function display($tpl null)
  38.     {
  39.         $app        JFactory::getApplication();
  40.         $user        JFactory::getUser();
  41.         $state        $this->get('State');
  42.         $item        $this->get('Item');
  43.         $this->form    = $this->get('Form');
  44.  
  45.         // Get the parameters
  46.         $params JComponentHelper::getParams('com_contact');
  47.  
  48.         if ($item)
  49.         {
  50.             // If we found an item, merge the item parameters
  51.             $params->merge($item->params);
  52.  
  53.             // Get Category Model data
  54.             $categoryModel JModelLegacy::getInstance('Category''ContactModel'array('ignore_request' => true));
  55.             $categoryModel->setState('category.id'$item->catid);
  56.             $categoryModel->setState('list.ordering''a.name');
  57.             $categoryModel->setState('list.direction''asc');
  58.             $categoryModel->setState('filter.published'1);
  59.  
  60.             $contacts $categoryModel->getItems();
  61.         }
  62.  
  63.         // Check for errors.
  64.         if (count($errors $this->get('Errors')))
  65.         {
  66.             JError::raiseWarning(500implode("\n"$errors));
  67.  
  68.             return false;
  69.         }
  70.  
  71.         // check if access is not public
  72.         $groups    $user->getAuthorisedViewLevels();
  73.  
  74.         $return '';
  75.  
  76.         if ((!in_array($item->access$groups)) || (!in_array($item->category_access$groups)))
  77.         {
  78.             JError::raiseWarning(403JText::_('JERROR_ALERTNOAUTHOR'));
  79.             return;
  80.         }
  81.  
  82.         $options['category_id']    $item->catid;
  83.         $options['order by']    'a.default_con DESC, a.ordering ASC';
  84.  
  85.         // Handle email cloaking
  86.         if ($item->email_to && $params->get('show_email'))
  87.         {
  88.             $item->email_to JHtml::_('email.cloak'$item->email_to);
  89.         }
  90.             if ($params->get('show_street_address'|| $params->get('show_suburb'|| $params->get('show_state'|| $params->get('show_postcode'|| $params->get('show_country'))
  91.             {
  92.                 if (!empty ($item->address|| !empty ($item->suburb|| !empty ($item->state|| !empty ($item->country|| !empty ($item->postcode))
  93.                 {
  94.                     $params->set('address_check'1);
  95.                 }
  96.             }
  97.         else
  98.         {
  99.             $params->set('address_check'0);
  100.         }
  101.  
  102.         // Manage the display mode for contact detail groups
  103.         switch ($params->get('contact_icons'))
  104.         {
  105.             case :
  106.                 // text
  107.                 $params->set('marker_address',   JText::_('COM_CONTACT_ADDRESS'": ");
  108.                 $params->set('marker_email',     JText::_('JGLOBAL_EMAIL'": ");
  109.                 $params->set('marker_telephone'JText::_('COM_CONTACT_TELEPHONE'": ");
  110.                 $params->set('marker_fax',       JText::_('COM_CONTACT_FAX'": ");
  111.                 $params->set('marker_mobile',    JText::_('COM_CONTACT_MOBILE'": ");
  112.                 $params->set('marker_misc',      JText::_('COM_CONTACT_OTHER_INFORMATION'": ");
  113.                 $params->set('marker_class',     'jicons-text');
  114.                 break;
  115.  
  116.             case :
  117.                 // none
  118.                 $params->set('marker_address',   '');
  119.                 $params->set('marker_email',     '');
  120.                 $params->set('marker_telephone''');
  121.                 $params->set('marker_mobile',    '');
  122.                 $params->set('marker_fax',       '');
  123.                 $params->set('marker_misc',      '');
  124.                 $params->set('marker_class',     'jicons-none');
  125.                 break;
  126.  
  127.             default :
  128.                 if ($params->get('icon_address'))
  129.                 {
  130.                     $image1 JHtml::_('image'$params->get('icon_address''con_address.png')JText::_('COM_CONTACT_ADDRESS').": "nullfalse);
  131.                 }
  132.                 else
  133.                 {
  134.                     $image1 JHtml::_('image''contacts/'.$params->get('icon_address''con_address.png')JText::_('COM_CONTACT_ADDRESS').": "nulltrue);
  135.                 }
  136.  
  137.                 if ($params->get('icon_email'))
  138.                 {
  139.                     $image2 JHtml::_('image'$params->get('icon_email''emailButton.png')JText::_('JGLOBAL_EMAIL').": "nullfalse);
  140.                 }
  141.                 else
  142.                 {
  143.                     $image2 JHtml::_('image''contacts/'.$params->get('icon_email''emailButton.png')JText::_('JGLOBAL_EMAIL').": "nulltrue);
  144.                 }
  145.  
  146.                 if ($params->get('icon_telephone'))
  147.                 {
  148.                     $image3 JHtml::_('image'$params->get('icon_telephone''con_tel.png')JText::_('COM_CONTACT_TELEPHONE').": "nullfalse);
  149.                 }
  150.                 else
  151.                 {
  152.                     $image3 JHtml::_('image''contacts/'.$params->get('icon_telephone''con_tel.png')JText::_('COM_CONTACT_TELEPHONE').": "nulltrue);
  153.                 }
  154.  
  155.                 if ($params->get('icon_fax'))
  156.                 {
  157.                     $image4 JHtml::_('image'$params->get('icon_fax''con_fax.png')JText::_('COM_CONTACT_FAX').": "nullfalse);
  158.                 }
  159.                 else
  160.                 {
  161.                     $image4 JHtml::_('image''contacts/'.$params->get('icon_fax''con_fax.png')JText::_('COM_CONTACT_FAX').": "nulltrue);
  162.                 }
  163.  
  164.                 if ($params->get('icon_misc'))
  165.                 {
  166.                     $image5 JHtml::_('image'$params->get('icon_misc''con_info.png')JText::_('COM_CONTACT_OTHER_INFORMATION').": "nullfalse);
  167.                 }
  168.                 else
  169.                 {
  170.                     $image5 JHtml::_('image''contacts/'.$params->get('icon_misc''con_info.png')JText::_('COM_CONTACT_OTHER_INFORMATION').": "nulltrue);
  171.                 }
  172.  
  173.                 if ($params->get('icon_mobile'))
  174.                 {
  175.                     $image6 JHtml::_('image'$params->get('icon_mobile''con_mobile.png')JText::_('COM_CONTACT_MOBILE').": "nullfalse);
  176.                 }
  177.                 else
  178.                 {
  179.                     $image6 JHtml::_('image''contacts/'.$params->get('icon_mobile''con_mobile.png')JText::_('COM_CONTACT_MOBILE').": "nulltrue);
  180.                 }
  181.  
  182.                 $params->set('marker_address',   $image1);
  183.                 $params->set('marker_email',     $image2);
  184.                 $params->set('marker_telephone'$image3);
  185.                 $params->set('marker_fax',       $image4);
  186.                 $params->set('marker_misc',      $image5);
  187.                 $params->set('marker_mobile',    $image6);
  188.                 $params->set('marker_class',     'jicons-icons');
  189.                 break;
  190.         }
  191.  
  192.         // Add links to contacts
  193.         if ($params->get('show_contact_list'&& count($contacts1)
  194.         {
  195.             foreach ($contacts as &$contact)
  196.             {
  197.                 $contact->link JRoute::_(ContactHelperRoute::getContactRoute($contact->slug$contact->catid));
  198.             }
  199.             $item->link JRoute::_(ContactHelperRoute::getContactRoute($item->slug$item->catid));
  200.         }
  201.  
  202.         JHtml::_('behavior.formvalidation');
  203.  
  204.         //Escape strings for HTML output
  205.         $this->pageclass_sfx htmlspecialchars($params->get('pageclass_sfx'));
  206.  
  207.         $this->contact  &$item;
  208.         $this->params   &$params;
  209.         $this->return   &$return;
  210.         $this->state    = &$state;
  211.         $this->item     = &$item;
  212.         $this->user     &$user;
  213.         $this->contacts &$contacts;
  214.  
  215.         $item->tags new JHelperTags;
  216.         $item->tags->getItemTags('com_contact.contact'$this->item->id);
  217.  
  218.         // Override the layout only if this is not the active menu item
  219.         // If it is the active menu item, then the view and item id will match
  220.         $active    $app->getMenu()->getActive();
  221.         if ((!$active|| ((strpos($active->link'view=contact'=== false|| (strpos($active->link'&id=' . (string) $this->item->id=== false)))
  222.         {
  223.             if ($layout $params->get('contact_layout'))
  224.             {
  225.                 $this->setLayout($layout);
  226.             }
  227.         }
  228.         elseif (isset($active->query['layout']))
  229.         {
  230.             // We need to set the layout in case this is an alternative menu item (with an alternative layout)
  231.             $this->setLayout($active->query['layout']);
  232.         }
  233.  
  234.         $model $this->getModel();
  235.         $model->hit();
  236.         $this->_prepareDocument();
  237.  
  238.         return parent::display($tpl);
  239.     }
  240.  
  241.     /**
  242.      * Prepares the document
  243.      */
  244.     protected function _prepareDocument()
  245.     {
  246.         $app        JFactory::getApplication();
  247.         $menus        $app->getMenu();
  248.         $pathway    $app->getPathway();
  249.         $title         null;
  250.  
  251.         // Because the application sets a default page title,
  252.         // we need to get it from the menu item itself
  253.         $menu $menus->getActive();
  254.  
  255.         if ($menu)
  256.         {
  257.             $this->params->def('page_heading'$this->params->get('page_title'$menu->title));
  258.         }
  259.         else
  260.         {
  261.             $this->params->def('page_heading'JText::_('COM_CONTACT_DEFAULT_PAGE_TITLE'));
  262.         }
  263.  
  264.         $title $this->params->get('page_title''');
  265.  
  266.         $id = (int) @$menu->query['id'];
  267.  
  268.         // if the menu item does not concern this contact
  269.         if ($menu && ($menu->query['option'!= 'com_contact' || $menu->query['view'!= 'contact' || $id != $this->item->id))
  270.         {
  271.  
  272.             // If this is not a single contact menu item, set the page title to the contact title
  273.             if ($this->item->name)
  274.             {
  275.                 $title $this->item->name;
  276.             }
  277.             $path array(array('title' => $this->contact->name'link' => ''));
  278.             $category JCategories::getInstance('Contact')->get($this->contact->catid);
  279.  
  280.             while ($category && ($menu->query['option'!= 'com_contact' || $menu->query['view'== 'contact' || $id != $category->id&& $category->id 1)
  281.             {
  282.                 $path[array('title' => $category->title'link' => ContactHelperRoute::getCategoryRoute($this->contact->catid));
  283.                 $category $category->getParent();
  284.             }
  285.  
  286.             $path array_reverse($path);
  287.  
  288.             foreach ($path as $item)
  289.             {
  290.                 $pathway->addItem($item['title']$item['link']);
  291.             }
  292.         }
  293.  
  294.         if (empty($title))
  295.         {
  296.             $title $app->getCfg('sitename');
  297.         }
  298.         elseif ($app->getCfg('sitename_pagetitles'0== 1)
  299.         {
  300.             $title JText::sprintf('JPAGETITLE'$app->getCfg('sitename')$title);
  301.         }
  302.         elseif ($app->getCfg('sitename_pagetitles'0== 2)
  303.         {
  304.             $title JText::sprintf('JPAGETITLE'$title$app->getCfg('sitename'));
  305.         }
  306.  
  307.         if (empty($title))
  308.         {
  309.             $title $this->item->name;
  310.         }
  311.         $this->document->setTitle($title);
  312.  
  313.         if ($this->item->metadesc)
  314.         {
  315.             $this->document->setDescription($this->item->metadesc);
  316.         }
  317.         elseif (!$this->item->metadesc && $this->params->get('menu-meta_description'))
  318.         {
  319.             $this->document->setDescription($this->params->get('menu-meta_description'));
  320.         }
  321.  
  322.         if ($this->item->metakey)
  323.         {
  324.             $this->document->setMetadata('keywords'$this->item->metakey);
  325.         }
  326.         elseif (!$this->item->metakey && $this->params->get('menu-meta_keywords'))
  327.         {
  328.             $this->document->setMetadata('keywords'$this->params->get('menu-meta_keywords'));
  329.         }
  330.  
  331.         if ($this->params->get('robots'))
  332.         {
  333.             $this->document->setMetadata('robots'$this->params->get('robots'));
  334.         }
  335.  
  336.         $mdata $this->item->metadata->toArray();
  337.  
  338.         foreach ($mdata as $k => $v)
  339.         {
  340.             if ($v)
  341.             {
  342.                 $this->document->setMetadata($k$v);
  343.             }
  344.         }
  345.     }
  346. }

Documentation generated on Tue, 19 Nov 2013 15:17:14 +0100 by phpDocumentor 1.4.3