PageRenderTime 157ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/cosmocommerce/joomla
PHP | 198 lines | 137 code | 29 blank | 32 comment | 37 complexity | 7f2ee3270c5653a3d34d6c64dc2b1df0 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Site
  5. * @subpackage Contact
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. // No direct access
  10. defined('_JEXEC') or die;
  11. jimport('joomla.application.component.view');
  12. /**
  13. * @package Joomla.Site
  14. * @subpackage Contacts
  15. */
  16. class ContactViewContact extends JView
  17. {
  18. protected $state = null;
  19. protected $contact = null;
  20. function display($tpl = null)
  21. {
  22. $app = &JFactory::getApplication();
  23. $user = &JFactory::getUser();
  24. $pathway = &$app->getPathway();
  25. $document = & JFactory::getDocument();
  26. $state = $this->get('State');
  27. $contact = $this->get('Contact');
  28. // report any errors and exit if they exist
  29. $this->reportErrors($this->get('Errors'));
  30. // Get the parameters of the active menu item
  31. $menus = &JSite::getMenu();
  32. $menu = $menus->getActive();
  33. $pparams = $this->getModel('contact')->getState()->params;
  34. // check if access is registered/special
  35. $groups = $user->authorisedLevels();
  36. $return ="";
  37. if ((!in_array($contact->access, $groups)) || (!in_array($contact->category_access, $groups))) {
  38. $uri = JFactory::getURI();
  39. $return = (string)$uri;
  40. $url = 'index.php?option=com_users&view=login';
  41. $url .= '&return='.base64_encode($return);
  42. $app->redirect($url, JText::_('YOU_MUST_LOGIN_FIRST'));
  43. }
  44. $options['category_id'] = $contact->catid;
  45. $options['order by'] = 'cd.default_con DESC, cd.ordering ASC';
  46. $contacts = &$this->getModel('Category')->getContacts($options);
  47. // Set the document page title
  48. // because the application sets a default page title, we need to get it
  49. // right from the menu item itself
  50. if (is_object($menu) && isset($menu->query['view']) && $menu->query['view'] == 'contact' && isset($menu->query['id']) && $menu->query['id'] == $contact->id) {
  51. $menu_params = new JParameter($menu->params);
  52. if (!$menu_params->get('page_title')) {
  53. $pparams->set('page_title', $contact->name);
  54. }
  55. } else {
  56. $pparams->set('page_title', $contact->name);
  57. }
  58. $document->setTitle($pparams->get('page_title'));
  59. //set breadcrumbs
  60. if (isset($menu) && isset($menu->query['view']) && $menu->query['view'] != 'contact'){
  61. $pathway->addItem($contact->name, '');
  62. }
  63. // Make contact parameters available to views
  64. $contact->params = new JParameter($contact->params);
  65. // Handle email cloaking
  66. if ($contact->email_to && $pparams->get('show_email')) {
  67. $contact->email_to = JHtml::_('email.cloak', $contact->email_to);
  68. }
  69. if ($pparams->get('show_street_address') || $pparams->get('show_suburb') || $pparams->get('show_state') || $pparams->get('show_postcode') || $pparams->get('show_country'))
  70. {
  71. if (!empty ($contact->address) || !empty ($contact->suburb) || !empty ($contact->state) || !empty ($contact->country) || !empty ($contact->postcode)) {
  72. $pparams->set('address_check', 1);
  73. }
  74. } else {
  75. $pparams->set('address_check', 0);
  76. }
  77. // Manage the display mode for contact detail groups
  78. switch ($pparams->get('contact_icons'))
  79. {
  80. case 1 :
  81. // text
  82. $pparams->set('marker_address', JText::_('Address').": ");
  83. $pparams->set('marker_email', JText::_('Email').": ");
  84. $pparams->set('marker_telephone', JText::_('Telephone').": ");
  85. $pparams->set('marker_fax', JText::_('Fax').": ");
  86. $pparams->set('marker_mobile', JText::_('Mobile').": ");
  87. $pparams->set('marker_misc', JText::_('Information').": ");
  88. $pparams->set('marker_class', 'jicons-text');
  89. break;
  90. case 2 :
  91. // none
  92. $pparams->set('marker_address', '');
  93. $pparams->set('marker_email', '');
  94. $pparams->set('marker_telephone', '');
  95. $pparams->set('marker_mobile', '');
  96. $pparams->set('marker_fax', '');
  97. $pparams->set('marker_misc', '');
  98. $pparams->set('marker_class', 'jicons-none');
  99. break;
  100. default :
  101. // icons
  102. $image1 = JHtml::_('image', 'contacts/'.$pparams->get('icon_address','con_address.png'), JText::_('Address').": ", NULL, true);
  103. $image2 = JHtml::_('image', 'contacts/'.$pparams->get('icon_email','emailButton.png'), JText::_('Email').": ", NULL, true);
  104. $image3 = JHtml::_('image', 'contacts/'.$pparams->get('icon_telephone','con_tel.png'), JText::_('Telephone').": ", NULL, true);
  105. $image4 = JHtml::_('image', 'contacts/'.$pparams->get('icon_fax','con_fax.png'), JText::_('Fax').": ", NULL, true);
  106. $image5 = JHtml::_('image', 'contacts/'.$pparams->get('icon_misc','con_info.png'), JText::_('Information').": ", NULL, true);
  107. $image6 = JHtml::_('image', 'contacts/'.$pparams->get('icon_mobile','con_mobile.png'), JText::_('Mobile').": ", NULL, true);
  108. $pparams->set('marker_address', $image1);
  109. $pparams->set('marker_email', $image2);
  110. $pparams->set('marker_telephone', $image3);
  111. $pparams->set('marker_fax', $image4);
  112. $pparams->set('marker_misc', $image5);
  113. $pparams->set('marker_mobile', $image6);
  114. $pparams->set('marker_class', 'jicons-icons');
  115. break;
  116. }
  117. // Use link labels from contact if blank in params
  118. $loopArray = array('a','b','c','d','e');
  119. foreach ($loopArray as $letter) {
  120. $thisLable = 'link'.$letter.'_name';
  121. $thisLink = 'link'.$letter;
  122. if (!$pparams->get($thisLable)) {
  123. if ($contact->params->get($thisLable)) {
  124. $pparams->set($thisLable, $contact->params->get($thisLable));
  125. } else {
  126. $pparams->set($thisLable, $contact->params->get($thisLink));
  127. }
  128. }
  129. }
  130. JHtml::_('behavior.formvalidation');
  131. $this->assignRef('contact', $contact);
  132. $this->assignRef('contacts', $contacts);
  133. $this->assignRef('params', $pparams);
  134. $this->assignRef('return', $return);
  135. parent::display($tpl);
  136. }
  137. /**
  138. * Checks for errors and exits with messages if found
  139. * @param Array of errors
  140. * @return null
  141. */
  142. function reportErrors($errors)
  143. {
  144. if (!$errors || !is_array($errors)) {
  145. return;
  146. }
  147. foreach ($errors as &$error)
  148. {
  149. if ($error instanceof Exception)
  150. {
  151. if ($error->getCode() == 404)
  152. {
  153. // If there is a 404, throw a hard error.
  154. JError::raiseError(404, $error->getMessage());
  155. return false;
  156. }
  157. else
  158. {
  159. JError::raiseError(500, $error->getMessage());
  160. }
  161. }
  162. else
  163. {
  164. JError::raiseWarning(500, $error);
  165. }
  166. }
  167. return false;
  168. }
  169. }