Source for file weblinks.php

Documentation is available at weblinks.php

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

Documentation generated on Tue, 19 Nov 2013 15:18:33 +0100 by phpDocumentor 1.4.3