- $action: action object being shown
StartPersonalGroupNav: beginning of personal group nav menu
-- $action: action object being shown
+- $menu: Menu list object being shown
+- $target: Profile for whom it is shown
+- $scoped: Profile of currently logged in user (or null)
EndPersonalGroupNav: end of personal group nav menu (good place to add a menu item)
- $action: action object being shown
/**
* Handle request
*
- * Shows a page with list of favorite notices
- *
* @param array $args $_REQUEST args; handled in prepare()
*
* @return void
$other->isSubscribed($this);
}
- function hasFave($notice)
- {
- $fave = Fave::pkeyGet(array('user_id' => $this->id,
- 'notice_id' => $notice->id));
- return ((is_null($fave)) ? false : true);
- }
-
- function faveCount()
- {
- $c = Cache::instance();
- if (!empty($c)) {
- $cnt = $c->get(Cache::key('profile:fave_count:'.$this->id));
- if (is_integer($cnt)) {
- return (int) $cnt;
- }
- }
-
- $faves = new Fave();
- $faves->user_id = $this->id;
- $cnt = (int) $faves->count('notice_id');
-
- if (!empty($c)) {
- $c->set(Cache::key('profile:fave_count:'.$this->id), $cnt);
- }
-
- return $cnt;
- }
-
- function favoriteNotices($own=false, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
- {
- return Fave::stream($this->id, $offset, $limit, $own, $since_id, $max_id);
- }
-
function noticeCount()
{
$c = Cache::instance();
return $cnt;
}
- function blowFavesCache()
- {
- $cache = Cache::instance();
- if ($cache) {
- // Faves don't happen chronologically, so we need to blow
- // ;last cache, too
- $cache->delete(Cache::key('fave:ids_by_user:'.$this->id));
- $cache->delete(Cache::key('fave:ids_by_user:'.$this->id.';last'));
- $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id));
- $cache->delete(Cache::key('fave:ids_by_user_own:'.$this->id.';last'));
- }
- $this->blowFaveCount();
- }
-
function blowSubscriberCount()
{
$c = Cache::instance();
}
}
- function blowFaveCount()
- {
- $c = Cache::instance();
- if (!empty($c)) {
- $c->delete(Cache::key('profile:fave_count:'.$this->id));
- }
- }
-
function blowNoticeCount()
{
$c = Cache::instance();
}
}
- function hasFave($notice)
- {
- return $this->getProfile()->hasFave($notice);
- }
-
function mutuallySubscribed(Profile $other)
{
return $this->getProfile()->mutuallySubscribed($other);
return $this->getProfile()->getNotices($offset, $limit, $since_id, $before_id);
}
- function favoriteNotices($own=false, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
- {
- return $this->getProfile()->favoriteNotices($own, $offset, $limit, $since_id, $max_id);
- }
-
- function blowFavesCache()
- {
- $this->getProfile()->blowFavesCache();
- }
-
function getSelfTags()
{
return Profile_tag::getTagsArray($this->id, $this->id, $this->id);
common_log(LOG_INFO, "User {$this->nickname} has no profile; continuing deletion.");
}
- $related = array('Fave',
+ $related = array(
'Confirm_address',
'Remember_me',
'Foreign_link',
$twitter_user['created_at'] = $this->dateTwitter($profile->created);
- $twitter_user['favourites_count'] = $profile->faveCount(); // British spelling!
-
$timezone = 'UTC';
if (!empty($user) && $user->timezone) {
$twitter_user['statusnet_profile_url'] = $profile->profileurl;
+ // The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array
+ Event::handle('TwitterUserArray', array($profile, &$twitter_user, $this->scoped, array()));
+
return $twitter_user;
}
*
* @return void
*/
- function show()
+ public function show()
{
- $user = common_current_user();
+ // FIXME: Legacy StatusNet behaviour was to do this, but really it should be the GroupNav
+ // of the targeted user! ($this->action->arg('nickname')
+ $target = Profile::current();
- if (empty($user)) {
+ if (!$target instanceof Profile) {
throw new ServerException('Cannot show personal group navigation without a current user.');
}
- $user_profile = $user->getProfile();
- $nickname = $user->nickname;
- $name = $user_profile->getBestName();
+ $nickname = $target->getNickname();
+ $name = $target->getBestName();
+
+ $scoped = Profile::current();
$action = $this->actionName;
$mine = ($this->action->arg('nickname') == $nickname); // @fixme kinda vague
$this->out->elementStart('ul', array('class' => 'nav'));
- if (Event::handle('StartPersonalGroupNav', array($this))) {
+ if (Event::handle('StartPersonalGroupNav', array($this, $target, $scoped))) {
$this->out->menuItem(common_local_url('all', array('nickname' =>
$nickname)),
// TRANS: Menu item in personal group navigation menu.
// TRANS: %s is a username.
sprintf(_('Replies to %s'), $name),
$mine && $action =='replies', 'nav_timeline_replies');
- $this->out->menuItem(common_local_url('showfavorites', array('nickname' =>
- $nickname)),
- // TRANS: Menu item in personal group navigation menu.
- _m('MENU','Favorites'),
- // @todo i18n FIXME: Need to make this two messages.
- // TRANS: Menu item title in personal group navigation menu.
- // TRANS: %s is a username.
- sprintf(_('%s\'s favorite notices'),
- // TRANS: Replaces %s in '%s\'s favorite notices'. (Yes, we know we need to fix this.)
- ($user_profile) ? $name : _m('FIXME','User')),
- $mine && $action =='showfavorites', 'nav_timeline_favorites');
- $cur = common_current_user();
- if ($cur && $cur->id == $user->id &&
+ if ($scoped instanceof Profile && $scoped->id == $target->id &&
!common_config('singleuser', 'enabled')) {
$this->out->menuItem(common_local_url('inbox', array('nickname' =>
$mine && $action =='inbox');
}
- Event::handle('EndPersonalGroupNav', array($this));
+ Event::handle('EndPersonalGroupNav', array($this, $target, $scoped));
}
$this->out->elementEnd('ul');
}
/**
* Handle request
*
- * Shows a page with list of favorite notices
- *
* @param array $args $_REQUEST args; handled in prepare()
*
* @return void
_('Featured users'), $this->actionName == 'featured', 'nav_featured');
}
- if (!common_config('singleuser', 'enabled')) {
- // TRANS: Menu item in search group navigation panel.
- $this->out->menuItem(common_local_url('favorited'), _m('MENU','Popular'),
- // TRANS: Menu item title in search group navigation panel.
- _('Popular notices'), $this->actionName == 'favorited', 'nav_timeline_favorited');
- }
-
Event::handle('EndPublicGroupNav', array($this));
}
$this->action->elementEnd('ul');
$count - 3),
$count - 3);
} else {
- // TRANS: List message for favoured notices.
- // TRANS: %%s is a list of users liking a notice.
- // TRANS: Plural is based on the number of of users that have favoured a notice.
+ // TRANS: List message for repeated notices.
+ // TRANS: %%s is a list of users who have repeated a notice.
+ // TRANS: Plural is based on the number of of users that have repeated a notice.
return sprintf(_m('%%s repeated this.',
'%%s repeated this.',
$count),
if ($this->boolean('ajax')) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
- // TRANS: Page title for page on which favorite notices can be unfavourited.
- $this->element('title', null, _('Disfavor favorite.'));
+ // TRANS: Page title for page on which we train the spam filter for ham or spam
+ $this->element('title', null, _('Train spam filter'));
$this->elementEnd('head');
$this->elementStart('body');
$form->show();
$this->serverError(_m('Could not delete favorite.'));
}
- $profile->blowFavesCache();
+ Fave::blowCacheForProfileId($profile->id);
if ($this->boolean('ajax')) {
$this->startHTML('text/xml;charset=utf-8');
}
$fave = Fave::addNew($profile, $notice);
- if (!$fave) {
+ if (!$fave instanceof Fave) {
// TRANS: Server error.
$this->serverError(_m('Could not create favorite.'));
}
- $profile->blowFavesCache();
+ Fave::blowCacheForProfileId($profile->id);
if ($this->boolean('ajax')) {
$this->startHTML('text/xml;charset=utf-8');
*
* @see Action
*/
- function onEndPersonalGroupNav($action)
+ function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
{
- $this->user = common_current_user();
-
- if (!$this->user) {
- // TRANS: Client error displayed when trying to display bookmarks for a non-existing user.
- $this->clientError(_('No such user.'));
- }
-
- $action->menuItem(common_local_url('bookmarks', array('nickname' => $this->user->nickname)),
+ $menu->menuItem(common_local_url('bookmarks', array('nickname' => $target->getNickname())),
// TRANS: Menu item in sample plugin.
_m('Bookmarks'),
// TRANS: Menu item title in sample plugin.
return true;
}
+ public function onTwitterUserArray(Profile $profile, array &$userdata, Profile $scoped=null, array $args=array())
+ {
+ $userdata['favourites_count'] = Fave::countByProfile($profile);
+ }
+
/**
* Typically just used to fill out StatusNet specific data in API calls in the referenced $info array.
*/
if ($fave->find()) {
while ($fave->fetch()) {
- Memcached_DataObject::blow('fave:ids_by_user_own:%d', $fave->user_id);
- Memcached_DataObject::blow('fave:ids_by_user_own:%d;last', $fave->user_id);
- Memcached_DataObject::blow('fave:ids_by_user:%d', $fave->user_id);
- Memcached_DataObject::blow('fave:ids_by_user:%d;last', $fave->user_id);
+ Fave::blowCacheForProfileId($fave->user_id);
$fave->delete();
}
}
$fave->free();
}
+ public function onUserDeleteRelated(User $user, array &$related)
+ {
+ $fave = new Fave();
+ $fave->user_id = $user->id;
+ $fave->delete(); // Will perform a DELETE matching "user_id = {$user->id}"
+
+ Fave::blowCacheForProfileId($user->id);
+ return true;
+ }
+
public function onStartNoticeListPrefill(array &$notices, array $notice_ids, Profile $scoped=null)
{
// prefill array of objects, before pluginfication it was Notice::fillFaves($notices)
$supported = $supported || $cmd instanceof FavCommand;
}
+ // Layout stuff
+
+ public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
+ {
+ $menu->out->menuItem(common_local_url('showfavorites', array('nickname' => $target->getNickname())),
+ // TRANS: Menu item in personal group navigation menu.
+ _m('MENU','Favorites'),
+ // @todo i18n FIXME: Need to make this two messages.
+ // TRANS: Menu item title in personal group navigation menu.
+ // TRANS: %s is a username.
+ sprintf(_('%s\'s favorite notices'), $target->getBestName()),
+ $scoped instanceof Profile && $target->id === $scoped->id && $menu->actionName =='showfavorites',
+ 'nav_timeline_favorites');
+ }
+
+ public function onEndPublicGroupNav(Menu $menu)
+ {
+ if (!common_config('singleuser', 'enabled')) {
+ // TRANS: Menu item in search group navigation panel.
+ $menu->out->menuItem(common_local_url('favorited'), _m('MENU','Popular'),
+ // TRANS: Menu item title in search group navigation panel.
+ _('Popular notices'), $menu->actionName == 'favorited', 'nav_timeline_favorited');
+ }
+ }
+
public function onPluginVersion(array &$versions)
{
$versions[] = array('name' => 'Favorite',
}
$this->notify($fave, $this->notice, $this->user);
- $this->user->blowFavesCache();
+ Fave::blowCacheForProfileId($this->user->id);
if ($this->format == 'xml') {
$this->showSingleXmlStatus($this->notice);
return;
}
- $this->user->blowFavesCache();
+ Fave::blowCacheForProfileId($this->user->id);
if ($this->format == 'xml') {
$this->showSingleXmlStatus($this->notice);
common_debug("since id = " . $this->since_id . " max id = " . $this->max_id);
- if (!empty($this->auth_user) && $this->auth_user->id == $this->target->id) {
- $notice = $this->target->favoriteNotices(
- true,
- ($this->page-1) * $this->count,
- $this->count,
- $this->since_id,
- $this->max_id
- );
- } else {
- $notice = $this->target->favoriteNotices(
- false,
- ($this->page-1) * $this->count,
- $this->count,
- $this->since_id,
- $this->max_id
- );
- }
+ $notice = Fave::stream($this->target->id,
+ ($this->page-1) * $this->count, // offset
+ $this->count, // limit
+ (!empty($this->auth_user) && $this->auth_user->id == $this->target->id), // own feed?
+ $this->since_id,
+ $this->max_id
+ );
while ($notice->fetch()) {
$notices[] = clone($notice);
$fave = Fave::addNew($profile, $notice);
- if (!empty($fave)) {
- $this->_profile->blowFavesCache();
+ if ($fave instanceof Fave) {
+ Fave::blowCacheForProfileId($this->_profile->id);
$this->notify($fave, $notice, $this->auth_user);
}
// TRANS: Server error displayed when removing a favorite from the database fails.
$this->serverError(_('Could not delete favorite.'));
}
- $this->scoped->blowFavesCache();
+ Fave::blowCacheForProfileId($this->scoped->id);
if (StatusNet::isAjax()) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
$this->serverError(_('Could not create favorite.'));
}
$this->notify($notice, $this->scoped->getUser());
- $this->scoped->blowFavesCache();
+ Fave::blowCacheForProfileId($this->scoped->id);
if (StatusNet::isAjax()) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
*/
function getNotices($limit=0)
{
- $user = $this->user;
- $notice = $user->favoriteNotices(false, 0, $limit);
+ $notice = Fave::stream($this->user->id, 0, $limit, $false);
$notices = array();
while ($notice->fetch()) {
$notices[] = clone($notice);
$cur = common_current_user();
- if (!empty($cur) && $cur->id == $this->user->id) {
-
- // Show imported/gateway notices as well as local if
- // the user is looking at their own favorites
-
- $this->notice = $this->user->favoriteNotices(true, ($this->page-1)*NOTICES_PER_PAGE,
- NOTICES_PER_PAGE + 1);
- } else {
- $this->notice = $this->user->favoriteNotices(false, ($this->page-1)*NOTICES_PER_PAGE,
- NOTICES_PER_PAGE + 1);
- }
+ // Show imported/gateway notices as well as local if
+ // the user is looking at their own favorites, otherwise not.
+ $this->notice = Fave::stream($this->user->id,
+ ($this->page-1)*NOTICES_PER_PAGE, // offset
+ NOTICES_PER_PAGE + 1, // limit
+ (!empty($cur) && $cur->id == $this->user->id) // own feed?
+ );
if (empty($this->notice)) {
// TRANS: Server error displayed when favourite notices could not be retrieved from the database.
return $fav;
}
+ static function countByProfile(Profile $profile)
+ {
+ $c = Cache::instance();
+ if (!empty($c)) {
+ $cnt = $c->get(Cache::key('fave:count_by_profile:'.$profile->id));
+ if (is_integer($cnt)) {
+ return $cnt;
+ }
+ }
+
+ $faves = new Fave();
+ $faves->user_id = $profile->id;
+ $cnt = (int) $faves->count('notice_id');
+
+ if (!empty($c)) {
+ $c->set(Cache::key('fave:count_by_profile:'.$profile->id), $cnt);
+ }
+
+ return $cnt;
+ }
+
function getURI()
{
if (!empty($this->uri)) {
$faveMap = Fave::listGet('notice_id', $notice_ids);
self::$_faves = array_replace(self::$_faves, $faveMap);
}
+
+ static public function blowCacheForProfileId($profile_id)
+ {
+ $cache = Cache::instance();
+ if ($cache) {
+ // Faves don't happen chronologically, so we need to blow
+ // ;last cache, too
+ $cache->delete(Cache::key('fave:ids_by_user:'.$profile_id));
+ $cache->delete(Cache::key('fave:ids_by_user:'.$profile_id.';last'));
+ $cache->delete(Cache::key('fave:ids_by_user_own:'.$profile_id));
+ $cache->delete(Cache::key('fave:ids_by_user_own:'.$profile_id.';last'));
+ $cache->delete(Cache::key('fave:count_by_profile:'.$profile_id));
+ }
+ }
}
}
}
- $this->user->blowFavesCache();
+ Fave::blowCacheForProfileId($this->user->id);
// TRANS: Text shown when a notice has been marked as favourite successfully.
$channel->output($this->user, _('Notice marked as fave.'));
'title' => _('Upload a photo')));
}
*/
- function onEndPersonalGroupNav($nav)
+ function onEndPersonalGroupNav(Menu $nav, Profile $target, Profile $scoped=null)
{
$nav->out->menuItem(common_local_url('photos',
return true;
}
- function onStartPersonalGroupNav($nav)
+ function onStartPersonalGroupNav(Menu $nav, Profile $target, Profile $scoped=null)
{
$nav->out->menuItem(common_local_url('bio',
array('nickname' => $nav->action->trimmed('nickname'))), _('Bio'),
*
* This class allows users to link their Twitter accounts
*
+ * Depends on Favorite plugin.
+ *
* @category Plugin
* @package StatusNet
* @author Zach Copley <zach@status.net>
/**
* Basic client class for Yammer's OAuth/JSON API.
*
+ * Depends on Favorite plugin
+ *
* @package YammerImportPlugin
* @author Brion Vibber <brion@status.net>
*/
$this->assertEquals($notice->source, $noticeInfo->getAttribute('source'));
$this->assertEquals('', $noticeInfo->getAttribute('repeat_of'));
$this->assertEquals('', $noticeInfo->getAttribute('repeated'));
- $this->assertEquals('', $noticeInfo->getAttribute('favorite'));
+// $this->assertEquals('', $noticeInfo->getAttribute('favorite'));
$this->assertEquals('', $noticeInfo->getAttribute('source_link'));
}
$this->assertEquals('false', $noticeInfo->getAttribute('repeated'));
}
- public function testNoticeInfoFave()
+/* public function testNoticeInfoFave()
{
$notice = $this->_fakeNotice();
$noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
$this->assertEquals('false', $noticeInfo->getAttribute('favorite'));
- }
+ }*/
public function testConversationLink()
{