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()
133 foreach ($this->modules() as $m){
134 $view_name = "Pman.$m";
136 $dh = opendir("Pman/$m");
144 while (($fn = readdir($dh)) !== false) {
146 if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
151 echo "Processing {$fn} \n";
154 $template = DB_DataObject::factory('core_template');
155 $template->setFrom(array(
158 'view_name' => $view_name,
166 if($template->find(true)){
167 $o = clone ($template);
169 $updated = empty($template->updated) ? '1970-01-01' : $template->updated ;
171 $template->is_deleted = 0;
173 $template->filetype = 'bjs';
174 $template->updated = $template->sqlValue("NOW()");
176 (empty($o)) ? $template->insert() : $template->update($o);
178 if (strtotime($updated) >= filemtime('Pman' . '/' . $m . '/' . $fn)) {
182 $ids[] = $template->id;
183 $data = json_decode(file_get_contents('Pman' . '/' . $m . '/' . $fn), true);
185 $template->words = empty($data['strings']) ? array() : $data['strings'];
187 $x = DB_DataObject::Factory('core_templatestr');
188 $x->syncTemplateWords($template, false);
192 $del = DB_DataObject::factory('core_template');
193 $del->whereAddIn('!id', $ids, 'int');
194 $del->whereAddIn('view_name', $this->modules(), 'string');
195 $del->filetype = 'bjs';
196 $delids = $del->fetchAll('id');
198 DB_DataObject::factory('core_template')->query(
199 'update core_template set is_deleted = 1 where id in('. implode(',', $delids). ')'
209 function scanTables()
211 $ff = HTML_FlexyFramework::get();
213 if (empty($ff->Pman_Core)) {
214 $this->jerr("config[Pman_Core] is not set");
217 if(isset($ff->Pman_Core['DataObjects_Core_templatestr']['tables'])){
218 $cts = DB_DataObject::factory('core_templatestr');
221 echo "Sync tables.....\n";
224 foreach($ff->Pman_Core['DataObjects_Core_templatestr']['tables'] as $table=>$cols){
225 $t = DB_DataObject::factory($table);
226 foreach($t->fetchAll() as $d) {
227 $cts->onTableChange($this, $d, 'update');
233 function syncLanguage()
235 $ff = HTML_FlexyFramework::get();
237 if (empty($ff->Pman_Core)) {
238 $this->jerr("config[Pman_Core] is not set");
240 $ff = HTML_FlexyFramework::get();
242 $opt_lang = empty($ff->Pman_Admin['languages']) ? array( 'l' => array()) : $ff->Pman_Admin['languages'];
245 echo "Sync the Languages template.....\n";
248 foreach($opt_lang as $l) {
250 echo "Sync $l Language.....\n";
253 $tps = DB_DataObject::factory('core_templatestr');
254 $tps->syncLang($l); /// this should be configured somewhere..
258 function scanPmanTemplates()
260 // the CMS stuff scanned the PHP code looking for references to templates..
261 $tp = DB_DAtaObject::Factory('core_template');
263 foreach ($this->modules() as $m){
266 $ar = $this->scanDir(array(
267 'tdir' => "Pman/$m/templates",
269 'match' => '/\.(html|txt|abw)$/',
270 'skipdir' => array('images','css','js'),
275 foreach($ar as $pg) {
277 $temp = $tp->syncTemplatePage(array(
279 'template_dir' => "Pman/$m/templates",
286 // should clean up old templates..
288 $ar = $this->scanDir(array(
291 'match' => '/\.(php)$/',
292 'skipdir' => array('templates'),
297 foreach($ar as $pg) {
299 $temp = $tp->syncPhpGetText(array(
301 'template_dir' => "Pman/$m",
314 //$tp->syncTemplatePage($pg);
316 $del = DB_DataObject::factory('core_template');
317 $del->whereAddIn('!id', $ids, 'int');
318 $del->whereAddIn('view_name', $this->modules(), 'string');
319 $del->whereAddIn('filetype' , array( 'php', 'html' ), 'string');
320 $delids = $del->fetchAll('id');
322 DB_DataObject::factory('core_template')->query(
323 'update core_template set is_deleted = 1 where id in('. implode(',', $delids). ')'
331 function scanDir($cfg) //$view, $tdir , $subdir='', $match)
333 //echo "TSCAN base= $base subdir =$subdir\n ";
334 $ff = HTML_FlexyFramework::get();
336 $subdir = $cfg['subdir'];
337 $scandir = $cfg['tdir']. (empty($subdir) ? '' : '/') . $subdir;
339 if (in_array($subdir, $cfg['skipdir'])) {
342 // skip dom_templates
344 if (!file_exists($scandir)) {
347 $dh = opendir($scandir);
349 return array(); // something went wrong!?
353 while (($fn = readdir($dh)) !== false) {
354 // do we care that it will try and parse the template directory??? - not really..
355 // as we are only looking for php files..
356 if(empty($fn) || $fn[0] == '.'){
360 $fullpath = $scandir.(empty($scandir) ? '' : "/").$fn;
361 // echo "filename: $fullpath \n";
363 if (is_link($fullpath)) {
367 if(is_dir($fullpath)){
368 // then recursively call self...
369 $cfg['subdir'] = $subdir . (empty($subdir) ? '' : '/') . $fn;
370 $children = $this->scanDir($cfg);
371 if (count($children)) {
372 $ret = array_merge($ret, $children);
379 if (!preg_match($cfg['match'], $fn) || !is_file($fullpath)) {
385 $ret[] = $subdir . (empty($subdir) ? '' : '/'). $fn; /// this used to be strtolower?? why???