[ 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 $http =& eZHTTPTool::instance(); 28 $module =& $Params["Module"]; 29 $parameters =& $Params["Parameters"]; 30 31 $overrideKeys = array( 'nodeID' => $Params['NodeID'], 32 'classID' => $Params['ClassID'] ); 33 34 include_once ( "kernel/common/template.php" ); 35 include_once ( "kernel/common/eztemplatedesignresource.php" ); 36 include_once ( 'lib/ezutils/classes/ezhttptool.php' ); 37 include_once ( "kernel/classes/ezcontentclass.php" ); 38 39 $ini =& eZINI::instance(); 40 $tpl =& templateInit(); 41 42 // Todo: read from siteaccess settings 43 $siteAccess = $Params['SiteAccess']; 44 if( $siteAccess ) 45 $http->setSessionVariable( 'eZTemplateAdminCurrentSiteAccess', $siteAccess ); 46 else 47 $siteAccess = $http->sessionVariable( 'eZTemplateAdminCurrentSiteAccess' ); 48 49 $siteBase = $siteAccess; 50 51 $siteINI = eZINI::instance( 'site.ini', 'settings', null, null, true ); 52 $siteINI->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' ); 53 $siteINI->loadCache(); 54 $siteDesign = $siteINI->variable( "DesignSettings", "SiteDesign" ); 55 56 $template = ""; 57 foreach ( $parameters as $param ) 58 { 59 $template .= "/$param"; 60 } 61 62 63 $templateType = 'default'; 64 if ( strpos( $template, "node/view" ) ) 65 { 66 $templateType = 'node_view'; 67 } 68 else if ( strpos( $template, "content/view" ) ) 69 { 70 $templateType = 'object_view'; 71 } 72 else if ( strpos( $template, "content/edit" ) ) 73 { 74 $templateType = 'object_view'; 75 } 76 else if ( strpos( $template, "pagelayout.tpl" ) ) 77 { 78 $templateType = 'pagelayout'; 79 } 80 81 $error = false; 82 $templateName = false; 83 84 if ( $module->isCurrentAction( 'CreateOverride' ) ) 85 { 86 $templateName = trim( $http->postVariable( 'TemplateName' ) ); 87 88 if ( preg_match( "#^[0-9a-z_]+$#", $templateName ) ) 89 { 90 $templateName = trim( $http->postVariable( 'TemplateName' ) ); 91 $fileName = "design/$siteDesign/override/templates/" . $templateName . ".tpl"; 92 $filePath = "design/$siteDesign/override/templates"; 93 94 $templateCode = ""; 95 switch ( $templateType ) 96 { 97 case "node_view": 98 { 99 $templateCode =& generateNodeViewTemplate( $http, $template, $fileName ); 100 }break; 101 102 case "object_view": 103 { 104 $templateCode =& generateObjectViewTemplate( $http, $template, $fileName ); 105 }break; 106 107 case "pagelayout": 108 { 109 $templateCode =& generatePagelayoutTemplate( $http, $template, $fileName ); 110 }break; 111 112 default: 113 { 114 $templateCode =& generateDefaultTemplate( $http, $template, $fileName ); 115 }break; 116 } 117 118 if ( !file_exists( $filePath ) ) 119 { 120 $dirPermission = $ini->variable( 'FileSettings', 'StorageDirPermissions' ); 121 122 eZDir::mkdir( $filePath, eZDir::directoryPermission(), true ); 123 } 124 125 126 $fp = fopen( $fileName, "w+" ); 127 if ( $fp ) 128 { 129 $filePermission = $ini->variable( 'FileSettings', 'StorageFilePermissions' ); 130 $oldumask = umask( 0 ); 131 fwrite( $fp, $templateCode ); 132 fclose( $fp ); 133 chmod( $fileName, octdec( $filePermission ) ); 134 umask( $oldumask ); 135 136 // Store override.ini.append file 137 $overrideINI = eZINI::instance( 'override.ini', 'settings', null, null, true ); 138 $overrideINI->prependOverrideDir( "siteaccess/$siteAccess", false, 'siteaccess' ); 139 $overrideINI->loadCache(); 140 141 $templateFile = preg_replace( "#^/(.*)$#", "\\1", $template ); 142 143 $overrideINI->setVariable( $templateName, 'Source', $templateFile ); 144 $overrideINI->setVariable( $templateName, 'MatchFile', $templateName . ".tpl" ); 145 $overrideINI->setVariable( $templateName, 'Subdir', "templates" ); 146 147 if ( $http->hasPostVariable( 'Match' ) ) 148 { 149 $matchArray = $http->postVariable( 'Match' ); 150 151 foreach ( array_keys( $matchArray ) as $matchKey ) 152 { 153 if ( $matchArray[$matchKey] == -1 or trim( $matchArray[$matchKey] ) == "" ) 154 unset( $matchArray[$matchKey] ); 155 } 156 $overrideINI->setVariable( $templateName, 'Match', $matchArray ); 157 } 158 159 $oldumask = umask( 0 ); 160 $overrideINI->save( "siteaccess/$siteAccess/override.ini.append" ); 161 chmod( "settings/siteaccess/$siteAccess/override.ini.append.php", octdec( $filePermission ) ); 162 umask( $oldumask ); 163 164 // Expire content view cache 165 include_once ( 'kernel/classes/ezcontentcachemanager.php' ); 166 eZContentCacheManager::clearAllContentCache(); 167 168 // Clear override cache 169 $cachedDir = eZSys::cacheDirectory(); 170 $cachedDir .= "/override/"; 171 eZDir::recursiveDelete( $cachedDir ); 172 } 173 else 174 { 175 $error = "permission_denied"; 176 eZDebug::writeError( "Could not create override template, check permissions on $fileName", "Template override" ); 177 } 178 } 179 else 180 { 181 $error = "invalid_name"; 182 } 183 184 if ( $error == false ) 185 { 186 $module->redirectTo( '/visual/templateview'. $template ); 187 return EZ_MODULE_HOOK_STATUS_CANCEL_RUN; 188 } 189 } 190 else if( $module->isCurrentAction( 'CancelOverride' ) ) 191 { 192 $module->redirectTo( '/visual/templateview'. $template ); 193 } 194 195 196 function &generateNodeViewTemplate( &$http, $template, $fileName ) 197 { 198 $matchArray = $http->postVariable( 'Match' ); 199 200 $templateCode = ""; 201 $classIdentifier = $matchArray['class_identifier']; 202 203 $class = eZContentClass::fetchByIdentifier( $classIdentifier ); 204 205 // Check what kind of contents we should create in the template 206 switch ( $http->postVariable( 'TemplateContent' ) ) 207 { 208 case 'DefaultCopy' : 209 { 210 $siteAccess = $http->sessionVariable( 'eZTemplateAdminCurrentSiteAccess' ); 211 $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess ); 212 $fileName = $overrideArray[$template]['base_dir'] . $overrideArray[$template]['template']; 213 $fp = fopen( $fileName, 'rb' ); 214 if ( $fp ) 215 { 216 $codeFromFile = fread( $fp, filesize( $fileName ) ); 217 218 // Remove the "{* DO NOT EDIT... *}" first line (if exists). 219 $templateCode = preg_replace('@^{\*\s*DO\sNOT\sEDIT.*?\*}\n(.*)@s', '$1', $codeFromFile); 220 } 221 else 222 { 223 eZDebug::writeError( "Could not open file $fileName, check read permissions" ); 224 } 225 fclose( $fp ); 226 }break; 227 228 case 'ContainerTemplate' : 229 { 230 $templateCode = "<h1>{\$node.name}</h1>\n\n"; 231 232 // Append attribute view 233 if ( get_class( $class ) == "ezcontentclass" ) 234 { 235 $attributes =& $class->fetchAttributes(); 236 foreach ( $attributes as $attribute ) 237 { 238 $identifier = $attribute->attribute( 'identifier' ); 239 $name = $attribute->attribute( 'name' ); 240 $templateCode .= "<h2>$name</h2>\n"; 241 $templateCode .= "{attribute_view_gui attribute=\$node.object.data_map.$identifier}\n\n"; 242 } 243 } 244 245 $templateCode .= "" . 246 "{let page_limit=20\n" . 247 " children=fetch('content','list',hash(parent_node_id,\$node.node_id,sort_by,\$node.sort_array,limit,\$page_limit,offset,\$view_parameters.offset))" . 248 " list_count=fetch('content','list_count',hash(parent_node_id,\$node.node_id))}\n" . 249 "\n" . 250 "{section name=Child loop=\$children sequence=array(bglight,bgdark)}\n" . 251 "{node_view_gui view=line content_node=\$Child:item}\n" . 252 "{/section}\n" . 253 254 "{include name=navigator\n" . 255 " uri='design:navigator/google.tpl'\n" . 256 " page_uri=concat('/content/view','/full/',\$node.node_id)\n" . 257 " item_count=\$list_count\n" . 258 " view_parameters=\$view_parameters\n" . 259 " item_limit=\$page_limit}\n"; 260 "{/let}\n"; 261 }break; 262 263 case 'ViewTemplate' : 264 { 265 $templateCode = "<h1>{\$node.name}</h1>\n\n"; 266 267 // Append attribute view 268 if ( get_class( $class ) == "ezcontentclass" ) 269 { 270 $attributes =& $class->fetchAttributes(); 271 foreach ( $attributes as $attribute ) 272 { 273 $identifier = $attribute->attribute( 'identifier' ); 274 $name = $attribute->attribute( 'name' ); 275 $templateCode .= "<h2>$name</h2>\n"; 276 $templateCode .= "{attribute_view_gui attribute=\$node.object.data_map.$identifier}\n\n"; 277 } 278 } 279 280 }break; 281 282 default: 283 case 'EmptyFile' : 284 { 285 }break; 286 } 287 288 return $templateCode; 289 } 290 291 292 function &generateObjectViewTemplate( &$http, $template, $fileName ) 293 { 294 $matchArray = $http->postVariable( 'Match' ); 295 296 $templateCode = ""; 297 $classID = $matchArray['class']; 298 299 $class = eZContentClass::fetch( $classID ); 300 301 // Check what kind of contents we should create in the template 302 switch ( $http->postVariable( 'TemplateContent' ) ) 303 { 304 case 'DefaultCopy' : 305 { 306 $siteAccess = $http->sessionVariable( 'eZTemplateAdminCurrentSiteAccess' ); 307 $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess ); 308 $fileName = $overrideArray[$template]['base_dir'] . $overrideArray[$template]['template']; 309 $fp = fopen( $fileName, 'rb' ); 310 if ( $fp ) 311 { 312 $codeFromFile = fread( $fp, filesize( $fileName ) ); 313 314 // Remove the "{* DO NOT EDIT... *}" first line (if exists). 315 $templateCode = preg_replace('@^{\*\s*DO\sNOT\sEDIT.*?\*}\n(.*)@s', '$1', $codeFromFile); 316 } 317 else 318 { 319 eZDebug::writeError( "Could not open file $fileName, check read permissions" ); 320 } 321 fclose( $fp ); 322 }break; 323 324 case 'ViewTemplate' : 325 { 326 $templateCode = "<h1>{\$object.name}</h1>\n\n"; 327 328 // Append attribute view 329 if ( get_class( $class ) == "ezcontentclass" ) 330 { 331 $attributes =& $class->fetchAttributes(); 332 foreach ( $attributes as $attribute ) 333 { 334 $identifier = $attribute->attribute( 'identifier' ); 335 $name = $attribute->attribute( 'name' ); 336 $templateCode .= "<h2>$name</h2>\n"; 337 $templateCode .= "{attribute_view_gui attribute=\$object.data_map.$identifier}\n\n"; 338 } 339 } 340 341 }break; 342 343 default: 344 case 'EmptyFile' : 345 { 346 }break; 347 } 348 return $templateCode; 349 } 350 351 function &generatePagelayoutTemplate( &$http, $template, $fileName ) 352 { 353 $templateCode = ""; 354 // Check what kind of contents we should create in the template 355 switch ( $http->postVariable( 'TemplateContent' ) ) 356 { 357 case 'DefaultCopy' : 358 { 359 $siteAccess = $http->sessionVariable( 'eZTemplateAdminCurrentSiteAccess' ); 360 $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess ); 361 $fileName = $overrideArray[$template]['base_dir'] . $overrideArray[$template]['template']; 362 $fp = fopen( $fileName, 'rb' ); 363 if ( $fp ) 364 { 365 $codeFromFile = fread( $fp, filesize( $fileName ) ); 366 367 // Remove the "{* DO NOT EDIT... *}" first line (if exists). 368 $templateCode = preg_replace('@^{\*\s*DO\sNOT\sEDIT.*?\*}\n(.*)@s', '$1', $codeFromFile); 369 } 370 else 371 { 372 eZDebug::writeError( "Could not open file $fileName, check read permissions" ); 373 } 374 fclose( $fp ); 375 }break; 376 377 default: 378 case 'EmptyFile' : 379 { 380 $templateCode = '{*?template charset=latin1?*}' . 381 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' . 382 '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n" . 383 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="no" lang="no">' . 384 '<head>' . "\n" . 385 ' <link rel="stylesheet" type="text/css" href={"stylesheets/core.css"|ezdesign} />' . "\n" . 386 ' <link rel="stylesheet" type="text/css" href={"stylesheets/admin.css"|ezdesign} />' . "\n" . 387 ' <link rel="stylesheet" type="text/css" href={"stylesheets/debug.css"|ezdesign} />' . "\n" . 388 ' {include uri="design:page_head.tpl"}' . "\n" . 389 '</head>' . "\n" . 390 '<body>' . "\n" . 391 '{$module_result.content}' . "\n" . 392 '<!--DEBUG_REPORT-->' . "\n" . 393 '</body>' . "\n" . 394 '</html>' . "\n"; 395 }break; 396 } 397 return $templateCode; 398 } 399 400 function &generateDefaultTemplate( &$http, $template, $fileName ) 401 { 402 $templateCode = ""; 403 // Check what kind of contents we should create in the template 404 switch ( $http->postVariable( 'TemplateContent' ) ) 405 { 406 case 'DefaultCopy' : 407 { 408 $siteAccess = $http->sessionVariable( 'eZTemplateAdminCurrentSiteAccess' ); 409 $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess ); 410 $fileName = $overrideArray[$template]['base_dir'] . $overrideArray[$template]['template']; 411 $fp = fopen( $fileName, 'rb' ); 412 if ( $fp ) 413 { 414 $codeFromFile = fread( $fp, filesize( $fileName ) ); 415 416 // Remove the "{* DO NOT EDIT... *}" first line (if exists). 417 $templateCode = preg_replace('@^{\*\s*DO\sNOT\sEDIT.*?\*}\n(.*)@s', '$1', $codeFromFile); 418 } 419 else 420 { 421 eZDebug::writeError( "Could not open file $fileName, check read permissions" ); 422 } 423 fclose( $fp ); 424 }break; 425 426 default: 427 case 'EmptyFile' : 428 { 429 $templateCode = '{*?template charset=latin1?*}' . 430 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' . 431 '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n" . 432 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="no" lang="no">' . 433 '<head>' . "\n" . 434 ' <link rel="stylesheet" type="text/css" href={"stylesheets/core.css"|ezdesign} />' . "\n" . 435 ' <link rel="stylesheet" type="text/css" href={"stylesheets/admin.css"|ezdesign} />' . "\n" . 436 ' <link rel="stylesheet" type="text/css" href={"stylesheets/debug.css"|ezdesign} />' . "\n" . 437 ' {include uri="design:page_head.tpl"}' . "\n" . 438 '</head>' . "\n" . 439 '<body>' . "\n" . 440 '{$module_result.content}' . "\n" . 441 '<!--DEBUG_REPORT-->' . "\n" . 442 '</body>' . "\n" . 443 '</html>' . "\n"; 444 }break; 445 } 446 return $templateCode; 447 } 448 449 450 $tpl->setVariable( 'error', $error ); 451 $tpl->setVariable( 'template', $template ); 452 $tpl->setVariable( 'template_type', $templateType ); 453 $tpl->setVariable( 'template_name', $templateName ); 454 $tpl->setVariable( 'site_base', $siteBase ); 455 $tpl->setVariable( 'site_design', $siteDesign ); 456 $tpl->setVariable( 'override_keys', $overrideKeys ); 457 458 $Result = array(); 459 $Result['content'] =& $tpl->fetch( "design:visual/templatecreate.tpl" ); 460 $Result['path'] = array( array( 'url' => "/visual/templatelist/", 461 'text' => ezi18n( 'kernel/design', 'Template list' ) ), 462 array( 'url' => "/visual/templateview". $template, 463 'text' => ezi18n( 'kernel/design', 'Template view' ) ), 464 array( 'url' => false, 465 'text' => ezi18n( 'kernel/design', 'Create new template' ) ) ); 466 ?>
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 |