PageRenderTime 77ms CodeModel.GetById 41ms RepoModel.GetById 4ms app.codeStats 0ms

/kernel/settings/view.php

https://github.com/Socrattes2099/ezpublish
PHP | 255 lines | 186 code | 29 blank | 40 comment | 26 complexity | b36f5538d47f7ceabe1b060e9e3fdb58 MD5 | raw file
  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 ( $http->hasPostVariable( 'RemoveSettingsArray' ) )
  47. {
  48. if ( isset( $settingFile ) )
  49. {
  50. $ini = eZSiteAccess::getIni( $currentSiteAccess, $settingFile );
  51. }
  52. $placements = $ini->groupPlacements();
  53. $deletedSettingArray = $http->postVariable( 'RemoveSettingsArray' );
  54. foreach ( $deletedSettingArray as $deletedSetting )
  55. {
  56. list( $block, $setting ) = explode( ':', $deletedSetting );
  57. if ( is_array( $placements[$block][$setting] ) )
  58. {
  59. foreach ( $placements[$block][$setting] as $settingElementKey => $key )
  60. {
  61. $placement = $ini->findSettingPlacement( $placements[$block][$setting][$settingElementKey] );
  62. break;
  63. }
  64. }
  65. else
  66. {
  67. $placement = $ini->findSettingPlacement( $placements[$block][$setting] );
  68. }
  69. // Get extension name if exists, $placement might be "extension:ezdhtml"
  70. $exploded = explode( ':', $placement );
  71. $extension = ( $exploded[0] === 'extension' || $exploded[0] === 'ext-siteaccess' )
  72. ? $exploded[1]
  73. : false;
  74. $path = 'settings/override';
  75. if ( $placement === 'siteaccess' )
  76. $path = "settings/siteaccess/$currentSiteAccess";
  77. elseif ( $exploded[0] === 'extension' && $extension !== false )
  78. $path = "extension/$extension/settings";
  79. elseif ( $exploded[0] === 'ext-siteaccess' && $extension !== false )
  80. $path = "extension/$extension/settings/siteaccess/$currentSiteAccess";
  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. $ini->setOverrideDirs( $siteIni->overrideDirs( false ) );
  100. $ini->load();
  101. }
  102. else
  103. {
  104. // load settings file more or less normally but with $addArrayDefinition = true
  105. $ini = new eZINI( $settingFile,'settings', null, false, null, false, true );
  106. }
  107. $blocks = $ini->groups();
  108. $placements = $ini->groupPlacements();
  109. $settings = array();
  110. $blockCount = 0;
  111. $totalSettingCount = 0;
  112. foreach( $blocks as $block=>$key )
  113. {
  114. $settingsCount = 0;
  115. $blockRemoveable = false;
  116. $blockEditable = true;
  117. foreach( $key as $setting=>$settingKey )
  118. {
  119. $hasSetPlacement = false;
  120. $type = $ini->settingType( $settingKey );
  121. $removeable = false;
  122. switch ( $type )
  123. {
  124. case 'array':
  125. if ( count( $settingKey ) == 0 )
  126. $settings[$block]['content'][$setting]['content'] = array();
  127. foreach( $settingKey as $settingElementKey=>$settingElementValue )
  128. {
  129. $settingPlacement = $ini->findSettingPlacement( $placements[$block][$setting][$settingElementKey] );
  130. if ( $settingElementValue != null )
  131. {
  132. // Make a space after the ';' to make it possible for
  133. // the browser to break long lines
  134. $settings[$block]['content'][$setting]['content'][$settingElementKey]['content'] = str_replace( ';', "; ", $settingElementValue );
  135. }
  136. else
  137. {
  138. $settings[$block]['content'][$setting]['content'][$settingElementKey]['content'] = "";
  139. }
  140. $settings[$block]['content'][$setting]['content'][$settingElementKey]['placement'] = $settingPlacement;
  141. $hasSetPlacement = true;
  142. if ( $settingPlacement != 'default' )
  143. {
  144. $removeable = true;
  145. $blockRemoveable = true;
  146. }
  147. }
  148. break;
  149. case 'string':
  150. if( strpos( $settingKey, ';' ) )
  151. {
  152. // Make a space after the ';' to make it possible for
  153. // the browser to break long lines
  154. $settingArray = str_replace( ';', "; ", $settingKey );
  155. $settings[$block]['content'][$setting]['content'] = $settingArray;
  156. }
  157. else
  158. {
  159. $settings[$block]['content'][$setting]['content'] = $settingKey;
  160. }
  161. break;
  162. default:
  163. $settings[$block]['content'][$setting]['content'] = $settingKey;
  164. }
  165. $settings[$block]['content'][$setting]['type'] = $type;
  166. $settings[$block]['content'][$setting]['placement'] = "";
  167. if ( !$hasSetPlacement )
  168. {
  169. $placement = $ini->findSettingPlacement( $placements[$block][$setting] );
  170. $settings[$block]['content'][$setting]['placement'] = $placement;
  171. if ( $placement != 'default' )
  172. {
  173. $removeable = true;
  174. $blockRemoveable = true;
  175. }
  176. }
  177. $editable = $ini->isSettingReadOnly( $settingFile, $block, $setting );
  178. $removeable = $editable === false ? false : $removeable;
  179. $settings[$block]['content'][$setting]['editable'] = $editable;
  180. $settings[$block]['content'][$setting]['removeable'] = $removeable;
  181. ++$settingsCount;
  182. }
  183. $blockEditable = $ini->isSettingReadOnly( $settingFile, $block );
  184. $settings[$block]['count'] = $settingsCount;
  185. $settings[$block]['removeable'] = $blockRemoveable;
  186. $settings[$block]['editable'] = $blockEditable;
  187. $totalSettingCount += $settingsCount;
  188. ++$blockCount;
  189. }
  190. ksort( $settings );
  191. $tpl->setVariable( 'settings', $settings );
  192. $tpl->setVariable( 'block_count', $blockCount );
  193. $tpl->setVariable( 'setting_count', $totalSettingCount );
  194. $tpl->setVariable( 'ini_file', $settingFile );
  195. }
  196. else
  197. {
  198. $tpl->setVariable( 'settings', false );
  199. $tpl->setVariable( 'block_count', false );
  200. $tpl->setVariable( 'setting_count', false );
  201. $tpl->setVariable( 'ini_file', false );
  202. }
  203. $rootDir = 'settings';
  204. $iniFiles = eZDir::recursiveFindRelative( $rootDir, '', '.ini' );
  205. // find all .ini files in active extensions
  206. foreach ( eZINI::globalOverrideDirs() as $iniDataSet )
  207. {
  208. $iniPath = $iniDataSet[1] ? $iniDataSet[0] : 'settings/' . $iniDataSet[0];
  209. $iniFiles = array_merge( $iniFiles, eZDir::recursiveFindRelative( $iniPath, '', '.ini' ) );
  210. $iniFiles = array_merge( $iniFiles, eZDir::recursiveFindRelative( $iniPath, '', '.ini.append.php' ) );
  211. }
  212. // extract all .ini files without path
  213. $iniFiles = preg_replace('%.*/%', '', $iniFiles );
  214. // remove *.ini[.append.php] from file name
  215. $iniFiles = preg_replace('%\.ini.*%', '.ini', $iniFiles );
  216. sort( $iniFiles );
  217. $tpl->setVariable( 'ini_files', array_unique( $iniFiles ) );
  218. $tpl->setVariable( 'siteaccess_list', $siteAccessList );
  219. $tpl->setVariable( 'current_siteaccess', $currentSiteAccess );
  220. $Result = array();
  221. $Result['content'] = $tpl->fetch( 'design:settings/view.tpl' );
  222. $Result['path'] = array( array( 'text' => ezpI18n::tr( 'settings/view', 'Settings' ),
  223. 'url' => false ),
  224. array( 'text' => ezpI18n::tr( 'settings/view', 'View' ),
  225. 'url' => false ) );
  226. ?>