/** * Runs a basic query in the active database. * * User-supplied arguments to the query should be passed in as separate * parameters so that they can be properly escaped to avoid SQL injection * attacks. * * Does not need to override this method in your implementation. * * @param string $query A string containing an SQL query. * @param mixed ... A variable number of arguments which are substituted into the query * using printf() syntax. Instead of a variable number of query arguments, * you may also pass a single array containing the query arguments. * @return result_resource A database query result resource, or FALSE if the query was not * executed correctly. */ function query($query) { if ($this->m_transaction_nesting > 0 && $this->m_transaction_failed === TRUE) { return false; } $args = func_get_args(); array_shift($args); if (isset($args[0]) && is_array($args[0])) { // 'All arguments in one array' syntax $args = $args[0]; } $foo = $this->_getQueryCallbackFunction(); $foo($args, TRUE); $query = preg_replace_callback('/(%d|%s|%%|%f|%b)/', $foo, $query); if (xConf::get('debug', true)) { $this->_dumpAddQuery($query); } $result = $this->_query($query); if ($result === FALSE) { xLog::log('Database', LOG_LEVEL_ERROR, 'Database errno: ' . $this->errno() . '. Error: ' . $this->error(), __FILE__, __LINE__); $this->m_transaction_failed = TRUE; } return $result; }
/** * */ function install() { ob_start(); //select DB if (xConf::get('db_type', 'mysql') == 'mysql') { $db = new xDBMysql(); $db->connect(xConf::get('db_host', ''), xConf::get('db_user', ''), xConf::get('db_pass', ''), xConf::get('db_port', '')); xDB::setDB($db); $name = xConf::get('db_name', ''); $db->query("DROP DATABASE {$name}"); $db->query("CREATE DATABASE {$name}"); $db->selectDB($name); } else { exit('Unknown database type'); } //error handler set_error_handler('xanth_php_error_handler'); $comp = new xModuleManager(); $comp->initModules('engine', 'comp', false, false, array(new xFrameworkComponent())); $comp->invokeAll('xm_install', array($name = xConf::get('db_name', ''))); $comp = new xModuleManager(); $comp->initModules('extensions', 'ext', true, true); $comp->invokeAll('xm_install', array($name = xConf::get('db_name', ''))); //print log echo xLogEntry::renderFromScreen(); echo "Xanthin Successfully installed"; ob_end_flush(); }
/** * Function for logging messages and errors. The log will be added in db (it will be not added * if level is DEBUG and the conf variable "debug" is set to false), a log is shown on screen * if conf variable "display_log" is set to true. If the level is LOG_LEVEL_FATAL_ERROR the * application will die immediately. * * @param string $cathegory The cathegory of the error * @param int $level One of the predefined level constants * - LOG_LEVEL_FATAL_ERROR * - LOG_LEVEL_ERROR * - LOG_LEVEL_WARNING * - LOG_LEVEL_NOTICE * - LOG_LEVEL_DEBUG * @param string $message Description og the log entry * @param string $filename The filename where the log was generated (can use the __FILE__ keyword) * @param string $line The line where the log was generated (can use the __LINE__ keyword) * @static */ function log($cathegory, $level, $message, $filename = '', $line = 0) { //prevent deadlock global $g_in_log; if (isset($g_in_log)) { exit("Fatal Error, contact webmaster (Error: Log Recursion)"); } $g_in_log = true; $log_entry = new xLogEntry(0, $cathegory, $level, $message, $filename, $line, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', $_SERVER['REQUEST_URI'], time(), $_SERVER['REMOTE_ADDR'], NULL); if ($level != LOG_LEVEL_DEBUG || xConf::get('debug', false)) { $log_entry->m_stacktrace = xStackTrace::getCurrent(2); if (xConf::get('display_log', false)) { $log_entry->insertToScreen(); } $log_entry->insert(); } if ($level == LOG_LEVEL_FATAL_ERROR) { exit("Fatal Error, please contact the webmaster"); } $g_in_log = NULL; }
/** * */ function x_full_path($rel_path) { return $_SERVER['DOCUMENT_ROOT'] . '/' . xConf::get('install_path', 'xanthin') . '/' . $rel_path; }