X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Ftwitterapi.php;h=4612f74e9faac0ba41d0824f558e666628805f44;hb=6e570a8440108ac0d16253d35543be19b1c2a713;hp=4115d9dcb48d7e908d2a679887c602b908476fac;hpb=0853ed069bb0b323d02cc8fe533ae82c87f68de5;p=quix0rs-gnu-social.git diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 4115d9dcb4..4612f74e9f 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -1,7 +1,7 @@ . */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } @@ -88,7 +88,7 @@ class TwitterapiAction extends Action Avatar::defaultImage(AVATAR_STREAM_SIZE); $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : null; - $twitter_user['protected'] = false; # not supported by Laconica yet + $twitter_user['protected'] = false; # not supported by StatusNet yet $twitter_user['followers_count'] = $profile->subscriberCount(); // To be supported soon... @@ -159,7 +159,7 @@ class TwitterapiAction extends Action $twitter_status = array(); $twitter_status['text'] = $notice->content; - $twitter_status['truncated'] = false; # Not possible on Laconica + $twitter_status['truncated'] = false; # Not possible on StatusNet $twitter_status['created_at'] = $this->date_twitter($notice->created); $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : null; @@ -188,20 +188,20 @@ class TwitterapiAction extends Action // Enclosures $attachments = $notice->attachments(); - $enclosures = array(); - foreach ($attachments as $attachment) { - if ($attachment->isEnclosure()) { - $enclosure = array(); - $enclosure['url'] = $attachment->url; - $enclosure['mimetype'] = $attachment->mimetype; - $enclosure['size'] = $attachment->size; - $enclosures[] = $enclosure; - } - } + if (!empty($attachments)) { - if (!empty($enclosures)) { - $twitter_status['attachments'] = $enclosures; + $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) { @@ -233,6 +233,24 @@ class TwitterapiAction extends Action return $twitter_group; } + function twitter_rss_group_array($group) + { + $entry = array(); + $entry['content']=$group->description; + $entry['title']=$group->nickname; + $entry['link']=$group->permalink(); + $entry['published']=common_date_iso8601($group->created); + $entry['updated']==common_date_iso8601($group->modified); + $taguribase = common_config('integration', 'groupuri'); + $entry['id'] = "group:$groupuribase:$entry[link]"; + + $entry['description'] = $entry['content']; + $entry['pubDate'] = common_date_rfc2822($group->created); + $entry['guid'] = $entry['link']; + + return $entry; + } + function twitter_rss_entry_array($notice) { $profile = $notice->getProfile(); @@ -256,11 +274,12 @@ class TwitterapiAction extends Action $enclosures = array(); foreach ($attachments as $attachment) { - if ($attachment->isEnclosure()) { + $enclosure_o=$attachment->getEnclosure(); + if ($enclosure_o) { $enclosure = array(); - $enclosure['url'] = $attachment->url; - $enclosure['mimetype'] = $attachment->mimetype; - $enclosure['size'] = $attachment->size; + $enclosure['url'] = $enclosure_o->url; + $enclosure['mimetype'] = $enclosure_o->mimetype; + $enclosure['size'] = $enclosure_o->size; $enclosures[] = $enclosure; } } @@ -576,7 +595,6 @@ class TwitterapiAction extends Action $this->init_document('rss'); - $this->elementStart('channel'); $this->element('title', null, $title); $this->element('link', null, $link); if (!is_null($suplink)) { @@ -602,7 +620,6 @@ class TwitterapiAction extends Action } } - $this->elementEnd('channel'); $this->end_twitter_rss(); } @@ -644,6 +661,63 @@ class TwitterapiAction extends Action } + function show_rss_groups($group, $title, $link, $subtitle) + { + + $this->init_document('rss'); + + $this->element('title', null, $title); + $this->element('link', null, $link); + $this->element('description', null, $subtitle); + $this->element('language', null, 'en-us'); + $this->element('ttl', null, '40'); + + if (is_array($group)) { + foreach ($group as $g) { + $twitter_group = $this->twitter_rss_group_array($g); + $this->show_twitter_rss_item($twitter_group); + } + } else { + while ($group->fetch()) { + $twitter_group = $this->twitter_rss_group_array($group); + $this->show_twitter_rss_item($twitter_group); + } + } + + $this->end_twitter_rss(); + } + + function show_atom_groups($group, $title, $id, $link, $subtitle=null, $selfuri=null) + { + + $this->init_document('atom'); + + $this->element('title', null, $title); + $this->element('id', null, $id); + $this->element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), null); + + if (!is_null($selfuri)) { + $this->element('link', array('href' => $selfuri, + 'rel' => 'self', 'type' => 'application/atom+xml'), null); + } + + $this->element('updated', null, common_date_iso8601('now')); + $this->element('subtitle', null, $subtitle); + + if (is_array($group)) { + foreach ($group as $g) { + $this->raw($g->asAtomEntry()); + } + } else { + while ($group->fetch()) { + $this->raw($group->asAtomEntry()); + } + } + + $this->end_document('atom'); + + } + function show_json_timeline($notice) { @@ -668,6 +742,52 @@ class TwitterapiAction extends Action $this->end_document('json'); } + function show_json_groups($group) + { + + $this->init_document('json'); + + $groups = array(); + + if (is_array($group)) { + foreach ($group as $g) { + $twitter_group = $this->twitter_group_array($g); + array_push($groups, $twitter_group); + } + } else { + while ($group->fetch()) { + $twitter_group = $this->twitter_group_array($group); + array_push($groups, $twitter_group); + } + } + + $this->show_json_objects($groups); + + $this->end_document('json'); + } + + function show_xml_groups($group) + { + + $this->init_document('xml'); + $this->elementStart('groups', array('type' => 'array')); + + if (is_array($group)) { + foreach ($group as $g) { + $twitter_group = $this->twitter_group_array($g); + $this->show_twitter_xml_group($twitter_group); + } + } else { + while ($group->fetch()) { + $twitter_group = $this->twitter_group_array($group); + $this->show_twitter_xml_group($twitter_group); + } + } + + $this->elementEnd('groups'); + $this->end_document('xml'); + } + function show_single_json_group($group) { $this->init_document('json'); @@ -820,11 +940,14 @@ class TwitterapiAction extends Action function init_twitter_rss() { $this->startXML(); - $this->elementStart('rss', array('version' => '2.0')); + $this->elementStart('rss', array('version' => '2.0', 'xmlns:atom'=>'http://www.w3.org/2005/Atom')); + $this->elementStart('channel'); + Event::handle('StartApiRss', array($this)); } function end_twitter_rss() { + $this->elementEnd('channel'); $this->elementEnd('rss'); $this->endXML(); } @@ -836,6 +959,7 @@ class TwitterapiAction extends Action $this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en-US', 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0')); + Event::handle('StartApiAtom', array($this)); } function end_twitter_atom() @@ -844,9 +968,9 @@ class TwitterapiAction extends Action $this->endXML(); } - function show_profile($profile, $content_type='xml', $notice=null) + function show_profile($profile, $content_type='xml', $notice=null, $includeStatuses=true) { - $profile_array = $this->twitter_user_array($profile, true); + $profile_array = $this->twitter_user_array($profile, $includeStatuses); switch ($content_type) { case 'xml': $this->show_twitter_xml_user($profile_array);