1
|
|
|
<?php |
2
|
|
|
// $Id$ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @file |
6
|
|
|
* Create a flag link with a JS dropdown with reasons why content has |
7
|
|
|
* been flagged for abuse. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * |
11
|
|
|
* Hooks into flag module |
12
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Implementation of hook_flag_default_flags() |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
function flag_abuse_reason_flag_default_flags() { |
19
|
|
|
$flags = array(); |
20
|
|
|
module_load_include('inc', 'flag_abuse_reason', 'includes/flag_abuse_reason.flag_default'); |
21
|
|
|
_flag_abuse_reason_abuse_node_flags($flags); |
22
|
|
|
_flag_abuse_reason_abuse_comment_flags($flags); |
23
|
|
|
_flag_abuse_reason_abuse_user_flags($flags); |
24
|
|
|
return $flags; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Implementation of hook_views_api(). |
29
|
|
|
*/ |
30
|
|
|
function flag_abuse_reason_views_api() { |
31
|
|
|
return array( |
32
|
|
|
'api' => 2.0, |
33
|
|
|
'path' => drupal_get_path('module', 'flag_abuse_reason') . '/includes', |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Implementation of hook_perm(). |
39
|
|
|
*/ |
40
|
|
|
function flag_abuse_reason_perm() { |
41
|
|
|
return array('reset abuse flags'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Implementation of hook_preprocess_flag(). |
46
|
|
|
* |
47
|
|
|
* Here we change our flag event/action to 'reset'. |
48
|
|
|
*/ |
49
|
|
|
function flag_abuse_reason_preprocess_flag(&$vars) { |
50
|
|
|
drupal_add_js(drupal_get_path('module', 'flag_abuse_reason') . "/includes/flag_abuse_reason.js"); |
51
|
|
|
drupal_add_css(drupal_get_path('module', 'flag_abuse_reason') . "/css/flag_abuse_reason.css"); |
52
|
|
|
$myuser = $vars['user']; |
53
|
|
|
$metaflags = array('abuse_node_meta', 'abuse_comment_meta', 'abuse_user_meta'); |
54
|
|
|
|
55
|
|
|
// permmission check instead of a role |
56
|
|
|
// Is this one of our abuse flags? |
57
|
|
|
if (in_array($vars['flag']->name, $metaflags)) { |
58
|
|
|
|
59
|
|
|
// count the number of flags on this content |
60
|
|
|
$count = db_result(db_query("SELECT COUNT(*) FROM {flag_content} WHERE content_id=%d AND fid=%d", $vars['content_id'], $vars['flag']->fid)); |
61
|
|
|
|
62
|
|
|
// If the variable <flagname>-<contentid> is set, then Reset |
63
|
|
|
// completely. |
64
|
|
|
if (variable_get($vars['flag']->name.'-'.$vars['content_id'], FALSE)) { |
65
|
|
|
if (user_access('reset abuse flags', $myuser)) { |
66
|
|
|
$vars['action'] = 'none'; |
67
|
|
|
$vars['link_text'] = t('Reset Completely'); |
68
|
|
|
$vars['link_title'] = t('Reset everying, allows users to re-flag content.'); |
69
|
|
|
} |
70
|
|
|
else { |
71
|
|
|
$vars['action'] = 'none'; |
72
|
|
|
$vars['link_text'] = t('Locked'); |
73
|
|
|
$vars['link_title'] = t('Reporting locked by moderator.'); |
74
|
|
|
$vars['link'] = array(); |
75
|
|
|
$vars['link_href'] = ''; |
76
|
|
|
$vars['flag_classes'] = 'flag style-like-link'; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
else { |
80
|
|
|
// If there are flags on this content, clear the flags and |
81
|
|
|
// lock the content. |
82
|
|
|
if (user_access('reset abuse flags', $myuser)) { |
83
|
|
|
if ($count>0) { |
84
|
|
|
$vars['action'] = 'reset'; |
85
|
|
|
$vars['link_text'] = t('Clear Reports and Lock'); |
86
|
|
|
$vars['link_title'] = t('Remove all flags on this content and prevent any new flagging.'); |
87
|
|
|
} |
88
|
|
|
// Otherwise the link is shown but has no effect. |
89
|
|
|
else { |
90
|
|
|
$vars['action'] = 'none'; |
91
|
|
|
$vars['link_text'] = t('No abuse reports'); |
92
|
|
|
$vars['link_title'] = t('This content has no abuse reports. Link does nothing.'); |
93
|
|
|
$vars['link'] = array(); |
94
|
|
|
$vars['link_href'] = ''; |
95
|
|
|
$vars['flag_classes'] = 'flag style-like-link'; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Implementation of hook_flag(). |
104
|
|
|
* |
105
|
|
|
* If a user with appropriate permission/role flags this content from our view |
106
|
|
|
* we want to remove all flags. http://drupal.org/node/327901#comment-1085685 |
107
|
|
|
*/ |
108
|
|
|
function flag_abuse_reason_flag($event, $flag, $content_id, $account) { |
109
|
|
|
$metaflags = array('abuse_node_meta', 'abuse_comment_meta', 'abuse_user_meta'); |
110
|
|
|
|
111
|
|
|
// For privileged users, check permissions and reset flags |
112
|
|
|
// permission check instead of a role. |
113
|
|
|
if (user_access('reset abuse flags', $account)) { |
114
|
|
|
// Is this one of our abuse flags? |
115
|
|
|
if (in_array($flag->name, $metaflags)) { |
116
|
|
|
|
117
|
|
|
// Reset the flags completely. |
118
|
|
|
if (variable_get($flag->name.'-'.$content_id, FALSE)) { |
119
|
|
|
// Since the user flags the content again, we need to unflag it. |
120
|
|
|
flag_reset_flag($flag, $content_id); |
121
|
|
|
drupal_set_message(bts('INFO: Reset everything. Users may reflag this content.', array(), NULL, 'boinc:flag-abuse-reset'), 'info'); |
122
|
|
|
// unlock flag; effectively resets flags for this content |
123
|
|
|
variable_del($flag->name.'-'.$content_id); |
124
|
|
|
} |
125
|
|
|
else { |
126
|
|
|
// Clear and Lock all flags on this content. |
127
|
|
|
$dbresult = db_query("SELECT DISTINCT fid FROM {flag_content} WHERE content_id = %d", $content_id); |
128
|
|
|
$rows = 0; |
129
|
|
|
while ($myfid = db_fetch_array($dbresult)) { |
|
|
|
|
130
|
|
|
$myflag = flag_get_flag(NULL, array_pop($myfid)); |
|
|
|
|
131
|
|
|
$rows += flag_reset_flag($myflag, $content_id); |
132
|
|
|
} |
133
|
|
|
if ($rows) { |
134
|
|
|
// This user actually flags the content as well, so it may |
135
|
|
|
// confuse the user if they reset what they thought was one |
136
|
|
|
// flag and we report two. |
137
|
|
|
$rows--; |
138
|
|
|
drupal_set_message(bts('INFO: Cleared !rows flags. Content is now locked and may not be reflagged.', array('!rows' => $rows), NULL, 'boinc:flag-abuse-reset'), 'info'); |
139
|
|
|
|
140
|
|
|
// This is the line which sets a Drupal variable which |
141
|
|
|
// prevents the flag link from showing again for all |
142
|
|
|
// users. Effectively preventing the content from being |
143
|
|
|
// flagged again. |
144
|
|
|
variable_set($flag->name.'-'.$content_id, TRUE); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
// Normal users may cancel their all their reported flags on this |
151
|
|
|
// content. |
152
|
|
|
else { |
153
|
|
|
if ( ($event=='unflag') && (in_array($flag->name, $metaflags)) ) { |
154
|
|
|
$allflags = flag_get_user_flags($flag->content_type, $content_id, $account->uid); |
155
|
|
|
foreach ($allflags as $subflag) { |
156
|
|
|
$myflag = flag_get_flag(NULL, $subflag->fid); |
157
|
|
|
$rc = $myflag->flag('unflag', $content_id, $account); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Implementation of hook_form_FORM_ID_alter(). |
165
|
|
|
*/ |
166
|
|
|
function flag_abuse_reason_form_flag_confirm_alter(&$form, &$form_state) { |
167
|
|
|
// Permmission check instead of a role. |
168
|
|
|
if (user_access('reset abuse flags', $account)) { |
|
|
|
|
169
|
|
|
$flag_name = $form['flag_name']['#value']; |
170
|
|
|
// Is this one of our abuse flags? |
171
|
|
|
if (in_array($flag_name, array('abuse_node_meta', 'abuse_comment_meta', 'abuse_user_meta'))) { |
172
|
|
|
drupal_set_title(t('Flag reset')); |
173
|
|
|
$form['description']['#value'] = t('Are you sure you want to reset all offensive flag on this content? Once doing so, users will not be able to flag this content again.'); |
174
|
|
|
$form['actions']['submit']['#value'] = t('Reset flags'); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.