PageRenderTime 21ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/kernel/settings/view.php

https://github.com/aurelienRT1/ezpublish
PHP | 255 lines | 186 code | 28 blank | 41 comment | 26 complexity | 45cc070c5603fe90b4f6c4529e35204a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. //
  3. // Created on: <17-Jan-2004 12:41:17 oh>
  4. //
  5. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  6. // SOFTWARE NAME: eZ Publish
  7. // SOFTWARE RELEASE: 4.1.x
  8. // COPYRIGHT NOTICE: Copyright (C) 1999-2010 eZ Systems AS
  9. // SOFTWARE LICENSE: GNU General Public License v2.0
  10. // NOTICE: >
  11. // This program is free software; you can redistribute it and/or
  12. // modify it under the terms of version 2.0 of the GNU General
  13. // Public License as published by the Free Software Foundation.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of version 2.0 of the GNU General
  21. // Public License along with this program; if not, write to the Free
  22. // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23. // MA 02110-1301, USA.
  24. //
  25. //
  26. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  27. //
  28. $tpl = eZTemplate::factory();
  29. $http = eZHTTPTool::instance();
  30. $ini = eZINI::instance();
  31. $siteAccessList = $ini->variable( 'SiteAccessSettings', 'RelatedSiteAccessList' );
  32. if ( $Params['INIFile'] )
  33. $settingFile = $Params['INIFile'];
  34. if ( $http->hasPostVariable( 'selectedINIFile' ) )
  35. $settingFile = $http->variable( "selectedINIFile" );
  36. if ( $Params['SiteAccess'] )
  37. $currentSiteAccess = $Params['SiteAccess'];
  38. if ( $http->hasPostVariable( 'CurrentSiteAccess' ) )
  39. $currentSiteAccess = $http->postVariable( 'CurrentSiteAccess' );
  40. if ( !isset( $currentSiteAccess ) or
  41. !in_array( $currentSiteAccess, $siteAccessList ) )
  42. $currentSiteAccess = $siteAccessList[0];
  43. unset( $ini );
  44. if ( $http->hasPostVariable( 'RemoveButton' ) )
  45. {
  46. if ( isset( $settingFile ) )
  47. {
  48. $ini = eZINI::create( $settingFile, 'settings', null, null, false );
  49. $ini->prependOverrideDir( "siteaccess/$currentSiteAccess", false, 'siteaccess' );
  50. $ini->loadCache();
  51. }
  52. $placements = $ini->groupPlacements();
  53. if ( $http->hasPostVariable( 'RemoveSettingsArray' ) )
  54. {
  55. $deletedSettingArray = $http->postVariable( 'RemoveSettingsArray' );
  56. foreach ( $deletedSettingArray as $deletedSetting )
  57. {
  58. list( $block, $setting ) = explode( ':', $deletedSetting );
  59. if ( is_array( $placements[$block][$setting] ) )
  60. {
  61. foreach ( $placements[$block][$setting] as $settingElementKey=>$key )
  62. {
  63. $placement = $ini->findSettingPlacement( $placements[$block][$setting][$settingElementKey] );
  64. break;
  65. }
  66. }
  67. else
  68. {
  69. $placement = $ini->findSettingPlacement( $placements[$block][$setting] );
  70. }
  71. // Get extension name if exists, $placement might be "extension:ezdhtml"
  72. $exploded = explode( ':', $placement );
  73. $extension = $exploded[0] == 'extension'
  74. ? $exploded[1]
  75. : false;
  76. $path = 'settings/override';
  77. if ( $placement == 'siteaccess' )
  78. $path = "settings/siteaccess/$currentSiteAccess";
  79. elseif ( $placement != 'override' and $extension !== false )
  80. $path = "extension/$extension/settings";
  81. // We should use "reference" if multiply removing of ini setting.
  82. // if eZINI::instance() is called twice instance will be fetched from GLOBAL variable.
  83. // Without reference there will be a inconsistency with GLOBAL instance and stored ini file.
  84. $iniTemp = eZINI::create( $settingFile . '.append.php', $path, null, null, null, true );
  85. $iniTemp->removeSetting( $block, $setting );
  86. $iniTemp->save();
  87. }
  88. }
  89. }
  90. if ( $http->hasPostVariable( 'ChangeINIFile' ) or
  91. ( $Params['SiteAccess'] and $Params['INIFile'] ) )
  92. {
  93. if ( $GLOBALS['eZCurrentAccess']['name'] !== $currentSiteAccess )
  94. {
  95. // create a site ini instance using $useLocalOverrides
  96. $siteIni = eZSiteAccess::getIni( $currentSiteAccess, 'site.ini' );
  97. // load settings file with $useLocalOverrides = true & $addArrayDefinition = true
  98. $ini = new eZINI( $settingFile,'settings', null, false, true, false, true );
  99. // overwrite overrideDirs from siteIni instance
  100. $ini->setOverrideDirs( $siteIni->overrideDirs( false ) );
  101. $ini->load();
  102. }
  103. else
  104. {
  105. // load settings file more or less normally but with $addArrayDefinition = true
  106. $ini = new eZINI( $settingFile,'settings', null, false, null, false, true );
  107. }
  108. $blocks = $ini->groups();
  109. $placements = $ini->groupPlacements();
  110. $settings = array();
  111. $blockCount = 0;
  112. $totalSettingCount = 0;
  113. foreach( $blocks as $block=>$key )
  114. {
  115. $settingsCount = 0;
  116. $blockRemoveable = false;
  117. $blockEditable = true;
  118. foreach( $key as $setting=>$settingKey )
  119. {
  120. $hasSetPlacement = false;
  121. $type = $ini->settingType( $settingKey );
  122. $removeable = false;
  123. switch ( $type )
  124. {
  125. case 'array':
  126. if ( count( $settingKey ) == 0 )
  127. $settings[$block]['content'][$setting]['content'] = array();
  128. foreach( $settingKey as $settingElementKey=>$settingElementValue )
  129. {
  130. $settingPlacement = $ini->findSettingPlacement( $placements[$block][$setting][$settingElementKey] );
  131. if ( $settingElementValue != null )
  132. {
  133. // Make a space after the ';' to make it possible for
  134. // the browser to break long lines
  135. $settings[$block]['content'][$setting]['content'][$settingElementKey]['content'] = str_replace( ';', "; ", $settingElementValue );
  136. }
  137. else
  138. {
  139. $settings[$block]['content'][$setting]['content'][$settingElementKey]['content'] = "";
  140. }
  141. $settings[$block]['content'][$setting]['content'][$settingElementKey]['placement'] = $settingPlacement;
  142. $hasSetPlacement = true;
  143. if ( $settingPlacement != 'default' )
  144. {
  145. $removeable = true;
  146. $blockRemoveable = true;
  147. }
  148. }
  149. break;
  150. case 'string':
  151. if( strpos( $settingKey, ';' ) )
  152. {
  153. // Make a space after the ';' to make it possible for
  154. // the browser to break long lines
  155. $settingArray = str_replace( ';', "; ", $settingKey );
  156. $settings[$block]['content'][$setting]['content'] = $settingArray;
  157. }
  158. else
  159. {
  160. $settings[$block]['content'][$setting]['content'] = $settingKey;
  161. }
  162. break;
  163. default:
  164. $settings[$block]['content'][$setting]['content'] = $settingKey;
  165. }
  166. $settings[$block]['content'][$setting]['type'] = $type;
  167. $settings[$block]['content'][$setting]['placement'] = "";
  168. if ( !$hasSetPlacement )
  169. {
  170. $placement = $ini->findSettingPlacement( $placements[$block][$setting] );
  171. $settings[$block]['content'][$setting]['placement'] = $placement;
  172. if ( $placement != 'default' )
  173. {
  174. $removeable = true;
  175. $blockRemoveable = true;
  176. }
  177. }
  178. $editable = $ini->isSettingReadOnly( $settingFile, $block, $setting );
  179. $removeable = $editable === false ? false : $removeable;
  180. $settings[$block]['content'][$setting]['editable'] = $editable;
  181. $settings[$block]['content'][$setting]['removeable'] = $removeable;
  182. ++$settingsCount;
  183. }
  184. $blockEditable = $ini->isSettingReadOnly( $settingFile, $block );
  185. $settings[$block]['count'] = $settingsCount;
  186. $settings[$block]['removeable'] = $blockRemoveable;
  187. $settings[$block]['editable'] = $blockEditable;
  188. $totalSettingCount += $settingsCount;
  189. ++$blockCount;
  190. }
  191. ksort( $settings );
  192. $tpl->setVariable( 'settings', $settings );
  193. $tpl->setVariable( 'block_count', $blockCount );
  194. $tpl->setVariable( 'setting_count', $totalSettingCount );
  195. $tpl->setVariable( 'ini_file', $settingFile );
  196. }
  197. else
  198. {
  199. $tpl->setVariable( 'settings', false );
  200. $tpl->setVariable( 'block_count', false );
  201. $tpl->setVariable( 'setting_count', false );
  202. $tpl->setVariable( 'ini_file', false );
  203. }
  204. $rootDir = 'settings';
  205. $iniFiles = eZDir::recursiveFindRelative( $rootDir, '', '.ini' );
  206. // find all .ini files in active extensions
  207. foreach ( eZINI::globalOverrideDirs() as $iniDataSet )
  208. {
  209. $iniPath = $iniDataSet[1] ? $iniDataSet[0] : 'settings/' . $iniDataSet[0];
  210. $iniFiles = array_merge( $iniFiles, eZDir::recursiveFindRelative( $iniPath, '', '.ini' ) );
  211. $iniFiles = array_merge( $iniFiles, eZDir::recursiveFindRelative( $iniPath, '', '.ini.append.php' ) );
  212. }
  213. // extract all .ini files without path
  214. $iniFiles = preg_replace('%.*/%', '', $iniFiles );
  215. // remove *.ini[.append.php] from file name
  216. $iniFiles = preg_replace('%\.ini.*%', '.ini', $iniFiles );
  217. sort( $iniFiles );
  218. $tpl->setVariable( 'ini_files', array_unique( $iniFiles ) );
  219. $tpl->setVariable( 'siteaccess_list', $siteAccessList );
  220. $tpl->setVariable( 'current_siteaccess', $currentSiteAccess );
  221. $Result = array();
  222. $Result['content'] = $tpl->fetch( 'design:settings/view.tpl' );
  223. $Result['path'] = array( array( 'text' => ezpI18n::tr( 'settings/view', 'Settings' ),
  224. 'url' => false ),
  225. array( 'text' => ezpI18n::tr( 'settings/view', 'View' ),
  226. 'url' => false ) );
  227. ?>