eZ Publish  [4.0]
ezoverride.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZOverride class
00004 //
00005 // Created on: <31-Oct-2002 09:18:07 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 ezoverride.php
00032 */
00033 
00034 /*!
00035   \class eZOverride ezoverride.php
00036   \brief The class eZOverride does
00037 
00038 */
00039 
00040 class eZOverride
00041 {
00042     static function selectFile( $matches, $matchKeys, &$matchedKeys, $regexpMatch )
00043     {
00044         $match = null;
00045         foreach ( $matches as $templateMatch )
00046         {
00047             $templatePath = $templateMatch["file"];
00048             $templateType = $templateMatch["type"];
00049             if ( $templateType == "normal" )
00050             {
00051                 if ( file_exists( $templatePath ) )
00052                 {
00053                     $match = $templateMatch;
00054                     break;
00055                 }
00056             }
00057             else if ( $templateType == "override" )
00058             {
00059                 $foundOverrideFile = false;
00060                 if ( file_exists( $templatePath ) )
00061                 {
00062                     $match = $templateMatch;
00063                     $match["file"] = $templatePath;
00064                     $foundOverrideFile = true;
00065                 }
00066                 if ( !$foundOverrideFile and
00067                      count( $matchKeys ) == 0 )
00068                     continue;
00069                 if ( !$foundOverrideFile and
00070                      preg_match( $regexpMatch, $templatePath, $regs ) )// Check for dir/filebase_keyname_keyid.tpl, eg. content/view_section_1.tpl
00071                 {
00072                     foreach ( $matchKeys as $matchKeyName => $matchKeyValue )
00073                     {
00074                         $file = $regs[1] . "/" . $regs[2] . "_$matchKeyName" . "_$matchKeyValue" . $regs[3];
00075                         if ( file_exists( $file ) )
00076                         {
00077                             $match = $templateMatch;
00078                             $match["file"] = $file;
00079                             $foundOverrideFile = true;
00080                             $matchedKeys[$matchKeyName] = $matchKeyValue;
00081                             break;
00082                         }
00083                     }
00084                 }
00085                 if ( $match !== null )
00086                     break;
00087             }
00088         }
00089         return $match;
00090     }
00091 }
00092 
00093 ?>