public function output(Pagemill_Data $data, Pagemill_Stream $stream) { Typeframe::Timestamp('Starting debug output'); $debug = new Pagemill_Data(); $timestamps = Typeframe::GetTimestamps(); $tdata = array(); if ($timestamps) { $begin = $timestamps[0]->time(); foreach ($timestamps as $t) { //$dump .= "{$t->action()}: " . ($t->time() - $begin) . "<br/>"; $tdata[] = array('action' => $t->action(), 'time' => $t->time() - $begin); } } $debug['timestamps'] = $tdata; $debug['memory_used'] = memory_get_usage(); $debug['memory_used_real'] = memory_get_usage(true); $debug['includes'] = get_included_files(); $debug['querycount'] = Dbi_Source::QueryCount(); $debug['templates'] = Pagemill::ProcessedTemplates(); // TODO: Get template files $debug['data'] = $data; $this->_recurseTines($debug); $include = new Typeframe_Tag_Include('include', array('template' => '/pagemill/tag/debug.html')); $include->process($debug, $stream); }
public function execute($return = false) { set_error_handler(array($this, '_errorHandler')); if ($return) { ob_start(); } $backups = array(); foreach ($this->_superglobals as $key => $value) { eval('$backups[\'' . $key . '\'] = $_' . $key . ';'); // The $_SERVER superglobal gets merged instead of replaced. if ($key == 'SERVER') { eval('$value = array_merge($_SERVER, $value);'); } eval('$_' . $key . ' = $value;'); } if (isset($this->_superglobals['GET']) || isset($this->_superglobals['POST'])) { $backups['REQUEST'] = $_REQUEST; $_REQUEST = array(); $order = array('_GET', '_POST'); foreach ($order as $var) { eval('$tmp = $' . $var . ';'); foreach ($tmp as $key => $value) { $_REQUEST[$key] = $value; } } } if (!isset($backups['SESSION']) && session_id() == '' && !headers_sent()) { session_start(); } self::$_current[] = $this; $this->_initialize(); self::_Include($this->_controller, $this->_pagemill); if (isset($this->_callbacks[$this->controllerPath()])) { foreach ($this->_callbacks[$this->controllerPath()] as $callback) { call_user_func($callback); } } Typeframe::Timestamp('Scripts and controller executed'); // TODO: Process output (Pagemill template) $selectedTemplate = null; if (is_null($this->_redirectLocation)) { if (is_null($this->_template)) { $selectedTemplate = $this->_resolveTemplate($this->_getDefaultTemplate()); } else { $selectedTemplate = $this->_resolveTemplate($this->_template); } } else { $selectedTemplate = $this->_resolveTemplate('/redirect.html'); if (!$return && !requestIsAjax()) { if ($this->_redirectHeader) { header('Location: ' . $this->_redirectLocation); } if (isset($this->_redirectResponseCode) && !requestIsAjax()) { http_response_code($this->_redirectResponseCode); } } } if ($selectedTemplate) { $pm = Typeframe::Pagemill(); $pm->writeFile($selectedTemplate, false, !isset($_SERVER['SHELL'])); } array_pop(self::$_current); if ($this->_errors) { echo "\n<!--[errors]\n"; foreach ($this->_errors as $error) { echo "{$error}\n"; } echo "[/errors]-->\n"; } foreach ($backups as $key => $value) { eval('$_' . $key . ' = $value;'); } if (!isset($backups['SESSION']) && session_id() != '') { if (TYPEF_WEB_DIR != '') { session_set_cookie_params(ini_get('session.cookie_lifetime'), TYPEF_WEB_DIR); } session_write_close(); } restore_error_handler(); if ($return) { return ob_get_clean(); } }
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('<', '<', $output); $output = str_replace('>', '>', $output); $output = str_replace('&', '&', $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(); }
public function __construct($useCache = true) { // TODO: Temporarily disabling cache //$this->_initializeRegistry(); //return; if ($useCache) { $useCache = $this->_validateCache(); } if (!$useCache) { Typeframe::Timestamp('Loading registry from XML files'); $this->_initializeRegistry(); file_put_contents(TYPEF_DIR . '/files/cache/registry.ser', serialize($this)); @chmod(TYPEF_DIR . '/files/cache/registry.ser', 0666); } else { Typeframe::Timestamp('Loading registry from cache'); $this->_loadCachedRegistry(); } Typeframe::Timestamp('Registry loaded'); }