function _DBHelper($Query, $action)
 {
     $DBHandler = XWB_plugin::getDB();
     switch ($action) {
         case 1:
             //GET FIRST RECORD
             return $DBHandler->fetch_first($Query);
             break;
         case 2:
             //INSERT, UPDATE, DELETE
             return $DBHandler->query($Query, 'UNBUFFERED') ? TRUE : $this->_ERHelper('4030003');
             break;
         case 3:
             //SELECT
             $RT = $DBHandler->query($Query);
             $RS = array();
             while ($row = $DBHandler->fetch_array($RT)) {
                 $RS[] = $row;
             }
             return $RS;
             break;
         default:
             return $this->_ERHelper('4030002');
     }
 }
 function gc()
 {
     $db = XWB_plugin::getDB();
     $table = XWB_S_TBPRE . 'common_cache';
     $timestamp = time() - 15 * 60;
     $sql = "DELETE FROM `{$table}` WHERE `cachekey` LIKE 'xipct_%' AND `dateline` < '{$timestamp}' ";
     $db->query($sql);
 }
 /**
  * 资源初始化
  * @access public
  * @return xwbSiteUserRegister
  */
 function xwbSiteUserRegister()
 {
     global $_G;
     loaducenter();
     $this->db = XWB_plugin::getDB();
     $this->ip = (string) $_G['clientip'];
     $this->timestamp = TIMESTAMP;
 }
 /**
  * 同步头像到指定的DZX uid,成功则执行一些更新后的操作
  *
  * @param integer $uid DZ uid
  * @return integer 同步结果
  */
 function sync4DX($uid)
 {
     loaducenter();
     $result = $this->syncToUC($uid);
     if ($result >= 0) {
         $db = XWB_plugin::getDB();
         $sql = "UPDATE " . DB::table('common_member') . " SET avatarstatus = '1' WHERE uid='{$uid}'";
         $db->query($sql, 'UNBUFFERED');
     }
     $this->_logFaceSyncResult($result);
 }
Beispiel #5
0
function xwb_setSiteRegister($nickname, $email, $pwd = false)
{
    $db = XWB_plugin::getDB();
    $uid = 0;
    $password = $pwd ? $pwd : rand(100000, 999999);
    $regstatus = jsg_member_register_check_status();
    if ($regstatus['normal_enable'] || true === JISHIGOU_FORCED_REGISTER) {
        $uid = jsg_member_register($nickname, $password, $email);
    }
    $rst = array('uid' => $uid, 'password' => $password);
    return $rst;
}
 /**
  * 构造函数
  */
 function sitePushback2thread()
 {
     $this->_userConfig['ip'] = mysql_real_escape_string(XWB_plugin::getIP());
     $this->_userConfig['uid'] = (int) XWB_plugin::pCfg('pushback_uid');
     $this->_userConfig['username'] = mysql_real_escape_string(XWB_plugin::convertEncoding((string) XWB_plugin::pCfg('pushback_username'), 'UTF-8', XWB_S_CHARSET));
     $this->_userConfig['timestamp'] = (int) TIMESTAMP;
     //DZ已有的变量,直接使用之
     if ($this->_userConfig['uid'] < 1) {
         $this->_userConfig['uid'] = 0;
         $this->_userConfig['username'] = '******';
     }
     $this->_db = XWB_plugin::getDB();
 }
 function step1()
 {
     $tokenhash = '';
     if (!xwb_token::checkInput('g', 'xwbuninstall', false)) {
         echo 'XWB_TOKEN_HASH_CHECK_FAILURE!';
         exit;
     }
     $cfg = $this->getCfg();
     $tips = array();
     $st = true;
     if (!empty($_GET['delete_data'])) {
         //delete db data
         $db = XWB_plugin::getDB();
         foreach ($cfg['db_data'] as $name => $format) {
             $tbSql = sprintf($format, DB::table($name));
             $db->query($tbSql);
             $tips[] = array(1, "删除数据表 [PRE_]{$name} 成功");
         }
         $_GET['delete_data'] = 1;
     } else {
         $tips[] = array(1, "已保留微博插件数据");
         $_GET['delete_data'] = 0;
     }
     $lock_file_output = '论坛目录' . str_replace(dirname(dirname(XWB_P_DATA)), '', $this->v['lock_file']);
     if (false == @unlink($this->v['lock_file'])) {
         $tips[] = array(1, "无法删除或找不到安装锁定文件(位于:{$lock_file_output})。如果文件存在,请自行删除。");
     }
     $showTab = 'uninstall';
     $btn_enable = 'class="btn"';
     $btn_name = $st ? '完成' : '重试';
     if ($st) {
         //根据安装来源给出完成跳转链接
         if ($this->_sess->getInfo('boot_referer') == 'admincp') {
             $installtype = 'SC_' . XWB_S_CHARSET;
             if (version_compare(XWB_S_VERSION, '2', '<')) {
                 //X1.5
                 $link = '../../admin.php?action=plugins&operation=pluginuninstall&dir=sina_xweibo&installtype=' . $installtype . '&finish=1';
             } else {
                 //X2
                 $link = '../../admin.php?action=plugins&operation=pluginuninstall&dir=sina_xweibo_x2&installtype=' . $installtype . '&finish=1';
             }
         } else {
             $link = '../../index.php';
         }
     } else {
         $link = 'uninstall.php?step=1&delete_data=' . $_GET['delete_data'];
     }
     $image_file = $st ? 'sucess.png' : "icon.gif";
     include $this->tpl_dir . '/uninstall.php';
     exit;
 }
function xwb_setSiteUserLogin($uid)
{
    global $_G;
    if (empty($uid)) {
        return false;
    }
    $db = XWB_plugin::getDB();
    //登录
    $member = DB::fetch_first("SELECT * FROM " . DB::table('common_member') . " WHERE uid='" . $uid . "'");
    if (!$member) {
        return false;
    }
    setloginstatus($member, time() + 60 * 60 * 24 ? 2592000 : 0);
    DB::query("UPDATE " . DB::table('common_member_status') . " SET lastip='" . $_G['clientip'] . "', lastvisit='" . time() . "' WHERE uid='{$uid}'");
    include_once libfile('function/stat');
    updatestat('login');
    updatecreditbyaction('daylogin', $uid);
    checkusergroup($uid);
    return true;
}
 /**
  * 将用户帐号导入(主要应对用了UC的多论坛)
  * 本函数主要供_setPushbackSiteAccount方法使用
  * @param array $userInfo uc_get_user返回的数据
  */
 function _importUserFromUC($userInfo)
 {
     $uid = (int) $userInfo[0];
     $db = XWB_plugin::getDB();
     $exist_uid = intval($db->result_first("SELECT uid FROM " . DB::table('common_member') . " WHERE uid='{$userInfo[0]}' LIMIT 0,1 "));
     if ($exist_uid > 0) {
         return true;
     }
     $username = mysql_real_escape_string($userInfo[1]);
     $email = mysql_real_escape_string($userInfo[2]);
     $password = md5(rand(1, 10000));
     $db->query("INSERT IGNORE INTO " . DB::table('common_member') . " (uid, username, password, adminid, groupid, email)\n\t\t\tVALUES ('{$uid}', '{$username}', '{$password}', '0', '10', '{$email}')");
     $db->query("INSERT IGNORE INTO " . DB::table('common_member_status') . " (uid)\n\t\t\tVALUES ('{$uid}')");
     $db->query("INSERT IGNORE INTO " . DB::table('common_member_profile') . " (uid)\n\t\t\tVALUES ('{$uid}')");
     $db->query("INSERT IGNORE INTO " . DB::table('common_member_field_forum') . " (uid)\n\t\t\tVALUES ('{$uid}')");
     $db->query("INSERT IGNORE INTO " . DB::table('common_member_field_home') . " (uid)\n\t\t\tVALUES ('{$uid}')");
     $db->query("INSERT IGNORE INTO " . DB::table('common_member_count') . " (uid)\n\t\t\tVALUES ('{$uid}')");
     manyoulog('user', $this->uid, 'add');
     return true;
 }
 function xwbUserProfile()
 {
     $this->uid = XWB_S_UID;
     $this->db = XWB_plugin::getDB();
 }
 function xwbUserProfile()
 {
     $this->uid = XWB_S_UID;
     $this->db = XWB_plugin::getDB();
     $this->tablepre = XWB_S_TBPRE;
 }
 function siteUserVerifier()
 {
     $this->db = XWB_plugin::getDB();
 }
 function bind()
 {
     if (!XWB_plugin::pCfg('is_account_binding')) {
         XWB_plugin::showError('新浪微博绑定功能已经关闭!');
     }
     if (XWB_S_UID > 0 && XWB_plugin::isUserBinded()) {
         $xwb_user = XWB_plugin::getUser();
         $sina_id = $xwb_user->getInfo('sina_uid');
         $wb = XWB_plugin::getWB();
         $wb->is_exit_error = false;
         $sina_user_info = $wb->getUserShow($sina_id);
         if (isset($sina_user_info['error_code']) || isset($sina_user_info['error'])) {
             include XWB_P_ROOT . '/tpl/xwb_cenbind_error.tpl.php';
         } else {
             $db = XWB_plugin::getDB();
             $share = XWB_plugin::V("R:share");
             $share_msg = '';
             if ($share) {
                 $bind_info = $db->fetch_first("select * from " . XWB_S_TBPRE . "xwb_bind_info where `uid`='" . XWB_S_UID . "'");
                 $share_time = $bind_info['share_time'];
                 if (!$share_time) {
                     $share_time = time();
                     $db->query("update " . XWB_S_TBPRE . "xwb_bind_info set `share_time`='" . $share_time . "' where `uid`='" . XWB_S_UID . "'");
                     jclass('misc')->update_account_bind_info(XWB_S_UID, '', '', 1);
                     $share_msg = "<img src='" . (XWB_plugin::baseUrl() . XWB_plugin::URL('&code=enter&share_time=' . $share_time)) . "' width='0' height='0' />";
                 }
             } else {
                 /**
                  * 分享给好友显示页面
                  */
                 $skip_share = XWB_plugin::V("R:skip_share");
                 if (!$skip_share) {
                     $bind_info = $db->fetch_first("select * from " . XWB_S_TBPRE . "xwb_bind_info where `uid`='" . XWB_S_UID . "'");
                     if (!$bind_info['share_time']) {
                         include XWB_P_ROOT . '/tpl/xwb_cenbind_share.tpl.php';
                         exit;
                     }
                 }
             }
             $screen_name = $sina_user_info['screen_name'];
             $profile = XWB_plugin::O('xwbUserProfile');
             $setting = $profile->get('bind_setting', 1);
             $tojishigou = $profile->get('synctopic_tojishigou', 0);
             $reply_tojishigou = $profile->get('syncreply_tojishigou', 0);
             include XWB_P_ROOT . '/tpl/xwb_cenbind_on.tpl.php';
         }
     } else {
         include XWB_P_ROOT . '/tpl/xwb_cenbind_off.tpl.php';
     }
 }
<?php

/*
 * @version $Id: newcomment2blog.hack.php 836 2011-06-15 01:48:00Z yaoying $
 */
if (!defined('IS_IN_XWB_PLUGIN')) {
    exit('Access Denied!');
}
global $_G;
$blogid = isset($_G['gp_id']) ? (int) $_G['gp_id'] : 0;
//dz在spacecp_comment.php处可能存在漏洞,用了$_POST
$idtype = isset($_G['gp_idtype']) ? (string) $_G['gp_idtype'] : '';
$message = !empty($GLOBALS['message']) ? (string) $GLOBALS['message'] : '';
//评论的上一id
$up_cid = isset($_G['gp_cid']) ? (int) $_G['gp_cid'] : 0;
if ($blogid > 0 && $up_cid == 0 && $idtype == 'blogid') {
    $db = XWB_plugin::getDB();
    $query = $db->query("SELECT * FROM " . DB::table('home_blog') . " WHERE blogid='{$blogid}'");
    $blog = $db->fetch_array($query);
    if (!empty($blog)) {
        $xp_publish = XWB_plugin::N('xwb_plugins_publish');
        register_shutdown_function(array(&$xp_publish, 'blogCommentSync'), $blogid, $blog['uid'], (string) $message);
    }
}
 /**
  * 新增用户绑定关系
  *
  */
 function addBindUser($site_uid, $sina_uid, $access_toke, $token_secret, $nickname = false, $turn = true)
 {
     if ($site_uid < 1) {
         return false;
     }
     $db = XWB_plugin::getDB();
     $site_uid = mysql_escape_string($site_uid);
     $sina_uid = mysql_escape_string($sina_uid);
     $access_toke = mysql_escape_string($access_toke);
     $token_secret = mysql_escape_string($token_secret);
     $sql = "INSERT INTO " . DB::table('xwb_bind_info') . " (`uid`,`sina_uid`,`token`,`tsecret`,`profile`) VALUES('{$site_uid}','{$sina_uid}','{$access_toke}','{$token_secret}','[]')";
     $rst = $db->query($sql, 'UNBUFFERED');
     $switch = XWB_plugin::pCfg('switch_to_xweibo');
     if ($turn && $switch && $rst) {
         $api = XWB_plugin::N('apixwb');
         $api->updateBindUser($site_uid, $sina_uid, $access_toke, $token_secret, $nickname);
     }
     return $rst;
 }
 function authCallBack()
 {
     if (!XWB_plugin::pCfg('is_account_binding')) {
         XWB_plugin::showError('网站管理员关闭了插件功能“新浪微博绑定”。请稍后再试。');
     }
     //--------------------------------------------------------------------
     global $_G;
     $sess = XWB_plugin::getUser();
     $waiting_site_bind = $sess->getInfo('waiting_site_bind');
     if (empty($waiting_site_bind)) {
         //XWB_plugin::deny();
         $siteUrl = XWB_plugin::siteUrl(0);
         XWB_plugin::redirect($siteUrl, 3);
     }
     $sess->setOAuthKey(array(), true);
     //--------------------------------------------------------------------
     $wbApi = XWB_plugin::getWB();
     $db = XWB_plugin::getDB();
     $last_key = $wbApi->getAccessToken(XWB_plugin::V('r:oauth_verifier'));
     //print_r($last_key);
     if (!isset($last_key['oauth_token']) || !isset($last_key['oauth_token_secret'])) {
         $api_error_origin = isset($last_key['error']) ? $last_key['error'] : 'UNKNOWN ERROR. MAYBE SERVER CAN NOT CONNECT TO SINA API SERVER';
         $api_error = isset($last_key['error_CN']) && !empty($last_key['error_CN']) && 'null' != $last_key['error_CN'] ? $last_key['error_CN'] : '';
         XWB_plugin::LOG("[WEIBO CLASS]\t[ERROR]\t#{$wbApi->req_error_count}\t{$api_error}\t{$wbApi->last_req_url}\tERROR ARRAY:\r\n" . print_r($last_key, 1));
         XWB_plugin::showError("服务器获取Access Token失败;请稍候再试。<br />错误原因:{$api_error}[{$api_error_origin}]");
     }
     $sess->setOAuthKey($last_key, true);
     $wbApi->setConfig();
     $uInfo = $wbApi->verifyCredentials();
     $sess->setInfo('sina_uid', $uInfo['id']);
     $sess->setInfo('sina_name', $uInfo['screen_name']);
     //print_r($uInfo);
     //--------------------------------------------------------------------
     /// 此帐号是否已经在当前站点中绑定
     $sinaHasBinded = false;
     $stat_is_bind_type = 0;
     if (defined('XWB_S_UID') && XWB_S_UID > 0) {
         $bInfo = XWB_plugin::getBUById(XWB_S_UID, $uInfo['id']);
     } else {
         $bInfo = XWB_plugin::getBindUser($uInfo['id'], 'sina_uid');
         //远程API
     }
     if (!is_array($bInfo) && (defined('XWB_S_UID') && XWB_S_UID > 0)) {
         $bInfo = XWB_plugin::getBindUser(XWB_S_UID, 'site_uid');
         //登录状态下再查一次API,确保没有绑定
     }
     if (!empty($bInfo) && is_array($bInfo)) {
         $sinaHasBinded = true;
         dsetcookie($this->_getBindCookiesName($bInfo['uid']), (string) $bInfo['sina_uid'], 604800);
         //核查存储的access token是否有更新,有更新则进行自动更新
         if ($bInfo['sina_uid'] == $uInfo['id'] && ($bInfo['token'] != $last_key['oauth_token'] || $bInfo['tsecret'] != $last_key['oauth_token_secret'])) {
             XWB_plugin::updateBindUser($bInfo['uid'], $bInfo['sina_uid'], (string) $last_key['oauth_token'], (string) $last_key['oauth_token_secret'], $uInfo['screen_name']);
             //远程API
         }
     }
     //--------------------------------------------------------------------
     /// 决定在首页中显示什么浮层
     $tipsType = '';
     //xwb_tips_type
     //已在论坛登录
     if (defined('XWB_S_UID') && XWB_S_UID) {
         if ($sinaHasBinded) {
             //$sinaHasBinded为true时,$bInfo必定存在
             if (XWB_S_UID != $bInfo['uid'] || $bInfo['sina_uid'] != $uInfo['id']) {
                 $tipsType = 'hasBinded';
                 $sess->clearToken();
             } else {
                 $tipsType = 'autoLogin';
             }
         } else {
             //远程API
             $rst = XWB_plugin::addBindUser(XWB_S_UID, $uInfo['id'], (string) $last_key['oauth_token'], (string) $last_key['oauth_token_secret'], $uInfo['screen_name']);
             if (!$rst) {
                 echo "DB ERROR";
                 exit;
                 return false;
             }
             $tipsType = 'bind';
             dsetcookie($this->_getBindCookiesName(XWB_S_UID), (string) $uInfo['id'], 604800);
             //正向绑定统计上报
             $sess->appendStat('bind', array('uid' => $uInfo['id'], 'type' => 1));
         }
     } else {
         //从 wb 登录后 检查用户是否绑定,如果绑定了 则在附属站点自
         if ($sinaHasBinded) {
             require_once XWB_P_ROOT . '/lib/xwbSite.inc.php';
             $result = xwb_setSiteUserLogin((int) $bInfo['uid']);
             if (false == $result) {
                 dsetcookie($this->_getBindCookiesName($bInfo['uid']), -1, 604800);
                 XWB_plugin::delBindUser($bInfo['uid']);
                 //远程API
                 $tipsType = 'siteuserNotExist';
             } else {
                 $stat_is_bind_type = 1;
                 $tipsType = 'autoLogin';
             }
         } else {
             //已登录WB,没有附属站点的帐号 引导注册
             $sess->setInfo('waiting_site_reg', '1');
             $tipsType = 'reg';
         }
     }
     //--------------------------------------------------------------------
     //bind的页面需要跳转,故需要使用cookies记录
     if ($tipsType == 'bind') {
         dsetcookie('xwb_tips_type', $tipsType, 0);
     }
     //$sess->setInfo('xwb_tips_type', $tipsType);
     $sess->setInfo('waiting_site_bind', 0);
     //使用sina微博帐号登录成功(不管是否绑定)统计上报
     $sess->appendStat('login', array('uid' => $uInfo['id'], 'is_bind' => $stat_is_bind_type));
     //所有跟站点相关的对接,必须放到_showBinging
     $this->_showBinging($tipsType);
 }
 function _envCheck()
 {
     $tips = array();
     $st = true;
     //-------------------------------------------------------------------
     $tips[] = array(1, '当前系统为: ' . PHP_OS . ' ');
     //各环境版本检查
     if ($this->_verChk(PHP_VERSION, $this->v['php_ver'])) {
         $tips[] = array(1, '当前PHP版本为: ' . PHP_VERSION . ' ');
     } else {
         $st = false;
         $tips[] = array(0, '当前PHP版本为: ' . PHP_VERSION . ' 当前插件支持版本: ' . $this->v['php_ver'][0] . ' - ' . $this->v['php_ver'][1]);
     }
     if ($this->_verChk(XWB_S_VERSION, $this->v['site_ver'])) {
         $tips[] = array(1, '当前' . XWB_S_NAME . '版本为: ' . XWB_S_VERSION . ' ');
     } else {
         $st = false;
         $tips[] = array(0, '当前' . XWB_S_NAME . '版本为: ' . XWB_S_VERSION . ' 当前插件支持版本: ' . $this->v['site_ver'][0] . ' - ' . $this->v['site_ver'][1]);
     }
     $s_charset = str_replace('-', '', strtoupper(XWB_S_CHARSET));
     if (in_array($s_charset, $this->v['charset'])) {
         $tips[] = array(1, '当前' . XWB_S_NAME . '字符集为: ' . $s_charset . ' ');
     } else {
         $st = false;
         $tips[] = array(0, '当前' . XWB_S_NAME . '字符集为: ' . $s_charset . ' 当前插件支持字符集为: ' . implode(',', $this->v['charset']));
     }
     //-------------------------------------------------------------------
     //函数依赖检查
     foreach ($this->v['func_chk'] as $func) {
         if (!is_array($func)) {
             if (function_exists($func)) {
                 $tips[] = array(1, '函数: ' . $func . ' 可用 ');
             } else {
                 $st = false;
                 $tips[] = array(0, '函数: ' . $func . ' 不可用,请开启此函数 ');
             }
         } else {
             $t = false;
             foreach ($func as $fu) {
                 if (function_exists($fu)) {
                     $t = true;
                     break;
                 }
             }
             if ($t) {
                 $tips[] = array(1, '函数: ' . $fu . ' 可用 ');
             } else {
                 $st = false;
                 $tips[] = array(0, '函数: ' . implode(',', $func) . ' 都不可用,插件要求至少有一个可用 ');
             }
         }
     }
     //http适配器特别检查
     if (function_exists('fsockopen')) {
         $tips[] = array(1, '函数: fsockopen 可用 ');
     } elseif (function_exists('curl_exec') && function_exists('curl_init')) {
         $tips[] = array(1, '函数: curl_exec + curl_init 可用 ');
     } else {
         $st = false;
         $tips[] = array(0, '函数fsockopen、或者扩展curl中的curl_exec+curl_init都不可用,插件要求至少有一个组合可用');
     }
     //-------------------------------------------------------------------
     //文件权限检查
     foreach ($this->v['path_chk'] as $p) {
         $t = $this->_writeableChk($p);
         if (!$t[0]) {
             $st = false;
         }
         $tips[] = $t[1];
     }
     //-------------------------------------------------------------------
     $db = XWB_plugin::getDB();
     if (!empty($db) && is_object($db)) {
         $tips[] = array(1, '数据库链接成功! ');
     } else {
         $st = false;
         $tips[] = array(0, '无法使用数据库句柄! ');
     }
     //-------------------------------------------------------------------
     return array($st, $tips);
 }
 /**
  * 构造函数
  */
 function siteBindMapper()
 {
     $this->_db = XWB_plugin::getDB();
 }
 /**
  * 记录某种类型的某个id的微博同步关系
  * @param int $id 要记录的id
  * @param string|float $mid 微博id
  * @param string $type $id所属的类型,可选值'thread','blog','doing', 'article', 'share'
  * @return false|int
  */
 function insertSyncId($id, $mid, $type)
 {
     if (!is_numeric($mid)) {
         return false;
     }
     $type = trim(strtolower($type));
     if (!in_array($type, array('thread', 'blog', 'doing', 'article', 'share'))) {
         return false;
     }
     $db = XWB_plugin::getDB();
     $id = (int) $id;
     $mid = mysql_real_escape_string($mid);
     $sql = "INSERT IGNORE INTO " . DB::table('xwb_bind_thread') . " (`tid`, `mid`, `type`) VALUES('{$id}', '{$mid}', '{$type}')";
     $db->query($sql);
     if ($db->affected_rows()) {
         return true;
     }
     return false;
 }
 /**
  * @return pushbackDispatcher
  */
 function pushbackDispatcher()
 {
     $this->_db = XWB_plugin::getDB();
     $this->_mapper = XWB_Plugin::O('siteBindMapper');
     $this->_thistime = time();
 }
Beispiel #21
0
 /**
  * 获取当前登录用户状态的绑定信息
  * 若当前没有用户登录,则返回false
  * 
  * @param mixed $key 键值。若传入false,则表示返回所有绑定信息
  * @param mixed $def 默认值。若没有值返回,则返回该默认值
  */
 function getBindInfo($key = false, $def = null)
 {
     static $rst = '-1';
     //由于服务器可能返回false或者null,故只能用这个作标识
     if (!XWB_S_UID) {
         return false;
     }
     if ($rst === '-1') {
         $db = XWB_plugin::getDB();
         $rst = $db->fetch_first("SELECT * FROM " . XWB_S_TBPRE . "xwb_bind_info  WHERE  uid=" . XWB_S_UID . " ");
     }
     if ($key === false) {
         return empty($rst) ? array() : $rst;
     } else {
         return isset($rst[$key]) ? $rst[$key] : $def;
     }
 }
Beispiel #22
0
 function authCallBack()
 {
     if (!XWB_plugin::pCfg('is_account_binding')) {
         XWB_plugin::showError('新浪微博绑定功能已经关闭!');
     }
     //--------------------------------------------------------------------
     $sess = XWB_plugin::getUser();
     $waiting_site_bind = $sess->getInfo('waiting_site_bind');
     if (empty($waiting_site_bind)) {
         //XWB_plugin::deny();
         $siteUrl = XWB_plugin::siteUrl(0);
         XWB_plugin::redirect($siteUrl, 3);
     }
     //--------------------------------------------------------------------
     $wbApi = XWB_plugin::getWB();
     $db = XWB_plugin::getDB();
     $last_key = $wbApi->getAccessToken(XWB_plugin::V('r:oauth_verifier'));
     $sess->setOAuthKey(array(), true);
     //		print_r($last_key);
     if (!isset($last_key['oauth_token']) || !isset($last_key['oauth_token_secret'])) {
         $api_error_origin = isset($last_key['error']) ? $last_key['error'] : 'UNKNOWN ERROR. MAYBE SERVER CAN NOT CONNECT TO SINA API SERVER';
         $api_error = isset($last_key['error_CN']) && !empty($last_key['error_CN']) && 'null' != $last_key['error_CN'] ? $last_key['error_CN'] : '';
         XWB_plugin::LOG("[WEIBO CLASS]\t[ERROR]\t#{$wbApi->req_error_count}\t{$api_error}\t{$wbApi->last_req_url}\tERROR ARRAY:\r\n" . print_r($last_key, 1));
         XWB_plugin::showError("服务器获取Access Token失败;请稍候再试。<br />错误原因:{$api_error}[{$api_error_origin}]");
     }
     $sess->setOAuthKey($last_key, true);
     $wbApi->setConfig();
     $uInfo = $wbApi->verifyCredentials();
     $sess->setInfo('sina_uid', $uInfo['id']);
     $sess->setInfo('sina_name', $uInfo['screen_name']);
     //print_r($uInfo);
     //--------------------------------------------------------------------
     /// 此帐号是否已经在当前站点中绑定
     $sinaHasBinded = false;
     if (defined('XWB_S_UID') && XWB_S_UID > 0) {
         $bInfo = $db->fetch_first("SELECT * FROM " . XWB_S_TBPRE . "xwb_bind_info WHERE sina_uid='" . $uInfo['id'] . "' OR uid='" . XWB_S_UID . "'");
     } else {
         $bInfo = $db->fetch_first("SELECT * FROM " . XWB_S_TBPRE . "xwb_bind_info WHERE sina_uid='" . $uInfo['id'] . "'");
     }
     if (!empty($bInfo) && is_array($bInfo)) {
         $sinaHasBinded = true;
         //核查存储的access token是否有更新,有更新则进行自动更新
         if ($bInfo['token'] != $last_key['oauth_token'] || $bInfo['tsecret'] != $last_key['oauth_token_secret']) {
             $db->query("UPDATE " . XWB_S_TBPRE . "xwb_bind_info SET token='" . (string) $last_key['oauth_token'] . "', tsecret='" . (string) $last_key['oauth_token_secret'] . "' WHERE sina_uid='" . $uInfo['id'] . "'");
         }
     }
     //--------------------------------------------------------------------
     /// 决定在首页中显示什么浮层
     $tipsType = '';
     //xwb_tips_type
     //已在论坛登录
     if (defined('XWB_S_UID') && XWB_S_UID) {
         if ($sinaHasBinded) {
             $tipsType = 'hasBinded';
             $sess->clearToken();
         } else {
             $inData = array();
             $inData['uid'] = XWB_S_UID;
             $inData['sina_uid'] = $uInfo['id'];
             $inData['token'] = $last_key['oauth_token'];
             $inData['tsecret'] = $last_key['oauth_token_secret'];
             $inData['profile'] = '[]';
             $sqlF = array();
             $sqlV = array();
             foreach ($inData as $k => $v) {
                 $sqlF[] = "`" . $k . "`";
                 $sqlV[] = "'" . mysql_real_escape_string($v) . "'";
             }
             $sql = "REPLACE INTO " . XWB_S_TBPRE . "xwb_bind_info  (" . implode(",", $sqlF) . ") VALUES (" . implode(",", $sqlV) . ") ;";
             $rst = $db->query($sql, 'UNBUFFERED');
             jclass('misc')->update_account_bind_info(XWB_S_UID, '', '', 1);
             if (!$rst) {
                 echo "DB ERROR";
                 exit;
                 return false;
             }
             $tipsType = 'bind';
             //正向绑定统计上报
             $sess->appendStat('bind', array('uid' => $uInfo['id'], 'type' => 1));
         }
     } else {
         //从 wb 登录后 检查用户是否绑定,如果绑定了 则在附属站点自
         if ($sinaHasBinded) {
             require_once XWB_P_ROOT . '/lib/xwbSite.inc.php';
             $result = xwb_setSiteUserLogin((int) $bInfo['uid']);
             if (!$result) {
                 $db->query("DELETE FROM " . XWB_S_TBPRE . "xwb_bind_info WHERE sina_uid='" . $uInfo['id'] . "'");
                 $tipsType = 'siteuserNotExist';
             } else {
                 $tipsType = 'autoLogin';
             }
         } else {
             //已登录WB,没有附属站点的帐号 引导注册
             $sess->setInfo('waiting_site_reg', '1');
             $tipsType = 'reg';
         }
     }
     //--------------------------------------------------------------------
     //bind的页面需要跳转,故需要使用cookies记录
     if ($tipsType == 'bind') {
         setcookie('xwb_tips_type', $tipsType, 0);
     }
     //$sess->setInfo('xwb_tips_type', $tipsType);
     $sess->setInfo('waiting_site_bind', 0);
     //使用sina微博帐号登录成功(不管是否绑定)统计上报
     $sess->appendStat('login', array('uid' => $uInfo['id']));
     //所有跟站点相关的对接,必须放到_showBinging
     $this->_showBinging($tipsType);
 }
 /**
  * 设置帖子同步标志
  * @param $tid int thread id
  * @param $mid int 微博id
  */
 function _setSynId($tid, $mid)
 {
     $tid = is_numeric($tid) ? $tid : 0;
     $mid = is_numeric($mid) ? $mid : 0;
     if ($tid > 0 && $mid > 0) {
         $db = XWB_plugin::getDB();
         $sql = 'INSERT INTO ' . XWB_S_TBPRE . 'xwb_bind_topic(`tid`,`mid`) VALUES("' . $tid . '", "' . mysql_real_escape_string($mid) . '")';
         $db->query($sql);
         if ($db->affected_rows()) {
             return true;
         }
     }
     return false;
 }
 /**
  * 数据源转数组
  * @param resource $result 数据源
  * @return array $rs 转换后的数组
  */
 function _dbToArray(&$result)
 {
     $rs = array();
     //返回数据集
     if (is_resource($result)) {
         $xwbDBHandler = XWB_plugin::getDB();
         //定义数据库管理器
         // 处理查询数据
         while ($row = $xwbDBHandler->fetch_array($result)) {
             $rs[] = $row;
         }
         //数据集赋值
     }
     return $rs;
     // 返回数据
 }
 /**
  * 生成要发送数据的UC地址。
  *
  * @return string
  */
 function _createUCUrl()
 {
     $db = XWB_plugin::getDB();
     $ucuid = $db->result_first("select `ucuid` from " . XWB_S_TBPRE . "members where `uid`='{$this->uid}' limit 1");
     //最关键的input!必须使用dz函数authcode,并且必须使用Discuz!和UC之间的通讯密钥!
     $ucinput = authcode('uid=' . $ucuid . '&agent=' . md5($_SERVER['HTTP_USER_AGENT']) . '&time=' . time(), 'ENCODE', UC_KEY);
     //PHP4没有http_build_query,只好.......
     $posturl = UC_API . '/index.php?m=user' . '&a=rectavatar' . '&inajax=1' . '&appid=' . UC_APPID . '&agent=' . urlencode(md5($_SERVER['HTTP_USER_AGENT'])) . '&input=' . urlencode($ucinput);
     return $posturl;
 }
 /**
  * 构造函数
  */
 function session_storage_db()
 {
     $this->_db = XWB_plugin::getDB();
 }