PageRenderTime 62ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/kernel/settings/view.php

https://github.com/stevoland/ezpublish
PHP | 296 lines | 210 code | 33 blank | 53 comment | 29 complexity | 97cd4a27ce121deb4295deb9fb1a8b38 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  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. /*
  94. To get the right INIOverrideDirList we have do do something
  95. 1. We delete all entry how are related to the admin siteaccess which want to diplay an ini setting from another siteaccess
  96. 2. We load the new site.ini to get all extensionNames for the choosen siteaccess
  97. 3. We add all this extensions to the overrideDirList
  98. 4. create ini for displaying
  99. */
  100. // $currentSiteAccess = choosen sitaccess to display selected ini
  101. if ( $GLOBALS['eZCurrentAccess']['name'] != $currentSiteAccess )
  102. {
  103. // 1. delete all entry which are related to the old siteaccess
  104. $newINIOverrideDirList = array();
  105. foreach ( array_reverse( $GLOBALS['eZINIOverrideDirList'] ) as $dir )
  106. {
  107. $path = $dir[0];
  108. if ( strpos( $path, 'siteaccess' ) !== false )
  109. {
  110. break;
  111. }
  112. else
  113. {
  114. $newINIOverrideDirList[] = $dir;
  115. }
  116. }
  117. $iniOverrideDirListWithoutSiteaccess = array_reverse( $newINIOverrideDirList );
  118. $GLOBALS['eZINIOverrideDirList'] = $iniOverrideDirListWithoutSiteaccess;
  119. // normal siteaccess
  120. if( file_exists( "settings/siteaccess/$currentSiteAccess" ) )
  121. {
  122. $GLOBALS['eZINIOverrideDirList'] = array_merge( array( array( "siteaccess/$currentSiteAccess", false, 'siteaccess' ) ) , $GLOBALS['eZINIOverrideDirList'] );
  123. }
  124. // extension sitaccess
  125. else
  126. {
  127. eZExtension::prependExtensionSiteAccesses( $currentSiteAccess, false, true, 'siteaccess' );
  128. }
  129. // 2. create site.ini for the new siteaccess
  130. $newSiteIni = eZINI::create( 'site.ini', 'settings', null, null, false );
  131. // 3. load all extension which are activated in the sitaccess
  132. $newActiveAccessExtensions = $newSiteIni->variable( 'ExtensionSettings', 'ActiveAccessExtensions' );
  133. $activeExtensionOverrideDirList = array();
  134. foreach ( array_reverse( $newActiveAccessExtensions ) as $extensionName )
  135. {
  136. $activeExtensionOverrideDirList[] = array( "extension/$extensionName/settings" , true, false );
  137. }
  138. $siteAccessOverrideDirListSetting = array_shift( $GLOBALS['eZINIOverrideDirList'] );
  139. array_push( $activeExtensionOverrideDirList, $siteAccessOverrideDirListSetting );
  140. $GLOBALS['eZINIOverrideDirList'] = array_merge( $activeExtensionOverrideDirList, $GLOBALS['eZINIOverrideDirList'] );
  141. // now we have the right order for the overideDirList :-)
  142. }
  143. // 4. create ini for displaying
  144. // create ini data with empty array definition so that count( placement array ) = count( ini files )
  145. $ini = new eZINI( $settingFile,'settings', null, false, null, false, true );
  146. $blocks = $ini->groups();
  147. $placements = $ini->groupPlacements();
  148. $settings = array();
  149. $blockCount = 0;
  150. $totalSettingCount = 0;
  151. foreach( $blocks as $block=>$key )
  152. {
  153. $settingsCount = 0;
  154. $blockRemoveable = false;
  155. $blockEditable = true;
  156. foreach( $key as $setting=>$settingKey )
  157. {
  158. $hasSetPlacement = false;
  159. $type = $ini->settingType( $settingKey );
  160. $removeable = false;
  161. switch ( $type )
  162. {
  163. case 'array':
  164. if ( count( $settingKey ) == 0 )
  165. $settings[$block]['content'][$setting]['content'] = array();
  166. foreach( $settingKey as $settingElementKey=>$settingElementValue )
  167. {
  168. $settingPlacement = $ini->findSettingPlacement( $placements[$block][$setting][$settingElementKey] );
  169. if ( $settingElementValue != null )
  170. {
  171. // Make a space after the ';' to make it possible for
  172. // the browser to break long lines
  173. $settings[$block]['content'][$setting]['content'][$settingElementKey]['content'] = str_replace( ';', "; ", $settingElementValue );
  174. }
  175. else
  176. {
  177. $settings[$block]['content'][$setting]['content'][$settingElementKey]['content'] = "";
  178. }
  179. $settings[$block]['content'][$setting]['content'][$settingElementKey]['placement'] = $settingPlacement;
  180. $hasSetPlacement = true;
  181. if ( $settingPlacement != 'default' )
  182. {
  183. $removeable = true;
  184. $blockRemoveable = true;
  185. }
  186. }
  187. break;
  188. case 'string':
  189. if( strpos( $settingKey, ';' ) )
  190. {
  191. // Make a space after the ';' to make it possible for
  192. // the browser to break long lines
  193. $settingArray = str_replace( ';', "; ", $settingKey );
  194. $settings[$block]['content'][$setting]['content'] = $settingArray;
  195. }
  196. else
  197. {
  198. $settings[$block]['content'][$setting]['content'] = $settingKey;
  199. }
  200. break;
  201. default:
  202. $settings[$block]['content'][$setting]['content'] = $settingKey;
  203. }
  204. $settings[$block]['content'][$setting]['type'] = $type;
  205. $settings[$block]['content'][$setting]['placement'] = "";
  206. if ( !$hasSetPlacement )
  207. {
  208. $placement = $ini->findSettingPlacement( $placements[$block][$setting] );
  209. $settings[$block]['content'][$setting]['placement'] = $placement;
  210. if ( $placement != 'default' )
  211. {
  212. $removeable = true;
  213. $blockRemoveable = true;
  214. }
  215. }
  216. $editable = $ini->isSettingReadOnly( $settingFile, $block, $setting );
  217. $removeable = $editable === false ? false : $removeable;
  218. $settings[$block]['content'][$setting]['editable'] = $editable;
  219. $settings[$block]['content'][$setting]['removeable'] = $removeable;
  220. ++$settingsCount;
  221. }
  222. $blockEditable = $ini->isSettingReadOnly( $settingFile, $block );
  223. $settings[$block]['count'] = $settingsCount;
  224. $settings[$block]['removeable'] = $blockRemoveable;
  225. $settings[$block]['editable'] = $blockEditable;
  226. $totalSettingCount += $settingsCount;
  227. ++$blockCount;
  228. }
  229. ksort( $settings );
  230. $tpl->setVariable( 'settings', $settings );
  231. $tpl->setVariable( 'block_count', $blockCount );
  232. $tpl->setVariable( 'setting_count', $totalSettingCount );
  233. $tpl->setVariable( 'ini_file', $settingFile );
  234. }
  235. else
  236. {
  237. $tpl->setVariable( 'settings', false );
  238. $tpl->setVariable( 'block_count', false );
  239. $tpl->setVariable( 'setting_count', false );
  240. $tpl->setVariable( 'ini_file', false );
  241. }
  242. $rootDir = 'settings';
  243. $iniFiles = eZDir::recursiveFindRelative( $rootDir, '', '.ini' );
  244. // find all .ini files in active extensions
  245. foreach ( $GLOBALS['eZINIOverrideDirList'] as $iniDataSet )
  246. {
  247. $rootDir = $iniDataSet[0];
  248. $iniFiles = array_merge( $iniFiles, eZDir::recursiveFindRelative( $rootDir, '', '.ini' ) );
  249. }
  250. // extract all .ini files without path
  251. $iniFiles = preg_replace('%.*/%', '', $iniFiles );
  252. sort( $iniFiles );
  253. $tpl->setVariable( 'ini_files', $iniFiles );
  254. $tpl->setVariable( 'siteaccess_list', $siteAccessList );
  255. $tpl->setVariable( 'current_siteaccess', $currentSiteAccess );
  256. $Result = array();
  257. $Result['content'] = $tpl->fetch( 'design:settings/view.tpl' );
  258. $Result['path'] = array( array( 'text' => ezpI18n::tr( 'settings/view', 'Settings' ),
  259. 'url' => false ),
  260. array( 'text' => ezpI18n::tr( 'settings/view', 'View' ),
  261. 'url' => false ) );
  262. ?>