3 * Table Definition for core_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_Core_DataObjects_Core_template extends DB_DataObject
15 /* the code below is auto generated do not remove the above tag */
17 public $__table = 'core_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('core_template');
38 //$opts = HTML_FlexyFramework::get()->Pman_Core;
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_Core)) {
72 echo "[ERROR] Not scanning template directory - no set in Pman_Core[templateDir]\n";
75 $opts = $ff->Pman_Core;
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('core_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|\.abw)$/', $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());
157 /* compile a html template
159 * @param template_dir << the path to the template dir ... Pman/XXX/template ...
160 * @param template << name of template used by name field)
161 * @param base << view name (module ? + templates?)
165 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_Core;
180 //$dir = $opts['templateDir'] . '/' . $node;
182 'fatalError' => PEAR_ERROR_EXCEPTION,
183 'disableTranslate' => false,
184 'templateDir' => $pgdata['template_dir'],
185 'compileDir' => $fopts['compileDir'] . '_translation_files',
186 'forceCompile' => true, //?? only for force above???
189 // non-html templates - treat as such..
190 // abiword - treat as html?
191 if (!preg_match('/\.(html|abw)$/i', $pgdata['template'])) {
192 $oo['nonHTML'] = true;
195 //print_r(array($oo, $n));
198 $flexy = new HTML_Template_Flexy( $oo );
200 if (!$flexy->resolvePath ($pgdata['template'])) {
201 //echo "SKIP - could not resolve path?\n"; print_r($oo);
205 // attempt to find the template... record.
206 $tmpl = DB_DataObject::Factory($this->tableName());
208 $tmpl->view_name = $pgdata['base'];
209 if ($tmpl->get('template', $pgdata['template'])) {
210 if (strtotime($tmpl->updated) >= filemtime($flexy->resolvePath ($pgdata['template']))) {
218 $r = $flexy->compile($pgdata['template']);
219 } catch(Exception $e) {
221 $tmpl->updated = date('Y-m-d H:i:s',filemtime($flexy->resolvePath ($pgdata['template'])));
223 $tmpl->update($tmpl);
234 if (is_a($r,'PEAR_Error')) {
236 // echo $r->toString(). "\n";
240 $tmpl = DB_DataObject::Factory($this->tableName());
241 $tmpl->words = file_exists($flexy->getTextStringsFile) ?
242 unserialize(file_get_contents($flexy->getTextStringsFile)) :
245 $tmpl->contentStrings = $flexy->compiler->contentStrings;
246 //var_dump(file_exists($flexy->getTextStringsFile));
247 //print_r($tmpl->words);
248 $tmpl->currentTemplate = $flexy->currentTemplate;
250 $tmpl->view_name = $pgdata['base'];
253 if (!$tmpl->get('template', $pgdata['template'])) {
255 $tmpl->template = $pgdata['template'];
256 $tmpl->lang = 'en'; /// ??? hard coded??
257 $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
261 // has it been cahnged...
262 //if (!$force && filemtime($flexy->currentTemplate) == strtotime($tmpl->updated)) {
266 if (empty($tmpl->lang)) {
267 //echo "FIX LANG?";exit;
268 $tmpl->lang = 'en'; /// ??? hard coded??
271 $tmpl->updated = date('Y-m-d H:i:s', filemtime($flexy->currentTemplate));
276 $x = DB_DataObject::Factory('core_templatestr');
277 $x->syncTemplateWords($tmpl);
279 // if file_exists ( template/path/name.php << eg. a matching view..)
280 // then create a system page for this.
284 $x = DB_DataObject::Factory('core_template_element');
285 $tmpl->elements = $x->syncTemplateElement($tmpl,
286 file_get_contents($flexy->currentTemplate),
287 $flexy->compiler->contentStrings,
295 function syncPhpGetText($pgdata)
297 $tmpl = DB_DataObject::Factory($this->tableName());
298 $tmpl->view_name = $pgdata['base'];
299 $tmpl->currentTemplate = $pgdata['template_dir'] . '/'. $pgdata['template'];
301 if ($tmpl->get('template', $pgdata['template'])) {
302 if (strtotime($tmpl->updated) >= filemtime( $tmpl->currentTemplate )) {
308 $ar = token_get_all(file_get_contents( $tmpl->currentTemplate ));
309 foreach( $ar as $i=> $tok) {
310 if (!is_array($tok) || $tok[0] != T_CONSTANT_ENCAPSED_STRING) {
316 if (is_array($ar[$i-1]) || $ar[$i-1] != '(') {
319 if (!is_array($ar[$i-2]) || $ar[$i-2][1] != '_') {
323 $words[] = str_replace('\\'. $ct, $ct, trim($tok[1] , $ct));
326 // create the template...
331 $tmpl->template = $pgdata['template'];
332 $tmpl->lang = 'en'; /// ??? hard coded??
333 $tmpl->updated = date('Y-m-d H:i:s', filemtime($tmpl->currentTemplate));
338 $tmpl->lang = 'en'; /// ??? hard coded??
339 $tmpl->updated = date('Y-m-d H:i:s', filemtime($tmpl->currentTemplate));
343 $words = array_unique($words);
345 if (!count($words)) {
350 $tmpl->words = $words;
352 $x = DB_DataObject::Factory('core_templatestr');
353 $x->syncTemplateWords($tmpl);