php7 fixes
[Pman.Builder] / Preview.php
1 <?php
2 /**
3  * extends the CMS preview  - but should take the template from the builder..
4  * intended use is with the bootstrap code HTML generated..
5  *
6 */
7 require_once 'Pman/Cms/Preview.php';
8
9 class Pman_Builder_Preview extends Pman_Cms_Preview
10 {
11     
12     
13     function loadPage($prefix, $name, $default = false)
14     {
15         
16         if (preg_match('/^BuilderJS/', $name)) {
17             $this->outputJS(preg_replace('#^BuilderJS/#','', $name));
18             
19         }
20         //var_dump($name, $default);
21         //DB_DataObject::debugLevel(5);
22         parent::loadPage($prefix, $name, $default );
23         
24         
25         // template...
26         
27         // menus????
28         
29          
30     }
31     
32     function outputJS($name)
33     {
34         $proj = HTML_FlexyFramework::get()->project;
35         // DB_DataObject::debugLevel(1);
36         $m = DB_DAtaObject::factory('Builder_modules');
37         $m->get('name', $proj );
38         $p = DB_DAtaObject::factory('Builder_part');
39         $p->module_id = $m->pid();
40         if (!$p->get('name', $name )) {
41            die("invalid url");
42         }
43         header('Content-type: text/javascript');
44         // this should outpt the file if it's found.
45         if (file_exists($m->path . '/'. $p->name .'.js')) {
46             $fh = fopen($m->path . '/'. $p->name .'.js', 'r');
47             fpassthru($fh);
48             exit;
49         }
50         
51         echo $p->jsource;
52         exit;
53     }
54     
55     function outputBody()
56     {
57         
58         if ($this->timer) {
59             $this->timer->setMarker(__CLASS__ . '::outputBody - start');
60         }
61         $ff = HTML_FlexyFramework::get();
62         
63         
64         $proj = $ff->project;
65         // DB_DataObject::debugLevel(1);
66         $m = DB_DAtaObject::factory('Builder_modules');
67         $m->get('name', $proj );
68         
69         //var_dump($m->path);exit;
70         // needs to modify the template directory??
71         // use the builder_module == app name
72         // look for part with same name.
73         if (empty($ff->Pman_Builder['from_filesystem'])) {
74             
75             $template_engine = new HTML_Template_Flexy(array(
76                 'templateDir' => $m->path
77             ));
78         } else {
79             $template_engine = new HTML_Template_Flexy();
80         }
81         
82         $template_engine->debug = 1;
83         //print_R($template_engine);
84         
85         $template_engine->compile($this->template);
86         if ($this->elements) { /* BC crap! */
87             $this->elements = HTML_Template_Flexy_Factory::setErrors($this->elements,$this->errors);
88         }
89         $template_engine->elements = $this->elements;
90         if ($this->timer) {
91             $this->timer->setMarker(__CLASS__ . '::outputBody - render template');
92         }
93         //DB_DataObject::debugLevel(1);
94         $template_engine->outputObject($this,$this->elements);
95         
96         if ($this->timer) {
97             $this->timer->setMarker(__CLASS__ . '::outputBody - end');
98         }
99         
100     }
101 }