/** * Log a message to the logger * * @param string $message The message to log * @param string $category [optional] The message category (default "main") * @param integer $level [optional] The loglevel */ public static function log($message, $category = 'main', $level = 1) { if (!self::$_logging_enabled) { return false; } if (self::$_loglevel > $level) { return false; } if (self::$_cli_log_to_screen_in_debug_mode && Context::isCLI() && Context::isDebugMode() && class_exists('\\thebuggenie\\core\\framework\\cli\\Command')) { \thebuggenie\core\framework\cli\Command::cli_echo(mb_strtoupper(self::getLevelName($level)), 'white', 'bold'); \thebuggenie\core\framework\cli\Command::cli_echo(" [{$category}] ", 'green', 'bold'); \thebuggenie\core\framework\cli\Command::cli_echo("{$message}\n"); } if (self::$_logonajaxcalls || Context::getRequest()->isAjaxCall()) { if (self::$_logfile !== null) { file_put_contents(self::$_logfile, mb_strtoupper(self::getLevelName($level)) . " [{$category}] {$message}\n", FILE_APPEND); } $time_msg = Context::isDebugMode() ? ($load_time = Context::getLoadtime()) >= 1 ? round($load_time, 2) . ' seconds' : round($load_time * 1000, 3) . ' ms' : ''; self::$_entries[] = array('category' => $category, 'time' => $time_msg, 'message' => $message, 'level' => $level); self::$_categorized_entries[$category][] = array('time' => $time_msg, 'message' => $message, 'level' => $level); } }
/** * Include a component from a module * * @param string $template * @param array $params */ public static function includeComponent($template, $params = array()) { $debug = Context::isDebugMode(); if ($debug) { $time = explode(' ', microtime()); $pretime = $time[1] + $time[0]; } if (self::doesComponentExist($template, false)) { list($template_name, $actionClass, $actionToRunName) = self::_doesComponentExist($template); foreach ($params as $key => $val) { $actionClass->{$key} = $val; } $actionClass->{$actionToRunName}(); $parameters = $actionClass->getParameterHolder(); } else { $template_name = self::getFinalTemplateName($template); $parameters = $params; } self::presentTemplate($template_name, $parameters); if ($debug) { $time = explode(' ', microtime()); $posttime = $time[1] + $time[0]; Context::visitPartial($template, $posttime - $pretime); } }
/** * Render current headers */ public function renderHeaders() { header("HTTP/1.0 " . $this->_http_status); /* headers to stop caching in browsers and proxies */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // HTTP/1.0 if (Context::isDebugMode()) { header("x-tbg-debugid: " . Context::getDebugID()); $load_time = Context::getLoadTime(); $load_time = $load_time >= 1 ? round($load_time, 2) . 's' : round($load_time * 1000, 1) . 'ms'; header("x-tbg-loadtime: " . $load_time); } if (Context::isI18nInitialized()) { header("Content-Type: " . $this->_content_type . "; charset=" . Context::getI18n()->getCharset()); } else { header("Content-Type: " . $this->_content_type . "; charset=utf-8"); } foreach ($this->_headers as $header) { header($header); } }