|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of kernel include functions 00004 // 00005 // Created on: <05-Mar-2003 10:02:29 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 ezincludefunctions.php 00032 Contains some useful kernel include functions which are nice to use in extensions. 00033 */ 00034 00035 /*! 00036 */ 00037 function kernel_include( $name ) 00038 { 00039 $include = "kernel/$name"; 00040 return include_once( $include ); 00041 } 00042 00043 /*! 00044 */ 00045 function kernel_common( $name ) 00046 { 00047 $name = strtolower( $name ); 00048 $include = "kernel/common/$name.php"; 00049 return include_once( $include ); 00050 } 00051 00052 /*! 00053 */ 00054 function datatype_class( $datatype, $className ) 00055 { 00056 $className = strtolower( $className ); 00057 $include = "kernel/classes/datatypes/$datatype/$className.php"; 00058 return include_once( $include ); 00059 } 00060 00061 //Loose functions originally from ezextension.php 00062 00063 function extension_path( $extension, $withWWWDir = false, $withHost = false, $withProtocol = false ) 00064 { 00065 $base = eZExtension::baseDirectory(); 00066 $path = ''; 00067 if ( $withProtocol ) 00068 { 00069 if ( is_string( $withProtocol ) ) 00070 $path .= $withProtocol; 00071 else 00072 { 00073 //include_once( 'lib/ezutils/classes/ezsys.php' ); 00074 $path .= eZSys::serverProtocol(); 00075 } 00076 $path .= ':'; 00077 } 00078 if ( $withHost ) 00079 { 00080 $path .= '//'; 00081 if ( is_string( $withHost ) ) 00082 $path .= $withHost; 00083 else 00084 $path .= eZSys::hostname(); 00085 } 00086 if ( $withWWWDir ) 00087 $path .= eZSys::wwwDir(); 00088 00089 if ( $withWWWDir ) 00090 $path .= '/' . $base . '/' . $extension; 00091 else 00092 $path .= $base . '/' . $extension; 00093 return $path; 00094 } 00095 00096 /*! 00097 \static 00098 \deprecated 00099 eZExtension::nameFromPath( __FILE__ ) executed in any file of an extension 00100 can help you to find the path to additional resources 00101 \return Name of the extension a path belongs to. 00102 \param $path Path to check. 00103 */ 00104 function nameFromPath( $path ) 00105 { 00106 //include_once( 'lib/ezfile/classes/ezdir.php' ); 00107 $path = eZDir::cleanPath( $path ); 00108 $base = eZExtension::baseDirectory() . '/'; 00109 $base = preg_quote( $base, '/' ); 00110 $pattern = '/'.$base.'([^\/]+)/'; 00111 if ( preg_match( $pattern, $path, $matches ) ) 00112 return $matches[1]; 00113 else 00114 false; 00115 } 00116 00117 /*! 00118 \static 00119 \deprecated 00120 \return true if this path is related to some extension. 00121 \param $path Path to check. 00122 \note The root of an extension is considered to be in this path too. 00123 */ 00124 function isExtension( $path ) 00125 { 00126 if ( eZExtension::nameFromPath( $path ) ) 00127 return true; 00128 else 00129 return false; 00130 } 00131 00132 /*! 00133 Includes the file named \a $name in extension \a $extension 00134 \note This works similar to include() meaning that it always includes the file. 00135 */ 00136 function ext_include( $extension, $name ) 00137 { 00138 $base = eZExtension::baseDirectory(); 00139 $include = "$base/$extension/$name"; 00140 return include( $include ); 00141 } 00142 00143 /*! 00144 Activates the file named \a $name in extension \a $extension 00145 \note This works similar to include_once() meaning that it's included one time. 00146 */ 00147 function ext_activate( $extension, $name ) 00148 { 00149 $base = eZExtension::baseDirectory(); 00150 $include = "$base/$extension/$name"; 00151 return include_once( $include ); 00152 } 00153 00154 /*! 00155 Activates the file named \a $name in extension \a $extension 00156 \note This works similar to include_once() meaning that it's included one time. 00157 */ 00158 function ext_class( $extension, $name ) 00159 { 00160 $name = strtolower( $name ); 00161 $base = eZExtension::baseDirectory(); 00162 $include = "$base/$extension/classes/$name.php"; 00163 return include_once( $include ); 00164 } 00165 00166 /*! 00167 */ 00168 function lib_include( $libName, $name ) 00169 { 00170 $include = "lib/$libName/classes/$name"; 00171 return include_once( $include ); 00172 } 00173 00174 /*! 00175 */ 00176 function lib_class( $libName, $name ) 00177 { 00178 $name = strtolower( $name ); 00179 $include = "lib/$libName/classes/$name.php"; 00180 return include_once( $include ); 00181 } 00182 00183 /*! 00184 */ 00185 function kernel_class( $name ) 00186 { 00187 $name = strtolower( $name ); 00188 $include = "kernel/classes/$name.php"; 00189 return include_once( $include ); 00190 } 00191 00192 00193 00194 00195 ?>