Esempio n. 1
0
 /**
  * 
  * @param $uid
  * @param $site
  * @param $content
  * @param $image
  * @return unknown_type
  */
 private function _sync_weibo($sync, $uid, $site, $title, $description, $image, $location)
 {
     $res = array();
     if (is_array($sync) && count($sync) > 0 && $title && $description && $image) {
         if ($sync['weibo']) {
             require_once Kohana::find_file('vendor', 'weibo/saetv2.ex.class');
             $oauth = Kohana::config('uap.oauth');
             $token = Bind_Model::instance()->oauth2_check($uid, 'weibo');
             $updated_time = $token['updated'] ? $token['updated'] : $token['created'];
             if ($updated_time + $token['expires_in'] > time()) {
                 $c = new SaeTClientV2($oauth['weibo.com']['WB_AKEY'], $oauth['weibo.com']['WB_SKEY'], $token['access_token']);
                 if ($c) {
                     $img = $this->model->_warp_image($image);
                     $img_url = $img[0]['url'] ? $img[0]['url'] : '';
                     $content = '#' . $title . '#' . $description;
                     $content = str::strLen($content) > 120 ? str::cnSubstr($content, 0, 120) . '..' : $content;
                     //$img_url = 'http://momoimg.com/photo/3846870_LrurOnCRM365Gc_cI0ferPZaqFP2hLDtdsB2R1WtHFsrGiLDQ647LfN09AM_780.jpg';
                     $latitude = $location['latitude'] ? $location['latitude'] : NULL;
                     $longitude = $location['longitude'] ? $location['longitude'] : NULL;
                     if ($img_url) {
                         $result = $c->upload($content, $img_url, $latitude, $longitude);
                     } else {
                         $result = $c->update($content, $latitude, $longitude);
                     }
                     if ($result['id']) {
                         $res = array('weibo' => 1);
                     } else {
                         $res = array('weibo' => 0, 'error' => $result['error'], 'type' => 'error');
                     }
                 }
             } else {
                 $res = array('weibo' => 0, 'error' => 'access_token expired!', 'type' => 'expire');
             }
         }
     }
     return $res;
 }