/** * exception handler; allows to remove paths from error messages and show * optional stack trace **/ public static function exceptionHandler($exception) { $exc_class = get_class($exception); try { $logger = CAT_Helper_KLogger::instance(CAT_PATH . '/temp/logs', 2); $logger->logFatal(sprintf('Exception with message [%s] emitted in [%s] line [%s]', $exception->getMessage(), $exception->getFile(), $exception->getLine())); } catch (Exception $e) { } if (isset($exc_class::$exc_trace) && $exc_class::$exc_trace === true) { $traceline = "#%s %s(%s): %s(%s)"; $msg = "Uncaught exception '%s' with message '%s'<br />" . "<div style=\"font-size:smaller;width:80%%;margin:5px auto;text-align:left;\">" . "in %s:%s<br />Stack trace:<br />%s<br />" . "thrown in %s on line %s</div>"; $trace = $exception->getTrace(); foreach ($trace as $key => $stackPoint) { $trace[$key]['args'] = array_map('gettype', $trace[$key]['args']); } // build tracelines $result = array(); foreach ($trace as $key => $stackPoint) { $result[] = sprintf($traceline, $key, isset($stackPoint['file']) ? $stackPoint['file'] : '-', isset($stackPoint['line']) ? $stackPoint['line'] : '-', $stackPoint['function'], implode(', ', $stackPoint['args'])); } // trace always ends with {main} $result[] = '#' . ++$key . ' {main}'; // write tracelines into main template $msg = sprintf($msg, get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), implode("<br />", $result), $exception->getFile(), $exception->getLine()); } else { // filter message $message = $exception->getMessage(); $message = str_replace(array(CAT_Helper_Directory::sanitizePath(CAT_PATH), str_replace('/', '\\', CAT_Helper_Directory::sanitizePath(CAT_PATH))), array('[path to]', '[path to]'), $message); $msg = "[{$exc_class}] {$message}"; } // log $logger->logFatal($msg); // show detailed error information to admin only if (CAT_Users::is_authenticated() && CAT_Users::is_root()) { CAT_Object::printFatalError($msg); } else { CAT_Object::printFatalError("An internal error occured. We're sorry for inconvenience."); } }
/** * * @access public * @return **/ public function findTemplate($_tpl) { // cached if (isset($this->seen[$this->te->paths['current'] . $_tpl])) { return $this->seen[$this->te->paths['current'] . $_tpl]; } $suffix = pathinfo($_tpl, PATHINFO_EXTENSION); $has_suffix = $suffix != '' ? true : false; // scan search paths (if any) $paths = array(); $s_paths = $this->te->paths; // sort paths by key; this sets 'workdir' to the end of the array ksort($s_paths); // move 'current' to begin $temp = array('current' => $s_paths['current']); unset($s_paths['current']); $s_paths = $temp + $s_paths; foreach ($s_paths as $key => $value) { if (isset($s_paths[$key]) && file_exists($s_paths[$key])) { $paths[] = $value; } } // remove doubles $paths = array_unique($paths); $this->log()->logDebug('template search paths:', $paths); // (re-)set suffix filter $this->dirh->setSuffixFilter(array('tpl', 'htt', 'lte')); foreach ($paths as $dir) { if ($has_suffix && file_exists($dir . '/' . $_tpl)) { $file = $dir . '/' . $_tpl; } else { $file = $this->dirh->findFile($_tpl, $dir, true); } if ($file) { $this->seen[$this->te->paths['current'] . $_tpl] = $file; return $file; } } $this->log()->logCrit("The template [{$_tpl}] does not exist in one of the possible template paths!", $paths); // the template does not exists, so at least prompt an error $br = "\n"; CAT_Object::printFatalError("Unable to render the page", NULL, true, $paths); }
} else { $root = "../"; $level = 1; while ($level < 10 && !file_exists($root . '/framework/class.secure.php')) { $root .= "../"; $level += 1; } if (file_exists($root . '/framework/class.secure.php')) { include $root . '/framework/class.secure.php'; } else { trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR); } } if (!file_exists(CAT_PATH . '/modules/' . SEARCH_LIBRARY . '/library.php')) { $page_id = CAT_Helper_Validate::get('_REQUEST', 'page_id'); CAT_Object::printFatalError(CAT_Object::lang()->translate('No search library installed!'), CAT_Helper_Page::getLink($page_id)); } // Required page details $page_id = -1; $page_description = ''; $page_keywords = ''; // load search library require_once CAT_PATH . '/modules/' . SEARCH_LIBRARY . '/library.php'; $s = new CATSearch(); $page_id = $s->getSearchPageID(); // load droplets extensions $h = CAT_Helper_Droplet::getInstance(); $h->register_droplet_css('SearchBox', $page_id, '/modules/' . SEARCH_LIBRARY . '/templates/default/', 'search.box.css'); $h->register_droplet_js('SearchBox', $page_id, '/modules/' . SEARCH_LIBRARY . '/templates/default/', 'search.box.js'); if (isset($_GET['string'])) { CAT_Helper_Page::addCSS(CAT_URL . '/modules/' . SEARCH_LIBRARY . '/templates/default/frontend.css');
$value = $row['value']; } elseif (preg_match('/^[0-9]+$/S', $row['value']) == true) { $value = intval($row['value']); } elseif ($row['value'] == 'false') { $value = false; } elseif ($row['value'] == 'true') { $value = true; } else { $value = $row['value']; } $temp_name = strtoupper($row['name']); CAT_Registry::register($temp_name, $value, true, true); } unset($row); } else { CAT_Object::printFatalError("No settings found in the database, please check your installation!"); } //************************************************************************** // moved from ./backend/interface/er_levels.php //************************************************************************** CAT_Registry::register('ER_LEVELS', array('System Default', '6135' => 'E_ALL^E_NOTICE', '0' => 'E_NONE', '6143' => 'E_ALL', '8191' => htmlentities('E_ALL&E_STRICT'))); //************************************************************************** //************************************************************************** $string_file_mode = STRING_FILE_MODE; CAT_Registry::register('OCTAL_FILE_MODE', (int) octdec($string_file_mode), true); $string_dir_mode = STRING_DIR_MODE; CAT_Registry::register('OCTAL_DIR_MODE', (int) octdec($string_dir_mode), true); //************************************************************************** // get CAPTCHA and ASP settings //************************************************************************** if (!defined('CAT_INSTALL_PROCESS')) {
/** * exception handler; allows to remove paths from error messages and show * optional stack trace if CAT_Helper_DB::$trace is true **/ public static function exceptionHandler($exception) { if (CAT_Helper_DB::$exc_trace === true) { $traceline = "#%s %s(%s): %s(%s)"; $msg = "Uncaught exception '%s' with message '%s'<br />" . "<div style=\"font-size:smaller;width:80%%;margin:5px auto;text-align:left;\">" . "in %s:%s<br />Stack trace:<br />%s<br />" . "thrown in %s on line %s</div>"; $trace = $exception->getTrace(); foreach ($trace as $key => $stackPoint) { $trace[$key]['args'] = array_map('gettype', $trace[$key]['args']); } // build tracelines $result = array(); foreach ($trace as $key => $stackPoint) { $result[] = sprintf($traceline, $key, isset($stackPoint['file']) ? $stackPoint['file'] : '-', isset($stackPoint['line']) ? $stackPoint['line'] : '-', $stackPoint['function'], implode(', ', $stackPoint['args'])); } // trace always ends with {main} $result[] = '#' . ++$key . ' {main}'; // write tracelines into main template $msg = sprintf($msg, get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), implode("<br />", $result), $exception->getFile(), $exception->getLine()); } else { // template $msg = "[DB Exception] %s<br />"; // filter message $message = $exception->getMessage(); preg_match('~SQLSTATE\\[[^\\]].+?\\]\\s+\\[[^\\]].+?\\]\\s+(.*)~i', $message, $match); $msg = sprintf($msg, isset($match[1]) ? $match[1] : $message); } try { $logger = CAT_Helper_KLogger::instance(CAT_PATH . '/temp/logs', 2); $logger->logFatal(sprintf('Exception with message [%s] emitted in [%s] line [%s]', $exception->getMessage(), $exception->getFile(), $exception->getLine())); $logger->logFatal($msg); } catch (Exception $e) { } // log or echo as you please CAT_Object::printFatalError($msg); }