| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZExtension class 4 // 5 // Created on: <16-Mar-2002 14:23:45 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezextension.php 30 */ 31 32 /*! 33 \class eZExtension ezextension.php 34 \brief The class eZExtension does 35 36 */ 37 38 include_once ( 'lib/ezutils/classes/ezini.php' ); 39 40 class eZExtension 41 { 42 /*! 43 Constructor 44 */ 45 function eZExtension() 46 { 47 } 48 49 /*! 50 \static 51 \return the base directory for extensions 52 */ 53 function baseDirectory() 54 { 55 $ini =& eZINI::instance(); 56 $extensionDirectory = $ini->variable( 'ExtensionSettings', 'ExtensionDirectory' ); 57 return $extensionDirectory; 58 } 59 60 /*! 61 \static 62 \return an array with extensions that has been activated. 63 \param $extensionType Decides which extension to include in the list, the follow values are possible. 64 - \c false - Means add both default and access extensions 65 - 'default' - Add only default extensions 66 - 'access' - Add only access extensions 67 68 Default extensions are those who are loaded before a siteaccess are determined while access extensions 69 are loaded after siteaccess is set. 70 */ 71 function activeExtensions( $extensionType = false ) 72 { 73 $ini =& eZINI::instance(); 74 $activeExtensions = array(); 75 if ( !$extensionType or 76 $extensionType == 'default' ) 77 $activeExtensions = array_merge( $activeExtensions, 78 $ini->variable( 'ExtensionSettings', 'ActiveExtensions' ) ); 79 if ( !$extensionType or 80 $extensionType == 'access' ) 81 $activeExtensions = array_merge( $activeExtensions, 82 $ini->variable( 'ExtensionSettings', 'ActiveAccessExtensions' ) ); 83 $globalActiveExtensions =& $GLOBALS['eZActiveExtensions']; 84 if ( isset( $globalActiveExtensions ) ) 85 { 86 $activeExtensions = array_merge( $activeExtensions, 87 $globalActiveExtensions ); 88 } 89 $activeExtensions = array_unique( $activeExtensions ); 90 return $activeExtensions; 91 } 92 93 /*! 94 \static 95 Will make sure that all extensions that has settings directories 96 are added to the eZINI override list. 97 */ 98 function activateExtensions( $extensionType = false ) 99 { 100 $extensionDirectory = eZExtension::baseDirectory(); 101 $activeExtensions = eZExtension::activeExtensions( $extensionType ); 102 $hasExtensions = false; 103 $ini =& eZINI::instance(); 104 foreach ( $activeExtensions as $activeExtension ) 105 { 106 if ( !file_exists( $extensionDirectory . '/' . $activeExtension ) ) 107 { 108 eZDebug::writeWarning( "Extension '$activeExtension' does not exist, looked for directory '" . $extensionDirectory . '/' . $activeExtension . "'" ); 109 } 110 $extensionSettingsPath = $extensionDirectory . '/' . $activeExtension . '/settings'; 111 if ( file_exists( $extensionSettingsPath ) ) 112 { 113 $ini->prependOverrideDir( $extensionSettingsPath, true ); 114 115 if ( isset( $GLOBALS['eZCurrentAccess'] ) ) 116 { 117 eZExtension::prependSiteAccess( $activeExtension ); 118 } 119 $hasExtensions = true; 120 } 121 } 122 if ( $hasExtensions ) 123 $ini->loadCache(); 124 } 125 126 /*! 127 \static 128 129 Prepend extension siteaccesses 130 131 \param siteaccess name ( default false ) 132 */ 133 function prependExtensionSiteAccesses( $accessName = false, $ini = false, $globalDir = true, $identifier = false, $order = true ) 134 { 135 $extensionList = eZExtension::activeExtensions(); 136 137 if ( !$order ) 138 { 139 $extensionList = array_reverse( $extensionList ); 140 } 141 142 foreach( $extensionList as $extension ) 143 { 144 eZExtension::prependSiteAccess( $extension, $accessName, $ini, $globalDir, $identifier ); 145 } 146 } 147 148 /*! 149 \static 150 151 Prepend siteaccess for specified extension. 152 153 \param $extension name 154 */ 155 function prependSiteAccess( $extension, $accessName = false, $ini = false, $globalDir = true, $identifier = false ) 156 { 157 if ( !$accessName ) 158 { 159 $accessName = $GLOBALS['eZCurrentAccess']['name']; 160 } 161 162 $extensionSettingsPath = eZExtension::baseDirectory() . '/' . $extension; 163 164 if ( file_exists ( $extensionSettingsPath . '/settings/siteaccess/' . $accessName ) ) 165 { 166 if ( !$ini ) 167 { 168 $ini =& eZINI::instance(); 169 } 170 $ini->prependOverrideDir( $extensionSettingsPath . '/settings/siteaccess/' . $accessName, $globalDir ); 171 } 172 } 173 174 /*! 175 \static 176 Generates a list with expanded paths and returns it. 177 The paths are expanded to where the extensions are placed. 178 Optionally a subdirectory of the extension may be set using \a $subdirectory. 179 */ 180 function expandedPathList( $extensionList, $subdirectory = false ) 181 { 182 $pathList = array(); 183 $extensionBase = eZExtension::baseDirectory(); 184 foreach ( $extensionList as $extensionName ) 185 { 186 $path = $extensionBase . '/' . $extensionName; 187 if ( $subdirectory ) 188 $path .= '/' . $subdirectory; 189 $pathList[] = $path; 190 } 191 return $pathList; 192 } 193 194 /*! 195 \static 196 This is help function for searching for extension code. It will read ini variables 197 defined in \a $parameters, search trough the specified directories for specific files 198 and set the result in \a $out. 199 200 The \a $parameters parameter must contain the following entries. 201 - ini-name - The name of the ini file which has the settings, must include the .ini suffix. 202 - repository-group - The INI group which has the basic repository settings. 203 - repository-variable - The INI variable which has the basic repository settings. 204 - extension-group - The INI group which has the extension settings. 205 - extension-variable - The INI variable which has the extension settings. 206 - subdir - A subdir which will be appended to all repositories searched for, can be left out. 207 - extension-subdir - A subdir which will be appended to all extension repositories searched for, can be left out. 208 - suffix-name - A suffix which will be appended after the file searched for. 209 - type-directory - Whether the type has a directory for it's file or not. Default is true. 210 - type - The type to look for, it will try to find a file named repository/subdir/type/type-suffix or 211 if type-directory is false repository/subdir/type-suffix. 212 If type is not specified the type-group and typ-variable may be used for fetching the current type. 213 - type-group - The INI group which has the type setting. 214 - type-variable - The INI variable which has the type setting. 215 - alias-group - The INI group which defines type aliases, see below. 216 - alias-variable - The INI variable which defines type aliases. 217 218 Type aliases allows overriding a specific type to use another type handler, 219 this is useful when extensions want to take control of some specific types 220 or you want multiple names (aliases) for one type. 221 222 On success the \a $out parameter will contain: 223 - type - The current type used. 224 - original-type - The original type, if aliasing was used it may differ from type. 225 - found-file-dir - The directory where the type was found. 226 - found-file-path - The full path to the type. 227 - found-file-name - The filename of the type. 228 229 \return true if the extension type was found. 230 */ 231 function findExtensionType( $parameters, &$out ) 232 { 233 $iniName = $parameters['ini-name']; 234 $repositoryGroup = $parameters['repository-group']; 235 $repositoryVariable = $parameters['repository-variable']; 236 $extensionGroup = $parameters['extension-group']; 237 $extensionVariable = $parameters['extension-variable']; 238 $subdir = false; 239 if ( isset( $parameters['subdir'] ) ) 240 $subdir = $parameters['subdir']; 241 $extensionSubdir = false; 242 if ( isset( $parameters['extension-subdir'] ) ) 243 $extensionSubdir = $parameters['extension-subdir']; 244 $typeDirectory = true; 245 if ( isset( $parameters['type-directory'] ) ) 246 $typeDirectory = $parameters['type-directory']; 247 $suffixName = $parameters['suffix-name']; 248 $ini =& eZINI::instance( $iniName ); 249 if ( isset( $parameters['type'] ) ) 250 $originalType = $parameters['type']; 251 else if ( isset( $parameters['type-group'] ) and 252 isset( $parameters['type-variable'] ) ) 253 $originalType = $ini->variable( $parameters['type-group'], $parameters['type-variable'] ); 254 else 255 return false; 256 $type = $originalType; 257 if ( isset( $parameters['alias-group'] ) and 258 isset( $parameters['alias-variable'] ) ) 259 { 260 if ( $ini->hasVariable( $parameters['alias-group'], $parameters['alias-variable'] ) ) 261 { 262 $aliasMap = $ini->variable( $parameters['alias-group'], $parameters['alias-variable'] ); 263 if ( isset( $aliasMap[$type] ) ) 264 $type = $aliasMap[$type]; 265 } 266 } 267 268 $baseDirectory = eZExtension::baseDirectory(); 269 $repositoryDirectoryList = array(); 270 $repositoryList = $ini->variable( $repositoryGroup, $repositoryVariable ); 271 $extensionDirectories = $ini->variable( $extensionGroup, $extensionVariable ); 272 foreach ( $repositoryList as $repository ) 273 { 274 $repositoryDirectory = $repository; 275 if ( $subdir != '' ) 276 $repositoryDirectory .= '/' . $subdir; 277 $repositoryDirectoryList[] = $repositoryDirectory; 278 } 279 foreach ( $extensionDirectories as $extensionDirectory ) 280 { 281 $extensionPath = $baseDirectory . '/' . $extensionDirectory; 282 if ( $extensionSubdir != '' ) 283 $extensionPath .= '/' . $extensionSubdir; 284 if ( file_exists( $extensionPath ) ) 285 { 286 $repositoryDirectoryList[] = $extensionPath; 287 } 288 else if ( $extensionSubdir ) 289 { 290 eZDebug::writeWarning( "Extension '$extensionDirectory' does not have the subdirectory $extensionSubdir, looked for directory '" . $extensionPath . "'" ); 291 } 292 } 293 $foundType = false; 294 foreach ( $repositoryDirectoryList as $repositoryDirectory ) 295 { 296 $fileDir = $repositoryDirectory; 297 if ( $typeDirectory ) 298 $fileDir .= "/$type"; 299 $fileName = $type . $suffixName; 300 $filePath = $fileDir . '/' . $fileName; 301 if ( file_exists( $filePath ) ) 302 { 303 $foundType = true; 304 break; 305 } 306 } 307 $out['repository-directory-list'] = $repositoryDirectoryList; 308 if ( $foundType ) 309 { 310 $out['type'] = $type; 311 $out['original-type'] = $originalType; 312 $out['found-file-dir'] = $fileDir; 313 $out['found-file-path'] = $filePath; 314 $out['found-file-name'] = $fileName; 315 } 316 $out['found-type'] = $foundType; 317 return $foundType; 318 } 319 320 /*! 321 \static 322 Read extension information. Returns extension information array 323 specified in feature request 9371. ( http://issues.ez.no/9371 ) 324 325 \param extension name 326 327 \return Extension information array. null if extension is not found, 328 or does not contain extension information. 329 */ 330 function extensionInfo( $extension ) 331 { 332 include_once ( 'lib/ezfile/classes/ezdir.php' ); 333 $infoFileName = eZDir::path( array( eZExtension::baseDirectory(), $extension, 'ezinfo.php' ) ); 334 if ( file_exists( $infoFileName ) ) 335 { 336 include_once( $infoFileName ); 337 $className = $extension . 'Info'; 338 if ( is_callable( array( $className, 'info' ) ) ) 339 { 340 $result = call_user_func_array( array( $className, 'info' ), array() ); 341 if ( is_array( $result ) ) 342 { 343 return $result; 344 } 345 } 346 } 347 348 return null; 349 } 350 } 351 352 function extension_path( $extension, $withWWWDir = false, $withHost = false, $withProtocol = false ) 353 { 354 $base = eZExtension::baseDirectory(); 355 $path = ''; 356 if ( $withProtocol ) 357 { 358 if ( is_string( $withProtocol ) ) 359 $path .= $withProtocol . ':'; 360 else 361 { 362 include_once ( 'lib/ezutils/classes/ezsys.php' ); 363 $path .= eZSys::serverProtocol(); 364 } 365 } 366 if ( $withHost ) 367 { 368 $path .= '//'; 369 if ( is_string( $withHost ) ) 370 $path .= $withHost; 371 else 372 $path .= eZSys::hostname(); 373 } 374 if ( $withWWWDir ) 375 $path .= eZSys::wwwDir(); 376 377 if ( $withWWWDir ) 378 $path .= '/' . $base . '/' . $extension; 379 else 380 $path .= $base . '/' . $extension; 381 return $path; 382 } 383 384 /*! 385 \static 386 eZExtension::nameFromPath( __FILE__ ) executed in any file of an extension 387 can help you to find the path to additional resources 388 \return Name of the extension a path belongs to. 389 \param $path Path to check. 390 */ 391 function nameFromPath( $path ) 392 { 393 include_once ( 'lib/ezfile/classes/ezdir.php' ); 394 $path = eZDir::cleanPath( $path ); 395 $base = eZExtension::baseDirectory() . '/'; 396 $base = preg_quote( $base, '/' ); 397 $pattern = '/'.$base.'([^\/]+)/'; 398 if ( preg_match( $pattern, $path, $matches ) ) 399 return $matches[1]; 400 else 401 false; 402 } 403 404 /*! 405 \static 406 \return true if this path is related to some extension. 407 \param $path Path to check. 408 \note The root of an extension is considered to be in this path too. 409 */ 410 function isExtension( $path ) 411 { 412 if ( eZExtension::nameFromPath( $path ) ) 413 return true; 414 else 415 return false; 416 } 417 418 /*! 419 Includes the file named \a $name in extension \a $extension 420 \note This works similar to include() meaning that it always includes the file. 421 */ 422 function ext_include( $extension, $name ) 423 { 424 $base = eZExtension::baseDirectory(); 425 $include = "$base/$extension/$name"; 426 return include( $include ); 427 } 428 429 /*! 430 Activates the file named \a $name in extension \a $extension 431 \note This works similar to include_once() meaning that it's included one time. 432 */ 433 function ext_activate( $extension, $name ) 434 { 435 $base = eZExtension::baseDirectory(); 436 $include = "$base/$extension/$name"; 437 return include_once( $include ); 438 } 439 440 /*! 441 Activates the file named \a $name in extension \a $extension 442 \note This works similar to include_once() meaning that it's included one time. 443 */ 444 function ext_class( $extension, $name ) 445 { 446 $name = strtolower( $name ); 447 $base = eZExtension::baseDirectory(); 448 $include = "$base/$extension/classes/$name.php"; 449 return include_once( $include ); 450 } 451 452 /*! 453 */ 454 function lib_include( $libName, $name ) 455 { 456 $include = "lib/$libName/classes/$name"; 457 return include_once( $include ); 458 } 459 460 /*! 461 */ 462 function lib_class( $libName, $name ) 463 { 464 $name = strtolower( $name ); 465 $include = "lib/$libName/classes/$name.php"; 466 return include_once( $include ); 467 } 468 469 /*! 470 */ 471 function kernel_class( $name ) 472 { 473 $name = strtolower( $name ); 474 $include = "kernel/classes/$name.php"; 475 return include_once( $include ); 476 } 477 478 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |