Preview.php
[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         echo $p->jsource;
45         exit;
46     }
47     
48     function outputBody()
49     {
50         
51         
52         $proj = HTML_FlexyFramework::get()->project;
53         // DB_DataObject::debugLevel(1);
54         $m = DB_DAtaObject::factory('Builder_modules');
55         $m->get('name', $proj );
56         
57         print_R($m->path);
58         print_R($this->template);
59         // needs to modify the template directory??
60         // use the builder_module == app name
61         // look for part with same name.
62         $template_engine = new HTML_Template_Flexy(array(
63             'templateDir' => $m->path
64         ));
65         $template_engine->compile($this->template);
66         if ($this->elements) { /* BC crap! */
67             $this->elements = HTML_Template_Flexy_Factory::setErrors($this->elements,$this->errors);
68         }
69         $template_engine->elements = $this->elements;
70         $template_engine->outputObject($this,$this->elements);
71         
72         
73         
74     }
75 }