示例#1
0
文件: Page.dep.php 项目: ssrsfs/blg
 public function execute()
 {
     static $executed = false;
     if (!$executed) {
         $executed = true;
         $this->_executeApplicationCode();
         Typeframe::Timestamp('Controller and triggers executed');
         $selectedTemplate = $this->_template;
         if (!$selectedTemplate && $this->_application->name()) {
             $pathinfo = pathinfo($this->_controller);
             $selectedTemplate = substr($pathinfo['dirname'], strlen(TYPEF_SOURCE_DIR . '/controllers')) . '/' . $pathinfo['filename'] . '.html';
             $finalTemplate = Typeframe::FindTemplate($selectedTemplate);
             if (is_null($finalTemplate)) {
                 $selectedTemplate = null;
             }
         } else {
             $finalTemplate = Typeframe::FindTemplate($selectedTemplate);
         }
         // $selectedTemplate tells us if a template was selected (either explicitly or automatically).
         // $finalTemplate tells us if the template is valid.
         if ($selectedTemplate) {
             if ($finalTemplate) {
                 Typeframe::Timestamp('Starting page render');
                 if ($this->_redirectLocation) {
                     // If there were errors sent to the browser (i.e., output has already started), don't use meta redirect
                     //if ( (headers_sent()) || (ob_get_length()) ) {
                     //	Typeframe::Pagemill()->setVariable("time", 0);
                     //}
                     if (Typeframe::Pagemill()->getVariable('time') == 0 && $_SERVER['REQUEST_METHOD'] == 'POST' && !headers_sent() && !requestIsAjax()) {
                         $_SESSION['typef_redirect_message'] = Typeframe::Pagemill()->getVariable('message');
                     }
                 }
                 $this->_executedTemplate = $finalTemplate;
                 if ($this->_redirectHeader) {
                     if (!headers_sent() && !requestIsAjax()) {
                         header('Location: ' . $this->_redirectLocation, true, $this->_redirectResponseCode);
                     }
                 }
                 Typeframe::Pagemill()->writeFile($finalTemplate);
                 // TODO: Another quick and dirty hack to make JavaScript templates work.
                 /*$pathinfo = pathinfo($selectedTemplate);
                 		switch ($pathinfo['extension']) {
                 			case 'js':
                 				$output = str_replace('&lt;', '<', $output);
                 				$output = str_replace('&gt;', '>', $output);
                 				$output = str_replace('&amp;', '&', $output);
                 		}
                 		echo $output;*/
             } else {
                 trigger_error("Template {$selectedTemplate} not found");
             }
         }
     } else {
         trigger_error("Page controller was already executed");
     }
     if (!$this->_redirectLocation && !requestIsAjax()) {
         unset($_SESSION['typef_redirect_message']);
     }
     session_write_close();
 }