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($tbl, $opts=array())
35 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
42 $this->scanProjectBJS();
44 $this->scanPmanTemplates();
47 $this->syncLanguage();
49 DB_DataObject::factory('core_template')->query(
50 "update core_template set is_deleted = 1 where filetype = ''"
57 function scanProjectBJS()
59 $ff = HTML_FlexyFramework::get();
61 if (empty($ff->Pman_Core)) {
62 $this->jerr("config[Pman_Core] is not set");
64 if (!empty($ff->Pman_Core['project_name'])) {
65 $base = $ff->Pman_Core['project_name'];
72 $this->jerr("could not open dir: config[Pman_Core] = " . $base);
73 return $ret; // something went wrong!?
76 while (($fn = readdir($dh)) !== false) {
78 if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
83 echo "Processing {$fn} \n";
86 $template = DB_DataObject::factory('core_template');
87 $template->setFrom(array(
95 if($template->find(true)){
96 $o = clone ($template);
98 $template->filetype = 'bjs';
100 $template->updated = $template->sqlValue("NOW()");
102 (empty($o)) ? $template->insert() : $template->update($o);
104 $data = json_decode(file_get_contents($base . '/' . $fn), true);
106 $template->words = empty($data['strings']) ? array() : $data['strings'];
108 $x = DB_DataObject::Factory('core_templatestr');
109 $x->syncTemplateWords($template, false);
115 function scanPmanBJS()
119 foreach ($this->modules() as $m){
120 $view_name = "Pman.$m";
122 $dh = opendir("Pman/$m");
130 while (($fn = readdir($dh)) !== false) {
132 if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
137 echo "Processing {$fn} \n";
140 $template = DB_DataObject::factory('core_template');
141 $template->setFrom(array(
144 'view_name' => $view_name,
150 if($template->find(true)){
151 $o = clone ($template);
153 $template->is_deleted = 0;
155 $template->filetype = 'bjs';
156 $template->updated = $template->sqlValue("NOW()");
158 (empty($o)) ? $template->insert() : $template->update($o);
159 $ids[] = $template->id;
160 $data = json_decode(file_get_contents('Pman' . '/' . $m . '/' . $fn), true);
162 $template->words = empty($data['strings']) ? array() : $data['strings'];
164 $x = DB_DataObject::Factory('core_templatestr');
165 $x->syncTemplateWords($template, false);
169 $del = DB_DataObject::factory('core_template');
170 $del->whereAddIn('!id', $ids, 'int');
171 $del->whereAddIn('view_name', $this->modules(), 'string');
172 $del->filetype = 'bjs';
173 $delids = $del->fetchAll('id');
175 DB_DataObject::factory('core_template')->query(
176 'update core_template set is_deleted = 1 where id in('. implode(',', $delids). ')'
186 function scanTables()
188 $ff = HTML_FlexyFramework::get();
190 if (empty($ff->Pman_Core)) {
191 $this->jerr("config[Pman_Core] is not set");
194 if(isset($ff->Pman_Core['DataObjects_Core_templatestr']['tables'])){
195 $cts = DB_DataObject::factory('core_templatestr');
198 echo "Sync tables.....\n";
201 foreach($ff->Pman_Core['DataObjects_Core_templatestr']['tables'] as $table=>$cols){
202 $t = DB_DataObject::factory($table);
203 foreach($t->fetchAll() as $d) {
204 $cts->onTableChange($this, $d, 'update');
210 function syncLanguage()
212 $ff = HTML_FlexyFramework::get();
214 if (empty($ff->Pman_Core)) {
215 $this->jerr("config[Pman_Core] is not set");
218 $opt_lang = empty($ff->Pman_Core_I18n) ? array( 'l' => array()) : $ff->Pman_Core_I18n;
221 echo "Sync the Languages template.....\n";
224 foreach($opt_lang['l'] as $l) {
226 echo "Sync $l Language.....\n";
229 $tps = DB_DataObject::factory('core_templatestr');
230 $tps->syncLang($l); /// this should be configured somewhere..
234 function scanPmanTemplates()
236 // the CMS stuff scanned the PHP code looking for references to templates..
237 $tp = DB_DAtaObject::Factory('core_template');
239 foreach ($this->modules() as $m){
242 $ar = $this->scanDir(array(
243 'tdir' => "Pman/$m/templates",
245 'match' => '/\.(html|txt|abw)$/',
246 'skipdir' => array('images','css','js'),
251 foreach($ar as $pg) {
253 $temp = $tp->syncTemplatePage(array(
255 'template_dir' => "Pman/$m/templates",
262 // should clean up old templates..
264 $ar = $this->scanDir(array(
267 'match' => '/\.(php)$/',
268 'skipdir' => array('templates'),
273 foreach($ar as $pg) {
275 $temp = $tp->syncPhpGetText(array(
277 'template_dir' => "Pman/$m",
290 //$tp->syncTemplatePage($pg);
292 $del = DB_DataObject::factory('core_template');
293 $del->whereAddIn('!id', $ids, 'int');
294 $del->whereAddIn('view_name', $this->modules(), 'string');
295 $del->whereAddIn('filetype' , array( 'php', 'html' ), 'string');
296 $delids = $del->fetchAll('id');
298 DB_DataObject::factory('core_template')->query(
299 'update core_template set is_deleted = 1 where id in('. implode(',', $delids). ')'
307 function scanDir($cfg) //$view, $tdir , $subdir='', $match)
309 //echo "TSCAN base= $base subdir =$subdir\n ";
310 $ff = HTML_FlexyFramework::get();
312 $subdir = $cfg['subdir'];
313 $scandir = $cfg['tdir']. (empty($subdir) ? '' : '/') . $subdir;
315 if (in_array($subdir, $cfg['skipdir'])) {
318 // skip dom_templates
320 if (!file_exists($scandir)) {
323 $dh = opendir($scandir);
325 return array(); // something went wrong!?
329 while (($fn = readdir($dh)) !== false) {
330 // do we care that it will try and parse the template directory??? - not really..
331 // as we are only looking for php files..
332 if(empty($fn) || $fn[0] == '.'){
336 $fullpath = $scandir.(empty($scandir) ? '' : "/").$fn;
337 // echo "filename: $fullpath \n";
339 if (is_link($fullpath)) {
343 if(is_dir($fullpath)){
344 // then recursively call self...
345 $cfg['subdir'] = $subdir . (empty($subdir) ? '' : '/') . $fn;
346 $children = $this->scanDir($cfg);
347 if (count($children)) {
348 $ret = array_merge($ret, $children);
355 if (!preg_match($cfg['match'], $fn) || !is_file($fullpath)) {
361 $ret[] = $subdir . (empty($subdir) ? '' : '/'). $fn; /// this used to be strtolower?? why???