/** * 评论回推设置:设置评论回推通讯密钥 */ function doCfg4setAuthKey() { if (!defined('XWB_S_IS_ADMIN') || !XWB_S_IS_ADMIN || !XWB_plugin::isRequestBy('POST')) { XWB_plugin::deny(''); } $pushInstance = XWB_Plugin::O('pushbackCommunicator'); $res = $pushInstance->getAuthKey(); if ($res['httpcode'] != 200 || !isset($res['data']['code'])) { $ret = array(0, '向评论回推服务器请求通讯密钥失败,请重试或者向Xweibo求助。'); echo json_encode($ret); } else { //根据以前的评论回推设置,重置评论回推总开关is_pushback_open $is_pushback_open = $this->_checkPushbackOpenConfig(); //注册虚拟账户 $username = '******'; $username_site = XWB_plugin::convertEncoding('微博评论', 'UTF-8', XWB_S_CHARSET); $uid = $this->_setPushbackSiteAccount($username_site); if ($uid > 0) { XWB_Plugin::setPCfg(array('is_pushback_open' => $is_pushback_open, 'pushback_authkey' => strval($res['data']['code']), 'pushback_username' => $username, 'pushback_uid' => $uid)); } else { XWB_Plugin::setPCfg(array('is_pushback_open' => $is_pushback_open, 'pushback_authkey' => strval($res['data']['code']))); } //根据is_pushback_open,进行评论回推服务器定制通知 $pushInstance->changePushbackAuthKey($res['data']['code']); if (1 == $is_pushback_open) { $pushInstance->setPushback('comment'); } else { $pushInstance->cancelPushback(); } $ret = array(1, '开启成功!'); echo json_encode($ret); } }
/** * 根据发送过来的数据,组装出已经转码的、要插入对应数据库的回帖内容 * * @param array $data API发送过来的数据 * @return string 要插入的回帖内容(已经转码) */ function _createContent($data) { //转换为论坛所需要的字符集 if (empty($data['nick'])) { $data['nick'] = '回推'; } $nickname = XWB_plugin::convertEncoding((string) $data['nick'], 'UTF-8', XWB_S_CHARSET); $content = XWB_plugin::convertEncoding((string) $data['text'], 'UTF-8', XWB_S_CHARSET); //DZ函数 $content = dhtmlspecialchars($content); $content = $this->_replaceSinaUrlToUBB($content); $content = $this->_filterContent($content); if (empty($content)) { return ''; } if (isset($data['pic']) && !empty($data['pic'])) { $content .= "\n\n" . '[img]http://ww3.sinaimg.cn/large/' . $data['pic'] . '.jpg[/img]'; } $content = $content . "\n\n" . '[img]' . XWB_plugin::getPluginUrl('images/bgimg/icon_logo.png') . '[/img] ' . '[size=2][color=gray]' . '[url=' . XWB_plugin::getWeiboProfileLink($data['uid']) . ']' . XWB_plugin::L('xwb_reply_from_2', $nickname) . '[/url][/color][/size]'; return $content; }
<div class="active-s1"> <h4>他们已经绑定微博了,你还不行动?</h4> <?php foreach ($huwbUserRs as $value) { ?> <div class="users"> <a href="<?php echo XWB_plugin::getWeiboProfileLink($value['sina_uid']); ?> " target="_blank"><?php echo $value['avatar']; ?> </a> <div class="user-info"> <p><?php echo XWB_plugin::convertEncoding($value['username'], XWB_S_CHARSET, 'UTF-8'); ?> </p> <a class="addfollow-btn" href="<?php echo XWB_plugin::getWeiboProfileLink($value['sina_uid']); ?> " target="_blank"></a> <a class="already-addfollow-btn hidden" href="javascript:void(0)#"></a> </div> </div> <?php } ?> </div> <?php }
runhooks(); //dx的设置文件中有个['output']['forceheader'],为1时会强制输出一个header编码,故只能如此处理,防止干扰插件,但不能做到100%完美 if (0 != $discuz->config['output']['forceheader'] && 'UTF-8' != strtoupper($discuz->config['output']['charset'])) { @header("Content-type: text/html; charset=utf-8"); } //在钩子环境中,可能无法读取$discuz实例,因此要做如此处理 } elseif (!isset($discuz) || !is_a($discuz, 'discuz_core')) { $discuz =& discuz_core::instance(); } $GLOBALS[XWB_SITE_GLOBAL_V_NAME]['site_db'] =& DB::object(); // 附属站点所用的字符集 UTF8 GBK BIG5 define('XWB_S_CHARSET', str_replace("-", "", strtoupper($discuz->config['output']['charset']))); // 附属站点所用的表前缀 define('XWB_S_TBPRE', $discuz->db->tablepre); // 附属站点 的版本号 define('XWB_S_VERSION', substr($discuz->var['setting']['version'], 1)); // 附属站点 的类型名称 define('XWB_S_NAME', 'DiscuzX'); // 附属站点 的标题名称 define('XWB_S_TITLE', XWB_plugin::convertEncoding($discuz->var['setting']['bbname'], XWB_S_CHARSET, 'UTF-8')); // 附属站点 的用户UID define('XWB_S_UID', (int) $discuz->var['uid']); define('XWB_S_IS_ADMIN', (int) $discuz->var['adminid'] == 1 ? true : false); if (!defined('CURSCRIPT') || CURSCRIPT == '') { $XWB_S_CURSCRIPT = isset($_SERVER['SCRIPT_FILENAME']) ? substr(basename($_SERVER['SCRIPT_FILENAME']), 0, -4) : 'unknown'; define('XWB_S_CURSCRIPT', $XWB_S_CURSCRIPT); } else { define('XWB_S_CURSCRIPT', CURSCRIPT); } //echo '<pre>';print_r(get_defined_constants());echo '</pre>';exit; define('XWB_PLUGIN_SITE_ENV_LOADED', true);
/** * 转换为微博可以使用的编码 */ function _convert($msg) { return XWB_plugin::convertEncoding($msg, XWB_S_CHARSET, 'UTF-8'); }
/** * 设置错误提示 * * @param string $error * @return unknown */ function setError($error) { $errmsg = isset($error['error']) ? strtolower($error['error']) : 'UNDEFINED ERROR'; if (strpos($errmsg, 'token_')) { $msg = XWB_plugin::L('xwb_token_error'); } elseif (strpos($errmsg, 'user does not exists')) { $msg = XWB_plugin::L('xwb_user_not_exists'); } elseif (strpos($errmsg, 'target weibo does not exist')) { $msg = XWB_plugin::L('xwb_target_weibo_not_exist'); } elseif (strpos($errmsg, 'weibo id is null')) { $msg = XWB_plugin::L('xwb_weibo_id_null'); } elseif (strpos($errmsg, 'system error')) { $msg = XWB_plugin::L('xwb_system_error'); } elseif (strpos($errmsg, 'consumer_key')) { $msg = XWB_plugin::L('xwb_app_key_error'); } elseif (strpos($errmsg, 'ip request')) { $msg = XWB_plugin::L('xwb_request_reach_api_maxium'); } elseif (strpos($errmsg, 'update comment')) { $msg = XWB_plugin::L('xwb_comment_reach_api_maxium'); } elseif (strpos($errmsg, 'update weibo')) { $msg = XWB_plugin::L('xwb_update_reach_api_maxium'); } elseif (strpos($errmsg, 'high level')) { $msg = XWB_plugin::L('xwb_access_resource_api_denied'); } else { $msg = XWB_plugin::L('xwb_system_error'); } //DEBUG 日志 $req_url = $this->last_req_url; XWB_plugin::LOG("[WEIBO CLASS]\t[ERROR]\t#{$this->req_error_count}\t{$msg}\t{$req_url}\tERROR ARRAY:\r\n" . print_r($error, 1)); //DEBUG END if (!$this->is_exit_error) { return false; } if ('utf8' != strtolower(XWB_S_CHARSET)) { $msg = XWB_plugin::convertEncoding($msg, XWB_S_CHARSET, 'UTF-8'); } XWB_plugin::showError($msg); }
/** * 在未登录论坛帐号,但已登录新浪微博帐号的绑定页面进行用户帐户验证和绑定 */ function doBindAtNotLog() { if (!XWB_plugin::pCfg('is_account_binding')) { XWB_plugin::showError('新浪微博绑定功能已经关闭!'); } $this->_chkIsWaitingForReg(); $usernameS = trim((string) XWB_plugin::V('p:siteBindName')); $password = trim((string) XWB_plugin::V('p:bindPwd')); $username = XWB_plugin::convertEncoding($usernameS, "UTF8", XWB_S_CHARSET); if (!empty($questionanswerS)) { $questionanswer = XWB_plugin::convertEncoding($questionanswerS, "UTF8", XWB_S_CHARSET); } else { $questionanswer = ''; } $uid = 0; //第1关:数据输入验证关 if (empty($username)) { $uid = -102; } if (empty($password)) { $uid = -103; } $msg = ''; //第2关:用户身份验证关 if ($uid == 0) { $verify = XWB_plugin::O('siteUserVerifier'); $verifyresult = $verify->verify($username, $password, $questionid, $questionanswer); $uid = $verifyresult[0]; } if ($uid > 0) { $wbApi = XWB_plugin::getWB(); $uInfo = $wbApi->verifyCredentials(); $db = XWB_plugin::getDB(); //第3关:验证微博帐号是否已经在当前站点中绑定,防止用户通过多个浏览器恶意注册用户 $bInfo = $db->fetch_first("SELECT * FROM " . XWB_S_TBPRE . "xwb_bind_info WHERE sina_uid='" . $uInfo['id'] . "' or uid='" . $uid . "'"); if (!empty($bInfo) && is_array($bInfo)) { $uid = -201; } else { $sess = XWB_plugin::getUser(); $sess->setInfo('sina_uid', $uInfo['id']); $last_key = $sess->getOAuthKey(true); $inData = array(); $inData['uid'] = $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 = "INSERT INTO " . XWB_S_TBPRE . "xwb_bind_info (" . implode(",", $sqlF) . ") VALUES (" . implode(",", $sqlV) . ") ;"; $rst = $db->query($sql, 'UNBUFFERED'); require_once XWB_P_ROOT . '/lib/xwbSite.inc.php'; xwb_setSiteUserLogin($uid); setcookie('xwb_tips_type', '', 0); $sess->setInfo('waiting_site_reg', '0'); jclass('misc')->update_account_bind_info($uid, '', '', 1); $msg = "绑定 " . XWB_S_TITLE . " 帐号成功。下次你可以继续使用新浪微博帐号登录使用 " . XWB_S_TITLE . " 。"; $msg .= "<br>绑定帐号: <em>" . htmlspecialchars($usernameS) . "</em> "; //正向绑定(在未登录论坛帐号已登录新浪微博帐号的绑定页面)统计上报 $sess->appendStat('bind', array('uid' => $uInfo['id'], 'type' => 1)); } } if ($uid <= 0) { $msg = $this->_getBindTip($uid); } $this->_oScript('xwbSetTips', array($uid, $msg, 1)); }
function setError($error) { if (!$this->error_exit) { return; } $err = array('Access time failure' => '请求时间失效', 'Signature is not correct' => '签名不正确', 'Request path is not correct' => '请求路径不正确', 'Save faileds' => '数据保存失败', 'Update faileds' => '数据更新失败'); $errmsg = isset($error['error']) ? strtolower($error['error']) : 'UNDEFINED ERROR'; $msg = isset($err[$errmsg]) ? $err[$errmsg] : '未知错误'; if ('utf8' != strtolower(XWB_S_CHARSET)) { $msg = XWB_plugin::convertEncoding($msg, XWB_S_CHARSET, 'UTF-8'); } XWB_plugin::showError($msg); }
/** * 在未登录论坛帐号,但已登录新浪微博帐号的绑定页面进行用户账户验证和绑定 */ function doBindAtNotLog() { if (!XWB_plugin::pCfg('is_account_binding') || !XWB_plugin::isRequestBy('POST')) { XWB_plugin::showError('网站管理员关闭了插件功能“新浪微博绑定”。请稍后再试。'); } $this->_chkIsWaitingForReg(); $usernameS = trim((string) XWB_plugin::V('p:siteBindName')); $password = trim((string) XWB_plugin::V('p:bindPwd')); $questionid = (int) XWB_plugin::V('p:questionid'); $questionanswerS = trim((string) XWB_plugin::V('p:questionanswer')); $username = XWB_plugin::convertEncoding($usernameS, "UTF8", XWB_S_CHARSET); if (!empty($questionanswerS)) { $questionanswer = XWB_plugin::convertEncoding($questionanswerS, "UTF8", XWB_S_CHARSET); } else { $questionanswer = ''; } $uid = 0; //第1关:数据输入验证关 if (empty($username)) { $uid = -102; } if (empty($password)) { $uid = -103; } $msg = ''; //第2关:用户身份验证关 if ($uid == 0) { $verify = XWB_plugin::O('siteUserVerifier'); $verifyresult = $verify->verify($username, $password, $questionid, $questionanswer); $uid = $verifyresult[0]; } if ($uid > 0) { $wbApi = XWB_plugin::getWB(); $uInfo = $wbApi->verifyCredentials(); //第3关:验证微博帐号是否已经在当前站点中绑定,防止用户通过多个浏览器恶意注册用户 $bInfo = XWB_plugin::getBUById($uid, $uInfo['id']); //远程API if (!empty($bInfo) && is_array($bInfo)) { $uid = -201; } else { $sess = XWB_plugin::getUser(); $sess->setInfo('sina_uid', $uInfo['id']); $last_key = $sess->getOAuthKey(true); $rst = XWB_plugin::addBindUser($uid, $uInfo['id'], (string) $last_key['oauth_token'], (string) $last_key['oauth_token_secret'], $uInfo['screen_name']); //远程API require_once XWB_P_ROOT . '/lib/xwbSite.inc.php'; xwb_setSiteUserLogin($uid); dsetcookie($this->_getBindCookiesName($uid), (string) $uInfo['id'], 604800); dsetcookie('xwb_tips_type', '', 0); $sess->setInfo('waiting_site_reg', '0'); $msg = "绑定论坛帐号成功。下次你可以继续使用新浪微博帐号登录使用" . XWB_S_TITLE . "论坛。"; $msg .= "<br>绑定帐号: <em>" . htmlspecialchars($usernameS) . "</em> "; //正向绑定(在未登录论坛帐号已登录新浪微博帐号的绑定页面)统计上报 $sess->appendStat('bind', array('uid' => $uInfo['id'], 'type' => 1)); //输出UCenter同步JS global $_G; loaducenter(); $ucsynlogin = $_G['setting']['allowsynlogin'] ? uc_user_synlogin($_G['uid']) : ''; $this->_outputUJ($ucsynlogin); } } if ($uid <= 0) { $msg = $this->_getBindTip($uid); } $displayWindow = 0; $this->_oScript('xwbSetTips', array($uid, $msg, $displayWindow)); }
} */ return $return; } //插件appkey定义 define('XWB_APP_KEY', $GLOBALS['_J']['config']['sina']['app_key'] ? $GLOBALS['_J']['config']['sina']['app_key'] : '3015840342'); define('XWB_APP_SECRET_KEY', $GLOBALS['_J']['config']['sina']['app_secret'] ? $GLOBALS['_J']['config']['sina']['app_secret'] : '484175eda3cf0da583d7e7231c405988'); /** * 定义记事狗相关的常量 * */ define('XWB_S_CHARSET', str_replace("-", "", strtoupper($GLOBALS['_J']['config']['charset']))); define('XWB_S_TBPRE', $GLOBALS['_J']['config']['db_table_prefix']); define('XWB_S_VERSION', '2.5.0'); define('XWB_S_NAME', 'JishiGou'); define('XWB_S_TITLE', XWB_plugin::convertEncoding($GLOBALS['_J']['config']['site_name'], XWB_S_CHARSET, 'UTF-8')); define('XWB_S_SITEURL', $GLOBALS['_J']['config']['site_url'] . "/"); /** * 初始化记事狗数据库操作类 */ if (!$GLOBALS[XWB_SITE_GLOBAL_V_NAME]['site_db']) { include_once XWB_P_ROOT . '/lib/xwbDB.class.php'; $GLOBALS[XWB_SITE_GLOBAL_V_NAME]['site_db'] = new xwbDB(); $GLOBALS[XWB_SITE_GLOBAL_V_NAME]['site_db']->connect($GLOBALS['_J']['config']['db_host'], $GLOBALS['_J']['config']['db_user'], $GLOBALS['_J']['config']['db_pass'], $GLOBALS['_J']['config']['db_name'], $GLOBALS['_J']['config']['db_persist'], true, XWB_S_CHARSET); } /** * 初始化记事狗系统的用户登录信息 */ if (!defined('MEMBER_ID')) { $jsg_authcode = $_COOKIE["{$GLOBALS['_J']['config']['cookie_prefix']}auth"]; list($jsg_password, $jsg_uid) = $jsg_authcode ? explode("\t", authcode($jsg_authcode, 'DECODE')) : array('', '', 0);
/** * 根据发送过来的数据,组装出已经转码的、要插入对应数据库的回帖内容 * * @param array $data API发送过来的数据 * @return string 要插入的回帖内容(已经转码) */ function _createContent($data) { //转换为论坛所需要的字符集 if (empty($data['nick'])) { $data['nick'] = '回推'; } $nickname = XWB_plugin::convertEncoding((string) $data['nick'], 'UTF-8', XWB_S_CHARSET); $content = XWB_plugin::convertEncoding((string) $data['text'], 'UTF-8', XWB_S_CHARSET); //DZ函数 $content = dhtmlspecialchars($content); $content = $this->_replaceSinaUrlToHTML($content); $content = $this->_filterContent($content); if (empty($content)) { return ''; } if (isset($data['pic']) && !empty($data['pic'])) { $content .= "<br />" . '<img src="chttp://ww3.sinaimg.cn/large/' . $data['pic'] . '.jpg" />'; } $content = '<img src="' . XWB_plugin::getPluginUrl('images/bgimg/icon_logo.png') . '" />' . $nickname . '(<a href="' . XWB_plugin::getWeiboProfileLink($data['uid']) . '" target="_blank">' . XWB_plugin::L('xwb_weibo') . '</a>): ' . $content; return $content; }