]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/twitterapi.php
Added a url field to hold the permalink. I believe this field is very useful for...
[quix0rs-gnu-social.git] / lib / twitterapi.php
index ce188e00d896b3347e034a14191f72da3333f349..e6af33e8289fe78de0f7d07b236712a12248a269 100644 (file)
@@ -186,6 +186,24 @@ class TwitterapiAction extends Action
             $twitter_status['favorited'] = false;
         }
 
+        // 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($enclosures)) {
+            $twitter_status['attachments'] = $enclosures;
+        }
+
         if ($include_user) {
             # Don't get notice (recursive!)
             $twitter_user = $this->twitter_user_array($profile, false);
@@ -195,12 +213,32 @@ class TwitterapiAction extends Action
         return $twitter_status;
     }
 
+    function twitter_group_array($group)
+    {
+        $twitter_group=array();
+        $twitter_group['id']=$group->id;
+        $twitter_group['url']=$group->permalink();
+        $twitter_group['nickname']=$group->nickname;
+        $twitter_group['fullname']=$group->fullname;
+        $twitter_group['homepage_url']=$group->homepage_url;
+        $twitter_group['original_logo']=$group->original_logo;
+        $twitter_group['homepage_logo']=$group->homepage_logo;
+        $twitter_group['stream_logo']=$group->stream_logo;
+        $twitter_group['mini_logo']=$group->mini_logo;
+        $twitter_group['homepage']=$group->homepage;
+        $twitter_group['description']=$group->description;
+        $twitter_group['location']=$group->location;
+        $twitter_group['created']=$this->date_twitter($group->created);
+        $twitter_group['modified']=$this->date_twitter($group->modified);
+        return $twitter_group;
+    }
+
     function twitter_rss_entry_array($notice)
     {
         $profile = $notice->getProfile();
         $entry = array();
 
-        # We trim() to avoid extraneous whitespace in the output
+        // We trim() to avoid extraneous whitespace in the output
 
         $entry['content'] = common_xml_safe_str(trim($notice->rendered));
         $entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
@@ -213,12 +251,31 @@ class TwitterapiAction extends Action
         $entry['updated'] = $entry['published'];
         $entry['author'] = $profile->getBestName();
 
-        # Enclosure
+        // 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($enclosures)) {
+            $entry['enclosures'] = $enclosures;
+        }
+
+/*
+        // Enclosure
         $attachments = $notice->attachments();
         if($attachments){
             $entry['enclosures']=array();
             foreach($attachments as $attachment){
-                if (isset($attachment->filename)) {
+                if ($attachment->isEnclosure()) {
                     $enclosure=array();
                     $enclosure['url']=$attachment->url;
                     $enclosure['mimetype']=$attachment->mimetype;
@@ -227,8 +284,20 @@ class TwitterapiAction extends Action
                 }
             }
         }
+*/
 
-        # RSS Item specific
+        // Tags/Categories
+        $tag = new Notice_tag();
+        $tag->notice_id = $notice->id;
+        if ($tag->find()) {
+            $entry['tags']=array();
+            while ($tag->fetch()) {
+                $entry['tags'][]=$tag->tag;
+            }
+        }
+        $tag->free();
+
+        // RSS Item specific
         $entry['description'] = $entry['content'];
         $entry['pubDate'] = common_date_rfc2822($notice->created);
         $entry['guid'] = $entry['link'];
@@ -354,6 +423,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);
             }
@@ -361,6 +433,15 @@ class TwitterapiAction extends Action
         $this->elementEnd('status');
     }
 
+    function show_twitter_xml_group($twitter_group)
+    {
+        $this->elementStart('group');
+        foreach($twitter_group as $element => $value) {
+            $this->element($element, null, $value);
+        }
+        $this->elementEnd('group');
+    }
+
     function show_twitter_xml_user($twitter_user, $role='user')
     {
         $this->elementStart($role);
@@ -374,6 +455,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');
@@ -388,6 +483,12 @@ class TwitterapiAction extends Action
             $enclosure = $entry['enclosures'][0];
             $this->element('enclosure', array('url'=>$enclosure['url'],'type'=>$enclosure['mimetype'],'length'=>$enclosure['size']), null);
         }
+        
+        if($entry['tags']){
+            foreach($entry['tags'] as $tag){
+                $this->element('category', null,$tag);
+            }
+        }
 
         $this->elementEnd('item');
     }
@@ -567,6 +668,22 @@ class TwitterapiAction extends Action
         $this->end_document('json');
     }
 
+    function show_single_json_group($group)
+    {
+        $this->init_document('json');
+        $twitter_group = $this->twitter_group_array($group);
+        $this->show_json_objects($twitter_group);
+        $this->end_document('json');
+    }
+
+    function show_single_xml_group($group)
+    {
+        $this->init_document('xml');
+        $twitter_group = $this->twitter_group_array($group);
+        $this->show_twitter_xml_group($twitter_group);
+        $this->end_document('xml');
+    }
+
     // Anyone know what date format this is?
     // Twitter's dates look like this: "Mon Jul 14 23:52:38 +0000 2008" -- Zach
     function date_twitter($dt)