eZ Publish  [trunk]
extensions.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00004  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00005  * @version //autogentag//
00006  * @package kernel
00007  */
00008 
00009 $http = eZHTTPTool::instance();
00010 $module = $Params['Module'];
00011 
00012 
00013 $tpl = eZTemplate::factory();
00014 
00015 $extensionDir = eZExtension::baseDirectory();
00016 $availableExtensionArray = eZDir::findSubItems( $extensionDir, 'dl' );
00017 
00018 // open site.ini for reading
00019 $siteINI = eZINI::instance();
00020 $siteINI->load();
00021 $selectedExtensionArray       = $siteINI->variable( 'ExtensionSettings', "ActiveExtensions" );
00022 $selectedAccessExtensionArray = $siteINI->variable( 'ExtensionSettings', "ActiveAccessExtensions" );
00023 $selectedExtensions           = array_merge( $selectedExtensionArray, $selectedAccessExtensionArray );
00024 $selectedExtensions           = array_unique( $selectedExtensions );
00025 
00026 // When the user clicks on "Apply changes" button in admin interface in the Extensions section
00027 if ( $module->isCurrentAction( 'ActivateExtensions' ) )
00028 {
00029     $ini = eZINI::instance( 'module.ini' );
00030     $oldModules = $ini->variable( 'ModuleSettings', 'ModuleList' );
00031 
00032     if ( $http->hasPostVariable( "ActiveExtensionList" ) )
00033     {
00034         $selectedExtensionArray = $http->postVariable( "ActiveExtensionList" );
00035         if ( !is_array( $selectedExtensionArray ) )
00036             $selectedExtensionArray = array( $selectedExtensionArray );
00037     }
00038     else
00039     {
00040         $selectedExtensionArray = array();
00041     }
00042 
00043     // The file settings/override/site.ini.append.php is updated like this:
00044     // - take the existing list of extensions from site.ini.append.php (to preserve their order)
00045     // - remove from the list the extensions that the user unchecked in the admin interface
00046     // - add to the list the extensions checked by the user in the admin interface, but to the end of the list
00047     $intersection = array_intersect( $selectedExtensions, $selectedExtensionArray );
00048     $difference = array_diff( $selectedExtensionArray, $selectedExtensions );
00049     $toSave = array_merge( $intersection, $difference );
00050     $toSave = array_unique( $toSave );
00051 
00052     // open settings/override/site.ini.append[.php] for writing
00053     $writeSiteINI = eZINI::instance( 'site.ini.append', 'settings/override', null, null, false, true );
00054     $writeSiteINI->setVariable( "ExtensionSettings", "ActiveExtensions", $toSave );
00055     $writeSiteINI->save( 'site.ini.append', '.php', false, false );
00056     eZCache::clearByTag( 'ini' );
00057 
00058     eZSiteAccess::reInitialise();
00059 
00060     $ini = eZINI::instance( 'module.ini' );
00061     $currentModules = $ini->variable( 'ModuleSettings', 'ModuleList' );
00062     if ( $currentModules != $oldModules )
00063     {
00064         // ensure that evaluated policy wildcards in the user info cache
00065         // will be up to date with the currently activated modules
00066         eZCache::clearByID( 'user_info_cache' );
00067     }
00068 
00069     updateAutoload( $tpl );
00070 }
00071 
00072 // open site.ini for reading (need to do it again to take into account the changes made to site.ini after clicking "Apply changes" button above
00073 $siteINI = eZINI::instance();
00074 $siteINI->load();
00075 $selectedExtensionArray       = $siteINI->variable( 'ExtensionSettings', "ActiveExtensions" );
00076 $selectedAccessExtensionArray = $siteINI->variable( 'ExtensionSettings', "ActiveAccessExtensions" );
00077 $selectedExtensions           = array_merge( $selectedExtensionArray, $selectedAccessExtensionArray );
00078 $selectedExtensions           = array_unique( $selectedExtensions );
00079 
00080 if ( $module->isCurrentAction( 'GenerateAutoloadArrays' ) )
00081 {
00082     updateAutoload( $tpl );
00083 }
00084 
00085 $tpl->setVariable( "available_extension_array", $availableExtensionArray );
00086 $tpl->setVariable( "selected_extension_array", $selectedExtensions );
00087 
00088 $Result = array();
00089 $Result['content'] = $tpl->fetch( "design:setup/extensions.tpl" );
00090 $Result['path'] = array( array( 'url' => false,
00091                                 'text' => ezpI18n::tr( 'kernel/setup', 'Extension configuration' ) ) );
00092 
00093 function updateAutoload( $tpl = null )
00094 {
00095     $autoloadGenerator = new eZAutoloadGenerator();
00096     try
00097     {
00098         $autoloadGenerator->buildAutoloadArrays();
00099 
00100         $messages = $autoloadGenerator->getMessages();
00101         foreach( $messages as $message )
00102         {
00103             eZDebug::writeNotice( $message, 'eZAutoloadGenerator' );
00104         }
00105 
00106         $warnings = $autoloadGenerator->getWarnings();
00107         foreach ( $warnings as &$warning )
00108         {
00109             eZDebug::writeWarning( $warning, "eZAutoloadGenerator" );
00110 
00111             // For web output we want to mark some of the important parts of
00112             // the message
00113             $pattern = '@^Class\s+(\w+)\s+.* file\s(.+\.php).*\n(.+\.php)\s@';
00114             preg_match( $pattern, $warning, $m );
00115 
00116             $warning = str_replace( $m[1], '<strong>'.$m[1].'</strong>', $warning );
00117             $warning = str_replace( $m[2], '<em>'.$m[2].'</em>', $warning );
00118             $warning = str_replace( $m[3], '<em>'.$m[3].'</em>', $warning );
00119         }
00120 
00121         if ( $tpl !== null )
00122         {
00123             $tpl->setVariable( 'warning_messages', $warnings );
00124         }
00125     }
00126     catch ( Exception $e )
00127     {
00128         eZDebug::writeError( $e->getMessage() );
00129     }
00130 }
00131 
00132 ?>