Port the code to PHP 8.5.

Replace the short open tags and the removed functions (mcrypt, mysql_error,
salt-less crypt). Decode the reCAPTCHA reply as JSON, turn off mysqli
exceptions, drop stripslashes(), and default missing input values.
Fix the misplaced continue in prune_images().
This commit is contained in:
tim
2026-09-25 21:18:58 +02:00
parent 15e81e17cc
commit 00829a0c0d
23 changed files with 145 additions and 130 deletions
+16 -13
View File
@@ -1,4 +1,4 @@
<?
<?php
require_once('open_db.lib.php');
function display_stories($id = NULL) {
@@ -193,9 +193,9 @@ function get_query($id = NULL) {
* Return array of the POST variables we may care about
* (safer than extract($_POST))
*
* If $stripslashes is non-null, run stripslashes on the values
* Note that stripslashes turns NULL into string("")
* and int(0) into string("0")
* If $stripslashes is non-null, turn every value into a string:
* NULL (or an array) becomes string(""), int(0) becomes string("0").
* (It used to run stripslashes, but magic_quotes_gpc no longer exists.)
*
* If $html is non-null, run the output through htmlspecialchars,
* to translate HTML-unsafe characters. This should only be needed
@@ -219,7 +219,7 @@ function get_post_data($stripslashes = NULL, $html = NULL) {
$entry['queue_url'] = $queue ? 1 : 0;
if ($stripslashes) {
$entry = array_map('stripslashes', $entry);
$entry = array_map('map_string', $entry);
}
if ($html) {
$entry = array_map('map_html', $entry);
@@ -227,8 +227,11 @@ function get_post_data($stripslashes = NULL, $html = NULL) {
$results[] = $entry;
return $results;
}
function map_string($value) {
return is_scalar($value) ? (string)$value : '';
}
function map_html($string) {
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8', FALSE);
return htmlspecialchars(map_string($string), ENT_QUOTES, 'UTF-8', FALSE);
}
function unmap_html($string) {
return htmlspecialchars_decode($string, ENT_QUOTES);
@@ -243,7 +246,7 @@ function get_id() {
if (is_numeric($id)) {
return $id;
} else if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
$id = $db->real_escape_string(stripslashes($_REQUEST['id']));
$id = $db->real_escape_string($_REQUEST['id']);
return $id;
} else {
return NULL;
@@ -252,7 +255,7 @@ function get_id() {
function get_search_args() {
global $db;
if (isset($_GET['search'])) {
if (isset($_GET['search']) && is_string($_GET['search'])) {
$search = $db->real_escape_string($_GET['search']);
return $search;
}
@@ -261,7 +264,7 @@ function get_search_args() {
function get_order() {
global $db;
$order = NULL;
if (isset($_GET['order'])) {
if (isset($_GET['order']) && is_string($_GET['order'])) {
$order = $db->real_escape_string($_GET['order']);
}
// Sort ascending by default
@@ -279,7 +282,7 @@ function get_order() {
function get_sort_arg() {
global $db;
$sort = NULL;
if (isset($_GET['sort'])) {
if (isset($_GET['sort']) && is_string($_GET['sort'])) {
$sort = $db->real_escape_string($_GET['sort']);
}
if ($sort != "author" &&
@@ -292,7 +295,7 @@ function get_sort_arg() {
function get_show_num() {
global $db, $num_stories;
$show = NULL;
if (isset($_GET['show'])) {
if (isset($_GET['show']) && is_string($_GET['show'])) {
$show = $db->real_escape_string($_GET['show']);
}
if (is_numeric($show))
@@ -306,7 +309,7 @@ function get_show_num() {
function get_start_num() {
global $db;
$start = NULL;
if (isset($_GET['start'])) {
if (isset($_GET['start']) && is_string($_GET['start'])) {
$start = $db->real_escape_string($_GET['start']);
}
if (!is_numeric($start))
@@ -344,7 +347,7 @@ function which_table($move = FALSE, $action = 'read') {
return 'queue';
// Viewing
} else if ($queue && ($is_admin || array_key_exists('allow_queue_image', $_SESSION))) {
} else if ($queue && ($is_admin || isset($_SESSION['allow_queue_image']))) {
return 'queue';
} else {
return 'xxx';