From 80623b0f8dc65ac4bde4bfcd9e64bce0275a7f66 Mon Sep 17 00:00:00 2001 From: wangbo Date: Fri, 14 Aug 2015 16:54:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Revert=20"=E4=BF=AE=E5=A4=8Dbug=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0init.php"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit dd67a1cff3574d68c260ff4014639978fdaef7ba. --- addquestion.php | 26 -- config/db.simple.config.php | 21 -- config/oauth.simple.config.php | 14 - includes/db.class.php | 48 --- includes/db_function.class.php | 586 --------------------------------- includes/errshow.class.php | 28 -- includes/index.function.php | 47 --- includes/oauth.class.php | 223 ------------- includes/show.function.php | 53 --- includes/user.class.php | 90 ----- index.php | 51 --- init.php | 32 -- oauth/index.php | 16 - oauth/login.php | 61 ---- question.php | 33 -- search.php | 28 -- 16 files changed, 1357 deletions(-) delete mode 100644 addquestion.php delete mode 100644 config/db.simple.config.php delete mode 100644 config/oauth.simple.config.php delete mode 100644 includes/db.class.php delete mode 100644 includes/db_function.class.php delete mode 100644 includes/errshow.class.php delete mode 100644 includes/index.function.php delete mode 100644 includes/oauth.class.php delete mode 100644 includes/show.function.php delete mode 100644 includes/user.class.php delete mode 100644 index.php delete mode 100644 init.php delete mode 100644 oauth/index.php delete mode 100644 oauth/login.php delete mode 100644 question.php delete mode 100644 search.php diff --git a/addquestion.php b/addquestion.php deleted file mode 100644 index 9703082..0000000 --- a/addquestion.php +++ /dev/null @@ -1,26 +0,0 @@ -db = new mysqli(FAQ_DB_HOST, FAQ_DB_USER, FAQ_DB_PASSWORD, FAQ_DB_NAME, FAQ_DB_PORT); - if (mysqli_connect_errno()) - { - echo "数据库连接失败".mysqli_connect_errno().mysqli_connect_error(); - exit(); - } - $this->db->set_charset('utf8'); - return $this->db; - } - - public function query($sql) - { - $this->res = $this->db->query($sql); - return $this->res; - //fetch_assoc - } - - //字符过滤 - public function escape_string($buf) - { - return $this->db->escape_string($buf); - } - - function __destruct() - { - if( is_object($this->res) ) - $this->res->free(); - $this->db->close(); - } -} \ No newline at end of file diff --git a/includes/db_function.class.php b/includes/db_function.class.php deleted file mode 100644 index 186255f..0000000 --- a/includes/db_function.class.php +++ /dev/null @@ -1,586 +0,0 @@ -dbconn = new \db(); - return $this; - } - - /* - * 获取问题的标题 - * 参数:start_id(默认为0),limit_num(默认为20) - * 返回值:问题title集合, question_id, user_id, answer_time - */ - public function get_question_list($start_id = 0, $limit_num = 20) - { - $sql = "select title, qid, uid, gmt_create_time from app_faq_question limit $start_id, $limit_num"; - $result = $this->dbconn->query($sql); - return $result; - } - - /* - * 获取问题详情 - * 参数:question_id - * 返回值:(array) title、content、tags、uid、ctime - */ - public function get_question_detial($question_id) - { - $sql = "select title, content, tags, uid, gmt_create_time as ctime from app_faq_question where qid='$question_id'"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 获取问题正文 - * 参数:question_id - * 返回值:问题的:content - */ - public function get_question_content($question_id) - { - $sql = "select content from app_faq_question where qid='$question_id'"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 获取问题的标签 - * 参数:question_id - * 返回值:(array) tags - * 说明:标签之间使用(英文逗号)分隔 - */ - public function get_question_tags($question_id) - { - $sql = "select tags from app_faq_question where qid='$question_id'"; - $re = $this->dbconn->query($sql); - - return explode(',', $re); - } - - - /* - * 获取提问的用户 - * 参数:question_id - * 返回值:user_id - */ - public function get_question_askuser($question_id) - { - $sql = "select uid from app_faq_question where qid='$question_id'"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 获取问题的状态 - * 参数:question_id - * 返回值:(int) 正常:0(默认), 关闭:1, 删除:2, 置顶:4, 精华:8 - */ - public function get_question_status($question_id) - { - $sql = "select status from app_faq_question where qid='$question_id'"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 添加问题 - * 参数:title, uid, content, tags(默认无标签) - * 返回值:(bool) 成功:true, 失败:false - */ - public function add_question($title, $uid, $content, $tags = '') - { - $sql = "insert into app_faq_question(uid, title, content, tags) value($uid,'$title','$content','$tags')"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 追加问题正文 - * 参数:question_id, add_content - * 返回值:(bool) 成功:true, 失败:false - */ - public function append_question_comment($question_id, $add_content) - { - $up_time = date('Y-m-d'); - $up_string = "'----------'.$up_time.'----------'"; - $sql = "select content from app_faq_question where qid=$question_id"; - $re = $this->dbconn->query($sql); - if ($re) { - $content = $re . $up_string . $add_content; - $sql = "update app_faq_question set content='$content' where qid='$question_id'"; - $re = $this->dbconn->query($sql); - if ($re) { - return true; - } else { - return false; - } - } else { - return false; - } - } - - /* - * 更新问题状态 - * 参数:question_id, (int)status - * 返回值:(bool) 成功:true, 失败:false - */ - public function update_status($question_id, $status) - { - $sql = "update app_faq_question set status=$status where qid='$question_id'"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 删除问题 - * 参数:question_id - * 返回值:(bool) 成功:true, 失败:false - */ - public function delete_question($question_id) - { - $sql = "delete from app_faq_question where qid='$question_id'"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 模糊查找问题 - * 参数:keyword - * 返回值:title_lists - */ - public function search_question_title($keyword) - { - $sql = "select title from app_faq_question where binary ucase(title) like concat('%',ucase('$keyword'),'%')"; - $re = $this->dbconn->query($sql); - $result = array(); - while ($res = mysql_fetch_array($re)) { - array_push($result, $res); - } - - return $result; - } - - - /****************************/ - /* - * 获取回复内容 - * 参数:question_id - * 返回值:answer_lists - */ - public function get_answer_comment($question_id) - { - $sql = "select content from app_faq_answer where qid='$question_id'"; - $re = $this->dbconn->query($sql); - $result = array(); - while ($res = mysql_fetch_array($re)) { - array_push($result, $res); - } - - return $result; - } - - /* - * 获取回复时间 - * 参数:answer_id - * 返回值:unix时间戳 - */ - public function get_answer_createtime($answer_id) - { - $sql = "select gmt_create_time from app_faq_answer where aid='$answer_id'"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 追加回复 - * 参数:answer_id, add_content - * 返回值:(bool) 成功:true, 失败:false - */ - public function append_answer_comment($answer_id, $add_content) - { - $up_time = date('Y-m-d'); - $up_string = "'----------'.$up_time.'----------'"; - $sql = "select content from app_faq_answer where aid=$answer_id"; - $re = $this->dbconn->query($sql); - if ($re) { - $content = $re . $up_string . $add_content; - $sql = "update app_faq_answer set content='$content' where aid='$answer_id'"; - $re = $this->dbconn->query($sql); - if ($re) { - return true; - } else { - return false; - } - } else { - return false; - } - - } - - /* - * 获取“赞”和“踩”人数 - * 参数:answer_id - * 返回值:(array) 下标agree表示“赞”数目,disagree表示“踩”数目 - */ - public function get_votenum($answer_id) - { - $sql = "select vote from app_faq_answer where aid='$answer_id'"; - $re = $this->dbconn->query($sql); - - $arr = json_decode($re, true); - $count_y = 0; - $count_n = 0; - - foreach ($arr as $key => $value) { - - if ($value == 1) $count_y++; - else $count_n++; - } - - return array('agree' => $count_y, 'disagree' => $count_n); - } - - /* - * 添加“赞”或“踩” - * 参数:answer_id, user_id, action(0踩,1赞) - * 返回值:(bool) 成功:true, 失败:false - */ - public function add_answer_vote($answer_id, $user_id, $action) - { - $result = $this->json_vote($answer_id, $user_id, $action, 1); - if ($result) { - return true; - } else { - return false; - } - } - - /* - * 删除“赞”或“踩” - * 参数:answer_id, user_id, action(0踩,1赞) - * 返回值:(bool) 成功:true, 失败:false - */ - public function delete_answer_vote($answer_id, $user_id, $action) - { - $sql = "select vote from app_faq_answer where aid='$answer_id' and uid ='$user_id'"; - $re = $this->dbconn->query($sql); - $result = $this->json_vote($answer_id, $user_id, $action, 0); - - if ($result) { - return true; - } else { - return false; - } - } - - /* - * 添加回复 - * 参数:user_id, question_id, content - * 返回值:(bool) 成功:true, 失败:false - */ - public function add_answer($user_id, $question_id, $content) - { - $sql = "insert into app_faq_answer(uid, qid, content) values('$user_id', '$question_id', '$content')"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 删除回复 - * 参数:answer_id - * 返回值:(bool) 成功:true, 失败:false - */ - public function delete_answer($answer_id) - { - $sql = "delete from app_faq_answer where aid='$answer_id'"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 获取回复总数 - * 参数:question_id - * 返回值:(int) answers - */ - public function get_answer_num($question_id) - { - $sql = "select count(aid) from app_faq_answer where qid='$question_id'"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 添加关注 - * 参数:user_id, question_id - * 返回值:(bool) 成功:true, 失败:false - */ - public function insert_follow($user_id, $question_id) - { - $sql = "insert into app_faq_follow(uid, qid) values($user_id, $question_id)"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 删除关注 - * 参数:user_id, question_id - * 返回值:(bool) 成功:true, 失败:false - */ - public function delete_follow($user_id, $question_id) - { - $sql = "deletc from app_faq_follow where uid=$user_id and qid=$question_id"; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 获取关注的问题id - * 参数:user_id - * 返回值:question_lists - */ - public function get_follow_question($user_id) - { - $sql = "select qid from app_faq_follow where uid=$user_id"; - $re = $this->dbconn->query($sql); - $result = array(); - while ($res = mysql_fetch_array($re)) { - array_push($result, $res); - } - - return $result; - } - - /* - * 获取关注某问题的全部关注用户id - * 参数:question_id - * 返回值:user_lists - */ - public function get_follow_id($question_id) - { - $sql = "select uid from app_faq_follow where qid=$question_id"; - $re = $this->dbconn->query($sql); - $result = array(); - while ($res = mysql_fetch_array($re)) { - array_push($result, $res); - } - - return $result; - } - - - /************************************/ - /* - * 添加通知 - * 参数:user_id, content, link - * 返回值:(bool) 成功:true, 失败:false - */ - public function add_notify($user_id, $content, $link) - { - $sql = "insert into app_faq_notify(uid, content, link) values($user_id, '$content', '$link') "; - $re = $this->dbconn->query($sql); - - return $re; - } - - /* - * 获取通知 - * 参数:user_id - * 返回值:notify_lists - */ - public function get_notify($user_id) - { - $sql = "select nid from app_faq_notify where uid=$user_id"; - $re = $this->dbconn->query($sql); - $result = array(); - while ($res = mysql_fetch_array($re)) { - array_push($result, $res); - } - - return $result; - } - - /* - * 标记已读 - * 参数:notify_id - * 返回值:(bool) 成功:true, 失败:false - */ - public function change_notify_status($notify_id) - { - $sql = "update app_faq_notify set nid=$notify_id"; - $re = $this->dbconn->query($sql); - - return $re; - } - - - /* - * 通知符合条件的人 - * 参数:question_id - * 返回值:userid_lists - */ - public function notice_all_user($question_id) - { - $sql = "select uid from app_faq_follow where qid=$question_id"; - $result = $this->dbconn->query($sql); - - return $result; - } - - - /* - * json 操作 - * 参数:answer_id, user_id, action, flag - * 返回值:(bool) 成功:true, 失败:false - * 说明:flag为1,表示add,反之,为del - */ - public function json_vote($answer_id, $user_id, $action, $flag) - { - $sql = "select vote from app_faq_answer where aid=$answer_id and uid =$user_id"; - $re = $this->dbconn->query($sql); - - $arr = json_decode($re, true); - foreach ($arr as $key => $value) { - - if ($key == $user_id) { - - if ($flag) { //找到key && flag == 1,即添加失败 - - return false; - } else { //找到key && flag == 0,进行删除操作 - - unset($arr[$key]); - $json = json_encode($arr); - $sql = "update app_faq_answer set vote='$json' where aid=$answer_id and uid=$user_id"; - $this->dbconn->query($sql); - - return true; - } - - } - } - if ($flag) { //未找到key && flag == 1,则添加 - - $add_vote = array($user_id => '1'); - array_push($arr, $add_vote); - $json = json_encode($arr); - $sql = "update app_faq_answer set vote='$json' where aid=$answer_id and uid=$user_id"; - $this->dbconn->query($sql); - - return true; - } else { //未找到key && flag == 0,即删除失败 - - return false; - } - } - - /** - * 响应QQ登录事件,更新数据 - * 参数:openid, name, sex, imgs - * 返回值:(bool) 成功:userid, 失败:失败原因id{-1,存在用户但数据库更新失败;-2,不存在用户,插入新用户信息失败,-3,其他} - * 说明:sex 男1女2 - */ - public function update_userinfo($openid,$name,$sex,$imgs){ - //判断参数合法性,需判断参数 - //判断openid是不是已经在数据库中 - $sql = "SELECT userid FROM app_faq_user WHERE openid = ".$openid; - $result = $this->dbconn->query($sql); - if($result && $result->num_rows>0){ - //数据库查询结果唯一,则存在该用户,更新用户信息 - $rows=$result->fetch_assoc(); - $userid = $rows['userid']; - $sql = "UPDATE `app_faq_user` SET `name`='{$name}', `sex`='{$sex}', `imgs`='{$imgs}' WHERE `userid` = '{$userid}'"; - $result = $this->dbconn->query($sql); - if ($result) - return $userid; - else - return -1; - }else { - //不存在该用户,插入新用户信息 - $sql = "INSERT INTO `app_faq_user` (`userid`, `openid`, `name`, `sex`, `imgs`, `privilege`) values(NULL,'{$openid}','{$name}','{$sex}','{$imgs}','0')"; - $result = $this->dbconn->query($sql); - if ($result) { - //新用户插入成功,查询userid,并返回 - $sql = "SELECT userid FROM app_faq_user WHERE openid = " . $openid; - $result = $this->dbconn->query($sql); - if ($result && $result->num_rows > 0) { - $rows = $result->fetch_assoc(); - $userid = $rows['userid']; - return $userid; - } else { - return -3; - } - } else { - //新用户插入失败 - return -2; - } - } - } - - /** - * 获取用户信息 - * 参数:user_id - * 返回值:用户信息数组 - * 说明:无 - */ - public function get_userinfo($user_id){ - //id合法性判断 - if ($user_id <1000 || $user_id > 100000) - return false; - $sql = "SELECT * FROM app_faq_user WHERE userid = ".$user_id; - $result = $this->dbconn->query($sql); - if($result && $result->num_rows>0){ - $rows = $result->fetch_assoc(); - return $rows; - }else{ - return false; - } - } - - /** - * 内部用户关联QQ - * 参数:user_id,openid - * 返回值:bool - * 说明:关联内部用户QQ信息 - */ - public function connect_qq_linux($user_id,$openid){ - //合法性判断 - //插入关联信息 - $sql = "SELECT userid FROM app_faq_user WHERE openid = ".$openid; - $result = $this->dbconn->query($sql); - if($result){ - return false; - }else { - - $sql = "SELECT * FROM app_faq_user WHERE userid = ".$user_id; - $result = $this->dbconn->query($sql); - if ($result){ - return false; - } - //关联 - $sql = "INSERT INTO `app_faq_user` (`userid`, `openid`, `name`, `sex`, `imgs`, `privilege`) values('{$user_id}','{$openid}','linuxer','0','http://xiyoulinux.qiniudn.com/linuxer.png','0')"; - $result = $this->dbconn->query($sql); - if ($result) - return $user_id; - else - return -1; - } - } -} diff --git a/includes/errshow.class.php b/includes/errshow.class.php deleted file mode 100644 index 389f98e..0000000 --- a/includes/errshow.class.php +++ /dev/null @@ -1,28 +0,0 @@ -assgin('error', $msg); - $smarty->display('err.tpl'); - - - } - - // 问题已删除时的错误提示 - public function has_del(){ - $msg = '该问题已被管理员删除!'; - $smarty->assgin('error', $msg); - $smarty->display('err.tpl'); - } - -} - -?> diff --git a/includes/index.function.php b/includes/index.function.php deleted file mode 100644 index 9d2fd6e..0000000 --- a/includes/index.function.php +++ /dev/null @@ -1,47 +0,0 @@ -> 1) && 1) == 1) return false; //获取状态的第二位数字,如果是1,表示问题被删除,不可访问. - return true; - -} - - -?> diff --git a/includes/oauth.class.php b/includes/oauth.class.php deleted file mode 100644 index 95d9b67..0000000 --- a/includes/oauth.class.php +++ /dev/null @@ -1,223 +0,0 @@ -appid = QQ_APPID; - $this->appkey = QQ_APPKEY; - $this->appcallback = QQ_CALLBACK; - $this->apperrreport = QQ_ERRORREPORT; - $this->appscope = QQ_SCOPE; - - if(!$this->appid || !$this->appkey || !$this->appcallback) - $this->showError('20001'); - - $this->callback_state = $_GET['state']; - } - - //QQ登陆 - public function qq_login(){ - - //-------生成唯一随机串防CSRF攻击 - $state = md5(uniqid(rand(), true)); - - $this->qq_static_var('state',$state); - - //-------构造请求参数列表 - $keysArr = array( - "response_type" => "code", - "client_id" => $this->appid, - "redirect_uri" => urlencode($this->appcallback), - "state" => $state, - "scope" => $this->appscope, - ); - - $login_url = $this->combineURL(self::GET_AUTH_CODE_URL, $keysArr); - - // 直接跳走 - header("Location:$login_url"); - exit(); - } - - //QQ回调函数 - public function qq_callback(){ - $state = $this->qq_static_var('state'); - $code = $_REQUEST['code']; - - //--------验证state防止CSRF攻击 - if($this->callback_state !== $state){ - $this->showError("30001"); - } - - //-------请求参数列表 - $keysArr = array( - "grant_type" => "authorization_code", - "client_id" => $this->appid, - "redirect_uri" => urlencode($this->appcallback), - "client_secret" => $this->appkey, - "code" =>$code, - ); - - //------构造请求access_token的url - $token_url = $this->combineURL(self::GET_ACCESS_TOKEN_URL, $keysArr); - $response = $this->get_contents($token_url); - - if(strpos($response, "callback") !== false){ - $lpos = strpos($response, "("); - $rpos = strrpos($response, ")"); - $response = substr($response, $lpos + 1, $rpos - $lpos -1); - $msg = json_decode($response); - - if(isset($msg->error)){ - $this->showError($msg->error, $msg->error_description); - } - } - - $params = array(); - parse_str($response, $params); - return $params["access_token"]; - } - - public function qq_openid($token){ - - if(!$token) - return false; - - //-------请求参数列表 - $keysArr = array( - "access_token" => $token - ); - - $graph_url = $this->combineURL(self::GET_OPENID_URL, $keysArr); - $response = $this->get_contents($graph_url); - - //--------检测错误是否发生 - if(strpos($response, "callback") !== false){ - $lpos = strpos($response, "("); - $rpos = strrpos($response, ")"); - $response = substr($response, $lpos + 1, $rpos - $lpos -1); - } - - $user = json_decode($response); - - if(isset($user->error)){ - $this->showError($user->error, $user->error_description); - } - return $user->openid; - } - - public function qq_static_var($key, $val=null){ - static $i =0; - - if($i === 0 && !$_SESSION) // 暂时用session. - session_start(); - - // 只有一个参数时是读, 否则是写. - if($val !== null){ - $_SESSION[$key] = $val; - } - - //无论如何都会返回! - return $_SESSION[$key]; - } - - //获取用户信息 - public function get_user_info($token,$openid){ - if(!$token || !$openid) - return false; - - //构造请求参数列表 - $keysArr = array( - "access_token" => $token, - "oauth_consumer_key" => $this->appid, - "openid" => $openid, - "format" => "json", - ); - - $url = $this->combineURL(self::GET_USER_INFO_URL, $keysArr); - $response = $this->get_contents($url); - - //处理返回数据,相关信息 - $userInfo = json_decode($response,true); - - return $userInfo; - - } - - private function showError($code, $description = '$'){ - $this->errorMsg = array( - '20001'=>'请将配置完全检查一遍', - '30001' => 'state防止CSRF攻击, 验证未通过', - '50001' => '请尝试开启curl支持,重启web服务器', - ); - - if(!$this->apperrreport){ - die();//die quietly - } - - echo ""; - if($description == "$"){ - die('

'.$this->errorMsg[$code].'

'); - }else{ - echo "

error:

$code"; - echo "

msg :

$description"; - } - exit(); - } - - private function combineURL($baseURL,$keysArr){ - $combined = $baseURL.'?'; - $valueArr = array(); - - foreach($keysArr as $key => $val){ - if($val) - $valueArr[] = "$key=$val"; - } - - $keyStr = implode("&",$valueArr); - $combined .= ($keyStr); - - return $combined; - } - - private function get_contents($url){ - if (!function_exists('curl_init')) { - $response = file_get_contents($url); - }else{ - $ch = curl_init(); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($ch, CURLOPT_URL, $url); - $response = curl_exec($ch); - curl_close($ch); - } - - //-------请求为空 - if(empty($response)){ - $this->showError("50001"); - } - - return $response; - } - -} \ No newline at end of file diff --git a/includes/show.function.php b/includes/show.function.php deleted file mode 100644 index 3c36e3c..0000000 --- a/includes/show.function.php +++ /dev/null @@ -1,53 +0,0 @@ -user_get_login()); //获得用户登录的json - $is_login = $temp['ret']; //is_login 用来标记用户是否登录,如果用户登录,赋值为0, 如果用户没有登录,赋值为非0 - return $is_login; -} - - -/*获取用户信息*/ -function get_user_info() //如果用户已经登录,返回用用户的信息,如果没有登录,返回NULL -{ - $user = new user(); - $temp = json_decode($user->user_get_login()); - return $temp; -} - - -/*左侧标签部分*/ -/*初步定位以下几个标签,后期会根据实际情况从数据库中获得访问量搞的标签的集合*/ -function get_left_tags() //返回左侧标签的列表 -{ - $tags = array("编程语言", "WEB应用开发", "移动应用开发", "云计算", "大数据", "数据挖掘", "其它"); - return $tags; -} - - - -/*右侧推荐部分*/ -/*初步定位几个相应的超链接*/ - -function get_right_rec() //返回右侧推荐的列表 -{ - $rec = array("西邮linux兴趣小组" => "http://www.xiyoulinux.org", "西安邮电大学" => "http://www.xupt.edu.cn"); - return $rec; -} - - - diff --git a/includes/user.class.php b/includes/user.class.php deleted file mode 100644 index 7db1bb4..0000000 --- a/includes/user.class.php +++ /dev/null @@ -1,90 +0,0 @@ -userid = $_SESSION['userid']; - $this->name = $_SESSION['name']; - $this->sex = $_SESSION['sex']; - $this->imgs = $_SESSION['imgs']; - $this->ret = 0; - } - else { - $this->userid = 0; - $this->ret = -1; - } - //$this->db = new db_sql_functions(); - } - - //תQQ֤û½Ϣ֤ɹture 򷵻false - public function user_login_qq(){ - header("Location:/oauth/login.php"); - return true; - } - - //תڲƽ̨֤û½Ϣ֤ɹture 򷵻false - public function user_login_linux(){ - return false; - } - - //˳ǰûɹture 򷵻false - public function user_login_out(){ - //session - //cookie - session_unset(); - if(isset($_COOKIE[session_name()])){ - setcookie(session_name(),'',time()-3600); - } - session_destroy(); - return true; - } - - //ȡǰ½ûϢ - public function user_get_login(){ - //û - $tmp = array($this->ret,$this->userid,$this->name,$this->sex,$this->imgs); - $tmp = json_encode($tmp); - return $tmp; - } - - //ȡϢ - public function user_getinfo($userid){ - //ͨݿѯû - //get_userinfo - // $result = $this->db->get_userinfo($userid); - if ($result){ -// $tmp = array("ret"=>"0"); -// $t = array_combine($tmp,$result); -// return json_encode($t); - }else{ - $tmp = array("ret"=>"-1"); - return json_encode($tmp); - } - } - - //ȡûȨޣݱбʶȨ޵ֶӦֵ - public function user_get_privilege($user_id){ - $result = $this->db->get_userinfo($user_id); - if ($result){ - return $result['privilege']; - } - return false; - } -} diff --git a/index.php b/index.php deleted file mode 100644 index 61a4b08..0000000 --- a/index.php +++ /dev/null @@ -1,51 +0,0 @@ -get_question_list($i , 20) ); -// foreach ($result as $temp) { -// if ((($db_function->get_question_status($temp['qid']) >> 1) & 1) == 1) { -// array_slice($result, $temp, 1); -// } -// } -// $i += 20; -// } while (count($result) <= 20); -// array_slice($result ,0, 20); -// return $result; -//} - -//$quesion_list = get_proper_question(); //question_list 获得的是前端可以展示的20个问题的列表 - -echo $user_is_login; - -var_dump($user_info); -var_dump($left_tags); -var_dump($right_rec); -//echo $quesion_list; diff --git a/init.php b/init.php deleted file mode 100644 index d396040..0000000 --- a/init.php +++ /dev/null @@ -1,32 +0,0 @@ -使用QQ登陆"; - $flag = 0; -}else{ - //登陆了 - echo $_SESSION['username']." welcome."; -} \ No newline at end of file diff --git a/oauth/login.php b/oauth/login.php deleted file mode 100644 index 935780f..0000000 --- a/oauth/login.php +++ /dev/null @@ -1,61 +0,0 @@ -'; - - //先判断是不是需要登录 - //如果用户不需要登录,就跳回主页 - if (isset($_SESSION['userid']) && ($_SESSION['userid'] != 0)){ - //跳回主页 - header("Location:/"); - exit; - } - - //QQ用户登录信息页面,用于QQ登录 - if($_GET['state']){ - //登录回调,获取信息 - $token = $t->qq_callback(); - $openid = $t->qq_openid($token); - $tmp = $t->get_user_info($token,$openid); - switch($tmp['gender']){ - case "男": - $sex = 1; - break; - case "女": - $sex = 0; - break; - default: - $sex = -1; - } - $db = new db_sql_functions(); - $userid = $db->update_userinfo($openid,$tmp['nickname'],'$sex',$tmp['figureurl_qq_1']); - if ($userid < 0){ - //失败 - header("Location:/"); - exit; - } - //登录成功,写入session - $_SESSION['userid'] = $userid; - $_SESSION['name'] = $tmp['nickname']; - $_SESSION['sex'] = $sex; - $_SESSION['imgs'] = $tmp['figureurl_qq_1']; - header("Location:/"); - exit; - }else{ - //未登录或者已经登录 - $t->qq_login(); - } -?> - diff --git a/question.php b/question.php deleted file mode 100644 index 2453cee..0000000 --- a/question.php +++ /dev/null @@ -1,33 +0,0 @@ -get_question_detial($qid); -if($detial['status'] == 1){ - $re = $err->has_down(); - return; - -}elseif($detial['status'] == 0){ - $re = $err->has_del(); - return; - -}else{ - $smarty->assign('question', $detial); - $answers = $db->get_answer_lists($qid); - $smarty->assign('answers', $answers); - - $smarty->display('question.tpl'); -} - -?> diff --git a/search.php b/search.php deleted file mode 100644 index be1dd14..0000000 --- a/search.php +++ /dev/null @@ -1,28 +0,0 @@ -search_question_title($key_word); //返回模糊搜索问题的集合 From 8331656181f9040d805b729946b12fd4382c4665 Mon Sep 17 00:00:00 2001 From: wangbo Date: Fri, 14 Aug 2015 17:07:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0init.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/includes/db.class.php | 2 + source/includes/db_function.class.php | 24 +--- source/includes/oauth.class.php | 1 + source/includes/show.function.php | 12 +- source/includes/user.class.php | 180 +++++++++++++------------- source/index.php | 8 +- source/init.php | 32 +++++ source/oauth/index.php | 2 +- source/oauth/login.php | 3 +- source/question.php | 4 +- 10 files changed, 138 insertions(+), 130 deletions(-) create mode 100644 source/init.php diff --git a/source/includes/db.class.php b/source/includes/db.class.php index 4e4ecbf..04da61f 100644 --- a/source/includes/db.class.php +++ b/source/includes/db.class.php @@ -6,6 +6,8 @@ * Time: 下午9:54 */ +require_once "../config/db.config.php"; + class db { //数据库连接信息 private $db; diff --git a/source/includes/db_function.class.php b/source/includes/db_function.class.php index 65f91b2..186255f 100644 --- a/source/includes/db_function.class.php +++ b/source/includes/db_function.class.php @@ -1,7 +1,7 @@ query($sql); - - return $re; - } - /* * 获取问题正文 * 参数:question_id @@ -241,7 +229,6 @@ public function append_answer_comment($answer_id, $add_content) } } - /* * 获取“赞”和“踩”人数 @@ -280,7 +267,7 @@ public function add_answer_vote($answer_id, $user_id, $action) return false; } } - + /* * 删除“赞”或“踩” * 参数:answer_id, user_id, action(0踩,1赞) @@ -337,7 +324,6 @@ public function get_answer_num($question_id) return $re; } - /* * 添加关注 @@ -400,6 +386,7 @@ public function get_follow_id($question_id) } + /************************************/ /* * 添加通知 * 参数:user_id, content, link @@ -443,13 +430,13 @@ public function change_notify_status($notify_id) return $re; } - ////////////////////////////////////////////////////////////////////////////// + /* * 通知符合条件的人 * 参数:question_id * 返回值:userid_lists */ - public function notice_all_user() + public function notice_all_user($question_id) { $sql = "select uid from app_faq_follow where qid=$question_id"; $result = $this->dbconn->query($sql); @@ -457,7 +444,6 @@ public function notice_all_user() return $result; } - /////////////////////////////////////////////////////////////////////////////// /* * json 操作 diff --git a/source/includes/oauth.class.php b/source/includes/oauth.class.php index 5e73146..95d9b67 100644 --- a/source/includes/oauth.class.php +++ b/source/includes/oauth.class.php @@ -4,6 +4,7 @@ * @author connect@qq.com * @copyright © 2013, Tencent Corporation. All rights reserved. */ +require_once "../config/oauth.config.php"; class oauth{ diff --git a/source/includes/show.function.php b/source/includes/show.function.php index 3c07384..3c36e3c 100644 --- a/source/includes/show.function.php +++ b/source/includes/show.function.php @@ -9,9 +9,6 @@ /*根据各个页面的相同的部分抽象出来的共同的函数*/ -require_once('db_function.class.php'); -require_once ('user.class.php'); - /*用户信息部分*/ /*判断用户状态*/ @@ -28,13 +25,8 @@ function get_user_status() //函数返回值为0,说明用户已经登录,否 function get_user_info() //如果用户已经登录,返回用用户的信息,如果没有登录,返回NULL { $user = new user(); - $temp = get_user_login(); - if ($temp == 0) { - $user_info = json_decode($user->user_getinfo()); //user_info展示登录用户的详细信息,name表示姓名,sex表示性别,images表示头像 - } else { - $user_info = NULL; //如果用户没有登录,用户的信息为空 - } - return $user_info; + $temp = json_decode($user->user_get_login()); + return $temp; } diff --git a/source/includes/user.class.php b/source/includes/user.class.php index 1501a9e..32abf82 100644 --- a/source/includes/user.class.php +++ b/source/includes/user.class.php @@ -1,90 +1,90 @@ -userid = $_SESSION['userid']; - $this->name = $_SESSION['name']; - $this->sex = $_SESSION['sex']; - $this->imgs = $_SESSION['imgs']; - $this->ret = 0; - } - else { - $this->userid = 0; - $this->ret = -1; - } - $this->db = new db_sql_functions(); - } - - //תQQ֤û½Ϣ֤ɹture 򷵻false - public function user_login_qq(){ - header("Location:/oauth/login.php"); - return true; - } - - //תڲƽ̨֤û½Ϣ֤ɹture 򷵻false - public function user_login_linux(){ - return false; - } - - //˳ǰûɹture 򷵻false - public function user_login_out(){ - //session - //cookie - session_unset(); - if(isset($_COOKIE[session_name()])){ - setcookie(session_name(),'',time()-3600); - } - session_destroy(); - return true; - } - - //ȡǰ½ûϢ - public function user_get_login(){ - //û - $tmp = array($this->ret,$this->userid,$this->name,$this->sex,$this->imgs); - $tmp = json_encode($tmp); - return $tmp; - } - - //ȡϢ - public function user_getinfo($userid){ - //ͨݿѯû - //get_userinfo - $result = $this->db->get_userinfo($userid); - if ($result){ - $tmp = array("ret"=>"0"); - $t = array_combine($tmp,$result); - return json_encode($t); - }else{ - $tmp = array("ret"=>"-1"); - return json_encode($tmp); - } - } - - //ȡûȨޣݱбʶȨ޵ֶӦֵ - public function user_get_privilege($user_id){ - $result = $this->db->get_userinfo($user_id); - if ($result){ - return $result['privilege']; - } - return false; - } -} \ No newline at end of file +userid = $_SESSION['userid']; + $this->name = $_SESSION['name']; + $this->sex = $_SESSION['sex']; + $this->imgs = $_SESSION['imgs']; + $this->ret = 0; + } + else { + $this->userid = 0; + $this->ret = -1; + } + $this->db = new db_sql_functions(); + } + + //跳转QQ验证用户登陆信息,验证成功返回ture 否则返回false + public function user_login_qq(){ + header("Location:/oauth/login.php"); + return true; + } + + //跳转内部平台验证用户登陆信息,验证成功返回ture 否则返回false + public function user_login_linux(){ + return false; + } + + //退出当前用户,成功返回ture 否则返回false + public function user_login_out(){ + //清除session + //清除cookie + session_unset(); + if(isset($_COOKIE[session_name()])){ + setcookie(session_name(),'',time()-3600); + } + session_destroy(); + return true; + } + + //获取当前登陆用户信息 + public function user_get_login(){ + //返回用户数据 + $tmp = array($this->ret,$this->userid,$this->name,$this->sex,$this->imgs); + $tmp = json_encode($tmp); + return $tmp; + } + + //获取个人资料信息 + public function user_getinfo($userid){ + //通过数据库查询用户数据 + //get_userinfo + $result = $this->db->get_userinfo($userid); + if ($result){ + $tmp = array("ret"=>"0"); + $t = array_combine($tmp,$result); + return json_encode($t); + }else{ + $tmp = array("ret"=>"-1"); + return json_encode($tmp); + } + } + + //获取用户权限,返回数据表中标识权限的字段所对应的值 + public function user_get_privilege($user_id){ + $result = $this->db->get_userinfo($user_id); + if ($result){ + return $result['privilege']; + } + return false; + } +} diff --git a/source/index.php b/source/index.php index 5368fc7..c0e1066 100644 --- a/source/index.php +++ b/source/index.php @@ -6,9 +6,7 @@ * Time: 下午3:28 */ -require_once ('./includes/db_function.class.php'); -require_once ('./includes/user.class.php'); -require_once('./includes/show.function.php'); +require_once './init.php'; /*右上角用户信息部分*/ @@ -19,7 +17,6 @@ /*左侧标签部分*/ $left_tags = get_left_tags(); //left_tags 存储的是左侧标签的数组 - /*右侧推荐部分*/ $right_rec = get_right_rec(); //right_rec 存储的是右侧推荐的集合 @@ -44,6 +41,3 @@ function get_proper_question() $quesion_list = get_proper_question(); //question_list 获得的是前端可以展示的20个问题的列表 - - - diff --git a/source/init.php b/source/init.php new file mode 100644 index 0000000..4207399 --- /dev/null +++ b/source/init.php @@ -0,0 +1,32 @@ +使用QQ登陆"; diff --git a/source/oauth/login.php b/source/oauth/login.php index 4247498..935780f 100644 --- a/source/oauth/login.php +++ b/source/oauth/login.php @@ -6,7 +6,8 @@ * Time: 下午8:00 */ - require_once '../config/oauth.config.php'; +session_start(); + require_once '../includes/oauth.class.php'; require_once "../includes/db_function.class.php"; diff --git a/source/question.php b/source/question.php index bbcfcdc..2453cee 100644 --- a/source/question.php +++ b/source/question.php @@ -7,11 +7,11 @@ */ require_once 'includes/db_function.class.php'; -require_once 'include/errshow.class.php'; +require_once 'includes/errshow.class.php'; $qid = $_GET['q']; -$db = new Db_functions(); +$db = new db_sql_functions(); $err = new Errshow(); $detial = $db->get_question_detial($qid); if($detial['status'] == 1){