forked from GNUsocial/gnu-social
pluginified most of hasFave, getFaves and related calls
The code is now more event-driven when it comes to rendering notices and their related HTML elements, since we can't have direct calls from core to a plugin. lib/activitymover.php has a function to move a Favorite activity which will not happen now. The move must be pluginified and performed as an event which plugins can catch on to.
This commit is contained in:
52
plugins/Favorite/lib/favcommand.php
Normal file
52
plugins/Favorite/lib/favcommand.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
class FavCommand extends Command
|
||||
{
|
||||
var $other = null;
|
||||
|
||||
function __construct($user, $other)
|
||||
{
|
||||
parent::__construct($user);
|
||||
$this->other = $other;
|
||||
}
|
||||
|
||||
function handle($channel)
|
||||
{
|
||||
$notice = $this->getNotice($this->other);
|
||||
|
||||
$fave = new Fave();
|
||||
$fave->user_id = $this->user->id;
|
||||
$fave->notice_id = $notice->id;
|
||||
$fave->find();
|
||||
|
||||
if ($fave->fetch()) {
|
||||
// TRANS: Error message text shown when a favorite could not be set because it has already been favorited.
|
||||
$channel->error($this->user, _('Could not create favorite: Already favorited.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$fave = Fave::addNew($this->user->getProfile(), $notice);
|
||||
|
||||
if (!$fave) {
|
||||
// TRANS: Error message text shown when a favorite could not be set.
|
||||
$channel->error($this->user, _('Could not create favorite.'));
|
||||
return;
|
||||
}
|
||||
|
||||
// @fixme favorite notification should be triggered
|
||||
// at a lower level
|
||||
|
||||
$other = User::getKV('id', $notice->profile_id);
|
||||
|
||||
if ($other && $other->id != $this->user->id) {
|
||||
if ($other->email && $other->emailnotifyfav) {
|
||||
mail_notify_fave($other, $this->user, $notice);
|
||||
}
|
||||
}
|
||||
|
||||
$this->user->blowFavesCache();
|
||||
|
||||
// TRANS: Text shown when a notice has been marked as favourite successfully.
|
||||
$channel->output($this->user, _('Notice marked as fave.'));
|
||||
}
|
||||
}
|
80
plugins/Favorite/lib/threadednoticelistfavesitem.php
Normal file
80
plugins/Favorite/lib/threadednoticelistfavesitem.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* GNU Social - a federating social network
|
||||
* Copyright (C) 2014, Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
/**
|
||||
* Placeholder for showing faves...
|
||||
*/
|
||||
class ThreadedNoticeListFavesItem extends NoticeListActorsItem
|
||||
{
|
||||
function getProfiles()
|
||||
{
|
||||
$faves = Fave::byNotice($this->notice);
|
||||
$profiles = array();
|
||||
foreach ($faves as $fave) {
|
||||
$profiles[] = $fave->user_id;
|
||||
}
|
||||
return $profiles;
|
||||
}
|
||||
|
||||
function magicList($items)
|
||||
{
|
||||
if (count($items) > 4) {
|
||||
return parent::magicList(array_slice($items, 0, 3));
|
||||
} else {
|
||||
return parent::magicList($items);
|
||||
}
|
||||
}
|
||||
|
||||
function getListMessage($count, $you)
|
||||
{
|
||||
if ($count == 1 && $you) {
|
||||
// darn first person being different from third person!
|
||||
// TRANS: List message for notice favoured by logged in user.
|
||||
return _m('FAVELIST', 'You like this.');
|
||||
} else if ($count > 4) {
|
||||
// TRANS: List message for when more than 4 people like something.
|
||||
// TRANS: %%s is a list of users liking a notice, %d is the number over 4 that like the notice.
|
||||
// TRANS: Plural is decided on the total number of users liking the notice (count of %%s + %d).
|
||||
return sprintf(_m('%%s and %d others like this.',
|
||||
'%%s and %d others like this.',
|
||||
$count),
|
||||
$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.
|
||||
return sprintf(_m('%%s likes this.',
|
||||
'%%s like this.',
|
||||
$count),
|
||||
$count);
|
||||
}
|
||||
}
|
||||
|
||||
function showStart()
|
||||
{
|
||||
$this->out->elementStart('li', array('class' => 'notice-data notice-faves'));
|
||||
}
|
||||
|
||||
function showEnd()
|
||||
{
|
||||
$this->out->elementEnd('li');
|
||||
}
|
||||
}
|
34
plugins/Favorite/lib/threadednoticelistinlinefavesitem.php
Normal file
34
plugins/Favorite/lib/threadednoticelistinlinefavesitem.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* GNU Social - a federating social network
|
||||
* Copyright (C) 2014, Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
|
||||
// @todo FIXME: needs documentation.
|
||||
class ThreadedNoticeListInlineFavesItem extends ThreadedNoticeListFavesItem
|
||||
{
|
||||
function showStart()
|
||||
{
|
||||
$this->out->elementStart('div', array('class' => 'notice-faves'));
|
||||
}
|
||||
|
||||
function showEnd()
|
||||
{
|
||||
$this->out->elementEnd('div');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user