X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FGroupPrivateMessage%2FGroupPrivateMessagePlugin.php;h=0f5c1a88309a35d1f0f02bf8e6b9b5956750ea4b;hb=d6b28c64830f632bb2f4b6f3c9369b9e56ad217a;hp=29e57c1aaed2d1a40ca6ffdf5efb0689bed5d7d4;hpb=1e73ba00bdd37f46415eb45b1b904dc894fb801c;p=quix0rs-gnu-social.git diff --git a/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php b/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php index 29e57c1aae..0f5c1a8830 100644 --- a/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php +++ b/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php @@ -46,7 +46,6 @@ if (!defined('STATUSNET')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ - class GroupPrivateMessagePlugin extends Plugin { /** @@ -57,122 +56,25 @@ class GroupPrivateMessagePlugin extends Plugin * * @return boolean hook value */ - function onCheckSchema() { $schema = Schema::get(); // For storing user-submitted flags on profiles - - $schema->ensureTable('group_privacy_settings', - array(new ColumnDef('group_id', - 'integer', - null, - false, - 'PRI'), - new ColumnDef('allow_privacy', - 'integer'), - new ColumnDef('allow_sender', - 'integer'), - new ColumnDef('created', - 'datetime'), - new ColumnDef('modified', - 'timestamp'))); - - $schema->ensureTable('group_message', - array(new ColumnDef('id', - 'char', - 36, - false, - 'PRI'), - new ColumnDef('uri', - 'varchar', - 255, - false, - 'UNI'), - new ColumnDef('from_profile', - 'integer', - null, - false, - 'MUL'), - new ColumnDef('to_group', - 'integer', - null, - false, - 'MUL'), - new ColumnDef('content', - 'text'), - new ColumnDef('rendered', - 'text'), - new ColumnDef('url', - 'varchar', - 255, - false, - 'UNI'), - new ColumnDef('created', - 'datetime'))); - - $schema->ensureTable('group_message_profile', - array(new ColumnDef('to_profile', - 'integer', - null, - false, - 'PRI'), - new ColumnDef('group_message_id', - 'char', - 36, - false, - 'PRI'), - new ColumnDef('created', - 'datetime'))); - + $schema->ensureTable('group_privacy_settings', Group_privacy_settings::schemaDef()); + $schema->ensureTable('group_message', Group_message::schemaDef()); + $schema->ensureTable('group_message_profile', Group_message_profile::schemaDef()); return true; } - /** - * Load related modules when needed - * - * @param string $cls Name of the class to be loaded - * - * @return boolean hook value - */ - - function onAutoload($cls) - { - $dir = dirname(__FILE__); - - switch ($cls) - { - case 'GroupinboxAction': - case 'ShowgroupmessageAction': - case 'NewgroupmessageAction': - include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php'; - return false; - case 'Group_privacy_settings': - case 'Group_message': - case 'Group_message_profile': - include_once $dir . '/'.$cls.'.php'; - return false; - case 'GroupMessageCommand': - case 'GroupMessageList': - case 'GroupMessageListItem': - case 'GroupMessageForm': - include_once $dir . '/'.strtolower($cls).'.php'; - return false; - default: - return true; - } - } - /** * Map URLs to actions * - * @param Net_URL_Mapper $m path-to-action mapper + * @param URLMapper $m path-to-action mapper * * @return boolean hook value */ - - function onRouterInitialized($m) + public function onRouterInitialized(URLMapper $m) { $m->connect('group/:nickname/inbox', array('action' => 'groupinbox'), @@ -199,16 +101,17 @@ class GroupPrivateMessagePlugin extends Plugin * * @see Action */ - - function onEndGroupGroupNav($groupnav) + function onEndGroupGroupNav(Menu $groupnav) { $action = $groupnav->action; $group = $groupnav->group; $action->menuItem(common_local_url('groupinbox', array('nickname' => $group->nickname)), - _m('Inbox'), - _m('Private messages for this group'), + // TRANS: Menu item in group page. + _m('MENU','Inbox'), + // TRANS: Menu title in group page. + _m('Private messages for this group.'), $action->trimmed('action') == 'groupinbox', 'nav_group_inbox'); return true; @@ -221,8 +124,7 @@ class GroupPrivateMessagePlugin extends Plugin * * @result boolean hook value */ - - function onEndGroupSave($group) + function onEndGroupSave(User_group $group) { $gps = new Group_privacy_settings(); @@ -244,55 +146,68 @@ class GroupPrivateMessagePlugin extends Plugin * * @param GroupEditForm $form form being shown */ - - function onEndGroupEditFormData($form) + function onEndGroupEditFormData(GroupEditForm $form) { $gps = null; if (!empty($form->group)) { - $gps = Group_privacy_settings::staticGet('group_id', $form->group->id); + $gps = Group_privacy_settings::getKV('group_id', $form->group->id); } $form->out->elementStart('li'); $form->out->dropdown('allow_privacy', + // TRANS: Dropdown label in group settings page for if group allows private messages. _m('Private messages'), + // TRANS: Dropdown option in group settings page for allowing private messages. array(Group_privacy_settings::SOMETIMES => _m('Sometimes'), + // TRANS: Dropdown option in group settings page for allowing private messages. Group_privacy_settings::ALWAYS => _m('Always'), + // TRANS: Dropdown option in group settings page for allowing private messages. Group_privacy_settings::NEVER => _m('Never')), - _m('Whether to allow private messages to this group'), + // TRANS: Dropdown title in group settings page for if group allows private messages. + _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', - _m('Private sender'), + // TRANS: Dropdown label in group settings page for who can send private messages to the group. + _m('Private senders'), + // TRANS: Dropdown option in group settings page for who can send private messages. array(Group_privacy_settings::EVERYONE => _m('Everyone'), + // TRANS: Dropdown option in group settings page for who can send private messages. Group_privacy_settings::MEMBER => _m('Member'), + // TRANS: Dropdown option in group settings page for who can send private messages. Group_privacy_settings::ADMIN => _m('Admin')), - _m('Who can send private messages to the group'), + // TRANS: Dropdown title in group settings page for who can send private messages to the group. + _m('Who can send private messages to the group.'), false, (empty($gps)) ? Group_privacy_settings::MEMBER : $gps->allow_sender); $form->out->elementEnd('li'); return true; } - function onEndGroupSaveForm($action) + function onEndGroupSaveForm(Action $action) { + // The Action class must contain this method + assert(is_callable(array($action, 'getGroup'))); + $gps = null; + $group = $action->getGroup(); - if (!empty($action->group)) { - $gps = Group_privacy_settings::staticGet('group_id', $action->group->id); + if ($group instanceof User_group) { + $gps = Group_privacy_settings::getKV('group_id', $group->id); } $orig = null; if (empty($gps)) { $gps = new Group_privacy_settings(); - $gps->group_id = $action->group->id; + $gps->group_id = $action->getGroup()->id; } else { $orig = clone($gps); } - + $gps->allow_privacy = $action->trimmed('allow_privacy'); $gps->allow_sender = $action->trimmed('allow_sender'); @@ -302,24 +217,24 @@ class GroupPrivateMessagePlugin extends Plugin } else { $gps->update($orig); } - + return true; } /** * Overload 'd' command to send private messages to groups. - * + * * 'd !group word word word' will send the private message * 'word word word' to the group 'group'. - * + * * @param string $cmd Command being run * @param string $arg Rest of the message (including address) * @param User $user User sending the message * @param Command &$result The resulting command object to be run. - * + * * @return boolean hook value */ - function onStartIntepretCommand($cmd, $arg, $user, &$result) + function onStartInterpretCommand($cmd, $arg, User $user, &$result) { if ($cmd == 'd' || $cmd == 'dm') { @@ -350,10 +265,10 @@ class GroupPrivateMessagePlugin extends Plugin * * @param Widget $widget The showgroup action being shown * @param User_group $group The current group - * + * * @return boolean hook value */ - function onEndGroupActionsList($widget, $group) + function onEndGroupActionsList(Widget $widget, User_group $group) { $cur = common_current_user(); $action = $widget->out; @@ -370,8 +285,10 @@ 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' => _m('Send a direct message to this group')), - _m('Message')); + // TRANS: Title for action in group actions list. + 'title' => _m('Send a direct message to this group.')), + // TRANS: Link text for action in group actions list to send a private message to a group. + _m('LINKTEXT','Message')); // $form = new GroupMessageForm($action, $group); // $form->hidden = true; // $form->show(); @@ -384,12 +301,9 @@ class GroupPrivateMessagePlugin extends Plugin * privacy == always, force a group private message to all mentioned groups. * If any of the groups disallows private messages, skip it. * - * @param - * + * @param */ - - function onStartNoticeSave(&$notice) { - + function onStartNoticeSave(Notice &$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 @@ -406,14 +320,12 @@ class GroupPrivateMessagePlugin extends Plugin $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)) { + if (!$group instanceof User_group) { continue; } @@ -433,14 +345,13 @@ class GroupPrivateMessagePlugin extends Plugin } 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); + $user = User::getKV('id', $notice->profile_id); if (empty($user)) { common_log(LOG_WARNING, @@ -454,11 +365,12 @@ class GroupPrivateMessagePlugin extends Plugin // Don't save the notice! // FIXME: this is probably cheating. + // TRANS: Client exception thrown when a private group message has to be forced. throw new ClientException(sprintf(_m('Forced notice to private group message.')), 200); } } - + return true; } @@ -470,23 +382,23 @@ class GroupPrivateMessagePlugin extends Plugin * * @return boolean hook value */ - - function onEndGroupProfileElements($action, $group) + function onEndGroupProfileElements(Action $action, User_group $group) { $gps = Group_privacy_settings::forGroup($group); - + if ($gps->allow_privacy == Group_privacy_settings::ALWAYS) { + // TRANS: Indicator on the group page that the group is (essentially) private. $action->element('p', 'privategroupindicator', _m('Private')); } return true; } - function onStartShowExportData($action) + function onStartShowExportData(Action $action) { if ($action instanceof ShowgroupAction) { - $gps = Group_privacy_settings::forGroup($action->group); - + $gps = Group_privacy_settings::forGroup($action->getGroup()); + if ($gps->allow_privacy == Group_privacy_settings::ALWAYS) { return false; } @@ -494,14 +406,15 @@ class GroupPrivateMessagePlugin extends Plugin return true; } - function onPluginVersion(&$versions) + function onPluginVersion(array &$versions) { $versions[] = array('name' => 'GroupPrivateMessage', - 'version' => STATUSNET_VERSION, + 'version' => GNUSOCIAL_VERSION, 'author' => 'Evan Prodromou', 'homepage' => 'http://status.net/wiki/Plugin:GroupPrivateMessage', 'rawdescription' => - _m('Allow posting DMs to a group.')); + // TRANS: Plugin description. + _m('Allow posting private messages to groups.')); return true; } }