Skip to content

Commit

Permalink
Add backward compatibility support for PHP 5.3.3 (#164)
Browse files Browse the repository at this point in the history
* Add backward compatibility support for PHP 5.3
* Re-activate Travis for PHP 5.3
* Downgrade to PHP 5.3 in the composer
* PHPDoc should be above the function definition
* Remove useless code related to PHP < 5.3
* Increase minor version required to 5.3.3 and remove duplicate check about it
* Simplify hex2bin since PHP >= 5.3
* Increase requirement in composer to 5.3.3 as well
* Update the message about requirement too
* Improve credits from PHP doc
  • Loading branch information
btlogy authored and michield committed Apr 8, 2017
1 parent b76f3c1 commit ba70408
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -7,6 +7,7 @@ php:
- 5.6
- 5.5
- 5.4
- 5.3

before_script:
- sudo apt-get update > /dev/null
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -18,7 +18,7 @@
},
"minimum-stability": "dev",
"require": {
"php": ">= 5.4.0, <= 7.1.99"
"php": ">= 5.3.3, <= 7.1.99"
},
"require-dev": {
"behat/mink": "~1.4",
Expand Down
33 changes: 33 additions & 0 deletions public_html/lists/admin/inc/php_compat.php
Expand Up @@ -52,3 +52,36 @@ function hash_equals($known_string, $user_string)
return $ret === 0;
}
}

if (!function_exists('hex2bin')) { // PHP 5.4 and up
/**
* Convert hexadecimal values to ASCII characters.
*
* Credits: Walf's user note from PHP Documentation Group - http://php.net/manual/en/function.hex2bin.php#113472
* License: CC-BY 3.0 (http://creativecommons.org/licenses/by/3.0/)
* Changes: The original part of the code has been simplified assuming PHP >= 5.3.3
*
* @param string $data The hexadecimal representation of data to be converted
*
* @return string Returns the binary representation of the given data or FALSE on failure.
*/
function hex2bin($data) {
if (is_scalar($data) || (method_exists($data, '__toString'))) {
$data = (string) $data;
}
else {
trigger_error(__FUNCTION__.'() expects parameter 1 to be string, ' . gettype($data) . ' given', E_USER_WARNING);
return;//null in this case
}
$len = strlen($data);
if ($len % 2) {
trigger_error(__FUNCTION__.'(): Hexadecimal input string must have an even length', E_USER_WARNING);
return false;
}
if (strspn($data, '0123456789abcdefABCDEF') != $len) {
trigger_error(__FUNCTION__.'(): Input string must be hexadecimal string', E_USER_WARNING);
return false;
}
return pack('H*', $data);
}
}
10 changes: 3 additions & 7 deletions public_html/lists/admin/index.php
@@ -1,6 +1,6 @@
<?php

if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50303) {
die('Your PHP version is too old. Please upgrade PHP before continuing.');
}

Expand Down Expand Up @@ -499,8 +499,8 @@ function mb_strtolower($string)
if (TEST) {
echo Info($GLOBALS['I18N']->get('Running in testmode, no emails will be sent. Check your config file.'));
}
if (version_compare(PHP_VERSION, '5.4.0', '<') && WARN_ABOUT_PHP_SETTINGS) {
Error(s('Your PHP version is out of date. phpList requires PHP version 5.4.0 or higher.'));
if (version_compare(PHP_VERSION, '5.3.3', '<') && WARN_ABOUT_PHP_SETTINGS) {
Error(s('Your PHP version is out of date. phpList requires PHP version 5.3.3 or higher.'));
}
if (defined('RELEASEDATE') && ((time() - RELEASEDATE) / 31536000) > 2) {
Fatal_Error(s('Your phpList version is older than two years. Please %supgrade phpList</a> before continuing.</br>
Expand All @@ -509,10 +509,6 @@ function mb_strtolower($string)
return;
}

if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
Fatal_Error(s('Your PHP version is too old. Please upgrade PHP before continuing'));
return;
}
if (defined('ENABLE_RSS') && ENABLE_RSS && !function_exists('xml_parse') && WARN_ABOUT_PHP_SETTINGS) {
Warn($GLOBALS['I18N']->get('You are trying to use RSS, but XML is not included in your PHP'));
}
Expand Down

0 comments on commit ba70408

Please sign in to comment.