PageRenderTime 62ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/ke2083/transfans.co.uk-website
PHP | 496 lines | 325 code | 82 blank | 89 comment | 60 complexity | 24ed2dd36b17e0351af8d4bf00a19d0a MD5 | raw file
  1. <?php
  2. /**
  3. * @package Joomla.Site
  4. * @subpackage com_contact
  5. *
  6. * @copyright Copyright (C) 2005 - 2018 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. /**
  11. * HTML Contact View class for the Contact component
  12. *
  13. * @since 1.5
  14. */
  15. class ContactViewContact extends JViewLegacy
  16. {
  17. /**
  18. * The item model state
  19. *
  20. * @var \Joomla\Registry\Registry
  21. * @since 1.6
  22. */
  23. protected $state;
  24. /**
  25. * The form object for the contact item
  26. *
  27. * @var JForm
  28. * @since 1.6
  29. */
  30. protected $form;
  31. /**
  32. * The item object details
  33. *
  34. * @var JObject
  35. * @since 1.6
  36. */
  37. protected $item;
  38. /**
  39. * The page to return to on sumission
  40. *
  41. * @var string
  42. * @since 1.6
  43. * @deprecated 4.0 Variable not used
  44. */
  45. protected $return_page;
  46. /**
  47. * Should we show a captcha form for the submission of the contact request?
  48. *
  49. * @var bool
  50. * @since 3.6.3
  51. */
  52. protected $captchaEnabled = false;
  53. /**
  54. * Execute and display a template script.
  55. *
  56. * @param string $tpl The name of the template file to parse; automatically searches through the template paths.
  57. *
  58. * @return mixed A string if successful, otherwise an Error object.
  59. */
  60. public function display($tpl = null)
  61. {
  62. $app = JFactory::getApplication();
  63. $user = JFactory::getUser();
  64. $item = $this->get('Item');
  65. $state = $this->get('State');
  66. // Get submitted values
  67. $data = $app->getUserState('com_contact.contact.data', array());
  68. // Add catid for selecting custom fields
  69. $data['catid'] = $item->catid;
  70. $app->setUserState('com_contact.contact.data', $data);
  71. $this->form = $this->get('Form');
  72. $params = $state->get('params');
  73. $temp = clone $params;
  74. $active = $app->getMenu()->getActive();
  75. if ($active)
  76. {
  77. // If the current view is the active item and a contact view for this contact, then the menu item params take priority
  78. if (strpos($active->link, 'view=contact') && strpos($active->link, '&id=' . (int) $item->id))
  79. {
  80. // $item->params are the contact params, $temp are the menu item params
  81. // Merge so that the menu item params take priority
  82. $item->params->merge($temp);
  83. }
  84. else
  85. {
  86. // Current view is not a single contact, so the contact params take priority here
  87. // Merge the menu item params with the contact params so that the contact params take priority
  88. $temp->merge($item->params);
  89. $item->params = $temp;
  90. }
  91. }
  92. else
  93. {
  94. // Merge so that contact params take priority
  95. $temp->merge($item->params);
  96. $item->params = $temp;
  97. }
  98. if ($item)
  99. {
  100. // Get Category Model data
  101. $categoryModel = JModelLegacy::getInstance('Category', 'ContactModel', array('ignore_request' => true));
  102. $categoryModel->setState('category.id', $item->catid);
  103. $categoryModel->setState('list.ordering', 'a.name');
  104. $categoryModel->setState('list.direction', 'asc');
  105. $categoryModel->setState('filter.published', 1);
  106. $contacts = $categoryModel->getItems();
  107. }
  108. // Check for errors.
  109. if (count($errors = $this->get('Errors')))
  110. {
  111. JError::raiseWarning(500, implode("\n", $errors));
  112. return false;
  113. }
  114. // Check if access is not public
  115. $groups = $user->getAuthorisedViewLevels();
  116. $return = '';
  117. if ((!in_array($item->access, $groups)) || (!in_array($item->category_access, $groups)))
  118. {
  119. $app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'error');
  120. $app->setHeader('status', 403, true);
  121. return false;
  122. }
  123. $options['category_id'] = $item->catid;
  124. $options['order by'] = 'a.default_con DESC, a.ordering ASC';
  125. /**
  126. * Handle email cloaking
  127. *
  128. * Keep a copy of the raw email address so it can
  129. * still be accessed in the layout if needed.
  130. */
  131. $item->email_raw = $item->email_to;
  132. if ($item->email_to && $item->params->get('show_email'))
  133. {
  134. $item->email_to = JHtml::_('email.cloak', $item->email_to, (bool) $item->params->get('add_mailto_link', true));
  135. }
  136. if ($item->params->get('show_street_address') || $item->params->get('show_suburb') || $item->params->get('show_state')
  137. || $item->params->get('show_postcode') || $item->params->get('show_country'))
  138. {
  139. if (!empty($item->address) || !empty($item->suburb) || !empty($item->state) || !empty($item->country) || !empty($item->postcode))
  140. {
  141. $item->params->set('address_check', 1);
  142. }
  143. }
  144. else
  145. {
  146. $item->params->set('address_check', 0);
  147. }
  148. // Manage the display mode for contact detail groups
  149. switch ($item->params->get('contact_icons'))
  150. {
  151. case 1 :
  152. // Text
  153. $item->params->set('marker_address', JText::_('COM_CONTACT_ADDRESS') . ': ');
  154. $item->params->set('marker_email', JText::_('JGLOBAL_EMAIL') . ': ');
  155. $item->params->set('marker_telephone', JText::_('COM_CONTACT_TELEPHONE') . ': ');
  156. $item->params->set('marker_fax', JText::_('COM_CONTACT_FAX') . ': ');
  157. $item->params->set('marker_mobile', JText::_('COM_CONTACT_MOBILE') . ': ');
  158. $item->params->set('marker_misc', JText::_('COM_CONTACT_OTHER_INFORMATION') . ': ');
  159. $item->params->set('marker_class', 'jicons-text');
  160. break;
  161. case 2 :
  162. // None
  163. $item->params->set('marker_address', '');
  164. $item->params->set('marker_email', '');
  165. $item->params->set('marker_telephone', '');
  166. $item->params->set('marker_mobile', '');
  167. $item->params->set('marker_fax', '');
  168. $item->params->set('marker_misc', '');
  169. $item->params->set('marker_class', 'jicons-none');
  170. break;
  171. default :
  172. if ($item->params->get('icon_address'))
  173. {
  174. $image1 = JHtml::_('image', $item->params->get('icon_address', 'con_address.png'), JText::_('COM_CONTACT_ADDRESS') . ': ', null, false);
  175. }
  176. else
  177. {
  178. $image1 = JHtml::_(
  179. 'image', 'contacts/' . $item->params->get('icon_address', 'con_address.png'), JText::_('COM_CONTACT_ADDRESS') . ': ', null, true
  180. );
  181. }
  182. if ($item->params->get('icon_email'))
  183. {
  184. $image2 = JHtml::_('image', $item->params->get('icon_email', 'emailButton.png'), JText::_('JGLOBAL_EMAIL') . ': ', null, false);
  185. }
  186. else
  187. {
  188. $image2 = JHtml::_('image', 'contacts/' . $item->params->get('icon_email', 'emailButton.png'), JText::_('JGLOBAL_EMAIL') . ': ', null, true);
  189. }
  190. if ($item->params->get('icon_telephone'))
  191. {
  192. $image3 = JHtml::_('image', $item->params->get('icon_telephone', 'con_tel.png'), JText::_('COM_CONTACT_TELEPHONE') . ': ', null, false);
  193. }
  194. else
  195. {
  196. $image3 = JHtml::_(
  197. 'image', 'contacts/' . $item->params->get('icon_telephone', 'con_tel.png'), JText::_('COM_CONTACT_TELEPHONE') . ': ', null, true
  198. );
  199. }
  200. if ($item->params->get('icon_fax'))
  201. {
  202. $image4 = JHtml::_('image', $item->params->get('icon_fax', 'con_fax.png'), JText::_('COM_CONTACT_FAX') . ': ', null, false);
  203. }
  204. else
  205. {
  206. $image4 = JHtml::_('image', 'contacts/' . $item->params->get('icon_fax', 'con_fax.png'), JText::_('COM_CONTACT_FAX') . ': ', null, true);
  207. }
  208. if ($item->params->get('icon_misc'))
  209. {
  210. $image5 = JHtml::_('image', $item->params->get('icon_misc', 'con_info.png'), JText::_('COM_CONTACT_OTHER_INFORMATION') . ': ', null, false);
  211. }
  212. else
  213. {
  214. $image5 = JHtml::_(
  215. 'image',
  216. 'contacts/' . $item->params->get('icon_misc', 'con_info.png'),
  217. JText::_('COM_CONTACT_OTHER_INFORMATION') . ': ', null, true
  218. );
  219. }
  220. if ($item->params->get('icon_mobile'))
  221. {
  222. $image6 = JHtml::_('image', $item->params->get('icon_mobile', 'con_mobile.png'), JText::_('COM_CONTACT_MOBILE') . ': ', null, false);
  223. }
  224. else
  225. {
  226. $image6 = JHtml::_(
  227. 'image', 'contacts/' . $item->params->get('icon_mobile', 'con_mobile.png'), JText::_('COM_CONTACT_MOBILE') . ': ', null, true
  228. );
  229. }
  230. $item->params->set('marker_address', $image1);
  231. $item->params->set('marker_email', $image2);
  232. $item->params->set('marker_telephone', $image3);
  233. $item->params->set('marker_fax', $image4);
  234. $item->params->set('marker_misc', $image5);
  235. $item->params->set('marker_mobile', $image6);
  236. $item->params->set('marker_class', 'jicons-icons');
  237. break;
  238. }
  239. // Add links to contacts
  240. if ($item->params->get('show_contact_list') && count($contacts) > 1)
  241. {
  242. foreach ($contacts as &$contact)
  243. {
  244. $contact->link = JRoute::_(ContactHelperRoute::getContactRoute($contact->slug, $contact->catid), false);
  245. }
  246. $item->link = JRoute::_(ContactHelperRoute::getContactRoute($item->slug, $item->catid), false);
  247. }
  248. // Process the content plugins
  249. JPluginHelper::importPlugin('content');
  250. $dispatcher = JEventDispatcher::getInstance();
  251. $offset = $state->get('list.offset');
  252. // Fix for where some plugins require a text attribute
  253. $item->text = null;
  254. if (!empty($item->misc))
  255. {
  256. $item->text = $item->misc;
  257. }
  258. $dispatcher->trigger('onContentPrepare', array('com_contact.contact', &$item, &$item->params, $offset));
  259. // Store the events for later
  260. $item->event = new stdClass;
  261. $results = $dispatcher->trigger('onContentAfterTitle', array('com_contact.contact', &$item, &$item->params, $offset));
  262. $item->event->afterDisplayTitle = trim(implode("\n", $results));
  263. $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_contact.contact', &$item, &$item->params, $offset));
  264. $item->event->beforeDisplayContent = trim(implode("\n", $results));
  265. $results = $dispatcher->trigger('onContentAfterDisplay', array('com_contact.contact', &$item, &$item->params, $offset));
  266. $item->event->afterDisplayContent = trim(implode("\n", $results));
  267. if (!empty($item->text))
  268. {
  269. $item->misc = $item->text;
  270. }
  271. $contactUser = null;
  272. if ($item->params->get('show_user_custom_fields') && $item->user_id && $contactUser = JFactory::getUser($item->user_id))
  273. {
  274. $contactUser->text = '';
  275. JEventDispatcher::getInstance()->trigger('onContentPrepare', array ('com_users.user', &$contactUser, &$item->params, 0));
  276. if (!isset($contactUser->jcfields))
  277. {
  278. $contactUser->jcfields = array();
  279. }
  280. }
  281. // Escape strings for HTML output
  282. $this->pageclass_sfx = htmlspecialchars($item->params->get('pageclass_sfx'));
  283. $this->contact = &$item;
  284. $this->params = &$item->params;
  285. $this->return = &$return;
  286. $this->state = &$state;
  287. $this->item = &$item;
  288. $this->user = &$user;
  289. $this->contacts = &$contacts;
  290. $this->contactUser = $contactUser;
  291. $item->tags = new JHelperTags;
  292. $item->tags->getItemTags('com_contact.contact', $this->item->id);
  293. // Override the layout only if this is not the active menu item
  294. // If it is the active menu item, then the view and item id will match
  295. if ((!$active) || ((strpos($active->link, 'view=contact') === false) || (strpos($active->link, '&id=' . (string) $this->item->id) === false)))
  296. {
  297. if (($layout = $item->params->get('contact_layout')))
  298. {
  299. $this->setLayout($layout);
  300. }
  301. }
  302. elseif (isset($active->query['layout']))
  303. {
  304. // We need to set the layout in case this is an alternative menu item (with an alternative layout)
  305. $this->setLayout($active->query['layout']);
  306. }
  307. $model = $this->getModel();
  308. $model->hit();
  309. $captchaSet = $item->params->get('captcha', JFactory::getApplication()->get('captcha', '0'));
  310. foreach (JPluginHelper::getPlugin('captcha') as $plugin)
  311. {
  312. if ($captchaSet === $plugin->name)
  313. {
  314. $this->captchaEnabled = true;
  315. break;
  316. }
  317. }
  318. $this->_prepareDocument();
  319. return parent::display($tpl);
  320. }
  321. /**
  322. * Prepares the document
  323. *
  324. * @return void
  325. *
  326. * @since 1.6
  327. */
  328. protected function _prepareDocument()
  329. {
  330. $app = JFactory::getApplication();
  331. $menus = $app->getMenu();
  332. $pathway = $app->getPathway();
  333. $title = null;
  334. // Because the application sets a default page title,
  335. // we need to get it from the menu item itself
  336. $menu = $menus->getActive();
  337. if ($menu)
  338. {
  339. $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
  340. }
  341. else
  342. {
  343. $this->params->def('page_heading', JText::_('COM_CONTACT_DEFAULT_PAGE_TITLE'));
  344. }
  345. $title = $this->params->get('page_title', '');
  346. $id = (int) @$menu->query['id'];
  347. // If the menu item does not concern this contact
  348. if ($menu && ($menu->query['option'] !== 'com_contact' || $menu->query['view'] !== 'contact' || $id != $this->item->id))
  349. {
  350. // If this is not a single contact menu item, set the page title to the contact title
  351. if ($this->item->name)
  352. {
  353. $title = $this->item->name;
  354. }
  355. $path = array(array('title' => $this->contact->name, 'link' => ''));
  356. $category = JCategories::getInstance('Contact')->get($this->contact->catid);
  357. while ($category && ($menu->query['option'] !== 'com_contact' || $menu->query['view'] === 'contact' || $id != $category->id) && $category->id > 1)
  358. {
  359. $path[] = array('title' => $category->title, 'link' => ContactHelperRoute::getCategoryRoute($this->contact->catid));
  360. $category = $category->getParent();
  361. }
  362. $path = array_reverse($path);
  363. foreach ($path as $item)
  364. {
  365. $pathway->addItem($item['title'], $item['link']);
  366. }
  367. }
  368. if (empty($title))
  369. {
  370. $title = $app->get('sitename');
  371. }
  372. elseif ($app->get('sitename_pagetitles', 0) == 1)
  373. {
  374. $title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
  375. }
  376. elseif ($app->get('sitename_pagetitles', 0) == 2)
  377. {
  378. $title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
  379. }
  380. if (empty($title))
  381. {
  382. $title = $this->item->name;
  383. }
  384. $this->document->setTitle($title);
  385. if ($this->item->metadesc)
  386. {
  387. $this->document->setDescription($this->item->metadesc);
  388. }
  389. elseif ($this->params->get('menu-meta_description'))
  390. {
  391. $this->document->setDescription($this->params->get('menu-meta_description'));
  392. }
  393. if ($this->item->metakey)
  394. {
  395. $this->document->setMetadata('keywords', $this->item->metakey);
  396. }
  397. elseif ($this->params->get('menu-meta_keywords'))
  398. {
  399. $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
  400. }
  401. if ($this->params->get('robots'))
  402. {
  403. $this->document->setMetadata('robots', $this->params->get('robots'));
  404. }
  405. $mdata = $this->item->metadata->toArray();
  406. foreach ($mdata as $k => $v)
  407. {
  408. if ($v)
  409. {
  410. $this->document->setMetadata($k, $v);
  411. }
  412. }
  413. }
  414. }