[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: class_custommoderation.php 5828 2012-05-08 16:06:16Z Tomm $ 10 */ 11 12 // Disallow direct access to this file for security reasons 13 if(!defined("IN_MYBB")) 14 { 15 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); 16 } 17 18 /** 19 * Used to execute a custom moderation tool 20 * 21 */ 22 23 class CustomModeration extends Moderation 24 { 25 /** 26 * Get info on a tool 27 * 28 * @param int Tool ID 29 * @param mixed Thread IDs 30 * @param mixed Post IDs 31 * @return mixed Returns tool data (tid, type, name, description) in an array, otherwise boolean false. 32 */ 33 function tool_info($tool_id) 34 { 35 global $db; 36 37 // Get tool info 38 $query = $db->simple_select("modtools", "*", 'tid="'.intval($tool_id).'"'); 39 $tool = $db->fetch_array($query); 40 if(!$tool['tid']) 41 { 42 return false; 43 } 44 else 45 { 46 return $tool; 47 } 48 } 49 50 /** 51 * Execute Custom Moderation Tool 52 * 53 * @param int Tool ID 54 * @param mixed Thread ID(s) 55 * @param mixed Post IDs 56 * @return string 'forum' or 'default' indicating where to redirect 57 */ 58 function execute($tool_id, $tids=0, $pids=0) 59 { 60 global $db; 61 62 // Get tool info 63 $query = $db->simple_select("modtools", '*', 'tid="'.intval($tool_id).'"'); 64 $tool = $db->fetch_array($query); 65 if(!$tool['tid']) 66 { 67 return false; 68 } 69 70 // Format single tid and pid 71 if(!is_array($tids)) 72 { 73 $tids = array($tids); 74 } 75 if(!is_array($pids)) 76 { 77 $pids = array($pids); 78 } 79 80 // Unserialize custom moderation 81 $post_options = unserialize($tool['postoptions']); 82 $thread_options = unserialize($tool['threadoptions']); 83 84 // If the tool type is a post tool, then execute the post moderation 85 if($tool['type'] == 'p') 86 { 87 $deleted_thread = $this->execute_post_moderation($post_options, $pids, $tids); 88 } 89 // Always execute thead moderation 90 $this->execute_thread_moderation($thread_options, $tids); 91 92 // If the thread is deleted, indicate to the calling script to redirect to the forum, and not the nonexistant thread 93 if($thread_options['deletethread'] == 1 || $deleted_thread === 1) 94 { 95 return 'forum'; 96 } 97 return 'default'; 98 } 99 100 /** 101 * Execute Inline Post Moderation 102 * 103 * @param array Moderation information 104 * @param mixed Post IDs 105 * @param array Thread IDs (in order of dateline ascending) 106 * @return boolean true 107 */ 108 function execute_post_moderation($post_options, $pids, $tid) 109 { 110 global $db, $mybb, $lang; 111 112 if(is_array($tid)) 113 { 114 $tid = intval($tid[0]); // There's only 1 thread when doing inline post moderation 115 // The thread chosen is the first thread in the array of tids. 116 // It is recommended that this be the tid of the oldest post 117 } 118 119 // Get the information about thread 120 $thread = get_thread($tid); 121 122 // If deleting posts, only do that 123 if($post_options['deleteposts'] == 1) 124 { 125 foreach($pids as $pid) 126 { 127 $this->delete_post($pid); 128 } 129 130 $delete_tids = array(); 131 $imploded_pids = implode(",", array_map("intval", $pids)); 132 $query = $db->simple_select("threads", "tid", "firstpost IN ({$imploded_pids})"); 133 while($threadid = $db->fetch_field($query, "tid")) 134 { 135 $delete_tids[] = $threadid; 136 } 137 if(!empty($delete_tids)) 138 { 139 foreach($delete_tids as $delete_tid) 140 { 141 $this->delete_thread($delete_tid); 142 mark_reports($delete_tid, "thread"); 143 } 144 // return 1 here so the code in execute() above knows to redirect to the forum 145 return 1; 146 } 147 } 148 else 149 { 150 if($post_options['mergeposts'] == 1) // Merge posts 151 { 152 $this->merge_posts($pids); 153 } 154 155 if($post_options['approveposts'] == 'approve') // Approve posts 156 { 157 $this->approve_posts($pids); 158 } 159 elseif($post_options['approveposts'] == 'unapprove') // Unapprove posts 160 { 161 $this->unapprove_posts($pids); 162 } 163 elseif($post_options['approveposts'] == 'toggle') // Toggle post visibility 164 { 165 $this->toggle_post_visibility($pids); 166 } 167 168 if($post_options['splitposts'] > 0 || $post_options['splitposts'] == -2) // Split posts 169 { 170 $query = $db->simple_select("posts", "COUNT(*) AS totalposts", "tid='{$tid}'"); 171 $count = $db->fetch_array($query); 172 173 if($count['totalposts'] == 1) 174 { 175 error($lang->error_cantsplitonepost); 176 } 177 178 if($count['totalposts'] == count($pids)) 179 { 180 error($lang->error_cantsplitall); 181 } 182 183 if($post_options['splitposts'] == -2) 184 { 185 $post_options['splitposts'] = $thread['fid']; 186 } 187 if(empty($post_options['splitpostsnewsubject'])) 188 { 189 // Enter in a subject if a predefined one does not exist. 190 $post_options['splitpostsnewsubject'] = "{$lang->split_thread_subject} {$thread['subject']}"; 191 } 192 $new_subject = str_ireplace('{subject}', $thread['subject'], $post_options['splitpostsnewsubject']); 193 $new_tid = $this->split_posts($pids, $tid, $post_options['splitposts'], $new_subject); 194 if($post_options['splitpostsclose'] == 'close') // Close new thread 195 { 196 $this->close_threads($new_tid); 197 } 198 if($post_options['splitpostsstick'] == 'stick') // Stick new thread 199 { 200 $this->stick_threads($new_tid); 201 } 202 if($post_options['splitpostsunapprove'] == 'unapprove') // Unapprove new thread 203 { 204 $this->unapprove_threads($new_tid, $thread['fid']); 205 } 206 if(!empty($post_options['splitpostsaddreply'])) // Add reply to new thread 207 { 208 require_once MYBB_ROOT."inc/datahandlers/post.php"; 209 $posthandler = new PostDataHandler("insert"); 210 211 if(empty($post_options['splitpostsreplysubject'])) 212 { 213 $post_options['splitpostsreplysubject'] = 'RE: '.$new_subject; 214 } 215 else 216 { 217 $post_options['splitpostsreplysubject'] = str_ireplace('{username}', $mybb->user['username'], $post_options['splitpostsreplysubject']); 218 $post_options['splitpostsreplysubject'] = str_ireplace('{subject}', $new_subject, $post_options['splitpostsreplysubject']); 219 } 220 221 // Set the post data that came from the input to the $post array. 222 $post = array( 223 "tid" => $new_tid, 224 "fid" => $post_options['splitposts'], 225 "subject" => $post_options['splitpostsreplysubject'], 226 "uid" => $mybb->user['uid'], 227 "username" => $mybb->user['username'], 228 "message" => $post_options['splitpostsaddreply'], 229 "ipaddress" => $db->escape_string(get_ip()), 230 ); 231 // Set up the post options from the input. 232 $post['options'] = array( 233 "signature" => 1, 234 "emailnotify" => 0, 235 "disablesmilies" => 0 236 ); 237 238 $posthandler->set_data($post); 239 240 if($posthandler->validate_post($post)) 241 { 242 $posthandler->insert_post($post); 243 } 244 } 245 } 246 } 247 return true; 248 } 249 250 /** 251 * Execute Normal and Inline Thread Moderation 252 * 253 * @param array Moderation information 254 * @param mixed Thread IDs 255 * @return boolean true 256 */ 257 function execute_thread_moderation($thread_options, $tids) 258 { 259 global $db, $mybb; 260 261 $tid = intval($tids[0]); // Take the first thread to get thread data from 262 $query = $db->simple_select("threads", 'fid', "tid='$tid'"); 263 $thread = $db->fetch_array($query); 264 265 // If deleting threads, only do that 266 if($thread_options['deletethread'] == 1) 267 { 268 foreach($tids as $tid) 269 { 270 $this->delete_thread($tid); 271 } 272 } 273 else 274 { 275 if($thread_options['mergethreads'] == 1 && count($tids) > 1) // Merge Threads (ugly temp code until find better fix) 276 { 277 $tid_list = implode(',', $tids); 278 $options = array('order_by' => 'dateline', 'order_dir' => 'DESC'); 279 $query = $db->simple_select("threads", 'tid, subject', "tid IN ($tid_list)", $options); // Select threads from newest to oldest 280 $last_tid = 0; 281 while($tid = $db->fetch_array($query)) 282 { 283 if($last_tid != 0) 284 { 285 $this->merge_threads($last_tid, $tid['tid'], $tid['subject']); // And keep merging them until we get down to one thread. 286 } 287 $last_tid = $tid['tid']; 288 } 289 } 290 if($thread_options['deletepoll'] == 1) // Delete poll 291 { 292 foreach($tids as $tid) 293 { 294 $this->delete_poll($tid); 295 } 296 } 297 if($thread_options['removeredirects'] == 1) // Remove redirects 298 { 299 foreach($tids as $tid) 300 { 301 $this->remove_redirects($tid); 302 } 303 } 304 305 if($thread_options['approvethread'] == 'approve') // Approve thread 306 { 307 $this->approve_threads($tids, $thread['fid']); 308 } 309 elseif($thread_options['approvethread'] == 'unapprove') // Unapprove thread 310 { 311 $this->unapprove_threads($tids, $thread['fid']); 312 } 313 elseif($thread_options['approvethread'] == 'toggle') // Toggle thread visibility 314 { 315 $this->toggle_thread_visibility($tids, $thread['fid']); 316 } 317 318 if($thread_options['openthread'] == 'open') // Open thread 319 { 320 $this->open_threads($tids); 321 } 322 elseif($thread_options['openthread'] == 'close') // Close thread 323 { 324 $this->close_threads($tids); 325 } 326 elseif($thread_options['openthread'] == 'toggle') // Toggle thread visibility 327 { 328 $this->toggle_thread_status($tids); 329 } 330 331 if($thread_options['threadprefix'] != '-1') 332 { 333 $this->apply_thread_prefix($tids, $thread_options['threadprefix']); // Update thread prefix 334 } 335 336 if(my_strtolower(trim($thread_options['newsubject'])) != '{subject}') // Update thread subjects 337 { 338 $this->change_thread_subject($tids, $thread_options['newsubject']); 339 } 340 if(!empty($thread_options['addreply'])) // Add reply to thread 341 { 342 $tid_list = implode(',', $tids); 343 $query = $db->simple_select("threads", 'fid, subject, tid, firstpost, closed', "tid IN ($tid_list) AND closed NOT LIKE 'moved|%'"); 344 require_once MYBB_ROOT."inc/datahandlers/post.php"; 345 346 // Loop threads adding a reply to each one 347 while($thread = $db->fetch_array($query)) 348 { 349 $posthandler = new PostDataHandler("insert"); 350 351 if(empty($thread_options['replysubject'])) 352 { 353 $new_subject = 'RE: '.$thread['subject']; 354 } 355 else 356 { 357 $new_subject = str_ireplace('{username}', $mybb->user['username'], $thread_options['replysubject']); 358 $new_subject = str_ireplace('{subject}', $thread['subject'], $new_subject); 359 } 360 361 // Set the post data that came from the input to the $post array. 362 $post = array( 363 "tid" => $thread['tid'], 364 "replyto" => $thread['firstpost'], 365 "fid" => $thread['fid'], 366 "subject" => $new_subject, 367 "uid" => $mybb->user['uid'], 368 "username" => $mybb->user['username'], 369 "message" => $thread_options['addreply'], 370 "ipaddress" => $db->escape_string(get_ip()), 371 ); 372 373 // Set up the post options from the input. 374 $post['options'] = array( 375 "signature" => 1, 376 "emailnotify" => 0, 377 "disablesmilies" => 0 378 ); 379 380 if($thread['closed'] == 1) 381 { 382 // Keep this thread closed 383 $post['modoptions']['closethread'] = 1; 384 } 385 386 $posthandler->set_data($post); 387 if($posthandler->validate_post($post)) 388 { 389 $posthandler->insert_post($post); 390 } 391 } 392 } 393 if($thread_options['movethread'] > 0 && $thread_options['movethread'] != $thread['fid']) // Move thread 394 { 395 if($thread_options['movethreadredirect'] == 1) // Move Thread with redirect 396 { 397 $time = TIME_NOW + ($thread_options['movethreadredirectexpire'] * 86400); 398 foreach($tids as $tid) 399 { 400 $this->move_thread($tid, $thread_options['movethread'], 'redirect', $time); 401 } 402 } 403 else // Normal move 404 { 405 $this->move_threads($tids, $thread_options['movethread']); 406 } 407 } 408 if($thread_options['copythread'] > 0 || $thread_options['copythread'] == -2) // Copy thread 409 { 410 if($thread_options['copythread'] == -2) 411 { 412 $thread_options['copythread'] = $thread['fid']; 413 } 414 foreach($tids as $tid) 415 { 416 $new_tid = $this->move_thread($tid, $thread_options['copythread'], 'copy'); 417 } 418 } 419 } 420 return true; 421 } 422 } 423 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |