| [ 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.Newsfeeds 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 14 // Load the base adapter. 15 require_once JPATH_ADMINISTRATOR . '/components/com_finder/helpers/indexer/adapter.php'; 16 17 /** 18 * Finder adapter for Joomla Newsfeeds. 19 * 20 * @package Joomla.Plugin 21 * @subpackage Finder.Newsfeeds 22 * @since 2.5 23 */ 24 class plgFinderNewsfeeds extends FinderIndexerAdapter 25 { 26 /** 27 * The plugin identifier. 28 * 29 * @var string 30 * @since 2.5 31 */ 32 protected $context = 'Newsfeeds'; 33 34 /** 35 * The extension name. 36 * 37 * @var string 38 * @since 2.5 39 */ 40 protected $extension = 'com_newsfeeds'; 41 42 /** 43 * The sublayout to use when rendering the results. 44 * 45 * @var string 46 * @since 2.5 47 */ 48 protected $layout = 'newsfeed'; 49 50 /** 51 * The type of content that the adapter indexes. 52 * 53 * @var string 54 * @since 2.5 55 */ 56 protected $type_title = 'News Feed'; 57 58 /** 59 * The table name. 60 * 61 * @var string 62 * @since 2.5 63 */ 64 protected $table = '#__newsfeeds'; 65 66 /** 67 * The field the published state is stored in. 68 * 69 * @var string 70 * @since 2.5 71 */ 72 protected $state_field = 'published'; 73 74 /** 75 * Constructor 76 * 77 * @param object &$subject The object to observe 78 * @param array $config An array that holds the plugin configuration 79 * 80 * @since 2.5 81 */ 82 public function __construct(&$subject, $config) 83 { 84 parent::__construct($subject, $config); 85 $this->loadLanguage(); 86 } 87 88 /** 89 * Method to update the item link information when the item category is 90 * changed. This is fired when the item category is published or unpublished 91 * from the list view. 92 * 93 * @param string $extension The extension whose category has been updated. 94 * @param array $pks A list of primary key ids of the content that has changed state. 95 * @param integer $value The value of the state that the content has been changed to. 96 * 97 * @return void 98 * 99 * @since 2.5 100 */ 101 public function onFinderCategoryChangeState($extension, $pks, $value) 102 { 103 // Make sure we're handling com_newsfeeds categories 104 if ($extension == 'com_newsfeeds') 105 { 106 $this->categoryStateChange($pks, $value); 107 } 108 } 109 110 /** 111 * Method to remove the link information for items that have been deleted. 112 * 113 * @param string $context The context of the action being performed. 114 * @param JTable $table A JTable object containing the record to be deleted 115 * 116 * @return boolean True on success. 117 * 118 * @since 2.5 119 * @throws Exception on database error. 120 */ 121 public function onFinderAfterDelete($context, $table) 122 { 123 if ($context == 'com_newsfeeds.newsfeed') 124 { 125 $id = $table->id; 126 } 127 elseif ($context == 'com_finder.index') 128 { 129 $id = $table->link_id; 130 } 131 else 132 { 133 return true; 134 } 135 // Remove the items. 136 return $this->remove($id); 137 } 138 139 /** 140 * Method to determine if the access level of an item changed. 141 * 142 * @param string $context The context of the content passed to the plugin. 143 * @param JTable $row A JTable object 144 * @param boolean $isNew If the content has just been created 145 * 146 * @return boolean True on success. 147 * 148 * @since 2.5 149 * @throws Exception on database error. 150 */ 151 public function onFinderAfterSave($context, $row, $isNew) 152 { 153 // We only want to handle news feeds here 154 if ($context == 'com_newsfeeds.newsfeed') 155 { 156 // Check if the access levels are different 157 if (!$isNew && $this->old_access != $row->access) 158 { 159 // Process the change. 160 $this->itemAccessChange($row); 161 } 162 163 // Reindex the item 164 $this->reindex($row->id); 165 } 166 167 // Check for access changes in the category 168 if ($context == 'com_categories.category') 169 { 170 // Check if the access levels are different 171 if (!$isNew && $this->old_cataccess != $row->access) 172 { 173 $this->categoryAccessChange($row); 174 } 175 } 176 177 return true; 178 } 179 180 /** 181 * Method to reindex the link information for an item that has been saved. 182 * This event is fired before the data is actually saved so we are going 183 * to queue the item to be indexed later. 184 * 185 * @param string $context The context of the content passed to the plugin. 186 * @param JTable $row A JTable object 187 * @param boolean $isNew If the content is just about to be created 188 * 189 * @return boolean True on success. 190 * 191 * @since 2.5 192 * @throws Exception on database error. 193 */ 194 public function onFinderBeforeSave($context, $row, $isNew) 195 { 196 // We only want to handle news feeds here 197 if ($context == 'com_newsfeeds.newsfeed') 198 { 199 // Query the database for the old access level if the item isn't new 200 if (!$isNew) 201 { 202 $this->checkItemAccess($row); 203 } 204 } 205 206 // Check for access levels from the category 207 if ($context == 'com_categories.category') 208 { 209 // Query the database for the old access level if the item isn't new 210 if (!$isNew) 211 { 212 $this->checkCategoryAccess($row); 213 } 214 } 215 216 return true; 217 } 218 219 /** 220 * Method to update the link information for items that have been changed 221 * from outside the edit screen. This is fired when the item is published, 222 * unpublished, archived, or unarchived from the list view. 223 * 224 * @param string $context The context for the content passed to the plugin. 225 * @param array $pks A list of primary key ids of the content that has changed state. 226 * @param integer $value The value of the state that the content has been changed to. 227 * 228 * @return void 229 * 230 * @since 2.5 231 */ 232 public function onFinderChangeState($context, $pks, $value) 233 { 234 // We only want to handle news feeds here 235 if ($context == 'com_newsfeeds.newsfeed') 236 { 237 $this->itemStateChange($pks, $value); 238 } 239 240 // Handle when the plugin is disabled 241 if ($context == 'com_plugins.plugin' && $value === 0) 242 { 243 $this->pluginDisable($pks); 244 } 245 } 246 247 /** 248 * Method to index an item. The item must be a FinderIndexerResult object. 249 * 250 * @param FinderIndexerResult $item The item to index as an FinderIndexerResult object. 251 * @param string $format The item format 252 * 253 * @return void 254 * 255 * @since 2.5 256 * @throws Exception on database error. 257 */ 258 protected function index(FinderIndexerResult $item, $format = 'html') 259 { 260 // Check if the extension is enabled 261 if (JComponentHelper::isEnabled($this->extension) == false) 262 { 263 return; 264 } 265 266 // Initialize the item parameters. 267 $registry = new JRegistry; 268 $registry->loadString($item->params); 269 $item->params = $registry; 270 271 $registry = new JRegistry; 272 $registry->loadString($item->metadata); 273 $item->metadata = $registry; 274 275 // Build the necessary route and path information. 276 $item->url = $this->getURL($item->id, $this->extension, $this->layout); 277 $item->route = NewsfeedsHelperRoute::getNewsfeedRoute($item->slug, $item->catslug); 278 $item->path = FinderIndexerHelper::getContentPath($item->route); 279 280 /* 281 * Add the meta-data processing instructions based on the newsfeeds 282 * configuration parameters. 283 */ 284 // Add the meta-author. 285 $item->metaauthor = $item->metadata->get('author'); 286 287 // Handle the link to the meta-data. 288 $item->addInstruction(FinderIndexer::META_CONTEXT, 'link'); 289 290 $item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey'); 291 $item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc'); 292 $item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor'); 293 $item->addInstruction(FinderIndexer::META_CONTEXT, 'author'); 294 $item->addInstruction(FinderIndexer::META_CONTEXT, 'created_by_alias'); 295 296 // Add the type taxonomy data. 297 $item->addTaxonomy('Type', 'News Feed'); 298 299 // Add the category taxonomy data. 300 $item->addTaxonomy('Category', $item->category, $item->cat_state, $item->cat_access); 301 302 // Add the language taxonomy data. 303 $item->addTaxonomy('Language', $item->language); 304 305 // Get content extras. 306 FinderIndexerHelper::getContentExtras($item); 307 308 // Index the item. 309 FinderIndexer::index($item); 310 } 311 312 /** 313 * Method to setup the indexer to be run. 314 * 315 * @return boolean True on success. 316 * 317 * @since 2.5 318 */ 319 protected function setup() 320 { 321 // Load dependent classes. 322 require_once JPATH_SITE . '/includes/application.php'; 323 require_once JPATH_SITE . '/components/com_newsfeeds/helpers/route.php'; 324 325 return true; 326 } 327 328 /** 329 * Method to get the SQL query used to retrieve the list of content items. 330 * 331 * @param mixed $sql A JDatabaseQuery object or null. 332 * 333 * @return JDatabaseQuery A database object. 334 * 335 * @since 2.5 336 */ 337 protected function getListQuery($sql = null) 338 { 339 $db = JFactory::getDbo(); 340 // Check if we can use the supplied SQL query. 341 $sql = is_a($sql, 'JDatabaseQuery') ? $sql : $db->getQuery(true); 342 $sql->select('a.id, a.catid, a.name AS title, a.alias, a.link AS link'); 343 $sql->select('a.published AS state, a.ordering, a.created AS start_date, a.params, a.access'); 344 $sql->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date'); 345 $sql->select('a.metakey, a.metadesc, a.metadata, a.language'); 346 $sql->select('a.created_by, a.created_by_alias, a.modified, a.modified_by'); 347 $sql->select('c.title AS category, c.published AS cat_state, c.access AS cat_access'); 348 349 // Handle the alias CASE WHEN portion of the query 350 $case_when_item_alias = ' CASE WHEN '; 351 $case_when_item_alias .= $sql->charLength('a.alias'); 352 $case_when_item_alias .= ' THEN '; 353 $a_id = $sql->castAsChar('a.id'); 354 $case_when_item_alias .= $sql->concatenate(array($a_id, 'a.alias'), ':'); 355 $case_when_item_alias .= ' ELSE '; 356 $case_when_item_alias .= $a_id.' END as slug'; 357 $sql->select($case_when_item_alias); 358 359 $case_when_category_alias = ' CASE WHEN '; 360 $case_when_category_alias .= $sql->charLength('c.alias'); 361 $case_when_category_alias .= ' THEN '; 362 $c_id = $sql->castAsChar('c.id'); 363 $case_when_category_alias .= $sql->concatenate(array($c_id, 'c.alias'), ':'); 364 $case_when_category_alias .= ' ELSE '; 365 $case_when_category_alias .= $c_id.' END as catslug'; 366 $sql->select($case_when_category_alias); 367 368 $sql->from('#__newsfeeds AS a'); 369 $sql->join('LEFT', '#__categories AS c ON c.id = a.catid'); 370 371 return $sql; 372 } 373 }
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 |