source: extensions/CryptograPHP/main.inc.php @ 20428

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

fix for new guestbook template + code cleaning

File size: 3.8 KB
Line 
1<?php
2/*
3Plugin Name: Crypto Captcha
4Version: auto
5Description: Add a captcha to register, comment, GuestBook and ContactForm pages (thanks to P@t)
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=535
7Author: Mistic
8Author URI: http://www.strangeplanet.fr
9*/
10
11## TODO : add customization of background image
12
13/*
14Author note :
15Le plugin était appellé à l'origine CryptograPHP et utilisait la librairie CryptograPHP
16Puis il a été renommé Crypto Captcha pour plus de clareté
17La version actuelle s'appelle toujours Crypto Captcha mais utilise la librairie Securimage
18*/
19
20if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
21
22defined('CRYPTO_ID') or define('CRYPTO_ID', basename(dirname(__FILE__)));
23define('CRYPTO_PATH' , PHPWG_PLUGINS_PATH . CRYPTO_ID . '/');
24define('CRYPTO_ADMIN', get_root_url() . 'admin.php?page=plugin-' . CRYPTO_ID);
25define('CRYPTO_VERSION', 'auto');
26
27
28add_event_handler('init', 'crypto_init');
29
30if (defined('IN_ADMIN'))
31{
32  add_event_handler('get_admin_plugin_menu_links', 'crypto_plugin_admin_menu');
33}
34else
35{
36  add_event_handler('init', 'crypto_document_init');
37  add_event_handler('loc_end_section_init', 'crypto_section_init', EVENT_HANDLER_PRIORITY_NEUTRAL+30);
38}
39
40
41// plugin init
42function crypto_init()
43{
44  global $conf, $pwg_loaded_plugins;
45 
46  if (
47    CRYPTO_VERSION == 'auto' or
48    $pwg_loaded_plugins[CRYPTO_ID]['version'] == 'auto' or
49    version_compare($pwg_loaded_plugins[CRYPTO_ID]['version'], CRYPTO_VERSION, '<')
50  )
51  {
52    include_once(CRYPTO_PATH . 'include/install.inc.php');
53    crypto_install();
54   
55    if ( $pwg_loaded_plugins[CRYPTO_ID]['version'] != 'auto' and CRYPTO_VERSION != 'auto' )
56    {
57      $query = '
58UPDATE '. PLUGINS_TABLE .'
59SET version = "'. CRYPTO_VERSION .'"
60WHERE id = "'. CRYPTO_ID .'"';
61      pwg_query($query);
62     
63      $pwg_loaded_plugins[CRYPTO_ID]['version'] = CRYPTO_VERSION;
64     
65      if (defined('IN_ADMIN'))
66      {
67        $_SESSION['page_infos'][] = 'Crypto Captcha updated to version '. CRYPTO_VERSION;
68      }
69    }
70  }
71 
72  $conf['cryptographp'] = unserialize($conf['cryptographp']);
73}
74
75
76// modules : picture comment & register
77function crypto_document_init()
78{
79  global $conf, $user;
80 
81  if (!is_a_guest()) return;
82  if ($user['theme'] == 'smartpocket') return;
83 
84  if ( script_basename() == 'register' and $conf['cryptographp']['activate_on']['register'] )
85  {
86    $conf['cryptographp']['template'] = 'register';
87    include(CRYPTO_PATH.'include/register.inc.php');
88  }
89  else if ( script_basename() == 'picture' and $conf['cryptographp']['activate_on']['picture'] )
90  {
91    $conf['cryptographp']['template'] = 'comment';
92    include(CRYPTO_PATH.'include/picture.inc.php');
93  }
94 
95}
96
97// modules : album comment & contact & guestbook
98function crypto_section_init()
99{
100  global $conf, $pwg_loaded_plugins, $page, $user;
101 
102  if (!is_a_guest()) return;
103  if ($user['theme'] == 'smartpocket') return;
104 
105  if (
106    script_basename() == 'index' and $conf['cryptographp']['activate_on']['category'] and 
107    isset($pwg_loaded_plugins['Comments_on_Albums']) and isset($page['section']) and 
108    $page['section'] == 'categories' and isset($page['category'])
109    ) 
110  {
111    $conf['cryptographp']['template'] = 'comment';
112    include(CRYPTO_PATH.'include/category.inc.php');
113  }
114  else if ( isset($page['section']) and $page['section'] == 'contact' and $conf['cryptographp']['activate_on']['contactform'] ) 
115  {
116    $conf['cryptographp']['template'] = 'contactform';
117    include(CRYPTO_PATH.'include/contactform.inc.php');
118  }
119  else if ( isset($page['section']) and $page['section'] == 'guestbook' and $conf['cryptographp']['activate_on']['guestbook'] ) 
120  {
121    $conf['cryptographp']['template'] = 'guestbook';
122    include(CRYPTO_PATH.'include/guestbook.inc.php');
123  }
124}
125
126
127// admin
128function crypto_plugin_admin_menu($menu)
129{
130  array_push($menu, array(
131    'NAME' => 'Crypto Captcha',
132    'URL' => CRYPTO_ADMIN,
133    ));
134  return $menu;
135}
136
137?>
Note: See TracBrowser for help on using the repository browser.