1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Easy Captcha |
---|
4 | Version: auto |
---|
5 | Description: A fun antibot system for comments, registration, ContactForm and GuestBook. |
---|
6 | Plugin URI: auto |
---|
7 | Author: Mistic |
---|
8 | Author URI: http://www.strangeplanet.fr |
---|
9 | */ |
---|
10 | |
---|
11 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
12 | |
---|
13 | // TODO : captcha on mobile |
---|
14 | if (mobile_theme()) |
---|
15 | { |
---|
16 | return; |
---|
17 | } |
---|
18 | |
---|
19 | define('EASYCAPTCHA_ID', basename(dirname(__FILE__))); |
---|
20 | define('EASYCAPTCHA_PATH' , PHPWG_PLUGINS_PATH . EASYCAPTCHA_ID . '/'); |
---|
21 | define('EASYCAPTCHA_ADMIN', get_root_url() . 'admin.php?page=plugin-' . EASYCAPTCHA_ID); |
---|
22 | define('EASYCAPTCHA_VERSION', 'auto'); |
---|
23 | |
---|
24 | |
---|
25 | add_event_handler('init', 'easycaptcha_init'); |
---|
26 | |
---|
27 | if (defined('IN_ADMIN')) |
---|
28 | { |
---|
29 | add_event_handler('get_admin_plugin_menu_links', 'easycaptcha_plugin_admin_menu'); |
---|
30 | } |
---|
31 | else |
---|
32 | { |
---|
33 | add_event_handler('loc_end_section_init', 'easycaptcha_document_init', EVENT_HANDLER_PRIORITY_NEUTRAL+30); |
---|
34 | add_event_handler('loc_begin_register', 'easycaptcha_register_init', EVENT_HANDLER_PRIORITY_NEUTRAL+30); |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | // plugin init |
---|
39 | function easycaptcha_init() |
---|
40 | { |
---|
41 | global $conf, $pwg_loaded_plugins; |
---|
42 | |
---|
43 | include_once(EASYCAPTCHA_PATH . 'maintain.inc.php'); |
---|
44 | $maintain = new EasyCaptcha_maintain(EASYCAPTCHA_ID); |
---|
45 | $maintain->autoUpdate(EASYCAPTCHA_VERSION, 'install'); |
---|
46 | |
---|
47 | load_language('plugin.lang', EASYCAPTCHA_PATH); |
---|
48 | $conf['EasyCaptcha'] = unserialize($conf['EasyCaptcha']); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | // modules |
---|
53 | function easycaptcha_document_init() |
---|
54 | { |
---|
55 | global $conf, $pwg_loaded_plugins, $page; |
---|
56 | |
---|
57 | if (!is_a_guest()) |
---|
58 | { |
---|
59 | return; |
---|
60 | } |
---|
61 | |
---|
62 | if (script_basename() == 'picture' && $conf['EasyCaptcha']['activate_on']['picture']) |
---|
63 | { |
---|
64 | include(EASYCAPTCHA_PATH . 'include/picture.inc.php'); |
---|
65 | } |
---|
66 | else if (isset($page['section'])) |
---|
67 | { |
---|
68 | if ( |
---|
69 | script_basename() == 'index' && |
---|
70 | $page['section'] == 'categories' && isset($page['category']) && |
---|
71 | isset($pwg_loaded_plugins['Comments_on_Albums']) && |
---|
72 | $conf['EasyCaptcha']['activate_on']['category'] |
---|
73 | ) |
---|
74 | { |
---|
75 | include(EASYCAPTCHA_PATH . 'include/category.inc.php'); |
---|
76 | } |
---|
77 | else if ($page['section'] == 'contact' && $conf['EasyCaptcha']['activate_on']['contactform']) |
---|
78 | { |
---|
79 | include(EASYCAPTCHA_PATH . 'include/contactform.inc.php'); |
---|
80 | } |
---|
81 | else if ($page['section'] == 'guestbook' && $conf['EasyCaptcha']['activate_on']['guestbook']) |
---|
82 | { |
---|
83 | include(EASYCAPTCHA_PATH . 'include/guestbook.inc.php'); |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | function easycaptcha_register_init() |
---|
88 | { |
---|
89 | global $conf; |
---|
90 | |
---|
91 | if (!is_a_guest()) |
---|
92 | { |
---|
93 | return; |
---|
94 | } |
---|
95 | |
---|
96 | if ($conf['EasyCaptcha']['activate_on']['register']) |
---|
97 | { |
---|
98 | include(EASYCAPTCHA_PATH . 'include/register.inc.php'); |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | // admin |
---|
104 | function easycaptcha_plugin_admin_menu($menu) |
---|
105 | { |
---|
106 | $menu[] = array( |
---|
107 | 'NAME' => 'Easy Captcha', |
---|
108 | 'URL' => EASYCAPTCHA_ADMIN, |
---|
109 | ); |
---|
110 | return $menu; |
---|
111 | } |
---|