| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Plugin 4 * @subpackage Finder.Categories 5 * 6 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10 defined('JPATH_BASE') or die; 11 12 jimport('joomla.application.component.helper'); 13 jimport('joomla.filesystem.file'); 14 15 // Load the base adapter. 16 require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/adapter.php'; 17 18 /** 19 * Finder adapter for Joomla Categories. 20 * 21 * @package Joomla.Plugin 22 * @subpackage Finder.Categories 23 * @since 2.5 24 */ 25 class plgFinderCategories extends FinderIndexerAdapter 26 { 27 /** 28 * The plugin identifier. 29 * 30 * @var string 31 * @since 2.5 32 */ 33 protected $context = 'Categories'; 34 35 /** 36 * The extension name. 37 * 38 * @var string 39 * @since 2.5 40 */ 41 protected $extension = 'com_categories'; 42 43 /** 44 * The sublayout to use when rendering the results. 45 * 46 * @var string 47 * @since 2.5 48 */ 49 protected $layout = 'category'; 50 51 /** 52 * The type of content that the adapter indexes. 53 * 54 * @var string 55 * @since 2.5 56 */ 57 protected $type_title = 'Category'; 58 59 /** 60 * The table name. 61 * 62 * @var string 63 * @since 2.5 64 */ 65 protected $table = '#__categories'; 66 67 /** 68 * The field the published state is stored in. 69 * 70 * @var string 71 * @since 2.5 72 */ 73 protected $state_field = 'published'; 74 75 /** 76 * Constructor 77 * 78 * @param object &$subject The object to observe 79 * @param array $config An array that holds the plugin configuration 80 * 81 * @since 2.5 82 */ 83 public function __construct(&$subject, $config) 84 { 85 parent::__construct($subject, $config); 86 $this->loadLanguage(); 87 } 88 89 /** 90 * Method to remove the link information for items that have been deleted. 91 * 92 * @param string $context The context of the action being performed. 93 * @param JTable $table A JTable object containing the record to be deleted 94 * 95 * @return boolean True on success. 96 * 97 * @since 2.5 98 * @throws Exception on database error. 99 */ 100 public function onFinderDelete($context, $table) 101 { 102 if ($context == 'com_categories.category') 103 { 104 $id = $table->id; 105 } 106 elseif ($context == 'com_finder.index') 107 { 108 $id = $table->link_id; 109 } 110 else 111 { 112 return true; 113 } 114 // Remove the items. 115 return $this->remove($id); 116 } 117 118 /** 119 * Method to determine if the access level of an item changed. 120 * 121 * @param string $context The context of the content passed to the plugin. 122 * @param JTable $row A JTable object 123 * @param boolean $isNew If the content has just been created 124 * 125 * @return boolean True on success. 126 * 127 * @since 2.5 128 * @throws Exception on database error. 129 */ 130 public function onFinderAfterSave($context, $row, $isNew) 131 { 132 // We only want to handle categories here 133 if ($context == 'com_categories.category') 134 { 135 // Check if the access levels are different 136 if (!$isNew && $this->old_access != $row->access) 137 { 138 // Process the change. 139 $this->itemAccessChange($row); 140 } 141 142 // Reindex the item 143 $this->reindex($row->id); 144 } 145 return true; 146 } 147 148 /** 149 * Method to reindex the link information for an item that has been saved. 150 * This event is fired before the data is actually saved so we are going 151 * to queue the item to be indexed later. 152 * 153 * @param string $context The context of the content passed to the plugin. 154 * @param JTable $row A JTable object 155 * @param boolean $isNew If the content is just about to be created 156 * 157 * @return boolean True on success. 158 * 159 * @since 2.5 160 * @throws Exception on database error. 161 */ 162 public function onFinderBeforeSave($context, $row, $isNew) 163 { 164 // We only want to handle categories here 165 if ($context == 'com_categories.category') 166 { 167 // Query the database for the old access level if the item isn't new 168 if (!$isNew) 169 { 170 $this->checkItemAccess($row); 171 } 172 } 173 174 return true; 175 } 176 177 /** 178 * Method to update the link information for items that have been changed 179 * from outside the edit screen. This is fired when the item is published, 180 * unpublished, archived, or unarchived from the list view. 181 * 182 * @param string $context The context for the content passed to the plugin. 183 * @param array $pks A list of primary key ids of the content that has changed state. 184 * @param integer $value The value of the state that the content has been changed to. 185 * 186 * @return void 187 * 188 * @since 2.5 189 */ 190 public function onFinderChangeState($context, $pks, $value) 191 { 192 // We only want to handle categories here 193 if ($context == 'com_categories.category') 194 { 195 // The category published state is tied to the parent category 196 // published state so we need to look up all published states 197 // before we change anything. 198 foreach ($pks as $pk) 199 { 200 $sql = clone($this->getStateQuery()); 201 $sql->where('a.id = ' . (int) $pk); 202 203 // Get the published states. 204 $this->db->setQuery($sql); 205 $item = $this->db->loadObject(); 206 207 // Translate the state. 208 $temp = $this->translateState($value); 209 210 // Update the item. 211 $this->change($pk, 'state', $temp); 212 213 // Reindex the item 214 $this->reindex($pk); 215 } 216 } 217 218 // Handle when the plugin is disabled 219 if ($context == 'com_plugins.plugin' && $value === 0) 220 { 221 $this->pluginDisable($pks); 222 } 223 } 224 225 /** 226 * Method to index an item. The item must be a FinderIndexerResult object. 227 * 228 * @param FinderIndexerResult $item The item to index as an FinderIndexerResult object. 229 * @param string $format The item format 230 * 231 * @return void 232 * 233 * @since 2.5 234 * @throws Exception on database error. 235 */ 236 protected function index(FinderIndexerResult $item, $format = 'html') 237 { 238 // Check if the extension is enabled 239 if (JComponentHelper::isEnabled($this->extension) == false) 240 { 241 return; 242 } 243 244 // Need to import component route helpers dynamically, hence the reason it's handled here 245 if (JFile::exists(JPATH_SITE . '/components/' . $item->extension . '/helpers/route.php')) 246 { 247 include_once JPATH_SITE . '/components/' . $item->extension . '/helpers/route.php'; 248 } 249 250 $extension = ucfirst(substr($item->extension, 4)); 251 252 // Initialize the item parameters. 253 $registry = new JRegistry; 254 $registry->loadString($item->params); 255 $item->params = $registry; 256 257 $registry = new JRegistry; 258 $registry->loadString($item->metadata); 259 $item->metadata = $registry; 260 261 /* Add the meta-data processing instructions based on the categories 262 * configuration parameters. 263 */ 264 // Add the meta-author. 265 $item->metaauthor = $item->metadata->get('author'); 266 267 // Handle the link to the meta-data. 268 $item->addInstruction(FinderIndexer::META_CONTEXT, 'link'); 269 $item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey'); 270 $item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc'); 271 $item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor'); 272 $item->addInstruction(FinderIndexer::META_CONTEXT, 'author'); 273 //$item->addInstruction(FinderIndexer::META_CONTEXT, 'created_by_alias'); 274 275 // Trigger the onContentPrepare event. 276 $item->summary = FinderIndexerHelper::prepareContent($item->summary, $item->params); 277 278 // Build the necessary route and path information. 279 $item->url = $this->getURL($item->id, $item->extension, $this->layout); 280 if (class_exists($extension . 'HelperRoute') && method_exists($extension . 'HelperRoute', 'getCategoryRoute')) 281 { 282 $class = $extension . 'HelperRoute'; 283 284 // This is necessary for PHP 5.2 compatibility 285 $item->route = call_user_func(array($class, 'getCategoryRoute'), $item->id); 286 287 // Use this when PHP 5.3 is minimum supported 288 //$item->route = $class::getCategoryRoute($item->id); 289 } 290 else 291 { 292 $item->route = ContentHelperRoute::getCategoryRoute($item->slug, $item->catid); 293 } 294 $item->path = FinderIndexerHelper::getContentPath($item->route); 295 296 // Get the menu title if it exists. 297 $title = $this->getItemMenuTitle($item->url); 298 299 // Adjust the title if necessary. 300 if (!empty($title) && $this->params->get('use_menu_title', true)) 301 { 302 $item->title = $title; 303 } 304 305 // Translate the state. Categories should only be published if the parent category is published. 306 $item->state = $this->translateState($item->state); 307 308 // Add the type taxonomy data. 309 $item->addTaxonomy('Type', 'Category'); 310 311 // Add the language taxonomy data. 312 $item->addTaxonomy('Language', $item->language); 313 314 // Get content extras. 315 FinderIndexerHelper::getContentExtras($item); 316 317 // Index the item. 318 FinderIndexer::index($item); 319 } 320 321 /** 322 * Method to setup the indexer to be run. 323 * 324 * @return boolean True on success. 325 * 326 * @since 2.5 327 */ 328 protected function setup() 329 { 330 // Load com_content route helper as it is the fallback for routing in the indexer in this instance. 331 include_once JPATH_SITE . '/components/com_content/helpers/route.php'; 332 333 return true; 334 } 335 336 /** 337 * Method to get the SQL query used to retrieve the list of content items. 338 * 339 * @param mixed $sql A JDatabaseQuery object or null. 340 * 341 * @return JDatabaseQuery A database object. 342 * 343 * @since 2.5 344 */ 345 protected function getListQuery($sql = null) 346 { 347 $db = JFactory::getDbo(); 348 // Check if we can use the supplied SQL query. 349 $sql = is_a($sql, 'JDatabaseQuery') ? $sql : $db->getQuery(true); 350 $sql->select('a.id, a.title, a.alias, a.description AS summary, a.extension'); 351 $sql->select('a.created_user_id AS created_by, a.modified_time AS modified, a.modified_user_id AS modified_by'); 352 $sql->select('a.metakey, a.metadesc, a.metadata, a.language, a.lft, a.parent_id, a.level'); 353 $sql->select('a.created_time AS start_date, a.published AS state, a.access, a.params'); 354 355 // Handle the alias CASE WHEN portion of the query 356 $case_when_item_alias = ' CASE WHEN '; 357 $case_when_item_alias .= $sql->charLength('a.alias'); 358 $case_when_item_alias .= ' THEN '; 359 $a_id = $sql->castAsChar('a.id'); 360 $case_when_item_alias .= $sql->concatenate(array($a_id, 'a.alias'), ':'); 361 $case_when_item_alias .= ' ELSE '; 362 $case_when_item_alias .= $a_id.' END as slug'; 363 $sql->select($case_when_item_alias); 364 $sql->from('#__categories AS a'); 365 $sql->where($db->quoteName('a.id') . ' > 1'); 366 367 return $sql; 368 } 369 370 /** 371 * Method to get a SQL query to load the published and access states for 372 * a category and section. 373 * 374 * @return JDatabaseQuery A database object. 375 * 376 * @since 2.5 377 */ 378 protected function getStateQuery() 379 { 380 $sql = $this->db->getQuery(true); 381 $sql->select($this->db->quoteName('a.id')); 382 $sql->select($this->db->quoteName('a.published') . ' AS cat_state'); 383 $sql->select($this->db->quoteName('a.access') . ' AS cat_access'); 384 $sql->from($this->db->quoteName('#__categories') . ' AS a'); 385 386 return $sql; 387 } 388 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |