| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @name: Akismet for Jlog |
|---|
| 4 | * @author: Jeena Paradies <jlog@jeenaparadies.net> |
|---|
| 5 | * @version: 1.0 |
|---|
| 6 | * @date: 2006-12-18 |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | /* |
|---|
| 10 | * This plugin requires the Akismet.class.php in the plugins directory. |
|---|
| 11 | * PHP5: http://www.achingbrain.net/stuff/akismet/ |
|---|
| 12 | * PHP4: http://miphp.net/blog/view/php4_akismet_class |
|---|
| 13 | * |
|---|
| 14 | * And you need a WordPress-Api-Key: http://wordpress.com/api-keys/ |
|---|
| 15 | */ |
|---|
| 16 | if(isset($_SERVER['SCRIPT_FILENAME']) AND __FILE__ == realpath( $_SERVER['SCRIPT_FILENAME'] ) AND $_GET['show'] == "spampic" ) { |
|---|
| 17 | header("Content-Type: image/png"); |
|---|
| 18 | echo base64_decode("iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1QMBFzUfR2tAPwAAAB10RVh0Q29tbWVudABDcmVhdGVkIHdpdGggVGhlIEdJTVDvZCVuAAABYklEQVQoz4WSPUvDUBSG35t7c9um1o+CNQZc1CJi3fzAQR3EzcXZTurgYv+OiAWn+AP0NygoCBWxxUjroCI1EkGbtLm5SR38mGx95udwzvtyCL6priyqkXW7ySnLM5VPEwBSBmUhA7NtGAfZ85IAAAIA1uToEPe84/RAZk5L9YJSCoAgCkN47jveHLvkJ+Jr2UrtiVRXlxm1rFNdH5mLJTT8hfBbqD8/XInhoXm6GzS3BtOZHS3Vh05QxsAo093686vCFbqh9XSWf0gke8CZmmdM5Tna3w8UCl0HlGIRav1pigEAOAdmZ7uvME0ABCyU8ia0X5bo+npXP4oiSBncKCKSZrPx/m+GlteAkIGpKBMTh45jXwi/2VEOhA/Hsa/bxvAeAYC7XFaPNdyTgXRmRkumoFD6e0bL/YDj2Fd+nK+NV2qP5Pc1lhfU9n1tO/ZVXQ4gJAyDsh/KIxjG/tjZpQ8An2Qliwg2VQq3AAAAAElFTkSuQmCC"); |
|---|
| 19 | exit; |
|---|
| 20 | } else { |
|---|
| 21 | |
|---|
| 22 | class AkismetPlugin extends JlogPlugin { |
|---|
| 23 | |
|---|
| 24 | var $spam_count = 0; |
|---|
| 25 | var $actual_spam = false; |
|---|
| 26 | |
|---|
| 27 | function __construct() { |
|---|
| 28 | $this->file = JLOG_BASEPATH.'personal/wpapikey.inc.php'; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | function hook_newComment($form) { |
|---|
| 32 | |
|---|
| 33 | if(is_readable($this->file)) include($this->file); |
|---|
| 34 | if(empty($WordPressAPIKey)) return $form; |
|---|
| 35 | |
|---|
| 36 | require_once(JLOG_BASEPATH.'plugins/Akismet.class.php'); |
|---|
| 37 | |
|---|
| 38 | $akismet = new Akismet(JLOG_PATH.'/', $WordPressAPIKey); |
|---|
| 39 | $akismet->setCommentAuthor($form['name']); |
|---|
| 40 | $akismet->setCommentAuthorEmail($form['email']); |
|---|
| 41 | $akismet->setCommentAuthorURL($form['homepage']); |
|---|
| 42 | $akismet->setCommentContent($form['content']); |
|---|
| 43 | $akismet->setPermalink('http://'.$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]); |
|---|
| 44 | |
|---|
| 45 | if($akismet->isCommentSpam()) { |
|---|
| 46 | $form['type'] = 'spam'; |
|---|
| 47 | $this->actual_spam = $form['sid']; |
|---|
| 48 | return $form; |
|---|
| 49 | } |
|---|
| 50 | else return $form; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | function hook_showComment($comment, $form, $nr) { |
|---|
| 54 | if($form['type'] == 'spam') { |
|---|
| 55 | $this->spam_count++; |
|---|
| 56 | if($this->actual_spam == $form['sid']) |
|---|
| 57 | return error_output(array("Your comment was marked as spam by <a href='http://akismet.com'>Akismet</a>.")); |
|---|
| 58 | } |
|---|
| 59 | // # ist extra an meine seite angeasst |
|---|
| 60 | else |
|---|
| 61 | return str_replace("href='#c".$form['id']."'>".$nr."</a>", "href='#c".$form['id']."'>".((int)$nr - $this->spam_count)."</a>", $comment); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | function hook_commentorMail($mail, $blog) { |
|---|
| 65 | if($this->actual_spam) $mail['nomail'] = true; |
|---|
| 66 | return $mail; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | function hook_adminMail($mail, $blog) { |
|---|
| 70 | if($this->actual_spam) $mail['nomail'] = true; |
|---|
| 71 | return $mail; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | function hook_adminContent() { |
|---|
| 75 | |
|---|
| 76 | $post = strip($_POST); |
|---|
| 77 | $get = strip($_GET); |
|---|
| 78 | if(!empty($post['wpapikey'])) file_put_contents($this->file, '<?php $WordPressAPIKey = "'.$post['wpapikey'].'"; ?>'); |
|---|
| 79 | if(is_readable($this->file)) include($this->file); |
|---|
| 80 | $change2spam = (!empty($get['spam']) AND is_numeric($get['spam'])); |
|---|
| 81 | |
|---|
| 82 | if(!empty($post['form_submit']) OR $change2spam) { |
|---|
| 83 | $change = ""; |
|---|
| 84 | $delete = ""; |
|---|
| 85 | if(is_array($post['spam'])) { |
|---|
| 86 | foreach($post['spam'] AS $key => $value) { |
|---|
| 87 | if($value == "change") $change .= $key.","; |
|---|
| 88 | if($value == "delete") $delete .= $key.","; |
|---|
| 89 | } |
|---|
| 90 | $change = trim($change, ','); |
|---|
| 91 | $delete = trim($delete, ','); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | if($change2spam) $change = $get['spam']; |
|---|
| 95 | if($change OR $change2spam) { |
|---|
| 96 | require_once(JLOG_BASEPATH.'plugins/Akismet.class.php'); |
|---|
| 97 | |
|---|
| 98 | $sql = "SELECT name, email, homepage, content FROM ".JLOG_DB_COMMENTS." WHERE id IN(".$change.")"; |
|---|
| 99 | $comments = new Query($sql); |
|---|
| 100 | if($comments->error()) { |
|---|
| 101 | echo "<pre>\n"; |
|---|
| 102 | echo $comments->getError(); |
|---|
| 103 | echo "</pre>\n"; |
|---|
| 104 | die(); |
|---|
| 105 | } |
|---|
| 106 | while($form = $comments->fetch()) { |
|---|
| 107 | $akismet = new Akismet(JLOG_PATH.'/', $WordPressAPIKey); |
|---|
| 108 | $akismet->setCommentAuthor($form['name']); |
|---|
| 109 | $akismet->setCommentAuthorEmail($form['email']); |
|---|
| 110 | $akismet->setCommentAuthorURL($form['homepage']); |
|---|
| 111 | $akismet->setCommentContent($form['content']); |
|---|
| 112 | # $akismet->setPermalink('http://'.$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]); |
|---|
| 113 | if($change2spam) $akismet->submitSpam(); |
|---|
| 114 | else $akismet->submitHam(); |
|---|
| 115 | } |
|---|
| 116 | $sql = "UPDATE ".JLOG_DB_COMMENTS." SET type = '".($change2spam ? "spam" : "")."' WHERE id IN(".$change.")"; |
|---|
| 117 | $comments = new Query($sql); |
|---|
| 118 | if($comments->error()) { |
|---|
| 119 | echo "<pre>\n"; |
|---|
| 120 | echo $comments->getError(); |
|---|
| 121 | echo "</pre>\n"; |
|---|
| 122 | die(); |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | if($delete) { |
|---|
| 126 | $sql = "DELETE FROM ".JLOG_DB_COMMENTS." WHERE id IN(".$delete.")"; |
|---|
| 127 | $comments = new Query($sql); |
|---|
| 128 | if($comments->error()) { |
|---|
| 129 | echo "<pre>\n"; |
|---|
| 130 | echo $comments->getError(); |
|---|
| 131 | echo "</pre>\n"; |
|---|
| 132 | die(); |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | return " |
|---|
| 138 | <form action='' method='POST'> |
|---|
| 139 | <p><a href='http://wordpress.com/api-keys/'>WordPress API Key</a>:<br /> |
|---|
| 140 | <input name='wpapikey' value='$WordPressAPIKey' /><input type='submit' value='save' /> |
|---|
| 141 | </p> |
|---|
| 142 | </form>".$this->spam_list(); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | function hook_countComments($com) { |
|---|
| 146 | $sql = "SELECT reference, COUNT(*) as count FROM ".JLOG_DB_COMMENTS." WHERE type <> 'pingback' AND type <> 'spam' GROUP BY reference"; |
|---|
| 147 | $comments = new Query($sql); |
|---|
| 148 | if($comments->error()) { |
|---|
| 149 | echo "<pre>\n"; |
|---|
| 150 | echo $comments->getError(); |
|---|
| 151 | echo "</pre>\n"; |
|---|
| 152 | die(); |
|---|
| 153 | } |
|---|
| 154 | $com = array(); |
|---|
| 155 | while($c = $comments->fetch()) $com[$c['reference']] = $c['count']; |
|---|
| 156 | |
|---|
| 157 | return $com; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | function hook_commentAdminList($comment, $data) { |
|---|
| 161 | if($data['type'] == 'spam') return; |
|---|
| 162 | global $l; |
|---|
| 163 | return str_replace("/img/JLOG_trash.png' alt='".$l['admin']['delete']."' /></a>", "/img/JLOG_trash.png' alt='".$l['admin']['delete']."' /></a> <a title='Spam' href='plugin.php?jplug=AkismetPlugin&spam=".$data['id']."'><img src='".JLOG_PATH."/plugins/AkismetPlugin.jplug.php?show=spampic"."' alt='spam' /></a>", $comment); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | function spam_list() { |
|---|
| 167 | |
|---|
| 168 | global $l; |
|---|
| 169 | $get = strip($_GET); |
|---|
| 170 | $yl = new Year_Links($get['y'], JLOG_START_YEAR, JLOG_PATH."/admin/plugin.php?jplug=AkismetPlugin", $l['admin']); |
|---|
| 171 | |
|---|
| 172 | $output = "<p>".$yl->get_admin_linklist()."</p><form action='plugin.php?jplug=AkismetPlugin' method='POST'><table> |
|---|
| 173 | <tr> |
|---|
| 174 | <th></th><th>".$l['admin']['change']." (no spam)</th><th>".$l['admin']['delete']."</th><th>ID</th><th>".$l['comments_name']."</th><th>".$l['comments_posted']."</th><th>".$l['admin']['kill_c_entry']."</th> |
|---|
| 175 | </tr>"; |
|---|
| 176 | |
|---|
| 177 | $sql = "SELECT |
|---|
| 178 | ".JLOG_DB_COMMENTS.".id AS id, |
|---|
| 179 | ".JLOG_DB_CONTENT.".url AS url, |
|---|
| 180 | UNIX_TIMESTAMP(".JLOG_DB_CONTENT.".date) AS reference_date, |
|---|
| 181 | UNIX_TIMESTAMP(".JLOG_DB_COMMENTS.".date) AS date, |
|---|
| 182 | ".JLOG_DB_COMMENTS.".name AS name, |
|---|
| 183 | ".JLOG_DB_CONTENT.".topic AS topic, |
|---|
| 184 | ".JLOG_DB_COMMENTS.".email AS email |
|---|
| 185 | FROM ".JLOG_DB_COMMENTS.", ".JLOG_DB_CONTENT." |
|---|
| 186 | WHERE ".JLOG_DB_COMMENTS.".reference = ".JLOG_DB_CONTENT.".id |
|---|
| 187 | AND YEAR(".JLOG_DB_COMMENTS.".date) = '".$yl->get_selected_year()."' |
|---|
| 188 | AND type = \"spam\" |
|---|
| 189 | ORDER BY id DESC;"; |
|---|
| 190 | |
|---|
| 191 | $comments = new Query($sql); |
|---|
| 192 | if($comments->error()) { |
|---|
| 193 | echo "<pre>\n"; |
|---|
| 194 | echo $comments->getError(); |
|---|
| 195 | echo "</pre>\n"; |
|---|
| 196 | die(); |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | while ($daten = $comments->fetch()) { |
|---|
| 200 | if(!empty($daten['name'])) $daten['name'] = htmlspecialchars($daten['name'], ENT_QUOTES); |
|---|
| 201 | else $daten['name'] = $l['comments_anonym']; |
|---|
| 202 | if(!empty($daten['email'])) $email = "<a href='mailto:".$daten['email']."'>".$daten['name']."</a>"; |
|---|
| 203 | else $email = $daten['name']; |
|---|
| 204 | |
|---|
| 205 | $output .= " |
|---|
| 206 | <tr> |
|---|
| 207 | <td><input type='radio' name='spam[".$daten['id']."]' value='' checked='checked' /></td> |
|---|
| 208 | <td><input type='radio' name='spam[".$daten['id']."]' value='change' /></td> |
|---|
| 209 | <td><input type='radio' name='spam[".$daten['id']."]' value='delete' /></td> |
|---|
| 210 | <td><a href='".blog($daten['reference_date'], $daten['url'])."#c".$daten['id']."'>".$daten['id']."</a></td> |
|---|
| 211 | <td>".$email."</td> |
|---|
| 212 | <td>".strftime(JLOG_DATE_COMMENT, $daten['date'])."</td> |
|---|
| 213 | <td>".$daten['topic']."</td> |
|---|
| 214 | </tr>"; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | $output .= " |
|---|
| 218 | <script type='text/javascript'> |
|---|
| 219 | document.write(\"<tr><td><input name='akismet' type='radio' onclick='jlog_akismet_checkall(this, 0);' checked='checked' /></td><td><input name='akismet' type='radio' onclick='jlog_akismet_checkall(this, 1);' /></td><td><input name='akismet' type='radio' onclick='jlog_akismet_checkall(this, 2);' /></td><td colspan='4'></td></tr>\") |
|---|
| 220 | function jlog_akismet_checkall(table, column) { |
|---|
| 221 | var trs = table.parentNode.parentNode.parentNode.getElementsByTagName('tr'); |
|---|
| 222 | for(var i=0; i<trs.length; i++) { |
|---|
| 223 | if(trs[i].getElementsByTagName('input')[column]) trs[i].getElementsByTagName('input')[column].checked = 'checked'; |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | </script> |
|---|
| 227 | </table> |
|---|
| 228 | "; |
|---|
| 229 | |
|---|
| 230 | return $output."<p><input type='submit' value='GO!' name='form_submit' /></p></form>"; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | } |
|---|
| 236 | ?> |
|---|