From fe9f5af2ee959bc2601614227a40ffc905642b97 Mon Sep 17 00:00:00 2001 From: Edwin Wood Date: Fri, 12 Apr 2024 20:16:43 -0700 Subject: [PATCH 1/5] reduce function calls; fix whitespace --- lib/framework.php | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/framework.php b/lib/framework.php index 78538ea4b2..271636649f 100644 --- a/lib/framework.php +++ b/lib/framework.php @@ -6,7 +6,7 @@ * @subpackage setup */ -define('VERSION', .1); +const VERSION = .1; /* load the framework */ require APP_PATH.'lib/repository.php'; @@ -42,15 +42,14 @@ /* check for and load the correct libsodium interface */ if (!defined('LIBSODIUM')) { - if (extension_loaded('libsodium') && function_exists('\Sodium\crypto_pwhash_str_verify')) { - define('LIBSODIUM', true); - class Hm_Sodium_Compat extends Hm_Sodium_PECL {} - } - if (!defined('LIBSODIUM') && extension_loaded('sodium') && function_exists('sodium_crypto_pwhash_str_verify')) { - define('LIBSODIUM', true); - class Hm_Sodium_Compat extends Hm_Sodium_PHP {} - } - if (!defined('LIBSODIUM')) { + if (extension_loaded('libsodium')) { + if (function_exists('\Sodium\crypto_pwhash_str_verify') || function_exists('sodium_crypto_pwhash_str_verify')) { + define('LIBSODIUM', true); + class Hm_Sodium_Compat extends Hm_Sodium_PHP {} + } else { + define('LIBSODIUM', false); + } + } else { define('LIBSODIUM', false); } } @@ -68,21 +67,20 @@ class Hm_Functions { * @param string $value * @return boolean */ - public static function setcookie($name, $value, $lifetime=0, $path='', $domain='', $secure=false, $html_only=false) { - $prefix = $lifetime != 0 && $lifetime < time() ? 'Deleting' : 'Setting'; + public static function setcookie($name, $value, $lifetime = 0, $path = '', $domain = '', $secure = false, $html_only = false) { + $prefix = ($lifetime != 0 && $lifetime < time()) ? 'Deleting' : 'Setting'; Hm_Debug::add(sprintf('%s cookie: name: %s, lifetime: %s, path: %s, domain: %s, secure: %s, html_only %s',$prefix, $name, $lifetime, $path, $domain, $secure, $html_only)); if (version_compare(PHP_VERSION, '7.3', '>=')) { - return setcookie($name,$value, array( + return setcookie($name, $value, [ 'expires' => $lifetime, 'path' => $path, 'domain' => $domain, 'secure' => $secure, 'httponly' => $html_only, 'samesite' => 'Strict' - ) + ] ); - } - else { + } else { return setcookie($name, $value, $lifetime, $path, $domain, $secure, $html_only); } } @@ -99,7 +97,7 @@ public static function header($header) { * @param string $msg * @return null */ - public static function cease($msg='') { + public static function cease($msg = '') { die($msg); } From 6c378c1d740d117a47c797ec3f15c67ea2bf2b11 Mon Sep 17 00:00:00 2001 From: Edwin Wood Date: Fri, 12 Apr 2024 21:56:41 -0700 Subject: [PATCH 2/5] expanded coverage of changes across all lib/ files; updated syntax to more closely adhere to PSR-12; changed array initializers to short-array (square bracket) syntax; --- lib/api.php | 8 +-- lib/auth.php | 35 ++++++------- lib/cache.php | 26 +++++----- lib/config.php | 106 +++++++++++++++++--------------------- lib/crypt.php | 14 ++--- lib/crypt_sodium.php | 5 +- lib/db.php | 21 ++++---- lib/dispatch.php | 47 ++++++----------- lib/environment.php | 5 +- lib/format.php | 20 +++---- lib/ini_set.php | 5 +- lib/module.php | 60 ++++++++++----------- lib/modules.php | 37 ++++++------- lib/modules_exec.php | 20 +++---- lib/oauth2.php | 6 +-- lib/output.php | 25 ++++----- lib/request.php | 50 +++++++++--------- lib/servers.php | 13 +++-- lib/session_base.php | 46 ++++++++--------- lib/session_db.php | 17 +++--- lib/session_memcached.php | 3 +- lib/session_php.php | 29 ++++------- lib/webdav_formats.php | 95 ++++++++++++++++------------------ 23 files changed, 306 insertions(+), 387 deletions(-) diff --git a/lib/api.php b/lib/api.php index dd0d19df6e..359890487c 100644 --- a/lib/api.php +++ b/lib/api.php @@ -18,7 +18,7 @@ class Hm_API_Curl { * Init * @param string $format format of the result */ - public function __construct($format='json') { + public function __construct($format = 'json') { $this->format = $format; } @@ -29,7 +29,7 @@ public function __construct($format='json') { * @param array $post post fields * @return array */ - public function command($url, $headers=array(), $post=array(), $body='', $method=false) { + public function command($url, $headers = [], $post = [], $body = '', $method = false) { $ch = Hm_Functions::c_init(); if (!$ch) { return []; @@ -86,7 +86,7 @@ private function curl_result($ch) { } $result = @json_decode($curl_result, true); if ($result === NULL) { - return array(); + return []; } return $result; } @@ -97,7 +97,7 @@ private function curl_result($ch) { * @return string */ private function format_post_data($data) { - $post = array(); + $post = []; if (!is_array($data)) { return $data; } diff --git a/lib/auth.php b/lib/auth.php index a2b81753e4..cf3512eb02 100644 --- a/lib/auth.php +++ b/lib/auth.php @@ -71,8 +71,8 @@ class Hm_Auth_DB extends Hm_Auth { */ public function check_credentials($user, $pass) { $this->connect(); - $row = Hm_DB::execute($this->dbh, 'select hash from hm_user where username = ?', array($user)); - if ($row && array_key_exists('hash', $row) && $row['hash'] && Hm_Crypt::check_password($pass, $row['hash'])) { + $row = Hm_DB::execute($this->dbh, 'select hash from hm_user where username = ?', [$user]); + if ($row && !empty($row['hash']) && Hm_Crypt::check_password($pass, $row['hash'])) { return true; } sleep(2); @@ -87,7 +87,7 @@ public function check_credentials($user, $pass) { */ public function delete($user) { $this->connect(); - if (Hm_DB::execute($this->dbh, 'delete from hm_user where username = ?', array($user))) { + if (Hm_DB::execute($this->dbh, 'delete from hm_user where username = ?', [$user])) { return true; } return false; @@ -115,7 +115,7 @@ protected function connect() { public function change_pass($user, $pass) { $this->connect(); $hash = Hm_Crypt::hash_password($pass); - if (Hm_DB::execute($this->dbh, 'update hm_user set hash=? where username=?', array($hash, $user))) { + if (Hm_DB::execute($this->dbh, 'update hm_user set hash=? where username=?', [$hash, $user])) { return true; } return false; @@ -130,13 +130,13 @@ public function change_pass($user, $pass) { public function create($user, $pass) { $this->connect(); $result = 0; - $res = Hm_DB::execute($this->dbh, 'select username from hm_user where username = ?', array($user)); + $res = Hm_DB::execute($this->dbh, 'select username from hm_user where username = ?', [$user]); if (!empty($res)) { $result = 1; } else { $hash = Hm_Crypt::hash_password($pass); - if (Hm_DB::execute($this->dbh, 'insert into hm_user values(?,?)', array($user, $hash))) { + if (Hm_DB::execute($this->dbh, 'insert into hm_user values(?,?)', [$user, $hash])) { $result = 2; } } @@ -159,7 +159,7 @@ public function __construct($config) { } /* IMAP authentication server settings */ - private $imap_settings = array(); + private $imap_settings = []; /** * @param object $imap imap connection object @@ -196,11 +196,11 @@ public function check_credentials($user, $pass) { Hm_Debug::add('Invalid IMAP auth configuration settings'); return false; } - $this->imap_settings = array('server' => $server, 'port' => $port, + $this->imap_settings = ['server' => $server, 'port' => $port, 'tls' => $tls, 'username' => $user, 'password' => $pass, - 'no_caps' => false, 'blacklisted_extensions' => array('enable'), + 'no_caps' => false, 'blacklisted_extensions' => ['enable'], 'sieve_config_host' => $sieve_config - ); + ]; return $this->check_connection($imap); } @@ -219,7 +219,7 @@ public function save_auth_detail($session) { */ class Hm_Auth_LDAP extends Hm_Auth { - protected $config = array(); + protected $config = []; protected $fh; protected $source = 'ldap'; @@ -231,7 +231,7 @@ private function connect_details() { $prefix = 'ldaps://'; $server = $this->apply_config_value('server', 'localhost'); $port = $this->apply_config_value('port', 389); - if (array_key_exists('enable_tls', $this->config) && !$this->config['enable_tls']) { + if (!empty($this->config['enable_tls'])) { $prefix = 'ldap://'; } return $prefix.$server.':'.$port; @@ -243,10 +243,7 @@ private function connect_details() { * @return mixed */ private function apply_config_value($name, $default) { - if (array_key_exists($name, $this->config) && trim($this->config[$name])) { - return $this->config[$name]; - } - return $default; + return !empty($this->config[$name]) ? $this->config[$name] : $default; } /** @@ -260,14 +257,14 @@ public function check_credentials($user, $pass) { $base_dn = $this->site_config->get('ldap_auth_base_dn', false); if ($server && $port && $base_dn) { $user = sprintf('cn=%s,%s', $user, $base_dn); - $this->config = array( + $this->config = [ 'server' => $server, 'port' => $port, 'enable_tls' => $tls, 'base_dn' => $base_dn, 'user' => $user, 'pass' => $pass - ); + ]; return $this->connect(); } Hm_Debug::add('Invalid LDAP auth configuration settings'); @@ -315,7 +312,7 @@ function get_auth_config($config, $prefix) { $server = $config->get($prefix.'_auth_server', false); $port = $config->get($prefix.'_auth_port', false); $tls = $config->get($prefix.'_auth_tls', false); - $ret = array($server, $port, $tls); + $ret = [$server, $port, $tls]; if ($prefix == 'imap') { $ret[] = $config->get($prefix.'_auth_sieve_conf_host', false); } diff --git a/lib/cache.php b/lib/cache.php index 1e4aed314c..3b96f67c02 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -23,8 +23,8 @@ trait Hm_Uid_Cache { /* UID list */ - private static $read = array(); - private static $unread = array(); + private static $read = []; + private static $unread = []; /* Load UIDs from an outside source * @param array $data list of uids @@ -75,11 +75,11 @@ public static function is_read($uid) { * @return array list of known UIDs */ public static function dump() { - return array(array_keys(self::$read), array_keys(self::$unread)); + return [array_keys(self::$read), array_keys(self::$unread)]; } /** - * Add a UID to the unread list + * Add a UID to the unread list * @param string $uid uid to add */ public static function unread($uid) { @@ -90,7 +90,7 @@ public static function unread($uid) { } /** - * Add a UID to the read list + * Add a UID to the read list * @param string $uid uid to add */ public static function read($uid) { @@ -153,7 +153,7 @@ public function del($key) { * @param string $crypt_key encryption key * @return boolean */ - public function set($key, $val, $lifetime=600, $crypt_key='') { + public function set($key, $val, $lifetime = 600, $crypt_key = '') { if (!$this->is_active()) { return false; } @@ -165,7 +165,7 @@ public function set($key, $val, $lifetime=600, $crypt_key='') { * @param string $crypt_key encryption key * @return false|array|string */ - public function get($key, $crypt_key='') { + public function get($key, $crypt_key = '') { if (!$this->is_active()) { return false; } @@ -258,8 +258,7 @@ private function connect() { $this->cache_con = false; return false; } - } - catch (Exception $oops) { + } catch (Exception $oops) { Hm_Debug::add('Redis connect failed'); $this->cache_con = false; return false; @@ -274,7 +273,7 @@ private function auth() { $this->cache_con->auth($this->config->get('redis_pass')); } } - + /** * @param string $key cache key to delete */ @@ -373,6 +372,7 @@ class Hm_Noop_Cache { public function del($key) { return true; } + public function set($key, $val, $lifetime, $crypt_key) { return false; } @@ -475,7 +475,7 @@ protected function log($key, $msg_type) { * @param boolean $session store in the session instead of the enabled cache * @return boolean */ - public function set($key, $val, $lifetime=600, $session=false) { + public function set($key, $val, $lifetime = 600, $session = false) { if ($session || $this->type == 'session') { return $this->session_set($key, $val, false); } @@ -488,7 +488,7 @@ public function set($key, $val, $lifetime=600, $session=false) { * @param boolean $session fetch from the session instead of the enabled cache * @return mixed */ - public function get($key, $default=false, $session=false) { + public function get($key, $default = false, $session = false) { if ($session || $this->type == 'session') { return $this->session_get($key, $default); } @@ -500,7 +500,7 @@ public function get($key, $default=false, $session=false) { * @param boolean $session fetch from the session instead of the enabled cache * @return boolean */ - public function del($key, $session=false) { + public function del($key, $session = false) { if ($session || $this->type == 'session') { return $this->session_del($key); } diff --git a/lib/config.php b/lib/config.php index f515eaa993..6228d342b5 100644 --- a/lib/config.php +++ b/lib/config.php @@ -15,7 +15,7 @@ abstract class Hm_Config { protected $source = ''; /* config data */ - protected $config = array('version' => VERSION); + protected $config = ['version' => VERSION]; /* flag indicating failed decryption */ public $decrypt_failed = false; @@ -25,7 +25,7 @@ abstract class Hm_Config { /* flag to save config after page handling */ public $save_on_login = false; - + /** * This method must be overriden by classes extending this one * @param string $source source or identifier to determine the source @@ -80,12 +80,12 @@ public function set($name, $value) { * @return void */ public function reset_factory() { - $this->config = array( - "version"=>$this->config["version"], - "feeds"=>$this->config["feeds"], - "imap_servers"=>$this->config["imap_servers"], - "smtp_servers"=>$this->config["smtp_servers"] - ); + $this->config = [ + 'version' => $this->config['version'], + 'feeds' => $this->config['feeds'], + 'imap_servers' => $this->config['imap_servers'], + 'smtp_servers' => $this->config['smtp_servers'] + ]; } /** @@ -94,8 +94,8 @@ public function reset_factory() { * @param false|string $default value to return if the name is not found * @return mixed found value, otherwise $default */ - public function get($name, $default=false) { - return array_key_exists($name, $this->config) ? $this->config[$name] : $default; + public function get($name, $default = false) { + return $this->config[$name] ?? $default; } /** @@ -111,7 +111,7 @@ public function set_tz() { * @return void */ public function shuffle() { - $new_config = array(); + $new_config = []; $keys = array_keys($this->config); shuffle($keys); foreach ($keys as $key) { @@ -140,21 +140,19 @@ public function decode($data) { * @return array of items removed */ public function filter_servers() { - $removed = array(); - $excluded = array('imap_servers','smtp_servers'); + $removed = []; + $excluded = ['imap_servers', 'smtp_servers']; $no_password = $this->get('no_password_save_setting', false); foreach ($this->config as $key => $vals) { if (in_array($key, $excluded, true)) { foreach ($vals as $index => $server) { - if (array_key_exists('default', $server) && $server['default']) { + if (!empty($server['default'])) { $removed[$key][$index] = $server; unset($this->config[$key][$index]); - } - elseif (!array_key_exists('server', $server)) { + } elseif (!array_key_exists('server', $server)) { $removed[$key][$index] = $server; unset($this->config[$key][$index]); - } - else { + } else { $this->config[$key][$index]['object'] = false; if ($no_password) { if (!array_key_exists('auth', $server) || $server['auth'] != 'xoauth2') { @@ -179,8 +177,7 @@ public function restore_servers($removed) { foreach ($vals as $index => $server) { if (is_array($server)) { $this->config[$key][$index] = $server; - } - else { + } else { $this->config[$key][$index]['pass'] = $server; } } @@ -236,15 +233,13 @@ public function load($username, $key) { if ($str_data) { if (!$this->crypt) { $data = $this->decode($str_data); - } - else { + } else { $data = $this->decode(Hm_Crypt::plaintext($str_data, $key)); } if (is_array($data)) { $this->config = array_merge($this->config, $data); $this->set_tz(); - } - else { + } else { $this->decrypt_failed = true; $this->encrypted_str = $str_data; } @@ -258,7 +253,7 @@ public function load($username, $key) { * @param string $username * @return void */ - public function reload($data, $username=false) { + public function reload($data, $username = false) { $this->username = $username; $this->config = $data; $this->set_tz(); @@ -276,8 +271,7 @@ public function save($username, $key) { $removed = $this->filter_servers(); if (!$this->crypt) { $data = json_encode($this->config); - } - else { + } else { $data = Hm_Crypt::ciphertext(json_encode($this->config), $key); } file_put_contents($destination, $data); @@ -302,12 +296,12 @@ public function set($name, $value) { * @return void */ public function reset_factory() { - $this->config = array( - "version"=>$this->config["version"], - "feeds"=>$this->config["feeds"], - "imap_servers"=>$this->config["imap_servers"], - "smtp_servers"=>$this->config["smtp_servers"] - ); + $this->config = [ + 'version' => $this->config['version'], + 'feeds' => $this->config['feeds'], + 'imap_servers' => $this->config['imap_servers'], + 'smtp_servers' => $this->config['smtp_servers'] + ]; if (!$this->crypt) { $this->save($this->username, false); } @@ -346,9 +340,9 @@ public function __construct($config) { * @return boolean */ private function new_settings($username) { - $res = Hm_DB::execute($this->dbh, 'insert into hm_user_settings values(?,?)', array($username, '')); + $res = Hm_DB::execute($this->dbh, 'insert into hm_user_settings values(?,?)', [$username, '']); Hm_Debug::add(sprintf("created new row in hm_user_settings for %s", $username)); - $this->config = array(); + $this->config = []; return $res ? true : false; } @@ -360,16 +354,14 @@ private function new_settings($username) { private function decrypt_settings($data, $key) { if (!$this->crypt) { $data = $this->decode($data['settings']); - } - else { + } else { $data = $this->decode(Hm_Crypt::plaintext($data['settings'], $key)); } if (is_array($data)) { $this->config = array_merge($this->config, $data); $this->set_tz(); return true; - } - else { + } else { $this->decrypt_failed = true; return false; } @@ -384,7 +376,7 @@ private function decrypt_settings($data, $key) { public function load($username, $key) { $this->username = $username; $this->connect(); - $data = Hm_DB::execute($this->dbh, 'select * from hm_user_settings where username=?', array($username)); + $data = Hm_DB::execute($this->dbh, 'select * from hm_user_settings where username=?', [$username]); if (!$data || !array_key_exists('settings', $data)) { return $this->new_settings($username); } @@ -397,7 +389,7 @@ public function load($username, $key) { * @param string $username * @return void */ - public function reload($data, $username=false) { + public function reload($data, $username = false) { $this->username = $username; $this->config = $data; $this->set_tz(); @@ -422,18 +414,16 @@ public function save($username, $key) { $removed = $this->filter_servers(); if (!$this->crypt) { $config = json_encode($this->config); - } - else { + } else { $config = Hm_Crypt::ciphertext(json_encode($this->config), $key); } $this->connect(); - if (Hm_DB::execute($this->dbh, 'select settings from hm_user_settings where username=?', array($username))) { - Hm_DB::execute($this->dbh, 'update hm_user_settings set settings=? where username=?', array($config, $username)); + if (Hm_DB::execute($this->dbh, 'select settings from hm_user_settings where username=?', [$username])) { + Hm_DB::execute($this->dbh, 'update hm_user_settings set settings=? where username=?', [$config, $username]); Hm_Debug::add(sprintf("Saved user data to DB for %s", $username)); $res = true; - } - else { - $res = Hm_DB::execute($this->dbh, 'insert into hm_user_settings values(?,?)', array($username, $config)); + } else { + $res = Hm_DB::execute($this->dbh, 'insert into hm_user_settings values(?,?)', [$username, $config]); } $this->restore_servers($removed); return $res; @@ -457,12 +447,12 @@ public function set($name, $value) { * @return void */ public function reset_factory() { - $this->config = array( - "version"=>$this->config["version"], - "feeds"=>$this->config["feeds"], - "imap_servers"=>$this->config["imap_servers"], - "smtp_servers"=>$this->config["smtp_servers"] - ); + $this->config = [ + 'version' => $this->config['version'], + 'feeds' => $this->config['feeds'], + 'imap_servers' => $this->config['imap_servers'], + 'smtp_servers' => $this->config['smtp_servers'] + ]; if (!$this->crypt) { $this->save($this->username, false); } @@ -474,7 +464,7 @@ public function reset_factory() { */ class Hm_Site_Config_File extends Hm_Config { - public $user_defaults = array(); + public $user_defaults = []; /** * Load data based on source @@ -538,10 +528,10 @@ function load_user_config_object($config) { case 'custom': if (class_exists($class)) { $user_config = new $class($config); - Hm_Debug::add("Using custom user configuration: $class"); + Hm_Debug::add("Using custom user configuration: {$class}"); break; } else { - Hm_Debug::add("User configuration class does not exist: $class"); + Hm_Debug::add("User configuration class does not exist: {$class}"); } default: $user_config = new Hm_User_Config_File($config); @@ -558,7 +548,7 @@ function load_user_config_object($config) { */ function crypt_state($config) { if ($config->get('single_server_mode') && - in_array($config->get('auth_type'), array('IMAP'), true)) { + in_array($config->get('auth_type'), ['IMAP'], true)) { return false; } return true; diff --git a/lib/crypt.php b/lib/crypt.php index 4a103f5285..b95e8d991e 100644 --- a/lib/crypt.php +++ b/lib/crypt.php @@ -174,7 +174,7 @@ private static function hash_equals($a, $b) { * @param string $a hash * @param string $b hash * @return bool - */ + */ public static function hash_compare($a, $b) { if (!is_string($a) || !is_string($b) || strlen($a) !== strlen($b)) { return false; @@ -193,8 +193,9 @@ public static function hash_compare($a, $b) { * @return string[] */ protected static function keygen($key, $salt) { - return array($salt, self::pbkdf2($key, $salt, 32, self::$encryption_rounds, self::$hmac)); + return [$salt, self::pbkdf2($key, $salt, 32, self::$encryption_rounds, self::$hmac)]; } + /** * Key derivation wth pbkdf2: http://en.wikipedia.org/wiki/PBKDF2 * @param string $key payload @@ -235,7 +236,7 @@ public static function pbkdf2($key, $salt, $length, $count, $algo) { * @param string $type Can be either pbkdf2 or php * @return string */ - public static function hash_password($password, $salt=false, $count=false, $algo='sha512', $type='php') { + public static function hash_password($password, $salt = false, $count = false, $algo = 'sha512', $type = 'php') { if (function_exists('password_hash') && $type === 'php') { return password_hash($password, PASSWORD_DEFAULT); } @@ -275,7 +276,7 @@ public static function check_password($password, $hash) { * @param int $size length of the result * @return string */ - public static function unique_id($size=128) { + public static function unique_id($size = 128) { return base64_encode(openssl_random_pseudo_bytes($size)); } @@ -284,11 +285,10 @@ public static function unique_id($size=128) { * @param int $size * @return string */ - public static function random($size=128) { + public static function random($size = 128) { try { return Hm_Functions::random_bytes($size); - } - catch (Exception $e) { + } catch (Exception $e) { Hm_Functions::cease('No reliable random byte source found'); } } diff --git a/lib/crypt_sodium.php b/lib/crypt_sodium.php index 5f4397a287..bd79b44b29 100644 --- a/lib/crypt_sodium.php +++ b/lib/crypt_sodium.php @@ -64,7 +64,7 @@ public static function ciphertext($string, $key) { * @param string $password password to hash * @return string */ - public static function hash_password($password, $salt=false, $count=false, $algo='sha512', $type='php') { + public static function hash_password($password, $salt = false, $count = false, $algo = 'sha512', $type = 'php') { if (!LIBSODIUM) { return parent::hash_password($password, $salt, $count, $algo, $type); } @@ -95,11 +95,10 @@ public static function check_password($password, $hash) { * @param string $salt a salt to use, or create one if needed * @return string[] */ - protected static function keygen($key, $salt=false) { + protected static function keygen($key, $salt = false) { if ($salt === false) { $salt = Hm_Sodium_Compat::randombytes_buf(); } return parent::keygen($key, $salt); } - } diff --git a/lib/db.php b/lib/db.php index 29b527c847..3dc7a3ea23 100644 --- a/lib/db.php +++ b/lib/db.php @@ -12,10 +12,10 @@ class Hm_DB { /* DB connection handlers */ - static public $dbh = array(); + static public $dbh = []; /* required DB configuration params */ - static private $required_config = array('db_user', 'db_pass', 'db_name', 'db_host', 'db_driver'); + static private $required_config = ['db_user', 'db_pass', 'db_name', 'db_host', 'db_driver']; /* DB config */ static private $config; @@ -26,7 +26,7 @@ class Hm_DB { * @return void */ static private function parse_config($site_config) { - self::$config = array( + self::$config = [ 'db_driver' => $site_config->get('db_driver', false), 'db_host' => $site_config->get('db_host', false), 'db_name' => $site_config->get('db_name', false), @@ -35,7 +35,7 @@ static private function parse_config($site_config) { 'db_socket' => $site_config->get('db_socket', false), 'db_conn_type' => $site_config->get('db_connection_type', 'host'), 'db_port' => $site_config->get('db_port', false), - ); + ]; foreach (self::$required_config as $v) { if (!self::$config[$v]) { @@ -70,12 +70,10 @@ static public function build_dsn() { } if (self::$config['db_conn_type'] == 'socket') { return sprintf('%s:unix_socket=%s;dbname=%s', self::$config['db_driver'], self::$config['db_socket'], self::$config['db_name']); - } - else { + } else { if (self::$config['db_port']) { return sprintf('%s:host=%s;port=%s;dbname=%s', self::$config['db_driver'], self::$config['db_host'], self::$config['db_port'], self::$config['db_name']); - } - else { + } else { return sprintf('%s:host=%s;dbname=%s', self::$config['db_driver'], self::$config['db_host'], self::$config['db_name']); } } @@ -89,7 +87,7 @@ static public function build_dsn() { * @param bool $all optional flag to return multiple rows * @return boolean|integer|array */ - static public function execute($dbh, $sql, $args, $type=false, $all=false) { + static public function execute($dbh, $sql, $args, $type = false, $all = false) { if (!$dbh) { return false; } @@ -134,7 +132,7 @@ static public function connect($site_config) { self::parse_config($site_config); $key = self::db_key(); - if (array_key_exists($key, self::$dbh) && self::$dbh[$key]) { + if (!empty(self::$dbh[$key])) { return self::$dbh[$key]; } $dsn = self::build_dsn(); @@ -143,8 +141,7 @@ static public function connect($site_config) { self::$dbh[$key]->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); Hm_Debug::add(sprintf('Connecting to dsn: %s', $dsn)); return self::$dbh[$key]; - } - catch (Exception $oops) { + } catch (Exception $oops) { Hm_Debug::add($oops->getMessage()); self::$dbh[$key] = false; return false; diff --git a/lib/dispatch.php b/lib/dispatch.php index 7535280e3b..ce6359ca66 100644 --- a/lib/dispatch.php +++ b/lib/dispatch.php @@ -43,7 +43,7 @@ private function redirect_to_current($request) { * @return void */ private function redirect_to_url($mod_exec) { - if (array_key_exists('redirect_url', $mod_exec->handler_response) && $mod_exec->handler_response['redirect_url']) { + if (!empty($mod_exec->handler_response['redirect_url'])) { Hm_Dispatch::page_redirect($mod_exec->handler_response['redirect_url']); } } @@ -89,19 +89,16 @@ public function validate_request_uri($uri) { * @return string|false */ public function check_for_redirect($request, $mod_exec, $session) { - if (array_key_exists('no_redirect', $mod_exec->handler_response) && $mod_exec->handler_response['no_redirect']) { + if (!empty($mod_exec->handler_response['no_redirect'])) { return 'noredirect'; } if ($this->post_redirect($request, $session, $mod_exec)) { return 'redirect'; - } - elseif (array_key_exists('redirect_url', $mod_exec->handler_response) && - $mod_exec->handler_response['redirect_url']) { + } elseif (!empty($mod_exec->handler_response['redirect_url'])) { $session->end(); $this->redirect_to_url($mod_exec); return 'redirect'; - } - elseif ($this->unpack_messages($request, $session)) { + } elseif ($this->unpack_messages($request, $session)) { return 'msg_forward'; } return false; @@ -114,7 +111,7 @@ public function check_for_redirect($request, $mod_exec, $session) { * @return boolean */ public function unpack_messages($request, $session) { - if (array_key_exists('hm_msgs', $request->cookie) && trim($request->cookie['hm_msgs'])) { + if (!empty($request->cookie['hm_msgs'])) { $msgs = @json_decode(base64_decode($request->cookie['hm_msgs']), true); if (is_array($msgs)) { array_walk($msgs, function($v) { Hm_Msgs::add($v); }); @@ -131,7 +128,7 @@ public function unpack_messages($request, $session) { * @param int $status current HTTP status * @return void */ - static public function page_redirect($url, $status=false) { + static public function page_redirect($url, $status = false) { if (DEBUG_MODE) { Hm_Debug::add(sprintf('Redirecting to %s', $url)); Hm_Debug::load_page_stats(); @@ -239,7 +236,7 @@ private function process_request() { /* output content to the browser */ $this->render_output(); } - + /** * Check for a flag to save settings on login */ @@ -257,7 +254,7 @@ private function save_settings_on_login() { * @return void */ private function close_connections() { - foreach (array('Hm_IMAP_List', 'Hm_SMTP_List') as $class) { + foreach (['Hm_IMAP_List', 'Hm_SMTP_List'] as $class) { if (Hm_Functions::class_exists($class)) { $class::clean_up(); } @@ -294,11 +291,7 @@ private function render_output() { * @param return array */ private function get_pages($filters) { - $pages = array(); - if (array_key_exists('allowed_pages', $filters)) { - $pages = $filters['allowed_pages']; - } - return $pages; + return $filters['allowed_pages'] ?? []; } /** @@ -311,17 +304,15 @@ public function validate_ajax_request($request, $filters) { if (array_key_exists('hm_ajax_hook', $request->get)) { if (in_array($request->get['hm_ajax_hook'], $this->get_pages($filters), true)) { return true; - } - else { - Hm_Functions::cease(json_encode(array('status' => 'not callable')));; + } else { + Hm_Functions::cease(json_encode(['status' => 'not callable']));; } } if (array_key_exists('hm_ajax_hook', $request->post)) { if (in_array($request->post['hm_ajax_hook'], $this->get_pages($filters), true)) { return true; - } - else { - Hm_Functions::cease(json_encode(array('status' => 'not callable')));; + } else { + Hm_Functions::cease(json_encode(['status' => 'not callable']));; } } return false; @@ -336,16 +327,10 @@ public function validate_ajax_request($request, $filters) { public function get_page($filters, $request) { $this->page = 'notfound'; if ($request->type == 'AJAX' && $this->validate_ajax_request($request, $filters)) { - if (array_key_exists('hm_ajax_hook', $request->get)) { - $this->page = $request->get['hm_ajax_hook']; - } else { - $this->page = $request->post['hm_ajax_hook']; - } - } - elseif (array_key_exists('page', $request->get) && in_array($request->get['page'], $this->get_pages($filters), true)) { + $this->page = $request->get['hm_ajax_hook'] ?? $request->post['hm_ajax_hook']; + } elseif (array_key_exists('page', $request->get) && in_array($request->get['page'], $this->get_pages($filters), true)) { $this->page = $request->get['page']; - } - elseif (!array_key_exists('page', $request->get)) { + } elseif (!array_key_exists('page', $request->get)) { $this->page = 'home'; } $this->module_exec->page = $this->page; diff --git a/lib/environment.php b/lib/environment.php index ce91136d37..416804934d 100644 --- a/lib/environment.php +++ b/lib/environment.php @@ -37,10 +37,9 @@ public function load() { } } - public static function get($key, $defaultValue = null) { + public static function get($key, $default = null) { $variables = self::getInstance()->get_environment_variables(); - - return array_key_exists($key, $variables) ? $variables[$key] : $defaultValue; + return $variables[$key] ?? $default; } /** diff --git a/lib/format.php b/lib/format.php index 0b56902c48..3527b23ce3 100644 --- a/lib/format.php +++ b/lib/format.php @@ -48,7 +48,7 @@ public function content($output, $allowed_output) { $output['router_user_msgs'] = Hm_Msgs::get(); $output = $this->filter_all_output($output, $allowed_output); if ($this->config->get('encrypt_ajax_requests', false)) { - $output = array('payload' => Hm_Crypt_Base::ciphertext(json_encode($output, JSON_FORCE_OBJECT), Hm_Request_Key::generate())); + $output = ['payload' => Hm_Crypt_Base::ciphertext(json_encode($output, JSON_FORCE_OBJECT), Hm_Request_Key::generate())]; } return json_encode($output, JSON_FORCE_OBJECT); } @@ -85,8 +85,7 @@ public function filter_all_output($data, $allowed) { private function filter_output($name, $value, $allowed) { if ($allowed[$name][1]) { $new_value = filter_var($value, $allowed[$name][0], $allowed[$name][1]); - } - else { + } else { $new_value = filter_var($value, $allowed[$name][0]); } if ($new_value === false && $allowed[$name] != FILTER_VALIDATE_BOOLEAN) { @@ -126,7 +125,7 @@ class Hm_Transform { * @param string $encoding encoding to use for values * @return string on success, false on failure */ - public static function stringify($data, $encoding='base64_encode') { + public static function stringify($data, $encoding = 'base64_encode') { if (is_string($data)) { return $data; } @@ -144,8 +143,7 @@ public static function stringify($data, $encoding='base64_encode') { public static function convert($data) { if (substr($data, 0, 2) === 'a:') { return @unserialize($data); - } - elseif (substr($data, 0, 1) === '{' || substr($data, 0, 1) === '[') { + } elseif (substr($data, 0, 1) === '{' || substr($data, 0, 1) === '[') { return @json_decode($data, true); } return false; @@ -158,7 +156,7 @@ public static function convert($data) { * @param boolean $return return original string if true * @return mixed array on success, false or original string on failure */ - public static function unstringify($data, $encoding='base64_decode', $return=false) { + public static function unstringify($data, $encoding = 'base64_decode', $return = false) { if (!is_string($data) || !trim($data)) { return false; } @@ -179,16 +177,14 @@ public static function unstringify($data, $encoding='base64_decode', $return=fal * @return array */ public static function hm_encode($data, $encoding) { - $result = array(); + $result = []; foreach ($data as $name => $val) { if (is_array($val)) { $result[$name] = self::hm_encode($val, $encoding); - } - else { + } else { if (is_string($val)) { $result[$name] = $encoding($val); - } - else { + } else { $result[$name] = $val; } } diff --git a/lib/ini_set.php b/lib/ini_set.php index db4726c2b5..7d37aaf6b0 100644 --- a/lib/ini_set.php +++ b/lib/ini_set.php @@ -33,7 +33,7 @@ } /* gc max lifetime */ -ini_set('session.gc_maxlifetime', 1440); +ini_set('session.gc_maxlifetime', 1440); /* disable trans sid */ ini_set('session.use_trans_sid', 0); @@ -44,8 +44,7 @@ /* session hash mechanism */ if (version_compare(PHP_VERSION, 7.4, '==')) { ini_set('session.hash_function', 1); -} -else { +} else { ini_set('session.hash_function', 'sha256'); } diff --git a/lib/module.php b/lib/module.php index ce1216a5d8..5062599e5d 100644 --- a/lib/module.php +++ b/lib/module.php @@ -11,17 +11,17 @@ * to fetch data set by other modules and to return their own output. Handler modules must use these * methods to set a response, output modules must if the format is AJAX, otherwise they should return * an HTML5 string - */ + */ trait Hm_Module_Output { /* module output */ - protected $output = array(); + protected $output = []; /* protected output keys */ - protected $protected = array(); + protected $protected = []; /* list of appendable keys */ - protected $appendable = array(); + protected $appendable = []; /** * @param string $name name to check for @@ -45,7 +45,7 @@ protected function check_overwrite($name, $list, $type, $value) { * @param bool $protected true disallows overwriting * @return bool true on success */ - public function out($name, $value, $protected=true) { + public function out($name, $value, $protected = true) { if (!$this->check_overwrite($name, $this->protected, 'protected', $value)) { return false; } @@ -73,14 +73,12 @@ public function append($name, $value) { if (is_array($this->output[$name])) { $this->output[$name][] = $value; return true; - } - else { + } else { Hm_Debug::add(sprintf('Tried to append %s to scaler %s', $value, $name)); return false; } - } - else { - $this->output[$name] = array($value); + } else { + $this->output[$name] = [$value]; $this->appendable[] = $name; return true; } @@ -92,11 +90,11 @@ public function append($name, $value) { * @param bool $special_only only use htmlspecialchars not htmlentities * @return string sanitized value */ - public function html_safe($string, $special_only=false) { + public function html_safe($string, $special_only = false) { if ($special_only) { - return htmlspecialchars((string) $string, ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8"); + return htmlspecialchars((string) $string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } - return htmlentities((string) $string, ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8"); + return htmlentities((string) $string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } /** @@ -110,13 +108,11 @@ public function concat($name, $value) { if (is_string($this->output[$name])) { $this->output[$name] .= $value; return true; - } - else { + } else { Hm_Debug::add(sprintf('Could not append %s to %s', print_r($value,true), $name)); return false; } - } - else { + } else { $this->output[$name] = $value; return true; } @@ -145,7 +141,7 @@ public function output_protected() { * @param string $typed if a default value is given, typecast the result to it's type * @return mixed value if found or default */ - public function get($name, $default=NULL, $typed=true) { + public function get($name, $default = NULL, $typed = true) { if (array_key_exists($name, $this->output)) { $val = $this->output[$name]; if (!is_null($default) && $typed) { @@ -195,7 +191,7 @@ trait Hm_Handler_Validate { * @return bool */ public function validate_method($session, $request) { - if (!in_array(strtolower($request->method), array('get', 'post'), true)) { + if (!in_array(strtolower($request->method), ['get', 'post'], true)) { if ($session->loaded) { $session->destroy($request); Hm_Debug::add(sprintf('LOGGED OUT: invalid method %s', $request->method)); @@ -231,18 +227,18 @@ private function source_and_target($request, $config) { if ($target == 'none') { $target = false; } - $server_vars = array( + $server_vars = [ 'HTTP_REFERER' => 'source', 'HTTP_ORIGIN' => 'source', 'HTTP_HOST' => 'target', 'HTTP_X_FORWARDED_HOST' => 'target' - ); + ]; foreach ($server_vars as $header => $type) { - if (array_key_exists($header, $request->server) && $request->server[$header]) { + if (!empty($request->server[$header])) { $$type = $request->server[$header]; } } - return array($source, $target); + return [$source, $target]; } /** @@ -328,7 +324,7 @@ abstract class Hm_Handler_Module { * @param array $output data from handler modules * @param array $protected list of protected output names */ - public function __construct($parent, $page, $output=array(), $protected=array()) { + public function __construct($parent, $page, $output = [], $protected = []) { $this->session = $parent->session; $this->request = $parent->request; $this->cache = $parent->cache; @@ -348,7 +344,7 @@ private function invalid_ajax_key() { Hm_Debug::load_page_stats(); Hm_Debug::show(); } - Hm_Functions::cease(json_encode(array('status' => 'not callable')));; + Hm_Functions::cease(json_encode(['status' => 'not callable'])); return 'exit'; } @@ -381,8 +377,7 @@ public function process_key() { } if ($this->request->type == 'AJAX') { return $this->invalid_ajax_key(); - } - else { + } else { return $this->invalid_http_key(); } } @@ -413,7 +408,7 @@ private function check_field($val) { * @return array tuple with a bool indicating success, and an array of valid form values */ public function process_form($form) { - $new_form = array(); + $new_form = []; foreach($form as $name) { if (!array_key_exists($name, $this->request->post)) { continue; @@ -423,7 +418,7 @@ public function process_form($form) { $new_form[$name] = $val; } } - return array((count($form) === count($new_form)), $new_form); + return [(count($form) === count($new_form)), $new_form]; } /** @@ -461,7 +456,7 @@ abstract class Hm_Output_Module { use Hm_Module_Output; /* translated language strings */ - protected $lstr = array(); + protected $lstr = []; /* langauge name */ protected $lang = false; @@ -491,8 +486,7 @@ public function trans($string) { if (array_key_exists($string, $this->lstr)) { if ($this->lstr[$string] === false) { return strip_tags($string); - } - else { + } else { return strip_tags($this->lstr[$string]); } } @@ -532,7 +526,7 @@ public function all_trans() { * @return string translated string */ public function translate_number($number) { - if (!is_numeric($number) || !in_array($this->lang, array("fa"))) { + if (!is_numeric($number) || !in_array($this->lang, ['fa'])) { return $number; } $number_splitted = str_split($number); diff --git a/lib/modules.php b/lib/modules.php index 52558368e2..a88de16b32 100644 --- a/lib/modules.php +++ b/lib/modules.php @@ -19,19 +19,19 @@ trait Hm_Modules_Queue { private static $queue_attempts = 0; /* holds the module to page assignment list */ - private static $module_list = array(); + private static $module_list = []; /* current module set name, used for error tracking and limiting php file inclusion */ private static $source = ''; /* a retry queue for modules that fail to insert immediately */ - private static $module_queue = array(); + private static $module_queue = []; /* queue for delayed module insertion for all pages */ - private static $all_page_queue = array(); + private static $all_page_queue = []; /* queue for module replacement */ - private static $replace_queue = array(); + private static $replace_queue = []; /** * Queue a module to be added to all defined pages @@ -43,7 +43,7 @@ trait Hm_Modules_Queue { * return void */ public static function queue_module_for_all_pages($module, $logged_in, $marker, $placement, $source) { - self::$all_page_queue[] = array($module, $logged_in, $marker, $placement, $source); + self::$all_page_queue[] = [$module, $logged_in, $marker, $placement, $source]; } /** @@ -68,10 +68,9 @@ public static function process_all_page_queue() { */ private static function queue_module($queue, $page, $module, $logged_in, $marker, $placement, $source) { if ($queue) { - self::$module_queue[] = array($page, $module, $logged_in, $marker, $placement, $source); + self::$module_queue[] = [$page, $module, $logged_in, $marker, $placement, $source]; return true; - } - else { + } else { Hm_Debug::add(sprintf('failed to insert module %s on %s', $module, $page)); } return false; @@ -85,7 +84,7 @@ private static function queue_module($queue, $page, $module, $logged_in, $marker * @return void */ private static function queue_replacement_module($target, $replacement, $page) { - self::$replace_queue[] = array($target, $replacement, $page, self::$source); + self::$replace_queue[] = [$target, $replacement, $page, self::$source]; } /** @@ -104,7 +103,7 @@ public static function process_replace_queue() { */ public static function try_queued_modules() { $requeue = true; - $new_queue = array(); + $new_queue = []; if (self::$queue_attempts >= self::$queue_limit) { $requeue = false; } @@ -197,7 +196,7 @@ public static function add($page, $module, $logged_in, $marker=false, $placement */ private static function add_page($page) { if (!array_key_exists($page, self::$module_list)) { - self::$module_list[$page] = array(); + self::$module_list[$page] = []; return true; } return false; @@ -215,9 +214,8 @@ private static function add_page($page) { private static function insert_module($marker, $page, $module, $logged_in, $placement, $source) { if ($marker !== false) { $inserted = self::insert_at_marker($marker, $page, $module, $logged_in, $placement, $source); - } - else { - self::$module_list[$page][$module] = array($source, $logged_in); + } else { + self::$module_list[$page][$module] = [$source, $logged_in]; $inserted = true; } return $inserted; @@ -242,8 +240,8 @@ private static function insert_at_marker($marker, $page, $module, $logged_in, $p $index++; } $list = self::$module_list[$page]; - self::$module_list[$page] = array_merge(array_slice($list, 0, $index), - array($module => array($source, $logged_in)), + self::$module_list[$page] = array_merge(array_slice($list, 0, $index), + [$module => [$source, $logged_in]], array_slice($list, $index)); $inserted = true; } @@ -265,8 +263,7 @@ public static function replace($target, $replacement, $page=false, $source=false self::$module_list[$page] = self::swap_key($target, $replacement, self::$module_list[$page], $source); $found = true; } - } - else { + } else { foreach (self::$module_list as $page => $modules) { if (array_key_exists($target, $modules)) { self::$module_list[$page] = self::swap_key($target, $replacement, self::$module_list[$page], $source); @@ -322,7 +319,7 @@ public static function del($page, $module) { * @return array list of assigned modules */ public static function get_for_page($page) { - $res = array(); + $res = []; if (array_key_exists($page, self::$module_list)) { $res = array_merge($res, self::$module_list[$page]); } @@ -354,7 +351,7 @@ class Hm_Output_Modules { use Hm_Modules; } * This is the functional interface used by module sets to * setup data handlers and output modules in their setup.php files. * They are easier to use than dealing directly with the class instances - */ + */ /** * Add a module set name to the input processing manager diff --git a/lib/modules_exec.php b/lib/modules_exec.php index 2df65262a1..01cca573a8 100644 --- a/lib/modules_exec.php +++ b/lib/modules_exec.php @@ -61,7 +61,7 @@ public function run_output_modules($request, $active_session, $page, $handler_re /** * Run a single output modules and return the results - * @param array $input handler output + * @param array $input handler output * @param array $protected list of protected output * @param string $name handler module name * @param array $args module arguments @@ -246,15 +246,10 @@ public function process_module_setup() { * return array */ public function get_current_language() { - if (array_key_exists('language', $this->handler_response)) { - $lang = $this->handler_response['language']; - } - else { - $lang = 'en'; - } - $strings = array(); - if (file_exists(APP_PATH.'language/'.$lang.'.php')) { - $strings = require APP_PATH.'language/'.$lang.'.php'; + $lang = $this->handler_response['language'] ?? 'en'; + $strings = []; + if (file_exists(APP_PATH."language/{$lang}.php")) { + $strings = require APP_PATH."language/{$lang}.php"; } return $strings; } @@ -309,8 +304,7 @@ static public function merge_filters($existing, $new) { if (array_key_exists($v, $new)) { if ($v == 'allowed_pages' || $v == 'allowed_output') { $existing[$v] = array_merge($existing[$v], $new[$v]); - } - else { + } else { $existing[$v] += $new[$v]; } } @@ -362,7 +356,7 @@ public function load_module_sets($page) { if (!count($active_mods)) { Hm_Functions::cease('No module assignments found'); } - $mods = $this->site_config->get_modules(); + $mods = $this->site_config->get_modules(); $this->load_module_set_files($mods, $active_mods); } diff --git a/lib/oauth2.php b/lib/oauth2.php index 1f4a8905b1..87ba5f02fc 100644 --- a/lib/oauth2.php +++ b/lib/oauth2.php @@ -37,7 +37,7 @@ public function __construct($id, $secret, $uri) { * @param string $login_hint optional username * @return string */ - public function request_authorization_url($url, $scope, $state, $login_hint=false) { + public function request_authorization_url($url, $scope, $state, $login_hint = false) { $res = sprintf('%s?response_type=code&scope=%s&state=%s&'. 'approval_prompt=force&access_type=offline&client_id=%s&redirect_uri=%s', $url, $scope, $state, $this->client_id, $this->redirect_uri); @@ -54,7 +54,7 @@ public function request_authorization_url($url, $scope, $state, $login_hint=fals * @param array $headers HTTP headers to add to the request * @return array */ - public function request_token($url, $authorization_code, $headers=array()) { + public function request_token($url, $authorization_code, $headers = []) { return $this->api->command($url, $headers, array('code' => $authorization_code, 'client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'redirect_uri' => $this->redirect_uri, 'grant_type' => 'authorization_code')); } @@ -66,7 +66,7 @@ public function request_token($url, $authorization_code, $headers=array()) { * @return array */ public function refresh_token($url, $refresh_token) { - return $this->api->command($url, array(), array('client_id' => $this->client_id, 'client_secret' => $this->client_secret, + return $this->api->command($url, [], array('client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'refresh_token' => $refresh_token, 'grant_type' => 'refresh_token')); } } diff --git a/lib/output.php b/lib/output.php index d68f91ac90..eb51518128 100644 --- a/lib/output.php +++ b/lib/output.php @@ -26,13 +26,8 @@ abstract protected function output_content($content, $headers); * @param array $input raw module data * @return void */ - public function send_response($response, $input=array()) { - if (array_key_exists('http_headers', $input)) { - $this->output_content($response, $input['http_headers']); - } - else { - $this->output_content($response, array()); - } + public function send_response($response, $input = []) { + $this->output_content($response, $input['http_headers'] ?? []); } } @@ -58,7 +53,7 @@ protected function output_headers($headers) { * @param array $headers HTTP headers to set * @return void */ - protected function output_content($content, $headers=array()) { + protected function output_content($content, $headers = []) { $this->output_headers($headers); ob_end_clean(); echo $content; @@ -71,7 +66,7 @@ protected function output_content($content, $headers=array()) { trait Hm_List { /* message list */ - private static $msgs = array(); + private static $msgs = []; /** * Add a message @@ -95,7 +90,7 @@ public static function get() { * @return null */ public static function flush() { - self::$msgs = array(); + self::$msgs = []; } /** @@ -103,15 +98,13 @@ public static function flush() { * @param mixed $mixed value to stringify * @return string */ - public static function str($mixed, $return_type=true) { + public static function str($mixed, $return_type = true) { $type = gettype($mixed); if (in_array($type, array('array', 'object'), true)) { $str = print_r($mixed, true); - } - elseif ($return_type) { + } elseif ($return_type) { $str = sprintf("%s: %s", $type, $mixed); - } - else { + } else { $str = (string) $mixed; } return $str; @@ -135,7 +128,7 @@ class Hm_Msgs { use Hm_List; } * System debug notices */ class Hm_Debug { - + use Hm_List; /** diff --git a/lib/request.php b/lib/request.php index 743b10047a..b3f4978b92 100644 --- a/lib/request.php +++ b/lib/request.php @@ -9,25 +9,25 @@ /** * Data request details * - * This is an interface to HTTP request details. All request data + * This is an interface to HTTP request details. All request data * must be white-listed and sanitized by module set filters. */ class Hm_Request { /* sanitized $_POST variables */ - public $post = array(); + public $post = []; /* sanitized $_GET variables */ - public $get = array(); + public $get = []; /* sanitized $_COOKIE variables */ - public $cookie = array(); + public $cookie = []; /* sanitized $_SERVER variables */ - public $server = array(); + public $server = []; /* $_ENV variables (fallback for missing $_SERVER vals) */ - private $env = array(); + private $env = []; /* request type. either AJAX or HTTP */ public $type = ''; @@ -48,19 +48,19 @@ class Hm_Request { public $path = ''; /* allowed AJAX output field names defined by module sets */ - public $allowed_output = array(); + public $allowed_output = []; /* bool indicating unknown input data */ public $invalid_input_detected = false; /* invalid input fields */ - public $invalid_input_fields = array(); + public $invalid_input_fields = []; /* uploaded file details */ - public $files = array(); + public $files = []; /* module filters */ - public $filters = array(); + public $filters = []; /* HTTP request method */ public $method = false; @@ -125,8 +125,7 @@ private function get_other_request_details() { } if (array_key_exists('REQUEST_METHOD', $this->server)) { $this->method = $this->server['REQUEST_METHOD']; - } - elseif (array_key_exists('REQUEST_METHOD', $this->env)) { + } elseif (array_key_exists('REQUEST_METHOD', $this->env)) { $this->method = $this->env['REQUEST_METHOD']; $this->server = $this->env; } @@ -143,14 +142,14 @@ private function empty_super_globals() { if (version_compare(PHP_VERSION, '8.1', '>=')) { return; } - $_POST = array(); - $_SERVER = array(); - $_GET = array(); - $_COOKIE = array(); - $_FILES = array(); - $_REQUEST = array(); - $_ENV = array(); - + $_POST = []; + $_SERVER = []; + $_GET = []; + $_COOKIE = []; + $_FILES = []; + $_REQUEST = []; + $_ENV = []; + foreach (array_keys($GLOBALS) as $key) { if (isset($GLOBALS)) { unset($GLOBALS[$key]); @@ -167,7 +166,7 @@ private function empty_super_globals() { public function filter_input($type, $filters) { $data = Hm_Functions::filter_input_array($type, $filters); if ($data === false || $data === NULL) { - return array(); + return []; } return $data; } @@ -195,8 +194,7 @@ private function is_mobile() { private function is_tls() { if (array_key_exists('HTTPS', $this->server) && strtolower($this->server['HTTPS']) == 'on') { $this->tls = true; - } - elseif (array_key_exists('REQUEST_SCHEME', $this->server) && strtolower($this->server['REQUEST_SCHEME']) == 'https') { + } elseif (array_key_exists('REQUEST_SCHEME', $this->server) && strtolower($this->server['REQUEST_SCHEME']) == 'https') { $this->tls = true; } } @@ -209,8 +207,7 @@ private function get_request_type() { if ($this->is_ajax()) { $this->type = 'AJAX'; $this->format = 'Hm_Format_JSON'; - } - else { + } else { $this->type = 'HTTP'; $this->format = 'Hm_Format_HTML5'; } @@ -233,8 +230,7 @@ private function get_clean_url_path($uri) { if (strpos($uri, '?') !== false) { $parts = explode('?', $uri, 2); $path = $parts[0]; - } - else { + } else { $path = $uri; } $path = str_replace('index.php', '', $path); diff --git a/lib/servers.php b/lib/servers.php index b578e950e0..1bd5fbf159 100644 --- a/lib/servers.php +++ b/lib/servers.php @@ -8,7 +8,7 @@ trait Hm_Server_Connect { /* list of server connections */ - protected static $server_list = array(); + protected static $server_list = []; /** * Connect to a server @@ -19,7 +19,7 @@ trait Hm_Server_Connect { * @param bool $save_credentials true to save the username and password * @return object|false connection object on success, otherwise false */ - public static function connect($id, $cache=false, $user=false, $pass=false, $save_credentials=false) { + public static function connect($id, $cache = false, $user = false, $pass = false, $save_credentials = false) { if (!array_key_exists($id, self::$server_list)) { return false; } @@ -85,11 +85,10 @@ public abstract static function service_connect($id, $server, $user, $pass, $cac * @param int $id server id * @return void */ - public static function clean_up($id=false) { + public static function clean_up($id = false) { if ($id !== false && array_key_exists($id, self::$server_list)) { self::disconnect($id); - } - else { + } else { foreach (self::$server_list as $index => $server) { self::disconnect($index); } @@ -202,8 +201,8 @@ public static function add($atts, $save = true) { * @param bool $full true to return passwords for server connections. CAREFUL! * @return array server details */ - public static function dump($id=false, $full=false) { - $list = array(); + public static function dump($id = false, $full = false) { + $list = []; if ($id !== false) { return self::get($id, $full); } diff --git a/lib/session_base.php b/lib/session_base.php index 4f6d3a7a30..366b90dffb 100644 --- a/lib/session_base.php +++ b/lib/session_base.php @@ -32,7 +32,7 @@ abstract protected function destroy($request); * @param string $default value to return if $name is not found * @return mixed the value if found, otherwise $default */ - abstract protected function get($name, $default=false); + abstract protected function get($name, $default = false); /** * Check HTTP header "fingerprint" against the session value @@ -60,8 +60,8 @@ public function check_fingerprint($request) { * @return array */ private function fingerprint_flds() { - $flds = array('HTTP_USER_AGENT', 'REQUEST_SCHEME', 'HTTP_ACCEPT_LANGUAGE', - 'HTTP_ACCEPT_CHARSET', 'HTTP_HOST'); + $flds = ['HTTP_USER_AGENT', 'REQUEST_SCHEME', 'HTTP_ACCEPT_LANGUAGE', + 'HTTP_ACCEPT_CHARSET', 'HTTP_HOST']; if (!$this->site_config->get('allow_long_session') && !$this->site_config->get('disable_ip_check')) { $flds[] = 'REMOTE_ADDR'; } @@ -73,7 +73,7 @@ private function fingerprint_flds() { * @param array $env server env values * @return string fingerprint value */ - public function build_fingerprint($env, $input='') { + public function build_fingerprint($env, $input = '') { $id = $input; foreach ($this->fingerprint_flds() as $val) { $id .= (array_key_exists($val, $env)) ? $env[$val] : ''; @@ -120,7 +120,7 @@ abstract class Hm_Session { public $site_config; /* session data */ - protected $data = array(); + protected $data = []; /* session cookie name */ protected $cname = 'hm_session'; @@ -356,7 +356,7 @@ private function prep_cookie_params($request, $name, $path, $domain) { if (preg_match("/:\d+$/", $domain, $matches)) { $domain = str_replace($matches[0], '', $domain); } - return array($path, $domain, $html_only); + return [$path, $domain, $html_only]; } /** @@ -410,23 +410,23 @@ public function setup_session() { * @return string */ private function get_session_class() { - $custom_session_class = $this->config->get('session_class', 'Custom_Session'); - if ($this->session_type == 'DB') { - $session_class = 'Hm_DB_Session'; + switch ($this->session_type) { + case 'DB': + $session_class = 'Hm_DB_Session'; + break; + case 'MEM': + $session_class = 'Hm_Memcached_Session'; + break; + case 'REDIS': + $session_class = 'Hm_Redis_Session'; + break; + case 'custom': + $session_class = $this->config->get('session_class', 'Custom_Session'); + break; } - elseif ($this->session_type == 'MEM') { - $session_class = 'Hm_Memcached_Session'; - } - elseif ($this->session_type == 'REDIS') { - $session_class = 'Hm_Redis_Session'; - } - elseif ($this->session_type == 'custom' && class_exists($custom_session_class)) { - $session_class = $custom_session_class; - } - else { - $session_class = 'Hm_PHP_Session'; - } - return $session_class; + return (isset($session_class) && class_exists($session_class)) + ? $session_class + : 'Hm_PHP_Session' } /** @@ -461,7 +461,7 @@ private function dynamic_auth() { * @return string|false */ private function standard_auth() { - if ($this->auth_type && in_array($this->auth_type, array('DB', 'LDAP', 'IMAP'), true)) { + if ($this->auth_type && in_array($this->auth_type, ['DB', 'LDAP', 'IMAP'], true)) { return sprintf('Hm_Auth_%s', $this->auth_type); } return false; diff --git a/lib/session_db.php b/lib/session_db.php index 070c17a476..8730aabb51 100644 --- a/lib/session_db.php +++ b/lib/session_db.php @@ -49,7 +49,7 @@ public function start($request) { * @return void */ public function start_new($request) { - $this->session_key = Hm_Crypt::unique_id(); + $this->session_key = Hm_Crypt::unique_id(); $this->secure_cookie($request, $this->cname, $this->session_key); if ($this->insert_session_row()) { Hm_Debug::add('LOGGED IN'); @@ -80,7 +80,7 @@ public function start_existing($key) { * @return mixed array results or false on failure */ public function get_session_data($key) { - $results = Hm_DB::execute($this->dbh, 'select data from hm_user_session where hm_id=?', array($key)); + $results = Hm_DB::execute($this->dbh, 'select data from hm_user_session where hm_id=?', [$key]); if (is_array($results) && array_key_exists('data', $results)) { return $this->plaintext($results['data']); } @@ -123,11 +123,10 @@ public function close_early() { */ public function upsert($type) { $res = false; - $params = array(':key' => $this->session_key, ':data' => $this->ciphertext($this->data)); + $params = [':key' => $this->session_key, ':data' => $this->ciphertext($this->data)]; if ($type == 'update') { $res = Hm_DB::execute($this->dbh, 'update hm_user_session set data=:data where hm_id=:key', $params); - } - elseif ($type == 'insert') { + } elseif ($type == 'insert') { $res = Hm_DB::execute($this->dbh, 'insert into hm_user_session values(:key, :data, current_date)', $params); } if (!$res) { @@ -145,7 +144,7 @@ public function destroy($request) { if (Hm_Functions::function_exists('delete_uploaded_files')) { delete_uploaded_files($this); } - Hm_DB::execute($this->dbh, 'delete from hm_user_session where hm_id=?', array($this->session_key)); + Hm_DB::execute($this->dbh, 'delete from hm_user_session where hm_id=?', [$this->session_key]); $this->delete_cookie($request, $this->cname); $this->delete_cookie($request, 'hm_id'); $this->delete_cookie($request, 'hm_reload_folders'); @@ -163,11 +162,9 @@ public function db_start($request) { if ($this->connect()) { if ($this->loaded) { $this->start_new($request); - } - elseif (!array_key_exists($this->cname, $request->cookie)) { + } elseif (!array_key_exists($this->cname, $request->cookie)) { $this->destroy($request); - } - else { + } else { $this->start_existing($request->cookie[$this->cname]); } } diff --git a/lib/session_memcached.php b/lib/session_memcached.php index ad7929a88e..de15dd6986 100644 --- a/lib/session_memcached.php +++ b/lib/session_memcached.php @@ -26,7 +26,7 @@ class Hm_Memcached_Session extends Hm_DB_Session { * @param object $request request details * @return void */ - public function start($request, $existing_session=False) { + public function start($request, $existing_session = false) { $this->db_start($request); } @@ -104,5 +104,4 @@ public function connect() { public function get_session_data($key) { return $this->plaintext($this->conn->get($key)); } - } diff --git a/lib/session_php.php b/lib/session_php.php index 07f5f1f5bf..afdc9d1af2 100644 --- a/lib/session_php.php +++ b/lib/session_php.php @@ -27,7 +27,7 @@ public function auth($user, $pass) { } /** - * Save auth detail if i'ts needed (mech specific) + * Save auth detail if it's needed (mech specific) * @return void */ public function save_auth_detail() { @@ -71,8 +71,7 @@ abstract class Hm_PHP_Session_Data extends Hm_Session { protected function validate_session_data($request) { if ($this->existing && count($this->data) == 0) { $this->destroy($request); - } - else { + } else { Hm_Debug::add('LOGGED IN'); $this->active = true; } @@ -87,8 +86,7 @@ protected function start_session_data($request) { $data = $this->plaintext($_SESSION['data']); if (is_array($data)) { $this->data = $data; - } - elseif (!$this->loaded) { + } elseif (!$this->loaded) { $this->destroy($request); Hm_Debug::add('Mismatched session level encryption key'); } @@ -102,11 +100,10 @@ protected function start_session_data($request) { * @param bool $user if true, only search the user_data section of the session * @return mixed the value if found, otherwise $default */ - public function get($name, $default=false, $user=false) { + public function get($name, $default = false, $user = false) { if ($user) { return array_key_exists('user_data', $this->data) && array_key_exists($name, $this->data['user_data']) ? $this->data['user_data'][$name] : $default; - } - else { + } else { return array_key_exists($name, $this->data) ? $this->data[$name] : $default; } } @@ -118,11 +115,10 @@ public function get($name, $default=false, $user=false) { * @param bool $user if true, save in the user_data section of the session * @return void */ - public function set($name, $value, $user=false) { + public function set($name, $value, $user = false) { if ($user) { $this->data['user_data'][$name] = $value; - } - else { + } else { $this->data[$name] = $value; } } @@ -194,13 +190,12 @@ protected function authed($request, $fingerprint) { * @param string $pass password * @return bool */ - public function check($request, $user=false, $pass=false, $fingerprint=true) { + public function check($request, $user = false, $pass = false, $fingerprint = true) { if ($user !== false && $pass !== false) { if ($this->auth($user, $pass)) { $this->authed($request, $fingerprint); } - } - elseif (array_key_exists($this->cname, $request->cookie)) { + } elseif (array_key_exists($this->cname, $request->cookie)) { $this->get_key($request); $this->existing = true; $this->start($request); @@ -235,8 +230,7 @@ public function set_session_params($request) { $path = false; if ($request->tls) { $secure = true; - } - else { + } else { $secure = false; } if (isset($request->path)) { @@ -247,8 +241,7 @@ public function set_session_params($request) { $host = parse_url($request->server['HTTP_HOST'], PHP_URL_HOST); if (trim((string) $host)) { $domain = $host; - } - else { + } else { $domain = $request->server['HTTP_HOST']; } } diff --git a/lib/webdav_formats.php b/lib/webdav_formats.php index ee5cb7aed1..3b0cdcc788 100644 --- a/lib/webdav_formats.php +++ b/lib/webdav_formats.php @@ -29,7 +29,7 @@ protected function split_value($line, $delim, $limit) { * @return string */ private function standard_eol($str) { - return rtrim(str_replace(array( "\r\n", "\n\r", "\r"), "\n", $str)); + return rtrim(str_replace([ "\r\n", "\n\r", "\r"], "\n", $str)); } /** @@ -47,10 +47,10 @@ private function unfold($str) { * @param string $type property type * @return array */ - private function process_value($value, $type=false) { - $res = array(); + private function process_value($value, $type = false) { + $res = []; foreach ($this->split_value($value, ',', -1) as $val) { - $res[] = str_replace(array('\n', '\,'), array("\n", ','), $val); + $res[] = str_replace(['\n', '\,'], ["\n", ','], $val); } return $res; } @@ -96,10 +96,10 @@ private function invalid_param($param) { */ private function parse_prop($prop) { $vals = $this->split_value($prop, ';', -1); - $res = array( + $res = [ 'prop' => $vals[0], - 'params' => array() - ); + 'params' => [] + ]; if (count($vals) > 1) { $res['params'] = $this->parse_prop_params($vals); } @@ -112,7 +112,7 @@ private function parse_prop($prop) { * @return array */ private function parse_prop_params($vals) { - $res = array(); + $res = []; array_shift($vals); foreach ($vals as $val) { $pair = $this->split_value($val, '=', 2); @@ -142,13 +142,13 @@ class Hm_Card_Parse { protected $raw_card = ''; /* placeholder for parsed data */ - protected $data = array(); + protected $data = []; /* list of valid parameters for the file type */ - protected $parameters = array(); + protected $parameters = []; /* list of valid properties for the file type */ - protected $properties = array(); + protected $properties = []; /** * init @@ -162,7 +162,7 @@ public function __construct() { * @return boolean */ public function import($str) { - $this->data = array(); + $this->data = []; $this->raw_card = $str; $lines = explode("\n", $this->unfold($this->standard_eol($str))); if ($this->is_valid($lines)) { @@ -196,18 +196,16 @@ public function raw_data() { * Format as vcard */ public function build_card() { - $new_card = array(); + $new_card = []; foreach ($this->data as $name => $val) { if (method_exists($this, 'format_vcard_'.$name)) { $res = $this->{'format_vcard_'.$name}(); - } - else { + } else { $res = $this->format_vcard_generic($name); } if (is_array($res) && $res) { $new_card = array_merge($new_card, $res); - } - elseif ($res) { + } elseif ($res) { $new_card[] = $res; } } @@ -225,7 +223,7 @@ public function parsed_data() { /** * Get the value for a field */ - public function fld_val($name, $type=false, $default=false, $all=false) { + public function fld_val($name, $type = false, $default = false, $all = false) { if (!array_key_exists($name, $this->data)) { return $default; } @@ -243,8 +241,7 @@ public function fld_val($name, $type=false, $default=false, $all=false) { } if (array_key_exists('formatted', $fld[0])) { return $fld[0]['formatted']['values']; - } - else { + } else { return $fld[0]['values']; } } @@ -261,8 +258,7 @@ private function is_type($type, $vals) { } if (is_array($vals['type']) && in_array($type, $vals['type'])) { return true; - } - elseif (strtolower($type) == strtolower($vals['type'])) { + } elseif (strtolower($type) == strtolower($vals['type'])) { return true; } return false; @@ -299,9 +295,8 @@ private function parse($lines) { $data['id'] = $id; if (array_key_exists(strtolower($prop['prop']), $this->data)) { $this->data[strtolower($prop['prop'])][] = $data; - } - else { - $this->data[strtolower($prop['prop'])] = array($data); + } else { + $this->data[strtolower($prop['prop'])] = [$data]; } } $this->data['raw'] = $this->raw_card; @@ -358,17 +353,17 @@ private function parse_values() { * @return array */ protected function format_vcard_generic($name) { - $res = array(); - if (in_array($name, array('raw'), true)) { + $res = []; + if (in_array($name, ['raw'], true)) { return; } - $vals = $this->fld_val($name, false, array(), true); + $vals = $this->fld_val($name, false, [], true); if (count($vals) == 0) { $res; } foreach ($vals as $val) { $name = substr($name, 0, 2) == 'x-' ? $name : strtoupper($name); - $params = array_merge(array($name), $this->build_vcard_params($val)); + $params = array_merge([$name], $this->build_vcard_params($val)); $res[] = sprintf("%s:%s", implode(';', $params), $val['values']); } return $res; @@ -380,7 +375,7 @@ protected function format_vcard_generic($name) { * @return array */ protected function build_vcard_params($fld_val) { - $props = array(); + $props = []; foreach ($this->parameters as $param) { if (array_key_exists(strtolower($param), $fld_val)) { $props[] = sprintf('%s=%s', strtoupper($param), @@ -397,7 +392,7 @@ protected function build_vcard_params($fld_val) { */ protected function combine($val) { if (is_array($val)) { - return implode(',', array_map(array($this, 'vcard_format'), $val)); + return implode(',', array_map([$this, 'vcard_format'], $val)); } return $this->vcard_format($val); } @@ -409,7 +404,7 @@ protected function combine($val) { * @return string */ protected function vcard_format($val) { - return str_replace(array(',', "\n"), array('\,', '\n'), $val); + return str_replace([',', "\n"], ['\,', '\n'], $val); } } @@ -419,13 +414,13 @@ protected function vcard_format($val) { class Hm_VCard extends Hm_Card_Parse { protected $format = 'vCard'; protected $raw_card = ''; - protected $data = array(); - protected $parameters = array( + protected $data = []; + protected $parameters = [ 'TYPE', 'PREF', 'LABEL', 'VALUE', 'LANGUAGE', 'MEDIATYPE', 'ALTID', 'PID', 'CALSCALE', 'SORT-AS', 'GEO', 'TZ' - ); - protected $properties = array( + ]; + protected $properties = [ 'BEGIN', 'VERSION', 'END', 'FN', 'N', 'KIND', 'BDAY', 'ANNIVERSARY', 'GENDER', 'PRODID', 'REV', 'UID', 'SOURCE', 'XML', @@ -435,7 +430,7 @@ class Hm_VCard extends Hm_Card_Parse { 'RELATED', 'CATEGORIES', 'NOTE', 'SOUND', 'CLIENTPIDMAP', 'PHOTO', 'URL', 'KEY', 'FBURL', 'CALADRURI', 'CALURI' - ); + ]; /* CONVERT VCARD INPUT */ @@ -447,13 +442,13 @@ class Hm_VCard extends Hm_Card_Parse { protected function parse_n($vals) { foreach ($vals as $index => $name) { $flds = $this->split_value($name['values'], ';', 5); - $vals[$index]['values'] = array( + $vals[$index]['values'] = [ 'lastname' => $flds[0], 'firstname' => $flds[1], 'additional' => $flds[2], 'prefixes' => $flds[3], 'suffixes' => $flds[4] - ); + ]; } return $vals; } @@ -475,7 +470,7 @@ protected function format_addr($vals) { } $value = sprintf('%s, %s, %s, %s, %s', $street, $vals['locality'], $vals['region'], $vals['country'], $vals['postal_code']); - return array('name' => $name, 'values' => $value); + return ['name' => $name, 'values' => $value]; } /** @@ -486,7 +481,7 @@ protected function format_addr($vals) { protected function parse_adr($vals) { foreach ($vals as $index => $addr) { $flds = $this->split_value($addr['values'], ';', 7); - $vals[$index]['values'] = array( + $vals[$index]['values'] = [ 'po' => $flds[0], 'apartment' => $flds[1], 'street' => $flds[2], @@ -494,7 +489,7 @@ protected function parse_adr($vals) { 'region' => $flds[4], 'postal_code' => $flds[5], 'country' => $flds[6] - ); + ]; $vals[$index]['formatted'] = $this->format_addr($vals[$index]); } return $vals; @@ -517,10 +512,10 @@ protected function format_vcard_n() { * @return array */ protected function format_vcard_adr() { - $res = array(); - foreach ($this->fld_val('adr', array(), false, true) as $adr) { + $res = []; + foreach ($this->fld_val('adr', [], false, true) as $adr) { $parts = $adr['values']; - $params = array_merge(array('ADR'), $this->build_vcard_params($adr)); + $params = array_merge(['ADR'], $this->build_vcard_params($adr)); $res[] = sprintf('%s:%s;%s;%s;%s;%s;%s;%s', implode(';', $params), $parts['po'], $parts['apartment'], $parts['street'], $parts['locality'], $parts['region'], $parts['postal_code'], $parts['country']); @@ -535,15 +530,15 @@ protected function format_vcard_adr() { class Hm_ICal extends Hm_Card_Parse { protected $format = 'iCal'; protected $raw_card = ''; - protected $data = array(); - protected $parameters = array( + protected $data = []; + protected $parameters = [ 'ALTREP', 'CN', 'CUTYPE', 'DELEGATED-FROM', 'DELEGATED-TO', 'DIR', 'ENCODING', 'FMTTYPE', 'FBTYPE', 'LANGUAGE', 'MEMBER', 'PARTSTAT', 'RANGE', 'RELATED', 'RELTYPE', 'ROLE', 'RSVP', 'SENT-BY', 'TZID', 'VALUE' - ); - protected $properties = array( + ]; + protected $properties = [ 'BEGIN', 'VERSION', 'END', 'CALSCALE', 'METHOD', 'PRODID', 'ATTACH', 'CATEGORIES', 'CLASS', 'COMMENT', 'DESCRIPTION', 'GEO', @@ -557,7 +552,7 @@ class Hm_ICal extends Hm_Card_Parse { 'RRULE', 'ACTION', 'REPEAT', 'TRIGGER', 'CREATED', 'DTSTAMP', 'LAST-MODIFIED', 'SEQUENCE', 'REQUEST-STATUS' - ); + ]; protected function parse_due($vals) { return $this->parse_dt($vals); From 251365833d8f8c5ab6a6a578ea3c78e2d396aa30 Mon Sep 17 00:00:00 2001 From: Edwin Wood Date: Fri, 12 Apr 2024 22:45:14 -0700 Subject: [PATCH 3/5] missed semicolon --- lib/session_base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/session_base.php b/lib/session_base.php index 366b90dffb..5eebf934a4 100644 --- a/lib/session_base.php +++ b/lib/session_base.php @@ -426,7 +426,7 @@ private function get_session_class() { } return (isset($session_class) && class_exists($session_class)) ? $session_class - : 'Hm_PHP_Session' + : 'Hm_PHP_Session'; } /** From d7fd682619603cb4b72294b0ed0f1e4d5e0e766c Mon Sep 17 00:00:00 2001 From: Edwin Wood Date: Sun, 28 Apr 2024 11:06:25 -0700 Subject: [PATCH 4/5] dash --- lib/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.php b/lib/config.php index 6228d342b5..c9e8293aa6 100644 --- a/lib/config.php +++ b/lib/config.php @@ -460,7 +460,7 @@ public function reset_factory() { } /** - * File based site configuration + * File-based site configuration */ class Hm_Site_Config_File extends Hm_Config { From eb3fdc42159b7974b935e63eb357142d62d5d50a Mon Sep 17 00:00:00 2001 From: Edwin Wood Date: Mon, 29 Apr 2024 09:44:53 -0700 Subject: [PATCH 5/5] restore original logic for libsodium check, but using `else/if` statements intead of three separate `if` statements --- lib/framework.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/framework.php b/lib/framework.php index 271636649f..8623a8b2f2 100644 --- a/lib/framework.php +++ b/lib/framework.php @@ -42,13 +42,12 @@ /* check for and load the correct libsodium interface */ if (!defined('LIBSODIUM')) { - if (extension_loaded('libsodium')) { - if (function_exists('\Sodium\crypto_pwhash_str_verify') || function_exists('sodium_crypto_pwhash_str_verify')) { - define('LIBSODIUM', true); - class Hm_Sodium_Compat extends Hm_Sodium_PHP {} - } else { - define('LIBSODIUM', false); - } + if (extension_loaded('libsodium') && function_exists('\Sodium\crypto_pwhash_str_verify')) { + define('LIBSODIUM', true); + class Hm_Sodium_Compat extends Hm_Sodium_PECL {} + } elseif (extension_loaded('sodium') && function_exists('sodium_crypto_pwhash_str_verify')) { + define('LIBSODIUM', true); + class Hm_Sodium_Compat extends Hm_Sodium_PHP {} } else { define('LIBSODIUM', false); }