summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorSarven Capadisli <csarven@controlyourself.ca>2009-04-08 22:55:13 +0000
committerSarven Capadisli <csarven@controlyourself.ca>2009-04-08 22:55:13 +0000
commite5657ca4bbd8a43bf2dd44c2554e807a45224bd7 (patch)
tree3ad9a722f787e277ab571d40522cd5289da738dc /actions
parente632f3be6f48c187b8049f35756b25ae80be2f0b (diff)
parent070cd3533c3474dc065c6681befb92dac51f4bf7 (diff)
Merge branch '0.7.x' into 0.8.x
Diffstat (limited to 'actions')
-rw-r--r--actions/all.php45
-rw-r--r--actions/favorited.php21
-rw-r--r--actions/groupsearch.php24
-rw-r--r--actions/noticesearch.php21
-rw-r--r--actions/peoplesearch.php19
-rw-r--r--actions/public.php21
-rw-r--r--actions/publictagcloud.php14
-rw-r--r--actions/replies.php24
-rw-r--r--actions/showfavorites.php27
-rw-r--r--actions/showstream.php217
-rw-r--r--actions/subscribers.php22
-rw-r--r--actions/subscriptions.php22
-rw-r--r--actions/userauthorization.php268
-rw-r--r--actions/usergroups.php18
14 files changed, 308 insertions, 455 deletions
diff --git a/actions/all.php b/actions/all.php
index 8e67ec0f3..f5bbfe2e3 100644
--- a/actions/all.php
+++ b/actions/all.php
@@ -23,31 +23,13 @@ require_once INSTALLDIR.'/lib/personalgroupnav.php';
require_once INSTALLDIR.'/lib/noticelist.php';
require_once INSTALLDIR.'/lib/feedlist.php';
-class AllAction extends Action
+class AllAction extends ProfileAction
{
- var $user = null;
- var $page = null;
-
function isReadOnly()
{
return true;
}
- function prepare($args)
- {
- parent::prepare($args);
- $nickname = common_canonical_nickname($this->arg('nickname'));
- $this->user = User::staticGet('nickname', $nickname);
- $this->page = $this->trimmed('page');
- if (!$this->page) {
- $this->page = 1;
- }
-
- common_set_returnto($this->selfUrl());
-
- return true;
- }
-
function handle($args)
{
parent::handle($args);
@@ -93,6 +75,27 @@ class AllAction extends Action
$nav->show();
}
+ function showEmptyListMessage()
+ {
+ $message = sprintf(_('This is the timeline for %s and friends but no one has posted anything yet.'), $this->user->nickname) . ' ';
+
+ if (common_logged_in()) {
+ $current_user = common_current_user();
+ if ($this->user->id === $current_user->id) {
+ $message .= _('Try subscribing to more people, [join a group](%%action.groups) or post something yourself.');
+ } else {
+ $message .= sprintf(_('You can try to [nudge %s](../%s) from his profile or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname);
+ }
+ }
+ else {
+ $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname);
+ }
+
+ $this->elementStart('div', 'guide');
+ $this->raw(common_markup_to_html($message));
+ $this->elementEnd('div');
+ }
+
function showContent()
{
$notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
@@ -101,6 +104,10 @@ class AllAction extends Action
$cnt = $nl->show();
+ if (0 == $cnt) {
+ $this->showEmptyListMessage();
+ }
+
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'all', array('nickname' => $this->user->nickname));
}
diff --git a/actions/favorited.php b/actions/favorited.php
index 20a354674..09ab1216a 100644
--- a/actions/favorited.php
+++ b/actions/favorited.php
@@ -104,9 +104,9 @@ class FavoritedAction extends Action
{
parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
-
+
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -143,14 +143,11 @@ class FavoritedAction extends Action
$this->elementStart('div', 'instructions');
$this->raw($output);
$this->elementEnd('div');
+ }
- $favorite = new Fave;
-
- if ($favorite->count()) {
- return;
- }
-
- $message = _('Favorite notices appear on this page but noone has favorited one yet.') . ' ';
+ function showEmptyList()
+ {
+ $message = _('Favorite notices appear on this page but no one has favorited one yet.') . ' ';
if (common_logged_in()) {
$message .= _('Be the first to add a notice to your favorites by clicking the fave button next to any notice you like.');
@@ -159,7 +156,7 @@ class FavoritedAction extends Action
$message .= _('Why not [register an account](%%action.register%%) and be the first to add a notice to your favorites!');
}
- $this->elementStart('div', 'blankfiller');
+ $this->elementStart('div', 'guide');
$this->raw(common_markup_to_html($message));
$this->elementEnd('div');
}
@@ -217,6 +214,10 @@ class FavoritedAction extends Action
$cnt = $nl->show();
+ if ($cnt == 0) {
+ $this->showEmptyList();
+ }
+
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'favorited');
}
diff --git a/actions/groupsearch.php b/actions/groupsearch.php
index 109a53ce1..06b4a7755 100644
--- a/actions/groupsearch.php
+++ b/actions/groupsearch.php
@@ -72,12 +72,23 @@ class GroupsearchAction extends SearchAction
$terms = preg_split('/[\s,]+/', $q);
$results = new GroupSearchResults($user_group, $terms, $this);
$results->show();
+ $user_group->free();
+ $this->pagination($page > 1, $cnt > GROUPS_PER_PAGE,
+ $page, 'groupsearch', array('q' => $q));
} else {
- $this->element('p', 'error', _('No results'));
+ $this->element('p', 'error', _('No results.'));
+ $this->searchSuggestions($q);
+ if (common_logged_in()) {
+ $message = _('If you can\'t find the group you\'re looking for, you can [create it](%%action.newgroup%%) yourself.');
+ }
+ else {
+ $message = _('Why not [register an account](%%action.register%%) and [create the group](%%action.newgroup%%) yourself!');
+ }
+ $this->elementStart('div', 'guide');
+ $this->raw(common_markup_to_html($message));
+ $this->elementEnd('div');
+ $user_group->free();
}
- $user_group->free();
- $this->pagination($page > 1, $cnt > GROUPS_PER_PAGE,
- $page, 'groupsearch', array('q' => $q));
}
}
@@ -98,10 +109,5 @@ class GroupSearchResults extends GroupList
{
return preg_replace($this->pattern, '<strong>\\1</strong>', htmlspecialchars($text));
}
-
- function isReadOnly()
- {
- return true;
- }
}
diff --git a/actions/noticesearch.php b/actions/noticesearch.php
index 9058cf53c..095d0a454 100644
--- a/actions/noticesearch.php
+++ b/actions/noticesearch.php
@@ -114,22 +114,27 @@ class NoticesearchAction extends SearchAction
$cnt = $notice->find();
}
if ($cnt === 0) {
- $this->element('p', 'error', _('No results'));
+ $this->element('p', 'error', _('No results.'));
+
+ $this->searchSuggestions($q);
+ if (common_logged_in()) {
+ $message = sprintf(_('Be the first to [post on this topic](%%%%action.newnotice%%%%?status_textarea=%s)!'), urlencode($q));
+ }
+ else {
+ $message = sprintf(_('Why not [register an account](%%%%action.register%%%%) and be the first to [post on this topic](%%%%action.newnotice%%%%?status_textarea=%s)!'), urlencode($q));
+ }
+
+ $this->elementStart('div', 'guide');
+ $this->raw(common_markup_to_html($message));
+ $this->elementEnd('div');
return;
}
$terms = preg_split('/[\s,]+/', $q);
$nl = new SearchNoticeList($notice, $this, $terms);
-
$cnt = $nl->show();
-
$this->pagination($page > 1, $cnt > NOTICES_PER_PAGE,
$page, 'noticesearch', array('q' => $q));
}
-
- function isReadOnly()
- {
- return true;
- }
}
class SearchNoticeList extends NoticeList {
diff --git a/actions/peoplesearch.php b/actions/peoplesearch.php
index 9e515ade1..65d970dd1 100644
--- a/actions/peoplesearch.php
+++ b/actions/peoplesearch.php
@@ -60,14 +60,8 @@ class PeoplesearchAction extends SearchAction
function showResults($q, $page)
{
-
$profile = new Profile();
-
- // lcase it for comparison
- // $q = strtolower($q);
-
$search_engine = $profile->getSearchEngine('identica_people');
-
$search_engine->set_sort_mode('chron');
// Ask for an extra to see if there's more.
$search_engine->limit((($page-1)*PROFILES_PER_PAGE), PROFILES_PER_PAGE + 1);
@@ -81,14 +75,15 @@ class PeoplesearchAction extends SearchAction
$terms = preg_split('/[\s,]+/', $q);
$results = new PeopleSearchResults($profile, $terms, $this);
$results->show();
+ $profile->free();
+ $this->pagination($page > 1, $cnt > PROFILES_PER_PAGE,
+ $page, 'peoplesearch', array('q' => $q));
+
} else {
- $this->element('p', 'error', _('No results'));
+ $this->element('p', 'error', _('No results.'));
+ $this->searchSuggestions($q);
+ $profile->free();
}
-
- $profile->free();
-
- $this->pagination($page > 1, $cnt > PROFILES_PER_PAGE,
- $page, 'peoplesearch', array('q' => $q));
}
}
diff --git a/actions/public.php b/actions/public.php
index 5a2720a9a..5a380de9a 100644
--- a/actions/public.php
+++ b/actions/public.php
@@ -166,20 +166,9 @@ class PublicAction extends Action
$nav->show();
}
- function showPageNotice()
+ function showEmptyList()
{
- $notice = new Notice;
-
- if (!$notice) {
- $this->serverError(_('Could not retrieve public stream.'));
- return;
- }
-
- if ($notice->count()) {
- return;
- }
-
- $message = _('This is the public timeline for %%site.name%% but noone has posted anything yet.') . ' ';
+ $message = _('This is the public timeline for %%site.name%% but no one has posted anything yet.') . ' ';
if (common_logged_in()) {
$message .= _('Be the first to post!');
@@ -188,7 +177,7 @@ class PublicAction extends Action
$message .= _('Why not [register an account](%%action.register%%) and be the first to post!');
}
- $this->elementStart('div', 'blankfiller');
+ $this->elementStart('div', 'guide');
$this->raw(common_markup_to_html($message));
$this->elementEnd('div');
}
@@ -216,6 +205,10 @@ class PublicAction extends Action
$cnt = $nl->show();
+ if ($cnt == 0) {
+ $this->showEmptyList();
+ }
+
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'public');
}
diff --git a/actions/publictagcloud.php b/actions/publictagcloud.php
index 5bc7e0cbf..855cfed9b 100644
--- a/actions/publictagcloud.php
+++ b/actions/publictagcloud.php
@@ -62,13 +62,11 @@ class PublictagcloudAction extends Action
$this->element('p', 'instructions',
sprintf(_('These are most popular recent tags on %s '),
common_config('site', 'name')));
+ }
- $tags = new Notice_tag;
- if ($tags->count()) {
- return;
- }
-
- $message = _('Noone has posted a notice with a [hashtag](%%doc.tags%%) yet.') . ' ';
+ function showEmptyList()
+ {
+ $message = _('No one has posted a notice with a [hashtag](%%doc.tags%%) yet.') . ' ';
if (common_logged_in()) {
$message .= _('Be the first to post one!');
@@ -77,7 +75,7 @@ class PublictagcloudAction extends Action
$message .= _('Why not [register an account](%%action.register%%) and be the first to post one!');
}
- $this->elementStart('div', 'blankfiller');
+ $this->elementStart('div', 'guide');
$this->raw(common_markup_to_html($message));
$this->elementEnd('div');
}
@@ -144,6 +142,8 @@ class PublictagcloudAction extends Action
$this->elementEnd('dd');
$this->elementEnd('dl');
$this->elementEnd('div');
+ } else {
+ $this->showEmptyList();
}
}
diff --git a/actions/replies.php b/actions/replies.php
index 4ab9b14ed..2769cb422 100644
--- a/actions/replies.php
+++ b/actions/replies.php
@@ -166,12 +166,36 @@ class RepliesAction extends Action
$nl = new NoticeList($notice, $this);
$cnt = $nl->show();
+ if (0 === $cnt) {
+ $this->showEmptyListMessage();
+ }
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'replies',
array('nickname' => $this->user->nickname));
}
+ function showEmptyListMessage()
+ {
+ $message = sprintf(_('This is the timeline showing replies to %s but %s hasn\'t received a notice to his attention yet.'), $this->user->nickname, $this->user->nickname) . ' ';
+
+ if (common_logged_in()) {
+ $current_user = common_current_user();
+ if ($this->user->id === $current_user->id) {
+ $message .= _('You can engage other users in a conversation, subscribe to more people or [join groups](%%action.groups%%).');
+ } else {
+ $message .= sprintf(_('You can try to [nudge %s](../%s) or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname);
+ }
+ }
+ else {
+ $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname);
+ }
+
+ $this->elementStart('div', 'guide');
+ $this->raw(common_markup_to_html($message));
+ $this->elementEnd('div');
+ }
+
function isReadOnly()
{
return true;
diff --git a/actions/showfavorites.php b/actions/showfavorites.php
index d1c9283f0..4d4349505 100644
--- a/actions/showfavorites.php
+++ b/actions/showfavorites.php
@@ -162,6 +162,25 @@ class ShowfavoritesAction extends Action
$nav->show();
}
+ function showEmptyListMessage()
+ {
+ if (common_logged_in()) {
+ $current_user = common_current_user();
+ if ($this->user->id === $current_user->id) {
+ $message = _('You haven\'t chosen any favorite notices yet. Click the fave button on notices you like to bookmark them for later or shed a spotlight on them.');
+ } else {
+ $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Post something interesting they would add to their favorites :)'), $this->user->nickname);
+ }
+ }
+ else {
+ $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Why not [register an account](%%%%action.register%%%%) and then post something interesting they would add to thier favorites :)'), $this->user->nickname);
+ }
+
+ $this->elementStart('div', 'guide');
+ $this->raw(common_markup_to_html($message));
+ $this->elementEnd('div');
+ }
+
/**
* Show the content
*
@@ -183,9 +202,17 @@ class ShowfavoritesAction extends Action
$nl = new NoticeList($notice, $this);
$cnt = $nl->show();
+ if (0 == $cnt) {
+ $this->showEmptyListMessage();
+ }
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
$this->page, 'showfavorites',
array('nickname' => $this->user->nickname));
}
+
+ function showPageNotice() {
+ $this->element('p', 'instructions', _('This is a way to share what you like.'));
+ }
}
+
diff --git a/actions/showstream.php b/actions/showstream.php
index f5886f3d3..ce237dae2 100644
--- a/actions/showstream.php
+++ b/actions/showstream.php
@@ -54,12 +54,8 @@ require_once INSTALLDIR.'/lib/feedlist.php';
* @link http://laconi.ca/
*/
-class ShowstreamAction extends Action
+class ShowstreamAction extends ProfileAction
{
- var $user = null;
- var $page = null;
- var $profile = null;
-
function isReadOnly()
{
return true;
@@ -82,45 +78,6 @@ class ShowstreamAction extends Action
}
}
- function prepare($args)
- {
- parent::prepare($args);
-
- $nickname_arg = $this->arg('nickname');
- $nickname = common_canonical_nickname($nickname_arg);
-
- // Permanent redirect on non-canonical nickname
-
- if ($nickname_arg != $nickname) {
- $args = array('nickname' => $nickname);
- if ($this->arg('page') && $this->arg('page') != 1) {
- $args['page'] = $this->arg['page'];
- }
- common_redirect(common_local_url('showstream', $args), 301);
- return false;
- }
-
- $this->user = User::staticGet('nickname', $nickname);
-
- if (!$this->user) {
- $this->clientError(_('No such user.'), 404);
- return false;
- }
-
- $this->profile = $this->user->getProfile();
-
- if (!$this->profile) {
- $this->serverError(_('User has no profile.'));
- return false;
- }
-
- $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
-
- common_set_returnto($this->selfUrl());
-
- return true;
- }
-
function handle($args)
{
@@ -372,165 +329,39 @@ class ShowstreamAction extends Action
_('Subscribe'));
}
- function showNotices()
- {
- $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
-
- $pnl = new ProfileNoticeList($notice, $this);
- $cnt = $pnl->show();
-
- $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
- 'showstream', array('nickname' => $this->user->nickname));
- }
-
- function showSections()
- {
- $this->showSubscriptions();
- $this->showSubscribers();
- $this->showGroups();
- $this->showStatistics();
- $cloud = new PersonalTagCloudSection($this, $this->user);
- $cloud->show();
- }
-
- function showSubscriptions()
- {
- $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1);
-
- $this->elementStart('div', array('id' => 'entity_subscriptions',
- 'class' => 'section'));
-
- $this->element('h2', null, _('Subscriptions'));
-
- if ($profile) {
- $pml = new ProfileMiniList($profile, $this->user, $this);
- $cnt = $pml->show();
- if ($cnt == 0) {
- $this->element('p', null, _('(None)'));
- }
- }
-
- if ($cnt > PROFILES_PER_MINILIST) {
- $this->elementStart('p');
- $this->element('a', array('href' => common_local_url('subscriptions',
- array('nickname' => $this->profile->nickname)),
- 'class' => 'more'),
- _('All subscriptions'));
- $this->elementEnd('p');
- }
-
- $this->elementEnd('div');
- }
-
- function showSubscribers()
+ function showEmptyListMessage()
{
- $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1);
-
- $this->elementStart('div', array('id' => 'entity_subscribers',
- 'class' => 'section'));
+ $message = sprintf(_('This is the timeline for %s but %s hasn\'t posted anything yet.'), $this->user->nickname, $this->user->nickname) . ' ';
- $this->element('h2', null, _('Subscribers'));
-
- if ($profile) {
- $pml = new ProfileMiniList($profile, $this->user, $this);
- $cnt = $pml->show();
- if ($cnt == 0) {
- $this->element('p', null, _('(None)'));
+ if (common_logged_in()) {
+ $current_user = common_current_user();
+ if ($this->user->id === $current_user->id) {
+ $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
+ } else {
+ $message .= sprintf(_('You can try to nudge %s or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%s).'), $this->user->nickname, '@' . $this->user->nickname);
}
}
-
- if ($cnt > PROFILES_PER_MINILIST) {
- $this->elementStart('p');
- $this->element('a', array('href' => common_local_url('subscribers',
- array('nickname' => $this->profile->nickname)),
- 'class' => 'more'),
- _('All subscribers'));
- $this->elementEnd('p');
+ else {
+ $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname);
}
+ $this->elementStart('div', 'guide');
+ $this->raw(common_markup_to_html($message));
$this->elementEnd('div');
}
- function showStatistics()
- {
- // XXX: WORM cache this
- $subs = new Subscription();
- $subs->subscriber = $this->profile->id;
- $subs_count = (int) $subs->count() - 1;
-
- $subbed = new Subscription();
- $subbed->subscribed = $this->profile->id;
- $subbed_count = (int) $subbed->count() - 1;
-
- $notices = new Notice();
- $notices->profile_id = $this->profile->id;
- $notice_count = (int) $notices->count();
-
- $this->elementStart('div', array('id' => 'entity_statistics',
- 'class' => 'section'));
-
- $this->element('h2', null, _('Statistics'));
-
- // Other stats...?
- $this->elementStart('dl', 'entity_member-since');
- $this->element('dt', null, _('Member since'));
- $this->element('dd', null, date('j M Y',
- strtotime($this->profile->created)));
- $this->elementEnd('dl');
-
- $this->elementStart('dl', 'entity_subscriptions');
- $this->elementStart('dt');
- $this->element('a', array('href' => common_local_url('subscriptions',
- array('nickname' => $this->profile->nickname))),
- _('Subscriptions'));
- $this->elementEnd('dt');
- $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
- $this->elementEnd('dl');
-
- $this->elementStart('dl', 'entity_subscribers');
- $this->elementStart('dt');
- $this->element('a', array('href' => common_local_url('subscribers',
- array('nickname' => $this->profile->nickname))),
- _('Subscribers'));
- $this->elementEnd('dt');
- $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
- $this->elementEnd('dl');
-
- $this->elementStart('dl', 'entity_notices');
- $this->element('dt', null, _('Notices'));
- $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
- $this->elementEnd('dl');
-
- $this->elementEnd('div');
- }
-
- function showGroups()
+ function showNotices()
{
- $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1);
-
- $this->elementStart('div', array('id' => 'entity_groups',
- 'class' => 'section'));
-
- $this->element('h2', null, _('Groups'));
-
- if ($groups) {
- $gml = new GroupMiniList($groups, $this->user, $this);
- $cnt = $gml->show();
- if ($cnt == 0) {
- $this->element('p', null, _('(None)'));
- }
- }
+ $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
- if ($cnt > GROUPS_PER_MINILIST) {
- $this->elementStart('p');
- $this->element('a', array('href' => common_local_url('usergroups',
- array('nickname' => $this->profile->nickname)),
- 'class' => 'more'),
- _('All groups'));
- $this->elementEnd('p');
+ $pnl = new ProfileNoticeList($notice, $this);
+ $cnt = $pnl->show();
+ if (0 == $cnt) {
+ $this->showEmptyListMessage();
}
- $this->elementEnd('div');
+ $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
+ 'showstream', array('nickname' => $this->user->nickname));
}
function showAnonymousMessage()
@@ -550,6 +381,12 @@ class ShowstreamAction extends Action
$this->elementEnd('div');
}
+ function showSections()
+ {
+ parent::showSections();
+ $cloud = new PersonalTagCloudSection($this, $this->user);
+ $cloud->show();
+ }
}
// We don't show the author for a profile, since we already know who it is!
diff --git a/actions/subscribers.php b/actions/subscribers.php
index 22faafaef..7ebb54d33 100644
--- a/actions/subscribers.php
+++ b/actions/subscribers.php
@@ -88,6 +88,9 @@ class SubscribersAction extends GalleryAction
if ($subscribers) {
$subscribers_list = new SubscribersList($subscribers, $this->user, $this);
$cnt = $subscribers_list->show();
+ if (0 == $cnt) {
+ $this->showEmptyListMessage();
+ }
}
$subscribers->free();
@@ -96,6 +99,25 @@ class SubscribersAction extends GalleryAction
$this->page, 'subscribers',
array('nickname' => $this->user->nickname));
}
+
+ function showEmptyListMessage()
+ {
+ if (common_logged_in()) {
+ $current_user = common_current_user();
+ if ($this->user->id === $current_user->id) {
+ $message = _('You have no subscribers. Try subscribing to people you know and they might return the favor');
+ } else {
+ $message = sprintf(_('%s has no subscribers. Want to be the first?'), $this->user->nickname);
+ }
+ }
+ else {
+ $message = sprintf(_('%s has no subscribers. Why not [register an account](%%%%action.register%%%%) and be the first?'), $this->user->nickname);
+ }
+
+ $this->elementStart('div', 'guide');
+ $this->raw(common_markup_to_html($message));
+ $this->elementEnd('div');
+ }
}
class SubscribersList extends ProfileList
diff --git a/actions/subscriptions.php b/actions/subscriptions.php
index 3fbea2039..b0c0a9b8d 100644
--- a/actions/subscriptions.php
+++ b/actions/subscriptions.php
@@ -95,6 +95,9 @@ class SubscriptionsAction extends GalleryAction
if ($subscriptions) {
$subscriptions_list = new SubscriptionsList($subscriptions, $this->user, $this);
$cnt = $subscriptions_list->show();
+ if (0 == $cnt) {
+ $this->showEmptyListMessage();
+ }
}
$subscriptions->free();
@@ -103,6 +106,25 @@ class SubscriptionsAction extends GalleryAction
$this->page, 'subscriptions',
array('nickname' => $this->user->nickname));
}
+
+ function showEmptyListMessage()
+ {
+ if (common_logged_in()) {
+ $current_user = common_current_user();
+ if ($this->user->id === $current_user->id) {
+ $message = _('You\'re not listening to anyone\'s notices right now, try subscribing to people you know. Try [people search](%%action.peoplesearch%%), look for members in groups you\'re interested in and in our [featured users](%%action.featured%%). If you\'re a [Twitter user](%%action.twittersettings%%), you can automatically subscribe to people you already follow there.');
+ } else {
+ $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
+ }
+ }
+ else {
+ $message = sprintf(_('%s is not listening to anyone.'), $this->user->nickname);
+ }
+
+ $this->elementStart('div', 'guide');
+ $this->raw(common_markup_to_html($message));
+ $this->elementEnd('div');
+ }
}
class SubscriptionsList extends ProfileList
diff --git a/actions/userauthorization.php b/actions/userauthorization.php
index 6a76e3a4c..8723848c7 100644
--- a/actions/userauthorization.php
+++ b/actions/userauthorization.php
@@ -25,7 +25,7 @@ define('TIMESTAMP_THRESHOLD', 300);
class UserauthorizationAction extends Action
{
var $error;
- var $req;
+ var $params;
function handle($args)
{
@@ -35,8 +35,8 @@ class UserauthorizationAction extends Action
# CSRF protection
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
- $req = $this->getStoredRequest();
- $this->showForm($req, _('There was a problem with your session token. '.
+ $params = $this->getStoredParams();
+ $this->showForm($params, _('There was a problem with your session token. '.
'Try again, please.'));
return;
}
@@ -50,18 +50,13 @@ class UserauthorizationAction extends Action
common_redirect(common_local_url('login'));
return;
}
+
try {
- # this must be a new request
- $req = $this->getNewRequest();
- if (!$req) {
- $this->clientError(_('No request found!'));
- }
- # XXX: only validate new requests, since nonce is one-time use
- $this->validateRequest($req);
- $this->storeRequest($req);
- $this->showForm($req);
+ $this->validateRequest();
+ $this->storeParams($_GET);
+ $this->showForm($_GET);
} catch (OAuthException $e) {
- $this->clearRequest();
+ $this->clearParams();
$this->clientError($e->getMessage());
return;
}
@@ -69,9 +64,9 @@ class UserauthorizationAction extends Action
}
}
- function showForm($req, $error=null)
+ function showForm($params, $error=null)
{
- $this->req = $req;
+ $this->params = $params;
$this->error = $error;
$this->showPage();
}
@@ -91,16 +86,16 @@ class UserauthorizationAction extends Action
function showContent()
{
- $req = $this->req;
+ $params = $this->params;
- $nickname = $req->get_parameter('omb_listenee_nickname');
- $profile = $req->get_parameter('omb_listenee_profile');
- $license = $req->get_parameter('omb_listenee_license');
- $fullname = $req->get_parameter('omb_listenee_fullname');
- $homepage = $req->get_parameter('omb_listenee_homepage');
- $bio = $req->get_parameter('omb_listenee_bio');
- $location = $req->get_parameter('omb_listenee_location');
- $avatar = $req->get_parameter('omb_listenee_avatar');
+ $nickname = $params['omb_listenee_nickname'];
+ $profile = $params['omb_listenee_profile'];
+ $license = $params['omb_listenee_license'];
+ $fullname = $params['omb_listenee_fullname'];
+ $homepage = $params['omb_listenee_homepage'];
+ $bio = $params['omb_listenee_bio'];
+ $location = $params['omb_listenee_location'];
+ $avatar = $params['omb_listenee_avatar'];
$this->elementStart('div', 'profile');
if ($avatar) {
@@ -147,56 +142,56 @@ class UserauthorizationAction extends Action
function sendAuthorization()
{
- $req = $this->getStoredRequest();
+ $params = $this->getStoredParams();
- if (!$req) {
+ if (!$params) {
$this->clientError(_('No authorization request!'));
return;
}
- $callback = $req->get_parameter('oauth_callback');
+ $callback = $params['oauth_callback'];
if ($this->arg('accept')) {
- if (!$this->authorizeToken($req)) {
+ if (!$this->authorizeToken($params)) {
$this->clientError(_('Error authorizing token'));
}
- if (!$this->saveRemoteProfile($req)) {
+ if (!$this->saveRemoteProfile($params)) {
$this->clientError(_('Error saving remote profile'));
}
if (!$callback) {
- $this->showAcceptMessage($req->get_parameter('oauth_token'));
+ $this->showAcceptMessage($params['oauth_token']);
} else {
- $params = array();
- $params['oauth_token'] = $req->get_parameter('oauth_token');
- $params['omb_version'] = OMB_VERSION_01;
- $user = User::staticGet('uri', $req->get_parameter('omb_listener'));
+ $newparams = array();
+ $newparams['oauth_token'] = $params['oauth_token'];
+ $newparams['omb_version'] = OMB_VERSION_01;
+ $user = User::staticGet('uri', $params['omb_listener']);
$profile = $user->getProfile();
if (!$profile) {
common_log_db_error($user, 'SELECT', __FILE__);
$this->serverError(_('User without matching profile'));
return;
}
- $params['omb_listener_nickname'] = $user->nickname;
- $params['omb_listener_profile'] = common_local_url('showstream',
+ $newparams['omb_listener_nickname'] = $user->nickname;
+ $newparams['omb_listener_profile'] = common_local_url('showstream',
array('nickname' => $user->nickname));
if (!is_null($profile->fullname)) {
- $params['omb_listener_fullname'] = $profile->fullname;
+ $newparams['omb_listener_fullname'] = $profile->fullname;
}
if (!is_null($profile->homepage)) {
- $params['omb_listener_homepage'] = $profile->homepage;
+ $newparams['omb_listener_homepage'] = $profile->homepage;
}
if (!is_null($profile->bio)) {
- $params['omb_listener_bio'] = $profile->bio;
+ $newparams['omb_listener_bio'] = $profile->bio;
}
if (!is_null($profile->location)) {
- $params['omb_listener_location'] = $profile->location;
+ $newparams['omb_listener_location'] = $profile->location;
}
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
if ($avatar) {
- $params['omb_listener_avatar'] = $avatar->url;
+ $newparams['omb_listener_avatar'] = $avatar->url;
}
$parts = array();
- foreach ($params as $k => $v) {
+ foreach ($newparams as $k => $v) {
$parts[] = $k . '=' . OAuthUtil::urlencode_rfc3986($v);
}
$query_string = implode('&', $parts);
@@ -214,12 +209,10 @@ class UserauthorizationAction extends Action
}
}
- function authorizeToken(&$req)
+ function authorizeToken(&$params)
{
- $consumer_key = $req->get_parameter('oauth_consumer_key');
- $token_field = $req->get_parameter('oauth_token');
+ $token_field = $params['oauth_token'];
$rt = new Token();
- $rt->consumer_key = $consumer_key;
$rt->tok = $token_field;
$rt->type = 0;
$rt->state = 0;
@@ -235,21 +228,21 @@ class UserauthorizationAction extends Action
# XXX: refactor with similar code in finishremotesubscribe.php
- function saveRemoteProfile(&$req)
+ function saveRemoteProfile(&$params)
{
# FIXME: we should really do this when the consumer comes
# back for an access token. If they never do, we've got stuff in a
# weird state.
- $nickname = $req->get_parameter('omb_listenee_nickname');
- $fullname = $req->get_parameter('omb_listenee_fullname');
- $profile_url = $req->get_parameter('omb_listenee_profile');
- $homepage = $req->get_parameter('omb_listenee_homepage');
- $bio = $req->get_parameter('omb_listenee_bio');
- $location = $req->get_parameter('omb_listenee_location');
- $avatar_url = $req->get_parameter('omb_listenee_avatar');
+ $nickname = $params['omb_listenee_nickname'];
+ $fullname = $params['omb_listenee_fullname'];
+ $profile_url = $params['omb_listenee_profile'];
+ $homepage = $params['omb_listenee_homepage'];
+ $bio = $params['omb_listenee_bio'];
+ $location = $params['omb_listenee_location'];
+ $avatar_url = $params['omb_listenee_avatar'];
- $listenee = $req->get_parameter('omb_listenee');
+ $listenee = $params['omb_listenee'];
$remote = Remote_profile::staticGet('uri', $listenee);
if ($remote) {
@@ -309,14 +302,11 @@ class UserauthorizationAction extends Action
}
$user = common_current_user();
- $datastore = omb_oauth_datastore();
- $consumer = $this->getConsumer($datastore, $req);
- $token = $this->getToken($datastore, $req, $consumer);
$sub = new Subscription();
$sub->subscriber = $user->id;
$sub->subscribed = $remote->id;
- $sub->token = $token->key; # NOTE: request token, not valid for use!
+ $sub->token = $params['oauth_token']; # NOTE: request token, not valid for use!
$sub->created = DB_DataObject_Cast::dateTime(); # current time
if (!$sub->insert()) {
@@ -360,65 +350,59 @@ class UserauthorizationAction extends Action
common_show_footer();
}
- function storeRequest($req)
+ function storeParams($params)
{
common_ensure_session();
- $_SESSION['userauthorizationrequest'] = $req;
+ $_SESSION['userauthorizationparams'] = $params;
}
- function clearRequest()
+ function clearParams()
{
common_ensure_session();
- unset($_SESSION['userauthorizationrequest']);
+ unset($_SESSION['userauthorizationparams']);
}
- function getStoredRequest()
+ function getStoredParams()
{
common_ensure_session();
- $req = $_SESSION['userauthorizationrequest'];
- return $req;
- }
-
- function getNewRequest()
- {
- common_remove_magic_from_request();
- $req = OAuthRequest::from_request();
- return $req;
+ $params = $_SESSION['userauthorizationparams'];
+ return $params;
}
# Throws an OAuthException if anything goes wrong
- function validateRequest(&$req)
+ function validateRequest()
{
- # OAuth stuff -- have to copy from OAuth.php since they're
- # all private methods, and there's no user-authentication method
- $this->checkVersion($req);
- $datastore = omb_oauth_datastore();
- $consumer = $this->getConsumer($datastore, $req);
- $token = $this->getToken($datastore, $req, $consumer);
- $this->checkTimestamp($req);
- $this->checkNonce($datastore, $req, $consumer, $token);
- $this->checkSignature($req, $consumer, $token);
- $this->validateOmb($req);
+ /* Find token.
+ TODO: If no token is passed the user should get a prompt to enter it
+ according to OAuth Core 1.0 */
+ $t = new Token();
+ $t->tok = $_GET['oauth_token'];
+ $t->type = 0;
+ if (!$t->find(true)) {
+ throw new OAuthException("Invalid request token: " . $_GET['oauth_token']);
+ }
+
+ $this->validateOmb();
return true;
}
- function validateOmb(&$req)
+ function validateOmb()
{
foreach (array('omb_version', 'omb_listener', 'omb_listenee',
'omb_listenee_profile', 'omb_listenee_nickname',
'omb_listenee_license') as $param)
{
- if (is_null($req->get_parameter($param))) {
+ if (!isset($_GET[$param]) || is_null($_GET[$param])) {
throw new OAuthException("Required parameter '$param' not found");
}
}
# Now, OMB stuff
- $version = $req->get_parameter('omb_version');
+ $version = $_GET['omb_version'];
if ($version != OMB_VERSION_01) {
throw new OAuthException("OpenMicroBlogging version '$version' not supported");
}
- $listener = $req->get_parameter('omb_listener');
+ $listener = $_GET['omb_listener'];
$user = User::staticGet('uri', $listener);
if (!$user) {
throw new OAuthException("Listener URI '$listener' not found here");
@@ -427,7 +411,7 @@ class UserauthorizationAction extends Action
if ($cur->id != $user->id) {
throw new OAuthException("Can't add for another user!");
}
- $listenee = $req->get_parameter('omb_listenee');
+ $listenee = $_GET['omb_listenee'];
if (!Validate::uri($listenee) &&
!common_valid_tag($listenee)) {
throw new OAuthException("Listenee URI '$listenee' not a recognizable URI");
@@ -450,13 +434,13 @@ class UserauthorizationAction extends Action
throw new OAuthException("Already subscribed to user!");
}
}
- $nickname = $req->get_parameter('omb_listenee_nickname');
+ $nickname = $_GET['omb_listenee_nickname'];
if (!Validate::string($nickname, array('min_length' => 1,
'max_length' => 64,
'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
throw new OAuthException('Nickname must have only letters and numbers and no spaces.');
}
- $profile = $req->get_parameter('omb_listenee_profile');
+ $profile = $_GET['omb_listenee_profile'];
if (!common_valid_http_url($profile)) {
throw new OAuthException("Invalid profile URL '$profile'.");
}
@@ -465,7 +449,7 @@ class UserauthorizationAction extends Action
throw new OAuthException("Profile URL '$profile' is for a local user.");
}
- $license = $req->get_parameter('omb_listenee_license');
+ $license = $_GET['omb_listenee_license'];
if (!common_valid_http_url($license)) {
throw new OAuthException("Invalid license URL '$license'.");
}
@@ -474,23 +458,23 @@ class UserauthorizationAction extends Action
throw new OAuthException("Listenee stream license '$license' not compatible with site license '$site_license'.");
}
# optional stuff
- $fullname = $req->get_parameter('omb_listenee_fullname');
+ $fullname = $_GET['omb_listenee_fullname'];
if ($fullname && mb_strlen($fullname) > 255) {
throw new OAuthException("Full name '$fullname' too long.");
}
- $homepage = $req->get_parameter('omb_listenee_homepage');
+ $homepage = $_GET['omb_listenee_homepage'];
if ($homepage && (!common_valid_http_url($homepage) || mb_strlen($homepage) > 255)) {
throw new OAuthException("Invalid homepage '$homepage'");
}
- $bio = $req->get_parameter('omb_listenee_bio');
+ $bio = $_GET['omb_listenee_bio'];
if ($bio && mb_strlen($bio) > 140) {
throw new OAuthException("Bio too long '$bio'");
}
- $location = $req->get_parameter('omb_listenee_location');
+ $location = $_GET['omb_listenee_location'];
if ($location && mb_strlen($location) > 255) {
throw new OAuthException("Location too long '$location'");
}
- $avatar = $req->get_parameter('omb_listenee_avatar');
+ $avatar = $_GET['omb_listenee_avatar'];
if ($avatar) {
if (!common_valid_http_url($avatar) || strlen($avatar) > 255) {
throw new OAuthException("Invalid avatar URL '$avatar'");
@@ -507,7 +491,7 @@ class UserauthorizationAction extends Action
throw new OAuthException("Wrong image type for '$avatar'");
}
}
- $callback = $req->get_parameter('oauth_callback');
+ $callback = $_GET['oauth_callback'];
if ($callback && !common_valid_http_url($callback)) {
throw new OAuthException("Invalid callback URL '$callback'");
}
@@ -515,92 +499,4 @@ class UserauthorizationAction extends Action
throw new OAuthException("Callback URL '$callback' is for local site.");
}
}
-
- # Snagged from OAuthServer
-
- function checkVersion(&$req)
- {
- $version = $req->get_parameter("oauth_version");
- if (!$version) {
- $version = 1.0;
- }
- if ($version != 1.0) {
- throw new OAuthException("OAuth version '$version' not supported");
- }
- return $version;
- }
-
- # Snagged from OAuthServer
-
- function getConsumer($datastore, $req)
- {
- $consumer_key = @$req->get_parameter("oauth_consumer_key");
- if (!$consumer_key) {
- throw new OAuthException("Invalid consumer key");
- }
-
- $consumer = $datastore->lookup_consumer($consumer_key);
- if (!$consumer) {
- throw new OAuthException("Invalid consumer");
- }
- return $consumer;
- }
-
- # Mostly cadged from OAuthServer
-
- function getToken($datastore, &$req, $consumer)
- {/*{{{*/
- $token_field = @$req->get_parameter('oauth_token');
- $token = $datastore->lookup_token($consumer, 'request', $token_field);
- if (!$token) {
- throw new OAuthException("Invalid $token_type token: $token_field");
- }
- return $token;
- }
-
- function checkTimestamp(&$req)
- {
- $timestamp = @$req->get_parameter('oauth_timestamp');
- $now = time();
- if ($now - $timestamp > TIMESTAMP_THRESHOLD) {
- throw new OAuthException("Expired timestamp, yours $timestamp, ours $now");
- }
- }
-
- # NOTE: don't call twice on the same request; will fail!
- function checkNonce(&$datastore, &$req, $consumer, $token)
- {
- $timestamp = @$req->get_parameter('oauth_timestamp');
- $nonce = @$req->get_parameter('oauth_nonce');
- $found = $datastore->lookup_nonce($consumer, $token, $nonce, $timestamp);
- if ($found) {
- throw new OAuthException("Nonce already used");
- }
- return true;
- }
-
- function checkSignature(&$req, $consumer, $token)
- {
- $signature_method = $this->getSignatureMethod($req);
- $signature = $req->get_parameter('oauth_signature');
- $valid_sig = $signature_method->check_signature($req,
- $consumer,
- $token,
- $signature);
- if (!$valid_sig) {
- throw new OAuthException("Invalid signature");
- }
- }
-
- function getSignatureMethod(&$req)
- {
- $signature_method = @$req->get_parameter("oauth_signature_method");
- if (!$signature_method) {
- $signature_method = "PLAINTEXT";
- }
- if ($signature_method != 'HMAC-SHA1') {
- throw new OAuthException("Signature method '$signature_method' not supported.");
- }
- return omb_hmac_sha1();
- }
}
diff --git a/actions/usergroups.php b/actions/usergroups.php
index ded4ba76b..06b2334bf 100644
--- a/actions/usergroups.php
+++ b/actions/usergroups.php
@@ -139,10 +139,28 @@ class UsergroupsAction extends Action
if ($groups) {
$gl = new GroupList($groups, $this->user, $this);
$cnt = $gl->show();
+ if (0 == $cnt) {
+ $this->showEmptyListMessage();
+ }
}
$this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
$this->page, 'usergroups',
array('nickname' => $this->user->nickname));
}
+
+ function showEmptyListMessage()
+ {
+ $message = sprintf(_('%s is not a member of any group.'), $this->user->nickname) . ' ';
+
+ if (common_logged_in()) {
+ $current_user = common_current_user();
+ if ($this->user->id === $current_user->id) {
+ $message .= _('Try [searching for groups](%%action.groupsearch%%) and joining them.');
+ }
+ }
+ $this->elementStart('div', 'guide');
+ $this->raw(common_markup_to_html($message));
+ $this->elementEnd('div');
+ }
}