function tweet_post()
{
    $args = func_get_args();
    $cate = $args[2];
    $content = format_str($_POST['text'], false);
    if (!$cate or !$content) {
        die("Invalid argument!");
    }
    include_once 'sinaoauth.inc.php';
    $c = new WeiboClient(SINA_AKEY, SINA_SKEY, $GLOBALS['user']['sinakey']['oauth_token'], $GLOBALS['user']['sinakey']['oauth_token_secret']);
    if ($_FILES['upload']['tmp_name']) {
        $msg = $c->upload($content, $_FILES['upload']['tmp_name']);
    } else {
        $msg = $c->update($content);
    }
    if ($msg === false || $msg === null) {
        echo "Error occured";
        return false;
    }
    if (isset($msg['error_code']) && isset($msg['error'])) {
        echo 'Error_code: ' . $msg['error_code'] . ';  Error: ' . $msg['error'];
        return false;
    }
    include_once "uuid.inc.php";
    $v4uuid = str_replace("-", "", UUID::v4());
    connect_db();
    $add = "INSERT INTO pending_tweets (\r\n                     site_id, tweet_id, user_site_id, content, post_datetime,\r\n                     type, tweet_site_id,\r\n                     post_screenname, profile_image_url, source)\r\n                     VALUES (1, '{$v4uuid}', '" . $msg['user']['id'] . "', '{$content}', '" . date("Y-m-d H:i:s", strtotime($msg["created_at"])) . "',\r\n                     {$cate}, '" . $msg['id'] . "', '" . $msg["user"]["name"] . "', '" . $msg["user"]["profile_image_url"] . "', '" . $msg["source"] . "')";
    if ($msg['thumbnail_pic']) {
        $add = "INSERT INTO pending_tweets (\r\n                     site_id, tweet_id, user_site_id, content, post_datetime,\r\n                     type, tweet_site_id,\r\n                     post_screenname, profile_image_url, source, thumbnail)\r\n                     VALUES (1, '{$v4uuid}', '" . $msg['user']['id'] . "', '{$content}', '" . date("Y-m-d H:i:s", strtotime($msg["created_at"])) . "',\r\n                     {$cate}, '" . $msg['id'] . "', '" . $msg["user"]["name"] . "', '" . $msg["user"]["profile_image_url"] . "', '" . $msg["source"] . "', '" . $msg['thumbnail_pic'] . "')";
    }
    $added = mysql_query($add) or die("Could not add entry!");
    echo "0";
}
Example #2
0
 protected function update($content)
 {
     $c = $this->getConfig();
     $o = new WeiboClient($c['WB_AKEY'], $c['WB_SKEY'], $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
     $msg = $o->update($content);
     //dump($msg);exit;
     return isset($msg['id']) ? true : false;
 }
Example #3
0
 private function status_bind($id, $text, $pic_id)
 {
     include_once ROOT_DIR . 'lib/user/user.class.php';
     $this->mUser = new user();
     $bind_info = $this->mUser->get_bind_info();
     //获取绑定信息
     include_once ROOT_PATH . 'lib/class/status.class.php';
     $status = new status();
     if (!$bind_info) {
         //do nothing!
     } else {
         //file_put_contents('d:/show.txt', '用户绑定了' , FILE_APPEND);
         $bind_info = $bind_info[0];
         if ($bind_info['state'] == 1 && $bind_info['last_key']) {
             //file_put_contents('d:/show.txt', '用户开启同步了' , FILE_APPEND);
             include_once ROOT_PATH . 'lib/class/weibooauth.class.php';
             $last_key = unserialize($bind_info['last_key']);
             $oauth = new WeiboClient(WB_AKEY, WB_SKEY, $last_key['oauth_token'], $last_key['oauth_token_secret']);
             //$oauth = new WeiboOAuth( WB_AKEY , WB_SKEY , 'e9b1d743a687550cec725e65fd204b6c' , '119934aabf1632d426533505c0f02e70' );
             //判断是否发送了图片
             if ($pic_id) {
                 //file_put_contents('d:/show.txt', '用户发送了图片' , FILE_APPEND);
                 //取出该图片的路径
                 //获取媒体信息
                 $pic_url = $status->getPicById($pic_id);
                 $url = $pic_url[0];
                 //$url = 'http://127.0.0.1/3.jpg';
                 $content = $oauth->upload($text, $url);
             } else {
                 $content = $text;
                 $pattern = "/#([\\x{4e00}-\\x{9fa5}0-9A-Za-z_-\\s‘’“”'\"!\\?\$%&:;!?¥×\\*\\<\\>》《]+)[\\s#]/iu";
                 if (preg_match_all($pattern, $content, $topic)) {
                     include_once ROOT_PATH . 'lib/class/shorturl.class.php';
                     $shorturl = new shorturl();
                     $link = '';
                     $tmp_url = '';
                     $topic_name = array();
                     foreach ($topic[1] as $key => $value) {
                         $tmp_url = SNS_MBLOG . 'k.php?q=' . urlencode($value);
                         $short_url = $shorturl->shorturl($tmp_url);
                         $link .= $short_url;
                     }
                     $content = $content . $link;
                 }
                 //			    	$content = $oauth->post( $oauth->updateURL() , array( 'status' =>  $content) );
                 $content = $oauth->update($content);
                 //同步发送
             }
             $syn_id = $content['id'];
             //返回点滴的ID
             $type = $bind_info['type'];
             //绑定类型
             /**
              * 记录同步发送的点滴id
              */
             $status->syn_relation($id, $syn_id, $type);
         }
     }
 }
Example #4
0
</form>

<h2>发送图片微博</h2>
<form action="weibolist.php" >
<input type="text" name="text" style="width:300px" value="文字内容" />
<input type="text" name="pic" style="width:300px" value="图片url" />
&nbsp;<input type="submit" />
</form>
<?php 
if (isset($_REQUEST['text']) || isset($_REQUEST['avatar'])) {
    if (isset($_REQUEST['pic'])) {
        $rr = $c->upload($_REQUEST['text'], $_REQUEST['pic']);
    } elseif (isset($_REQUEST['avatar'])) {
        $rr = $c->update_avatar($_REQUEST['avatar']);
    } else {
        $rr = $c->update($_REQUEST['text']);
    }
    echo "<p>发送完成</p>";
}
?>

<?php 
if (is_array($ms)) {
    foreach ($ms as $item) {
        ?>
<div style="padding:10px;margin:5px;border:1px solid #ccc">
<?php 
        echo $item['text'];
        ?>
</div>
<?php 
Example #5
0
 public function sentShare($uid, $data)
 {
     global $_FANWE;
     static $client = NULL;
     if ($client === NULL) {
         $uid = (int) $uid;
         $bind = FS("User")->getUserBindByType($uid, 'sina');
         $client = new WeiboClient($this->config['app_key'], $this->config['app_secret'], $bind['oauth_token'], $bind['oauth_token_secret']);
     }
     try {
         $data['content'] .= ' ' . $data['url'];
         if (empty($data['img'])) {
             $msg = $client->update($data['content']);
         } else {
             $msg = $client->upload($data['content'], $data['img']);
         }
         //print_r($msg);
         return true;
     } catch (Exception $e) {
         //print_r($e);
     }
     return false;
 }
Example #6
0
 function sendtalk()
 {
     $weibo = D('Weibobind');
     $ctent = D('Content');
     $user = Action::$login_user;
     $contentid = mysql_insert_id();
     if ($contentid) {
         $content = $ctent->where("content_id='{$contentid}'")->find();
         $text = $content['content_body'];
         $media = $content['media_body'];
         $text = str_replace('&amp;', '&', $text);
         $text = ubbreplace($text);
         $media = ubbreplace($content['media_body']);
         $st = getsubstr($media, 0, 7, false);
         if ($st == 'http://' || $st == '/photo/') {
             if ($st == '/photo/') {
                 $media = __PUBLIC__ . '/attachments' . $media;
                 $media = str_replace('s_', '', $media);
             }
             $text = $text . $media;
         }
         $text = clean_html($text);
     }
     if ($text) {
         $bind = $weibo->where("uid='{$user['user_id']}'")->find();
         if ($bind['sina_uid'] && $bind['sina_token'] && $bind['sina_tsecret'] && $bind['sendtosina'] == 1) {
             $sinawb = new WeiboClient(WB_AKEY, WB_SKEY, $bind['sina_token'], $bind['sina_tsecret']);
             $me = $sinawb->verify_credentials();
             if ($me['id'] == $bind['sina_uid']) {
                 $rssina = $sinawb->update($text);
             }
         }
         if ($bind['qq_uid'] && $bind['qq_token'] && $bind['qq_tsecret'] && $bind['sendtoqq'] == 1) {
             include_once "qqweibo/api_client.php";
             $qqwb = new MBApiClient(MB_AKEY, MB_SKEY, $bind['qq_token'], $bind['qq_tsecret']);
             $me = $qqwb->getUserInfo();
             if ($me['data']['name'] == $bind['qq_uid']) {
                 $p = array('c' => $text, 'ip' => $_SERVER['REMOTE_ADDR'], 'j' => '', 'w' => '');
                 $rsqq = $qqwb->postOne($p);
             }
         }
     }
 }
Example #7
0
/**
 * 发送新浪微博
 */
function sendSinaWeibo($weibocontent, $P)
{
    // 如果没有新浪的授权,直接返回
    if (!$P['sinalastkey']) {
        return;
    }
    $c = new WeiboClient(WB_AKEY, WB_SKEY, $P['sinalastkey']['oauth_token'], $P['sinalastkey']['oauth_token_secret']);
    // 如果有图片,上传图片,发表有图片的微博
    if ($weibocontent['imgurl']) {
        $rtn1 = $c->upload($weibocontent['text'], $weibocontent['imgurl']);
    } else {
        // 发表没有图片的微博
        $rtn = $c->update($weibocontent['text']);
    }
}
Example #8
0
 //get oauth_token
 $mblog = $_POST['sync'];
 if ($video != "") {
     $entry .= $video;
 }
 //if has video then add
 $user = sql_query('SELECT * FROM ' . DB_PREFIX . 'user WHERE username = "******"');
 $user = mysql_fetch_array($user);
 $microblog = unserialize($user['microblog']);
 if (is_array($mblog)) {
     foreach ($mblog as $key => $var) {
         if ($var == 'fanfou') {
             sync_fanfou(strip_tags($entry), $microblog['ff']['name'], $microblog['ff']['pass']);
         } elseif ($var == 'sina') {
             $c = new WeiboClient(WB_AKEY, WB_SKEY, $microblog['sina']['oauth_token'], $microblog['sina']['oauth_token_secret']);
             $c->update($entry);
         } elseif ($var == 'digu') {
             sync_digu(strip_tags($entry), $microblog['dg']['name'], $microblog['dg']['pass']);
         } elseif ($var == 'qq') {
             $tecent = new MBApiClient(MB_AKEY, MB_SKEY, $microblog['qq']['oauth_token'], $microblog['qq']['oauth_token_secret']);
             $p = array('c' => $entry, 'ip' => $_SERVER['REMOTE_ADDR'], 'j' => '', 'w' => '');
             $tecent->postOne($p);
         } elseif ($var == '163') {
             $wangyi = new wy_WeiboClient(WY_AKEY, WY_SKEY, $microblog['163']['oauth_token'], $microblog['163']['oauth_token_secret']);
             $wangyi->update($entry);
         } elseif ($var == 'sohu') {
             sync_sohu($entry, $microblog['sh']['name'], $microblog['sh']['pass']);
         } elseif ($var == 'tumblr') {
             sync_tumblr($entry, $microblog['tumblr']['name'], $microblog['tumblr']['pass']);
         } elseif ($var == 'leihou') {
             sync_leihou($entry, $microblog['lh']['name'], $microblog['lh']['pass']);