X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Ftwitterapi.php;h=ab6c0d62c8a5ec409d6e222e5020d48be41afef3;hb=6aee059033981cbf2499026a8697375fc7987a9e;hp=8f902cbcaf87066ab58cc5d1cd2e693d19145db0;hpb=db587562756483ec285b274adc073df29d4031ae;p=quix0rs-gnu-social.git diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 8f902cbcaf..ab6c0d62c8 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -89,7 +89,7 @@ class TwitterapiAction extends Action $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : null; $twitter_user['protected'] = false; # not supported by Laconica yet - $twitter_user['followers_count'] = $this->count_subscriptions($profile); + $twitter_user['followers_count'] = $profile->subscriberCount(); // To be supported soon... $twitter_user['profile_background_color'] = ''; @@ -98,17 +98,11 @@ class TwitterapiAction extends Action $twitter_user['profile_sidebar_fill_color'] = ''; $twitter_user['profile_sidebar_border_color'] = ''; - $subbed = DB_DataObject::factory('subscription'); - $subbed->subscriber = $profile->id; - $subbed_count = (int) $subbed->count() - 1; - $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0; + $twitter_user['friends_count'] = $profile->subscriptionCount(); $twitter_user['created_at'] = $this->date_twitter($profile->created); - $faves = DB_DataObject::factory('fave'); - $faves->user_id = $user->id; - $faves_count = (int) $faves->count(); - $twitter_user['favourites_count'] = $faves_count; // British spelling! + $twitter_user['favourites_count'] = $profile->faveCount(); // British spelling! // Need to pull up the user for some of this $user = User::staticGet($profile->id); @@ -129,11 +123,7 @@ class TwitterapiAction extends Action $twitter_user['profile_background_image_url'] = ''; $twitter_user['profile_background_tile'] = false; - $notices = DB_DataObject::factory('notice'); - $notices->profile_id = $profile->id; - $notice_count = (int) $notices->count(); - - $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0; + $twitter_user['statuses_count'] = $profile->noticeCount(); // Is the requesting user following this user? $twitter_user['following'] = false; @@ -196,6 +186,24 @@ class TwitterapiAction extends Action $twitter_status['favorited'] = false; } + # Enclosures + $attachments = $notice->attachments(); + + if (!empty($attachments)) { + + $twitter_status['attachments'] = array(); + + foreach ($attachments as $attachment) { + if ($attachment->isEnclosure()) { + $enclosure = array(); + $enclosure['url'] = $attachment->url; + $enclosure['mimetype'] = $attachment->mimetype; + $enclosure['size'] = $attachment->size; + $twitter_status['attachments'][] = $enclosure; + } + } + } + if ($include_user) { # Don't get notice (recursive!) $twitter_user = $this->twitter_user_array($profile, false); @@ -228,11 +236,13 @@ class TwitterapiAction extends Action if($attachments){ $entry['enclosures']=array(); foreach($attachments as $attachment){ - $enclosure=array(); - $enclosure['url']=$attachment->url; - $enclosure['mimetype']=$attachment->mimetype; - $enclosure['size']=$attachment->size; - $entry['enclosures'][]=$enclosure; + if ($attachment->isEnclosure()) { + $enclosure=array(); + $enclosure['url']=$attachment->url; + $enclosure['mimetype']=$attachment->mimetype; + $enclosure['size']=$attachment->size; + $entry['enclosures'][]=$enclosure; + } } } @@ -362,6 +372,9 @@ class TwitterapiAction extends Action case 'text': $this->element($element, null, common_xml_safe_str($value)); break; + case 'attachments': + $this->show_xml_attachments($twitter_status['attachments']); + break; default: $this->element($element, null, $value); } @@ -382,6 +395,20 @@ class TwitterapiAction extends Action $this->elementEnd($role); } + function show_xml_attachments($attachments) { + if (!empty($attachments)) { + $this->elementStart('attachments', array('type' => 'array')); + foreach ($attachments as $attachment) { + $attrs = array(); + $attrs['url'] = $attachment['url']; + $attrs['mimetype'] = $attachment['mimetype']; + $attrs['size'] = $attachment['size']; + $this->element('enclosure', $attrs, ''); + } + $this->elementEnd('attachments'); + } + } + function show_twitter_rss_item($entry) { $this->elementStart('item'); @@ -396,7 +423,7 @@ class TwitterapiAction extends Action $enclosure = $entry['enclosures'][0]; $this->element('enclosure', array('url'=>$enclosure['url'],'type'=>$enclosure['mimetype'],'length'=>$enclosure['size']), null); } - + $this->elementEnd('item'); } @@ -784,6 +811,34 @@ class TwitterapiAction extends Action } } + function get_group($id, $apidata=null) + { + if (empty($id)) { + + if (is_numeric($this->arg('id'))) { + return User_group::staticGet($this->arg('id')); + } else if ($this->arg('id')) { + $nickname = common_canonical_nickname($this->arg('id')); + return User_group::staticGet('nickname', $nickname); + } else if ($this->arg('group_id')) { + // This is to ensure that a non-numeric user_id still + // overrides screen_name even if it doesn't get used + if (is_numeric($this->arg('group_id'))) { + return User_group::staticGet('id', $this->arg('group_id')); + } + } else if ($this->arg('group_name')) { + $nickname = common_canonical_nickname($this->arg('group_name')); + return User_group::staticGet('nickname', $nickname); + } + + } else if (is_numeric($id)) { + return User_group::staticGet($id); + } else { + $nickname = common_canonical_nickname($id); + return User_group::staticGet('nickname', $nickname); + } + } + function get_profile($id) { if (is_numeric($id)) {