[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage com_contact 6 * 7 * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Contact\Site\View\Contact; 12 13 use Joomla\CMS\Categories\Categories; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\HTML\HTMLHelper; 16 use Joomla\CMS\Language\Text; 17 use Joomla\CMS\MVC\View\GenericDataException; 18 use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; 19 use Joomla\CMS\Plugin\PluginHelper; 20 use Joomla\CMS\Router\Route; 21 use Joomla\Component\Contact\Site\Helper\RouteHelper; 22 23 // phpcs:disable PSR1.Files.SideEffects 24 \defined('_JEXEC') or die; 25 // phpcs:enable PSR1.Files.SideEffects 26 27 /** 28 * HTML Contact View class for the Contact component 29 * 30 * @since 1.5 31 */ 32 class HtmlView extends BaseHtmlView 33 { 34 /** 35 * The item model state 36 * 37 * @var \Joomla\Registry\Registry 38 * 39 * @since 1.6 40 */ 41 protected $state; 42 43 /** 44 * The form object for the contact item 45 * 46 * @var \Joomla\CMS\Form\Form 47 * 48 * @since 1.6 49 */ 50 protected $form; 51 52 /** 53 * The item object details 54 * 55 * @var \Joomla\CMS\Object\CMSObject 56 * 57 * @since 1.6 58 */ 59 protected $item; 60 61 /** 62 * The page to return to on submission 63 * 64 * @var string 65 * 66 * @since 1.6 67 * 68 * @todo Implement this functionality 69 */ 70 protected $return_page = ''; 71 72 /** 73 * Should we show a captcha form for the submission of the contact request? 74 * 75 * @var boolean 76 * 77 * @since 3.6.3 78 */ 79 protected $captchaEnabled = false; 80 81 /** 82 * The page parameters 83 * 84 * @var \Joomla\Registry\Registry|null 85 * 86 * @since 4.0.0 87 */ 88 protected $params = null; 89 90 /** 91 * The user object 92 * 93 * @var \Joomla\CMS\User\User 94 * 95 * @since 4.0.0 96 */ 97 protected $user; 98 99 /** 100 * Other contacts in this contacts category 101 * 102 * @var array 103 * 104 * @since 4.0.0 105 */ 106 protected $contacts; 107 108 /** 109 * The page class suffix 110 * 111 * @var string 112 * 113 * @since 4.0.0 114 */ 115 protected $pageclass_sfx = ''; 116 117 /** 118 * The flag to mark if the active menu item is linked to the contact being displayed 119 * 120 * @var boolean 121 * 122 * @since 4.0.0 123 */ 124 protected $menuItemMatchContact = false; 125 126 /** 127 * Execute and display a template script. 128 * 129 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 130 * 131 * @return void|boolean 132 */ 133 public function display($tpl = null) 134 { 135 $app = Factory::getApplication(); 136 $user = $this->getCurrentUser(); 137 $state = $this->get('State'); 138 $item = $this->get('Item'); 139 $this->form = $this->get('Form'); 140 $params = $state->get('params'); 141 $contacts = []; 142 143 $temp = clone $params; 144 145 $active = $app->getMenu()->getActive(); 146 147 // If the current view is the active item and a contact view for this contact, then the menu item params take priority 148 if ( 149 $active 150 && $active->component == 'com_contact' 151 && isset($active->query['view'], $active->query['id']) 152 && $active->query['view'] == 'contact' 153 && $active->query['id'] == $item->id 154 ) { 155 $this->menuItemMatchContact = true; 156 157 // Load layout from active query (in case it is an alternative menu item) 158 if (isset($active->query['layout'])) { 159 $this->setLayout($active->query['layout']); 160 } elseif ($layout = $item->params->get('contact_layout')) { 161 // Check for alternative layout of contact 162 $this->setLayout($layout); 163 } 164 165 $item->params->merge($temp); 166 } else { 167 // Merge so that contact params take priority 168 $temp->merge($item->params); 169 $item->params = $temp; 170 171 if ($layout = $item->params->get('contact_layout')) { 172 $this->setLayout($layout); 173 } 174 } 175 176 // Collect extra contact information when this information is required 177 if ($item && $item->params->get('show_contact_list')) { 178 // Get Category Model data 179 /** @var \Joomla\Component\Contact\Site\Model\CategoryModel $categoryModel */ 180 $categoryModel = $app->bootComponent('com_contact')->getMVCFactory() 181 ->createModel('Category', 'Site', ['ignore_request' => true]); 182 183 $categoryModel->setState('category.id', $item->catid); 184 $categoryModel->setState('list.ordering', 'a.name'); 185 $categoryModel->setState('list.direction', 'asc'); 186 $categoryModel->setState('filter.published', 1); 187 188 $contacts = $categoryModel->getItems(); 189 } 190 191 // Check for errors. 192 if (count($errors = $this->get('Errors'))) { 193 throw new GenericDataException(implode("\n", $errors), 500); 194 } 195 196 // Check if access is not public 197 $groups = $user->getAuthorisedViewLevels(); 198 199 if (!in_array($item->access, $groups) || !in_array($item->category_access, $groups)) { 200 $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error'); 201 $app->setHeader('status', 403, true); 202 203 return false; 204 } 205 206 $options['category_id'] = $item->catid; 207 $options['order by'] = 'a.default_con DESC, a.ordering ASC'; 208 209 /** 210 * Handle email cloaking 211 * 212 * Keep a copy of the raw email address so it can 213 * still be accessed in the layout if needed. 214 */ 215 $item->email_raw = $item->email_to; 216 217 if ($item->email_to && $item->params->get('show_email')) { 218 $item->email_to = HTMLHelper::_('email.cloak', $item->email_to, (bool) $item->params->get('add_mailto_link', true)); 219 } 220 221 if ( 222 $item->params->get('show_street_address') || $item->params->get('show_suburb') || $item->params->get('show_state') 223 || $item->params->get('show_postcode') || $item->params->get('show_country') 224 ) { 225 if (!empty($item->address) || !empty($item->suburb) || !empty($item->state) || !empty($item->country) || !empty($item->postcode)) { 226 $item->params->set('address_check', 1); 227 } 228 } else { 229 $item->params->set('address_check', 0); 230 } 231 232 // Manage the display mode for contact detail groups 233 switch ($item->params->get('contact_icons')) { 234 case 1: 235 // Text 236 $item->params->set('marker_address', Text::_('COM_CONTACT_ADDRESS') . ': '); 237 $item->params->set('marker_email', Text::_('JGLOBAL_EMAIL') . ': '); 238 $item->params->set('marker_telephone', Text::_('COM_CONTACT_TELEPHONE') . ': '); 239 $item->params->set('marker_fax', Text::_('COM_CONTACT_FAX') . ': '); 240 $item->params->set('marker_mobile', Text::_('COM_CONTACT_MOBILE') . ': '); 241 $item->params->set('marker_webpage', Text::_('COM_CONTACT_WEBPAGE') . ': '); 242 $item->params->set('marker_misc', Text::_('COM_CONTACT_OTHER_INFORMATION') . ': '); 243 $item->params->set('marker_class', 'jicons-text'); 244 break; 245 246 case 2: 247 // None 248 $item->params->set('marker_address', ''); 249 $item->params->set('marker_email', ''); 250 $item->params->set('marker_telephone', ''); 251 $item->params->set('marker_mobile', ''); 252 $item->params->set('marker_fax', ''); 253 $item->params->set('marker_misc', ''); 254 $item->params->set('marker_webpage', ''); 255 $item->params->set('marker_class', 'jicons-none'); 256 break; 257 258 default: 259 if ($item->params->get('icon_address')) { 260 $item->params->set( 261 'marker_address', 262 HTMLHelper::_('image', $item->params->get('icon_address', ''), Text::_('COM_CONTACT_ADDRESS'), false) 263 ); 264 } 265 266 if ($item->params->get('icon_email')) { 267 $item->params->set( 268 'marker_email', 269 HTMLHelper::_('image', $item->params->get('icon_email', ''), Text::_('COM_CONTACT_EMAIL'), false) 270 ); 271 } 272 273 if ($item->params->get('icon_telephone')) { 274 $item->params->set( 275 'marker_telephone', 276 HTMLHelper::_('image', $item->params->get('icon_telephone', ''), Text::_('COM_CONTACT_TELEPHONE'), false) 277 ); 278 } 279 280 if ($item->params->get('icon_fax', '')) { 281 $item->params->set( 282 'marker_fax', 283 HTMLHelper::_('image', $item->params->get('icon_fax', ''), Text::_('COM_CONTACT_FAX'), false) 284 ); 285 } 286 287 if ($item->params->get('icon_misc')) { 288 $item->params->set( 289 'marker_misc', 290 HTMLHelper::_('image', $item->params->get('icon_misc', ''), Text::_('COM_CONTACT_OTHER_INFORMATION'), false) 291 ); 292 } 293 294 if ($item->params->get('icon_mobile')) { 295 $item->params->set( 296 'marker_mobile', 297 HTMLHelper::_('image', $item->params->get('icon_mobile', ''), Text::_('COM_CONTACT_MOBILE'), false) 298 ); 299 } 300 301 if ($item->params->get('icon_webpage')) { 302 $item->params->set( 303 'marker_webpage', 304 HTMLHelper::_('image', $item->params->get('icon_webpage', ''), Text::_('COM_CONTACT_WEBPAGE'), false) 305 ); 306 } 307 308 $item->params->set('marker_class', 'jicons-icons'); 309 break; 310 } 311 312 // Add links to contacts 313 if ($item->params->get('show_contact_list') && count($contacts) > 1) { 314 foreach ($contacts as &$contact) { 315 $contact->link = Route::_(RouteHelper::getContactRoute($contact->slug, $contact->catid, $contact->language)); 316 } 317 318 $item->link = Route::_(RouteHelper::getContactRoute($item->slug, $item->catid, $item->language), false); 319 } 320 321 // Process the content plugins. 322 PluginHelper::importPlugin('content'); 323 $offset = $state->get('list.offset'); 324 325 // Fix for where some plugins require a text attribute 326 $item->text = ''; 327 328 if (!empty($item->misc)) { 329 $item->text = $item->misc; 330 } 331 332 $app->triggerEvent('onContentPrepare', array ('com_contact.contact', &$item, &$item->params, $offset)); 333 334 // Store the events for later 335 $item->event = new \stdClass(); 336 $results = $app->triggerEvent('onContentAfterTitle', array('com_contact.contact', &$item, &$item->params, $offset)); 337 $item->event->afterDisplayTitle = trim(implode("\n", $results)); 338 339 $results = $app->triggerEvent('onContentBeforeDisplay', array('com_contact.contact', &$item, &$item->params, $offset)); 340 $item->event->beforeDisplayContent = trim(implode("\n", $results)); 341 342 $results = $app->triggerEvent('onContentAfterDisplay', array('com_contact.contact', &$item, &$item->params, $offset)); 343 $item->event->afterDisplayContent = trim(implode("\n", $results)); 344 345 if (!empty($item->text)) { 346 $item->misc = $item->text; 347 } 348 349 $contactUser = null; 350 351 if ($item->params->get('show_user_custom_fields') && $item->user_id && $contactUser = Factory::getUser($item->user_id)) { 352 $contactUser->text = ''; 353 $app->triggerEvent('onContentPrepare', array ('com_users.user', &$contactUser, &$item->params, 0)); 354 355 if (!isset($contactUser->jcfields)) { 356 $contactUser->jcfields = array(); 357 } 358 } 359 360 // Escape strings for HTML output 361 $this->pageclass_sfx = htmlspecialchars($item->params->get('pageclass_sfx', '')); 362 363 $this->params = &$item->params; 364 $this->state = &$state; 365 $this->item = &$item; 366 $this->user = &$user; 367 $this->contacts = &$contacts; 368 $this->contactUser = $contactUser; 369 370 $model = $this->getModel(); 371 $model->hit(); 372 373 $captchaSet = $item->params->get('captcha', $app->get('captcha', '0')); 374 375 foreach (PluginHelper::getPlugin('captcha') as $plugin) { 376 if ($captchaSet === $plugin->name) { 377 $this->captchaEnabled = true; 378 break; 379 } 380 } 381 382 $this->_prepareDocument(); 383 384 parent::display($tpl); 385 } 386 387 /** 388 * Prepares the document 389 * 390 * @return void 391 * 392 * @since 1.6 393 */ 394 protected function _prepareDocument() 395 { 396 $app = Factory::getApplication(); 397 $pathway = $app->getPathway(); 398 399 // Because the application sets a default page title, 400 // we need to get it from the menu item itself 401 $menu = $app->getMenu()->getActive(); 402 403 if ($menu) { 404 $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); 405 } else { 406 $this->params->def('page_heading', Text::_('COM_CONTACT_DEFAULT_PAGE_TITLE')); 407 } 408 409 $title = $this->params->get('page_title', ''); 410 411 // If the menu item does not concern this contact 412 if (!$this->menuItemMatchContact) { 413 // If this is not a single contact menu item, set the page title to the contact title 414 if ($this->item->name) { 415 $title = $this->item->name; 416 } 417 418 // Get ID of the category from active menu item 419 if ( 420 $menu && $menu->component == 'com_contact' && isset($menu->query['view']) 421 && in_array($menu->query['view'], ['categories', 'category']) 422 ) { 423 $id = $menu->query['id']; 424 } else { 425 $id = 0; 426 } 427 428 $path = array(array('title' => $this->item->name, 'link' => '')); 429 $category = Categories::getInstance('Contact')->get($this->item->catid); 430 431 while ($category !== null && $category->id != $id && $category->id !== 'root') { 432 $path[] = array('title' => $category->title, 'link' => RouteHelper::getCategoryRoute($category->id, $category->language)); 433 $category = $category->getParent(); 434 } 435 436 $path = array_reverse($path); 437 438 foreach ($path as $item) { 439 $pathway->addItem($item['title'], $item['link']); 440 } 441 } 442 443 if (empty($title)) { 444 $title = $this->item->name; 445 } 446 447 $this->setDocumentTitle($title); 448 449 if ($this->item->metadesc) { 450 $this->document->setDescription($this->item->metadesc); 451 } elseif ($this->params->get('menu-meta_description')) { 452 $this->document->setDescription($this->params->get('menu-meta_description')); 453 } 454 455 if ($this->params->get('robots')) { 456 $this->document->setMetaData('robots', $this->params->get('robots')); 457 } 458 459 $mdata = $this->item->metadata->toArray(); 460 461 foreach ($mdata as $k => $v) { 462 if ($v) { 463 $this->document->setMetaData($k, $v); 464 } 465 } 466 } 467 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |