cli)) { $this->cli = true; return true; } return true; } function get($tbl, $opts=array()) { PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError')); $this->opts = $opts; $this->updateData(); } function updateData() { $this->scanFiles(); $this->scanTables(); $this->syncLanguage(); $this->jok('OK'); } function scanFiles() { $ff = HTML_FlexyFramework::get(); if (empty($ff->Pman_Cms)) { $this->jerr("config[Pman_Cms] is not set"); } foreach(explode(',', $ff->Pman_Cms['project_name']) as $base) { $this->scanFilesBase($base); } } /* * this does all the scan work. * it's pretty simple (does not do subdirectories...) * * only supports BJS / PHP / JS currently. * */ function scanFilesBase($base) { $ff = HTML_FlexyFramework::get(); $dir = $ff->Pman_Cms['site_dir'][$base]; //var_dump($dir); $dh = opendir($dir); $tp = DB_DAtaObject::Factory('cms_template'); $ret = array(); if(!$dh){ $this->jerr("could not open dir: config[Pman_Cms] = " . $dir); return $ret; // something went wrong!? } while (($fn = readdir($dh)) !== false) { if(empty($fn) || $fn[0] == '.') { continue; } $fp = $dir . '/'. $fn; //var_dump($fp); if (is_dir($fp)) { continue; } if (is_link($fp)) { continue; } if (preg_match('/\.js$/', $fn) && !file_exists($dir.'/'. preg_replace('/\.js$/', '.bjs', $fn))) { $temp = $tp->syncJsWords(array( 'base' => $base, 'template_dir' => $dir, 'template' => $fn )); if ($temp) { $ids[] = $temp->id; } continue; } if (preg_match('/\.php$/', $fn)) { $temp = $tp->syncPhpGetText(array( 'base' =>$base, 'template_dir' => $dir, 'template' => $fn )); if ($temp) { $ids[] = $temp->id; } continue; } if (!preg_match('/\.bjs$/', $fn)){ continue; } // var_dump($fn);exit; if($this->cli){ echo "Processing {$fn} \n"; } $template = DB_DataObject::factory('cms_template'); $template->setFrom(array( 'template' => $fn, 'lang' => 'en', 'view_name' => $base )); $o = false; if($template->find(true)){ $o = clone ($template); } $template->filetype = 'bjs'; $template->updated = $template->sqlValue("NOW()"); if (empty($o)) { $ids[] = $template->insert() ; } else { $template->update($o); $ids[] = $o->id; } $data = json_decode(file_get_contents($base . '/' . $fn), true); $template->words = empty($data['strings']) ? array() : $data['strings']; $x = DB_DataObject::Factory('cms_templatestr'); $x->syncTemplateWords($template, false); } $del = DB_DataObject::factory('cms_template'); $del->whereAddIn('!id', $ids, 'int'); $del->view_name = $base; $del->whereAddIn('filetype' , array( 'php', 'bjs' , 'js' ), 'string'); $delids = $del->fetchAll('id'); if ($delids) { DB_DataObject::factory('core_template')->query( 'update cms_template set is_deleted = 1 where id in('. implode(',', $delids). ')' ); } } function scanTables() { $ff = HTML_FlexyFramework::get(); if (empty($ff->Pman_Cms)) { $this->jerr("config[Pman_Cms] is not set"); } if(isset($ff->Pman_Cms['DataObjects_Cms_templatestr']['tables'])){ $cts = DB_DataObject::factory('cms_templatestr'); if($this->cli){ echo "Sync tables.....\n"; } foreach($ff->Pman_Cms['DataObjects_Cms_templatestr']['tables'] as $table=>$cols){ $t = DB_DataObject::factory($table); foreach($t->fetchAll() as $d) { $cts->onTableChange($this, $d, 'update'); } } } } function syncLanguage() { $ff = HTML_FlexyFramework::get(); if (empty($ff->Pman_Cms) || empty($ff->Pman_Cms['languages']) || !is_array($ff->Pman_Cms['languages']) ) { $this->jerr("config[Pman_Cms][languages] is not set"); } if($this->cli){ echo "Sync the Languages template.....\n"; } foreach($ff->Pman_Cms['languages'] as $l) { if($this->cli){ echo "Sync $l Language.....\n"; } $tps = DB_DataObject::factory('cms_templatestr'); $tps->syncLang($l); /// this should be configured somewhere.. } } }