|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZHTTPHeader class 00004 // 00005 // Created on: <24-Nov-2005 12:34:48 hovik> 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 ezhttpheader.php 00032 */ 00033 00034 /*! 00035 \class eZHTTPHeader ezhttpheader.php 00036 \brief The class eZHTTPHeader does 00037 00038 */ 00039 00040 class eZHTTPHeader 00041 { 00042 /*! 00043 * \static 00044 * Returns true if the custom HTTP headers are enabled, false otherwise. 00045 * The result is cached in memory to save time on multiple invocations. 00046 */ 00047 static function enabled() 00048 { 00049 if ( isset( $GLOBALS['eZHTTPHeaderCustom'] ) ) 00050 { 00051 return $GLOBALS['eZHTTPHeaderCustom']; 00052 } 00053 00054 $ini = eZINI::instance(); 00055 if ( !$ini->hasVariable( 'HTTPHeaderSettings', 'CustomHeader' ) ) 00056 { 00057 $GLOBALS['eZHTTPHeaderCustom'] = false; 00058 } 00059 else 00060 { 00061 if ( $ini->variable( 'HTTPHeaderSettings', 'CustomHeader' ) === 'enabled' 00062 && $ini->hasVariable( 'HTTPHeaderSettings', 'OnlyForAnonymous' ) 00063 && $ini->variable( 'HTTPHeaderSettings', 'OnlyForAnonymous' ) === 'enabled' ) 00064 { 00065 $user = eZUser::currentUser(); 00066 $GLOBALS['eZHTTPHeaderCustom'] = !$user->isLoggedIn(); 00067 } 00068 else 00069 { 00070 $GLOBALS['eZHTTPHeaderCustom'] = $ini->variable( 'HTTPHeaderSettings', 'CustomHeader' ) == 'enabled'; 00071 } 00072 } 00073 00074 return $GLOBALS['eZHTTPHeaderCustom']; 00075 } 00076 00077 /*! 00078 \static 00079 Get Header override array by requested URI 00080 */ 00081 static function headerOverrideArray( $uri ) 00082 { 00083 $headerArray = array(); 00084 00085 if ( !eZHTTPHeader::enabled() ) 00086 { 00087 return $headerArray; 00088 } 00089 00090 $contentView = false; 00091 00092 //include_once( 'kernel/classes/ezurlaliasml.php' ); 00093 $uriString = eZURLAliasML::cleanURL( $uri->uriString() ); 00094 00095 // If content/view used, get url alias for node 00096 if ( strpos( $uriString, 'content/view/' ) === 0 ) 00097 { 00098 $urlParts = explode( '/', $uriString ); 00099 $nodeID = $urlParts[3]; 00100 if ( !$nodeID ) 00101 { 00102 return $headerArray; 00103 } 00104 00105 //include_once( 'kernel/classes/ezcontentobjecttreenode.php' ); 00106 $node = eZContentObjectTreeNode::fetch( $nodeID ); 00107 if ( !$node ) 00108 { 00109 return $headerArray; 00110 } 00111 00112 $uriString = $node->pathWithNames(); 00113 $contentView = true; 00114 } 00115 else 00116 { 00117 $uriCopy = clone $uri; 00118 eZURLAliasML::translate( $uriCopy ); 00119 if ( strpos( $uriCopy->uriString(), 'content/view' ) === 0 ) 00120 { 00121 $contentView = true; 00122 } 00123 } 00124 00125 $uriString = '/' . eZURLAliasML::cleanURL( $uriString ); 00126 $ini = eZINI::instance(); 00127 00128 foreach( $ini->variable( 'HTTPHeaderSettings', 'HeaderList' ) as $header ) 00129 { 00130 foreach( $ini->variable( 'HTTPHeaderSettings', $header ) as $path => $value ) 00131 { 00132 $path = '/' . eZURLAliasML::cleanURL( $path ); 00133 if ( strlen( $path ) == 1 && 00134 !$contentView && 00135 $uriString != '/' ) 00136 { 00137 continue; 00138 } 00139 00140 if ( strpos( $uriString, $path ) === 0 ) 00141 { 00142 @list( $headerValue, $depth, $level ) = explode( ';', $value ); 00143 00144 if ( $header == 'Expires' ) 00145 { 00146 $headerValue = gmdate( 'D, d M Y H:i:s', time() + $headerValue ) . ' GMT'; 00147 } 00148 00149 if ( $depth === null ) 00150 { 00151 $headerArray[$header] = $headerValue; 00152 } 00153 else 00154 { 00155 $pathLevel = count( explode( '/', $path ) ); 00156 $uriLevel = count( explode( '/', $uriString ) ); 00157 if ( $level === null ) 00158 { 00159 if ( $uriLevel <= $pathLevel + $depth ) 00160 { 00161 $headerArray[$header] = $headerValue; 00162 } 00163 } 00164 else 00165 { 00166 if ( $uriLevel <= $pathLevel + $depth && 00167 $uriLevel >= $pathLevel + $level ) 00168 { 00169 $headerArray[$header] = $headerValue; 00170 } 00171 } 00172 } 00173 } 00174 } 00175 } 00176 00177 return $headerArray; 00178 } 00179 } 00180 00181 ?>