Mod/Hack: Adding Akismet spam-checking to Coppermine commenting - Page 5 Mod/Hack: Adding Akismet spam-checking to Coppermine commenting - Page 5
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Mod/Hack: Adding Akismet spam-checking to Coppermine commenting

Started by pharaohweb, July 13, 2006, 07:09:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DJTG

Is akismet still alive? I tried all methods posted in this Thread but can't get it to work. It seems it doenst filter any spam comments i try (also the examples by gau-gau). At the moment i am using the hack from fcollingwood and got the same prob.


fcollingwood

The methods have probably changed again. You'll need to have a look at the Akismet plugin, and modify the hack accordingly

jesusarmy

Quote from: deandre81 on July 07, 2007, 09:47:53 PM
is any of this up to date cause i got the akismet but it only comes as a 28kb file named "akismet.php" along with a gif image file "akismet.gif"
version 2.0
or have i downloaded the wrong thing....
because i get a blank screen in firefox but get this error in explorer
Fatal error: Call to undefined function: add_action() in /home/content/d/e/a/deandre81/html/coppermine/akismet.php on line 25


You downloaded the wrong file: the correct one is PHP5 Class or PHP4 Class (depending on your version of PHP) on http://akismet.com/development/

For the sake of completeness, this is what the relevant sections of my PHP4 mod look like now, updated to reflect the new PHP4 Class version of akismet.class.php:
        $WordPressAPIKey =  'xxxxxxxxxxx'; // Put your API key here
        $MyBlogURL = 'http://www.jesus.org.uk/gallery/displayimage.php?album=lastcom&cat=0&pos=0';

        // load array with comment data
        $comment = array(
            'author'       => $msg_author,
            //'email'        => $email,
            //'website'      => $url,
            'body'         => $msg_body,
            'permalink'    => $MyBlogURL,
        );
        // instantiate an instance of the class
        $akismet = new Akismet($MyBlogURL,$WordPressAPIKey,$comment);

        // Check for spam
        if ($akismet->isSpam()) { // returns true if Akismet thinks the comment is spam
            // do something with the spam comment
            // store the comment but mark it as spam (in case of a mis-diagnosis)
            if (!isset($lang_errors['spam_found'])) $lang_errors['spam_found'] = 'Spam?' . $lang_errors['perm_denied'];
            cpg_die(ERROR, $lang_errors['spam_found'], __FILE__, __LINE__);
        } else {
            // do something with the non-spam comment
            // store the comment normally
            $insert = cpg_db_query("INSERT INTO {$CONFIG['TABLE_COMMENTS']} (pid, msg_author, msg_body, msg_date, author_md5_id, author_id, msg_raw_ip, msg_hdr_ip) VALUES ('$pid', '{$CONFIG['comments_anon_pfx']}$msg_author', '$msg_body', NOW(), '{$USER['ID']}', '0', '$raw_ip', '$hdr_ip')");
        }

/*
        $insert = cpg_db_query("INSERT INTO {$CONFIG['TABLE_COMMENTS']} (pid, msg_author, msg_body, msg_date, author_md5_id, author_id, msg_raw_ip, msg_hdr_ip) VALUES ('$pid', '" . addslashes(USER_NAME) . "', '$msg_body', NOW(), '', '" . USER_ID . "', '$raw_ip', '$hdr_ip')");
*/


However, the process is interminably slow, and I'm not sure if I will be using it.

Scott O

Okay, I just read over the entire thread, but I'm not a developer or PHP expert, so I'm really confused.

Since the original instructions appeared, it looks like there have been a lot of modifications, etc.  I'm not sure which ones to add and which ones are obsolete.  I'm wondering if someone could update the instructions with all the updates, etc, to something really simple for an idiot like me.

I'm using PHP5 which I guess makes a big difference.

Thanks.

dannypritchett01

I did what it said on page 1, as well as what is mentioned below.

Quote from: JLB on June 06, 2007, 03:00:47 PM
^^OK, I've solved my problem, and this may help others as well.

I was only looking at the "Last Comments" page as an anonymous user to determine whether it was working properly.  What I eventually figured out was that it WAS blocking spam comments from being shown with individual pictures, but not on the "Last Comments" page.

Since this is the page my wife tends to view most often, it was important to me to get this fixed.

****************************
DISCLAIMER:
I'm NOT a PHP or SQL Expert. 
I'm NOT EVEN a PHP noob.
The only testing that was done was that this fixed MY problem on MY Coppermine 1.4.10 install.
****************************

It appears that the comments shown on the "Last Comments" page are queried from the section of code that begins on Line 963 of functions.inc.php (in /include)

I made very minor changes to two queries in this section, and it seems to have fixed the problem.

The first is on Line 979

The ORIGINAL, UMODIFIED QUERY:
$query = "SELECT COUNT(*) from {$CONFIG['TABLE_COMMENTS']}, {$CONFIG['TABLE_PICTURES']}  WHERE approved = 'YES' AND {$CONFIG['TABLE_COMMENTS']}.pid = {$CONFIG['TABLE_PICTURES']}.pid $TMP_SET $keyword)";

All I did was ad an "AND" to check that is_spam=0.  If you don't change this query, your spam comments will still be masked, but it will count ALL the records, and show you empty pages where the spam comments would be.

Modify the above query to match this:
$query = "SELECT COUNT(*) from {$CONFIG['TABLE_COMMENTS']}, {$CONFIG['TABLE_PICTURES']}  WHERE approved = 'YES' AND {$CONFIG['TABLE_COMMENTS']}.is_spam = 0 AND {$CONFIG['TABLE_COMMENTS']}.pid = {$CONFIG['TABLE_PICTURES']}.pid $TMP_SET $keyword)";


One more query to do.  It's on line 993.  This is the one that actually loads the comments (vs counting the comments it intends to load).

This is the ORIGINAL, UNMODIFIED QUERY:
$query = "SELECT $select_columns FROM {$CONFIG['TABLE_COMMENTS']} as c, {$CONFIG['TABLE_PICTURES']} as p WHERE approved = 'YES' AND c.pid = p.pid $TMP_SET $keyword) ORDER by msg_id DESC $limit";

Again, I just added an AND.  Modify it to match this:
$query = "SELECT $select_columns FROM {$CONFIG['TABLE_COMMENTS']} as c, {$CONFIG['TABLE_PICTURES']} as p WHERE approved = 'YES' AND c.pid = p.pid AND c.is_spam = 0 $TMP_SET $keyword) ORDER by msg_id DESC $limit";

I don't know enough to know whether it will be in exactly the same place on every install, nor whether functions.inc.php is the same on every 1.4.10 install, so that's why I thought it would be better to just post exactly what I did.  It does, however, work.

Joe

akismet.class.php version 0.3.4

var $blogUrl = "http://www.dannysgamefowlfarm.com/cpg/";
var $apiKey  = "MY KEY REMOVED";
var $comment = array();
.....................skip a lot of code.....
function _formatCommentArray() {
$format = array(
'type' => 'comment_type',
'author' => 'comment_author',
'email' => 'comment_author_email',
'website' => 'comment_author_url',
'body' => 'comment_content'
);


db_input.php


include 'akismet.class.php';
define('IN_COPPERMINE', true);
define('DB_INPUT_PHP', true);

require('include/init.inc.php');
require('include/picmgmt.inc.php');
require('include/mailer.inc.php');
require('include/smilies.inc.php');

... skip a lot of lines...

$WordPressAPIKey =  '....my key removed....';
$MyBlogURL = 'http://www.dannysgamefowlfarm.com/cpg/';
$name = $msg_author;
$comment = $msg_body;

$akismet = new Akismet($MyBlogURL ,$WordPressAPIKey);
$akismet->setAuthor($name);
$akismet->setAuthorEmail($email);
$akismet->setAuthorURL($url);
$akismet->setContent($comment);
$akismet->setPermalink('http://www.dannysgamefowlfarm.com/cpg/displayimage.php?album=lastcom&cat=0&pos=18');

if($akismet->isSpam())
    // store the comment but mark it as spam (in case of a mis-diagnosis)
    cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
else
    // store the comment normally
    $insert = cpg_db_query("INSERT INTO {$CONFIG['TABLE_COMMENTS']} (pid, msg_author, msg_body, msg_date, author_md5_id, author_id, msg_raw_ip, msg_hdr_ip) VALUES ('$pid', '{$CONFIG['comments_anon_pfx']}$msg_author', '$msg_body', NOW(), '{$USER['ID']}', '0', '$raw_ip', '$hdr_ip')");



and of course my funcions.inc.php was modified as stated above. When I post a spam message such as buy levitra online | http://buy-levitra-online.mabulle.com/ it posts it as if the hack was never made. Yet when I click "last comments" i get this error...

There was an error while processing a database query

Use this if you wish to test...

User: test
Pass: testpass

I have to work tonight so I will be home around 10-11pm. Hopefully we can figure it out. Ive been getting users in my gallery posting the same spam message on every photo. Its annoying.

dannypritchett01

Where is the edit on this message board? I tried to edit my last post...

I changed my db_input.php as mentioned in the akismet class usate code below to the code at the end of the post but still nothing working and spam still gets entered...

* <code>
*    $comment = array(
*           'author'    => 'viagra-test-123',
*           'email'     => 'test@example.com',
*           'website'   => 'http://www.example.com/',
*           'body'      => 'This is a test comment',
*           'permalink' => 'http://yourdomain.com/yourblogpost.url',
*        );
*
*    $akismet = new Akismet('http://www.yourdomain.com/';, 'YOUR_WORDPRESS_API_KEY', $comment);
*
*    if($akismet->errorsExist()) {
*        echo"Couldn't connected to Akismet server!";
*    } else {
*        if($akismet->isSpam()) {
*            echo"Spam detected";
*        } else {
*            echo"yay, no spam!";
*        }
*    }
* </code>

updated code in db_input.php

   $WordPressAPIKey =  'xxx';
$MyBlogURL = 'http://www.dannysgamefowlfarm.com/cpg/';
$name = $msg_author;
$comment = $msg_body;

$akismet = new Akismet($MyBlogURL ,$WordPressAPIKey);
$akismet->setauthor($name);
$akismet->setemail($email);
$akismet->setwebsite($url);
$akismet->setbody($comment);
$akismet->setpermalink('http://www.dannysgamefowlfarm.com/cpg/displayimage.php?album=lastcom&cat=0&pos=18');

if($akismet->isSpam())
    // store the comment but mark it as spam (in case of a mis-diagnosis)
    cpg_die(ERROR, $lang_errors['perm_denied'], __FILE__, __LINE__);
else
    // store the comment normally
    $insert = cpg_db_query("INSERT INTO {$CONFIG['TABLE_COMMENTS']} (pid, msg_author, msg_body, msg_date, author_md5_id, author_id, msg_raw_ip, msg_hdr_ip) VALUES ('$pid', '{$CONFIG['comments_anon_pfx']}$msg_author', '$msg_body', NOW(), '{$USER['ID']}', '0', '$raw_ip', '$hdr_ip')");

Nibbler

You post code that applies this mod to anonymous users but yet you test with a registered user. The code change does not affect that.

dannypritchett01

oh ok. Would you please edit the post and remove the api key, I accidently posted it with my last post and I can not find a edit or modify button as the help section says.

Scott O

After reading through this entire board (again), I'm still confused on implementing this.

Since the original post there have been several modifications, etc.  My questions:

-Should I still follow the instructions in the original post (i.e. have they been updated)?  If not, has anyone combined all the updates, fixes, etc, into a new set of instructions?

-Does this work with PHP 5?  I can't discern whether or not it does merely by reading this thread.

-There was talk of making this into a plug-in for Coppermine.  Did anyone ever do that?  (I would, but I don't have the skillz!)

Thanks in advance for any info you can share.

totalcollection

Which one to download then?

Libraries

    * David Lynch's Python library
    * Voidspace Python module
    * PHP 5 class by Alex
    * PHP 4 class by Bret Kuhns
    * Micro-Akismet PHP class by Gaby Vanhegan
    * CFAkismet for Coldfusion
    * Net::Akismet Perl module on CPAN
    * David Czarnecki's Java API
    * David Czarnecki's Ruby API
    * Ruby on Rails plugin
    * Lasso API
    * Akismet .Net 2.0 API Library
    * Akismet .Net 1.1 API Library
    * Code Igniter (PHP) Library
Total Wallpaper Collection
We collect everything for your desktop look and feel!
http://www.totalcollection.info

totalcollection

Total Wallpaper Collection
We collect everything for your desktop look and feel!
http://www.totalcollection.info

totalcollection

strange when I tried to enter some comments, it returned: include 'Akismet.class.php';

Any solution, please?
Total Wallpaper Collection
We collect everything for your desktop look and feel!
http://www.totalcollection.info

totalcollection

Edit: Seems to work fine now. Anyway, I attempted to do some spam by entering many links, and it returns this:

You don't have permission to perform this operation. 

Is this the correct behavior from my setup of Akismet? If so, I am now free from SPAM!!!
BRAVO
Total Wallpaper Collection
We collect everything for your desktop look and feel!
http://www.totalcollection.info

uglycars

I get this error after doing the mod:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/40/d237348395/htdocs/uglycars/photo/gallery/Akismet.class.php on line 66

I also put the db_input.php mod here:
require('Akismet.class.php');
require('include/init.inc.php');
require('include/picmgmt.inc.php');
require('include/mailer.inc.php');
require('include/smilies.inc.php');

is that correct?

archiski123

 ???

I tried implementing this.  Unfortunatley I now very little about PHP.  I have tried with both PHP4 and PHP5. 
I do believe that I have read the entire thread (about 3 times). 

My problem I believe is more basic. when I try to add a comment, I get :

Fatal error: require() [function.require]: Failed opening required 'include/akismet.class.php' (include_path='.:/usr/local/php5/lib/php') in /home/skildum/www/www/darcarphoto/db_input.php on line 27

I assume there is something someplace that sets the include_path, but I do not know how or where. 

You can see my site in the error message. 

Any Ideas??

Nibbler

What do you have on line 27? The instructions say to put


include 'Akismet.class.php';


The error message says you put something different.

Post a link to your gallery so we can see if you uploaded Akismet.class.php to the correct location.

archiski123

I did get it figured it out.  The problem in following the entire thread, that some indicated a
Requires('include......).  I thought that was how some people had made it work. 

I did go back to the plain old include, and now it works. 

Thank you for getting back to me. 

dwo

Works wonderful. Thank you.

It is important that you dont use your existing blog aksimet key, but get a new one at the website of akismet.

That was my problem with getting the white screen..


regards

JoniW

I have no idea how to mess with any of this stuff. Is is just wise then, to makes sure you approve of all comments so that you can week them out via email and approve the ligit ones?

If I knew any of this hack business, I'd try it but for me I'd say I am Artist Jim not a damn Hacker!  :D

hlabout

Running cpg 1.4.26 on PHP version 4.4.7 on my gallery www.haraldlabout.nl
Downloaded PHP 4 class library from askimet.com
Installed mod and applied modifications by fcollingwood's.
Working fine so far, no waiting and see if the spam comments disappear.

Harald