|
eZ Publish
[4.0]
|
00001 #!/usr/bin/env php 00002 <?php 00003 // 00004 // Created on: <02-Mar-2004 20:10:18 amos> 00005 // 00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00007 // SOFTWARE NAME: eZ Publish 00008 // SOFTWARE RELEASE: 4.0.x 00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00010 // SOFTWARE LICENSE: GNU General Public License v2.0 00011 // NOTICE: > 00012 // This program is free software; you can redistribute it and/or 00013 // modify it under the terms of version 2.0 of the GNU General 00014 // Public License as published by the Free Software Foundation. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of version 2.0 of the GNU General 00022 // Public License along with this program; if not, write to the Free 00023 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00024 // MA 02110-1301, USA. 00025 // 00026 // 00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00028 // 00029 00030 //include_once( 'lib/ezutils/classes/ezcli.php' ); 00031 //include_once( 'kernel/classes/ezscript.php' ); 00032 00033 require 'autoload.php'; 00034 00035 $cli = eZCLI::instance(); 00036 $script = eZScript::instance( array( 'description' => ( "eZ Publish Template Compiler\n" . 00037 "\n" . 00038 "./bin/php/eztc.php -snews --www-dir='/mypath' --index-file='/index.php' --access-path='news'" ), 00039 'use-session' => false, 00040 'use-modules' => true, 00041 'use-extensions' => true ) ); 00042 00043 $script->startup(); 00044 00045 $options = $script->getOptions( "[compile-directory:][www-dir:][index-file:][access-path:][force][full-url][no-full-url]", 00046 "", 00047 array( 'force' => "Force compilation of template whether it has changed or not", 00048 'compile-directory' => "Where to place compiled files,\ndefault is template/compiled in current cache directory", 00049 'full-url' => "Makes sure generated urls have http:// in them (i.e. global), used mainly by sites that include the eZ Publish HTML (e.g payment gateways)", 00050 'no-full-url' => "Makes sure generated urls are relative to the site. (default)", 00051 'www-dir' => "The part before the index.php in your URL, you should supply this if you are running in non-virtualhost mode", 00052 'index-file' => "The name of your index.php if you are running in non-virtualhost mode", 00053 'access-path' => "Extra access path" ) ); 00054 $sys = eZSys::instance(); 00055 00056 $forceCompile = false; 00057 $useFullURL = false; 00058 00059 if ( $options['www-dir'] ) 00060 { 00061 $sys->WWWDir = $options['www-dir']; 00062 } 00063 if ( $options['index-file'] ) 00064 { 00065 $sys->IndexFile = $options['index-file']; 00066 } 00067 if ( $options['access-path'] ) 00068 { 00069 $sys->AccessPath = array( $options['access-path'] ); 00070 } 00071 if ( $options['force'] ) 00072 { 00073 $forceCompile = true; 00074 } 00075 if ( $options['full-url'] ) 00076 { 00077 $useFullURL = true; 00078 } 00079 if ( $options['no-full-url'] ) 00080 { 00081 $useFullURL = false; 00082 } 00083 00084 $script->initialize(); 00085 00086 //include_once( 'lib/ezutils/classes/ezhttptool.php' ); 00087 $http = eZHTTPTool::instance(); 00088 $http->UseFullUrl = $useFullURL; 00089 00090 00091 if ( count( $options['arguments'] ) > 0 ) 00092 { 00093 $ini = eZINI::instance(); 00094 00095 require_once( 'kernel/common/template.php' ); 00096 //include_once( 'lib/eztemplate/classes/eztemplatecompiler.php' ); 00097 $tpl = templateInit(); 00098 00099 $fileList = $options['arguments']; 00100 00101 $script->setIterationData( '.', '~' ); 00102 $script->setShowVerboseOutput( true ); 00103 if ( $forceCompile ) 00104 eZTemplateCompiler::setSettings( array( 'generate' => true ) ); 00105 00106 $files = array(); 00107 foreach ( $fileList as $file ) 00108 { 00109 $filename = basename( $file ); 00110 if ( preg_match( "!^.+~$|^/?#.+#$|^\..+$!", $filename ) ) 00111 continue; 00112 $files[] = $file; 00113 } 00114 00115 $script->resetIteration( count( $files ) ); 00116 foreach ( $files as $file ) 00117 { 00118 if ( is_dir( $file ) ) 00119 { 00120 $script->iterate( $cli, true, "Skipping directory: " . $cli->stylize( 'dir', $file ) ); 00121 } 00122 else 00123 { 00124 $status = $tpl->compileTemplateFile( $file ); 00125 $text = false; 00126 if ( $status ) 00127 $text = "Compiled template file: " . $cli->stylize( 'file', $file ); 00128 else 00129 $text = "Compilation failed: " . $cli->stylize( 'file', $file ); 00130 $script->iterate( $cli, $status, $text ); 00131 } 00132 } 00133 } 00134 else 00135 { 00136 $ini = eZINI::instance(); 00137 $standardDesign = $ini->variable( "DesignSettings", "StandardDesign" ); 00138 $siteDesign = $ini->variable( "DesignSettings", "SiteDesign" ); 00139 $additionalSiteDesignList = $ini->variable( "DesignSettings", "AdditionalSiteDesignList" ); 00140 00141 $designList = array_merge( array( $standardDesign ), $additionalSiteDesignList, array( $siteDesign ) ); 00142 00143 require_once( 'kernel/common/template.php' ); 00144 //include_once( 'lib/eztemplate/classes/eztemplatecompiler.php' ); 00145 $tpl = templateInit(); 00146 00147 $script->setIterationData( '.', '~' ); 00148 if ( $forceCompile ) 00149 eZTemplateCompiler::setSettings( array( 'generate' => true ) ); 00150 00151 $extensionDirectory = eZExtension::baseDirectory(); 00152 $designINI = eZINI::instance( 'design.ini' ); 00153 $extensions = $designINI->variable( 'ExtensionSettings', 'DesignExtensions' ); 00154 00155 foreach ( $designList as $design ) 00156 { 00157 $cli->output( "Compiling in design " . $cli->stylize( 'emphasize', $design ) ); 00158 $baseDir = 'design/' . $design; 00159 00160 $files = eZDir::recursiveFindRelative( '', "$baseDir/templates", "\.tpl" ); 00161 $files = array_merge( $files, eZDir::recursiveFindRelative( '', "$baseDir/override/templates", "\.tpl" ) ); 00162 00163 foreach( $extensions as $extension ) 00164 { 00165 $files = array_merge( $files, eZDir::recursiveFindRelative( '', "$extensionDirectory/$extension/$baseDir/templates", "\.tpl" ) ); 00166 $files = array_merge( $files, eZDir::recursiveFindRelative( '', "$extensionDirectory/$extension/$baseDir/override/templates", "\.tpl" ) ); 00167 } 00168 00169 $script->resetIteration( count( $files ) ); 00170 foreach ( $files as $file ) 00171 { 00172 $status = $tpl->compileTemplateFile( $file ); 00173 $text = false; 00174 if ( $status ) 00175 $text = "Compiled template file: " . $cli->stylize( 'file', $file ); 00176 else 00177 $text = "Compilation failed: " . $cli->stylize( 'file', $file ); 00178 $script->iterate( $cli, $status, $text ); 00179 } 00180 } 00181 } 00182 00183 $script->shutdown(); 00184 00185 ?>