/** * * * * **/ public static function getInstance($driver = NULL) { if (!self::$init) { self::init(); } if (!$driver && isset(self::$routine_driver_map[CATMAILER_LIB])) { $driver = self::$routine_driver_map[CATMAILER_LIB]; } if (!$driver) { $driver = 'PHPMailer'; } if (!preg_match('/driver$/i', $driver)) { $driver .= 'Driver'; } // check if the lib is available if (!file_exists(dirname(__FILE__) . '/../../../modules/' . CATMAILER_LIB)) { return false; } if (!isset(self::$_drivers[$driver]) || !is_object(self::$_drivers[$driver])) { if (!file_exists(dirname(__FILE__) . '/Mail/' . $driver . '.php')) { CAT_Object::getInstance()->printFatalError('No such mail driver: [' . $driver . ']'); } require dirname(__FILE__) . '/Mail/' . $driver . '.php'; $driver = 'CAT_Helper_Mail_' . $driver; self::$_drivers[$driver] = $driver::getInstance(self::$settings); } return self::$_drivers[$driver]; }
/** * include/enable HTMLPurifier * * @access private * @param $config - optional config array passed to HTMLPurifier * @return object **/ private static function getPurifier($config = NULL) { if (is_object(self::$purifier)) { return self::$purifier; } if (!class_exists('HTMLPurifier', false)) { $path = CAT_Helper_Directory::getInstance()->sanitizePath(CAT_PATH . '/modules/lib_htmlpurifier/htmlpurifier/library/HTMLPurifier.auto.php'); if (!file_exists($path)) { CAT_Object::getInstance()->printFatalError('Missing library HTMLPurifier!'); } include $path; } $pconfig = HTMLPurifier_Config::createDefault(); if ($config && is_array($config)) { foreach ($config as $key => $val) { $pconfig->set($key, $val); } } $pconfig->set('AutoFormat.Linkify', TRUE); $pconfig->set('URI.Disable', false); // allow most HTML but not all (no forms, for example) $pconfig->set('HTML.Allowed', 'a[href|title],abbr[title],acronym[title],b,blockquote[cite],br,caption,cite,code,dd,del,dfn,div,dl,dt,em,h1,h2,h3,h4,h5,h6,i,img[src|alt|title|class],ins,kbd,li,ol,p,pre,s,strike,strong,sub,sup,table,tbody,td,tfoot,th,thead,tr,tt,u,ul,var'); self::$purifier = new HTMLPurifier($pconfig); return self::$purifier; }
public function __construct($compileDir = null, $cacheDir = null) { parent::__construct($compileDir, $cacheDir); // get current working directory $callstack = debug_backtrace(); $this->workdir = isset($callstack[0]) && isset($callstack[0]['file']) ? realpath(dirname($callstack[0]['file'])) : realpath(dirname(__FILE__)); if (file_exists($this->workdir . '/templates')) { $this->setPath($this->workdir . '/templates'); } }
/** * check a value as type * * @access public * @param mixed $value * @param string $as * @return mixed **/ public static function check($value, $as) { $func = 'is_' . $as; if (!function_exists($func)) { CAT_Object::getInstance()->printFatalError('No such validation method: ' . $as); } if (!$func($value)) { return false; } return $value; }
/** * try to load the driver * * @access private * @param string $driver - driver name * @param string $zipfile - optional zip file name * @return object **/ private static function getDriver($driver, $zipfile = NULL) { if (!preg_match('/driver$/i', $driver)) { $driver .= 'Driver'; } if (!isset(self::$_drivers[$driver]) || !is_object(self::$_drivers[$driver])) { if (!file_exists(dirname(__FILE__) . '/Zip/' . $driver . '.php')) { CAT_Object::getInstance()->printFatalError('No such Zip driver: [' . $driver . ']'); } require dirname(__FILE__) . '/Zip/' . $driver . '.php'; $driver = 'CAT_Helper_Zip_' . $driver; self::$_drivers[$driver] = $driver::getInstance($zipfile); } return self::$_drivers[$driver]; }
/** * private constructor; use getInstance() to load this class **/ public function __construct($options = array()) { parent::__construct($options); if (!isset($options['lang'])) { if (defined('LANGUAGE')) { $options['lang'] = LANGUAGE; } } if (isset($options['lang'])) { self::$_current_lang = $options['lang']; } if (!is_object($this->_path)) { $this->_path = CAT_Helper_Directory::getInstance(); } $this->init(); }
/** * 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."); } }
} 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');
$func = 'wysiwyg'; $type = 'module'; break; case 'template': $pre = 'template_'; $func = 'template'; break; case 'language': $func = 'language'; $pre = 'language_'; break; case 'module': $func = 'page'; break; } $info = array($pre . 'name' => $name, $pre . 'directory' => $dir, $pre . 'type' => $type, $pre . 'function' => $func, $pre . 'description' => $desc, $pre . 'version' => '0.1', $pre . 'platform' => '1.x', $pre . 'author' => $author, $pre . 'guid' => CAT_Object::createGUID(), $pre . 'license' => 'GNU General Public License'); if ($type == 'language') { $info[$pre . 'code'] = $dir; } // create directories if ($type != 'language') { if (!CAT_Helper_Directory::createDirectory($full)) { $message = $backend->lang()->translate('Directory could not be created!'); printResult(); } foreach (array('templates', 'css', 'js') as $sub) { CAT_Helper_Directory::createDirectory($full . '/' . $sub); } if ($type != 'module') { CAT_Helper_Directory::createDirectory($full . '/languages'); }
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); } } ob_start(); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Content-Type: text/html; charset:utf-8;"); $backend = CAT_Backend::getInstance('Settings', 'settings_basic'); $curr_user_is_admin = in_array(1, CAT_Users::getInstance()->get_groups_id()); if (!$curr_user_is_admin) { echo "<div style='border: 2px solid #CC0000; padding: 5px; text-align: center; background-color: #ffbaba;'>You're not allowed to use this function!</div>"; exit; } $settings = array(); $sql = 'SELECT * FROM `' . CAT_TABLE_PREFIX . 'settings` WHERE name="guid"'; if ($res = $backend->db()->query($sql)) { $row = $res->fetchRow(MYSQL_ASSOC); } if (!isset($row['value']) || $row['value'] == '') { @(require_once CAT_PATH . '/framework/CAT/Object.php'); $guid = CAT_Object::createGUID(); $row['setting_id'] = isset($row['setting_id']) ? $row['setting_id'] : NULL; $backend->db()->query('REPLACE INTO `' . CAT_TABLE_PREFIX . 'settings` VALUES("' . $row['setting_id'] . '", "guid", "' . $guid . '")'); } else { $guid = $row['value']; } ob_clean(); echo $guid;
if (count($files)) { foreach ($files as $f) { if (filemtime($f) < time() - 24 * 60 * 60 && filesize($f) == 0) { unlink($f); } } } $files = CAT_Helper_Directory::findFiles('log_\\d{4}-\\d{2}-\\d{2}\\.txt', CAT_PATH . '/temp/logs'); if (count($files)) { foreach ($files as $f) { if (filemtime($f) < time() - 24 * 60 * 60 && filesize($f) == 0) { unlink($f); } } } $widget_name = CAT_Object::lang()->translate('Logfiles'); $current = strftime('%Y-%m-%d'); $logs = array(); $list = array(); $files = CAT_Helper_Directory::getInstance()->maxRecursionDepth(2)->setSuffixFilter(array('txt'))->setSkipDirs(array('cache', 'compiled'))->setSkipFiles(array('index.php'))->findFiles('log_\\d{4}-\\d{2}-\\d{2}\\.txt', CAT_PATH . '/temp'); if (count($files)) { foreach ($files as $f) { if (filesize($f) !== 0) { $list[] = array('file' => $f, 'size' => filesize($f)); } } } if (count($list)) { foreach (array_values($list) as $f) { $file = str_ireplace(CAT_Helper_Directory::sanitizePath(CAT_PATH . '/temp/'), '', CAT_Helper_Directory::sanitizePath($f['file'])); if (substr($file, 0, 1) == "/") {
public function print_success($message, $redirect = 'index.php', $auto_footer = true) { // this sets auto_exit to false, as some WB modules (like Bakery) // have additional code after calling print_success() CAT_Object::printMsg($message, $redirect, $auto_footer, false); }
/** * 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); }
/** * print message * * @access public * @param string $message * @param string $redirect - default 'index.php' * @param boolean $auto_footer - default true **/ public function print_success($message, $redirect = 'index.php', $auto_footer = true) { CAT_Backend::updateWhenModified(); CAT_Object::printMsg($message, $redirect, $auto_footer); }
/** * * @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); }
$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')) {
/** * returns a database connection handle * * This function must be used by all classes, as we plan to replace * the database class in later versions! * * @access public * @return object **/ public function db() { if (!self::$db || !is_object(self::$db)) { if (!CAT_Registry::exists('CAT_PATH', false)) { CAT_Registry::define('CAT_PATH', dirname(__FILE__) . '/../..'); } self::$db = CAT_Helper_DB::getInstance(); } return self::$db; }