Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

PHP 7/8 compatibility fixes #1043

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/admin/PhorumInputForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PhorumInputForm {
var $_submit;
var $_help;

function PhorumInputForm ( $action = "", $method = "get", $submit = "Submit", $target = "", $enctype = "", $events = array() )
function __construct($action = "", $method = "get", $submit = "Submit", $target = "", $enctype = "", $events = array())
{
$this->_action = ( empty( $action ) ) ? $_SERVER["PHP_SELF"] : $action;
$this->_method = $method;
Expand Down Expand Up @@ -208,7 +208,7 @@ function show()
{
global $PHORUM;

if(count($this->_help)){
if (is_array($this->_help) && count($this->_help)) {
echo "<script type=\"text/javascript\">\nvar help = Array;\n";
foreach($this->_help as $key=>$data){
echo "help[$key] = [\"$data[0]\", \"$data[1]\"];\n";
Expand Down
2 changes: 1 addition & 1 deletion include/admin/badwords.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

echo "<hr class=\"PhorumAdminHR\" />";

if(count($bad_words)){
if (is_array($bad_words) && count($bad_words)) {

echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" class=\"PhorumAdminTable\" width=\"100%\">\n";
echo "<tr>\n";
Expand Down
1 change: 1 addition & 0 deletions include/admin/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

require_once './include/admin/PhorumInputForm.php';
require_once './include/version_functions.php';
require_once './include/misc/polyfill-each.php';

$is_module_upgrade = isset($_POST['is_module_upgrade'])
? ($_POST['is_module_upgrade'] ? 1 : 0)
Expand Down
2 changes: 1 addition & 1 deletion include/api/custom_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ function phorum_api_custom_field_restore($id)
* Returns the input array with the custom fields added.
*/
function phorum_api_custom_field_apply(
$field_type = NULL, $data_array, $raw_data = FALSE)
$field_type, $data_array, $raw_data = FALSE)
{
global $PHORUM;

Expand Down
2 changes: 1 addition & 1 deletion include/api/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function phorum_api_system_get_max_upload()
function phorum_api_system_phpsize2bytes($size)
{
$size = trim($size);
$last = strtolower($size{strlen($size)-1});
$last = strtolower($size[strlen($size)-1]);
switch($last) {
// The 'G' modifier is available since PHP 5.1.0
case 'g':
Expand Down
2 changes: 2 additions & 0 deletions include/db/PhorumDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
// included separately from the Phorum core code.)
defined('PHORUM_PATH') or define('PHORUM_PATH', dirname(__FILE__).'/../..');

require_once __DIR__.'/../misc/polyfill-each.php';

// ----------------------------------------------------------------------
// Definitions
// ----------------------------------------------------------------------
Expand Down
54 changes: 54 additions & 0 deletions include/misc/polyfill-each.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
// MIT License
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this license compatible with phorum/core to be bundled?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phorum license is based on The Apache Software License Version 1.1. Both licenses are permissive, non-copyleft. So I think it's okay. Some explanation.

//
// Copyright (c) 2021 Christiaan Bye
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// https://github.com/ChristiaanBye/polyfill-each

if (!function_exists('each')) {
/**
* @param array $array Although the actual function accepted objects, it was discouraged to pass them. Hence for the
* shim only an array is supported.
*
* @return array|false
*/
function each(array &$array)
{
$key = key($array);
$value = current($array);

if ($key === null) {
// key() returns null if the array pointer is beyond the list of element or if the array is empty. If the
// same scenario occurred in the each() function, a false was returned instead. Hence returning false here
return false;
}

// Advance the array pointer before returning
next($array);

return array(
1 => $value,
'value' => $value,
0 => $key,
'key' => $key
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class ConvertCharset {
* @param boolean $TurnOnEntities
* @access public
*/
function ConvertCharset ($FromCharset, $ToCharset, $TurnOnEntities = false)
function __construct($FromCharset, $ToCharset, $TurnOnEntities = false)
{
/**
* For all people who like to use uppercase for charset encoding names :)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
define ("CONVERT_TABLES_DIR", $PATH_TO_CLASS);
define ("DEBUG_MODE", 1);

require_once __DIR__.'/../../include/misc/polyfill-each.php';

class ConvertCharset{
var $RecognizedEncoding; // (boolean) This value keeps information if string contains multibyte chars.
Expand Down
6 changes: 3 additions & 3 deletions mods/spamhurdles/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ function spamhurdles_iScramble_escape($plain)

for ($i = 0; $i < strlen($plain); $i++)
{
$char = $plain{$i};
$char = $plain[$i];
if (strpos($passChars, $char) === false)
{
// $char is not in the list of $passChars. Encode in hex format
Expand Down Expand Up @@ -753,7 +753,7 @@ function spamhurdles_iScramble($plain, $longPwd=False, $rot13=False, $sorry="<i>
$availChars = substr("0123456789", 0, $numberOfColumns);
for ($i = 0 ; $i < $numberOfColumns; $i++)
{
$char = $availChars{ random_int(0, strlen($availChars)-1) };
$char = $availChars[random_int(0, strlen($availChars)-1)];
$password .= $char;
$availChars = str_replace($char, "", $availChars);
}
Expand All @@ -768,7 +768,7 @@ function spamhurdles_iScramble($plain, $longPwd=False, $rot13=False, $sorry="<i>
{
for($j = 0; $j < $numberOfColumns; $j++ )
{
$scrambled{(int)(((int)$scramblePassword{$k}) * $numberOfRows) + $i} = $escaped{$k};
$scrambled[(int)(((int)$scramblePassword[$k]) * $numberOfRows) + $i] = $escaped[$k];
$k++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion mods/spamhurdles/captcha/class.banner.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class banner
{
function banner($font = "banner.fnt")
function __construct($font = "banner.fnt")
{
$font = basename($font);

Expand Down
4 changes: 2 additions & 2 deletions mods/spamhurdles/captcha/class.captcha_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

// The default set of characters to create random strings with.
define("CAPTCHA_RANDOMCHARS",
"0123456789" .
"abcdefghijklmnopqrstuvwxyz",
"0123456789".
"abcdefghijklmnopqrstuvwxyz".
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
);

Expand Down
4 changes: 2 additions & 2 deletions mods/spamhurdles/include/crypt/aes.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Crypt_AES extends Crypt_Rijndael {
* @return Crypt_AES
* @access public
*/
function Crypt_AES($mode = CRYPT_AES_MODE_CBC)
function __construct($mode = CRYPT_AES_MODE_CBC)
{
if ( !defined('CRYPT_AES_MODE') ) {
switch (true) {
Expand Down Expand Up @@ -166,7 +166,7 @@ function Crypt_AES($mode = CRYPT_AES_MODE_CBC)
}

if (CRYPT_AES_MODE == CRYPT_AES_MODE_INTERNAL) {
parent::Crypt_Rijndael($this->mode);
parent::__construct($this->mode);
}
}

Expand Down
2 changes: 1 addition & 1 deletion mods/spamhurdles/include/crypt/rijndael.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class Crypt_Rijndael {
* @return Crypt_Rijndael
* @access public
*/
function Crypt_Rijndael($mode = CRYPT_MODE_RIJNDAEL_CBC)
function __construct($mode = CRYPT_MODE_RIJNDAEL_CBC)
{
switch ($mode) {
case CRYPT_RIJNDAEL_MODE_ECB:
Expand Down