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");
55 $this->scanProjectBJS();
57 $this->scanPmanTemplates();
60 $this->syncLanguage();
62 DB_DataObject::factory('core_template')->query(
63 "update core_template set is_deleted = 1 where filetype = ''"
70 function scanProjectBJS()
72 $ff = HTML_FlexyFramework::get();
74 if (empty($ff->Pman_Core)) {
75 $this->jerr("config[Pman_Core] is not set");
77 if (!empty($ff->Pman_Core['project_name'])) {
78 $base = $ff->Pman_Core['project_name'];
85 $this->jerr("could not open dir: config[Pman_Core] = " . $base);
86 return $ret; // something went wrong!?
89 while (($fn = readdir($dh)) !== false) {
91 if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
96 echo "Processing {$fn} \n";
99 $template = DB_DataObject::factory('core_template');
100 $template->setFrom(array(
108 if($template->find(true)){
109 $o = clone ($template);
111 $template->filetype = 'bjs';
113 $template->updated = $template->sqlValue("NOW()");
115 (empty($o)) ? $template->insert() : $template->update($o);
117 $data = json_decode(file_get_contents($base . '/' . $fn), true);
119 $template->words = empty($data['strings']) ? array() : $data['strings'];
121 $x = DB_DataObject::Factory('core_templatestr');
122 $x->syncTemplateWords($template, false);
128 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,
163 if($template->find(true)){
164 $o = clone ($template);
166 $template->is_deleted = 0;
168 $template->filetype = 'bjs';
169 $template->updated = $template->sqlValue("NOW()");
171 (empty($o)) ? $template->insert() : $template->update($o);
172 $ids[] = $template->id;
173 $data = json_decode(file_get_contents('Pman' . '/' . $m . '/' . $fn), true);
175 $template->words = empty($data['strings']) ? array() : $data['strings'];
177 $x = DB_DataObject::Factory('core_templatestr');
178 $x->syncTemplateWords($template, false);
182 $del = DB_DataObject::factory('core_template');
183 $del->whereAddIn('!id', $ids, 'int');
184 $del->whereAddIn('view_name', $this->modules(), 'string');
185 $del->filetype = 'bjs';
186 $delids = $del->fetchAll('id');
188 DB_DataObject::factory('core_template')->query(
189 'update core_template set is_deleted = 1 where id in('. implode(',', $delids). ')'
199 function scanTables()
201 $ff = HTML_FlexyFramework::get();
203 if (empty($ff->Pman_Core)) {
204 $this->jerr("config[Pman_Core] is not set");
207 if(isset($ff->Pman_Core['DataObjects_Core_templatestr']['tables'])){
208 $cts = DB_DataObject::factory('core_templatestr');
211 echo "Sync tables.....\n";
214 foreach($ff->Pman_Core['DataObjects_Core_templatestr']['tables'] as $table=>$cols){
215 $t = DB_DataObject::factory($table);
216 foreach($t->fetchAll() as $d) {
217 $cts->onTableChange($this, $d, 'update');
223 function syncLanguage()
225 $ff = HTML_FlexyFramework::get();
227 if (empty($ff->Pman_Core)) {
228 $this->jerr("config[Pman_Core] is not set");
230 $ff = HTML_FlexyFramework::get();
232 $opt_lang = empty($ff->Pman_Admin['languages']) ? array( 'l' => array()) : $ff->Pman_Admin['languages'];
235 echo "Sync the Languages template.....\n";
238 foreach($opt_lang as $l) {
240 echo "Sync $l Language.....\n";
243 $tps = DB_DataObject::factory('core_templatestr');
244 $tps->syncLang($l); /// this should be configured somewhere..
248 function scanPmanTemplates()
250 // the CMS stuff scanned the PHP code looking for references to templates..
251 $tp = DB_DAtaObject::Factory('core_template');
253 foreach ($this->modules() as $m){
256 $ar = $this->scanDir(array(
257 'tdir' => "Pman/$m/templates",
259 'match' => '/\.(html|txt|abw)$/',
260 'skipdir' => array('images','css','js'),
265 foreach($ar as $pg) {
267 $temp = $tp->syncTemplatePage(array(
269 'template_dir' => "Pman/$m/templates",
276 // should clean up old templates..
278 $ar = $this->scanDir(array(
281 'match' => '/\.(php)$/',
282 'skipdir' => array('templates'),
287 foreach($ar as $pg) {
289 $temp = $tp->syncPhpGetText(array(
291 'template_dir' => "Pman/$m",
304 //$tp->syncTemplatePage($pg);
306 $del = DB_DataObject::factory('core_template');
307 $del->whereAddIn('!id', $ids, 'int');
308 $del->whereAddIn('view_name', $this->modules(), 'string');
309 $del->whereAddIn('filetype' , array( 'php', 'html' ), 'string');
310 $delids = $del->fetchAll('id');
312 DB_DataObject::factory('core_template')->query(
313 'update core_template set is_deleted = 1 where id in('. implode(',', $delids). ')'
321 function scanDir($cfg) //$view, $tdir , $subdir='', $match)
323 //echo "TSCAN base= $base subdir =$subdir\n ";
324 $ff = HTML_FlexyFramework::get();
326 $subdir = $cfg['subdir'];
327 $scandir = $cfg['tdir']. (empty($subdir) ? '' : '/') . $subdir;
329 if (in_array($subdir, $cfg['skipdir'])) {
332 // skip dom_templates
334 if (!file_exists($scandir)) {
337 $dh = opendir($scandir);
339 return array(); // something went wrong!?
343 while (($fn = readdir($dh)) !== false) {
344 // do we care that it will try and parse the template directory??? - not really..
345 // as we are only looking for php files..
346 if(empty($fn) || $fn[0] == '.'){
350 $fullpath = $scandir.(empty($scandir) ? '' : "/").$fn;
351 // echo "filename: $fullpath \n";
353 if (is_link($fullpath)) {
357 if(is_dir($fullpath)){
358 // then recursively call self...
359 $cfg['subdir'] = $subdir . (empty($subdir) ? '' : '/') . $fn;
360 $children = $this->scanDir($cfg);
361 if (count($children)) {
362 $ret = array_merge($ret, $children);
369 if (!preg_match($cfg['match'], $fn) || !is_file($fullpath)) {
375 $ret[] = $subdir . (empty($subdir) ? '' : '/'). $fn; /// this used to be strtolower?? why???