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 require_once 'Pman/Core/DataObjects/Core_template.php';
12 class Pman_Cms_DataObjects_Cms_template extends Pman_Core_DataObjects_Core_template
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 return DB_DataObject::factory('cms_templatestr');
65 * ?? is this still used - code is in updateTemplateBJS?
66 * @param base (should be full path to template directory)
67 * @param subdir = empty for top or subpath.
69 function syncTemplateDir($base = false, $subdir = '', $force = false)
71 echo "syncTemplateDir: $base , $subdir, $force \n";
72 //print_r(func_get_args());
74 $ff = HTML_FlexyFramework::get();
75 if (!isset($ff->Pman_Cms)) {
76 echo "[ERROR] Not scanning template directory - no set in Pman_Cms[templateDir]\n";
79 $opts = $ff->Pman_Cms;
80 if (is_array($opts['templateDir'])) {
81 foreach($opts['templateDir'] as $type=>$dir) {
82 $this->syncTemplateDir($dir, '', $force);
87 $base = $opts['templateDir'];
92 $tmpls = DB_DataObject::factory('cms_template');
93 $this->tmpls = $tmpls->fetchAll('template','id'); // dupes??
96 $tmp_dir = $base . (empty($subdir) ? '' : '/') . $subdir;
98 if(!is_dir($tmp_dir)){
102 $dh = opendir($tmp_dir);
104 return; // something went wrong!?
107 while (($fn = readdir($dh)) !== false) {
108 // do we care that it will try and parse the template directory??? - not really..
109 // as we are only looking for php files..
110 if(empty($fn) || $fn[0] == '.'){
114 $fullpath = $tmp_dir."/".$fn;
115 // echo "filename: ".$fullpath." \n";
117 $relpath = $subdir . (empty($subdir) ? '' : '/') . $fn;
119 if(is_dir($fullpath)){
120 // then recursively call self...
122 // var_Dump($subdir . (empty($subdir) ? '' : '/') . $fn);
123 $this->syncTemplateDir($base, $subdir . (empty($subdir) ? '' : '/') . $fn );
127 if (!preg_match('/(\.html|\.txt)$/', $fn)) {
133 // var_dump($tmp_path);
134 // $fn = basename($fn);
135 if (isset($this->tmpls[$relpath])) {
136 unset($this->tmpls[$relpath]);
142 $template = $this->syncTemplate($relpath, true, false);
143 // var_dump($template);
144 if (is_a($template, 'PEAR_Error')) {
152 foreach($this->tmpls as $id) {
153 $x = DB_DataObject::factory($this->tableName());
163 * ?? code is in UpdateBJS?
167 function syncTemplatePage($pgdata)
170 echo "compiling:"; print_r($pgdata);
171 // read the template and extract the translatable strings.
172 ini_set('memory_limit', '512M');
175 $n= $pgdata['template']; // remove trailing slash..
177 $fopts = HTML_FlexyFramework::get()->HTML_Template_Flexy;
178 $opts = HTML_FlexyFramework::get()->Pman_Cms;
180 //$dir = $opts['templateDir'] . '/' . $node;
182 'disableTranslate' => false,
183 'templateDir' => $pgdata['template_dir'],
184 'compileDir' => $fopts['compileDir'] . '_translation_files',
185 'forceCompile' => true, //?? only for force above???
188 // non-html templates - treat as such..
189 if (!preg_match('/\.html$/i', $pgdata['template'])) {
190 $oo['nonHTML'] = true;
193 //print_r(array($oo, $n));
196 $flexy = new HTML_Template_Flexy( $oo );
198 if (!$flexy->resolvePath ($pgdata['template'])) {
200 echo "SKIP - could not resolve path?\n";
206 $r = $flexy->compile($pgdata['template']);
210 //printf(" %0.3fs : $fname<BR>", $time);
211 if (is_a($r,'PEAR_Error')) {
213 echo $r->toString(). "\n";
216 //print_R(number_format(memory_get_usage(),0, '.', ',')) ;
218 $tmpl = DB_DataObject::Factory($this->tableName());
219 $tmpl->words = file_exists($flexy->getTextStringsFile) ?
220 unserialize(file_get_contents($flexy->getTextStringsFile)) :
223 $tmpl->contentStrings = $flexy->compiler->contentStrings;
224 //var_dump(file_exists($flexy->getTextStringsFile));
225 print_r($tmpl->words);
226 $tmpl->currentTemplate = $flexy->currentTemplate;
228 $tmpl->view_name = $pgdata['base'];
231 if (!$tmpl->get('template', $pgdata['template'])) {
233 $tmpl->template = $pgdata['template'];
234 $tmpl->lang = 'en'; /// ??? hard coded??
235 $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
239 // has it been cahnged...
240 //if (!$force && filemtime($flexy->currentTemplate) == strtotime($tmpl->updated)) {
244 if (empty($tmpl->lang)) {
245 //echo "FIX LANG?";exit;
246 $tmpl->lang = 'en'; /// ??? hard coded??
249 $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
254 $x = DB_DataObject::Factory('cms_templatestr');
255 $x->syncTemplateWords($tmpl);
257 // if file_exists ( template/path/name.php << eg. a matching view..)
258 // then create a system page for this.
262 $x = DB_DataObject::Factory('cms_template_element');
263 $tmpl->elements = $x->syncTemplateElement($tmpl,
264 file_get_contents($flexy->currentTemplate),
265 $flexy->compiler->contentStrings,