Location: PHPKode > projects > Gnew > Gnew-2013.1/includes/common.php
<?php
// -----------------------------------------------------------------------------
// $Id: common.php 685 2013-03-28 16:22:26Z raoul $
//
// Copyright (C) 2013 Raoul Proença
// License: GNU GPL version 3 (see copying.txt file)
// Website: http://www.gnew.fr/
// -----------------------------------------------------------------------------
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------

$start_time = microtime(true);

$invalid = preg_match('`(ftp|http|www)`i', $_SERVER['QUERY_STRING']);
if ($invalid != false)
{
    exit('Invalid query string. Exiting...');
}

// Report all PHP errors
error_reporting(E_ALL);

define('GNEW_VERSION', '2013.1');
define('TABLE_ANSWERS', 'gnew_answers');
define('TABLE_ARTICLES', 'gnew_articles');
define('TABLE_CATEGORIES', 'gnew_categories');
define('TABLE_COMMENTS', 'gnew_comments');
define('TABLE_EMOTICONS', 'gnew_emoticons');
define('TABLE_NEWS', 'gnew_news');
define('TABLE_POSTS', 'gnew_posts');
define('TABLE_QUESTIONS', 'gnew_questions');
define('TABLE_SESSIONS', 'gnew_sessions');
define('TABLE_SETTINGS', 'gnew_settings');
define('TABLE_USERS', 'gnew_users');
define('TABLE_VOTES', 'gnew_votes');

include('./../includes/config.php');
switch (SQL_TYPE)
{
    case 'mysql':
        include('./../includes/mysql.php');
        $sql = new mysql;
        break;
    case 'pgsql':
        include('./../includes/pgsql.php');
        $sql = new pgsql;
        break;
    case 'sqlite':
        include('./../includes/sqlite.php');
        $sql = new sqlite;
        break;
    default:
        exit('Invalid SQL type. Exiting...');
}

// Create a global variable with all settings
$sql->query('SELECT *
             FROM ' . TABLE_SETTINGS);
$settings = $sql->fetch();

include('./../includes/sessions.php');
// User logged?
if ($_SESSION['user_id'] > 0)
{
    $sql->query('SELECT user_avatar, user_date_format, user_date_offset, user_day, user_email, user_language, user_last_visit, user_level, user_location, user_month, user_name, user_occupation, user_template, user_show_email, user_signature, user_website, user_year
                 FROM ' . TABLE_USERS . '
                 WHERE user_id = \'' . $_SESSION['user_id'] . '\'');
    $users = $sql->fetch();
    setcookie('gnew_date_format', $users['user_date_format'], (time() + ($settings['cookies_expiry'] * 24 * 3600)), '/');
    setcookie('gnew_date_offset', $users['user_date_offset'], (time() + ($settings['cookies_expiry'] * 24 * 3600)), '/');
    setcookie('gnew_language', $users['user_language'], (time() + ($settings['cookies_expiry'] * 24 * 3600)), '/');
    setcookie('gnew_template', $users['user_template'], (time() + ($settings['cookies_expiry'] * 24 * 3600)), '/');
}
else
{
    $users['user_level'] = 0;
}

include('./../includes/functions.php');

include('./../languages/' . get_language() . '.php');

include('./../includes/cache.php');
$cache = new cache;

include('./../includes/template.php');
$template = new template('./../templates/' . get_template());

// Set all language files variables
$template->set_var($lang);

if (strcmp(get_phpversion(), '5.4.0') < 0)
{
    ini_set('magic_quotes_runtime', 0);
    if (get_magic_quotes_gpc())
    {
        $_GET = remove_slashes($_GET);
        $_POST = remove_slashes($_POST);
        $_COOKIE = remove_slashes($_COOKIE);
    }
}
$_GET = add_slashes($_GET);
$_COOKIE = add_slashes($_COOKIE);

?>
Return current item: Gnew