]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Twitter-compatible API - don't strip XML-illegal chars from JSON output
authorzach <zach@controlyourself.ca>
Thu, 6 Nov 2008 22:57:21 +0000 (17:57 -0500)
committerzach <zach@controlyourself.ca>
Thu, 6 Nov 2008 22:57:21 +0000 (17:57 -0500)
darcs-hash:20081106225721-462f3-b80ba75f87a4b36b803868653c956c393a236626.gz

actions/twitapidirect_messages.php
lib/twitterapi.php

index d6eaf844e9120ba1f9e0bddf6b210769fc603b48..a0a09a4108dc02d06efc30f0008035dd4bbc5be3 100644 (file)
@@ -133,8 +133,8 @@ class Twitapidirect_messagesAction extends TwitterapiAction {
                                $code = 403, $apidata['content-type']);
                        return;
                }
-               
-               $message = Message::saveNew($user->id, $other->id, 
+
+               $message = Message::saveNew($user->id, $other->id,
                        html_entity_decode($content, ENT_NOQUOTES, 'UTF-8'), $source);
 
                if (is_string($message)) {
index 378716eaadec2ba53dae9235e76b6dc86f16c4fc..e2b0ba164d016edf947f734a8f8a3b79eefc44b3 100644 (file)
@@ -60,14 +60,14 @@ class TwitterapiAction extends Action {
                $profile = $notice->getProfile();
 
                $twitter_status = array();
-               $twitter_status['text'] = common_xml_safe_str($notice->content);
+               $twitter_status['text'] = $notice->content;
                $twitter_status['truncated'] = 'false'; # Not possible on Laconica
                $twitter_status['created_at'] = $this->date_twitter($notice->created);
                $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : NULL;
                $twitter_status['source'] = $this->source_link($notice->source);
                $twitter_status['id'] = intval($notice->id);
                $twitter_status['in_reply_to_user_id'] = ($notice->reply_to) ? $this->replier_by_reply(intval($notice->reply_to)) : NULL;
-               
+
                if (isset($this->auth_user)) {
                        common_debug("auth user set: " . $this->auth_user->nickname);
                        $twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
@@ -91,7 +91,7 @@ class TwitterapiAction extends Action {
 
                $server = common_config('site', 'server');
                $entry = array();
-                
+
                $entry['content'] = $profile->nickname . ': ' . common_xml_safe_str($notice->content);
                $entry['title'] = $entry['content'];
                $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
@@ -137,8 +137,8 @@ class TwitterapiAction extends Action {
                $to_profile = $message->getTo();
 
                $twitter_dm['id'] = $message->id;
-               $twitter_dm['sender_id'] = $message->from_profile;              
-               $twitter_dm['text'] = common_xml_safe_str($message->content);
+               $twitter_dm['sender_id'] = $message->from_profile;
+               $twitter_dm['text'] = $message->content;
                $twitter_dm['recipient_id'] = $message->to_profile;
                $twitter_dm['created_at'] = $this->date_twitter($message->created);
                $twitter_dm['sender_screen_name'] = $from_profile->nickname;
@@ -152,9 +152,14 @@ class TwitterapiAction extends Action {
        function show_twitter_xml_status($twitter_status) {
                common_element_start('status');
                foreach($twitter_status as $element => $value) {
-                       if ($element == 'user') {
+                       switch ($element) {
+                       case 'user':
                                $this->show_twitter_xml_user($twitter_status['user']);
-                       } else {
+                               break;
+                       case 'text':
+                               common_element($element, NULL, common_xml_safe_str($value));
+                               break;
+                       default:
                                common_element($element, NULL, $value);
                        }
                }
@@ -229,9 +234,15 @@ class TwitterapiAction extends Action {
        function show_twitter_xml_dmsg($twitter_dm) {
                common_element_start('direct_message');
                foreach($twitter_dm as $element => $value) {
-                       if ($element == 'sender' || $element == 'recipient') {
+                       switch ($element) {
+                       case 'sender':
+                       case 'recipient':
                                $this->show_twitter_xml_user($value, $element);
-                       } else {
+                               break;
+                       case 'text':
+                               common_element($element, NULL, common_xml_safe_str($value));
+                               break;
+                       default:
                                common_element($element, NULL, $value);
                        }
                }
@@ -386,7 +397,7 @@ class TwitterapiAction extends Action {
                }
        }
 
-       function init_document($type='xml') {   
+       function init_document($type='xml') {
                switch ($type) {
                 case 'xml':
                        header('Content-Type: application/xml; charset=utf-8');
@@ -569,5 +580,5 @@ class TwitterapiAction extends Action {
                }
                return $source_name;
        }
-       
+
 }
\ No newline at end of file