9 require_once 'Pman.php';
10 class Pman_Admin_UpdateBjsTemplates extends Pman
13 static $cli_desc = "Update BJS Templates";
15 static $cli_opts = array();
24 $ff = HTML_FlexyFramework::get();
25 if (!empty($ff->cli)) {
33 function get($step, $opts=array())
35 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
39 case 'scanProjectBJS':
41 case 'scanPmanTemplates':
45 $this->jok("DONE - " . $step);
47 $this->jerr("invalid step");
53 function updateData() // this does everything?? not used?
56 $this->scanProjectBJS();
58 $this->scanPmanTemplates();
61 $this->syncLanguage();
63 DB_DataObject::factory('core_template')->query(
64 "update core_template set is_deleted = 1 where filetype = ''"
71 function scanProjectBJS() // this is probably not used (replace by the CMS scanner)
73 $ff = HTML_FlexyFramework::get();
75 if (empty($ff->Pman_Core)) {
76 $this->jerr("config[Pman_Core] is not set");
78 if (!empty($ff->Pman_Core['project_name'])) {
79 $base = $ff->Pman_Core['project_name'];
86 $this->jerr("could not open dir: config[Pman_Core] = " . $base);
87 return $ret; // something went wrong!?
90 while (($fn = readdir($dh)) !== false) {
92 if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
97 echo "Processing {$fn} \n";
100 $template = DB_DataObject::factory('core_template');
101 $template->setFrom(array(
109 if($template->find(true)){
110 $o = clone ($template);
112 $template->filetype = 'bjs';
114 $template->updated = $template->sqlValue("NOW()");
116 (empty($o)) ? $template->insert() : $template->update($o);
118 $data = json_decode(file_get_contents($base . '/' . $fn), true);
120 $template->words = empty($data['strings']) ? array() : $data['strings'];
122 $x = DB_DataObject::Factory('core_templatestr');
123 $x->syncTemplateWords($template, false);
129 function scanPmanBJS()
132 foreach ($this->modules() as $m){
133 $view_name = "Pman.$m";
135 $dh = opendir("Pman/$m");
143 while (($fn = readdir($dh)) !== false) {
145 if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
150 echo "Processing {$fn} \n";
153 $template = DB_DataObject::factory('core_template');
154 $template->setFrom(array(
157 'view_name' => $view_name,
165 if($template->find(true)){
166 $o = clone ($template);
168 $updated = empty($template->updated) ? '1970-01-01' : $template->updated ;
170 $template->is_deleted = 0;
172 $template->filetype = 'bjs';
173 $template->updated = $template->sqlValue("NOW()");
175 (empty($o)) ? $template->insert() : $template->update($o);
177 if (strtotime($updated) >= filemtime('Pman' . '/' . $m . '/' . $fn)) {
181 $ids[] = $template->id;
182 $data = json_decode(file_get_contents('Pman' . '/' . $m . '/' . $fn), true);
184 $template->words = empty($data['strings']) ? array() : $data['strings'];
186 $x = DB_DataObject::Factory('core_templatestr');
187 $x->syncTemplateWords($template, false);
191 $del = DB_DataObject::factory('core_template');
192 $del->whereAddIn('!id', $ids, 'int');
193 $del->whereAddIn('view_name', $this->modules(), 'string');
194 $del->filetype = 'bjs';
195 $delids = $del->fetchAll('id');
197 DB_DataObject::factory('core_template')->query(
198 'update core_template set is_deleted = 1 where id in('. implode(',', $delids). ')'
208 function scanTables()
210 $ff = HTML_FlexyFramework::get();
212 if (empty($ff->Pman_Core)) {
213 $this->jerr("config[Pman_Core] is not set");
216 if(isset($ff->Pman_Core['DataObjects_Core_templatestr']['tables'])){
217 $cts = DB_DataObject::factory('core_templatestr');
220 echo "Sync tables.....\n";
223 // deactivate all table translation
224 $t = DB_DataObject::factory('core_templatestr');
226 "UPDATE core_templatestr
228 WHERE on_table != ''"
231 // activate the used table translation
232 foreach($ff->Pman_Core['DataObjects_Core_templatestr']['tables'] as $table=>$cols){
233 $t = DB_DataObject::factory($table);
234 foreach($t->fetchAll() as $d) {
235 $cts->onTableChange($this, $d, 'update');
241 function syncLanguage()
243 $ff = HTML_FlexyFramework::get();
245 if (empty($ff->Pman_Core)) {
246 $this->jerr("config[Pman_Core] is not set");
248 $ff = HTML_FlexyFramework::get();
250 $opt_lang = empty($ff->Pman_Admin['languages']) ? array( 'l' => array()) : $ff->Pman_Admin['languages'];
253 echo "Sync the Languages template.....\n";
256 foreach($opt_lang as $l) {
258 echo "Sync $l Language.....\n";
261 $tps = DB_DataObject::factory('core_templatestr');
262 $tps->syncLang($l); /// this should be configured somewhere..
266 function scanPmanTemplates()
268 // the CMS stuff scanned the PHP code looking for references to templates..
269 $tp = DB_DAtaObject::Factory('core_template');
271 foreach ($this->modules() as $m){
274 $ar = $this->scanDir(array(
275 'tdir' => "Pman/$m/templates",
277 'match' => '/\.(html|txt|abw)$/',
278 'skipdir' => array('images','css','js'),
283 foreach($ar as $pg) {
285 $temp = $tp->syncTemplatePage(array(
287 'template_dir' => "Pman/$m/templates",
294 // should clean up old templates..
296 $ar = $this->scanDir(array(
299 'match' => '/\.(php)$/',
300 'skipdir' => array('templates'),
305 foreach($ar as $pg) {
307 $temp = $tp->syncPhpGetText(array(
309 'template_dir' => "Pman/$m",
322 //$tp->syncTemplatePage($pg);
324 $del = DB_DataObject::factory('core_template');
325 $del->whereAddIn('!id', $ids, 'int');
326 $del->whereAddIn('view_name', $this->modules(), 'string');
327 $del->whereAddIn('filetype' , array( 'php', 'html' ), 'string');
328 $delids = $del->fetchAll('id');
330 DB_DataObject::factory('core_template')->query(
331 'update core_template set is_deleted = 1 where id in('. implode(',', $delids). ')'
339 function scanDir($cfg) //$view, $tdir , $subdir='', $match)
341 //echo "TSCAN base= $base subdir =$subdir\n ";
342 $ff = HTML_FlexyFramework::get();
344 $subdir = $cfg['subdir'];
345 $scandir = $cfg['tdir']. (empty($subdir) ? '' : '/') . $subdir;
347 if (in_array($subdir, $cfg['skipdir'])) {
350 // skip dom_templates
352 if (!file_exists($scandir)) {
355 $dh = opendir($scandir);
357 return array(); // something went wrong!?
361 while (($fn = readdir($dh)) !== false) {
362 // do we care that it will try and parse the template directory??? - not really..
363 // as we are only looking for php files..
364 if(empty($fn) || $fn[0] == '.'){
368 $fullpath = $scandir.(empty($scandir) ? '' : "/").$fn;
369 // echo "filename: $fullpath \n";
371 if (is_link($fullpath)) {
375 if(is_dir($fullpath)){
376 // then recursively call self...
377 $cfg['subdir'] = $subdir . (empty($subdir) ? '' : '/') . $fn;
378 $children = $this->scanDir($cfg);
379 if (count($children)) {
380 $ret = array_merge($ret, $children);
387 if (!preg_match($cfg['match'], $fn) || !is_file($fullpath)) {
393 $ret[] = $subdir . (empty($subdir) ? '' : '/'). $fn; /// this used to be strtolower?? why???