- Fixed #16160: Call to undefined function ezi18n()
[tinyz:tinyz.git] / kernel / settings / view.php
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
29 require_once( "kernel/common/template.php" );
30
31 $tpl = templateInit();
32 $http = eZHTTPTool::instance();
33 $ini = eZINI::instance();
34 $siteAccessList = $ini->variable( 'SiteAccessSettings', 'RelatedSiteAccessList' );
35
36 if ( $Params['INIFile'] )
37     $settingFile = $Params['INIFile'];
38
39 if ( $http->hasPostVariable( 'selectedINIFile' )  )
40     $settingFile = $http->variable( "selectedINIFile" );
41
42 if ( $Params['SiteAccess'] )
43     $currentSiteAccess = $Params['SiteAccess'];
44
45 if ( $http->hasPostVariable( 'CurrentSiteAccess' ) )
46     $currentSiteAccess = $http->postVariable( 'CurrentSiteAccess' );
47
48 if ( !isset( $currentSiteAccess ) or
49      !in_array( $currentSiteAccess, $siteAccessList ) )
50     $currentSiteAccess = $siteAccessList[0];
51
52 unset( $ini );
53
54 if ( $http->hasPostVariable( 'RemoveButton' ) )
55 {
56     if ( isset( $settingFile ) )
57     {
58         $ini = eZINI::create( $settingFile, 'settings', null, null, false );
59         $ini->prependOverrideDir( "siteaccess/$currentSiteAccess", false, 'siteaccess' );
60         $ini->loadCache();
61     }
62
63     $placements = $ini->groupPlacements();
64     if ( $http->hasPostVariable( 'RemoveSettingsArray' ) )
65     {
66         $deletedSettingArray = $http->postVariable( 'RemoveSettingsArray' );
67         foreach ( $deletedSettingArray as $deletedSetting )
68         {
69             list( $block, $setting ) = explode( ':', $deletedSetting );
70
71             if ( is_array( $placements[$block][$setting] ) )
72             {
73                 foreach ( $placements[$block][$setting] as $settingElementKey=>$key )
74                 {
75                     $placement = $ini->findSettingPlacement( $placements[$block][$setting][$settingElementKey] );
76                     break;
77                 }
78             }
79             else
80             {
81                 $placement = $ini->findSettingPlacement( $placements[$block][$setting] );
82             }
83             // Get extension name if exists, $placement might be "extension:ezdhtml"
84             $exploded = explode( ':', $placement );
85             $extension = $exploded[0] == 'extension'
86                         ? $exploded[1]
87                         : false;
88
89             $path = 'settings/override';
90             if ( $placement == 'siteaccess' )
91                 $path = "settings/siteaccess/$currentSiteAccess";
92             elseif ( $placement != 'override' and $extension !== false )
93                 $path = "extension/$extension/settings";
94
95             // We should use "reference" if multiply removing of ini setting.
96             // if eZINI::instance() is called twice instance will be fetched from GLOBAL variable.
97             // Without reference there will be a inconsistency with GLOBAL instance and stored ini file.
98             $iniTemp = eZINI::create( $settingFile . '.append.php', $path, null, null, null, true );
99             $iniTemp->removeSetting( $block, $setting );
100             $iniTemp->save();
101         }
102     }
103 }
104
105 if ( $http->hasPostVariable( 'ChangeINIFile' ) or
106      ( $Params['SiteAccess'] and $Params['INIFile'] ) )
107 {
108     /*
109         To get the right INIOverrideDirList we have do do something
110
111         1. We delete all entry how are related to the admin siteaccess which want to diplay an ini setting from another siteaccess
112         2. We load the new site.ini to get all extensionNames for the choosen siteaccess
113         3. We add all this extensions to the overrideDirList
114         4. create ini for displaying
115     */
116     // $currentSiteAccess = choosen sitaccess to display selected ini
117     if ( $GLOBALS['eZCurrentAccess']['name'] != $currentSiteAccess )
118     {
119         // 1. delete all entry which are related to the old siteaccess
120         $newINIOverrideDirList = array();
121         foreach ( array_reverse( $GLOBALS['eZINIOverrideDirList'] ) as $dir )
122         {
123             $path = $dir[0];
124             if ( strpos( $path, 'siteaccess' ) !== false )
125             {
126                 break;
127             }
128             else
129             {
130                 $newINIOverrideDirList[] = $dir;
131             }
132         }
133         $iniOverrideDirListWithoutSiteaccess = array_reverse( $newINIOverrideDirList );
134
135         $GLOBALS['eZINIOverrideDirList'] = $iniOverrideDirListWithoutSiteaccess;
136
137         // normal siteaccess
138         if( file_exists( "settings/siteaccess/$currentSiteAccess" ) )
139         {
140             $GLOBALS['eZINIOverrideDirList'] = array_merge( array( array( "siteaccess/$currentSiteAccess", false, 'siteaccess' ) ) , $GLOBALS['eZINIOverrideDirList'] );
141         }
142         // extension sitaccess
143         else
144         {
145             eZExtension::prependExtensionSiteAccesses( $currentSiteAccess, false, true, 'siteaccess' );
146         }
147
148         // 2. create site.ini for the new siteaccess
149         $newSiteIni = eZINI::create( 'site.ini', 'settings', null, null, false );
150
151         // 3. load all extension which are activated in the sitaccess
152         $newActiveAccessExtensions = $newSiteIni->variable( 'ExtensionSettings', 'ActiveAccessExtensions' );
153         $activeExtensionOverrideDirList = array();
154         foreach ( array_reverse( $newActiveAccessExtensions ) as $extensionName )
155         {
156             $activeExtensionOverrideDirList[] = array( "extension/$extensionName/settings" , true, false );
157         }
158         $siteAccessOverrideDirListSetting = array_shift( $GLOBALS['eZINIOverrideDirList'] );
159
160         array_push( $activeExtensionOverrideDirList, $siteAccessOverrideDirListSetting );
161         $GLOBALS['eZINIOverrideDirList'] = array_merge( $activeExtensionOverrideDirList, $GLOBALS['eZINIOverrideDirList'] );
162
163         // now we have the right order for the overideDirList :-)
164     }
165
166     // 4. create ini for displaying
167     // create ini data with empty array definition so that count( placement array ) = count( ini files )
168     $ini = new eZINI( $settingFile,'settings', null, false, null, false, true );
169
170     $blocks = $ini->groups();
171     $placements = $ini->groupPlacements();
172     $settings = array();
173     $blockCount = 0;
174     $totalSettingCount = 0;
175
176     foreach( $blocks as $block=>$key )
177     {
178         $settingsCount = 0;
179         $blockRemoveable = false;
180         $blockEditable = true;
181         foreach( $key as $setting=>$settingKey )
182         {
183             $hasSetPlacement = false;
184             $type = $ini->settingType( $settingKey );
185             $removeable = false;
186
187             switch ( $type )
188             {
189                 case 'array':
190                     if ( count( $settingKey ) == 0 )
191                         $settings[$block]['content'][$setting]['content'] = array();
192
193                     foreach( $settingKey as $settingElementKey=>$settingElementValue )
194                     {
195                         $settingPlacement = $ini->findSettingPlacement( $placements[$block][$setting][$settingElementKey] );
196                         if ( $settingElementValue != null )
197                         {
198                             // Make a space after the ';' to make it possible for
199                             // the browser to break long lines
200                             $settings[$block]['content'][$setting]['content'][$settingElementKey]['content'] = str_replace( ';', "; ", $settingElementValue );
201                         }
202                         else
203                         {
204                             $settings[$block]['content'][$setting]['content'][$settingElementKey]['content'] = "";
205                         }
206                         $settings[$block]['content'][$setting]['content'][$settingElementKey]['placement'] = $settingPlacement;
207                         $hasSetPlacement = true;
208                         if ( $settingPlacement != 'default' )
209                         {
210                             $removeable = true;
211                             $blockRemoveable = true;
212                         }
213                     }
214                     break;
215                 case 'string':
216                     if( strpos( $settingKey, ';' ) )
217                     {
218                         // Make a space after the ';' to make it possible for
219                         // the browser to break long lines
220                         $settingArray = str_replace( ';', "; ", $settingKey );
221                         $settings[$block]['content'][$setting]['content'] = $settingArray;
222                     }
223                     else
224                     {
225                         $settings[$block]['content'][$setting]['content'] = $settingKey;
226                     }
227                     break;
228                 default:
229                     $settings[$block]['content'][$setting]['content'] = $settingKey;
230             }
231             $settings[$block]['content'][$setting]['type'] = $type;
232             $settings[$block]['content'][$setting]['placement'] = "";
233
234             if ( !$hasSetPlacement )
235             {
236                 $placement = $ini->findSettingPlacement( $placements[$block][$setting] );
237                 $settings[$block]['content'][$setting]['placement'] = $placement;
238                 if ( $placement != 'default' )
239                 {
240                     $removeable = true;
241                     $blockRemoveable = true;
242                 }
243             }
244             $editable = $ini->isSettingReadOnly( $settingFile, $block, $setting );
245             $removeable = $editable === false ? false : $removeable;
246             $settings[$block]['content'][$setting]['editable'] = $editable;
247             $settings[$block]['content'][$setting]['removeable'] = $removeable;
248             ++$settingsCount;
249         }
250         $blockEditable = $ini->isSettingReadOnly( $settingFile, $block );
251         $settings[$block]['count'] = $settingsCount;
252         $settings[$block]['removeable'] = $blockRemoveable;
253         $settings[$block]['editable'] = $blockEditable;
254         $totalSettingCount += $settingsCount;
255         ++$blockCount;
256     }
257     ksort( $settings );
258     $tpl->setVariable( 'settings', $settings );
259     $tpl->setVariable( 'block_count', $blockCount );
260     $tpl->setVariable( 'setting_count', $totalSettingCount );
261     $tpl->setVariable( 'ini_file', $settingFile );
262 }
263 else
264 {
265     $tpl->setVariable( 'settings', false );
266     $tpl->setVariable( 'block_count', false );
267     $tpl->setVariable( 'setting_count', false );
268     $tpl->setVariable( 'ini_file', false );
269 }
270
271 $rootDir = 'settings';
272 $iniFiles = eZDir::recursiveFindRelative( $rootDir, '', '.ini' );
273
274 // find all .ini files in active extensions
275 foreach ( $GLOBALS['eZINIOverrideDirList'] as $iniDataSet )
276 {
277     $rootDir = $iniDataSet[0];
278     $iniFiles = array_merge( $iniFiles, eZDir::recursiveFindRelative( $rootDir, '', '.ini' ) );
279 }
280
281 // extract all .ini files without path
282 $iniFiles = preg_replace('%.*/%', '', $iniFiles );
283 sort( $iniFiles );
284
285 $tpl->setVariable( 'ini_files', $iniFiles );
286 $tpl->setVariable( 'siteaccess_list', $siteAccessList );
287 $tpl->setVariable( 'current_siteaccess', $currentSiteAccess );
288
289 $Result = array();
290 $Result['content'] = $tpl->fetch( 'design:settings/view.tpl' );
291 $Result['path'] = array( array( 'text' => ezpI18n::translate( 'settings/view', 'Settings' ),
292                                 'url' => false ),
293                          array( 'text' => ezpI18n::translate( 'settings/view', 'View' ),
294                                 'url' => false ) );
295
296 ?>