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, $opts=array())
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)) {
137 $this->err(404, "$name not found");
140 $blocks = $x->children(array(
141 'type'=>'named_blocks',
142 'language' => $this->bootLoader->locale,
144 foreach($blocks as $k=>$b) {
145 $this->block[$k] = $b;
148 $this->page = $x->inLanguage($this->bootLoader->locale);
150 if ($this->page_en->id != $this->page->id) {
152 $blocks = $this->page->children(array(
153 'type'=>'named_blocks',
154 'language' => $this->bootLoader->locale
156 foreach($blocks as $k=>$b) {
157 $this->block[$k] = $b;
166 // load all the blocks..
168 $this->template = $this->page_en->template()->template;
169 //var_dump($this->template);
176 function assignMeta()
178 foreach(array($this->page ,$this->defaultPage) as $argsItem) {
179 if(empty($this->title) && !empty($argsItem->content->title)){
180 $this->title = ' - ' . $argsItem->title;
182 if(empty($this->keywords) && !empty($argsItem->keywords)){
183 $this->keywords = $argsItem->keywords;
185 if(empty($this->descriptions) && !empty($argsItem->descriptions)){
186 $this->descriptions = $argsItem->descriptions;
192 function herr( $error_name, $args = array(), $redirect=false )
195 if($redirect !== false){
196 $args['errors'][$error_name] = 1;
197 return HTML_FlexyFramework::run($redirect, $args);
200 $this->errors[$error_name] = 1;
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);
208 function err($n, $msg = false)
210 header("HTTP/1.0 $n Not Found");
211 $this->template = 'error.html';
214 // should we log the referer!!
217 function errmsg($str)
219 $this->errors[$str] = 1;
220 return $this->get('');
223 function redirect($loc)
225 header('Location: '. $this->baseURL . $loc);
231 function ellipsis($input, $length) {
234 //no need to trim, already shorter than trim length
235 if (strlen($input) <= $length) {
239 //find last space within length
240 $last_space = strrpos(substr($input, 0, $length), ' ');
241 $trimmed_text = substr($input, 0, $last_space);
245 $trimmed_text .= '...';
248 return $trimmed_text;
256 function checkIsAdmin()
258 if(!$this->authUser){
261 $x = DB_DataObject::factory('core_company');
262 if($x->get($this->authUser->company_id)){
263 if($x->comptype == 'OWNER'){
270 function templateClass() {
271 return preg_replace('/[^a-z]+/', '-', preg_replace('/\.html$/', '', strtolower($this->template)));