-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecaptcha.php
More file actions
106 lines (95 loc) · 2.22 KB
/
recaptcha.php
File metadata and controls
106 lines (95 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* LightPHP Framework
* LitePHP is a framework that has been designed to be lite waight, extensible and fast.
*
* @author Robert Pitt <robertpitt1988@gmail.com>
* @category core
* @copyright 2013 Robert Pitt
* @license GPL v3 - GNU Public License v3
* @version 1.0.0
*/
/**
* Recaptcha class
*/
class ReCAPTCHA_Library
{
/**
* API Server endpoint
*/
const API_SERVER = "//api.recaptcha.net/";
/**
* Varifiy Server
*/
const VARIFIY_SERVER = "www.google.com";
/**
* Public Key used for authentication to reCAPTCHA.
* @see https://www.google.com/recaptcha/admin/create
* @var string
*/
protected $public_key = null;
/**
* Constructor
*/
public function __construct()
{
/**
* Try and load the config
*/
try
{
$this->public_key = Registry::get("ConfigLoader")->recaptcha->public_key;
}catch(Exception $e)
{}
}
/**
* Set the public key
* @param string $key Key used for authentication
*/
public function setPublicKey($key)
{
$this->public_key = $key;
}
/**
* Generate a html fragment for displaying the reCAPTCHA widget
*/
public function generate($error = null)
{
/**
* Create the params
*/
$params = array('k' => $this->public_key);
/**
* Check to see if we have an error
*/
if($error)
{
$params['error'] = $error;
}
/**
* If we have an error, we need to append that to our url
*/
$curl = self::API_SERVER . '/challenge?' . http_build_query($params, '', '&');
/**
* Create the noscript
*/
$nurl = self::API_SERVER . '/noscript?' . http_build_query($params, '', '&');
/**
* Start generating the output
*/
$output = '<script type="text/javascript" src="' . $curl . '"></script>';
/**
* Extend the output with a noscript
*/
$output .= '<noscript>';
$output .= '<iframe src="' . $nurl . '" height="300" width="500" frameborder="0"></iframe>';
$output .= '<br/>'; //< not even sure why google do this.
$output .= '<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>';
$output .= '<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>';
$output .= '</noscript>';
/**
* Return the response to be outputed
*/
return $output;
}
}