source: extensions/captcha/maintain.inc.php @ 10633

Revision 8054, 1.3 KB checked in by patdenice, 9 years ago (diff)

Check if reCaptcha API is responding before activate.

Line 
1<?php
2function plugin_install()
3{
4  global $conf;
5
6  if (!isset($conf['captcha_publickey']))
7  {
8    $q = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment) VALUES ("captcha_publickey","","Captcha public key");';
9    pwg_query($q);
10  }
11
12  if (!isset($conf['captcha_privatekey']))
13  {
14    $q = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment) VALUES ("captcha_privatekey","","Captcha private key");';
15    pwg_query($q);
16  }
17 
18  if (!isset($conf['captcha_theme']))
19  {
20    $q = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment) VALUES ("captcha_theme","red","Captcha theme");';
21    pwg_query($q);
22  }
23}
24
25function plugin_activate($id, $version, &$errors)
26{
27  global $conf;
28
29  if (!isset($conf['captcha_theme']))
30  {
31    plugin_install();
32  }
33
34  // Check if API is responding
35  include(PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/recaptchalib.php');
36  $response = _recaptcha_http_post(RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify", array ());
37  $answers = explode ("\n", $response [1]);
38
39  if ($answers[0] != 'true' and $answers[0] != 'false')
40  {
41    array_push($errors, l10n('Piwigo can\'t connect to reCaptcha server'));
42  }
43}
44
45
46function plugin_uninstall()
47{
48  foreach (array('captcha_publickey','captcha_privatekey', 'captcha_theme') as $param)
49  {
50    $q = 'DELETE FROM '.CONFIG_TABLE.' WHERE param="'.$param.'" LIMIT 1';
51    pwg_query( $q );
52  }
53}
54
55?>
Note: See TracBrowser for help on using the repository browser.