3 * Table Definition for cms_template
6 * The idea here is that it contains all the strings in the templates with a language '' (empty)
7 * , it then generates a matching set of strings
10 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
12 class Pman_Cms_DataObjects_Cms_template extends DB_DataObject
15 /* the code below is auto generated do not remove the above tag */
17 public $__table = 'cms_template'; // table name
18 public $id; // int(11) not_null primary_key auto_increment
19 public $template; // string(64) not_null
21 public $updated; // blob(65535) blob
22 public $lang; // text NOT NULL;
23 public $view_name; // eg mobile or desktop
24 /* the code above is auto generated do not remove the tag below */
28 function applyFilters($q, $au, $roo)
30 //DB_DataObject::debugLEvel(1);
31 // $x = DB_Dataobject::Factory($this->tableName());
34 // template scanning and syncing should be done by the UpdateDatabase Code.
35 //if (!$x->count() || !empty($q['_rescan'])) {
36 //DB_DataObject::debugLEvel(1);
37 //$tp = DB_DataObject::factory('cms_template');
38 //$opts = HTML_FlexyFramework::get()->Pman_Cms;
39 //$tp->syncTemplateDir(false, '', !empty($q['_rescan']));
40 //if (isset($q['lang'])) {
41 // $this->syncLang($q['lang']);
50 function toRooArray($req)
52 $ret = $this->toArray();
53 if (!empty($req['_clean_name']) ) {
54 $ret['template_clean'] = preg_replace('#\.html$#i', '', $this->template);
62 * @param base (should be full path to template directory)
63 * @param subdir = empty for top or subpath.
65 function syncTemplateDir($base = false, $subdir = '', $force = false)
67 echo "syncTemplateDir: $base , $subdir, $force \n";
68 //print_r(func_get_args());
70 $ff = HTML_FlexyFramework::get();
71 if (!isset($ff->Pman_Cms)) {
72 echo "[ERROR] Not scanning template directory - no set in Pman_Cms[templateDir]\n";
75 $opts = $ff->Pman_Cms;
76 if (is_array($opts['templateDir'])) {
77 foreach($opts['templateDir'] as $type=>$dir) {
78 $this->syncTemplateDir($dir, '', $force);
83 $base = $opts['templateDir'];
88 $tmpls = DB_DataObject::factory('cms_template');
89 $this->tmpls = $tmpls->fetchAll('template','id'); // dupes??
92 $tmp_dir = $base . (empty($subdir) ? '' : '/') . $subdir;
94 if(!is_dir($tmp_dir)){
98 $dh = opendir($tmp_dir);
100 return; // something went wrong!?
103 while (($fn = readdir($dh)) !== false) {
104 // do we care that it will try and parse the template directory??? - not really..
105 // as we are only looking for php files..
106 if(empty($fn) || $fn[0] == '.'){
110 $fullpath = $tmp_dir."/".$fn;
111 // echo "filename: ".$fullpath." \n";
113 $relpath = $subdir . (empty($subdir) ? '' : '/') . $fn;
115 if(is_dir($fullpath)){
116 // then recursively call self...
118 // var_Dump($subdir . (empty($subdir) ? '' : '/') . $fn);
119 $this->syncTemplateDir($base, $subdir . (empty($subdir) ? '' : '/') . $fn );
123 if (!preg_match('/(\.html|\.txt)$/', $fn)) {
129 // var_dump($tmp_path);
130 // $fn = basename($fn);
131 if (isset($this->tmpls[$relpath])) {
132 unset($this->tmpls[$relpath]);
138 $template = $this->syncTemplate($relpath, true, false);
139 // var_dump($template);
140 if (is_a($template, 'PEAR_Error')) {
148 foreach($this->tmpls as $id) {
149 $x = DB_DataObject::factory($this->tableName());
160 * sync a single template
161 * This should only be called by the UpdateDatabase code.
162 * @param string $n name of template
163 * @param boolean $force force parsing.
164 * @param string $link ??? related to CMS page???
166 * @return boolean|PEAR_Error errors if compile fails..
170 function syncTemplate($n, $force = false, $link = '')
172 // read the template and extract the translatable strings.
173 ini_set('memory_limit', '512M');
176 $n= ltrim($n,'/'); // remove trailing slash..
178 $fopts = HTML_FlexyFramework::get()->HTML_Template_Flexy;
179 $opts = HTML_FlexyFramework::get()->Pman_Cms;
181 //$dir = $opts['templateDir'] . '/' . $node;
183 $oo['templateDir'] = $opts['templateDir'] ;
184 $oo['compileDir'] = $fopts['compileDir'] . '_translation_files';
185 $oo['forceCompile'] = true; //?? only for force above???
187 $prefix = explode('/', $link);
189 $n_split = explode('/', $n);
190 // this is project specific and should not be put in here..
191 // we need a better way to handle it...
192 // if first part of template dire matches an option in our settings...
194 if (is_array($opts['templateDir']) && strlen($link) && isset($opts['templateDir'][$prefix[0]] )) {
195 //echo "renaming templatedir/file (2)\n";
197 $oo['templateDir'] = $opts['templateDir'][$pf];
202 if (is_array($opts['templateDir']) && count($n_split) > 1 && isset($opts['templateDir'][$n_split[0]] )) {
203 //echo "renaming templatedir/file (2)\n";
205 $oo['templateDir'] = $opts['templateDir'][$pf];
206 $n = substr($n, (strlen($pf)+1));
209 // non-html templates - treat as such..
210 if (!preg_match('/\.html$/i', $n)) {
211 $oo['nonHTML'] = true;
213 ///print_r(array($oo, $n));
216 $flexy = new HTML_Template_Flexy( $oo );
218 $r = $flexy->compile($n);
220 // print_r( $flexy->compiler);
222 //printf(" %0.3fs : $fname<BR>", $time);
223 if (is_a($r,'PEAR_Error')) {
226 //print_R(number_format(memory_get_usage(),0, '.', ',')) ;
227 $words = file_exists($flexy->getTextStringsFile) ?
228 unserialize(file_get_contents($flexy->getTextStringsFile)) :
231 $contentStrings = $flexy->compiler->contentStrings;
233 print_R($contentStrings);
235 if($pf){// support prefix
240 //check the template is static page or not
241 $link_split = explode('/', $link);
242 $is_static = ($link_split[0] == 'Static') ? 1 : 0;
244 $tmpl = DB_DataObject::Factory($this->tableName());
245 if (!$tmpl->get('template', $n)) {
251 $tmpl->template = $nn;
252 $tmpl->lang = 'en'; /// ??? hard coded??
253 $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
257 // has it been cahnged...
258 if (!$force && filemtime($flexy->currentTemplate) == strtotime($tmpl->updated)) {
262 if (empty($tmpl->lang)) {
263 //echo "FIX LANG?";exit;
264 $tmpl->lang = 'en'; /// ??? hard coded??
267 $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
274 if(!empty($link) && empty($is_static)){
276 $page_id = DB_DataObject::factory('core_enum')->lookup('cms_page_type', 'page');
278 $cmsPage = DB_DataObject::factory('cms_page');
279 $cmsPage->setFrom(array(
280 'page_link' => $link,
281 'page_type_id' => $page_id,
282 'translation_of_id' => 0,
286 if(!$cmsPage->find(true)){
287 $cmsPage = DB_DataObject::factory('cms_page');
290 $parent = $cmsPage->parent_id;
293 if (!$parent && strpos($link,'/') !== false) {
294 $par = explode('/', $link);
296 $pname = implode('/', $par);
297 $cmsPageP = DB_DataObject::factory('cms_page');
298 if ($cmsPageP->get('page_link',$pname)) {
299 $parent = $cmsPageP->id;
303 //if not php was found then the page should be a static
304 $php = explode('/', $link);
308 $file = explode('/', $oo['templateDir']);
310 $file = implode('/', $file).'/'.implode('/', $php).'.php';
314 // not sure how this is supposed to work..
315 // if a tempalte exists then static = 0 ??
317 if(preg_match('/\.html$/', $ori_n) && file_exists($file)){
321 // echo "$ori_n <<<< $is_static \n";
322 $run_opts = HTML_FlexyFramework::get()->page->opts;
324 $cmsPage->setFrom(array(
325 'parent_id' => $parent,
326 'page_link' => $link,
327 'title' => basename($link),
328 'page_type_id' => $page_id,
329 'template_id' => $tmpl->id,
331 'translation_of_id' => 0,
332 'is_system_page' => 1,
334 'is_static' => $is_static,
336 //print_r($contentStrings);
338 if (!empty($run_opts['force-content-update']) || !$cmsPage->id) { // only do this for the initila load
339 foreach( array('title', 'body', 'extended') as $prop) {
340 if (isset($contentStrings['{page.'. $prop.'}'])) {
341 $cmsPage->{$prop} = $contentStrings['{page.'. $prop.'}'];
343 if (isset($contentStrings['{page.'. $prop.':h}'])) {
344 $cmsPage->{$prop} = $contentStrings['{page.'. $prop.':h}'];
346 if (isset($contentStrings['{page.'. $prop.'ToDisplayHtml():h}'])) {
347 $cmsPage->{$prop} = $contentStrings['{page.'. $prop.'ToDisplayHtml():h}'];
349 echo "cmrpage->{$prop} = ". $cmsPage->{$prop} ."\n";
362 $x = DB_DataObject::Factory('cms_templatestr');
363 $x->syncTemplateWords($tmpl, $words);
365 // if file_exists ( template/path/name.php << eg. a matching view..)
366 // then create a system page for this.
370 $x = DB_DataObject::Factory('cms_template_element');
371 $x->syncTemplateElement($tmpl, file_get_contents($flexy->currentTemplate), $flexy->compiler->contentStrings, $cmsPage);
377 function syncTemplatePage($pgdata)
380 echo "compiling:"; print_r($pgdata);
381 // read the template and extract the translatable strings.
382 ini_set('memory_limit', '512M');
385 $n= $pgdata['template']; // remove trailing slash..
387 $fopts = HTML_FlexyFramework::get()->HTML_Template_Flexy;
388 $opts = HTML_FlexyFramework::get()->Pman_Cms;
390 //$dir = $opts['templateDir'] . '/' . $node;
392 'disableTranslate' => false,
393 'templateDir' => $pgdata['template_dir'],
394 'compileDir' => $fopts['compileDir'] . '_translation_files',
395 'forceCompile' => true, //?? only for force above???
398 // non-html templates - treat as such..
399 if (!preg_match('/\.html$/i', $pgdata['template'])) {
400 $oo['nonHTML'] = true;
403 //print_r(array($oo, $n));
406 $flexy = new HTML_Template_Flexy( $oo );
408 if (!$flexy->resolvePath ($pgdata['template'])) {
410 echo "SKIP - could not resolve path?\n";
416 $r = $flexy->compile($pgdata['template']);
420 //printf(" %0.3fs : $fname<BR>", $time);
421 if (is_a($r,'PEAR_Error')) {
423 echo $r->toString(). "\n";
426 //print_R(number_format(memory_get_usage(),0, '.', ',')) ;
428 $tmpl = DB_DataObject::Factory($this->tableName());
429 $tmpl->words = file_exists($flexy->getTextStringsFile) ?
430 unserialize(file_get_contents($flexy->getTextStringsFile)) :
433 $tmpl->contentStrings = $flexy->compiler->contentStrings;
434 //var_dump(file_exists($flexy->getTextStringsFile));
435 print_r($tmpl->words);
436 $tmpl->currentTemplate = $flexy->currentTemplate;
438 $tmpl->view_name = $pgdata['base'];
441 if (!$tmpl->get('template', $pgdata['template'])) {
443 $tmpl->template = $pgdata['template'];
444 $tmpl->lang = 'en'; /// ??? hard coded??
445 $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
449 // has it been cahnged...
450 //if (!$force && filemtime($flexy->currentTemplate) == strtotime($tmpl->updated)) {
454 if (empty($tmpl->lang)) {
455 //echo "FIX LANG?";exit;
456 $tmpl->lang = 'en'; /// ??? hard coded??
459 $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
464 $x = DB_DataObject::Factory('cms_templatestr');
465 $x->syncTemplateWords($tmpl);
467 // if file_exists ( template/path/name.php << eg. a matching view..)
468 // then create a system page for this.
472 $x = DB_DataObject::Factory('cms_template_element');
473 $tmpl->elements = $x->syncTemplateElement($tmpl,
474 file_get_contents($flexy->currentTemplate),
475 $flexy->compiler->contentStrings,