From 61a5ade87230bf59549730f5e464e297353385c9 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sat, 12 Dec 2020 16:20:14 +0100 Subject: [PATCH] PHP8 fixes, short array syntax --- bin/cleandb.sh | 6 +- bin/deluser.sh | 6 +- bin/initdb.sh | 4 +- bin/install-jsdeps.sh | 43 +++++++---- bin/installto.sh | 19 +++-- bin/moduserprefs.sh | 12 +-- bin/msgexport.sh | 28 ++++--- bin/msgimport.sh | 31 ++++---- bin/package2composer.sh | 106 -------------------------- bin/update.sh | 51 +++++-------- bin/updatecss.sh | 14 ++-- bin/updatedb.sh | 12 +-- program/lib/Roundcube/rcube.php | 2 +- program/lib/Roundcube/rcube_imap.php | 9 ++- program/lib/Roundcube/rcube_utils.php | 5 +- 15 files changed, 132 insertions(+), 216 deletions(-) delete mode 100755 bin/package2composer.sh diff --git a/bin/cleandb.sh b/bin/cleandb.sh index a2349dd72..711f32b6c 100755 --- a/bin/cleandb.sh +++ b/bin/cleandb.sh @@ -21,9 +21,11 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); require INSTALL_PATH.'program/include/clisetup.php'; -if (!empty($_SERVER['argv'][1])) +if (!empty($_SERVER['argv'][1])) { $days = intval($_SERVER['argv'][1]); -else +} +else { $days = 7; +} rcmail_utils::db_clean($days); diff --git a/bin/deluser.sh b/bin/deluser.sh index 984320fd1..b57e0ae0a 100755 --- a/bin/deluser.sh +++ b/bin/deluser.sh @@ -41,7 +41,7 @@ function _die($msg, $usage=false) $rcmail = rcube::get_instance(); // get arguments -$args = rcube_utils::get_opt(array('h' => 'host', 'a' => 'age', 'd' => 'dry-run:bool')); +$args = rcube_utils::get_opt(['h' => 'host', 'a' => 'age', 'd' => 'dry-run:bool']); if (!empty($args['age']) && ($age = intval($args['age']))) { $db = $rcmail->get_dbh(); @@ -103,7 +103,7 @@ if (!$user) { } // inform plugins about approaching user deletion -$plugin = $rcmail->plugins->exec_hook('user_delete_prepare', array('user' => $user, 'username' => $username, 'host' => $args['host'])); +$plugin = $rcmail->plugins->exec_hook('user_delete_prepare', ['user' => $user, 'username' => $username, 'host' => $args['host']]); // let plugins cleanup their own user-related data if (!$plugin['abort']) { @@ -120,7 +120,7 @@ if ($plugin['abort']) { // deleting the user record should be sufficient due to ON DELETE CASCADE foreign key references // but not all database backends actually support this so let's do it by hand -foreach (array('identities','contacts','contactgroups','dictionary','cache','cache_index','cache_messages','cache_thread','searches','users') as $table) { +foreach (['identities','contacts','contactgroups','dictionary','cache','cache_index','cache_messages','cache_thread','searches','users'] as $table) { $db->query('DELETE FROM ' . $db->table_name($table, true) . ' WHERE `user_id` = ?', $user->ID); } diff --git a/bin/initdb.sh b/bin/initdb.sh index 31c5078e6..acff3121c 100755 --- a/bin/initdb.sh +++ b/bin/initdb.sh @@ -23,9 +23,9 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); require_once INSTALL_PATH . 'program/include/clisetup.php'; // get arguments -$opts = rcube_utils::get_opt(array( +$opts = rcube_utils::get_opt([ 'd' => 'dir', -)); +]); if (empty($opts['dir'])) { rcube::raise_error("Database schema directory not specified (--dir).", false, true); diff --git a/bin/install-jsdeps.sh b/bin/install-jsdeps.sh index 5094e46e8..f57430c05 100755 --- a/bin/install-jsdeps.sh +++ b/bin/install-jsdeps.sh @@ -33,9 +33,9 @@ if (empty($SOURCES['dependencies'])) { rcube::raise_error("Failed to read dependencies list from $cfgfile", false, true); } -$CURL = trim(`which curl`); -$WGET = trim(`which wget`); -$UNZIP = trim(`which unzip`); +$CURL = trim(`which curl`); +$WGET = trim(`which wget`); +$UNZIP = trim(`which unzip`); if (($CACHEDIR = getenv("CACHEDIR")) && is_writeable($CACHEDIR)) { // use $CACHEDIR @@ -50,7 +50,7 @@ else { //////////////// License definitions -$LICENSES = array(); +$LICENSES = []; $LICENSES['MIT'] = << 'force:bool', 'd' => 'delete:bool', 'g' => 'get:bool', 'e' => 'extract:bool')) - + array('force' => false, 'delete' => false, 'get' => false, 'extract' => false); -$WHAT = $args[0]; +$args = rcube_utils::get_opt([ + 'f' => 'force:bool', + 'd' => 'delete:bool', + 'g' => 'get:bool', + 'e' => 'extract:bool' + ]) + + [ + 'force' => false, + 'delete' => false, + 'get' => false, + 'extract' => false + ]; + +$WHAT = isset($args[0]) ? $args[0] : null; $useCache = !$args['force'] && !$args['get']; if (!$args['get'] && !$args['extract'] && !$args['delete']) { diff --git a/bin/installto.sh b/bin/installto.sh index 62ab5cfbb..d657e8799 100755 --- a/bin/installto.sh +++ b/bin/installto.sh @@ -29,18 +29,21 @@ if (!function_exists('system')) { $target_dir = unslashify(end($_SERVER['argv'])); $accept = in_array('-y', $_SERVER['argv']) ? 'y' : null; -if (empty($target_dir) || !is_dir(realpath($target_dir))) +if (empty($target_dir) || !is_dir(realpath($target_dir))) { rcube::raise_error("Invalid target: not a directory\nUsage: installto.sh [-y] ", false, true); +} // read version from iniset.php $iniset = @file_get_contents($target_dir . '/program/include/iniset.php'); -if (!preg_match('/define\(.RCMAIL_VERSION.,\s*.([0-9.]+[a-z0-9-]*)/', $iniset, $m)) +if (!preg_match('/define\(.RCMAIL_VERSION.,\s*.([0-9.]+[a-z0-9-]*)/', $iniset, $m)) { rcube::raise_error("No valid Roundcube installation found at $target_dir", false, true); +} $oldversion = $m[1]; -if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '>')) +if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '>')) { rcube::raise_error("Target installation already in version $oldversion.", false, true); +} if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '==')) { echo "Target installation already in version $oldversion. Do you want to update again? (y/N)\n"; @@ -54,8 +57,8 @@ $input = $accept ?: trim(fgets(STDIN)); if (strtolower($input) == 'y') { echo "Copying files to target location..."; - $adds = array(); - $dirs = array('bin','SQL','plugins','skins','program'); + $adds = []; + $dirs = ['bin','SQL','plugins','skins','program']; if (is_dir(INSTALL_PATH . 'vendor') && !is_file("$target_dir/composer.json")) { $dirs[] = 'vendor'; @@ -66,7 +69,7 @@ if (strtolower($input) == 'y') { foreach ($dirs as $dir) { // @FIXME: should we use --delete for all directories? - $delete = in_array($dir, array('program', 'vendor', 'installer')) ? '--delete ' : ''; + $delete = in_array($dir, ['program', 'vendor', 'installer']) ? '--delete ' : ''; $command = "rsync -aC --out-format=%n " . $delete . INSTALL_PATH . "$dir/ $target_dir/$dir/"; if (system($command, $ret) === false || $ret > 0) { @@ -74,7 +77,7 @@ if (strtolower($input) == 'y') { } } - foreach (array('index.php','config/defaults.inc.php','composer.json-dist','jsdeps.json','CHANGELOG','README.md','UPGRADING','LICENSE','INSTALL') as $file) { + foreach (['index.php','config/defaults.inc.php','composer.json-dist','jsdeps.json','CHANGELOG','README.md','UPGRADING','LICENSE','INSTALL'] as $file) { $command = "rsync -a --out-format=%n " . INSTALL_PATH . "$file $target_dir/$file"; if (file_exists(INSTALL_PATH . $file) && (system($command, $ret) === false || $ret > 0)) { @@ -83,7 +86,7 @@ if (strtolower($input) == 'y') { } // Copy .htaccess or .user.ini if needed - foreach (array('.htaccess','.user.ini') as $file) { + foreach (['.htaccess','.user.ini'] as $file) { if (file_exists(INSTALL_PATH . $file)) { if (!file_exists("$target_dir/$file") || file_get_contents(INSTALL_PATH . $file) != file_get_contents("$target_dir/$file")) { if (copy(INSTALL_PATH . $file, "$target_dir/$file.new")) { diff --git a/bin/moduserprefs.sh b/bin/moduserprefs.sh index 4de60a83d..77ab15e9c 100755 --- a/bin/moduserprefs.sh +++ b/bin/moduserprefs.sh @@ -33,14 +33,14 @@ function print_usage() // get arguments -$args = rcube_utils::get_opt(array( +$args = rcube_utils::get_opt([ 'u' => 'user', 'd' => 'delete:bool', 't' => 'type', 'c' => 'config', -)); +]); -if ($_SERVER['argv'][1] == 'help') { +if (empty($_SERVER['argv'][1]) || $_SERVER['argv'][1] == 'help') { print_usage(); exit; } @@ -51,15 +51,15 @@ else if (empty($args[0]) || (empty($args[1]) && empty($args['delete']))) { } $pref_name = trim($args[0]); -$pref_value = $args['delete'] ? null : trim($args[1]); +$pref_value = !empty($args['delete']) ? null : trim($args[1]); if ($pref_value === null) { $args['type'] = null; } -if ($args['config']) { +if (!empty($args['config'])) { $rcube = rcube::get_instance(); $rcube->config->load_from_file($args['config']); } -rcmail_utils::mod_pref($pref_name, $pref_value, $args['user'], $args['type']); +rcmail_utils::mod_pref($pref_name, $pref_value, $args['user'], isset($args['type']) ? $args['type'] : null); diff --git a/bin/msgexport.sh b/bin/msgexport.sh index 358ed1cc2..66d470c65 100755 --- a/bin/msgexport.sh +++ b/bin/msgexport.sh @@ -30,7 +30,7 @@ function print_usage() function vputs($str) { - $out = $GLOBALS['args']['file'] ? STDOUT : STDERR; + $out = !empty($GLOBALS['args']['file']) ? STDOUT : STDERR; fwrite($out, $str); } @@ -46,11 +46,12 @@ function export_mailbox($mbox, $filename) $IMAP->set_folder($mbox); + vputs("Getting message list of {$mbox}..."); + $index = $IMAP->index($mbox, null, 'ASC'); $count = $index->count(); $index = $index->get(); - vputs("Getting message list of {$mbox}..."); vputs("$count messages\n"); if ($filename) { @@ -82,10 +83,10 @@ function export_mailbox($mbox, $filename) } // get arguments -$opts = array('h' => 'host', 'u' => 'user', 'p' => 'pass', 'm' => 'mbox', 'f' => 'file'); -$args = rcube_utils::get_opt($opts) + array('host' => 'localhost', 'mbox' => 'INBOX'); +$opts = ['h' => 'host', 'u' => 'user', 'p' => 'pass', 'm' => 'mbox', 'f' => 'file']; +$args = rcube_utils::get_opt($opts) + ['host' => 'localhost', 'mbox' => 'INBOX']; -if ($_SERVER['argv'][1] == 'help') { +if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] == 'help') { print_usage(); exit; } @@ -107,14 +108,15 @@ $args['pass'] = rcube_utils::prompt_silent("Password: "); // parse $host URL $a_host = parse_url($args['host']); -if ($a_host['host']) { +if (!empty($a_host['host'])) { $host = $a_host['host']; - $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? TRUE : FALSE; + $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], ['ssl','imaps','tls'])) ? TRUE : FALSE; $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : 143); } else { - $host = $args['host']; + $host = $args['host']; $imap_port = 143; + $imap_ssl = false; } // instantiate IMAP class @@ -125,15 +127,17 @@ if ($IMAP->connect($host, $args['user'], $args['pass'], $imap_port, $imap_ssl)) vputs("IMAP login successful.\n"); $filename = null; - $mailboxes = $args['mbox'] == '*' ? $IMAP->list_folders(null) : array($args['mbox']); + $mailboxes = $args['mbox'] == '*' ? $IMAP->list_folders(null) : [$args['mbox']]; foreach ($mailboxes as $mbox) { - if ($args['file']) + if (!empty($args['file'])) { $filename = preg_replace('/\.[a-z0-9]{3,4}$/i', '', $args['file']) . asciiwords($mbox) . '.mbox'; - else if ($args['mbox'] == '*') + } + else if ($args['mbox'] == '*') { $filename = asciiwords($mbox) . '.mbox'; + } - if ($args['mbox'] == '*' && in_array(strtolower($mbox), array('junk','spam','trash'))) { + if ($args['mbox'] == '*' && in_array(strtolower($mbox), ['junk','spam','trash'])) { continue; } diff --git a/bin/msgimport.sh b/bin/msgimport.sh index bd9aab4d4..070e87036 100755 --- a/bin/msgimport.sh +++ b/bin/msgimport.sh @@ -28,16 +28,15 @@ function print_usage() print "--file Message file to upload\n"; } - // get arguments -$opts = array('h' => 'host', 'u' => 'user', 'p' => 'pass', 'm' => 'mbox', 'f' => 'file'); -$args = rcube_utils::get_opt($opts) + array('host' => 'localhost', 'mbox' => 'INBOX'); +$opts = ['h' => 'host', 'u' => 'user', 'p' => 'pass', 'm' => 'mbox', 'f' => 'file']; +$args = rcube_utils::get_opt($opts) + ['host' => 'localhost', 'mbox' => 'INBOX']; -if ($_SERVER['argv'][1] == 'help') { +if (!isset($_SERVER['argv'][1]) || $_SERVER['argv'][1] == 'help') { print_usage(); exit; } -else if (!($args['host'] && $args['file'])) { +else if (empty($args['host']) || empty($args['file'])) { print "Missing required parameters.\n"; print_usage(); exit; @@ -60,14 +59,15 @@ if (empty($args['pass'])) { // parse $host URL $a_host = parse_url($args['host']); -if ($a_host['host']) { +if (!empty($a_host['host'])) { $host = $a_host['host']; - $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? TRUE : FALSE; + $imap_ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], ['ssl','imaps','tls'])) ? TRUE : FALSE; $imap_port = isset($a_host['port']) ? $a_host['port'] : ($imap_ssl ? 993 : 143); } else { - $host = $args['host']; + $host = $args['host']; $imap_port = 143; + $imap_ssl = false; } // instantiate IMAP class @@ -85,10 +85,12 @@ if ($IMAP->connect($host, $args['user'], $args['pass'], $imap_port, $imap_ssl)) while (($line = fgets($fp)) !== false) { if (preg_match('/^From\s+-/', $line) && $lastline == '') { if (!empty($message)) { - if ($IMAP->save_message($args['mbox'], rtrim($message))) + if ($IMAP->save_message($args['mbox'], rtrim($message))) { $count++; - else + } + else { rcube::raise_error("Failed to save message to {$args['mbox']}", false, true); + } $message = ''; } continue; @@ -98,14 +100,17 @@ if ($IMAP->connect($host, $args['user'], $args['pass'], $imap_port, $imap_ssl)) $lastline = rtrim($line); } - if (!empty($message) && $IMAP->save_message($args['mbox'], rtrim($message))) + if (!empty($message) && $IMAP->save_message($args['mbox'], rtrim($message))) { $count++; + } // upload message from file - if ($count) + if ($count) { print "$count messages successfully added to {$args['mbox']}.\n"; - else + } + else { print "Adding messages failed!\n"; + } } else { rcube::raise_error("IMAP login failed.", false, true); diff --git a/bin/package2composer.sh b/bin/package2composer.sh deleted file mode 100755 index dc3bfea8b..000000000 --- a/bin/package2composer.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env php - | - +-----------------------------------------------------------------------+ -*/ - -ini_set('error_reporting', E_ALL & ~E_NOTICE); - -list(, $filename, $vendor) = $_SERVER['argv']; - -if (!$filename || !is_readable($filename)) { - die("Invalid input file name!\nUsage: " . $_SERVER['argv'][0] . " XMLFILE VENDOR\n"); -} - -if (!$vendor) { - $vendor = 'anonymous'; -} - -$package = new SimpleXMLElement(file_get_contents($filename)); - -$data = array( - 'name' => $vendor . '/' . strval($package->name), - 'type' => 'roundcube-plugin', - 'description' => trim(strval($package->description), '- ') ? trim(strval($package->description)) : trim(strval($package->summary)), - 'homepage' => strval($package->uri), - 'license' => 'GPLv3+', - 'version' => strval($package->version->release), - 'authors' => array(), - 'repositories' => array( - array('type' => 'composer', 'url' => 'https://plugins.roundcube.net'), - ), - 'require' => array( - 'php' => '>=5.3.0', - 'roundcube/plugin-installer' => '>=0.1.3', - ), -); - -if ($package->license) { - $data['license'] = strval($package->license); -} - -if ($package->lead) { - foreach ($package->lead as $lead) { - if (strval($lead->active) == 'no') { - continue; - } - $data['authors'][] = array( - 'name' => strval($lead->name), - 'email' => strval($lead->email), - 'role' => 'Lead', - ); - } -} - -if ($devs = $package->developer) { - foreach ($package->developer as $dev) { - $data['authors'][] = array( - 'name' => strval($dev->name), - 'email' => strval($dev->email), - 'role' => 'Developer', - ); - } -} - -if ($package->dependencies->required->extension) { - foreach ($package->dependencies->required->extension as $ext) { - $data['require']['ext-' . strval($ext->name)] = '*'; - } -} - -// remove empty values -$data = array_filter($data); - -// use the JSON encoder from the Composer package -if (is_file('composer.phar')) { - include 'phar://composer.phar/src/Composer/Json/JsonFile.php'; - echo \Composer\Json\JsonFile::encode($data); -} -// PHP 5.4's json_encode() does the job, too -else if (defined('JSON_PRETTY_PRINT')) { - $flags = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT & JSON_UNESCAPED_SLASHES : 0; - echo json_encode($data, $flags); -} -else { - fwrite(STDERR, -"FAILED! composer.phar not found in current directory. - -Please download it from http://getcomposer.org/download/ or with - curl -s http://getcomposer.org/installer | php -"); -} - -echo "\n"; diff --git a/bin/update.sh b/bin/update.sh index f9f8b4c27..8d3cffae6 100755 --- a/bin/update.sh +++ b/bin/update.sh @@ -23,10 +23,10 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); require_once INSTALL_PATH . 'program/include/clisetup.php'; // get arguments -$opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept:bool')); +$opts = rcube_utils::get_opt(['v' => 'version', 'y' => 'accept:bool']); // ask user if no version is specified -if (!$opts['version']) { +if (empty($opts['version'])) { echo "What version are you upgrading from? Type '?' if you don't know.\n"; if (($input = trim(fgets(STDIN))) && preg_match('/^[0-9.]+[a-z0-9-]*$/', $input)) { @@ -48,7 +48,7 @@ if ($RCI->configured) { $err = 0; // list old/replaced config options - if (is_array($messages['replaced'])) { + if (!empty($messages['replaced'])) { echo "WARNING: Replaced config options:\n"; echo "(These config options have been replaced or renamed)\n"; @@ -59,7 +59,7 @@ if ($RCI->configured) { } // list obsolete config options (just a notice) - if (is_array($messages['obsolete'])) { + if (!empty($messages['obsolete'])) { echo "NOTICE: Obsolete config options:\n"; echo "(You still have some obsolete or inexistent properties set." . " This isn't a problem but should be noticed)\n"; @@ -79,18 +79,18 @@ if ($RCI->configured) { // ask user to update config files if ($err) { - if (!$opts['accept']) { + if (empty($opts['accept'])) { echo "Do you want me to fix your local configuration? (y/N)\n"; $input = trim(fgets(STDIN)); } // positive: merge the local config with the defaults - if ($opts['accept'] || strtolower($input) == 'y') { + if (!empty($opts['accept']) || strtolower($input) == 'y') { $error = $written = false; echo ". backing up the current config file(s)...\n"; - foreach (array('config', 'main', 'db') as $file) { + foreach (['config', 'main', 'db'] as $file) { if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) { if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) { $error = true; @@ -109,7 +109,7 @@ if ($RCI->configured) { echo "Done.\n"; echo "Your configuration files are now up-to-date!\n"; - if ($messages['missing']) { + if (!empty($messages['missing'])) { echo "But you still need to add the following missing options:\n"; foreach ($messages['missing'] as $msg) { echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n"; @@ -117,7 +117,7 @@ if ($RCI->configured) { } if ($RCI->legacy_config) { - foreach (array('main', 'db') as $file) { + foreach (['main', 'db'] as $file) { @unlink(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php'); } } @@ -143,7 +143,7 @@ if ($RCI->configured) { } // check dependencies based on the current configuration - if (is_array($messages['dependencies'])) { + if (!empty($messages['dependencies'])) { echo "WARNING: Dependency check failed!\n"; echo "(Some of your configuration settings require other options to be configured " . "or additional PHP modules to be installed)\n"; @@ -168,10 +168,9 @@ if ($RCI->configured) { } // check database schema - if ($RCI->config['db_dsnw']) { + if (!empty($RCI->config['db_dsnw'])) { echo "Executing database schema update.\n"; - $success = rcmail_utils::db_update(INSTALL_PATH . 'SQL', 'roundcube', $opts['version'], - array('errors' => true)); + $success = rcmail_utils::db_update(INSTALL_PATH . 'SQL', 'roundcube', $opts['version'], ['errors' => true]); } // update composer dependencies @@ -181,11 +180,11 @@ if ($RCI->configured) { $comsposer_json = null; // update the require section with the new dependencies - if (is_array($composer_data['require']) && is_array($composer_template['require'])) { + if (!empty($composer_data['require']) && !empty($composer_template['require'])) { $composer_data['require'] = array_merge($composer_data['require'], $composer_template['require']); // remove obsolete packages - $old_packages = array( + $old_packages = [ 'pear-pear.php.net/net_socket', 'pear-pear.php.net/auth_sasl', 'pear-pear.php.net/net_idna2', @@ -196,7 +195,7 @@ if ($RCI->configured) { 'pear/mail_mime-decode', 'roundcube/net_sieve', 'endroid/qrcode', - ); + ]; foreach ($old_packages as $pkg) { if (array_key_exists($pkg, $composer_data['require'])) { @@ -206,9 +205,9 @@ if ($RCI->configured) { } // update the repositories section with the new dependencies - if (is_array($composer_template['repositories'])) { - if (!is_array($composer_data['repositories'])) { - $composer_data['repositories'] = array(); + if (!empty($composer_template['repositories'])) { + if (empty($composer_data['repositories'])) { + $composer_data['repositories'] = []; } foreach ($composer_template['repositories'] as $repo) { @@ -242,19 +241,7 @@ if ($RCI->configured) { $composer_data['repositories'] = array_values($composer_data['repositories']); } - // use the JSON encoder from the Composer package - if (is_file('composer.phar')) { - include 'phar://composer.phar/src/Composer/Json/JsonFile.php'; - $comsposer_json = \Composer\Json\JsonFile::encode($composer_data); - } - // PHP 5.4's json_encode() does the job, too - else if (defined('JSON_PRETTY_PRINT')) { - $comsposer_json = json_encode($composer_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - } - else { - $success = false; - $comsposer_json = null; - } + $comsposer_json = json_encode($composer_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); // write updated composer.json back to disk if ($comsposer_json && is_writeable(INSTALL_PATH . 'composer.json')) { diff --git a/bin/updatecss.sh b/bin/updatecss.sh index 772ad8393..cac720100 100755 --- a/bin/updatecss.sh +++ b/bin/updatecss.sh @@ -22,9 +22,7 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); require_once INSTALL_PATH . 'program/include/clisetup.php'; // get arguments -$opts = rcube_utils::get_opt(array( - 'd' => 'dir', -)); +$opts = rcube_utils::get_opt(['d' => 'dir']); if (empty($opts['dir'])) { print "Skin directory not specified (--dir). Using skins/ and plugins/*/skins/.\n"; @@ -41,7 +39,7 @@ else if (!file_exists($opts['dir'])) { rcube::raise_error("Specified directory doesn't exist.", false, true); } else { - $dirs = array($opts['dir']); + $dirs = [$opts['dir']]; } foreach ($dirs as $dir) { @@ -52,8 +50,8 @@ foreach ($dirs as $dir) { $files = get_files($dir); $images = get_images($img_dir); - $find = array(); - $replace = array(); + $find = []; + $replace = []; // build regexps array foreach ($images as $path => $sum) { @@ -76,7 +74,7 @@ foreach ($dirs as $dir) { function get_images($dir) { - $images = array(); + $images = []; $dh = opendir($dir); while ($file = readdir($dh)) { @@ -99,7 +97,7 @@ function get_images($dir) function get_files($dir) { - $files = array(); + $files = []; $dh = opendir($dir); while ($file = readdir($dh)) { diff --git a/bin/updatedb.sh b/bin/updatedb.sh index 338b07f7c..018e72daa 100755 --- a/bin/updatedb.sh +++ b/bin/updatedb.sh @@ -23,11 +23,11 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); require_once INSTALL_PATH . 'program/include/clisetup.php'; // get arguments -$opts = rcube_utils::get_opt(array( - 'v' => 'version', - 'd' => 'dir', - 'p' => 'package', -)); +$opts = rcube_utils::get_opt([ + 'v' => 'version', + 'd' => 'dir', + 'p' => 'package', +]); if (empty($opts['dir'])) { rcube::raise_error("Database schema directory not specified (--dir).", false, true); @@ -36,4 +36,4 @@ if (empty($opts['package'])) { rcube::raise_error("Database schema package name not specified (--package).", false, true); } -rcmail_utils::db_update($opts['dir'], $opts['package'], $opts['version'], array('errors' => true)); +rcmail_utils::db_update($opts['dir'], $opts['package'], $opts['version'], ['errors' => true]); diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php index 6ba90802f..8e0a184ab 100644 --- a/program/lib/Roundcube/rcube.php +++ b/program/lib/Roundcube/rcube.php @@ -815,7 +815,7 @@ class rcube static $rcube_languages, $rcube_language_aliases; // user HTTP_ACCEPT_LANGUAGE if no language is specified - if (empty($lang) || $lang == 'auto') { + if ((empty($lang) || $lang == 'auto') && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); $lang = $accept_langs[0]; diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php index 118daf132..17244fd70 100644 --- a/program/lib/Roundcube/rcube_imap.php +++ b/program/lib/Roundcube/rcube_imap.php @@ -147,7 +147,14 @@ class rcube_imap extends rcube_storage $attempt = 0; do { - $data = ['host' => $host, 'user' => $user, 'attempt' => ++$attempt, 'socket_options' => []]; + $data = [ + 'host' => $host, + 'user' => $user, + 'attempt' => ++$attempt, + 'socket_options' => [], + 'retry' => false + ]; + $data = $this->plugins->exec_hook('storage_connect', array_merge($this->options, $data)); if (!empty($data['pass'])) { diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php index 3c12b05df..1bc600f99 100644 --- a/program/lib/Roundcube/rcube_utils.php +++ b/program/lib/Roundcube/rcube_utils.php @@ -704,7 +704,7 @@ class rcube_utils */ public static function remote_ip() { - $address = $_SERVER['REMOTE_ADDR']; + $address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; // append the NGINX X-Real-IP header, if set if (!empty($_SERVER['HTTP_X_REAL_IP']) && $_SERVER['HTTP_X_REAL_IP'] != $address) { @@ -1197,7 +1197,8 @@ class rcube_utils $args[] = $arg; } - if ($alias = $aliases[$key]) { + if (!empty($aliases[$key])) { + $alias = $aliases[$key]; $args[$alias] = $args[$key]; } }