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
+21 -16
View File
@@ -1,4 +1,4 @@
<?
<?php
require_once('../open_db.lib.php');
require_once('../get_data.lib.php');
@@ -11,12 +11,14 @@ function save_data($id = NULL) {
else
$move = FALSE;
$table = which_table($move, $action);
$image_file = FALSE;
$queue_id = NULL;
// extract POST variables (running through stripslashes)
// extract POST variables
$result = get_post_data(TRUE);
// assign their keys and values to the symbol table
extract($result[0], EXTR_OVERWRITE);
// Process data...
$story = sanitise($story);
// Add the date if it's not got one
@@ -86,7 +88,7 @@ function save_data($id = NULL) {
// Get the (new) ID if we don't already have it.
if (!is_numeric($id) || $move) {
$query = "SELECT LAST_INSERT_ID();";
$getid = $db->query($query) or die("Query failed: ".$db->error());
$getid = $db->query($query) or die("Query failed: ".$db->error);
$row = $getid->fetch_row();
$id = $row[0];
}
@@ -119,8 +121,9 @@ function delete_story($id, $move = FALSE) {
$query = "DELETE FROM $table WHERE `id` = '".$id."' LIMIT 1;";
//echo $query;
$result = $db->query($query)or die("Query failed : ".$db->error());
$result = $db->query($query)or die("Query failed : ".$db->error);
$message = '';
if (!$move)
$message = 'Article has been deleted.';
@@ -129,13 +132,13 @@ function delete_story($id, $move = FALSE) {
function get_mimetype($image_file) {
$upload = getimagesize($image_file);
$mimetype = $upload['mime'];
$mimetype = $upload ? $upload['mime'] : NULL;
return $mimetype;
}
function save_uploaded_file() {
// Save uploaded file to new, temporary location
if (is_uploaded_file($_FILES['upload']['tmp_name'])) {
if (is_uploaded_file($_FILES['upload']['tmp_name'] ?? '')) {
$tmp_file = $_FILES['upload']['tmp_name'];
$new_file = $_SERVER['DOCUMENT_ROOT'] . "/graphics" . $tmp_file;
$end_dir = dirname($new_file);
@@ -164,8 +167,8 @@ function prune_images($image_file) {
unlink($image_file);
if ( $dir_handle = @opendir($cleanup_dir) ) {
if($dir_handle=='.' || $dir_handle=='..') continue;
while ($cleanup_file = readdir ($dir_handle)) {
while (($cleanup_file = readdir ($dir_handle)) !== FALSE) {
if ($cleanup_file == '.' || $cleanup_file == '..') continue;
$cleanup_file = $cleanup_dir . "/". $cleanup_file;
if (@filemtime($cleanup_file) < (time() - $age)) {
@unlink($cleanup_file);
@@ -184,10 +187,12 @@ function prune_images($image_file) {
$validate = array();
function validate_data() {
global $validate;
// extract POST variables (running through stripslashes)
// extract POST variables
$result = get_post_data(TRUE);
// assign their keys and values to the symbol table
extract($result[0], EXTR_OVERWRITE);
$upload_error = $_FILES['upload']['error'] ?? UPLOAD_ERR_NO_FILE;
$upload_tmp = $_FILES['upload']['tmp_name'] ?? '';
if (!$author) {
@@ -203,11 +208,11 @@ function validate_data() {
}
// 0 == no error; 4 == no file; all others are errors.
if ($_FILES['upload']['error'] > 0 &&
$_FILES['upload']['error'] !== 4) {
$validate['upload'] = 'There was an error uploading the file ('.$_FILES['upload']['error'].')';
} else if ($_FILES['upload']['tmp_name']) {
$upload = getimagesize($_FILES['upload']['tmp_name']);
if ($upload_error > 0 &&
$upload_error !== 4) {
$validate['upload'] = 'There was an error uploading the file ('.$upload_error.')';
} else if ($upload_tmp) {
$upload = getimagesize($upload_tmp);
if (!$upload)
$validate['upload'] = htmlspecialchars($_FILES['upload']['name']) .
" wasn't an image file. Please go back.";
@@ -245,7 +250,7 @@ function send_email($title, $author, $story) {
$headers = 'From: x.x.x Queue <editor@xxx.org.za>'."\r\n";
$message = "Please review the queue. $author has sent the following new submission:\n\n";
if ($story)
$message .= wordwrap(preg_replace("#(<br.?/?>|</p>)#", "\n", strip_tags(stripslashes(html_entity_decode_full($story)))));
$message .= wordwrap(preg_replace("#(<br.?/?>|</p>)#", "\n", strip_tags(html_entity_decode_full($story))));
else
$message .= "<Submission is an image. Review on the site.>";
$message .= "\n\nhttp://xxx.org.za/publish/edit";