summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
Diffstat (limited to 'actions')
-rw-r--r--actions/avatarsettings.php8
-rw-r--r--actions/favorited.php8
-rw-r--r--actions/newnotice.php5
-rw-r--r--actions/twitapiaccount.php20
-rw-r--r--actions/twitapisearchjson.php149
-rw-r--r--actions/twitapitrends.php90
-rw-r--r--actions/twitapiusers.php52
7 files changed, 304 insertions, 28 deletions
diff --git a/actions/avatarsettings.php b/actions/avatarsettings.php
index 6545d9489..c2bb35a39 100644
--- a/actions/avatarsettings.php
+++ b/actions/avatarsettings.php
@@ -324,11 +324,13 @@ class AvatarsettingsAction extends AccountSettingsAction
return;
}
- // If image is not being cropped assume pos & dimensions of original.
+ $file_d = ($filedata['width'] > $filedata['height'])
+ ? $filedata['height'] : $filedata['width'];
+
$dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x'):0;
$dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y'):0;
- $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w'):$filedata['width'];
- $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h'):$filedata['height'];
+ $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w'):$file_d;
+ $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h'):$file_d;
$size = min($dest_w, $dest_h, MAX_ORIGINAL);
$user = common_current_user();
diff --git a/actions/favorited.php b/actions/favorited.php
index fd5ff413c..5082f4a4e 100644
--- a/actions/favorited.php
+++ b/actions/favorited.php
@@ -169,8 +169,14 @@ class FavoritedAction extends Action
function showContent()
{
+ if (common_config('db', 'type') == 'pgsql') {
+ $weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
+ } else {
+ $weightexpr='sum(exp(-(now() - fave.modified) / %s))';
+ }
+
$qry = 'SELECT notice.*, '.
- 'sum(exp(-(now() - fave.modified) / %s)) as weight ' .
+ $weightexpr . ' as weight ' .
'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
'GROUP BY fave.notice_id ' .
'ORDER BY weight DESC';
diff --git a/actions/newnotice.php b/actions/newnotice.php
index 9f44d2516..cbd04c58b 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -152,6 +152,11 @@ class NewnoticeAction extends Action
}
$replyto = $this->trimmed('inreplyto');
+ #If an ID of 0 is wrongly passed here, it will cause a database error,
+ #so override it...
+ if ($replyto == 0) {
+ $replyto = 'false';
+ }
$notice = Notice::saveNew($user->id, $content, 'web', 1,
($replyto == 'false') ? null : $replyto);
diff --git a/actions/twitapiaccount.php b/actions/twitapiaccount.php
index c19cd370d..68a18cb57 100644
--- a/actions/twitapiaccount.php
+++ b/actions/twitapiaccount.php
@@ -23,22 +23,24 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapiaccountAction extends TwitterapiAction
{
-
function verify_credentials($args, $apidata)
{
- if ($apidata['content-type'] == 'xml') {
- header('Content-Type: application/xml; charset=utf-8');
- print '<authorized>true</authorized>';
- } elseif ($apidata['content-type'] == 'json') {
- header('Content-Type: application/json; charset=utf-8');
- print '{"authorized":true}';
- } else {
+ parent::handle($args);
+
+ switch ($apidata['content-type']) {
+ case 'xml':
+ case 'json':
+ $action_obj = new TwitapiusersAction();
+ $action_obj->prepare($args);
+ call_user_func(array($action_obj, 'show'), $args, $apidata);
+ break;
+ default:
header('Content-Type: text/html; charset=utf-8');
print 'Authorized';
}
}
- function end_session($args, $apidata)
+ function end_session($args, $apidata)
{
parent::handle($args);
$this->serverError(_('API method under construction.'), $code=501);
diff --git a/actions/twitapisearchjson.php b/actions/twitapisearchjson.php
new file mode 100644
index 000000000..b50aa86b7
--- /dev/null
+++ b/actions/twitapisearchjson.php
@@ -0,0 +1,149 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * List of replies
+ *
+ * PHP version 5
+ *
+ * LICENCE: 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/>.
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @copyright 2008-2009 Control Yourself, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+if (!defined('LACONICA')) {
+ exit(1);
+}
+
+require_once INSTALLDIR.'/lib/twitterapi.php';
+require_once INSTALLDIR.'/lib/jsonsearchresultslist.php';
+
+/**
+ * Action handler for Twitter-compatible API search
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ * @see TwitterapiAction
+ */
+
+class TwitapisearchjsonAction extends TwitterapiAction
+{
+ var $query;
+ var $lang;
+ var $rpp;
+ var $page;
+ var $since_id;
+ var $limit;
+ var $geocode;
+
+ /**
+ * Initialization.
+ *
+ * @param array $args Web and URL arguments
+ *
+ * @return boolean true if nothing goes wrong
+ */
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ $this->query = $this->trimmed('q');
+ $this->lang = $this->trimmed('lang');
+ $this->rpp = $this->trimmed('rpp');
+
+ if (!$this->rpp) {
+ $this->rpp = 15;
+ }
+
+ if ($this->rpp > 100) {
+ $this->rpp = 100;
+ }
+
+ $this->page = $this->trimmed('page');
+
+ if (!$this->page) {
+ $this->page = 1;
+ }
+
+ $this->since_id = $this->trimmed('since_id');
+ $this->geocode = $this->trimmed('geocode');
+
+ return true;
+ }
+
+ /**
+ * Handle a request
+ *
+ * @param array $args Arguments from $_REQUEST
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ parent::handle($args);
+ $this->showResults();
+ }
+
+ /**
+ * Show search results
+ *
+ * @return void
+ */
+
+ function showResults()
+ {
+
+ // TODO: Support search operators like from: and to:
+
+ $notice = new Notice();
+
+ // lcase it for comparison
+ $q = strtolower($this->query);
+
+ $search_engine = $notice->getSearchEngine('identica_notices');
+ $search_engine->set_sort_mode('chron');
+ $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1, true);
+ $search_engine->query($q);
+ $cnt = $notice->find();
+
+ // TODO: since_id, lang, geocode
+
+ $results = new JSONSearchResultsList($notice, $q, $this->rpp, $this->page);
+
+ $this->init_document('json');
+ $results->show();
+ $this->end_document('json');
+ }
+
+ /**
+ * This is a read-only action
+ *
+ * @return boolean true
+ */
+
+ function isReadOnly()
+ {
+ return true;
+ }
+} \ No newline at end of file
diff --git a/actions/twitapitrends.php b/actions/twitapitrends.php
new file mode 100644
index 000000000..c73d89446
--- /dev/null
+++ b/actions/twitapitrends.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * List of replies
+ *
+ * PHP version 5
+ *
+ * LICENCE: 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/>.
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @copyright 2008-2009 Control Yourself, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+if (!defined('LACONICA')) {
+ exit(1);
+}
+
+require_once INSTALLDIR.'/lib/twitterapi.php';
+
+/**
+ * Returns the top ten queries that are currently trending
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ *
+ * @see TwitterapiAction
+ */
+
+class TwitapitrendsAction extends TwitterapiAction
+{
+
+ var $callback;
+
+ /**
+ * Initialization.
+ *
+ * @param array $args Web and URL arguments
+ *
+ * @return boolean false if user doesn't exist
+ */
+ function prepare($args)
+ {
+ parent::prepare($args);
+ return true;
+ }
+
+ /**
+ * Handle a request
+ *
+ * @param array $args Arguments from $_REQUEST
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ parent::handle($args);
+ $this->showTrends();
+ }
+
+ /**
+ * Output the trends
+ *
+ * @return void
+ */
+ function showTrends()
+ {
+ $this->serverError(_('API method under construction.'), $code = 501);
+ }
+
+} \ No newline at end of file
diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php
index 8f16e5613..2894b7486 100644
--- a/actions/twitapiusers.php
+++ b/actions/twitapiusers.php
@@ -25,25 +25,29 @@ 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;
}
-
- $this->auth_user = $apidata['user'];
+
$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']);
- }
-
- if (!$user) {
+ } 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;
@@ -74,9 +78,12 @@ class TwitapiusersAction extends TwitterapiAction
// 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;
@@ -94,18 +101,27 @@ class TwitapiusersAction extends TwitterapiAction
$twitter_user['utc_offset'] = $t->format('Z');
$twitter_user['time_zone'] = $timezone;
- if (isset($this->auth_user)) {
+ if (isset($apidata['user'])) {
- if ($this->auth_user->isSubscribed($profile)) {
+ if ($apidata['user']->isSubscribed($profile)) {
$twitter_user['following'] = 'true';
} else {
$twitter_user['following'] = 'false';
}
-
- // Not implemented yet
- $twitter_user['notifications'] = 'false';
- }
-
+
+ // Notifications on?
+ $sub = Subscription::pkeyGet(array('subscriber' =>
+ $apidata['user']->id, 'subscribed' => $profile->id));
+
+ if ($sub) {
+ if ($sub->jabber || $sub->sms) {
+ $twitter_user['notifications'] = 'true';
+ } else {
+ $twitter_user['notifications'] = 'false';
+ }
+ }
+ }
+
if ($apidata['content-type'] == 'xml') {
$this->init_document('xml');
$this->show_twitter_xml_user($twitter_user);
@@ -114,7 +130,13 @@ class TwitapiusersAction extends TwitterapiAction
$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';
+ }
}
}