X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FGroupPrivateMessage%2FGroupPrivateMessagePlugin.php;h=87c5aa9bdafe55b25ddb5329ce74e66ba5646fac;hb=524b98bfa3fd340ade6ce8b0e7f23ce773db5d92;hp=9707c08107aa1667f37a567725c48b81e9f100a5;hpb=20824292c986733d3efb71fb4aaf411e5b008b94;p=quix0rs-gnu-social.git diff --git a/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php b/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php index 9707c08107..87c5aa9bda 100644 --- a/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php +++ b/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php @@ -1,7 +1,7 @@ - * @copyright 2010 StatusNet, Inc. + * @copyright 2011 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ @@ -42,7 +42,7 @@ if (!defined('STATUSNET')) { * @category Privacy * @package StatusNet * @author Evan Prodromou - * @copyright 2010 StatusNet, Inc. + * @copyright 2011 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ @@ -207,8 +207,8 @@ class GroupPrivateMessagePlugin extends Plugin $action->menuItem(common_local_url('groupinbox', array('nickname' => $group->nickname)), - _m('Inbox'), - _m('Private messages for this group'), + _m('MENU','Inbox'), + _m('Private messages for this group.'), $action->trimmed('action') == 'groupinbox', 'nav_group_inbox'); return true; @@ -255,21 +255,21 @@ class GroupPrivateMessagePlugin extends Plugin $form->out->elementStart('li'); $form->out->dropdown('allow_privacy', - _('Private messages'), - array(Group_privacy_settings::SOMETIMES => _('Sometimes'), - Group_privacy_settings::ALWAYS => _('Always'), - Group_privacy_settings::NEVER => _('Never')), - _('Whether to allow private messages to this group'), + _m('Private messages'), + array(Group_privacy_settings::SOMETIMES => _m('Sometimes'), + Group_privacy_settings::ALWAYS => _m('Always'), + Group_privacy_settings::NEVER => _m('Never')), + _m('Whether to allow private messages to this group.'), false, (empty($gps)) ? Group_privacy_settings::SOMETIMES : $gps->allow_privacy); $form->out->elementEnd('li'); $form->out->elementStart('li'); $form->out->dropdown('allow_sender', - _('Private sender'), - array(Group_privacy_settings::EVERYONE => _('Everyone'), - Group_privacy_settings::MEMBER => _('Member'), - Group_privacy_settings::ADMIN => _('Admin')), - _('Who can send private messages to the group'), + _m('Private senders'), + array(Group_privacy_settings::EVERYONE => _m('Everyone'), + Group_privacy_settings::MEMBER => _m('Member'), + Group_privacy_settings::ADMIN => _m('Admin')), + _m('Who can send private messages to the group.'), false, (empty($gps)) ? Group_privacy_settings::MEMBER : $gps->allow_sender); $form->out->elementEnd('li'); @@ -348,14 +348,15 @@ class GroupPrivateMessagePlugin extends Plugin /** * To add a "Message" button to the group profile page * - * @param Action $action The showgroup action being shown + * @param Widget $widget The showgroup action being shown * @param User_group $group The current group * * @return boolean hook value */ - function onEndGroupActionsList($action, $group) + function onEndGroupActionsList($widget, $group) { $cur = common_current_user(); + $action = $widget->out; if (empty($cur)) { return true; @@ -369,15 +370,130 @@ class GroupPrivateMessagePlugin extends Plugin $action->elementStart('li', 'entity_send-a-message'); $action->element('a', array('href' => common_local_url('newgroupmessage', array('nickname' => $group->nickname)), - 'title' => _('Send a direct message to this group')), - _('Message')); + 'title' => _m('Send a direct message to this group.')), + _m('Message')); // $form = new GroupMessageForm($action, $group); // $form->hidden = true; // $form->show(); $action->elementEnd('li'); return true; } - + + /** + * When saving a notice, check its groups. If any of them has + * privacy == always, force a group private message to all mentioned groups. + * If any of the groups disallows private messages, skip it. + * + * @param + * + */ + + function onStartNoticeSave(&$notice) { + + // Look for group tags + // FIXME: won't work for remote groups + // @fixme if Notice::saveNew is refactored so we can just pull its list + // of groups between processing and saving, make use of it + + $count = preg_match_all('/(?:^|\s)!(' . Nickname::DISPLAY_FMT . ')/', + strtolower($notice->content), + $match); + + $groups = array(); + $ignored = array(); + + $forcePrivate = false; + $profile = $notice->getProfile(); + + if ($count > 0) { + + /* Add them to the database */ + + foreach (array_unique($match[1]) as $nickname) { + + $group = User_group::getForNickname($nickname, $profile); + + if (empty($group)) { + continue; + } + + $gps = Group_privacy_settings::forGroup($group); + + switch ($gps->allow_privacy) { + case Group_privacy_settings::ALWAYS: + $forcePrivate = true; + // fall through + case Group_privacy_settings::SOMETIMES: + $groups[] = $group; + break; + case Group_privacy_settings::NEVER: + $ignored[] = $group; + break; + } + } + + if ($forcePrivate) { + + foreach ($ignored as $group) { + common_log(LOG_NOTICE, + "Notice forced to group direct message ". + "but group ".$group->nickname." does not allow them."); + } + + $user = User::staticGet('id', $notice->profile_id); + + if (empty($user)) { + common_log(LOG_WARNING, + "Notice forced to group direct message ". + "but profile ".$notice->profile_id." is not a local user."); + } else { + foreach ($groups as $group) { + Group_message::send($user, $group, $notice->content); + } + } + + // Don't save the notice! + // FIXME: this is probably cheating. + throw new ClientException(sprintf(_m('Forced notice to private group message.')), + 200); + } + } + + return true; + } + + /** + * Show an indicator that the group is (essentially) private on the group page + * + * @param Action $action The action being shown + * @param User_group $group The group being shown + * + * @return boolean hook value + */ + + function onEndGroupProfileElements($action, $group) + { + $gps = Group_privacy_settings::forGroup($group); + + if ($gps->allow_privacy == Group_privacy_settings::ALWAYS) { + $action->element('p', 'privategroupindicator', _m('Private')); + } + + return true; + } + + function onStartShowExportData($action) + { + if ($action instanceof ShowgroupAction) { + $gps = Group_privacy_settings::forGroup($action->group); + + if ($gps->allow_privacy == Group_privacy_settings::ALWAYS) { + return false; + } + } + return true; + } + function onPluginVersion(&$versions) { $versions[] = array('name' => 'GroupPrivateMessage', @@ -385,7 +501,7 @@ class GroupPrivateMessagePlugin extends Plugin 'author' => 'Evan Prodromou', 'homepage' => 'http://status.net/wiki/Plugin:GroupPrivateMessage', 'rawdescription' => - _m('Allow posting DMs to a group.')); + _m('Allow posting private messages to groups.')); return true; } }