From ac7170bf6cbf36699cf182ccb1bd5214f6e8741e Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 6 Mar 2009 21:09:43 -0800 Subject: Atom search results for Twitter-compatible API + phpcs stuff --- actions/twitapisearchatom.php | 368 ++++++++++++++++++++++++++++++++++++++++++ actions/twitapisearchjson.php | 6 +- 2 files changed, 371 insertions(+), 3 deletions(-) create mode 100644 actions/twitapisearchatom.php (limited to 'actions') diff --git a/actions/twitapisearchatom.php b/actions/twitapisearchatom.php new file mode 100644 index 000000000..3ab82bfb6 --- /dev/null +++ b/actions/twitapisearchatom.php @@ -0,0 +1,368 @@ +. + * + * @category Search + * @package Laconica + * @author Zach Copley + * @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 for outputting search results in Twitter compatible Atom + * format. + * + * TODO: abstract Atom stuff into a ruseable base class like + * RSS10Action. + * + * @category Search + * @package Laconica + * @author Zach Copley + * @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 TwitapisearchatomAction extends TwitterapiAction +{ + + var $notices; + var $cnt; + var $query; + var $lang; + var $rpp; + var $page; + var $since_id; + var $geocode; + + /** + * Constructor + * + * Just wraps the Action constructor. + * + * @param string $output URI to output to, default = stdout + * @param boolean $indent Whether to indent output, default true + * + * @see Action::__construct + */ + + function __construct($output='php://output', $indent=true) + { + parent::__construct($output, $indent); + } + + /** + * Do we need to write to the database? + * + * @return boolean true + */ + + function isReadonly() + { + return true; + } + + /** + * Read arguments and initialize members + * + * @param array $args Arguments from $_REQUEST + * + * @return boolean success + * + */ + + 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; + } + + // TODO: Suppport since_id -- we need to tweak the backend + // Search classes to support it. + + $this->since_id = $this->trimmed('since_id'); + $this->geocode = $this->trimmed('geocode'); + + // TODO: Also, language and geocode + + return true; + } + + /** + * Handle a request + * + * @param array $args Arguments from $_REQUEST + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + $this->showAtom(); + } + + /** + * Get the notices to output as results. This also sets some class + * attrs so we can use them to calculate pagination, and output + * since_id and max_id. + * + * @return array an array of Notice objects sorted in reverse chron + */ + + function getNotices() + { + // TODO: Support search operators like from: and to:, boolean, etc. + + $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); + $this->cnt = $notice->find(); + + $cnt = 0; + + while ($notice->fetch()) { + + ++$cnt; + + if (!$this->max_id) { + $this->max_id = $notice->id; + } + + if ($cnt > $this->rpp) { + break; + } + + $notices[] = clone($notice); + } + + return $notices; + } + + /** + * Output search results as an Atom feed + * + * @return void + */ + + function showAtom() + { + $notices = $this->getNotices(); + + $this->initAtom(); + $this->showFeed(); + + foreach ($notices as $n) { + $this->showEntry($n); + } + + $this->endAtom(); + } + + /** + * Show feed specific Atom elements + * + * @return void + */ + + function showFeed() + { + // TODO: A9 OpenSearch stuff like search.twitter.com? + + $lang = common_config('site', 'language'); + $server = common_config('site', 'server'); + $sitename = common_config('site', 'name'); + + // XXX: Use xmlns:laconica instead? + + $this->elementStart('feed', + array('xmlns' => 'http://www.w3.org/2005/Atom', + 'xmlns:twitter' => 'http://api.twitter.com/', + 'xml:lang' => $lang)); + + $year = date('Y'); + $this->element('id', null, "tag:$server,$year:search/$server"); + + $site_uri = common_path(false); + + $search_uri = $site_uri . 'api/search.atom?q=' . urlencode($this->query); + + if ($this->rpp != 15) { + $search_uri .= '&rpp=' . $this->rpp; + } + + // FIXME: this alternate link is not quite right because our + // web-based notice search doesn't support a rpp (responses per + // page) param yet + + $this->element('link', array('type' => 'text/html', + 'rel' => 'alternate', + 'href' => $site_uri . 'search/notice?q=' . + urlencode($this->query))); + + // self link + + $self_uri = $search_uri . '&page=' . $this->page; + + $this->element('link', array('type' => 'application/atom+xml', + 'rel' => 'self', + 'href' => $self_uri)); + + $this->element('title', null, "$this->query - $sitename Search"); + + // refresh link + + $refresh_uri = $search_uri . "&since_id=" . $this->max_id; + + $this->element('link', array('type' => 'application/atom+xml', + 'rel' => 'refresh', + 'href' => $refresh_uri)); + + // pagination links + + if ($this->cnt > $this->rpp) { + + $next_uri = $search_uri . "&max_id=" . $this->max_id . + '&page=' . ($this->page + 1); + + $this->element('link', array('type' => 'application/atom+xml', + 'rel' => 'next', + 'href' => $next_uri)); + } + + if ($this->page > 1) { + + $previous_uri = $search_uri . "&max_id=" . $this->max_id . + '&page=' . ($this->page - 1); + + $this->element('link', array('type' => 'application/atom+xml', + 'rel' => 'previous', + 'href' => $previous_uri)); + } + + } + + /** + * Build an Atom entry similar to search.twitter.com's based on + * a given notice + * + * @param Notice $notice the notice to use + * + * @return void + */ + + function showEntry($notice) + { + $server = common_config('site', 'server'); + $profile = $notice->getProfile(); + $nurl = common_local_url('shownotice', array('notice' => $notice->id)); + + $this->elementStart('entry'); + + $year = date('Y', strtotime($notice->created)); + + $this->element('id', null, "tag:$server,$year:$notice->id"); + $this->element('published', null, common_date_w3dtf($notice->created)); + $this->element('link', array('type' => 'text/html', + 'rel' => 'alternate', + 'href' => $nurl)); + $this->element('title', null, common_xml_safe_str(trim($notice->content))); + $this->element('content', array('type' => 'text/html'), $notice->rendered); + $this->element('updated', null, common_date_w3dtf($notice->created)); + $this->element('link', array('type' => 'image/png', + 'rel' => 'image', + 'href' => $profile->avatarUrl())); + + // TODO: Here is where we'd put in a link to an atom feed for threads + + $this->element("twitter:source", null, + htmlentities($this->source_link($notice->source))); + + $this->elementStart('author'); + + $name = $profile->nickname; + + if ($profile->fullname) { + $name .= ' (' . $profile->fullname . ')'; + } + + $this->element('name', null, $name); + $this->element('uri', null, common_profile_uri($profile)); + $this->elementEnd('author'); + + $this->elementEnd('entry'); + } + + /** + * Initialize the Atom output, send headers + * + * @return void + */ + + function initAtom() + { + header('Content-Type: application/atom+xml; charset=utf-8'); + $this->startXml(); + } + + /** + * End the Atom feed + * + * @return void + */ + + function endAtom() + { + $this->elementEnd('feed'); + } + +} diff --git a/actions/twitapisearchjson.php b/actions/twitapisearchjson.php index b50aa86b7..0f9f523a1 100644 --- a/actions/twitapisearchjson.php +++ b/actions/twitapisearchjson.php @@ -2,7 +2,7 @@ /** * Laconica, the distributed open-source microblogging tool * - * List of replies + * Action for showing Twitter-like JSON search results * * PHP version 5 * @@ -114,7 +114,7 @@ class TwitapisearchjsonAction extends TwitterapiAction function showResults() { - // TODO: Support search operators like from: and to: + // TODO: Support search operators like from: and to:, boolean, etc. $notice = new Notice(); @@ -137,7 +137,7 @@ class TwitapisearchjsonAction extends TwitterapiAction } /** - * This is a read-only action + * Do we need to write to the database? * * @return boolean true */ -- cgit v1.2.3-54-g00ecf From 162da3cbc5f05d4e01c678019c1db92a940d4da5 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sat, 7 Mar 2009 10:16:05 +0100 Subject: Correct api method names for rss2 and atom feeds in all.php action. --- actions/all.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actions') diff --git a/actions/all.php b/actions/all.php index 08dcccbdd..8e67ec0f3 100644 --- a/actions/all.php +++ b/actions/all.php @@ -77,12 +77,12 @@ class AllAction extends Action sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)), new Feed(Feed::RSS2, common_local_url('api', array('apiaction' => 'statuses', - 'method' => 'friends', + 'method' => 'friends_timeline', 'argument' => $this->user->nickname.'.rss')), sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)), new Feed(Feed::ATOM, common_local_url('api', array('apiaction' => 'statuses', - 'method' => 'friends', + 'method' => 'friends_timeline', 'argument' => $this->user->nickname.'.atom')), sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname))); } -- cgit v1.2.3-54-g00ecf From 3383e780635a29d3457a7d983a137b86c63b27ef Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sat, 7 Mar 2009 13:52:52 +0100 Subject: More api actions which need no auth when called with parameter. --- actions/api.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actions') diff --git a/actions/api.php b/actions/api.php index a27d24492..c18d551b6 100644 --- a/actions/api.php +++ b/actions/api.php @@ -127,7 +127,9 @@ class ApiAction extends Action 'laconica/wadl'); static $bareauth = array('statuses/user_timeline', + 'statuses/friends_timeline', 'statuses/friends', + 'statuses/replies', 'statuses/followers', 'favorites/favorites'); -- cgit v1.2.3-54-g00ecf From ba9c589bb2616fb1bdcb2416a934a8f91cd401e5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 7 Mar 2009 13:32:44 -0800 Subject: fix for change in OAuthUtil upstream --- actions/userauthorization.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actions') diff --git a/actions/userauthorization.php b/actions/userauthorization.php index 0dc1841d4..5fd8f8cce 100644 --- a/actions/userauthorization.php +++ b/actions/userauthorization.php @@ -197,7 +197,7 @@ class UserauthorizationAction extends Action } $parts = array(); foreach ($params as $k => $v) { - $parts[] = $k . '=' . OAuthUtil::urlencodeRFC3986($v); + $parts[] = $k . '=' . OAuthUtil::urlencode_RFC3986($v); } $query_string = implode('&', $parts); $parsed = parse_url($callback); -- cgit v1.2.3-54-g00ecf From 1a63d7d8299259dc13c8b21700bf441123947d3a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 7 Mar 2009 13:35:19 -0800 Subject: fix case of OAuthUtil method --- actions/userauthorization.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actions') diff --git a/actions/userauthorization.php b/actions/userauthorization.php index 5fd8f8cce..0566b4b70 100644 --- a/actions/userauthorization.php +++ b/actions/userauthorization.php @@ -197,7 +197,7 @@ class UserauthorizationAction extends Action } $parts = array(); foreach ($params as $k => $v) { - $parts[] = $k . '=' . OAuthUtil::urlencode_RFC3986($v); + $parts[] = $k . '=' . OAuthUtil::urlencode_rfc3986($v); } $query_string = implode('&', $parts); $parsed = parse_url($callback); -- cgit v1.2.3-54-g00ecf From c21d61840dcacb8dac3f511decef61f2fb3a80d9 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 7 Mar 2009 14:13:33 -0800 Subject: Let people view friends_timeline of others Add some code to view others' friends timelines through API. --- actions/twitapistatuses.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'actions') diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 216835026..63e29068b 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -115,9 +115,14 @@ class TwitapistatusesAction extends TwitterapiAction $since = strtotime($this->arg('since')); - $user = $this->get_user(null, $apidata); + $user = $this->get_user($apidata['api_arg'], $apidata); $this->auth_user = $user; + if (empty($user)) { + $this->clientError(_('No such user!'), 404, $apidata['content-type']); + return; + } + $profile = $user->getProfile(); $sitename = common_config('site', 'name'); -- cgit v1.2.3-54-g00ecf From f8d13817174a63dc8452ed60a00b7d336633fa88 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sun, 8 Mar 2009 01:30:11 +0100 Subject: Corrected redirect targets for some group actions. These redirects can occur when the canonical name differs from the passed name. --- actions/grouplogo.php | 2 +- actions/joingroup.php | 2 +- actions/leavegroup.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'actions') diff --git a/actions/grouplogo.php b/actions/grouplogo.php index 499db4ae8..fe6127da2 100644 --- a/actions/grouplogo.php +++ b/actions/grouplogo.php @@ -83,7 +83,7 @@ class GrouplogoAction extends Action if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); - common_redirect(common_local_url('editgroup', $args), 301); + common_redirect(common_local_url('grouplogo', $args), 301); return false; } diff --git a/actions/joingroup.php b/actions/joingroup.php index 1888ecdab..eeea4a37b 100644 --- a/actions/joingroup.php +++ b/actions/joingroup.php @@ -73,7 +73,7 @@ class JoingroupAction extends Action if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); - common_redirect(common_local_url('editgroup', $args), 301); + common_redirect(common_local_url('joingroup', $args), 301); return false; } diff --git a/actions/leavegroup.php b/actions/leavegroup.php index c7152e3c0..1d85aa3d5 100644 --- a/actions/leavegroup.php +++ b/actions/leavegroup.php @@ -73,7 +73,7 @@ class LeavegroupAction extends Action if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); - common_redirect(common_local_url('editgroup', $args), 301); + common_redirect(common_local_url('leavegroup', $args), 301); return false; } -- cgit v1.2.3-54-g00ecf From 7d7d78b7f7a5065a866468c2e8b5bd536f56611a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 7 Mar 2009 17:43:59 -0800 Subject: you can _so_ leave a group if you're its admin --- actions/leavegroup.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'actions') diff --git a/actions/leavegroup.php b/actions/leavegroup.php index 1d85aa3d5..eb30d0e50 100644 --- a/actions/leavegroup.php +++ b/actions/leavegroup.php @@ -96,12 +96,6 @@ class LeavegroupAction extends Action return false; } - if ($cur->isAdmin($this->group)) { - $this->clientError(_('You may not leave a group while you are its administrator.'), 403); - return false; - - } - return true; } -- cgit v1.2.3-54-g00ecf From f66775658c0f231c8bcf9ea310fc8ac0dbf19bfd Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 7 Mar 2009 17:47:43 -0800 Subject: trying to kill the can't-leave-a-group bug --- actions/showgroup.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'actions') diff --git a/actions/showgroup.php b/actions/showgroup.php index c20941a35..b6022840b 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -275,10 +275,8 @@ class ShowgroupAction extends Action $cur = common_current_user(); if ($cur) { if ($cur->isMember($this->group)) { - if (!$cur->isAdmin($this->group)) { - $lf = new LeaveForm($this, $this->group); - $lf->show(); - } + $lf = new LeaveForm($this, $this->group); + $lf->show(); } else { $jf = new JoinForm($this, $this->group); $jf->show(); -- cgit v1.2.3-54-g00ecf From 2133d5a4e7fc694b097fe65282e557d99ee109ad Mon Sep 17 00:00:00 2001 From: CiaranG Date: Sun, 8 Mar 2009 16:16:10 +0000 Subject: PostgreSQL - some more fixes to make queries compatible with both databases. (submitted by oxygene) --- actions/postnotice.php | 2 +- actions/twittersettings.php | 8 ++++---- lib/jabber.php | 4 ++-- lib/util.php | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'actions') diff --git a/actions/postnotice.php b/actions/postnotice.php index 0b4735296..c32d8ca94 100644 --- a/actions/postnotice.php +++ b/actions/postnotice.php @@ -79,7 +79,7 @@ class PostnoticeAction extends Action } $notice = Notice::staticGet('uri', $notice_uri); if (!$notice) { - $notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, 0, $notice_uri); + $notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, null, $notice_uri); if (is_string($notice)) { common_server_serror($notice, 500); return false; diff --git a/actions/twittersettings.php b/actions/twittersettings.php index a79859bbf..45725d3ff 100644 --- a/actions/twittersettings.php +++ b/actions/twittersettings.php @@ -186,12 +186,12 @@ class TwittersettingsAction extends ConnectSettingsAction $current_user = common_current_user(); - $qry = 'SELECT user.* ' . + $qry = 'SELECT "user".* ' . 'FROM subscription ' . - 'JOIN user ON subscription.subscribed = user.id ' . - 'JOIN foreign_link ON foreign_link.user_id = user.id ' . + 'JOIN "user" ON subscription.subscribed = "user".id ' . + 'JOIN foreign_link ON foreign_link.user_id = "user".id ' . 'WHERE subscriber = %d ' . - 'ORDER BY user.nickname'; + 'ORDER BY "user".nickname'; $user = new User(); diff --git a/lib/jabber.php b/lib/jabber.php index 3fbb3e1ab..3cd3b0d37 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -410,8 +410,8 @@ function jabber_broadcast_notice($notice) "ON $UT.id = notice_inbox.user_id " . 'WHERE notice_inbox.notice_id = ' . $notice->id . ' ' . 'AND notice_inbox.source = 2 ' . - 'AND user.jabber is not null ' . - 'AND user.jabbernotify = 1 '); + "AND $UT.jabber is not null " . + "AND $UT.jabbernotify = 1 "); while ($user->fetch()) { if (!array_key_exists($user->id, $sent_to)) { diff --git a/lib/util.php b/lib/util.php index ca8376f28..221175ccd 100644 --- a/lib/util.php +++ b/lib/util.php @@ -688,7 +688,7 @@ function common_relative_profile($sender, $nickname, $dt=null) $recipient = new Profile(); // XXX: use a join instead of a subquery $recipient->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$sender->id.' and subscribed = id)', 'AND'); - $recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND'); + $recipient->whereAdd("nickname = '" . trim($nickname) . "'", 'AND'); if ($recipient->find(true)) { // XXX: should probably differentiate between profiles with // the same name by date of most recent update @@ -698,7 +698,7 @@ function common_relative_profile($sender, $nickname, $dt=null) $recipient = new Profile(); // XXX: use a join instead of a subquery $recipient->whereAdd('EXISTS (SELECT subscriber from subscription where subscribed = '.$sender->id.' and subscriber = id)', 'AND'); - $recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND'); + $recipient->whereAdd("nickname = '" . trim($nickname) . "'", 'AND'); if ($recipient->find(true)) { // XXX: should probably differentiate between profiles with // the same name by date of most recent update -- cgit v1.2.3-54-g00ecf From 4c8c9bb9dfe962e0d34f1acb2df20ddd2728920c Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sat, 7 Mar 2009 02:19:18 +0100 Subject: Define undefined variable. --- actions/allrss.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'actions') diff --git a/actions/allrss.php b/actions/allrss.php index 0114c4396..45f3946a6 100644 --- a/actions/allrss.php +++ b/actions/allrss.php @@ -81,8 +81,9 @@ class AllrssAction extends Rss10Action */ function getNotices($limit=0) { - $user = $this->user; - $notice = $user->noticesWithFriends(0, $limit); + $user = $this->user; + $notice = $user->noticesWithFriends(0, $limit); + $notices = array(); while ($notice->fetch()) { $notices[] = clone($notice); -- cgit v1.2.3-54-g00ecf From 6ab9d6b14016cf97fe1a31d89591e1a0e919c8a7 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sun, 8 Mar 2009 17:09:09 +0100 Subject: Remove additional output as response to updateprofile. This output breaks our own response validation and is not part of the OMB spec. --- actions/updateprofile.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'actions') diff --git a/actions/updateprofile.php b/actions/updateprofile.php index 4751a04ff..2268c432f 100644 --- a/actions/updateprofile.php +++ b/actions/updateprofile.php @@ -34,6 +34,8 @@ class UpdateprofileAction extends Action $server = omb_oauth_server(); list($consumer, $token) = $server->verify_request($req); if ($this->update_profile($req, $consumer, $token)) { + header('HTTP/1.1 200 OK'); + header('Content-type: text/plain'); print "omb_version=".OMB_VERSION_01; } } catch (OAuthException $e) { @@ -173,10 +175,6 @@ class UpdateprofileAction extends Action return false; } } - header('HTTP/1.1 200 OK'); - header('Content-type: text/plain'); - print 'Updated profile'; - print "\n"; return true; } } -- cgit v1.2.3-54-g00ecf From fbe794e44d235d2f66ef418796f87947631afb6a Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Tue, 3 Mar 2009 16:12:05 +0100 Subject: Improve handling of null values in profile parameters. This commit fixes two issues: - Allowing remote users to clear profile parameters via OMB. - Improved handling of profile parameters which evaluate to false ('0' for example) --- actions/finishremotesubscribe.php | 8 ++++---- actions/remotesubscribe.php | 8 ++++---- actions/updateprofile.php | 14 ++++++++------ actions/userauthorization.php | 26 +++++++++++++------------- lib/profilelist.php | 10 +++++----- 5 files changed, 34 insertions(+), 32 deletions(-) (limited to 'actions') diff --git a/actions/finishremotesubscribe.php b/actions/finishremotesubscribe.php index acfacbdc1..eaf57c2d8 100644 --- a/actions/finishremotesubscribe.php +++ b/actions/finishremotesubscribe.php @@ -136,16 +136,16 @@ class FinishremotesubscribeAction extends Action $profile->nickname = $nickname; $profile->profileurl = $profile_url; - if ($fullname) { + if (!is_null($fullname)) { $profile->fullname = $fullname; } - if ($homepage) { + if (!is_null($homepage)) { $profile->homepage = $homepage; } - if ($bio) { + if (!is_null($bio)) { $profile->bio = $bio; } - if ($location) { + if (!is_null($location)) { $profile->location = $location; } diff --git a/actions/remotesubscribe.php b/actions/remotesubscribe.php index 7ea7acd6d..a2e01bd3a 100644 --- a/actions/remotesubscribe.php +++ b/actions/remotesubscribe.php @@ -367,16 +367,16 @@ class RemotesubscribeAction extends Action return; } - if ($profile->fullname) { + if (!is_null($profile->fullname)) { $req->set_parameter('omb_listenee_fullname', $profile->fullname); } - if ($profile->homepage) { + if (!is_null($profile->homepage)) { $req->set_parameter('omb_listenee_homepage', $profile->homepage); } - if ($profile->bio) { + if (!is_null($profile->bio)) { $req->set_parameter('omb_listenee_bio', $profile->bio); } - if ($profile->location) { + if (!is_null($profile->location)) { $req->set_parameter('omb_listenee_location', $profile->location); } $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); diff --git a/actions/updateprofile.php b/actions/updateprofile.php index 2268c432f..7dc52fda9 100644 --- a/actions/updateprofile.php +++ b/actions/updateprofile.php @@ -138,22 +138,24 @@ class UpdateprofileAction extends Action $orig_profile = clone($profile); - if ($nickname) { + /* Use values even if they are an empty string. Parsing an empty string in + updateProfile is the specified way of clearing a parameter in OMB. */ + if (!is_null($nickname)) { $profile->nickname = $nickname; } - if ($profile_url) { + if (!is_null($profile_url)) { $profile->profileurl = $profile_url; } - if ($fullname) { + if (!is_null($fullname)) { $profile->fullname = $fullname; } - if ($homepage) { + if (!is_null($homepage)) { $profile->homepage = $homepage; } - if ($bio) { + if (!is_null($bio)) { $profile->bio = $bio; } - if ($location) { + if (!is_null($location)) { $profile->location = $location; } diff --git a/actions/userauthorization.php b/actions/userauthorization.php index 0566b4b70..6a76e3a4c 100644 --- a/actions/userauthorization.php +++ b/actions/userauthorization.php @@ -113,9 +113,9 @@ class UserauthorizationAction extends Action $this->element('a', array('href' => $profile, 'class' => 'external profile nickname'), $nickname); - if ($fullname) { + if (!is_null($fullname)) { $this->elementStart('div', 'fullname'); - if ($homepage) { + if (!is_null($homepage)) { $this->element('a', array('href' => $homepage), $fullname); } else { @@ -123,10 +123,10 @@ class UserauthorizationAction extends Action } $this->elementEnd('div'); } - if ($location) { + if (!is_null($location)) { $this->element('div', 'location', $location); } - if ($bio) { + if (!is_null($bio)) { $this->element('div', 'bio', $bio); } $this->elementStart('div', 'license'); @@ -179,16 +179,16 @@ class UserauthorizationAction extends Action $params['omb_listener_nickname'] = $user->nickname; $params['omb_listener_profile'] = common_local_url('showstream', array('nickname' => $user->nickname)); - if ($profile->fullname) { + if (!is_null($profile->fullname)) { $params['omb_listener_fullname'] = $profile->fullname; } - if ($profile->homepage) { + if (!is_null($profile->homepage)) { $params['omb_listener_homepage'] = $profile->homepage; } - if ($profile->bio) { + if (!is_null($profile->bio)) { $params['omb_listener_bio'] = $profile->bio; } - if ($profile->location) { + if (!is_null($profile->location)) { $params['omb_listener_location'] = $profile->location; } $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); @@ -267,16 +267,16 @@ class UserauthorizationAction extends Action $profile->nickname = $nickname; $profile->profileurl = $profile_url; - if ($fullname) { + if (!is_null($fullname)) { $profile->fullname = $fullname; } - if ($homepage) { + if (!is_null($homepage)) { $profile->homepage = $homepage; } - if ($bio) { + if (!is_null($bio)) { $profile->bio = $bio; } - if ($location) { + if (!is_null($location)) { $profile->location = $location; } @@ -409,7 +409,7 @@ class UserauthorizationAction extends Action 'omb_listenee_profile', 'omb_listenee_nickname', 'omb_listenee_license') as $param) { - if (!$req->get_parameter($param)) { + if (is_null($req->get_parameter($param))) { throw new OAuthException("Required parameter '$param' not found"); } } diff --git a/lib/profilelist.php b/lib/profilelist.php index c2040fbc2..75053b7a4 100644 --- a/lib/profilelist.php +++ b/lib/profilelist.php @@ -102,13 +102,13 @@ class ProfileList extends Widget 'alt' => ($this->profile->fullname) ? $this->profile->fullname : $this->profile->nickname)); - $hasFN = ($this->profile->fullname) ? 'nickname' : 'fn nickname'; + $hasFN = ($this->profile->fullname !== '') ? 'nickname' : 'fn nickname'; $this->out->elementStart('span', $hasFN); $this->out->raw($this->highlight($this->profile->nickname)); $this->out->elementEnd('span'); $this->out->elementEnd('a'); - if ($this->profile->fullname) { + if ($this->profile->fullname !== '') { $this->out->elementStart('dl', 'entity_fn'); $this->out->element('dt', null, 'Full name'); $this->out->elementStart('dd'); @@ -118,7 +118,7 @@ class ProfileList extends Widget $this->out->elementEnd('dd'); $this->out->elementEnd('dl'); } - if ($this->profile->location) { + if ($this->profile->location !== '') { $this->out->elementStart('dl', 'entity_location'); $this->out->element('dt', null, _('Location')); $this->out->elementStart('dd', 'label'); @@ -126,7 +126,7 @@ class ProfileList extends Widget $this->out->elementEnd('dd'); $this->out->elementEnd('dl'); } - if ($this->profile->homepage) { + if ($this->profile->homepage !== '') { $this->out->elementStart('dl', 'entity_url'); $this->out->element('dt', null, _('URL')); $this->out->elementStart('dd'); @@ -137,7 +137,7 @@ class ProfileList extends Widget $this->out->elementEnd('dd'); $this->out->elementEnd('dl'); } - if ($this->profile->bio) { + if ($this->profile->bio !== '') { $this->out->elementStart('dl', 'entity_note'); $this->out->element('dt', null, _('Note')); $this->out->elementStart('dd', 'note'); -- cgit v1.2.3-54-g00ecf From f87ef9b72b8e054296a3fd37c74f07af5f6a6c38 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 9 Mar 2009 09:45:40 +0100 Subject: Fixes #1277: Typo in variable name in actions/twitapidirect_messages.php. --- actions/twitapidirect_messages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actions') diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php index db55e8cd0..ce98bf6ec 100644 --- a/actions/twitapidirect_messages.php +++ b/actions/twitapidirect_messages.php @@ -190,7 +190,7 @@ class Twitapidirect_messagesAction extends TwitterapiAction $this->init_document('xml'); $this->elementStart('direct-messages', array('type' => 'array')); - if (is_array($messages)) { + if (is_array($message)) { foreach ($message as $m) { $twitter_dm = $this->twitter_dmsg_array($m); $this->show_twitter_xml_dmsg($twitter_dm); -- cgit v1.2.3-54-g00ecf From 945bbf00dc9ee106359e9387956c72c1290d12fc Mon Sep 17 00:00:00 2001 From: CiaranG Date: Mon, 9 Mar 2009 20:24:56 +0000 Subject: PostgreSQL - a couple more GROUP BY queries that needed to be explicit --- actions/favorited.php | 2 +- lib/topposterssection.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'actions') diff --git a/actions/favorited.php b/actions/favorited.php index 5082f4a4e..231b97897 100644 --- a/actions/favorited.php +++ b/actions/favorited.php @@ -178,7 +178,7 @@ class FavoritedAction extends Action $qry = 'SELECT notice.*, '. $weightexpr . ' as weight ' . 'FROM notice JOIN fave ON notice.id = fave.notice_id ' . - 'GROUP BY fave.notice_id ' . + 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source ' . 'ORDER BY weight DESC'; $offset = ($this->page - 1) * NOTICES_PER_PAGE; diff --git a/lib/topposterssection.php b/lib/topposterssection.php index 4bd59ac79..1a2ce0014 100644 --- a/lib/topposterssection.php +++ b/lib/topposterssection.php @@ -51,7 +51,7 @@ class TopPostersSection extends ProfileSection $qry = 'SELECT profile.*, count(*) as value ' . 'FROM profile JOIN notice ON profile.id = notice.profile_id ' . (common_config('public', 'localonly') ? 'WHERE is_local = 1 ' : '') . - 'GROUP BY profile.id ' . + 'GROUP BY profile.id,nickname,fullname,profileurl,homepage,bio,location,profile.created,profile.modified,textsearch ' . 'ORDER BY value DESC '; $limit = PROFILES_PER_SECTION; -- cgit v1.2.3-54-g00ecf From c6cd87c106b763ed5610dae64e5a02ba86609ece Mon Sep 17 00:00:00 2001 From: Eric Helgeson Date: Mon, 9 Mar 2009 20:01:35 -0500 Subject: Changed all $config[][] calls to common_config() --- actions/finishopenidlogin.php | 3 +-- actions/noticesearchrss.php | 3 +-- actions/publicrss.php | 5 ++--- actions/remotesubscribe.php | 4 +--- lib/mail.php | 7 +++---- lib/omb.php | 1 - lib/searchaction.php | 4 +--- lib/twitter.php | 3 +-- lib/util.php | 11 ++++------- 9 files changed, 14 insertions(+), 27 deletions(-) (limited to 'actions') diff --git a/actions/finishopenidlogin.php b/actions/finishopenidlogin.php index 6d92cb9aa..52d9be29c 100644 --- a/actions/finishopenidlogin.php +++ b/actions/finishopenidlogin.php @@ -62,9 +62,8 @@ class FinishopenidloginAction extends Action if ($this->error) { $this->element('div', array('class' => 'error'), $this->error); } else { - global $config; $this->element('div', 'instructions', - sprintf(_('This is the first time you\'ve logged into %s so we must connect your OpenID to a local account. You can either create a new account, or connect with your existing account, if you have one.'), $config['site']['name'])); + sprintf(_('This is the first time you\'ve logged into %s so we must connect your OpenID to a local account. You can either create a new account, or connect with your existing account, if you have one.'), common_config('site', 'name'))); } } diff --git a/actions/noticesearchrss.php b/actions/noticesearchrss.php index 7172977ee..0f98ed04b 100644 --- a/actions/noticesearchrss.php +++ b/actions/noticesearchrss.php @@ -82,10 +82,9 @@ class NoticesearchrssAction extends Rss10Action function getChannel() { - global $config; $q = $this->trimmed('q'); $c = array('url' => common_local_url('noticesearchrss', array('q' => $q)), - 'title' => $config['site']['name'] . sprintf(_(' Search Stream for "%s"'), $q), + 'title' => common_config('site', 'name') . sprintf(_(' Search Stream for "%s"'), $q), 'link' => common_local_url('noticesearch', array('q' => $q)), 'description' => sprintf(_('All updates matching search term "%s"'), $q)); return $c; diff --git a/actions/publicrss.php b/actions/publicrss.php index c35877997..77e26e0f4 100644 --- a/actions/publicrss.php +++ b/actions/publicrss.php @@ -84,12 +84,11 @@ class PublicrssAction extends Rss10Action */ function getChannel() { - global $config; $c = array( 'url' => common_local_url('publicrss') - , 'title' => sprintf(_('%s Public Stream'), $config['site']['name']) + , 'title' => sprintf(_('%s Public Stream'), common_config('site', 'name')) , 'link' => common_local_url('public') - , 'description' => sprintf(_('All updates for %s'), $config['site']['name'])); + , 'description' => sprintf(_('All updates for %s'), common_config('site', 'name'))); return $c; } diff --git a/actions/remotesubscribe.php b/actions/remotesubscribe.php index a2e01bd3a..af130f425 100644 --- a/actions/remotesubscribe.php +++ b/actions/remotesubscribe.php @@ -333,8 +333,6 @@ class RemotesubscribeAction extends Action function requestAuthorization($user, $omb, $token, $secret) { - global $config; # for license URL - $con = omb_oauth_consumer(); $tok = new OAuthToken($token, $secret); @@ -358,7 +356,7 @@ class RemotesubscribeAction extends Action $req->set_parameter('omb_listenee', $user->uri); $req->set_parameter('omb_listenee_profile', common_profile_url($user->nickname)); $req->set_parameter('omb_listenee_nickname', $user->nickname); - $req->set_parameter('omb_listenee_license', $config['license']['url']); + $req->set_parameter('omb_listenee_license', common_config('license', 'url')); $profile = $user->getProfile(); if (!$profile) { diff --git a/lib/mail.php b/lib/mail.php index 9fa86de5c..dde7571eb 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -50,10 +50,9 @@ function mail_backend() static $backend = null; if (!$backend) { - global $config; - $backend = Mail::factory($config['mail']['backend'], - ($config['mail']['params']) ? - $config['mail']['params'] : + $backend = Mail::factory(common_config('mail', 'backend'), + (common_config('mail', 'params')) ? + common_config('mail', 'params') : array()); if (PEAR::isError($backend)) { common_server_error($backend->getMessage(), 500); diff --git a/lib/omb.php b/lib/omb.php index c302a7b64..878c735da 100644 --- a/lib/omb.php +++ b/lib/omb.php @@ -251,7 +251,6 @@ function omb_broadcast_profile($profile) function omb_update_profile($profile, $remote_profile, $subscription) { - global $config; # for license URL $user = User::staticGet($profile->id); $con = omb_oauth_consumer(); $token = new OAuthToken($subscription->token, $subscription->secret); diff --git a/lib/searchaction.php b/lib/searchaction.php index df6876445..c762db16f 100644 --- a/lib/searchaction.php +++ b/lib/searchaction.php @@ -110,8 +110,6 @@ class SearchAction extends Action function showForm($error=null) { - global $config; - $q = $this->trimmed('q'); $page = $this->trimmed('page', 1); $this->elementStart('form', array('method' => 'get', @@ -122,7 +120,7 @@ class SearchAction extends Action $this->element('legend', null, _('Search site')); $this->elementStart('ul', 'form_data'); $this->elementStart('li'); - if (!isset($config['site']['fancy']) || !$config['site']['fancy']) { + if (!common_config('site', 'fancy')) { $this->hidden('action', $this->trimmed('action')); } $this->input('q', 'Keyword(s)', $q); diff --git a/lib/twitter.php b/lib/twitter.php index deb6fd276..a3929524b 100644 --- a/lib/twitter.php +++ b/lib/twitter.php @@ -224,7 +224,6 @@ function is_twitter_bound($notice, $flink) { function broadcast_twitter($notice) { - global $config; $success = true; $flink = Foreign_link::getByUserID($notice->profile_id, @@ -248,7 +247,7 @@ function broadcast_twitter($notice) CURLOPT_POSTFIELDS => array( 'status' => $statustxt, - 'source' => $config['integration']['source'] + 'source' => common_config('integration', 'source') ), CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => true, diff --git a/lib/util.php b/lib/util.php index ca9006d64..6341438ca 100644 --- a/lib/util.php +++ b/lib/util.php @@ -72,8 +72,7 @@ function common_timezone() } } - global $config; - return $config['site']['timezone']; + return common_config('site', 'timezone'); } function common_language() @@ -737,9 +736,8 @@ function common_local_url($action, $args=null, $params=null, $fragment=null) function common_path($relative) { - global $config; - $pathpart = ($config['site']['path']) ? $config['site']['path']."/" : ''; - return "http://".$config['site']['server'].'/'.$pathpart.$relative; + $pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : ''; + return "http://".common_config('site', 'server').'/'.$pathpart.$relative; } function common_date_string($dt) @@ -992,8 +990,7 @@ function common_ensure_syslog() { static $initialized = false; if (!$initialized) { - global $config; - openlog($config['syslog']['appname'], 0, LOG_USER); + openlog(common_config('syslog', 'appname'), 0, LOG_USER); $initialized = true; } } -- cgit v1.2.3-54-g00ecf From 91980c73a76bcbedd5f23a3232988a32aa8c7127 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 10 Mar 2009 16:15:57 -0700 Subject: Updates to the API to improve Atom feeds --- actions/twitapidirect_messages.php | 22 +++++--- actions/twitapifavorites.php | 14 +++-- actions/twitapistatuses.php | 53 +++++++++++++------ lib/common.php | 3 +- lib/router.php | 8 +-- lib/twitterapi.php | 103 ++++++++----------------------------- 6 files changed, 90 insertions(+), 113 deletions(-) (limited to 'actions') diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php index ce98bf6ec..7101db8df 100644 --- a/actions/twitapidirect_messages.php +++ b/actions/twitapidirect_messages.php @@ -38,7 +38,6 @@ class Twitapidirect_messagesAction extends TwitterapiAction function show_messages($args, $apidata, $type) { - $user = $apidata['user']; $count = $this->arg('count'); @@ -102,7 +101,17 @@ class Twitapidirect_messagesAction extends TwitterapiAction $this->show_rss_dmsgs($message, $title, $link, $subtitle); break; case 'atom': - $this->show_atom_dmsgs($message, $title, $link, $subtitle); + $selfuri = common_root_url() . 'api/direct_messages'; + $selfuri .= ($type == 'received') ? '.atom' : '/sent.atom'; + $taguribase = common_config('integration', 'taguri'); + + if ($type == 'sent') { + $id = "tag:$taguribase:SentDirectMessages:" . $user->id; + } else { + $id = "tag:$taguribase:DirectMessages:" . $user->id; + } + + $this->show_atom_dmsgs($message, $title, $link, $subtitle, $selfuri, $id); break; case 'json': $this->show_json_dmsgs($message); @@ -261,16 +270,17 @@ class Twitapidirect_messagesAction extends TwitterapiAction } - function show_atom_dmsgs($message, $title, $link, $subtitle) + function show_atom_dmsgs($message, $title, $link, $subtitle, $selfuri, $id) { $this->init_document('atom'); $this->element('title', null, $title); - $siteserver = common_config('site', 'server'); - $this->element('id', null, "tag:$siteserver,2008:DirectMessage"); + $this->element('id', null, $id); $this->element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), null); - $this->element('updated', null, common_date_iso8601(strftime('%c'))); + $this->element('link', array('href' => $selfuri, 'rel' => 'self', + 'type' => 'application/atom+xml'), null); + $this->element('updated', null, common_date_iso8601('now')); $this->element('subtitle', null, $subtitle); if (is_array($message)) { diff --git a/actions/twitapifavorites.php b/actions/twitapifavorites.php index 737b7229f..31dce341b 100644 --- a/actions/twitapifavorites.php +++ b/actions/twitapifavorites.php @@ -61,10 +61,9 @@ class TwitapifavoritesAction extends TwitterapiAction } $sitename = common_config('site', 'name'); - $siteserver = common_config('site', 'server'); - $title = sprintf(_('%s / Favorites from %s'), $sitename, $user->nickname); - $id = "tag:$siteserver:favorites:".$user->id; + $taguribase = common_config('integration', 'taguri'); + $id = "tag:$taguribase:Favorites:".$user->id; $link = common_local_url('favorites', array('nickname' => $user->nickname)); $subtitle = sprintf(_('%s updates favorited by %s / %s.'), $sitename, $profile->getBestName(), $user->nickname); @@ -76,7 +75,14 @@ class TwitapifavoritesAction extends TwitterapiAction $this->show_rss_timeline($notice, $title, $link, $subtitle); break; case 'atom': - $this->show_atom_timeline($notice, $title, $id, $link, $subtitle); + if (isset($apidata['api_arg'])) { + $selfuri = $selfuri = common_root_url() . + 'api/favorites/' . $apidata['api_arg'] . '.atom'; + } else { + $selfuri = $selfuri = common_root_url() . + 'api/favorites.atom'; + } + $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri); break; case 'json': $this->show_json_timeline($notice); diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 63e29068b..b50a17abd 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -29,10 +29,12 @@ class TwitapistatusesAction extends TwitterapiAction parent::handle($args); $sitename = common_config('site', 'name'); - $siteserver = common_config('site', 'server'); $title = sprintf(_("%s public timeline"), $sitename); - $id = "tag:$siteserver:Statuses"; + + $taguribase = common_config('integration', 'taguri'); + $id = "tag:$taguribase:PublicTimeline"; $link = common_root_url(); + $subtitle = sprintf(_("%s updates from everyone!"), $sitename); // Number of public statuses to return by default -- Twitter sends 20 @@ -70,7 +72,8 @@ class TwitapistatusesAction extends TwitterapiAction $this->show_rss_timeline($notice, $title, $link, $subtitle); break; case 'atom': - $this->show_atom_timeline($notice, $title, $id, $link, $subtitle); + $selfuri = common_root_url() . 'api/statuses/public_timeline.atom'; + $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri); break; case 'json': $this->show_json_timeline($notice); @@ -114,7 +117,6 @@ class TwitapistatusesAction extends TwitterapiAction } $since = strtotime($this->arg('since')); - $user = $this->get_user($apidata['api_arg'], $apidata); $this->auth_user = $user; @@ -124,12 +126,10 @@ class TwitapistatusesAction extends TwitterapiAction } $profile = $user->getProfile(); - $sitename = common_config('site', 'name'); - $siteserver = common_config('site', 'server'); - $title = sprintf(_("%s and friends"), $user->nickname); - $id = "tag:$siteserver:friends:" . $user->id; + $taguribase = common_config('integration', 'taguri'); + $id = "tag:$taguribase:FriendsTimeline:" . $user->id; $link = common_local_url('all', array('nickname' => $user->nickname)); $subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'), $user->nickname, $sitename); @@ -143,7 +143,14 @@ class TwitapistatusesAction extends TwitterapiAction $this->show_rss_timeline($notice, $title, $link, $subtitle); break; case 'atom': - $this->show_atom_timeline($notice, $title, $id, $link, $subtitle); + if (isset($apidata['api_arg'])) { + $selfuri = $selfuri = common_root_url() . + 'api/statuses/friends_timeline/' . $apidata['api_arg'] . '.atom'; + } else { + $selfuri = $selfuri = common_root_url() . + 'api/statuses/friends_timeline.atom'; + } + $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri); break; case 'json': $this->show_json_timeline($notice); @@ -199,10 +206,9 @@ class TwitapistatusesAction extends TwitterapiAction $since = strtotime($this->arg('since')); $sitename = common_config('site', 'name'); - $siteserver = common_config('site', 'server'); - $title = sprintf(_("%s timeline"), $user->nickname); - $id = "tag:$siteserver:user:".$user->id; + $taguribase = common_config('integration', 'taguri'); + $id = "tag:$taguribase:UserTimeline:".$user->id; $link = common_local_url('showstream', array('nickname' => $user->nickname)); $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $user->nickname, $sitename); @@ -224,7 +230,14 @@ class TwitapistatusesAction extends TwitterapiAction $this->show_rss_timeline($notice, $title, $link, $subtitle, $suplink); break; case 'atom': - $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink); + if (isset($apidata['api_arg'])) { + $selfuri = $selfuri = common_root_url() . + 'api/statuses/user_timeline/' . $apidata['api_arg'] . '.atom'; + } else { + $selfuri = $selfuri = common_root_url() . + 'api/statuses/user_timeline.atom'; + } + $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink, $selfuri); break; case 'json': $this->show_json_timeline($notice); @@ -347,10 +360,9 @@ class TwitapistatusesAction extends TwitterapiAction $profile = $user->getProfile(); $sitename = common_config('site', 'name'); - $siteserver = common_config('site', 'server'); - $title = sprintf(_('%1$s / Updates replying to %2$s'), $sitename, $user->nickname); - $id = "tag:$siteserver:replies:".$user->id; + $taguribase = common_config('integration', 'taguri'); + $id = "tag:$taguribase:Replies:".$user->id; $link = common_local_url('replies', array('nickname' => $user->nickname)); $subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'), $sitename, $user->nickname, $profile->getBestName()); @@ -388,7 +400,14 @@ class TwitapistatusesAction extends TwitterapiAction $this->show_rss_timeline($notices, $title, $link, $subtitle); break; case 'atom': - $this->show_atom_timeline($notices, $title, $id, $link, $subtitle); + if (isset($apidata['api_arg'])) { + $selfuri = $selfuri = common_root_url() . + 'api/statuses/replies/' . $apidata['api_arg'] . '.atom'; + } else { + $selfuri = $selfuri = common_root_url() . + 'api/statuses/replies.atom'; + } + $this->show_atom_timeline($notices, $title, $id, $link, $subtitle, null, $selfuri); break; case 'json': $this->show_json_timeline($notices); diff --git a/lib/common.php b/lib/common.php index 917fdeafa..c3d697aee 100644 --- a/lib/common.php +++ b/lib/common.php @@ -140,7 +140,8 @@ $config = 'user' => false, 'group' => false), 'integration' => - array('source' => 'Laconica'), # source attribute for Twitter + array('source' => 'Laconica', # source attribute for Twitter + 'taguri' => $_server.',2009'), # base for tag URIs 'memcached' => array('enabled' => false, 'server' => 'localhost', diff --git a/lib/router.php b/lib/router.php index 902f25d8a..50d5a4ee1 100644 --- a/lib/router.php +++ b/lib/router.php @@ -226,7 +226,7 @@ class Router $m->connect('api/statuses/:method/:argument', array('action' => 'api', 'apiaction' => 'statuses'), - array('method' => '(user_timeline|friends_timeline|show|destroy|friends|followers)')); + array('method' => '(user_timeline|friends_timeline|replies|show|destroy|friends|followers)')); // users @@ -257,7 +257,7 @@ class Router } foreach (array('xml', 'json', 'rss', 'atom') as $e) { - $m->connect('api/direct_message/sent.'.$e, + $m->connect('api/direct_messages/sent.'.$e, array('action' => 'api', 'apiaction' => 'direct_messages', 'method' => 'sent.'.$e)); @@ -277,7 +277,7 @@ class Router $m->connect('api/friendships/:method', array('action' => 'api', 'apiaction' => 'friendships'), - array('method' => 'exists(\.(xml|json|rss|atom))')); + array('method' => 'exists(\.(xml|json))')); // Social graph @@ -360,7 +360,7 @@ class Router // user stuff - foreach (array('subscriptions', 'subscribers', + foreach (array('subscriptions', 'subscribers', 'nudge', 'xrds', 'all', 'foaf', 'replies', 'inbox', 'outbox', 'microsummary') as $a) { $m->connect(':nickname/'.$a, diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 1de169a0b..e7239acd5 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -127,8 +127,6 @@ class TwitterapiAction extends Action { $profile = $notice->getProfile(); - - $server = common_config('site', 'server'); $entry = array(); # We trim() to avoid extraneous whitespace in the output @@ -137,8 +135,12 @@ class TwitterapiAction extends Action $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); - $entry['id'] = "tag:$server,2008:$entry[link]"; + + $taguribase = common_config('integration', 'taguri'); + $entry['id'] = "tag:$taguribase:$entry[link]"; + $entry['updated'] = $entry['published']; + $entry['author'] = $profile->getBestName(); # RSS Item specific $entry['description'] = $entry['content']; @@ -151,7 +153,6 @@ class TwitterapiAction extends Action function twitter_rss_dmsg_array($message) { - $server = common_config('site', 'server'); $entry = array(); $entry['title'] = sprintf('Message from %s to %s', @@ -160,8 +161,12 @@ class TwitterapiAction extends Action $entry['content'] = common_xml_safe_str(trim($message->content)); $entry['link'] = common_local_url('showmessage', array('message' => $message->id)); $entry['published'] = common_date_iso8601($message->created); - $entry['id'] = "tag:$server,2008:$entry[link]"; + + $taguribase = common_config('integration', 'taguri'); + + $entry['id'] = "tag:$taguribase,:$entry[link]"; $entry['updated'] = $entry['published']; + $entry['author'] = $message->getFrom()->getBestName(); # RSS Item specific $entry['description'] = $entry['content']; @@ -242,6 +247,9 @@ class TwitterapiAction extends Action $this->element('published', null, $entry['published']); $this->element('updated', null, $entry['updated']); $this->element('link', array('href' => $entry['link'], 'rel' => 'alternate', 'type' => 'text/html'), null); + $this->elementStart('author'); + $this->element('name', null, $entry['author']); + $this->elementEnd('author'); $this->elementEnd('entry'); } @@ -358,7 +366,7 @@ class TwitterapiAction extends Action $this->end_twitter_rss(); } - function show_atom_timeline($notice, $title, $id, $link, $subtitle=null, $suplink=null) + function show_atom_timeline($notice, $title, $id, $link, $subtitle=null, $suplink=null, $selfuri=null) { $this->init_document('atom'); @@ -366,12 +374,20 @@ class TwitterapiAction extends Action $this->element('title', null, $title); $this->element('id', null, $id); $this->element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), null); + if (!is_null($suplink)) { # For FriendFeed's SUP protocol $this->element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup', 'href' => $suplink, 'type' => 'application/json')); } + + if (!is_null($selfuri)) { + $this->element('link', array('href' => $selfuri, + 'rel' => 'self', 'type' => 'application/atom+xml'), null); + } + + $this->element('updated', null, common_date_iso8601('now')); $this->element('subtitle', null, $subtitle); if (is_array($notice)) { @@ -634,79 +650,4 @@ class TwitterapiAction extends Action return $source_name; } - function show_extended_profile($user, $apidata) - { - - $this->auth_user = $apidata['user']; - - $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_text_color'] = ''; - $twitter_user['profile_link_color'] = ''; - $twitter_user['profile_sidebar_fill_color'] = ''; - - $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; - - $following = 'false'; - - if (isset($this->auth_user)) { - if ($this->auth_user->isSubscribed($profile)) { - $following = 'true'; - } - - // Not implemented yet - $twitter_user['notifications'] = 'false'; - } - - $twitter_user['following'] = $following; - - 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'); - } - - } - } -- cgit v1.2.3-54-g00ecf From df07786f28e89474f66a910eeb3d454e3a5b75ba Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 10 Mar 2009 16:48:14 -0700 Subject: Allow unauthenticated users to view /api/statuses/replies/id.format (they can already see @replies via friends_timeline anyway). --- actions/twitapistatuses.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actions') diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index b50a17abd..323c4f1f8 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -355,8 +355,8 @@ class TwitapistatusesAction extends TwitterapiAction $since_id = $this->arg('since_id'); $before_id = $this->arg('before_id'); + $user = $this->get_user($apidata['api_arg'], $apidata); $this->auth_user = $apidata['user']; - $user = $this->auth_user; $profile = $user->getProfile(); $sitename = common_config('site', 'name'); -- cgit v1.2.3-54-g00ecf From a989c58c11004f850ff0d7bb633df570c7f68f45 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 10 Mar 2009 17:20:43 -0700 Subject: Fix tag URIs in Atom feeds for search thru the API --- actions/twitapisearchatom.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'actions') diff --git a/actions/twitapisearchatom.php b/actions/twitapisearchatom.php index 3ab82bfb6..c0e55df05 100644 --- a/actions/twitapisearchatom.php +++ b/actions/twitapisearchatom.php @@ -229,8 +229,8 @@ class TwitapisearchatomAction extends TwitterapiAction 'xmlns:twitter' => 'http://api.twitter.com/', 'xml:lang' => $lang)); - $year = date('Y'); - $this->element('id', null, "tag:$server,$year:search/$server"); + $taguribase = common_config('integration', 'taguri'); + $this->element('id', null, "tag:$taguribase:search/$server"); $site_uri = common_path(false); @@ -258,6 +258,7 @@ class TwitapisearchatomAction extends TwitterapiAction 'href' => $self_uri)); $this->element('title', null, "$this->query - $sitename Search"); + $this->element('updated', null, common_date_iso8601('now')); // refresh link @@ -308,9 +309,9 @@ class TwitapisearchatomAction extends TwitterapiAction $this->elementStart('entry'); - $year = date('Y', strtotime($notice->created)); + $taguribase = common_config('integration', 'taguri'); - $this->element('id', null, "tag:$server,$year:$notice->id"); + $this->element('id', null, "tag:$taguribase:$notice->id"); $this->element('published', null, common_date_w3dtf($notice->created)); $this->element('link', array('type' => 'text/html', 'rel' => 'alternate', -- cgit v1.2.3-54-g00ecf From 1e29cbd6919380aee54b57db62e08c5d1497d763 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 10 Mar 2009 18:17:20 -0700 Subject: Make search API Atom feeds more valid --- actions/twitapisearchatom.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'actions') diff --git a/actions/twitapisearchatom.php b/actions/twitapisearchatom.php index c0e55df05..c5f724c12 100644 --- a/actions/twitapisearchatom.php +++ b/actions/twitapisearchatom.php @@ -52,7 +52,6 @@ require_once INSTALLDIR.'/lib/twitterapi.php'; class TwitapisearchatomAction extends TwitterapiAction { - var $notices; var $cnt; var $query; var $lang; @@ -156,6 +155,7 @@ class TwitapisearchatomAction extends TwitterapiAction { // TODO: Support search operators like from: and to:, boolean, etc. + $notices = array(); $notice = new Notice(); // lcase it for comparison @@ -226,6 +226,10 @@ class TwitapisearchatomAction extends TwitterapiAction $this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', + + // XXX: xmlns:twitter causes Atom validation to fail + // It's used for the source attr on notices + 'xmlns:twitter' => 'http://api.twitter.com/', 'xml:lang' => $lang)); @@ -251,7 +255,8 @@ class TwitapisearchatomAction extends TwitterapiAction // self link - $self_uri = $search_uri . '&page=' . $this->page; + $self_uri = $search_uri; + $self_uri .= ($this->page > 1) ? '&page=' . $this->page : ''; $this->element('link', array('type' => 'application/atom+xml', 'rel' => 'self', @@ -317,10 +322,11 @@ class TwitapisearchatomAction extends TwitterapiAction 'rel' => 'alternate', 'href' => $nurl)); $this->element('title', null, common_xml_safe_str(trim($notice->content))); - $this->element('content', array('type' => 'text/html'), $notice->rendered); + $this->element('content', array('type' => 'html'), $notice->rendered); $this->element('updated', null, common_date_w3dtf($notice->created)); $this->element('link', array('type' => 'image/png', - 'rel' => 'image', + // XXX: Twitter uses rel="image" (not valid) + 'rel' => 'related', 'href' => $profile->avatarUrl())); // TODO: Here is where we'd put in a link to an atom feed for threads -- cgit v1.2.3-54-g00ecf From 622cc150d86265cbb1dcd35ae11f4941d42ffdeb Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 10 Mar 2009 18:30:58 -0700 Subject: Fix xml:lang attr --- actions/twitapisearchatom.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'actions') diff --git a/actions/twitapisearchatom.php b/actions/twitapisearchatom.php index c5f724c12..eb9ab5d8e 100644 --- a/actions/twitapisearchatom.php +++ b/actions/twitapisearchatom.php @@ -218,7 +218,6 @@ class TwitapisearchatomAction extends TwitterapiAction { // TODO: A9 OpenSearch stuff like search.twitter.com? - $lang = common_config('site', 'language'); $server = common_config('site', 'server'); $sitename = common_config('site', 'name'); @@ -231,7 +230,7 @@ class TwitapisearchatomAction extends TwitterapiAction // It's used for the source attr on notices 'xmlns:twitter' => 'http://api.twitter.com/', - 'xml:lang' => $lang)); + 'xml:lang' => 'en-US')); // XXX Other locales ? $taguribase = common_config('integration', 'taguri'); $this->element('id', null, "tag:$taguribase:search/$server"); @@ -265,6 +264,9 @@ class TwitapisearchatomAction extends TwitterapiAction $this->element('title', null, "$this->query - $sitename Search"); $this->element('updated', null, common_date_iso8601('now')); + // XXX: The below "rel" links are not valid Atom, but it's what + // Twitter does... + // refresh link $refresh_uri = $search_uri . "&since_id=" . $this->max_id; -- cgit v1.2.3-54-g00ecf From 2cbb67c21e77e76a4faa73532751bf2eb8dd44a9 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sat, 7 Mar 2009 23:38:42 +0100 Subject: Define undefined variable. --- actions/userrss.php | 1 + 1 file changed, 1 insertion(+) (limited to 'actions') diff --git a/actions/userrss.php b/actions/userrss.php index a3e5a3aab..d3bf352d8 100644 --- a/actions/userrss.php +++ b/actions/userrss.php @@ -53,6 +53,7 @@ class UserrssAction extends Rss10Action $notice = $user->getNotices(0, ($limit == 0) ? NOTICES_PER_PAGE : $limit); + $notices = array(); while ($notice->fetch()) { $notices[] = clone($notice); } -- cgit v1.2.3-54-g00ecf From c08e4d904ec80144379c5728e2274e3513e6c819 Mon Sep 17 00:00:00 2001 From: CiaranG Date: Wed, 11 Mar 2009 23:41:30 +0000 Subject: PostgreSQL - a few more query compatibility issues (submitted by oxygene) --- actions/peopletag.php | 2 +- actions/sup.php | 4 +++- classes/Notice.php | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'actions') diff --git a/actions/peopletag.php b/actions/peopletag.php index 6b1e34f1a..5add75485 100644 --- a/actions/peopletag.php +++ b/actions/peopletag.php @@ -119,7 +119,7 @@ class PeopletagAction extends Action 'FROM profile JOIN profile_tag ' . 'ON profile.id = profile_tag.tagger ' . 'WHERE profile_tag.tagger = profile_tag.tagged ' . - 'AND tag = "%s" ' . + "AND tag = '%s' " . 'ORDER BY profile_tag.modified DESC%s'; $profile->query(sprintf($qry, $this->tag, $lim)); diff --git a/actions/sup.php b/actions/sup.php index f4b1cda23..8ef9207fa 100644 --- a/actions/sup.php +++ b/actions/sup.php @@ -65,7 +65,9 @@ class SupAction extends Action $notice->query('SELECT profile_id, max(id) AS max_id ' . 'FROM notice ' . - 'WHERE created > (now() - ' . $seconds . ') ' . + ((common_config('db','type') == 'pgsql') ? + 'WHERE extract(epoch from created) > (extract(epoch from now()) - ' . $seconds . ') ' : + 'WHERE created > (now() - ' . $seconds . ') ' ) . 'GROUP BY profile_id'); $updates = array(); diff --git a/classes/Notice.php b/classes/Notice.php index 1e3b330f2..3087e39a7 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -232,7 +232,11 @@ class Notice extends Memcached_DataObject $notice = new Notice(); $notice->profile_id = $profile_id; $notice->content = $content; - $notice->whereAdd('now() - created < ' . common_config('site', 'dupelimit')); + if (common_config('db','type') == 'pgsql') + $notice->whereAdd('extract(epoch from now() - created) < ' . common_config('site', 'dupelimit')); + else + $notice->whereAdd('now() - created < ' . common_config('site', 'dupelimit')); + $cnt = $notice->count(); return ($cnt == 0); } -- cgit v1.2.3-54-g00ecf