Exemplo n.º 1
0
 function SyncTopic()
 {
     $sina = jconf::get('sina');
     if (!$sina['is_synctopic_tojishigou']) {
         return;
     }
     $info = array();
     $uid = max(0, (int) ($this->Post['uid'] ? $this->Post['uid'] : $this->Get['uid']));
     if (!$uid) {
         $uid = MEMBER_ID;
     }
     if (!$uid) {
         return;
     }
     $info = sina_weibo_bind_info($uid);
     if (!$info) {
         return;
     }
     if (!sina_weibo_bind($uid)) {
         return;
     }
     $uid = max(0, (int) $info['uid']);
     if (!$uid) {
         return;
     }
     $sina_uid = $info['sina_uid'];
     if (!$sina_uid) {
         return;
     }
     if (!sina_weibo_synctopic_tojishigou($uid)) {
         return;
     }
     if ($sina['syncweibo_tojishigou_time'] > 0 && $info['last_read_time'] + $sina['syncweibo_tojishigou_time'] > time()) {
         return;
     }
     $member = DB::fetch_first("select * from " . TABLE_PREFIX . "members where `uid`='{$uid}'");
     if (!$member) {
         return;
     }
     if (!$this->MemberHandler->HasPermission('xwb', '__synctopic', 0, $uid)) {
         return;
     }
     if ($this->module_config['oauth2_enable']) {
         $p = array('uid' => $sina_uid, 'access_token' => $info['access_token']);
         $rets = sina_weibo_api('2/statuses/user_timeline', $p, 'GET');
         $datas = $rets['statuses'];
     } else {
         require_once ROOT_PATH . 'include/ext/xwb/sina.php';
         $wb = XWB_plugin::getWB();
         $datas = $wb->getUserTimeline(null, $sina_uid);
     }
     if ($datas) {
         krsort($datas);
         $TopicLogic = jlogic('topic');
         foreach ($datas as $data) {
             $mid = $data['idstr'] ? $data['idstr'] : ($data['mid'] ? $data['mid'] : $data['id']);
             if ($mid && !DB::fetch_first("select * from " . TABLE_PREFIX . "xwb_bind_topic where `mid`='{$mid}'") && ($content = trim(strip_tags(array_iconv('utf-8', $this->Config['charset'], $data['text'] . (isset($data['retweeted_status']) ? " /" . "/@{$data['retweeted_status']['user']['name']}: {$data['retweeted_status']['text']}" : "")))))) {
                 DB::query("insert into " . TABLE_PREFIX . "xwb_bind_topic (`mid`) values ('{$mid}')");
                 $_t = time();
                 if ($data['created_at']) {
                     $_t = strtotime($data['created_at']);
                 }
                 $_t = is_numeric($_t) ? $_t : 0;
                 $add_datas = array('content' => $content, 'from' => 'sina', 'type' => 'first', 'uid' => $uid, 'timestamp' => $_t);
                 $add_result = $TopicLogic->Add($add_datas);
                 if (is_array($add_result) && count($add_result)) {
                     $tid = max(0, (int) $add_result['tid']);
                     if ($tid) {
                         if ($sina['is_syncimage_tojishigou'] && $data['original_pic']) {
                             $TopicLogic->_parse_url_image($add_result, $data['original_pic']);
                         }
                         if ($sina['is_syncimage_tojishigou'] && $data['retweeted_status']['original_pic']) {
                             $TopicLogic->_parse_url_image($add_result, $data['retweeted_status']['original_pic']);
                         }
                         DB::query("replace into " . DB::table('xwb_bind_topic') . " (`tid`, `mid`) values ('{$tid}', '{$mid}')");
                     }
                 }
             }
         }
     }
     DB::query("update " . TABLE_PREFIX . "xwb_bind_info set `last_read_time`='" . time() . "',`last_read_id`='{$mid}' where `sina_uid`='{$sina_uid}'");
     $this->_update($uid);
 }
Exemplo n.º 2
0
function sina_weibo_bind_icon($uid = 0)
{
    $return = '';
    $uid = max(0, (int) ($uid ? $uid : MEMBER_ID));
    if ($uid > 0 && ($sys_config = sina_weibo_enable())) {
        $return = "<img src='{$sys_config['site_url']}/images/xwb/bgimg/sinawebo_off.gif' alt='未绑定新浪微博' />";
        if (sina_weibo_bind($uid, !rand(0, 10))) {
            $return = "<img src='{$sys_config['site_url']}/images/xwb/bgimg/sinawebo_on.gif' alt='已经绑定新浪微博' />";
            if ($sys_config['sina']['is_synctopic_tojishigou'] && sina_weibo_synctopic_tojishigou($uid)) {
                $_read_now = true;
                if ($sys_config['sina']['syncweibo_tojishigou_time'] > 0) {
                    $xwb_bind_info = sina_weibo_bind_info($uid);
                    if ($xwb_bind_info['last_read_time'] + $sys_config['sina']['syncweibo_tojishigou_time'] > time()) {
                        $_read_now = false;
                    }
                }
                if ($_read_now && !jaccess('xwb', '__synctopic', $uid)) {
                    $_read_now = false;
                }
                if ($_read_now) {
                    $return .= "<img src='{$sys_config['site_url']}/index.php?mod=xwb&code=synctopic&uid={$uid}' width='0' height='0' style='display:none' />";
                }
            }
            if ($sys_config['sina']['is_syncreply_tojishigou'] && is_numeric($_GET['code']) && sina_weibo_syncreply_tojishigou($uid) && ($xwb_bind_topic = sina_weibo_bind_topic($_GET['code'])) && ($topic_info = DB::fetch_first("select * from " . TABLE_PREFIX . "topic where `tid`='{$_GET['code']}'"))) {
                $_read_now = true;
                if ($sys_config['sina']['syncweibo_tojishigou_time'] > 0) {
                    if ($xwb_bind_topic['last_read_time'] + $sys_config['sina']['syncweibo_tojishigou_time'] > time()) {
                        $_read_now = false;
                    }
                }
                if ($_read_now && !jaccess('xwb', '__syncreply', $topic_info['uid'])) {
                    $_read_now = false;
                }
                if ($_read_now) {
                    $return .= "<img src='{$sys_config['site_url']}/index.php?mod=xwb&code=syncreply&tid={$_GET['code']}' width='0' height='0' style='display:none' />";
                }
            }
        }
        if (MEMBER_ID > 0) {
            $return = "<a href='#' title='新浪微博绑定设置' onclick=\"window.location.href='{$sys_config['site_url']}/index.php?mod=account&code=sina';return false;\">{$return}</a>";
        }
    }
    return $return;
}