| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * ReCaptcha Settings
|
|---|
| 4 | *
|
|---|
| 5 | * PHP version 5
|
|---|
| 6 | *
|
|---|
| 7 | * LICENSE: Hotaru CMS is free software: you can redistribute it and/or
|
|---|
| 8 | * modify it under the terms of the GNU General Public License as
|
|---|
| 9 | * published by the Free Software Foundation, either version 3 of
|
|---|
| 10 | * the License, or (at your option) any later version.
|
|---|
| 11 | *
|
|---|
| 12 | * Hotaru CMS is distributed in the hope that it will be useful, but WITHOUT
|
|---|
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|---|
| 14 | * FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License along
|
|---|
| 17 | * with Hotaru CMS. If not, see http://www.gnu.org/licenses/.
|
|---|
| 18 | *
|
|---|
| 19 | * @category Content Management System
|
|---|
| 20 | * @package HotaruCMS
|
|---|
| 21 | * @author Nick Ramsay <admin@hotarucms.org>
|
|---|
| 22 | * @copyright Copyright (c) 2009, Hotaru CMS
|
|---|
| 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
|
|---|
| 24 | * @link http://www.hotarucms.org/
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 | class ReCaptchaSettings
|
|---|
| 28 | {
|
|---|
| 29 | /**
|
|---|
| 30 | * Admin settings for the Users plugin
|
|---|
| 31 | */
|
|---|
| 32 | public function settings($h)
|
|---|
| 33 | {
|
|---|
| 34 | // If the form has been submitted, go and save the data...
|
|---|
| 35 | if ($h->cage->post->getAlpha('submitted') == 'true') {
|
|---|
| 36 | $this->saveSettings($h);
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | echo "<h1>" . $h->lang["recaptcha_settings_header"] . "</h1>\n";
|
|---|
| 40 |
|
|---|
| 41 | // Get settings from database if they exist...
|
|---|
| 42 | $recaptcha_settings = $h->getSerializedSettings();
|
|---|
| 43 | $pubkey = $recaptcha_settings['pubkey'];
|
|---|
| 44 | $privkey = $recaptcha_settings['privkey'];
|
|---|
| 45 |
|
|---|
| 46 | //...otherwise set to blank:
|
|---|
| 47 | if (!$pubkey) { $pubkey = ''; }
|
|---|
| 48 | if (!$privkey) { $privkey = ''; }
|
|---|
| 49 |
|
|---|
| 50 | echo "<form name='recaptcha_settings_form' action='" . BASEURL . "admin_index.php?page=plugin_settings&plugin=recaptcha' method='post'>\n";
|
|---|
| 51 |
|
|---|
| 52 | $thisdomain = rstrtrim(str_replace("http://", "", BASEURL), '/');
|
|---|
| 53 | echo "<p>" . $h->lang["recaptcha_settings_desc"] . " <a href='http://recaptcha.net/api/getkey?domain=" . $thisdomain . "&app=HotaruCMS'>reCAPTCHA.net</a>.</p><br />\n";
|
|---|
| 54 |
|
|---|
| 55 | echo " " . $h->lang["recaptcha_settings_public_key"] . ": <input type='text' name='rc_pubkey' size=50 value='" . $pubkey . "'><br /><br />\n";
|
|---|
| 56 | echo " " . $h->lang["recaptcha_settings_private_key"] . ": <input type='text' name='rc_privkey' size=50 value='" . $privkey . "'><br /><br />\n";
|
|---|
| 57 |
|
|---|
| 58 | echo "<input type='hidden' name='submitted' value='true' />\n";
|
|---|
| 59 | echo "<input type='submit' value='" . $h->lang["main_form_save"] . "' />\n";
|
|---|
| 60 | echo "<input type='hidden' name='csrf' value='" . $h->csrfToken . "' />\n";
|
|---|
| 61 | echo "</form><br />\n";
|
|---|
| 62 |
|
|---|
| 63 | /* *************************************
|
|---|
| 64 | * RECAPTCHA TEST START
|
|---|
| 65 | * ********************************** */
|
|---|
| 66 |
|
|---|
| 67 | echo $h->lang["recaptcha_settings_example"] . "<br /><br />";
|
|---|
| 68 |
|
|---|
| 69 | if ($h->cage->post->getAlpha('submitted') == 'test')
|
|---|
| 70 | {
|
|---|
| 71 | $result = $h->pluginHook('check_recaptcha'); // This hook checks the captcha
|
|---|
| 72 |
|
|---|
| 73 | if ($result['ReCaptcha_check_recaptcha'] == 'success')
|
|---|
| 74 | {
|
|---|
| 75 | $h->showMessage($h->lang["recaptcha_success"], 'green'); // success message
|
|---|
| 76 | }
|
|---|
| 77 | elseif ($result['ReCaptcha_check_recaptcha'] == 'empty')
|
|---|
| 78 | {
|
|---|
| 79 | $h->showMessage($h->lang["recaptcha_empty"], 'red'); // empty message
|
|---|
| 80 | }
|
|---|
| 81 | else
|
|---|
| 82 | {
|
|---|
| 83 | $h->showMessage($h->lang["recaptcha_error"], 'red'); // error message
|
|---|
| 84 | }
|
|---|
| 85 | echo "<br />";
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | echo "<form name='recaptcha_settings_test' action='" . BASEURL . "admin_index.php?page=plugin_settings&plugin=recaptcha' method='post'>\n";
|
|---|
| 89 | $h->pluginHook('show_recaptcha');
|
|---|
| 90 | echo "<input type='hidden' name='submitted' value='test' />\n";
|
|---|
| 91 | echo "<input type='submit' value='" . $h->lang["recaptcha_settings_do_test"] . "' />\n";
|
|---|
| 92 | echo "<input type='hidden' name='csrf' value='" . $h->csrfToken . "' />\n";
|
|---|
| 93 | echo "</form><br />\n";
|
|---|
| 94 |
|
|---|
| 95 | /* *************************************
|
|---|
| 96 | * RECAPTCHA TEST END
|
|---|
| 97 | * ********************************** */
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | /**
|
|---|
| 102 | * Save Settings
|
|---|
| 103 | */
|
|---|
| 104 | public function saveSettings($h)
|
|---|
| 105 | {
|
|---|
| 106 | // ReCaptcha Public Key
|
|---|
| 107 | $pubkey = $h->cage->post->testAlnumLines('rc_pubkey');
|
|---|
| 108 | if (!$pubkey) {
|
|---|
| 109 | $pubkey = "";
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | // ReCaptcha Private Key
|
|---|
| 113 | $privkey = $h->cage->post->testAlnumLines('rc_privkey');
|
|---|
| 114 | if (!$privkey) {
|
|---|
| 115 | $privkey = "";
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | $recaptcha_settings['pubkey'] = $pubkey;
|
|---|
| 119 | $recaptcha_settings['privkey'] = $privkey;
|
|---|
| 120 |
|
|---|
| 121 | $h->updateSetting('recaptcha_settings', serialize($recaptcha_settings));
|
|---|
| 122 |
|
|---|
| 123 | if (!$pubkey || !$privkey) {
|
|---|
| 124 | $h->message = $h->lang["recaptcha_settings_error"];
|
|---|
| 125 | $h->messageType = "red";
|
|---|
| 126 | $h->showMessage();
|
|---|
| 127 | } else {
|
|---|
| 128 | $h->message = $h->lang["main_settings_saved"];
|
|---|
| 129 | $h->messageType = "green";
|
|---|
| 130 | $h->showMessage();
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | return true;
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 | ?>
|
|---|