[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Created on: <09-May-2003 10:44:02 bf> 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 27 include_once ( "kernel/common/template.php" ); 28 include_once ( "kernel/common/eztemplatedesignresource.php" ); 29 include_once ( 'lib/ezutils/classes/ezhttptool.php' ); 30 include_once ( 'lib/ezi18n/classes/eztextcodec.php' ); 31 32 $http =& eZHTTPTool::instance(); 33 $module =& $Params["Module"]; 34 $parameters =& $Params["Parameters"]; 35 36 if ( $http->hasPostVariable( 'Cancel' ) ) 37 { 38 return $Module->redirectTo( $http->postVariable( 'RedirectToURI' ) ); 39 } 40 41 $ini =& eZINI::instance(); 42 $tpl =& templateInit(); 43 44 $Result = array(); 45 $Result['path'] = array( array( 'url' => false, 46 'text' => ezi18n( 'kernel/design', 'Template edit' ) ) ); 47 48 $template = ""; 49 $i = 0; 50 foreach ( $parameters as $param ) 51 { 52 if ( $i > 0 ) 53 $template .= "/"; 54 $template .= "$param"; 55 $i++; 56 } 57 58 $siteAccess = $Params['SiteAccess']; 59 if( $siteAccess ) 60 $http->setSessionVariable( 'eZTemplateAdminCurrentSiteAccess', $siteAccess ); 61 else 62 $siteAccess = $http->sessionVariable( 'eZTemplateAdminCurrentSiteAccess' ); 63 64 $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess ); 65 66 // Check if template already exists 67 $isExistingTemplate = false; 68 foreach ( $overrideArray as $overrideSetting ) 69 { 70 if ( $overrideSetting['base_dir'] . $overrideSetting['template'] == $template ) 71 { 72 $isExistingTemplate = true; 73 } 74 } 75 76 if ( $isExistingTemplate == false ) 77 { 78 $tpl->setVariable( 'template', $template ); 79 $tpl->setVariable( 'template_exists', false ); 80 $tpl->setVariable( 'original_template', false ); 81 $tpl->setVariable( 'site_access', $siteAccess ); 82 83 $Result['content'] =& $tpl->fetch( "design:visual/templateedit_error.tpl" ); 84 return; 85 } 86 87 // Find the main template for this override 88 $originalTemplate = false; 89 foreach ( $overrideArray as $overrideSetting ) 90 { 91 if ( isset( $overrideSetting['custom_match'] ) ) 92 { 93 foreach ( $overrideSetting['custom_match'] as $customMatch ) 94 { 95 if ( $customMatch['match_file'] == $template ) 96 { 97 $originalTemplate = $overrideSetting['template']; 98 break; 99 } 100 } 101 if ( $originalTemplate ) 102 break; 103 } 104 } 105 106 /* Check if we need to do characterset conversions for editting and saving 107 * templates. */ 108 $templateConfig =& eZINI::instance( 'template.ini' ); 109 $i18nConfig =& eZINI::instance( 'i18n.ini' ); 110 111 /* First we check the HTML Output Charset */ 112 $outputCharset = eZTextCodec::internalCharset(); 113 114 if ( $module->isCurrentAction( 'Save' ) ) 115 { 116 if ( $http->hasPostVariable( 'TemplateContent' ) ) 117 { 118 $templateContent = $http->postVariable( 'TemplateContent' ); 119 120 if ( $templateConfig->variable( 'CharsetSettings', 'AutoConvertOnSave') == 'enabled' ) 121 { 122 include_once ( 'lib/ezi18n/classes/ezcharsetinfo.php' ); 123 $outputCharset = eZCharsetInfo::realCharsetCode( $outputCharset ); 124 if ( preg_match( '|{\*\?template.*charset=([a-zA-Z0-9-]*).*\?\*}|', $templateContent, $matches ) ) 125 { 126 $templateContent = preg_replace( '|({\*\?template.*charset=)[a-zA-Z0-9-]*(.*\?\*})|', 127 '\\1'. $outputCharset. '\\2', 128 $templateContent ); 129 } 130 else 131 { 132 $templateCharset = eZCharsetInfo::realCharsetCode( $templateConfig->variable( 'CharsetSettings', 'DefaultTemplateCharset') ); 133 if ( $templateCharset != $outputCharset ) 134 $templateContent = "{*?template charset=$outputCharset?*}\n" . $templateContent; 135 } 136 } 137 else 138 { 139 /* Here we figure out the characterset of the template. If there is a charset 140 * associated with the template in the header we use that one, if not we fall 141 * back to the INI setting "DefaultTemplateCharset". */ 142 if ( preg_match( '|{\*\?template.*charset=([a-zA-Z0-9-]*).*\?\*}|', $templateContent, $matches ) ) 143 { 144 $templateCharset = $matches[1]; 145 } 146 else 147 { 148 $templateCharset = $templateConfig->variable( 'CharsetSettings', 'DefaultTemplateCharset'); 149 } 150 151 /* If we're saving a template after editting we need to convert it to the template's 152 * Charset. */ 153 $codec =& eZTextCodec::instance( $outputCharset, $templateCharset, false ); 154 if ( $codec ) 155 { 156 $templateContent = $codec->convertString( $templateContent ); 157 } 158 } 159 160 $fp = fopen( $template, 'w' ); 161 if ( $fp ) 162 { 163 fwrite( $fp, $templateContent ); 164 } 165 fclose( $fp ); 166 167 $siteConfig =& eZINI::instance( 'site.ini' ); 168 $filePermissions = $siteConfig->variable( 'FileSettings', 'StorageFilePermissions'); 169 @chmod( $template, octdec( $filePermissions ) ); 170 171 // Expire content view cache 172 include_once ( 'kernel/classes/ezcontentcachemanager.php' ); 173 eZContentCacheManager::clearAllContentCache(); 174 175 $module->redirectTo( '/visual/templateview'. $originalTemplate ); 176 return EZ_MODULE_HOOK_STATUS_CANCEL_RUN; 177 } 178 } 179 180 181 if ( $module->isCurrentAction( 'Discard' ) ) 182 { 183 $module->redirectTo( '/visual/templateview'. $originalTemplate ); 184 return EZ_MODULE_HOOK_STATUS_CANCEL_RUN; 185 } 186 187 // get the content of the template 188 $fileName = $template; 189 190 if ( !is_readable( $fileName ) ) 191 { 192 $tpl->setVariable( 'template', $template ); 193 $tpl->setVariable( 'template_exists', true ); 194 $tpl->setVariable( 'original_template', $originalTemplate ); 195 $tpl->setVariable( 'is_readable', false ); 196 $tpl->setVariable( 'site_access', $siteAccess ); 197 198 $Result['content'] =& $tpl->fetch( "design:visual/templateedit_error.tpl" ); 199 return; 200 } 201 202 if ( !is_writable( $fileName ) ) 203 { 204 if ( $http->hasPostVariable( 'OpenReadOnly' ) ) 205 { 206 $tpl->setVariable( 'is_writable', false ); 207 } 208 else 209 { 210 $tpl->setVariable( 'template', $template ); 211 $tpl->setVariable( 'template_exists', true ); 212 $tpl->setVariable( 'original_template', $originalTemplate ); 213 $tpl->setVariable( 'is_readable', true ); 214 $tpl->setVariable( 'site_access', $siteAccess ); 215 216 $Result['content'] =& $tpl->fetch( "design:visual/templateedit_error.tpl" ); 217 return; 218 } 219 } 220 else 221 { 222 $tpl->setVariable( 'is_writable', true ); 223 } 224 225 $templateContent = file_get_contents( $fileName ); 226 227 /* Here we figure out the characterset of the template. If there is a charset 228 * associated with the template in the header we use that one, if not we fall 229 * back to the INI setting "DefaultTemplateCharset". */ 230 if ( preg_match('|{\*\?template.*charset=([a-zA-Z0-9-]*).*\?\*}|', $templateContent, $matches ) ) 231 { 232 $templateCharset = $matches[1]; 233 } 234 else 235 { 236 $templateCharset = $templateConfig->variable( 'CharsetSettings', 'DefaultTemplateCharset'); 237 } 238 239 /* If we're loading a template for editting we need to convert it to the HTTP 240 * Charset. */ 241 $codec =& eZTextCodec::instance( $templateCharset, $outputCharset, false ); 242 if ( $codec ) 243 { 244 $templateContent = $codec->convertString( $templateContent ); 245 } 246 247 $tpl->setVariable( 'template', $template ); 248 $tpl->setVariable( 'template_content', $templateContent ); 249 250 $Result['content'] =& $tpl->fetch( "design:visual/templateedit.tpl" ); 251 252 ?>
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 |