3 * GNU Social - a federating social network
4 * Copyright (C) 2014, Free Software Foundation, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('GNUSOCIAL')) { exit(1); }
23 * @maintainer Mikael Nordfeldth <mmn@hethane.se>
25 class DirectMessagePlugin extends Plugin
27 public function onCheckSchema()
29 $schema = Schema::get();
30 $schema->ensureTable('message', Message::schemaDef());
34 public function onRouterInitialized(URLMapper $m)
36 // web front-end actions
37 $m->connect('message/new', array('action' => 'newmessage'));
38 $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => Nickname::DISPLAY_FMT));
39 $m->connect('message/:message',
40 array('action' => 'showmessage'),
41 array('message' => '[0-9]+'));
44 $m->connect('api/direct_messages.:format',
45 array('action' => 'ApiDirectMessage',
46 'format' => '(xml|json|rss|atom)'));
47 $m->connect('api/direct_messages/sent.:format',
48 array('action' => 'ApiDirectMessage',
49 'format' => '(xml|json|rss|atom)',
51 $m->connect('api/direct_messages/new.:format',
52 array('action' => 'ApiDirectMessageNew',
53 'format' => '(xml|json)'));
58 public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
60 if ($scoped instanceof Profile && $scoped->id == $target->id
61 && !common_config('singleuser', 'enabled')) {
63 $menu->out->menuItem(common_local_url('inbox', array('nickname' =>
64 $target->getNickname())),
65 // TRANS: Menu item in personal group navigation menu.
66 _m('MENU','Messages'),
67 // TRANS: Menu item title in personal group navigation menu.
68 _('Your incoming messages'),
69 $scoped->id === $target->id && $menu->actionName =='inbox');
73 public function onEndProfilePageActionsElements(HTMLOutputter $out, Profile $profile)
75 $scoped = Profile::current();
76 if (!$scoped instanceof Profile) {
80 if ($profile->isLocal() && $scoped->mutuallySubscribed($profile)) {
81 $out->elementStart('li', 'entity_send-a-message');
82 $out->element('a', array('href' => common_local_url('newmessage', array('to' => $profile->id)),
83 // TRANS: Link title for link on user profile.
84 'title' => _('Send a direct message to this user.')),
85 // TRANS: Link text for link on user profile.
86 _m('BUTTON','Message'));
87 $out->elementEnd('li');
92 public function onProfileDeleteRelated(Profile $profile, &$related)
95 $msg->from_profile = $profile->id;
99 $msg->to_profile = $profile->id;
104 public function onPluginVersion(array &$versions)
106 $versions[] = array('name' => 'Direct Message',
107 'version' => GNUSOCIAL_VERSION,
108 'author' => 'Mikael Nordfeldth',
109 'homepage' => 'http://gnu.io/',
111 // TRANS: Plugin description.
112 _m('Direct Message to other local users (broken out of core).'));