[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Created on: <17-Jan-2004 12:36:36 oh> 4 // 5 // SOFTWARE NAME: eZ publish 6 // SOFTWARE RELEASE: 3.9.0 7 // BUILD VERSION: 17785 8 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 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 include_once ( "kernel/common/template.php" ); 27 include_once ( "lib/ezutils/classes/ezhttptool.php" ); 28 include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" ); 29 30 $settingTypeArray = array( 'array' => 'Array', 31 'true/false' => 'True/False', 32 'enable/disable' => 'Enabled/Disabled', 33 'string' => 'String', 34 'numeric' => 'Numeric' ); 35 36 $tpl =& templateInit(); 37 $http =& eZHTTPTool::instance(); 38 //$ini =& eZINI::instance(); 39 40 if ( $Params['INIFile'] ) 41 $iniFile = $Params['INIFile']; 42 43 if ( $Params['SiteAccess'] ) 44 $siteAccess = $Params['SiteAccess']; 45 46 if ( $Params['Block'] ) 47 $block = $Params['Block']; 48 49 if ( $Params['Setting'] ) 50 $settingName = $Params['Setting']; 51 52 if ( $Params['Placement'] ) 53 $settingPlacement = $Params['Placement']; 54 55 if ( $http->hasPostVariable( 'INIFile' ) ) 56 $iniFile = $http->variable( "INIFile" ); 57 58 if ( $http->hasPostVariable( 'SiteAccess' ) ) 59 $siteAccess = $http->postVariable( 'SiteAccess' ); 60 61 if ( $http->hasPostVariable( 'Block' ) ) 62 $block = trim( $http->postVariable( 'Block' ) ); 63 64 if ( $http->hasPostVariable( 'SettingType' ) ) 65 $settingType = trim( $http->postVariable( 'SettingType' ) ); 66 67 if ( $http->hasPostVariable( 'SettingName' ) ) 68 $settingName = trim( $http->postVariable( 'SettingName' ) ); 69 70 if ( $http->hasPostVariable( 'SettingPlacement' ) ) 71 $settingPlacement = trim( $http->postVariable( 'SettingPlacement' ) ); 72 73 if ( $http->hasPostVariable( 'Value' ) ) 74 $valueToWrite = trim( $http->postVariable( 'Value' ) ); 75 76 if ( !isset( $settingName ) ) 77 $settingName = ''; 78 79 if ( !isset( $settingPlacement ) ) 80 $settingPlacement = 'siteaccess'; 81 82 if ( $http->hasPostVariable( 'WriteSetting' ) ) 83 { 84 $path = 'settings/override'; 85 if ( $settingPlacement == 'siteaccess' ) 86 $path = "settings/siteaccess/$siteAccess"; 87 elseif ( $settingPlacement != 'override' ) 88 $path = "extension/$settingPlacement/settings"; 89 90 $ini =& eZINI::instance( $iniFile . '.append', $path, null, null, null, true, true ); 91 92 $hasValidationError = false; 93 include_once ( 'kernel/settings/validation.php' ); 94 $validationResult = validate( array( 'Name' => $settingName, 95 'Value' => $valueToWrite ), 96 array( 'name', $settingType ), true ); 97 if ( $validationResult['hasValidationError'] ) 98 { 99 $tpl->setVariable( 'validation_field', $validationResult['fieldContainingError'] ); 100 $hasValidationError = true; 101 } 102 103 if ( !$hasValidationError ) 104 { 105 if ( $settingType == 'array' ) 106 { 107 $valueArray = explode( "\n", $valueToWrite ); 108 $valuesToWriteArray = array(); 109 110 $settingCount = 0; 111 foreach( $valueArray as $value ) 112 { 113 if ( preg_match( "/^\[(.+)\]\=(.+)$/", $value, $matches ) ) 114 { 115 $valuesToWriteArray[$matches[1]] = trim( $matches[2], "\r\n" ); 116 } 117 else 118 { 119 $value = substr( strchr( $value, '=' ), 1 ); 120 if ( $value == "" ) 121 { 122 if ( $settingCount == 0 ) 123 $valuesToWriteArray[] = NULL; 124 } 125 else 126 { 127 $valuesToWriteArray[] = trim( $value, "\r\n" ); 128 } 129 } 130 ++$settingCount; 131 } 132 133 $ini->setVariable( $block, $settingName, $valuesToWriteArray ); 134 } 135 else 136 { 137 $ini->setVariable( $block, $settingName, $valueToWrite ); 138 } 139 $writeOk = $ini->save(); // false, false, false, false, true, true ); 140 141 if ( !$writeOk ) 142 { 143 $tpl->setVariable( 'validation_error', true ); 144 $tpl->setVariable( 'validation_error_type', 'write_error' ); 145 $tpl->setVariable( 'path', $path ); 146 $tpl->setVariable( 'filename', $iniFile . '.append.php' ); 147 } 148 else 149 { 150 return $Module->redirectTo( '/settings/view/' . $siteAccess . '/' . $iniFile ); 151 } 152 } 153 else // found validation errors... 154 { 155 $tpl->setVariable( 'validation_error', true ); 156 $tpl->setVariable( 'validation_error_type', $validationResult['type'] ); 157 $tpl->setVariable( 'validation_error_message', $validationResult['message'] ); 158 } 159 } 160 else 161 { 162 $tpl->setVariable( 'validation_error', false ); 163 $tpl->setVariable( 'validation_error_type', false ); 164 $tpl->setVariable( 'validation_error_message', false ); 165 } 166 167 if ( $http->hasPostVariable( 'Cancel' ) ) 168 { 169 return $Module->redirectTo( '/settings/view/' . $siteAccess . '/' . $iniFile ); 170 } 171 172 function parseArrayToStr( $value, $separator ) 173 { 174 if ( !is_array( $value ) ) 175 return $value; 176 177 $valueArray = array(); 178 $valueArray[] = "="; 179 180 foreach( $value as $param=>$key ) 181 { 182 if ( !is_numeric( $param ) ) 183 { 184 $valueArray[] = "[$param]=$key"; 185 } 186 else 187 { 188 $valueArray[] = "=$key"; 189 } 190 } 191 $value = implode( $separator, $valueArray ); 192 return $value; 193 } 194 195 function getVariable( $block, $settingName, $iniFile, $path ) 196 { 197 $ini =& eZINI::instance( $iniFile, $path, null, null, null, true ); 198 $result = $ini->hasVariable( $block, $settingName ) ? $ini->variable( $block, $settingName ) : false; 199 $result = parseArrayToStr( $result, '<br>' ); 200 return $result; 201 } 202 203 $ini =& eZINI::instance( $iniFile, 'settings', null, null, false ); 204 205 if ( isset( $settingPlacement ) and $settingPlacement == 'siteaccess' ) 206 { 207 $ini->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' ); 208 $ini->loadCache(); 209 } 210 211 $value = $settingName != '' ? $ini->variable( $block, $settingName ) : ''; 212 213 // Do modifications to the value before it's sent to the template 214 if ( ( is_array( $value ) || $value ) and !isset( $settingType ) ) 215 { 216 $settingType = $ini->settingType( $value ); 217 if ( $settingType == 'array' ) 218 { 219 $value = parseArrayToStr( $value, "\n" ); 220 } 221 222 } 223 // Init value from ini (default\override\extensions\siteaccess) 224 $values = array(); 225 $values['default'] = getVariable( $block, $settingName, $iniFile, 'settings/' ); 226 $values['siteaccess'] = getVariable( $block, $settingName, $iniFile, "settings/siteaccess/$siteAccess" ); 227 $values['override'] = getVariable( $block, $settingName, $iniFile, "settings/override/" ); 228 // Get values from extensions 229 $ini =& eZINI::instance(); 230 $extensions = $ini->hasVariable( 'ExtensionSettings','ActiveExtensions' ) ? $ini->variable( 'ExtensionSettings','ActiveExtensions' ) : array(); 231 $extensionDir = $ini->hasVariable( 'ExtensionSettings','ExtensionDirectory' ) ? $ini->variable( 'ExtensionSettings','ExtensionDirectory' ) : 'extension'; 232 foreach ( $extensions as $extension ) 233 { 234 $extValue = getVariable( $block, $settingName, $iniFile, "$extensionDir/$extension/settings" ); 235 $values['extensions'][$extension] = $extValue; 236 } 237 238 if ( !isset( $settingType ) ) 239 $settingType = 'string'; 240 241 $tpl->setVariable( 'setting_name', $settingName ); 242 $tpl->setVariable( 'current_siteaccess', $siteAccess ); 243 $tpl->setVariable( 'setting_type_array', $settingTypeArray ); 244 $tpl->setVariable( 'setting_type', $settingType ); 245 $tpl->setVariable( 'ini_file', $iniFile ); 246 $tpl->setVariable( 'block', $block ); 247 $tpl->setVariable( 'value', $value ); 248 $tpl->setVariable( 'values', $values ); 249 $tpl->setVariable( 'placement', $settingPlacement ); 250 251 $Result = array(); 252 $Result['content'] =& $tpl->fetch( 'design:settings/edit.tpl' ); 253 $Result['path'] = array( array( 'text' => ezi18n( 'settings/edit', 'Settings' ), 254 'url' => false ), 255 array( 'text' => ezi18n( 'settings/edit', 'Edit' ), 256 'url' => false ) ); 257 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |