summaryrefslogtreecommitdiff
path: root/lib/twitterapi.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/twitterapi.php')
-rw-r--r--lib/twitterapi.php45
1 files changed, 39 insertions, 6 deletions
diff --git a/lib/twitterapi.php b/lib/twitterapi.php
index 4a5de6ab3..708738832 100644
--- a/lib/twitterapi.php
+++ b/lib/twitterapi.php
@@ -24,8 +24,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
class TwitterapiAction extends Action
{
- var $auth_user;
-
/**
* Initialization.
*
@@ -934,7 +932,7 @@ class TwitterapiAction extends Action
return;
}
- function clientError($msg, $code = 400, $content_type = 'json')
+ function clientError($msg, $code = 400, $format = 'xml')
{
$action = $this->trimmed('action');
@@ -948,20 +946,23 @@ class TwitterapiAction extends Action
header('HTTP/1.1 '.$code.' '.$status_string);
- if ($content_type == 'xml') {
+ if ($format == 'xml') {
$this->init_document('xml');
$this->elementStart('hash');
$this->element('error', null, $msg);
$this->element('request', null, $_SERVER['REQUEST_URI']);
$this->elementEnd('hash');
$this->end_document('xml');
- } else {
+ } elseif ($format == 'json'){
$this->init_document('json');
$error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
print(json_encode($error_array));
$this->end_document('json');
- }
+ } else {
+ // If user didn't request a useful format, throw a regular client error
+ throw new ClientException($msg, $code);
+ }
}
function serverError($msg, $code = 500, $content_type = 'json')
@@ -1073,6 +1074,38 @@ class TwitterapiAction extends Action
}
}
+ function getTargetUser($id)
+ {
+ if (empty($id)) {
+
+ // Twitter supports these other ways of passing the user ID
+ if (is_numeric($this->arg('id'))) {
+ return User::staticGet($this->arg('id'));
+ } else if ($this->arg('id')) {
+ $nickname = common_canonical_nickname($this->arg('id'));
+ return User::staticGet('nickname', $nickname);
+ } else if ($this->arg('user_id')) {
+ // This is to ensure that a non-numeric user_id still
+ // overrides screen_name even if it doesn't get used
+ if (is_numeric($this->arg('user_id'))) {
+ return User::staticGet('id', $this->arg('user_id'));
+ }
+ } else if ($this->arg('screen_name')) {
+ $nickname = common_canonical_nickname($this->arg('screen_name'));
+ return User::staticGet('nickname', $nickname);
+ } else {
+ // Fall back to trying the currently authenticated user
+ return $this->auth_user;
+ }
+
+ } else if (is_numeric($id)) {
+ return User::staticGet($id);
+ } else {
+ $nickname = common_canonical_nickname($id);
+ return User::staticGet('nickname', $nickname);
+ }
+ }
+
function get_group($id, $apidata=null)
{
if (empty($id)) {