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