| | 10 | /** |
|---|
| | 11 | * Filter topics held for moderation |
|---|
| | 12 | * |
|---|
| | 13 | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| | 14 | * @version v 0.02 Sun Apr 08 2007 01:31:51 GMT-0400 (Eastern Daylight Time) |
|---|
| | 15 | */ |
|---|
| | 16 | function bb_moderation_hold_where_moderated_topics($where){ |
|---|
| | 17 | return str_replace("topic_status = '0'", "topic_status = '-1'", $where); |
|---|
| | 18 | } |
|---|
| | 19 | |
|---|
| | 20 | /** |
|---|
| | 21 | * Filter posts held for moderation |
|---|
| | 22 | * |
|---|
| | 23 | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| | 24 | * @version v 0.02 Sun Apr 08 2007 01:32:35 GMT-0400 (Eastern Daylight Time) |
|---|
| | 25 | */ |
|---|
| | 26 | function bb_moderation_hold_where_moderated_posts($where){ |
|---|
| | 27 | return str_replace("post_status = '0'", "post_status = '-1'", $where); |
|---|
| | 28 | } |
|---|
| | 29 | |
|---|
| | 30 | /** |
|---|
| | 31 | * Holds stuff for moderation |
|---|
| | 32 | * |
|---|
| | 33 | * Hold topics and posts for moderation depending on the options. |
|---|
| | 34 | * Also send mail options are set |
|---|
| | 35 | * |
|---|
| | 36 | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| | 37 | * @version v 0.01 Tue Apr 10 2007 23:29:07 GMT-0400 (Eastern Daylight Time) |
|---|
| | 38 | */ |
|---|
| | 39 | function bb_moderation_hold_after_posting_do_the_magic($post_id){ |
|---|
| | 40 | global $bbdb, $topic_id, $post_id; |
|---|
| | 41 | $options = bb_anonymous_default_options(bb_get_option('bb_moderation_hold')); |
|---|
| | 42 | |
|---|
| | 43 | $hold_topics = bb_moderation_check_options('hold_topics', $options); |
|---|
| | 44 | $hold_posts = bb_moderation_check_options('hold_posts', $options); |
|---|
| | 45 | |
|---|
| | 46 | if ( $hold_topics && isset($_POST['topic']) && $forum = (int) $_POST['forum_id'] ) { |
|---|
| | 47 | $bbdb->query("UPDATE $bbdb->topics SET topic_status = '-1' WHERE topic_id = '$topic_id'"); |
|---|
| | 48 | if ('Y' == $options['hold_topics_send_email']) bb_moderation_hold_mail_moderation(); |
|---|
| | 49 | $post_id = false; |
|---|
| | 50 | } elseif($hold_posts) { |
|---|
| | 51 | $post_id = false; |
|---|
| | 52 | if ('Y' == $options['hold_posts_send_email']) bb_moderation_hold_mail_moderation('P'); |
|---|
| | 53 | } |
|---|
| | 54 | |
|---|
| | 55 | } |
|---|
| | 56 | |
|---|
| | 57 | /** |
|---|
| | 58 | * Send Moderation Notification |
|---|
| | 59 | * |
|---|
| | 60 | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| | 61 | * @version v 0.01 Sun Apr 08 2007 01:37:30 GMT-0400 (Eastern Daylight Time) |
|---|
| | 62 | */ |
|---|
| | 63 | function bb_moderation_hold_mail_moderation($obj = 'T') { |
|---|
| | 64 | |
|---|
| | 65 | if ('T' == $obj) { |
|---|
| | 66 | $email = $options['hold_topics_email_address']; |
|---|
| | 67 | $obj = 'topic'; |
|---|
| | 68 | } elseif ('P' == $obj) { |
|---|
| | 69 | $email = $options['hold_posts_email_address']; |
|---|
| | 70 | $obj = 'post'; |
|---|
| | 71 | } else |
|---|
| | 72 | return; |
|---|
| | 73 | |
|---|
| | 74 | $message = __("You have a new $s in the moderation queue."); |
|---|
| | 75 | |
|---|
| | 76 | mail( $email, bb_get_option('name') . ': ' . __('Moderation Alert'), |
|---|
| | 77 | sprintf( $message, "$obj"), |
|---|
| | 78 | 'From: ' . bb_get_option('admin_email') |
|---|
| | 79 | ); |
|---|
| | 80 | } |
|---|
| | 81 | |
|---|
| | 82 | /** |
|---|
| | 83 | * Change the status before post is created |
|---|
| | 84 | * |
|---|
| | 85 | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| | 86 | * @version v 0.02 Tue Apr 10 2007 23:29:38 GMT-0400 (Eastern Daylight Time) |
|---|
| | 87 | */ |
|---|
| | 88 | function bb_moderation_fix_status_before_post($old_status, $post_id, $topic_id) { |
|---|
| | 89 | $options = bb_anonymous_default_options(bb_get_option('bb_moderation_hold')); |
|---|
| | 90 | |
|---|
| | 91 | $hold_posts = bb_moderation_check_options('hold_posts', $options); |
|---|
| | 92 | if (!$post_id && $hold_posts) { |
|---|
| | 93 | $old_status = -1; |
|---|
| | 94 | } |
|---|
| | 95 | return $old_status; |
|---|
| | 96 | } |
|---|
| | 97 | |
|---|
| | 98 | /** |
|---|
| | 99 | * Check Moderation options |
|---|
| | 100 | * |
|---|
| | 101 | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| | 102 | * @version v 0.01 Tue Apr 10 2007 23:30:05 GMT-0400 (Eastern Daylight Time) |
|---|
| | 103 | */ |
|---|
| | 104 | function bb_moderation_check_options($check = 'hold_topics', $options = false) { |
|---|
| | 105 | |
|---|
| | 106 | if (!$options) |
|---|
| | 107 | $options = bb_anonymous_default_options(bb_get_option('bb_moderation_hold')); |
|---|
| | 108 | |
|---|
| | 109 | switch($options[$check]) { |
|---|
| | 110 | case 2: |
|---|
| | 111 | if (!$user = bb_current_user()) $ret = true; |
|---|
| | 112 | break; |
|---|
| | 113 | case 3: |
|---|
| | 114 | if (!bb_current_user_can('moderate')) $ret = true; |
|---|
| | 115 | break; |
|---|
| | 116 | default: |
|---|
| | 117 | $ret = false; |
|---|
| | 118 | } |
|---|
| | 119 | |
|---|
| | 120 | return $ret; |
|---|
| | 121 | } |
|---|
| | 122 | add_action('bb_post.php','bb_moderation_hold_after_posting_do_the_magic'); |
|---|
| | 123 | add_filter('pre_post_status','bb_moderation_fix_status_before_post',10,3); |
|---|
| | 124 | add_filter('post_delete_link','bb_moderation_fix_delete_link',10,3); |
|---|
| | 125 | |
|---|
| | 126 | /** |
|---|
| | 127 | * Add a delete/moderate link to posts |
|---|
| | 128 | * |
|---|
| | 129 | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| | 130 | * @version v 0.01 Tue Apr 10 2007 23:30:05 GMT-0400 (Eastern Daylight Time) |
|---|
| | 131 | */ |
|---|
| | 132 | function bb_moderation_fix_delete_link($r, $post_status, $post_id){ |
|---|
| | 133 | if (-1 == $post_status) |
|---|
| | 134 | $r = "<a href='" . bb_get_option('uri') . 'bb-admin/admin-base.php?plugin=bb_moderation_hold_post_admin_page' . "' >". __('Moderate') ."</a>"; |
|---|
| | 135 | return $r; |
|---|
| | 136 | } |
|---|
| | 137 | |
|---|
| | 138 | if (!BB_IS_ADMIN) { |
|---|
| | 139 | return; |
|---|
| | 140 | } |
|---|
| 348 | | /** |
|---|
| 349 | | * Holds stuff for moderation |
|---|
| 350 | | * |
|---|
| 351 | | * Hold topics and posts for moderation depending on the options. |
|---|
| 352 | | * Also send mail options are set |
|---|
| 353 | | * |
|---|
| 354 | | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| 355 | | * @version v 0.01 Tue Apr 10 2007 23:29:07 GMT-0400 (Eastern Daylight Time) |
|---|
| 356 | | */ |
|---|
| 357 | | function bb_moderation_hold_after_posting_do_the_magic($post_id){ |
|---|
| 358 | | global $bbdb, $topic_id, $post_id; |
|---|
| 359 | | $options = bb_anonymous_default_options(bb_get_option('bb_moderation_hold')); |
|---|
| 360 | | |
|---|
| 361 | | $hold_topics = bb_moderation_check_options('hold_topics', $options); |
|---|
| 362 | | $hold_posts = bb_moderation_check_options('hold_posts', $options); |
|---|
| 363 | | |
|---|
| 364 | | if ( $hold_topics && isset($_POST['topic']) && $forum = (int) $_POST['forum_id'] ) { |
|---|
| 365 | | $bbdb->query("UPDATE $bbdb->topics SET topic_status = '-1' WHERE topic_id = '$topic_id'"); |
|---|
| 366 | | if ('Y' == $options['hold_topics_send_email']) bb_moderation_hold_mail_moderation(); |
|---|
| 367 | | $post_id = false; |
|---|
| 368 | | } elseif($hold_posts) { |
|---|
| 369 | | $post_id = false; |
|---|
| 370 | | if ('Y' == $options['hold_posts_send_email']) bb_moderation_hold_mail_moderation('P'); |
|---|
| 371 | | } |
|---|
| 372 | | |
|---|
| 373 | | } |
|---|
| 374 | | |
|---|
| 375 | | /** |
|---|
| 376 | | * Send Moderation Notification |
|---|
| 377 | | * |
|---|
| 378 | | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| 379 | | * @version v 0.01 Sun Apr 08 2007 01:37:30 GMT-0400 (Eastern Daylight Time) |
|---|
| 380 | | */ |
|---|
| 381 | | function bb_moderation_hold_mail_moderation($obj = 'T') { |
|---|
| 382 | | |
|---|
| 383 | | if ('T' == $obj) { |
|---|
| 384 | | $email = $options['hold_topics_email_address']; |
|---|
| 385 | | $obj = 'topic'; |
|---|
| 386 | | } elseif ('P' == $obj) { |
|---|
| 387 | | $email = $options['hold_posts_email_address']; |
|---|
| 388 | | $obj = 'post'; |
|---|
| 389 | | } else |
|---|
| 390 | | return; |
|---|
| 391 | | |
|---|
| 392 | | $message = __("You have a new $s in the moderation queue."); |
|---|
| 393 | | |
|---|
| 394 | | mail( $email, bb_get_option('name') . ': ' . __('Moderation Alert'), |
|---|
| 395 | | sprintf( $message, "$obj"), |
|---|
| 396 | | 'From: ' . bb_get_option('admin_email') |
|---|
| 397 | | ); |
|---|
| 398 | | } |
|---|
| 399 | | |
|---|
| 400 | | /** |
|---|
| 401 | | * Change the status before post is created |
|---|
| 402 | | * |
|---|
| 403 | | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| 404 | | * @version v 0.01 Tue Apr 10 2007 23:29:38 GMT-0400 (Eastern Daylight Time) |
|---|
| 405 | | */ |
|---|
| 406 | | function bb_moderation_fix_status_before_post($old_status, $post_id, $topic_id) { |
|---|
| 407 | | if (!$post_id) { |
|---|
| 408 | | $old_status = -1; |
|---|
| 409 | | } |
|---|
| 410 | | return $old_status; |
|---|
| 411 | | } |
|---|
| 412 | | |
|---|
| 413 | | /** |
|---|
| 414 | | * Check Moderation options |
|---|
| 415 | | * |
|---|
| 416 | | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| 417 | | * @version v 0.01 Tue Apr 10 2007 23:30:05 GMT-0400 (Eastern Daylight Time) |
|---|
| 418 | | */ |
|---|
| 419 | | function bb_moderation_check_options($check = 'hold_topics', $options = false) { |
|---|
| 420 | | |
|---|
| 421 | | if (!$options) |
|---|
| 422 | | $options = bb_anonymous_default_options(bb_get_option('bb_moderation_hold')); |
|---|
| 423 | | |
|---|
| 424 | | switch($options[$check]) { |
|---|
| 425 | | case 2: |
|---|
| 426 | | if (!$user = bb_current_user()) $ret = true; |
|---|
| 427 | | break; |
|---|
| 428 | | case 3: |
|---|
| 429 | | if (!bb_current_user_can('moderate')) $ret = true; |
|---|
| 430 | | break; |
|---|
| 431 | | default: |
|---|
| 432 | | $ret = false; |
|---|
| 433 | | } |
|---|
| 434 | | |
|---|
| 435 | | return $ret; |
|---|
| 436 | | } |
|---|
| 437 | | add_action('bb_post.php','bb_moderation_hold_after_posting_do_the_magic'); |
|---|
| 438 | | add_filter('pre_post_status','bb_moderation_fix_status_before_post',10,3); |
|---|
| 439 | | add_filter('post_delete_link','bb_moderation_fix_delete_link',10,3); |
|---|
| 440 | | |
|---|
| 441 | | /** |
|---|
| 442 | | * Add a delete/moderate link to posts |
|---|
| 443 | | * |
|---|
| 444 | | * @author Aditya Naik <aditya@adityanaik.com> |
|---|
| 445 | | * @version v 0.01 Tue Apr 10 2007 23:30:05 GMT-0400 (Eastern Daylight Time) |
|---|
| 446 | | */ |
|---|
| 447 | | function bb_moderation_fix_delete_link($r, $post_status, $post_id){ |
|---|
| 448 | | if (-1 == $post_status) |
|---|
| 449 | | $r = "<a href='" . bb_get_option('uri') . 'bb-admin/admin-base.php?plugin=bb_moderation_hold_post_admin_page' . "' >". __('Moderate') ."</a>"; |
|---|
| 450 | | return $r; |
|---|
| 451 | | } |
|---|