PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

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