[24215] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Easy Captcha |
---|
| 4 | Version: auto |
---|
[24233] | 5 | Description: A fun antibot system for comments, registration, ContactForm and GuestBook. |
---|
[24215] | 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 | |
---|
[26025] | 13 | // TODO : captcha on mobile |
---|
[24215] | 14 | if (mobile_theme()) |
---|
| 15 | { |
---|
| 16 | return; |
---|
| 17 | } |
---|
| 18 | |
---|
[26025] | 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); |
---|
[24215] | 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 | { |
---|
[24234] | 33 | add_event_handler('loc_end_section_init', 'easycaptcha_document_init', EVENT_HANDLER_PRIORITY_NEUTRAL+30); |
---|
[24215] | 34 | } |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | // plugin init |
---|
| 38 | function easycaptcha_init() |
---|
| 39 | { |
---|
| 40 | global $conf, $pwg_loaded_plugins; |
---|
| 41 | |
---|
[26025] | 42 | include_once(EASYCAPTCHA_PATH . 'maintain.inc.php'); |
---|
| 43 | $maintain = new EasyCaptcha_maintain(EASYCAPTCHA_ID); |
---|
| 44 | $maintain->autoUpdate(EASYCAPTCHA_VERSION, 'install'); |
---|
[24215] | 45 | |
---|
| 46 | load_language('plugin.lang', EASYCAPTCHA_PATH); |
---|
| 47 | $conf['EasyCaptcha'] = unserialize($conf['EasyCaptcha']); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | |
---|
[24234] | 51 | // modules |
---|
[24215] | 52 | function easycaptcha_document_init() |
---|
| 53 | { |
---|
[24234] | 54 | global $conf, $pwg_loaded_plugins, $page; |
---|
[24215] | 55 | |
---|
[26025] | 56 | if (!is_a_guest()) |
---|
| 57 | { |
---|
| 58 | return; |
---|
| 59 | } |
---|
[24215] | 60 | |
---|
[26025] | 61 | if (script_basename() == 'register' && $conf['EasyCaptcha']['activate_on']['register']) |
---|
[24215] | 62 | { |
---|
| 63 | $conf['EasyCaptcha']['template'] = 'register'; |
---|
| 64 | include(EASYCAPTCHA_PATH . 'include/register.inc.php'); |
---|
| 65 | } |
---|
[26025] | 66 | else if (script_basename() == 'picture' && $conf['EasyCaptcha']['activate_on']['picture']) |
---|
[24215] | 67 | { |
---|
| 68 | $conf['EasyCaptcha']['template'] = 'comment'; |
---|
| 69 | include(EASYCAPTCHA_PATH . 'include/picture.inc.php'); |
---|
| 70 | } |
---|
[24234] | 71 | else if (isset($page['section'])) |
---|
[24215] | 72 | { |
---|
[24234] | 73 | if ( |
---|
| 74 | script_basename() == 'index' && |
---|
| 75 | $page['section'] == 'categories' && isset($page['category']) && |
---|
| 76 | isset($pwg_loaded_plugins['Comments_on_Albums']) && |
---|
| 77 | $conf['EasyCaptcha']['activate_on']['category'] |
---|
| 78 | ) |
---|
| 79 | { |
---|
| 80 | $conf['EasyCaptcha']['template'] = 'comment'; |
---|
| 81 | include(EASYCAPTCHA_PATH . 'include/category.inc.php'); |
---|
| 82 | } |
---|
[26025] | 83 | else if ($page['section'] == 'contact' && $conf['EasyCaptcha']['activate_on']['contactform']) |
---|
[24234] | 84 | { |
---|
| 85 | $conf['EasyCaptcha']['template'] = 'contactform'; |
---|
| 86 | include(EASYCAPTCHA_PATH . 'include/contactform.inc.php'); |
---|
| 87 | } |
---|
[26025] | 88 | else if ($page['section'] == 'guestbook' && $conf['EasyCaptcha']['activate_on']['guestbook']) |
---|
[24234] | 89 | { |
---|
| 90 | $conf['EasyCaptcha']['template'] = 'guestbook'; |
---|
| 91 | include(EASYCAPTCHA_PATH . 'include/guestbook.inc.php'); |
---|
| 92 | } |
---|
[24215] | 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | // admin |
---|
| 98 | function easycaptcha_plugin_admin_menu($menu) |
---|
| 99 | { |
---|
[26025] | 100 | $menu[] = array( |
---|
[24215] | 101 | 'NAME' => 'Easy Captcha', |
---|
| 102 | 'URL' => EASYCAPTCHA_ADMIN, |
---|
[26025] | 103 | ); |
---|
[24215] | 104 | return $menu; |
---|
| 105 | } |
---|