Source for file tags.php

Documentation is available at tags.php

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

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