diff --git a/publish/post.lib.php b/publish/post.lib.php
index 1a91ac3..3addd41 100644
--- a/publish/post.lib.php
+++ b/publish/post.lib.php
@@ -115,6 +115,10 @@ function save_data($id = NULL) {
if (!$is_admin && $action == 'submit')
$_SESSION['allow_queue_image'] = $id;
+ // A visitor's next story needs a new captcha
+ if (!$is_admin)
+ captcha_used();
+
// Prune filesystem
if ($image_file)
prune_images($image_file);
@@ -189,7 +193,7 @@ function prune_images($image_file) {
*/
$validate = array();
function validate_data() {
- global $validate;
+ global $validate, $is_admin;
// extract POST variables
$result = get_post_data(TRUE);
// assign their keys and values to the symbol table
@@ -197,6 +201,10 @@ function validate_data() {
$upload_error = $_FILES['upload']['error'] ?? UPLOAD_ERR_NO_FILE;
$upload_tmp = $_FILES['upload']['tmp_name'] ?? '';
+ // Visitors must solve the captcha before a preview or a save
+ if (!$is_admin && !captcha_check()) {
+ $validate['captcha'] = 'Please complete the captcha.';
+ }
if (!$author) {
$validate['author'] = "You have not submitted an author.";
diff --git a/publish/preview.inc.php b/publish/preview.inc.php
index 378fb84..35f9ccb 100644
--- a/publish/preview.inc.php
+++ b/publish/preview.inc.php
@@ -2,25 +2,6 @@
$result = get_post_data(TRUE);
extract($result[0], EXTR_OVERWRITE);
-if (isset($_POST['g-recaptcha-response'])) {
- $captcha = $_POST['g-recaptcha-response'];
- if (! $captcha) {
- $validate['captcha'] = 'Invalid captcha. Please try again.';
- include('./write.inc.php');
- return;
- }
- $captcha_resp = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".urlencode(config('RECAPTCHA_SECRET'))."&response=".
- $captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
- var_dump($captcha_resp);
- // PHP 8 treats the bare word "success" as an undefined constant, so decode the JSON reply
- $captcha_json = json_decode((string)$captcha_resp);
- if (empty($captcha_json->success)) {
- $validate['captcha'] = 'The words you typed in the captcha were not correct. Please try again.';
- include('./write.inc.php');
- return;
- }
-}
-
echo '
Please review your submission. Once you\'ve finished, please click "Submit" at the bottom of the page, or click "Preview" to check it again.
';
// Keep a new image outside the web root until the story is saved;
diff --git a/publish/style.css b/publish/style.css
index e7f1108..3dfa5b4 100644
--- a/publish/style.css
+++ b/publish/style.css
@@ -148,8 +148,8 @@ ul.error-box li {
}
#main .grid div.g-recaptcha {
- overflow: inherit;
- margin-left: 120px;
+ grid-column: 2;
+ margin: 5px 0;
}
#captcha #recaptcha_image {
margin-left: 120px;
diff --git a/publish/write.inc.php b/publish/write.inc.php
index 8ef0548..14fa83f 100644
--- a/publish/write.inc.php
+++ b/publish/write.inc.php
@@ -103,8 +103,9 @@ if (isset($file_src) || isset($img)) {
';
+ // Visitors solve the captcha once; the session remembers it until the story is saved
+ if (!$is_admin && !captcha_passed()) {
+ echo captcha_widget();
}
if ($is_admin) {
diff --git a/session.lib.php b/session.lib.php
index 72422d2..a56296e 100644
--- a/session.lib.php
+++ b/session.lib.php
@@ -1,6 +1,7 @@