[ticket/12487] Update PHP code

PHPBB3-12487
This commit is contained in:
Gaëtan Muller 2014-12-30 02:22:13 +01:00
parent ef1be6e247
commit 63da128ee5
5 changed files with 25 additions and 89 deletions

View file

@ -303,8 +303,7 @@ class acp_search
} }
else else
{ {
$starttime = explode(' ', microtime()); $starttime = microtime(true);
$starttime = $starttime[1] + $starttime[0];
$row_count = 0; $row_count = 0;
while (still_on_time() && $post_counter <= $this->max_post_id) while (still_on_time() && $post_counter <= $this->max_post_id)
{ {
@ -336,8 +335,7 @@ class acp_search
if ($post_counter <= $this->max_post_id) if ($post_counter <= $this->max_post_id)
{ {
$mtime = explode(' ', microtime()); $totaltime = microtime(true) - $starttime;
$totaltime = $mtime[0] + $mtime[1] - $starttime;
$rows_per_second = $row_count / $totaltime; $rows_per_second = $row_count / $totaltime;
meta_refresh(1, append_sid($this->u_action . '&amp;action=delete&amp;skip_rows=' . $post_counter)); meta_refresh(1, append_sid($this->u_action . '&amp;action=delete&amp;skip_rows=' . $post_counter));
trigger_error($user->lang('SEARCH_INDEX_DELETE_REDIRECT', (int) $row_count, $post_counter, $rows_per_second)); trigger_error($user->lang('SEARCH_INDEX_DELETE_REDIRECT', (int) $row_count, $post_counter, $rows_per_second));
@ -376,8 +374,7 @@ class acp_search
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
$starttime = explode(' ', microtime()); $starttime = microtime(true);
$starttime = $starttime[1] + $starttime[0];
$row_count = 0; $row_count = 0;
while (still_on_time() && $post_counter <= $this->max_post_id) while (still_on_time() && $post_counter <= $this->max_post_id)
{ {
@ -426,8 +423,7 @@ class acp_search
if ($post_counter <= $this->max_post_id) if ($post_counter <= $this->max_post_id)
{ {
$mtime = explode(' ', microtime()); $totaltime = microtime(true) - $starttime;
$totaltime = $mtime[0] + $mtime[1] - $starttime;
$rows_per_second = $row_count / $totaltime; $rows_per_second = $row_count / $totaltime;
meta_refresh(1, append_sid($this->u_action . '&amp;action=create&amp;skip_rows=' . $post_counter)); meta_refresh(1, append_sid($this->u_action . '&amp;action=create&amp;skip_rows=' . $post_counter));
trigger_error($user->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $row_count, $post_counter) . $user->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $rows_per_second)); trigger_error($user->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $row_count, $post_counter) . $user->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $rows_per_second));

View file

@ -376,8 +376,7 @@ function still_on_time($extra_time = 15)
{ {
static $max_execution_time, $start_time; static $max_execution_time, $start_time;
$time = explode(' ', microtime()); $current_time = microtime(true);
$current_time = $time[0] + $time[1];
if (empty($max_execution_time)) if (empty($max_execution_time))
{ {
@ -802,7 +801,7 @@ function phpbb_own_realpath($path)
$max = sizeof($bits) - 1; $max = sizeof($bits) - 1;
// Check if we are able to resolve symlinks, Windows cannot. // Check if we are able to resolve symlinks, Windows (prior to Vista and Server 2008) cannot.
$symlink_resolve = (function_exists('readlink')) ? true : false; $symlink_resolve = (function_exists('readlink')) ? true : false;
foreach ($bits as $i => $bit) foreach ($bits as $i => $bit)
@ -3659,38 +3658,12 @@ function phpbb_checkdnsrr($host, $type = 'MX')
return (@gethostbyname($host_fqdn) == $host_fqdn) ? false : true; return (@gethostbyname($host_fqdn) == $host_fqdn) ? false : true;
} }
// checkdnsrr() is available on Windows since PHP 5.3, if (function_exists('checkdnsrr'))
// but until 5.3.3 it only works for MX records
// See: http://bugs.php.net/bug.php?id=51844
// Call checkdnsrr() if
// we're looking for an MX record or
// we're not on Windows or
// we're running a PHP version where #51844 has been fixed
// checkdnsrr() supports AAAA since 5.0.0
// checkdnsrr() supports TXT since 5.2.4
if (
($type == 'MX' || DIRECTORY_SEPARATOR != '\\' || version_compare(PHP_VERSION, '5.3.3', '>=')) &&
($type != 'AAAA' || version_compare(PHP_VERSION, '5.0.0', '>=')) &&
($type != 'TXT' || version_compare(PHP_VERSION, '5.2.4', '>=')) &&
function_exists('checkdnsrr')
)
{ {
return checkdnsrr($host_fqdn, $type); return checkdnsrr($host_fqdn, $type);
} }
// dns_get_record() is available since PHP 5; since PHP 5.3 also on Windows, if (function_exists('dns_get_record'))
// but on Windows it does not work reliable for AAAA records before PHP 5.3.1
// Call dns_get_record() if
// we're not looking for an AAAA record or
// we're not on Windows or
// we're running a PHP version where AAAA lookups work reliable
if (
($type != 'AAAA' || DIRECTORY_SEPARATOR != '\\' || version_compare(PHP_VERSION, '5.3.1', '>=')) &&
function_exists('dns_get_record')
)
{ {
// dns_get_record() expects an integer as second parameter // dns_get_record() expects an integer as second parameter
// We have to convert the string $type to the corresponding integer constant. // We have to convert the string $type to the corresponding integer constant.
@ -3837,11 +3810,6 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
$msg_text = $msg_long_text; $msg_text = $msg_long_text;
} }
if (!defined('E_DEPRECATED'))
{
define('E_DEPRECATED', 8192);
}
switch ($errno) switch ($errno)
{ {
case E_NOTICE: case E_NOTICE:

View file

@ -87,8 +87,7 @@ class jabber
*/ */
static public function can_use_ssl() static public function can_use_ssl()
{ {
// Will not work with PHP >= 5.2.1 or < 5.2.3RC2 until timeout problem with ssl hasn't been fixed (http://bugs.php.net/41236) return @extension_loaded('openssl');
return ((version_compare(PHP_VERSION, '5.2.1', '<') || version_compare(PHP_VERSION, '5.2.3RC2', '>=')) && @extension_loaded('openssl')) ? true : false;
} }
/** /**

View file

@ -33,8 +33,6 @@ class messenger
/** @var \phpbb\template\template */ /** @var \phpbb\template\template */
protected $template; protected $template;
var $eol = "\n";
/** /**
* Constructor * Constructor
*/ */
@ -44,10 +42,6 @@ class messenger
$this->use_queue = (!$config['email_package_size']) ? false : $use_queue; $this->use_queue = (!$config['email_package_size']) ? false : $use_queue;
$this->subject = ''; $this->subject = '';
// Determine EOL character (\n for UNIX, \r\n for Windows and \r for Mac)
$this->eol = (!defined('PHP_EOL')) ? (($eol = strtolower(substr(PHP_OS, 0, 3))) == 'win') ? "\r\n" : (($eol == 'mac') ? "\r" : "\n") : PHP_EOL;
$this->eol = (!$this->eol) ? "\n" : $this->eol;
} }
/** /**
@ -497,7 +491,7 @@ class messenger
$this->from = $board_contact; $this->from = $board_contact;
} }
$encode_eol = ($config['smtp_delivery']) ? "\r\n" : $this->eol; $encode_eol = ($config['smtp_delivery']) ? "\r\n" : PHP_EOL;
// Build to, cc and bcc strings // Build to, cc and bcc strings
$to = $cc = $bcc = ''; $to = $cc = $bcc = '';
@ -529,7 +523,7 @@ class messenger
} }
else else
{ {
$result = phpbb_mail($mail_to, $this->subject, $this->msg, $headers, $this->eol, $err_msg); $result = phpbb_mail($mail_to, $this->subject, $this->msg, $headers, PHP_EOL, $err_msg);
} }
if (!$result) if (!$result)
@ -686,10 +680,6 @@ class queue
$this->data = array(); $this->data = array();
$this->cache_file = "{$phpbb_root_path}cache/queue.$phpEx"; $this->cache_file = "{$phpbb_root_path}cache/queue.$phpEx";
// Determine EOL character (\n for UNIX, \r\n for Windows and \r for Mac)
$this->eol = (!defined('PHP_EOL')) ? (($eol = strtolower(substr(PHP_OS, 0, 3))) == 'win') ? "\r\n" : (($eol == 'mac') ? "\r" : "\n") : PHP_EOL;
$this->eol = (!$this->eol) ? "\n" : $this->eol;
} }
/** /**
@ -822,7 +812,7 @@ class queue
} }
else else
{ {
$result = phpbb_mail($to, $subject, $msg, $headers, $this->eol, $err_msg); $result = phpbb_mail($to, $subject, $msg, $headers, PHP_EOL, $err_msg);
} }
if (!$result) if (!$result)

View file

@ -19,10 +19,6 @@ if (!defined('IN_PHPBB'))
} }
// Report all errors, except notices and deprecation messages // Report all errors, except notices and deprecation messages
if (!defined('E_DEPRECATED'))
{
define('E_DEPRECATED', 8192);
}
$level = E_ALL & ~E_NOTICE & ~E_DEPRECATED; $level = E_ALL & ~E_NOTICE & ~E_DEPRECATED;
error_reporting($level); error_reporting($level);
@ -105,33 +101,21 @@ else
define('STRIP', (get_magic_quotes_gpc()) ? true : false); define('STRIP', (get_magic_quotes_gpc()) ? true : false);
} }
// Prevent date/time functions from throwing E_WARNING on PHP 5.3 by setting a default timezone // In PHP 5.3.0 the error level has been raised to E_WARNING which causes problems
if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) // because we show E_WARNING errors and do not set a default timezone.
{ // This is because we have our own timezone handling and work in UTC only anyway.
// For PHP 5.1.0 the date/time functions have been rewritten
// and setting a timezone is required prior to calling any date/time function.
// Since PHP 5.2.0 calls to date/time functions without having a timezone set // So what we basically want to do is set our timezone to UTC,
// result in E_STRICT errors being thrown. // but we don't know what other scripts (such as bridges) are involved,
// Note: We already exclude E_STRICT errors // so we check whether a timezone is already set by calling date_default_timezone_get().
// (to be exact: they are not included in E_ALL in PHP 5.2)
// In PHP 5.3.0 the error level has been raised to E_WARNING which causes problems // Unfortunately, date_default_timezone_get() itself might throw E_WARNING
// because we show E_WARNING errors and do not set a default timezone. // if no timezone has been set, so we have to keep it quiet with @.
// This is because we have our own timezone handling and work in UTC only anyway.
// So what we basically want to do is set our timezone to UTC, // date_default_timezone_get() tries to guess the correct timezone first
// but we don't know what other scripts (such as bridges) are involved, // and then falls back to UTC when everything fails.
// so we check whether a timezone is already set by calling date_default_timezone_get(). // We just set the timezone to whatever date_default_timezone_get() returns.
date_default_timezone_set(@date_default_timezone_get());
// Unfortunately, date_default_timezone_get() itself might throw E_WARNING
// if no timezone has been set, so we have to keep it quiet with @.
// date_default_timezone_get() tries to guess the correct timezone first
// and then falls back to UTC when everything fails.
// We just set the timezone to whatever date_default_timezone_get() returns.
date_default_timezone_set(@date_default_timezone_get());
}
// Autoloading of dependencies. // Autoloading of dependencies.
// Three options are supported: // Three options are supported:
@ -168,5 +152,4 @@ else
require($phpbb_root_path . 'vendor/autoload.php'); require($phpbb_root_path . 'vendor/autoload.php');
} }
$starttime = explode(' ', microtime()); $starttime = microtime(true);
$starttime = $starttime[1] + $starttime[0];