X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fapiaction.php;h=18ec44bb2bcc7ec0560206d9428571e16f12d074;hb=945920f24dba53d8367160b221bc842db0768fc4;hp=155d91ca7b3953072e6c7f80bffc0b0333340be2;hpb=0f938ff23479d92113620552eab76b50613c87e3;p=quix0rs-gnu-social.git diff --git a/lib/apiaction.php b/lib/apiaction.php index 155d91ca7b..18ec44bb2b 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -214,11 +214,11 @@ class ApiAction extends Action $user = null; } - $twitter_user['id'] = intval($profile->id); + $twitter_user['id'] = $profile->getID(); $twitter_user['name'] = $profile->getBestName(); - $twitter_user['screen_name'] = $profile->nickname; - $twitter_user['location'] = ($profile->location) ? $profile->location : null; - $twitter_user['description'] = ($profile->bio) ? $profile->bio : null; + $twitter_user['screen_name'] = $profile->getNickname(); + $twitter_user['location'] = $profile->location; + $twitter_user['description'] = $profile->getDescription(); // TODO: avatar url template (example.com/user/avatar?size={x}x{y}) $twitter_user['profile_image_url'] = Avatar::urlByProfile($profile, AVATAR_STREAM_SIZE); @@ -337,22 +337,22 @@ class ApiAction extends Action $twitter_status['in_reply_to_status_id'] = $in_reply_to; $source = null; + $source_link = null; $ns = $notice->getSource(); if ($ns instanceof Notice_source) { - if (!empty($ns->name) && !empty($ns->url)) { - $source = '' - . htmlspecialchars($ns->name) - . ''; - } else { - $source = $ns->code; + $source = $ns->code; + if (!empty($ns->url)) { + $source_link = $ns->url; + if (!empty($ns->name)) { + $source = $ns->name; + } } } $twitter_status['uri'] = $notice->getUri(); $twitter_status['source'] = $source; + $twitter_status['source_link'] = $source_link; $twitter_status['id'] = intval($notice->id); $replier_profile = null; @@ -408,7 +408,7 @@ class ApiAction extends Action // StatusNet-specific - $twitter_status['statusnet_html'] = $notice->rendered; + $twitter_status['statusnet_html'] = $notice->getRendered(); $twitter_status['statusnet_conversation_id'] = intval($notice->conversation); // The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array @@ -503,7 +503,7 @@ class ApiAction extends Action // We trim() to avoid extraneous whitespace in the output - $entry['content'] = common_xml_safe_str(trim($notice->rendered)); + $entry['content'] = common_xml_safe_str(trim($notice->getRendered())); $entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content)); $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id)); $entry['published'] = common_date_iso8601($notice->created); @@ -651,6 +651,11 @@ class ApiAction extends Action break; default: if (strncmp($element, 'statusnet_', 10) == 0) { + if ($element === 'statusnet_in_groups' && is_array($value)) { + // QVITTERFIX because it would cause an array to be sent as $value + // THIS IS UNDOCUMENTED AND SHOULD NEVER BE RELIED UPON (qvitter uses json output) + $value = json_encode($value); + } $this->element('statusnet:'.substr($element, 10), null, $value); } else { $this->element($element, null, $value); @@ -766,9 +771,15 @@ class ApiAction extends Action function showJsonObjects($objects) { - print(json_encode($objects)); + $json_objects = json_encode($objects); + if($json_objects === false) { + $this->clientError(_('JSON encoding failed. Error: ').json_last_error_msg()); + } else { + print $json_objects; + } } + function showSingleXmlStatus($notice) { $this->initDocument('xml'); @@ -779,7 +790,8 @@ class ApiAction extends Action function showSingleAtomStatus($notice) { - header('Content-Type: application/atom+xml; charset=utf-8'); + header('Content-Type: application/atom+xml;type=entry;charset="utf-8"'); + print '' . "\n"; print $notice->asAtomEntry(true, true, true, $this->scoped); } @@ -1393,20 +1405,21 @@ class ApiAction extends Action if (self::is_decimal($this->arg('user_id'))) { return Profile::getKV('id', $this->arg('user_id')); } - } else if ($this->arg('screen_name')) { + } elseif (mb_strlen($this->arg('screen_name')) > 0) { $nickname = common_canonical_nickname($this->arg('screen_name')); - $user = User::getKV('nickname', $nickname); - return $user instanceof User ? $user->getProfile() : null; + $user = User::getByNickname($nickname); + return $user->getProfile(); } else { // Fall back to trying the currently authenticated user return $this->scoped; } - } else if (self::is_decimal($id)) { - return Profile::getKV($id); + } else if (self::is_decimal($id) && intval($id) > 0) { + return Profile::getByID($id); } else { + // FIXME: check if isAcct to identify remote profiles and not just local nicknames $nickname = common_canonical_nickname($id); - $user = User::getKV('nickname', $nickname); - return $user ? $user->getProfile() : null; + $user = User::getByNickname($nickname); + return $user->getProfile(); } }