/** * Show PHP-Fusion Performance * @param bool $queries * @return string */ function showrendertime($queries = TRUE) { global $mysql_queries_count; $locale = array(); include LOCALE . LOCALESET . "global.php"; $db = DatabaseFactory::getConnection(); if ($db) { $mysql_queries_count = $db->getGlobalQueryCount(); } if (fusion_get_settings('rendertime_enabled') == 1 || fusion_get_settings('rendertime_enabled') == 2 && iADMIN) { $render_time = substr(microtime(TRUE) - START_TIME, 0, 7); $_SESSION['performance'][] = $render_time; if (count($_SESSION['performance']) > 5) { array_shift($_SESSION['performance']); } $average_speed = $render_time; $diff = 0; if (isset($_SESSION['performance'])) { $average_speed = substr(array_sum($_SESSION['performance']) / count($_SESSION['performance']), 0, 7); $previous_render = array_values(array_slice($_SESSION['performance'], -2, 1, TRUE)); $diff = $render_time - (!empty($previous_render) ? $previous_render[0] : 0); } $res = sprintf($locale['global_172'], $render_time) . " | " . sprintf($locale['global_175'], $average_speed . " ({$diff})"); $res .= $queries ? " | " . ucfirst($locale['global_173']) . ": {$mysql_queries_count}" : ""; return $res; } else { return ""; } }
function setError($error_level, $error_message, $error_file, $error_line, $error_context) { global $userdata, $_errorHandler; $showError = TRUE; $db = DatabaseFactory::getConnection(); $result = $db->query("SELECT error_id, error_status FROM " . DB_ERRORS . "\n\t\tWHERE error_message = :message AND error_file = :file AND error_line = :line AND error_status != '1'\n\t\tORDER BY error_timestamp DESC LIMIT 1", array(':message' => $error_message, ':file' => $error_file, ':line' => $error_line)); if ($db->countRows($result) == 0) { $db->query("INSERT INTO " . DB_ERRORS . " (\n\t\t\t\terror_level, error_message, error_file, error_line, error_page,\n\t\t\t\terror_user_level, error_user_ip, error_user_ip_type, error_status, error_timestamp\n\t\t\t) VALUES (\n\t\t\t\t:level, :message, :file, :line,\n\t\t\t\t'" . TRUE_PHP_SELF . "', '" . $userdata['user_level'] . "', '" . USER_IP . "', '" . USER_IP_TYPE . "',\n\t\t\t\t'0', '" . time() . "'\n\t\t\t)", array(':level' => $error_level, ':message' => $error_message, ':file' => $error_file, ':line' => $error_line)); $errorId = $db->getLastId(); } else { $data = $db->fetchAssoc($result); $errorId = $data['error_id']; if ($data['error_status'] == 2) { $showError = FALSE; } } if ($showError) { $_errorHandler[] = array("id" => $errorId, "level" => $error_level, "file" => $error_file, "line" => $error_line); } }
/** * Custom error handler for PHP processor * @param $error_level * @param $error_message * @param $error_file * @param $error_line * @param $error_context */ public function setError($error_level, $error_message, $error_file, $error_line, $error_context) { global $userdata; $showLiveError = TRUE; // directly show error - push to another instance $data = array(); $db = DatabaseFactory::getConnection(); $result = $db->query("SELECT error_id, error_status FROM " . DB_ERRORS . "\n WHERE error_message = :message AND error_file = :file AND error_line = :line AND error_status != '1' AND error_page = :page\n ORDER BY error_timestamp DESC LIMIT 1", array(':message' => $error_message, ':file' => $error_file, ':page' => FUSION_REQUEST, ':line' => $error_line)); if ($db->countRows($result) == 0) { $db->query("INSERT INTO " . DB_ERRORS . " (\n\t\t\t\terror_level, error_message, error_file, error_line, error_page,\n\t\t\t\terror_user_level, error_user_ip, error_user_ip_type, error_status, error_timestamp\n\t\t\t) VALUES (\n\t\t\t\t:level, :message, :file, :line, :page,\n\t\t\t\t'" . $userdata['user_level'] . "', '" . USER_IP . "', '" . USER_IP_TYPE . "',\n\t\t\t\t'0', '" . time() . "'\n\t\t\t)", array(':level' => $error_level, ':message' => $error_message, ':file' => $error_file, ':page' => FUSION_REQUEST, ':line' => $error_line)); $errorId = $db->getLastId(); } else { $data = $db->fetchAssoc($result); $errorId = $data['error_id']; if ($data['error_status'] == 2) { $showLiveError = FALSE; } } if ($showLiveError) { $this->new_errors[$errorId] = array("error_id" => $errorId, "error_level" => $error_level, "error_file" => $error_file, "error_line" => $error_line, "error_page" => FUSION_REQUEST, "error_message" => $error_message, "error_timestamp" => time(), "error_status" => 0); } }
if (file_exists(BASEDIR . 'config.php')) { include BASEDIR . 'config.php'; } elseif (file_exists(BASEDIR . 'config_temp.php')) { include BASEDIR . 'config_temp.php'; } if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') === 'POST') { $pdo_enabled = (bool) intval($pdo_enabled); $db_host = (string) (stripinput(trim(filter_input(INPUT_POST, 'db_host'))) ?: $db_host); $db_user = (string) (stripinput(trim(filter_input(INPUT_POST, 'db_user'))) ?: $db_user); $db_pass = (string) (stripinput(filter_input(INPUT_POST, 'db_pass')) ?: $db_pass); $db_name = (string) (stripinput(trim(filter_input(INPUT_POST, 'db_name'))) ?: $db_name); $db_prefix = (string) (stripinput(trim(filter_input(INPUT_POST, 'db_prefix'))) ?: $db_prefix); } $locale_files = makefilelist("../locale/", ".svn|.|..", TRUE, "folders"); include_once INCLUDES . "dynamics/dynamics.inc.php"; DatabaseFactory::setDefaultDriver(intval($pdo_enabled) === 1 ? DatabaseFactory::DRIVER_PDO_MYSQL : DatabaseFactory::DRIVER_MYSQL); require_once INCLUDES . "db_handlers/all_functions_include.php"; if (defined('DB_PREFIX')) { require_once INCLUDES . 'multisite_include.php'; dbconnect($db_host, $db_user, $db_pass, $db_name, FALSE); } $settings = fusion_get_settings(); if ($settings) { $userdata = Authenticate::validateAuthUser(); if (INSTALLATION_STEP != 8 and dbresult(dbquery('SELECT exists(SELECT * FROM ' . DB_PREFIX . 'users)'), 0) and intval($userdata['user_level']) !== USER_LEVEL_SUPER_ADMIN) { // TODO: handle this case better way exit('You are not superadmin.'); } } $localeset = filter_input(INPUT_GET, 'localeset') ?: (isset($settings['locale']) ? $settings['locale'] : 'English'); define('LANGUAGE', is_dir(LOCALE . $localeset) ? $localeset : 'English');
/** * @param array $configuration */ public function __construct(array $configuration = array()) { $this->configuration = $configuration + array('host' => '', 'database' => '', 'user' => '', 'password' => '', 'charset' => 'utf8', 'driver' => DatabaseFactory::getDefaultDriver(), 'debug' => FALSE); $this->configuration['driver'] = strtolower($this->configuration['driver']); }
die("Access Denied"); } use PHPFusion\Database\DatabaseFactory; require_once __DIR__ . '/autoloader.php'; require_once __DIR__ . '/core_functions_include.php'; require_once fusion_detect_installation(); require_once __DIR__ . '/core_constants_include.php'; require_once __DIR__ . '/multisite_include.php'; // Database handler functions /** * Documentation: * Default connection id = "default"; * To debug sql statements (showing sql queries) insert either of the following line before "require_once footer.php" * $log = PHPFusion\Database\Driver\MySQL::getGlobalQueryLog(); * $log = PHPFusion\Database\Driver\PDOMySQL::getGlobalQueryLog(); * @todo: missing doc - usage to set true false otherwise.. ? * @todo: add a form_select("debug_sql", "Debug SQL?", fusion_get_settings("debug_sql"), array( * "options" => array($locale['disable'], $locale['enable']), * "inline"=>true)); into administration/security_settings.php */ DatabaseFactory::setDefaultDriver(intval($pdo_enabled) === 1 ? DatabaseFactory::DRIVER_PDO_MYSQL : DatabaseFactory::DRIVER_MYSQL); DatabaseFactory::registerConfiguration(DatabaseFactory::getDefaultConnectionID(), array('host' => $db_host, 'user' => $db_user, 'password' => $db_pass, 'database' => $db_name, 'debug' => DatabaseFactory::isDebug(DatabaseFactory::getDefaultConnectionID()))); DatabaseFactory::registerConfigurationFromFile(__DIR__ . '/../config.db.php'); require_once DB_HANDLERS . "all_functions_include.php"; require_once __DIR__ . "/system_images.php"; require_once __DIR__ . "/output_handling_include.php"; require_once __DIR__ . "/translate_include.php"; require_once __DIR__ . "/notify/notify.inc.php"; require_once __DIR__ . "/sqlhandler.inc.php"; require_once __DIR__ . "/defender.inc.php"; require_once __DIR__ . "/dynamics/dynamics.inc.php";
/** * Get the AbstractDatabase instance * * @return AbstractDatabaseDriver */ function dbconnection() { return DatabaseFactory::getConnection('default'); }
/** * @param string $file */ public static function registerConfigurationFromFile($file) { if (is_file($file)) { $configurations = (require $file); if (is_array($configurations)) { DatabaseFactory::registerConfigurations($configurations); } // TODO Exception otherwise } // TODO Exception otherwise }