From d3d499879c4d01bde46033a3a98f9190ea18cb63 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 16 Jun 2010 14:29:24 -0700 Subject: [PATCH 1/9] - More useful group info from api/statusnet/group/show - Add statusnet:group_info tag to group Atom feeds --- actions/showgroup.php | 10 +--------- classes/User_group.php | 15 ++++++++++++++ lib/apiaction.php | 40 ++++++++++++++++++++++++------------- lib/atomgroupnoticefeed.php | 19 ++++++++++++++++++ 4 files changed, 61 insertions(+), 23 deletions(-) diff --git a/actions/showgroup.php b/actions/showgroup.php index 3d369e9ebf..17c37e4d79 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -430,14 +430,6 @@ class ShowgroupAction extends GroupDesignAction function showStatistics() { - // XXX: WORM cache this - $members = $this->group->getMembers(); - $members_count = 0; - /** $member->count() doesn't work. */ - while ($members->fetch()) { - $members_count++; - } - $this->elementStart('div', array('id' => 'entity_statistics', 'class' => 'section')); @@ -451,7 +443,7 @@ class ShowgroupAction extends GroupDesignAction $this->elementStart('dl', 'entity_members'); $this->element('dt', null, _('Members')); - $this->element('dd', null, (is_int($members_count)) ? $members_count : '0'); + $this->element('dd', null, $this->group->getMemberCount()); $this->elementEnd('dl'); $this->elementEnd('div'); diff --git a/classes/User_group.php b/classes/User_group.php index 110f083012..e04c466266 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -154,6 +154,21 @@ class User_group extends Memcached_DataObject return $members; } + function getMemberCount() + { + // XXX: WORM cache this + + $members = $this->getMembers(); + $member_count = 0; + + /** $member->count() doesn't work. */ + while ($members->fetch()) { + $member_count++; + } + + return $member_count; + } + function getAdmins($offset=0, $limit=null) { $qry = diff --git a/lib/apiaction.php b/lib/apiaction.php index 320aa03160..7cc473d512 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -346,20 +346,32 @@ class ApiAction extends Action function twitterGroupArray($group) { - $twitter_group=array(); - $twitter_group['id']=$group->id; - $twitter_group['url']=$group->permalink(); - $twitter_group['nickname']=$group->nickname; - $twitter_group['fullname']=$group->fullname; - $twitter_group['original_logo']=$group->original_logo; - $twitter_group['homepage_logo']=$group->homepage_logo; - $twitter_group['stream_logo']=$group->stream_logo; - $twitter_group['mini_logo']=$group->mini_logo; - $twitter_group['homepage']=$group->homepage; - $twitter_group['description']=$group->description; - $twitter_group['location']=$group->location; - $twitter_group['created']=$this->dateTwitter($group->created); - $twitter_group['modified']=$this->dateTwitter($group->modified); + $twitter_group = array(); + + $twitter_group['id'] = $group->id; + $twitter_group['url'] = $group->permalink(); + $twitter_group['nickname'] = $group->nickname; + $twitter_group['fullname'] = $group->fullname; + + if (isset($this->auth_user)) { + $twitter_group['member'] = $this->auth_user->isMember($group); + $twitter_group['blocked'] = Group_block::isBlocked( + $group, + $this->auth_user->getProfile() + ); + } + + $twitter_group['member_count'] = $group->getMemberCount(); + $twitter_group['original_logo'] = $group->original_logo; + $twitter_group['homepage_logo'] = $group->homepage_logo; + $twitter_group['stream_logo'] = $group->stream_logo; + $twitter_group['mini_logo'] = $group->mini_logo; + $twitter_group['homepage'] = $group->homepage; + $twitter_group['description'] = $group->description; + $twitter_group['location'] = $group->location; + $twitter_group['created'] = $this->dateTwitter($group->created); + $twitter_group['modified'] = $this->dateTwitter($group->modified); + return $twitter_group; } diff --git a/lib/atomgroupnoticefeed.php b/lib/atomgroupnoticefeed.php index 7934a4f9e5..761df587ce 100644 --- a/lib/atomgroupnoticefeed.php +++ b/lib/atomgroupnoticefeed.php @@ -93,4 +93,23 @@ class AtomGroupNoticeFeed extends AtomNoticeFeed return $this->group; } + function initFeed() + { + parent::initFeed(); + + $attrs = array(); + + if (!empty($this->cur)) { + $attrs['member'] = $this->cur->isMember($this->group) + ? 'true' : 'false'; + $attrs['blocked'] = Group_block::isBlocked( + $this->group, + $this->cur->getProfile() + ) ? 'true' : 'false'; + } + + $attrs['member_count'] = $this->group->getMemberCount(); + + $this->element('statusnet:group_info', $attrs, null); + } } From a6ce4eef0df225dd863baf45d5615cbe22dcdea6 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 16 Jun 2010 18:27:51 -0700 Subject: [PATCH 2/9] Fix problem with AvatarLink in which it was sometimes leaving the width attribute empty --- lib/avatarlink.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/avatarlink.php b/lib/avatarlink.php index e67799e2eb..7d4256d6e1 100644 --- a/lib/avatarlink.php +++ b/lib/avatarlink.php @@ -76,8 +76,8 @@ class AvatarLink $alink = new AvatarLink(); $alink->url = $filename; $alink->height = $size; + $alink->width = $size; if (!empty($filename)) { - $alink->width = $size; $alink->type = self::mediatype($filename); } else { $alink->url = User_group::defaultLogo($size); From 105c1a22d6513d9a5cb33d6134a6d60d423ee462 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 17 Jun 2010 23:08:40 +0000 Subject: [PATCH 3/9] Include source client's related URL (if any) in source attribution for Atom notice feeds --- classes/Notice.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 0838ca2a2c..f8eda5777d 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1238,9 +1238,25 @@ class Notice extends Memcached_DataObject $xs->element('published', null, common_date_w3dtf($this->created)); $xs->element('updated', null, common_date_w3dtf($this->created)); + $source = null; + + $ns = $this->getSource(); + + if ($ns) { + if (!empty($ns->name) && !empty($ns->url)) { + $source = '' + . htmlspecialchars($ns->name) + . ''; + } else { + $source = $ns->code; + } + } + $noticeInfoAttr = array( - 'local_id' => $this->id, // local notice ID (useful to clients for ordering) - 'source' => $this->source, // the client name (source attribution) + 'local_id' => $this->id, // local notice ID (useful to clients for ordering) + 'source' => $source, // the client name (source attribution) ); $ns = $this->getSource(); @@ -1252,8 +1268,8 @@ class Notice extends Memcached_DataObject if (!empty($cur)) { $noticeInfoAttr['favorite'] = ($cur->hasFave($this)) ? "true" : "false"; - $profile = $cur->getProfile(); - $noticeInfoAttr['repeated'] = ($profile->hasRepeated($this->id)) ? "true" : "false"; + $profile = $cur->getProfile(); + $noticeInfoAttr['repeated'] = ($profile->hasRepeated($this->id)) ? "true" : "false"; } if (!empty($this->repeat_of)) { From 9d890e2be07364487cb3b333b49650b820dd7176 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 18 Jun 2010 09:59:11 -0700 Subject: [PATCH 4/9] Catch a couple of missing XML namespace declarations on API XML output. Missing NS declarations were breaking XML parsing for some clients since beaecb18d5b92b913473dfffd545dc436f50cf66 --- actions/apiaccountverifycredentials.php | 2 +- actions/apisubscriptions.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/actions/apiaccountverifycredentials.php b/actions/apiaccountverifycredentials.php index ea61a32059..79416e9b26 100644 --- a/actions/apiaccountverifycredentials.php +++ b/actions/apiaccountverifycredentials.php @@ -75,7 +75,7 @@ class ApiAccountVerifyCredentialsAction extends ApiAuthAction if ($this->format == 'xml') { $this->initDocument('xml'); - $this->showTwitterXmlUser($twitter_user); + $this->showTwitterXmlUser($twitter_user, 'user', true); $this->endDocument('xml'); } elseif ($this->format == 'json') { $this->initDocument('json'); diff --git a/actions/apisubscriptions.php b/actions/apisubscriptions.php index 0ba324057e..63d65f2893 100644 --- a/actions/apisubscriptions.php +++ b/actions/apisubscriptions.php @@ -206,7 +206,8 @@ class ApiSubscriptionsAction extends ApiBareAuthAction { switch ($this->format) { case 'xml': - $this->elementStart('users', array('type' => 'array')); + $this->elementStart('users', array('type' => 'array', + 'xmlns:statusnet' => 'http://status.net/schema/api/1/')); foreach ($this->profiles as $profile) { $this->showProfile( $profile, From 2e98a48f2b992c0a566689d3246880f6e81fbee3 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 20 Jun 2010 19:30:12 +0000 Subject: [PATCH 5/9] RecaptchaPlugin: fix for missing captcha on iPhone/Android. MobileProfile serves pages out to iPhone and Android as application/xhtml+xml, which doesn't work with the default we we were loading recaptcha (as it used document.write). Switched to filling out a
from the AJAX API, which doesn't use document.write in the XHTML context. Tested that view & submission works ok in following browsers: Mobile: iPhone 3.1, Android 2.1, iPad 3.2 (this last doesn't trigger mobile theme tweaks) Ubuntu 10.04: Firefox 3.6.3, Chrome 6 Mac 10.6: Safari 5/OS X 10.6.4 Windows 7: IE 8, Opera 10.56 --- plugins/Recaptcha/RecaptchaPlugin.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/plugins/Recaptcha/RecaptchaPlugin.php b/plugins/Recaptcha/RecaptchaPlugin.php index c585da43c4..f09d81ec00 100644 --- a/plugins/Recaptcha/RecaptchaPlugin.php +++ b/plugins/Recaptcha/RecaptchaPlugin.php @@ -62,12 +62,29 @@ class RecaptchaPlugin extends Plugin { $action->elementStart('li'); $action->raw(''); - if($this->checkssl() === true) { - $action->raw(recaptcha_get_html($this->public_key), null, true); - } else { - $action->raw(recaptcha_get_html($this->public_key)); - } + + // AJAX API will fill this div out. + // We're calling that instead of the regular one so we stay compatible + // with application/xml+xhtml output as for mobile. + $action->element('div', array('id' => 'recaptcha')); $action->elementEnd('li'); + + $action->recaptchaPluginNeedsOutput = true; + return true; + } + + function onEndShowScripts($action) + { + if (isset($action->recaptchaPluginNeedsOutput) && $action->recaptchaPluginNeedsOutput) { + // Load the AJAX API + $proto = $this->checkssl() ? 'https' : 'http'; + $url = "$proto://api.recaptcha.net/js/recaptcha_ajax.js"; + $action->script($url); + + // And when we're ready, fill out the captcha! + $key = json_encode($this->public_key); + $action->inlinescript("\$(function(){Recaptcha.create($key, 'recaptcha');});"); + } return true; } From 1852eae36f9ed9a57d37f2048dfbf2257c7eccb4 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 21 Jun 2010 08:07:12 -0700 Subject: [PATCH 6/9] quick-fix for localization typo per #2366 (also fixed upstream in translatewiki) --- locale/de/LC_MESSAGES/statusnet.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/de/LC_MESSAGES/statusnet.po b/locale/de/LC_MESSAGES/statusnet.po index eda01937ab..e453e80252 100644 --- a/locale/de/LC_MESSAGES/statusnet.po +++ b/locale/de/LC_MESSAGES/statusnet.po @@ -2620,7 +2620,7 @@ msgstr "Profil-Einstellungen ansehen" #: actions/othersettings.php:123 msgid "Show or hide profile designs." -msgstr "Prifil-Designs anzeigen oder verstecken." +msgstr "Profil-Designs anzeigen oder verstecken." #: actions/othersettings.php:153 msgid "URL shortening service is too long (max 50 chars)." From 1eec7f779fc85b530907ea31deceadb2a30d7614 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 22 Jun 2010 16:28:06 -0700 Subject: [PATCH 7/9] - Add profile_info tag to Atom author - Normalize xmlns:statusnet links in the API --- classes/Notice.php | 4 ++-- classes/Profile.php | 10 +++++++++- lib/apiaction.php | 2 ++ lib/atomnoticefeed.php | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index f8eda5777d..c752e35a72 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1190,7 +1190,7 @@ class Notice extends Memcached_DataObject 'xmlns:media' => 'http://purl.org/syndication/atommedia', 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0', 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0', - 'xmlns:statusnet' => 'http://status.net/ont/'); + 'xmlns:statusnet' => 'http://status.net/schema/api/1/'); } else { $attrs = array(); } @@ -1225,7 +1225,7 @@ class Notice extends Memcached_DataObject $xs->element('title', null, common_xml_safe_str($this->content)); if ($author) { - $xs->raw($profile->asAtomAuthor()); + $xs->raw($profile->asAtomAuthor($cur)); $xs->raw($profile->asActivityActor()); } diff --git a/classes/Profile.php b/classes/Profile.php index 54f557ea7c..a303469e96 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -849,15 +849,23 @@ class Profile extends Memcached_DataObject * * Assumes that Atom has been previously set up as the base namespace. * + * @param Profile $cur the current authenticated user + * * @return string */ - function asAtomAuthor() + function asAtomAuthor($cur = null) { $xs = new XMLStringer(true); $xs->elementStart('author'); $xs->element('name', null, $this->nickname); $xs->element('uri', null, $this->getUri()); + if ($cur != null) { + $attrs = Array(); + $attrs['following'] = $cur->isSubscribed($this) ? 'true' : 'false'; + $attrs['blocking'] = $cur->hasBlocked($this) ? 'true' : 'false'; + $xs->element('statusnet:profile_info', $attrs, null); + } $xs->elementEnd('author'); return $xs->getString(); diff --git a/lib/apiaction.php b/lib/apiaction.php index 7cc473d512..226481778e 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -208,11 +208,13 @@ class ApiAction extends Action // Is the requesting user following this user? $twitter_user['following'] = false; + $twitter_user['statusnet:blocking'] = false; $twitter_user['notifications'] = false; if (isset($this->auth_user)) { $twitter_user['following'] = $this->auth_user->isSubscribed($profile); + $twitter_user['statusnet:blocking'] = $this->auth_user->hasBlocked($profile); // Notifications on? $sub = Subscription::pkeyGet(array('subscriber' => diff --git a/lib/atomnoticefeed.php b/lib/atomnoticefeed.php index ef44de4b6c..6ed803ce4e 100644 --- a/lib/atomnoticefeed.php +++ b/lib/atomnoticefeed.php @@ -95,7 +95,7 @@ class AtomNoticeFeed extends Atom10Feed $this->addNamespace( 'statusnet', - 'http://status.net/ont/' + 'http://status.net/schema/api/1/' ); } From a6408be566dc9877eb67c86d4283dd57b2255d8b Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 24 Jun 2010 15:21:04 +0000 Subject: [PATCH 8/9] Regression fix for Recaptcha on SSL registration page; their API is served on a different hostname for SSL. --- plugins/Recaptcha/RecaptchaPlugin.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/Recaptcha/RecaptchaPlugin.php b/plugins/Recaptcha/RecaptchaPlugin.php index f09d81ec00..7cc34c5686 100644 --- a/plugins/Recaptcha/RecaptchaPlugin.php +++ b/plugins/Recaptcha/RecaptchaPlugin.php @@ -77,8 +77,11 @@ class RecaptchaPlugin extends Plugin { if (isset($action->recaptchaPluginNeedsOutput) && $action->recaptchaPluginNeedsOutput) { // Load the AJAX API - $proto = $this->checkssl() ? 'https' : 'http'; - $url = "$proto://api.recaptcha.net/js/recaptcha_ajax.js"; + if ($this->checkssl()) { + $url = "https://api-secure.recaptcha.net/js/recaptcha_ajax.js"; + } else { + $url = "http://api.recaptcha.net/js/recaptcha_ajax.js"; + } $action->script($url); // And when we're ready, fill out the captcha! From 9eb5a976b03fae6bd1e1fce6abfe4a6c7964d1ae Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 24 Jun 2010 18:11:50 -0700 Subject: [PATCH 9/9] Have API methods for search subclass ApiPrivateAuthAction --- actions/{twitapisearchatom.php => apisearchatom.php} | 12 +++++++++--- actions/{twitapisearchjson.php => apisearchjson.php} | 7 +++++-- actions/{twitapitrends.php => apitrends.php} | 8 +++++--- lib/router.php | 6 +++--- 4 files changed, 22 insertions(+), 11 deletions(-) rename actions/{twitapisearchatom.php => apisearchatom.php} (97%) rename actions/{twitapisearchjson.php => apisearchjson.php} (94%) rename actions/{twitapitrends.php => apitrends.php} (93%) diff --git a/actions/twitapisearchatom.php b/actions/apisearchatom.php similarity index 97% rename from actions/twitapisearchatom.php rename to actions/apisearchatom.php index 51e8a8881b..60bb8b0408 100644 --- a/actions/twitapisearchatom.php +++ b/actions/apisearchatom.php @@ -22,7 +22,7 @@ * @category Search * @package StatusNet * @author Zach Copley - * @copyright 2008-2009 StatusNet, Inc. + * @copyright 2008-2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -31,6 +31,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +require_once INSTALLDIR.'/lib/apiprivateauth.php'; + /** * Action for outputting search results in Twitter compatible Atom * format. @@ -44,10 +46,10 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ * - * @see ApiAction + * @see ApiPrivateAuthAction */ -class TwitapisearchatomAction extends ApiAction +class ApiSearchAtomAction extends ApiPrivateAuthAction { var $cnt; @@ -96,8 +98,11 @@ class TwitapisearchatomAction extends ApiAction function prepare($args) { + common_debug("in apisearchatom prepare()"); + parent::prepare($args); + $this->query = $this->trimmed('q'); $this->lang = $this->trimmed('lang'); $this->rpp = $this->trimmed('rpp'); @@ -138,6 +143,7 @@ class TwitapisearchatomAction extends ApiAction function handle($args) { parent::handle($args); + common_debug("In apisearchatom handle()"); $this->showAtom(); } diff --git a/actions/twitapisearchjson.php b/actions/apisearchjson.php similarity index 94% rename from actions/twitapisearchjson.php rename to actions/apisearchjson.php index b5c006aa7b..e44634684d 100644 --- a/actions/twitapisearchjson.php +++ b/actions/apisearchjson.php @@ -22,7 +22,7 @@ * @category Search * @package StatusNet * @author Zach Copley - * @copyright 2008-2009 StatusNet, Inc. + * @copyright 2008-2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -31,6 +31,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +require_once INSTALLDIR.'/lib/apiprivateauth.php'; require_once INSTALLDIR.'/lib/jsonsearchresultslist.php'; /** @@ -44,7 +45,7 @@ require_once INSTALLDIR.'/lib/jsonsearchresultslist.php'; * @see ApiAction */ -class TwitapisearchjsonAction extends ApiAction +class ApiSearchJSONAction extends ApiPrivateAuthAction { var $query; var $lang; @@ -64,6 +65,8 @@ class TwitapisearchjsonAction extends ApiAction function prepare($args) { + common_debug("apisearchjson prepare()"); + parent::prepare($args); $this->query = $this->trimmed('q'); diff --git a/actions/twitapitrends.php b/actions/apitrends.php similarity index 93% rename from actions/twitapitrends.php rename to actions/apitrends.php index 5a04569a22..5b74636c69 100644 --- a/actions/twitapitrends.php +++ b/actions/apitrends.php @@ -22,7 +22,7 @@ * @category Search * @package StatusNet * @author Zach Copley - * @copyright 2008-2009 StatusNet, Inc. + * @copyright 2008-2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -31,6 +31,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +require_once INSTALLDIR.'/lib/apiprivateauth.php'; + /** * Returns the top ten queries that are currently trending * @@ -43,7 +45,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { * @see ApiAction */ -class TwitapitrendsAction extends ApiAction +class ApiTrendsAction extends ApiPrivateAuthAction { var $callback; @@ -82,7 +84,7 @@ class TwitapitrendsAction extends ApiAction */ function showTrends() { - $this->serverError(_('API method under construction.'), $code = 501); + $this->serverError(_('API method under construction.'), 501); } } \ No newline at end of file diff --git a/lib/router.php b/lib/router.php index fec229c9b6..7e1e6a2a47 100644 --- a/lib/router.php +++ b/lib/router.php @@ -667,9 +667,9 @@ class Router ); // search - $m->connect('api/search.atom', array('action' => 'twitapisearchatom')); - $m->connect('api/search.json', array('action' => 'twitapisearchjson')); - $m->connect('api/trends.json', array('action' => 'twitapitrends')); + $m->connect('api/search.atom', array('action' => 'ApiSearchAtom')); + $m->connect('api/search.json', array('action' => 'ApiSearchJSON')); + $m->connect('api/trends.json', array('action' => 'ApiTrends')); $m->connect('api/oauth/request_token', array('action' => 'apioauthrequesttoken'));