]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/UserFlagPlugin.php
Merge branch 'master' of git@gitorious.org:statusnet/mainline
[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 profiles
51
52         $schema->ensureTable('user_flag_profile',
53                              array(new ColumnDef('profile_id', 'integer', null,
54                                                  false, 'PRI'),
55                                    new ColumnDef('user_id', 'integer', null,
56                                                  false, 'PRI'),
57                                    new ColumnDef('created', 'datetime', null,
58                                                  false, 'MUL'),
59                                    new ColumnDef('cleared', 'datetime', null,
60                                                  true, 'MUL')));
61
62         return true;
63     }
64
65     function onInitializePlugin()
66     {
67         // XXX: do something here?
68         return true;
69     }
70
71     function onRouterInitialized(&$m) {
72         $m->connect('main/flag/profile', array('action' => 'flagprofile'));
73         $m->connect('admin/profile/flag', array('action' => 'adminprofileflag'));
74         return true;
75     }
76
77    function onAutoload($cls)
78     {
79         switch ($cls)
80         {
81         case 'FlagprofileAction':
82         case 'AdminprofileflagAction':
83             require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
84             return false;
85         case 'FlagProfileForm':
86             require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower($cls . '.php'));
87             return false;
88         case 'User_flag_profile':
89             require_once(INSTALLDIR.'/plugins/UserFlag/'.$cls.'.php');
90             return false;
91         default:
92             return true;
93         }
94     }
95
96     function onEndProfilePageActionsElements(&$action, $profile)
97     {
98         $user = common_current_user();
99
100         if (!empty($user) && ($user->id != $profile->id)) {
101
102             $action->elementStart('li', 'entity_flag');
103
104             if (User_flag_profile::exists($profile->id, $user->id)) {
105                 $action->element('p', 'flagged', _('Flagged'));
106             } else {
107                 $form = new FlagProfileForm($action, $profile,
108                                         array('action' => 'showstream',
109                                               'nickname' => $profile->nickname));
110                 $form->show();
111             }
112
113             $action->elementEnd('li');
114         }
115
116         return true;
117     }
118
119     function onEndProfileListItemActionElements($item)
120     {
121         $user = common_current_user();
122
123         if (!empty($user)) {
124
125             list($action, $args) = $item->action->returnToArgs();
126
127             $args['action'] = $action;
128
129             $form = new FlagProfileForm($item->action, $item->profile, $args);
130
131             $item->action->elementStart('li', 'entity_flag');
132             $form->show();
133             $item->action->elementEnd('li');
134         }
135
136         return true;
137     }
138
139     function onEndShowStatusNetStyles($action)
140     {
141         $action->elementStart('style', array('type' => 'text/css'));
142         $action->raw('.entity_flag input, .entity_flag p {'.
143             ' background:url('.common_path('plugins/UserFlag/flag.gif').') 5px 5px no-repeat;'.
144             ' }');
145         $action->elementEnd('style');
146
147         return true;
148     }
149
150     function onEndShowScripts($action)
151     {
152         $action->elementStart('script', array('type' => 'text/javascript'));
153         $action->raw('/*<![CDATA[*/ SN.U.FormXHR($(".form_entity_flag")); /*]]>*/');
154         $action->elementEnd('script');
155         return true;
156     }
157 }