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();
53 function scanProjectBJS()
55 $ff = HTML_FlexyFramework::get();
57 if (empty($ff->Pman_Core)) {
58 $this->jerr("config[Pman_Core] is not set");
60 if (!empty($ff->Pman_Core['project_name'])) {
61 $base = $ff->Pman_Core['project_name'];
68 $this->jerr("could not open dir: config[Pman_Core] = " . $base);
69 return $ret; // something went wrong!?
72 while (($fn = readdir($dh)) !== false) {
74 if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
79 echo "Processing {$fn} \n";
82 $template = DB_DataObject::factory('core_template');
83 $template->setFrom(array(
91 if($template->find(true)){
92 $o = clone ($template);
95 $template->updated = $template->sqlValue("NOW()");
97 (empty($o)) ? $template->insert() : $template->update($o);
99 $data = json_decode(file_get_contents($base . '/' . $fn), true);
101 $template->words = empty($data['strings']) ? array() : $data['strings'];
103 $x = DB_DataObject::Factory('core_templatestr');
104 $x->syncTemplateWords($template, false);
110 function scanPmanBJS()
112 foreach ($this->modules() as $m){
113 $view_name = "Pman.$m";
115 $dh = opendir("Pman/$m");
123 while (($fn = readdir($dh)) !== false) {
125 if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
130 echo "Processing {$fn} \n";
133 $template = DB_DataObject::factory('core_template');
134 $template->setFrom(array(
137 'view_name' => $view_name
142 if($template->find(true)){
143 $o = clone ($template);
146 $template->updated = $template->sqlValue("NOW()");
148 (empty($o)) ? $template->insert() : $template->update($o);
150 $data = json_decode(file_get_contents('Pman' . '/' . $m . '/' . $fn), true);
152 $template->words = empty($data['strings']) ? array() : $data['strings'];
154 $x = DB_DataObject::Factory('core_templatestr');
155 $x->syncTemplateWords($template, false);
161 function scanTables()
163 $ff = HTML_FlexyFramework::get();
165 if (empty($ff->Pman_Core)) {
166 $this->jerr("config[Pman_Core] is not set");
169 if(isset($ff->Pman_Core['DataObjects_Core_templatestr']['tables'])){
170 $cts = DB_DataObject::factory('core_templatestr');
173 echo "Sync tables.....\n";
176 foreach($ff->Pman_Core['DataObjects_Core_templatestr']['tables'] as $table=>$cols){
177 $t = DB_DataObject::factory($table);
178 foreach($t->fetchAll() as $d) {
179 $cts->onTableChange($this, $d, 'update');
185 function syncLanguage()
187 $ff = HTML_FlexyFramework::get();
189 if (empty($ff->Pman_Core)) {
190 $this->jerr("config[Pman_Core] is not set");
193 $opt_lang = empty($ff->Pman_Core_I18n) ? array( 'l' => array()) : $ff->Pman_Core_I18n;
196 echo "Sync the Languages template.....\n";
199 foreach($opt_lang['l'] as $l) {
201 echo "Sync $l Language.....\n";
204 $tps = DB_DataObject::factory('core_templatestr');
205 $tps->syncLang($l); /// this should be configured somewhere..
209 function scanPmanTemplates()
211 // the CMS stuff scanned the PHP code looking for references to templates..
212 $tp = DB_DAtaObject::Factory('core_template');
214 foreach ($this->modules() as $m){
217 $ar = $this->scanDir(array(
218 'tdir' => "Pman/$m/templates",
220 'match' => '/\.(html|txt|abw)$/',
221 'skipdir' => array('images','css','js'),
226 foreach($ar as $pg) {
229 $tp->syncTemplatePage(array(
231 'template_dir' => "Pman/$m/templates",
235 // should clean up old templates..
237 $ar = $this->scanDir(array(
240 'match' => '/\.(php)$/',
241 'skipdir' => array('templates'),
246 foreach($ar as $pg) {
248 $tp->syncPhpGetText(array(
250 'template_dir' => "Pman/$m",
259 //$tp->syncTemplatePage($pg);
267 function scanDir($cfg) //$view, $tdir , $subdir='', $match)
269 //echo "TSCAN base= $base subdir =$subdir\n ";
270 $ff = HTML_FlexyFramework::get();
272 $subdir = $cfg['subdir'];
273 $scandir = $cfg['tdir']. (empty($subdir) ? '' : '/') . $subdir;
275 if (in_array($subdir, $cfg['skipdir'])) {
278 // skip dom_templates
280 if (!file_exists($scandir)) {
283 $dh = opendir($scandir);
285 return array(); // something went wrong!?
289 while (($fn = readdir($dh)) !== false) {
290 // do we care that it will try and parse the template directory??? - not really..
291 // as we are only looking for php files..
292 if(empty($fn) || $fn[0] == '.'){
296 $fullpath = $scandir.(empty($scandir) ? '' : "/").$fn;
297 // echo "filename: $fullpath \n";
299 if (is_link($fullpath)) {
303 if(is_dir($fullpath)){
304 // then recursively call self...
305 $cfg['subdir'] = $subdir . (empty($subdir) ? '' : '/') . $fn;
306 $children = $this->scanDir($cfg);
307 if (count($children)) {
308 $ret = array_merge($ret, $children);
315 if (!preg_match($cfg['match'], $fn) || !is_file($fullpath)) {
321 $ret[] = $subdir . (empty($subdir) ? '' : '/'). $fn; /// this used to be strtolower?? why???