Beispiel #1
0
 function sync_weibo()
 {
     $qqwb = jconf::get('qqwb');
     if (!$qqwb['is_synctopic_tojishigou']) {
         return;
     }
     $info = array();
     $uid = jget('uid', 'int');
     if ($uid < 1) {
         $uid = MEMBER_ID;
     }
     if ($uid < 1) {
         return;
     }
     $info = qqwb_bind_info($uid);
     if (!$info) {
         return;
     }
     if (!qqwb_bind($uid)) {
         return;
     }
     $uid = (int) $info['uid'];
     if ($uid < 1) {
         return;
     }
     $qqwb_username = $info['qqwb_username'];
     if (!$qqwb_username) {
         return;
     }
     if (!qqwb_syncweibo_tojishigou($uid)) {
         return;
     }
     if ($qqwb['syncweibo_tojishigou_time'] > 0 && $info['last_read_time'] + $qqwb['syncweibo_tojishigou_time'] > TIMESTAMP) {
         return;
     }
     $member = DB::fetch_first("select * from " . TABLE_PREFIX . "members where `uid`='{$uid}'");
     if (!$member) {
         return;
     }
     require_once ROOT_PATH . 'include/ext/qqwb/qqoauth.php';
     $QQAuth = new QQOAuth($qqwb['app_key'], $qqwb['app_secret'], $info['token'], $info['tsecret']);
     $rs = $QQAuth->statusesUserTimeline($info['qqwb_username']);
     $datas = $rs['data']['info'];
     if ($datas) {
         krsort($datas);
         $TopicLogic = jlogic('topic');
         foreach ($datas as $data) {
             $qqwb_id = $data['idstr'] ? $data['idstr'] : ($data['qqwb_id'] ? $data['qqwb_id'] : $data['id']);
             if ($qqwb_id && !DB::fetch_first("select * from " . TABLE_PREFIX . "qqwb_bind_topic where `qqwb_id`='{$qqwb_id}'") && ($content = trim(strip_tags(array_iconv('utf-8', $this->Config['charset'], $data['origtext'] . (isset($data['source']['origtext']) ? " /" . "/@{$data['source']['name']}: {$data['source']['origtext']}" : "")))))) {
                 DB::query("insert into " . TABLE_PREFIX . "qqwb_bind_topic (`qqwb_id`) values ('{$qqwb_id}')");
                 $_t = $data['timestamp'] ? $data['timestamp'] : TIMESTAMP;
                 $add_datas = array('content' => $content, 'from' => 'qqwb', '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 > 0) {
                         DB::query("replace into " . DB::table('qqwb_bind_topic') . " (`tid`, `qqwb_id`) values ('{$tid}', '{$qqwb_id}')");
                         if ($qqwb['is_syncimage_tojishigou'] && $data['image']) {
                             $TopicLogic->_parse_url_image($add_result, $this->_img($data['image']));
                         }
                         if ($qqwb['is_syncimage_tojishigou'] && $data['source']['image']) {
                             $TopicLogic->_parse_url_image($add_result, $this->_img($data['source']['image']));
                         }
                     }
                 }
             }
         }
     }
     DB::query("update " . TABLE_PREFIX . "qqwb_bind_info set `last_read_time`='" . TIMESTAMP . "',`last_read_id`='{$qqwb_id}' where `qqwb_username`='{$qqwb_username}'");
     $this->_update($uid);
     exit;
 }