PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/kernel/setup/extensions.php

https://github.com/granitegreg/ezpublish
PHP | 154 lines | 91 code | 23 blank | 40 comment | 7 complexity | fb6c8ff42999f77e9e81c3a9c2ff150b MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. //
  3. // Definition of Extensions class
  4. //
  5. // Created on: <03-Jul-2003 10:14:14 jhe>
  6. //
  7. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  8. // SOFTWARE NAME: eZ Publish
  9. // SOFTWARE RELEASE: 4.1.x
  10. // COPYRIGHT NOTICE: Copyright (C) 1999-2011 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. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  29. //
  30. $http = eZHTTPTool::instance();
  31. $module = $Params['Module'];
  32. $tpl = eZTemplate::factory();
  33. $extensionDir = eZExtension::baseDirectory();
  34. $availableExtensionArray = eZDir::findSubItems( $extensionDir, 'dl' );
  35. // open site.ini for reading
  36. $siteINI = eZINI::instance();
  37. $siteINI->load();
  38. $selectedExtensionArray = $siteINI->variable( 'ExtensionSettings', "ActiveExtensions" );
  39. $selectedAccessExtensionArray = $siteINI->variable( 'ExtensionSettings', "ActiveAccessExtensions" );
  40. $selectedExtensions = array_merge( $selectedExtensionArray, $selectedAccessExtensionArray );
  41. $selectedExtensions = array_unique( $selectedExtensions );
  42. // When the user clicks on "Apply changes" button in admin interface in the Extensions section
  43. if ( $module->isCurrentAction( 'ActivateExtensions' ) )
  44. {
  45. $ini = eZINI::instance( 'module.ini' );
  46. $oldModules = $ini->variable( 'ModuleSettings', 'ModuleList' );
  47. if ( $http->hasPostVariable( "ActiveExtensionList" ) )
  48. {
  49. $selectedExtensionArray = $http->postVariable( "ActiveExtensionList" );
  50. if ( !is_array( $selectedExtensionArray ) )
  51. $selectedExtensionArray = array( $selectedExtensionArray );
  52. }
  53. else
  54. {
  55. $selectedExtensionArray = array();
  56. }
  57. // The file settings/override/site.ini.append.php is updated like this:
  58. // - take the existing list of extensions from site.ini.append.php (to preserve their order)
  59. // - remove from the list the extensions that the user unchecked in the admin interface
  60. // - add to the list the extensions checked by the user in the admin interface, but to the end of the list
  61. $intersection = array_intersect( $selectedExtensions, $selectedExtensionArray );
  62. $difference = array_diff( $selectedExtensionArray, $selectedExtensions );
  63. $toSave = array_merge( $intersection, $difference );
  64. $toSave = array_unique( $toSave );
  65. // open settings/override/site.ini.append[.php] for writing
  66. $writeSiteINI = eZINI::instance( 'site.ini.append', 'settings/override', null, null, false, true );
  67. $writeSiteINI->setVariable( "ExtensionSettings", "ActiveExtensions", $toSave );
  68. $writeSiteINI->save( 'site.ini.append', '.php', false, false );
  69. eZCache::clearByTag( 'ini' );
  70. eZSiteAccess::reInitialise();
  71. $ini = eZINI::instance( 'module.ini' );
  72. $currentModules = $ini->variable( 'ModuleSettings', 'ModuleList' );
  73. if ( $currentModules != $oldModules )
  74. {
  75. // ensure that evaluated policy wildcards in the user info cache
  76. // will be up to date with the currently activated modules
  77. eZCache::clearByID( 'user_info_cache' );
  78. }
  79. updateAutoload( $tpl );
  80. }
  81. // 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
  82. $siteINI = eZINI::instance();
  83. $siteINI->load();
  84. $selectedExtensionArray = $siteINI->variable( 'ExtensionSettings', "ActiveExtensions" );
  85. $selectedAccessExtensionArray = $siteINI->variable( 'ExtensionSettings', "ActiveAccessExtensions" );
  86. $selectedExtensions = array_merge( $selectedExtensionArray, $selectedAccessExtensionArray );
  87. $selectedExtensions = array_unique( $selectedExtensions );
  88. if ( $module->isCurrentAction( 'GenerateAutoloadArrays' ) )
  89. {
  90. updateAutoload( $tpl );
  91. }
  92. $tpl->setVariable( "available_extension_array", $availableExtensionArray );
  93. $tpl->setVariable( "selected_extension_array", $selectedExtensions );
  94. $Result = array();
  95. $Result['content'] = $tpl->fetch( "design:setup/extensions.tpl" );
  96. $Result['path'] = array( array( 'url' => false,
  97. 'text' => ezpI18n::tr( 'kernel/setup', 'Extension configuration' ) ) );
  98. function updateAutoload( $tpl = null )
  99. {
  100. $autoloadGenerator = new eZAutoloadGenerator();
  101. try
  102. {
  103. $autoloadGenerator->buildAutoloadArrays();
  104. $messages = $autoloadGenerator->getMessages();
  105. foreach( $messages as $message )
  106. {
  107. eZDebug::writeNotice( $message, 'eZAutoloadGenerator' );
  108. }
  109. $warnings = $autoloadGenerator->getWarnings();
  110. foreach ( $warnings as &$warning )
  111. {
  112. eZDebug::writeWarning( $warning, "eZAutoloadGenerator" );
  113. // For web output we want to mark some of the important parts of
  114. // the message
  115. $pattern = '@^Class\s+(\w+)\s+.* file\s(.+\.php).*\n(.+\.php)\s@';
  116. preg_match( $pattern, $warning, $m );
  117. $warning = str_replace( $m[1], '<strong>'.$m[1].'</strong>', $warning );
  118. $warning = str_replace( $m[2], '<em>'.$m[2].'</em>', $warning );
  119. $warning = str_replace( $m[3], '<em>'.$m[3].'</em>', $warning );
  120. }
  121. if ( $tpl !== null )
  122. {
  123. $tpl->setVariable( 'warning_messages', $warnings );
  124. }
  125. }
  126. catch ( Exception $e )
  127. {
  128. eZDebug::writeError( $e->getMessage() );
  129. }
  130. }
  131. ?>