00001 <?php
00002
00015
00016
00017
00018 require(dirname(__FILE__) . '/includes/cliTool.inc.php');
00019
00020 class preCompile extends CommandLineTool {
00021
00023 var $templateMgr;
00024 var $helpTopicDao;
00025 var $helpTocDao;
00026
00031 function preCompile($argv = array()) {
00032 parent::CommandLineTool($argv);
00033
00034 if (isset($this->argv[0]) && $this->argv[0] == '-h') {
00035 $this->usage();
00036 exit(0);
00037 }
00038 }
00039
00043 function usage() {
00044 echo "Script to precompile all templates and localization and help cache files\n"
00045 . "Usage: {$this->scriptName}\n";
00046 }
00047
00048 function execute() {
00049 $this->compileTemplates();
00050 $this->compileLocales();
00051 $this->compileHelp();
00052 }
00053
00054 function compileTemplates() {
00055 import('issue.IssueAction');
00056 import('form.Form');
00057 $this->templateMgr = &TemplateManager::getManager();
00058
00059
00060
00061
00062
00063 $this->templateMgr->register_function('print_issue_id', array(new IssueAction(), 'smartyPrintIssueId'));
00064 $this->templateMgr->register_function('fieldLabel', array(new Form(null), 'smartyFieldLabel'));
00065 $this->templateMgr->register_modifier('validate_url', 'smarty_rtadmin_validate_url');
00066
00067 import('plugins.ImportExportPlugin');
00068 $this->templateMgr->register_function('plugin_url', array(new ImportExportPlugin(), 'smartyPluginUrl'));
00069
00070
00071 $this->_findFiles('templates', '_compileTemplate', create_function('$f', 'return preg_match(\'/\.tpl$/\', $f);'));
00072 $this->_findFiles('plugins', '_compilePluginTemplate', create_function('$f', 'return preg_match(\'/\.tpl$/\', $f);'));
00073 }
00074
00075 function _compileTemplate($file) {
00076 $this->templateMgr->compile(preg_replace('|^templates/|', '', $file));
00077 }
00078
00079 function _compilePluginTemplate($file) {
00080 $this->templateMgr->compile('file:' . getcwd() . '/' . $file);
00081 }
00082
00083 function compileLocales() {
00084 $locales = &Locale::getAllLocales();
00085 foreach ($locales as $key => $name) {
00086 Locale::loadLocale($key);
00087 }
00088 }
00089
00090 function compileHelp() {
00091 import('help.HelpToc');
00092 import('help.HelpTocDAO');
00093 import('help.HelpTopic');
00094 import('help.HelpTopicDAO');
00095 import('help.HelpTopicSection');
00096 $this->helpTopicDao = &DAORegistry::getDAO('HelpTopicDAO');
00097 $this->helpTocDao = &DAORegistry::getDAO('HelpTocDAO');
00098 $this->_findFiles('help', '_compileHelp', create_function('$f', 'return preg_match(\'/[\d]+\.xml$/\', $f);'));
00099 }
00100
00101 function _compileHelp($file) {
00102 preg_match('|help/([\w]+)/(.+)\.xml|', $file, $matches);
00103 Request::setCookieVar('currentLocale', $matches[1]);
00104
00105 if (strstr($matches[2], '/topic/')) {
00106 $this->helpTopicDao->getTopic($matches[2]);
00107 } else {
00108 $this->helpTocDao->getToc($matches[2]);
00109 }
00110 }
00111
00112 function _findFiles($baseDir, $func, $filter = null) {
00113 $dir = opendir($baseDir);
00114 while(($file = readdir($dir)) !== false) {
00115 if ($file != '.' && $file != '..') {
00116 $path = $baseDir . '/' . $file;
00117 if (is_file($path)) {
00118 if (!isset($filter) || $filter($path)) {
00119 call_user_func(array($this, $func), $path);
00120 }
00121 } else {
00122 $this->_findFiles($path, $func, $filter);
00123 }
00124 }
00125 }
00126
00127 }
00128
00129 }
00130
00131 $tool = &new preCompile(isset($argv) ? $argv : array());
00132 $tool->execute();
00133
00134 ?>