Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ReCaptcha | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__call | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getHtml | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * Recaptcha service |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2016. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Service |
25 | * @author Chris Hallberg <crhallberg@gmail.com> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Service; |
31 | |
32 | use Laminas\ReCaptcha\ReCaptcha as LaminasReCaptcha; |
33 | |
34 | use function func_get_args; |
35 | use function is_callable; |
36 | |
37 | /** |
38 | * Recaptcha service |
39 | * |
40 | * @category VuFind |
41 | * @package View_Helpers |
42 | * @author Chris Hallberg <crhallberg@gmail.com> |
43 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
44 | * @link https://vufind.org/wiki/development Wiki |
45 | */ |
46 | class ReCaptcha |
47 | { |
48 | /** |
49 | * Proxied helper |
50 | * |
51 | * @var LaminasRecaptcha |
52 | */ |
53 | protected $recaptcha; |
54 | |
55 | /** |
56 | * Constructor |
57 | */ |
58 | public function __construct() |
59 | { |
60 | $this->recaptcha = new LaminasReCaptcha(...func_get_args()); |
61 | } |
62 | |
63 | /** |
64 | * Proxy calls to the Laminas ReCaptcha object. |
65 | * |
66 | * @param string $method Method to call |
67 | * @param array $args Method arguments |
68 | * |
69 | * @return mixed |
70 | */ |
71 | public function __call($method, $args) |
72 | { |
73 | if (is_callable([$this->recaptcha, $method])) { |
74 | return $this->recaptcha->$method(...$args); |
75 | } |
76 | throw new \Exception("Unsupported method: $method"); |
77 | } |
78 | |
79 | /** |
80 | * Get the HTML code for the captcha |
81 | * |
82 | * This method uses the public key to fetch a recaptcha form. |
83 | * |
84 | * @return string |
85 | * |
86 | * @throws \Laminas\ReCaptcha\Exception |
87 | */ |
88 | public function getHtml() |
89 | { |
90 | // Get standard HTML |
91 | $html = $this->recaptcha->getHtml(); |
92 | |
93 | // Disable script tag (it is handled by \VuFind\Captcha\ReCaptcha, and |
94 | // we don't want to load duplicate Javascript). |
95 | $scriptRegex = '|<script[^>]*></script>|'; |
96 | $scriptReplacement = ''; // remove |
97 | return preg_replace($scriptRegex, $scriptReplacement, $html); |
98 | } |
99 | } |