Skip to content

Commit

Permalink
PHP 5.3, 5.5, 5.6 and 7.0 deprecation fixes (#1428)
Browse files Browse the repository at this point in the history
* PHP 5.3, 5.5, 5.6 and 7.0 deprecation fixes
* PHP7.x left-right-order evaluation
* Reintroduced old-style constructors for BC
* Renamed eZDFSFileHandlerMySQLiBackend::__mkdir_p() to eZDFSFileHandlerMySQLiBackend::mkdir_p()
* Replaced deprecated use of ini_get(track_errors) and $php_errormsg
* Replaced old-style constructor in datatype_code.tpl
* Replaced check for zlib extension with check for gzcompress()
* Removed safe_mode support. Removed from PHP 5.4.0 and later
  • Loading branch information
vidarl authored and andrerom committed Apr 29, 2019
1 parent faf906d commit 0711409
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 74 deletions.
2 changes: 1 addition & 1 deletion cronjobs/linkcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
// Check if it is a valid internal link.
foreach ( $siteURLs as $siteURL )
{
$siteURL = preg_replace("/\/$/e", "", $siteURL );
$siteURL = preg_replace("/\/$/", "", $siteURL );
$fp = @fopen( $siteURL . "/". $url, "r" );
if ( !$fp )
{
Expand Down
4 changes: 2 additions & 2 deletions design/admin/templates/setup/datatype_code.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class {$full_class_name} extends eZDataType
/*!
{'Constructor'|i18n('design/admin/setup/datatypecode')}
*/
function {$full_class_name}()
function __construct()
{literal}{{/literal}
$this->eZDataType( self::{$constant_name}, "{$desc_name}" );
parent::__construct( self::{$constant_name}, "{$desc_name}" );
{literal}}{/literal}

{if $class_input}
Expand Down
4 changes: 2 additions & 2 deletions design/standard/templates/setup/datatype_code.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class {$full_class_name} extends eZDataType
/*!
{'Constructor'|i18n('design/standard/setup/datatypecode')}
*/
function {$full_class_name}()
function __construct()
{literal}{{/literal}
$this->eZDataType( self::{$constant_name}, "{$desc_name}" );
parent::__construct( self::{$constant_name}, "{$desc_name}" );
{literal}}{/literal}

{if $class_input}
Expand Down
12 changes: 6 additions & 6 deletions extension/ezoe/ezxmltext/handlers/input/ezoexmlinput.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ function validateInput( $http, $base, $contentObjectAttribute )
*/

// Get section level and reset curent xml node according to input header.
function &sectionLevel( &$sectionLevel, $headerLevel, &$TagStack, &$currentNode, &$domDocument )
function sectionLevel( &$sectionLevel, $headerLevel, &$TagStack, &$currentNode, &$domDocument )
{
if ( $sectionLevel < $headerLevel )
{
Expand Down Expand Up @@ -773,7 +773,7 @@ function inputXML( )
\private
\return the user input format for the given section
*/
function &inputSectionXML( &$section, $currentSectionLevel, $tdSectionLevel = null )
function inputSectionXML( &$section, $currentSectionLevel, $tdSectionLevel = null )
{
$output = '';

Expand Down Expand Up @@ -894,7 +894,7 @@ function &inputSectionXML( &$section, $currentSectionLevel, $tdSectionLevel = nu
\private
\return the user input format for the given list item
*/
function &inputListXML( &$listNode, $currentSectionLevel, $listSectionLevel = null, $noParagraphs = true )
function inputListXML( &$listNode, $currentSectionLevel, $listSectionLevel = null, $noParagraphs = true )
{
$output = '';
$tagName = $listNode instanceof DOMNode ? $listNode->nodeName : '';
Expand Down Expand Up @@ -932,7 +932,7 @@ function &inputListXML( &$listNode, $currentSectionLevel, $listSectionLevel = nu
\private
\return the user input format for the given table cell
*/
function &inputTdXML( &$tdNode, $currentSectionLevel, $tdSectionLevel = null )
function inputTdXML( &$tdNode, $currentSectionLevel, $tdSectionLevel = null )
{
$output = '';
$tagName = $tdNode instanceof DOMNode ? $tdNode->nodeName : '';
Expand Down Expand Up @@ -961,7 +961,7 @@ function &inputTdXML( &$tdNode, $currentSectionLevel, $tdSectionLevel = null )
/*!
\return the input xml of the given paragraph
*/
function &inputParagraphXML( &$paragraph,
function inputParagraphXML( &$paragraph,
$currentSectionLevel,
$tdSectionLevel = null,
$noRender = false )
Expand Down Expand Up @@ -1045,7 +1045,7 @@ function &inputParagraphXML( &$paragraph,
\return the input xml for the given tag
\as in the xhtml used inside the editor
*/
function &inputTagXML( &$tag, $currentSectionLevel, $tdSectionLevel = null )
function inputTagXML( &$tag, $currentSectionLevel, $tdSectionLevel = null )
{
$output = '';
$tagName = $tag instanceof DOMNode ? $tag->nodeName : '';
Expand Down
4 changes: 2 additions & 2 deletions extension/ezoe/modules/ezoe/classes/GoogleSpell.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ function &_getMatches($lang, $str) {
}

function _unhtmlentities($string) {
$string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
$string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
$string = preg_replace_callback('~&#x([0-9a-f]+);~i', function($m) {return chr(hexdec($m[1]));}, $string);
$string = preg_replace_callback('~&#([0-9]+);~', function($m) {return chr($m[1]);}, $string);

$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
Expand Down
12 changes: 10 additions & 2 deletions extension/ezoe/modules/ezoe/classes/SpellChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
*
* @author Moxiecode
* @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
* @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
*/

class SpellChecker {
Expand All @@ -12,10 +12,18 @@ class SpellChecker {
*
* @param $config Configuration name/value array.
*/
function SpellChecker(&$config) {
function __construct(&$config) {
$this->_config = $config;
}

/**
* @deprecated Use SpellChecker::__construct() instead
* @param $config
*/
function SpellChecker(&$config) {
self::__construct($config);
}

/**
* Simple loopback function everything that gets in will be send back.
*
Expand Down
19 changes: 17 additions & 2 deletions extension/ezoe/modules/ezoe/classes/utils/mcejson.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package MCManager.utils
* @author Moxiecode
* @copyright Copyright © 2007, Moxiecode Systems AB, All rights reserved.
* @copyright Copyright © 2007, Moxiecode Systems AB, All rights reserved.
*/

class Moxiecode_JSONReader
Expand Down Expand Up @@ -36,7 +36,7 @@ class Moxiecode_JSONReader
private $_lastLocations;
private $_needProp;

function Moxiecode_JSONReader($data) {
function __construct($data) {
$this->_data = $data;
$this->_len = strlen($data);
$this->_pos = -1;
Expand All @@ -45,6 +45,14 @@ function Moxiecode_JSONReader($data) {
$this->_needProp = false;
}

/**
* @deprecated Use Moxiecode_JSONReader::__construct() instead
* @param $data
*/
function Moxiecode_JSONReader($data) {
self::__construct($data);
}

function getToken() {
return $this->_token;
}
Expand Down Expand Up @@ -367,7 +375,14 @@ function peek() {
* @package MCManager.utils
*/
class Moxiecode_JSON {
function __construct() {
}

/**
* @deprecated Use Moxiecode_JSON::__construct() instead
*/
function Moxiecode_JSON() {
self::__construct();
}

function decode($input) {
Expand Down
4 changes: 2 additions & 2 deletions extension/ezoe/modules/ezoe/spellcheck_rpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ function getRequestParam($name, $default_value = false, $sanitize = false)
// Try globals array
if (!$raw && isset($_GLOBALS["HTTP_RAW_POST_DATA"]))
$raw = $_GLOBALS["HTTP_RAW_POST_DATA"];
else if (!$raw && isset($HTTP_RAW_POST_DATA))
$raw = $HTTP_RAW_POST_DATA;
else if (!$raw)
$raw = file_get_contents("php://input");

// Try stream
if (!$raw)
Expand Down
2 changes: 1 addition & 1 deletion kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function isValid()
\pure
\return the suffix for the attribute template, if false it is ignored.
*/
function &viewTemplateSuffix( &$contentobjectAttribute )
function viewTemplateSuffix( &$contentobjectAttribute )
{
$suffix = false;
return $suffix;
Expand Down
2 changes: 1 addition & 1 deletion kernel/classes/ezpersistentobject.php
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ public function attribute( $attr, $noFunction = false )

if ( isset( $def["functions"][$attr] ) )
{
return $this->$def["functions"][$attr]();
return $this->{$def["functions"][$attr]}();
}

eZDebug::writeError( "Attribute '$attr' does not exist", $def['class_name'] . '::attribute' );
Expand Down
14 changes: 12 additions & 2 deletions kernel/private/classes/clusterfilehandlers/dfsbackends/mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ public function _exists( $filePath, $fname = false, $ignoreExpiredFiles = true,
* @param string $dir
* @return bool
*/
protected function __mkdir_p( $dir )
private function mkdir_p( $dir )
{
// create parent directories
$dirElements = explode( '/', $dir );
Expand Down Expand Up @@ -685,6 +685,16 @@ protected function __mkdir_p( $dir )
return $result;
}

/**
* @deprecated Use eZDFSFileHandlerMySQLiBackend::mkdir_p() instead
* @param $dir
* @return bool
*/
protected function __mkdir_p( $dir )
{
return $this->mkdir_p( $dir );
}

/**
* Fetches the file $filePath from the database to its own name
*
Expand Down Expand Up @@ -716,7 +726,7 @@ public function _fetch( $filePath, $uniqueName = false )
$tmpFilePath = substr_replace( $filePath, $tmpid, strrpos( $filePath, '.' ), 0 );
else
$tmpFilePath = $filePath . '.' . $tmpid;
$this->__mkdir_p( dirname( $tmpFilePath ) );
$this->mkdir_p( dirname( $tmpFilePath ) );
eZDebugSetting::writeDebug( 'kernel-clustering', "copying DFS://$filePath to FS://$tmpFilePath on try: $loopCount " );

// copy DFS file to temporary FS path
Expand Down
7 changes: 2 additions & 5 deletions kernel/setup/steps/ezstep_site_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,10 @@ function retrieveRemoteSitePackagesList()
*/
function fopen( $fileName, $mode )
{
$savedTrackErrorsFlag = ini_get( 'track_errors' );
ini_set( 'track_errors', 1 );
error_clear_last();

if ( ( $handle = @fopen( $fileName, 'wb' ) ) === false )
$this->FileOpenErrorMsg = $php_errormsg;

ini_set( 'track_errors', $savedTrackErrorsFlag );
$this->FileOpenErrorMsg = implode(',', error_get_last());

return $handle;
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/url/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
$preFix = $protocol . "://" . $domain;
$preFix .= eZSys::wwwDir();

$link = preg_replace("/^\//e", "", $link );
$link = preg_replace("/^\//", "", $link );
$link = $preFix . "/" . $link;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ezdb/classes/ezmysqlidb.php
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ function escapeString( $str )
else
{
eZDebug::writeDebug( 'escapeString called before connection is made', __METHOD__ );
return mysql_escape_string( $str );
return mysqli_real_escape_string( $str );
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ezdbschema/classes/ezmysqlschema.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ function escapeSQLString( $value )
return $this->DBInstance->escapeString( $value );
}

return mysql_escape_string( $value );
return mysqli_real_escape_string( $value );
}

function schemaType()
Expand Down
9 changes: 2 additions & 7 deletions lib/ezfile/classes/ezgzipzlibcompressionhandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,8 @@ function compressionLevel()
*/
static function isAvailable()
{
$extensionName = 'zlib';
if ( !extension_loaded( $extensionName ) )
{
$dlExtension = ( eZSys::osType() == 'win32' ) ? '.dll' : '.so';
@dl( $extensionName . $dlExtension );
}
return extension_loaded( $extensionName );
// Only check a few of the functions, it's assumed all used gz methods are here if these two are present
return function_exists('gzcompress') && function_exists('gzuncompress');
}

function doOpen( $filename, $mode )
Expand Down
14 changes: 12 additions & 2 deletions lib/ezpdf/classes/class.ezpdftable.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class eZPDFTable extends Cezpdf
* @param string $paper
* @param string $orientation
*/
function eZPDFTable($paper='a4',$orientation='portrait')
function __construct($paper='a4',$orientation='portrait')
{
parent::__construct( $paper, $orientation );
$this->TOC = array();
Expand All @@ -49,6 +49,16 @@ function eZPDFTable($paper='a4',$orientation='portrait')
$this->FrontpageID = null;
}

/**
* @deprecated Use eZPDFTable::__construct() instead
* @param string $paper
* @param string $orientation
*/
function eZPDFTable($paper='a4',$orientation='portrait')
{
self::__construct($paper,$orientation);
}

/*!
* \private
* Initialize footer and header frame margins. Called by constructor
Expand Down Expand Up @@ -1516,7 +1526,7 @@ function callFont( $params )
return '';
}

function &fixWhitespace( &$text )
function fixWhitespace( &$text )
{
$text = str_replace( array( self::SPACE,
self::TAB,
Expand Down
17 changes: 1 addition & 16 deletions lib/ezpdf/classes/class.pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2014,10 +2014,7 @@ function selectFont( $fontName, $encoding = '', $set = 1 )
// note that pdf supports only binary format type 1 font files, though there is a
// simple utility to convert them from pfa to pfb.
$fp = fopen( $fbfile, 'rb' );
$tmp = get_magic_quotes_runtime();
set_magic_quotes_runtime( 0 );
$data = fread( $fp, filesize( $fbfile ) );
set_magic_quotes_runtime( $tmp );
fclose( $fp );

// create the font descriptor
Expand Down Expand Up @@ -3564,8 +3561,6 @@ function addPngFromFile( $file, $x, $y, $w = 0, $h = 0 )
{
// read in a png file, interpret it, then add to the system
$error = 0;
$tmp = get_magic_quotes_runtime();
set_magic_quotes_runtime(0);
$fp = @fopen( $file, 'rb' );
if ( $fp )
{
Expand All @@ -3581,7 +3576,6 @@ function addPngFromFile( $file, $x, $y, $w = 0, $h = 0 )
$error = 1;
$errormsg = 'trouble opening file: '.$file;
}
set_magic_quotes_runtime( $tmp );

if ( !$error )
{
Expand Down Expand Up @@ -3832,10 +3826,7 @@ function addJpegFromFile( $img, $x, $y, $w = 0, $h = 0 )

$fp = fopen( $img, 'rb' );

$tmp = get_magic_quotes_runtime();
set_magic_quotes_runtime( 0 );
$data = fread( $fp, filesize( $img ) );
set_magic_quotes_runtime( $tmp );

fclose( $fp );

Expand Down Expand Up @@ -3886,11 +3877,8 @@ function addImage( &$img, $x, $y, $w = 0, $h = 0, $quality = 75 )
$tmpDir = '/tmp';
$tmpName = tempnam( $tmpDir, 'img' );
imagejpeg( $img, $tmpName, $quality );
$fp = fopen( $tmpName, 'rb' );

$tmp = get_magic_quotes_runtime();
set_magic_quotes_runtime( 0 );
$fp = @fopen( $tmpName, 'rb' );
$fp = fopen( $tmpName, 'rb' );
if ( $fp )
{
$data = '';
Expand All @@ -3905,9 +3893,6 @@ function addImage( &$img, $x, $y, $w = 0, $h = 0, $quality = 75 )
$error = 1;
$errormsg = 'trouble opening file';
}
// $data = fread($fp,filesize($tmpName));
set_magic_quotes_runtime( $tmp );
// fclose( $fp );
unlink( $tmpName );
$this->addJpegImage_common( $data, $x, $y, $w, $h, $imageWidth, $imageHeight );
}
Expand Down
Loading

0 comments on commit 0711409

Please sign in to comment.