eZ Publish  [4.0]
ezurlaliasfilter.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZURLAliasFilter class
00004 //
00005 // Created on: <22-Jun-2007 09:03:31 amos>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezurlaliasfilter.php
00032 */
00033 
00034 /*!
00035   \class eZURLAliasFilter ezurlaliasfilter.php
00036   \brief Handles filtering of URL aliases
00037 
00038   This class defines the interface for all url alias filters, the filter implementation must implement the process method.
00039 
00040   For execution of the configured filters use the static method processFilters.
00041   Help with configuration is found in settings/site.ini under the group URLTranslator.
00042 */
00043 
00044 class eZURLAliasFilter
00045 {
00046     /**
00047      Initialize the filter object.
00048      */
00049     function eZURLAliasFilter()
00050     {
00051     }
00052 
00053     /*!
00054      \abstract
00055      Process the url alias element $text and return the new element as a string.
00056 
00057      \param $languageObject The current language object used for the string $text.
00058      \param $caller The object which called the filtering process, can be null.
00059      */
00060     function process( $text, &$languageObject, &$caller )
00061     {
00062         return $text;
00063     }
00064 
00065     /*!
00066      \static
00067      Process all configured filters and return the resulting text.
00068 
00069      Filters are found in the INI group URLTranslator and the setting Filters.
00070      This is done in combination with the setting Extensions which controls
00071      which extensions have filter classes.
00072 
00073      The parameters $text, $languageObject and $caller are sent to the method
00074      process on the filter object.
00075 
00076      Note: The filter list will be cached in memory to improve performance of subsequent calls.
00077      */
00078     static function processFilters( $text, $languageObject, $caller )
00079     {
00080         $filters = array();
00081         if ( isset( $GLOBALS['eZURLAliasFilters'] ) )
00082         {
00083             $filters = $GLOBALS['eZURLAliasFilters'];
00084         }
00085         else
00086         {
00087             // No filters are cached in memory, load them and cache for later use
00088 
00089             $ini = eZINI::instance();
00090             $extensionList = $ini->variable( 'URLTranslator', 'Extensions' );
00091             //include_once( 'lib/ezutils/classes/ezextension.php' );
00092             $pathList = eZExtension::expandedPathList( $extensionList, 'urlfilters' );
00093             $filterNames = $ini->variable( 'URLTranslator', 'Filters' );
00094             foreach ( $filterNames as $filterName )
00095             {
00096                 foreach ( $pathList as $path )
00097                 {
00098                     $filterPath = $path . '/' . strtolower( $filterName ) . '.php';
00099                     if ( !file_exists( $filterPath ) )
00100                         continue;
00101                     include_once( $filterPath );
00102                     if ( !class_exists( $filterName ) )
00103                     {
00104                         eZDebug::writeError( "URLAlias filter class named '$filterName' does not exist after loading PHP file $filterPath, ignoring entry." );
00105                         break;
00106                     }
00107                     $filters[] = new $filterName;
00108                 }
00109             }
00110             $GLOBALS['eZURLAliasFilters'] = $filters;
00111         }
00112 
00113         foreach ( $filters as $filter )
00114         {
00115             $text = $filter->process( $text, $languageObject, $caller );
00116         }
00117         return $text;
00118     }
00119 }
00120 
00121 ?>