1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-24 07:42:40 +01:00

Update Figlet implementation to be PHP8 compatible

Summary:
As of PHP ~v8 the zip_open and associated functions have been deprecated and
removed. The replacement is the ZipArchive API. This updates the figlet
implementation to use this API which has been present in PHP since 5.2.

Additionally in PHP 8 the use of squiggly brackets for indexing into arrays
is also deprecated. This updates to remove two uses of squiggly brackets and
replace with square brackets.

These two deprecations would result in being unable to load differential
revisions in which someone had commented using figlet remarkup.

Imported from:

https://secure.phabricator.com/rPd5c63c86e7e4e87d5f72b35b1bdb1e888aea49bc

https://secure.phabricator.com/rPbc6f4786a2e36441d17b765fde8e8e047840bc58

Closes T15289

Test Plan:
Applied these changes to an install and loaded a revision that had comments
where someone utilized figlet remarkup. The revision loaded properly and the
figlet comment rendered properly.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: speck, tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15064, T15289

Differential Revision: https://we.phorge.it/D25142
This commit is contained in:
Valerio Bozzolan 2023-06-05 09:16:41 -04:00 committed by Christopher Speck
parent cb938d869c
commit 71e4eee275
2 changed files with 14 additions and 11 deletions

View file

@ -140,20 +140,23 @@ class Text_Figlet
if (!$compressed) {
/* ZIPed font */
if (fread($fp, 2) == 'PK') {
if (!function_exists('zip_open')) {
return self::raiseError('Cannot load ZIP compressed fonts since'
. ' ZIP PHP extension is not available.',
5);
}
fclose($fp);
if (!($fp = zip_open($filename))) {
return self::raiseError('Cannot open figlet font file ' . $filename, 2);
$zip = new ZipArchive();
$zip_flags = 0;
if(defined('ZipArchive::RDONLY')) {
$zip_flags = ZipArchive::RDONLY; // Flag available since PHP 7.4, unnecessary before
}
$name = zip_entry_name(zip_read($fp));
zip_close($fp);
$open_result = $zip->open($filename, $zip_flags);
if ($open_result !== true) {
return self::raiseError('Cannot open figlet font file ' .
$filename . ', got error: ' . $open_result, 2);
}
$name = $zip->getNameIndex(0);
$zip->close();
if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) {
return self::raiseError('Cannot open figlet font file ' . $filename, 2);

View file

@ -124,7 +124,7 @@ Here's a general description of what you need to install:
- PHP (usually "php")
- Required PHP extensions: mbstring, iconv, mysql (or mysqli), curl, pcntl
(these might be something like "php-mysql" or "php5-mysqlnd")
- Optional PHP extensions: gd
- Optional PHP extensions: gd, zip
If you already have LAMP setup, you've probably already got everything you need.
It may also be helpful to refer to the install scripts above, even if they don't