[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3   * @package     Joomla.Plugin
   4   * @subpackage  Finder.Weblinks
   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 Web Links.
  19   *
  20   * @package     Joomla.Plugin
  21   * @subpackage  Finder.Weblinks
  22   * @since       2.5
  23   */
  24  class plgFinderWeblinks extends FinderIndexerAdapter
  25  {
  26      /**
  27       * The plugin identifier.
  28       *
  29       * @var    string
  30       * @since  2.5
  31       */
  32      protected $context = 'Weblinks';
  33  
  34      /**
  35       * The extension name.
  36       *
  37       * @var    string
  38       * @since  2.5
  39       */
  40      protected $extension = 'com_weblinks';
  41  
  42      /**
  43       * The sublayout to use when rendering the results.
  44       *
  45       * @var    string
  46       * @since  2.5
  47       */
  48      protected $layout = 'weblink';
  49  
  50      /**
  51       * The type of content that the adapter indexes.
  52       *
  53       * @var    string
  54       * @since  2.5
  55       */
  56      protected $type_title = 'Web Link';
  57  
  58      /**
  59       * The table name.
  60       *
  61       * @var    string
  62       * @since  2.5
  63       */
  64      protected $table = '#__weblinks';
  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_weblinks categories
  96          if ($extension == 'com_weblinks')
  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_weblinks.weblink')
 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 web links here. We need to handle front end and back end editing.
 146          if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.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 web links here
 189          if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.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 web links here
 227          if ($context == 'com_weblinks.weblink' || $context == 'com_weblinks.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      /**
 240       * Method to index an item. The item must be a FinderIndexerResult object.
 241       *
 242       * @param   FinderIndexerResult  $item    The item to index as an FinderIndexerResult object.
 243       * @param   string               $format  The item format
 244       *
 245       * @return  void
 246       *
 247       * @since   2.5
 248       * @throws  Exception on database error.
 249       */
 250  	protected function index(FinderIndexerResult $item, $format = 'html')
 251      {
 252          // Check if the extension is enabled
 253          if (JComponentHelper::isEnabled($this->extension) == false)
 254          {
 255              return;
 256          }
 257  
 258          // Initialize the item parameters.
 259          $registry = new JRegistry;
 260          $registry->loadString($item->params);
 261          $item->params = $registry;
 262  
 263          $registry = new JRegistry;
 264          $registry->loadString($item->metadata);
 265          $item->metadata = $registry;
 266  
 267          // Build the necessary route and path information.
 268          $item->url = $this->getURL($item->id, $this->extension, $this->layout);
 269          $item->route = WeblinksHelperRoute::getWeblinkRoute($item->slug, $item->catslug);
 270          $item->path = FinderIndexerHelper::getContentPath($item->route);
 271  
 272          /*
 273           * Add the meta-data processing instructions based on the newsfeeds
 274           * configuration parameters.
 275           */
 276          // Add the meta-author.
 277          $item->metaauthor = $item->metadata->get('author');
 278  
 279          // Handle the link to the meta-data.
 280          $item->addInstruction(FinderIndexer::META_CONTEXT, 'link');
 281          $item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey');
 282          $item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc');
 283          $item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor');
 284          $item->addInstruction(FinderIndexer::META_CONTEXT, 'author');
 285          $item->addInstruction(FinderIndexer::META_CONTEXT, 'created_by_alias');
 286  
 287          // Add the type taxonomy data.
 288          $item->addTaxonomy('Type', 'Web Link');
 289  
 290          // Add the category taxonomy data.
 291          $item->addTaxonomy('Category', $item->category, $item->cat_state, $item->cat_access);
 292  
 293          // Add the language taxonomy data.
 294          $item->addTaxonomy('Language', $item->language);
 295  
 296          // Get content extras.
 297          FinderIndexerHelper::getContentExtras($item);
 298  
 299          // Index the item.
 300          FinderIndexer::index($item);
 301      }
 302  
 303      /**
 304       * Method to setup the indexer to be run.
 305       *
 306       * @return  boolean  True on success.
 307       *
 308       * @since   2.5
 309       */
 310  	protected function setup()
 311      {
 312          // Load dependent classes.
 313          require_once  JPATH_SITE . '/includes/application.php';
 314          require_once  JPATH_SITE . '/components/com_weblinks/helpers/route.php';
 315  
 316          return true;
 317      }
 318  
 319      /**
 320       * Method to get the SQL query used to retrieve the list of content items.
 321       *
 322       * @param   mixed  $sql  A JDatabaseQuery object or null.
 323       *
 324       * @return  JDatabaseQuery  A database object.
 325       *
 326       * @since   2.5
 327       */
 328  	protected function getListQuery($sql = null)
 329      {
 330          $db = JFactory::getDbo();
 331          // Check if we can use the supplied SQL query.
 332          $sql = is_a($sql, 'JDatabaseQuery') ? $sql : $db->getQuery(true);
 333          $sql->select('a.id, a.catid, a.title, a.alias, a.url AS link, a.description AS summary');
 334          $sql->select('a.metakey, a.metadesc, a.metadata, a.language, a.access, a.ordering');
 335          $sql->select('a.created_by_alias, a.modified, a.modified_by');
 336          $sql->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date');
 337          $sql->select('a.state AS state, a.ordering, a.access, a.approved, a.created AS start_date, a.params');
 338          $sql->select('c.title AS category, c.published AS cat_state, c.access AS cat_access');
 339  
 340          // Handle the alias CASE WHEN portion of the query
 341          $case_when_item_alias = ' CASE WHEN ';
 342          $case_when_item_alias .= $sql->charLength('a.alias');
 343          $case_when_item_alias .= ' THEN ';
 344          $a_id = $sql->castAsChar('a.id');
 345          $case_when_item_alias .= $sql->concatenate(array($a_id, 'a.alias'), ':');
 346          $case_when_item_alias .= ' ELSE ';
 347          $case_when_item_alias .= $a_id.' END as slug';
 348          $sql->select($case_when_item_alias);
 349  
 350          $case_when_category_alias = ' CASE WHEN ';
 351          $case_when_category_alias .= $sql->charLength('c.alias');
 352          $case_when_category_alias .= ' THEN ';
 353          $c_id = $sql->castAsChar('c.id');
 354          $case_when_category_alias .= $sql->concatenate(array($c_id, 'c.alias'), ':');
 355          $case_when_category_alias .= ' ELSE ';
 356          $case_when_category_alias .= $c_id.' END as catslug';
 357          $sql->select($case_when_category_alias);
 358  
 359          $sql->from('#__weblinks AS a');
 360          $sql->join('LEFT', '#__categories AS c ON c.id = a.catid');
 361          $sql->where('a.approved = 1');
 362  
 363          return $sql;
 364      }
 365  
 366      /**
 367       * Method to get the query clause for getting items to update by time.
 368       *
 369       * @param   string  $time  The modified timestamp.
 370       *
 371       * @return  JDatabaseQuery  A database object.
 372       *
 373       * @since   2.5
 374       */
 375  	protected function getUpdateQueryByTime($time)
 376      {
 377          // Build an SQL query based on the modified time.
 378          $sql = $this->db->getQuery(true);
 379          $sql->where('a.date >= ' . $this->db->quote($time));
 380  
 381          return $sql;
 382      }
 383  }


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