summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-03-05 11:04:16 -0800
committerEvan Prodromou <evan@controlyourself.ca>2009-03-05 11:04:16 -0800
commit6ce7d0c567b23d3bec035a9c4428399bdfdb896b (patch)
treeae887738020b1c67cd57aa247f4c326fe331a048 /actions
parentb9781258bbfaac0e7fc91af4f77f1f340274a88e (diff)
parent3087e4ad5dfbccb7218c12ca747e1dbcf3a6415c (diff)
Merge branch '0.7.x' of git@gitorious.org:laconica/dev into 0.7.x
Diffstat (limited to 'actions')
-rw-r--r--actions/twitapiaccount.php20
-rw-r--r--actions/twitapisearch.php97
-rw-r--r--actions/twitapitrends.php90
-rw-r--r--actions/twitapiusers.php52
4 files changed, 235 insertions, 24 deletions
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/twitapisearch.php b/actions/twitapisearch.php
new file mode 100644
index 000000000..822ee77e1
--- /dev/null
+++ b/actions/twitapisearch.php
@@ -0,0 +1,97 @@
+<?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';
+
+/**
+ * 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 TwitapisearchAction extends TwitterapiAction
+{
+
+ var $query;
+ var $limit;
+ var $callback;
+
+ /**
+ * Initialization.
+ *
+ * @param array $args Web and URL arguments
+ *
+ * @return boolean false if user doesn't exist
+ */
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+ $qeury = $this->trimmed('query');
+
+ return true;
+ }
+
+ /**
+ * Handle a request
+ *
+ * @param array $args Arguments from $_REQUEST
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ parent::handle($args);
+ $this->showResults($this->limit);
+ }
+
+ /**
+ * Show search results
+ *
+ * @param int $limit Number of notices to show
+ *
+ * @return void
+ */
+
+ function showResults($limit)
+ {
+ $this->serverError(_('API method under construction.'), $code = 501);
+ }
+
+}
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';
+ }
}
}