summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
Diffstat (limited to 'actions')
-rw-r--r--actions/api.php5
-rw-r--r--actions/conversation.php10
-rw-r--r--actions/designsettings.php6
-rw-r--r--actions/facebookhome.php5
-rw-r--r--actions/facebookinvite.php65
-rw-r--r--actions/facebooksettings.php2
-rw-r--r--actions/file.php40
-rw-r--r--actions/newnotice.php109
-rw-r--r--actions/shownotice.php6
-rw-r--r--actions/twitapiaccount.php24
-rw-r--r--actions/twitapidirect_messages.php6
-rw-r--r--actions/twitapistatuses.php36
-rw-r--r--actions/twitapiusers.php145
13 files changed, 278 insertions, 181 deletions
diff --git a/actions/api.php b/actions/api.php
index 8762b4bcd..b8da852b5 100644
--- a/actions/api.php
+++ b/actions/api.php
@@ -67,6 +67,7 @@ class ApiAction extends Action
$this->process_command();
} else {
# basic authentication failed
+ common_log(LOG_WARNING, "Failed API auth attempt, nickname: $nickname.");
$this->show_basic_auth_error();
}
}
@@ -143,8 +144,8 @@ class ApiAction extends Action
}
if (in_array($fullname, $bareauth)) {
- # bareauth: only needs auth if without an argument
- if ($this->api_arg) {
+ # bareauth: only needs auth if without an argument or query param specifying user
+ if ($this->api_arg || $this->arg('id') || is_numeric($this->arg('user_id')) || $this->arg('screen_name')) {
return false;
} else {
return true;
diff --git a/actions/conversation.php b/actions/conversation.php
index ef189016a..0d7cb9a87 100644
--- a/actions/conversation.php
+++ b/actions/conversation.php
@@ -179,14 +179,14 @@ class ConversationTree extends NoticeList
$this->out->elementStart('div', array('id' =>'notices_primary'));
$this->out->element('h2', null, _('Notices'));
- $this->out->elementStart('ul', array('class' => 'notices'));
+ $this->out->elementStart('ol', array('class' => 'notices xoxo'));
if (array_key_exists('root', $this->tree)) {
$rootid = $this->tree['root'][0];
$this->showNoticePlus($rootid);
}
- $this->out->elementEnd('ul');
+ $this->out->elementEnd('ol');
$this->out->elementEnd('div');
return $cnt;
@@ -215,13 +215,13 @@ class ConversationTree extends NoticeList
if (array_key_exists($id, $this->tree)) {
$children = $this->tree[$id];
- $this->out->elementStart('ul', array('class' => 'notices'));
+ $this->out->elementStart('ol', array('class' => 'notices'));
foreach ($children as $child) {
$this->showNoticePlus($child);
}
- $this->out->elementEnd('ul');
+ $this->out->elementEnd('ol');
}
$this->out->elementEnd('li');
@@ -295,4 +295,4 @@ class ConversationTreeItem extends NoticeListItem
{
return;
}
-} \ No newline at end of file
+}
diff --git a/actions/designsettings.php b/actions/designsettings.php
index da8894042..66476e677 100644
--- a/actions/designsettings.php
+++ b/actions/designsettings.php
@@ -68,7 +68,7 @@ class DesignsettingsAction extends AccountSettingsAction
function showContent()
{
$user = common_current_user();
- $this->elementStart('form', array('method' => 'POST',
+ $this->elementStart('form', array('method' => 'post',
'id' => 'form_settings_design',
'class' => 'form_settings',
'action' =>
@@ -80,8 +80,8 @@ class DesignsettingsAction extends AccountSettingsAction
$this->element('legend', null, _('Change background image'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
- $this->element('label', array('for' => 'design_ background-image_file'),
- _('Upload file'));
+ $this->element('label', array('for' => 'design_background-image_file'),
+ _('Upload file'));
$this->element('input', array('name' => 'design_background-image_file',
'type' => 'file',
'id' => 'design_background-image_file'));
diff --git a/actions/facebookhome.php b/actions/facebookhome.php
index 5946e6c98..00b35ef68 100644
--- a/actions/facebookhome.php
+++ b/actions/facebookhome.php
@@ -115,7 +115,7 @@ class FacebookhomeAction extends FacebookAction
$flink->foreign_id = $this->fbuid;
$flink->service = FACEBOOK_SERVICE;
$flink->created = common_sql_now();
- $flink->set_flags(true, false, false);
+ $flink->set_flags(true, false, false, false);
$flink_id = $flink->insert();
@@ -138,9 +138,6 @@ class FacebookhomeAction extends FacebookAction
function setDefaults()
{
- // A default prefix string for notices
- $this->facebook->api_client->data_setUserPreference(
- FACEBOOK_NOTICE_PREFIX, 'dented: ');
$this->facebook->api_client->data_setUserPreference(
FACEBOOK_PROMPTED_UPDATE_PREF, 'false');
}
diff --git a/actions/facebookinvite.php b/actions/facebookinvite.php
index 1302064ad..2207580f7 100644
--- a/actions/facebookinvite.php
+++ b/actions/facebookinvite.php
@@ -17,7 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('LACONICA')) {
+ exit(1);
+}
require_once(INSTALLDIR.'/lib/facebookaction.php');
@@ -67,7 +69,7 @@ class FacebookinviteAction extends FacebookAction
function showSuccessContent()
{
- $this->element('h2', null, sprintf(_('Thanks for inviting your friends to use %s'),
+ $this->element('h2', null, sprintf(_('Thanks for inviting your friends to use %s'),
common_config('site', 'name')));
$this->element('p', null, _('Invitations have been sent to the following users:'));
@@ -89,16 +91,6 @@ class FacebookinviteAction extends FacebookAction
function showFormContent()
{
-
- // Get a list of users who are already using the app for exclusion
- $exclude_ids = $this->facebook->api_client->friends_getAppUsers();
- $exclude_ids_csv = null;
-
- // fbml needs these as a csv string, not an array
- if ($exclude_ids) {
- $exclude_ids_csv = implode(',', $exclude_ids);
- }
-
$content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) .
htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>');
@@ -109,36 +101,43 @@ class FacebookinviteAction extends FacebookAction
'content' => $content));
$this->hidden('invite', 'true');
$actiontext = sprintf(_('Invite your friends to use %s'), common_config('site', 'name'));
-
- $multi_params = array('showborder' => 'false');
+
+ $multi_params = array('showborder' => 'false');
$multi_params['actiontext'] = $actiontext;
-
- if ($exclude_ids_csv) {
+ $multi_params['bypass'] = 'cancel';
+
+ // Get a list of users who are already using the app for exclusion
+ $exclude_ids = $this->facebook->api_client->friends_getAppUsers();
+ $exclude_ids_csv = null;
+
+ // fbml needs these as a csv string, not an array
+ if ($exclude_ids) {
+ $exclude_ids_csv = implode(',', $exclude_ids);
$multi_params['exclude_ids'] = $exclude_ids_csv;
}
- $multi_params['bypass'] = 'cancel';
-
$this->element('fb:multi-friend-selector', $multi_params);
-
$this->elementEnd('fb:request-form');
- $this->element('h2', null, sprintf(_('Friends already using %s:'),
- common_config('site', 'name')));
- $this->elementStart('ul', array('id' => 'facebook-friends'));
-
- foreach ($exclude_ids as $friend) {
- $this->elementStart('li');
- $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
- $this->element('fb:name', array('uid' => $friend,
- 'capitalize' => 'true'));
- $this->elementEnd('li');
- }
+ if ($exclude_ids) {
- $this->elementEnd("ul");
+ $this->element('h2', null, sprintf(_('Friends already using %s:'),
+ common_config('site', 'name')));
+ $this->elementStart('ul', array('id' => 'facebook-friends'));
+
+ foreach ($exclude_ids as $friend) {
+ $this->elementStart('li');
+ $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
+ $this->element('fb:name', array('uid' => $friend,
+ 'capitalize' => 'true'));
+ $this->elementEnd('li');
+ }
+
+ $this->elementEnd("ul");
+ }
}
-
- function title()
+
+ function title()
{
return sprintf(_('Send invitations'));
}
diff --git a/actions/facebooksettings.php b/actions/facebooksettings.php
index 236460c1c..227e12316 100644
--- a/actions/facebooksettings.php
+++ b/actions/facebooksettings.php
@@ -55,7 +55,7 @@ class FacebooksettingsAction extends FacebookAction
$prefix = $this->trimmed('prefix');
$original = clone($this->flink);
- $this->flink->set_flags($noticesync, $replysync, false);
+ $this->flink->set_flags($noticesync, $replysync, false, false);
$result = $this->flink->update($original);
$this->facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX,
diff --git a/actions/file.php b/actions/file.php
new file mode 100644
index 000000000..1179dbe9a
--- /dev/null
+++ b/actions/file.php
@@ -0,0 +1,40 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
+
+require_once(INSTALLDIR.'/actions/shownotice.php');
+
+class FileAction extends ShowNoticeAction
+{
+ function showPage() {
+ $source_url = common_local_url('file', array('notice' => $this->notice->id));
+ $query = "select file_redirection.url as url from file join file_redirection on file.id = file_redirection.file_id where file.url = '$source_url'";
+ $file = new File_redirection;
+ $file->query($query);
+ $file->fetch();
+ if (empty($file->url)) {
+ die('nothing attached here');
+ } else {
+ header("Location: {$file->url}");
+ die();
+ }
+ }
+}
+
diff --git a/actions/newnotice.php b/actions/newnotice.php
index ae0ff9636..02976a2ae 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -84,20 +84,24 @@ class NewnoticeAction extends Action
function handle($args)
{
- parent::handle($args);
-
if (!common_logged_in()) {
$this->clientError(_('Not logged in.'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ // check for this before token since all POST and FILES data
+ // is losts when size is exceeded
+ if (empty($_POST) && $_SERVER['CONTENT_LENGTH']) {
+ $this->clientError(sprintf(_('The server was unable to handle ' .
+ 'that much POST data (%s bytes) due to its current configuration.'),
+ $_SERVER['CONTENT_LENGTH']));
+ }
+ parent::handle($args);
// CSRF protection
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->clientError(_('There was a problem with your session token. '.
'Try again, please.'));
- return;
}
-
try {
$this->saveNewNotice();
} catch (Exception $e) {
@@ -109,6 +113,30 @@ class NewnoticeAction extends Action
}
}
+ function getUploadedFileType() {
+ require_once 'MIME/Type.php';
+
+ $filetype = MIME_Type::autoDetect($_FILES['attach']['tmp_name']);
+ if (in_array($filetype, common_config('attachments', 'supported'))) {
+ return $filetype;
+ }
+ $media = MIME_Type::getMedia($filetype);
+ if ('application' !== $media) {
+ $hint = sprintf(_(' Try using another %s format.'), $media);
+ } else {
+ $hint = '';
+ }
+ $this->clientError(sprintf(
+ _('%s is not a supported filetype on this server.'), $filetype) . $hint);
+ }
+
+ function isRespectsQuota($user) {
+ $file = new File;
+ $ret = $file->isRespectsQuota($user);
+ if (true === $ret) return true;
+ $this->clientError($ret);
+ }
+
/**
* Save a new notice, based on arguments
*
@@ -131,7 +159,6 @@ class NewnoticeAction extends Action
$this->clientError(_('No content!'));
} else {
$content_shortened = common_shorten_links($content);
-
if (mb_strlen($content_shortened) > 140) {
$this->clientError(_('That\'s too long. '.
'Max notice size is 140 chars.'));
@@ -158,17 +185,53 @@ class NewnoticeAction extends Action
$replyto = 'false';
}
-// $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
+ if (isset($_FILES['attach']['error'])) {
+ switch ($_FILES['attach']['error']) {
+ case UPLOAD_ERR_NO_FILE:
+ // no file uploaded, nothing to do
+ break;
+
+ case UPLOAD_ERR_OK:
+ $mimetype = $this->getUploadedFileType();
+ if (!$this->isRespectsQuota($user)) {
+ die('clientError() should trigger an exception before reaching here.');
+ }
+ break;
+
+ case UPLOAD_ERR_INI_SIZE:
+ $this->clientError(_('The uploaded file exceeds the upload_max_filesize directive in php.ini.'));
+
+ case UPLOAD_ERR_FORM_SIZE:
+ $this->clientError(_('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'));
+
+ case UPLOAD_ERR_PARTIAL:
+ $this->clientError(_('The uploaded file was only partially uploaded.'));
+
+ case UPLOAD_ERR_NO_TMP_DIR:
+ $this->clientError(_('Missing a temporary folder.'));
+
+ case UPLOAD_ERR_CANT_WRITE:
+ $this->clientError(_('Failed to write file to disk.'));
+
+ case UPLOAD_ERR_EXTENSION:
+ $this->clientError(_('File upload stopped by extension.'));
+
+ default:
+ die('Should never reach here.');
+ }
+ }
+
$notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
($replyto == 'false') ? null : $replyto);
if (is_string($notice)) {
$this->clientError($notice);
- return;
}
+ if (isset($mimetype)) {
+ $this->storeFile($notice, $mimetype);
+ }
$this->saveUrls($notice);
-
common_broadcast_notice($notice);
if ($this->boolean('ajax')) {
@@ -194,6 +257,33 @@ class NewnoticeAction extends Action
}
}
+ function storeFile($notice, $mimetype) {
+ $filename = basename($_FILES['attach']['name']);
+ $destination = "file/{$notice->id}-$filename";
+ if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) {
+ $file = new File;
+ $file->url = common_local_url('file', array('notice' => $notice->id));
+ $file->size = filesize(INSTALLDIR . "/$destination");
+ $file->date = time();
+ $file->mimetype = $mimetype;
+ if ($file_id = $file->insert()) {
+ $file_redir = new File_redirection;
+ $file_redir->url = common_path($destination);
+ $file_redir->file_id = $file_id;
+ $file_redir->insert();
+
+ $f2p = new File_to_post;
+ $f2p->file_id = $file_id;
+ $f2p->post_id = $notice->id;
+ $f2p->insert();
+ } else {
+ $this->clientError(_('There was a database error while saving your file. Please try again.'));
+ }
+ } else {
+ $this->clientError(_('File could not be moved to destination directory.'));
+ }
+ }
+
/** save all urls in the notice to the db
*
* follow redirects and save all available file information
@@ -203,7 +293,7 @@ class NewnoticeAction extends Action
*
* @return void
*/
- function saveUrls($notice) {
+ function saveUrls($notice, $uploaded = null) {
common_replace_urls_callback($notice->content, array($this, 'saveUrl'), $notice->id);
}
@@ -316,3 +406,4 @@ class NewnoticeAction extends Action
$nli->show();
}
}
+
diff --git a/actions/shownotice.php b/actions/shownotice.php
index 2c469c9de..b0d973a99 100644
--- a/actions/shownotice.php
+++ b/actions/shownotice.php
@@ -122,7 +122,7 @@ class ShownoticeAction extends Action
function lastModified()
{
- return max(strtotime($this->notice->created),
+ return max(strtotime($this->notice->modified),
strtotime($this->profile->modified),
($this->avatar) ? strtotime($this->avatar->modified) : 0);
}
@@ -208,10 +208,10 @@ class ShownoticeAction extends Action
function showContent()
{
- $this->elementStart('ul', array('class' => 'notices'));
+ $this->elementStart('ol', array('class' => 'notices xoxo'));
$nli = new NoticeListItem($this->notice, $this);
$nli->show();
- $this->elementEnd('ul');
+ $this->elementEnd('ol');
}
/**
diff --git a/actions/twitapiaccount.php b/actions/twitapiaccount.php
index 68a18cb57..8b956f897 100644
--- a/actions/twitapiaccount.php
+++ b/actions/twitapiaccount.php
@@ -98,9 +98,31 @@ class TwitapiaccountAction extends TwitterapiAction
$this->serverError(_('API method under construction.'), $code=501);
}
+ // We don't have a rate limit, but some clients check this method.
+ // It always returns the same thing: 100 hit left.
function rate_limit_status($args, $apidata)
{
parent::handle($args);
- $this->serverError(_('API method under construction.'), $code=501);
+
+ $type = $apidata['content-type'];
+ $this->init_document($type);
+
+ if ($apidata['content-type'] == 'xml') {
+ $this->elementStart('hash');
+ $this->element('remaining-hits', array('type' => 'integer'), 100);
+ $this->element('hourly-limit', array('type' => 'integer'), 100);
+ $this->element('reset-time', array('type' => 'datetime'), null);
+ $this->element('reset_time_in_seconds', array('type' => 'integer'), 0);
+ $this->elementEnd('hash');
+ } elseif ($apidata['content-type'] == 'json') {
+
+ $out = array('reset_time_in_seconds' => 0,
+ 'remaining_hits' => 100,
+ 'hourly_limit' => 100,
+ 'reset_time' => '');
+ print json_encode($out);
+ }
+
+ $this->end_document($type);
}
}
diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php
index 7101db8df..d2dbdb619 100644
--- a/actions/twitapidirect_messages.php
+++ b/actions/twitapidirect_messages.php
@@ -43,7 +43,7 @@ class Twitapidirect_messagesAction extends TwitterapiAction
$count = $this->arg('count');
$since = $this->arg('since');
$since_id = $this->arg('since_id');
- $before_id = $this->arg('before_id');
+ $max_id = $this->arg('max_id');
$page = $this->arg('page');
@@ -74,8 +74,8 @@ class Twitapidirect_messagesAction extends TwitterapiAction
$link = $server . $user->nickname . '/outbox';
}
- if ($before_id) {
- $message->whereAdd("id < $before_id");
+ if ($max_id) {
+ $message->whereAdd("id <= $max_id");
}
if ($since_id) {
diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php
index 3abeba367..1fbde6639 100644
--- a/actions/twitapistatuses.php
+++ b/actions/twitapistatuses.php
@@ -45,22 +45,21 @@ class TwitapistatusesAction extends TwitterapiAction
$page = $this->arg('page');
$since_id = $this->arg('since_id');
- $before_id = $this->arg('before_id');
+ $max_id = $this->arg('max_id');
- // NOTE: page, since_id, and before_id are extensions to Twitter API -- TB
if (!$page) {
$page = 1;
}
if (!$since_id) {
$since_id = 0;
}
- if (!$before_id) {
- $before_id = 0;
+ if (!$max_id) {
+ $max_id = 0;
}
$since = strtotime($this->arg('since'));
- $notice = Notice::publicStream((($page-1)*$MAX_PUBSTATUSES), $MAX_PUBSTATUSES, $since_id, $before_id, $since);
+ $notice = Notice::publicStream((($page-1)*$MAX_PUBSTATUSES), $MAX_PUBSTATUSES, $since_id, $max_id, $since);
if ($notice) {
@@ -97,7 +96,7 @@ class TwitapistatusesAction extends TwitterapiAction
$since_id = $this->arg('since_id');
$count = $this->arg('count');
$page = $this->arg('page');
- $before_id = $this->arg('before_id');
+ $max_id = $this->arg('max_id');
if (!$page) {
$page = 1;
@@ -111,9 +110,8 @@ class TwitapistatusesAction extends TwitterapiAction
$since_id = 0;
}
- // NOTE: before_id is an extension to Twitter API -- TB
- if (!$before_id) {
- $before_id = 0;
+ if (!$max_id) {
+ $max_id = 0;
}
$since = strtotime($this->arg('since'));
@@ -133,7 +131,7 @@ class TwitapistatusesAction extends TwitterapiAction
$link = common_local_url('all', array('nickname' => $user->nickname));
$subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'), $user->nickname, $sitename);
- $notice = $user->noticesWithFriends(($page-1)*20, $count, $since_id, $before_id, $since);
+ $notice = $user->noticesWithFriends(($page-1)*20, $count, $since_id, $max_id, $since);
switch($apidata['content-type']) {
case 'xml':
@@ -184,7 +182,7 @@ class TwitapistatusesAction extends TwitterapiAction
$since = $this->arg('since');
$since_id = $this->arg('since_id');
$page = $this->arg('page');
- $before_id = $this->arg('before_id');
+ $max_id = $this->arg('max_id');
if (!$page) {
$page = 1;
@@ -198,9 +196,8 @@ class TwitapistatusesAction extends TwitterapiAction
$since_id = 0;
}
- // NOTE: before_id is an extensions to Twitter API -- TB
- if (!$before_id) {
- $before_id = 0;
+ if (!$max_id) {
+ $max_id = 0;
}
$since = strtotime($this->arg('since'));
@@ -220,7 +217,7 @@ class TwitapistatusesAction extends TwitterapiAction
# XXX: since
- $notice = $user->getNotices((($page-1)*20), $count, $since_id, $before_id, $since);
+ $notice = $user->getNotices((($page-1)*20), $count, $since_id, $max_id, $since);
switch($apidata['content-type']) {
case 'xml':
@@ -353,7 +350,7 @@ class TwitapistatusesAction extends TwitterapiAction
$count = $this->arg('count');
$page = $this->arg('page');
$since_id = $this->arg('since_id');
- $before_id = $this->arg('before_id');
+ $max_id = $this->arg('max_id');
$user = $this->get_user($apidata['api_arg'], $apidata);
$this->auth_user = $apidata['user'];
@@ -380,15 +377,14 @@ class TwitapistatusesAction extends TwitterapiAction
$since_id = 0;
}
- // NOTE: before_id is an extension to Twitter API -- TB
- if (!$before_id) {
- $before_id = 0;
+ if (!$max_id) {
+ $max_id = 0;
}
$since = strtotime($this->arg('since'));
$notice = $user->getReplies((($page-1)*20),
- $count, $since_id, $before_id, $since);
+ $count, $since_id, $max_id, $since);
$notices = array();
while ($notice->fetch()) {
diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php
index 1542cfb33..b90bbfa98 100644
--- a/actions/twitapiusers.php
+++ b/actions/twitapiusers.php
@@ -25,110 +25,61 @@ class TwitapiusersAction extends TwitterapiAction
{
function show($args, $apidata)
- {
+ {
parent::handle($args);
- if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+ if (!in_array($apidata['content-type'], array('xml', 'json'))) {
$this->clientError(_('API method not found!'), $code = 404);
return;
}
-
- $user = null;
- $email = $this->arg('email');
- $user_id = $this->arg('user_id');
-
- if ($email) {
- $user = User::staticGet('email', $email);
- } elseif ($user_id) {
- $user = $this->get_user($user_id);
- } elseif (isset($apidata['api_arg'])) {
- $user = $this->get_user($apidata['api_arg']);
- } elseif (isset($apidata['user'])) {
- $user = $apidata['user'];
- }
-
- if (!$user) {
- // XXX: Twitter returns a random(?) user instead of throwing and err! -- Zach
- $this->client_error(_('Not found.'), 404, $apidata['content-type']);
- return;
- }
-
- $profile = $user->getProfile();
-
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
-
- $twitter_user = $this->twitter_user_array($profile, true);
-
- // Add in extended user fields offered up by this method
- $twitter_user['created_at'] = $this->date_twitter($profile->created);
-
- $subbed = DB_DataObject::factory('subscription');
- $subbed->subscriber = $profile->id;
- $subbed_count = (int) $subbed->count() - 1;
-
- $notices = DB_DataObject::factory('notice');
- $notices->profile_id = $profile->id;
- $notice_count = (int) $notices->count();
-
- $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0;
- $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0;
-
- // Other fields Twitter sends...
- $twitter_user['profile_background_color'] = '';
- $twitter_user['profile_background_image_url'] = '';
- $twitter_user['profile_text_color'] = '';
- $twitter_user['profile_link_color'] = '';
- $twitter_user['profile_sidebar_fill_color'] = '';
- $twitter_user['profile_sidebar_border_color'] = '';
- $twitter_user['profile_background_tile'] = false;
-
- $faves = DB_DataObject::factory('fave');
- $faves->user_id = $user->id;
- $faves_count = (int) $faves->count();
- $twitter_user['favourites_count'] = $faves_count;
-
- $timezone = 'UTC';
-
- if ($user->timezone) {
- $timezone = $user->timezone;
- }
-
- $t = new DateTime;
- $t->setTimezone(new DateTimeZone($timezone));
- $twitter_user['utc_offset'] = $t->format('Z');
- $twitter_user['time_zone'] = $timezone;
-
- if (isset($apidata['user'])) {
-
- $twitter_user['following'] = $apidata['user']->isSubscribed($profile);
-
- // Notifications on?
- $sub = Subscription::pkeyGet(array('subscriber' =>
- $apidata['user']->id, 'subscribed' => $profile->id));
-
- if ($sub) {
- $twitter_user['notifications'] = ($sub->jabber || $sub->sms);
- }
- }
-
- if ($apidata['content-type'] == 'xml') {
- $this->init_document('xml');
- $this->show_twitter_xml_user($twitter_user);
- $this->end_document('xml');
- } elseif ($apidata['content-type'] == 'json') {
- $this->init_document('json');
- $this->show_json_objects($twitter_user);
- $this->end_document('json');
- } else {
-
- // This is in case 'show' was called via /account/verify_credentials
- // without a format (xml or json).
+
+ $user = null;
+ $email = $this->arg('email');
+ $user_id = $this->arg('user_id');
+
+ // XXX: email field deprecated in Twitter's API
+
+ // XXX: Also: need to add screen_name param
+
+ if ($email) {
+ $user = User::staticGet('email', $email);
+ } elseif ($user_id) {
+ $user = $this->get_user($user_id);
+ } elseif (isset($apidata['api_arg'])) {
+ $user = $this->get_user($apidata['api_arg']);
+ } elseif (isset($apidata['user'])) {
+ $user = $apidata['user'];
+ }
+
+ if (!$user) {
+ $this->client_error(_('Not found.'), 404, $apidata['content-type']);
+ return;
+ }
+
+ $profile = $user->getProfile();
+
+ if (!$profile) {
+ common_server_error(_('User has no profile.'));
+ return;
+ }
+
+ $twitter_user = $this->twitter_user_array($profile, true);
+
+ if ($apidata['content-type'] == 'xml') {
+ $this->init_document('xml');
+ $this->show_twitter_xml_user($twitter_user);
+ $this->end_document('xml');
+ } elseif ($apidata['content-type'] == 'json') {
+ $this->init_document('json');
+ $this->show_json_objects($twitter_user);
+ $this->end_document('json');
+ } else {
+
+ // This is in case 'show' was called via /account/verify_credentials
+ // without a format (xml or json).
header('Content-Type: text/html; charset=utf-8');
print 'Authorized';
}
- }
+ }
}