Beispiel #1
0
function check_env()
{
    if (BABEL_ENABLED == 'yes') {
        global $dirs;
        foreach ($dirs as $dir) {
            if (!is_writable(BABEL_PREFIX . $dir)) {
                return exception_message('permission');
            }
        }
    } else {
        return exception_message('off');
    }
}
 public function __construct($sess_start = true)
 {
     check_env();
     if (@($this->db = mysql_connect(BABEL_DB_HOSTNAME . ':' . BABEL_DB_PORT, BABEL_DB_USERNAME, BABEL_DB_PASSWORD))) {
         mysql_select_db(BABEL_DB_SCHEMATA);
         mysql_query("SET NAMES utf8");
         mysql_query("SET CHARACTER SET utf8");
         mysql_query("SET COLLATION_CONNECTION='utf8_general_ci'");
         $rs = mysql_query('SELECT nod_id FROM babel_node WHERE nod_id = 1');
         if (@mysql_num_rows($rs) == 1) {
         } else {
             exception_message('world');
         }
     } else {
         exception_message('db');
     }
     if ($sess_start) {
         session_start();
     }
     $this->URL = new URL();
     $this->User = new User('', '', $this->db);
     if (!isset($GLOBALS['SET_LANG'])) {
         if ($this->User->vxIsLogin()) {
             define('BABEL_LANG', $this->User->usr_lang);
         } else {
             include BABEL_PREFIX . '/res/supported_languages.php';
             if (isset($_SESSION['babel_lang'])) {
                 if (in_array($_SESSION['babel_lang'], array_keys($_languages))) {
                     define('BABEL_LANG', $_SESSION['babel_lang']);
                 } else {
                     define('BABEL_LANG', BABEL_LANG_DEFAULT);
                 }
             } else {
                 define('BABEL_LANG', BABEL_LANG_DEFAULT);
             }
         }
         $GLOBALS['SET_LANG'] = true;
     }
     $this->Validator = new Validator($this->db, $this->User);
     if (!isset($_SESSION['babel_ua'])) {
         $_SESSION['babel_ua'] = LividUtil::parseUserAgent();
     }
     global $CACHE_LITE_OPTIONS_SHORT;
     $this->cs = new Cache_Lite($CACHE_LITE_OPTIONS_SHORT);
     global $CACHE_LITE_OPTIONS_LONG;
     $this->cl = new Cache_Lite($CACHE_LITE_OPTIONS_LONG);
 }
Beispiel #3
0
 public function __construct()
 {
     session_start();
     if (BABEL_DEBUG) {
         $this->timer = new Benchmark_Timer();
         $this->timer->start();
         if (!isset($_SESSION['babel_debug_log'])) {
             $_SESSION['babel_debug_log'] = array();
         }
     } else {
         error_reporting(0);
     }
     check_env();
     if (@($this->db = mysql_connect(BABEL_DB_HOSTNAME . ':' . BABEL_DB_PORT, BABEL_DB_USERNAME, BABEL_DB_PASSWORD))) {
         mysql_select_db(BABEL_DB_SCHEMATA);
         mysql_query("SET NAMES utf8");
         mysql_query("SET CHARACTER SET utf8");
         mysql_query("SET COLLATION_CONNECTION='utf8_general_ci'");
         $rs = mysql_query('SELECT nod_id FROM babel_node WHERE nod_id = 1');
         if (@mysql_num_rows($rs) == 1) {
             mysql_free_result($rs);
         } else {
             mysql_free_result($rs);
             exception_message('world');
         }
     } else {
         exception_message('db');
     }
     global $CACHE_LITE_OPTIONS_SHORT;
     $this->cs = new Cache_Lite($CACHE_LITE_OPTIONS_SHORT);
     /* legacy long cache:
     		global $CACHE_LITE_OPTIONS_LONG;
     		$this->cl = new Cache_Lite($CACHE_LITE_OPTIONS_LONG);
     		*/
     global $ZEND_CACHE_OPTIONS_LONG_FRONTEND;
     global $ZEND_CACHE_OPTIONS_LONG_BACKEND;
     global $ZEND_CACHE_OPTIONS_MEMCACHED;
     if (ZEND_CACHE_MEMCACHED_ENABLED == 'yes') {
         $this->cl = Zend_Cache::factory('Core', 'Memcached', $ZEND_CACHE_OPTIONS_LONG_FRONTEND, $ZEND_CACHE_OPTIONS_MEMCACHED);
     } else {
         $this->cl = Zend_Cache::factory('Core', ZEND_CACHE_TYPE_LONG, $ZEND_CACHE_OPTIONS_LONG_FRONTEND, $ZEND_CACHE_OPTIONS_LONG_BACKEND[ZEND_CACHE_TYPE_LONG]);
     }
     if (BABEL_DEBUG) {
         $_SESSION['babel_debug_profiling'] = true;
         mysql_query("SET PROFILING = 1") or $_SESSION['babel_debug_profiling'] = false;
         mysql_query("SET PROFILING_HISTORY_SIZE = 100") or $_SESSION['babel_debug_profiling'] = false;
     } else {
         $_SESSION['babel_debug_profiling'] = false;
     }
     $this->User = new User('', '', $this->db);
     if ($this->User->vxIsLogin()) {
         define('BABEL_LANG', $this->User->usr_lang);
     } else {
         include BABEL_PREFIX . '/res/supported_languages.php';
         if (isset($_SESSION['babel_lang'])) {
             if (in_array($_SESSION['babel_lang'], array_keys($_languages))) {
                 define('BABEL_LANG', $_SESSION['babel_lang']);
             } else {
                 define('BABEL_LANG', BABEL_LANG_DEFAULT);
             }
         } else {
             define('BABEL_LANG', BABEL_LANG_DEFAULT);
         }
     }
     $GLOBALS['SET_LANG'] = true;
     require_once BABEL_PREFIX . '/lang/' . BABEL_LANG . '/lang.php';
     $this->lang = new lang();
     if ($this->User->vxIsLogin()) {
         $sql = "SELECT usr_id, usr_gender, usr_nick, usr_portrait FROM babel_user, babel_friend WHERE usr_id = frd_fid AND frd_uid = {$this->User->usr_id} ORDER BY frd_created ASC";
         $rs = mysql_query($sql);
         $_friends = array();
         while ($_friend = mysql_fetch_array($rs)) {
             $_friends[$_friend['usr_id']] = $_friend;
         }
         mysql_free_result($rs);
         $this->User->usr_friends = $_friends;
     }
     $this->Validator = new Validator($this->db, $this->User);
     if (!isset($_SESSION['babel_ua'])) {
         $_SESSION['babel_ua'] = LividUtil::parseUserAgent();
     }
     $sql = 'DELETE FROM babel_online WHERE onl_lastmoved < ' . (time() - BABEL_USR_ONLINE_DURATION);
     mysql_query($sql, $this->db);
     $sql = "SELECT onl_hash FROM babel_online WHERE onl_hash = '" . mysql_real_escape_string(session_id()) . "'";
     $rs = mysql_query($sql, $this->db);
     if (isset($_SERVER['HTTP_REFERER'])) {
         $referer = mysql_real_escape_string($_SERVER['HTTP_REFERER']);
     } else {
         $referer = '';
     }
     if (mysql_num_rows($rs) == 1) {
         $s = mysql_fetch_object($rs);
         mysql_free_result($rs);
         $sql = "UPDATE babel_online SET onl_nick = '" . mysql_real_escape_string($this->User->usr_nick, $this->db) . "', onl_ua = '" . mysql_real_escape_string($_SESSION['babel_ua']['ua'], $this->db) . "', onl_ip = '" . $_SERVER['REMOTE_ADDR'] . "', onl_uri = '" . mysql_real_escape_string($_SERVER['REQUEST_URI']) . "', onl_ref = '" . $referer . "', onl_lastmoved = " . time() . " WHERE onl_hash = '" . mysql_real_escape_string(session_id()) . "'";
         mysql_query($sql, $this->db);
     } else {
         mysql_free_result($rs);
         $sql = "INSERT INTO babel_online(onl_hash, onl_nick, onl_ua, onl_ip, onl_uri, onl_ref, onl_created, onl_lastmoved) VALUES('" . mysql_real_escape_string(session_id()) . "', '" . mysql_real_escape_string($this->User->usr_nick) . "', '" . mysql_real_escape_string($_SESSION['babel_ua']['ua']) . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . mysql_real_escape_string($_SERVER['REQUEST_URI']) . "', '" . $referer . "', " . time() . ', ' . time() . ')';
         mysql_query($sql, $this->db);
     }
     $this->URL = new URL();
     $this->Geo = new Geo($this->User->usr_geo);
     if ($count_a = $this->cs->get('count')) {
         $count_a = unserialize($count_a);
         $this->pst_count = $count_a['pst_count'];
         $this->tpc_count = $count_a['tpc_count'];
         $this->fav_count = $count_a['fav_count'];
         $this->svp_count = $count_a['svp_count'];
         $this->usr_count = $count_a['usr_count'];
         $this->ing_count = $count_a['ing_count'];
         $this->blg_count = $count_a['blg_count'];
     } else {
         $sql = "SELECT COUNT(pst_id) FROM babel_post";
         $rs = mysql_query($sql, $this->db);
         $this->pst_count = mysql_result($rs, 0, 0);
         mysql_free_result($rs);
         $sql = "SELECT COUNT(tpc_id) FROM babel_topic";
         $rs = mysql_query($sql, $this->db);
         $this->tpc_count = mysql_result($rs, 0, 0);
         mysql_free_result($rs);
         $sql = "SELECT COUNT(fav_id) FROM babel_favorite";
         $rs = mysql_query($sql, $this->db);
         $this->fav_count = mysql_result($rs, 0, 0);
         mysql_free_result($rs);
         $sql = "SELECT COUNT(svp_id) FROM babel_savepoint";
         $rs = mysql_query($sql, $this->db);
         $this->svp_count = mysql_result($rs, 0, 0);
         mysql_free_result($rs);
         $sql = "SELECT COUNT(usr_id) FROM babel_user";
         $rs = mysql_query($sql, $this->db);
         $this->usr_count = mysql_result($rs, 0, 0);
         mysql_free_result($rs);
         $sql = "SELECT COUNT(ing_id) FROM babel_ing_update";
         $rs = mysql_query($sql, $this->db);
         $this->ing_count = mysql_result($rs, 0, 0);
         mysql_free_result($rs);
         $sql = "SELECT COUNT(blg_id) FROM babel_weblog";
         $rs = mysql_query($sql, $this->db);
         $this->blg_count = mysql_result($rs, 0, 0);
         mysql_free_result($rs);
         $count_a = array();
         $count_a['pst_count'] = $this->pst_count;
         $count_a['tpc_count'] = $this->tpc_count;
         $count_a['fav_count'] = $this->fav_count;
         $count_a['svp_count'] = $this->svp_count;
         $count_a['usr_count'] = $this->usr_count;
         $count_a['ing_count'] = $this->ing_count;
         $count_a['blg_count'] = $this->blg_count;
         $this->cs->save(serialize($count_a), 'count');
     }
     $sql = "SELECT onl_hash FROM babel_online WHERE onl_nick = ''";
     $rs_a = mysql_query($sql, $this->db);
     $sql = "SELECT onl_hash, onl_nick FROM babel_online WHERE onl_nick != ''";
     $rs_b = mysql_query($sql, $this->db);
     $this->online_count_anon = mysql_num_rows($rs_a);
     $this->online_count_reg = mysql_num_rows($rs_b);
     mysql_free_result($rs_a);
     mysql_free_result($rs_b);
     $this->online_count = $this->online_count_anon + $this->online_count_reg;
     $this->restricted = get_restricted($this->cs);
     preg_match('/([0-9]+)/', '$Revision$', $z);
     $this->ver = '0.5.' . $z[1];
     header('Content-Type: text/html; charset=UTF-8');
     header('Cache-control: no-cache, must-revalidate');
 }