Source for file highlight.php

Documentation is available at highlight.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Plugin
  4.  * @subpackage  System.Highlight
  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. /**
  13.  * System plugin to highlight terms.
  14.  *
  15.  * @package     Joomla.Plugin
  16.  * @subpackage  System.Highlight
  17.  * @since       2.5
  18.  */
  19. class PlgSystemHighlight extends JPlugin
  20. {
  21.     /**
  22.      * Method to catch the onAfterDispatch event.
  23.      *
  24.      * This is where we setup the click-through content highlighting for.
  25.      * The highlighting is done with JavaScript so we just
  26.      * need to check a few parameters and the JHtml behavior will do the rest.
  27.      *
  28.      * @return  boolean  True on success
  29.      *
  30.      * @since   2.5
  31.      */
  32.     public function onAfterDispatch()
  33.     {
  34.         // Check that we are in the site application.
  35.         if (JFactory::getApplication()->isAdmin())
  36.         {
  37.             return true;
  38.         }
  39.  
  40.         // Set the variables
  41.         $input JFactory::getApplication()->input;
  42.         $extension $input->get('option''''cmd');
  43.  
  44.         // Check if the highlighter is enabled.
  45.         if (!JComponentHelper::getParams($extension)->get('highlight_terms'1))
  46.         {
  47.             return true;
  48.         }
  49.  
  50.         // Check if the highlighter should be activated in this environment.
  51.         if (JFactory::getDocument()->getType(!== 'html' || $input->get('tmpl''''cmd'=== 'component')
  52.         {
  53.             return true;
  54.         }
  55.  
  56.         // Get the terms to highlight from the request.
  57.         $terms $input->request->get('highlight'null'base64');
  58.         $terms $terms json_decode(base64_decode($terms)) null;
  59.  
  60.         // Check the terms.
  61.         if (empty($terms))
  62.         {
  63.             return true;
  64.         }
  65.  
  66.         // Clean the terms array
  67.         $filter JFilterInput::getInstance();
  68.  
  69.         $cleanTerms array();
  70.         foreach ($terms as $term)
  71.         {
  72.             $cleanTerms[htmlspecialchars($filter->clean($term'string'));
  73.         }
  74.  
  75.         // Activate the highlighter.
  76.         JHtml::_('behavior.highlighter'$cleanTerms);
  77.  
  78.         // Adjust the component buffer.
  79.         $doc JFactory::getDocument();
  80.         $buf $doc->getBuffer('component');
  81.         $buf '<br id="highlighter-start" />' $buf '<br id="highlighter-end" />';
  82.         $doc->setBuffer($buf'component');
  83.  
  84.         return true;
  85.     }
  86. }

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