5 * Possibly a base page for general CMS usage..
7 * -- it's Currently used by the Page Preview code
10 * in theory a general base page would extend this..
14 require_once 'Pman.php'; /// needed as we might not be included from pman..
16 class Pman_Cms_Preview extends Pman
26 var $page; // the page that is being rendered...
29 var $block = array(); // the key/object blocks on the page.
32 var $defaultPage = false;
35 var $content = false; // cms_page object (content);
39 return false; // no access by default..
44 function get($path= false)
49 function post($path=false) {
53 // now all the helper functions
56 * load page -- API has changed..
58 * $this->page= loadPage($name);
61 function loadPage($prefix, $name, $default = false)
63 //var_dump($name, $default);
66 $oo = HTML_FlexyFramework::get()->Pman_Cms;
67 $template_prefix = isset($oo['template_prefix']) ? $oo['template_prefix'] : '';
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);
81 if ($default != false) {
83 $x = DB_DataObject::factory("cms_page");
87 $x->language = 'en'; //$this->bootLoader->locale;
89 if (!$x->get("page_link", $prefix .'/'. $default)) {
90 die("default page '$default' does not exist");
92 // load the home page blocks..
94 $blocks = $x->children(array(
95 'type'=>'named_blocks',
96 'language' => $this->bootLoader->locale,
98 foreach($blocks as $k=>$b) {
99 $this->block[$k] = $b;
102 $this->defaultPage = $x->inLanguage($this->bootLoader->locale);
103 $this->defaultPage_en = $x;
105 if ($this->defaultPage_en->id != $this->defaultPage->id) {
106 $blocks =$this->defaultPage->children(array(
107 'type'=>'named_blocks',
108 'language' => $this->bootLoader->locale
110 foreach($blocks as $k=>$b) {
111 $this->block[$k] = $b;
128 $this->page = $this->defaultPage;
129 $this->page_en = $this->defaultPage_en;
131 $x = DB_DataObject::factory("cms_page");
136 if (!$x->get("page_link", $prefix .'/'. $name)) {
138 $this->err(404, "$name not found");
141 $blocks = $x->children(array(
142 'type'=>'named_blocks',
143 'language' => $this->bootLoader->locale,
145 foreach($blocks as $k=>$b) {
146 $this->block[$k] = $b;
149 $this->page = $x->inLanguage($this->bootLoader->locale);
151 if ($this->page_en->id != $this->page->id) {
153 $blocks = $this->page->children(array(
154 'type'=>'named_blocks',
155 'language' => $this->bootLoader->locale
157 foreach($blocks as $k=>$b) {
158 $this->block[$k] = $b;
167 // load all the blocks..
169 $this->template = $this->page_en->template()->template;
170 //var_dump($this->template);
177 function assignMeta()
179 foreach(array($this->page ,$this->defaultPage) as $argsItem) {
180 if(empty($this->title) && !empty($argsItem->content->title)){
181 $this->title = ' - ' . $argsItem->title;
183 if(empty($this->keywords) && !empty($argsItem->keywords)){
184 $this->keywords = $argsItem->keywords;
186 if(empty($this->descriptions) && !empty($argsItem->descriptions)){
187 $this->descriptions = $argsItem->descriptions;
193 function herr( $error_name, $args = array(), $redirect=false )
196 if($redirect !== false){
197 $args['errors'][$error_name] = 1;
198 return HTML_FlexyFramework::run($redirect, $args);
201 $this->errors[$error_name] = 1;
203 $this->elements = HTML_Template_Flexy_Factory::fromArray($_REQUEST, $this->elements);
204 $this->addEvent('FRONTEND:'.$error_name, (empty($args['error_on'])) ? false : $args['error_on'], $error_name);
209 function err($n, $msg = false)
211 header("HTTP/1.0 $n Not Found");
212 $this->template = 'error.html';
215 // should we log the referer!!
218 function errmsg($str)
220 $this->errors[$str] = 1;
221 return $this->get('');
224 function redirect($loc)
226 header('Location: '. $this->baseURL . $loc);
232 function ellipsis($input, $length) {
235 //no need to trim, already shorter than trim length
236 if (strlen($input) <= $length) {
240 //find last space within length
241 $last_space = strrpos(substr($input, 0, $length), ' ');
242 $trimmed_text = substr($input, 0, $last_space);
246 $trimmed_text .= '...';
249 return $trimmed_text;
257 function checkIsAdmin()
259 if(!$this->authUser){
262 $x = DB_DataObject::factory('Companies');
263 if($x->get($this->authUser->company_id)){
264 if($x->comptype == 'OWNER'){
271 function templateClass() {
272 return preg_replace('/[^a-z]+/', '-', preg_replace('/\.html$/', '', strtolower($this->template)));