3 * StatusNet, the distributed open-source microblogging tool
5 * Allows users to flag content and accounts as offensive/spam/whatever
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.
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.
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/>.
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/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 * Allows users to flag content and accounts as offensive/spam/whatever
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/
44 class UserFlagPlugin extends Plugin
46 function onCheckSchema()
48 $schema = Schema::get();
50 // For storing user-submitted flags on notices
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,
59 // Allowable values for user_flag_notice
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')));
66 // For storing user-submitted flags on profiles
68 $schema->ensureTable('user_flag_profile',
69 array(new ColumnDef('profile_id', 'integer', null,
71 new ColumnDef('user_id', 'integer', null,
73 new ColumnDef('flag', 'varchar', '8'),
74 new ColumnDef('created', 'datetime', null,
77 // Allowable values for user_flag_notice
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,
87 function onInitializePlugin()
89 // XXX: do something here?
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'));
101 function onAutoload($cls)
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');
111 case 'FlagProfileForm':
112 require_once(INSTALLDIR.'/plugins/UserFlag/' . strtolower($cls . '.php'));
114 case 'User_flag_notice':
116 case 'User_flag_profile':
118 require_once(INSTALLDIR.'/plugins/UserFlag/'.$cls.'.php');
125 function onEndProfilePageActionsElements(&$action, $profile)
127 $user = common_current_user();
131 $action->elementStart('li', 'entity_flag');
133 if (User_flag_profile::exists($profile->id, $user->id,
134 Profile_flag::DEFAULTFLAG)) {
135 $action->element('span',
136 _('Flagged for review'));
138 $form = new FlagProfileForm($action, $profile,
139 array('action' => 'showstream',
140 'nickname' => $profile->nickname));
144 $action->elementEnd('li');
150 function onEndProfileListItemActionElements($item)
152 $user = common_current_user();
156 $form = new FlagProfileForm($item->action, $item->profile);