Pman.Dialog.CmsBlog.bjs
[Pman.Cms] / Preview.php
1 <?php
2
3
4 /**
5  * Possibly a base page for general CMS usage..
6  *
7  * -- it's Currently used by the Page Preview code
8  *
9  *
10  *  in theory a general base page would extend this..
11  *  
12  * 
13  */
14 require_once 'Pman.php'; /// needed as we might not be included from pman..
15
16 class Pman_Cms_Preview extends Pman
17 {
18     // page header
19     var $title; 
20     
21     var $keywords;
22     
23     var $descriptions;
24     
25     // body
26     var $page; // the page that is being rendered...
27     
28     // blocks
29     var $block = array(); // the key/object blocks on the page.
30     
31     // home page 
32     var $defaultPage = false;
33     
34     
35     var $content = false; // cms_page object (content);
36     
37     function getAuth()
38     {
39         return false; // no access by default..
40         
41     }
42     
43     
44     function get($path, $opts=array())
45     {
46         die("implement me");
47         
48     }
49     function post($path=false) {
50         die("implement me");
51         
52     }
53     // now all the helper functions
54     
55     /**
56      * load page -- API has changed..
57      *
58      * $this->page= loadPage($name);
59      */
60     
61     function loadPage($prefix, $name, $default = false)
62     {
63         //var_dump($name, $default);
64         
65         
66         $oo = HTML_FlexyFramework::get()->Pman_Cms;
67         $template_prefix = isset($oo['template_prefix']) ? $oo['template_prefix'] : '';
68          
69         // used to load sub elements. of a site..
70         if ($default === false && preg_match('/\*$/', $name)) {
71             $x = DB_DataObject::factory("cms_page");
72             $x->whereAdd("page_link like '" . $x->escape(substr($name,0,-1)) ."%'");
73             foreach($x->fetchAll('page_link') as $pl) {
74                 $this->loadPage($pl, false);
75             }
76             return;
77             
78         }
79         
80         
81         if ($default != false) {
82             
83             $x = DB_DataObject::factory("cms_page");
84             $x->autoJoin();
85             $x->is_element = 0;
86             $x->is_draft = 0;
87             $x->language =  'en'; //$this->bootLoader->locale;
88             
89             if (!$x->get("page_link", $prefix .'/'. $default)) {
90                 die("default page '$default' does not exist");
91             }
92             // load the home page blocks..
93             
94             $blocks = $x->children(array(
95                 'type'=>'named_blocks',
96                 'language' => $this->bootLoader->locale,
97             ));
98             foreach($blocks as $k=>$b) {
99                 $this->block[$k] = $b;
100             }
101             
102             $this->defaultPage = $x->inLanguage($this->bootLoader->locale);
103             $this->defaultPage_en = $x;
104             
105             if ($this->defaultPage_en->id != $this->defaultPage->id) {
106                 $blocks =$this->defaultPage->children(array(
107                     'type'=>'named_blocks',
108                     'language' => $this->bootLoader->locale
109                 ));
110                 foreach($blocks as $k=>$b) {
111                     $this->block[$k] = $b;
112                 }
113                 
114             }
115              
116             
117             
118             
119             
120             
121             
122             
123         }
124         
125         
126         
127         if (empty($name)) {
128             $this->page = $this->defaultPage;
129             $this->page_en = $this->defaultPage_en;
130         } else {
131             $x = DB_DataObject::factory("cms_page");
132             $x->autoJoin();
133             $x->is_element = 0;
134             $x->is_draft = 0;
135             $x->language =  'en';
136             if (!$x->get("page_link", $prefix .'/'. $name)) {
137                 $this->err(404, "$name not found");
138             }
139             
140             $blocks = $x->children(array(
141                 'type'=>'named_blocks',
142                 'language' => $this->bootLoader->locale,
143             ));
144             foreach($blocks as $k=>$b) {
145                 $this->block[$k] = $b;
146             }
147             $this->page_en = $x;
148             $this->page = $x->inLanguage($this->bootLoader->locale);
149             
150             if ($this->page_en->id != $this->page->id) {
151             
152                 $blocks = $this->page->children(array(
153                     'type'=>'named_blocks',
154                     'language' => $this->bootLoader->locale
155                 ));
156                 foreach($blocks as $k=>$b) {
157                     $this->block[$k] = $b;
158                 }
159                  
160                 
161             }
162              
163             
164         }
165         
166         // load all the blocks..
167         $this->assignMeta();
168         $this->template = $this->page_en->template()->template;
169         //var_dump($this->template);
170         
171         // menus????
172         
173          
174     }
175       
176     function assignMeta()
177     {   
178         foreach(array($this->page ,$this->defaultPage) as $argsItem) {
179             if(empty($this->title) && !empty($argsItem->content->title)){
180                 $this->title = ' - ' . $argsItem->title;
181             }
182             if(empty($this->keywords) && !empty($argsItem->keywords)){
183                 $this->keywords =   $argsItem->keywords;
184             }
185             if(empty($this->descriptions) && !empty($argsItem->descriptions)){
186                 $this->descriptions =   $argsItem->descriptions;
187             }
188         }
189     }
190     
191     /*
192     function herr( $error_name, $args = array(), $redirect=false )
193     {
194         
195         if($redirect !== false){
196             $args['errors'][$error_name] = 1;
197             return HTML_FlexyFramework::run($redirect, $args);
198         }
199         
200         $this->errors[$error_name] = 1;
201         
202         $this->elements =  HTML_Template_Flexy_Factory::fromArray($_REQUEST, $this->elements);
203         $this->addEvent('FRONTEND:'.$error_name,  (empty($args['error_on'])) ? false : $args['error_on'], $error_name);
204         
205         return true;
206     }
207     */
208     function err($n, $msg = false)
209     {
210         header("HTTP/1.0 $n Not Found");
211         $this->template = 'error.html';
212         $this->msg = $msg;
213         $this->output();
214         // should we log the referer!!
215         exit;
216     }
217     function errmsg($str)
218     {
219         $this->errors[$str] = 1;
220         return $this->get('');
221     }
222     
223     function redirect($loc)
224     {
225         header('Location: '. $this->baseURL . $loc);
226       
227         exit;
228     }
229     
230     
231     function ellipsis($input, $length) {
232          
233       
234         //no need to trim, already shorter than trim length
235         if (strlen($input) <= $length) {
236             return $input;
237         }
238       
239         //find last space within length
240         $last_space = strrpos(substr($input, 0, $length), ' ');
241         $trimmed_text = substr($input, 0, $last_space);
242       
243         //add ellipses (...)
244          
245          $trimmed_text .= '...';
246         
247       
248         return $trimmed_text;
249           
250     }
251     
252     function eq($a,$b){
253         return $a == $b;
254     }
255     
256     function checkIsAdmin()
257     {
258         if(!$this->authUser){
259             return false;
260         }
261         $x = DB_DataObject::factory('core_company');
262         if($x->get($this->authUser->company_id)){
263             if($x->comptype == 'OWNER'){
264                 return true;
265             }
266             return false;
267         }
268         return false;
269     }
270     function templateClass() {
271         return preg_replace('/[^a-z]+/', '-', preg_replace('/\.html$/', '', strtolower($this->template)));
272         
273     }
274 }
275
276
277