00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class eZOverride
00041 {
00042
00043
00044
00045 function eZOverride()
00046 {
00047 }
00048
00049 function selectFile( $matches, $matchKeys, &$matchedKeys, $regexpMatch )
00050 {
00051 $match = null;
00052 foreach ( $matches as $templateMatch )
00053 {
00054 $templatePath = $templateMatch["file"];
00055 $templateType = $templateMatch["type"];
00056 if ( $templateType == "normal" )
00057 {
00058 if ( file_exists( $templatePath ) )
00059 {
00060 $match = $templateMatch;
00061 break;
00062 }
00063 }
00064 else if ( $templateType == "override" )
00065 {
00066 $foundOverrideFile = false;
00067 if ( file_exists( $templatePath ) )
00068 {
00069 $match = $templateMatch;
00070 $match["file"] = $templatePath;
00071 $foundOverrideFile = true;
00072 }
00073 if ( !$foundOverrideFile and
00074 count( $matchKeys ) == 0 )
00075 continue;
00076 if ( !$foundOverrideFile and
00077 preg_match( $regexpMatch, $templatePath, $regs ) )
00078 {
00079 foreach ( $matchKeys as $matchKeyName => $matchKeyValue )
00080 {
00081 $file = $regs[1] . "/" . $regs[2] . "_$matchKeyName" . "_$matchKeyValue" . $regs[3];
00082 if ( file_exists( $file ) )
00083 {
00084 $match = $templateMatch;
00085 $match["file"] = $file;
00086 $foundOverrideFile = true;
00087 $matchedKeys[$matchKeyName] = $matchKeyValue;
00088
00089 break;
00090 }
00091 }
00092 }
00093 if ( $match !== null )
00094 break;
00095 }
00096 }
00097 return $match;
00098 }
00099 }
00100
00101 ?>