9 require_once 'Pman.php';
10 class Pman_Cms_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->scanTemplates();
46 $this->syncLanguage();
52 function scanTemplates()
54 $ff = HTML_FlexyFramework::get();
56 if (empty($ff->Pman_Cms)) {
57 $this->jerr("config[Pman_Cms] is not set");
60 $base = $ff->Pman_Cms['project_name'];
67 $this->jerr("could not open dir: config[Pman_Cms] = " . $base);
68 return $ret; // something went wrong!?
71 while (($fn = readdir($dh)) !== false) {
73 if(empty($fn) || $fn[0] == '.' || !preg_match('/\.bjs$/', $fn)){
78 echo "Processing {$fn} \n";
81 $template = DB_DataObject::factory('cms_template');
82 $template->setFrom(array(
90 if($template->find(true)){
91 $o = clone ($template);
94 $template->updated = $template->sqlValue("NOW()");
96 (empty($o)) ? $template->insert() : $template->update($o);
98 $data = json_decode(file_get_contents($base . '/' . $fn), true);
100 $template->words = empty($data['strings']) ? array() : $data['strings'];
102 $x = DB_DataObject::Factory('cms_templatestr');
103 $x->syncTemplateWords($template, false);
106 $this->scanPmanTemplates();
110 function scanPmanTemplates()
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('cms_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('cms_templatestr');
155 $x->syncTemplateWords($template, false);
161 function scanTables()
163 $ff = HTML_FlexyFramework::get();
165 if (empty($ff->Pman_Cms)) {
166 $this->jerr("config[Pman_Cms] is not set");
169 if(isset($ff->Pman_Cms['DataObjects_Cms_templatestr']['tables'])){
170 $cts = DB_DataObject::factory('cms_templatestr');
173 echo "Sync tables.....\n";
176 foreach($ff->Pman_Cms['DataObjects_Cms_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_Cms)) {
190 $this->jerr("config[Pman_Cms] 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('cms_templatestr');
205 $tps->syncLang($l); /// this should be configured somewhere..