source: extensions/rv_akismet/main.inc.php @ 14518

Last change on this file since 14518 was 13799, checked in by rvelices, 12 years ago

rv_akismet - added a technique to detect robots (as of today my tests show 100% spams caught) :)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1<?php /*
2Plugin Name: RV Akismet
3Version: 2.4.a
4Description: Uses Akismet online service to check comments agains spam
5Plugin URI: http://piwigo.org/ext/extension_view.php?eid=192
6Author: rvelices
7Author URI: http://www.modusoptimus.com
8*/
9
10define('AKIS_DIR' , basename(dirname(__FILE__)));
11define('AKIS_PATH' , PHPWG_PLUGINS_PATH . AKIS_DIR . '/');
12
13add_event_handler('user_comment_check', 'akismet_user_comment_check_wrapper', EVENT_HANDLER_PRIORITY_NEUTRAL+10, 2);
14add_event_handler('loc_begin_page_tail', 'akismet_page_tail' );
15
16
17add_event_handler('get_admin_plugin_menu_links', 'akismet_plugin_admin_menu' );
18add_event_handler('init', 'akismet_init' );
19
20
21function akismet_plugin_admin_menu($menu)
22{
23        global $page,$conf;
24        if ( empty($conf['akismet_api_key']) and in_array($page['page'], array('intro','plugins_list')) )
25        {
26                load_language('plugin.lang', AKIS_PATH);
27                $page['errors'][] = l10n('You need to define the Akismet api key');
28        }
29        $admin_url = get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php');
30        array_push($menu,
31                        array(
32                                'NAME' => 'Akismet',
33                                'URL' => $admin_url
34                        )
35                );
36        return $menu;
37}
38
39
40function akismet_user_comment_check_wrapper($action, $comment)
41{
42        include_once( dirname(__FILE__).'/check.inc.php' );
43        $action = akismet_user_comment_check($action, $comment);
44        if (!isset($_SESSION['csi']) && isset($_POST['url']) && strlen($_POST['url']) )
45        {
46                $action = 'reject';
47                $_POST['cr'][] = 'csi url';
48        }
49        return $action;
50}
51
52function akismet_init()
53{
54        global $template;
55        $template->smarty->register_prefilter('akismet_prefilter_comment_form');
56}
57
58function akismet_prefilter_comment_form($source, $smarty)
59{
60        if ( ($pos=strpos($source, '<textarea'))!==false
61                && ($pos2=strpos($source, 'comment', $pos))!==false
62                && $pos2-$pos <300)
63        {
64                $source= substr_replace($source, '{html_style}#urlid{ldelim}display:none}{/html_style}<input type="text" name="url" id="urlid">', $pos,0);
65        }
66        return $source;
67}
68
69function akismet_page_tail()
70{
71        global $template, $conf;
72        if (!isset($_SESSION['csi']) && strpos($_SERVER['HTTP_USER_AGENT'],'bot')===false)
73        {
74                $src = get_root_url().'plugins/'.AKIS_DIR.'/csi.php';
75                $template->append( 'footer_elements', '<img src="'.$src.'" width=0 height=0>');
76        }
77}
78
79?>
Note: See TracBrowser for help on using the repository browser.