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