| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * StatusNet - the distributed open-source microblogging tool | 
					
						
							| 
									
										
										
										
											2011-02-07 12:28:58 -05:00
										 |  |  |  * Copyright (C) 2011, StatusNet, Inc. | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Private groups for StatusNet 0.9.x | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * PHP version 5 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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/>. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category  Privacy | 
					
						
							|  |  |  |  * @package   StatusNet | 
					
						
							|  |  |  |  * @author    Evan Prodromou <evan@status.net> | 
					
						
							| 
									
										
										
										
											2011-02-07 12:28:58 -05:00
										 |  |  |  * @copyright 2011 StatusNet, Inc. | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 | 
					
						
							|  |  |  |  * @link      http://status.net/ | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if (!defined('STATUSNET')) { | 
					
						
							|  |  |  |     // This check helps protect against security problems;
 | 
					
						
							|  |  |  |     // your code file can't be executed directly from the web.
 | 
					
						
							|  |  |  |     exit(1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Private groups | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This plugin allows users to send private messages to a group. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category  Privacy | 
					
						
							|  |  |  |  * @package   StatusNet | 
					
						
							|  |  |  |  * @author    Evan Prodromou <evan@status.net> | 
					
						
							| 
									
										
										
										
											2011-02-07 12:28:58 -05:00
										 |  |  |  * @copyright 2011 StatusNet, Inc. | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 | 
					
						
							|  |  |  |  * @link      http://status.net/ | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-02-07 11:57:34 -05:00
										 |  |  | class GroupPrivateMessagePlugin extends Plugin | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Database schema setup | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @see Schema | 
					
						
							|  |  |  |      * @see ColumnDef | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return boolean hook value | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function onCheckSchema() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $schema = Schema::get(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // For storing user-submitted flags on profiles
 | 
					
						
							| 
									
										
										
										
											2013-08-19 17:08:18 +02:00
										 |  |  |         $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()); | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Map URLs to actions | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-11-07 15:24:05 +01:00
										 |  |  |      * @param URLMapper $m path-to-action mapper | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return boolean hook value | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-11-07 15:24:05 +01:00
										 |  |  |     public function onRouterInitialized(URLMapper $m) | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         $m->connect('group/:nickname/inbox', | 
					
						
							|  |  |  |                     array('action' => 'groupinbox'), | 
					
						
							|  |  |  |                     array('nickname' => Nickname::DISPLAY_FMT)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-04 15:51:59 -05:00
										 |  |  |         $m->connect('group/message/:id', | 
					
						
							|  |  |  |                     array('action' => 'showgroupmessage'), | 
					
						
							|  |  |  |                     array('id' => '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-07 11:24:00 -05:00
										 |  |  |         $m->connect('group/:nickname/message/new', | 
					
						
							|  |  |  |                     array('action' => 'newgroupmessage'), | 
					
						
							|  |  |  |                     array('nickname' => Nickname::DISPLAY_FMT)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Add group inbox to the menu | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Action $action The current action handler. Use this to | 
					
						
							|  |  |  |      *                       do any output. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return boolean hook value; true means continue processing, false means stop. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @see Action | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-09-12 21:13:01 +02:00
										 |  |  |     function onEndGroupGroupNav(Menu $groupnav) | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         $action = $groupnav->action; | 
					
						
							|  |  |  |         $group  = $groupnav->group; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $action->menuItem(common_local_url('groupinbox', | 
					
						
							|  |  |  |                                            array('nickname' => $group->nickname)), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                           // TRANS: Menu item in group page.
 | 
					
						
							| 
									
										
										
										
											2011-04-01 22:20:25 +02:00
										 |  |  |                           _m('MENU','Inbox'), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                           // TRANS: Menu title in group page.
 | 
					
						
							| 
									
										
										
										
											2011-04-01 22:20:25 +02:00
										 |  |  |                           _m('Private messages for this group.'), | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |                           $action->trimmed('action') == 'groupinbox', | 
					
						
							|  |  |  |                           'nav_group_inbox'); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-26 18:48:13 -07:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Create default group privacy settings at group create time | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-02-03 15:28:41 -05:00
										 |  |  |      * @param User_group $group Group that was just created | 
					
						
							| 
									
										
										
										
											2011-01-26 18:48:13 -07:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @result boolean hook value | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function onEndGroupSave($group) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $gps = new Group_privacy_settings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $gps->group_id      = $group->id; | 
					
						
							|  |  |  |         $gps->allow_privacy = Group_privacy_settings::SOMETIMES; | 
					
						
							|  |  |  |         $gps->allow_sender  = Group_privacy_settings::MEMBER; | 
					
						
							|  |  |  |         $gps->created       = common_sql_now(); | 
					
						
							|  |  |  |         $gps->modified      = $gps->created; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // This will throw an exception on error
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $gps->insert(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-03 15:28:41 -05:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Show group privacy controls on group edit form | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |      * @param GroupEditForm $form form being shown | 
					
						
							| 
									
										
										
										
											2011-02-03 15:28:41 -05:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-09-12 21:13:01 +02:00
										 |  |  |     function onEndGroupEditFormData(GroupEditForm $form) | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         $gps = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($form->group)) { | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |             $gps = Group_privacy_settings::getKV('group_id', $form->group->id); | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $form->out->elementStart('li'); | 
					
						
							|  |  |  |         $form->out->dropdown('allow_privacy', | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                              // TRANS: Dropdown label in group settings page for if group allows private messages.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 22:30:23 +02:00
										 |  |  |                              _m('Private messages'), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                              // TRANS: Dropdown option in group settings page for allowing private messages.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 22:30:23 +02:00
										 |  |  |                              array(Group_privacy_settings::SOMETIMES => _m('Sometimes'), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                                    // TRANS: Dropdown option in group settings page for allowing private messages.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 22:30:23 +02:00
										 |  |  |                                    Group_privacy_settings::ALWAYS => _m('Always'), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                                    // TRANS: Dropdown option in group settings page for allowing private messages.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 22:30:23 +02:00
										 |  |  |                                    Group_privacy_settings::NEVER => _m('Never')), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                              // TRANS: Dropdown title in group settings page for if group allows private messages.
 | 
					
						
							| 
									
										
										
										
											2011-04-01 22:20:25 +02:00
										 |  |  |                              _m('Whether to allow private messages to this group.'), | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |                              false, | 
					
						
							|  |  |  |                              (empty($gps)) ? Group_privacy_settings::SOMETIMES : $gps->allow_privacy); | 
					
						
							|  |  |  |         $form->out->elementEnd('li'); | 
					
						
							|  |  |  |         $form->out->elementStart('li'); | 
					
						
							|  |  |  |         $form->out->dropdown('allow_sender', | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                              // TRANS: Dropdown label in group settings page for who can send private messages to the group.
 | 
					
						
							| 
									
										
										
										
											2011-04-01 22:20:25 +02:00
										 |  |  |                              _m('Private senders'), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                              // TRANS: Dropdown option in group settings page for who can send private messages.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 22:30:23 +02:00
										 |  |  |                              array(Group_privacy_settings::EVERYONE => _m('Everyone'), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                                    // TRANS: Dropdown option in group settings page for who can send private messages.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 22:30:23 +02:00
										 |  |  |                                    Group_privacy_settings::MEMBER => _m('Member'), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                                    // TRANS: Dropdown option in group settings page for who can send private messages.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 22:30:23 +02:00
										 |  |  |                                    Group_privacy_settings::ADMIN => _m('Admin')), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                              // TRANS: Dropdown title in group settings page for who can send private messages to the group.
 | 
					
						
							| 
									
										
										
										
											2011-04-01 22:20:25 +02:00
										 |  |  |                              _m('Who can send private messages to the group.'), | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |                              false, | 
					
						
							|  |  |  |                              (empty($gps)) ? Group_privacy_settings::MEMBER : $gps->allow_sender); | 
					
						
							|  |  |  |         $form->out->elementEnd('li'); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-12 22:38:17 +02:00
										 |  |  |     function onEndGroupSaveForm(Action $action) | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-09-12 22:38:17 +02:00
										 |  |  |         // The Action class must contain this method
 | 
					
						
							| 
									
										
										
										
											2014-09-12 22:40:12 +02:00
										 |  |  |         assert(is_callable(array($action, 'getGroup'))); | 
					
						
							| 
									
										
										
										
											2014-09-12 22:38:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |         $gps = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-25 14:29:27 +02:00
										 |  |  |         if ($action->getGroup() instanceof User_group) { | 
					
						
							| 
									
										
										
										
											2014-09-12 21:13:01 +02:00
										 |  |  |             $gps = Group_privacy_settings::getKV('group_id', $action->getGroup()->id); | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $orig = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($gps)) { | 
					
						
							|  |  |  |             $gps = new Group_privacy_settings(); | 
					
						
							| 
									
										
										
										
											2014-09-12 21:13:01 +02:00
										 |  |  |             $gps->group_id = $action->getGroup()->id; | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             $orig = clone($gps); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |         $gps->allow_privacy = $action->trimmed('allow_privacy'); | 
					
						
							|  |  |  |         $gps->allow_sender  = $action->trimmed('allow_sender'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($orig)) { | 
					
						
							|  |  |  |             $gps->created = common_sql_now(); | 
					
						
							|  |  |  |             $gps->insert(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $gps->update($orig); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-03 16:39:52 -05:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-04 15:51:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Overload 'd' command to send private messages to groups. | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-02-04 15:51:59 -05:00
										 |  |  |      * 'd !group word word word' will send the private message | 
					
						
							|  |  |  |      * 'word word word' to the group 'group'. | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-02-04 15:51:59 -05:00
										 |  |  |      * @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. | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-02-04 15:51:59 -05:00
										 |  |  |      * @return boolean hook value | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-09-12 21:13:01 +02:00
										 |  |  |     function onStartInterpretCommand($cmd, $arg, User $user, &$result) | 
					
						
							| 
									
										
										
										
											2011-02-04 15:51:59 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         if ($cmd == 'd' || $cmd == 'dm') { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $this->debug('Got a d command'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // Break off the first word as the address
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $pieces = explode(' ', $arg, 2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (count($pieces) == 1) { | 
					
						
							|  |  |  |                 $pieces[] = null; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             list($addr, $msg) = $pieces; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (!empty($addr) && $addr[0] == '!') { | 
					
						
							|  |  |  |                 $result = new GroupMessageCommand($user, substr($addr, 1), $msg); | 
					
						
							|  |  |  |                 Event::handle('EndInterpretCommand', array($cmd, $arg, $user, $result)); | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-07 11:51:38 -05:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * To add a "Message" button to the group profile page | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-03-18 15:00:02 -07:00
										 |  |  |      * @param Widget     $widget The showgroup action being shown | 
					
						
							| 
									
										
										
										
											2011-02-07 11:51:38 -05:00
										 |  |  |      * @param User_group $group  The current group | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-02-07 11:51:38 -05:00
										 |  |  |      * @return boolean hook value | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-09-12 21:13:01 +02:00
										 |  |  |     function onEndGroupActionsList(Widget $widget, User_group $group) | 
					
						
							| 
									
										
										
										
											2011-02-07 11:51:38 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         $cur = common_current_user(); | 
					
						
							| 
									
										
										
										
											2011-03-18 15:00:02 -07:00
										 |  |  |         $action = $widget->out; | 
					
						
							| 
									
										
										
										
											2011-02-07 11:51:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (empty($cur)) { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             Group_privacy_settings::ensurePost($cur, $group); | 
					
						
							|  |  |  |         } catch (Exception $e) { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $action->elementStart('li', 'entity_send-a-message'); | 
					
						
							|  |  |  |         $action->element('a', array('href' => common_local_url('newgroupmessage', array('nickname' => $group->nickname)), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                                     // TRANS: Title for action in group actions list.
 | 
					
						
							| 
									
										
										
										
											2011-04-01 22:20:25 +02:00
										 |  |  |                                     'title' => _m('Send a direct message to this group.')), | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                          // TRANS: Link text for action in group actions list to send a private message to a group.
 | 
					
						
							|  |  |  |                          _m('LINKTEXT','Message')); | 
					
						
							| 
									
										
										
										
											2011-02-07 11:51:38 -05:00
										 |  |  |         // $form = new GroupMessageForm($action, $group);
 | 
					
						
							|  |  |  |         // $form->hidden = true;
 | 
					
						
							|  |  |  |         // $form->show();
 | 
					
						
							|  |  |  |         $action->elementEnd('li'); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-07 12:58:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 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. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |      * @param | 
					
						
							| 
									
										
										
										
											2011-02-07 12:58:42 -05:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-09-12 21:13:01 +02:00
										 |  |  |     function onStartNoticeSave(Notice &$notice) { | 
					
						
							| 
									
										
										
										
											2011-02-07 12:58:42 -05:00
										 |  |  |         // Look for group tags
 | 
					
						
							|  |  |  |         // FIXME: won't work for remote groups
 | 
					
						
							| 
									
										
										
										
											2011-02-07 12:18:41 -08:00
										 |  |  |         // @fixme if Notice::saveNew is refactored so we can just pull its list
 | 
					
						
							|  |  |  |         // of groups between processing and saving, make use of it
 | 
					
						
							| 
									
										
										
										
											2011-02-07 12:58:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-07 12:18:41 -08:00
										 |  |  |         $count = preg_match_all('/(?:^|\s)!(' . Nickname::DISPLAY_FMT . ')/', | 
					
						
							| 
									
										
										
										
											2011-02-07 12:58:42 -05:00
										 |  |  |                                 strtolower($notice->content), | 
					
						
							|  |  |  |                                 $match); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $groups = array(); | 
					
						
							|  |  |  |         $ignored = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $forcePrivate = false; | 
					
						
							| 
									
										
										
										
											2011-03-18 15:00:02 -07:00
										 |  |  |         $profile = $notice->getProfile(); | 
					
						
							| 
									
										
										
										
											2011-02-07 12:58:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         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."); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |                 $user = User::getKV('id', $notice->profile_id); | 
					
						
							| 
									
										
										
										
											2011-02-07 12:58:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 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.
 | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                 // TRANS: Client exception thrown when a private group message has to be forced.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 22:30:23 +02:00
										 |  |  |                 throw new ClientException(sprintf(_m('Forced notice to private group message.')), | 
					
						
							| 
									
										
										
										
											2011-02-07 12:58:42 -05:00
										 |  |  |                                           200); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-07 12:58:42 -05:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-07 14:21:54 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 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 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-09-12 21:13:01 +02:00
										 |  |  |     function onEndGroupProfileElements(Action $action, User_group $group) | 
					
						
							| 
									
										
										
										
											2011-02-07 14:21:54 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         $gps = Group_privacy_settings::forGroup($group); | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-07 14:21:54 -05:00
										 |  |  |         if ($gps->allow_privacy == Group_privacy_settings::ALWAYS) { | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |             // TRANS: Indicator on the group page that the group is (essentially) private.
 | 
					
						
							| 
									
										
										
										
											2011-03-30 22:30:23 +02:00
										 |  |  |             $action->element('p', 'privategroupindicator', _m('Private')); | 
					
						
							| 
									
										
										
										
											2011-02-07 14:21:54 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-12 22:38:17 +02:00
										 |  |  |     function onStartShowExportData(Action $action) | 
					
						
							| 
									
										
										
										
											2011-02-07 14:24:35 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         if ($action instanceof ShowgroupAction) { | 
					
						
							| 
									
										
										
										
											2014-09-12 21:13:01 +02:00
										 |  |  |             $gps = Group_privacy_settings::forGroup($action->getGroup()); | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-07 14:24:35 -05:00
										 |  |  |             if ($gps->allow_privacy == Group_privacy_settings::ALWAYS) { | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-06 22:04:01 +02:00
										 |  |  |     function onPluginVersion(array &$versions) | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-02-07 11:57:34 -05:00
										 |  |  |         $versions[] = array('name' => 'GroupPrivateMessage', | 
					
						
							| 
									
										
										
										
											2013-11-01 13:51:41 +01:00
										 |  |  |                             'version' => GNUSOCIAL_VERSION, | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |                             'author' => 'Evan Prodromou', | 
					
						
							| 
									
										
										
										
											2011-02-07 11:57:34 -05:00
										 |  |  |                             'homepage' => 'http://status.net/wiki/Plugin:GroupPrivateMessage', | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |                             'rawdescription' => | 
					
						
							| 
									
										
										
										
											2011-04-08 18:46:41 +02:00
										 |  |  |                             // TRANS: Plugin description.
 | 
					
						
							| 
									
										
										
										
											2011-04-01 22:20:25 +02:00
										 |  |  |                             _m('Allow posting private messages to groups.')); | 
					
						
							| 
									
										
										
										
											2011-01-18 16:55:51 -05:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |