[6506] | 1 | <?php |
---|
[26859] | 2 | function akismet_user_comment_check($action, $comment, $where) |
---|
[6506] | 3 | { |
---|
| 4 | global $conf; |
---|
| 5 | if ('reject'==$action or $conf['akismet_spam_action']==$action) |
---|
| 6 | return $action; // already rejecting |
---|
| 7 | if ( empty($conf['akismet_api_key']) ) |
---|
| 8 | return $action; // need to config it |
---|
| 9 | /*if ( !is_a_guest() ) |
---|
| 10 | return $action;*/ |
---|
| 11 | |
---|
| 12 | include_once( dirname(__FILE__).'/akismet.class.php' ); |
---|
| 13 | |
---|
| 14 | set_make_full_url(); |
---|
[26859] | 15 | switch($where) |
---|
| 16 | { |
---|
| 17 | case 'guestbook': |
---|
| 18 | $url = defined('GUESTBOOK_URL') ? GUESTBOOK_URL : get_absolute_root_url(); |
---|
| 19 | break; |
---|
| 20 | case 'album': |
---|
| 21 | // build category url with minimum data (only id is always known) |
---|
| 22 | $url = duplicate_index_url( array( |
---|
| 23 | 'section'=>'categories', |
---|
| 24 | 'category'=>array('id'=>$comment['category_id'], 'name'=>'', 'permalink'=>'') |
---|
| 25 | ) ); |
---|
| 26 | break; |
---|
| 27 | default: |
---|
| 28 | $url = duplicate_picture_url( array('image_id'=>$comment['image_id']) ); |
---|
| 29 | } |
---|
[6506] | 30 | unset_make_full_url(); |
---|
[26859] | 31 | |
---|
[6506] | 32 | $aki_comm = array( |
---|
| 33 | 'author' => $comment['author'], |
---|
| 34 | 'body' => $comment['content'], |
---|
[18945] | 35 | 'comment_author_url' => $comment['website_url'], |
---|
| 36 | 'comment_author_email' => $comment['email'], |
---|
[6506] | 37 | 'permalink' => $url, |
---|
| 38 | 'referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', |
---|
| 39 | ); |
---|
[18945] | 40 | /*if (isset($_POST['url']) && strlen($_POST['url'])) |
---|
| 41 | $aki_comm['comment_author_url'] = $_POST['url'];*/ |
---|
[6506] | 42 | |
---|
| 43 | $akismet = new Akismet(get_absolute_root_url(), $conf['akismet_api_key'], $aki_comm); |
---|
| 44 | |
---|
| 45 | if( !$akismet->errorsExist() ) |
---|
| 46 | { |
---|
| 47 | $counters = explode('/', $conf['akismet_counters']); |
---|
| 48 | if ( $akismet->isSpam() ) |
---|
| 49 | { |
---|
| 50 | $action = $conf['akismet_spam_action']; |
---|
[16004] | 51 | if ('reject'==$action && !is_a_guest() && isset($_SESSION['csi']) && (!isset($_POST['url']) || strlen($_POST['url'])==0)) |
---|
[15837] | 52 | $action='moderate'; |
---|
[6506] | 53 | if ('reject'!=$action) set_status_header(403); |
---|
| 54 | $counters[0]++; |
---|
[13799] | 55 | $_POST['cr'][] = 'aki'; |
---|
[6506] | 56 | } |
---|
[13799] | 57 | else |
---|
[15837] | 58 | { |
---|
[13799] | 59 | $_POST['cr'][] = 'aki-ok'; |
---|
[18945] | 60 | if (!isset($_SESSION['csi']) /*&& isset($_POST['url']) && strlen($_POST['url']) */) |
---|
[15837] | 61 | { |
---|
[18945] | 62 | $action = 'moderate'; |
---|
| 63 | $_POST['cr'][] = 'csi'; |
---|
[15837] | 64 | } |
---|
| 65 | } |
---|
[6506] | 66 | $counters[1]++; |
---|
| 67 | $conf['akismet_counters'] = implode('/', $counters); |
---|
| 68 | $query = 'UPDATE '.CONFIG_TABLE.' SET value="'.$conf['akismet_counters'].'" WHERE param="akismet_counters" LIMIT 1'; |
---|
| 69 | pwg_query($query); |
---|
| 70 | } |
---|
[13799] | 71 | else { |
---|
| 72 | $_POST['cr'][] = 'aki-FAIL'; |
---|
| 73 | if (is_admin()) |
---|
| 74 | var_export( $akismet->getErrors() ); |
---|
| 75 | } |
---|
[6506] | 76 | |
---|
| 77 | return $action; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | ?> |
---|