-
Notifications
You must be signed in to change notification settings - Fork 16
/
ocf_moderation_action2.php
executable file
·265 lines (221 loc) · 10.5 KB
/
ocf_moderation_action2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php /*
ocPortal
Copyright (c) ocProducts, 2004-2012
See text/EN/licence.txt for full licencing information.
NOTE TO PROGRAMMERS:
Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
**** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****
*/
/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright ocProducts Ltd
* @package core_ocf
*/
/**
* Edit a multi moderation.
*
* @param AUTO_LINK The ID of the multi moderation we are editing.
* @param SHORT_TEXT The name of the multi moderation.
* @param LONG_TEXT The default post text to add when applying (may be blank).
* @param ?AUTO_LINK The forum to move the topic when applying (NULL: do not move).
* @param BINARY The pin state after applying.
* @param BINARY The sink state after applying.
* @param BINARY The open state after applying.
* @param SHORT_TEXT The forum multi code for where this multi moderation may be applied.
* @param SHORT_TEXT The title suffix.
*/
function ocf_edit_multi_moderation($id,$name,$post_text,$move_to,$pin_state,$sink_state,$open_state,$forum_multi_code,$title_suffix)
{
$_name=$GLOBALS['FORUM_DB']->query_value('f_multi_moderations','mm_name',array('id'=>$id));
if ($move_to==-1) $move_to=NULL;
if ($pin_state==-1) $pin_state=NULL;
if ($open_state==-1) $open_state=NULL;
if ($sink_state==-1) $sink_state=NULL;
$GLOBALS['FORUM_DB']->query_update('f_multi_moderations',array(
'mm_name'=>lang_remap($_name,$name,$GLOBALS['FORUM_DB']),
'mm_post_text'=>$post_text,
'mm_move_to'=>$move_to,
'mm_pin_state'=>$pin_state,
'mm_sink_state'=>$sink_state,
'mm_open_state'=>$open_state,
'mm_forum_multi_code'=>$forum_multi_code,
'mm_title_suffix'=>$title_suffix,
),array('id'=>$id),'',1);
log_it('EDIT_MULTI_MODERATION',strval($id),$name);
}
/**
* Delete a multi moderation.
*
* @param AUTO_LINK The ID of the multi moderation we are deleting.
*/
function ocf_delete_multi_moderation($id)
{
$_name=$GLOBALS['FORUM_DB']->query_value('f_multi_moderations','mm_name',array('id'=>$id));
$name=get_translated_text($_name,$GLOBALS['FORUM_DB']);
$GLOBALS['FORUM_DB']->query_delete('f_multi_moderations',array('id'=>$id),'',1);
delete_lang($_name,$GLOBALS['FORUM_DB']);
log_it('DELETE_MULTI_MODERATION',strval($id),$name);
}
/**
* Perform a multi moderation.
*
* @param AUTO_LINK The ID of the multi moderation we are performing.
* @param AUTO_LINK The ID of the topic we are performing the multi moderation on.
* @param LONG_TEXT The reason for performing the multi moderation (may be blank).
* @param LONG_TEXT The post text for a post to be added to the topic (blank: do not add a post).
* @param BINARY Whether the post is marked emphasised.
* @param BINARY Whether to skip showing the posters signature in the post.
*/
function ocf_perform_multi_moderation($id,$topic_id,$reason,$post_text='',$is_emphasised=1,$skip_sig=0)
{
$topic_details=$GLOBALS['FORUM_DB']->query_select('f_topics',array('t_forum_id','t_cache_first_title','t_cache_first_post_id'),array('id'=>$topic_id),'',1);
if (!array_key_exists(0,$topic_details)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$from=$topic_details[0]['t_forum_id'];
if (!ocf_may_perform_multi_moderation($from)) access_denied('I_ERROR');
$mm=$GLOBALS['FORUM_DB']->query_select('f_multi_moderations',array('*'),array('id'=>$id));
if (!array_key_exists(0,$mm)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
require_code('ocfiltering');
$idlist=ocfilter_to_idlist_using_db($mm[0]['mm_forum_multi_code'],'id','f_forums','f_forums','f_parent_forum','f_parent_forum','id',true,true,$GLOBALS['FORUM_DB']);
if (!in_array($from,$idlist)) warn_exit(do_lang_tempcode('MM_APPLY_TWICE'));
$pin_state=$mm[0]['mm_pin_state'];
$open_state=$mm[0]['mm_open_state'];
$sink_state=$mm[0]['mm_sink_state'];
$move_to=$mm[0]['mm_move_to'];
$title_suffix=$mm[0]['mm_title_suffix'];
//$post_text=$mm[0]['mm_post_text']; We'll allow user to specify the post_text, with this as a default
$update_array=array();
if (!is_null($pin_state)) $update_array['t_pinned']=$pin_state;
if (!is_null($sink_state)) $update_array['t_sunk']=$sink_state;
if (!is_null($open_state)) $update_array['t_is_open']=$open_state;
if ($title_suffix!='')
{
$new_title=$topic_details[0]['t_cache_first_title'].' ['.$title_suffix.']';
$update_array['t_cache_first_title']=$new_title;
$GLOBALS['FORUM_DB']->query_update('f_posts',array('p_title'=>$new_title),array('id'=>$topic_details[0]['t_cache_first_post_id']),'',1);
}
if (count($update_array)!=0)
$GLOBALS['FORUM_DB']->query_update('f_topics',$update_array,array('id'=>$topic_id),'',1);
if (!is_null($move_to))
{
require_code('ocf_topics_action');
require_code('ocf_topics_action2');
ocf_move_topics($from,$move_to,array($topic_id));
}
if ($post_text!='')
{
require_code('ocf_posts_action');
require_code('ocf_posts_action2');
require_code('ocf_topics_action');
require_code('ocf_topics_action2');
ocf_make_post($topic_id,'',$post_text,$skip_sig,false,1,$is_emphasised);
$forum_id=is_null($move_to)?$from:$move_to;
handle_topic_ticket_reply($forum_id,$topic_id,$topic_details[0]['t_cache_first_title'],$post_text);
}
require_code('ocf_general_action2');
ocf_mod_log_it('PERFORM_MULTI_MODERATION',strval($id),strval($topic_id),$reason);
}
/**
* Script for loading presets from saved warnings.
*/
function warnings_script()
{
if (get_forum_type()!='ocf') warn_exit(do_lang_tempcode('NO_OCF')); else ocf_require_all_forum_stuff();
require_lang('ocf_warnings');
if (!ocf_may_warn_members())
access_denied('PRIVILEGE','warn_members');
$type=get_param('type');
if ($type=='delete') // Delete a saved warning
{
$_title=post_param('title');
$GLOBALS['FORUM_DB']->query_delete('f_saved_warnings',array('s_title'=>$_title),'',1);
$content=paragraph(do_lang_tempcode('SUCCESS'));
$echo=do_template('STANDALONE_HTML_WRAP',array('TITLE'=>do_lang_tempcode('DELETE_SAVED_WARNING'),'CONTENT'=>$content));
$echo->evaluate_echo();
return;
}
// Show list of saved warnings
// ---------------------------
$content=new ocp_tempcode();
$rows=$GLOBALS['FORUM_DB']->query_select('f_saved_warnings',array('*'),NULL,'ORDER BY s_title');
$keep=symbol_tempcode('KEEP');
$url=find_script('warnings').'?type=delete'.$keep->evaluate();
foreach ($rows as $myrow)
{
$delete_link=hyperlink($url,do_lang_tempcode('DELETE'),false,false,'',NULL,form_input_hidden('title',$myrow['s_title']));
$content->attach(do_template('OCF_SAVED_WARNING',array('MESSAGE'=>$myrow['s_message'],'EXPLANATION'=>$myrow['s_explanation'],'TITLE'=>$myrow['s_title'],'DELETE_LINK'=>$delete_link)));
}
if ($content->is_empty()) $content=paragraph(do_lang_tempcode('NO_ENTRIES'),'rfdsfsdf3t45');
$echo=do_template('STANDALONE_HTML_WRAP',array('TITLE'=>do_lang_tempcode('CHOOSE_SAVED_WARNING'),'POPUP'=>true,'CONTENT'=>$content));
$echo->evaluate_echo();
}
/**
* Add a formal warning.
*
* @param MEMBER The member being warned.
* @param LONG_TEXT An explanation for why the member is being warned.
* @param ?MEMBER The member doing the warning (NULL: current member).
* @param ?TIME The time of the warning (NULL: now).
* @param BINARY Whether this counts as a warning
* @param ?AUTO_LINK The topic being silenced from (NULL: none)
* @param ?AUTO_LINK The forum being silenced from (NULL: none)
* @param integer Number of extra days for probation
* @param IP The IP address being banned (blank: none)
* @param integer The points being charged
* @param BINARY Whether the member is being banned
* @param ?GROUP The usergroup being changed from (NULL: no change)
* @return AUTO_LINK The ID of the newly created warning.
*/
function ocf_make_warning($member_id,$explanation,$by=NULL,$time=NULL,$is_warning=1,$silence_from_topic=NULL,$silence_from_forum=NULL,$probation=0,$banned_ip='',$charged_points=0,$banned_member=0,$changed_usergroup_from=NULL)
{
if ((is_null($time)) && (!ocf_may_warn_members())) access_denied('PRIVILEGE','warn_members');
if (is_null($time)) $time=time();
if (is_null($by)) $by=get_member();
if ($is_warning==1)
{
$GLOBALS['FORUM_DB']->query('UPDATE '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_members SET m_cache_warnings=(m_cache_warnings+1) WHERE id='.strval((integer)$member_id),1);
}
return $GLOBALS['FORUM_DB']->query_insert('f_warnings',array(
'w_member_id'=>$member_id,
'w_time'=>$time,
'w_explanation'=>$explanation,
'w_by'=>$by,
'w_is_warning'=>$is_warning,
'p_silence_from_topic'=>$silence_from_topic,
'p_silence_from_forum'=>$silence_from_forum,
'p_probation'=>$probation,
'p_banned_ip'=>$banned_ip,
'p_charged_points'=>$charged_points,
'p_banned_member'=>$banned_member,
'p_changed_usergroup_from'=>$changed_usergroup_from,
),true);
}
/**
* Edit a formal warning.
*
* @param AUTO_LINK The ID of the formal warning we are editing.
* @param LONG_TEXT An explanation for why the member is being warned.
* @param BINARY Whether this counts as a warning
*/
function ocf_edit_warning($warning_id,$explanation,$is_warning=1)
{
if (!ocf_may_warn_members()) access_denied('PRIVILEGE','warn_members');
$member_id=$GLOBALS['FORUM_DB']->query_value_null_ok('f_warnings','w_member_id',array('id'=>$warning_id));
if (is_null($member_id)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$GLOBALS['FORUM_DB']->query_update('f_warnings',array('w_explanation'=>$explanation,'w_is_warning'=>$is_warning),array('id'=>$warning_id),'',1);
$member_id=$GLOBALS['FORUM_DB']->query_value('f_warnings','w_member_id',array('id'=>$warning_id));
$num_warnings=$GLOBALS['FORUM_DB']->query_value('f_warnings','COUNT(*)',array('w_is_warning'=>1,'w_member_id'=>$member_id));
$GLOBALS['FORUM_DB']->query_update('f_members',array('m_cache_warnings'=>$num_warnings),array('id'=>$member_id),'',1);
}
/**
* Delete a formal warning.
*
* @param AUTO_LINK The ID of the formal warning we are deleting.
*/
function ocf_delete_warning($warning_id)
{
if (!ocf_may_warn_members()) access_denied('PRIVILEGE','warn_members');
$member_id=$GLOBALS['FORUM_DB']->query_value_null_ok('f_warnings','w_member_id',array('id'=>$warning_id));
if (is_null($member_id)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$GLOBALS['FORUM_DB']->query('UPDATE '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_members SET m_cache_warnings=(m_cache_warnings-1) WHERE id='.strval((integer)$member_id),1);
$GLOBALS['FORUM_DB']->query_delete('f_warnings',array('id'=>$warning_id),'',1);
}