Commit f8839bf4 authored by Côme Chilliet's avatar Côme Chilliet

🚑 fix(code) Use shorthand array syntax

issue #5955
parent 43447205
...@@ -61,17 +61,17 @@ function smarty_block_render ($params, $text) ...@@ -61,17 +61,17 @@ function smarty_block_render ($params, $text)
} }
/* Remove select options */ /* Remove select options */
$from = array( $from = [
"#<option.*<\/option>#is", "#<option.*<\/option>#is",
"/(<textarea.*>).*(<\/textarea>)/is", "/(<textarea.*>).*(<\/textarea>)/is",
"/^(.*<input.*)checked(.*>.*)$/isD" "/^(.*<input.*)checked(.*>.*)$/isD"
); ];
$to = array( $to = [
" ", " ",
"\\1\\2", "\\1\\2",
"\\1 \\2" "\\1 \\2"
); ];
return preg_replace($from, $to, $text); return preg_replace($from, $to, $text);
} }
...@@ -21,14 +21,14 @@ ...@@ -21,14 +21,14 @@
function smarty_function_msgPool ($params) function smarty_function_msgPool ($params)
{ {
if (class_available('msgPool') && isset($params['type'])) { if (class_available('msgPool') && isset($params['type'])) {
$parameter = array(); $parameter = [];
foreach ($params as $para => $value) { foreach ($params as $para => $value) {
if (!preg_match('/^type$/i', $para)) { if (!preg_match('/^type$/i', $para)) {
$parameter[$para] = $value; $parameter[$para] = $value;
} }
} }
if (is_callable('msgPool::'.$params['type'])) { if (is_callable('msgPool::'.$params['type'])) {
echo call_user_func_array(array('msgPool',$params['type']), $parameter); echo call_user_func_array(['msgPool',$params['type']], $parameter);
} else { } else {
trigger_error('Unknown msgPool function '.$params['type']); trigger_error('Unknown msgPool function '.$params['type']);
} }
......
...@@ -30,7 +30,7 @@ reset_errors(); ...@@ -30,7 +30,7 @@ reset_errors();
/* Logged in? Simple security check */ /* Logged in? Simple security check */
if (!session::global_is_set('ui')) { if (!session::global_is_set('ui')) {
logging::log('security', 'unknown', '', array(), 'Error: autocomplete.php called without session'); logging::log('security', 'unknown', '', [], 'Error: autocomplete.php called without session');
header('Location: index.php'); header('Location: index.php');
exit; exit;
} }
......
...@@ -31,7 +31,7 @@ reset_errors(); ...@@ -31,7 +31,7 @@ reset_errors();
/* Logged in? Simple security check */ /* Logged in? Simple security check */
if (!session::global_is_set('ui')) { if (!session::global_is_set('ui')) {
logging::log('security', 'unknown', '', array(), 'Error: getbin.php called without session'); logging::log('security', 'unknown', '', [], 'Error: getbin.php called without session');
header('Location: index.php'); header('Location: index.php');
exit; exit;
} }
......
...@@ -34,7 +34,7 @@ if (session::global_is_set('config')) { ...@@ -34,7 +34,7 @@ if (session::global_is_set('config')) {
} else { } else {
header("cache-control: no-cache"); header("cache-control: no-cache");
} }
IconTheme::$extensions = array('png'); IconTheme::$extensions = ['png'];
if (!isset($_GET['context']) || !isset($_GET['icon']) || !isset($_GET['size'])) { if (!isset($_GET['context']) || !isset($_GET['icon']) || !isset($_GET['size'])) {
trigger_error('Missing information in query string: '.$_SERVER['QUERY_STRING']); trigger_error('Missing information in query string: '.$_SERVER['QUERY_STRING']);
exit; exit;
......
...@@ -123,7 +123,7 @@ if ( ...@@ -123,7 +123,7 @@ if (
($config->get_cfg_value('casActivated') == 'TRUE') || ($config->get_cfg_value('casActivated') == 'TRUE') ||
($config->get_cfg_value('httpAuthActivated') == 'TRUE') || ($config->get_cfg_value('httpAuthActivated') == 'TRUE') ||
($config->get_cfg_value('httpHeaderAuthActivated') == 'TRUE') || ($config->get_cfg_value('httpHeaderAuthActivated') == 'TRUE') ||
in_array($config->get_cfg_value('LoginMethod'), array('LoginCas', 'LoginHTTPAuth', 'LoginHTTPHeader'))) { in_array($config->get_cfg_value('LoginMethod'), ['LoginCas', 'LoginHTTPAuth', 'LoginHTTPHeader'])) {
session::global_set('DEBUGLEVEL', 0); session::global_set('DEBUGLEVEL', 0);
} }
......
...@@ -46,7 +46,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { ...@@ -46,7 +46,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
/* Logged in? Simple security check */ /* Logged in? Simple security check */
if (!session::global_is_set('connected')) { if (!session::global_is_set('connected')) {
logging::log('security', 'login', '', array(), 'main.php called without session - logging out'); logging::log('security', 'login', '', [], 'main.php called without session - logging out');
header('Location: index.php?message=nosession'); header('Location: index.php?message=nosession');
exit; exit;
} }
...@@ -78,7 +78,7 @@ if (session::global_get('_LAST_PAGE_REQUEST') != '') { ...@@ -78,7 +78,7 @@ if (session::global_get('_LAST_PAGE_REQUEST') != '') {
*/ */
if ($request_time > $max_life) { if ($request_time > $max_life) {
session::destroy(); session::destroy();
logging::log('security', 'login', '', array(), 'main.php called with expired session - logging out'); logging::log('security', 'login', '', [], 'main.php called with expired session - logging out');
header('Location: index.php?signout=1&message=expired'); header('Location: index.php?signout=1&message=expired');
exit; exit;
} }
...@@ -114,7 +114,7 @@ if ($config->get_cfg_value("handleExpiredAccounts") == "TRUE") { ...@@ -114,7 +114,7 @@ if ($config->get_cfg_value("handleExpiredAccounts") == "TRUE") {
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, 'This user account ('.$ui->uid.') is about to expire'); @DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $expired, 'This user account ('.$ui->uid.') is about to expire');
// The users password is about to xpire soon, display a warning message. // The users password is about to xpire soon, display a warning message.
logging::log('security', 'fusiondirectory', '', array(), 'password for user "'.$ui->uid.'" is about to expire'); logging::log('security', 'fusiondirectory', '', [], 'password for user "'.$ui->uid.'" is about to expire');
msg_dialog::display(_('Password change'), _('Your password is about to expire, please change your password!'), INFO_DIALOG); msg_dialog::display(_('Password change'), _('Your password is about to expire, please change your password!'), INFO_DIALOG);
session::set('POSIX_WARN_ABOUT_EXPIRATION__DONE', TRUE); session::set('POSIX_WARN_ABOUT_EXPIRATION__DONE', TRUE);
} elseif ($expired == POSIX_FORCE_PASSWORD_CHANGE) { } elseif ($expired == POSIX_FORCE_PASSWORD_CHANGE) {
......
...@@ -57,7 +57,7 @@ if (!function_exists("imagecreate")) { ...@@ -57,7 +57,7 @@ if (!function_exists("imagecreate")) {
} else { } else {
$x_matches = FALSE; $x_matches = FALSE;
$y_matches = FALSE; $y_matches = FALSE;
foreach (array(7,6,5,4,3,2,1,0) as $font) { foreach ([7,6,5,4,3,2,1,0] as $font) {
$fx = ImageFontWidth($font) * strlen("$p%"); $fx = ImageFontWidth($font) * strlen("$p%");
$fy = ImageFontHeight($font); $fy = ImageFontHeight($font);
......
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
*/ */
function parse_scores ($str) function parse_scores ($str)
{ {
$scores = array(); $scores = [];
$parts = preg_split('/,/', $str); $parts = preg_split('/,/', $str);
foreach ($parts as $part) { foreach ($parts as $part) {
$part = trim(strtolower($part)); $part = trim(strtolower($part));
...@@ -109,7 +109,7 @@ function max_scores ($scores, $testvals) ...@@ -109,7 +109,7 @@ function max_scores ($scores, $testvals)
function parse_gettext_lang ($str) function parse_gettext_lang ($str)
{ {
if (preg_match("/^([^_]*)(_([^_]*))?\.(.*)$/", $str, $m)) { if (preg_match("/^([^_]*)(_([^_]*))?\.(.*)$/", $str, $m)) {
return array(strtolower($m[1]), strtolower($m[3]), strtolower($m[4])); return [strtolower($m[1]), strtolower($m[3]), strtolower($m[4])];
} else { } else {
return FALSE; return FALSE;
} }
...@@ -157,8 +157,8 @@ function al2gt ($gettextlangs) ...@@ -157,8 +157,8 @@ function al2gt ($gettextlangs)
} }
list ($lang, $country, $char) = $infos; list ($lang, $country, $char) = $infos;
$lang_score = max_scores($lang_scores, array($lang,$lang.'-'.$country,'*')); $lang_score = max_scores($lang_scores, [$lang,$lang.'-'.$country,'*']);
$char_score = max_scores($char_scores, array($char,'*')); $char_score = max_scores($char_scores, [$char,'*']);
if ($char_score == 0) { if ($char_score == 0) {
// exclude charsets the user refuses // exclude charsets the user refuses
continue; continue;
......
...@@ -43,7 +43,7 @@ class Combinations implements Iterator ...@@ -43,7 +43,7 @@ class Combinations implements Iterator
function current () function current ()
{ {
$r = array(); $r = [];
for ($i = 0; $i < $this->size; $i++) { for ($i = 0; $i < $this->size; $i++) {
$r[] = $this->input[$this->current[$i]]; $r[] = $this->input[$this->current[$i]];
} }
......
...@@ -34,20 +34,20 @@ class CopyPasteHandler ...@@ -34,20 +34,20 @@ class CopyPasteHandler
/*! /*!
* \brief This array contains all dns of the currently copied objects * \brief This array contains all dns of the currently copied objects
*/ */
protected $objectList = array(); protected $objectList = [];
/*! /*!
* \brief This array contains all remaining objects to paste * \brief This array contains all remaining objects to paste
*/ */
protected $queue = array(); protected $queue = [];
/*! /*!
* \brief The dn of the last edited object * \brief The dn of the last edited object
*/ */
protected $lastdn = ''; protected $lastdn = '';
protected $disallowed_objects = array(); protected $disallowed_objects = [];
protected $objects_to_fix = array(); protected $objects_to_fix = [];
protected $clean_objects = array(); protected $clean_objects = [];
protected $require_update = FALSE; protected $require_update = FALSE;
/*! /*!
...@@ -74,12 +74,12 @@ class CopyPasteHandler ...@@ -74,12 +74,12 @@ class CopyPasteHandler
{ {
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'add_to_queue'); @DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'add_to_queue');
if (!in_array($action, array('cut','copy'))) { if (!in_array($action, ['cut','copy'])) {
trigger_error(sprintf('Specified action "%s" does not exists for copy & paste.', $action)); trigger_error(sprintf('Specified action "%s" does not exists for copy & paste.', $action));
return FALSE; return FALSE;
} }
$tmp = array(); $tmp = [];
$tmp['method'] = $action; $tmp['method'] = $action;
$tmp['dn'] = $dn; $tmp['dn'] = $dn;
...@@ -109,8 +109,8 @@ class CopyPasteHandler ...@@ -109,8 +109,8 @@ class CopyPasteHandler
{ {
$this->current = FALSE; $this->current = FALSE;
$this->require_update = TRUE; $this->require_update = TRUE;
$this->queue = array(); $this->queue = [];
$this->objectList = array(); $this->objectList = [];
} }
/*! /*!
...@@ -138,7 +138,7 @@ class CopyPasteHandler ...@@ -138,7 +138,7 @@ class CopyPasteHandler
{ {
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $entry['dn'], 'load_entry_from_ldap'); @DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $entry['dn'], 'load_entry_from_ldap');
if (!isset($entry['tab_class']) && !isset($entry['type'])) { if (!isset($entry['tab_class']) && !isset($entry['type'])) {
return array(); return [];
} }
$entry['object'] = objects::open($entry['dn'], $entry['type']); $entry['object'] = objects::open($entry['dn'], $entry['type']);
...@@ -169,9 +169,9 @@ class CopyPasteHandler ...@@ -169,9 +169,9 @@ class CopyPasteHandler
* Create a list of all entries that can be pasted directly. * Create a list of all entries that can be pasted directly.
*/ */
if ($this->require_update) { if ($this->require_update) {
$this->clean_objects = array(); $this->clean_objects = [];
$this->objects_to_fix = array(); $this->objects_to_fix = [];
$this->disallowed_objects = array(); $this->disallowed_objects = [];
/* Put each queued object in one of the above arrays */ /* Put each queued object in one of the above arrays */
foreach ($this->queue as $key => $entry) { foreach ($this->queue as $key => $entry) {
...@@ -195,7 +195,7 @@ class CopyPasteHandler ...@@ -195,7 +195,7 @@ class CopyPasteHandler
} }
} }
if (count($this->disallowed_objects)) { if (count($this->disallowed_objects)) {
$dns = array(); $dns = [];
foreach ($this->disallowed_objects as $entry) { foreach ($this->disallowed_objects as $entry) {
$dns[] = $entry['dn']; $dns[] = $entry['dn'];
} }
......
This diff is collapsed.
...@@ -118,7 +118,7 @@ class Language ...@@ -118,7 +118,7 @@ class Language
$languages = static::getList(); $languages = static::getList();
/* Move supported languages to flat list */ /* Move supported languages to flat list */
$langs = array(); $langs = [];
foreach (array_keys($languages) as $lang) { foreach (array_keys($languages) as $lang) {
$langs[] = $lang.'.UTF-8'; $langs[] = $lang.'.UTF-8';
} }
...@@ -135,7 +135,7 @@ class Language ...@@ -135,7 +135,7 @@ class Language
public static function getList ($ownLanguage = FALSE) public static function getList ($ownLanguage = FALSE)
{ {
/* locales in english */ /* locales in english */
$tmp_english = array( $tmp_english = [
'en_US' => 'English', 'en_US' => 'English',
'af_ZA' => 'Afrikaans', 'af_ZA' => 'Afrikaans',
'ar_EG' => 'Arabic', 'ar_EG' => 'Arabic',
...@@ -166,12 +166,12 @@ class Language ...@@ -166,12 +166,12 @@ class Language
'vi_VN' => 'Vietnamese', 'vi_VN' => 'Vietnamese',
'zh_TW' => 'Taiwanese', 'zh_TW' => 'Taiwanese',
'zh_CN' => 'Chinese', 'zh_CN' => 'Chinese',
); ];
$ret = array(); $ret = [];
if ($ownLanguage) { if ($ownLanguage) {
/* locales in their own language */ /* locales in their own language */
$tmp_ownlang = array( $tmp_ownlang = [
'en_US' => 'English', 'en_US' => 'English',
'ar_EG' => 'عربية', 'ar_EG' => 'عربية',
'af_ZA' => 'Afrikaans', 'af_ZA' => 'Afrikaans',
...@@ -202,7 +202,7 @@ class Language ...@@ -202,7 +202,7 @@ class Language
'vi_VN' => 'Tiếng Việt', 'vi_VN' => 'Tiếng Việt',
'zh_TW' => 'Taiwanese', 'zh_TW' => 'Taiwanese',
'zh_CN' => '中文, 汉语, 漢語', 'zh_CN' => '中文, 汉语, 漢語',
); ];
foreach ($tmp_english as $key => $name) { foreach ($tmp_english as $key => $name) {
$ret[$key] = _($name).' ('.$tmp_ownlang[$key].')'; $ret[$key] = _($name).' ('.$tmp_ownlang[$key].')';
......
...@@ -28,17 +28,17 @@ class SnapshotCreateDialog extends simplePlugin ...@@ -28,17 +28,17 @@ class SnapshotCreateDialog extends simplePlugin
static function plInfo (): array static function plInfo (): array
{ {
return array( return [
'plShortName' => 'SnapshotCreateDialog', 'plShortName' => 'SnapshotCreateDialog',
); ];
} }
static function getAttributesInfo (): array static function getAttributesInfo (): array
{ {
return array( return [
'main' => array( 'main' => [
'name' => _('Creating an object snapshot'), 'name' => _('Creating an object snapshot'),
'attrs' => array( 'attrs' => [
new DisplayAttribute( new DisplayAttribute(
_('Object'), _('DN of the object you are creating a snapshot of'), _('Object'), _('DN of the object you are creating a snapshot of'),
'object_dn', FALSE 'object_dn', FALSE
...@@ -53,9 +53,9 @@ class SnapshotCreateDialog extends simplePlugin ...@@ -53,9 +53,9 @@ class SnapshotCreateDialog extends simplePlugin
'', '',
'SnapshotHandler' 'SnapshotHandler'
), ),
) ]
), ],
); ];
} }
function __construct ($dn, $parent, $aclCategory) function __construct ($dn, $parent, $aclCategory)
...@@ -116,7 +116,7 @@ class SnapshotCreateDialog extends simplePlugin ...@@ -116,7 +116,7 @@ class SnapshotCreateDialog extends simplePlugin
function save (): array function save (): array
{ {
$this->parent->createSnapshot($this->object_dn, $this->description); $this->parent->createSnapshot($this->object_dn, $this->description);
return array(); return [];
} }
} }
...@@ -125,7 +125,7 @@ class SnapshotCreateDialog extends simplePlugin ...@@ -125,7 +125,7 @@ class SnapshotCreateDialog extends simplePlugin
*/ */
class SnapshotsAttribute extends OrderedArrayAttribute class SnapshotsAttribute extends OrderedArrayAttribute
{ {
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = array(), $acl = '') function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $acl = '')
{ {
Attribute::__construct($label, $description, $ldapName, $required, $defaultValue, $acl); Attribute::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
$this->edit_enabled = FALSE; $this->edit_enabled = FALSE;
...@@ -139,18 +139,18 @@ class SnapshotsAttribute extends OrderedArrayAttribute ...@@ -139,18 +139,18 @@ class SnapshotsAttribute extends OrderedArrayAttribute
parent::setParent($plugin); parent::setParent($plugin);
if (is_object($this->plugin)) { if (is_object($this->plugin)) {
if ($this->plugin->global) { if ($this->plugin->global) {
$this->setHeaders(array( $this->setHeaders([
_('DN'), _('DN'),
_('Date'), _('Date'),
_('Description'), _('Description'),
'' ''
)); ]);
} else { } else {
$this->setHeaders(array( $this->setHeaders([
_('Date'), _('Date'),
_('Description'), _('Description'),
'' ''
)); ]);
} }
} }
} }
...@@ -184,10 +184,10 @@ class SnapshotsAttribute extends OrderedArrayAttribute ...@@ -184,10 +184,10 @@ class SnapshotsAttribute extends OrderedArrayAttribute
protected function getAttributeArrayValue ($key, $value) protected function getAttributeArrayValue ($key, $value)
{ {
$values = array( $values = [
date(_('Y-m-d, H:i:s'), preg_replace('/\-.*$/', '', $value['gosaSnapshotTimestamp'][0])), date(_('Y-m-d, H:i:s'), preg_replace('/\-.*$/', '', $value['gosaSnapshotTimestamp'][0])),
$value['description'][0] $value['description'][0]
); ];
if ($this->plugin->global) { if ($this->plugin->global) {
array_unshift($values, $value['gosaSnapshotDN'][0]); array_unshift($values, $value['gosaSnapshotDN'][0]);
} }
...@@ -200,16 +200,16 @@ class SnapshotsAttribute extends OrderedArrayAttribute ...@@ -200,16 +200,16 @@ class SnapshotsAttribute extends OrderedArrayAttribute
list ($img, $nbicons) = parent::genRowIcons($key, $value); list ($img, $nbicons) = parent::genRowIcons($key, $value);
$img = $this->renderInputField( $img = $this->renderInputField(
'image', $id.'_restore_'.$key, 'image', $id.'_restore_'.$key,
array( [
'src' => 'geticon.php?context=actions&amp;icon=document-restore&amp;size=16', 'src' => 'geticon.php?context=actions&amp;icon=document-restore&amp;size=16',
'title' => _('Restore'), 'title' => _('Restore'),
'alt' => _('Restore'), 'alt' => _('Restore'),
'class' => 'center' 'class' => 'center'
) ]
).$img; ).$img;
$nbicons++; $nbicons++;
return array ($img, $nbicons); return [$img, $nbicons];
} }
protected function handlePostValueActions ($id, $postValue) protected function handlePostValueActions ($id, $postValue)
...@@ -246,18 +246,18 @@ class SnapshotRestoreDialog extends simplePlugin ...@@ -246,18 +246,18 @@ class SnapshotRestoreDialog extends simplePlugin
static function plInfo (): array static function plInfo (): array
{ {
return array( return [
'plShortName' => 'SnapshotRestoreDialog', 'plShortName' => 'SnapshotRestoreDialog',
); ];
} }
static function getAttributesInfo (): array static function getAttributesInfo (): array
{ {
return array( return [
'main' => array( 'main' => [
'name' => _('Restoring snapshots'), 'name' => _('Restoring snapshots'),
'class' => array('fullwidth'), 'class' => ['fullwidth'],
'attrs' => array( 'attrs' => [
new DisplayAttribute( new DisplayAttribute(
_('Object'), _('DN of the object you are creating a snapshot of'), _('Object'), _('DN of the object you are creating a snapshot of'),
'object_dn', FALSE 'object_dn', FALSE
...@@ -265,12 +265,12 @@ class SnapshotRestoreDialog extends simplePlugin ...@@ -265,12 +265,12 @@ class SnapshotRestoreDialog extends simplePlugin
new SnapshotsAttribute( new SnapshotsAttribute(
_('Snapshots'), _('Existing snapshots for this object'), _('Snapshots'), _('Existing snapshots for this object'),
'snapshots', FALSE, 'snapshots', FALSE,
array(), [],
'SnapshotHandler' 'SnapshotHandler'
), ),
) ]
), ],
); ];
} }
function __construct ($dn, $parent, $global, $aclCategory) function __construct ($dn, $parent, $global, $aclCategory)
...@@ -300,28 +300,28 @@ class SnapshotRestoreDialog extends simplePlugin ...@@ -300,28 +300,28 @@ class SnapshotRestoreDialog extends simplePlugin
{ {
global $ui; global $ui;
if ($this->dialog == 'delete') { if ($this->dialog == 'delete') {
$objects = array( $objects = [
array( [
'name' => 'snapshot', 'name' => 'snapshot',
'dn' => $this->snapDn, 'dn' => $this->snapDn,
'icon' => 'geticon.php?context=actions&amp;icon=document-restore&amp;size=16', 'icon' => 'geticon.php?context=actions&amp;icon=document-restore&amp;size=16',
'type' => 'Snapshot' 'type' => 'Snapshot'
) ]
); ];
// Display confirmation dialog. // Display confirmation dialog.
$smarty = get_smarty(); $smarty = get_smarty();
$smarty->assign('objects', $objects); $smarty->assign('objects', $objects);
$str = $smarty->fetch(get_template_path('simple-remove.tpl')); $str = $smarty->fetch(get_template_path('simple-remove.tpl'));
} elseif ($this->dialog == 'restore') { } elseif ($this->dialog == 'restore') {
$objects = array( $objects = [
array( [
'name' => 'snapshot', 'name' => 'snapshot',
'dn' => $this->snapDn, 'dn' => $this->snapDn,
'icon' => 'geticon.php?context=actions&amp;icon=document-restore&amp;size=16', 'icon' => 'geticon.php?context=actions&amp;icon=document-restore&amp;size=16',
'type' => 'Snapshot' 'type' => 'Snapshot'
) ]
); ];