]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/UserFlagPlugin.php
insert profile flags more or less correctly
[quix0rs-gnu-social.git] / plugins / UserFlag / UserFlagPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Allows users to flag content and accounts as offensive/spam/whatever
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Plugin
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Allows users to flag content and accounts as offensive/spam/whatever
36  *
37  * @category Plugin
38  * @package  StatusNet
39  * @author   Evan Prodromou <evan@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43
44 class UserFlagPlugin extends Plugin
45 {
46     function onCheckSchema()
47     {
48         $schema = Schema::get();
49
50         // For storing user-submitted flags on notices
51
52         $schema->ensureTable('user_flag_notice',
53                              array(new ColumnDef('notice_id', 'integer', null, null, 'PRI'),
54                                    new ColumnDef('user_id', 'integer', null, null, 'PRI'),
55                                    new ColumnDef('flag', 'varchar', '8'),
56                                    new ColumnDef('created', 'datetime', null,
57                                                  null, 'MUL')));
58
59         // Allowable values for user_flag_notice
60
61         $schema->ensureTable('notice_flag',
62                              array(new ColumnDef('flag', 'varchar', '8', null, 'PRI'),
63                                    new ColumnDef('display', 'varchar', '255'),
64                                    new ColumnDef('created', 'datetime', null, null, 'MUL')));
65
66         // For storing user-submitted flags on profiles
67
68         $schema->ensureTable('user_flag_profile',
69                              array(new ColumnDef('profile_id', 'integer', null,
70                                                  null, 'PRI'),
71                                    new ColumnDef('user_id', 'integer', null,
72                                                  null, 'PRI'),
73                                    new ColumnDef('flag', 'varchar', '8'),
74                                    new ColumnDef('created', 'datetime', null,
75                                                  null, 'MUL')));
76
77         // Allowable values for user_flag_notice
78
79         $schema->ensureTable('profile_flag',
80                              array(new ColumnDef('flag', 'varchar', '8', null, 'PRI'),
81                                    new ColumnDef('display', 'varchar', '255'),
82                                    new ColumnDef('created', 'datetime', null,
83                                                  null, 'MUL')));
84         return true;
85     }
86
87     function onInitializePlugin()
88     {
89         // XXX: do something here?
90         return true;
91     }
92
93     function onRouterInitialized(&$m) {
94         $m->connect('main/flag/notice', array('action' => 'flagnotice'));
95         $m->connect('main/flag/profile', array('action' => 'flagprofile'));
96         $m->connect('admin/notice/flag', array('action' => 'adminnoticeflag'));
97         $m->connect('admin/profile/flag', array('action' => 'adminprofileflag'));
98         return true;
99     }
100
101    function onAutoload($cls)
102     {
103         switch ($cls)
104         {
105         case 'FlagnoticeAction':
106         case 'FlagprofileAction':
107         case 'AdminnoticeflagAction':
108         case 'AdminprofileflagAction':
109             require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
110             return false;
111         case 'FlagProfileForm':
112             require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower($cls . '.php'));
113             return false;
114         case 'User_flag_notice':
115         case 'Notice_flag':
116         case 'User_flag_profile':
117         case 'Profile_flag':
118             require_once(INSTALLDIR.'/plugins/UserFlag/'.$cls.'.php');
119             return false;
120         default:
121             return true;
122         }
123     }
124
125     function onEndProfilePageActionsElements(&$action, $profile)
126     {
127         $user = common_current_user();
128
129         if (!empty($user)) {
130
131             $action->elementStart('li', 'entity_flag');
132
133             if (User_flag_profile::exists($profile->id, $user->id,
134                                           Profile_flag::DEFAULTFLAG)) {
135                 $action->element('span',
136                                  _('Flagged for review'));
137             } else {
138                 $form = new FlagProfileForm($action, $profile,
139                                         array('action' => 'showstream',
140                                               'nickname' => $profile->nickname));
141                 $form->show();
142             }
143
144             $action->elementEnd('li');
145         }
146
147         return true;
148     }
149
150     function onEndProfileListItemActionElements($item)
151     {
152         $user = common_current_user();
153
154         if (!empty($user)) {
155
156             $form = new FlagProfileForm($item->action, $item->profile);
157
158             $form->show();
159         }
160
161         return true;
162     }
163 }