molyx($cfg); } /** * 初始化函数 * * @access public * @param * * @return void */ function molyx($cfg) { parent::integrate($cfg); if ($this->error) { /* 数据库连接出错 */ return false; } $this->field_id = 'id'; $this->field_name = 'name'; $this->field_email = 'email'; $this->field_gender = 'gender'; $this->field_bday = 'birthday'; $this->field_pass = 'password'; $this->field_reg_date = 'joindate'; $this->user_table = 'user'; /* 检查数据表是否存在 */ $sql = "SHOW TABLES LIKE '" . $this->prefix . "%'"; $exist_tables = $this->db->getCol($sql); if (empty($exist_tables) || (!in_array($this->prefix.$this->user_table, $exist_tables)) || (!in_array($this->prefix.'setting', $exist_tables))) { $this->error = 2; /* 缺少数据表 */ return false; } $cookie_prefix = $this->db->getOne("SELECT value FROM " .$this->table('setting'). " WHERE varname='cookieprefix'"); } /** * 检查指定用户是否存在及密码是否正确 * * @access public * @param string $username 用户名 * * @return int */ function check_user($username, $password = null) { if ($this->charset != 'UTF8') { $post_username = strtolower(ecs_iconv('UTF8', $this->charset, $username)); } else { $post_username = strtolower($username); } $sql = "SELECT " . $this->field_id . " AS user_id, ". $this->field_pass . " AS password, salt". " FROM " . $this->table($this->user_table). " WHERE " . $this->field_name . "='" . $post_username . "'"; $row = $this->db->getRow($sql); if (empty($row)) { return 0; } if ($password === null) { return $row['user_id']; } if ($row['password'] == $this->compile_password(array('type'=>PWD_SUF_SALT, 'salt'=>$row['salt'], 'md5password'=>md5($password)))) { return $row['user_id']; } else { return 0; } } /** * 设置论坛cookie * * @access public * @param * * @return void */ function set_cookie ($username="") { parent::set_cookie($username); if (empty($username)) { $time = time() - 3600 * 24; setcookie($this->cookie_prefix.'sessionid', '', $time, $this->cookie_path, $this->cookie_domain); setcookie($this->cookie_prefix.'userid', '', $time, $this->cookie_path, $this->cookie_domain); setcookie($this->cookie_prefix.'password', '', $time, $this->cookie_path, $this->cookie_domain); } else { if ($this->charset != 'UTF8') { $username = ecs_iconv('UTF8', $this->charset, $username); } $sql = "SELECT " . $this->field_id . " AS user_id, salt, " . $this->field_pass . " As password ". " FROM " . $this->table($this->user_table) . " WHERE " . $this->field_name . "='$username'"; $row = $this->db->getRow($sql); $time = time() + 3600 * 24 * 30; setcookie($this->cookie_prefix.'sessionid', '', time() - 3600 * 24, $this->cookie_path, $this->cookie_domain); setcookie($this->cookie_prefix.'userid', $row['user_id'], time() + 3600 * 24 * 30, $this->cookie_path, $this->cookie_domain); setcookie($this->cookie_prefix.'password', $row['password'], time() + 3600 * 24 * 30, $this->cookie_path, $this->cookie_domain); } } /** * 检查cookie * * @access public * @param * * @return void */ function check_cookie () { if ((!isset($_COOKIE[$this->cookie_prefix.'userid'])) || (!isset($_COOKIE[$this->cookie_prefix.'password']))) { return false; } $sql = "SELECT " . $this->field_name . " FROM " .$this->table($this->user_table). " WHERE " .$this->field_id ."='". $_COOKIE[$this->cookie_prefix.'userid'] . "'". " AND " . $this->field_pass . "='" . $_COOKIE[$this->cookie_prefix.'password'] . "'"; $username = $this->db->getOne($sql); if ($username && ($this->charset != 'UTF8')) { $username = ecs_iconv($this->charset, 'UTF8', $username); } return $username; } /** * 获取论坛有效积分及单位 * * @access public * @param * * @return void */ function get_points_name () { static $ava_credits = NULL; if ($ava_credits === NULL) { $sql = "SELECT IF(value>'' , value, defaultvalue)". " FROM " . $this->table('setting'). " WHERE varname = 'bankcurrency'"; $unit = $this->db->getOne($sql); $ava_credits['cash']['title'] = 'CASH'; $ava_credits['cash']['unit'] = empty($unit)? '' : ($this->charset != 'UTF8') ? ecs_iconv($this->charset, 'UTF8', $unit) : $unit; } return $ava_credits; } } ?>