Skip to content

Commit

Permalink
[4] Add intl extension check to system info, and while there clean up…
Browse files Browse the repository at this point in the history
… deprecations/types/[] (#33457)

* add check for intl and moderise code and remove deprecated calls

* php modernisation

* HArd code the names of PHP Extensions to avoid them being translated
  • Loading branch information
Phil E. Taylor authored May 1, 2021
1 parent 2c57a4a commit 15c7ecb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 50 deletions.
98 changes: 50 additions & 48 deletions administrator/components/com_admin/src/Model/SysinfoModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ class SysinfoModel extends BaseDatabaseModel
* @var array
* @since 1.6
*/
protected $php_settings = array();
protected $php_settings = [];

/**
* Config values
*
* @var array
* @since 1.6
*/
protected $config = array();
protected $config = [];

/**
* Some system values
*
* @var array
* @since 1.6
*/
protected $info = array();
protected $info = [];

/**
* PHP info
Expand All @@ -74,8 +74,8 @@ class SysinfoModel extends BaseDatabaseModel
*
* @since 3.5
*/
protected $privateSettings = array(
'phpInfoArray' => array(
protected $privateSettings = [
'phpInfoArray' => [
'CONTEXT_DOCUMENT_ROOT',
'Cookie',
'DOCUMENT_ROOT',
Expand Down Expand Up @@ -111,8 +111,8 @@ class SysinfoModel extends BaseDatabaseModel
'upload_tmp_dir',
'User/Group',
'open_basedir',
),
'other' => array(
],
'other' => [
'db',
'dbprefix',
'fromname',
Expand All @@ -137,8 +137,8 @@ class SysinfoModel extends BaseDatabaseModel
'smtphost',
'tmp_path',
'open_basedir',
)
);
]
];

/**
* System values that can be "safely" shared
Expand All @@ -155,7 +155,7 @@ class SysinfoModel extends BaseDatabaseModel
* @var array
* @since 1.6
*/
protected $directories = array();
protected $directories = [];

/**
* The current editor.
Expand All @@ -175,7 +175,7 @@ class SysinfoModel extends BaseDatabaseModel
*
* @since 3.5
*/
protected function cleanPrivateData($dataArray, $dataType = 'other')
protected function cleanPrivateData(array $dataArray, string $dataType = 'other'): array
{
$dataType = isset($this->privateSettings[$dataType]) ? $dataType : 'other';

Expand All @@ -188,12 +188,12 @@ protected function cleanPrivateData($dataArray, $dataType = 'other')

foreach ($dataArray as $section => $values)
{
if (is_array($values))
if (\is_array($values))
{
$dataArray[$section] = $this->cleanPrivateData($values, $dataType);
}

if (in_array($section, $privateSettings, true))
if (\in_array($section, $privateSettings, true))
{
$dataArray[$section] = $this->cleanSectionPrivateData($values);
}
Expand All @@ -207,13 +207,13 @@ protected function cleanPrivateData($dataArray, $dataType = 'other')
*
* @param mixed $sectionValues Section data
*
* @return mixed
* @return string|array
*
* @since 3.5
*/
protected function cleanSectionPrivateData($sectionValues)
{
if (!is_array($sectionValues))
if (!\is_array($sectionValues))
{
if (strstr($sectionValues, JPATH_ROOT))
{
Expand All @@ -238,14 +238,14 @@ protected function cleanSectionPrivateData($sectionValues)
*
* @since 1.6
*/
public function &getPhpSettings()
public function &getPhpSettings(): array
{
if (!empty($this->php_settings))
{
return $this->php_settings;
}

$this->php_settings = array(
$this->php_settings = [
'memory_limit' => ini_get('memory_limit'),
'upload_max_filesize' => ini_get('upload_max_filesize'),
'post_max_size' => ini_get('post_max_size'),
Expand All @@ -262,8 +262,9 @@ public function &getPhpSettings()
'zip' => function_exists('zip_open') && function_exists('zip_read'),
'mbstring' => extension_loaded('mbstring'),
'iconv' => function_exists('iconv'),
'intl' => function_exists('transliterator_transliterate'),
'max_input_vars' => ini_get('max_input_vars'),
);
];

return $this->php_settings;
}
Expand All @@ -275,7 +276,7 @@ public function &getPhpSettings()
*
* @since 1.6
*/
public function &getConfig()
public function &getConfig(): array
{
if (!empty($this->config))
{
Expand All @@ -284,11 +285,11 @@ public function &getConfig()

$registry = new Registry(new \JConfig);
$this->config = $registry->toArray();
$hidden = array(
$hidden = [
'host', 'user', 'password', 'ftp_user', 'ftp_pass',
'smtpuser', 'smtppass', 'redis_server_auth', 'session_redis_server_auth',
'proxy_user', 'proxy_pass', 'secret'
);
];

foreach ($hidden as $key)
{
Expand All @@ -305,7 +306,7 @@ public function &getConfig()
*
* @since 1.6
*/
public function &getInfo()
public function &getInfo(): array
{
if (!empty($this->info))
{
Expand All @@ -314,7 +315,7 @@ public function &getInfo()

$db = $this->getDbo();

$this->info = array(
$this->info = [
'php' => php_uname(),
'dbserver' => $db->getServerType(),
'dbversion' => $db->getVersion(),
Expand All @@ -327,7 +328,7 @@ public function &getInfo()
'sapi_name' => PHP_SAPI,
'version' => (new Version)->getLongVersion(),
'useragent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
);
];

return $this->info;
}
Expand All @@ -339,9 +340,9 @@ public function &getInfo()
*
* @since 3.4.1
*/
public function phpinfoEnabled()
public function phpinfoEnabled(): bool
{
return !in_array('phpinfo', explode(',', ini_get('disable_functions')));
return !\in_array('phpinfo', explode(',', ini_get('disable_functions')));
}

/**
Expand All @@ -354,7 +355,7 @@ public function phpinfoEnabled()
*
* @since 3.5
*/
public function getSafeData($dataType, $public = true)
public function getSafeData(string $dataType, bool $public = true): array
{
if (isset($this->safeData[$dataType]))
{
Expand All @@ -365,7 +366,7 @@ public function getSafeData($dataType, $public = true)

if (!method_exists($this, $methodName))
{
return array();
return [];
}

$data = $this->$methodName($public);
Expand All @@ -382,7 +383,7 @@ public function getSafeData($dataType, $public = true)
*
* @since 1.6
*/
public function &getPHPInfo()
public function &getPHPInfo(): string
{
if (!$this->phpinfoEnabled())
{
Expand All @@ -406,7 +407,7 @@ public function &getPHPInfo()
$output = preg_replace('#(\w),(\w)#', '\1, \2', $output);
$output = preg_replace('#<hr />#', '', $output);
$output = str_replace('<div class="text-center">', '', $output);
$output = preg_replace('#<tr class="h">(.*)<\/tr>#', '<thead><tr class="h">$1</tr></thead><tbody>', $output);
$output = preg_replace('#<tr class="h">(.*)</tr>#', '<thead><tr class="h">$1</tr></thead><tbody>', $output);
$output = str_replace('</table>', '</tbody></table>', $output);
$output = str_replace('</div>', '', $output);
$this->php_info = $output;
Expand All @@ -421,7 +422,7 @@ public function &getPHPInfo()
*
* @since 3.5
*/
public function getPhpInfoArray()
public function getPhpInfoArray(): array
{
// Already cached
if (null !== $this->phpInfoArray)
Expand All @@ -443,10 +444,10 @@ public function getPhpInfoArray()
*
* @since 3.5
*/
public function getExtensions()
public function getExtensions(): array
{
$installed = array();
$db = Factory::getDbo();
$installed = [];
$db = Factory::getContainer()->get('DatabaseDriver');
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__extensions'));
Expand Down Expand Up @@ -485,24 +486,24 @@ public function getExtensions()
continue;
}

$installed[$extension->name] = array(
$installed[$extension->name] = [
'name' => $extension->name,
'type' => $extension->type,
'state' => $extension->enabled ? Text::_('JENABLED') : Text::_('JDISABLED'),
'author' => 'unknown',
'version' => 'unknown',
'creationDate' => 'unknown',
'authorUrl' => 'unknown',
);
];

$manifest = new Registry($extension->manifest_cache);

$extraData = array(
$extraData = [
'author' => $manifest->get('author', ''),
'version' => $manifest->get('version', ''),
'creationDate' => $manifest->get('creationDate', ''),
'authorUrl' => $manifest->get('authorUrl', '')
);
];

$installed[$extension->name] = array_merge($installed[$extension->name], $extraData);
}
Expand All @@ -513,20 +514,21 @@ public function getExtensions()
/**
* Method to get the directory states
*
* @param bool $public If true no information is going to be removed
* @param bool $public If true no information is going to be removed
*
* @return array States of directories
*
* @throws \Exception
* @since 1.6
*/
public function getDirectory($public = false)
public function getDirectory(bool $public = false): array
{
if (!empty($this->directories))
{
return $this->directories;
}

$this->directories = array();
$this->directories = [];

$registry = Factory::getApplication()->getConfig();
$cparams = ComponentHelper::getParams('com_media');
Expand Down Expand Up @@ -679,9 +681,9 @@ public function getDirectory($public = false)
*
* @since 1.6
*/
private function addDirectory($name, $path, $message = '')
private function addDirectory(string $name, string $path, string $message = ''): void
{
$this->directories[$name] = array('writable' => is_writable($path), 'message' => $message,);
$this->directories[$name] = ['writable' => is_writable($path), 'message' => $message,];
}

/**
Expand All @@ -692,7 +694,7 @@ private function addDirectory($name, $path, $message = '')
* @note Has to be removed (it is present in the config...)
* @since 1.6
*/
public function &getEditor()
public function &getEditor(): string
{
if (!is_null($this->editor))
{
Expand All @@ -714,14 +716,14 @@ public function &getEditor()
*
* @since 3.5
*/
protected function parsePhpInfo($html)
protected function parsePhpInfo(string $html): array
{
$html = strip_tags($html, '<h2><th><td>');
$html = preg_replace('/<th[^>]*>([^<]+)<\/th>/', '<info>\1</info>', $html);
$html = preg_replace('/<td[^>]*>([^<]+)<\/td>/', '<info>\1</info>', $html);
$t = preg_split('/(<h2[^>]*>[^<]+<\/h2>)/', $html, -1, PREG_SPLIT_DELIM_CAPTURE);
$r = array();
$count = count($t);
$r = [];
$count = \count($t);
$p1 = '<info>([^<]+)<\/info>';
$p2 = '/' . $p1 . '\s*' . $p1 . '\s*' . $p1 . '/';
$p3 = '/' . $p1 . '\s*' . $p1 . '/';
Expand All @@ -738,7 +740,7 @@ protected function parsePhpInfo($html)
// 3cols
if (preg_match($p2, $val, $matchs))
{
$r[$name][trim($matchs[1])] = array(trim($matchs[2]), trim($matchs[3]),);
$r[$name][trim($matchs[1])] = [trim($matchs[2]), trim($matchs[3]),];
}
// 2cols
elseif (preg_match($p3, $val, $matchs))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,20 @@
</tr>
<tr>
<th scope="row">
<?php echo Text::_('COM_ADMIN_ICONV_AVAILABLE'); ?>
iconv <?php echo Text::_('COM_ADMIN_EXTENSION_AVAILABLE'); ?>
</th>
<td>
<?php echo HTMLHelper::_('phpsetting.set', $this->phpSettings['iconv']); ?>
</td>
</tr>
<tr>
<th scope="row">
intl <?php echo Text::_('COM_ADMIN_EXTENSION_AVAILABLE'); ?>
</th>
<td>
<?php echo HTMLHelper::_('phpsetting.set', $this->phpSettings['intl']); ?>
</td>
</tr>
<tr>
<th scope="row">
<?php echo Text::_('COM_ADMIN_MAX_INPUT_VARS'); ?>
Expand Down
2 changes: 1 addition & 1 deletion administrator/language/en-GB/com_admin.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ COM_ADMIN_DISABLED_FUNCTIONS="Disabled Functions"
COM_ADMIN_DISPLAY_ERRORS="Display Errors"
COM_ADMIN_DOWNLOAD_SYSTEM_INFORMATION_JSON="Download as JSON"
COM_ADMIN_DOWNLOAD_SYSTEM_INFORMATION_TEXT="Download as text"
COM_ADMIN_EXTENSION_AVAILABLE="Available"
COM_ADMIN_EXTENSIONS="Extensions"
COM_ADMIN_FILE_UPLOADS="File Uploads"
COM_ADMIN_GLOSSARY="Glossary"
Expand Down Expand Up @@ -118,7 +119,6 @@ COM_ADMIN_HELP_USERS_USER_MANAGER="Users"
COM_ADMIN_HELP_USERS_USER_MANAGER_EDIT="Users: New/Edit"
COM_ADMIN_HELP_USERS_USER_NOTES="Users: User Notes"
COM_ADMIN_HELP_USERS_USER_NOTES_EDIT="Users: User Notes - New/Edit"
COM_ADMIN_ICONV_AVAILABLE="Iconv Available"
COM_ADMIN_JOOMLA_VERSION="Joomla! Version"
COM_ADMIN_LICENSE="License"
COM_ADMIN_LOG_DIRECTORY="(Log folder)"
Expand Down

0 comments on commit 15c7ecb

Please sign in to comment.