2010-10-01 08:25:15 +09:00
|
|
|
<?php
|
2019-08-04 22:39:18 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social 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.
|
|
|
|
//
|
|
|
|
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
2010-10-01 08:25:15 +09:00
|
|
|
|
|
|
|
/**
|
2019-08-04 22:39:18 +09:00
|
|
|
* The ForceGroup plugin allows forced group memberships and allows forcing all notices
|
|
|
|
* to appear in some groups.
|
|
|
|
*
|
|
|
|
* @package ForceGroupPlugin
|
2010-10-01 08:25:15 +09:00
|
|
|
* @maintainer Brion Vibber <brion@status.net>
|
2019-08-04 22:39:18 +09:00
|
|
|
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2010-10-01 08:25:15 +09:00
|
|
|
*/
|
|
|
|
|
2019-08-04 22:39:18 +09:00
|
|
|
defined('GNUSOCIAL') || die;
|
2010-10-01 08:25:15 +09:00
|
|
|
|
|
|
|
class ForceGroupPlugin extends Plugin
|
|
|
|
{
|
2019-06-03 09:56:52 +09:00
|
|
|
const PLUGIN_VERSION = '2.0.0';
|
|
|
|
|
2019-08-04 22:39:18 +09:00
|
|
|
// settings which can be set in config.php with addModule('ForceGroup', ['param'=>'value', ...]);
|
|
|
|
|
2010-10-01 08:25:15 +09:00
|
|
|
/**
|
|
|
|
* Members of these groups will have all their posts mirrored into
|
|
|
|
* the group even if they don't explicitly mention it.
|
|
|
|
*
|
|
|
|
* List by local nickname.
|
|
|
|
*/
|
2019-08-04 22:39:18 +09:00
|
|
|
public $post = [];
|
2011-04-09 01:46:41 +09:00
|
|
|
|
2010-10-01 08:25:15 +09:00
|
|
|
/**
|
|
|
|
* New user registrations will automatically join these groups on
|
|
|
|
* registration. They're not prevented from leaving, however.
|
2011-04-09 01:46:41 +09:00
|
|
|
*
|
2010-10-01 08:25:15 +09:00
|
|
|
* List by local nickname.
|
|
|
|
*/
|
2019-08-04 22:39:18 +09:00
|
|
|
public $join = [];
|
2010-10-01 08:25:15 +09:00
|
|
|
|
|
|
|
/**
|
2019-08-04 22:39:18 +09:00
|
|
|
* If poster is in one of the $post groups, make sure their notice
|
2010-10-01 08:25:15 +09:00
|
|
|
* gets saved into that group even if not explicitly mentioned.
|
|
|
|
*
|
|
|
|
* @param Notice $notice
|
2019-08-04 22:39:18 +09:00
|
|
|
* @return bool event hook return
|
|
|
|
* @throws ServerException
|
2010-10-01 08:25:15 +09:00
|
|
|
*/
|
2019-08-04 22:39:18 +09:00
|
|
|
public function onStartNoticeDistribute($notice): bool
|
2010-10-01 08:25:15 +09:00
|
|
|
{
|
|
|
|
$profile = $notice->getProfile();
|
2012-06-19 12:39:47 +09:00
|
|
|
|
2013-10-25 20:17:29 +09:00
|
|
|
$isRemote = !(User::getKV('id', $profile->id));
|
2012-06-19 12:39:47 +09:00
|
|
|
if ($isRemote) {
|
|
|
|
/*
|
|
|
|
* Notices from remote users on other sites
|
|
|
|
* will normally not end up here unless they're
|
|
|
|
* specifically directed here, e.g.: via explicit
|
|
|
|
* post to a remote (to them) group. But remote
|
|
|
|
* notices can also be `pulled in' as a result of
|
|
|
|
* local users subscribing to the remote user;
|
|
|
|
* from the remote user's perspective, this results
|
|
|
|
* in group-forcing appearing effectively random.
|
|
|
|
* So let's be consistent, and just never force
|
|
|
|
* incoming remote notices into a ForceGroup:
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-01 08:25:15 +09:00
|
|
|
foreach ($this->post as $nickname) {
|
|
|
|
$group = User_group::getForNickname($nickname);
|
|
|
|
if ($group && $profile->isMember($group)) {
|
|
|
|
$notice->addToGroupInbox($group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-04 22:39:18 +09:00
|
|
|
/**
|
|
|
|
* Make sure that this new user is added to all of the $join groups
|
|
|
|
*
|
|
|
|
* @param Profile $profile
|
|
|
|
* @return bool event hook return
|
|
|
|
* @throws ServerException
|
|
|
|
*/
|
2013-09-15 01:36:35 +09:00
|
|
|
public function onEndUserRegister(Profile $profile)
|
2010-10-01 08:25:15 +09:00
|
|
|
{
|
|
|
|
foreach ($this->join as $nickname) {
|
|
|
|
$group = User_group::getForNickname($nickname);
|
|
|
|
if ($group && !$profile->isMember($group)) {
|
|
|
|
try {
|
2011-03-22 06:35:29 +09:00
|
|
|
$profile->joinGroup($group);
|
2010-10-01 08:25:15 +09:00
|
|
|
} catch (Exception $e) {
|
2010-10-02 04:53:20 +09:00
|
|
|
// TRANS: Server exception.
|
|
|
|
// TRANS: %1$s is a user nickname, %2$s is a group nickname.
|
2019-08-04 22:39:18 +09:00
|
|
|
throw new ServerException(sprintf(
|
|
|
|
_m('Could not join user %1$s to group %2$s.'),
|
|
|
|
$profile->nickname,
|
|
|
|
$group->nickname
|
|
|
|
));
|
2010-10-01 08:25:15 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-04 22:39:18 +09:00
|
|
|
return true;
|
2010-10-01 08:25:15 +09:00
|
|
|
}
|
2010-10-02 04:53:20 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide plugin version information.
|
|
|
|
*
|
|
|
|
* This data is used when showing the version page.
|
|
|
|
*
|
|
|
|
* @param array &$versions array of version data arrays; see EVENTS.txt
|
|
|
|
*
|
2019-08-04 22:39:18 +09:00
|
|
|
* @return bool hook value
|
|
|
|
* @throws Exception
|
2010-10-02 04:53:20 +09:00
|
|
|
*/
|
2019-08-12 23:03:30 +09:00
|
|
|
public function onPluginVersion(array &$versions): bool
|
2010-10-02 04:53:20 +09:00
|
|
|
{
|
2016-01-23 01:38:42 +09:00
|
|
|
$url = 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/ForceGroup';
|
2010-10-02 04:53:20 +09:00
|
|
|
|
|
|
|
$versions[] = array('name' => 'ForceGroup',
|
2019-06-03 09:56:52 +09:00
|
|
|
'version' => self::PLUGIN_VERSION,
|
2010-10-02 04:53:20 +09:00
|
|
|
'author' => 'Brion Vibber',
|
|
|
|
'homepage' => $url,
|
|
|
|
'rawdescription' =>
|
2019-08-04 22:39:18 +09:00
|
|
|
// TRANS: Module description.
|
|
|
|
_m('Allows forced group memberships and forces all notices to appear in groups that users were forced in.'));
|
2010-10-02 04:53:20 +09:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-01 08:25:15 +09:00
|
|
|
}
|