Source for file sef.php

Documentation is available at sef.php

  1. <?php
  2. /**
  3. @version        $Id: sef.php 9976 2008-01-30 21:19:04Z ircmaxell $
  4. @package        Joomla
  5. @copyright    Copyright (C) 2005 - 2008 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.            $regex  '#href="index.php\?([^"]*)#m';
  58.           $buffer preg_replace_callback$regexarray('plgSystemSEF''route')$buffer );
  59.  
  60.            $protocols '[a-zA-Z0-9]+:'//To check for all unknown protocals (a protocol must contain at least one alpahnumeric fillowed by :
  61.           $regex     '#(src|href)="(?!/|'.$protocols.'|\#)([^"]*)"#m';
  62.         $buffer    preg_replace($regex"$1=\"$base\$2\""$buffer);
  63.         $regex     '#(onclick="window.open\(\')(?!/|'.$protocols.'|\#)([^/]+[^\']*?\')#m';
  64.         $buffer    preg_replace($regex'$1'.$base.'$2'$buffer);
  65.  
  66.         JResponse::setBody($buffer);
  67.         return true;
  68.     }
  69.  
  70.     /**
  71.      * Replaces the matched tags
  72.      *
  73.      * @param array An array of matches (see preg_match_all)
  74.      * @return string 
  75.      */
  76.         function route&$matches )
  77.      {
  78.         $original       $matches[0];
  79.            $url            $matches[1];
  80.  
  81.         $url str_replace('&amp;','&',$url);
  82.  
  83.            $route          JRoute::_('index.php?'.$url);
  84.           return 'href="'.$route;
  85.       }
  86. }

Documentation generated on Sun, 06 Apr 2008 07:15:04 +0200 by phpDocumentor 1.4.0a2