' modified = "%s" '.
'WHERE user_id = %d '.
'AND notice_id = %d',
- Fave::newURI($fave->user_id, $fave->notice_id, $fave->modified),
+ Fave::newUri($fave->user_id, $fave->notice_id, $fave->modified),
common_sql_date(strtotime($fave->modified)),
$fave->user_id,
$fave->notice_id));
'format' => '(xml|json)'));
}
+ // FIXME: Set this to abstract public in lib/activityhandlerplugin.php ddwhen all plugins have migrated!
+ protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
+ {
+ assert($this->isMyActivity($act));
+
+ // If empty, we should've created it ourselves on our node.
+ if (!isset($options['created'])) {
+ $options['created'] = !empty($act->time) ? common_sql_date($act->time) : common_sql_now();
+ }
+ if (!isset($options['uri'])) {
+ $options['uri'] = !empty($act->id) ? $act->id : $act->selfLink;
+ }
+
+ // We must have an objects[0] here because in isMyActivity we require the count to be == 1
+ $actobj = $act->objects[0];
+
+ try {
+ $object = Fave::saveActivityObject($actobj, $stored);
+ } catch (ServerException $e) {
+ // Probably that the favored notice doesn't exist in our local database
+ // but may also be some missing profile or so, which we could catch in a
+ // more explicit catch-statement.
+ return null;
+ }
+ return $object;
+ }
+
+
+ public function activityObjectFromNotice(Notice $notice)
+ {
+ $fave = Fave::fromStored($notice);
+ return $fave->asActivityObject();
+ }
+
+ public function deleteRelated(Notice $notice)
+ {
+ try {
+ $fave = Fave::fromStored($notice);
+ $fave->delete();
+ } catch (NoResultException $e) {
+ // Cool, no problem. We wanted to get rid of it anyway.
+ }
+ }
+
+ // API stuff
+
/**
* Typically just used to fill out Twitter-compatible API status data.
*
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.
*/
public function onNoticeDeleteRelated(Notice $notice)
{
+ parent::onNoticeDeleteRelated($notice);
+
+ // The below algorithm is because we want to delete fave
+ // activities on any notice which _has_ faves, and not as
+ // in the parent function only ones that _are_ faves.
+
$fave = new Fave();
$fave->notice_id = $notice->id;
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->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)
}
}
+ public function showNoticeListItem(NoticeListItem $nli)
+ {
+ // pass
+ }
+ public function openNoticeListItemElement(NoticeListItem $nli)
+ {
+ // pass
+ }
+ public function closeNoticeListItemElement(NoticeListItem $nli)
+ {
+ // pass
+ }
+
public function onAppendUserActivityStreamObjects(UserActivityStream $uas, array &$objs)
{
$faves = array();
$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 onEndShowSections(Action $action)
+ {
+ if (!$action->isAction(array('all', 'public'))) {
+ return true;
+ }
+
+ if (!common_config('performance', 'high')) {
+ $section = new PopularNoticeSection($action, $action->getScoped());
+ $section->show();
+ }
+ }
+
public function onPluginVersion(array &$versions)
{
$versions[] = array('name' => 'Favorite',