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

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

error with question_mark_in_urls=false, restore full language keys
+ de_DE for icons.lang.php

File size: 3.3 KB
RevLine 
[24215]1<?php
2/*
3Plugin Name: Easy Captcha
4Version: auto
[24233]5Description: A fun antibot system for comments, registration, ContactForm and GuestBook.
[24215]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{
[24234]33  add_event_handler('loc_end_section_init', 'easycaptcha_document_init', EVENT_HANDLER_PRIORITY_NEUTRAL+30);
[24215]34}
35
36
37// plugin init
38function easycaptcha_init()
39{
40  global $conf, $pwg_loaded_plugins;
41
42  if (
43    EASYCAPTCHA_VERSION == 'auto' or
44    $pwg_loaded_plugins[EASYCAPTCHA_ID]['version'] == 'auto' or
45    version_compare($pwg_loaded_plugins[EASYCAPTCHA_ID]['version'], EASYCAPTCHA_VERSION, '<')
46  )
47  {
48    include_once(EASYCAPTCHA_PATH . 'include/install.inc.php');
49    easycaptcha_install();
50
51    if ( $pwg_loaded_plugins[EASYCAPTCHA_ID]['version'] != 'auto' && EASYCAPTCHA_VERSION != 'auto' )
52    {
53      $query = '
54UPDATE '. PLUGINS_TABLE .'
55SET version = "'. EASYCAPTCHA_VERSION .'"
56WHERE id = "'. EASYCAPTCHA_ID .'"';
57      pwg_query($query);
58
59      $pwg_loaded_plugins[EASYCAPTCHA_ID]['version'] = EASYCAPTCHA_VERSION;
60    }
61  }
62
63  load_language('plugin.lang', EASYCAPTCHA_PATH);
64  $conf['EasyCaptcha'] = unserialize($conf['EasyCaptcha']);
65}
66
67
[24234]68// modules
[24215]69function easycaptcha_document_init()
70{
[24234]71  global $conf, $pwg_loaded_plugins, $page;
[24215]72
73  if (!is_a_guest()) return;
74
75  if ( script_basename() == 'register' && $conf['EasyCaptcha']['activate_on']['register'] )
76  {
77    $conf['EasyCaptcha']['template'] = 'register';
78    include(EASYCAPTCHA_PATH . 'include/register.inc.php');
79  }
80  else if ( script_basename() == 'picture' && $conf['EasyCaptcha']['activate_on']['picture'] )
81  {
82    $conf['EasyCaptcha']['template'] = 'comment';
83    include(EASYCAPTCHA_PATH . 'include/picture.inc.php');
84  }
[24234]85  else if (isset($page['section']))
[24215]86  {
[24234]87    if (
88      script_basename() == 'index' &&
89      $page['section'] == 'categories' && isset($page['category']) &&
90      isset($pwg_loaded_plugins['Comments_on_Albums']) &&
91      $conf['EasyCaptcha']['activate_on']['category']
92      )
93    {
94      $conf['EasyCaptcha']['template'] = 'comment';
95      include(EASYCAPTCHA_PATH . 'include/category.inc.php');
96    }
97    else if ( $page['section'] == 'contact' && $conf['EasyCaptcha']['activate_on']['contactform'] )
98    {
99      $conf['EasyCaptcha']['template'] = 'contactform';
100      include(EASYCAPTCHA_PATH . 'include/contactform.inc.php');
101    }
102    else if ( $page['section'] == 'guestbook' && $conf['EasyCaptcha']['activate_on']['guestbook'] )
103    {
104      $conf['EasyCaptcha']['template'] = 'guestbook';
105      include(EASYCAPTCHA_PATH . 'include/guestbook.inc.php');
106    }
[24215]107  }
108}
109
110
111// admin
112function easycaptcha_plugin_admin_menu($menu)
113{
114  array_push($menu, array(
115    'NAME' => 'Easy Captcha',
116    'URL' => EASYCAPTCHA_ADMIN,
117    ));
118  return $menu;
119}
Note: See TracBrowser for help on using the repository browser.