3 require('includes/header.php');
5 if( ! $administrator && ! $moderator ||
$moderator && ! ALLOW_MODS_EXTERMINATE
)
7 add_error('You are not wise enough.', true);
10 $page_title = 'Exterminate trolls by phrase';
12 if($_POST['exterminate'])
14 $_POST['phrase'] = str_replace("\r", '', $_POST['phrase']);
17 if(empty($_POST['start_time']) ||
$_POST['start_time'] != $_SESSION['exterminate_start_time'])
19 add_error('Session error.', true);
22 if(strlen($_POST['phrase']) < 4)
24 add_error('That phrase is too short.', true);
27 $phrase = '%' . $_POST['phrase'] . '%';
29 if(ctype_digit($_POST['range']))
31 $affect_posts_after = $_SERVER['REQUEST_TIME'] - $_POST['range'];
34 $fetch_parents = $link->prepare('SELECT id, parent_id FROM replies WHERE body LIKE ? AND time > ?');
35 $fetch_parents->bind_param('si', $phrase, $affect_posts_after);
36 $fetch_parents->execute();
37 $fetch_parents->bind_result($reply_id, $parent_id);
39 $victim_parents = array();
40 while($fetch_parents->fetch())
42 $victim_parents[] = $parent_id;
44 $fetch_parents->close();
46 $delete_replies = $link->prepare('DELETE FROM replies WHERE body LIKE ? AND time > ?');
47 $delete_replies->bind_param('si', $phrase, $affect_posts_after);
48 $delete_replies->execute();
49 $delete_replies->close();
51 $decrement = $link->prepare('UPDATE topics SET replies = replies - 1 WHERE id = ?');
52 foreach($victim_parents as $parent_id)
54 $decrement->bind_param('i', $parent_id);
55 $decrement->execute();
60 $delete_topics = $link->prepare('DELETE FROM topics WHERE body LIKE ? OR headline LIKE ? AND time > ?');
61 $delete_topics->bind_param('ssi', $phrase, $phrase, $affect_posts_after);
62 $delete_topics->execute();
63 $delete_topics->close();
65 $_SESSION['notice'] = 'Finished.';
69 $start_time = $_SERVER['REQUEST_TIME'];
70 $_SESSION['exterminate_start_time'] = $start_time;
74 <p
>This features removes all posts that contain anywhere in the body
or headline the exact phrase that you specify
.</p
>
76 <form action
="" method
="post">
77 <div
class="noscreen">
78 <input type
="hidden" name
="start_time" value
="<?php echo $start_time ?>" />
82 <label
for="phrase">Phrase
</label
>
83 <textarea id
="phrase" name
="phrase"></textarea
>
87 <label
for="range" class="inline">Affect posts made within
:</label
>
88 <select id
="range" name
="range" class="inline">
89 <option value
="28800">Last
8 hours
</option
>
90 <option value
="86400">Last
24 hours
</option
>
91 <option value
="259200">Last
72 hours
</option
>
92 <option value
="604800">Last week
</option
>
93 <option value
="2629743">Last month
</option
>
98 <input type
="submit" name
="exterminate" value
="Clean up this fucking mess" onclick
="confirm('Really?')" />
104 require('includes/footer.php');