[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Plugin 5 * @subpackage Content.Contact 6 * 7 * @copyright (C) 2014 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 10 * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 11 */ 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\Multilanguage; 15 use Joomla\CMS\Plugin\CMSPlugin; 16 use Joomla\CMS\Router\Route; 17 use Joomla\Component\Contact\Site\Helper\RouteHelper; 18 use Joomla\Database\ParameterType; 19 use Joomla\Registry\Registry; 20 21 // phpcs:disable PSR1.Files.SideEffects 22 \defined('_JEXEC') or die; 23 // phpcs:enable PSR1.Files.SideEffects 24 25 /** 26 * Contact Plugin 27 * 28 * @since 3.2 29 */ 30 class PlgContentContact extends CMSPlugin 31 { 32 /** 33 * @var \Joomla\Database\DatabaseDriver 34 * 35 * @since 3.3 36 */ 37 protected $db; 38 39 /** 40 * Plugin that retrieves contact information for contact 41 * 42 * @param string $context The context of the content being passed to the plugin. 43 * @param mixed &$row An object with a "text" property 44 * @param mixed $params Additional parameters. See {@see PlgContentContent()}. 45 * @param integer $page Optional page number. Unused. Defaults to zero. 46 * 47 * @return void 48 */ 49 public function onContentPrepare($context, &$row, $params, $page = 0) 50 { 51 $allowed_contexts = array('com_content.category', 'com_content.article', 'com_content.featured'); 52 53 if (!in_array($context, $allowed_contexts)) { 54 return; 55 } 56 57 // Return if we don't have valid params or don't link the author 58 if (!($params instanceof Registry) || !$params->get('link_author')) { 59 return; 60 } 61 62 // Return if an alias is used 63 if ((int) $this->params->get('link_to_alias', 0) === 0 && $row->created_by_alias != '') { 64 return; 65 } 66 67 // Return if we don't have a valid article id 68 if (!isset($row->id) || !(int) $row->id) { 69 return; 70 } 71 72 $contact = $this->getContactData($row->created_by); 73 74 if ($contact === null) { 75 return; 76 } 77 78 $row->contactid = $contact->contactid; 79 $row->webpage = $contact->webpage; 80 $row->email = $contact->email_to; 81 $url = $this->params->get('url', 'url'); 82 83 if ($row->contactid && $url === 'url') { 84 $row->contact_link = Route::_(RouteHelper::getContactRoute($contact->contactid . ':' . $contact->alias, $contact->catid)); 85 } elseif ($row->webpage && $url === 'webpage') { 86 $row->contact_link = $row->webpage; 87 } elseif ($row->email && $url === 'email') { 88 $row->contact_link = 'mailto:' . $row->email; 89 } else { 90 $row->contact_link = ''; 91 } 92 } 93 94 /** 95 * Retrieve Contact 96 * 97 * @param int $userId Id of the user who created the article 98 * 99 * @return stdClass|null Object containing contact details or null if not found 100 */ 101 protected function getContactData($userId) 102 { 103 static $contacts = array(); 104 105 // Note: don't use isset() because value could be null. 106 if (array_key_exists($userId, $contacts)) { 107 return $contacts[$userId]; 108 } 109 110 $db = $this->db; 111 $query = $db->getQuery(true); 112 $userId = (int) $userId; 113 114 $query->select($db->quoteName('contact.id', 'contactid')) 115 ->select( 116 $db->quoteName( 117 [ 118 'contact.alias', 119 'contact.catid', 120 'contact.webpage', 121 'contact.email_to', 122 ] 123 ) 124 ) 125 ->from($db->quoteName('#__contact_details', 'contact')) 126 ->where( 127 [ 128 $db->quoteName('contact.published') . ' = 1', 129 $db->quoteName('contact.user_id') . ' = :createdby', 130 ] 131 ) 132 ->bind(':createdby', $userId, ParameterType::INTEGER); 133 134 if (Multilanguage::isEnabled() === true) { 135 $query->where( 136 '(' . $db->quoteName('contact.language') . ' IN (' 137 . implode(',', $query->bindArray([Factory::getLanguage()->getTag(), '*'], ParameterType::STRING)) 138 . ') OR ' . $db->quoteName('contact.language') . ' IS NULL)' 139 ); 140 } 141 142 $query->order($db->quoteName('contact.id') . ' DESC') 143 ->setLimit(1); 144 145 $db->setQuery($query); 146 147 $contacts[$userId] = $db->loadObject(); 148 149 return $contacts[$userId]; 150 } 151 }
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 |