source: extensions/EasyCaptcha/main.inc.php @ 24233

Last change on this file since 24233 was 24233, checked in by mistic100, 11 years ago

error when open_basedir restriction in effect

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