]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/DirectMessage/DirectMessagePlugin.php
DirectMessage moved into a plugin, not done yet
[quix0rs-gnu-social.git] / plugins / DirectMessage / DirectMessagePlugin.php
1 <?php
2 /*
3  * GNU Social - a federating social network
4  * Copyright (C) 2014, Free Software Foundation, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('GNUSOCIAL')) { exit(1); }
21
22 /**
23  * @maintainer  Mikael Nordfeldth <mmn@hethane.se>
24  */
25 class DirectMessagePlugin extends Plugin
26 {
27     public function onCheckSchema()
28     {
29         $schema = Schema::get();
30         $schema->ensureTable('message', Message::schemaDef());
31         return true;
32     }
33
34     public function onRouterInitialized(URLMapper $m)
35     {
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]+'));
42
43         // direct messages
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)',
50                           'sent' => true));
51         $m->connect('api/direct_messages/new.:format',
52                     array('action' => 'ApiDirectMessageNew',
53                           'format' => '(xml|json)'));
54
55         return true;
56     }
57
58     public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
59     {
60         if ($scoped instanceof Profile && $scoped->id == $target->id
61                 && !common_config('singleuser', 'enabled')) {
62
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');
70         }
71     }
72
73     public function onEndProfilePageActionsElements(HTMLOutputter $out, Profile $profile)
74     {
75         $scoped = Profile::current();
76         if (!$scoped instanceof Profile) {
77             return true;
78         }
79
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');
88         }
89         return true;
90     }
91
92     public function onProfileDeleteRelated(Profile $profile, &$related)
93     {
94         $msg = new Message();
95         $msg->from_profile = $profile->id;
96         $msg->delete();
97
98         $msg = new Message();
99         $msg->to_profile = $profile->id;
100         $msg->delete();
101         return true;
102     }
103
104     public function onPluginVersion(array &$versions)
105     {
106         $versions[] = array('name' => 'Direct Message',
107                             'version' => GNUSOCIAL_VERSION,
108                             'author' => 'Mikael Nordfeldth',
109                             'homepage' => 'http://gnu.io/',
110                             'rawdescription' =>
111                             // TRANS: Plugin description.
112                             _m('Direct Message to other local users (broken out of core).'));
113
114         return true;
115     }
116 }