[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/plugins/finder/content/ -> content.php (source)

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


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1