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..
15 class Pman_Cms_Preview extends Pman
25 var $page; // the page that is being rendered...
28 var $block = array(); // the key/object blocks on the page.
31 var $defaultPage = false;
34 var $content = false; // cms_page object (content);
38 return false; // no access by default..
43 function get($path= false)
48 function post($path=false) {
52 // now all the helper functions
55 * load page -- API has changed..
57 * $this->page= loadPage($name);
60 function loadPage($name, $default = false)
62 // used to load sub elements. of a site..
63 if ($default == false && preg_match('/\*$/', $name)) {
64 $x = DB_DataObject::factory("cms_page");
65 $x->whereAdd("page_link like '" . $x->escape(substr($name,0,-1)) ."%'");
66 foreach($x->fetchAll('page_link') as $pl) {
67 $this->loadPage($pl, false);
74 if ($default != false) {
76 $x = DB_DataObject::factory("cms_page");
80 if (!$x->get("page_link", $default)) {
81 die("default page '$default' does not exist");
83 // load the home page blocks..
85 $blocks = $x->children(array(
86 'type'=>'named_blocks'
88 foreach($blocks as $k=>$b) {
89 $this->block[$k] = $b;
93 $this->defaultPage = $x;
100 $this->page = $this->defaultPage;
103 $x = DB_DataObject::factory("cms_page");
107 if (!$x->get("page_link", $name)) {
110 $blocks = $x->children(array(
111 'type'=>'named_blocks'
113 foreach($blocks as $k=>$b) {
114 $this->block[$k] = $b;
119 // load all the blocks..
127 function assignMeta()
129 foreach(array($this->content,$this->defaultPage) as $argsItem) {
130 if(empty($this->title) && !empty($argsItem->content->title)){
131 $this->title = ' - ' . $argsItem->title;
133 if(empty($this->keywords) && !empty($argsItem->keywords)){
134 $this->keywords = $argsItem->keywords;
136 if(empty($this->descriptions) && !empty($argsItem->descriptions)){
137 $this->descriptions = $argsItem->descriptions;
143 function herr( $error_name, $args = array(), $redirect=false )
146 if($redirect !== false){
147 $args['errors'][$error_name] = 1;
148 return HTML_FlexyFramework::run($redirect, $args);
151 $this->errors[$error_name] = 1;
153 $this->elements = HTML_Template_Flexy_Factory::fromArray($_REQUEST, $this->elements);
154 $this->addEvent('FRONTEND:'.$error_name, (empty($args['error_on'])) ? false : $args['error_on'], $error_name);
159 function err($n, $msg = false)
161 header("HTTP/1.0 $n Not Found");
162 $this->template = 'error.html';
165 // should we log the referer!!
168 function errmsg($str)
170 $this->errors[$str] = 1;
171 return $this->get('');
174 function redirect($loc)
176 header('Location: '. $this->baseURL . $loc);
182 function ellipsis($input, $length) {
185 //no need to trim, already shorter than trim length
186 if (strlen($input) <= $length) {
190 //find last space within length
191 $last_space = strrpos(substr($input, 0, $length), ' ');
192 $trimmed_text = substr($input, 0, $last_space);
196 $trimmed_text .= '...';
199 return $trimmed_text;
208 function checkIsAdmin()
210 if(!$this->authUser){
213 $x = DB_DataObject::factory('Companies');
214 if($x->get($this->authUser->company_id)){
215 if($x->comptype == 'OWNER'){
222 function templateClass() {
223 return preg_replace('/[^a-z]+/', '-', preg_replace('/\.html$/', '', strtolower($this->template)));