[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/plugins/system/ -> sef.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: sef.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla
   5  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   6  * @license        GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  // no direct access
  15  defined( '_JEXEC' ) or die( 'Restricted access' );
  16  
  17  jimport( 'joomla.plugin.plugin');
  18  
  19  /**
  20  * Joomla! SEF Plugin
  21  *
  22  * @package         Joomla
  23  * @subpackage    System
  24  */
  25  class plgSystemSef extends JPlugin
  26  {
  27      /**
  28       * Constructor
  29       *
  30       * For php4 compatability we must not use the __constructor as a constructor for plugins
  31       * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
  32       * This causes problems with cross-referencing necessary for the observer design pattern.
  33       *
  34       * @param    object        $subject The object to observe
  35        * @param     array          $config  An array that holds the plugin configuration
  36       * @since    1.0
  37       */
  38  	function plgSystemSef(&$subject, $config)  {
  39          parent::__construct($subject, $config);
  40      }
  41  
  42      /**
  43       * Converting the site URL to fit to the HTTP request
  44       */
  45  	function onAfterRender()
  46      {
  47          $app =& JFactory::getApplication();
  48  
  49          if($app->getName() != 'site') {
  50              return true;
  51          }
  52  
  53          //Replace src links
  54            $base   = JURI::base(true).'/';
  55          $buffer = JResponse::getBody();
  56          
  57          // pull out contents of editor to prevent URL changes inside edit area
  58          $editor =& JFactory::getEditor();
  59          $regex = '#'.$editor->_tagForSEF['start'].'(.*)'.$editor->_tagForSEF['end'].'#Us';
  60          preg_match_all($regex, $buffer, $editContents, PREG_PATTERN_ORDER);
  61  
  62          // create an array to hold the placeholder text (in case there are more than one editor areas)
  63          $placeholders = array();
  64          for ($i = 0; $i < count($editContents[0]); $i++) {
  65              $placeholders[] = $editor->_tagForSEF['start'].$i.$editor->_tagForSEF['end'];
  66          }
  67          
  68          // replace editor contents with placeholder text
  69          $buffer     = str_replace($editContents[0], $placeholders, $buffer);
  70  
  71          // do the SEF substitutions
  72             $regex  = '#href="index.php\?([^"]*)#m';
  73            $buffer = preg_replace_callback( $regex, array('plgSystemSEF', 'route'), $buffer );
  74  
  75             $protocols = '[a-zA-Z0-9]+:'; //To check for all unknown protocals (a protocol must contain at least one alpahnumeric fillowed by :
  76            $regex     = '#(src|href)="(?!/|'.$protocols.'|\#|\')([^"]*)"#m';
  77          $buffer    = preg_replace($regex, "$1=\"$base\$2\"", $buffer);
  78          $regex     = '#(onclick="window.open\(\')(?!/|'.$protocols.'|\#)([^/]+[^\']*?\')#m';
  79          $buffer    = preg_replace($regex, '$1'.$base.'$2', $buffer);
  80          
  81          // ONMOUSEOVER / ONMOUSEOUT
  82          $regex         = '#(onmouseover|onmouseout)="this.src=([\']+)(?!/|'.$protocols.'|\#|\')([^"]+)"#m';
  83          $buffer     = preg_replace($regex, '$1="this.src=$2'. $base .'$3$4"', $buffer);
  84          
  85          // Background image
  86          $regex         = '#style\s*=\s*[\'\"](.*):\s*url\s*\([\'\"]?(?!/|'.$protocols.'|\#)([^\)\'\"]+)[\'\"]?\)#m';
  87          $buffer     = preg_replace($regex, 'style="$1: url(\''. $base .'$2$3\')', $buffer);
  88          
  89          // OBJECT <param name="xx", value="yy"> -- fix it only inside the <param> tag
  90          $regex         = '#(<param\s+)name\s*=\s*"(movie|src|url)"[^>]\s*value\s*=\s*"(?!/|'.$protocols.'|\#|\')([^"]*)"#m';
  91          $buffer     = preg_replace($regex, '$1name="$2" value="' . $base . '$3"', $buffer);
  92          
  93          // OBJECT <param value="xx", name="yy"> -- fix it only inside the <param> tag
  94          $regex         = '#(<param\s+[^>]*)value\s*=\s*"(?!/|'.$protocols.'|\#|\')([^"]*)"\s*name\s*=\s*"(movie|src|url)"#m';
  95          $buffer     = preg_replace($regex, '<param value="'. $base .'$2" name="$3"', $buffer);
  96  
  97          // OBJECT data="xx" attribute -- fix it only in the object tag
  98          $regex =     '#(<object\s+[^>]*)data\s*=\s*"(?!/|'.$protocols.'|\#|\')([^"]*)"#m';
  99          $buffer     = preg_replace($regex, '$1data="' . $base . '$2"$3', $buffer);
 100          
 101          // restore the editor contents
 102          $buffer     = str_replace($placeholders, $editContents[0], $buffer);
 103          
 104          JResponse::setBody($buffer);
 105          return true;
 106      }
 107  
 108      /**
 109       * Replaces the matched tags
 110       *
 111       * @param array An array of matches (see preg_match_all)
 112       * @return string
 113       */
 114     	 function route( &$matches )
 115       {
 116          $original       = $matches[0];
 117             $url            = $matches[1];
 118  
 119          $url = str_replace('&amp;','&',$url);
 120  
 121             $route          = JRoute::_('index.php?'.$url);
 122            return 'href="'.$route;
 123        }
 124  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1