public function fetchBody() { // If there is set to be no system content, don't even bother with anything here! if ($this->mode == View::MODE_NOOUTPUT) { return null; } // Was this called before? if($this->_bodyCache !== null){ return $this->_bodyCache; } // Resolve the template based on the error code. (if present) if ($this->error != View::ERROR_NOERROR && !$this->allowerrors) { // Update some information in the view. // Transpose some useful data for it. //$view->baseurl = '/Error/Error' . $view->error; //$view->setParameters(array()); $tmpl = '/pages/error/error' . $this->error . '.tpl'; //$mastertmpl = ConfigHandler::Get('/theme/default_template'); } else { $tmpl = $this->templatename; //$mastertmpl = } // If the content type is set to something other that html, check if that template exists. switch ($this->contenttype) { case View::CTYPE_XML: // Already resolved? if (strpos($tmpl, ROOT_PDIR) === 0 && strpos($tmpl, '.xml.tpl') !== false) { $this->mastertemplate = false; } else { $ctemp = Core\Templates\Template::ResolveFile(preg_replace('/tpl$/i', 'xml.tpl', $tmpl)); if ($ctemp) { $tmpl = $ctemp; $this->mastertemplate = false; } else { $this->contenttype = View::CTYPE_HTML; } } break; case View::CTYPE_ICS: // Already resolved? if(strpos($tmpl, ROOT_PDIR) === 0 && strpos($tmpl, '.ics.tpl') !== false){ $this->mastertemplate = false; } else{ $ctemp = Core\Templates\Template::ResolveFile(preg_replace('/tpl$/i', 'ics.tpl', $tmpl)); if($ctemp){ $tmpl = $ctemp; $this->mastertemplate = false; } else{ $this->contenttype = View::CTYPE_HTML; } } // TESTING //$this->contenttype = View::CTYPE_HTML; break; case View::CTYPE_JSON: // Did the controller send data to this view directly? // (because JSON supports raw data ^_^ ) if ($this->jsondata !== null) { $this->mastertemplate = false; $tmpl = false; return json_encode($this->jsondata); } $ctemp = Core\Templates\Template::ResolveFile(preg_replace('/tpl$/i', 'json.tpl', $tmpl)); if ($ctemp) { $tmpl = $ctemp; $this->mastertemplate = false; } else { $this->contenttype = View::CTYPE_HTML; } break; } if (!$tmpl && $this->templatename == '') { throw new Exception('Please set the variable "templatename" on the page view.'); } switch ($this->mode) { case View::MODE_PAGE: case View::MODE_AJAX: case View::MODE_PAGEORAJAX: case View::MODE_EMAILORPRINT: $t = $this->getTemplate(); $html = $t->fetch($tmpl); // Retrieve any/all JS, CSS, and Meta elements from that widget's View and transpose them here! // This is because now that View operations now correctly manipulate the View directly attached to the template, // the top-level page view no longer gets these directives. if($this->parent){ $this->parent->_syncFromView($this); } break; case View::MODE_WIDGET: // This template can be a couple things. $tn = Core\Templates\Template::ResolveFile(preg_replace(':^[/]{0,1}pages/:', '/widgets/', $tmpl)); if (!$tn) $tn = $tmpl; $t = $this->getTemplate(); $html = $t->fetch($tn); // Retrieve any/all JS, CSS, and Meta elements from that widget's View and transpose them here! // This is because now that View operations now correctly manipulate the View directly attached to the template, // the top-level page view no longer gets these directives. if($this->parent){ $this->parent->_syncFromView($this); } break; } // Save this HTML in local cache $this->_bodyCache = $html; return $html; }