Twitter-compatible API - don't strip XML-illegal chars from JSON output

darcs-hash:20081106225721-462f3-b80ba75f87a4b36b803868653c956c393a236626.gz
This commit is contained in:
zach 2008-11-06 17:57:21 -05:00
parent ab6c83dab8
commit aac0605bd1
2 changed files with 24 additions and 13 deletions

View File

@ -133,8 +133,8 @@ class Twitapidirect_messagesAction extends TwitterapiAction {
$code = 403, $apidata['content-type']); $code = 403, $apidata['content-type']);
return; return;
} }
$message = Message::saveNew($user->id, $other->id, $message = Message::saveNew($user->id, $other->id,
html_entity_decode($content, ENT_NOQUOTES, 'UTF-8'), $source); html_entity_decode($content, ENT_NOQUOTES, 'UTF-8'), $source);
if (is_string($message)) { if (is_string($message)) {

View File

@ -60,14 +60,14 @@ class TwitterapiAction extends Action {
$profile = $notice->getProfile(); $profile = $notice->getProfile();
$twitter_status = array(); $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['truncated'] = 'false'; # Not possible on Laconica
$twitter_status['created_at'] = $this->date_twitter($notice->created); $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['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : NULL;
$twitter_status['source'] = $this->source_link($notice->source); $twitter_status['source'] = $this->source_link($notice->source);
$twitter_status['id'] = intval($notice->id); $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; $twitter_status['in_reply_to_user_id'] = ($notice->reply_to) ? $this->replier_by_reply(intval($notice->reply_to)) : NULL;
if (isset($this->auth_user)) { if (isset($this->auth_user)) {
common_debug("auth user set: " . $this->auth_user->nickname); common_debug("auth user set: " . $this->auth_user->nickname);
$twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false'; $twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
@ -91,7 +91,7 @@ class TwitterapiAction extends Action {
$server = common_config('site', 'server'); $server = common_config('site', 'server');
$entry = array(); $entry = array();
$entry['content'] = $profile->nickname . ': ' . common_xml_safe_str($notice->content); $entry['content'] = $profile->nickname . ': ' . common_xml_safe_str($notice->content);
$entry['title'] = $entry['content']; $entry['title'] = $entry['content'];
$entry['link'] = common_local_url('shownotice', array('notice' => $notice->id)); $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
@ -137,8 +137,8 @@ class TwitterapiAction extends Action {
$to_profile = $message->getTo(); $to_profile = $message->getTo();
$twitter_dm['id'] = $message->id; $twitter_dm['id'] = $message->id;
$twitter_dm['sender_id'] = $message->from_profile; $twitter_dm['sender_id'] = $message->from_profile;
$twitter_dm['text'] = common_xml_safe_str($message->content); $twitter_dm['text'] = $message->content;
$twitter_dm['recipient_id'] = $message->to_profile; $twitter_dm['recipient_id'] = $message->to_profile;
$twitter_dm['created_at'] = $this->date_twitter($message->created); $twitter_dm['created_at'] = $this->date_twitter($message->created);
$twitter_dm['sender_screen_name'] = $from_profile->nickname; $twitter_dm['sender_screen_name'] = $from_profile->nickname;
@ -152,9 +152,14 @@ class TwitterapiAction extends Action {
function show_twitter_xml_status($twitter_status) { function show_twitter_xml_status($twitter_status) {
common_element_start('status'); common_element_start('status');
foreach($twitter_status as $element => $value) { foreach($twitter_status as $element => $value) {
if ($element == 'user') { switch ($element) {
case 'user':
$this->show_twitter_xml_user($twitter_status['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); common_element($element, NULL, $value);
} }
} }
@ -229,9 +234,15 @@ class TwitterapiAction extends Action {
function show_twitter_xml_dmsg($twitter_dm) { function show_twitter_xml_dmsg($twitter_dm) {
common_element_start('direct_message'); common_element_start('direct_message');
foreach($twitter_dm as $element => $value) { foreach($twitter_dm as $element => $value) {
if ($element == 'sender' || $element == 'recipient') { switch ($element) {
case 'sender':
case 'recipient':
$this->show_twitter_xml_user($value, $element); $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); 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) { switch ($type) {
case 'xml': case 'xml':
header('Content-Type: application/xml; charset=utf-8'); header('Content-Type: application/xml; charset=utf-8');
@ -569,5 +580,5 @@ class TwitterapiAction extends Action {
} }
return $source_name; return $source_name;
} }
} }