Source for file newsfeeds.php

Documentation is available at newsfeeds.php

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

Documentation generated on Tue, 19 Nov 2013 15:09:32 +0100 by phpDocumentor 1.4.3