PageRenderTime 154ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_contact/views/contact/view.html.php

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