Ejemplo n.º 1
0
 function sync_reply()
 {
     $qqwb = jconf::get('qqwb');
     if (!$qqwb['is_syncreply_tojishigou']) {
         return;
     }
     $tid = jget('tid', 'int');
     if ($tid < 1) {
         return;
     }
     $info = DB::fetch_first("select * from " . TABLE_PREFIX . "qqwb_bind_topic where `tid`='{$tid}'");
     if (!$info || !$info['qqwb_id']) {
         return;
     }
     if ($qqwb['syncweibo_tojishigou_time'] > 0 && $info['last_read_time'] + $qqwb['syncweibo_tojishigou_time'] > TIMESTAMP) {
         return;
     }
     if (!($topic_info = DB::fetch_first("select * from " . TABLE_PREFIX . "topic where `tid`='{$tid}'"))) {
         return;
     }
     $uid = (int) $topic_info['uid'];
     if ($uid < 1) {
         return;
     }
     $qqwb_bind_info = qqwb_bind_info($uid);
     if (!$qqwb_bind_info) {
         return;
     }
     if (!qqwb_bind($uid)) {
         return;
     }
     if (!qqwb_syncreply_tojishigou($uid)) {
         return;
     }
     require_once ROOT_PATH . 'include/ext/qqwb/qqoauth.php';
     $QQAuth = new QQOAuth($qqwb['app_key'], $qqwb['app_secret'], $qqwb_bind_info['token'], $qqwb_bind_info['tsecret']);
     $rs = $QQAuth->tReList($info['qqwb_id']);
     $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']);
             $qqwb_username = $data['name'];
             $_type = 2 == $data['type'] ? 'forward' : 'reply';
             if ($qqwb_id && ($bind_info = DB::fetch_first("select * from " . TABLE_PREFIX . "qqwb_bind_info where `qqwb_username`='{$qqwb_username}'")) && !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'] . (2 == $data['type'] && 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('totid' => $tid, 'content' => $content, 'from' => 'qqwb', 'type' => $_type, 'uid' => $bind_info['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']));
                         }
                     }
                 }
             }
         }
     }
     DB::query("update `" . TABLE_PREFIX . "qqwb_bind_topic` set `last_read_time`='" . TIMESTAMP . "' where `tid`='{$tid}'");
     exit;
 }