[ 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 Finder.Tags 6 * 7 * @copyright (C) 2013 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\Component\ComponentHelper; 14 use Joomla\CMS\Table\Table; 15 use Joomla\Component\Finder\Administrator\Indexer\Adapter; 16 use Joomla\Component\Finder\Administrator\Indexer\Helper; 17 use Joomla\Component\Finder\Administrator\Indexer\Indexer; 18 use Joomla\Component\Finder\Administrator\Indexer\Result; 19 use Joomla\Component\Tags\Site\Helper\RouteHelper; 20 use Joomla\Database\DatabaseQuery; 21 use Joomla\Registry\Registry; 22 23 // phpcs:disable PSR1.Files.SideEffects 24 \defined('_JEXEC') or die; 25 // phpcs:enable PSR1.Files.SideEffects 26 27 /** 28 * Finder adapter for Joomla Tag. 29 * 30 * @since 3.1 31 */ 32 class PlgFinderTags extends Adapter 33 { 34 /** 35 * The plugin identifier. 36 * 37 * @var string 38 * @since 3.1 39 */ 40 protected $context = 'Tags'; 41 42 /** 43 * The extension name. 44 * 45 * @var string 46 * @since 3.1 47 */ 48 protected $extension = 'com_tags'; 49 50 /** 51 * The sublayout to use when rendering the results. 52 * 53 * @var string 54 * @since 3.1 55 */ 56 protected $layout = 'tag'; 57 58 /** 59 * The type of content that the adapter indexes. 60 * 61 * @var string 62 * @since 3.1 63 */ 64 protected $type_title = 'Tag'; 65 66 /** 67 * The table name. 68 * 69 * @var string 70 * @since 3.1 71 */ 72 protected $table = '#__tags'; 73 74 /** 75 * Load the language file on instantiation. 76 * 77 * @var boolean 78 * @since 3.1 79 */ 80 protected $autoloadLanguage = true; 81 82 /** 83 * The field the published state is stored in. 84 * 85 * @var string 86 * @since 3.1 87 */ 88 protected $state_field = 'published'; 89 90 /** 91 * Method to remove the link information for items that have been deleted. 92 * 93 * @param string $context The context of the action being performed. 94 * @param Table $table A Table object containing the record to be deleted 95 * 96 * @return void 97 * 98 * @since 3.1 99 * @throws Exception on database error. 100 */ 101 public function onFinderAfterDelete($context, $table): void 102 { 103 if ($context === 'com_tags.tag') { 104 $id = $table->id; 105 } elseif ($context === 'com_finder.index') { 106 $id = $table->link_id; 107 } else { 108 return; 109 } 110 111 // Remove the items. 112 $this->remove($id); 113 } 114 115 /** 116 * Method to determine if the access level of an item changed. 117 * 118 * @param string $context The context of the content passed to the plugin. 119 * @param Table $row A Table object 120 * @param boolean $isNew If the content has just been created 121 * 122 * @return void 123 * 124 * @since 3.1 125 * @throws Exception on database error. 126 */ 127 public function onFinderAfterSave($context, $row, $isNew): void 128 { 129 // We only want to handle tags here. 130 if ($context === 'com_tags.tag') { 131 // Check if the access levels are different 132 if (!$isNew && $this->old_access != $row->access) { 133 // Process the change. 134 $this->itemAccessChange($row); 135 } 136 137 // Reindex the item 138 $this->reindex($row->id); 139 } 140 } 141 142 /** 143 * Method to reindex the link information for an item that has been saved. 144 * This event is fired before the data is actually saved so we are going 145 * to queue the item to be indexed later. 146 * 147 * @param string $context The context of the content passed to the plugin. 148 * @param Table $row A Table object 149 * @param boolean $isNew If the content is just about to be created 150 * 151 * @return boolean True on success. 152 * 153 * @since 3.1 154 * @throws Exception on database error. 155 */ 156 public function onFinderBeforeSave($context, $row, $isNew) 157 { 158 // We only want to handle news feeds here 159 if ($context === 'com_tags.tag') { 160 // Query the database for the old access level if the item isn't new 161 if (!$isNew) { 162 $this->checkItemAccess($row); 163 } 164 } 165 166 return true; 167 } 168 169 /** 170 * Method to update the link information for items that have been changed 171 * from outside the edit screen. This is fired when the item is published, 172 * unpublished, archived, or unarchived from the list view. 173 * 174 * @param string $context The context for the content passed to the plugin. 175 * @param array $pks A list of primary key ids of the content that has changed state. 176 * @param integer $value The value of the state that the content has been changed to. 177 * 178 * @return void 179 * 180 * @since 3.1 181 */ 182 public function onFinderChangeState($context, $pks, $value) 183 { 184 // We only want to handle tags here 185 if ($context === 'com_tags.tag') { 186 $this->itemStateChange($pks, $value); 187 } 188 189 // Handle when the plugin is disabled 190 if ($context === 'com_plugins.plugin' && $value === 0) { 191 $this->pluginDisable($pks); 192 } 193 } 194 195 /** 196 * Method to index an item. The item must be a Result object. 197 * 198 * @param Result $item The item to index as a Result object. 199 * 200 * @return void 201 * 202 * @since 3.1 203 * @throws Exception on database error. 204 */ 205 protected function index(Result $item) 206 { 207 // Check if the extension is enabled 208 if (ComponentHelper::isEnabled($this->extension) === false) { 209 return; 210 } 211 212 $item->setLanguage(); 213 214 // Initialize the item parameters. 215 $registry = new Registry($item->params); 216 $item->params = clone ComponentHelper::getParams('com_tags', true); 217 $item->params->merge($registry); 218 219 $item->metadata = new Registry($item->metadata); 220 221 // Create a URL as identifier to recognise items again. 222 $item->url = $this->getUrl($item->id, $this->extension, $this->layout); 223 224 // Build the necessary route and path information. 225 $item->route = RouteHelper::getComponentTagRoute($item->slug, $item->language); 226 227 // Get the menu title if it exists. 228 $title = $this->getItemMenuTitle($item->url); 229 230 // Adjust the title if necessary. 231 if (!empty($title) && $this->params->get('use_menu_title', true)) { 232 $item->title = $title; 233 } 234 235 // Add the meta author. 236 $item->metaauthor = $item->metadata->get('author'); 237 238 // Handle the link to the metadata. 239 $item->addInstruction(Indexer::META_CONTEXT, 'link'); 240 $item->addInstruction(Indexer::META_CONTEXT, 'metakey'); 241 $item->addInstruction(Indexer::META_CONTEXT, 'metadesc'); 242 $item->addInstruction(Indexer::META_CONTEXT, 'metaauthor'); 243 $item->addInstruction(Indexer::META_CONTEXT, 'author'); 244 $item->addInstruction(Indexer::META_CONTEXT, 'created_by_alias'); 245 246 // Add the type taxonomy data. 247 $item->addTaxonomy('Type', 'Tag'); 248 249 // Add the author taxonomy data. 250 if (!empty($item->author) || !empty($item->created_by_alias)) { 251 $item->addTaxonomy('Author', !empty($item->created_by_alias) ? $item->created_by_alias : $item->author); 252 } 253 254 // Add the language taxonomy data. 255 $item->addTaxonomy('Language', $item->language); 256 257 // Get content extras. 258 Helper::getContentExtras($item); 259 260 // Index the item. 261 $this->indexer->index($item); 262 } 263 264 /** 265 * Method to setup the indexer to be run. 266 * 267 * @return boolean True on success. 268 * 269 * @since 3.1 270 */ 271 protected function setup() 272 { 273 return true; 274 } 275 276 /** 277 * Method to get the SQL query used to retrieve the list of content items. 278 * 279 * @param mixed $query A DatabaseQuery object or null. 280 * 281 * @return DatabaseQuery A database object. 282 * 283 * @since 3.1 284 */ 285 protected function getListQuery($query = null) 286 { 287 $db = $this->db; 288 289 // Check if we can use the supplied SQL query. 290 $query = $query instanceof DatabaseQuery ? $query : $db->getQuery(true) 291 ->select('a.id, a.title, a.alias, a.description AS summary') 292 ->select('a.created_time AS start_date, a.created_user_id AS created_by') 293 ->select('a.metakey, a.metadesc, a.metadata, a.language, a.access') 294 ->select('a.modified_time AS modified, a.modified_user_id AS modified_by') 295 ->select('a.published AS state, a.access, a.created_time AS start_date, a.params'); 296 297 // Handle the alias CASE WHEN portion of the query 298 $case_when_item_alias = ' CASE WHEN '; 299 $case_when_item_alias .= $query->charLength('a.alias', '!=', '0'); 300 $case_when_item_alias .= ' THEN '; 301 $a_id = $query->castAsChar('a.id'); 302 $case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':'); 303 $case_when_item_alias .= ' ELSE '; 304 $case_when_item_alias .= $a_id . ' END as slug'; 305 $query->select($case_when_item_alias) 306 ->from('#__tags AS a'); 307 308 // Join the #__users table 309 $query->select('u.name AS author') 310 ->join('LEFT', '#__users AS u ON u.id = a.created_user_id'); 311 312 // Exclude the ROOT item 313 $query->where($db->quoteName('a.id') . ' > 1'); 314 315 return $query; 316 } 317 318 /** 319 * Method to get a SQL query to load the published and access states for the given tag. 320 * 321 * @return DatabaseQuery A database object. 322 * 323 * @since 3.1 324 */ 325 protected function getStateQuery() 326 { 327 $query = $this->db->getQuery(true); 328 $query->select($this->db->quoteName('a.id')) 329 ->select($this->db->quoteName('a.' . $this->state_field, 'state') . ', ' . $this->db->quoteName('a.access')) 330 ->select('NULL AS cat_state, NULL AS cat_access') 331 ->from($this->db->quoteName($this->table, 'a')); 332 333 return $query; 334 } 335 336 /** 337 * Method to get the query clause for getting items to update by time. 338 * 339 * @param string $time The modified timestamp. 340 * 341 * @return DatabaseQuery A database object. 342 * 343 * @since 3.1 344 */ 345 protected function getUpdateQueryByTime($time) 346 { 347 // Build an SQL query based on the modified time. 348 $query = $this->db->getQuery(true) 349 ->where('a.date >= ' . $this->db->quote($time)); 350 351 return $query; 352 } 353 }
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 |