diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2fa900e75..5aaf47dd8 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -3,7 +3,8 @@ $config = new PhpCsFixer\Config(); return $config->setRules([ - '@PHP74Migration' => true, + '@PHP83Migration' => true, '@PSR12' => true, 'single_quote' => true, + 'nullable_type_declaration_for_default_null_value' => true, ]); diff --git a/lib/Horde.php b/lib/Horde.php index d35faad46..7519b3b51 100644 --- a/lib/Horde.php +++ b/lib/Horde.php @@ -1,4 +1,5 @@ setRaw(true)->add(array('_t' => $now, '_h' => '')); + $url->setRaw(true)->add(['_t' => $now, '_h' => '']); $url->add( '_h', Horde_Url::uriB64Encode( @@ -275,7 +282,7 @@ public static function signQueryString($queryString, $now = null) } if ($queryString instanceof Horde_Url) { - $queryString->setRaw(true)->add(array('_t' => $now, '_h' => '')); + $queryString->setRaw(true)->add(['_t' => $now, '_h' => '']); $parse_url = parse_url($queryString); $queryString->add('_h', Horde_Url::uriB64Encode(hash_hmac('sha1', $parse_url['query'] . '=', $GLOBALS['conf']['secret_key'], true))); return $queryString; @@ -331,7 +338,7 @@ public static function verifySignedQueryString($data, $now = null) * * @return string The escaped string. */ - public static function escapeJson($data, array $options = array()) + public static function escapeJson($data, array $options = []) { $json = Horde_Serialize::serialize($data, Horde_Serialize::JSON); if (empty($options['nodelimit'])) { @@ -389,7 +396,7 @@ public static function isConnectionSecure() public static function requireSecureConnection() { if (!self::isConnectionSecure()) { - throw new Horde_Exception(Horde_Core_Translation::t("The encryption features require a secure web connection.")); + throw new Horde_Exception(Horde_Core_Translation::t('The encryption features require a secure web connection.')); } } @@ -448,7 +455,7 @@ public static function getDriverConfig($backend, $type = 'sql') return (!is_null($type) && isset($conf[$type])) ? $conf[$type] - : array(); + : []; } /** @@ -469,11 +476,14 @@ public static function getDriverConfig($backend, $type = 'sql') * * @throws Horde_Exception */ - public static function assertDriverConfig($params, $driver, $fields, - $name = null, - $file = 'conf.php', - $variable = '$conf') - { + public static function assertDriverConfig( + $params, + $driver, + $fields, + $name = null, + $file = 'conf.php', + $variable = '$conf' + ) { global $registry; // Don't generate a fatal error if we fail during or before @@ -485,19 +495,25 @@ public static function assertDriverConfig($params, $driver, $fields, if (!is_array($params) || !count($params)) { throw new Horde_Exception( - sprintf(Horde_Core_Translation::t("No configuration information specified for %s."), $name) . "\n\n" . - sprintf(Horde_Core_Translation::t("The file %s should contain some %s settings."), + sprintf(Horde_Core_Translation::t('No configuration information specified for %s.'), $name) . "\n\n" . + sprintf( + Horde_Core_Translation::t('The file %s should contain some %s settings.'), $fileroot . '/config/' . $file, - sprintf("%s['%s']['params']", $variable, $driver))); + sprintf("%s['%s']['params']", $variable, $driver) + ) + ); } foreach ($fields as $field) { if (!isset($params[$field])) { throw new Horde_Exception( - sprintf(Horde_Core_Translation::t("Required \"%s\" not specified in %s configuration."), $field, $name) . "\n\n" . - sprintf(Horde_Core_Translation::t("The file %s should contain a %s setting."), + sprintf(Horde_Core_Translation::t('Required "%s" not specified in %s configuration.'), $field, $name) . "\n\n" . + sprintf( + Horde_Core_Translation::t('The file %s should contain a %s setting.'), $fileroot . '/config/' . $file, - sprintf("%s['%s']['params']['%s']", $variable, $driver, $field))); + sprintf("%s['%s']['params']['%s']", $variable, $driver, $field) + ) + ); } } } @@ -523,18 +539,17 @@ public static function assertDriverConfig($params, $driver, $fields, * * @return Horde_Url The URL with the session id appended (if needed). */ - public static function url($uri, $full = false, $opts = array()) + public static function url($uri, $full = false, $opts = []) { if (is_array($opts)) { - $append_session = isset($opts['append_session']) - ? $opts['append_session'] - : 0; + $append_session = $opts['append_session'] + ?? 0; if (!empty($opts['force_ssl'])) { $full = true; } } else { $append_session = $opts; - $opts = array(); + $opts = []; } $puri = parse_url($uri); @@ -564,28 +579,27 @@ public static function url($uri, $full = false, $opts = array()) !preg_match($schemeRegexp, $webroot)) { /* Store connection parameters in local variables. */ $server_name = $GLOBALS['conf']['server']['name']; - $server_port = isset($GLOBALS['conf']['server']['port']) - ? $GLOBALS['conf']['server']['port'] - : ''; + $server_port = $GLOBALS['conf']['server']['port'] + ?? ''; $protocol = 'http'; switch ($GLOBALS['conf']['use_ssl']) { - case self::SSL_ALWAYS: - $protocol = 'https'; - break; - - case self::SSL_AUTO: - if ($GLOBALS['browser']->usingSSLConnection()) { + case self::SSL_ALWAYS: $protocol = 'https'; - } - break; + break; - case self::SSL_ONLY_LOGIN: - if (!empty($opts['force_ssl'])) { - $protocol = 'https'; - $server_port = ''; - } - break; + case self::SSL_AUTO: + if ($GLOBALS['browser']->usingSSLConnection()) { + $protocol = 'https'; + } + break; + + case self::SSL_ONLY_LOGIN: + if (!empty($opts['force_ssl'])) { + $protocol = 'https'; + $server_port = ''; + } + break; } /* If using a non-standard port, add to the URL. */ @@ -621,7 +635,7 @@ public static function url($uri, $full = false, $opts = array()) $url = $webroot . '/' . $puri['path']; } } else { - $url .= '/' . ($webroot ? $webroot . '/' : '') . (isset($puri['path']) ? $puri['path'] : ''); + $url .= '/' . ($webroot ? $webroot . '/' : '') . ($puri['path'] ?? ''); } if (isset($puri['query'])) { @@ -687,11 +701,17 @@ public static function externalUrl($url, $tag = false) * * @return string The full tag. */ - public static function link($url = '', $title = '', $class = '', - $target = '', $onclick = '', $title2 = '', - $accesskey = '', $attributes = array(), - $escape = true) - { + public static function link( + $url = '', + $title = '', + $class = '', + $target = '', + $onclick = '', + $title2 = '', + $accesskey = '', + $attributes = [], + $escape = true + ) { if (!($url instanceof Horde_Url)) { $url = new Horde_Url($url); } @@ -714,8 +734,10 @@ public static function link($url = '', $title = '', $class = '', if (!empty($title)) { if ($escape) { $title = str_replace( - array("\r", "\n"), '', - htmlspecialchars(nl2br(htmlspecialchars($title)))); + ["\r", "\n"], + '', + htmlspecialchars(nl2br(htmlspecialchars($title))) + ); /* Remove double encoded entities. */ $title = preg_replace('/&([a-z]+|(#\d+));/i', '&\\1;', $title); } @@ -743,10 +765,15 @@ public static function link($url = '', $title = '', $class = '', * @return string The full tag. */ public static function linkTooltip( - $url, $status = '', $class = '', $target = '', $onclick = '', - $title = '', $accesskey = '', $attributes = array() - ) - { + $url, + $status = '', + $class = '', + $target = '', + $onclick = '', + $title = '', + $accesskey = '', + $attributes = [] + ) { if (strlen($title)) { $attributes['nicetitle'] = Horde_Serialize::serialize( preg_split( @@ -790,11 +817,11 @@ public static function linkTooltip( public static function widget($params) { $params = array_merge( - array( + [ 'class' => '', 'target' => '', 'onclick' => '', - 'nocheck' => false), + 'nocheck' => false], $params ); @@ -826,17 +853,19 @@ public static function widget($params) * * @return Horde_Url The requested URL. */ - public static function selfUrl($script_params = false, $nocache = true, - $full = false, $force_ssl = false) - { + public static function selfUrl( + $script_params = false, + $nocache = true, + $full = false, + $force_ssl = false + ) { if (!strncmp(PHP_SAPI, 'cgi', 3)) { // When using CGI PHP, SCRIPT_NAME may contain the path to // the PHP binary instead of the script being run; use // PHP_SELF instead. $url = $_SERVER['PHP_SELF']; } else { - $url = isset($_SERVER['SCRIPT_NAME']) ? - $_SERVER['SCRIPT_NAME'] : + $url = $_SERVER['SCRIPT_NAME'] ?? $_SERVER['PHP_SELF']; } if (isset($_SERVER['REQUEST_URI'])) { @@ -857,7 +886,7 @@ public static function selfUrl($script_params = false, $nocache = true, } } - $url = self::url($url, $full, array('force_ssl' => $force_ssl)); + $url = self::url($url, $full, ['force_ssl' => $force_ssl]); return ($nocache && $GLOBALS['browser']->hasQuirk('cache_same_url')) ? $url->unique() @@ -884,11 +913,10 @@ public static function selfUrl($script_params = false, $nocache = true, * * @return Horde_Url The self URL. */ - public static function selfUrlParams(array $opts = array()) + public static function selfUrlParams(array $opts = []) { - $vars = isset($opts['vars']) - ? $opts['vars'] - : $GLOBALS['injector']->createInstance('Horde_Variables'); + $vars = $opts['vars'] + ?? $GLOBALS['injector']->createInstance('Horde_Variables'); $url = self::selfUrl( false, @@ -950,10 +978,13 @@ public static function getTempDir() * @return string Returns the full path-name to the temporary file or * false if a temporary file could not be created. */ - public static function getTempFile($prefix = 'Horde', $delete = true, - $dir = '', $secure = false, - $session_remove = false) - { + public static function getTempFile( + $prefix = 'Horde', + $delete = true, + $dir = '', + $secure = false, + $session_remove = false + ) { if (empty($dir) || !is_dir($dir)) { $dir = self::getTempDir(); } @@ -977,15 +1008,15 @@ public static function getTempFile($prefix = 'Horde', $delete = true, public static function webServerID() { switch (PHP_SAPI) { - case 'apache': - return 'apache1'; + case 'apache': + return 'apache1'; - case 'apache2filter': - case 'apache2handler': - return 'apache2'; + case 'apache2filter': + case 'apache2handler': + return 'apache2'; - default: - return PHP_SAPI; + default: + return PHP_SAPI; } } @@ -1001,9 +1032,10 @@ public static function webServerID() * string if no key can be found. */ public static function getAccessKey( - $label, $nocheck = false, $shutdown = false - ) - { + $label, + $nocheck = false, + $shutdown = false + ) { /* Shutdown call for translators? */ if ($shutdown) { if (!count(self::$_labels)) { @@ -1014,7 +1046,7 @@ public static function getAccessKey( sort($labels); $used = array_keys(self::$_used); sort($used); - $remaining = str_replace($used, array(), 'abcdefghijklmnopqrstuvwxyz'); + $remaining = str_replace($used, [], 'abcdefghijklmnopqrstuvwxyz'); self::log('Access key information for ' . $script); self::log('Used labels: ' . implode(',', $labels)); self::log('Used keys: ' . implode('', $used)); @@ -1109,13 +1141,15 @@ public static function highlightAccessKey($label, $accessKey) * @return string The title, and if appropriate, the accesskey attributes * for the element. */ - public static function getAccessKeyAndTitle($label, $nocheck = false, - $return_array = false) - { + public static function getAccessKeyAndTitle( + $label, + $nocheck = false, + $return_array = false + ) { $ak = self::getAccessKey($label, $nocheck); - $attributes = array('title' => self::stripAccessKey($label)); + $attributes = ['title' => self::stripAccessKey($label)]; if (!empty($ak)) { - $attributes['title'] .= sprintf(Horde_Core_Translation::t(" (Accesskey %s)"), strtoupper($ak)); + $attributes['title'] .= sprintf(Horde_Core_Translation::t(' (Accesskey %s)'), strtoupper($ak)); $attributes['accesskey'] = $ak; } @@ -1148,10 +1182,12 @@ public static function label($for, $label, $ak = null) } $label = self::highlightAccessKey($label, $ak); - return sprintf('', - $for, - !empty($ak) ? ' accesskey="' . $ak . '"' : '', - $label); + return sprintf( + '', + $for, + !empty($ak) ? ' accesskey="' . $ak . '"' : '', + $label + ); } /** @@ -1186,7 +1222,7 @@ public static function wrapInlineScript($script) * * @return Horde_Url The URL to the cache page. */ - public static function getCacheUrl($type, $params = array()) + public static function getCacheUrl($type, $params = []) { $url = $GLOBALS['registry'] ->getserviceLink('cache', 'horde') @@ -1195,7 +1231,7 @@ public static function getCacheUrl($type, $params = array()) $url .= '/' . $key . '=' . rawurlencode(strval($val)); } - return self::url($url, true, array('append_session' => -1)); + return self::url($url, true, ['append_session' => -1]); } /** @@ -1219,11 +1255,11 @@ public static function getCacheUrl($type, $params = array()) * * @return string The javascript needed to call the popup code. */ - public static function popupJs($url, $options = array()) + public static function popupJs($url, $options = []) { $GLOBALS['page_output']->addScriptPackage('Horde_Core_Script_Package_Popup'); - $params = new stdClass; + $params = new stdClass(); if (!$url instanceof Horde_Url) { $url = new Horde_Url($url); @@ -1232,7 +1268,7 @@ public static function popupJs($url, $options = array()) if (!empty($url->parameters)) { if (!isset($options['params'])) { - $options['params'] = array(); + $options['params'] = []; } foreach (array_merge($url->parameters, $options['params']) as $key => $val) { $options['params'][$key] = addcslashes($val, '"'); @@ -1242,13 +1278,13 @@ public static function popupJs($url, $options = array()) if (!empty($options['menu'])) { $params->menu = 1; } - foreach (array('height', 'onload', 'params', 'width') as $key) { + foreach (['height', 'onload', 'params', 'width'] as $key) { if (!empty($options[$key])) { $params->$key = $options[$key]; } } - return 'void(HordePopup.popup(' . self::escapeJson($params, array('nodelimit' => true, 'urlencode' => !empty($options['urlencode']))) . '));'; + return 'void(HordePopup.popup(' . self::escapeJson($params, ['nodelimit' => true, 'urlencode' => !empty($options['urlencode'])]) . '));'; } /** @@ -1307,13 +1343,13 @@ public static function sidebar($app = null) } $menu = new Horde_Menu(); - $registry->callAppMethod($app, 'menu', array( - 'args' => array($menu) - )); + $registry->callAppMethod($app, 'menu', [ + 'args' => [$menu], + ]); $sidebar = $menu->render(); - $registry->callAppMethod($app, 'sidebar', array( - 'args' => array($sidebar) - )); + $registry->callAppMethod($app, 'sidebar', [ + 'args' => [$sidebar], + ]); return $sidebar; } @@ -1331,8 +1367,9 @@ public static function permissionDeniedError($app, $perm, $error = null) { try { $GLOBALS['injector']->getInstance('Horde_Core_Hooks') - ->callHook('perms_denied', 'horde', array($app, $perm)); - } catch (Horde_Exception_HookNotSet $e) {} + ->callHook('perms_denied', 'horde', [$app, $perm]); + } catch (Horde_Exception_HookNotSet $e) { + } if (!is_null($error)) { $GLOBALS['notification']->push($error, 'horde.warning'); @@ -1345,7 +1382,7 @@ public static function permissionDeniedError($app, $perm, $error = null) public static function __callStatic($name, $arguments) { return call_user_func_array( - array('Horde_Deprecated', $name), + ['Horde_Deprecated', $name], $arguments ); } diff --git a/lib/Horde/Config.php b/lib/Horde/Config.php index 2d87f1d69..c3ad49bcd 100644 --- a/lib/Horde/Config.php +++ b/lib/Horde/Config.php @@ -1,4 +1,5 @@ getInstance('Horde_Core_Factory_HttpClient') - ->create(array( + ->create([ 'request.timeout' => 60, - 'request.userAgent' => 'Horde ' . $GLOBALS['registry']->getVersion('horde', true) - )) + 'request.userAgent' => 'Horde ' . $GLOBALS['registry']->getVersion('horde', true), + ]) ->get($this->_versionUrl); if ($response->code != 200) { throw new Horde_Exception('Unexpected response from server.'); @@ -138,15 +139,15 @@ public function checkVersions() throw new Horde_Exception('Unexpected response from server.'); } - $versions = array(); + $versions = []; foreach ($result as $package) { uksort($package['versions'], 'version_compare'); $version = end($package['versions']); - $versions[str_replace('pear-horde/', '', $package['name'])] = array( + $versions[str_replace('pear-horde/', '', $package['name'])] = [ 'version' => $version['version'], - 'url' => 'https://pear.horde.org/' - ); + 'url' => 'https://pear.horde.org/', + ]; } return $versions; @@ -212,7 +213,7 @@ public function readXMLConfig($custom_conf = null) } /* Parse the config file. */ - $this->_xmlConfigTree = array(); + $this->_xmlConfigTree = []; $root = $dom->documentElement; if ($root->hasChildNodes()) { $this->_parseLevel($this->_xmlConfigTree, $root->childNodes, ''); @@ -224,7 +225,7 @@ public function readXMLConfig($custom_conf = null) $dom->load($additional); $root = $dom->documentElement; if ($root->hasChildNodes()) { - $tree = array(); + $tree = []; $this->_parseLevel($tree, $root->childNodes, ''); $this->_xmlConfigTree = array_replace_recursive($this->_xmlConfigTree, $tree); } @@ -305,9 +306,9 @@ public function writePHPConfig($formvars, &$php = null) $configFile = $this->configFile(); if (file_exists($configFile)) { if (@copy($configFile, $path . '/conf.bak.php')) { - $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("Successfully saved the backup configuration file %s."), Horde_Util::realPath($path . '/conf.bak.php')), 'horde.success'); + $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t('Successfully saved the backup configuration file %s.'), Horde_Util::realPath($path . '/conf.bak.php')), 'horde.success'); } else { - $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("Could not save the backup configuration file %s."), Horde_Util::realPath($path . '/conf.bak.php')), 'horde.warning'); + $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t('Could not save the backup configuration file %s.'), Horde_Util::realPath($path . '/conf.bak.php')), 'horde.warning'); } } if ($fp = @fopen($configFile, 'w')) { @@ -315,7 +316,7 @@ public function writePHPConfig($formvars, &$php = null) fwrite($fp, $php); fclose($fp); $GLOBALS['registry']->rebuild(); - $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("Successfully wrote %s"), Horde_Util::realPath($configFile)), 'horde.success'); + $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t('Successfully wrote %s'), Horde_Util::realPath($configFile)), 'horde.success'); return true; } @@ -390,7 +391,7 @@ protected function _generatePHPConfig($section, $prefix, $formvars) } elseif (isset($configitem['switch'])) { $val = $formvars->getExists($configname, $wasset); if (!$wasset) { - $val = isset($configitem['default']) ? $configitem['default'] : null; + $val = $configitem['default'] ?? null; } if (isset($configitem['switch'][$val])) { $value = $val; @@ -405,74 +406,74 @@ protected function _generatePHPConfig($section, $prefix, $formvars) ((array_key_exists('is_default', $configitem) && $configitem['is_default']) || !array_key_exists('is_default', $configitem))) { - $val = isset($configitem['default']) ? $configitem['default'] : null; + $val = $configitem['default'] ?? null; } $type = $configitem['_type']; switch ($type) { - case 'multienum': - if (is_array($val)) { - $encvals = array(); - foreach ($val as $v) { - $encvals[] = $this->_quote($v); - } - $arrayval = "'" . implode('\', \'', $encvals) . "'"; - if ($arrayval == "''") { + case 'multienum': + if (is_array($val)) { + $encvals = []; + foreach ($val as $v) { + $encvals[] = $this->_quote($v); + } + $arrayval = "'" . implode('\', \'', $encvals) . "'"; + if ($arrayval == "''") { + $arrayval = ''; + } + } else { $arrayval = ''; } - } else { - $arrayval = ''; - } - $value = 'array(' . $arrayval . ')'; - break; - - case 'boolean': - if (is_bool($val)) { - $value = $val ? 'true' : 'false'; - } else { - $value = ($val == 'on') ? 'true' : 'false'; - } - break; + $value = 'array(' . $arrayval . ')'; + break; - case 'stringlist': - $values = explode(',', $val); - if (!is_array($values)) { - $value = "array('" . $this->_quote(trim($values)) . "')"; - } else { - $encvals = array(); - foreach ($values as $v) { - $encvals[] = $this->_quote(trim($v)); + case 'boolean': + if (is_bool($val)) { + $value = $val ? 'true' : 'false'; + } else { + $value = ($val == 'on') ? 'true' : 'false'; } - $arrayval = "'" . implode('\', \'', $encvals) . "'"; - if ($arrayval == "''") { - $arrayval = ''; + break; + + case 'stringlist': + $values = explode(',', $val); + if (!is_array($values)) { + $value = "array('" . $this->_quote(trim($values)) . "')"; + } else { + $encvals = []; + foreach ($values as $v) { + $encvals[] = $this->_quote(trim($v)); + } + $arrayval = "'" . implode('\', \'', $encvals) . "'"; + if ($arrayval == "''") { + $arrayval = ''; + } + $value = 'array(' . $arrayval . ')'; } - $value = 'array(' . $arrayval . ')'; - } - break; - - case 'int': - if (strlen($val)) { - $value = (int)$val; - } - break; - - case 'octal': - $value = sprintf('0%o', octdec($val)); - break; + break; - case 'header': - case 'description': - break; - - default: - if ($val != '') { - $value = $val; - if ($quote && $value != 'true' && $value != 'false') { - $value = "'" . $this->_quote($value) . "'"; + case 'int': + if (strlen($val)) { + $value = (int)$val; } - } - break; + break; + + case 'octal': + $value = sprintf('0%o', octdec($val)); + break; + + case 'header': + case 'description': + break; + + default: + if ($val != '') { + $value = $val; + if ($quote && $value != 'true' && $value != 'false') { + $value = "'" . $this->_quote($value) . "'"; + } + } + break; } } else { $this->_generatePHPConfig($configitem, $prefixedname, $formvars); @@ -514,244 +515,244 @@ protected function _parseLevel(&$conf, $children, $ctx) : $ctx . '|' . $name; switch ($node->tagName) { - case 'configdescription': - if (empty($name)) { - $name = uniqid(mt_rand()); - } + case 'configdescription': + if (empty($name)) { + $name = uniqid(mt_rand()); + } - $conf[$name] = array( - '_type' => 'description', - 'desc' => $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($this->_default($curctx, $this->_getNodeOnlyText($node)), 'linkurls') - ); - break; + $conf[$name] = [ + '_type' => 'description', + 'desc' => $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($this->_default($curctx, $this->_getNodeOnlyText($node)), 'linkurls'), + ]; + break; - case 'configheader': - if (empty($name)) { - $name = uniqid(mt_rand()); - } + case 'configheader': + if (empty($name)) { + $name = uniqid(mt_rand()); + } - $conf[$name] = array( - '_type' => 'header', - 'desc' => $this->_default($curctx, $this->_getNodeOnlyText($node)) - ); - break; + $conf[$name] = [ + '_type' => 'header', + 'desc' => $this->_default($curctx, $this->_getNodeOnlyText($node)), + ]; + break; - case 'configswitch': - $values = $this->_getSwitchValues($node, $ctx); - list($default, $isDefault) = $quote - ? $this->__default($curctx, $this->_getNodeOnlyText($node)) - : $this->__defaultRaw($curctx, $this->_getNodeOnlyText($node)); + case 'configswitch': + $values = $this->_getSwitchValues($node, $ctx); + [$default, $isDefault] = $quote + ? $this->__default($curctx, $this->_getNodeOnlyText($node)) + : $this->__defaultRaw($curctx, $this->_getNodeOnlyText($node)); - if ($default === '') { - $default = key($values); - } + if ($default === '') { + $default = key($values); + } - if (is_bool($default)) { - $default = $default ? 'true' : 'false'; - } + if (is_bool($default)) { + $default = $default ? 'true' : 'false'; + } - $conf[$name] = array( - 'desc' => $desc, - 'switch' => $values, - 'default' => $default, - 'is_default' => $isDefault, - 'quote' => $quote - ); - break; + $conf[$name] = [ + 'desc' => $desc, + 'switch' => $values, + 'default' => $default, + 'is_default' => $isDefault, + 'quote' => $quote, + ]; + break; - case 'configenum': - $values = $this->_getEnumValues($node); - list($default, $isDefault) = $quote - ? $this->__default($curctx, $this->_getNodeOnlyText($node)) - : $this->__defaultRaw($curctx, $this->_getNodeOnlyText($node)); + case 'configenum': + $values = $this->_getEnumValues($node); + [$default, $isDefault] = $quote + ? $this->__default($curctx, $this->_getNodeOnlyText($node)) + : $this->__defaultRaw($curctx, $this->_getNodeOnlyText($node)); - if ($default === '') { - $default = key($values); - } + if ($default === '') { + $default = key($values); + } - if (is_bool($default)) { - $default = $default ? 'true' : 'false'; - } + if (is_bool($default)) { + $default = $default ? 'true' : 'false'; + } - $conf[$name] = array( - '_type' => 'enum', - 'required' => $required, - 'quote' => $quote, - 'values' => $values, - 'desc' => $desc, - 'default' => $default, - 'is_default' => $isDefault - ); - break; + $conf[$name] = [ + '_type' => 'enum', + 'required' => $required, + 'quote' => $quote, + 'values' => $values, + 'desc' => $desc, + 'default' => $default, + 'is_default' => $isDefault, + ]; + break; - case 'configlist': - list($default, $isDefault) = $this->__default($curctx, null); + case 'configlist': + [$default, $isDefault] = $this->__default($curctx, null); - if (is_null($default)) { - $default = $this->_getNodeOnlyText($node); - } elseif (is_array($default)) { - $default = implode(', ', $default); - } + if (is_null($default)) { + $default = $this->_getNodeOnlyText($node); + } elseif (is_array($default)) { + $default = implode(', ', $default); + } - $conf[$name] = array( - '_type' => 'stringlist', - 'required' => $required, - 'desc' => $desc, - 'default' => $default, - 'is_default' => $isDefault - ); - break; + $conf[$name] = [ + '_type' => 'stringlist', + 'required' => $required, + 'desc' => $desc, + 'default' => $default, + 'is_default' => $isDefault, + ]; + break; - case 'configmultienum': - $default = $this->_getNodeOnlyText($node); - if (strlen($default)) { - $default = explode(',', $default); - } else { - $default = array(); - } - list($default, $isDefault) = $this->__default($curctx, $default); - - $conf[$name] = array( - '_type' => 'multienum', - 'required' => $required, - 'values' => $this->_getEnumValues($node), - 'desc' => $desc, - 'default' => Horde_Array::valuesToKeys($default), - 'is_default' => $isDefault - ); - break; + case 'configmultienum': + $default = $this->_getNodeOnlyText($node); + if (strlen($default)) { + $default = explode(',', $default); + } else { + $default = []; + } + [$default, $isDefault] = $this->__default($curctx, $default); + + $conf[$name] = [ + '_type' => 'multienum', + 'required' => $required, + 'values' => $this->_getEnumValues($node), + 'desc' => $desc, + 'default' => Horde_Array::valuesToKeys($default), + 'is_default' => $isDefault, + ]; + break; - case 'configpassword': - $conf[$name] = array( - '_type' => 'password', - 'required' => $required, - 'desc' => $desc, - 'default' => $this->_default($curctx, $this->_getNodeOnlyText($node)), - 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)) - ); - break; + case 'configpassword': + $conf[$name] = [ + '_type' => 'password', + 'required' => $required, + 'desc' => $desc, + 'default' => $this->_default($curctx, $this->_getNodeOnlyText($node)), + 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)), + ]; + break; - case 'configstring': - $conf[$name] = array( - '_type' => 'text', - 'required' => $required, - 'desc' => $desc, - 'default' => $this->_default($curctx, $this->_getNodeOnlyText($node)), - 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)) - ); - - if ($conf[$name]['default'] === false) { - $conf[$name]['default'] = 'false'; - } elseif ($conf[$name]['default'] === true) { - $conf[$name]['default'] = 'true'; - } - break; + case 'configstring': + $conf[$name] = [ + '_type' => 'text', + 'required' => $required, + 'desc' => $desc, + 'default' => $this->_default($curctx, $this->_getNodeOnlyText($node)), + 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)), + ]; + + if ($conf[$name]['default'] === false) { + $conf[$name]['default'] = 'false'; + } elseif ($conf[$name]['default'] === true) { + $conf[$name]['default'] = 'true'; + } + break; - case 'configboolean': - $default = $this->_getNodeOnlyText($node); - $default = !(empty($default) || $default === 'false'); - - $conf[$name] = array( - '_type' => 'boolean', - 'required' => $required, - 'desc' => $desc, - 'default' => $this->_default($curctx, $default), - 'is_default' => $this->_isDefault($curctx, $default) - ); - break; + case 'configboolean': + $default = $this->_getNodeOnlyText($node); + $default = !(empty($default) || $default === 'false'); + + $conf[$name] = [ + '_type' => 'boolean', + 'required' => $required, + 'desc' => $desc, + 'default' => $this->_default($curctx, $default), + 'is_default' => $this->_isDefault($curctx, $default), + ]; + break; - case 'configinteger': - $values = $this->_getEnumValues($node); - - $conf[$name] = array( - '_type' => 'int', - 'required' => $required, - 'values' => $values, - 'desc' => $desc, - 'default' => $this->_default($curctx, $this->_getNodeOnlyText($node)), - 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)) - ); - - if ($node->getAttribute('octal') == 'true' && - $conf[$name]['default'] != '') { - $conf[$name]['_type'] = 'octal'; - $conf[$name]['default'] = sprintf('0%o', $this->_default($curctx, octdec($this->_getNodeOnlyText($node)))); - } - break; + case 'configinteger': + $values = $this->_getEnumValues($node); + + $conf[$name] = [ + '_type' => 'int', + 'required' => $required, + 'values' => $values, + 'desc' => $desc, + 'default' => $this->_default($curctx, $this->_getNodeOnlyText($node)), + 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)), + ]; + + if ($node->getAttribute('octal') == 'true' && + $conf[$name]['default'] != '') { + $conf[$name]['_type'] = 'octal'; + $conf[$name]['default'] = sprintf('0%o', $this->_default($curctx, octdec($this->_getNodeOnlyText($node)))); + } + break; - case 'configldap': - $conf[$node->getAttribute('switchname')] = $this->_configLDAP($ctx, $node); - break; + case 'configldap': + $conf[$node->getAttribute('switchname')] = $this->_configLDAP($ctx, $node); + break; - case 'configldapuser': - $conf = array_merge($conf, $this->_configLDAPUser($ctx, $node)); - break; + case 'configldapuser': + $conf = array_merge($conf, $this->_configLDAPUser($ctx, $node)); + break; - case 'configphp': - $conf[$name] = array( - '_type' => 'php', - 'required' => $required, - 'quote' => false, - 'desc' => $desc, - 'default' => $this->_defaultRaw($curctx, $this->_getNodeOnlyText($node)), - 'is_default' => $this->_isDefaultRaw($curctx, $this->_getNodeOnlyText($node)) - ); - break; + case 'configphp': + $conf[$name] = [ + '_type' => 'php', + 'required' => $required, + 'quote' => false, + 'desc' => $desc, + 'default' => $this->_defaultRaw($curctx, $this->_getNodeOnlyText($node)), + 'is_default' => $this->_isDefaultRaw($curctx, $this->_getNodeOnlyText($node)), + ]; + break; - case 'configsecret': - $conf[$name] = array( - '_type' => 'text', - 'required' => true, - 'desc' => $desc, - 'default' => $this->_default($curctx, strval(new Horde_Support_Randomid())), - 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)) - ); - break; + case 'configsecret': + $conf[$name] = [ + '_type' => 'text', + 'required' => true, + 'desc' => $desc, + 'default' => $this->_default($curctx, strval(new Horde_Support_Randomid())), + 'is_default' => $this->_isDefault($curctx, $this->_getNodeOnlyText($node)), + ]; + break; - case 'configsql': - $conf[$node->getAttribute('switchname')] = $this->configSQL($ctx, $node); - break; + case 'configsql': + $conf[$node->getAttribute('switchname')] = $this->configSQL($ctx, $node); + break; - case 'confignosql': - $conf[$node->getAttribute('switchname')] = $this->configNoSQL($ctx, $node); - break; + case 'confignosql': + $conf[$node->getAttribute('switchname')] = $this->configNoSQL($ctx, $node); + break; - case 'configvfs': - $conf[$node->getAttribute('switchname')] = $this->_configVFS($ctx, $node); - break; + case 'configvfs': + $conf[$node->getAttribute('switchname')] = $this->_configVFS($ctx, $node); + break; - case 'configsection': - $conf[$name] = array(); - $cur = &$conf[$name]; - if ($node->hasChildNodes()) { - $this->_parseLevel($cur, $node->childNodes, $curctx); - } - break; + case 'configsection': + $conf[$name] = []; + $cur = &$conf[$name]; + if ($node->hasChildNodes()) { + $this->_parseLevel($cur, $node->childNodes, $curctx); + } + break; - case 'configtab': - $key = uniqid(mt_rand()); + case 'configtab': + $key = uniqid(mt_rand()); - $conf[$key] = array( - 'tab' => $name, - 'desc' => $desc - ); + $conf[$key] = [ + 'tab' => $name, + 'desc' => $desc, + ]; - if ($node->hasChildNodes()) { - $this->_parseLevel($conf, $node->childNodes, $ctx); - } - break; + if ($node->hasChildNodes()) { + $this->_parseLevel($conf, $node->childNodes, $ctx); + } + break; - case 'configplaceholder': - $conf[uniqid(mt_rand())] = 'placeholder'; - break; + case 'configplaceholder': + $conf[uniqid(mt_rand())] = 'placeholder'; + break; - default: - $conf[$name] = array(); - $cur = &$conf[$name]; - if ($node->hasChildNodes()) { - $this->_parseLevel($cur, $node->childNodes, $curctx); - } - break; + default: + $conf[$name] = []; + $cur = &$conf[$name]; + if ($node->hasChildNodes()) { + $this->_parseLevel($cur, $node->childNodes, $curctx); + } + break; } } } @@ -770,56 +771,58 @@ protected function _parseLevel(&$conf, $children, $ctx) * * @return array An associative array with the LDAP configuration tree. */ - protected function _configLDAP($ctx, $node = null, - $switchname = 'driverconfig') - { + protected function _configLDAP( + $ctx, + $node = null, + $switchname = 'driverconfig' + ) { if ($node) { $xpath = new DOMXPath($node->ownerDocument); } $host = $node ? explode(',', ($xpath->evaluate('string(configstring[@name="hostspec"])', $node) ?: '')) - : array(); + : []; $host = $this->_default($ctx . '|hostspec', $host); - $fields = array( - 'hostspec' => array( + $fields = [ + 'hostspec' => [ '_type' => 'stringlist', 'required' => true, 'desc' => 'LDAP server(s)/hostname(s)', 'default' => is_array($host) ? implode(',', $host) : $host, - ), + ], - 'port' => array( + 'port' => [ '_type' => 'int', 'required' => false, 'desc' => 'Port on which LDAP is listening, if non-standard', 'default' => $this->_default( $ctx . '|port', $node ? ($xpath->evaluate('string(configinteger[@name="port"])', $node) ?: null) : null - ) - ), + ), + ], - 'tls' => array( + 'tls' => [ '_type' => 'boolean', 'required' => false, 'desc' => 'Use TLS to connect to the server?', 'default' => $this->_default( $ctx . '|tls', $node ? ($xpath->evaluate('string(configboolean[@name="tls"])', $node) ?: false) : false - ) - ), + ), + ], - 'timeout' => array( + 'timeout' => [ '_type' => 'int', 'required' => false, 'desc' => 'Connection timeout', 'default' => $this->_default( $ctx . '|timeout', $node ? ($xpath->evaluate('string(configinteger[@name="timeout"])', $node) ?: 5) : 5 - ) - ), + ), + ], - 'version' => array( + 'version' => [ '_type' => 'int', 'required' => true, 'quote' => false, @@ -828,61 +831,62 @@ protected function _configLDAP($ctx, $node = null, $ctx . '|version', $node ? ($xpath->evaluate('normalize-space(configswitch[@name="version"]/text())', $node) ?: 3) : 3 ), - 'switch' => array( - '2' => array( + 'switch' => [ + '2' => [ 'desc' => '2 (deprecated)', - 'fields' => array() - ), - '3' => array( + 'fields' => [], + ], + '3' => [ 'desc' => '3', - 'fields' => array() - ) - ), - ), + 'fields' => [], + ], + ], + ], - 'bindas' => array( + 'bindas' => [ 'desc' => 'Bind to LDAP as which user?', 'default' => $this->_default( $ctx . '|bindas', $node ? ($xpath->evaluate('normalize-space(configswitch[@name="bindas"]/text())', $node) ?: 'admin') : 'admin' ), - 'switch' => array( - 'anon' => array( + 'switch' => [ + 'anon' => [ 'desc' => 'Bind anonymously', - 'fields' => $this->_configLDAPUser($ctx, $node) - ), - 'user' => array( + 'fields' => $this->_configLDAPUser($ctx, $node), + ], + 'user' => [ 'desc' => 'Bind as the currently logged-in user', - 'fields' => $this->_configLDAPUser($ctx, $node) - ), - 'admin' => array( + 'fields' => $this->_configLDAPUser($ctx, $node), + ], + 'admin' => [ 'desc' => 'Bind with administrative/system credentials', 'fields' => array_merge( - array( - 'binddn' => array( + [ + 'binddn' => [ '_type' => 'text', 'required' => true, 'desc' => 'DN used to bind to LDAP', 'default' => $this->_default( $ctx . '|binddn', $node ? ($xpath->evaluate('string(configsection/configstring[@name="binddn"])', $node) ?: '') : '' - ) - ), - 'bindpw' => array( + ), + ], + 'bindpw' => [ '_type' => 'text', 'required' => true, 'desc' => 'Password for bind DN', 'default' => $this->_default( $ctx . '|bindpw', - $node ? ($xpath->evaluate('string(configsection/configstring[@name="bindpw"])', $node) ?: '') : '') - ) - ), + $node ? ($xpath->evaluate('string(configsection/configstring[@name="bindpw"])', $node) ?: '') : '' + ), + ], + ], $this->_configLDAPUser($ctx, $node) ), - ), - ) - ), - ); + ], + ], + ], + ]; if (isset($node) && $node->getAttribute('excludebind')) { $excludes = explode(',', $node->getAttribute('excludebind')); @@ -892,67 +896,68 @@ protected function _configLDAP($ctx, $node = null, } if (isset($node) && $node->getAttribute('baseconfig') == 'true') { - return array( + return [ 'desc' => 'Use LDAP?', 'default' => $this->_default( $ctx . '|' . $node->getAttribute('switchname'), $node ? ($xpath->evaluate('normalize-space(text())', $node) ?: false) : false ), - 'switch' => array( - 'false' => array( + 'switch' => [ + 'false' => [ 'desc' => 'No', - 'fields' => array() - ), - 'true' => array( + 'fields' => [], + ], + 'true' => [ 'desc' => 'Yes', - 'fields' => $fields - ), - ) - ); + 'fields' => $fields, + ], + ], + ]; } - $standardFields = array( - 'basedn' => array( + $standardFields = [ + 'basedn' => [ '_type' => 'text', 'required' => true, 'desc' => 'Base DN', 'default' => $this->_default( $ctx . '|basedn', $node ? ($xpath->evaluate('string(configstring[@name="basedn"])', $node) ?: '') : '' - ) - ), - 'scope' => array( + ), + ], + 'scope' => [ '_type' => 'enum', 'required' => true, 'desc' => 'Search scope', 'default' => $this->_default( $ctx . '|scope', - $node ? ($xpath->evaluate('normalize-space(configenum[@name="scope"]/text())', $node) ?: '') : ''), - 'values' => array( + $node ? ($xpath->evaluate('normalize-space(configenum[@name="scope"]/text())', $node) ?: '') : '' + ), + 'values' => [ 'sub' => 'Subtree search', - 'one' => 'One level'), - ), - ); + 'one' => 'One level'], + ], + ]; - list($default, $isDefault) = $this->__default($ctx . '|' . (isset($node) ? $node->getAttribute('switchname') : $switchname), 'horde'); - $config = array( + [$default, $isDefault] = $this->__default($ctx . '|' . (isset($node) ? $node->getAttribute('switchname') : $switchname), 'horde'); + $config = [ 'desc' => 'Driver configuration', 'default' => $default, 'is_default' => $isDefault, - 'switch' => array( - 'horde' => array( + 'switch' => [ + 'horde' => [ 'desc' => 'Horde defaults', 'fields' => $standardFields, - ), - 'custom' => array( + ], + 'custom' => [ 'desc' => 'Custom parameters', 'fields' => $fields + $standardFields, - ) - ) - ); + ], + ], + ]; if (isset($node) && $node->hasChildNodes()) { - $cur = array(); + $cur = []; $this->_parseLevel($cur, $node->childNodes, $ctx); $config['switch']['horde']['fields'] = array_merge($config['switch']['horde']['fields'], $cur); $config['switch']['custom']['fields'] = array_merge($config['switch']['custom']['fields'], $cur); @@ -980,64 +985,66 @@ protected function _configLDAPUser($ctx, $node = null) $xpath = new DOMXPath($node->ownerDocument); } - return array( - 'user' => array( - 'basedn' => array( + return [ + 'user' => [ + 'basedn' => [ '_type' => 'text', 'required' => false, 'desc' => 'Base DN for searching the user\'s DN', 'default' => $this->_default( $ctx . '|user|basedn', $node ? ($xpath->evaluate('string(configsection/configstring[@name="basedn"])', $node) ?: '') : '' - ) - ), - 'uid' => array( + ), + ], + 'uid' => [ '_type' => 'text', 'required' => true, 'desc' => 'The username search key (set to samaccountname for AD).', 'default' => $this->_default( $ctx . '|user|uid', $node ? ($xpath->evaluate('string(configsection/configstring[@name="uid"])', $node) ?: 'uid') : 'uid' - ) - ), - 'filter_type' => array( + ), + ], + 'filter_type' => [ 'required' => false, 'desc' => 'How to specify a filter for the user lists.', 'default' => $this->_default( $ctx . '|user|filter_type', - $node ? ($xpath->evaluate('normalize-space(configsection/configswitch[@name="filter_type"]/text())', $node) ?: 'objectclass') : 'objectclass'), - 'switch' => array( - 'filter' => array( + $node ? ($xpath->evaluate('normalize-space(configsection/configswitch[@name="filter_type"]/text())', $node) ?: 'objectclass') : 'objectclass' + ), + 'switch' => [ + 'filter' => [ 'desc' => 'LDAP filter string', - 'fields' => array( - 'filter' => array( + 'fields' => [ + 'filter' => [ '_type' => 'text', 'required' => true, 'desc' => 'The LDAP filter string used to search for users.', 'default' => $this->_default( $ctx . '|user|filter', $node ? ($xpath->evaluate('string(configsection/configstring[@name="filter"])', $node) ?: '(objectClass=*)') : '(objectClass=*)' - ) - ), - ), - ), - 'objectclass' => array( + ), + ], + ], + ], + 'objectclass' => [ 'desc' => 'List of objectClasses', - 'fields' => array( - 'objectclass' => array( + 'fields' => [ + 'objectclass' => [ '_type' => 'stringlist', 'required' => true, 'desc' => 'The objectclass filter used to search for users. Can be a single objectclass or a comma-separated list.', 'default' => implode(', ', $this->_default( $ctx . '|user|objectclass', - $node ? ($xpath->evaluate('string(configsection/configlist[@name="objectclass"])', $node) ?: array('*')) : array('*'))) - ), - ), - ), - ), - ), - ), - ); + $node ? ($xpath->evaluate('string(configsection/configlist[@name="objectclass"])', $node) ?: ['*']) : ['*'] + )), + ], + ], + ], + ], + ], + ], + ]; } /** @@ -1054,76 +1061,78 @@ protected function _configLDAPUser($ctx, $node = null) * * @return array An associative array with the SQL configuration tree. */ - public function configNoSQL($ctx, $node = null, - $switchname = 'driverconfig') - { + public function configNoSQL( + $ctx, + $node = null, + $switchname = 'driverconfig' + ) { if ($node) { $xpath = new DOMXPath($node->ownerDocument); } - $custom_fields = array( + $custom_fields = [ 'required' => true, 'desc' => 'What database backend should we use?', 'default' => $this->_default( $ctx . '|phptype', $node ? $node->getAttribute('default') : '' ), - 'switch' => array( - 'false' => array( + 'switch' => [ + 'false' => [ 'desc' => '[None]', - 'fields' => array() - ), - 'mongo' => array( + 'fields' => [], + ], + 'mongo' => [ 'desc' => 'MongoDB', - 'fields' => array( - 'hostspec' => array( + 'fields' => [ + 'hostspec' => [ '_type' => 'text', 'required' => false, 'desc' => 'Server specification (format: "mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db"; see http://www.php.net/manual/en/mongoclient.construct.php for further details)', 'default' => $this->_default( $ctx . '|hostspec', $node ? ($xpath->evaluate('string(configstring[@name="hostspec"])', $node) ?: '') : '' - ) - ), - 'dbname' => array( + ), + ], + 'dbname' => [ '_type' => 'text', 'required' => false, 'desc' => 'Database name to use', 'default' => $this->_default( $ctx . '|dbname', $node ? ($xpath->evaluate('string(configstring[@name="dbname"])', $node) ?: '') : '' - ) - ) - ) - ) - ) - ); + ), + ], + ], + ], + ], + ]; if (isset($node) && $node->getAttribute('baseconfig') == 'true') { return $custom_fields; } - list($default, $isDefault) = $this->__default($ctx . '|' . (isset($node) ? $node->getAttribute('switchname') : $switchname), 'horde'); - $config = array( + [$default, $isDefault] = $this->__default($ctx . '|' . (isset($node) ? $node->getAttribute('switchname') : $switchname), 'horde'); + $config = [ 'desc' => 'NoSQL driver configuration', 'default' => $default, 'is_default' => $isDefault, - 'switch' => array( - 'horde' => array( + 'switch' => [ + 'horde' => [ 'desc' => 'Horde defaults', - 'fields' => array() - ), - 'custom' => array( + 'fields' => [], + ], + 'custom' => [ 'desc' => 'Custom parameters', - 'fields' => array( - 'phptype' => $custom_fields - ) - ) - ) - ); + 'fields' => [ + 'phptype' => $custom_fields, + ], + ], + ], + ]; if (isset($node) && $node->hasChildNodes()) { - $cur = array(); + $cur = []; $this->_parseLevel($cur, $node->childNodes, $ctx); $config['switch']['horde']['fields'] = array_merge($config['switch']['horde']['fields'], $cur); $config['switch']['custom']['fields'] = array_merge($config['switch']['custom']['fields'], $cur); @@ -1152,86 +1161,88 @@ public function configSQL($ctx, $node = null, $switchname = 'driverconfig') $xpath = new DOMXPath($node->ownerDocument); } - $hostspec = array( + $hostspec = [ '_type' => 'text', 'required' => true, 'desc' => 'Database server/host', 'default' => $this->_default( $ctx . '|hostspec', $node ? ($xpath->evaluate('string(configstring[@name="hostspec"])', $node) ?: '') : '' - ) - ); + ), + ]; - $username = array( + $username = [ '_type' => 'text', 'required' => true, 'desc' => 'Username to connect to the database as', 'default' => $this->_default( $ctx . '|username', $node ? ($xpath->evaluate('string(configstring[@name="username"])', $node) ?: '') : '' - ) - ); + ), + ]; - $password = array( + $password = [ '_type' => 'text', 'required' => false, 'desc' => 'Password to connect with', 'default' => $this->_default( $ctx . '|password', - $node ? ($xpath->evaluate('string(configstring[@name="password"])', $node) ?: '') : '' - ) - ); + $node ? ($xpath->evaluate('string(configstring[@name="password"])', $node) ?: '') : '' + ), + ]; - $database = array( + $database = [ '_type' => 'text', 'required' => true, 'desc' => 'Database name to use', 'default' => $this->_default( $ctx . '|database', $node ? ($xpath->evaluate('string(configstring[@name="database"])', $node) ?: '') : '' - ) - ); + ), + ]; - $socket = array( + $socket = [ '_type' => 'text', 'required' => false, 'desc' => 'Location of UNIX socket', 'default' => $this->_default( $ctx . '|socket', $node ? ($xpath->evaluate('string(configstring[@name="socket"])', $node) ?: '') : '' - ) - ); + ), + ]; - $port = array( + $port = [ '_type' => 'int', 'required' => false, 'desc' => 'Port the DB is running on, if non-standard', 'default' => $this->_default( $ctx . '|port', - $node ? ($xpath->evaluate('string(configinteger[@name="port"])', $node) ?: null) : null) - ); + $node ? ($xpath->evaluate('string(configinteger[@name="port"])', $node) ?: null) : null + ), + ]; - $protocol = array( + $protocol = [ 'desc' => 'How should we connect to the database?', 'default' => $this->_default( $ctx . '|protocol', - $node ? ($xpath->evaluate('normalize-space(configswitch[@name="protocol"]/text())', $node) ?: 'unix') : 'unix'), - 'switch' => array( - 'unix' => array( + $node ? ($xpath->evaluate('normalize-space(configswitch[@name="protocol"]/text())', $node) ?: 'unix') : 'unix' + ), + 'switch' => [ + 'unix' => [ 'desc' => 'UNIX Sockets', - 'fields' => array( - 'socket' => $socket - ) - ), - 'tcp' => array( + 'fields' => [ + 'socket' => $socket, + ], + ], + 'tcp' => [ 'desc' => 'TCP/IP', - 'fields' => array( + 'fields' => [ 'hostspec' => $hostspec, - 'port' => $port - ) - ) - ) - ); + 'port' => $port, + ], + ], + ], + ]; $mysql_protocol = $protocol; $mysql_protocol['switch']['tcp']['fields']['port']['default'] = @@ -1243,69 +1254,72 @@ public function configSQL($ctx, $node = null, $switchname = 'driverconfig') $pgsql_protocol = $protocol; $pgsql_protocol['switch']['unix']['fields']['port'] = $port; - $charset = array( + $charset = [ '_type' => 'text', 'required' => true, 'desc' => 'Internally used charset', 'default' => $this->_default( $ctx . '|charset', - $node ? ($xpath->evaluate('string(configstring[@name="charset"])', $node) ?: 'utf-8') : 'utf-8') - ); + $node ? ($xpath->evaluate('string(configstring[@name="charset"])', $node) ?: 'utf-8') : 'utf-8' + ), + ]; - $ssl = array( + $ssl = [ '_type' => 'boolean', 'required' => false, 'desc' => 'Use SSL to connect to the server?', 'default' => $this->_default( $ctx . '|ssl', - $node ? ($xpath->evaluate('string(configboolean[@name="ssl"])', $node) ?: false) : false), - 'switch' => array( - 'false' => array('desc' => 'No', 'fields' => array()), - 'true' => array( + $node ? ($xpath->evaluate('string(configboolean[@name="ssl"])', $node) ?: false) : false + ), + 'switch' => [ + 'false' => ['desc' => 'No', 'fields' => []], + 'true' => [ 'desc' => 'Yes', - 'fields' => array( - 'ca' => array( + 'fields' => [ + 'ca' => [ '_type' => 'text', 'required' => false, 'desc' => 'Certification Authority to use for SSL connections', 'default' => $this->_default( $ctx . '|ca', $node ? ($xpath->evaluate('string(configstring[@name="ca"])', $node) ?: '') : '' - ) - ) - ) - ) - ) - ); + ), + ], + ], + ], + ], + ]; - list($default, $isDefault) = $this->__default( + [$default, $isDefault] = $this->__default( $ctx . '|logqueries', $node ? ($xpath->evaluate('string(configboolean[@name="logqueries"])', $node) ?: false) - : false); - $logqueries = array( + : false + ); + $logqueries = [ '_type' => 'boolean', 'required' => false, 'desc' => 'Should Horde log all queries. If selected, queries will be logged at the DEBUG level to your configured logger.', 'default' => $default, 'is_default' => $isDefault, - ); + ]; - $custom_fields = array( + $custom_fields = [ 'required' => true, 'desc' => 'What database backend should we use?', 'default' => $this->_default( $ctx . '|phptype', $node ? $node->getAttribute('default') : '' ), - 'switch' => array( - 'false' => array( + 'switch' => [ + 'false' => [ 'desc' => '[None]', - 'fields' => array() - ), - 'mysql' => array( + 'fields' => [], + ], + 'mysql' => [ 'desc' => 'MySQL / PDO', - 'fields' => array( + 'fields' => [ 'username' => $username, 'password' => $password, 'protocol' => $mysql_protocol, @@ -1314,11 +1328,11 @@ public function configSQL($ctx, $node = null, $switchname = 'driverconfig') 'ssl' => $ssl, 'splitread' => $this->_configSQLSplitRead($ctx, $node, 'mysql'), 'logqueries' => $logqueries, - ) - ), - 'mysqli' => array( + ], + ], + 'mysqli' => [ 'desc' => 'MySQL (mysqli)', - 'fields' => array( + 'fields' => [ 'username' => $username, 'password' => $password, 'protocol' => $mysql_protocol, @@ -1327,72 +1341,77 @@ public function configSQL($ctx, $node = null, $switchname = 'driverconfig') 'ssl' => $ssl, 'splitread' => $this->_configSQLSplitRead($ctx, $node, 'mysqli'), 'logqueries' => $logqueries, - ) - ), - 'oci8' => array( + ], + ], + 'oci8' => [ 'desc' => 'Oracle', - 'fields' => array( + 'fields' => [ 'username' => $username, 'password' => $password, 'charset' => $charset, - 'method' => array( + 'method' => [ 'desc' => 'How should the database connection be specified', 'default' => $this->_default( $ctx . '|method', - $node ? ($xpath->evaluate('normalize-space(configswitch[@name="method"]/text())', $node) ?: 'easy') : 'easy'), - 'switch' => array( - 'tns' => array( + $node ? ($xpath->evaluate('normalize-space(configswitch[@name="method"]/text())', $node) ?: 'easy') : 'easy' + ), + 'switch' => [ + 'tns' => [ 'desc' => 'TNS', - 'fields' => array( - 'tns' => array( + 'fields' => [ + 'tns' => [ '_type' => 'text', 'required' => true, 'desc' => 'Connect name from tnsnames.ora', 'default' => $this->_default( $ctx . '|tns', - $node ? ($xpath->evaluate('string(configstring[@name="tns"])', $node) ?: false) : false), - ), - ), - ), - 'easy' => array( + $node ? ($xpath->evaluate('string(configstring[@name="tns"])', $node) ?: false) : false + ), + ], + ], + ], + 'easy' => [ 'desc' => 'Easy Connect', - 'fields' => array( + 'fields' => [ 'hostspec' => $hostspec, 'port' => $port, - 'service' => array( + 'service' => [ '_type' => 'text', 'required' => false, 'desc' => 'Service name', 'default' => $this->_default( $ctx . '|service', - $node ? ($xpath->evaluate('string(configstring[@name="service"])', $node) ?: false) : false), - ), - 'type' => array( + $node ? ($xpath->evaluate('string(configstring[@name="service"])', $node) ?: false) : false + ), + ], + 'type' => [ '_type' => 'text', 'required' => false, 'desc' => 'Server type', 'default' => $this->_default( $ctx . '|type', - $node ? ($xpath->evaluate('string(configstring[@name="type"])', $node) ?: false) : false), - ), - 'instance' => array( + $node ? ($xpath->evaluate('string(configstring[@name="type"])', $node) ?: false) : false + ), + ], + 'instance' => [ '_type' => 'text', 'required' => false, 'desc' => 'Instance name', 'default' => $this->_default( $ctx . '|instance', - $node ? ($xpath->evaluate('string(configstring[@name="instance"])', $node) ?: false) : false), - ), - ), - ), - ), - ), + $node ? ($xpath->evaluate('string(configstring[@name="instance"])', $node) ?: false) : false + ), + ], + ], + ], + ], + ], 'logqueries' => $logqueries, - ), - ), - 'pgsql' => array( + ], + ], + 'pgsql' => [ 'desc' => 'PostgreSQL', - 'fields' => array( + 'fields' => [ 'username' => $username, 'password' => $password, 'protocol' => $pgsql_protocol, @@ -1400,52 +1419,52 @@ public function configSQL($ctx, $node = null, $switchname = 'driverconfig') 'charset' => $charset, 'splitread' => $this->_configSQLSplitRead($ctx, $node, 'pgsql'), 'logqueries' => $logqueries, - ) - ), - 'sqlite' => array( + ], + ], + 'sqlite' => [ 'desc' => 'SQLite', - 'fields' => array( - 'database' => array( + 'fields' => [ + 'database' => [ '_type' => 'text', 'required' => true, 'desc' => 'Absolute path to the database file', 'default' => $this->_default( $ctx . '|database', $node ? ($xpath->evaluate('string(configstring[@name="database"])', $node) ?: '') : '' - ) - ), + ), + ], 'charset' => $charset, 'logqueries' => $logqueries, - ) - ) - ) - ); + ], + ], + ], + ]; if (isset($node) && $node->getAttribute('baseconfig') == 'true') { return $custom_fields; } - list($default, $isDefault) = $this->__default($ctx . '|' . (isset($node) ? $node->getAttribute('switchname') : $switchname), 'horde'); - $config = array( + [$default, $isDefault] = $this->__default($ctx . '|' . (isset($node) ? $node->getAttribute('switchname') : $switchname), 'horde'); + $config = [ 'desc' => 'Driver configuration', 'default' => $default, 'is_default' => $isDefault, - 'switch' => array( - 'horde' => array( + 'switch' => [ + 'horde' => [ 'desc' => 'Horde defaults', - 'fields' => array() - ), - 'custom' => array( + 'fields' => [], + ], + 'custom' => [ 'desc' => 'Custom parameters', - 'fields' => array( - 'phptype' => $custom_fields - ) - ) - ) - ); + 'fields' => [ + 'phptype' => $custom_fields, + ], + ], + ], + ]; if (isset($node) && $node->hasChildNodes()) { - $cur = array(); + $cur = []; $this->_parseLevel($cur, $node->childNodes, $ctx); $config['switch']['horde']['fields'] = array_merge($config['switch']['horde']['fields'], $cur); $config['switch']['custom']['fields'] = array_merge($config['switch']['custom']['fields'], $cur); @@ -1477,24 +1496,25 @@ protected function _configSQLSplitRead($ctx, $node, $phptype) $splitread_fields = $this->configSQL($ctx . '|read'); $splitread_fields = $splitread_fields['switch']['custom']['fields']['phptype']['switch'][$phptype]['fields']; - return array( + return [ '_type' => 'boolean', 'required' => false, 'desc' => 'Split reads to a different server?', 'default' => $this->_default( $ctx . '|splitread', - $node ? ($xpath->evaluate('normalize-space(configswitch[@name="splitread"]/text())', $node) ?: 'false') : 'false'), - 'switch' => array( - 'false' => array( + $node ? ($xpath->evaluate('normalize-space(configswitch[@name="splitread"]/text())', $node) ?: 'false') : 'false' + ), + 'switch' => [ + 'false' => [ 'desc' => 'Disabled', - 'fields' => array() - ), - 'true' => array( + 'fields' => [], + ], + 'true' => [ 'desc' => 'Enabled', - 'fields' => array('read' => $splitread_fields) - ) - ) - ); + 'fields' => ['read' => $splitread_fields], + ], + ], + ]; } /** @@ -1515,107 +1535,108 @@ protected function _configVFS($ctx, $node) $sql = $this->configSQL($ctx . '|params'); $default = $node->getAttribute('default'); $default = empty($default) ? 'horde' : $default; - list($default, $isDefault) = $this->__default($ctx . '|' . $node->getAttribute('switchname'), $default); + [$default, $isDefault] = $this->__default($ctx . '|' . $node->getAttribute('switchname'), $default); $xpath = new DOMXPath($node->ownerDocument); - $config = array( + $config = [ 'desc' => 'What VFS driver should we use?', 'default' => $default, 'is_default' => $isDefault, - 'switch' => array( - 'None' => array( + 'switch' => [ + 'None' => [ 'desc' => 'None', - 'fields' => array() - ), - 'File' => array( + 'fields' => [], + ], + 'File' => [ 'desc' => 'Files on the local system', - 'fields' => array( - 'params' => array( - 'vfsroot' => array( + 'fields' => [ + 'params' => [ + 'vfsroot' => [ '_type' => 'text', 'desc' => 'Where on the real filesystem should Horde use as root of the virtual filesystem?', 'default' => $this->_default( $ctx . '|params|vfsroot', $xpath->evaluate('string(configsection/configstring[@name="vfsroot"])', $node) ?: '/tmp' - ) - ) - ) - ) - ), - 'Nosql' => array( + ), + ], + ], + ], + ], + 'Nosql' => [ 'desc' => 'NoSQL database', - 'fields' => array( - 'params' => array( - 'driverconfig' => $nosql - ) - ) - ), - 'Sql' => array( + 'fields' => [ + 'params' => [ + 'driverconfig' => $nosql, + ], + ], + ], + 'Sql' => [ 'desc' => 'SQL database', - 'fields' => array( - 'params' => array( - 'driverconfig' => $sql - ) - ) - ), - 'Ssh2' => array( + 'fields' => [ + 'params' => [ + 'driverconfig' => $sql, + ], + ], + ], + 'Ssh2' => [ 'desc' => 'SSH2 (SFTP)', - 'fields' => array( - 'params' => array( - 'hostspec' => array( + 'fields' => [ + 'params' => [ + 'hostspec' => [ '_type' => 'text', 'required' => true, 'desc' => 'SSH server/host', 'default' => $this->_default( $ctx . '|hostspec', $xpath->evaluate('string(configsection/configstring[@name="hostspec"])', $node) ?: '' - ) - ), - 'port' => array( + ), + ], + 'port' => [ '_type' => 'text', 'required' => false, 'desc' => 'Port number on which SSH listens', 'default' => $this->_default( $ctx . '|port', $xpath->evaluate('string(configsection/configstring[@name="port"])', $node) ?: '22' - ) - ), - 'username' => array( + ), + ], + 'username' => [ '_type' => 'text', 'required' => true, 'desc' => 'Username to connect to the SSH server', 'default' => $this->_default( $ctx . '|username', $xpath->evaluate('string(configsection/configstring[@name="username"])', $node) ?: '' - ) - ), - 'password' => array( + ), + ], + 'password' => [ '_type' => 'text', 'required' => true, 'desc' => 'Password with which to connect', 'default' => $this->_default( $ctx . '|password', $xpath->evaluate('string(configsection/configstring[@name="password"])', $node) ?: '' - ) - ), - 'vfsroot' => array( + ), + ], + 'vfsroot' => [ '_type' => 'text', 'desc' => 'Where on the real filesystem should Horde use as root of the virtual filesystem?', 'default' => $this->_default( $ctx . '|vfsroot', - $xpath->evaluate('string(configsection/configstring[@name="vfsroot"])', $node) ?: '/tmp') - ) - ) - ) - ) - ) - ); + $xpath->evaluate('string(configsection/configstring[@name="vfsroot"])', $node) ?: '/tmp' + ), + ], + ], + ], + ], + ], + ]; if (isset($node) && $node->getAttribute('baseconfig') != 'true') { - $config['switch']['horde'] = array( + $config['switch']['horde'] = [ 'desc' => 'Horde defaults', - 'fields' => array() - ); + 'fields' => [], + ]; } $cases = $this->_getSwitchValues($node, $ctx . '|params'); foreach ($cases as $case => $fields) { @@ -1641,7 +1662,7 @@ protected function _configVFS($ctx, $node) */ protected function _default($ctx, $default) { - list ($ptr,) = $this->__default($ctx, $default); + [$ptr, ] = $this->__default($ctx, $default); return $ptr; } @@ -1658,7 +1679,7 @@ protected function _default($ctx, $default) */ protected function _isDefault($ctx, $default) { - list (,$isDefault) = $this->__default($ctx, $default); + [, $isDefault] = $this->__default($ctx, $default); return $isDefault; } @@ -1685,13 +1706,13 @@ protected function __default($ctx, $default) for ($i = 0, $ctx_count = count($ctx); $i < $ctx_count; ++$i) { if (!isset($ptr[$ctx[$i]])) { - return array($default, true); + return [$default, true]; } $ptr = $ptr[$ctx[$i]]; } - return array($ptr, false); + return [$ptr, false]; } /** @@ -1710,7 +1731,7 @@ protected function __default($ctx, $default) */ protected function _defaultRaw($ctx, $default) { - list ($ptr,) = $this->__defaultRaw($ctx, $default); + [$ptr, ] = $this->__defaultRaw($ctx, $default); return $ptr; } @@ -1727,7 +1748,7 @@ protected function _defaultRaw($ctx, $default) */ protected function _isDefaultRaw($ctx, $default) { - list (,$isDefault) = $this->__defaultRaw($ctx, $default); + [, $isDefault] = $this->__defaultRaw($ctx, $default); return $isDefault; } @@ -1756,8 +1777,8 @@ protected function __defaultRaw($ctx, $default) $pattern = '/^\$conf\[\'' . implode("'\]\['", $ctx) . '\'\] = (.*);\r?$/m'; return preg_match($pattern, $this->getPHPConfig(), $matches) - ? array($matches[1], false) - : array($default, true); + ? [$matches[1], false] + : [$default, true]; } /** @@ -1799,7 +1820,7 @@ protected function _getNodeOnlyText($node) */ protected function _getEnumValues($node) { - $values = array(); + $values = []; if (!$node->hasChildNodes()) { return $values; @@ -1809,7 +1830,7 @@ protected function _getEnumValues($node) if ($vnode->nodeType == XML_ELEMENT_NODE && $vnode->tagName == 'values') { if (!$vnode->hasChildNodes()) { - return array(); + return []; } foreach ($vnode->childNodes as $value) { @@ -1841,7 +1862,7 @@ protected function _getEnumValues($node) */ protected function _getSwitchValues(&$node, $curctx) { - $values = array(); + $values = []; if (!$node->hasChildNodes()) { return $values; @@ -1850,10 +1871,10 @@ protected function _getSwitchValues(&$node, $curctx) foreach ($node->childNodes as $case) { if ($case->nodeType == XML_ELEMENT_NODE) { $name = $case->getAttribute('name'); - $values[$name] = array( + $values[$name] = [ 'desc' => $case->getAttribute('desc'), - 'fields' => array() - ); + 'fields' => [], + ]; if ($case->hasChildNodes()) { $this->_parseLevel($values[$name]['fields'], $case->childNodes, $curctx); } @@ -1880,15 +1901,15 @@ protected function _handleSpecials($node) $app = $GLOBALS['registry']->hasInterface($app); } } catch (Horde_Exception $e) { - return array(); + return []; } if (!$app) { - return array(); + return []; } try { - return $GLOBALS['registry']->callAppMethod($app, 'configSpecialValues', array('args' => array($node->getAttribute('name')), 'noperms' => true)); + return $GLOBALS['registry']->callAppMethod($app, 'configSpecialValues', ['args' => [$node->getAttribute('name')], 'noperms' => true]); } catch (Horde_Exception $e) { - return array(); + return []; } } diff --git a/lib/Horde/Config/Form.php b/lib/Horde/Config/Form.php index 718b4c2f4..2168e1d37 100644 --- a/lib/Horde/Config/Form.php +++ b/lib/Horde/Config/Form.php @@ -1,4 +1,5 @@ setSection($configitem['tab'], $configitem['desc']); } elseif (isset($configitem['switch'])) { $selected = $this->_vars->getExists($varname, $wasset); - $var_params = array(); + $var_params = []; $select_option = true; if (is_bool($configitem['default'])) { $configitem['default'] = $configitem['default'] ? 'true' : 'false'; @@ -101,7 +102,7 @@ protected function _buildVariables($config, $prefix = '') $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']'; $desc = $configitem['desc']; - $v = $this->addVariable($name, $varname, 'enum', true, false, $desc, array($var_params, $select_option)); + $v = $this->addVariable($name, $varname, 'enum', true, false, $desc, [$var_params, $select_option]); if (array_key_exists('default', $configitem)) { $v->setDefault($configitem['default']); if ($this->_fillvars) { @@ -122,8 +123,8 @@ protected function _buildVariables($config, $prefix = '') } $var_params = ($type == 'multienum' || $type == 'enum') - ? array($configitem['values']) - : array(); + ? [$configitem['values']] + : []; if ($type == 'header' || $type == 'description') { $name = $configitem['desc']; @@ -142,17 +143,17 @@ protected function _buildVariables($config, $prefix = '') $v->setDefault($configitem['default']); if ($this->_fillvars) { switch ($type) { - case 'boolean': - if ($configitem['default']) { - $this->_vars->set($varname, 'on'); - } - break; - case 'int': - $this->_vars->set($varname, (string)$configitem['default']); - break; - default: - $this->_vars->set($varname, $configitem['default']); - break; + case 'boolean': + if ($configitem['default']) { + $this->_vars->set($varname, 'on'); + } + break; + case 'int': + $this->_vars->set($varname, (string)$configitem['default']); + break; + default: + $this->_vars->set($varname, $configitem['default']); + break; } } } diff --git a/lib/Horde/Core/ActiveSync/Auth.php b/lib/Horde/Core/ActiveSync/Auth.php index 835408b54..e82552cfa 100644 --- a/lib/Horde/Core/ActiveSync/Auth.php +++ b/lib/Horde/Core/ActiveSync/Auth.php @@ -1,4 +1,5 @@ _registry->calendar->listUids($calendar, $startstamp, $endstamp); } catch (Exception $e) { - return array(); + return []; } } @@ -118,9 +119,9 @@ public function calendar_listUids($startstamp, $endstamp, $calendar) * * @return Horde_ActiveSync_Message_Appointment The requested event. */ - public function calendar_export($uid, array $options = array(), $calendar = null) + public function calendar_export($uid, array $options = [], $calendar = null) { - $calendar = empty($calendar) ? null : array($calendar); + $calendar = empty($calendar) ? null : [$calendar]; return $this->_registry->calendar->export($uid, 'activesync', $options, $calendar); } @@ -134,10 +135,14 @@ public function calendar_export($uid, array $options = array(), $calendar = null * @return string The event's UID. */ public function calendar_import( - Horde_ActiveSync_Message_Appointment $content, $calendar = null) - { + Horde_ActiveSync_Message_Appointment $content, + $calendar = null + ) { return $this->_registry->calendar->import( - $content, 'activesync', $calendar); + $content, + 'activesync', + $calendar + ); } /** @@ -153,16 +158,21 @@ public function calendar_import( * @todo Remove for H6 and make calendar_import return this structure. */ public function calendar_import16( - Horde_ActiveSync_Message_Appointment $content, $calendar = null) - { + Horde_ActiveSync_Message_Appointment $content, + $calendar = null + ) { $result = $this->_registry->calendar->import( - $content, 'activesync', $calendar, true); + $content, + 'activesync', + $calendar, + true + ); if (!is_array($result)) { - $result = array( + $result = [ 'uid' => $result, - 'atchash' => false - ); + 'atchash' => false, + ]; } return $result; @@ -188,9 +198,10 @@ public function calendar_import_vevent(Horde_Icalendar_vEvent $vEvent) * @param Horde_Icalendar_vEvent $vEvent The event data. * @param string $attendee The attendee. */ - public function calendar_import_attendee(Horde_Icalendar_vEvent $vEvent, - $attendee) - { + public function calendar_import_attendee( + Horde_Icalendar_vEvent $vEvent, + $attendee + ) { if ($this->_registry->hasMethod('calendar/updateAttendee')) { // If the mail interface (i.e., IMP) provides a mime driver for // iTips, check if we are allowed to autoupdate. If we have no @@ -215,7 +226,7 @@ public function calendar_import_attendee(Horde_Icalendar_vEvent $vEvent, } try { - $this->_registry->calendar->updateAttendee($vEvent, $attendee); + $this->_registry->calendar->updateAttendee($vEvent, $attendee); } catch (Horde_Exception $e) { $this->_logger->err($e->getMessage()); } @@ -266,7 +277,11 @@ public function calendar_delete($uid, $calendar = null, $instanceid = null) public function calendar_getActionTimestamp($uid, $action, $calendar = null) { return $this->_registry->calendar->getActionTimestamp( - $uid, $action, $calendar, $this->hasFeature('modseq', 'calendar')); + $uid, + $action, + $calendar, + $this->hasFeature('modseq', 'calendar') + ); } /** @@ -307,13 +322,16 @@ public function calendar_getAttachment($filereference) { if (!$this->_registry->hasMethod( 'getAttachment', - $this->_registry->hasInterface('calendar'))) { + $this->_registry->hasInterface('calendar') + )) { return false; } $fileinfo = explode(':', $filereference, 4); try { return $this->_registry->calendar->getAttachment( - $fileinfo[1], $fileinfo[2], $fileinfo[3] + $fileinfo[1], + $fileinfo[2], + $fileinfo[3] ); } catch (Horde_Exception $e) { return false; @@ -348,7 +366,7 @@ public function contacts_listUids($source = null) * * @return Horde_ActiveSync_Message_Contact The contact object. */ - public function contacts_export($uid, array $options = array()) + public function contacts_export($uid, array $options = []) { return $this->_registry->contacts->export($uid, 'activesync', null, null, $options); } @@ -403,7 +421,11 @@ public function contacts_delete($uid) public function contacts_getActionTimestamp($uid, $action, $addressbook = null) { return $this->_registry->contacts->getActionTimestamp( - $uid, $action, $addressbook, $this->hasFeature('modseq', 'contacts')); + $uid, + $action, + $addressbook, + $this->hasFeature('modseq', 'contacts') + ); } /** @@ -417,7 +439,7 @@ public function getRecipientCache($max = 100) { if (!$this->_registry->hasInterface('mail') || !$this->_registry->hasInterface('contacts')) { - return array(); + return []; } $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $cache_key = 'HCASC:' . $this->_registry->getAuth() . ':' . $max; @@ -444,35 +466,35 @@ public function getRecipientCache($max = 100) * * @return array The search results. */ - public function contacts_search($query, array $options = array()) + public function contacts_search($query, array $options = []) { if ((!$gal = $this->contacts_getGal()) && empty($options['recipient_cache_search'])) { - return array(); + return []; } if (!empty($options['recipient_cache_search'])) { $sources = array_keys($this->_registry->contacts->sources(false, true)); - $return_fields = array('name', 'alias', 'email'); + $return_fields = ['name', 'alias', 'email']; foreach ($sources as $source) { - $fields[$source] = array('email'); + $fields[$source] = ['email']; } } else { - $sources = array($gal); - $fields = array(); - $return_fields = array('name', 'alias', 'email', 'firstname', 'lastname', + $sources = [$gal]; + $fields = []; + $return_fields = ['name', 'alias', 'email', 'firstname', 'lastname', 'company', 'homePhone', 'workPhone', 'cellPhone', 'title', - 'office'); + 'office']; } if (!empty($options['pictures'])) { $return_fields[] = 'photo'; } - $opts = array( + $opts = [ 'matchBegin' => true, 'forceSource' => true, 'sources' => $sources, 'returnFields' => $return_fields, - 'fields' => $fields - ); + 'fields' => $fields, + ]; return $this->_registry->contacts->search($query, $opts); } @@ -498,11 +520,11 @@ public function contacts_search($query, array $options = array()) * * @return array The search results, keyed by the $query. */ - public function resolveRecipient($query, array $opts = array()) + public function resolveRecipient($query, array $opts = []) { if (!empty($opts['starttime'])) { try { - return array($query => $this->_registry->calendar->lookupFreeBusy($query, true)); + return [$query => $this->_registry->calendar->lookupFreeBusy($query, true)]; } catch (Horde_Exception $e) { return false; // ? } @@ -513,23 +535,23 @@ public function resolveRecipient($query, array $opts = array()) if (!in_array($gal, $sources)) { $sources[] = $gal; } - $fields = array(); + $fields = []; foreach ($sources as $source) { - $fields[$source] = array('email'); + $fields[$source] = ['email']; } - $returnFields = array('name', 'email', 'alias', 'smimePublicKey'); + $returnFields = ['name', 'email', 'alias', 'smimePublicKey']; if (!empty($opts['pictures'])) { - $returnFields[$source]['photo']; + $returnFields[$source]['photo']; } - $options = array( + $options = [ 'matchBegin' => true, 'sources' => $sources, 'returnFields' => $returnFields, - 'fields' => $fields - ); + 'fields' => $fields, + ]; if (isset($opts['maxAmbiguous']) && $opts['maxAmbiguous'] == 0) { - $options['customStrict'] = array('email', 'name', 'alias'); + $options['customStrict'] = ['email', 'name', 'alias']; } return $this->_registry->contacts->search($query, $options); } @@ -596,23 +618,23 @@ public function files_browse($path) throw new Horde_ActiveSync_Exception($e); } - $files = array(); + $files = []; // An explicit file requested? if (!empty($results['data'])) { $data = new Horde_Stream(); $data->add($results['data']); - $files[] = array( + $files[] = [ 'linkid' => $original_path, 'name' => $results['name'], 'content-length' => $results['contentlength'], 'modified' => new Horde_Date($results['mtime']), 'created' => new Horde_Date($results['mtime']), // No creation date? 'is_folder' => false, - 'data' => $data); + 'data' => $data]; } else { foreach ($results as $id => $result) { - $file = array('name' => $result['name']); + $file = ['name' => $result['name']]; $file['is_folder'] = $result['browseable']; $file['modified'] = new Horde_Date($result['modified']); $file['created'] = clone $file['modified']; @@ -647,7 +669,7 @@ public function tasks_listUids($tasklist = null) * * @return Horde_ActiveSync_Message_Task The task message object */ - public function tasks_export($uid, array $options = array()) + public function tasks_export($uid, array $options = []) { return $this->_registry->tasks->export($uid, 'activesync', $options); } @@ -698,7 +720,11 @@ public function tasks_delete($id) public function tasks_getActionTimestamp($uid, $action, $tasklist = null) { return $this->_registry->tasks->getActionTimestamp( - $uid, $action, $tasklist, $this->hasFeature('modseq', 'tasks')); + $uid, + $action, + $tasklist, + $this->hasFeature('modseq', 'tasks') + ); } /** @@ -736,7 +762,7 @@ public function notes_listUids($notepad = null) * @return Horde_ActiveSync_Message_Note The note message object * @since 5.1 */ - public function notes_export($uid, array $options = array()) + public function notes_export($uid, array $options = []) { return $this->_registry->notes->export($uid, 'activesync', $options); } @@ -792,7 +818,11 @@ public function notes_delete($id) public function notes_getActionTimestamp($uid, $action, $notepad = null) { return $this->_registry->notes->getActionTimestamp( - $uid, $action, $notepad, $this->hasFeature('modseq', 'notes')); + $uid, + $action, + $notepad, + $this->hasFeature('modseq', 'notes') + ); } /** @@ -812,7 +842,7 @@ public function horde_listApis() unset($apis[$key]); } } - $active_apis = array(); + $active_apis = []; foreach ($apis as $api) { if (!$this->_registry->isInactive($this->_registry->hasInterface($api))) { $active_apis[] = $api; @@ -951,17 +981,17 @@ public function filters_setVacation(array $setting) foreach ($setting['oofmsgs'] as $msg) { if ($msg['appliesto'] == Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALKNOWN || $msg['appliesto'] == Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALUNKNOWN) { - $vacation = array( + $vacation = [ 'reason' => $msg['replymessage'], - 'subject' => Horde_Core_Translation::t('Out Of Office') - ); + 'subject' => Horde_Core_Translation::t('Out Of Office'), + ]; break; } if ($msg['appliesto'] == Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOINTERNAL) { - $vacation = array( + $vacation = [ 'reason' => $msg['replymessage'], - 'subject' => Horde_Core_Translation::t('Out Of Office') - ); + 'subject' => Horde_Core_Translation::t('Out Of Office'), + ]; } } if (!empty($setting['starttime'])) { @@ -1006,10 +1036,12 @@ public function mail_getMaillog($mid) * @param string $folder The sent-mail folder. @since Horde_Core 2.27.0 */ public function mail_logMaillog( - $action, $mid, $recipients = null, $folder = null - ) - { - $data = array(); + $action, + $mid, + $recipients = null, + $folder = null + ) { + $data = []; if (!empty($recipients)) { $data['recipients'] = $recipients; } @@ -1049,7 +1081,7 @@ public function mail_getMaillogChanges($ts) try { return $this->_registry->mail->getMaillogChanges($ts); } catch (Horde_Exception $e) { - return array(); + return []; } } } @@ -1082,7 +1114,7 @@ public function mail_ensureMessageFlags(array $flags) */ public function getChanges($collection, $from_ts, $to_ts, $server_id) { - if (!in_array($collection, array('calendar', 'contacts', 'tasks', 'notes'))) { + if (!in_array($collection, ['calendar', 'contacts', 'tasks', 'notes'])) { throw new InvalidArgumentException('collection must be one of calendar, contacts, tasks or notes'); } @@ -1095,26 +1127,28 @@ public function getChanges($collection, $from_ts, $to_ts, $server_id) if ($this->hasFeature('modseq', $collection)) { $this->_logger->meta(sprintf( 'Fetching changes for %s using MODSEQ.', - $collection)); + $collection + )); try { return $this->_registry->{$collection}->getChangesByModSeq($from_ts, $to_ts, $server_id); } catch (Exception $e) { - return array('add' => array(), - 'modify' => array(), - 'delete' => array()); + return ['add' => [], + 'modify' => [], + 'delete' => []]; } } // Older API, use timestamps. $this->_logger->meta(sprintf( 'Fetching changes for %s using TIMESTAMPS.', - $collection)); + $collection + )); try { return $this->_registry->{$collection}->getChanges($from_ts, $to_ts, false, $server_id); } catch (Exception $e) { - return array('add' => array(), - 'modify' => array(), - 'delete' => array()); + return ['add' => [], + 'modify' => [], + 'delete' => []]; } } @@ -1137,20 +1171,23 @@ protected function _ensureCalendar($source) $calendars = unserialize( $this->_registry->horde->getPreference( $this->_registry->hasInterface('calendar'), - 'sync_calendars')); + 'sync_calendars' + ) + ); if (empty($calendars)) { $calendars = $this->_registry->calendar->listCalendars(true, Horde_Perms::EDIT); $default_calendar = $this->_registry->horde->getPreference( $this->_registry->hasInterface('calendar'), - 'default_share'); + 'default_share' + ); if (empty($calendars[$default_calendar])) { - return array(); + return []; } else { - $calendars = array($default_calendar); + $calendars = [$default_calendar]; } } } else { - $calendars = array($source); + $calendars = [$source]; } return $calendars; @@ -1170,32 +1207,32 @@ protected function _ensureCalendar($source) */ public function softDelete($collection, $from_ts, $to_ts, $source = null) { - $results = array(); + $results = []; switch ($collection) { - case 'calendar': - $calendars = $this->_ensureCalendar($source); - - // Need to use listEvents instead of listUids since we must - // ignore recurring events when softdeleting or else we run - // the risk of removing a still active recurrence. - $events = $this->_registry->calendar->listEvents( - $from_ts, - $to_ts, - $calendars, // Calendars - false, // showRecurrence - false, // alarmsOnly - false, // showRemote - true, // hideExceptions - false // coverDates - ); + case 'calendar': + $calendars = $this->_ensureCalendar($source); + + // Need to use listEvents instead of listUids since we must + // ignore recurring events when softdeleting or else we run + // the risk of removing a still active recurrence. + $events = $this->_registry->calendar->listEvents( + $from_ts, + $to_ts, + $calendars, // Calendars + false, // showRecurrence + false, // alarmsOnly + false, // showRemote + true, // hideExceptions + false // coverDates + ); - foreach ($events as $day) { - foreach ($day as $e) { - if (empty($e->recurrence)) { - $results[] = $e->uid; + foreach ($events as $day) { + foreach ($day as $e) { + if (empty($e->recurrence)) { + $results[] = $e->uid; + } } } - } } return $results; @@ -1221,58 +1258,58 @@ public function getFolders($collection, $multiplex) $folders = false; if (empty($this->_folderCache[$collection])) { switch ($collection) { - case Horde_ActiveSync::CLASS_CALENDAR: - if ($this->_registry->hasMethod('calendar/sources') && - $this->_registry->horde->getPreference($this->_registry->hasInterface('calendar'), 'activesync_no_multiplex') && - !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_CALENDAR)) { - - $folders = $this->_registry->calendar->sources(true, true); - $default = $this->_registry->calendar->getDefaultShare(); - } else { - $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::APPOINTMENTS_FOLDER_UID; - } - break; + case Horde_ActiveSync::CLASS_CALENDAR: + if ($this->_registry->hasMethod('calendar/sources') && + $this->_registry->horde->getPreference($this->_registry->hasInterface('calendar'), 'activesync_no_multiplex') && + !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_CALENDAR)) { + + $folders = $this->_registry->calendar->sources(true, true); + $default = $this->_registry->calendar->getDefaultShare(); + } else { + $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::APPOINTMENTS_FOLDER_UID; + } + break; - case Horde_ActiveSync::CLASS_CONTACTS: - if ($this->_registry->hasMethod('contacts/sources') && - $this->_registry->horde->getPreference($this->_registry->hasInterface('contacts'), 'activesync_no_multiplex') && - !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_CONTACTS)) { + case Horde_ActiveSync::CLASS_CONTACTS: + if ($this->_registry->hasMethod('contacts/sources') && + $this->_registry->horde->getPreference($this->_registry->hasInterface('contacts'), 'activesync_no_multiplex') && + !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_CONTACTS)) { - $folders = $this->_registry->contacts->sources(true, true); - $default = $this->_registry->contacts->getDefaultShare(); - } else { - $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::CONTACTS_FOLDER_UID; - } - break; + $folders = $this->_registry->contacts->sources(true, true); + $default = $this->_registry->contacts->getDefaultShare(); + } else { + $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::CONTACTS_FOLDER_UID; + } + break; - case Horde_ActiveSync::CLASS_TASKS: - if ($this->_registry->hasMethod('tasks/sources') && - $this->_registry->horde->getPreference($this->_registry->hasInterface('tasks'), 'activesync_no_multiplex') && - !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_TASKS)) { + case Horde_ActiveSync::CLASS_TASKS: + if ($this->_registry->hasMethod('tasks/sources') && + $this->_registry->horde->getPreference($this->_registry->hasInterface('tasks'), 'activesync_no_multiplex') && + !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_TASKS)) { - $folders = $this->_registry->tasks->sources(true, true); - $default = $this->_registry->tasks->getDefaultShare(); - } else { - $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::TASKS_FOLDER_UID; - } - break; + $folders = $this->_registry->tasks->sources(true, true); + $default = $this->_registry->tasks->getDefaultShare(); + } else { + $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::TASKS_FOLDER_UID; + } + break; - case Horde_ActiveSync::CLASS_NOTES: - if ($this->_registry->hasMethod('notes/sources') && - $this->_registry->horde->getPreference($this->_registry->hasInterface('notes'), 'activesync_no_multiplex') && - !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_NOTES)) { + case Horde_ActiveSync::CLASS_NOTES: + if ($this->_registry->hasMethod('notes/sources') && + $this->_registry->horde->getPreference($this->_registry->hasInterface('notes'), 'activesync_no_multiplex') && + !($multiplex & Horde_ActiveSync_Device::MULTIPLEX_NOTES)) { - $folders = $this->_registry->notes->sources(true, true); - $default = $this->_registry->notes->getDefaultShare(); - } else { - $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::NOTES_FOLDER_UID; - } + $folders = $this->_registry->notes->sources(true, true); + $default = $this->_registry->notes->getDefaultShare(); + } else { + $this->_folderCache[$collection] = Horde_Core_ActiveSync_Driver::NOTES_FOLDER_UID; + } } if (!empty($folders) && is_array($folders)) { - $results = array(); + $results = []; foreach ($folders as $id => $folder) { - $results[$id] = array('display' => $folder, 'primary' => ($id == $default)); + $results[$id] = ['display' => $folder, 'primary' => ($id == $default)]; } $this->_folderCache[$collection] = $results; } elseif (is_array($folders)) { @@ -1299,47 +1336,47 @@ public function getFolders($collection, $multiplex) public function createFolder($class, $foldername) { switch ($class) { - case Horde_ActiveSync::CLASS_CALENDAR: - // @todo Remove hasMethod checks in H6. - if (!$this->_registry->hasMethod('calendar/addCalendar') || - !$this->_registry->horde->getPreference($this->_registry->hasInterface('calendar'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Creating calendars not supported by the calendar API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - return $this->_registry->calendar->addCalendar($foldername, array('synchronize' => true)); - - case Horde_ActiveSync::CLASS_CONTACTS: - // @todo Remove hasMethod check in H6 - if (!$this->_registry->hasMethod('contacts/addAddressbook') || - !$this->_registry->horde->getPreference($this->_registry->hasInterface('contacts'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Creating addressbooks not supported by the contacts API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - return $this->_registry->contacts->addAddressbook($foldername, array('synchronize' => true)); - - case Horde_ActiveSync::CLASS_NOTES: - // @todo Remove hasMethod checks in H6. - if (!$this->_registry->hasMethod('notes/addNotepad') || - !$this->_registry->horde->getPreference($this->_registry->hasInterface('notes'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Creating notepads not supported by the notes API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - return $this->_registry->notes->addNotepad($foldername, array('synchronize' => true)); + case Horde_ActiveSync::CLASS_CALENDAR: + // @todo Remove hasMethod checks in H6. + if (!$this->_registry->hasMethod('calendar/addCalendar') || + !$this->_registry->horde->getPreference($this->_registry->hasInterface('calendar'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Creating calendars not supported by the calendar API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + return $this->_registry->calendar->addCalendar($foldername, ['synchronize' => true]); - case Horde_ActiveSync::CLASS_TASKS: - if (!$this->_registry->horde->getPreference($this->_registry->hasInterface('tasks'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Creating notepads not supported by the notes API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - return $this->_registry->tasks->addTasklist($foldername, '', '', array('synchronize' => true)); + case Horde_ActiveSync::CLASS_CONTACTS: + // @todo Remove hasMethod check in H6 + if (!$this->_registry->hasMethod('contacts/addAddressbook') || + !$this->_registry->horde->getPreference($this->_registry->hasInterface('contacts'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Creating addressbooks not supported by the contacts API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + return $this->_registry->contacts->addAddressbook($foldername, ['synchronize' => true]); + + case Horde_ActiveSync::CLASS_NOTES: + // @todo Remove hasMethod checks in H6. + if (!$this->_registry->hasMethod('notes/addNotepad') || + !$this->_registry->horde->getPreference($this->_registry->hasInterface('notes'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Creating notepads not supported by the notes API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + return $this->_registry->notes->addNotepad($foldername, ['synchronize' => true]); + + case Horde_ActiveSync::CLASS_TASKS: + if (!$this->_registry->horde->getPreference($this->_registry->hasInterface('tasks'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Creating notepads not supported by the notes API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + return $this->_registry->tasks->addTasklist($foldername, '', '', ['synchronize' => true]); } } @@ -1357,63 +1394,63 @@ public function createFolder($class, $foldername) public function changeFolder($class, $id, $name) { switch ($class) { - case Horde_ActiveSync::CLASS_CALENDAR: - // @todo Remove hasMethod check - if (!$this->_registry->hasMethod('calendar/getCalendar') || - !$this->_registry->horde->getPreference($this->_registry->hasInterface('calendar'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Updating calendars not supported by the calendar API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - $calendar = $this->_registry->calendar->getCalendar($id); - $info = array( - 'name' => $name, - 'color' => $calendar->background(), - 'description' => $calendar->description() - ); - $this->_registry->calendar->updateCalendar($id, $info); - break; - - case Horde_ActiveSync::CLASS_CONTACTS: - // @todo remove hasMethod check - if (!$this->_registry->hasMethod('contacts/updateAddressbook') || - !$this->_registry->horde->getPreference($this->_registry->hasInterface('contacts'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Updating addressbooks not supported by the contacts API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - $this->_registry->contacts->updateAddressbook($id, array('name' => $name)); - break; - - case Horde_ActiveSync::CLASS_NOTES: - // @todo remove hasMethod check - if (!$this->_registry->hasMethod('notes/updateNotepad') || - !$this->_registry->horde->getPreference($this->_registry->hasInterface('notes'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Updating notepads not supported by the notes API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - $this->_registry->notes->updateNotepad($id, array('name' => $name)); - break; - - case Horde_ActiveSync::CLASS_TASKS: - if (!$this->_registry->horde->getPreference($this->_registry->hasInterface('tasks'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Updating notepads not supported by the notes API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - $share = $this->_registry->tasks->getTasklist($id); - $info = array( - 'name' => $name, - 'color' => $share->get('color'), - 'desc' => $share->get('desc') - ); - $this->_registry->tasks->updateTasklist($id, $info); - break; + case Horde_ActiveSync::CLASS_CALENDAR: + // @todo Remove hasMethod check + if (!$this->_registry->hasMethod('calendar/getCalendar') || + !$this->_registry->horde->getPreference($this->_registry->hasInterface('calendar'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Updating calendars not supported by the calendar API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + $calendar = $this->_registry->calendar->getCalendar($id); + $info = [ + 'name' => $name, + 'color' => $calendar->background(), + 'description' => $calendar->description(), + ]; + $this->_registry->calendar->updateCalendar($id, $info); + break; + + case Horde_ActiveSync::CLASS_CONTACTS: + // @todo remove hasMethod check + if (!$this->_registry->hasMethod('contacts/updateAddressbook') || + !$this->_registry->horde->getPreference($this->_registry->hasInterface('contacts'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Updating addressbooks not supported by the contacts API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + $this->_registry->contacts->updateAddressbook($id, ['name' => $name]); + break; + + case Horde_ActiveSync::CLASS_NOTES: + // @todo remove hasMethod check + if (!$this->_registry->hasMethod('notes/updateNotepad') || + !$this->_registry->horde->getPreference($this->_registry->hasInterface('notes'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Updating notepads not supported by the notes API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + $this->_registry->notes->updateNotepad($id, ['name' => $name]); + break; + + case Horde_ActiveSync::CLASS_TASKS: + if (!$this->_registry->horde->getPreference($this->_registry->hasInterface('tasks'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Updating notepads not supported by the notes API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + $share = $this->_registry->tasks->getTasklist($id); + $info = [ + 'name' => $name, + 'color' => $share->get('color'), + 'desc' => $share->get('desc'), + ]; + $this->_registry->tasks->updateTasklist($id, $info); + break; } } @@ -1428,48 +1465,48 @@ public function changeFolder($class, $id, $name) public function deleteFolder($class, $id) { switch ($class) { - case Horde_ActiveSync::CLASS_TASKS: - if (!$this->_registry->horde->getPreference($this->_registry->hasInterface('tasks'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Deleting addressbooks not supported by the contacts API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - $this->_registry->tasks->deleteTasklist($id); - break; - - case Horde_ActiveSync::CLASS_CONTACTS: - if (!$this->_registry->hasMethod('contacts/deleteAddressbook') || - !$this->_registry->horde->getPreference($this->_registry->hasInterface('contacts'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Deleting addressbooks not supported by the contacts API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - $this->_registry->contacts->deleteAddressbook($id); - break; - - case Horde_ActiveSync::CLASS_CALENDAR: - if (!$this->_registry->hasMethod('calendar/deleteCalendar') || - !$this->_registry->horde->getPreference($this->_registry->hasInterface('calendar'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Deleting calendars not supported by the calendar API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - $this->_registry->calendar->deleteCalendar($id); - break; - - case Horde_ActiveSync::CLASS_NOTES : - if (!$this->_registry->hasMethod('notes/deleteNotepad') || - !$this->_registry->horde->getPreference($this->_registry->hasInterface('notes'), 'activesync_no_multiplex')) { - throw new Horde_ActiveSync_Exception( - 'Deleting notepads not supported by the notes API.', - Horde_ActiveSync_Exception::UNSUPPORTED - ); - } - $this->_registry->notes->deleteNotepad($id); - break; + case Horde_ActiveSync::CLASS_TASKS: + if (!$this->_registry->horde->getPreference($this->_registry->hasInterface('tasks'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Deleting addressbooks not supported by the contacts API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + $this->_registry->tasks->deleteTasklist($id); + break; + + case Horde_ActiveSync::CLASS_CONTACTS: + if (!$this->_registry->hasMethod('contacts/deleteAddressbook') || + !$this->_registry->horde->getPreference($this->_registry->hasInterface('contacts'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Deleting addressbooks not supported by the contacts API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + $this->_registry->contacts->deleteAddressbook($id); + break; + + case Horde_ActiveSync::CLASS_CALENDAR: + if (!$this->_registry->hasMethod('calendar/deleteCalendar') || + !$this->_registry->horde->getPreference($this->_registry->hasInterface('calendar'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Deleting calendars not supported by the calendar API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + $this->_registry->calendar->deleteCalendar($id); + break; + + case Horde_ActiveSync::CLASS_NOTES: + if (!$this->_registry->hasMethod('notes/deleteNotepad') || + !$this->_registry->horde->getPreference($this->_registry->hasInterface('notes'), 'activesync_no_multiplex')) { + throw new Horde_ActiveSync_Exception( + 'Deleting notepads not supported by the notes API.', + Horde_ActiveSync_Exception::UNSUPPORTED + ); + } + $this->_registry->notes->deleteNotepad($id); + break; } } diff --git a/lib/Horde/Core/ActiveSync/Driver.php b/lib/Horde/Core/ActiveSync/Driver.php index c2c9f8d59..3df645511 100644 --- a/lib/Horde/Core/ActiveSync/Driver.php +++ b/lib/Horde/Core/ActiveSync/Driver.php @@ -1,4 +1,5 @@ display names. Populated in the const'r @@ -42,7 +43,7 @@ class Horde_Core_ActiveSync_Driver extends Horde_ActiveSync_Driver_Base * * @var array */ - protected $_displayMap = array(); + protected $_displayMap = []; /** * Cache message stats @@ -63,7 +64,7 @@ class Horde_Core_ActiveSync_Driver extends Horde_ActiveSync_Driver_Base * * @var array */ - protected $_folders = array(); + protected $_folders = []; /** * Imap client adapter @@ -91,19 +92,19 @@ class Horde_Core_ActiveSync_Driver extends Horde_ActiveSync_Driver_Base * * @var array */ - protected $_verbs = array(); + protected $_verbs = []; /** * Class => Id map * * @var array */ - protected $_classMap = array( + protected $_classMap = [ Horde_ActiveSync::CLASS_TASKS => self::TASKS_FOLDER_UID, Horde_ActiveSync::CLASS_CALENDAR => self::APPOINTMENTS_FOLDER_UID, Horde_ActiveSync::CLASS_CONTACTS => self::CONTACTS_FOLDER_UID, - Horde_ActiveSync::CLASS_NOTES => self::NOTES_FOLDER_UID - ); + Horde_ActiveSync::CLASS_NOTES => self::NOTES_FOLDER_UID, + ]; /** * Const'r @@ -126,7 +127,7 @@ class Horde_Core_ActiveSync_Driver extends Horde_ActiveSync_Driver_Base * data, such as mailbox search results. * @since 2.12.0 */ - public function __construct(array $params = array()) + public function __construct(array $params = []) { parent::__construct($params); if (empty($this->_params['connector']) || @@ -152,12 +153,12 @@ public function __construct(array $params = array()) } // Build the displaymap - $this->_displayMap = array( + $this->_displayMap = [ self::APPOINTMENTS_FOLDER_UID => Horde_ActiveSync_Translation::t('Calendar'), self::CONTACTS_FOLDER_UID => Horde_ActiveSync_Translation::t('Contacts'), self::TASKS_FOLDER_UID => Horde_ActiveSync_Translation::t('Tasks'), self::NOTES_FOLDER_UID => Horde_ActiveSync_Translation::t('Notes'), - ); + ]; } /** @@ -190,11 +191,13 @@ public function authenticate($username, $password, $domain = null) { global $injector, $conf; - $this->_logger->info(sprintf( - '%sHorde_Core_ActiveSync_Driver::authenticate() attempt for %s%s', - str_repeat('-', 10), - $username, - str_repeat('-', 10)) + $this->_logger->info( + sprintf( + '%sHorde_Core_ActiveSync_Driver::authenticate() attempt for %s%s', + str_repeat('-', 10), + $username, + str_repeat('-', 10) + ) ); // First try transparent/X509. Happens for authtype == 'cert' || 'basic_cert' @@ -206,20 +209,25 @@ public function authenticate($username, $password, $domain = null) if ($username != $GLOBALS['registry']->getAuth()) { $injector->getInstance('Horde_Log_Logger')->notice(sprintf( 'Access granted based on transparent authentication of user %s, but ActiveSync client is requesting access for %s.', - $GLOBALS['registry']->getAuth(), $username)); + $GLOBALS['registry']->getAuth(), + $username + )); $GLOBALS['registry']->clearAuth(); return false; } - $this->_logger->info(sprintf( - 'Access granted based on transparent authentication for %s. Client certificate name: %s', - $GLOBALS['registry']->getAuth(), $username) + $this->_logger->info( + sprintf( + 'Access granted based on transparent authentication for %s. Client certificate name: %s', + $GLOBALS['registry']->getAuth(), + $username + ) ); } // Now check Basic. Happens for authtype == 'basic' || 'basic_cert' if ($conf['activesync']['auth']['type'] != 'cert') { try { - $authResult = $this->_auth->authenticate($username, array('password' => $password)); + $authResult = $this->_auth->authenticate($username, ['password' => $password]); } catch (Horde_Auth_Exception $e) { if ($e->getCode() == Horde_Auth::REASON_MESSAGE) { // This error code would only happen if it's an error @@ -229,10 +237,10 @@ public function authenticate($username, $password, $domain = null) // TODO: Remove BC shim if (defined('Horde_ActiveSync::AUTH_REASON_UNAVAILABLE')) { - return constant('Horde_ActiveSync::AUTH_REASON_UNAVAILABLE'); - } + return constant('Horde_ActiveSync::AUTH_REASON_UNAVAILABLE'); + } - return false; + return false; } } @@ -249,9 +257,11 @@ public function authenticate($username, $password, $domain = null) if ($perms->exists('horde:activesync')) { // Check permissions to ActiveSync if (!$this->_getPolicyValue('activesync', $perms->getPermissions('horde:activesync', $username))) { - $this->_logger->info(sprintf( - 'Access denied for user %s per policy settings.', - $username) + $this->_logger->info( + sprintf( + 'Access denied for user %s per policy settings.', + $username + ) ); return Horde_ActiveSync::AUTH_REASON_USER_DENIED; } @@ -268,9 +278,11 @@ public function authenticate($username, $password, $domain = null) public function clearAuthentication() { $this->_connector->clearAuth(); - $this->_logger->info(sprintf( - 'User %s logged off', - $this->_user) + $this->_logger->info( + sprintf( + 'User %s logged off', + $this->_user + ) ); return true; } @@ -287,7 +299,7 @@ public function clearAuthentication() public function setup($user) { parent::setup($user); - $this->_modCache = array(); + $this->_modCache = []; return true; } @@ -325,10 +337,15 @@ public function getFolderList() { $this->_logger->meta('Horde_Core_ActiveSync_Driver::getFolderList()'); $folderlist = $this->getFolders(); - $folders = array(); + $folders = []; foreach ($folderlist as $f) { $folders[] = $this->statFolder( - $f->serverid, $f->parentid, $f->displayname, $f->_serverid, $f->type); + $f->serverid, + $f->parentid, + $f->displayname, + $f->_serverid, + $f->type + ); } return $folders; @@ -349,9 +366,9 @@ public function getFolders() } catch (Exception $e) { $this->_logger->err($e->getMessage()); $this->_endBuffer(); - return array(); + return []; } - $folders = array(); + $folders = []; if (array_search('calendar', $supported) !== false) { $temp = $this->_connector->getFolders(Horde_ActiveSync::CLASS_CALENDAR, $multiplex); @@ -360,11 +377,11 @@ public function getFolders() try { $temp_folder = $this->_getFolder( Horde_ActiveSync::CLASS_CALENDAR . ':' . $id, - array( + [ 'class' => Horde_ActiveSync::CLASS_CALENDAR, 'primary' => $folder['primary'], - 'display' => $folder['display'] - ) + 'display' => $folder['display'], + ] ); if (!empty($temp_folder)) { $folders[] = $temp_folder; @@ -395,11 +412,11 @@ public function getFolders() try { $temp_folder = $this->_getFolder( Horde_ActiveSync::CLASS_CONTACTS . ':' . $id, - array( + [ 'class' => Horde_ActiveSync::CLASS_CONTACTS, 'primary' => $folder['primary'], - 'display' => $folder['display'] - ) + 'display' => $folder['display'], + ] ); if (!empty($temp_folder)) { $folders[] = $temp_folder; @@ -428,23 +445,23 @@ public function getFolders() $temp = $this->_connector->getFolders(Horde_ActiveSync::CLASS_TASKS, $multiplex); if (is_array($temp)) { foreach ($temp as $id => $folder) { - try { - $temp_folder = $this->_getFolder( + try { + $temp_folder = $this->_getFolder( Horde_ActiveSync::CLASS_TASKS . ':' . $id, - array( - 'class' => Horde_ActiveSync::CLASS_TASKS, - 'primary' => $folder['primary'], - 'display' => $folder['display'] - ) + [ + 'class' => Horde_ActiveSync::CLASS_TASKS, + 'primary' => $folder['primary'], + 'display' => $folder['display'], + ] ); if (!empty($temp_folder)) { $folders[] = $temp_folder; } else { $this->_logger->meta('Unable to find a useable tasks folder.'); } - } catch (Horde_ActiveSync_Exception $e) { + } catch (Horde_ActiveSync_Exception $e) { $this->_logger->meta('Unable to find a useable tasks folder.'); - } + } } } else { try { @@ -467,11 +484,11 @@ public function getFolders() try { $temp_folder = $this->_getFolder( Horde_ActiveSync::CLASS_NOTES . ':' . $id, - array( + [ 'class' => Horde_ActiveSync::CLASS_NOTES, 'primary' => $folder['primary'], - 'display' => $folder['display'] - ) + 'display' => $folder['display'], + ] ); if (!empty($temp_folder)) { $folders[] = $temp_folder; @@ -496,7 +513,7 @@ public function getFolders() } if ($this->_version > Horde_ActiveSync::VERSION_TWELVEONE && $GLOBALS['registry']->hasInterface('contacts')) { - $folders[] = $this->_getFolder('RI', array('class' => 'RI')); + $folders[] = $this->_getFolder('RI', ['class' => 'RI']); } // Always return at least the "dummy" IMAP folders since some @@ -507,7 +524,7 @@ public function getFolders() } catch (Horde_ActiveSync_Exception $e) { $this->_logger->err($e->getMessage()); $this->_endBuffer(); - return array(); + return []; } $this->_endBuffer(); @@ -534,7 +551,7 @@ public function getFolders() * @return Horde_ActiveSync_Message_Folder The folder object. * @throws Horde_ActiveSync_Exception */ - protected function _getFolder($id, array $params = array()) + protected function _getFolder($id, array $params = []) { if (empty($id)) { throw new Horde_ActiveSync_Exception(); @@ -542,40 +559,44 @@ protected function _getFolder($id, array $params = array()) // First check for legacy/multiplexed IDs. switch ($id) { - case self::APPOINTMENTS_FOLDER_UID: - return $this->_buildNonMailFolder( - $id, - 0, - Horde_ActiveSync::FOLDER_TYPE_APPOINTMENT, - $this->_displayMap[self::APPOINTMENTS_FOLDER_UID]); - - case self::CONTACTS_FOLDER_UID: - return $this->_buildNonMailFolder( - $id, - 0, - Horde_ActiveSync::FOLDER_TYPE_CONTACT, - $this->_displayMap[self::CONTACTS_FOLDER_UID]); - - case self::TASKS_FOLDER_UID: - return $this->_buildNonMailFolder( - $id, - 0, - Horde_ActiveSync::FOLDER_TYPE_TASK, - $this->_displayMap[self::TASKS_FOLDER_UID]); - - case self::NOTES_FOLDER_UID: - return $this->_buildNonMailFolder( - $id, - 0, - Horde_ActiveSync::FOLDER_TYPE_NOTE, - $this->_displayMap[self::NOTES_FOLDER_UID]); - case 'RI': - return $this->_buildNonMailFolder( - 'RI', - 0, - Horde_ActiveSync::FOLDER_TYPE_RECIPIENT_CACHE, - 'RI' - ); + case self::APPOINTMENTS_FOLDER_UID: + return $this->_buildNonMailFolder( + $id, + 0, + Horde_ActiveSync::FOLDER_TYPE_APPOINTMENT, + $this->_displayMap[self::APPOINTMENTS_FOLDER_UID] + ); + + case self::CONTACTS_FOLDER_UID: + return $this->_buildNonMailFolder( + $id, + 0, + Horde_ActiveSync::FOLDER_TYPE_CONTACT, + $this->_displayMap[self::CONTACTS_FOLDER_UID] + ); + + case self::TASKS_FOLDER_UID: + return $this->_buildNonMailFolder( + $id, + 0, + Horde_ActiveSync::FOLDER_TYPE_TASK, + $this->_displayMap[self::TASKS_FOLDER_UID] + ); + + case self::NOTES_FOLDER_UID: + return $this->_buildNonMailFolder( + $id, + 0, + Horde_ActiveSync::FOLDER_TYPE_NOTE, + $this->_displayMap[self::NOTES_FOLDER_UID] + ); + case 'RI': + return $this->_buildNonMailFolder( + 'RI', + 0, + Horde_ActiveSync::FOLDER_TYPE_RECIPIENT_CACHE, + 'RI' + ); } // Either an email folder or a non-multiplexed non-email folder. @@ -595,34 +616,34 @@ protected function _getFolder($id, array $params = array()) // Non-Multiplexed non-email collection? $primary = !empty($params['primary']); switch ($params['class']) { - case Horde_ActiveSync::CLASS_CALENDAR: - return $this->_buildNonMailFolder( - $id, - 0, - $primary ? Horde_ActiveSync::FOLDER_TYPE_APPOINTMENT : Horde_ActiveSync::FOLDER_TYPE_USER_APPOINTMENT, - $params['display'] - ); - case Horde_ActiveSync::CLASS_CONTACTS: - return $this->_buildNonMailFolder( - $id, - 0, - $primary ? Horde_ActiveSync::FOLDER_TYPE_CONTACT : Horde_ActiveSync::FOLDER_TYPE_USER_CONTACT, - $params['display'] - ); - case Horde_ActiveSync::CLASS_TASKS: - return $this->_buildNonMailFolder( - $id, - 0, - $primary ? Horde_ActiveSync::FOLDER_TYPE_TASK : Horde_ActiveSync::FOLDER_TYPE_USER_TASK, - $params['display'] - ); - case Horde_ActiveSync::CLASS_NOTES: - return $this->_buildNonMailFolder( - $id, - 0, - $primary ? Horde_ActiveSync::FOLDER_TYPE_NOTE : Horde_ActiveSync::FOLDER_TYPE_USER_NOTE, - $params['display'] - ); + case Horde_ActiveSync::CLASS_CALENDAR: + return $this->_buildNonMailFolder( + $id, + 0, + $primary ? Horde_ActiveSync::FOLDER_TYPE_APPOINTMENT : Horde_ActiveSync::FOLDER_TYPE_USER_APPOINTMENT, + $params['display'] + ); + case Horde_ActiveSync::CLASS_CONTACTS: + return $this->_buildNonMailFolder( + $id, + 0, + $primary ? Horde_ActiveSync::FOLDER_TYPE_CONTACT : Horde_ActiveSync::FOLDER_TYPE_USER_CONTACT, + $params['display'] + ); + case Horde_ActiveSync::CLASS_TASKS: + return $this->_buildNonMailFolder( + $id, + 0, + $primary ? Horde_ActiveSync::FOLDER_TYPE_TASK : Horde_ActiveSync::FOLDER_TYPE_USER_TASK, + $params['display'] + ); + case Horde_ActiveSync::CLASS_NOTES: + return $this->_buildNonMailFolder( + $id, + 0, + $primary ? Horde_ActiveSync::FOLDER_TYPE_NOTE : Horde_ActiveSync::FOLDER_TYPE_USER_NOTE, + $params['display'] + ); } } @@ -639,18 +660,23 @@ public function getFolder($id) $folders = $this->getFolders(); foreach ($folders as $folder) { if ($folder->_serverid == $id) { - $this->_logger->meta(sprintf( - 'Returning folder %s (%s type %s) from Horde_Core_ActiveSync_Driver::getFolder()', - $id, - $folder->serverid, - $folder->type) + $this->_logger->meta( + sprintf( + 'Returning folder %s (%s type %s) from Horde_Core_ActiveSync_Driver::getFolder()', + $id, + $folder->serverid, + $folder->type + ) ); return $folder; } } - throw new Horde_ActiveSync_Exception(sprintf( - 'Folder: %s not found!', $id) + throw new Horde_ActiveSync_Exception( + sprintf( + 'Folder: %s not found!', + $id + ) ); } @@ -670,34 +696,34 @@ protected function _parseFolderId($id, $checkEmail = false) } if (strpos($id, ':') === false) { switch ($id) { - case self::APPOINTMENTS_FOLDER_UID: - return Horde_ActiveSync::CLASS_CALENDAR; - case self::CONTACTS_FOLDER_UID: - return Horde_ActiveSync::CLASS_CONTACTS; - case self::TASKS_FOLDER_UID: - return Horde_ActiveSync::CLASS_TASKS; - case self::NOTES_FOLDER_UID: - return Horde_ActiveSync::CLASS_NOTES; - default: - return Horde_ActiveSync::CLASS_EMAIL; + case self::APPOINTMENTS_FOLDER_UID: + return Horde_ActiveSync::CLASS_CALENDAR; + case self::CONTACTS_FOLDER_UID: + return Horde_ActiveSync::CLASS_CONTACTS; + case self::TASKS_FOLDER_UID: + return Horde_ActiveSync::CLASS_TASKS; + case self::NOTES_FOLDER_UID: + return Horde_ActiveSync::CLASS_NOTES; + default: + return Horde_ActiveSync::CLASS_EMAIL; } } else { $parts = explode(':', $id, 2); if (count($parts) == 2) { switch ($parts[self::FOLDER_PART_CLASS]) { - case Horde_ActiveSync::CLASS_CALENDAR: - case Horde_ActiveSync::CLASS_TASKS: - case Horde_ActiveSync::CLASS_CONTACTS: - case Horde_ActiveSync::CLASS_NOTES: - if ($checkEmail) { - $folders = $this->_getMailFolders(); - foreach ($folders as $folder) { - if ($folder->_serverid == $id) { - return Horde_ActiveSync::CLASS_EMAIL; + case Horde_ActiveSync::CLASS_CALENDAR: + case Horde_ActiveSync::CLASS_TASKS: + case Horde_ActiveSync::CLASS_CONTACTS: + case Horde_ActiveSync::CLASS_NOTES: + if ($checkEmail) { + $folders = $this->_getMailFolders(); + foreach ($folders as $folder) { + if ($folder->_serverid == $id) { + return Horde_ActiveSync::CLASS_EMAIL; + } } } - } - return $parts; + return $parts; } } return Horde_ActiveSync::CLASS_EMAIL; @@ -721,9 +747,15 @@ protected function _parseFolderId($id, $checkEmail = false) */ public function changeFolder($old_name, $new_name, $parent, $uid = null, $type = null) { - $this->_logger->meta(sprintf( - 'Horde_Core_ActiveSync_Driver::changeFolder(%s, %s, %s, %s, %s)', - $old_name, $new_name, $parent, $uid, $type) + $this->_logger->meta( + sprintf( + 'Horde_Core_ActiveSync_Driver::changeFolder(%s, %s, %s, %s, %s)', + $old_name, + $new_name, + $parent, + $uid, + $type + ) ); // For FOLDERUPDATE requests, the EAS Folder type is not passed by @@ -738,55 +770,57 @@ public function changeFolder($old_name, $new_name, $parent, $uid = null, $type = } switch ($type) { - case Horde_ActiveSync::CLASS_EMAIL: - case Horde_ActiveSync::FOLDER_TYPE_USER_MAIL: - if (!$old_name) { - try { - $serverid = $this->_imap->createMailbox($new_name, $parent); - $this->_logger->meta(sprintf( - 'New IMAP folder created: %s', - $serverid) - ); - } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err($e->getMessage()); - throw $e; - } - } else { - try { - $serverid = $this->_imap->renameMailbox($old_name, $new_name, $parent); - $uid = $this->_getFolderUidForBackendId($serverid, Horde_ActiveSync::FOLDER_TYPE_USER_MAIL, $old_name); - } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err($e->getMessage()); - throw $e; + case Horde_ActiveSync::CLASS_EMAIL: + case Horde_ActiveSync::FOLDER_TYPE_USER_MAIL: + if (!$old_name) { + try { + $serverid = $this->_imap->createMailbox($new_name, $parent); + $this->_logger->meta( + sprintf( + 'New IMAP folder created: %s', + $serverid + ) + ); + } catch (Horde_ActiveSync_Exception $e) { + $this->_logger->err($e->getMessage()); + throw $e; + } + } else { + try { + $serverid = $this->_imap->renameMailbox($old_name, $new_name, $parent); + $uid = $this->_getFolderUidForBackendId($serverid, Horde_ActiveSync::FOLDER_TYPE_USER_MAIL, $old_name); + } catch (Horde_ActiveSync_Exception $e) { + $this->_logger->err($e->getMessage()); + throw $e; + } } - } - return $this->getFolder($serverid); - - case Horde_ActiveSync::CLASS_TASKS: - case Horde_ActiveSync::FOLDER_TYPE_USER_TASK: - $class = Horde_ActiveSync::CLASS_TASKS; - $type = Horde_ActiveSync::FOLDER_TYPE_USER_TASK; - break; - - case Horde_ActiveSync::CLASS_CALENDAR: - case Horde_ActiveSync::FOLDER_TYPE_USER_APPOINTMENT: - $class = Horde_ActiveSync::CLASS_CALENDAR; - $type = Horde_ActiveSync::FOLDER_TYPE_USER_APPOINTMENT; - break; - - case Horde_ActiveSync::CLASS_CONTACTS: - case Horde_ActiveSync::FOLDER_TYPE_USER_CONTACT: - $class = Horde_ActiveSync::CLASS_CONTACTS; - $type = Horde_ActiveSync::FOLDER_TYPE_USER_CONTACT; - break; - case Horde_ActiveSync::CLASS_NOTES: - case Horde_ActiveSync::FOLDER_TYPE_USER_NOTE: - $class = Horde_ActiveSync::CLASS_NOTES; - $type = Horde_ActiveSync::FOLDER_TYPE_USER_NOTE; - break; - - default: - throw new Horde_ActiveSync_Exception('Unsupported EAS Collection Class.'); + return $this->getFolder($serverid); + + case Horde_ActiveSync::CLASS_TASKS: + case Horde_ActiveSync::FOLDER_TYPE_USER_TASK: + $class = Horde_ActiveSync::CLASS_TASKS; + $type = Horde_ActiveSync::FOLDER_TYPE_USER_TASK; + break; + + case Horde_ActiveSync::CLASS_CALENDAR: + case Horde_ActiveSync::FOLDER_TYPE_USER_APPOINTMENT: + $class = Horde_ActiveSync::CLASS_CALENDAR; + $type = Horde_ActiveSync::FOLDER_TYPE_USER_APPOINTMENT; + break; + + case Horde_ActiveSync::CLASS_CONTACTS: + case Horde_ActiveSync::FOLDER_TYPE_USER_CONTACT: + $class = Horde_ActiveSync::CLASS_CONTACTS; + $type = Horde_ActiveSync::FOLDER_TYPE_USER_CONTACT; + break; + case Horde_ActiveSync::CLASS_NOTES: + case Horde_ActiveSync::FOLDER_TYPE_USER_NOTE: + $class = Horde_ActiveSync::CLASS_NOTES; + $type = Horde_ActiveSync::FOLDER_TYPE_USER_NOTE; + break; + + default: + throw new Horde_ActiveSync_Exception('Unsupported EAS Collection Class.'); } if (!$old_name) { @@ -814,7 +848,10 @@ public function changeFolder($old_name, $new_name, $parent, $uid = null, $type = } return $this->_buildNonMailFolder( - $class . ':' . $id, Horde_ActiveSync::FOLDER_ROOT, $type, $new_name + $class . ':' . $id, + Horde_ActiveSync::FOLDER_ROOT, + $type, + $new_name ); } @@ -829,8 +866,11 @@ public function changeFolder($old_name, $new_name, $parent, $uid = null, $type = */ public function deleteFolder($id, $parent = Horde_ActiveSync::FOLDER_ROOT) { - $this->_logger->meta(sprintf( - 'Horde_Core_ActiveSync_Driver::deleteFolder(%s)', $id) + $this->_logger->meta( + sprintf( + 'Horde_Core_ActiveSync_Driver::deleteFolder(%s)', + $id + ) ); $parts = $this->_parseFolderId($id); @@ -843,24 +883,24 @@ public function deleteFolder($id, $parent = Horde_ActiveSync::FOLDER_ROOT) } switch ($folder_class) { - case Horde_ActiveSync::CLASS_EMAIL: - case Horde_ActiveSync::FOLDER_TYPE_USER_MAIL: - try { - $this->_imap->deleteMailbox($folder_id); - } catch (Horde_ActiveSync_Exception $e) { - if ($this->_isSpecialMailbox($folder_id)) { - throw new Horde_ActiveSync_Exception_DeletionNotSupported($e); + case Horde_ActiveSync::CLASS_EMAIL: + case Horde_ActiveSync::FOLDER_TYPE_USER_MAIL: + try { + $this->_imap->deleteMailbox($folder_id); + } catch (Horde_ActiveSync_Exception $e) { + if ($this->_isSpecialMailbox($folder_id)) { + throw new Horde_ActiveSync_Exception_DeletionNotSupported($e); + } + $this->_logger->err($e->getMessage()); + throw $e; } - $this->_logger->err($e->getMessage()); - throw $e; - } - break; + break; - case Horde_ActiveSync::CLASS_TASKS: - case Horde_ActiveSync::CLASS_CALENDAR: - case Horde_ActiveSync::CLASS_CONTACTS: - case Horde_ActiveSync::CLASS_NOTES: - $this->_connector->deleteFolder($folder_class, $folder_id); + case Horde_ActiveSync::CLASS_TASKS: + case Horde_ActiveSync::CLASS_CALENDAR: + case Horde_ActiveSync::CLASS_CONTACTS: + case Horde_ActiveSync::CLASS_NOTES: + $this->_connector->deleteFolder($folder_class, $folder_id); } } @@ -889,7 +929,7 @@ public function deleteFolder($id, $parent = Horde_ActiveSync::FOLDER_ROOT) */ public function statFolder($id, $parent = '0', $mod = null, $serverid = null, $type = null) { - $folder = array(); + $folder = []; $folder['id'] = $id; $folder['mod'] = empty($mod) ? $id : $mod; $folder['parent'] = $parent; @@ -952,292 +992,306 @@ public function statFolder($id, $parent = '0', $mod = null, $serverid = null, $t * to better define the available properties. */ public function getServerChanges( - $folder, $from_ts, $to_ts, $cutoffdate, $ping, $ignoreFirstSync = false, $maxitems = 100, $refreshFilter = false) - { - $this->_logger->meta(sprintf( - 'Horde_Core_ActiveSync_Driver::getServerChanges(%s, %u, %u, %u, %d, %s, %u, %s)', - $folder->serverid(), - $from_ts, - $to_ts, - $cutoffdate, - $ping, - $ignoreFirstSync, - $maxitems, - $refreshFilter) + $folder, + $from_ts, + $to_ts, + $cutoffdate, + $ping, + $ignoreFirstSync = false, + $maxitems = 100, + $refreshFilter = false + ) { + $this->_logger->meta( + sprintf( + 'Horde_Core_ActiveSync_Driver::getServerChanges(%s, %u, %u, %u, %d, %s, %u, %s)', + $folder->serverid(), + $from_ts, + $to_ts, + $cutoffdate, + $ping, + $ignoreFirstSync, + $maxitems, + $refreshFilter + ) ); - $changes = array( - 'add' => array(), - 'delete' => array(), - 'modify' => array(), - 'soft' => array() - ); + $changes = [ + 'add' => [], + 'delete' => [], + 'modify' => [], + 'soft' => [], + ]; ob_start(); switch ($folder->collectionClass()) { - case Horde_ActiveSync::CLASS_CALENDAR: - if ($folder->serverid() == self::APPOINTMENTS_FOLDER_UID) { - $server_id = null; - } else { - $parts = $this->_parseFolderId($folder->serverid()); - $server_id = $parts[self::FOLDER_PART_ID]; - } - - if ($from_ts == 0 && !$ignoreFirstSync) { - // Can't use History if it's a first sync - $startstamp = (int)$cutoffdate; - $endstamp = time() + 32140800; //60 * 60 * 24 * 31 * 12 == one year - try { - $changes['add'] = $this->_connector->calendar_listUids($startstamp, $endstamp, $server_id); - } catch (Horde_Exception_AuthenticationFailure $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return array(); + case Horde_ActiveSync::CLASS_CALENDAR: + if ($folder->serverid() == self::APPOINTMENTS_FOLDER_UID) { + $server_id = null; + } else { + $parts = $this->_parseFolderId($folder->serverid()); + $server_id = $parts[self::FOLDER_PART_ID]; } - $folder->setSoftDeleteTimes($cutoffdate, time()); - } else { - try { - $changes = $this->_connector->getChanges('calendar', $from_ts, $to_ts, $server_id); - } catch (Horde_Exception_AuthenticationFailure $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return array(); - } - - // Softdelete. We check this once per close-to 24 hour period,or - // if the FILTERTYPE range changes. We introduce an element of - // randomness in the time to help avoid a large number of - // clients performing a softdelete at once. It's 23 hours + some - // random number of minutes < 60. - // - // @todo We need to populate additional events if the FILTERTYPE - // is expanded, but we need to persist the previous FILTERTYPE - // so we know exactly which events we already have and which - // we don't (since we don't track the UIDs themselves). - if (!$ping) { - if (!$refreshFilter) { - $sd = $folder->getSoftDeleteTimes(); - if ($sd[0] + 82800 + mt_rand(0, 3600) < time()) { - $from = $sd[1]; - } - } else { - // Force refresh the FILTERTYPE. - $from = 0; + + if ($from_ts == 0 && !$ignoreFirstSync) { + // Can't use History if it's a first sync + $startstamp = (int)$cutoffdate; + $endstamp = time() + 32140800; //60 * 60 * 24 * 31 * 12 == one year + try { + $changes['add'] = $this->_connector->calendar_listUids($startstamp, $endstamp, $server_id); + } catch (Horde_Exception_AuthenticationFailure $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return []; } - if (isset($from)) { - $this->_logger->meta('Polling for SOFTDELETE items in calendar collection'); - $changes['soft'] = $this->_connector->softDelete( - 'calendar', $from, $cutoffdate, $server_id - ); - $folder->setSoftDeleteTimes($cutoffdate, time()); + $folder->setSoftDeleteTimes($cutoffdate, time()); + } else { + try { + $changes = $this->_connector->getChanges('calendar', $from_ts, $to_ts, $server_id); + } catch (Horde_Exception_AuthenticationFailure $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return []; + } + + // Softdelete. We check this once per close-to 24 hour period,or + // if the FILTERTYPE range changes. We introduce an element of + // randomness in the time to help avoid a large number of + // clients performing a softdelete at once. It's 23 hours + some + // random number of minutes < 60. + // + // @todo We need to populate additional events if the FILTERTYPE + // is expanded, but we need to persist the previous FILTERTYPE + // so we know exactly which events we already have and which + // we don't (since we don't track the UIDs themselves). + if (!$ping) { + if (!$refreshFilter) { + $sd = $folder->getSoftDeleteTimes(); + if ($sd[0] + 82800 + mt_rand(0, 3600) < time()) { + $from = $sd[1]; + } + } else { + // Force refresh the FILTERTYPE. + $from = 0; + } + if (isset($from)) { + $this->_logger->meta('Polling for SOFTDELETE items in calendar collection'); + $changes['soft'] = $this->_connector->softDelete( + 'calendar', + $from, + $cutoffdate, + $server_id + ); + $folder->setSoftDeleteTimes($cutoffdate, time()); + } } } - } - break; + break; - case Horde_ActiveSync::CLASS_CONTACTS: - // Multiplexed or multiple? - if ($folder->serverid() == self::CONTACTS_FOLDER_UID) { - $server_id = null; - } else { - $parts = $this->_parseFolderId($folder->serverid()); - $server_id = $parts[self::FOLDER_PART_ID]; - } + case Horde_ActiveSync::CLASS_CONTACTS: + // Multiplexed or multiple? + if ($folder->serverid() == self::CONTACTS_FOLDER_UID) { + $server_id = null; + } else { + $parts = $this->_parseFolderId($folder->serverid()); + $server_id = $parts[self::FOLDER_PART_ID]; + } - // Can't use History for first sync - if ($from_ts == 0 && !$ignoreFirstSync) { - try { - $changes['add'] = $this->_connector->contacts_listUids($server_id); - } catch (Horde_Exception_AuthenticationFailure $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return array(); + // Can't use History for first sync + if ($from_ts == 0 && !$ignoreFirstSync) { + try { + $changes['add'] = $this->_connector->contacts_listUids($server_id); + } catch (Horde_Exception_AuthenticationFailure $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return []; + } + } else { + try { + $changes = $this->_connector->getChanges('contacts', $from_ts, $to_ts, $server_id); + } catch (Horde_Exception_AuthenticationFailure $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return []; + } } - } else { - try { - $changes = $this->_connector->getChanges('contacts', $from_ts, $to_ts, $server_id); - } catch (Horde_Exception_AuthenticationFailure $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return array(); + break; + + case Horde_ActiveSync::CLASS_TASKS: + // Multiplexed or multiple? + if ($folder->serverid() == self::TASKS_FOLDER_UID) { + $server_id = null; + } else { + $parts = $this->_parseFolderId($folder->serverid()); + $server_id = $parts[self::FOLDER_PART_ID]; } - } - break; - case Horde_ActiveSync::CLASS_TASKS: - // Multiplexed or multiple? - if ($folder->serverid() == self::TASKS_FOLDER_UID) { - $server_id = null; - } else { - $parts = $this->_parseFolderId($folder->serverid()); - $server_id = $parts[self::FOLDER_PART_ID]; - } + // Can't use History for first sync + if ($from_ts == 0 && !$ignoreFirstSync) { + try { + $changes['add'] = $this->_connector->tasks_listUids($server_id); + } catch (Horde_Exception_AuthenticationFailure $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return []; + } + } else { + try { + $changes = $this->_connector->getChanges('tasks', $from_ts, $to_ts, $server_id); + } catch (Horde_Exception_AuthenticationFailure $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return []; + } + } + break; - // Can't use History for first sync - if ($from_ts == 0 && !$ignoreFirstSync) { - try { - $changes['add'] = $this->_connector->tasks_listUids($server_id); - } catch (Horde_Exception_AuthenticationFailure $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return array(); + case Horde_ActiveSync::CLASS_NOTES: + // Multiplexed or multiple? + if ($folder->serverid() == self::NOTES_FOLDER_UID) { + $server_id = null; + } else { + $parts = $this->_parseFolderId($folder->serverid()); + $server_id = $parts[self::FOLDER_PART_ID]; } - } else { - try { - $changes = $this->_connector->getChanges('tasks', $from_ts, $to_ts, $server_id); - } catch (Horde_Exception_AuthenticationFailure $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return array(); + + // Can't use History for first sync + if ($from_ts == 0 && !$ignoreFirstSync) { + try { + $changes['add'] = $this->_connector->notes_listUids($server_id); + } catch (Horde_Exception_AuthenticationFailure $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return []; + } + } else { + try { + $changes = $this->_connector->getChanges('notes', $from_ts, $to_ts, $server_id); + } catch (Horde_Exception_AuthenticationFailure $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return []; + } } - } - break; + break; - case Horde_ActiveSync::CLASS_NOTES: - // Multiplexed or multiple? - if ($folder->serverid() == self::NOTES_FOLDER_UID) { - $server_id = null; - } else { - $parts = $this->_parseFolderId($folder->serverid()); - $server_id = $parts[self::FOLDER_PART_ID]; - } + case 'RI': + $folder->setChanges($this->_connector->getRecipientCache($maxitems)); + $changes = [ + 'add' => $folder->added(), + 'delete' => $folder->removed(), + 'modify' => [], + 'soft' => []]; + break; - // Can't use History for first sync - if ($from_ts == 0 && !$ignoreFirstSync) { - try { - $changes['add'] = $this->_connector->notes_listUids($server_id); - } catch (Horde_Exception_AuthenticationFailure $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); + case Horde_ActiveSync::CLASS_EMAIL: + if (empty($this->_imap) || + $folder->serverid() == 'OUTBOX') { $this->_endBuffer(); - return array(); + return []; } - } else { - try { - $changes = $this->_connector->getChanges('notes', $from_ts, $to_ts, $server_id); - } catch (Horde_Exception_AuthenticationFailure $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return array(); - } - } - break; - - case 'RI': - $folder->setChanges($this->_connector->getRecipientCache($maxitems)); - $changes = array( - 'add' => $folder->added(), - 'delete' => $folder->removed(), - 'modify' => array(), - 'soft' => array()); - break; - - case Horde_ActiveSync::CLASS_EMAIL: - if (empty($this->_imap) || - $folder->serverid() == 'OUTBOX') { - $this->_endBuffer(); - return array(); - } - $this->_logger->meta(sprintf( - '%s IMAP PREVIOUS MODSEQ: %d', - $folder->serverid(), - $folder->modseq()) - ); - if ($ping) { - try { - $ping_res = $this->_imap->ping($folder); - if ($ping_res) { - $changes['add'] = array(1); + $this->_logger->meta( + sprintf( + '%s IMAP PREVIOUS MODSEQ: %d', + $folder->serverid(), + $folder->modseq() + ) + ); + if ($ping) { + try { + $ping_res = $this->_imap->ping($folder); + if ($ping_res) { + $changes['add'] = [1]; + } + } catch (Horde_ActiveSync_Exeption_StaleState $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_ActiveSync_Exception_FolderGone $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception_AuthenticationFailure $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return []; } - } catch (Horde_ActiveSync_Exeption_StaleState $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_ActiveSync_Exception_FolderGone $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception_AuthenticationFailure $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return array(); - } - } else { - // SOFTDELETE, but only if we aren't refreshing FILTERTYPE. - // @todo - Move the soft delete check(s) into the AS library. - $soft = false; - if (!$refreshFilter) { - $sd = $folder->getSoftDeleteTimes(); - if (empty($sd[0]) && empty($sd[1]) && !empty($cutoffdate)) { - // No SOFTDELETE performed, this is likely the first - // sync so we must prime the SOFTDELETE values. - $folder->setSoftDeleteTimes((int)$cutoffdate, time()); - } else { - if ($sd[1] + 82800 + mt_rand(0, 3600) < time()) { - $soft = true; + } else { + // SOFTDELETE, but only if we aren't refreshing FILTERTYPE. + // @todo - Move the soft delete check(s) into the AS library. + $soft = false; + if (!$refreshFilter) { + $sd = $folder->getSoftDeleteTimes(); + if (empty($sd[0]) && empty($sd[1]) && !empty($cutoffdate)) { + // No SOFTDELETE performed, this is likely the first + // sync so we must prime the SOFTDELETE values. + $folder->setSoftDeleteTimes((int)$cutoffdate, time()); } else { - $soft = false; + if ($sd[1] + 82800 + mt_rand(0, 3600) < time()) { + $soft = true; + } else { + $soft = false; + } } } - } - try { - $folder = $this->_imap->getMessageChanges( - $folder, - array( - 'sincedate' => (int)$cutoffdate, - 'protocolversion' => $this->_version, - 'softdelete' => $soft, - 'refreshfilter' => $refreshFilter - ) - ); - // Poll the maillog for reply/forward state changes. - if (empty($GLOBALS['conf']['activesync']['no_maillogsync'])) { - $folder = $this->_getMaillogChanges($folder, $from_ts); + try { + $folder = $this->_imap->getMessageChanges( + $folder, + [ + 'sincedate' => (int)$cutoffdate, + 'protocolversion' => $this->_version, + 'softdelete' => $soft, + 'refreshfilter' => $refreshFilter, + ] + ); + // Poll the maillog for reply/forward state changes. + if (empty($GLOBALS['conf']['activesync']['no_maillogsync'])) { + $folder = $this->_getMaillogChanges($folder, $from_ts); + } + } catch (Horde_ActiveSync_Exception_StaleState $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_ActiveSync_Exception_FolderGone $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception_AuthenticationFailure $e) { + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return []; } - } catch (Horde_ActiveSync_Exception_StaleState $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_ActiveSync_Exception_FolderGone $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception_AuthenticationFailure $e) { - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return array(); + $changes['add'] = $folder->added(); + $changes['delete'] = $folder->removed(); + $changes['modify'] = $folder->changed(); + $changes['soft'] = $folder->getSoftDeleted(); } - $changes['add'] = $folder->added(); - $changes['delete'] = $folder->removed(); - $changes['modify'] = $folder->changed(); - $changes['soft'] = $folder->getSoftDeleted(); - } } // Short circuit initial sync. @@ -1249,17 +1303,17 @@ public function getServerChanges( return $add; } - $results = array(); + $results = []; foreach ($changes['add'] as $add) { $type = ($folder->collectionClass() == Horde_ActiveSync::CLASS_EMAIL && $folder->serverid() == $this->getSpecialFolderNameByType(self::SPECIAL_DRAFTS)) ? Horde_ActiveSync::CHANGE_TYPE_DRAFT : Horde_ActiveSync::CHANGE_TYPE_CHANGE; - $results[] = array( + $results[] = [ 'id' => $add, 'type' => $type, - 'flags' => Horde_ActiveSync::FLAG_NEWMESSAGE - ); + 'flags' => Horde_ActiveSync::FLAG_NEWMESSAGE, + ]; } // For CLASS_EMAIL, all changes are a change in flags, categories or @@ -1268,34 +1322,34 @@ public function getServerChanges( $flags = $folder->flags(); $categories = $folder->categories(); foreach ($changes['modify'] as $uid) { - $results[] = array( + $results[] = [ 'id' => $uid, 'type' => Horde_ActiveSync::CHANGE_TYPE_FLAGS, 'flags' => $flags[$uid], - 'categories' => $categories[$uid] - ); + 'categories' => $categories[$uid], + ]; } } else { foreach ($changes['modify'] as $change) { - $results[] = array( + $results[] = [ 'id' => $change, - 'type' => Horde_ActiveSync::CHANGE_TYPE_CHANGE - ); + 'type' => Horde_ActiveSync::CHANGE_TYPE_CHANGE, + ]; } } // Server Deletions and Softdeletions foreach ($changes['delete'] as $deleted) { - $results[] = array( + $results[] = [ 'id' => $deleted, - 'type' => Horde_ActiveSync::CHANGE_TYPE_DELETE); + 'type' => Horde_ActiveSync::CHANGE_TYPE_DELETE]; } if (!empty($changes['soft'])) { foreach ($changes['soft'] as $deleted) { - $results[] = array( + $results[] = [ 'id' => $deleted, - 'type' => Horde_ActiveSync::CHANGE_TYPE_SOFTDELETE - ); + 'type' => Horde_ActiveSync::CHANGE_TYPE_SOFTDELETE, + ]; } } @@ -1327,10 +1381,12 @@ public function getServerChanges( */ public function getMessage($folderid, $id, array $collection) { - $this->_logger->meta(sprintf( - 'Horde_Core_ActiveSync_Driver::getMessage(%s, %s)', - $folderid, - $id) + $this->_logger->meta( + sprintf( + 'Horde_Core_ActiveSync_Driver::getMessage(%s, %s)', + $folderid, + $id + ) ); ob_start(); $message = false; @@ -1343,222 +1399,225 @@ public function getMessage($folderid, $id, array $collection) } switch ($folder_class) { - case Horde_ActiveSync::CLASS_CALENDAR: - // Explicitly set the calendar to search if we are not using - // multiplexed collections since multiple calendars may have - // the same event UID. - $folder_id = is_array($folder_split) ? $folder_split[self::FOLDER_PART_ID] : null; - try { - $message = $this->_connector->calendar_export($id, array( - 'protocolversion' => $this->_version, - 'truncation' => empty($collection['truncation']) ? Horde_ActiveSync::TRUNCATION_9 : $collection['truncation'], - 'bodyprefs' => $collection['bodyprefs'], - 'mimesupport' => $collection['mimesupport']), $folder_id); + case Horde_ActiveSync::CLASS_CALENDAR: + // Explicitly set the calendar to search if we are not using + // multiplexed collections since multiple calendars may have + // the same event UID. + $folder_id = is_array($folder_split) ? $folder_split[self::FOLDER_PART_ID] : null; + try { + $message = $this->_connector->calendar_export($id, [ + 'protocolversion' => $this->_version, + 'truncation' => empty($collection['truncation']) ? Horde_ActiveSync::TRUNCATION_9 : $collection['truncation'], + 'bodyprefs' => $collection['bodyprefs'], + 'mimesupport' => $collection['mimesupport']], $folder_id); - // Nokia MfE requires the optional UID element. - if (!$message->getUid()) { - $message->setUid($id); + // Nokia MfE requires the optional UID element. + if (!$message->getUid()) { + $message->setUid($id); + } + } catch (Horde_Exception_NotFound $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + throw new Horde_ActiveSync_Exception($e->getMessage()); } - } catch (Horde_Exception_NotFound $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - throw new Horde_ActiveSync_Exception($e->getMessage()); - } - break; + break; - case 'RI': - $id = explode(':', $id); - try { - $recipients = $this->_connector->contacts_search($id[0], array('recipient_cache_search' => true)); - } catch (Horde_Exception_NotFound $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - throw new Horde_ActiveSync_Exception($e->getMessage()); - } - if (is_array($recipients) && count($recipients)) { - $row = array_pop(array_pop($recipients)); - if (!count($row)) { - $row = array(); + case 'RI': + $id = explode(':', $id); + try { + $recipients = $this->_connector->contacts_search($id[0], ['recipient_cache_search' => true]); + } catch (Horde_Exception_NotFound $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + throw new Horde_ActiveSync_Exception($e->getMessage()); } - } else { - $row = array(); - } - $message = Horde_ActiveSync::messageFactory('RecipientInformation'); - $message->alias = !empty($row['alias']) ? $row['alias'] : $id[0]; - $message->email1address = !empty($row['email']) ? $row['email'] : $id[0]; - $message->fileas = empty($row['name']) ? $id[0] : $row['name']; - $message->weightedrank = $id[1] + 1; - break; - - case Horde_ActiveSync::CLASS_CONTACTS: - try { - $message = $this->_connector->contacts_export($id, array( - 'protocolversion' => $this->_version, - 'truncation' => empty($collection['truncation']) ? Horde_ActiveSync::TRUNCATION_9 : $collection['truncation'], - 'bodyprefs' => $collection['bodyprefs'], - 'mimesupport' => $collection['mimesupport'], - 'device' => $this->_device)); - } catch (Horde_Exception_NotFound $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - throw new Horde_ActiveSync_Exception($e->getMessage()); - } - break; + if (is_array($recipients) && count($recipients)) { + $row = array_pop(array_pop($recipients)); + if (!count($row)) { + $row = []; + } + } else { + $row = []; + } + $message = Horde_ActiveSync::messageFactory('RecipientInformation'); + $message->alias = !empty($row['alias']) ? $row['alias'] : $id[0]; + $message->email1address = !empty($row['email']) ? $row['email'] : $id[0]; + $message->fileas = empty($row['name']) ? $id[0] : $row['name']; + $message->weightedrank = $id[1] + 1; + break; - case Horde_ActiveSync::CLASS_TASKS: - try { - $message = $this->_connector->tasks_export($id, array( - 'protocolversion' => $this->_version, - 'truncation' => $collection['truncation'], - 'bodyprefs' => $collection['bodyprefs'], - 'mimesupport' => $collection['mimesupport'])); - } catch (Horde_Exception_NotFound $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - throw new Horde_ActiveSync_Exception($e->getMessage); - } - break; + case Horde_ActiveSync::CLASS_CONTACTS: + try { + $message = $this->_connector->contacts_export($id, [ + 'protocolversion' => $this->_version, + 'truncation' => empty($collection['truncation']) ? Horde_ActiveSync::TRUNCATION_9 : $collection['truncation'], + 'bodyprefs' => $collection['bodyprefs'], + 'mimesupport' => $collection['mimesupport'], + 'device' => $this->_device]); + } catch (Horde_Exception_NotFound $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + throw new Horde_ActiveSync_Exception($e->getMessage()); + } + break; - case Horde_ActiveSync::CLASS_NOTES: - try { - $message = $this->_connector->notes_export($id, array( - 'protocolversion' => $this->_version, - 'truncation' => $collection['truncation'], - 'bodyprefs' => $collection['bodyprefs'], - 'mimesupport' => $collection['mimesupport'])); - } catch (Horde_Exception_NotFound $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - throw $e; - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - throw new Horde_ActiveSync_Exception($e->getMessage); - } - break; + case Horde_ActiveSync::CLASS_TASKS: + try { + $message = $this->_connector->tasks_export($id, [ + 'protocolversion' => $this->_version, + 'truncation' => $collection['truncation'], + 'bodyprefs' => $collection['bodyprefs'], + 'mimesupport' => $collection['mimesupport']]); + } catch (Horde_Exception_NotFound $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + throw new Horde_ActiveSync_Exception($e->getMessage); + } + break; - case Horde_ActiveSync::CLASS_EMAIL: - // Get the message from the IMAP server. - try { - $messages = $this->_imap->getMessages( - $folderid, - array($id), - array( + case Horde_ActiveSync::CLASS_NOTES: + try { + $message = $this->_connector->notes_export($id, [ 'protocolversion' => $this->_version, - 'truncation' => !empty($collection['truncation']) + 'truncation' => $collection['truncation'], + 'bodyprefs' => $collection['bodyprefs'], + 'mimesupport' => $collection['mimesupport']]); + } catch (Horde_Exception_NotFound $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + throw $e; + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + throw new Horde_ActiveSync_Exception($e->getMessage); + } + break; + + case Horde_ActiveSync::CLASS_EMAIL: + // Get the message from the IMAP server. + try { + $messages = $this->_imap->getMessages( + $folderid, + [$id], + [ + 'protocolversion' => $this->_version, + 'truncation' => !empty($collection['truncation']) + ? $collection['truncation'] + : (!empty($collection['mimetruncation']) ? $collection['mimetruncation'] : false), + 'bodyprefs' => $collection['bodyprefs'], + 'bodypartprefs' => !empty($collection['bodypartprefs']) + ? $collection['bodypartprefs'] + : false, + 'mimesupport' => $collection['mimesupport'], + ] + ); + } catch (Horde_ActiveSync_Exception $e) { + $this->_logger->err($e->getMessage()); + $context = 'Protocol Version: ' . $this->_version . "\r\n" + . 'Truncation: ' . (!empty($collection['truncation']) ? $collection['truncation'] - : (!empty($collection['mimetruncation']) ? $collection['mimetruncation'] : false), - 'bodyprefs' => $collection['bodyprefs'], - 'bodypartprefs' => !empty($collection['bodypartprefs']) - ? $collection['bodypartprefs'] - : false, - 'mimesupport' => $collection['mimesupport'] - ) - ); - } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err($e->getMessage()); - $context = 'Protocol Version: ' . $this->_version . "\r\n" - . 'Truncation: ' . (!empty($collection['truncation']) - ? $collection['truncation'] - : (!empty($collection['mimetruncation']) ? $collection['mimetruncation'] : 'false') ). "\r\n" - . 'BodyPrefs: ' . print_r($collection['bodyprefs'], true) . "\r\n" - . 'BodyPartPrefs: ' . (!empty($collection['bodypartprefs']) - ? print_r($collection['bodypartprefs'], true) - : 'false') . "\r\n" - . 'MimeSupport: ' . $collection['mimesupport']; - - $this->_logger->err($context); + : (!empty($collection['mimetruncation']) ? $collection['mimetruncation'] : 'false')). "\r\n" + . 'BodyPrefs: ' . print_r($collection['bodyprefs'], true) . "\r\n" + . 'BodyPartPrefs: ' . (!empty($collection['bodypartprefs']) + ? print_r($collection['bodypartprefs'], true) + : 'false') . "\r\n" + . 'MimeSupport: ' . $collection['mimesupport']; - $this->_endBuffer(); - throw $e; - } - if (empty($messages)) { - $this->_endBuffer(); - throw new Horde_Exception_NotFound(); - } - $msg = array_pop($messages); + $this->_logger->err($context); - // Check for verb status from the Maillog. - if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEEN) { - $last = null; - if (!empty($msg->messageid)) { - $last = $this->_getLastVerb($msg->messageid); + $this->_endBuffer(); + throw $e; } - if (!empty($last)) { - switch ($last['action']) { - case 'reply': - case 'reply_list': - $msg->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_SENDER; - break; - case 'reply_all': - $msg->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_ALL; - break; - case 'forward': - $msg->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_FORWARD; + if (empty($messages)) { + $this->_endBuffer(); + throw new Horde_Exception_NotFound(); + } + $msg = array_pop($messages); + + // Check for verb status from the Maillog. + if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEEN) { + $last = null; + if (!empty($msg->messageid)) { + $last = $this->_getLastVerb($msg->messageid); } - $msg->lastverbexecutiontime = new Horde_Date($last['ts']); - } else { - // No maillog found, double check the IMAP flags. - // We favor the Maillog since EAS allows for a complete log - // of actions - and it requires a timestamp. - if ($msg->answered) { - $msg->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_SENDER; - $msg->lastverbexecutiontime = new Horde_Date(time()); - } elseif ($msg->forwarded) { - $msg->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_FORWARD; - $msg->lastverbexecutiontime = new Horde_Date(time()); + if (!empty($last)) { + switch ($last['action']) { + case 'reply': + case 'reply_list': + $msg->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_SENDER; + break; + case 'reply_all': + $msg->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_ALL; + break; + case 'forward': + $msg->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_FORWARD; + } + $msg->lastverbexecutiontime = new Horde_Date($last['ts']); + } else { + // No maillog found, double check the IMAP flags. + // We favor the Maillog since EAS allows for a complete log + // of actions - and it requires a timestamp. + if ($msg->answered) { + $msg->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_SENDER; + $msg->lastverbexecutiontime = new Horde_Date(time()); + } elseif ($msg->forwarded) { + $msg->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_FORWARD; + $msg->lastverbexecutiontime = new Horde_Date(time()); + } } } - } - // Is this from the draft folder? - if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN && - !empty($collection['type']) && - $collection['type'] == Horde_ActiveSync::FOLDER_TYPE_DRAFTS) { - $msg->isdraft = true; - } + // Is this from the draft folder? + if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN && + !empty($collection['type']) && + $collection['type'] == Horde_ActiveSync::FOLDER_TYPE_DRAFTS) { + $msg->isdraft = true; + } - $this->_endBuffer(); + $this->_endBuffer(); - // Should we import an iTip response if we have one and we are in - // the INBOX? - if ($folderid == 'INBOX' && - $this->_version >= Horde_ActiveSync::VERSION_TWELVE && - $msg->contentclass == 'urn:content-classes:calendarmessage') { - - switch ($msg->messageclass) { - case 'IPM.Schedule.Meeting.Resp.Pos': - case 'IPM.Schedule.Meeting.Resp.Neg': - case 'IPM.Schedule.Meeting.Resp.Tent': - $addr = new Horde_Mail_Rfc822_Address($msg->from); - $rq = $msg->meetingrequest; - $this->_connector->calendar_import_attendee( - $rq->getvEvent(), - $addr->bare_address); + // Should we import an iTip response if we have one and we are in + // the INBOX? + if ($folderid == 'INBOX' && + $this->_version >= Horde_ActiveSync::VERSION_TWELVE && + $msg->contentclass == 'urn:content-classes:calendarmessage') { + + switch ($msg->messageclass) { + case 'IPM.Schedule.Meeting.Resp.Pos': + case 'IPM.Schedule.Meeting.Resp.Neg': + case 'IPM.Schedule.Meeting.Resp.Tent': + $addr = new Horde_Mail_Rfc822_Address($msg->from); + $rq = $msg->meetingrequest; + $this->_connector->calendar_import_attendee( + $rq->getvEvent(), + $addr->bare_address + ); + } } - } - return $msg; + return $msg; - default: - $this->_endBuffer(); - throw new Horde_ActiveSync_Exception(sprintf( - 'Unsupported type: %s', $folder_class)); + default: + $this->_endBuffer(); + throw new Horde_ActiveSync_Exception(sprintf( + 'Unsupported type: %s', + $folder_class + )); } $this->_endBuffer(); @@ -1580,16 +1639,16 @@ public function getMessage($folderid, $id, array $collection) * array('content-type' => {the content-type of the attachement}, * 'data' => {the raw attachment data}) */ - public function getAttachment($name, array $options = array()) + public function getAttachment($name, array $options = []) { - $options = array_merge(array('stream' => true), $options); - list($mailbox, $uid, $part) = explode(':', $name); + $options = array_merge(['stream' => true], $options); + [$mailbox, $uid, $part] = explode(':', $name); $atc = $this->_imap->getAttachment($mailbox, $uid, $part); - return array( + return [ 'content-type' => $atc->getType(), - 'data' => $atc->getContents(array('stream' => $options['stream'])) - ); + 'data' => $atc->getContents(['stream' => $options['stream']]), + ]; } /** @@ -1606,15 +1665,17 @@ public function getAttachment($name, array $options = array()) * @return Horde_ActiveSync_Message_Base The message requested. */ public function itemOperationsFetchMailbox( - $longid, array $bodyprefs, $mimesupport = 0) - { - list($mailbox, $uid) = explode(':', $longid); + $longid, + array $bodyprefs, + $mimesupport = 0 + ) { + [$mailbox, $uid] = explode(':', $longid); return $this->getMessage( $mailbox, $uid, - array( + [ 'bodyprefs' => $bodyprefs, - 'mimesupport' => $mimesupport) + 'mimesupport' => $mimesupport] ); } @@ -1704,11 +1765,13 @@ public function statMessage($folderid, $id) */ public function deleteMessage($folderid, array $ids, $instanceids = false) { - $this->_logger->meta(sprintf( - 'Horde_Core_ActiveSync_Driver::deleteMessage() %s: %s %s', - $folderid, - print_r($ids, true), - $instanceids) + $this->_logger->meta( + sprintf( + 'Horde_Core_ActiveSync_Driver::deleteMessage() %s: %s %s', + $folderid, + print_r($ids, true), + $instanceids + ) ); $parts = $this->_parseFolderId($folderid); @@ -1723,104 +1786,108 @@ public function deleteMessage($folderid, array $ids, $instanceids = false) $results = $ids; switch ($class) { - case Horde_ActiveSync::CLASS_CALENDAR: - if ($instanceids) { - $instanceid = reset($ids); - $ids = key($ids); - } else { - $instanceid = false; - } - try { - $this->_logger->meta(sprintf( - 'calendar_delete: %s %s %s', - print_r($ids, true), $folder_id, $instanceid) - ); - $this->_connector->calendar_delete($ids, $folder_id, $instanceid); - } catch (Horde_Exception $e) { - // Since we don't get back successfully deleted ids and we can - // can pass an array of ids to delete, we need to see what ids - // were deleted if there was an error. - // @todo For Horde 6, the API should return successfully - // deleted ids. - $this->_logger->err($e->getMessage()); - $success = array(); - foreach ($ids as $uid) { - if ($mod_time = $this->_connector->calendar_getActionTimestamp($uid, 'delete', $folder_id)) { - $success[] = $uid; + case Horde_ActiveSync::CLASS_CALENDAR: + if ($instanceids) { + $instanceid = reset($ids); + $ids = key($ids); + } else { + $instanceid = false; + } + try { + $this->_logger->meta( + sprintf( + 'calendar_delete: %s %s %s', + print_r($ids, true), + $folder_id, + $instanceid + ) + ); + $this->_connector->calendar_delete($ids, $folder_id, $instanceid); + } catch (Horde_Exception $e) { + // Since we don't get back successfully deleted ids and we can + // can pass an array of ids to delete, we need to see what ids + // were deleted if there was an error. + // @todo For Horde 6, the API should return successfully + // deleted ids. + $this->_logger->err($e->getMessage()); + $success = []; + foreach ($ids as $uid) { + if ($mod_time = $this->_connector->calendar_getActionTimestamp($uid, 'delete', $folder_id)) { + $success[] = $uid; + } } + $results = $success; } - $results = $success; - } - break; + break; - case Horde_ActiveSync::CLASS_CONTACTS: - try { - $this->_connector->contacts_delete($ids); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - // Since we don't get back successfully deleted ids and we can - // can pass an array of ids to delete, we need to see what ids - // were deleted if there was an error. - // @todo For Horde 6, the API should return successfully - // deleted ids. - $this->_logger->err($e->getMessage()); - $success = array(); - foreach ($ids as $uid) { - if ($mod_time = $this->_connector->contacts_getActionTimestamp($uid, 'delete', $folder_id)) { - $success[] = $uid; + case Horde_ActiveSync::CLASS_CONTACTS: + try { + $this->_connector->contacts_delete($ids); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + // Since we don't get back successfully deleted ids and we can + // can pass an array of ids to delete, we need to see what ids + // were deleted if there was an error. + // @todo For Horde 6, the API should return successfully + // deleted ids. + $this->_logger->err($e->getMessage()); + $success = []; + foreach ($ids as $uid) { + if ($mod_time = $this->_connector->contacts_getActionTimestamp($uid, 'delete', $folder_id)) { + $success[] = $uid; + } } + $results = $success; } - $results = $success; - } - break; + break; - case Horde_ActiveSync::CLASS_TASKS: - try { - $this->_connector->tasks_delete($ids); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - // Since we don't get back successfully deleted ids and we can - // can pass an array of ids to delete, we need to see what ids - // were deleted if there was an error. - // @todo For Horde 6, the API should return successfully - // deleted ids. - $this->_logger->err($e->getMessage()); - $success = array(); - foreach ($ids as $uid) { - if ($mod_time = $this->_connector->tasks_getActionTimestamp($uid, 'delete', $folder_id)) { - $success[] = $uid; + case Horde_ActiveSync::CLASS_TASKS: + try { + $this->_connector->tasks_delete($ids); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + // Since we don't get back successfully deleted ids and we can + // can pass an array of ids to delete, we need to see what ids + // were deleted if there was an error. + // @todo For Horde 6, the API should return successfully + // deleted ids. + $this->_logger->err($e->getMessage()); + $success = []; + foreach ($ids as $uid) { + if ($mod_time = $this->_connector->tasks_getActionTimestamp($uid, 'delete', $folder_id)) { + $success[] = $uid; + } } + $results = $success; } - $results = $success; - } - break; + break; - case Horde_ActiveSync::CLASS_NOTES: - try { - $this->_connector->notes_delete($ids); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - // Since we don't get back successfully deleted ids and we can - // can pass an array of ids to delete, we need to see what ids - // were deleted if there was an error. - // @todo For Horde 6, the API should return successfully - // deleted ids. - $success = array(); - foreach ($ids as $uid) { - if ($mod_time = $this->_connector->tasks_getActionTimestamp($uid, 'delete', $folder_id)) { - $success[] = $uid; + case Horde_ActiveSync::CLASS_NOTES: + try { + $this->_connector->notes_delete($ids); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + // Since we don't get back successfully deleted ids and we can + // can pass an array of ids to delete, we need to see what ids + // were deleted if there was an error. + // @todo For Horde 6, the API should return successfully + // deleted ids. + $success = []; + foreach ($ids as $uid) { + if ($mod_time = $this->_connector->tasks_getActionTimestamp($uid, 'delete', $folder_id)) { + $success[] = $uid; + } } + $results = $success; + } + break; + default: + // Must be mail folder + try { + $results = $this->_imap->deleteMessages($ids, $folderid); + } catch (Horde_ActiveSync_Exception $e) { + $this->_logger->err($e->getMessage()); } - $results = $success; - } - break; - default: - // Must be mail folder - try { - $results = $this->_imap->deleteMessages($ids, $folderid); - } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err($e->getMessage()); - } } $this->_endBuffer(); @@ -1843,11 +1910,13 @@ public function deleteMessage($folderid, array $ids, $instanceids = false) */ public function moveMessage($folderid, array $ids, $newfolderid) { - $this->_logger->meta(sprintf( - 'Horde_Core_ActiveSync_Driver::moveMessage(%s, [%s], %s)', - $folderid, - implode(',', $ids), - $newfolderid) + $this->_logger->meta( + sprintf( + 'Horde_Core_ActiveSync_Driver::moveMessage(%s, [%s], %s)', + $folderid, + implode(',', $ids), + $newfolderid + ) ); $parts = $this->_parseFolderId($folderid); @@ -1858,26 +1927,26 @@ public function moveMessage($folderid, array $ids, $newfolderid) $folder_class = $parts; $folder_id = null; } - $move_res = array(); + $move_res = []; ob_start(); switch ($folder_class) { - case Horde_ActiveSync::CLASS_CALENDAR: - $parts = $this->_parseFolderId($newfolderid); - if (is_array($parts)) { - $newfolderid = $parts[self::FOLDER_PART_ID]; - } - if ($res = $this->_connector->calendar_move(array_pop($ids), $folder_id, $newfolderid)) { - $move_res[$res] = $res; - } - break; - case Horde_ActiveSync::CLASS_CONTACTS: - case Horde_ActiveSync::CLASS_TASKS: - case Horde_ActiveSync::CLASS_NOTES: - $this->_endBuffer(); - // Not supported, so just drop through to return the empty array. - break; - default: - $move_res = $this->_imap->moveMessage($folderid, $ids, $newfolderid); + case Horde_ActiveSync::CLASS_CALENDAR: + $parts = $this->_parseFolderId($newfolderid); + if (is_array($parts)) { + $newfolderid = $parts[self::FOLDER_PART_ID]; + } + if ($res = $this->_connector->calendar_move(array_pop($ids), $folder_id, $newfolderid)) { + $move_res[$res] = $res; + } + break; + case Horde_ActiveSync::CLASS_CONTACTS: + case Horde_ActiveSync::CLASS_TASKS: + case Horde_ActiveSync::CLASS_NOTES: + $this->_endBuffer(); + // Not supported, so just drop through to return the empty array. + break; + default: + $move_res = $this->_imap->moveMessage($folderid, $ids, $newfolderid); } $this->_endBuffer(); @@ -1911,10 +1980,12 @@ public function moveMessage($folderid, array $ids, $newfolderid) */ public function changeMessage($folderid, $id, Horde_ActiveSync_Message_Base $message, $device) { - $this->_logger->meta(sprintf( - 'Horde_Core_ActiveSync_Driver::changeMessage(%s, %s ...)', - $folderid, - $id) + $this->_logger->meta( + sprintf( + 'Horde_Core_ActiveSync_Driver::changeMessage(%s, %s ...)', + $folderid, + $id + ) ); // Short circuit OUTBOX modifications to work around broken clients. @@ -1924,211 +1995,214 @@ public function changeMessage($folderid, $id, Horde_ActiveSync_Message_Base $mes ob_start(); - $folder_split = $this->_parseFolderId($folderid); - if (is_array($folder_split)) { - $folder_class = $folder_split[self::FOLDER_PART_CLASS]; - $server_id = $folder_split[self::FOLDER_PART_ID]; - } else { - $folder_class = $folder_split; - $server_id = null; - } - - $stat = false; - - switch ($folder_class) { - case Horde_ActiveSync::CLASS_CALENDAR: - if (!$id) { - try { - // @todo, remove 'import16' hack for H6 - $results = $this->_connector->calendar_import16($message, $server_id); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return false; - } - $stat = array( - 'mod' => $this->getSyncStamp($folderid), - 'id' => $results['uid'], - 'flags' => 1, - 'atchash' => $results['atchash'] - ); - } else { - // ActiveSync messages do NOT contain the serverUID value, put - // it in ourselves so we can have it during import/change. - $message->setServerUID($id); - try { - $results = $this->_connector->calendar_replace($id, $message, $server_id); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return false; - } - $stat = $this->_smartStatMessage($folderid, $id, false); - // @todo Remove this check in H6, when the API always returns. - if (!empty($results)) { - $stat['atchash'] = !empty($results['atchash']) - ? $results['atchash'] - : false; - } - } - break; + $folder_split = $this->_parseFolderId($folderid); + if (is_array($folder_split)) { + $folder_class = $folder_split[self::FOLDER_PART_CLASS]; + $server_id = $folder_split[self::FOLDER_PART_ID]; + } else { + $folder_class = $folder_split; + $server_id = null; + } - case Horde_ActiveSync::CLASS_CONTACTS: - if (!$id) { - try { - $id = $this->_connector->contacts_import($message, $server_id); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return false; - } - $stat = array('mod' => $this->getSyncStamp($folderid), 'id' => $id, 'flags' => 1); - } else { - try { - $this->_connector->contacts_replace($id, $message); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return false; - } - $stat = $this->_smartStatMessage($folderid, $id, false); - } - break; + $stat = false; - case Horde_ActiveSync::CLASS_TASKS: - if (!$id) { - try { - $id = $this->_connector->tasks_import($message, $server_id); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return false; - } - $stat = array('mod' => $this->getSyncStamp($folderid), 'id' => $id, 'flags' => 1); - } else { - try { - $this->_connector->tasks_replace($id, $message); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return false; + switch ($folder_class) { + case Horde_ActiveSync::CLASS_CALENDAR: + if (!$id) { + try { + // @todo, remove 'import16' hack for H6 + $results = $this->_connector->calendar_import16($message, $server_id); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return false; + } + $stat = [ + 'mod' => $this->getSyncStamp($folderid), + 'id' => $results['uid'], + 'flags' => 1, + 'atchash' => $results['atchash'], + ]; + } else { + // ActiveSync messages do NOT contain the serverUID value, put + // it in ourselves so we can have it during import/change. + $message->setServerUID($id); + try { + $results = $this->_connector->calendar_replace($id, $message, $server_id); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return false; + } + $stat = $this->_smartStatMessage($folderid, $id, false); + // @todo Remove this check in H6, when the API always returns. + if (!empty($results)) { + $stat['atchash'] = !empty($results['atchash']) + ? $results['atchash'] + : false; + } } - $stat = $this->_smartStatMessage($folderid, $id, false); - } - break; + break; - case Horde_ActiveSync::CLASS_NOTES: - if (!$id) { - try { - $id = $this->_connector->notes_import($message, $server_id); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return false; - } - $stat = array('mod' => $this->getSyncStamp($folderid), 'id' => $id, 'flags' => 1); - } else { - try { - $this->_connector->notes_replace($id, $message); - } catch (Horde_Exception $e) { - $this->_logger->err($e->getMessage()); - $this->_endBuffer(); - return false; + case Horde_ActiveSync::CLASS_CONTACTS: + if (!$id) { + try { + $id = $this->_connector->contacts_import($message, $server_id); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return false; + } + $stat = ['mod' => $this->getSyncStamp($folderid), 'id' => $id, 'flags' => 1]; + } else { + try { + $this->_connector->contacts_replace($id, $message); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return false; + } + $stat = $this->_smartStatMessage($folderid, $id, false); } - $stat = $this->_smartStatMessage($folderid, $id, false); - } - break; - - default: - if ($message instanceof Horde_ActiveSync_Message_Mail) { - $stat = array( - 'id' => $id, - 'mod' => 0, - 'flags' => array(), - 'categories' => false - ); - - // Check for draft sync. - if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN && - $folderid == $this->getSpecialFolderNameByType(self::SPECIAL_DRAFTS)) { + break; - // @todo Does this only happen on drafts? - if ($message->send) { - $this->_logger->err('NOT YET SUPPORTED.'); - return $stat; + case Horde_ActiveSync::CLASS_TASKS: + if (!$id) { + try { + $id = $this->_connector->tasks_import($message, $server_id); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return false; + } + $stat = ['mod' => $this->getSyncStamp($folderid), 'id' => $id, 'flags' => 1]; + } else { + try { + $this->_connector->tasks_replace($id, $message); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return false; } + $stat = $this->_smartStatMessage($folderid, $id, false); + } + break; - // Are we addding/changing a draft email? - if ($message->airsyncbasebody) { - $draft_folder = $this->getSpecialFolderNameByType( - self::SPECIAL_DRAFTS - ); - $draft = new Horde_Core_ActiveSync_Mail_Draft( - $this->_imap, - $this->_user, - $this->_version - ); - $draft->setDraftMessage($message); + case Horde_ActiveSync::CLASS_NOTES: + if (!$id) { + try { + $id = $this->_connector->notes_import($message, $server_id); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return false; + } + $stat = ['mod' => $this->getSyncStamp($folderid), 'id' => $id, 'flags' => 1]; + } else { + try { + $this->_connector->notes_replace($id, $message); + } catch (Horde_Exception $e) { + $this->_logger->err($e->getMessage()); + $this->_endBuffer(); + return false; + } + $stat = $this->_smartStatMessage($folderid, $id, false); + } + break; - // Do we need an existing Draft message? - if ($id && !empty($message->airsyncbaseattachments)) { - $draft->getExistingDraftMessage($draft_folder, $id); + default: + if ($message instanceof Horde_ActiveSync_Message_Mail) { + $stat = [ + 'id' => $id, + 'mod' => 0, + 'flags' => [], + 'categories' => false, + ]; + + // Check for draft sync. + if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN && + $folderid == $this->getSpecialFolderNameByType(self::SPECIAL_DRAFTS)) { + + // @todo Does this only happen on drafts? + if ($message->send) { + $this->_logger->err('NOT YET SUPPORTED.'); + return $stat; } - // Append the message and return results. - $results = $draft->append($draft_folder); - $stat['id'] = $results['uid']; - $stat['atchash'] = $results['atchash']; - $stat['conversationid'] = bin2hex($message->subject); - $stat['conversationindex'] = time(); + // Are we addding/changing a draft email? + if ($message->airsyncbasebody) { + $draft_folder = $this->getSpecialFolderNameByType( + self::SPECIAL_DRAFTS + ); + $draft = new Horde_Core_ActiveSync_Mail_Draft( + $this->_imap, + $this->_user, + $this->_version + ); + $draft->setDraftMessage($message); - return $stat; - } - } + // Do we need an existing Draft message? + if ($id && !empty($message->airsyncbaseattachments)) { + $draft->getExistingDraftMessage($draft_folder, $id); + } - if ($message->read !== '') { - $this->setReadFlag($folderid, $id, $message->read); - $stat['flags'] = array_merge( - $stat['flags'], - array('read' => $message->read) - ); + // Append the message and return results. + $results = $draft->append($draft_folder); + $stat['id'] = $results['uid']; + $stat['atchash'] = $results['atchash']; + $stat['conversationid'] = bin2hex($message->subject); + $stat['conversationindex'] = time(); - // Do RFC 3798 MDN checks. If $message->read is being set to - // FLAG_READ_SEEN, then we *might* be able to send one. - if ($message->read == Horde_ActiveSync_Message_Mail::FLAG_READ_SEEN) { - $this->_logger->meta('Checking for MDN'); - $mdn = new Horde_Core_ActiveSync_Mdn( - $folderid, $id, $this->_imap, $this->_connector + return $stat; + } + } + + if ($message->read !== '') { + $this->setReadFlag($folderid, $id, $message->read); + $stat['flags'] = array_merge( + $stat['flags'], + ['read' => $message->read] ); - if ($mdn->mdnCheck()) { - $this->_logger->meta('Sending MDN'); + + // Do RFC 3798 MDN checks. If $message->read is being set to + // FLAG_READ_SEEN, then we *might* be able to send one. + if ($message->read == Horde_ActiveSync_Message_Mail::FLAG_READ_SEEN) { + $this->_logger->meta('Checking for MDN'); + $mdn = new Horde_Core_ActiveSync_Mdn( + $folderid, + $id, + $this->_imap, + $this->_connector + ); + if ($mdn->mdnCheck()) { + $this->_logger->meta('Sending MDN'); + } } } - } - if ($message->propertyExists('flag')) { - if (!$message->flag) { - $message->flag = Horde_ActiveSync::messageFactory('Flag'); + if ($message->propertyExists('flag')) { + if (!$message->flag) { + $message->flag = Horde_ActiveSync::messageFactory('Flag'); + } + $this->_imap->setMessageFlag($folderid, $id, $message->flag); + $stat['flags'] = array_merge( + $stat['flags'], + ['flagged' => $message->flag->flagstatus] + ); } - $this->_imap->setMessageFlag($folderid, $id, $message->flag); - $stat['flags'] = array_merge( - $stat['flags'], - array('flagged' => $message->flag->flagstatus) - ); - } - if ($message->propertyExists('categories') && - $message->categories) { - // We *try* to make sure the category is added as a custom - // IMAP flag. This might fail in some edge cases, like e.g. - // with non-ascii characters. - $this->_connector->mail_ensureMessageFlags($message->categories); - $this->_imap->categoriesToFlags($folderid, $message->categories, $id); - $stat['categories'] = $message->categories; + if ($message->propertyExists('categories') && + $message->categories) { + // We *try* to make sure the category is added as a custom + // IMAP flag. This might fail in some edge cases, like e.g. + // with non-ascii characters. + $this->_connector->mail_ensureMessageFlags($message->categories); + $this->_imap->categoriesToFlags($folderid, $message->categories, $id); + $stat['categories'] = $message->categories; + } + } else { + $this->_endBuffer(); + return false; } - } else { - $this->_endBuffer(); - return false; - } } $this->_endBuffer(); @@ -2159,52 +2233,52 @@ public function changeMessage($folderid, $id, Horde_ActiveSync_Message_Base $mes public function getSearchResults($type, array $query) { switch (Horde_String::lower($type)) { - case 'gal': - return $this->_searchGal($query); - case 'mailbox': - if (!empty($this->_cache)) { - $clear_cache = !empty($query['rebuildresults']); - unset($query['rebuildresults']); - $cache_key = $GLOBALS['registry']->getAuth() . ':HCASD:' . hash('md5', serialize($query)); - if ($clear_cache) { - $this->_cache->expire($cache_key); + case 'gal': + return $this->_searchGal($query); + case 'mailbox': + if (!empty($this->_cache)) { + $clear_cache = !empty($query['rebuildresults']); + unset($query['rebuildresults']); + $cache_key = $GLOBALS['registry']->getAuth() . ':HCASD:' . hash('md5', serialize($query)); + if ($clear_cache) { + $this->_cache->expire($cache_key); + } } - } - if (!empty($this->_cache) && $this->_cache->exists($cache_key, 0)) { - $results = json_decode($this->_cache->get($cache_key, 0), true); - } else { - try { - $results = $this->_searchMailbox($query); - if (!empty($this->_cache)) { - $this->_cache->set($cache_key, json_encode($results)); + if (!empty($this->_cache) && $this->_cache->exists($cache_key, 0)) { + $results = json_decode($this->_cache->get($cache_key, 0), true); + } else { + try { + $results = $this->_searchMailbox($query); + if (!empty($this->_cache)) { + $this->_cache->set($cache_key, json_encode($results)); + } + } catch (Horde_ActiveSync_Exception $e) { + $this->_logger->err($e->getMessage()); + $results = []; } - } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err($e->getMessage()); - $results = array(); } - } - $count = count($results); - if (!empty($query['range'])) { - $range = explode('-', $query['range']); - $results = array_slice($results, $range[0], $range[1] - $range[0] + 1); - } - return array( - 'rows' => $results, - 'total' => $count, - 'status' => Horde_ActiveSync_Request_Search::STORE_STATUS_SUCCESS); + $count = count($results); + if (!empty($query['range'])) { + $range = explode('-', $query['range']); + $results = array_slice($results, $range[0], $range[1] - $range[0] + 1); + } + return [ + 'rows' => $results, + 'total' => $count, + 'status' => Horde_ActiveSync_Request_Search::STORE_STATUS_SUCCESS]; - case 'documentlibrary': - foreach ($query['query'][0] as $q) { - if (!empty($q['DocumentLibrary:LinkId'])) { - $results = $this->_connector->files_browse($q['DocumentLibrary:LinkId']); + case 'documentlibrary': + foreach ($query['query'][0] as $q) { + if (!empty($q['DocumentLibrary:LinkId'])) { + $results = $this->_connector->files_browse($q['DocumentLibrary:LinkId']); + } } - } - return array( - 'rows' => $results, - 'total' => count($results), - 'status' => Horde_ActiveSync_Request_Search::STORE_STATUS_SUCCESS - ); + return [ + 'rows' => $results, + 'total' => count($results), + 'status' => Horde_ActiveSync_Request_Search::STORE_STATUS_SUCCESS, + ]; } } @@ -2229,14 +2303,18 @@ public function getSearchResults($type, array $query) * @throws Horde_ActiveSync_Exception */ public function sendMail( - $rfc822, $forward = false, $reply = false, $parent = false, $save = true, - Horde_ActiveSync_Message_SendMail $message = null) - { + $rfc822, + $forward = false, + $reply = false, + $parent = false, + $save = true, + ?Horde_ActiveSync_Message_SendMail $message = null + ) { // Ignore if we do not support email operations. // @TODO: This assumes the only way to not have an imap object is // if we turn off email support. We should probably make this a flag. if (empty($this->_imap)) { - $this->_logger->notice("No IMAP object. Ignoring."); + $this->_logger->notice('No IMAP object. Ignoring.'); return true; } @@ -2257,7 +2335,7 @@ public function sendMail( if ($forward || $reply) { $source = $message->source; if ($source->longid) { - list($folderid, $itemid) = explode(':', $source, 2); + [$folderid, $itemid] = explode(':', $source, 2); } elseif ($forward === true || $reply === true) { $folderid = $source->folderid; $itemid = $source->itemid; @@ -2269,7 +2347,7 @@ public function sendMail( if (!empty($message) && !empty($message->forwardees)) { $fowardees = $message->forwardees; } else { - $forwardees = array(); + $forwardees = []; } $mailer->setForward($folderid, $itemid, $forwardees); } elseif (!empty($forward)) { @@ -2289,15 +2367,19 @@ public function sendMail( try { $mailer->send(); - $this->_logger->meta(sprintf( - 'Message-ID: \'%s\' successfully sent.', - $mailer->headers['Message-ID']) + $this->_logger->meta( + sprintf( + 'Message-ID: \'%s\' successfully sent.', + $mailer->headers['Message-ID'] + ) ); } catch (Horde_ActiveSync_Exception $e) { $this->_logger->err($e->getMessage()); - $this->_logger->err(sprintf( - 'Message headers: %s', - $mailer->headers->toString()) + $this->_logger->err( + sprintf( + 'Message headers: %s', + $mailer->headers->toString() + ) ); $this->_endBuffer(); throw $e; @@ -2306,21 +2388,25 @@ public function sendMail( if ($save) { $sf = $this->getSpecialFolderNameByType(self::SPECIAL_SENT); if (!empty($sf)) { - $this->_logger->meta(sprintf( - 'Preparing to copy Message-ID: \'%s\' to \'%s\'.', - $mailer->headers['Message-ID'], - $sf) + $this->_logger->meta( + sprintf( + 'Preparing to copy Message-ID: \'%s\' to \'%s\'.', + $mailer->headers['Message-ID'], + $sf + ) ); - $flags = array(Horde_Imap_Client::FLAG_SEEN); + $flags = [Horde_Imap_Client::FLAG_SEEN]; // Ignore issues sending to sent, in case the folder isn't // available. try { $this->_imap->appendMessage($sf, $mailer->getSentMail(), $flags); - $this->_logger->meta(sprintf( - 'Message-ID: \'%s\' appended to \'%s\'.', - $mailer->headers['Message-ID'], - $sf) + $this->_logger->meta( + sprintf( + 'Message-ID: \'%s\' appended to \'%s\'.', + $mailer->headers['Message-ID'], + $sf + ) ); } catch (Horde_ActiveSync_Exception $e) { $this->_logger->err($e->getMessage()); @@ -2330,11 +2416,13 @@ public function sendMail( // Attempt to write forward/reply state. if ($this->_version > Horde_ActiveSync::VERSION_TWELVEONE && $mailer->id) { - $this->_logger->meta(sprintf( - 'Logging LASTVERBEXECUTED to Maillog: %s, %s, %s', - $mailer->reply ? 'reply' : 'forward', - $mailer->imapMessage->getHeaders()->getValue('Message-ID'), - $mailer->headers->getValue('To')) + $this->_logger->meta( + sprintf( + 'Logging LASTVERBEXECUTED to Maillog: %s, %s, %s', + $mailer->reply ? 'reply' : 'forward', + $mailer->imapMessage->getHeaders()->getValue('Message-ID'), + $mailer->headers->getValue('To') + ) ); $this->_connector->mail_logMaillog( $mailer->reply ? 'reply' : 'forward', @@ -2358,7 +2446,10 @@ public function sendMail( : ($mailer->forward ? 'forward' : 'new'); try { $this->_connector->mail_logRecipient( - $action, $mailer->headers->getValue('To'), $mailer->headers->getValue('Message-ID')); + $action, + $mailer->headers->getValue('To'), + $mailer->headers->getValue('Message-ID') + ); } catch (Horde_Exception $e) { $this->_logger->err($e->getMessage()); } @@ -2417,10 +2508,10 @@ public function statMailMessage($folderid, $id) // I can't think of a time when we would actually need to hit the // server. As long as 'mod' is 0, this should be fine as we don't // track flag conflicts. - return array( + return [ 'id' => $id, 'mod' => 0, - 'flags' => false); + 'flags' => false]; } /** @@ -2442,23 +2533,25 @@ public function getCurrentPolicy($device = false) * * @return mixed The value of the provisiong support flag. */ - public function getProvisioning(Horde_ActiveSync_Device $device = null) + public function getProvisioning(?Horde_ActiveSync_Device $device = null) { if (!empty($device)) { try { $hooks = $GLOBALS['injector']->getInstance('Horde_Core_Hooks'); - $result = $hooks->callHook('activesync_provisioning_check', 'horde', array($device, $this->_user)); + $result = $hooks->callHook('activesync_provisioning_check', 'horde', [$device, $this->_user]); if ($result !== -1) { return $result; } - } catch (Horde_Exception_HookNotSet $e) {} + } catch (Horde_Exception_HookNotSet $e) { + } } $provisioning = $GLOBALS['injector'] ->getInstance('Horde_Perms') ->getPermissions( 'horde:activesync:provisioning', - $this->_user); + $this->_user + ); return $this->_getPolicyValue('provisioning', $provisioning); } @@ -2491,74 +2584,74 @@ public function getSettings(array $settings, $device) { global $injector, $prefs, $registry; - $res = array(); + $res = []; foreach ($settings as $key => $setting) { switch ($key) { - case 'oof': - if (!$vacation = $this->_connector->filters_getVacation()) { - $res['oof'] = array( + case 'oof': + if (!$vacation = $this->_connector->filters_getVacation()) { + $res['oof'] = [ + 'status' => Horde_ActiveSync_Request_Settings::STATUS_SUCCESS, + 'oofstate' => Horde_ActiveSync_Request_Settings::OOF_STATE_DISABLED, + 'oofmsgs' => [], + ]; + break; + } + $res['oof'] = [ 'status' => Horde_ActiveSync_Request_Settings::STATUS_SUCCESS, - 'oofstate' => Horde_ActiveSync_Request_Settings::OOF_STATE_DISABLED, - 'oofmsgs' => array() - ); + 'oofstate' => ($vacation['disabled'] + ? Horde_ActiveSync_Request_Settings::OOF_STATE_DISABLED + : Horde_ActiveSync_Request_Settings::OOF_STATE_ENABLED), + 'oofmsgs' => [], + ]; + // If we have start/end it's a timebased vacation in EAS-speak. + if (!empty($vacation['end']) && !$vacation['disabled']) { + $res['oof']['oofstate'] = Horde_ActiveSync_Request_Settings::OOF_STATE_TIMEBASED; + $res['oof']['starttime'] = new Horde_Date($vacation['start']); + $res['oof']['endtime'] = new Horde_Date($vacation['end']); + } + // Horde's filter API doesn't support internal/external so + // always send as internal since that's what most clients + // fall back to as well. + $res['oof']['oofmsgs'][] = [ + 'appliesto' => Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOINTERNAL, + 'replymessage' => $vacation['reason'], + 'enabled' => !$vacation['disabled'], + 'bodytype' => $setting['bodytype'], + 'subject' => $vacation['subject'], + ]; break; - } - $res['oof'] = array( - 'status' => Horde_ActiveSync_Request_Settings::STATUS_SUCCESS, - 'oofstate' => ($vacation['disabled'] - ? Horde_ActiveSync_Request_Settings::OOF_STATE_DISABLED - : Horde_ActiveSync_Request_Settings::OOF_STATE_ENABLED), - 'oofmsgs' => array() - ); - // If we have start/end it's a timebased vacation in EAS-speak. - if (!empty($vacation['end']) && !$vacation['disabled']) { - $res['oof']['oofstate'] = Horde_ActiveSync_Request_Settings::OOF_STATE_TIMEBASED; - $res['oof']['starttime'] = new Horde_Date($vacation['start']); - $res['oof']['endtime'] = new Horde_Date($vacation['end']); - } - // Horde's filter API doesn't support internal/external so - // always send as internal since that's what most clients - // fall back to as well. - $res['oof']['oofmsgs'][] = array( - 'appliesto' => Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOINTERNAL, - 'replymessage' => $vacation['reason'], - 'enabled' => !$vacation['disabled'], - 'bodytype' => $setting['bodytype'], - 'subject' => $vacation['subject'], - ); - break; - case 'userinformation': - $identities = $injector - ->getInstance('Horde_Core_Factory_Identity') - ->create($registry->getAuth()); - $as_ident = $prefs->getValue('activesync_identity'); - if ($as_ident != 'horde') { - $identities->setDefault($prefs->getValue('activesync_identity')); - } else { - $as_ident = $identities->getDefault(); - } - $default_email = $identities->getValue('from_addr'); - $email_addresses = array($default_email); - $accounts = array(); - if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEENONE) { - $identity = $identities->get(); - $emails = !empty($identity['alias_addr']) ? $identity['alias_addr'] : array(); - $emails[] = $identity['from_addr']; - $accounts[] = array('fullname' => $identity['fullname'], 'emailaddresses' => array_reverse($emails), 'accountname' => $identity['id']); - foreach ($identities as $id => $identity) { - if ($id != $as_ident) { - $emails = !empty($identity['alias_addr']) ? $identity['alias_addr'] : array(); - $emails[] = $identity['from_addr']; - $accounts[] = array('fullname' => $identity['fullname'], 'emailaddresses' => array_reverse($emails), 'accountname' => $identity['id'], 'id' => $id); + case 'userinformation': + $identities = $injector + ->getInstance('Horde_Core_Factory_Identity') + ->create($registry->getAuth()); + $as_ident = $prefs->getValue('activesync_identity'); + if ($as_ident != 'horde') { + $identities->setDefault($prefs->getValue('activesync_identity')); + } else { + $as_ident = $identities->getDefault(); + } + $default_email = $identities->getValue('from_addr'); + $email_addresses = [$default_email]; + $accounts = []; + if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEENONE) { + $identity = $identities->get(); + $emails = !empty($identity['alias_addr']) ? $identity['alias_addr'] : []; + $emails[] = $identity['from_addr']; + $accounts[] = ['fullname' => $identity['fullname'], 'emailaddresses' => array_reverse($emails), 'accountname' => $identity['id']]; + foreach ($identities as $id => $identity) { + if ($id != $as_ident) { + $emails = !empty($identity['alias_addr']) ? $identity['alias_addr'] : []; + $emails[] = $identity['from_addr']; + $accounts[] = ['fullname' => $identity['fullname'], 'emailaddresses' => array_reverse($emails), 'accountname' => $identity['id'], 'id' => $id]; + } } } - } - $res['userinformation'] = array( - 'emailaddresses' => $email_addresses, - 'primarysmtpaddress' => $default_email, - 'status' => Horde_ActiveSync_Request_Settings::STATUS_SUCCESS, - 'accounts' => $accounts - ); + $res['userinformation'] = [ + 'emailaddresses' => $email_addresses, + 'primarysmtpaddress' => $default_email, + 'status' => Horde_ActiveSync_Request_Settings::STATUS_SUCCESS, + 'accounts' => $accounts, + ]; } } @@ -2578,17 +2671,17 @@ public function getSettings(array $settings, $device) */ public function setSettings(array $settings, $device) { - $res = array(); + $res = []; foreach ($settings as $key => $setting) { switch ($key) { - case 'oof': - try { - $this->_connector->filters_setVacation($setting); - $res['oof'] = Horde_ActiveSync_Request_Settings::STATUS_SUCCESS; - } catch (Horde_Exception $e) { - $res['oof'] = Horde_ActiveSync_Request_Settings::STATUS_ERROR; - } - break; + case 'oof': + try { + $this->_connector->filters_setVacation($setting); + $res['oof'] = Horde_ActiveSync_Request_Settings::STATUS_SUCCESS; + } catch (Horde_Exception $e) { + $res['oof'] = Horde_ActiveSync_Request_Settings::STATUS_ERROR; + } + break; } } @@ -2609,7 +2702,7 @@ public function setSettings(array $settings, $device) * ActiveSync server will use to build the response, or * the raw XML response contained in the raw_xml key. */ - public function autoDiscover($params = array(), $version = 1) + public function autoDiscover($params = [], $version = 1) { $hooks = $GLOBALS['injector']->getInstance('Horde_Core_Hooks'); $url = parse_url((string)Horde::url(null, true)); @@ -2617,7 +2710,7 @@ public function autoDiscover($params = array(), $version = 1) if ($version == 2) { if (Horde_String::lower($params['protocol']) == 'autodiscoverv1') { $params['url'] = $url['scheme'] . '://' . $url['host'] . '/Autodiscover/Autodiscover.xml'; - } else if (Horde_String::lower($params['protocol']) == 'activesync') { + } elseif (Horde_String::lower($params['protocol']) == 'activesync') { $params['url'] = $url['scheme'] . '://' . $url['host'] . '/Microsoft-Server-ActiveSync'; } return $params; @@ -2634,9 +2727,10 @@ public function autoDiscover($params = array(), $version = 1) $params['culture'] = 'en:en'; $params['username'] = $this->getUsernameFromEmail($params['email']); try { - $xml = $hooks->callHook('activesync_autodiscover_xml', 'horde', array($params)); - return array('raw_xml' => $xml); - } catch (Horde_Exception_HookNotSet $e) {} + $xml = $hooks->callHook('activesync_autodiscover_xml', 'horde', [$params]); + return ['raw_xml' => $xml]; + } catch (Horde_Exception_HookNotSet $e) { + } // Bring in the host configuration if needed. if (!empty($GLOBALS['conf']['activesync']['outlookdiscovery'])) { @@ -2659,8 +2753,9 @@ public function autoDiscover($params = array(), $version = 1) } try { - $params = $hooks->callHook('activesync_autodiscover_parameters', 'horde', array($params)); - } catch (Horde_Exception_HookNotSet $e) {} + $params = $hooks->callHook('activesync_autodiscover_parameters', 'horde', [$params]); + } catch (Horde_Exception_HookNotSet $e) { + } return $params; } @@ -2676,23 +2771,24 @@ public function autoDiscover($params = array(), $version = 1) public function getUsernameFromEmail($email) { switch ($GLOBALS['conf']['activesync']['autodiscovery']) { - case 'full': - return $email; - case 'user': - if (strpos($email, '@') !== false) { - return substr($email, 0, strpos($email, '@')); - } else { + case 'full': return $email; - } - case 'hook': - try { - return $GLOBALS['injector']->getInstance('Horde_Core_Hooks') - ->callHook('activesync_get_autodiscover_username', 'horde', array($email)); - } catch (Horde_Exception_HookNotSet $e) { + case 'user': + if (strpos($email, '@') !== false) { + return substr($email, 0, strpos($email, '@')); + } else { + return $email; + } + // no break + case 'hook': + try { + return $GLOBALS['injector']->getInstance('Horde_Core_Hooks') + ->callHook('activesync_get_autodiscover_username', 'horde', [$email]); + } catch (Horde_Exception_HookNotSet $e) { + return $email; + } + default: return $email; - } - default: - return $email; } } @@ -2726,9 +2822,9 @@ public function getUsernameFromEmail($email) * - availability: (string) A EAS style FB string. * - picture: (Horde_ActiveSync_Message_ResolveRecipientsPicture) */ - public function resolveRecipient($type, $search, array $opts = array()) + public function resolveRecipient($type, $search, array $opts = []) { - $return = array(); + $return = []; if ($type == 'certificate') { $results = $this->_connector->resolveRecipient($search, $opts); @@ -2739,7 +2835,8 @@ public function resolveRecipient($type, $search, array $opts = array()) foreach ($results[$search] as $result) { if (!empty($opts['pictures'])) { $picture = new Horde_ActiveSync_Message_ResolveRecipientsPicture( - array('protocolversion' => $this->_version, 'logger' => $this->_logger)); + ['protocolversion' => $this->_version, 'logger' => $this->_logger] + ); if (empty($result['photo'])) { $picture->status = Horde_ActiveSync_Status::NO_PICTURE; } elseif (!empty($opts['maxpictures']) && @@ -2754,24 +2851,24 @@ public function resolveRecipient($type, $search, array $opts = array()) ++$picture_count; } } - $entry = array( + $entry = [ 'displayname' => $result['name'], 'emailaddress' => $result['email'], - 'entries' => !empty($result['smimePublicKey']) ? array($this->_mungeCert($result['smimePublicKey'])) : array(), + 'entries' => !empty($result['smimePublicKey']) ? [$this->_mungeCert($result['smimePublicKey'])] : [], 'type' => $result['source'] == $gal ? Horde_ActiveSync::RESOLVE_RESULT_GAL : Horde_ActiveSync::RESOLVE_RESULT_ADDRESSBOOK, - 'picture' => !empty($picture) ? $picture : null - ); + 'picture' => !empty($picture) ? $picture : null, + ]; $return[] = $entry; } } } else { - $options = array( + $options = [ 'maxcerts' => 0, 'maxambiguous' => $opts['maxambiguous'], 'maxsize' => !empty($opts['maxsize']) ? $opts['maxsize'] : null, 'maxpictures' => !empty($opts['maxpictures']) ? $opts['maxpictures'] : null, - 'pictures' => !empty($opts['pictures']) - ); + 'pictures' => !empty($opts['pictures']), + ]; $entry = current($this->resolveRecipient('certificate', $search, $options)); // These are empty if we do not have a AVAILABILITY request. @@ -2939,14 +3036,14 @@ public function meetingResponse(array $response) $cn = $ident->getValue('fullname'); $email = $ident->getValue('from_addr'); switch ($response['response']) { - case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_ACCEPTED: - $itip_response = 'ACCEPTED'; - break; - case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_TENTATIVE: - $itip_response = 'TENTATIVE'; - break; - case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_DECLINED: - $itip_response = 'DECLINED'; + case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_ACCEPTED: + $itip_response = 'ACCEPTED'; + break; + case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_TENTATIVE: + $itip_response = 'TENTATIVE'; + break; + case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_DECLINED: + $itip_response = 'DECLINED'; } $vEvent->updateAttendee($email, $itip_response); @@ -2968,13 +3065,13 @@ public function meetingResponse(array $response) $comment = Horde_Text_Filter::filter( $comment, 'Html2text', - array('charset' => 'UTF-8', 'nestingLimit' => 1000) + ['charset' => 'UTF-8', 'nestingLimit' => 1000] ); } } else { $comment = ''; } - // Start building the iTip response email. + // Start building the iTip response email. try { $organizer = parse_url($vEvent->getAttribute('ORGANIZER')); $organizer = $organizer['path']; @@ -2986,7 +3083,7 @@ public function meetingResponse(array $response) $ident = $injector->getInstance('Horde_Core_Factory_Identity') ->create($event->creator); if (!$ident->getValue('from_addr')) { - throw new Horde_ActiveSync_Exception(_("You do not have an email address configured in your Personal Information Preferences.")); + throw new Horde_ActiveSync_Exception(_('You do not have an email address configured in your Personal Information Preferences.')); } $resource = new Horde_Itip_Resource_Identity( $ident, @@ -2994,21 +3091,21 @@ public function meetingResponse(array $response) (string)$ident->getFromAddress() ); switch ($response['response']) { - case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_ACCEPTED: - $type = new Horde_Itip_Response_Type_Accept($resource, $comment); - break; - case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_DECLINED: - $type = new Horde_Itip_Response_Type_Decline($resource, $comment); - break; - case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_TENTATIVE: - $type = new Horde_Itip_Response_Type_Tentative($resource, $comment); - break; + case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_ACCEPTED: + $type = new Horde_Itip_Response_Type_Accept($resource, $comment); + break; + case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_DECLINED: + $type = new Horde_Itip_Response_Type_Decline($resource, $comment); + break; + case Horde_ActiveSync_Request_MeetingResponse::RESPONSE_TENTATIVE: + $type = new Horde_Itip_Response_Type_Tentative($resource, $comment); + break; } try { // Send the reply. Horde_Itip::factory($vEvent, $resource)->sendMultiPartResponse( $type, - new Horde_Core_Itip_Response_Options_Horde('UTF-8', array()), + new Horde_Core_Itip_Response_Options_Horde('UTF-8', []), $injector->getInstance('Horde_Mail') ); $this->_logger->meta('Reply sent.'); @@ -3022,7 +3119,7 @@ public function meetingResponse(array $response) // Failure to remove it from the server will result in an inconsistent // sync state. try { - $this->_imap->deleteMessages(array($response['requestid']), $response['folderid']); + $this->_imap->deleteMessages([$response['requestid']], $response['folderid']); } catch (Horde_ActiveSync_Exception $e) { $this->_logger->err($e->getMessage()); } @@ -3052,14 +3149,16 @@ public function createDeviceCallback(Horde_ActiveSync_Device $device) $this->_logger->meta(sprintf( 'Maximum number of devices of %d reached for %s.', $max_devices, - $registry->getAuth())); + $registry->getAuth() + )); return Horde_ActiveSync_Status::MAXIMUM_DEVICES_REACHED; } } try { return $injector->getInstance('Horde_Core_Hooks') - ->callHook('activesync_create_device', 'horde', array($device)); - } catch (Horde_Exception_HookNotSet $e) {} + ->callHook('activesync_create_device', 'horde', [$device]); + } catch (Horde_Exception_HookNotSet $e) { + } return true; } @@ -3078,8 +3177,9 @@ public function deviceCallback(Horde_ActiveSync_Device $device) { try { return $GLOBALS['injector']->getInstance('Horde_Core_Hooks') - ->callHook('activesync_device_check', 'horde', array($device)); - } catch (Horde_Exception_HookNotSet $e) {} + ->callHook('activesync_device_check', 'horde', [$device]); + } catch (Horde_Exception_HookNotSet $e) { + } return true; } @@ -3096,12 +3196,13 @@ public function modifyDeviceCallback(Horde_ActiveSync_Device $device) { try { $device = $GLOBALS['injector']->getInstance('Horde_Core_Hooks') - ->callHook('activesync_device_modify', 'horde', array($device)); + ->callHook('activesync_device_modify', 'horde', [$device]); if (!($device instanceof Horde_ActiveSync_Device)) { $this->_logger->err('activesync_device_modify hook must return device object.'); throw new Exception(); } - } catch (Horde_Exception_HookNotSet $e) {} + } catch (Horde_Exception_HookNotSet $e) { + } return $device; } @@ -3112,7 +3213,7 @@ public function modifyDeviceCallback(Horde_ActiveSync_Device $device) * @deprecated Will be removed in H6 - this is provided via * self::resolveRecipients(). */ - public function getFreebusy($user, array $options = array()) + public function getFreebusy($user, array $options = []) { throw new Horde_ActiveSync_Exception('Not supported'); } @@ -3131,9 +3232,12 @@ public function getFreebusy($user, array $options = array()) */ public function getSyncStamp($collection, $last = null) { - $this->_logger->meta(sprintf( - 'Horde_Core_ActiveSync_Driver::getSyncStamp(%s, %d);', - $collection, $last) + $this->_logger->meta( + sprintf( + 'Horde_Core_ActiveSync_Driver::getSyncStamp(%s, %d);', + $collection, + $last + ) ); // For FolderSync (empty $collection) or Email collections, we don't care. @@ -3150,7 +3254,7 @@ public function getSyncStamp($collection, $last = null) $id = null; } - if (!in_array($class, array(Horde_ActiveSync::CLASS_CALENDAR, Horde_ActiveSync::CLASS_NOTES, Horde_ActiveSync::CLASS_CONTACTS, Horde_ActiveSync::CLASS_TASKS))) { + if (!in_array($class, [Horde_ActiveSync::CLASS_CALENDAR, Horde_ActiveSync::CLASS_NOTES, Horde_ActiveSync::CLASS_CONTACTS, Horde_ActiveSync::CLASS_TASKS])) { return time(); } @@ -3181,11 +3285,11 @@ public function setDevice(Horde_ActiveSync_Device $device) { parent::setDevice($device); // @todo remove is_callable for Horde 6(?) - if (!empty($this->_imap) && is_callable(array($this->_imap, 'setOptions'))) { - $options = array( + if (!empty($this->_imap) && is_callable([$this->_imap, 'setOptions'])) { + $options = [ Horde_ActiveSync_Imap_Message::OPTIONS_DECODE_TNEF => - !$this->_device->hasQuirk(Horde_ActiveSync_Device::QUIRK_SUPPORTS_TNEF) - ); + !$this->_device->hasQuirk(Horde_ActiveSync_Device::QUIRK_SUPPORTS_TNEF), + ]; $this->_imap->setOptions($options); } } @@ -3224,10 +3328,12 @@ protected function _buildNonMailFolder($id, $parent, $type, $name) protected function _smartStatMessage($folderid, $id, $hint) { ob_start(); - $this->_logger->meta(sprintf( - 'Horde_Core_ActiveSync_Driver::_smartStatMessage(%s, %s)', - $folderid, - $id) + $this->_logger->meta( + sprintf( + 'Horde_Core_ActiveSync_Driver::_smartStatMessage(%s, %s)', + $folderid, + $id + ) ); $statKey = $folderid . $id; $mod = false; @@ -3240,63 +3346,63 @@ protected function _smartStatMessage($folderid, $id, $hint) // and pass the folderid. // First, see if we are using a multiplexed id. switch ($folderid) { - case self::APPOINTMENTS_FOLDER_UID: - $mod = $this->_connector->calendar_getActionTimestamp($id, 'modify'); - break; - - case self::CONTACTS_FOLDER_UID: - $mod = $this->_connector->contacts_getActionTimestamp($id, 'modify'); - break; - - case self::TASKS_FOLDER_UID: - $mod = $this->_connector->tasks_getActionTimestamp($id, 'modify'); - break; - - case self::NOTES_FOLDER_UID: - $mod = $this->_connector->notes_getActionTimestamp($id, 'modify'); - break; - default: - // Not using non-email multiplexed collection. - $folder_parts = $this->_parseFolderId($folderid); - if (count($folder_parts) == 2) { - $folder_class = $folder_parts[self::FOLDER_PART_CLASS]; - $serverid = $folder_parts[self::FOLDER_PART_ID]; - } else { - $folder_class = false; - $serverid = null; - } - switch ($folder_class) { - case Horde_ActiveSync::CLASS_CALENDAR: - $mod = $this->_connector->calendar_getActionTimestamp($id, 'modify', $serverid); + case self::APPOINTMENTS_FOLDER_UID: + $mod = $this->_connector->calendar_getActionTimestamp($id, 'modify'); break; - case Horde_ActiveSync::CLASS_CONTACTS: - $mod = $this->_connector->contacts_getActionTimestamp($id, 'modify', $serverid); + + case self::CONTACTS_FOLDER_UID: + $mod = $this->_connector->contacts_getActionTimestamp($id, 'modify'); break; - case Horde_ActiveSync::CLASS_TASKS: - $mod = $this->_connector->tasks_getActionTimestamp($id, 'modify', $serverid); + + case self::TASKS_FOLDER_UID: + $mod = $this->_connector->tasks_getActionTimestamp($id, 'modify'); break; - case Horde_ActiveSync::CLASS_NOTES: - $mod = $this->_connector->notes_getActionTimestamp($id, 'modify', $serverid); + + case self::NOTES_FOLDER_UID: + $mod = $this->_connector->notes_getActionTimestamp($id, 'modify'); break; default: - try { - return $this->statMailMessage($folderid, $id); - } catch (Horde_ActiveSync_Exception $e) { - $this->_endBuffer(); - return false; + // Not using non-email multiplexed collection. + $folder_parts = $this->_parseFolderId($folderid); + if (count($folder_parts) == 2) { + $folder_class = $folder_parts[self::FOLDER_PART_CLASS]; + $serverid = $folder_parts[self::FOLDER_PART_ID]; + } else { + $folder_class = false; + $serverid = null; } + switch ($folder_class) { + case Horde_ActiveSync::CLASS_CALENDAR: + $mod = $this->_connector->calendar_getActionTimestamp($id, 'modify', $serverid); + break; + case Horde_ActiveSync::CLASS_CONTACTS: + $mod = $this->_connector->contacts_getActionTimestamp($id, 'modify', $serverid); + break; + case Horde_ActiveSync::CLASS_TASKS: + $mod = $this->_connector->tasks_getActionTimestamp($id, 'modify', $serverid); + break; + case Horde_ActiveSync::CLASS_NOTES: + $mod = $this->_connector->notes_getActionTimestamp($id, 'modify', $serverid); + break; + default: + try { + return $this->statMailMessage($folderid, $id); + } catch (Horde_ActiveSync_Exception $e) { + $this->_endBuffer(); + return false; + } - } + } } } catch (Horde_Exception $e) { $this->_logger->err($e->getMessage()); $this->_endBuffer(); - return array('id' => '', 'mod' => 0, 'flags' => 1); + return ['id' => '', 'mod' => 0, 'flags' => 1]; } $this->_modCache[$statKey] = $mod; } - $message = array(); + $message = []; $message['id'] = $id; $message['mod'] = $mod; $message['flags'] = 1; @@ -3305,29 +3411,31 @@ protected function _smartStatMessage($folderid, $id, $hint) return $message; } - /** - * Return the list of mail server folders. - * - * @return array An array of Horde_ActiveSync_Message_Folder objects. - */ + /** + * Return the list of mail server folders. + * + * @return array An array of Horde_ActiveSync_Message_Folder objects. + */ protected function _getMailFolders() { if (empty($this->_mailFolders)) { if (empty($this->_imap)) { - $this->_mailFolders = array($this->_buildDummyFolder(self::SPECIAL_INBOX)); + $this->_mailFolders = [$this->_buildDummyFolder(self::SPECIAL_INBOX)]; $this->_mailFolders[] = $this->_buildDummyFolder(self::SPECIAL_TRASH); $this->_mailFolders[] = $this->_buildDummyFolder(self::SPECIAL_SENT); $this->_mailFolders[] = $this->_buildDummyFolder(self::SPECIAL_DRAFTS); $this->_mailFolders[] = $this->_buildDummyFolder(self::SPECIAL_OUTBOX); } else { $this->_logger->meta('Polling Horde_Core_ActiveSync_Driver::_getMailFolders()'); - $folders = array(); + $folders = []; try { $imap_folders = $this->_imap->getMailboxes(true); } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err(sprintf( - 'Problem loading mail folders from IMAP server: %s', - $e->getMessage()) + $this->_logger->err( + sprintf( + 'Problem loading mail folders from IMAP server: %s', + $e->getMessage() + ) ); throw $e; } @@ -3343,8 +3451,11 @@ protected function _getMailFolders() $folders[] = $this->_getMailFolder((string)$id, $imap_folders, $folder); ++$cnt; } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err(sprintf( - 'Problem retrieving %s mail folder', $id) + $this->_logger->err( + sprintf( + 'Problem retrieving %s mail folder', + $id + ) ); } } @@ -3367,31 +3478,31 @@ protected function _buildDummyFolder($id) $folder = new Horde_ActiveSync_Message_Folder(); $folder->parentid = '0'; switch ($id) { - case self::SPECIAL_TRASH: - $folder->type = Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET; - $folder->serverid = $folder->_serverid = 'Trash'; - $folder->displayname = Horde_Core_Translation::t("Trash"); - break; - case self::SPECIAL_SENT: - $folder->type = Horde_ActiveSync::FOLDER_TYPE_SENTMAIL; - $folder->serverid = $folder->_serverid = 'Sent'; - $folder->displayname = Horde_Core_Translation::t("Sent"); - break; - case self::SPECIAL_INBOX: - $folder->type = Horde_ActiveSync::FOLDER_TYPE_INBOX; - $folder->serverid = $folder->_serverid = 'INBOX'; - $folder->displayname = Horde_Core_Translation::t("Inbox"); - break; - case self::SPECIAL_DRAFTS: - $folder->type = Horde_ActiveSync::FOLDER_TYPE_DRAFTS; - $folder->serverid = $folder->_serverid = 'DRAFTS'; - $folder->displayname = Horde_Core_Translation::t("Drafts"); - break; - case self::SPECIAL_OUTBOX: - $folder->type = Horde_ActiveSync::FOLDER_TYPE_OUTBOX; - $folder->serverid = $folder->_serverid = 'OUTBOX'; - $folder->displayname = Horde_Core_Translation::t("Outbox"); - break; + case self::SPECIAL_TRASH: + $folder->type = Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET; + $folder->serverid = $folder->_serverid = 'Trash'; + $folder->displayname = Horde_Core_Translation::t('Trash'); + break; + case self::SPECIAL_SENT: + $folder->type = Horde_ActiveSync::FOLDER_TYPE_SENTMAIL; + $folder->serverid = $folder->_serverid = 'Sent'; + $folder->displayname = Horde_Core_Translation::t('Sent'); + break; + case self::SPECIAL_INBOX: + $folder->type = Horde_ActiveSync::FOLDER_TYPE_INBOX; + $folder->serverid = $folder->_serverid = 'INBOX'; + $folder->displayname = Horde_Core_Translation::t('Inbox'); + break; + case self::SPECIAL_DRAFTS: + $folder->type = Horde_ActiveSync::FOLDER_TYPE_DRAFTS; + $folder->serverid = $folder->_serverid = 'DRAFTS'; + $folder->displayname = Horde_Core_Translation::t('Drafts'); + break; + case self::SPECIAL_OUTBOX: + $folder->type = Horde_ActiveSync::FOLDER_TYPE_OUTBOX; + $folder->serverid = $folder->_serverid = 'OUTBOX'; + $folder->displayname = Horde_Core_Translation::t('Outbox'); + break; } return $folder; @@ -3437,9 +3548,11 @@ protected function _getMailFolder($sid, array $fl, array $f) try { $specialFolders = $this->_imap->getSpecialMailboxes(); } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err(sprintf( - 'Problem retrieving special folders: %s', - $e->getMessage()) + $this->_logger->err( + sprintf( + 'Problem retrieving special folders: %s', + $e->getMessage() + ) ); throw $e; } @@ -3447,33 +3560,33 @@ protected function _getMailFolder($sid, array $fl, array $f) // Check for known, supported special folders. foreach ($specialFolders as $key => $value) { if (!is_array($value)) { - $value = array($value); + $value = [$value]; } foreach ($value as $mailbox) { if (!is_null($mailbox)) { switch ($key) { - case self::SPECIAL_SENT: - if ($sid == $mailbox->value) { - $folder->type = Horde_ActiveSync::FOLDER_TYPE_SENTMAIL; - $folder->serverid = $this->_getFolderUidForBackendId($sid, $folder->type); - return $folder; - } - break; - case self::SPECIAL_TRASH: - if ($sid == $mailbox->value) { - $folder->type = Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET; - $folder->serverid = $this->_getFolderUidForBackendId($sid, $folder->type); - return $folder; - } - break; + case self::SPECIAL_SENT: + if ($sid == $mailbox->value) { + $folder->type = Horde_ActiveSync::FOLDER_TYPE_SENTMAIL; + $folder->serverid = $this->_getFolderUidForBackendId($sid, $folder->type); + return $folder; + } + break; + case self::SPECIAL_TRASH: + if ($sid == $mailbox->value) { + $folder->type = Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET; + $folder->serverid = $this->_getFolderUidForBackendId($sid, $folder->type); + return $folder; + } + break; - case self::SPECIAL_DRAFTS: - if ($sid == $mailbox->value) { - $folder->type = Horde_ActiveSync::FOLDER_TYPE_DRAFTS; - $folder->serverid = $this->_getFolderUidForBackendId($sid, $folder->type); - return $folder; - } - break; + case self::SPECIAL_DRAFTS: + if ($sid == $mailbox->value) { + $folder->type = Horde_ActiveSync::FOLDER_TYPE_DRAFTS; + $folder->serverid = $this->_getFolderUidForBackendId($sid, $folder->type); + return $folder; + } + break; } } } @@ -3508,23 +3621,24 @@ protected function _searchMailbox(array $query) protected function _searchGal(array $query) { ob_start(); - $return = array( - 'rows' => array(), + $return = [ + 'rows' => [], 'status' => Horde_ActiveSync_Request_Search::STORE_STATUS_SUCCESS, - 'total' => 0 - ); + 'total' => 0, + ]; // If no perms to the GAL, return zero results. $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if ($perms->exists('horde:activesync:no_gal') && $perms->getPermissions('horde:activesync:no_gal', $this->_user)) { - return $return; + return $return; } try { $results = $this->_connector->contacts_search( $query['query'], - array('pictures' => !empty($query[Horde_ActiveSync_Request_Search::SEARCH_PICTURE]))); + ['pictures' => !empty($query[Horde_ActiveSync_Request_Search::SEARCH_PICTURE])] + ); } catch (Horde_ActiveSync_Exception $e) { $this->_logger->err($e); $this->_endBuffer(); @@ -3539,8 +3653,11 @@ protected function _searchGal(array $query) return $return; } $return['total'] = $count; - $this->_logger->meta(sprintf( - 'Horde_Core_ActiveSync_Driver::_searchGal() found %d matches.', $count) + $this->_logger->meta( + sprintf( + 'Horde_Core_ActiveSync_Driver::_searchGal() found %d matches.', + $count + ) ); if (!empty($query['range'])) { @@ -3560,7 +3677,7 @@ protected function _searchGal(array $query) continue; } - $entry = array( + $entry = [ Horde_ActiveSync::GAL_ALIAS => !empty($row['alias']) ? $row['alias'] : '', Horde_ActiveSync::GAL_DISPLAYNAME => $row['name'], Horde_ActiveSync::GAL_EMAILADDRESS => !empty($row['email']) ? $row['email'] : '', @@ -3572,7 +3689,7 @@ protected function _searchGal(array $query) Horde_ActiveSync::GAL_MOBILEPHONE => !empty($row['cellPhone']) ? $row['cellPhone'] : '', Horde_ActiveSync::GAL_TITLE => !empty($row['title']) ? $row['title'] : '', Horde_ActiveSync::GAL_OFFICE => !empty($row['office']) ? $row['office'] : '', - ); + ]; if (!empty($query[Horde_ActiveSync_Request_Search::SEARCH_PICTURE])) { $picture = Horde_ActiveSync::messageFactory('GalPicture'); if (empty($row['photo'])) { @@ -3617,8 +3734,8 @@ protected function _endBuffer() */ protected function _mungeCert($cert) { - $cert = str_replace("-----BEGIN CERTIFICATE-----", '', $cert); - $cert = str_replace("-----END CERTIFICATE-----", '', $cert); + $cert = str_replace('-----BEGIN CERTIFICATE-----', '', $cert); + $cert = str_replace('-----END CERTIFICATE-----', '', $cert); $cert = str_replace("\r\n", '', $cert); return $cert; @@ -3635,7 +3752,7 @@ protected function _mungeCert($cert) protected function _getPolicyFromPerms($deviceinfo = false) { $prefix = 'horde:activesync:provisioning:'; - $policy = array(); + $policy = []; $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if (!$perms->exists('horde:activesync:provisioning')) { return $policy; @@ -3657,41 +3774,41 @@ protected function _getPolicyValue($policy, $allowed) { if (is_array($allowed)) { switch ($policy) { - case 'activesync': - case 'max_devices': - case Horde_ActiveSync_Policies::POLICY_ATC: - case Horde_ActiveSync_Policies::POLICY_PIN: - case Horde_ActiveSync_Policies::POLICY_COMPLEXITY: - case Horde_ActiveSync_Policies::POLICY_MAXFAILEDATTEMPTS: - case Horde_ActiveSync_Policies::POLICY_CODEFREQ: - case Horde_ActiveSync_Policies::POLICY_AEFVALUE: - case Horde_ActiveSync_Policies::POLICY_MAXATCSIZE: - case Horde_ActiveSync_Policies::POLICY_ALLOW_SDCARD: - case Horde_ActiveSync_Policies::POLICY_ALLOW_CAMERA: - case Horde_ActiveSync_Policies::POLICY_ALLOW_SMS: - case Horde_ActiveSync_Policies::POLICY_ALLOW_WIFI: - case Horde_ActiveSync_Policies::POLICY_ALLOW_BLUETOOTH: - case Horde_ActiveSync_Policies::POLICY_ALLOW_POPIMAP: - case Horde_ActiveSync_Policies::POLICY_ALLOW_BROWSER: - case Horde_ActiveSync_Policies::POLICY_ALLOW_HTML: - case Horde_ActiveSync_Policies::POLICY_MAX_EMAIL_AGE: - case Horde_ActiveSync_Policies::POLICY_DEVICE_ENCRYPTION: - case Horde_ActiveSync_Policies::POLICY_ENCRYPTION: - $allowed = max($allowed); - break; - case Horde_ActiveSync_Policies::POLICY_MINLENGTH: - case Horde_ActiveSync_Policies::POLICY_ROAMING_NOPUSH: - $allowed = min($allowed); - break; - case 'provisioning': - if (array_search('false', $allowed) !== false) { - $allowed = Horde_ActiveSync::PROVISIONING_NONE; - } elseif (array_search('allow', $allowed) !== false) { - $allowed = Horde_ActiveSync::PROVISIONING_LOOSE; - } elseif (array_search('true', $allowed) !== false) { - $allowed = Horde_ActiveSync::PROVISIONING_FORCE; - } - break; + case 'activesync': + case 'max_devices': + case Horde_ActiveSync_Policies::POLICY_ATC: + case Horde_ActiveSync_Policies::POLICY_PIN: + case Horde_ActiveSync_Policies::POLICY_COMPLEXITY: + case Horde_ActiveSync_Policies::POLICY_MAXFAILEDATTEMPTS: + case Horde_ActiveSync_Policies::POLICY_CODEFREQ: + case Horde_ActiveSync_Policies::POLICY_AEFVALUE: + case Horde_ActiveSync_Policies::POLICY_MAXATCSIZE: + case Horde_ActiveSync_Policies::POLICY_ALLOW_SDCARD: + case Horde_ActiveSync_Policies::POLICY_ALLOW_CAMERA: + case Horde_ActiveSync_Policies::POLICY_ALLOW_SMS: + case Horde_ActiveSync_Policies::POLICY_ALLOW_WIFI: + case Horde_ActiveSync_Policies::POLICY_ALLOW_BLUETOOTH: + case Horde_ActiveSync_Policies::POLICY_ALLOW_POPIMAP: + case Horde_ActiveSync_Policies::POLICY_ALLOW_BROWSER: + case Horde_ActiveSync_Policies::POLICY_ALLOW_HTML: + case Horde_ActiveSync_Policies::POLICY_MAX_EMAIL_AGE: + case Horde_ActiveSync_Policies::POLICY_DEVICE_ENCRYPTION: + case Horde_ActiveSync_Policies::POLICY_ENCRYPTION: + $allowed = max($allowed); + break; + case Horde_ActiveSync_Policies::POLICY_MINLENGTH: + case Horde_ActiveSync_Policies::POLICY_ROAMING_NOPUSH: + $allowed = min($allowed); + break; + case 'provisioning': + if (array_search('false', $allowed) !== false) { + $allowed = Horde_ActiveSync::PROVISIONING_NONE; + } elseif (array_search('allow', $allowed) !== false) { + $allowed = Horde_ActiveSync::PROVISIONING_LOOSE; + } elseif (array_search('true', $allowed) !== false) { + $allowed = Horde_ActiveSync::PROVISIONING_FORCE; + } + break; } } @@ -3739,8 +3856,8 @@ protected function _getMaillogChanges(Horde_ActiveSync_Folder_Imap $folder, $ts) } $changes = $this->_connector->mail_getMaillogChanges($ts); - $flags = array(); - $s_changes = array(); + $flags = []; + $s_changes = []; foreach ($changes as $mid) { try { $uid = $this->_imap->getUidFromMid($mid, $folder); @@ -3754,15 +3871,15 @@ protected function _getMaillogChanges(Horde_ActiveSync_Folder_Imap $folder, $ts) $verb = $this->_getLastVerb($mid); if (!empty($verb)) { switch ($verb['action']) { - case 'reply': - case 'reply_list': - $flags[$uid] = array(Horde_ActiveSync::CHANGE_REPLY_STATE => $verb['ts']); - break; - case 'reply_all': - $flags[$uid] = array(Horde_ActiveSync::CHANGE_REPLYALL_STATE => $verb['ts']); - break; - case 'forward': - $flags[$uid] = array(Horde_ActiveSync::CHANGE_FORWARD_STATE => $verb['ts']); + case 'reply': + case 'reply_list': + $flags[$uid] = [Horde_ActiveSync::CHANGE_REPLY_STATE => $verb['ts']]; + break; + case 'reply_all': + $flags[$uid] = [Horde_ActiveSync::CHANGE_REPLYALL_STATE => $verb['ts']]; + break; + case 'forward': + $flags[$uid] = [Horde_ActiveSync::CHANGE_FORWARD_STATE => $verb['ts']]; } } } @@ -3784,7 +3901,7 @@ protected function _getLastVerb($mid) { if (!array_key_exists($mid, $this->_verbs)) { $log = $this->_connector->mail_getMaillog($mid); - $last = array(); + $last = []; foreach ($log as $entry) { if (empty($last) || $last['ts'] < $entry['ts']) { $last = $entry; diff --git a/lib/Horde/Core/ActiveSync/Imap/Factory.php b/lib/Horde/Core/ActiveSync/Imap/Factory.php index d09231d22..ca5e014e6 100644 --- a/lib/Horde/Core/ActiveSync/Imap/Factory.php +++ b/lib/Horde/Core/ActiveSync/Imap/Factory.php @@ -1,4 +1,5 @@ mail->mailboxList(array('reload' => true, 'unsub' => !$subscriptions)) as $mbox) { + foreach ($registry->mail->mailboxList(['reload' => true, 'unsub' => !$subscriptions]) as $mbox) { if (isset($mbox['subscribed'])) { /* IMP 7. Guaranteed that return will match what was * asked for in 'unsub' argument. */ @@ -85,7 +86,8 @@ public function getMailboxes($force = false) } catch (Horde_Exception $e) { Horde::log(sprintf( 'Error retrieving mailbox list: %s', - $e->getMessage()), 'ERR'); + $e->getMessage() + ), 'ERR'); throw new Horde_ActiveSync_Exception($e); } } @@ -93,9 +95,10 @@ public function getMailboxes($force = false) $this->_mailboxlist = $injector->getInstance('Horde_Core_Hooks')->callHook( 'activesync_mailboxlist', 'horde', - array($this->_mailboxlist) + [$this->_mailboxlist] ); - } catch (Horde_Exception_HookNotSet $e) {} + } catch (Horde_Exception_HookNotSet $e) { + } return $this->_mailboxlist; } @@ -116,7 +119,8 @@ public function getSpecialMailboxes() } catch (Horde_Exception $e) { Horde::log(sprintf( 'Error retrieving specialmailbox list: %s', - $e->getMessage()), 'ERR'); + $e->getMessage() + ), 'ERR'); throw new Horde_ActiveSync_Exception($e); } @@ -143,25 +147,25 @@ public function getMsgFlags() { global $registry; - $msgFlags = array(); + $msgFlags = []; $flags = unserialize($registry->horde->getPreference($registry->hasInterface('mail'), 'msgflags')); // Remove any system flags, as these should never be user (un)set. - $system_flags = array( + $system_flags = [ Horde_Imap_Client::FLAG_ANSWERED, Horde_Imap_Client::FLAG_DELETED, Horde_Imap_Client::FLAG_DRAFT, Horde_Imap_Client::FLAG_FLAGGED, Horde_Imap_Client::FLAG_RECENT, - Horde_Imap_Client::FLAG_SEEN - ); + Horde_Imap_Client::FLAG_SEEN, + ]; foreach ($system_flags as $flag) { unset($flags[$flag]); } foreach ($flags as $flag) { if ($flag->imapflag) { - $msgFlags[Horde_String::lower($flag->imapflag)] = $flag->label; + $msgFlags[Horde_String::lower($flag->imapflag)] = $flag->label; } } diff --git a/lib/Horde/Core/ActiveSync/Logger/Factory.php b/lib/Horde/Core/ActiveSync/Logger/Factory.php index 59bc62ef7..1cd741c27 100644 --- a/lib/Horde/Core/ActiveSync/Logger/Factory.php +++ b/lib/Horde/Core/ActiveSync/Logger/Factory.php @@ -1,4 +1,5 @@ - * @package Core - */ +/** +* Horde_Core_ActiveSync_Logger_Factory:: Implements a factory/builder for +* providing a Horde_Log_Logger object correctly configured for the +* debug settings and the device properties. +* +* @license http://www.horde.org/licenses/gpl GPLv2 +* @copyright 2010-2017 Horde LLC (http://www.horde.org/) +* @author Michael J Rubinsky +* @package Core +*/ class Horde_Core_ActiveSync_Logger_Factory implements Horde_ActiveSync_Interface_LoggerFactory { - /** * Factory for a log object. Attempts to create a device specific file if * custom logging is requested. @@ -33,53 +33,55 @@ class Horde_Core_ActiveSync_Logger_Factory implements Horde_ActiveSync_Interface * * @return Horde_Log_Logger The logger object, correctly configured. */ - public function create($properties = array()) + public function create($properties = []) { global $conf; $logger = false; switch ($conf['activesync']['logging']['type']) { - case 'onefile': - if (empty($properties['DeviceId'])) { - $properties['DeviceId'] = 'UNKNOWN'; - } - $device_id = Horde_String::upper($properties['DeviceId']); - $format = "%timestamp% $device_id %levelName%: %message%" . PHP_EOL; - $formatter = new Horde_Log_Formatter_Simple(array('format' => $format)); - $stream = fopen($conf['activesync']['logging']['path'], 'a'); - if ($stream) { - $logger = new Horde_Log_Logger(new Horde_Log_Handler_Stream($stream, false, $formatter)); - } - break; - case 'perdevice': - if (!empty($properties['DeviceId'])) { - $stream = fopen($conf['activesync']['logging']['path'] . '/' . Horde_String::upper($properties['DeviceId']) . '.txt', 'a'); + case 'onefile': + if (empty($properties['DeviceId'])) { + $properties['DeviceId'] = 'UNKNOWN'; + } + $device_id = Horde_String::upper($properties['DeviceId']); + $format = "%timestamp% $device_id %levelName%: %message%" . PHP_EOL; + $formatter = new Horde_Log_Formatter_Simple(['format' => $format]); + $stream = fopen($conf['activesync']['logging']['path'], 'a'); if ($stream) { - $formatter = new Horde_ActiveSync_Log_Formatter(); - $logger = new Horde_ActiveSync_Log_Logger(new Horde_ActiveSync_Log_Handler($stream, false, $formatter)); + $logger = new Horde_Log_Logger(new Horde_Log_Handler_Stream($stream, false, $formatter)); } - } - break; - case 'perrequest': - if (!empty($properties['DeviceId'])) { - $dir = sprintf('%s/%s', - $conf['activesync']['logging']['path'], - Horde_String::upper($properties['DeviceId']) - ); - if (!is_dir($dir)) { - mkdir($dir, 0755, true); + break; + case 'perdevice': + if (!empty($properties['DeviceId'])) { + $stream = fopen($conf['activesync']['logging']['path'] . '/' . Horde_String::upper($properties['DeviceId']) . '.txt', 'a'); + if ($stream) { + $formatter = new Horde_ActiveSync_Log_Formatter(); + $logger = new Horde_ActiveSync_Log_Logger(new Horde_ActiveSync_Log_Handler($stream, false, $formatter)); + } } - $path = sprintf('%s/%s-%s-%s.txt', - $dir, - time(), - getmypid(), - (!empty($properties['Cmd']) ? $properties['Cmd'] : 'UnknownCmd') - ); - $stream = fopen($path, 'a'); - if ($stream) { - $logger = new Horde_Log_Logger(new Horde_Log_Handler_Stream($stream)); + break; + case 'perrequest': + if (!empty($properties['DeviceId'])) { + $dir = sprintf( + '%s/%s', + $conf['activesync']['logging']['path'], + Horde_String::upper($properties['DeviceId']) + ); + if (!is_dir($dir)) { + mkdir($dir, 0o755, true); + } + $path = sprintf( + '%s/%s-%s-%s.txt', + $dir, + time(), + getmypid(), + (!empty($properties['Cmd']) ? $properties['Cmd'] : 'UnknownCmd') + ); + $stream = fopen($path, 'a'); + if ($stream) { + $logger = new Horde_Log_Logger(new Horde_Log_Handler_Stream($stream)); + } } - } } if (!$logger) { $logger = new Horde_Log_Logger(new Horde_Log_Handler_Null()); diff --git a/lib/Horde/Core/ActiveSync/Mail.php b/lib/Horde/Core/ActiveSync/Mail.php index 23ff952f5..21a992b80 100644 --- a/lib/Horde/Core/ActiveSync/Mail.php +++ b/lib/Horde/Core/ActiveSync/Mail.php @@ -1,4 +1,5 @@ '; + public const HTML_BLOCKQUOTE = '
'; /** * The headers used when sending the email. @@ -131,7 +132,7 @@ class Horde_Core_ActiveSync_Mail * @var array * @since 2.31.0 */ - protected $_forwardees = array(); + protected $_forwardees = []; /** * Const'r @@ -141,8 +142,10 @@ class Horde_Core_ActiveSync_Mail * @param integer $eas_version EAS version in use. */ public function __construct( - Horde_ActiveSync_Imap_Adapter $imap, $user, $eas_version) - { + Horde_ActiveSync_Imap_Adapter $imap, + $user, + $eas_version + ) { $this->_imap = $imap; $this->_user = $user; $this->_version = $eas_version; @@ -151,19 +154,19 @@ public function __construct( public function &__get($property) { switch ($property) { - case 'imapMessage': - if (!isset($this->_imapMessage)) { - $this->_getImapMessage(); - } - return $this->_imapMessage; - case 'replacemime': - case 'id': - case 'reply': - case 'forward': - case 'headers': - case 'parentFolder': - $property = '_' . $property; - return $this->$property; + case 'imapMessage': + if (!isset($this->_imapMessage)) { + $this->_getImapMessage(); + } + return $this->_imapMessage; + case 'replacemime': + case 'id': + case 'reply': + case 'forward': + case 'headers': + case 'parentFolder': + $property = '_' . $property; + return $this->$property; } } @@ -210,7 +213,7 @@ public function setRawMessage(Horde_ActiveSync_Rfc822 $raw) * message. * @throws Horde_ActiveSync_Exception */ - public function setForward($parent, $id, $params = array()) + public function setForward($parent, $id, $params = []) { if (!empty($this->_reply)) { throw new Horde_ActiveSync_Exception('Cannot set both Forward and Reply.'); @@ -262,14 +265,14 @@ public function send() protected function _callPreSendHook() { $hooks = $GLOBALS['injector']->getInstance('Horde_Core_Hooks'); - $params = array( + $params = [ 'raw' => $this->_raw, 'imap_msg' => $this->imapMessage, 'parent' => $this->_parentFolder, 'reply' => $this->_reply, - 'forward' => $this->_forward); + 'forward' => $this->_forward]; try { - if (!$result = $hooks->callHook('activesync_email_presend', 'horde', array($params))) { + if (!$result = $hooks->callHook('activesync_email_presend', 'horde', [$params])) { throw new Horde_ActiveSync_Exception('There was an issue running the activesync_email_presend hook.'); } if ($result instanceof Horde_ActiveSync_Mime) { @@ -289,8 +292,8 @@ public function getSentMail() if (!empty($this->_mailer)) { return $this->_mailer->getRaw(); } - $stream = new Horde_Stream_Temp(array('max_memory' => 262144)); - $stream->add($this->_headers->toString(array('charset' => 'UTF-8')) . $this->_raw->getMessage(), true); + $stream = new Horde_Stream_Temp(['max_memory' => 262144]); + $stream->add($this->_headers->toString(['charset' => 'UTF-8']) . $this->_raw->getMessage(), true); return $stream; } @@ -302,7 +305,7 @@ public function getSentMail() protected function _sendRaw() { $recipients = ''; - $h_array = $this->_headers->toArray(array('charset' => 'UTF-8')); + $h_array = $this->_headers->toArray(['charset' => 'UTF-8']); if (!empty($h_array['To'])) { $recipients = $h_array['To']; } @@ -400,15 +403,16 @@ protected function _sendSmart() */ protected function _buildSmartReply() { - $mail = new Horde_Mime_Mail($this->_headers->toArray(array('charset' => 'UTF-8'))); + $mail = new Horde_Mime_Mail($this->_headers->toArray(['charset' => 'UTF-8'])); $base_part = $this->imapMessage->getStructure(); $plain_id = $base_part->findBody('plain'); $html_id = $base_part->findBody('html'); try { - $body_data = $this->imapMessage->getMessageBodyData(array( + $body_data = $this->imapMessage->getMessageBodyData( + [ 'protocolversion' => $this->_version, - 'bodyprefs' => array(Horde_ActiveSync::BODYPREF_TYPE_MIME => true)) + 'bodyprefs' => [Horde_ActiveSync::BODYPREF_TYPE_MIME => true]] ); } catch (Horde_Exception_NotFound $e) { throw new Horde_ActiveSync_Exception($e->getMessage()); @@ -451,15 +455,15 @@ protected function _buildSmartForward() // Forwarded message $rfc822Stream = $this->imapMessage->getFullMsg(true); $rfc822Part = new Horde_Mime_Part(); - $rfc822Part->setType("message/rfc822"); + $rfc822Part->setType('message/rfc822'); $rfc822Part->setContents($rfc822Stream); - $rfc822Part->setName(Horde_Core_Translation::t("Forwarded Message")); + $rfc822Part->setName(Horde_Core_Translation::t('Forwarded Message')); // Incoming message to append to forward. $mime_message = $this->_raw->getMimeObject(); // Outgoing message - $mail = new Horde_Mime_Mail($this->_headers->toArray(array('charset' => 'UTF-8'))); + $mail = new Horde_Mime_Mail($this->_headers->toArray(['charset' => 'UTF-8'])); $mail->setBody($this->_getSmartPlainText($mime_message)); $mail->setHtmlBody($this->_getSmartHtmlText($mime_message)); @@ -487,8 +491,11 @@ protected function _buildSmartForward() * @return string The plaintext part of the email message that is being sent. */ protected function _getPlainPart( - $plain_id, Horde_Mime_Part $mime_message, array $body_data, Horde_Mime_Part $base_part) - { + $plain_id, + Horde_Mime_Part $mime_message, + array $body_data, + Horde_Mime_Part $base_part + ) { $smart_text = $this->_getSmartPlainText($mime_message); if ($this->_forward) { return $smart_text . $this->_forwardText($body_data, $base_part->getPart($plain_id)); @@ -516,7 +523,8 @@ protected function _getSmartPlainText(Horde_Mime_Part $mime_message) } else { $smart_text = Horde_ActiveSync_Utils::ensureUtf8( $mime_message->getPart($id)->getContents(), - $mime_message->getCharset()); + $mime_message->getCharset() + ); } return $smart_text; @@ -557,11 +565,14 @@ protected function _getSmartHtmlText(Horde_Mime_Part $mime_message) $smart_text = self::text2html( Horde_ActiveSync_Utils::ensureUtf8( $mime_message->getPart($mime_message->findBody('plain'))->getContents(), - $mime_message->getCharset())); + $mime_message->getCharset() + ) + ); } else { $smart_text = Horde_ActiveSync_Utils::ensureUtf8( $mime_message->getPart($id)->getContents(), - $mime_message->getCharset()); + $mime_message->getCharset() + ); } return $smart_text; @@ -577,7 +588,7 @@ protected function _getImapMessage() if (empty($this->_id) || empty($this->_parentFolder)) { return; } - $this->_imapMessage = array_pop($this->_imap->getImapMessage($this->_parentFolder, $this->_id, array('headers' => true))); + $this->_imapMessage = array_pop($this->_imap->getImapMessage($this->_parentFolder, $this->_id, ['headers' => true])); if (empty($this->_imapMessage)) { throw new Horde_Exception_NotFound('The forwarded/replied message was not found.'); } @@ -661,7 +672,7 @@ protected function _replyText(array $body_data, Horde_Mime_Part $part, $html = f return self::HTML_BLOCKQUOTE . $msg . '


'; } return empty($msg) - ? '[' . Horde_Core_Translation::t("No message body text") . ']' + ? '[' . Horde_Core_Translation::t('No message body text') . ']' : $msg; } @@ -718,7 +729,7 @@ protected function _tidyHtml($html) return Horde_Text_Filter::filter( $html, 'Cleanhtml', - array('body_only' => true) + ['body_only' => true] ); } else { // If no tidy, use Horde_Dom. @@ -739,15 +750,15 @@ public static function text2html($msg) return Horde_Text_Filter::filter( $msg, 'Text2html', - array( + [ 'flowed' => self::HTML_BLOCKQUOTE, - 'parselevel' => Horde_Text_Filter_Text2html::MICRO) + 'parselevel' => Horde_Text_Filter_Text2html::MICRO] ); } public static function html2text($msg) { - return Horde_Text_Filter::filter($msg, 'Html2text', array('nestingLimit' => 1000)); + return Horde_Text_Filter::filter($msg, 'Html2text', ['nestingLimit' => 1000]); } } diff --git a/lib/Horde/Core/ActiveSync/Mail/Draft.php b/lib/Horde/Core/ActiveSync/Mail/Draft.php index 3ad0f6480..9b53246a9 100644 --- a/lib/Horde/Core/ActiveSync/Mail/Draft.php +++ b/lib/Horde/Core/ActiveSync/Mail/Draft.php @@ -1,4 +1,5 @@ addPart($this->_textPart); // Add Mime headers - $base->addMimeHeaders(array( - 'headers' => $this->_headers) + $base->addMimeHeaders( + [ + 'headers' => $this->_headers] ); foreach ($this->_atcAdd as $atc) { @@ -106,15 +108,15 @@ public function append($folderid) $atc_map[$atc->displayname] = $atc->clientid; } - $stream = $base->toString(array( + $stream = $base->toString([ 'stream' => true, - 'headers' => $this->_headers->toString() - )); + 'headers' => $this->_headers->toString(), + ]); $new_uid = $this->_imap->appendMessage( $folderid, $stream, - array('\draft', '\seen') + ['\draft', '\seen'] ); foreach ($base as $part) { @@ -127,13 +129,13 @@ public function append($folderid) // If we pulled down an existing Draft, delete it now since the // new one will replace it. if (!empty($this->_imapMessage)) { - $this->_imap->deleteMessages(array($this->_draftUid), $folderid); + $this->_imap->deleteMessages([$this->_draftUid], $folderid); } - return array( + return [ 'uid' => $new_uid, - 'atchash' => $atc_hash - ); + 'atchash' => $atc_hash, + ]; } /** @@ -192,16 +194,16 @@ protected function _handleAttachments() // New attachments foreach ($this->_draftMessage->airsyncbaseattachments as $atc) { switch (get_class($atc)) { - case 'Horde_ActiveSync_Message_AirSyncBaseAdd': - $atc_mime = new Horde_Mime_Part(); - $atc_mime->setType($atc->contenttype); - $atc_mime->setName($atc->displayname); - $atc_mime->setContents($atc->content); - $this->_atcAdd[] = $atc_mime; - break; - case 'Horde_ActiveSync_Message_AirSyncBaseDelete': - list($mailbox, $uid, $part) = explode(':', $atc->filereference, 3); - $this->_atcDelete[] = $part; + case 'Horde_ActiveSync_Message_AirSyncBaseAdd': + $atc_mime = new Horde_Mime_Part(); + $atc_mime->setType($atc->contenttype); + $atc_mime->setName($atc->displayname); + $atc_mime->setContents($atc->content); + $this->_atcAdd[] = $atc_mime; + break; + case 'Horde_ActiveSync_Message_AirSyncBaseDelete': + [$mailbox, $uid, $part] = explode(':', $atc->filereference, 3); + $this->_atcDelete[] = $part; } } } @@ -217,15 +219,18 @@ protected function _handleAttachments() */ public function getExistingDraftMessage($folderid, $uid) { - $imap_msg = $this->_imap->getImapMessage($folderid,$uid); + $imap_msg = $this->_imap->getImapMessage($folderid, $uid); if (empty($imap_msg[$uid])) { - throw new Horde_ActiveSync_Exception(sprintf( - 'Unable to fetch %d from %s.', - $uid, $folderid) + throw new Horde_ActiveSync_Exception( + sprintf( + 'Unable to fetch %d from %s.', + $uid, + $folderid + ) ); } $this->_imapMessage = $imap_msg[$uid]; $this->_draftUid = $uid; } -} \ No newline at end of file +} diff --git a/lib/Horde/Core/ActiveSync/Mdn.php b/lib/Horde/Core/ActiveSync/Mdn.php index 0e80d7ab6..59075311a 100644 --- a/lib/Horde/Core/ActiveSync/Mdn.php +++ b/lib/Horde/Core/ActiveSync/Mdn.php @@ -1,4 +1,5 @@ _imap = $imap; $this->_mailbox = $mailbox; $this->_uid = $uid; @@ -50,15 +53,15 @@ public function __construct( public function __call($method, $args) { switch ($method) { - case 'headers': - if (empty($this->_msg)) { - return false; - } - return $this->_msg->getHeaders(); - case 'mailbox': - return $this->_mailbox; - case 'uid': - return $this->_uid; + case 'headers': + if (empty($this->_msg)) { + return false; + } + return $this->_msg->getHeaders(); + case 'mailbox': + return $this->_mailbox; + case 'uid': + return $this->_uid; } } @@ -84,7 +87,7 @@ public function mdnCheck() */ protected function _msgCheck() { - $msgs = $this->_imap->getImapMessage($this->_mailbox, $this->_uid, array('headers' => true)); + $msgs = $this->_imap->getImapMessage($this->_mailbox, $this->_uid, ['headers' => true]); if (!count($msgs)) { return false; } @@ -115,4 +118,4 @@ protected function _sysCheck() return true; } -} \ No newline at end of file +} diff --git a/lib/Horde/Core/Ajax/Application.php b/lib/Horde/Core/Ajax/Application.php index 0d228dc9e..cc0041f0a 100644 --- a/lib/Horde/Core/Ajax/Application.php +++ b/lib/Horde/Core/Ajax/Application.php @@ -1,4 +1,5 @@ _app = $app; @@ -122,11 +126,11 @@ protected function _init() public function __get($name) { switch ($name) { - case 'app': - return $this->_app; + case 'app': + return $this->_app; - case 'vars': - return $this->_vars; + case 'vars': + return $this->_vars; } } @@ -172,14 +176,14 @@ public function doAction() /* Look for action in helpers. */ if ($ob = $this->_getHandler()) { - $this->data = call_user_func(array($ob, $this->_action)); + $this->data = call_user_func([$ob, $this->_action]); } else { /* Look for action in application hook. */ try { $this->data = $hooks->callHook( 'ajaxaction_handle', $this->_app, - array($this, $this->_action) + [$this, $this->_action] ); } catch (Horde_Exception $e) { /* DEPRECATED hook. @deprecated */ @@ -187,7 +191,7 @@ public function doAction() $this->data = $hooks->callHook( 'ajaxaction', $this->_app, - array($this->_action, $this->_vars) + [$this->_action, $this->_vars] ); } catch (Horde_Exception $e) { throw new Horde_Exception('Handler for action "' . $this->_action . '" does not exist.'); @@ -199,9 +203,10 @@ public function doAction() $this->data = $hooks->callHook( 'ajaxaction_data', $this->_app, - array($this->_action, $this->data) + [$this->_action, $this->data] ); - } catch (Horde_Exception_HookNotSet $e) {} + } catch (Horde_Exception_HookNotSet $e) { + } } /** @@ -214,7 +219,7 @@ public function doAction() public function addTask($name, $data, $app = null) { if (empty($this->tasks)) { - $this->tasks = new stdClass; + $this->tasks = new stdClass(); } $name = (is_null($app) ? $this->_app : $app) . ':' . $name; @@ -254,7 +259,7 @@ public function callAction($action) { foreach ($this->_handlers as $ob) { if ($ob->has($action)) { - return call_user_func(array($ob, $action)); + return call_user_func([$ob, $action]); } } } diff --git a/lib/Horde/Core/Ajax/Application/Handler.php b/lib/Horde/Core/Ajax/Application/Handler.php index 011a5805c..258f9c054 100644 --- a/lib/Horde/Core/Ajax/Application/Handler.php +++ b/lib/Horde/Core/Ajax/Application/Handler.php @@ -1,4 +1,5 @@ _base->vars; + case 'vars': + return $this->_base->vars; } } diff --git a/lib/Horde/Core/Ajax/Application/Handler/Chunk.php b/lib/Horde/Core/Ajax/Application/Handler/Chunk.php index 52fa3418c..808a17b4c 100644 --- a/lib/Horde/Core/Ajax/Application/Handler/Chunk.php +++ b/lib/Horde/Core/Ajax/Application/Handler/Chunk.php @@ -1,4 +1,5 @@ vars->chunk); - $result = new stdClass; + $result = new stdClass(); if (!empty($chunk)) { Horde::startBuffer(); try { diff --git a/lib/Horde/Core/Ajax/Application/Handler/Email.php b/lib/Horde/Core/Ajax/Application/Handler/Email.php index ab584bdb2..fd269cf41 100644 --- a/lib/Horde/Core/Ajax/Application/Handler/Email.php +++ b/lib/Horde/Core/Ajax/Application/Handler/Email.php @@ -1,4 +1,5 @@ vars->email); if (is_null($ob->mailbox)) { - throw new Horde_Exception(Horde_Core_Translation::t("No valid email address found")); + throw new Horde_Exception(Horde_Core_Translation::t('No valid email address found')); } if (is_null($ob->host) && !is_null($this->defaultDomain)) { $ob->host = $this->defaultDomain; } - $ret = new stdClass; + $ret = new stdClass(); $ret->email = $ob->bare_address; return $ret; diff --git a/lib/Horde/Core/Ajax/Application/Handler/Groups.php b/lib/Horde/Core/Ajax/Application/Handler/Groups.php index b662a7f5e..3406f4a94 100644 --- a/lib/Horde/Core/Ajax/Application/Handler/Groups.php +++ b/lib/Horde/Core/Ajax/Application/Handler/Groups.php @@ -1,4 +1,5 @@ pushApp($this->vars->app); - $imple = $injector->getInstance('Horde_Core_Factory_Imple')->create($this->vars->imple, array(), true); + $imple = $injector->getInstance('Horde_Core_Factory_Imple')->create($this->vars->imple, [], true); $result = $imple->handle($this->vars); diff --git a/lib/Horde/Core/Ajax/Application/Handler/Noop.php b/lib/Horde/Core/Ajax/Application/Handler/Noop.php index 4dc95c9ff..2e3db0dff 100644 --- a/lib/Horde/Core/Ajax/Application/Handler/Noop.php +++ b/lib/Horde/Core/Ajax/Application/Handler/Noop.php @@ -1,4 +1,5 @@ $this->getDomId(), - 'observe' => $this->_observe - ); + 'observe' => $this->_observe, + ]; $args['params'] = is_array($result) ? array_merge($result, $this->_impleParams()) : $result; - $page_output->addInlineScript(array( + $page_output->addInlineScript([ 'HordeImple.add(' . Horde_Serialize::serialize($args, Horde_Serialize::JSON) . - ')' - ), true); + ')', + ], true); } /** @@ -151,10 +152,10 @@ final public function getImpleUrl() */ final protected function _impleParams() { - return array( + return [ 'app' => $GLOBALS['registry']->getApp(), - 'imple' => get_class($this) - ); + 'imple' => get_class($this), + ]; } /** @@ -165,10 +166,10 @@ final protected function _impleParams() */ protected function _jsOnDoAction($js) { - $GLOBALS['page_output']->addInlineScript(array( + $GLOBALS['page_output']->addInlineScript([ 'document.observe("' . get_class($this) . ':do", function(e) {' . - $js . '});' - )); + $js . '});', + ]); } /** @@ -179,10 +180,10 @@ protected function _jsOnDoAction($js) */ protected function _jsOnComplete($js) { - $GLOBALS['page_output']->addInlineScript(array( + $GLOBALS['page_output']->addInlineScript([ 'document.observe("' . get_class($this) . ':complete", function(e) {' . - $js . '});' - )); + $js . '});', + ]); } /** diff --git a/lib/Horde/Core/Ajax/Imple/AutoCompleter.php b/lib/Horde/Core/Ajax/Imple/AutoCompleter.php index 404273de0..a03797a14 100644 --- a/lib/Horde/Core/Ajax/Imple/AutoCompleter.php +++ b/lib/Horde/Core/Ajax/Imple/AutoCompleter.php @@ -1,4 +1,5 @@ addScriptPackage('Horde_Core_Script_Package_Autocomplete'); - $page_output->addInlineJsVars(array( - 'HordeImple.AutoCompleter' => new stdClass - )); + $page_output->addInlineJsVars([ + 'HordeImple.AutoCompleter' => new stdClass(), + ]); self::$_initAc = true; } - $page_output->addInlineScript(array( - 'HordeImple.AutoCompleter["' . $this->getDomId() . '"]=' . $this->_getAutoCompleter()->generate($this) - ), true); + $page_output->addInlineScript([ + 'HordeImple.AutoCompleter["' . $this->getDomId() . '"]=' . $this->_getAutoCompleter()->generate($this), + ], true); return false; } @@ -56,12 +57,12 @@ protected function _handle(Horde_Variables $vars) { // Avoid errors if 'input' isn't set and short-circuit empty searches. if (!isset($vars->input)) { - $result = array(); + $result = []; } else { $input = $vars->get($vars->input); $result = strlen($input) ? $this->_handleAutoCompleter($input) - : array(); + : []; } return new Horde_Core_Ajax_Response_Prototypejs($result); diff --git a/lib/Horde/Core/Ajax/Imple/AutoCompleter/Ajax.php b/lib/Horde/Core/Ajax/Imple/AutoCompleter/Ajax.php index 362be9810..5bf493afb 100644 --- a/lib/Horde/Core/Ajax/Imple/AutoCompleter/Ajax.php +++ b/lib/Horde/Core/Ajax/Imple/AutoCompleter/Ajax.php @@ -1,4 +1,5 @@ array(',', ';') - ), $params)); + parent::__construct(array_merge([ + 'tokens' => [',', ';'], + ], $params)); } /** @@ -50,7 +51,7 @@ public function generate(Horde_Core_Ajax_Imple_AutoCompleter $ac) return 'new Ajax.Autocompleter(' . Horde_Serialize::serialize($dom_id, Horde_Serialize::JSON) . ',' . - Horde_Serialize::serialize(strval($ac->getImpleUrl()->setRaw(true)->add(array('input' => $dom_id))), Horde_Serialize::JSON) . ',' . + Horde_Serialize::serialize(strval($ac->getImpleUrl()->setRaw(true)->add(['input' => $dom_id])), Horde_Serialize::JSON) . ',' . '{' . implode(',', $this->_getOpts($ac)) . '})'; } @@ -61,7 +62,7 @@ public function generate(Horde_Core_Ajax_Imple_AutoCompleter $ac) */ protected function _getOpts(Horde_Core_Ajax_Imple_AutoCompleter $ac) { - $opts = array(); + $opts = []; if (!isset($this->params['indicator'])) { $this->params['indicator'] = $ac->getDomId() . '_loading_img'; diff --git a/lib/Horde/Core/Ajax/Imple/AutoCompleter/Base.php b/lib/Horde/Core/Ajax/Imple/AutoCompleter/Base.php index 658ff78de..c2b5a022b 100644 --- a/lib/Horde/Core/Ajax/Imple/AutoCompleter/Base.php +++ b/lib/Horde/Core/Ajax/Imple/AutoCompleter/Base.php @@ -1,4 +1,5 @@ params = $params; } @@ -38,6 +39,6 @@ public function __construct(array $params = array()) * @param Horde_Core_Ajax_Imple_AutoCompleter $ac The underlying imple * object. */ - abstract function generate(Horde_Core_Ajax_Imple_AutoCompleter $ac); + abstract public function generate(Horde_Core_Ajax_Imple_AutoCompleter $ac); } diff --git a/lib/Horde/Core/Ajax/Imple/AutoCompleter/Local.php b/lib/Horde/Core/Ajax/Imple/AutoCompleter/Local.php index a5102329f..645eb2d43 100644 --- a/lib/Horde/Core/Ajax/Imple/AutoCompleter/Local.php +++ b/lib/Horde/Core/Ajax/Imple/AutoCompleter/Local.php @@ -1,4 +1,5 @@ _search = $search; - parent::__construct(array_merge(array( + parent::__construct(array_merge([ 'fullSearch' => 1, 'partialSearch' => 1, 'score' => 1, - 'tokens' => array(',', ';') - ), $params)); + 'tokens' => [',', ';'], + ], $params)); } /** diff --git a/lib/Horde/Core/Ajax/Imple/AutoCompleter/Pretty.php b/lib/Horde/Core/Ajax/Imple/AutoCompleter/Pretty.php index cb51e4c67..1c2f0cf9a 100644 --- a/lib/Horde/Core/Ajax/Imple/AutoCompleter/Pretty.php +++ b/lib/Horde/Core/Ajax/Imple/AutoCompleter/Pretty.php @@ -1,4 +1,5 @@ strval(Horde_Themes::img('delete-small.png')), - 'triggerContainer' => strval(new Horde_Support_Randomid()) - ), $params) + 'triggerContainer' => strval(new Horde_Support_Randomid()), + ], + $params + ) ); - $this->_raw = array_merge($this->_raw, array( + $this->_raw = array_merge($this->_raw, [ 'displayFilter', 'filterCallback', 'onAdd', 'onRemove', - 'beforeUpdate' - )); + 'beforeUpdate', + ]); $GLOBALS['page_output']->addScriptFile('prettyautocomplete.js', 'horde'); } diff --git a/lib/Horde/Core/Ajax/Imple/ContactAutoCompleter.php b/lib/Horde/Core/Ajax/Imple/ContactAutoCompleter.php index b3bb51ddf..f0697543e 100644 --- a/lib/Horde/Core/Ajax/Imple/ContactAutoCompleter.php +++ b/lib/Horde/Core/Ajax/Imple/ContactAutoCompleter.php @@ -1,4 +1,5 @@ 'function (v) { return v + ", "; }', 'onType' => 'function (e) { return e.include("<") ? "" : e; }', - 'tokens' => array(',') - ); + 'tokens' => [','], + ]; } /** */ protected function _handleAutoCompleter($input) { - return array_map('strval', $this->getAddressList($input, array( - 'levenshtein' => true - ))->base_addresses); + return array_map('strval', $this->getAddressList($input, [ + 'levenshtein' => true, + ])->base_addresses); } /** @@ -64,19 +65,19 @@ protected function _handleAutoCompleter($input) * * @return Horde_Mail_Rfc822_List Expand results. */ - public function getAddressList($str = '', array $opts = array()) + public function getAddressList($str = '', array $opts = []) { $searchpref = $this->_getAddressbookSearchParams(); try { - $search = $GLOBALS['registry']->call('contacts/search', array($str, array( + $search = $GLOBALS['registry']->call('contacts/search', [$str, [ 'fields' => $searchpref->fields, - 'returnFields' => array('email', 'name'), + 'returnFields' => ['email', 'name'], 'rfc822Return' => true, 'sources' => $searchpref->sources, 'count_only' => !empty($opts['count_only']), - 'emailSearch' => true - ))); + 'emailSearch' => true, + ]]); } catch (Horde_Exception $e) { Horde::log($e, 'ERR'); return new Horde_Mail_Rfc822_List(); @@ -90,7 +91,7 @@ public function getAddressList($str = '', array $opts = array()) return $search; } - $sort_list = array(); + $sort_list = []; foreach ($search->base_addresses as $val) { $sort_list[strval($val)] = @levenshtein($str, $val); } diff --git a/lib/Horde/Core/Ajax/Imple/Geocoder/Geonames.php b/lib/Horde/Core/Ajax/Imple/Geocoder/Geonames.php index 32c124dad..88f2bda73 100644 --- a/lib/Horde/Core/Ajax/Imple/Geocoder/Geonames.php +++ b/lib/Horde/Core/Ajax/Imple/Geocoder/Geonames.php @@ -1,4 +1,5 @@ location) { $url = new Horde_Url('https://secure.geonames.org/searchJSON'); - $url->add(array( - 'q' => $vars->location - )); + $url->add([ + 'q' => $vars->location, + ]); } elseif ($vars->lat && $vars->lon) { $url = new Horde_Url('https://secure.geonames.org/findNearestJSON'); - $url->add(array( + $url->add([ 'lat' => $vars->lat, - 'lng' => $vars->lon - )); + 'lng' => $vars->lon, + ]); } else { throw new Horde_Exception('Incorrect parameters'); } @@ -54,16 +55,16 @@ protected function _handle(Horde_Variables $vars) throw new Horde_Exception('Missing required key parameter'); } - $url->add(array( - 'username' => $vars->key - )); + $url->add([ + 'username' => $vars->key, + ]); $response = $GLOBALS['injector']->getInstance('Horde_Core_Factory_HttpClient')->create()->get($url); - return new Horde_Core_Ajax_Response_Prototypejs(array( + return new Horde_Core_Ajax_Response_Prototypejs([ 'results' => $response->getBody(), - 'status' => 200 - )); + 'status' => 200, + ]); } } diff --git a/lib/Horde/Core/Ajax/Imple/InPlaceEditor.php b/lib/Horde/Core/Ajax/Imple/InPlaceEditor.php index ab1f27c7b..c6f5323a0 100644 --- a/lib/Horde/Core/Ajax/Imple/InPlaceEditor.php +++ b/lib/Horde/Core/Ajax/Imple/InPlaceEditor.php @@ -1,4 +1,5 @@ 20, 'dataid' => '', - 'rows' => 2 - ), $params); + 'rows' => 2, + ], $params); parent::__construct($params); } @@ -43,35 +44,35 @@ protected function _attach($init) $page_output->addScriptFile('scriptaculous/effects.js', 'horde'); $page_output->addScriptFile('inplaceeditor.js', 'horde'); - $value_url = $this->getImpleUrl()->add(array( + $value_url = $this->getImpleUrl()->add([ 'id' => $this->_params['dataid'], - 'input' => 'value' - ))->setRaw(true); - $load_url = $value_url->copy()->add(array( - 'action' => 'load' - ))->setRaw(true); - $config = new stdClass; - $config->config = array( + 'input' => 'value', + ])->setRaw(true); + $load_url = $value_url->copy()->add([ + 'action' => 'load', + ])->setRaw(true); + $config = new stdClass(); + $config->config = [ 'cancelClassName' => '', - 'cancelText' => Horde_Core_Translation::t("Cancel"), - 'emptyText' => Horde_Core_Translation::t("Click to add caption..."), - 'okText' => Horde_Core_Translation::t("Ok") - ); - $config->ids = new stdClass; - $config->ids->{$this->getDomId()} = array( + 'cancelText' => Horde_Core_Translation::t('Cancel'), + 'emptyText' => Horde_Core_Translation::t('Click to add caption...'), + 'okText' => Horde_Core_Translation::t('Ok'), + ]; + $config->ids = new stdClass(); + $config->ids->{$this->getDomId()} = [ 'load_url' => (string)$load_url, 'rows' => $this->_params['rows'], - 'value_url' => (string)$value_url - ); + 'value_url' => (string)$value_url, + ]; if (!empty($this->_params['width'])) { $config->ids->{$this->getDomId()}['width'] = $this->_params['width']; } - $page_output->addInlineJsVars(array( - 'HordeImple.InPlaceEditor' . $this->getDomId() => $config - )); - $page_output->addInlineScript(array( + $page_output->addInlineJsVars([ + 'HordeImple.InPlaceEditor' . $this->getDomId() => $config, + ]); + $page_output->addInlineScript([ '$H(HordeImple.InPlaceEditor' . $this->getDomId() . '.ids).each(function(pair) { new InPlaceEditor(pair.key, pair.value.value_url, Object.extend(HordeImple.InPlaceEditor' . $this->getDomId() . '.config, { htmlResponse: false, @@ -88,8 +89,8 @@ protected function _attach($init) rows: pair.value.rows, autoWidth: true })); - })' - ), true); + })', + ], true); } return false; diff --git a/lib/Horde/Core/Ajax/Imple/SpellChecker.php b/lib/Horde/Core/Ajax/Imple/SpellChecker.php index fc5d4ec69..116a45b2d 100644 --- a/lib/Horde/Core/Ajax/Imple/SpellChecker.php +++ b/lib/Horde/Core/Ajax/Imple/SpellChecker.php @@ -1,4 +1,5 @@ nlsconfig->spelling); asort($key_list, SORT_LOCALE_STRING); - $params['locales'] = array(); + $params['locales'] = []; foreach ($key_list as $lcode) { - $params['locales'][] = array( + $params['locales'][] = [ 'l' => $registry->nlsconfig->languages[$lcode], 's' => $lcode == $language, - 'v' => $lcode - ); + 'v' => $lcode, + ]; } } @@ -55,26 +56,26 @@ protected function _attach($init) $page_output->addScriptFile('spellchecker.js', 'horde'); $page_output->addScriptPackage('Horde_Core_Script_Package_Keynavlist'); - $page_output->addInlineJsVars(array( - 'HordeImple.SpellChecker' => new stdClass - )); + $page_output->addInlineJsVars([ + 'HordeImple.SpellChecker' => new stdClass(), + ]); } $dom_id = $this->getDomId(); - $opts = array( + $opts = [ 'locales' => $this->_params['locales'], 'statusButton' => $dom_id, 'target' => $this->_params['targetId'], - 'url' => strval($this->getImpleUrl()->setRaw(true)->add(array('input' => $this->_params['targetId']))) - ); + 'url' => strval($this->getImpleUrl()->setRaw(true)->add(['input' => $this->_params['targetId']])), + ]; if (isset($this->_params['states'])) { $opts['bs'] = $this->_params['states']; } - $page_output->addInlineScript(array( - 'HordeImple.SpellChecker.' . $dom_id . '=new SpellChecker(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON) . ')' - ), true); + $page_output->addInlineScript([ + 'HordeImple.SpellChecker.' . $dom_id . '=new SpellChecker(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON) . ')', + ], true); return false; } @@ -87,7 +88,7 @@ protected function _handle(Horde_Variables $vars) { global $injector; - $args = array('html' => !empty($vars->html)); + $args = ['html' => !empty($vars->html)]; if (isset($vars->locale)) { $args['locale'] = $vars->locale; } @@ -99,10 +100,10 @@ protected function _handle(Horde_Variables $vars) ); } catch (Horde_Exception $e) { Horde::log($e, 'ERR'); - return array( - 'bad' => array(), - 'suggestions' => array() - ); + return [ + 'bad' => [], + 'suggestions' => [], + ]; } } diff --git a/lib/Horde/Core/Ajax/Imple/UserAutoCompleter.php b/lib/Horde/Core/Ajax/Imple/UserAutoCompleter.php index 5d7fc1b53..8bf2a301a 100644 --- a/lib/Horde/Core/Ajax/Imple/UserAutoCompleter.php +++ b/lib/Horde/Core/Ajax/Imple/UserAutoCompleter.php @@ -1,4 +1,5 @@ array(',')) + ['tokens' => [',']] ); } diff --git a/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter.php b/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter.php index 2a8ef9681..1d5b32479 100644 --- a/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter.php +++ b/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter.php @@ -1,4 +1,5 @@ _params['id'] . '_loading_img'; $GLOBALS['injector']->getInstance('Horde_PageOutput')->addInlineScript( - array( + [ 'window.weatherupdate = window.weatherupdate || {}', 'window.weatherupdate["' . $this->_params['instance'] . '"] = { value: false, @@ -51,13 +52,13 @@ protected function _getAutoCompleter() '$("button' . $this->_params['instance'] . '").observe("click", function(e) { window.weatherupdate["' . $this->_params['instance'] . '"].update(); e.stop(); - })' - ) + })', + ] ); - return new Horde_Core_Ajax_Imple_AutoCompleter_Ajax(array( + return new Horde_Core_Ajax_Imple_AutoCompleter_Ajax([ 'minChars' => 3, - 'tokens' => array(), + 'tokens' => [], 'domParent' => 'horde-content', 'filterCallback' => 'function(c) { if (c) { @@ -81,8 +82,8 @@ protected function _getAutoCompleter() } }); return c; - }' - )); + }', + ]); } /** @@ -92,4 +93,4 @@ protected function _handleAutoCompleter($input) return $GLOBALS['injector']->getInstance('Horde_Weather')->autocompleteLocation($input); } -} \ No newline at end of file +} diff --git a/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Base.php b/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Base.php index 691a7aa7a..55d5ccf30 100644 --- a/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Base.php +++ b/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Base.php @@ -1,4 +1,5 @@ _params['id'] . '_loading_img'; $injector->getInstance('Horde_PageOutput')->addInlineScript( - array( + [ 'window.weatherupdate = window.weatherupdate || {}', 'window.weatherupdate["' . $this->_params['instance'] . '"] = { value: false, @@ -61,13 +61,13 @@ protected function _getAutoCompleterForBlock($block) '$("button' . $this->_params['instance'] . '").observe("click", function(e) { window.weatherupdate["' . $this->_params['instance'] . '"].update(); e.stop(); - })' - ) + })', + ] ); - return new Horde_Core_Ajax_Imple_AutoCompleter_Ajax(array( + return new Horde_Core_Ajax_Imple_AutoCompleter_Ajax([ 'minChars' => 3, - 'tokens' => array(), + 'tokens' => [], 'domParent' => 'horde-content', 'filterCallback' => 'function(c) { if (c) { @@ -93,7 +93,7 @@ protected function _getAutoCompleterForBlock($block) } }); return c; - }' - )); + }', + ]); } } diff --git a/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Metar.php b/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Metar.php index f47b7f87a..74c780090 100644 --- a/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Metar.php +++ b/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Metar.php @@ -1,4 +1,5 @@ $injector->getInstance('Horde_Cache'), 'cache_lifetime' => $conf['weather']['params']['lifetime'], 'http_client' => $injector->createInstance('Horde_Core_Factory_HttpClient')->create(), - 'db' => $injector->getInstance('Horde_Db_Adapter')) + 'db' => $injector->getInstance('Horde_Db_Adapter')] ); return $weather->autocompleteLocation($input); diff --git a/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Weather.php b/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Weather.php index 6eeeac15b..e2b42a4e0 100644 --- a/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Weather.php +++ b/lib/Horde/Core/Ajax/Imple/WeatherLocationAutoCompleter/Weather.php @@ -1,4 +1,5 @@ response = $this->data; - $stack = $notification->notify(array( + $stack = $notification->notify([ // @todo: Make this configurable for H6 - 'listeners' => array('status', 'audio', 'webnotification'), - 'raw' => true - )); + 'listeners' => ['status', 'audio', 'webnotification'], + 'raw' => true, + ]); if (!empty($stack)) { - $ob->msgs = array(); + $ob->msgs = []; foreach ($stack as $val) { - $ob->msgs[] = array_filter(array( + $ob->msgs[] = array_filter([ 'flags' => $val->flags, 'message' => $val->message, 'type' => $val->type, - 'webnotify' => isset($val->webnotify) ? $val->webnotify : null - )); + 'webnotify' => $val->webnotify ?? null, + ]); } } @@ -130,7 +131,7 @@ protected function _jsonData() $this->jsfiles[] = strval($val->url); } $page_output->hsl->clear(); - foreach ($page_output->css->getStylesheetUrls(array('nobase' => true)) as $val) { + foreach ($page_output->css->getStylesheetUrls(['nobase' => true]) as $val) { $this->cssfiles[] = strval($val->url); } diff --git a/lib/Horde/Core/Ajax/Response/HordeCore/JsonHtml.php b/lib/Horde/Core/Ajax/Response/HordeCore/JsonHtml.php index c2691bad8..b8ffcc6dc 100644 --- a/lib/Horde/Core/Ajax/Response/HordeCore/JsonHtml.php +++ b/lib/Horde/Core/Ajax/Response/HordeCore/JsonHtml.php @@ -1,4 +1,5 @@ message = strval($GLOBALS['registry']->getLogoutUrl(array( - 'reason' => $this->_error - ))->add('url', Horde::url('', false, array( + $msg = new stdClass(); + $msg->message = strval($GLOBALS['registry']->getLogoutUrl([ + 'reason' => $this->_error, + ])->add('url', Horde::url('', false, [ 'app' => $this->_app, - 'append_session' => -1 - )))); + 'append_session' => -1, + ]))); $msg->type = 'horde.noauth'; - $ob = new stdClass; - $ob->msgs = array($msg); + $ob = new stdClass(); + $ob->msgs = [$msg]; $ob->response = false; return $ob; diff --git a/lib/Horde/Core/Ajax/Response/HordeCore/Reload.php b/lib/Horde/Core/Ajax/Response/HordeCore/Reload.php index ba1edbeb6..a6489b279 100644 --- a/lib/Horde/Core/Ajax/Response/HordeCore/Reload.php +++ b/lib/Horde/Core/Ajax/Response/HordeCore/Reload.php @@ -1,4 +1,5 @@ reload = is_null($this->data) ? true : $this->data; diff --git a/lib/Horde/Core/Ajax/Response/HordeCore/SessionTimeout.php b/lib/Horde/Core/Ajax/Response/HordeCore/SessionTimeout.php index 5c239bfee..430ddb4c3 100644 --- a/lib/Horde/Core/Ajax/Response/HordeCore/SessionTimeout.php +++ b/lib/Horde/Core/Ajax/Response/HordeCore/SessionTimeout.php @@ -1,4 +1,5 @@ message = strval($GLOBALS['registry']->getLogoutUrl(array( - 'reason' => Horde_Auth::REASON_SESSION - ))->add('url', Horde::url('', false, array( + $msg = new stdClass(); + $msg->message = strval($GLOBALS['registry']->getLogoutUrl([ + 'reason' => Horde_Auth::REASON_SESSION, + ])->add('url', Horde::url('', false, [ 'app' => $this->_app, - 'append_session' => -1 - )))); + 'append_session' => -1, + ]))); $msg->type = 'horde.ajaxtimeout'; - $ob = new stdClass; - $ob->msgs = array($msg); + $ob = new stdClass(); + $ob->msgs = [$msg]; $ob->response = false; return $ob; diff --git a/lib/Horde/Core/Ajax/Response/Notifications.php b/lib/Horde/Core/Ajax/Response/Notifications.php index 9241825ec..6e8682b7d 100644 --- a/lib/Horde/Core/Ajax/Response/Notifications.php +++ b/lib/Horde/Core/Ajax/Response/Notifications.php @@ -1,4 +1,5 @@ charset = $charset; diff --git a/lib/Horde/Core/Alarm/Handler/Desktop.php b/lib/Horde/Core/Alarm/Handler/Desktop.php index bf38d24d2..53ecc1e2e 100644 --- a/lib/Horde/Core/Alarm/Handler/Desktop.php +++ b/lib/Horde/Core/Alarm/Handler/Desktop.php @@ -1,4 +1,5 @@ getView() != Horde_Registry::VIEW_DYNAMIC) { if (!isset($params['js_notify'])) { @@ -74,14 +75,21 @@ public function notify(array $alarm) if ($registry->getView() == Horde_Registry::VIEW_DYNAMIC) { $alarm['params']['desktop']['icon'] = $icon; - $notification->push($alarm['title'], 'horde.alarm', array( - 'alarm' => $alarm - )); - } else { - $js = sprintf('if(window.Notification){if (window.Notification.permission != "granted") {window.Notification.requestPermission(function(){if (window.Notification.permission == "granted") { new window.Notification("%s", {body: "%s", icon: "%s" }); } }) } else { new window.Notification("%s", {body: "%s", icon: "%s" }); } };', - $alarm['title'], $alarm['params']['desktop']['subtitle'], $icon, $alarm['title'], $alarm['params']['desktop']['subtitle'], $icon); + $notification->push($alarm['title'], 'horde.alarm', [ + 'alarm' => $alarm, + ]); + } else { + $js = sprintf( + 'if(window.Notification){if (window.Notification.permission != "granted") {window.Notification.requestPermission(function(){if (window.Notification.permission == "granted") { new window.Notification("%s", {body: "%s", icon: "%s" }); } }) } else { new window.Notification("%s", {body: "%s", icon: "%s" }); } };', + $alarm['title'], + $alarm['params']['desktop']['subtitle'], + $icon, + $alarm['title'], + $alarm['params']['desktop']['subtitle'], + $icon + ); call_user_func($this->_jsNotify, $js); - } + } } /** @@ -91,7 +99,7 @@ public function notify(array $alarm) */ public function getDescription() { - return Horde_Alarm_Translation::t("Desktop notification (with certain browsers)"); + return Horde_Alarm_Translation::t('Desktop notification (with certain browsers)'); } } diff --git a/lib/Horde/Core/Alarm/Handler/Desktop/Icon.php b/lib/Horde/Core/Alarm/Handler/Desktop/Icon.php index f35584270..6b6c8db20 100644 --- a/lib/Horde/Core/Alarm/Handler/Desktop/Icon.php +++ b/lib/Horde/Core/Alarm/Handler/Desktop/Icon.php @@ -1,4 +1,5 @@ linkByPackage( - $app, 'show', $params + $app, + 'show', + $params ); } $notification->push( $alarm['title'], 'horde.alarm', - array('alarm' => $alarm) + ['alarm' => $alarm] ); if (!empty($alarm['params']['notify']['sound']) && !isset($this->_soundPlayed[$alarm['params']['notify']['sound']])) { @@ -53,7 +56,7 @@ public function notify(array $alarm) $notification->push( $alarm['params']['notify']['sound'], 'audio', - array('id' => $alarm['id']) + ['id' => $alarm['id']] ); $this->_soundPlayed[$alarm['params']['notify']['sound']] = true; } @@ -66,7 +69,7 @@ public function notify(array $alarm) */ public function getDescription() { - return Horde_Core_Translation::t("Inline"); + return Horde_Core_Translation::t('Inline'); } /** @@ -83,12 +86,12 @@ public function getDescription() */ public function getParameters() { - return array( - 'sound' => array( + return [ + 'sound' => [ 'type' => 'sound', - 'desc' => Horde_Core_Translation::t("Play a sound?"), - 'required' => false - ) - ); + 'desc' => Horde_Core_Translation::t('Play a sound?'), + 'required' => false, + ], + ]; } } diff --git a/lib/Horde/Core/Auth/Application.php b/lib/Horde/Core/Auth/Application.php index 17aef637d..64ca7d021 100644 --- a/lib/Horde/Core/Auth/Application.php +++ b/lib/Horde/Core/Auth/Application.php @@ -1,4 +1,5 @@ true, 'authenticate' => true, 'exists' => true, @@ -77,8 +78,8 @@ class Horde_Core_Auth_Application extends Horde_Auth_Base 'resetpassword' => true, 'transparent' => true, 'update' => true, - 'validate' => true - ); + 'validate' => true, + ]; /** * Constructor. @@ -90,7 +91,7 @@ class Horde_Core_Auth_Application extends Horde_Auth_Base * * @throws InvalidArgumentException */ - public function __construct(array $params = array()) + public function __construct(array $params = []) { if (!isset($params['app'])) { throw new InvalidArgumentException('Missing app parameter.'); @@ -129,8 +130,8 @@ public function authenticate($userId, $credentials, $login = true) } try { - list($userId, $credentials) = $this->runHook(trim($userId), $credentials, 'preauthenticate', 'authenticate'); - } catch (Horde_Auth_Exception $e) { + [$userId, $credentials] = $this->runHook(trim($userId), $credentials, 'preauthenticate', 'authenticate'); + } catch (Horde_Auth_Exception $e) { return false; } @@ -167,7 +168,7 @@ protected function _authenticate($userId, $credentials) $credentials['auth_ob'] = $this; - $GLOBALS['registry']->callAppMethod($this->_app, 'authAuthenticate', array('args' => array($userId, $credentials), 'noperms' => true)); + $GLOBALS['registry']->callAppMethod($this->_app, 'authAuthenticate', ['args' => [$userId, $credentials], 'noperms' => true]); } /** @@ -184,7 +185,7 @@ public function validateAuth() try { return $this->hasCapability('validate') - ? $GLOBALS['registry']->callAppMethod($this->_app, 'authValidate', array('noperms' => true)) + ? $GLOBALS['registry']->callAppMethod($this->_app, 'authValidate', ['noperms' => true]) : parent::validateAuth(); } catch (Horde_Exception_AuthenticationFailure $e) { return false; @@ -207,7 +208,7 @@ public function addUser($userId, $credentials) } if ($this->hasCapability('add')) { - $GLOBALS['registry']->callAppMethod($this->_app, 'authAddUser', array('args' => array($userId, $credentials))); + $GLOBALS['registry']->callAppMethod($this->_app, 'authAddUser', ['args' => [$userId, $credentials]]); } else { parent::addUser($userId, $credentials); } @@ -287,7 +288,7 @@ public function updateUser($oldID, $newID, $credentials) } if ($this->hasCapability('update')) { - $GLOBALS['registry']->callAppMethod($this->_app, 'authUpdateUser', array('args' => array($oldID, $newID, $credentials))); + $GLOBALS['registry']->callAppMethod($this->_app, 'authUpdateUser', ['args' => [$oldID, $newID, $credentials]]); } else { parent::updateUser($oldID, $newID, $credentials); } @@ -306,7 +307,7 @@ public function removeUser($userId) $this->_base->removeUser($userId); } else { if ($this->hasCapability('remove')) { - $GLOBALS['registry']->callAppMethod($this->_app, 'authRemoveUser', array('args' => array($userId))); + $GLOBALS['registry']->callAppMethod($this->_app, 'authRemoveUser', ['args' => [$userId]]); } else { parent::removeUser($userId); } @@ -342,7 +343,7 @@ public function listNames() { $factory = $GLOBALS['injector'] ->getInstance('Horde_Core_Factory_Identity'); - $names = array(); + $names = []; foreach ($this->listUsers() as $user) { $names[$user] = $factory->create($user)->getName(); } @@ -364,7 +365,7 @@ public function exists($userId) } return $this->hasCapability('exists') - ? $GLOBALS['registry']->callAppMethod($this->_app, 'authUserExists', array('args' => array($userId))) + ? $GLOBALS['registry']->callAppMethod($this->_app, 'authUserExists', ['args' => [$userId]]) : parent::exists($userId); } @@ -385,7 +386,7 @@ public function transparent() $credentials = $registry->getAuthCredential(); } - list($userId, $credentials) = $this->runHook($userId, $credentials, 'preauthenticate', 'transparent'); + [$userId, $credentials] = $this->runHook($userId, $credentials, 'preauthenticate', 'transparent'); $this->setCredential('userId', $userId); $this->setCredential('credentials', $credentials); @@ -393,7 +394,7 @@ public function transparent() if ($this->_base) { $result = $this->_base->transparent(); } elseif ($this->hasCapability('transparent')) { - $result = $registry->callAppMethod($this->_app, 'authTransparent', array('args' => array($this), 'noperms' => true)); + $result = $registry->callAppMethod($this->_app, 'authTransparent', ['args' => [$this], 'noperms' => true]); } else { /* If this application contains neither transparent nor * authenticate capabilities, it does not require any @@ -420,7 +421,7 @@ public function resetPassword($userId) } return $this->hasCapability('resetpassword') - ? $GLOBALS['registry']->callAppMethod($this->_app, 'authResetPassword', array('args' => array($userId))) + ? $GLOBALS['registry']->callAppMethod($this->_app, 'authResetPassword', ['args' => [$userId]]) : parent::resetPassword(); } @@ -439,7 +440,7 @@ public function hasCapability($capability) } // The follow capabilities are not determined by the Application, // but by 'Horde'. - if (in_array(Horde_String::lower($capability), array('badlogincount', 'lock'))) { + if (in_array(Horde_String::lower($capability), ['badlogincount', 'lock'])) { return parent::hasCapability($capability); } elseif (!isset($this->_appCapabilities)) { $this->_appCapabilities = $GLOBALS['registry']->getApiInstance($this->_app, 'application')->auth; @@ -558,7 +559,7 @@ public function getLoginParams() { return ($this->_base && method_exists($this->_base, 'getLoginParams')) ? $this->_base->getLoginParams() - : $GLOBALS['registry']->callAppMethod($this->_app, 'authLoginParams', array('noperms' => true)); + : $GLOBALS['registry']->callAppMethod($this->_app, 'authLoginParams', ['noperms' => true]); } /** @@ -590,11 +591,11 @@ public function runHook($userId, $credentials, $type, $method = null) { if (!is_array($credentials)) { $credentials = empty($credentials) - ? array() - : array($credentials); + ? [] + : [$credentials]; } - $ret_array = array($userId, $credentials); + $ret_array = [$userId, $credentials]; if ($type == 'preauthenticate') { $credentials['authMethod'] = $method; @@ -602,7 +603,7 @@ public function runHook($userId, $credentials, $type, $method = null) try { $result = $GLOBALS['injector']->getInstance('Horde_Core_Hooks') - ->callHook($type, $this->_app, array($userId, $credentials)); + ->callHook($type, $this->_app, [$userId, $credentials]); } catch (Horde_Exception_HookNotSet $e) { return $ret_array; } catch (Horde_Exception $e) { @@ -644,7 +645,7 @@ protected function _setAuth() { global $registry; - if ($registry->isAuthenticated(array('app' => $this->_app, 'notransparent' => true))) { + if ($registry->isAuthenticated(['app' => $this->_app, 'notransparent' => true])) { return true; } @@ -661,16 +662,16 @@ protected function _setAuth() $credentials = $this->getCredential('credentials'); try { - list(,$credentials) = $this->runHook($userId, $credentials, 'postauthenticate'); + [, $credentials] = $this->runHook($userId, $credentials, 'postauthenticate'); } catch (Horde_Auth_Exception $e) { return false; } - $registry->setAuth($userId, $credentials, array( + $registry->setAuth($userId, $credentials, [ 'app' => $this->_app, 'change' => $this->getCredential('change'), - 'language' => $language - )); + 'language' => $language, + ]); /* Only set the view mode on initial authentication */ if (!$GLOBALS['session']->exists('horde', 'view')) { @@ -681,7 +682,7 @@ protected function _setAuth() isset($GLOBALS['notification']) && ($expire = $this->_base->getCredential('expire'))) { $toexpire = ($expire - time()) / 86400; - $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::ngettext("%d day until your password expires.", "%d days until your password expires.", $toexpire), $toexpire), 'horde.warning'); + $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::ngettext('%d day until your password expires.', '%d days until your password expires.', $toexpire), $toexpire), 'horde.warning'); } return true; @@ -719,63 +720,63 @@ protected function _setView() /* $mode now contains the user's preference for view based on the * login screen parameters and configuration. */ switch ($mode) { - case 'auto': - if ($browser->hasFeature('ajax')) { - $mode = $browser->isMobile() - ? 'smartmobile' - : 'dynamic'; - } else { - $mode = $browser->isMobile() - ? 'mobile' - : 'basic'; - } - break; + case 'auto': + if ($browser->hasFeature('ajax')) { + $mode = $browser->isMobile() + ? 'smartmobile' + : 'dynamic'; + } else { + $mode = $browser->isMobile() + ? 'mobile' + : 'basic'; + } + break; - case 'basic': - if (!$browser->hasFeature('javascript')) { - $notification->push(Horde_Core_Translation::t("Your browser does not support javascript. Using minimal view instead."), 'horde.warning'); - $mode = 'mobile'; - } - break; + case 'basic': + if (!$browser->hasFeature('javascript')) { + $notification->push(Horde_Core_Translation::t('Your browser does not support javascript. Using minimal view instead.'), 'horde.warning'); + $mode = 'mobile'; + } + break; + + case 'dynamic': + if (!$browser->hasFeature('ajax')) { + if ($browser->hasFeature('javascript')) { + $notification->push(Horde_Core_Translation::t('Your browser does not support the dynamic view. Using basic view instead.'), 'horde.warning'); + $mode = 'basic'; + } else { + $notification->push(Horde_Core_Translation::t('Your browser does not support the dynamic view. Using minimal view instead.'), 'horde.warning'); + $mode = 'mobile'; + } + } + break; - case 'dynamic': - if (!$browser->hasFeature('ajax')) { - if ($browser->hasFeature('javascript')) { - $notification->push(Horde_Core_Translation::t("Your browser does not support the dynamic view. Using basic view instead."), 'horde.warning'); - $mode = 'basic'; - } else { - $notification->push(Horde_Core_Translation::t("Your browser does not support the dynamic view. Using minimal view instead."), 'horde.warning'); + case 'smartmobile': + if (!$browser->hasFeature('ajax')) { + $notification->push(Horde_Core_Translation::t('Your browser does not support the dynamic view. Using minimal view instead.'), 'horde.warning'); $mode = 'mobile'; } - } - break; + break; - case 'smartmobile': - if (!$browser->hasFeature('ajax')) { - $notification->push(Horde_Core_Translation::t("Your browser does not support the dynamic view. Using minimal view instead."), 'horde.warning'); + case 'mobile': + default: $mode = 'mobile'; - } - break; - - case 'mobile': - default: - $mode = 'mobile'; - break; + break; } if (($browser->getBrowser() == 'msie') && ($browser->getMajor() < 8) && ($mode != 'mobile')) { - $notification->push(Horde_Core_Translation::t("You are using an old, unsupported version of Internet Explorer. You need at least Internet Explorer 8. If you already run IE8 or higher, disable the Compatibility View. Minimal view will be used until you upgrade your browser.")); + $notification->push(Horde_Core_Translation::t('You are using an old, unsupported version of Internet Explorer. You need at least Internet Explorer 8. If you already run IE8 or higher, disable the Compatibility View. Minimal view will be used until you upgrade your browser.')); $mode = 'mobile'; } - $registry_map = array( + $registry_map = [ 'basic' => Horde_Registry::VIEW_BASIC, 'dynamic' => Horde_Registry::VIEW_DYNAMIC, 'mobile' => Horde_Registry::VIEW_MINIMAL, - 'smartmobile' => Horde_Registry::VIEW_SMARTMOBILE - ); + 'smartmobile' => Horde_Registry::VIEW_SMARTMOBILE, + ]; $this->_view = $mode; $registry->setView($registry_map[$mode]); diff --git a/lib/Horde/Core/Auth/Composite.php b/lib/Horde/Core/Auth/Composite.php index 994b12100..2767f6fef 100644 --- a/lib/Horde/Core/Auth/Composite.php +++ b/lib/Horde/Core/Auth/Composite.php @@ -1,4 +1,5 @@ _params['auth_driver']->getLoginParams(); } - return array( - 'js_code' => array(), - 'js_files' => array(), - 'params' => array() - ); + return [ + 'js_code' => [], + 'js_files' => [], + 'params' => [], + ]; } } diff --git a/lib/Horde/Core/Auth/Imsp.php b/lib/Horde/Core/Auth/Imsp.php index 6df95bfa2..8a4901271 100644 --- a/lib/Horde/Core/Auth/Imsp.php +++ b/lib/Horde/Core/Auth/Imsp.php @@ -1,4 +1,5 @@ getInstance('Horde_Core_Factory_Auth')->create()->runHook($userId, $credentials, 'preauthenticate', 'admin'); + [$userId, $credentials] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create()->runHook($userId, $credentials, 'preauthenticate', 'admin'); parent::addUser($userId, $credentials); } @@ -41,15 +42,19 @@ public function addUser($userId, $credentials) * * @throws Horde_Auth_Exception */ - public function updateUser($oldID, $newID, $credentials, $olddn = null, - $newdn = null) - { + public function updateUser( + $oldID, + $newID, + $credentials, + $olddn = null, + $newdn = null + ) { $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create(); - list($oldID, $old_credentials) = $auth->runHook($oldID, $credentials, 'preauthenticate', 'admin'); - list($newID, $new_credentials) = $auth->runHook($newID, $credentials, 'preauthenticate', 'admin'); - $olddn = isset($old_credentials['dn']) ? $old_credentials['dn'] : null; - $newdn = isset($new_credentials['dn']) ? $new_credentials['dn'] : null; + [$oldID, $old_credentials] = $auth->runHook($oldID, $credentials, 'preauthenticate', 'admin'); + [$newID, $new_credentials] = $auth->runHook($newID, $credentials, 'preauthenticate', 'admin'); + $olddn = $old_credentials['dn'] ?? null; + $newdn = $new_credentials['dn'] ?? null; parent::updateUser($oldID, $newID, $new_credentials, $olddn, $newdn); } @@ -64,7 +69,7 @@ public function updateUser($oldID, $newID, $credentials, $olddn = null, */ public function removeUser($userId, $dn = null) { - list($userId, $credentials) = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create()->runHook($userId, array(), 'preauthenticate', 'admin'); + [$userId, $credentials] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create()->runHook($userId, [], 'preauthenticate', 'admin'); parent::removeUser($userId, isset($credentials['ldap']) ? $credentials['ldap']['dn'] : null); } diff --git a/lib/Horde/Core/Auth/Msad.php b/lib/Horde/Core/Auth/Msad.php index ef71c1577..a8bc7d421 100644 --- a/lib/Horde/Core/Auth/Msad.php +++ b/lib/Horde/Core/Auth/Msad.php @@ -1,4 +1,5 @@ getInstance('Horde_Core_Factory_Auth')->create()->runHook($userId, $credentials, 'preauthenticate', 'admin'); + [$userId, $credentials] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create()->runHook($userId, $credentials, 'preauthenticate', 'admin'); parent::addUser($userId, $credentials); } @@ -39,10 +40,14 @@ public function addUser($userId, $credentials) * * @throws Horde_Auth_Exception */ - public function updateUser($oldID, $newID, $credentials, $olddn = null, - $newdn = null) - { - list($oldId, $credentials) = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create()->runHook($oldId, $credentials, 'preauthenticate', 'admin'); + public function updateUser( + $oldID, + $newID, + $credentials, + $olddn = null, + $newdn = null + ) { + [$oldId, $credentials] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create()->runHook($oldId, $credentials, 'preauthenticate', 'admin'); parent::updateUser($oldID, $newID, $credentials, $olddn, $newdn); } @@ -57,7 +62,7 @@ public function updateUser($oldID, $newID, $credentials, $olddn = null, */ public function removeUser($userId, $dn = null) { - list($userId, $credentials) = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create()->runHook($userId, array(), 'preauthenticate', 'admin'); + [$userId, $credentials] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create()->runHook($userId, [], 'preauthenticate', 'admin'); parent::removeUser($userId, isset($credentials['ldap']) ? $credentials['ldap']['dn'] : $dn); } diff --git a/lib/Horde/Core/Auth/Shibboleth.php b/lib/Horde/Core/Auth/Shibboleth.php index aa05eadfe..954aa24d5 100644 --- a/lib/Horde/Core/Auth/Shibboleth.php +++ b/lib/Horde/Core/Auth/Shibboleth.php @@ -1,4 +1,5 @@ _preSignup($info); // Attempt to add the user to the system. - $auth->addUser($info['user_name'], array('password' => $info['password'])); + $auth->addUser($info['user_name'], ['password' => $info['password']]); // Attempt to add/update any extra data handed in. if (!empty($info['extra'])) { @@ -43,13 +44,14 @@ public function addSignup(&$info) $injector->getInstance('Horde_Core_Hooks')->callHook( 'signup_addextra', 'horde', - array( + [ $info['user_name'], $info['extra'], - $info['password'] - ) + $info['password'], + ] ); - } catch (Horde_Exception_HookNotSet $e) {} + } catch (Horde_Exception_HookNotSet $e) { + } } } @@ -77,10 +79,10 @@ public function queueSignup(&$info) if (!empty($info['extra'])) { $signup->setData($info['extra']); } - $signup->setData(array_merge($signup->getData(), array( + $signup->setData(array_merge($signup->getData(), [ 'dateReceived' => time(), 'password' => $info['password'], - ))); + ])); $this->_queueSignup($signup); @@ -88,29 +90,30 @@ public function queueSignup(&$info) $injector->getInstance('Horde_Core_Hooks')->callHook( 'signup_queued', 'horde', - array( + [ $info['user_name'], - $info - ) + $info, + ] ); - } catch (Horde_Exception_HookNotSet $e) {} + } catch (Horde_Exception_HookNotSet $e) { + } if (!empty($conf['signup']['email'])) { - $link = Horde::url($registry->get('webroot', 'horde') . '/admin/signup_confirm.php', true, -1)->setRaw(true)->add(array( + $link = Horde::url($registry->get('webroot', 'horde') . '/admin/signup_confirm.php', true, -1)->setRaw(true)->add([ 'u' => $signup->getName(), - 'h' => hash_hmac('sha1', $signup->getName(), $conf['secret_key']) - )); - $message = sprintf(Horde_Core_Translation::t("A new account for the user \"%s\" has been requested through the signup form."), $signup->getName()) + 'h' => hash_hmac('sha1', $signup->getName(), $conf['secret_key']), + ]); + $message = sprintf(Horde_Core_Translation::t('A new account for the user "%s" has been requested through the signup form.'), $signup->getName()) . "\n\n" - . Horde_Core_Translation::t("Approve the account:") + . Horde_Core_Translation::t('Approve the account:') . "\n" . $link->copy()->add('a', 'approve') . "\n" - . Horde_Core_Translation::t("Deny the account:") + . Horde_Core_Translation::t('Deny the account:') . "\n" . $link->copy()->add('a', 'deny'); - $mail = new Horde_Mime_Mail(array( + $mail = new Horde_Mime_Mail([ 'body' => $message, - 'Subject' => sprintf(Horde_Core_Translation::t("Account signup request for \"%s\""), $signup->getName()), + 'Subject' => sprintf(Horde_Core_Translation::t('Account signup request for "%s"'), $signup->getName()), 'To' => $conf['signup']['email'], - 'From' => $conf['signup']['email'])); + 'From' => $conf['signup']['email']]); $mail->send($injector->getInstance('Horde_Mail')); } } @@ -132,15 +135,16 @@ protected function _preSignup(&$info) $info = $injector->getInstance('Horde_Core_Hooks')->callHook( 'signup_preprocess', 'horde', - array($info) + [$info] ); - } catch (Horde_Exception_HookNotSet $e) {} + } catch (Horde_Exception_HookNotSet $e) { + } // Check to see if the username already exists in the auth backend or // the signup queue. if ($auth->exists($info['user_name']) || $this->exists($info['user_name'])) { - throw new Horde_Exception(sprintf(Horde_Core_Translation::t("Username \"%s\" already exists."), $info['user_name'])); + throw new Horde_Exception(sprintf(Horde_Core_Translation::t('Username "%s" already exists.'), $info['user_name'])); } } diff --git a/lib/Horde/Core/Auth/Signup/Form.php b/lib/Horde/Core/Auth/Signup/Form.php index 6ca0c6247..73ccde342 100644 --- a/lib/Horde/Core/Auth/Signup/Form.php +++ b/lib/Horde/Core/Auth/Signup/Form.php @@ -1,4 +1,5 @@ setButtons(Horde_Core_Translation::t("Sign up")); + $this->setButtons(Horde_Core_Translation::t('Sign up')); $this->addHidden('', 'url', 'text', false); @@ -36,28 +37,35 @@ public function __construct(&$vars) try { $extra = $GLOBALS['injector']->getInstance('Horde_Core_Hooks') ->callHook('signup_getextra', 'horde'); - } catch (Horde_Exception_HookNotSet $e) {} + } catch (Horde_Exception_HookNotSet $e) { + } if (!empty($extra)) { if (!isset($extra['user_name'])) { - $this->addVariable(Horde_Core_Translation::t("Choose a username"), 'user_name', 'text', true); + $this->addVariable(Horde_Core_Translation::t('Choose a username'), 'user_name', 'text', true); } if (!isset($extra['password'])) { - $this->addVariable(Horde_Core_Translation::t("Choose a password"), 'password', 'passwordconfirm', true, false, Horde_Core_Translation::t("Type your password twice to confirm")); + $this->addVariable(Horde_Core_Translation::t('Choose a password'), 'password', 'passwordconfirm', true, false, Horde_Core_Translation::t('Type your password twice to confirm')); } foreach ($extra as $field_name => $field) { - $readonly = isset($field['readonly']) ? $field['readonly'] : null; - $desc = isset($field['desc']) ? $field['desc'] : null; - $required = isset($field['required']) ? $field['required'] : false; - $field_params = isset($field['params']) ? $field['params'] : array(); + $readonly = $field['readonly'] ?? null; + $desc = $field['desc'] ?? null; + $required = $field['required'] ?? false; + $field_params = $field['params'] ?? []; - $this->addVariable($field['label'], 'extra[' . $field_name . ']', - $field['type'], $required, $readonly, - $desc, $field_params); + $this->addVariable( + $field['label'], + 'extra[' . $field_name . ']', + $field['type'], + $required, + $readonly, + $desc, + $field_params + ); } } else { - $this->addVariable(Horde_Core_Translation::t("Choose a username"), 'user_name', 'text', true); - $this->addVariable(Horde_Core_Translation::t("Choose a password"), 'password', 'passwordconfirm', true, false, Horde_Core_Translation::t("Type your password twice to confirm")); + $this->addVariable(Horde_Core_Translation::t('Choose a username'), 'user_name', 'text', true); + $this->addVariable(Horde_Core_Translation::t('Choose a password'), 'password', 'passwordconfirm', true, false, Horde_Core_Translation::t('Type your password twice to confirm')); } } @@ -84,7 +92,7 @@ public function getInfo($vars, &$info) /** * Get the renderer for this form */ - function getRenderer($params = array()) + public function getRenderer($params = []) { $renderer = new Horde_Core_Ui_ModalFormRenderer($params); return $renderer; diff --git a/lib/Horde/Core/Auth/Signup/Null.php b/lib/Horde/Core/Auth/Signup/Null.php index 33f764fa5..212b5974a 100644 --- a/lib/Horde/Core/Auth/Signup/Null.php +++ b/lib/Horde/Core/Auth/Signup/Null.php @@ -1,4 +1,5 @@ _params = array_merge( $this->_params, - array('table' => 'horde_signups'), - Horde::getDriverConfig('signup', 'Sql')); + ['table' => 'horde_signups'], + Horde::getDriverConfig('signup', 'Sql') + ); } /** @@ -47,12 +49,12 @@ protected function _queueSignup($signup) . ' (user_name, signup_date, signup_host, signup_data) VALUES (?, ?, ?, ?) '; $remote = $registry->remoteHost(); - $values = array( + $values = [ $signup->getName(), time(), $remote->addr, - serialize($signup->getData()) - ); + serialize($signup->getData()), + ]; $GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('horde', 'signup')->insert($query, $values); } @@ -73,7 +75,7 @@ public function exists($user) $query = 'SELECT 1 FROM ' . $this->_params['table'] . ' WHERE user_name = ?'; - $values = array($user); + $values = [$user]; return (bool)$GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('horde', 'signup')->selectValue($query, $values); } @@ -92,11 +94,11 @@ public function getQueuedSignup($username) { $query = 'SELECT * FROM ' . $this->_params['table'] . ' WHERE user_name = ?'; - $values = array($username); + $values = [$username]; $result = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('horde', 'signup')->selectOne($query, $values); if (empty($result)) { - throw new Horde_Exception(sprintf(Horde_Core_Translation::t("User \"%s\" does not exist."), $username)); + throw new Horde_Exception(sprintf(Horde_Core_Translation::t('User "%s" does not exist.'), $username)); } $object = new Horde_Core_Auth_Signup_SqlObject($result['user_name']); $object->setData($result); @@ -118,7 +120,7 @@ public function getQueuedSignups() $result = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('horde', 'signup')->select($query); - $signups = array(); + $signups = []; foreach ($result as $signup) { $object = new Horde_Core_Auth_Signup_SqlObject($signup['user_name']); $object->setData($signup); @@ -139,7 +141,7 @@ public function removeQueuedSignup($username) { $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE user_name = ?'; - $values = array($username); + $values = [$username]; $GLOBALS['injector']->getInstance('Horde_Core_Factory_Db')->create('horde', 'signup')->delete($query, $values); } diff --git a/lib/Horde/Core/Auth/Signup/SqlObject.php b/lib/Horde/Core/Auth/Signup/SqlObject.php index 3f14ad5e7..6dddc499f 100644 --- a/lib/Horde/Core/Auth/Signup/SqlObject.php +++ b/lib/Horde/Core/Auth/Signup/SqlObject.php @@ -1,4 +1,5 @@ _base->getError($msg); } -} \ No newline at end of file +} diff --git a/lib/Horde/Core/Auth/X509.php b/lib/Horde/Core/Auth/X509.php index 11758b2a7..2617a767c 100644 --- a/lib/Horde/Core/Auth/X509.php +++ b/lib/Horde/Core/Auth/X509.php @@ -1,4 +1,5 @@ _app = $app; @@ -114,7 +115,7 @@ public function getName() */ public function getParams() { - return $this->_call('_params', array()); + return $this->_call('_params', []); } /** @@ -124,7 +125,7 @@ public function getParams() */ protected function _params() { - return array(); + return []; } /** @@ -246,8 +247,8 @@ protected function _ajaxUpdate(Horde_Variables $vars) protected function _ajaxUpdateUrl() { $ajax_url = $GLOBALS['registry']->getServiceLink('ajax') - ->add(array('app' => $this->getApp(), - 'blockid' => get_class($this))); + ->add(['app' => $this->getApp(), + 'blockid' => get_class($this)]); $ajax_url->pathInfo = 'blockUpdate'; return $ajax_url; @@ -265,10 +266,10 @@ protected function _ajaxUpdateUrl() protected function _call($name, $default, $args = null) { try { - $pushed = $GLOBALS['registry']->pushApp($this->getApp(), array( + $pushed = $GLOBALS['registry']->pushApp($this->getApp(), [ 'check_perms' => true, - 'logintasks' => false - )); + 'logintasks' => false, + ]); } catch (Horde_Exception $e) { return $default; } @@ -276,7 +277,7 @@ protected function _call($name, $default, $args = null) try { $ret = is_null($args) ? $this->$name() - : call_user_func(array($this, $name), $args); + : call_user_func([$this, $name], $args); } catch (Horde_Exception $e) { $ret = $default; } diff --git a/lib/Horde/Core/Block/Collection.php b/lib/Horde/Core/Block/Collection.php index 5aeab64e2..ccc01ffba 100644 --- a/lib/Horde/Core/Block/Collection.php +++ b/lib/Horde/Core/Block/Collection.php @@ -1,4 +1,5 @@ getValue($this->_layout)); if (empty($layout)) { - $layout = array(); + $layout = []; if (isset($GLOBALS['conf']['portal']['fixed_blocks'])) { foreach ($GLOBALS['conf']['portal']['fixed_blocks'] as $block) { - list($app, $type) = explode(':', $block, 2); - $layout[] = array( - array( + [$app, $type] = explode(':', $block, 2); + $layout[] = [ + [ 'app' => $app, - 'params' => array( + 'params' => [ 'type2' => $type, - 'params' => false - ), + 'params' => false, + ], 'height' => 1, - 'width' => 1 - ) - ); + 'width' => 1, + ], + ]; } } } @@ -154,7 +155,7 @@ public function getBlock($app, $name, $params = null) */ public function getBlocksList() { - $blocks = array(); + $blocks = []; $this->_loadBlocks(); @@ -177,7 +178,7 @@ public function getBlocksList() */ public function getFixedBlocks() { - $layout = array(); + $layout = []; return $layout; @@ -193,9 +194,12 @@ public function getFixedBlocks() * * @return string The select tag with all available blocks. */ - public function getBlocksWidget($cur_app = null, $cur_block = null, - $onchange = false, $readonly = false) - { + public function getBlocksWidget( + $cur_app = null, + $cur_block = null, + $onchange = false, + $readonly = false + ) { $widget = '', $param_id, $checked); - break; - - case 'enum': - $widget = sprintf('', $param_id, $checked); + break; + + case 'enum': + $widget = sprintf(''; - break; + $widget .= ''; + break; - case 'multienum': - $widget = sprintf('', $param_id); + foreach ($param['values'] as $key => $name) { + if (Horde_String::length($name) > 30) { + $name = substr($name, 0, 27) . '...'; + } + $widget .= sprintf( + "\n", + htmlspecialchars($key), + (isset($val[$param_id]) && in_array($key, $val[$param_id])) ? ' selected="selected"' : '', + htmlspecialchars($name) + ); } - $widget .= sprintf("\n", - htmlspecialchars($key), - (isset($val[$param_id]) && in_array($key, $val[$param_id])) ? ' selected="selected"' : '', - htmlspecialchars($name)); - } - $widget .= ''; - break; + $widget .= ''; + break; - case 'mlenum': - // Multi-level enum. - if (is_array($val) && isset($val['__' . $param_id])) { - $firstval = $val['__' . $param_id]; - } else { - $tmp = array_keys($param['values']); - $firstval = current($tmp); - } - $blockvalues = $param['values'][$firstval]; - asort($blockvalues); - - $widget = sprintf('
\n"; - - $widget .= sprintf("
\n"; - break; + case 'mlenum': + // Multi-level enum. + if (is_array($val) && isset($val['__' . $param_id])) { + $firstval = $val['__' . $param_id]; + } else { + $tmp = array_keys($param['values']); + $firstval = current($tmp); + } + $blockvalues = $param['values'][$firstval]; + asort($blockvalues); + + $widget = sprintf('
\n"; + + $widget .= sprintf("
\n"; + break; - case 'int': - case 'text': - $widget = sprintf('', $param_id, !isset($val[$param_id]) ? $param['default'] : $val[$param_id]); - break; + case 'int': + case 'text': + $widget = sprintf('', $param_id, !isset($val[$param_id]) ? $param['default'] : $val[$param_id]); + break; - case 'password': - $widget = sprintf('', $param_id, !isset($val[$param_id]) ? $param['default'] : $val[$param_id]); - break; + case 'password': + $widget = sprintf('', $param_id, !isset($val[$param_id]) ? $param['default'] : $val[$param_id]); + break; - case 'error': - $widget = '' . $param['default'] . ''; - break; + case 'error': + $widget = '' . $param['default'] . ''; + break; } return $widget; @@ -395,7 +406,7 @@ public function getName($app, $block) return isset($this->_blocks[$app][$block]) ? $this->_blocks[$app][$block]['name'] - : sprintf(Horde_Core_Translation::t("Block \"%s\" of application \"%s\" not found."), $block, $app); + : sprintf(Horde_Core_Translation::t('Block "%s" of application "%s" not found.'), $block, $app); } /** @@ -411,7 +422,7 @@ public function getParams($app, $block) $this->_loadBlocks(); if (!isset($this->_blocks[$app][$block])) { - return array(); + return []; } if (!isset($this->_blocks[$app][$block]['params'])) { @@ -424,7 +435,7 @@ public function getParams($app, $block) return array_keys($this->_blocks[$app][$block]['params']); } - return array(); + return []; } /** @@ -456,9 +467,8 @@ public function getDefaultValue($app, $block, $param) { /* getParams() loads $_blocks */ $this->getParams($app, $block); - return isset($this->_blocks[$app][$block]['params'][$param]['default']) - ? $this->_blocks[$app][$block]['params'][$param]['default'] - : null; + return $this->_blocks[$app][$block]['params'][$param]['default'] + ?? null; } /** @@ -491,7 +501,7 @@ public function _loadBlocks() } $currentApp = $registry->getApp(); - $this->_blocks = array(); + $this->_blocks = []; foreach ($this->_apps as $app) { $drivers = $registry->getAppDrivers($app, 'Block'); @@ -516,16 +526,16 @@ public function serialize() public function __serialize(): array { - return array( + return [ $this->_apps, $this->_blocks, - $this->_layout - ); + $this->_layout, + ]; } public function jsonSerialize(): mixed { - return json_encode($this->__serialize()); + return json_encode($this->__serialize()); } public function unserialize($data) @@ -535,11 +545,11 @@ public function unserialize($data) public function __unserialize(array $data): void { - list( + [ $this->_apps, $this->_blocks, $this->_layout - ) = $data; + ] = $data; } } diff --git a/lib/Horde/Core/Block/Layout.php b/lib/Horde/Core/Block/Layout.php index b6d6af7d9..6aae12ab4 100644 --- a/lib/Horde/Core/Block/Layout.php +++ b/lib/Horde/Core/Block/Layout.php @@ -1,4 +1,5 @@ _editUrl) ->unique() ->setAnchor('block') - ->add(array( + ->add( + [ 'col' => $col, 'row' => $row, 'action' => $action, - 'url' => Horde::signUrl($this->_viewUrl) - ) - ); + 'url' => Horde::signUrl($this->_viewUrl), + ] + ); } /** @@ -108,19 +110,24 @@ public function getHeaderIcons($row, $col, $edit, $url = null) $icons = ''; if ($edit) { - $icons .= Horde::link($this->getActionUrl('edit', $row, $col), - Horde_Core_Translation::t("Edit")) - . Horde_Themes_Image::tag('edit.png', array('alt' => Horde_Core_Translation::t("Edit"))) + $icons .= Horde::link( + $this->getActionUrl('edit', $row, $col), + Horde_Core_Translation::t('Edit') + ) + . Horde_Themes_Image::tag('edit.png', ['alt' => Horde_Core_Translation::t('Edit')]) . '
'; } if ($this->isRemovable($row, $col)) { $icons .= Horde::link( - $this->getActionUrl('removeBlock', $row, $col), Horde_Core_Translation::t("Remove"), - '', '', + $this->getActionUrl('removeBlock', $row, $col), + Horde_Core_Translation::t('Remove'), + '', + '', 'return window.confirm(\'' - . addslashes(Horde_Core_Translation::t("Really delete this block?")) . '\')') - . Horde_Themes_Image::tag('delete.png', array('alt' => Horde_Core_Translation::t("Remove"))) + . addslashes(Horde_Core_Translation::t('Really delete this block?')) . '\')' + ) + . Horde_Themes_Image::tag('delete.png', ['alt' => Horde_Core_Translation::t('Remove')]) . ''; } diff --git a/lib/Horde/Core/Block/Layout/Manager.php b/lib/Horde/Core/Block/Layout/Manager.php index b1a177430..5cfc150ac 100644 --- a/lib/Horde/Core/Block/Layout/Manager.php +++ b/lib/Horde/Core/Block/Layout/Manager.php @@ -1,4 +1,5 @@ _layout); - $emptyrows = array(); + $emptyrows = []; for ($row = 0; $row < $rows; $row++) { $cols = count($this->_layout[$row]); @@ -137,7 +138,7 @@ public function __construct(Horde_Core_Block_Collection $collection) } // Fill all rows up to the same length. - $layout = array(); + $layout = []; for ($row = 0; $row < $rows; ++$row) { $cols = count($this->_layout[$row]); if ($cols < $this->_columns) { @@ -182,97 +183,98 @@ public function unserialize($data) public function handle($action, $row, $col, $url = null) { switch ($action) { - case 'moveUp': - case 'moveDown': - case 'moveLeft': - case 'moveRight': - case 'expandUp': - case 'expandDown': - case 'expandLeft': - case 'expandRight': - case 'shrinkLeft': - case 'shrinkRight': - case 'shrinkUp': - case 'shrinkDown': - case 'removeBlock': - try { - call_user_func(array($this, $action), $row, $col); - $this->_updated = true; - } catch (Horde_Exception $e) { - $GLOBALS['notification']->push($e); - } - break; - - // Save the changes made to a block. - case 'save': - // Save the changes made to a block and continue editing. - case 'save-resume': - // Check form token. - $GLOBALS['session']->checkToken(Horde_Util::getFormData('token')); - - // Get requested block type. - list($newapp, $newtype) = explode(':', Horde_Util::getFormData('app')); - - // Is this a new block? - $new = false; - if ($this->isEmpty($row, $col) || - !$this->rowExists($row) || - !$this->colExists($col)) { - // Check permissions. - $max_blocks = $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_blocks'); - if (($max_blocks !== true) && - ($max_blocks <= count($this))) { - Horde::permissionDeniedError( - 'horde', - 'max_blocks', - sprintf(Horde_Core_Translation::ngettext("You are not allowed to create more than %d block.", "You are not allowed to create more than %d blocks.", $max_blocks), $max_blocks) - ); - break; + case 'moveUp': + case 'moveDown': + case 'moveLeft': + case 'moveRight': + case 'expandUp': + case 'expandDown': + case 'expandLeft': + case 'expandRight': + case 'shrinkLeft': + case 'shrinkRight': + case 'shrinkUp': + case 'shrinkDown': + case 'removeBlock': + try { + call_user_func([$this, $action], $row, $col); + $this->_updated = true; + } catch (Horde_Exception $e) { + $GLOBALS['notification']->push($e); } + break; - $new = true; - // Make sure there is somewhere to put it. - $this->addBlock($row, $col); - } + // Save the changes made to a block. + case 'save': + // Save the changes made to a block and continue editing. + case 'save-resume': + // Check form token. + $GLOBALS['session']->checkToken(Horde_Util::getFormData('token')); + + // Get requested block type. + [$newapp, $newtype] = explode(':', Horde_Util::getFormData('app')); + + // Is this a new block? + $new = false; + if ($this->isEmpty($row, $col) || + !$this->rowExists($row) || + !$this->colExists($col)) { + // Check permissions. + $max_blocks = $GLOBALS['injector']->getInstance('Horde_Core_Perms')->hasAppPermission('max_blocks'); + if (($max_blocks !== true) && + ($max_blocks <= count($this))) { + Horde::permissionDeniedError( + 'horde', + 'max_blocks', + sprintf(Horde_Core_Translation::ngettext('You are not allowed to create more than %d block.', 'You are not allowed to create more than %d blocks.', $max_blocks), $max_blocks) + ); + break; + } - // Or an existing one? - $exists = false; - $changed = false; - if (!$new) { - // Get target block info. - $info = $this->getBlockInfo($row, $col); - $exists = $this->isBlock($row, $col); - // Has a different block been selected? - if ($exists && - ($info['app'] != $newapp || - $info['block'] != $newtype)) { - $changed = true; + $new = true; + // Make sure there is somewhere to put it. + $this->addBlock($row, $col); } - } - if ($new || $changed) { - // Change app or type. - $info = array('app' => $newapp, - 'block' => $newtype); - $params = $this->_collection->getParams($newapp, $newtype); - foreach ($params as $newparam) { - $info['params'][$newparam] = $this->_collection->getDefaultValue($newapp, $newtype, $newparam); + // Or an existing one? + $exists = false; + $changed = false; + if (!$new) { + // Get target block info. + $info = $this->getBlockInfo($row, $col); + $exists = $this->isBlock($row, $col); + // Has a different block been selected? + if ($exists && + ($info['app'] != $newapp || + $info['block'] != $newtype)) { + $changed = true; + } + } + + if ($new || $changed) { + // Change app or type. + $info = ['app' => $newapp, + 'block' => $newtype]; + $params = $this->_collection->getParams($newapp, $newtype); + foreach ($params as $newparam) { + $info['params'][$newparam] = $this->_collection->getDefaultValue($newapp, $newtype, $newparam); + } + $this->setBlockInfo($row, $col, $info); + } elseif ($exists) { + // Change values. + $this->setBlockInfo($row, $col, ['params' => Horde_Util::getFormData('params', [])]); + } + $this->_updated = true; + if ($action == 'save') { + break; } - $this->setBlockInfo($row, $col, $info); - } elseif ($exists) { - // Change values. - $this->setBlockInfo($row, $col, array('params' => Horde_Util::getFormData('params', array()))); - } - $this->_updated = true; - if ($action == 'save') { - break; - } - // Make a block the current block for editing. - case 'edit': - $this->_currentBlock = array($row, $col); - $url = null; - break; + // Make a block the current block for editing. + // no break + case 'edit': + $this->_currentBlock = [$row, $col]; + $url = null; + break; } if (!empty($url)) { @@ -316,9 +318,11 @@ public function getBlock($row, $col) $this->_blocks[$row][$col] = $GLOBALS['injector'] ->getInstance('Horde_Core_Factory_BlockCollection') ->create() - ->getBlock($field['app'], - $field['params']['type2'], - $field['params']['params']); + ->getBlock( + $field['app'], + $field['params']['type2'], + $field['params']['params'] + ); } return $this->_blocks[$row][$col]; @@ -341,7 +345,7 @@ public function getBlockAt($row, $col) if ($this->isEmpty($row, $col)) { return null; } elseif (!$this->isCovered($row, $col)) { - return array($row, $col); + return [$row, $col]; } /* This is a covered field. */ @@ -349,14 +353,14 @@ public function getBlockAt($row, $col) if (!$this->isCovered($test, $col) && !$this->isEmpty($test, $col) && $test + $this->getHeight($test, $col) - 1 == $row) { - return array($test, $col); + return [$test, $col]; } } for ($test = $col - 1; $test >= 0; $test--) { if (!$this->isCovered($row, $test) && !$this->isEmpty($test, $col) && $test + $this->getWidth($row, $test) - 1 == $col) { - return array($row, $test); + return [$row, $test]; } } } @@ -384,11 +388,11 @@ public function getBlockInfo($row, $col) throw new Horde_Exception('No block exists at the requested position'); } - return array( + return [ 'app' => $this->_layout[$row][$col]['app'], 'block' => $this->_layout[$row][$col]['params']['type2'], - 'params' => $this->_layout[$row][$col]['params']['params'] - ); + 'params' => $this->_layout[$row][$col]['params']['params'], + ]; } /** @@ -404,7 +408,7 @@ public function getBlockInfo($row, $col) * * @throws Horde_Exception */ - public function setBlockInfo($row, $col, $info = array()) + public function setBlockInfo($row, $col, $info = []) { if (!isset($this->_layout[$row][$col])) { throw new Horde_Exception('No block exists at the requested position'); @@ -535,59 +539,59 @@ public function getControl($type, $row, $col) $url = $this->getActionUrl($action, $row, $col); switch ($type[0]) { - case 'expand': - $title = Horde_Core_Translation::t("Expand"); - $img = 'large_' . $type[1]; - break; - - case 'shrink': - $title = Horde_Core_Translation::t("Shrink"); - $img = 'large_'; - - switch ($type[1]) { - case 'up': - $img .= 'down'; + case 'expand': + $title = Horde_Core_Translation::t('Expand'); + $img = 'large_' . $type[1]; break; - case 'down': - $img .= 'up'; - break; + case 'shrink': + $title = Horde_Core_Translation::t('Shrink'); + $img = 'large_'; - case 'left': - $img .= 'right'; - break; + switch ($type[1]) { + case 'up': + $img .= 'down'; + break; - case 'right': - $img .= 'left'; - break; - } - break; + case 'down': + $img .= 'up'; + break; - case 'move': - switch ($type[1]) { - case 'up': - $title = Horde_Core_Translation::t("Move Up"); - break; + case 'left': + $img .= 'right'; + break; - case 'down': - $title = Horde_Core_Translation::t("Move Down"); + case 'right': + $img .= 'left'; + break; + } break; - case 'left': - $title = Horde_Core_Translation::t("Move Left"); - break; + case 'move': + switch ($type[1]) { + case 'up': + $title = Horde_Core_Translation::t('Move Up'); + break; - case 'right': - $title = Horde_Core_Translation::t("Move Right"); - break; - } + case 'down': + $title = Horde_Core_Translation::t('Move Down'); + break; - $img = $type[1]; - break; + case 'left': + $title = Horde_Core_Translation::t('Move Left'); + break; + + case 'right': + $title = Horde_Core_Translation::t('Move Right'); + break; + } + + $img = $type[1]; + break; } return Horde::link($url, $title) . - Horde_Themes_Image::tag('block/' . $img . '.png', array('alt' => $title)) . ''; + Horde_Themes_Image::tag('block/' . $img . '.png', ['alt' => $title]) . ''; } /** @@ -673,11 +677,11 @@ public function addBlock($row, $col) $this->addCol($col); } - $this->_layout[$row][$col] = array('app' => null, + $this->_layout[$row][$col] = ['app' => null, 'height' => 1, 'width' => 1, - 'params' => array('type2' => null, - 'params' => array())); + 'params' => ['type2' => null, + 'params' => []]]; } /** @@ -815,10 +819,20 @@ public function moveUp($row, $col) $in_way[1] == $col && $this->getWidth($in_way[0], $in_way[1]) == $width) { // We need to swap the blocks. - $rec1 = Horde_Array::getRectangle($this->_layout, $row, $col, - $this->getHeight($row, $col), $this->getWidth($row, $col)); - $rec2 = Horde_Array::getRectangle($this->_layout, $in_way[0], $in_way[1], - $this->getHeight($in_way[0], $in_way[1]), $this->getWidth($in_way[0], $in_way[1])); + $rec1 = Horde_Array::getRectangle( + $this->_layout, + $row, + $col, + $this->getHeight($row, $col), + $this->getWidth($row, $col) + ); + $rec2 = Horde_Array::getRectangle( + $this->_layout, + $in_way[0], + $in_way[1], + $this->getHeight($in_way[0], $in_way[1]), + $this->getWidth($in_way[0], $in_way[1]) + ); for ($j = 0; $j < count($rec1); $j++) { for ($k = 0; $k < count($rec1[$j]); $k++) { $this->_layout[$in_way[0] + $j][$in_way[1] + $k] = $rec1[$j][$k]; @@ -879,10 +893,20 @@ public function moveDown($row, $col) $in_way[1] == $col && $this->getWidth($in_way[0], $in_way[1]) == $width) { // We need to swap the blocks. - $rec1 = Horde_Array::getRectangle($this->_layout, $row, $col, - $this->getHeight($row, $col), $this->getWidth($row, $col)); - $rec2 = Horde_Array::getRectangle($this->_layout, $in_way[0], $in_way[1], - $this->getHeight($in_way[0], $in_way[1]), $this->getWidth($in_way[0], $in_way[1])); + $rec1 = Horde_Array::getRectangle( + $this->_layout, + $row, + $col, + $this->getHeight($row, $col), + $this->getWidth($row, $col) + ); + $rec2 = Horde_Array::getRectangle( + $this->_layout, + $in_way[0], + $in_way[1], + $this->getHeight($in_way[0], $in_way[1]), + $this->getWidth($in_way[0], $in_way[1]) + ); for ($j = 0; $j < count($rec2); $j++) { for ($k = 0; $k < count($rec2[$j]); $k++) { $this->_layout[$row + $j][$col + $k] = $rec2[$j][$k]; @@ -929,9 +953,9 @@ public function moveDown($row, $col) * * @return boolean True if all rows could be moved down. */ - function moveDownBelow($row) + public function moveDownBelow($row) { - $moved = array(); + $moved = []; for ($y = count($this->_layout) - 1; $y > $row; $y--) { for ($x = 0; $x < $this->_columns; $x++) { $block = $this->getBlockAt($y, $x); @@ -972,10 +996,20 @@ public function moveLeft($row, $col) $in_way[0] == $row && $this->getHeight($in_way[0], $in_way[1]) == $height) { // We need to swap the blocks. - $rec1 = Horde_Array::getRectangle($this->_layout, $row, $col, - $this->getHeight($row, $col), $this->getWidth($row, $col)); - $rec2 = Horde_Array::getRectangle($this->_layout, $in_way[0], $in_way[1], - $this->getHeight($in_way[0], $in_way[1]), $this->getWidth($in_way[0], $in_way[1])); + $rec1 = Horde_Array::getRectangle( + $this->_layout, + $row, + $col, + $this->getHeight($row, $col), + $this->getWidth($row, $col) + ); + $rec2 = Horde_Array::getRectangle( + $this->_layout, + $in_way[0], + $in_way[1], + $this->getHeight($in_way[0], $in_way[1]), + $this->getWidth($in_way[0], $in_way[1]) + ); for ($j = 0; $j < count($rec1); $j++) { for ($k = 0; $k < count($rec1[$j]); $k++) { $this->_layout[$in_way[0] + $j][$in_way[1] + $k] = $rec1[$j][$k]; @@ -1039,10 +1073,20 @@ public function moveRight($row, $col) $in_way[0] == $row && $this->getHeight($in_way[0], $in_way[1]) == $height) { // We need to swap the blocks. - $rec1 = Horde_Array::getRectangle($this->_layout, $row, $col, - $this->getHeight($row, $col), $this->getWidth($row, $col)); - $rec2 = Horde_Array::getRectangle($this->_layout, $in_way[0], $in_way[1], - $this->getHeight($in_way[0], $in_way[1]), $this->getWidth($in_way[0], $in_way[1])); + $rec1 = Horde_Array::getRectangle( + $this->_layout, + $row, + $col, + $this->getHeight($row, $col), + $this->getWidth($row, $col) + ); + $rec2 = Horde_Array::getRectangle( + $this->_layout, + $in_way[0], + $in_way[1], + $this->getHeight($in_way[0], $in_way[1]), + $this->getWidth($in_way[0], $in_way[1]) + ); for ($j = 0; $j < count($rec2); $j++) { for ($k = 0; $k < count($rec2[$j]); $k++) { $this->_layout[$row + $j][$col + $k] = $rec2[$j][$k]; @@ -1091,7 +1135,7 @@ public function moveRight($row, $col) */ public function moveRightAfter($col) { - $moved = array(); + $moved = []; for ($x = $this->_columns - 1; $x > $col; $x--) { for ($y = 0; $y < count($this->_layout); $y++) { $block = $this->getBlockAt($y, $x); diff --git a/lib/Horde/Core/Block/Layout/View.php b/lib/Horde/Core/Block/Layout/View.php index a67e8bfc3..0ba209e9c 100644 --- a/lib/Horde/Core/Block/Layout/View.php +++ b/lib/Horde/Core/Block/Layout/View.php @@ -1,4 +1,5 @@ '; $bc = $GLOBALS['injector']->getInstance('Horde_Core_Factory_BlockCollection')->create(); - $covered = array(); - $js = array(); + $covered = []; + $js = []; foreach ($this->_layout as $row_num => $row) { $width = floor(100 / count($row)); $html .= ''; @@ -87,7 +88,7 @@ public function toHtml() $colspan = $item['width']; for ($i = 0; $i < $item['height']; $i++) { if (!isset($covered[$row_num + $i])) { - $covered[$row_num + $i] = array(); + $covered[$row_num + $i] = []; } for ($j = 0; $j < $item['width']; $j++) { $covered[$row_num + $i][$col_num + $j] = true; @@ -104,9 +105,8 @@ public function toHtml() if ($block->updateable && $GLOBALS['browser']->hasFeature('xmlhttpreq')) { - $refresh_time = isset($item['params']['params']['_refresh_time']) - ? $item['params']['params']['_refresh_time'] - : $interval; + $refresh_time = $item['params']['params']['_refresh_time'] + ?? $interval; if (!empty($refresh_time)) { $js[] = 'HordeBlocks.addUpdateableBlock(' . @@ -120,7 +120,7 @@ public function toHtml() $html .= ' '; } } catch (Horde_Exception $e) { - $header = Horde_Core_Translation::t("Error"); + $header = Horde_Core_Translation::t('Error'); $content = $e->getMessage(); ob_start(); include $tplDir . '/portal/block.inc'; @@ -155,15 +155,15 @@ public function getApplications() public function getStylesheets() { $css = $GLOBALS['injector']->getInstance('Horde_PageOutput')->css; - $stylesheets = array(); + $stylesheets = []; foreach ($this->getApplications() as $app) { - $app_css = $css->getStylesheets('', array( + $app_css = $css->getStylesheets('', [ 'app' => $app, 'nohorde' => !in_array('horde', $this->getApplications()), 'sub' => 'block', - 'subonly' => true - )); + 'subonly' => true, + ]); if (!empty($app_css)) { $stylesheets = array_merge($stylesheets, $app_css); diff --git a/lib/Horde/Core/Block/Upgrade.php b/lib/Horde/Core/Block/Upgrade.php index 7830160f0..3f0933956 100644 --- a/lib/Horde/Core/Block/Upgrade.php +++ b/lib/Horde/Core/Block/Upgrade.php @@ -1,4 +1,5 @@ getInstance('Horde_Core_Hooks') - ->callHook('browser_modify', 'horde', array($this)); - } catch (Horde_Exception_HookNotSet $e) {} + ->callHook('browser_modify', 'horde', [$this]); + } catch (Horde_Exception_HookNotSet $e) { + } } } diff --git a/lib/Horde/Core/Bundle.php b/lib/Horde/Core/Bundle.php index 91eee7563..9e6dcc4bc 100644 --- a/lib/Horde/Core/Bundle.php +++ b/lib/Horde/Core/Bundle.php @@ -1,4 +1,5 @@ true, 'authentication' => 'none')); + Horde_Registry::appInit('horde', ['nocompress' => true, 'authentication' => 'none']); $this->_config = new Horde_Config(); umask($umask); } @@ -78,7 +79,8 @@ public function configDb() $vars, 'sql', 'phptype', - $sql_config['switch']['custom']['fields']['phptype']); + $sql_config['switch']['custom']['fields']['phptype'] + ); $this->writeConfig($vars); } diff --git a/lib/Horde/Core/Cache/Session.php b/lib/Horde/Core/Cache/Session.php index 63aaeed84..da023f4ad 100644 --- a/lib/Horde/Core/Cache/Session.php +++ b/lib/Horde/Core/Cache/Session.php @@ -1,4 +1,5 @@ 'horde', 'maxsize' => 5000, - 'storage_key' => 'sess_cache' - ), + 'storage_key' => 'sess_cache', + ], $params )); } @@ -148,7 +149,7 @@ public function clear() foreach (array_keys($this->_stored) as $key) { $this->_params['cache']->expire($key); } - $this->_stored = array(); + $this->_stored = []; $this->_saveStored(); } @@ -162,11 +163,11 @@ protected function _getCid($key, $in_session) return $this->_params['storage_key'] . '/' . $key; } - return implode('|', array( + return implode('|', [ $this->_params['app'], $session->getToken(), - $key - )); + $key, + ]); } /** diff --git a/lib/Horde/Core/Cache/SessionObjects.php b/lib/Horde/Core/Cache/SessionObjects.php index 374addc9a..5b8a3cd09 100644 --- a/lib/Horde/Core/Cache/SessionObjects.php +++ b/lib/Horde/Core/Cache/SessionObjects.php @@ -1,4 +1,5 @@ 'horde', 'cache' => new Horde_Cache_Storage_Null(), /* Sanity checking. */ 'maxsize' => 1048576, - 'storage_key' => 'sess_obcache' - )); + 'storage_key' => 'sess_obcache', + ]); } /** diff --git a/lib/Horde/Core/Cli.php b/lib/Horde/Core/Cli.php index f3ba9c9ce..c29583297 100644 --- a/lib/Horde/Core/Cli.php +++ b/lib/Horde/Core/Cli.php @@ -1,4 +1,5 @@ $case_field) { $values[$case] = $case_field['desc']; } } else { switch ($field['_type']) { - case 'boolean': - $values = array(true => 'Yes', false => 'No'); - $default = (int)$default; - break; - case 'enum': - $values = $field['values']; - break; + case 'boolean': + $values = [true => 'Yes', false => 'No']; + $default = (int)$default; + break; + case 'enum': + $values = $field['values']; + break; } if (!empty($field['required'])) { $question .= $this->red('*'); diff --git a/lib/Horde/Core/Controller/NotAuthorized.php b/lib/Horde/Core/Controller/NotAuthorized.php index acc5f5b4f..8426db2e2 100644 --- a/lib/Horde/Core/Controller/NotAuthorized.php +++ b/lib/Horde/Core/Controller/NotAuthorized.php @@ -1,4 +1,5 @@ setHeader('HTTP/1.0 401 ', 'Not Authorized'); $response->setBody('401 Not Authorized

401 Not Authorized

'); } diff --git a/lib/Horde/Core/Controller/NotFound.php b/lib/Horde/Core/Controller/NotFound.php index ec77d9d76..f55918d1f 100644 --- a/lib/Horde/Core/Controller/NotFound.php +++ b/lib/Horde/Core/Controller/NotFound.php @@ -1,4 +1,5 @@ setHeader('HTTP/1.0 404 ', 'Not Found'); $response->setBody('404 File Not Found

404 File Not Found

'); } diff --git a/lib/Horde/Core/Controller/RequestConfiguration.php b/lib/Horde/Core/Controller/RequestConfiguration.php index de05b65b9..980edbe97 100644 --- a/lib/Horde/Core/Controller/RequestConfiguration.php +++ b/lib/Horde/Core/Controller/RequestConfiguration.php @@ -1,4 +1,5 @@ _classNames = array( + $this->_classNames = [ 'controller' => 'Horde_Core_Controller_NotFound', 'settings' => 'Horde_Controller_SettingsExporter_Default', - ); + ]; } /** diff --git a/lib/Horde/Core/Controller/RequestMapper.php b/lib/Horde/Core/Controller/RequestMapper.php index baca01425..990281c13 100644 --- a/lib/Horde/Core/Controller/RequestMapper.php +++ b/lib/Horde/Core/Controller/RequestMapper.php @@ -1,4 +1,5 @@ listApps(null, false, null) as $app) - { + foreach ($registry->listApps(null, false, null) as $app) { $default = [ 'scheme' => $scheme, 'host' => $host, 'path' => '', - 'app' => $app + 'app' => $app, ]; $applicationUrl = array_merge($default, parse_url($registry->get('webroot', $app))); $applicationUrl['path'] = $this->_normalize($applicationUrl['path']); // sort out cases with wrong host or scheme - if ($scheme != $applicationUrl['scheme']) { continue; } - if ($host != $applicationUrl['host']) { continue; } + if ($scheme != $applicationUrl['scheme']) { + continue; + } + if ($host != $applicationUrl['host']) { + continue; + } // does the path match at all? - if (substr($request->getPath(),0, strlen($applicationUrl['path'])) == $applicationUrl['path']) { + if (substr($request->getPath(), 0, strlen($applicationUrl['path'])) == $applicationUrl['path']) { $matches[] = $applicationUrl; } } @@ -125,10 +129,11 @@ protected function _identifyApp($scheme, $request, $host, $registry) return $matches; } // Longest match path *should* always be the right app - usort($matches, function($a, $b) - { - return strlen($a['path']) <=> strlen($b['path']); - } + usort( + $matches, + function ($a, $b) { + return strlen($a['path']) <=> strlen($b['path']); + } ); return array_pop($matches); } @@ -193,7 +198,7 @@ public function getRequestConfiguration(Horde_Injector $injector) // Load application routes. $mapper = $this->_mapper; - $mapper->environ = array('REQUEST_METHOD' => $request->getMethod()); + $mapper->environ = ['REQUEST_METHOD' => $request->getMethod()]; include $routeFile; if (file_exists($fileroot . '/config/routes.local.php')) { include $fileroot . '/config/routes.local.php'; diff --git a/lib/Horde/Core/Controller/SettingsFinder.php b/lib/Horde/Core/Controller/SettingsFinder.php index 0f837077d..408b2880d 100644 --- a/lib/Horde/Core/Controller/SettingsFinder.php +++ b/lib/Horde/Core/Controller/SettingsFinder.php @@ -1,4 +1,5 @@ getAuth(), - $key - )); + $key, + ]); } } diff --git a/lib/Horde/Core/Dav/Auth.php b/lib/Horde/Core/Dav/Auth.php index 573261ceb..a0bafbb8c 100644 --- a/lib/Horde/Core/Dav/Auth.php +++ b/lib/Horde/Core/Dav/Auth.php @@ -1,4 +1,5 @@ _auth->getCredential('userId'); try { $user = $GLOBALS['injector']->getInstance('Horde_Core_Hooks') - ->callHook('davusername', 'horde', array($user, false)); + ->callHook('davusername', 'horde', [$user, false]); } catch (Horde_Exception_HookNotSet $e) { } return $user; diff --git a/lib/Horde/Core/Db/Migration.php b/lib/Horde/Core/Db/Migration.php index f89fc4716..b95805ab2 100644 --- a/lib/Horde/Core/Db/Migration.php +++ b/lib/Horde/Core/Db/Migration.php @@ -1,4 +1,5 @@ getRegistry(); foreach (glob($pear->get('data_dir') . '/*/migration') as $dir) { $package = $registry->getPackage( - basename(dirname($dir)), 'pear.horde.org'); + basename(dirname($dir)), + 'pear.horde.org' + ); if ($package == false) { Horde::log("Ignoring package in directory $dir", Horde_Log::WARN); continue; @@ -156,16 +159,16 @@ public function __construct($basedir = null, $pearconf = null) * * @return Horde_Db_Migration_Migrator A migrator for the specified module. */ - public function getMigrator($app, Horde_Log_Logger $logger = null) + public function getMigrator($app, ?Horde_Log_Logger $logger = null) { $app = Horde_String::lower($app); $db = $GLOBALS['injector']->getInstance('Horde_Db_Adapter'); return new Horde_Db_Migration_Migrator( $db, $logger, - array( + [ 'migrationsPath' => $this->dirs[array_search($app, $this->_lower)], - 'schemaTableName' => $db->tableAliasFor($app . '_schema_info')) - ); + 'schemaTableName' => $db->tableAliasFor($app . '_schema_info')] + ); } } diff --git a/lib/Horde/Core/Editor/Ckeditor.php b/lib/Horde/Core/Editor/Ckeditor.php index 258fbee4e..e9b714e99 100644 --- a/lib/Horde/Core/Editor/Ckeditor.php +++ b/lib/Horde/Core/Editor/Ckeditor.php @@ -1,4 +1,5 @@ $registry); - $adapter_params = array('factory' => new Horde_Core_ActiveSync_Imap_Factory()); + $params = ['registry' => $registry]; + $adapter_params = ['factory' => new Horde_Core_ActiveSync_Imap_Factory()]; // Force emailsync to off if we don't have a mail API. if (!$registry->hasInterface('mail')) { $conf['activesync']['emailsync'] = false; } - $driver_params = array( + $driver_params = [ 'connector' => new Horde_Core_ActiveSync_Connector($params), 'imap' => !empty($conf['activesync']['emailsync']) ? new Horde_ActiveSync_Imap_Adapter($adapter_params) @@ -26,7 +27,7 @@ public function create(Horde_Injector $injector) 'ping' => $conf['activesync']['ping'], 'state' => $injector->getInstance('Horde_ActiveSyncState'), 'auth' => $this->_getAuth(), - 'cache' => $injector->getInstance('Horde_Cache')); + 'cache' => $injector->getInstance('Horde_Cache')]; return new Horde_Core_ActiveSync_Driver($driver_params); } @@ -40,9 +41,9 @@ protected function _getAuth() { global $conf, $injector; - $params = array( + $params = [ 'base_driver' => $injector->getInstance('Horde_Core_Factory_Auth')->create(), - ); + ]; if ($conf['activesync']['auth']['type'] != 'basic') { $x_params = $conf['activesync']['auth']['params']; diff --git a/lib/Horde/Core/Factory/ActiveSyncServer.php b/lib/Horde/Core/Factory/ActiveSyncServer.php index 53cd5bc08..87ab585f9 100644 --- a/lib/Horde/Core/Factory/ActiveSyncServer.php +++ b/lib/Horde/Core/Factory/ActiveSyncServer.php @@ -1,4 +1,5 @@ setLogger(new Horde_ActiveSync_Log_Factory(array( + $server->setLogger( + new Horde_ActiveSync_Log_Factory([ 'type' => $conf['activesync']['logging']['type'], 'path' => !empty($conf['activesync']['logging']['path']) ? $conf['activesync']['logging']['path'] : '', - 'level' => $level)) + 'level' => $level]) ); if (!empty($conf['openssl']['cafile'])) { $server->setRootCertificatePath($conf['openssl']['cafile']); diff --git a/lib/Horde/Core/Factory/ActiveSyncState.php b/lib/Horde/Core/Factory/ActiveSyncState.php index 123309387..c7b1f9767 100644 --- a/lib/Horde/Core/Factory/ActiveSyncState.php +++ b/lib/Horde/Core/Factory/ActiveSyncState.php @@ -1,4 +1,5 @@ getInstance('Horde_Core_Factory_Nosql')->create('horde', 'activesync'); - return new Horde_ActiveSync_State_Mongo(array( - 'connection' => $nosql - )); + case 'nosql': + $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'activesync'); + return new Horde_ActiveSync_State_Mongo([ + 'connection' => $nosql, + ]); - case 'sql': - return new Horde_ActiveSync_State_Sql(array( - 'db' => $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'activesync') - )); + case 'sql': + return new Horde_ActiveSync_State_Sql([ + 'db' => $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'activesync'), + ]); } } diff --git a/lib/Horde/Core/Factory/Ajax.php b/lib/Horde/Core/Factory/Ajax.php index f5b8af61c..5806dad4f 100644 --- a/lib/Horde/Core/Factory/Ajax.php +++ b/lib/Horde/Core/Factory/Ajax.php @@ -1,4 +1,5 @@ _injector - ->getInstance('Horde_Core_Factory_Db') - ->create('horde', 'alarms'); - } catch (Horde_Exception $e) { - $driver = 'null'; - $params = Horde::getDriverConfig('alarms', $driver); - } - break; + case 'sql': + try { + $params['db'] = $this->_injector + ->getInstance('Horde_Core_Factory_Db') + ->create('horde', 'alarms'); + } catch (Horde_Exception $e) { + $driver = 'null'; + $params = Horde::getDriverConfig('alarms', $driver); + } + break; } $params['logger'] = $this->_injector->getInstance('Horde_Log_Logger'); - $params['loader'] = array($this, 'load'); + $params['loader'] = [$this, 'load']; - $this->_ttl = isset($params['ttl']) - ? $params['ttl'] - : 300; + $this->_ttl = $params['ttl'] + ?? 300; $class = $this->_getDriverName($driver, 'Horde_Alarm'); $this->_alarm = new $class($params); @@ -92,21 +92,21 @@ public function create() $this->_alarm->addHandler( 'desktop', - new Horde_Core_Alarm_Handler_Desktop(array( + new Horde_Core_Alarm_Handler_Desktop([ 'icon' => new Horde_Core_Alarm_Handler_Desktop_Icon('alerts/alarm.png'), - 'js_notify' => array( + 'js_notify' => [ $this->_injector->getInstance('Horde_PageOutput'), - 'addInlineScript' - ) - )) + 'addInlineScript', + ], + ]) ); $this->_alarm->addHandler( 'mail', - new Horde_Alarm_Handler_Mail(array( + new Horde_Alarm_Handler_Mail([ 'identity' => $this->_injector->getInstance('Horde_Core_Factory_Identity'), 'mail' => $this->_injector->getInstance('Horde_Mail'), - )) + ]) ); return $this->_alarm; @@ -138,13 +138,13 @@ public function load($user = null, $preload = true) $cache = $session->get('horde', 'factory_alarm'); if (is_null($cache)) { - $save = array(); + $save = []; $changed = ($registry->getAuth() !== false); try { $apps = $registry->listApps(null, false, Horde_Perms::READ); } catch (Horde_Exception $e) { - $apps = array(); + $apps = []; } } else { $apps = $cache; @@ -165,10 +165,11 @@ public function load($user = null, $preload = true) : time(); try { - foreach ($registry->callAppMethod($app, 'listAlarms', array('args' => array($time, $user), 'noperms' => true)) as $alarm) { + foreach ($registry->callAppMethod($app, 'listAlarms', ['args' => [$time, $user], 'noperms' => true]) as $alarm) { $this->_alarm->set($alarm, true); } - } catch (Horde_Exception $e) {} + } catch (Horde_Exception $e) { + } } if ($changed) { diff --git a/lib/Horde/Core/Factory/Auth.php b/lib/Horde/Core/Factory/Auth.php index 6a582fb8b..b38e7cfff 100644 --- a/lib/Horde/Core/Factory/Auth.php +++ b/lib/Horde/Core/Factory/Auth.php @@ -1,4 +1,5 @@ _instances[$app])) { - $this->_instances[$app] = new Horde_Core_Auth_Application(array_filter(array( + $this->_instances[$app] = new Horde_Core_Auth_Application(array_filter([ 'app' => $app, 'base' => ($app === 'horde') ? $this->_create($GLOBALS['conf']['auth']['driver']) : null, - 'logger' => $this->_injector->getInstance('Horde_Log_Logger') - ))); + 'logger' => $this->_injector->getInstance('Horde_Log_Logger'), + ])); } return $this->_instances[$app]; @@ -98,78 +99,78 @@ protected function _create($driver, $orig_params = null) $lc_driver = Horde_String::lower($driver); switch ($lc_driver) { - case 'horde_core_auth_composite': - // Both of these params are required, but we need to skip if - // non-existent to return a useful error message later. - if (!empty($params['admin_driver'])) { - $params['admin_driver'] = $this->_create($params['admin_driver']['driver'], $params['admin_driver']['params']); - } - if (!empty($params['auth_driver'])) { - $params['auth_driver'] = $this->_create($params['auth_driver']['driver'], $params['auth_driver']['params']); - } - break; - - case 'horde_auth_cyrsql': - $imap_config = array( - 'hostspec' => empty($params['cyrhost']) ? null : $params['cyrhost'], - 'password' => $params['cyrpass'], - 'port' => empty($params['cyrport']) ? null : $params['cyrport'], - 'secure' => ($params['secure'] == 'none') ? null : $params['secure'], - 'username' => $params['cyradmin'], - ); - - try { - $ob = new Horde_Imap_Client_Socket($imap_config); - $ob->login(); - $params['imap'] = $ob; - } catch (Horde_Imap_Client_Exception $e) { - throw new Horde_Auth_Exception($e); - } - - $params['db'] = $this->_injector - ->getInstance('Horde_Core_Factory_Db') - ->create('horde', is_null($orig_params) ? 'auth' : $orig_params); - break; - - case 'horde_auth_http_remote': - $params['client'] = $this->_injector->getInstance('Horde_Core_Factory_HttpClient')->create(); - break; - - case 'horde_core_auth_application': - if (isset($this->_instances[$params['app']])) { - return $this->_instances[$params['app']]; - } - break; - - case 'horde_core_auth_imsp': - $params['imsp'] = $this->_injector->getInstance('Horde_Core_Factory_Imsp')->create(); - break; - - case 'horde_auth_kolab': - $params['kolab'] = $this->_injector - ->getInstance('Horde_Kolab_Session'); - break; - - case 'horde_core_auth_ldap': - case 'horde_core_auth_msad': - $params['ldap'] = $this->_injector - ->getInstance('Horde_Core_Factory_Ldap') - ->create('horde', is_null($orig_params) ? 'auth' : $orig_params); - break; - case 'horde_core_auth_x509': - if (!empty($params['password_source']) && $params['password_source'] == 'unified') { - $params['password'] = $params['unified_password']; - unset($params['password_source'], $params['unified_password']); - } - // @TODO: Add filters - break; - - case 'horde_auth_customsql': - case 'horde_auth_sql': - $params['db'] = $this->_injector - ->getInstance('Horde_Core_Factory_Db') - ->create('horde', is_null($orig_params) ? 'auth' : $orig_params); - break; + case 'horde_core_auth_composite': + // Both of these params are required, but we need to skip if + // non-existent to return a useful error message later. + if (!empty($params['admin_driver'])) { + $params['admin_driver'] = $this->_create($params['admin_driver']['driver'], $params['admin_driver']['params']); + } + if (!empty($params['auth_driver'])) { + $params['auth_driver'] = $this->_create($params['auth_driver']['driver'], $params['auth_driver']['params']); + } + break; + + case 'horde_auth_cyrsql': + $imap_config = [ + 'hostspec' => empty($params['cyrhost']) ? null : $params['cyrhost'], + 'password' => $params['cyrpass'], + 'port' => empty($params['cyrport']) ? null : $params['cyrport'], + 'secure' => ($params['secure'] == 'none') ? null : $params['secure'], + 'username' => $params['cyradmin'], + ]; + + try { + $ob = new Horde_Imap_Client_Socket($imap_config); + $ob->login(); + $params['imap'] = $ob; + } catch (Horde_Imap_Client_Exception $e) { + throw new Horde_Auth_Exception($e); + } + + $params['db'] = $this->_injector + ->getInstance('Horde_Core_Factory_Db') + ->create('horde', is_null($orig_params) ? 'auth' : $orig_params); + break; + + case 'horde_auth_http_remote': + $params['client'] = $this->_injector->getInstance('Horde_Core_Factory_HttpClient')->create(); + break; + + case 'horde_core_auth_application': + if (isset($this->_instances[$params['app']])) { + return $this->_instances[$params['app']]; + } + break; + + case 'horde_core_auth_imsp': + $params['imsp'] = $this->_injector->getInstance('Horde_Core_Factory_Imsp')->create(); + break; + + case 'horde_auth_kolab': + $params['kolab'] = $this->_injector + ->getInstance('Horde_Kolab_Session'); + break; + + case 'horde_core_auth_ldap': + case 'horde_core_auth_msad': + $params['ldap'] = $this->_injector + ->getInstance('Horde_Core_Factory_Ldap') + ->create('horde', is_null($orig_params) ? 'auth' : $orig_params); + break; + case 'horde_core_auth_x509': + if (!empty($params['password_source']) && $params['password_source'] == 'unified') { + $params['password'] = $params['unified_password']; + unset($params['password_source'], $params['unified_password']); + } + // @TODO: Add filters + break; + + case 'horde_auth_customsql': + case 'horde_auth_sql': + $params['db'] = $this->_injector + ->getInstance('Horde_Core_Factory_Db') + ->create('horde', is_null($orig_params) ? 'auth' : $orig_params); + break; } $params['default_user'] = $GLOBALS['registry']->getAuth(); diff --git a/lib/Horde/Core/Factory/AuthSignup.php b/lib/Horde/Core/Factory/AuthSignup.php index c218e9098..ecb49d37d 100644 --- a/lib/Horde/Core/Factory/AuthSignup.php +++ b/lib/Horde/Core/Factory/AuthSignup.php @@ -1,4 +1,5 @@ listApps() : array_intersect($registry->listApps(), $apps); sort($apps); - $sig = hash('md5', json_encode(array($apps, $layout))); + $sig = hash('md5', json_encode([$apps, $layout])); if (!isset($this->_instances[$sig])) { $this->_instances[$sig] = diff --git a/lib/Horde/Core/Factory/Browser.php b/lib/Horde/Core/Factory/Browser.php index 88d543d36..37d27f26e 100644 --- a/lib/Horde/Core/Factory/Browser.php +++ b/lib/Horde/Core/Factory/Browser.php @@ -1,4 +1,5 @@ true, - 'logger' => $injector->getInstance('Horde_Core_Log_Wrapper') - ); + 'logger' => $injector->getInstance('Horde_Core_Log_Wrapper'), + ]; if (isset($conf['cache']['default_lifetime'])) { $params['lifetime'] = $conf['cache']['default_lifetime']; } @@ -56,50 +57,50 @@ public function create(Horde_Injector $injector) $sparams = Horde::getDriverConfig('cache', $driver); switch ($driver) { - case 'hashtable': - // DEPRECATED - case 'memcache': - $sparams['hashtable'] = $injector->getInstance('Horde_Core_HashTable_Wrapper'); - $driver = 'Horde_Cache_Storage_Hashtable'; - unset($sparams['driverconfig'], $sparams['umask']); - break; - - case 'nosql': - $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'cache'); - if ($nosql instanceof Horde_Mongo_Client) { - $sparams['mongo_db'] = $nosql; - $driver = 'Horde_Cache_Storage_Mongo'; - } else { - $driver = 'Horde_Cache_Storage_Null'; - } - unset($sparams['driverconfig'], $sparams['umask']); - break; + case 'hashtable': + // DEPRECATED + case 'memcache': + $sparams['hashtable'] = $injector->getInstance('Horde_Core_HashTable_Wrapper'); + $driver = 'Horde_Cache_Storage_Hashtable'; + unset($sparams['driverconfig'], $sparams['umask']); + break; + + case 'nosql': + $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'cache'); + if ($nosql instanceof Horde_Mongo_Client) { + $sparams['mongo_db'] = $nosql; + $driver = 'Horde_Cache_Storage_Mongo'; + } else { + $driver = 'Horde_Cache_Storage_Null'; + } + unset($sparams['driverconfig'], $sparams['umask']); + break; - case 'sql': - $sparams['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'cache'); - unset($sparams['driverconfig'], $sparams['umask']); - break; + case 'sql': + $sparams['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'cache'); + unset($sparams['driverconfig'], $sparams['umask']); + break; } $storage = $this->storage = $this->_getStorage($driver, $sparams); if (!empty($conf['cache']['use_memorycache']) && - in_array($driver, array('file', 'sql'))) { + in_array($driver, ['file', 'sql'])) { switch (Horde_String::lower($conf['cache']['use_memorycache'])) { - case 'hashtable': - case 'memcache': - $storage = new Horde_Cache_Storage_Stack(array( - 'stack' => array( - $this->_getStorage( - $conf['cache']['use_memorycache'], - array( - 'hashtable' => $injector->getInstance('Horde_Core_HashTable_Wrapper') - ) - ), - $storage - ) - )); - break; + case 'hashtable': + case 'memcache': + $storage = new Horde_Cache_Storage_Stack([ + 'stack' => [ + $this->_getStorage( + $conf['cache']['use_memorycache'], + [ + 'hashtable' => $injector->getInstance('Horde_Core_HashTable_Wrapper'), + ] + ), + $storage, + ], + ]); + break; } } @@ -122,15 +123,15 @@ public function getDriverName() : Horde_String::lower($conf['cache']['driver']); switch ($driver) { - case 'none': - $driver = 'null'; - break; - - case 'xcache': - if (Horde_Cli::runningFromCLI()) { + case 'none': $driver = 'null'; - } - break; + break; + + case 'xcache': + if (Horde_Cli::runningFromCLI()) { + $driver = 'null'; + } + break; } return $driver; diff --git a/lib/Horde/Core/Factory/Crypt.php b/lib/Horde/Core/Factory/Crypt.php index 385baef1c..677cdae81 100644 --- a/lib/Horde/Core/Factory/Crypt.php +++ b/lib/Horde/Core/Factory/Crypt.php @@ -1,4 +1,5 @@ $registry->getEmailCharset(), - 'temp' => Horde::getTempDir() - ), $params); + 'temp' => Horde::getTempDir(), + ], $params); return Horde_Crypt::factory($driver, $params); } diff --git a/lib/Horde/Core/Factory/CssCache.php b/lib/Horde/Core/Factory/CssCache.php index 924883fc5..3fcfa69f9 100644 --- a/lib/Horde/Core/Factory/CssCache.php +++ b/lib/Horde/Core/Factory/CssCache.php @@ -1,4 +1,5 @@ _getDriverName($driver, 'Horde_Data'); $params['browser'] = $this->_injector->getInstance('Horde_Browser'); $params['vars'] = $this->_injector->getInstance('Horde_Variables'); $params['http'] = $this->_injector ->getInstance('Horde_Core_Factory_HttpClient') - ->create(array('request.verifyPeer' => false)); + ->create(['request.verifyPeer' => false]); return new $class($this->_injector->getInstance('Horde_Core_Data_Storage'), $params); } diff --git a/lib/Horde/Core/Factory/DavServer.php b/lib/Horde/Core/Factory/DavServer.php index f7686c4b1..8dcde963c 100644 --- a/lib/Horde/Core/Factory/DavServer.php +++ b/lib/Horde/Core/Factory/DavServer.php @@ -1,4 +1,5 @@ $injector ->getInstance('Horde_Core_Factory_Auth') - ->create() - ) + ->create(), + ] ), $injector->getInstance('Horde_Core_Factory_Identity_DavUsernameHook') ); @@ -51,8 +52,8 @@ public function create(Horde_Injector $injector) $server = new DAV\Server( new Horde_Dav_RootCollection( $registry, - array($principals, $caldav, $carddav), - isset($conf['mime']['magic_db']) ? $conf['mime']['magic_db'] : null + [$principals, $caldav, $carddav], + $conf['mime']['magic_db'] ?? null ) ); $server->debugExceptions = false; @@ -64,7 +65,7 @@ public function create(Horde_Injector $injector) if (!empty($conf['dav_root'])) { $candidates = explode(';', $conf['dav_root']); // Ensure longer hits overrule shorter hits regardless of input order - usort($candidates, function($a, $b) { return strlen($a) <=> strlen($b);}); + usort($candidates, function ($a, $b) { return strlen($a) <=> strlen($b);}); foreach ($candidates as $davBaseTest) { if (!empty($_SERVER['REQUEST_URI']) && (strpos($_SERVER['REQUEST_URI'], $davBaseTest) === 0)) { $davBaseUri = $davBaseTest; diff --git a/lib/Horde/Core/Factory/DavStorage.php b/lib/Horde/Core/Factory/DavStorage.php index 208800a0f..afd6e7e1e 100644 --- a/lib/Horde/Core/Factory/DavStorage.php +++ b/lib/Horde/Core/Factory/DavStorage.php @@ -1,4 +1,5 @@ getInstance('Horde_Core_Factory_Db') - ->create('horde', 'davstorage'); - break; + case 'Sql': + $class = 'Horde_Dav_Storage_Sql'; + $params['db'] = $injector + ->getInstance('Horde_Core_Factory_Db') + ->create('horde', 'davstorage'); + break; - default: - throw new Horde_Exception('A storage backend for DAV has not been configured.'); - break; + default: + throw new Horde_Exception('A storage backend for DAV has not been configured.'); + break; } return new $class($params); diff --git a/lib/Horde/Core/Factory/Db.php b/lib/Horde/Core/Factory/Db.php index 991b353a2..9cc1003ef 100644 --- a/lib/Horde/Core/Factory/Db.php +++ b/lib/Horde/Core/Factory/Db.php @@ -1,4 +1,5 @@ _instances[$sig])) { try { $this->_createDb($config, $sig); - } catch (Horde_Exception $e) {} + } catch (Horde_Exception $e) { + } } if ($pushed) { @@ -161,23 +163,23 @@ protected function _createDb($config, $sig = null, $cache = true) throw new Horde_Exception('The database configuration is missing.'); } else { switch ($config['phptype']) { - case 'mysqli': - $class = 'Horde_Db_Adapter_Mysqli'; - break; - - case 'mysql': - $class = extension_loaded('pdo_mysql') - ? 'Horde_Db_Adapter_Pdo_Mysql' - : 'Horde_Db_Adapter_Mysql'; - break; - - case 'oci8': - $class = 'Horde_Db_Adapter_Oci8'; - break; - - default: - $class = 'Horde_Db_Adapter_Pdo_' . Horde_String::ucfirst($config['phptype']); - break; + case 'mysqli': + $class = 'Horde_Db_Adapter_Mysqli'; + break; + + case 'mysql': + $class = extension_loaded('pdo_mysql') + ? 'Horde_Db_Adapter_Pdo_Mysql' + : 'Horde_Db_Adapter_Mysql'; + break; + + case 'oci8': + $class = 'Horde_Db_Adapter_Oci8'; + break; + + default: + $class = 'Horde_Db_Adapter_Pdo_' . Horde_String::ucfirst($config['phptype']); + break; } } diff --git a/lib/Horde/Core/Factory/DbBase.php b/lib/Horde/Core/Factory/DbBase.php index 0df0550cf..2f0efa3dd 100644 --- a/lib/Horde/Core/Factory/DbBase.php +++ b/lib/Horde/Core/Factory/DbBase.php @@ -1,4 +1,5 @@ !empty($config['persistent']), - 'ssl' => !empty($config['ssl']) - )); + 'ssl' => !empty($config['ssl']), + ]); if ($db instanceof PEAR_Error) { if ($pushed) { diff --git a/lib/Horde/Core/Factory/Dns.php b/lib/Horde/Core/Factory/Dns.php index 8a0f4fca2..d68b0415a 100644 --- a/lib/Horde/Core/Factory/Dns.php +++ b/lib/Horde/Core/Factory/Dns.php @@ -1,4 +1,5 @@ $tmpdir . '/horde_dns.cache' . gethostname(), 'cache_size' => 100000, 'cache_type' => 'file', - ); + ]; } else { - $config = array(); + $config = []; } $resolver = new Net_DNS2_Resolver($config); @@ -26,7 +27,8 @@ public function create(Horde_Injector $injector) if (is_readable('/etc/resolv.conf')) { try { $resolver->setServers('/etc/resolv.conf'); - } catch (Net_DNS2_Exception $e) {} + } catch (Net_DNS2_Exception $e) { + } } return $resolver; diff --git a/lib/Horde/Core/Factory/Editor.php b/lib/Horde/Core/Factory/Editor.php index 7f3b55df0..4f6787255 100644 --- a/lib/Horde/Core/Factory/Editor.php +++ b/lib/Horde/Core/Factory/Editor.php @@ -1,4 +1,5 @@ $injector->getInstance('Horde_Core_Factory_HttpClient')->create(), - 'http_request' => $injector->getInstance('Horde_Controller_Request_Http') - ) + 'http_request' => $injector->getInstance('Horde_Controller_Request_Http'), + ] ); /* Check for facebook session */ diff --git a/lib/Horde/Core/Factory/Group.php b/lib/Horde/Core/Factory/Group.php index a8ad17c0a..6d8e6306e 100644 --- a/lib/Horde/Core/Factory/Group.php +++ b/lib/Horde/Core/Factory/Group.php @@ -1,4 +1,5 @@ contacts; - break; - - case 'Kolab': - $class = 'Horde_Group_Kolab'; - $params['ldap'] = $injector - ->getInstance('Horde_Core_Factory_Ldap') - ->create('horde', 'group'); - break; - - case 'Ldap': - $class = 'Horde_Core_Group_Ldap'; - $params['ldap'] = $injector - ->getInstance('Horde_Core_Factory_Ldap') - ->create('horde', 'group'); - break; - - case 'Sql': - $class = 'Horde_Group_Sql'; - $params['db'] = $injector - ->getInstance('Horde_Core_Factory_Db') - ->create('horde', 'group'); - break; - - default: - $class = $this->_getDriverName($driver, 'Horde_Group'); - break; + case 'Contactlists': + $class = 'Horde_Group_Contactlists'; + $params['api'] = $GLOBALS['registry']->contacts; + break; + + case 'Kolab': + $class = 'Horde_Group_Kolab'; + $params['ldap'] = $injector + ->getInstance('Horde_Core_Factory_Ldap') + ->create('horde', 'group'); + break; + + case 'Ldap': + $class = 'Horde_Core_Group_Ldap'; + $params['ldap'] = $injector + ->getInstance('Horde_Core_Factory_Ldap') + ->create('horde', 'group'); + break; + + case 'Sql': + $class = 'Horde_Group_Sql'; + $params['db'] = $injector + ->getInstance('Horde_Core_Factory_Db') + ->create('horde', 'group'); + break; + + default: + $class = $this->_getDriverName($driver, 'Horde_Group'); + break; } return new $class($params); diff --git a/lib/Horde/Core/Factory/HashTable.php b/lib/Horde/Core/Factory/HashTable.php index 7dd43f988..e68105ba5 100644 --- a/lib/Horde/Core/Factory/HashTable.php +++ b/lib/Horde/Core/Factory/HashTable.php @@ -1,4 +1,5 @@ $logger, - 'memcache' => $injector->getInstance('Horde_Memcache') - )); + 'memcache' => $injector->getInstance('Horde_Memcache'), + ]); } $driver = empty($conf['hashtable']['driver']) @@ -46,72 +47,72 @@ public function create(Horde_Injector $injector) $params = Horde::getDriverConfig('hashtable', $driver); switch ($lc_driver) { - case 'memcache': - return new Horde_HashTable_Memcache(array( - 'logger' => $logger, - 'memcache' => new Horde_Memcache(array_merge($params, array( - 'logger' => $logger - ))) - )); - - case 'predis': - $params = array_merge(array( - 'hostspec' => array(), - 'password' => null, - 'database' => null, - 'port' => '', - 'protocol' => 'tcp', - ), $params); - $redis_params = array(); - - $common = array_filter(array( - 'password' => strlen($params['password']) ? $params['password'] : null, - 'persistent' => !empty($params['persistent']), - 'database' => !empty($params['database']) ? $params['database'] : null - )); - - switch ($params['protocol']) { - case 'tcp': - foreach ($params['hostspec'] as $key => $val) { - $redis_params[] = array_merge($common, array_filter(array( - 'host' => trim($val), - 'port' => isset($params['port'][$key]) ? trim($params['port'][$key]) : null, - 'scheme' => 'tcp' - ))); + case 'memcache': + return new Horde_HashTable_Memcache([ + 'logger' => $logger, + 'memcache' => new Horde_Memcache(array_merge($params, [ + 'logger' => $logger, + ])), + ]); + + case 'predis': + $params = array_merge([ + 'hostspec' => [], + 'password' => null, + 'database' => null, + 'port' => '', + 'protocol' => 'tcp', + ], $params); + $redis_params = []; + + $common = array_filter([ + 'password' => strlen($params['password']) ? $params['password'] : null, + 'persistent' => !empty($params['persistent']), + 'database' => !empty($params['database']) ? $params['database'] : null, + ]); + + switch ($params['protocol']) { + case 'tcp': + foreach ($params['hostspec'] as $key => $val) { + $redis_params[] = array_merge($common, array_filter([ + 'host' => trim($val), + 'port' => isset($params['port'][$key]) ? trim($params['port'][$key]) : null, + 'scheme' => 'tcp', + ])); + } + break; + + case 'unix': + $redis_params[] = array_merge($common, [ + 'path' => trim($params['socket']), + 'scheme' => 'unix', + ]); + break; } - break; - - case 'unix': - $redis_params[] = array_merge($common, array( - 'path' => trim($params['socket']), - 'scheme' => 'unix' - )); - break; - } - - /* No need to use complex clustering if not needed. */ - if (count($redis_params) === 1) { - $redis_params = reset($redis_params); - } - - $redis_replication_options = array(); - if (!empty($params['replication'])) { - $redis_replication_options = array( - 'replication' => $params['replication'], - 'service' => !empty($params['service']) ? $params['service'] : null, - ); - } - - return new Horde_HashTable_Predis(array( - 'logger' => $logger, - 'predis' => new Predis\Client($redis_params, $redis_replication_options) - )); - - case 'memory': - default: - return new Horde_HashTable_Memory(array( - 'logger' => $logger - )); + + /* No need to use complex clustering if not needed. */ + if (count($redis_params) === 1) { + $redis_params = reset($redis_params); + } + + $redis_replication_options = []; + if (!empty($params['replication'])) { + $redis_replication_options = [ + 'replication' => $params['replication'], + 'service' => !empty($params['service']) ? $params['service'] : null, + ]; + } + + return new Horde_HashTable_Predis([ + 'logger' => $logger, + 'predis' => new Predis\Client($redis_params, $redis_replication_options), + ]); + + case 'memory': + default: + return new Horde_HashTable_Memory([ + 'logger' => $logger, + ]); } } diff --git a/lib/Horde/Core/Factory/History.php b/lib/Horde/Core/Factory/History.php index b0f35f138..55f9aa4f4 100644 --- a/lib/Horde/Core/Factory/History.php +++ b/lib/Horde/Core/Factory/History.php @@ -1,4 +1,5 @@ getInstance('Horde_Registry')->getAuth(); switch (Horde_String::lower($driver)) { - case 'nosql': - $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'history'); - if ($nosql instanceof Horde_History_Mongo) { - $history = new Horde_History_Mongo( - $user, - array('mongo_db' => $nosql) - ); - } - break; + case 'nosql': + $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'history'); + if ($nosql instanceof Horde_History_Mongo) { + $history = new Horde_History_Mongo( + $user, + ['mongo_db' => $nosql] + ); + } + break; - case 'sql': - try { - $history = new Horde_History_Sql( - $user, - $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'history') - ); - } catch (Exception $e) {} - break; + case 'sql': + try { + $history = new Horde_History_Sql( + $user, + $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'history') + ); + } catch (Exception $e) { + } + break; } if (is_null($history)) { diff --git a/lib/Horde/Core/Factory/HttpClient.php b/lib/Horde/Core/Factory/HttpClient.php index 56fde6b43..869f8f7f3 100644 --- a/lib/Horde/Core/Factory/HttpClient.php +++ b/lib/Horde/Core/Factory/HttpClient.php @@ -1,4 +1,5 @@ _instances[$key])) { - $params = array( + $params = [ 'user' => is_null($user) ? $registry->getAuth() : $user, - ); + ]; if (isset($prefs) && ($params['user'] == $registry->getAuth())) { $params['prefs'] = $prefs; } else { - $params['prefs'] = $this->_injector->getInstance('Horde_Core_Factory_Prefs')->create($registry->getApp() ?: 'horde', array( + $params['prefs'] = $this->_injector->getInstance('Horde_Core_Factory_Prefs')->create($registry->getApp() ?: 'horde', [ 'cache' => false, - 'user' => $user - )); + 'user' => $user, + ]); } $this->_instances[$key] = new $class($params); diff --git a/lib/Horde/Core/Factory/Identity/DavUsernameHook.php b/lib/Horde/Core/Factory/Identity/DavUsernameHook.php index 0e73ee0e3..f0217b14e 100644 --- a/lib/Horde/Core/Factory/Identity/DavUsernameHook.php +++ b/lib/Horde/Core/Factory/Identity/DavUsernameHook.php @@ -1,4 +1,5 @@ _injector->getInstance('Horde_Core_Hooks') - ->callHook('davusername', 'horde', array($user, true)); + ->callHook('davusername', 'horde', [$user, true]); } catch (Horde_Exception_HookNotSet $e) { } return parent::create($user, $driver); diff --git a/lib/Horde/Core/Factory/Identity/UsernameHook.php b/lib/Horde/Core/Factory/Identity/UsernameHook.php index 606ca2bd3..41d47cf2a 100644 --- a/lib/Horde/Core/Factory/Identity/UsernameHook.php +++ b/lib/Horde/Core/Factory/Identity/UsernameHook.php @@ -1,4 +1,5 @@ _getDriverName($driver, 'Horde_Image'); - $context = array( + $context = [ 'tmpdir' => Horde::getTempdir(), - 'logger' => $this->_injector->getInstance('Horde_Log_Logger') - ); + 'logger' => $this->_injector->getInstance('Horde_Log_Logger'), + ]; switch ($driver) { - case 'Im': - $context['convert'] = $conf['image']['convert']; - $context['identify'] = $conf['image']['identify']; - break; + case 'Im': + $context['convert'] = $conf['image']['convert']; + $context['identify'] = $conf['image']['identify']; + break; } return new $class($params, $context); diff --git a/lib/Horde/Core/Factory/Imple.php b/lib/Horde/Core/Factory/Imple.php index accf636a3..55020525b 100644 --- a/lib/Horde/Core/Factory/Imple.php +++ b/lib/Horde/Core/Factory/Imple.php @@ -1,4 +1,5 @@ _getDriverName($driver, 'Horde_Core_Ajax_Imple'); $ob = new $class($params); diff --git a/lib/Horde/Core/Factory/Imsp.php b/lib/Horde/Core/Factory/Imsp.php index 930b62343..67ec38df7 100644 --- a/lib/Horde/Core/Factory/Imsp.php +++ b/lib/Horde/Core/Factory/Imsp.php @@ -1,4 +1,5 @@ _instances[$signature])) { $this->_instances[$signature] = self::_factory($driver, $params); } @@ -75,7 +76,7 @@ public function create($driver = null, array $params = array()) * @return mixed The Horde_Imsp object or Horde_Imsp_Client object. * @throws Horde_Exception */ - protected function _factory($driver = null, array $params = array()) + protected function _factory($driver = null, array $params = []) { $driver = basename($driver); diff --git a/lib/Horde/Core/Factory/ImspAuth.php b/lib/Horde/Core/Factory/ImspAuth.php index a116d8f14..947b79430 100644 --- a/lib/Horde/Core/Factory/ImspAuth.php +++ b/lib/Horde/Core/Factory/ImspAuth.php @@ -1,4 +1,5 @@ _injector->setInstance( - 'Horde_Kolab_Server_Configuration', $configuration + 'Horde_Kolab_Server_Configuration', + $configuration ); } @@ -147,12 +149,12 @@ private function _setupSchema() private function _setupStructure() { $configuration = $this->getConfiguration(); - $driver = isset($configuration['structure']['driver']) - ? $configuration['structure']['driver'] - : 'Horde_Kolab_Server_Structure_Kolab'; + $driver = $configuration['structure']['driver'] + ?? 'Horde_Kolab_Server_Structure_Kolab'; $this->_injector->bindImplementation( - 'Horde_Kolab_Server_Structure_Interface', $driver + 'Horde_Kolab_Server_Structure_Interface', + $driver ); } @@ -190,7 +192,8 @@ public function getConnection() $configuration['hostspec'] = $configuration['host_master']; $ldap_write = new Horde_Ldap($configuration); return new Horde_Kolab_Server_Connection_Splittedldap( - $ldap_read, $ldap_write + $ldap_read, + $ldap_write ); } @@ -199,13 +202,13 @@ public function getConnection() ); } - $data = isset($configuration['data']) - ? $configuration['data'] - : array(); + $data = $configuration['data'] + ?? []; return new Horde_Kolab_Server_Connection_Mock( new Horde_Kolab_Server_Connection_Mock_Ldap( - $configuration, $data + $configuration, + $data ) ); } @@ -249,19 +252,22 @@ public function getServer() if (isset($configuration['map'])) { $server = new Horde_Kolab_Server_Decorator_Map( - $server, $configuration['map'] + $server, + $configuration['map'] ); } if (isset($configuration['debug']) || isset($configuration['log'])) { $server = new Horde_Kolab_Server_Decorator_Log( - $server, $this->_injector->getInstance('Horde_Log_Logger') + $server, + $this->_injector->getInstance('Horde_Log_Logger') ); } if (isset($configuration['debug']) || isset($configuration['count'])) { $server = new Horde_Kolab_Server_Decorator_Count( - $server, $this->_injector->getInstance('Horde_Log_Logger') + $server, + $this->_injector->getInstance('Horde_Log_Logger') ); } diff --git a/lib/Horde/Core/Factory/KolabSession.php b/lib/Horde/Core/Factory/KolabSession.php index f4d37b95b..6975775f7 100644 --- a/lib/Horde/Core/Factory/KolabSession.php +++ b/lib/Horde/Core/Factory/KolabSession.php @@ -1,4 +1,5 @@ _injector->getInstance('Horde_Log_Logger') + $validator, + $this->_injector->getInstance('Horde_Log_Logger') ); } @@ -71,7 +74,7 @@ public function createSessionValidator( public function createSession() { if (!empty($GLOBALS['conf']['kolab']['enabled']) && - !isset($GLOBALS['conf']['kolab']['users'])) { + !isset($GLOBALS['conf']['kolab']['users'])) { $session = new Horde_Kolab_Session_Base( $this->_injector->getInstance('Horde_Kolab_Server_Composite'), $GLOBALS['conf']['kolab'] @@ -87,7 +90,8 @@ public function createSession() if (isset($GLOBALS['conf']['kolab']['session']['debug'])) { $session = new Horde_Kolab_Session_Decorator_Logged( - $session, $this->_injector->getInstance('Horde_Log_Logger') + $session, + $this->_injector->getInstance('Horde_Log_Logger') ); } diff --git a/lib/Horde/Core/Factory/KolabStorage.php b/lib/Horde/Core/Factory/KolabStorage.php index 42e4b1ce2..a2f99d0d1 100644 --- a/lib/Horde/Core/Factory/KolabStorage.php +++ b/lib/Horde/Core/Factory/KolabStorage.php @@ -1,4 +1,5 @@ _injector->setInstance( - 'Horde_Kolab_Storage_Configuration', $configuration + 'Horde_Kolab_Storage_Configuration', + $configuration ); } @@ -82,53 +84,53 @@ public function create() ? $configuration['cache'] : 'Mock'; switch ($cache) { - case 'Horde': - $cacheob = $this->_injector->getInstance('Horde_Cache'); - break; - case 'Mock': - default: - $cacheob = new Horde_Cache( - new Horde_Cache_Storage_Mock(), array('compress' => true) - ); + case 'Horde': + $cacheob = $this->_injector->getInstance('Horde_Cache'); + break; + case 'Mock': + default: + $cacheob = new Horde_Cache( + new Horde_Cache_Storage_Mock(), + ['compress' => true] + ); } - $params = array( + $params = [ 'driver' => 'horde', - 'params' => array( + 'params' => [ 'host' => $configuration['server'], 'username' => $GLOBALS['registry']->getAuth(), 'password' => $GLOBALS['registry']->getAuthCredential('password'), 'port' => $configuration['port'], 'secure' => $configuration['secure'], - 'debug' => isset($configuration['debug']) - ? $configuration['debug'] - : null, - 'cache' => array( + 'debug' => $configuration['debug'] + ?? null, + 'cache' => [ 'backend' => new Horde_Imap_Client_Cache_Backend_Cache( - array('cacheob' => $cacheob) - ) - ) - ), - 'queries' => array( - 'list' => array( - Horde_Kolab_Storage_List_Tools::QUERY_BASE => array( - 'cache' => true - ), - Horde_Kolab_Storage_List_Tools::QUERY_ACL => array( - 'cache' => true + ['cacheob' => $cacheob] ), - Horde_Kolab_Storage_List_Tools::QUERY_SHARE => array( - 'cache' => true - ), - ) - ), - 'queryset' => array( - 'data' => array('queryset' => 'horde'), - ), + ], + ], + 'queries' => [ + 'list' => [ + Horde_Kolab_Storage_List_Tools::QUERY_BASE => [ + 'cache' => true, + ], + Horde_Kolab_Storage_List_Tools::QUERY_ACL => [ + 'cache' => true, + ], + Horde_Kolab_Storage_List_Tools::QUERY_SHARE => [ + 'cache' => true, + ], + ], + ], + 'queryset' => [ + 'data' => ['queryset' => 'horde'], + ], 'logger' => $this->_injector->getInstance('Horde_Log_Logger'), - 'log' => array('debug'), + 'log' => ['debug'], 'cache' => $this->_injector->getInstance('Horde_Cache'), - ); + ]; // Check if the history system is enabled // @todo remove interface_exists check in H6. @@ -137,7 +139,7 @@ public function create() $history = $this->_injector->getInstance('Horde_History'); $params['history'] = $history; $params['history_prefix_generator'] = new Horde_Core_Kolab_Storage_HistoryPrefix(); - } catch(Horde_Exception $e) { + } catch (Horde_Exception $e) { } } diff --git a/lib/Horde/Core/Factory/LanguageDetect.php b/lib/Horde/Core/Factory/LanguageDetect.php index 9873c28bb..651de1486 100644 --- a/lib/Horde/Core/Factory/LanguageDetect.php +++ b/lib/Horde/Core/Factory/LanguageDetect.php @@ -1,4 +1,5 @@ 'sq', 'arabic' => 'ar', // azeri @@ -90,8 +91,8 @@ class Horde_Core_Factory_LanguageDetect extends Horde_Core_Factory_Base 'urdu' => 'ur', 'uzbek' => 'uz', 'vietnamese' => 'vi', - 'welsh' => 'cy' - ); + 'welsh' => 'cy', + ]; /** * Return a Text_LanguageDetect instance. diff --git a/lib/Horde/Core/Factory/Ldap.php b/lib/Horde/Core/Factory/Ldap.php index eacd4abad..43d94a234 100644 --- a/lib/Horde/Core/Factory/Ldap.php +++ b/lib/Horde/Core/Factory/Ldap.php @@ -1,4 +1,5 @@ _instances[$sig])) { return $this->_instances[$sig]; @@ -78,7 +79,8 @@ public function create($app = 'horde', $backend = null) $GLOBALS['registry']->getAuth()) { $this->_instances[$sig]->bind( $this->_instances[$sig]->findUserDN($GLOBALS['registry']->getAuth()), - $GLOBALS['registry']->getAuthCredential('password')); + $GLOBALS['registry']->getAuthCredential('password') + ); } } catch (Horde_Exception_NotFound $notfound) { } diff --git a/lib/Horde/Core/Factory/Lock.php b/lib/Horde/Core/Factory/Lock.php index e2e5ef4f7..b2a82c52f 100644 --- a/lib/Horde/Core/Factory/Lock.php +++ b/lib/Horde/Core/Factory/Lock.php @@ -1,4 +1,5 @@ getInstance('Horde_Log_Logger'); switch (Horde_String::lower($driver)) { - case 'none': - $driver = 'null'; - break; - - case 'nosql': - $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'cache'); - if ($nosql instanceof Horde_Mongo_Client) { - $params['mongo_db'] = $nosql; - $driver = 'mongo'; - } - break; - - case 'sql': - $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'lock'); - break; + case 'none': + $driver = 'null'; + break; + + case 'nosql': + $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'cache'); + if ($nosql instanceof Horde_Mongo_Client) { + $params['mongo_db'] = $nosql; + $driver = 'mongo'; + } + break; + + case 'sql': + $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'lock'); + break; } $class = $this->_getDriverName($driver, 'Horde_Lock'); diff --git a/lib/Horde/Core/Factory/Logger.php b/lib/Horde/Core/Factory/Logger.php index ad88e50a7..bbe2e6eca 100644 --- a/lib/Horde/Core/Factory/Logger.php +++ b/lib/Horde/Core/Factory/Logger.php @@ -1,4 +1,5 @@ $conf['log']['params']['template'])); - break; + case 'file': + case 'stream': + $append = ($conf['log']['type'] == 'file') + ? ($conf['log']['params']['append'] ? 'a+' : 'w+') + : null; + $format = $conf['log']['params']['format'] + ?? 'default'; + + switch ($format) { + case 'custom': + $formatter = new Horde_Log_Formatter_Simple(['format' => $conf['log']['params']['template']]); + break; + + case 'default': + default: + // Use Horde_Log defaults. + $formatter = null; + break; + + case 'xml': + $formatter = new Horde_Log_Formatter_Xml(); + break; + } - case 'default': - default: - // Use Horde_Log defaults. - $formatter = null; + try { + $handler = new Horde_Log_Handler_Stream($conf['log']['name'], $append, $formatter); + } catch (Horde_Log_Exception $e) { + $this->error = $e; + return new Horde_Core_Log_Logger(new Horde_Log_Handler_Null()); + } + try { + $handler->setOption('ident', $conf['log']['ident']); + } catch (Horde_Log_Exception $e) { + } break; - case 'xml': - $formatter = new Horde_Log_Formatter_Xml(); + case 'syslog': + try { + $handler = new Horde_Log_Handler_Syslog(); + if (!empty($conf['log']['name'])) { + $handler->setOption('facility', $conf['log']['name']); + } + if (!empty($conf['log']['ident'])) { + $handler->setOption('ident', $conf['log']['ident']); + } + } catch (Horde_Log_Exception $e) { + $this->error = $e; + return new Horde_Core_Log_Logger(new Horde_Log_Handler_Null()); + } break; - } - - try { - $handler = new Horde_Log_Handler_Stream($conf['log']['name'], $append, $formatter); - } catch (Horde_Log_Exception $e) { - $this->error = $e; - return new Horde_Core_Log_Logger(new Horde_Log_Handler_Null()); - } - try { - $handler->setOption('ident', $conf['log']['ident']); - } catch (Horde_Log_Exception $e) { - } - break; - case 'syslog': - try { - $handler = new Horde_Log_Handler_Syslog(); - if (!empty($conf['log']['name'])) { - $handler->setOption('facility', $conf['log']['name']); - } - if (!empty($conf['log']['ident'])) { - $handler->setOption('ident', $conf['log']['ident']); - } - } catch (Horde_Log_Exception $e) { - $this->error = $e; + case 'null': + default: + // Use default null handler. return new Horde_Core_Log_Logger(new Horde_Log_Handler_Null()); - } - break; - - case 'null': - default: - // Use default null handler. - return new Horde_Core_Log_Logger(new Horde_Log_Handler_Null()); } switch ($conf['log']['priority']) { - case 'WARNING': - // Bug #12109 - $priority = 'WARN'; - break; - - default: - $priority = defined('Horde_Log::' . $conf['log']['priority']) - ? $conf['log']['priority'] - : 'NOTICE'; - break; + case 'WARNING': + // Bug #12109 + $priority = 'WARN'; + break; + + default: + $priority = defined('Horde_Log::' . $conf['log']['priority']) + ? $conf['log']['priority'] + : 'NOTICE'; + break; } $handler->addFilter(constant('Horde_Log::' . $priority)); @@ -133,8 +133,8 @@ public static function available() public static function queue(Horde_Core_Log_Object $ob) { if (!isset(self::$_queue)) { - self::$_queue = array(); - register_shutdown_function(array(__CLASS__, 'processQueue')); + self::$_queue = []; + register_shutdown_function([__CLASS__, 'processQueue']); } self::$_queue[] = $ob; @@ -160,7 +160,7 @@ public static function processQueue($logger = null) } catch (Exception $e) { } - self::$_queue = array(); + self::$_queue = []; } } diff --git a/lib/Horde/Core/Factory/LoginTasks.php b/lib/Horde/Core/Factory/LoginTasks.php index a28ef8b68..01cf98aa5 100644 --- a/lib/Horde/Core/Factory/LoginTasks.php +++ b/lib/Horde/Core/Factory/LoginTasks.php @@ -1,4 +1,5 @@ getConfig(); + [$transport, $params] = $this->getConfig(); } else { $transport = $config['transport']; $params = $config['params']; @@ -91,9 +92,8 @@ public function getConfig() $transport = isset($conf['mailer']['type']) ? Horde_String::lower($conf['mailer']['type']) : 'null'; - $params = isset($conf['mailer']['params']) - ? $conf['mailer']['params'] - : array(); + $params = $conf['mailer']['params'] + ?? []; /* Add username/password options now, regardless of current value of * 'auth'. Will remove in create() if final config doesn't require @@ -114,7 +114,7 @@ public function getConfig() unset($params['password_auth'], $params['username_auth']); } - return array($transport, $params); + return [$transport, $params]; } } diff --git a/lib/Horde/Core/Factory/MailBase.php b/lib/Horde/Core/Factory/MailBase.php index 4a7c77cb2..663c52a4c 100644 --- a/lib/Horde/Core/Factory/MailBase.php +++ b/lib/Horde/Core/Factory/MailBase.php @@ -1,4 +1,5 @@ $injector->getInstance('Horde_Core_Log_Wrapper')))); + : new Horde_Memcache(array_merge($GLOBALS['conf']['memcache'], ['logger' => $injector->getInstance('Horde_Core_Log_Wrapper')])); } } diff --git a/lib/Horde/Core/Factory/MimeViewer.php b/lib/Horde/Core/Factory/MimeViewer.php index 68afc69b6..bd94fbf86 100644 --- a/lib/Horde/Core/Factory/MimeViewer.php +++ b/lib/Horde/Core/Factory/MimeViewer.php @@ -1,4 +1,5 @@ getApp(); + $app = $opts['app'] + ?? $GLOBALS['registry']->getApp(); - $type = isset($opts['type']) - ? $opts['type'] - : $mime->getType(); + $type = $opts['type'] + ?? $mime->getType(); - list($driver, $params) = $this->getViewerConfig($type, $app); + [$driver, $params] = $this->getViewerConfig($type, $app); return new $driver($mime, $params); } @@ -77,78 +76,78 @@ public function getViewerConfig($type, $app) ? $config['driver'] : $config['app'] . '_Mime_Viewer_' . $config['driver']; - $params = array_merge($config, array( + $params = array_merge($config, [ 'charset' => 'UTF-8', // TODO: Logging // 'logger' => $this->_injector->getInstance('Horde_Log_Logger'), - 'temp_file' => array('Horde', 'getTempFile'), - 'text_filter' => array($this->_injector->getInstance('Horde_Core_Factory_TextFilter'), 'filter') - )); + 'temp_file' => ['Horde', 'getTempFile'], + 'text_filter' => [$this->_injector->getInstance('Horde_Core_Factory_TextFilter'), 'filter'], + ]); switch ($config['driver']) { - case 'Deb': - case 'Rpm': - $params['monospace'] = 'fixed'; - break; - - case 'Html': - $params['browser'] = $GLOBALS['browser']; - $params['dns'] = $this->_injector->getInstance('Net_DNS2_Resolver'); - $params['external_callback'] = array('Horde', 'externalUrl'); - break; - - case 'Ooo': - $params['temp_dir'] = Horde::getTempDir(); - $params['zip'] = Horde_Compress::factory('Zip'); - break; - - case 'Rar': - $params['monospace'] = 'fixed'; - $params['rar'] = Horde_Compress::factory('Rar'); - break; - - case 'Report': - case 'Security': - $params['viewer_callback'] = array($this, 'getViewerCallback'); - break; - - case 'Syntaxhighlighter': - if ($config['app'] == 'horde') { - $driver = 'Horde_Core_Mime_Viewer_Syntaxhighlighter'; - } - $params['registry'] = $GLOBALS['registry']; - break; - - case 'Tgz': - $params['gzip'] = Horde_Compress::factory('Gzip'); - $params['monospace'] = 'fixed'; - $params['tar'] = Horde_Compress::factory('Tar'); - break; - - case 'Tnef': - $params['tnef'] = Horde_Compress::factory('Tnef'); - break; - - case 'Vcard': - if ($config['app'] == 'horde') { - $driver = 'Horde_Core_Mime_Viewer_Vcard'; - } - $params['browser'] = $GLOBALS['browser']; - $params['notification'] = $GLOBALS['notification']; - $params['prefs'] = $GLOBALS['prefs']; - $params['registry'] = $GLOBALS['registry']; - break; - - case 'Zip': - $params['monospace'] = 'fixed'; - $params['zip'] = Horde_Compress::factory('Zip'); - break; + case 'Deb': + case 'Rpm': + $params['monospace'] = 'fixed'; + break; + + case 'Html': + $params['browser'] = $GLOBALS['browser']; + $params['dns'] = $this->_injector->getInstance('Net_DNS2_Resolver'); + $params['external_callback'] = ['Horde', 'externalUrl']; + break; + + case 'Ooo': + $params['temp_dir'] = Horde::getTempDir(); + $params['zip'] = Horde_Compress::factory('Zip'); + break; + + case 'Rar': + $params['monospace'] = 'fixed'; + $params['rar'] = Horde_Compress::factory('Rar'); + break; + + case 'Report': + case 'Security': + $params['viewer_callback'] = [$this, 'getViewerCallback']; + break; + + case 'Syntaxhighlighter': + if ($config['app'] == 'horde') { + $driver = 'Horde_Core_Mime_Viewer_Syntaxhighlighter'; + } + $params['registry'] = $GLOBALS['registry']; + break; + + case 'Tgz': + $params['gzip'] = Horde_Compress::factory('Gzip'); + $params['monospace'] = 'fixed'; + $params['tar'] = Horde_Compress::factory('Tar'); + break; + + case 'Tnef': + $params['tnef'] = Horde_Compress::factory('Tnef'); + break; + + case 'Vcard': + if ($config['app'] == 'horde') { + $driver = 'Horde_Core_Mime_Viewer_Vcard'; + } + $params['browser'] = $GLOBALS['browser']; + $params['notification'] = $GLOBALS['notification']; + $params['prefs'] = $GLOBALS['prefs']; + $params['registry'] = $GLOBALS['registry']; + break; + + case 'Zip': + $params['monospace'] = 'fixed'; + $params['zip'] = Horde_Compress::factory('Zip'); + break; } - return array( + return [ $this->_getDriverName($driver, 'Horde_Mime_Viewer'), - $params - ); + $params, + ]; } /** @@ -165,10 +164,12 @@ public function getViewerConfig($type, $app) * @return Horde_Mime_Viewer_Base The newly created instance. * @throws Horde_Mime_Viewer_Exception */ - public function getViewerCallback(Horde_Mime_Viewer_Base $viewer, - Horde_Mime_Part $mime, $type) - { - return $this->create($mime, array('type' => $type)); + public function getViewerCallback( + Horde_Mime_Viewer_Base $viewer, + Horde_Mime_Part $mime, + $type + ) { + return $this->create($mime, ['type' => $type]); } /** @@ -184,11 +185,10 @@ public function getViewerCallback(Horde_Mime_Viewer_Base $viewer, * @return Horde_Themes_Image An object which contains the URI * and filesystem location of the image. */ - public function getIcon($mime, array $opts = array()) + public function getIcon($mime, array $opts = []) { - $app = isset($opts['app']) - ? $opts['app'] - : $GLOBALS['registry']->getApp(); + $app = $opts['app'] + ?? $GLOBALS['registry']->getApp(); $type = ($mime instanceof Horde_Mime_Part) ? $mime->getType() @@ -197,10 +197,10 @@ public function getIcon($mime, array $opts = array()) $config = $this->_getDriver($type, $app); if (!isset($config['icon'])) { - $config['icon'] = array( + $config['icon'] = [ 'app' => 'horde', - 'icon' => 'text.png' - ); + 'icon' => 'text.png', + ]; } return Horde_Themes::img('mime/' . $config['icon']['icon'], $config['icon']['app']); @@ -228,13 +228,13 @@ private function _loadConfig($app) try { $aconfig = $registry->loadConfigFile('mime_drivers.php', 'mime_drivers', $app)->config['mime_drivers']; } catch (Horde_Exception $e) { - $aconfig = array(); + $aconfig = []; } - $config = array( - 'config' => array(), - 'handles' => array() - ); + $config = [ + 'config' => [], + 'handles' => [], + ]; foreach ($aconfig as $key => $val) { if (empty($val['disable'])) { @@ -249,7 +249,7 @@ private function _loadConfig($app) /* Make sure there is a default entry. */ if (($app == 'horde') && !isset($config['config']['default'])) { - $config['config']['default'] = array(); + $config['config']['default'] = []; } $this->_config[$app] = $config; @@ -269,18 +269,18 @@ private function _getDriver($type, $app) /* Start with default driver, and then merge in wildcard and exact * match configs. */ - $config = array(); - list($ptype,) = explode('/', $type, 2); + $config = []; + [$ptype, ] = explode('/', $type, 2); $wild = $ptype . '/*'; - $app_list = array( - array('horde', 'default', 'config'), - array($app, 'default', 'config'), - array('horde', $wild, 'handles'), - array($app, $wild, 'handles'), - array('horde', $type, 'handles'), - array($app, $type, 'handles') - ); + $app_list = [ + ['horde', 'default', 'config'], + [$app, 'default', 'config'], + ['horde', $wild, 'handles'], + [$app, $wild, 'handles'], + ['horde', $type, 'handles'], + [$app, $type, 'handles'], + ]; if ($app == 'horde') { unset($app_list[1], $app_list[3], $app_list[5]); } @@ -293,22 +293,22 @@ private function _getDriver($type, $app) if ($driver) { $tmp = $this->_config[$val[0]]['config'][$driver]; if (isset($tmp['icons'])) { - foreach (array($type, $wild, 'default') as $val2) { + foreach ([$type, $wild, 'default'] as $val2) { if (isset($tmp['icons'][$val2])) { - $tmp['icon'] = array( + $tmp['icon'] = [ 'app' => $val[0], - 'icon' => $tmp['icons'][$val2] - ); + 'icon' => $tmp['icons'][$val2], + ]; break; } } unset($tmp['icons']); } - $config = array_merge(array_replace_recursive($config, $tmp), array( + $config = array_merge(array_replace_recursive($config, $tmp), [ 'app' => $val[0], - 'driver' => $driver - )); + 'driver' => $driver, + ]); } } diff --git a/lib/Horde/Core/Factory/Nosql.php b/lib/Horde/Core/Factory/Nosql.php index e346faf2d..a9afff169 100644 --- a/lib/Horde/Core/Factory/Nosql.php +++ b/lib/Horde/Core/Factory/Nosql.php @@ -1,4 +1,5 @@ _instances[$sig])) { return $this->_instances[$sig]; @@ -68,7 +69,8 @@ public function create($app = 'horde', $backend = null) $e = null; try { $this->_instances[$sig] = $this->createNosql($config); - } catch (Horde_Exception $e) {} + } catch (Horde_Exception $e) { + } if ($pushed) { $GLOBALS['registry']->popApp(); @@ -98,15 +100,15 @@ public function createNosql($config) } switch ($config['phptype']) { - case 'mongo': - $ob = new Horde_Mongo_Client(empty($config['hostspec']) ? 'localhost' : $config['hostspec']); - if (isset($config['dbname']) && strlen($config['dbname'])) { - $ob->dbname = $config['dbname']; - } - return $ob; - - default: - throw new Horde_Exception(sprintf('Nosql driver %s doesn\'t exist.', $config['phptype'])); + case 'mongo': + $ob = new Horde_Mongo_Client(empty($config['hostspec']) ? 'localhost' : $config['hostspec']); + if (isset($config['dbname']) && strlen($config['dbname'])) { + $ob->dbname = $config['dbname']; + } + return $ob; + + default: + throw new Horde_Exception(sprintf('Nosql driver %s doesn\'t exist.', $config['phptype'])); } } diff --git a/lib/Horde/Core/Factory/NosqlBase.php b/lib/Horde/Core/Factory/NosqlBase.php index 70f560bf0..d1c83a1d7 100644 --- a/lib/Horde/Core/Factory/NosqlBase.php +++ b/lib/Horde/Core/Factory/NosqlBase.php @@ -1,4 +1,5 @@ getInstance('Horde_Core_Factory_Db') - ->create('horde', 'perms'); - } catch (Horde_Exception $e) { - $driver = 'Null'; - } - break; + case 'sql': + try { + $params['db'] = $injector + ->getInstance('Horde_Core_Factory_Db') + ->create('horde', 'perms'); + } catch (Horde_Exception $e) { + $driver = 'Null'; + } + break; } $params['cache'] = new Horde_Cache( - new Horde_Cache_Storage_Stack(array( - 'stack' => array( + new Horde_Cache_Storage_Stack([ + 'stack' => [ new Horde_Cache_Storage_Memory(), - $injector->getInstance('Horde_Cache') - ) - )) + $injector->getInstance('Horde_Cache'), + ], + ]) ); $params['logger'] = $injector->getInstance('Horde_Log_Logger'); diff --git a/lib/Horde/Core/Factory/PermsCore.php b/lib/Horde/Core/Factory/PermsCore.php index d3f0d01d3..c4962ba90 100644 --- a/lib/Horde/Core/Factory/PermsCore.php +++ b/lib/Horde/Core/Factory/PermsCore.php @@ -1,4 +1,5 @@ _injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'prefs'); - if ($nosql instanceof Horde_Mongo_Client) { - $driver = 'mongo'; - } - break; + case 'nosql': + $nosql = $this->_injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'prefs'); + if ($nosql instanceof Horde_Mongo_Client) { + $driver = 'mongo'; + } + break; } $driver = $this->_getDriverName($driver, 'Horde_Prefs_Storage'); } catch (Horde_Exception $e) { @@ -90,13 +91,13 @@ public function create($scope = 'horde', array $opts = array()) $params = $opts['driver_params']; } - $opts = array_merge(array( + $opts = array_merge([ 'cache' => true, 'logger' => $this->_injector->getInstance('Horde_Log_Logger'), 'password' => '', - 'sizecallback' => ((isset($conf['prefs']['maxsize'])) ? array($this, 'sizeCallback') : null), - 'user' => '' - ), $opts); + 'sizecallback' => ((isset($conf['prefs']['maxsize'])) ? [$this, 'sizeCallback'] : null), + 'user' => '', + ], $opts); /* If $params['user_hook'] is defined, use it to retrieve the value to * use for the username. */ @@ -107,10 +108,10 @@ function_exists($params['user_hook'])) { /* To determine signature, don't serialize the logger or size * callback, since they may contain unserializable components. */ - $sig_opts = array_merge($opts, array( + $sig_opts = array_merge($opts, [ 'logger' => get_class($opts['logger']), - 'sizecallback' => !is_null($opts['sizecallback']) - )); + 'sizecallback' => !is_null($opts['sizecallback']), + ]); ksort($sig_opts); $sig = hash('md5', serialize($sig_opts) . '|' . $registry->getAuth()); @@ -121,39 +122,39 @@ function_exists($params['user_hook'])) { try { switch ($driver) { - case 'Horde_Prefs_Storage_Ldap': - $params['ldap'] = $this->_injector - ->getInstance('Horde_Core_Factory_Ldap') - ->create('horde', 'prefs'); - break; + case 'Horde_Prefs_Storage_Ldap': + $params['ldap'] = $this->_injector + ->getInstance('Horde_Core_Factory_Ldap') + ->create('horde', 'prefs'); + break; - case 'Horde_Prefs_Storage_Mongo': - $params['mongo_db'] = $nosql; - break; + case 'Horde_Prefs_Storage_Mongo': + $params['mongo_db'] = $nosql; + break; - case 'Horde_Prefs_Storage_Session': - $driver = 'Horde_Prefs_Storage_Null'; - break; + case 'Horde_Prefs_Storage_Session': + $driver = 'Horde_Prefs_Storage_Null'; + break; - case 'Horde_Prefs_Storage_Sql': - $params['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'prefs'); - break; + case 'Horde_Prefs_Storage_Sql': + $params['db'] = $this->_injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'prefs'); + break; - case 'Horde_Prefs_Storage_KolabImap': - if ($registry->isAdmin()) { - throw new Horde_Exception('The IMAP based Kolab preferences backend is unavailable for system administrators.'); - } - $params['kolab'] = $this->_injector - ->getInstance('Horde_Kolab_Storage'); - $params['logger'] = $opts['logger']; - break; - - case 'Horde_Prefs_Storage_Imsp': - $imspParams = $conf['imsp']; - $imspParams['username'] = $registry->getAuth('bare'); - $imspParams['password'] = $registry->getAuthCredential('password'); - $params['imsp'] = $this->_injector - ->getInstance('Horde_Core_Factory_Imsp')->create('Options', $imspParams); + case 'Horde_Prefs_Storage_KolabImap': + if ($registry->isAdmin()) { + throw new Horde_Exception('The IMAP based Kolab preferences backend is unavailable for system administrators.'); + } + $params['kolab'] = $this->_injector + ->getInstance('Horde_Kolab_Storage'); + $params['logger'] = $opts['logger']; + break; + + case 'Horde_Prefs_Storage_Imsp': + $imspParams = $conf['imsp']; + $imspParams['username'] = $registry->getAuth('bare'); + $imspParams['password'] = $registry->getAuthCredential('password'); + $params['imsp'] = $this->_injector + ->getInstance('Horde_Core_Factory_Imsp')->create('Options', $imspParams); } $this->storage = new $driver($opts['user'], $params); } catch (Horde_Exception $e) { @@ -164,11 +165,11 @@ function_exists($params['user_hook'])) { } $config_driver = new Horde_Core_Prefs_Storage_Configuration($opts['user']); - $hooks_driver = new Horde_Core_Prefs_Storage_Hooks($opts['user'], array('conf_ob' => $config_driver)); + $hooks_driver = new Horde_Core_Prefs_Storage_Hooks($opts['user'], ['conf_ob' => $config_driver]); $drivers = $driver - ? array($config_driver, $this->storage, $hooks_driver) - : array($config_driver, $hooks_driver); + ? [$config_driver, $this->storage, $hooks_driver] + : [$config_driver, $hooks_driver]; if ($driver && $opts['cache']) { $opts['cache'] = $this->_getCache($opts['user'], false); @@ -187,7 +188,7 @@ function_exists($params['user_hook'])) { $this->_instances[$sig] = new Horde_Prefs( $scope, - array($config_driver, $hooks_driver), + [$config_driver, $hooks_driver], $opts ); } @@ -206,7 +207,7 @@ protected function _notifyError($e) if (!$GLOBALS['session']->get('horde', 'no_prefs')) { $GLOBALS['session']->set('horde', 'no_prefs', true); if (isset($GLOBALS['notification'])) { - $GLOBALS['notification']->push(Horde_Core_Translation::t("The preferences backend is currently unavailable and your preferences have not been loaded. You may continue to use the system with default preferences.")); + $GLOBALS['notification']->push(Horde_Core_Translation::t('The preferences backend is currently unavailable and your preferences have not been loaded. You may continue to use the system with default preferences.')); Horde::log($e); } } @@ -224,10 +225,10 @@ protected function _getCache($user, $fallback) { global $injector; - $params = array( + $params = [ 'app' => 'horde', - 'storage_key' => 'horde_prefs_cache' - ); + 'storage_key' => 'horde_prefs_cache', + ]; if ($fallback) { $params['cache'] = new Horde_Cache_Storage_Null(); @@ -238,19 +239,19 @@ protected function _getCache($user, $fallback) return new Horde_Prefs_Cache_HordeCache( $user, - array( + [ 'cache' => new Horde_Cache( new Horde_Core_Cache_Session($params), - array( + [ /* Don't enable compression here. Data is either * compressed in the main Horde_Cache object (if * oversized) or is compressed within the session * (if stored in session cache). */ 'compress' => false, - 'logger' => $injector->getInstance('Horde_Core_Log_Wrapper') - ) - ) - ) + 'logger' => $injector->getInstance('Horde_Core_Log_Wrapper'), + ] + ), + ] ); } @@ -259,7 +260,7 @@ protected function _getCache($user, $fallback) */ public function clearCache() { - $this->_instances = array(); + $this->_instances = []; } /** @@ -276,7 +277,7 @@ public function sizeCallback($pref, $size) return false; } - $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("The preference \"%s\" could not be saved because its data exceeds the maximum allowable size"), $pref), 'horde.error'); + $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t('The preference "%s" could not be saved because its data exceeds the maximum allowable size'), $pref), 'horde.error'); return true; } diff --git a/lib/Horde/Core/Factory/QueueStorage.php b/lib/Horde/Core/Factory/QueueStorage.php index 11361ed01..25278736b 100644 --- a/lib/Horde/Core/Factory/QueueStorage.php +++ b/lib/Horde/Core/Factory/QueueStorage.php @@ -1,4 +1,5 @@ setPath(isset($_SERVER['REDIRECT_URL']) ? $_SERVER['REDIRECT_URL'] : $_SERVER['REQUEST_URI']); + $request->setPath($_SERVER['REDIRECT_URL'] ?? $_SERVER['REQUEST_URI']); return $request; } } diff --git a/lib/Horde/Core/Factory/Secret.php b/lib/Horde/Core/Factory/Secret.php index 98e0630cc..0d3f3fcf9 100644 --- a/lib/Horde/Core/Factory/Secret.php +++ b/lib/Horde/Core/Factory/Secret.php @@ -1,4 +1,5 @@ $conf['cookie']['domain'], 'cookie_path' => $conf['cookie']['path'], 'cookie_ssl' => $conf['use_ssl'] == 1, - 'session_name' => $conf['session']['name'] - )); + 'session_name' => $conf['session']['name'], + ]); } } diff --git a/lib/Horde/Core/Factory/Secret/Cbc.php b/lib/Horde/Core/Factory/Secret/Cbc.php index ef3046e67..6185b18ce 100644 --- a/lib/Horde/Core/Factory/Secret/Cbc.php +++ b/lib/Horde/Core/Factory/Secret/Cbc.php @@ -1,4 +1,5 @@ $conf['cookie']['domain'], 'cookie_path' => $conf['cookie']['path'], 'cookie_ssl' => $conf['use_ssl'] == 1, 'iv' => $conf['secret_key'], - 'session_name' => $conf['session']['name'] - )); + 'session_name' => $conf['session']['name'], + ]); } } diff --git a/lib/Horde/Core/Factory/SessionHandler.php b/lib/Horde/Core/Factory/SessionHandler.php index 7edbeaee9..3ecf0876a 100644 --- a/lib/Horde/Core/Factory/SessionHandler.php +++ b/lib/Horde/Core/Factory/SessionHandler.php @@ -1,4 +1,5 @@ getInstance('Horde_HashTable'); - $driver = 'hashtable'; - break; - - case 'nosql': - $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'sessionhandler'); - if ($nosql instanceof Horde_Mongo_Client) { - $params['mongo_db'] = $nosql; - $driver = 'Horde_SessionHandler_Storage_Mongo'; - } - break; - - case 'sql': - $factory = $injector->getInstance('Horde_Core_Factory_Db'); - $config = $factory->getConfig('sessionhandler'); - unset($config['umask'], $config['driverconfig']); - $params['db'] = $factory->createDb($config); - break; + case 'builtin': + $noset = true; + break; + + case 'hashtable': + // DEPRECATED + case 'memcache': + $params['hashtable'] = $injector->getInstance('Horde_HashTable'); + $driver = 'hashtable'; + break; + + case 'nosql': + $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'sessionhandler'); + if ($nosql instanceof Horde_Mongo_Client) { + $params['mongo_db'] = $nosql; + $driver = 'Horde_SessionHandler_Storage_Mongo'; + } + break; + + case 'sql': + $factory = $injector->getInstance('Horde_Core_Factory_Db'); + $config = $factory->getConfig('sessionhandler'); + unset($config['umask'], $config['driverconfig']); + $params['db'] = $factory->createDb($config); + break; } $class = $this->_getDriverName($driver, 'Horde_SessionHandler_Storage'); @@ -75,25 +76,25 @@ public function create(Horde_Injector $injector) if ((!empty($conf['sessionhandler']['hashtable']) || !empty($conf['sessionhandler']['memcache'])) && - !in_array($driver, array('builtin', 'hashtable'))) { - $storage = new Horde_SessionHandler_Storage_Stack(array( - 'stack' => array( - new Horde_SessionHandler_Storage_Hashtable(array( - 'hashtable' => $injector->getInstance('Horde_HashTable') - )), - $this->storage - ) - )); + !in_array($driver, ['builtin', 'hashtable'])) { + $storage = new Horde_SessionHandler_Storage_Stack([ + 'stack' => [ + new Horde_SessionHandler_Storage_Hashtable([ + 'hashtable' => $injector->getInstance('Horde_HashTable'), + ]), + $this->storage, + ], + ]); } return new Horde_SessionHandler( $storage, - array( + [ 'logger' => $injector->getInstance('Horde_Log_Logger'), 'no_md5' => true, 'noset' => $noset, - 'parse' => array($this, 'readSessionData') - ) + 'parse' => [$this, 'readSessionData'], + ] ); } @@ -118,7 +119,7 @@ public function readSessionData($session_data) * search for the needed auth entries and swap the old session data * back. */ $old_sess = $_SESSION; - $_SESSION = array(); + $_SESSION = []; if (session_id()) { $new_sess = false; @@ -127,12 +128,12 @@ public function readSessionData($session_data) $stub = new Horde_Support_Stub(); session_set_save_handler( - array($this, '_returnTrue'), - array($this, '_returnTrue'), - array($stub, 'read'), - array($stub, 'write'), - array($this, '_returnTrue'), - array($this, '_returnTrue') + [$this, '_returnTrue'], + [$this, '_returnTrue'], + [$stub, 'read'], + [$stub, 'write'], + [$this, '_returnTrue'], + [$this, '_returnTrue'] ); ob_start(); @@ -155,13 +156,13 @@ public function readSessionData($session_data) $_SESSION = $old_sess; return isset($data['userId']) - ? array( + ? [ 'apps' => $apps, 'browser' => $data['browser'], 'remoteAddr' => $data['remoteAddr'], 'timestamp' => $data['timestamp'], - 'userid' => $data['userId'] - ) + 'userid' => $data['userId'], + ] : false; } diff --git a/lib/Horde/Core/Factory/Share.php b/lib/Horde/Core/Factory/Share.php index d7b92a578..100330f63 100644 --- a/lib/Horde/Core/Factory/Share.php +++ b/lib/Horde/Core/Factory/Share.php @@ -1,4 +1,5 @@ _getDriverName($driver, 'Horde_Share'); $ob = new $class($app, $registry->getAuth(), $this->_injector->getInstance('Horde_Perms'), $this->_injector->getInstance('Horde_Group')); $cb = new Horde_Core_Share_FactoryCallback($app, $driver); - $ob->setShareCallback(array($cb, 'create')); + $ob->setShareCallback([$cb, 'create']); $ob->setLogger($this->_injector->getInstance('Horde_Log_Logger')); if (!empty($conf['share']['cache'])) { @@ -77,10 +78,10 @@ public function create($app = null, $driver = null) $ob->setListCache($listCache); if (empty($this->_toCache)) { - register_shutdown_function(array($this, 'shutdown')); + register_shutdown_function([$this, 'shutdown']); } - $this->_toCache[$sig] = array($app, $cache_sig); + $this->_toCache[$sig] = [$app, $cache_sig]; } $this->_instances[$sig] = $ob; diff --git a/lib/Horde/Core/Factory/SpellChecker.php b/lib/Horde/Core/Factory/SpellChecker.php index 731c0572a..12754b601 100644 --- a/lib/Horde/Core/Factory/SpellChecker.php +++ b/lib/Horde/Core/Factory/SpellChecker.php @@ -1,4 +1,5 @@ array()), + ['localDict' => []], Horde::getDriverConfig('spell', null), $args ); @@ -50,7 +51,8 @@ public function create(array $args = array(), $input = null) if (!is_null($input)) { try { $args['locale'] = $this->_injector->getInstance('Horde_Core_Factory_LanguageDetect')->getLanguageCode($input); - } catch (Horde_Exception $e) {} + } catch (Horde_Exception $e) { + } } if (empty($args['locale']) && isset($language)) { @@ -64,7 +66,8 @@ public function create(array $args = array(), $input = null) $args['localDict'], $registry->loadConfigFile('spelling.php', 'ignore_list', 'horde')->config['ignore_list'] ); - } catch (Horde_Exception $e) {} + } catch (Horde_Exception $e) { + } $classname = 'Horde_SpellChecker_' . Horde_String::ucfirst(basename($conf['spell']['driver'])); if (!class_exists($classname)) { diff --git a/lib/Horde/Core/Factory/Template.php b/lib/Horde/Core/Factory/Template.php index a2c72350a..798d68e11 100644 --- a/lib/Horde/Core/Factory/Template.php +++ b/lib/Horde/Core/Factory/Template.php @@ -1,4 +1,5 @@ $injector->getInstance('Horde_Cache'), - 'logger' => $injector->getInstance('Horde_Log_Logger') - )); + 'logger' => $injector->getInstance('Horde_Log_Logger'), + ]); } } diff --git a/lib/Horde/Core/Factory/TextFilter.php b/lib/Horde/Core/Factory/TextFilter.php index ecc3e2f70..ce73aa16b 100644 --- a/lib/Horde/Core/Factory/TextFilter.php +++ b/lib/Horde/Core/Factory/TextFilter.php @@ -1,4 +1,5 @@ _getDriver($driver, $params); + [$driver, $params] = $this->_getDriver($driver, $params); $driver = $this->_getDriverName($driver, 'Horde_Text_Filter'); return new $driver($params); } @@ -52,18 +53,18 @@ public function create($driver, array $params = array()) * * @return string The transformed text. */ - public function filter($text, $filters = array(), $params = array()) + public function filter($text, $filters = [], $params = []) { if (!is_array($filters)) { - $filters = array($filters); - $params = array($params); + $filters = [$filters]; + $params = [$params]; } - $filter_list = array(); + $filter_list = []; $params = array_values($params); foreach (array_values($filters) as $num => $filter) { - list($driver, $driv_param) = $this->_getDriver($filter, isset($params[$num]) ? $params[$num] : array()); + [$driver, $driv_param] = $this->_getDriver($filter, $params[$num] ?? []); $filter_list[$driver] = $driv_param; } @@ -85,42 +86,42 @@ protected function _getDriver($driver, $params) $lc_driver = Horde_String::lower($driver); switch ($lc_driver) { - case 'bbcode': - $driver = 'Horde_Core_Text_Filter_Bbcode'; - break; + case 'bbcode': + $driver = 'Horde_Core_Text_Filter_Bbcode'; + break; - case 'emails': - $driver = 'Horde_Core_Text_Filter_Emails'; - break; + case 'emails': + $driver = 'Horde_Core_Text_Filter_Emails'; + break; - case 'emoticons': - $driver = 'Horde_Core_Text_Filter_Emoticons'; - break; + case 'emoticons': + $driver = 'Horde_Core_Text_Filter_Emoticons'; + break; - case 'highlightquotes': - $driver = 'Horde_Core_Text_Filter_Highlightquotes'; - break; + case 'highlightquotes': + $driver = 'Horde_Core_Text_Filter_Highlightquotes'; + break; - case 'linkurls': - if (!isset($params['callback'])) { - $params['callback'] = 'Horde::externalUrl'; - } - break; + case 'linkurls': + if (!isset($params['callback'])) { + $params['callback'] = 'Horde::externalUrl'; + } + break; - case 'text2html': - $param_copy = $params; - foreach (array('emails', 'linkurls', 'space2html') as $val) { - if (!isset($params[$val])) { - $tmp = $this->_getDriver($val, $param_copy); - $params[$val] = array( - $tmp[0] => $tmp[1] - ); + case 'text2html': + $param_copy = $params; + foreach (['emails', 'linkurls', 'space2html'] as $val) { + if (!isset($params[$val])) { + $tmp = $this->_getDriver($val, $param_copy); + $params[$val] = [ + $tmp[0] => $tmp[1], + ]; + } } - } - break; + break; } - return array($driver, $params); + return [$driver, $params]; } } diff --git a/lib/Horde/Core/Factory/ThemesCache.php b/lib/Horde/Core/Factory/ThemesCache.php index 2095bf142..aaf576501 100644 --- a/lib/Horde/Core/Factory/ThemesCache.php +++ b/lib/Horde/Core/Factory/ThemesCache.php @@ -1,4 +1,5 @@ * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 */ -class Horde_Core_Factory_ThemesCache -extends Horde_Core_Factory_Base -implements Horde_Shutdown_Task +class Horde_Core_Factory_ThemesCache extends Horde_Core_Factory_Base implements Horde_Shutdown_Task { /** * Instances. * * @var array */ - private $_instances = array(); + private $_instances = []; /** * Return the Horde_Themes_Cache:: instance. @@ -44,7 +43,7 @@ class Horde_Core_Factory_ThemesCache */ public function create($app, $theme) { - $sig = implode('|', array($app, $theme)); + $sig = implode('|', [$app, $theme]); if (!isset($this->_instances[$sig])) { $cache = empty($GLOBALS['conf']['cachethemes']) @@ -85,7 +84,7 @@ public function create($app, $theme) */ public function expireCache($app, $theme) { - $sig = implode('|', array($app, $theme)); + $sig = implode('|', [$app, $theme]); $cache = $this->_injector->getInstance('Horde_Cache'); diff --git a/lib/Horde/Core/Factory/Timezone.php b/lib/Horde/Core/Factory/Timezone.php index e491e2fa6..d3cca75cf 100644 --- a/lib/Horde/Core/Factory/Timezone.php +++ b/lib/Horde/Core/Factory/Timezone.php @@ -1,4 +1,5 @@ $injector->getInstance('Horde_Cache'), 'location' => $GLOBALS['conf']['timezone']['location'], - 'temp' => Horde::getTempDir() - )); + 'temp' => Horde::getTempDir(), + ]); } } diff --git a/lib/Horde/Core/Factory/Token.php b/lib/Horde/Core/Factory/Token.php index 33297347f..777cdb3b4 100644 --- a/lib/Horde/Core/Factory/Token.php +++ b/lib/Horde/Core/Factory/Token.php @@ -1,4 +1,5 @@ getInstance('Horde_Log_Logger'); @@ -24,21 +25,21 @@ public function create(Horde_Injector $injector) $params['secret'] = $session->get('horde', 'token_secret_key'); switch (Horde_String::lower($driver)) { - case 'none': - $driver = 'null'; - break; - - case 'nosql': - $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'token'); - if ($nosql instanceof Horde_Mongo_Client) { - $params['mongo_db'] = $nosql; - $driver = 'Horde_Token_Mongo'; - } - break; - - case 'sql': - $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'token'); - break; + case 'none': + $driver = 'null'; + break; + + case 'nosql': + $nosql = $injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'token'); + if ($nosql instanceof Horde_Mongo_Client) { + $params['mongo_db'] = $nosql; + $driver = 'Horde_Token_Mongo'; + } + break; + + case 'sql': + $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('horde', 'token'); + break; } if (isset($conf['urls']['token_lifetime'])) { diff --git a/lib/Horde/Core/Factory/Topbar.php b/lib/Horde/Core/Factory/Topbar.php index ee5352881..e3312d748 100644 --- a/lib/Horde/Core/Factory/Topbar.php +++ b/lib/Horde/Core/Factory/Topbar.php @@ -1,4 +1,5 @@ _instances[$id])) { switch ($lc_renderer) { - case 'html': - $renderer = 'Horde_Core_Tree_Renderer_Html'; - break; + case 'html': + $renderer = 'Horde_Core_Tree_Renderer_Html'; + break; - case 'javascript': - $renderer = 'Horde_Core_Tree_Renderer_Javascript'; - break; + case 'javascript': + $renderer = 'Horde_Core_Tree_Renderer_Javascript'; + break; - case 'simplehtml': - $renderer = 'Horde_Core_Tree_Renderer_Simplehtml'; - break; + case 'simplehtml': + $renderer = 'Horde_Core_Tree_Renderer_Simplehtml'; + break; } $params['name'] = $name; if (empty($params['nosession'])) { - $params['session'] = array( - 'get' => array(__CLASS__, 'getSession'), - 'set' => array(__CLASS__, 'setSession') - ); + $params['session'] = [ + 'get' => [__CLASS__, 'getSession'], + 'set' => [__CLASS__, 'setSession'], + ]; } $this->_instances[$id] = Horde_Tree_Renderer::factory($renderer, $params); diff --git a/lib/Horde/Core/Factory/Twitter.php b/lib/Horde/Core/Factory/Twitter.php index cd356654f..fee91d553 100644 --- a/lib/Horde/Core/Factory/Twitter.php +++ b/lib/Horde/Core/Factory/Twitter.php @@ -1,4 +1,5 @@ $consumer_key, 'secret' => $consumer_secret, 'requestTokenUrl' => Horde_Service_Twitter::REQUEST_TOKEN_URL, 'authorizeTokenUrl' => Horde_Service_Twitter::USER_AUTHORIZE_URL, 'accessTokenUrl' => Horde_Service_Twitter::ACCESS_TOKEN_URL, 'signatureMethod' => new Horde_Oauth_SignatureMethod_HmacSha1(), - 'callbackUrl' => $GLOBALS['registry']->getServiceLink('twitter') - ); + 'callbackUrl' => $GLOBALS['registry']->getServiceLink('twitter'), + ]; /* Create the Consumer */ $auth = new Horde_Service_Twitter_Auth_Oauth(new Horde_Oauth_Consumer($params)); diff --git a/lib/Horde/Core/Factory/UrlShortener.php b/lib/Horde/Core/Factory/UrlShortener.php index 2e1c29b42..f162a3b88 100644 --- a/lib/Horde/Core/Factory/UrlShortener.php +++ b/lib/Horde/Core/Factory/UrlShortener.php @@ -1,4 +1,5 @@ _injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'vfs'); - if ($nosql instanceof Horde_Mongo_Client) { - $vfs['params']['mongo_db'] = $nosql; - $vfs['type'] = 'mongo'; - } - break; + case 'nosql': + $nosql = $this->_injector->getInstance('Horde_Core_Factory_Nosql')->create('horde', 'vfs'); + if ($nosql instanceof Horde_Mongo_Client) { + $vfs['params']['mongo_db'] = $nosql; + $vfs['type'] = 'mongo'; + } + break; - case 'sql': - case 'sqlfile': - case 'musql': - $config = Horde::getDriverConfig('vfs', 'sql'); - unset($config['umask'], $config['vfsroot']); - $vfs['params']['db'] = $this->_injector - ->getInstance('Horde_Core_Factory_Db') - ->create('horde', $config); - break; + case 'sql': + case 'sqlfile': + case 'musql': + $config = Horde::getDriverConfig('vfs', 'sql'); + unset($config['umask'], $config['vfsroot']); + $vfs['params']['db'] = $this->_injector + ->getInstance('Horde_Core_Factory_Db') + ->create('horde', $config); + break; } return $vfs; diff --git a/lib/Horde/Core/Factory/View.php b/lib/Horde/Core/Factory/View.php index b57e3d7f1..e7165e8b7 100644 --- a/lib/Horde/Core/Factory/View.php +++ b/lib/Horde/Core/Factory/View.php @@ -1,4 +1,5 @@ getInstance('Horde_Registry'); - $view = new Horde_View(array('templatePath' => $registry->get('templates', $registry->getApp()))); + $view = new Horde_View(['templatePath' => $registry->get('templates', $registry->getApp())]); $view->addHelper('Tag'); $view->addHelper('Text'); return $view; diff --git a/lib/Horde/Core/Factory/Weather.php b/lib/Horde/Core/Factory/Weather.php index 90eff10ac..51929aad0 100644 --- a/lib/Horde/Core/Factory/Weather.php +++ b/lib/Horde/Core/Factory/Weather.php @@ -1,4 +1,5 @@ $injector->getInstance('Horde_Cache'), 'cache_lifetime' => $conf['weather']['params']['lifetime'], - 'http_client' => $injector->createInstance('Horde_Core_Factory_HttpClient')->create() - ); + 'http_client' => $injector->createInstance('Horde_Core_Factory_HttpClient')->create(), + ]; $driver = $conf['weather']['provider']; switch ($driver) { - case 'WeatherUnderground': - case 'Wwo': - case 'Owm': - $params['apikey'] = $conf['weather']['params']['key']; - if (!empty($conf['weather']['params']['apiversion'])) { - $params['apiVersion'] = $conf['weather']['params']['apiversion']; - } - break; - case 'Metar': - $params['db'] = $injector->getInstance('Horde_Db_Adapter'); - break; + case 'WeatherUnderground': + case 'Wwo': + case 'Owm': + $params['apikey'] = $conf['weather']['params']['key']; + if (!empty($conf['weather']['params']['apiversion'])) { + $params['apiVersion'] = $conf['weather']['params']['apiversion']; + } + break; + case 'Metar': + $params['db'] = $injector->getInstance('Horde_Db_Adapter'); + break; } $class = $this->_getDriverName($driver, 'Horde_Service_Weather'); diff --git a/lib/Horde/Core/Group/Ldap.php b/lib/Horde/Core/Group/Ldap.php index 67861bc99..32e0364d0 100644 --- a/lib/Horde/Core/Group/Ldap.php +++ b/lib/Horde/Core/Group/Ldap.php @@ -1,4 +1,5 @@ getInstance('Horde_Core_Hooks')->callHook('groupldap', 'horde', array($name, $email)) + $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook('groupldap', 'horde', [$name, $email]) ); } catch (Horde_Exception_HookNotSet $e) { return parent::create($name, $email); diff --git a/lib/Horde/Core/HashTable/PersistentSession.php b/lib/Horde/Core/HashTable/PersistentSession.php index c317ce377..e445a1f63 100644 --- a/lib/Horde/Core/HashTable/PersistentSession.php +++ b/lib/Horde/Core/HashTable/PersistentSession.php @@ -1,4 +1,5 @@ $session->getToken(), - 'vfspath' => self::VFS_PATH - )); + 'vfspath' => self::VFS_PATH, + ]); $this->gc(86400); } /** */ - public function set($key, $val, array $opts = array()) + public function set($key, $val, array $opts = []) { global $session; diff --git a/lib/Horde/Core/HashTable/Vfs.php b/lib/Horde/Core/HashTable/Vfs.php index be98ee95b..1b226a9c9 100644 --- a/lib/Horde/Core/HashTable/Vfs.php +++ b/lib/Horde/Core/HashTable/Vfs.php @@ -1,4 +1,5 @@ getInstance('Horde_Core_Factory_Vfs')->create(); - } catch (Horde_Vfs_Exception $e) {} + } catch (Horde_Vfs_Exception $e) { + } if (!isset($vfs) || ($vfs instanceof Horde_Vfs_Null)) { - $vfs = new Horde_Vfs_File(array('vfsroot' => Horde::getTempDir())); + $vfs = new Horde_Vfs_File(['vfsroot' => Horde::getTempDir()]); } - parent::__construct(array_merge($params, array( + parent::__construct(array_merge($params, [ 'logger' => $injector->getInstance('Horde_Core_Log_Wrapper'), - 'vfs' => $vfs - ))); + 'vfs' => $vfs, + ])); } /** @@ -84,14 +85,14 @@ protected function _get($keys) return parent::_get($keys); } - $out = array(); + $out = []; foreach ($keys as $key) { try { if (method_exists($this->_vfs, 'readStream')) { - $data = new Horde_Stream_Existing(array( - 'stream' => $this->_vfs->readStream($this->_params['vfspath'], $key) - )); + $data = new Horde_Stream_Existing([ + 'stream' => $this->_vfs->readStream($this->_params['vfspath'], $key), + ]); $data->rewind(); } else { $data = new Horde_Stream_Temp(); diff --git a/lib/Horde/Core/HashTable/Wrapper.php b/lib/Horde/Core/HashTable/Wrapper.php index 00be0d8c2..afbc6bbc6 100644 --- a/lib/Horde/Core/HashTable/Wrapper.php +++ b/lib/Horde/Core/HashTable/Wrapper.php @@ -1,4 +1,5 @@ getInstance('Horde_HashTable'), $name), + [$GLOBALS['injector']->getInstance('Horde_HashTable'), $name], $arguments ); } diff --git a/lib/Horde/Core/History.php b/lib/Horde/Core/History.php index 445f7bcf8..317fab347 100644 --- a/lib/Horde/Core/History.php +++ b/lib/Horde/Core/History.php @@ -1,4 +1,5 @@ getAuth() @@ -87,7 +88,7 @@ public function getHistory($guid) /** * @see Horde_History::getByTimestamp() */ - public function getByTimestamp($cmp, $ts, array $filters = array(), $parent = null) + public function getByTimestamp($cmp, $ts, array $filters = [], $parent = null) { return $this->_history->getByTimestamp($cmp, $ts, $filters, $parent); } @@ -95,7 +96,7 @@ public function getByTimestamp($cmp, $ts, array $filters = array(), $parent = nu /** * @see Horde_History:getByModSeq() */ - public function getByModSeq($start, $end, $filters = array(), $parent = null) + public function getByModSeq($start, $end, $filters = [], $parent = null) { return $this->_history->getByModSeq($start, $end, $filters, $parent); } @@ -159,7 +160,7 @@ protected function _log(Horde_History_Log $history, array $attributes, $replaceA // Horde_History class to satisfy any typehints. } - public function _getByTimestamp($cmp, $ts, array $filters = array(), $parent = null) + public function _getByTimestamp($cmp, $ts, array $filters = [], $parent = null) { // NOOP } diff --git a/lib/Horde/Core/Hooks.php b/lib/Horde/Core/Hooks.php index cade7a9a5..93ff38d99 100644 --- a/lib/Horde/Core/Hooks.php +++ b/lib/Horde/Core/Hooks.php @@ -1,4 +1,5 @@ hookExists($hook, $app)) { throw new Horde_Exception_HookNotSet(); @@ -57,7 +58,7 @@ public function callHook($hook, $app = 'horde', array $args = array()) 'DEBUG' ); return call_user_func_array( - array($this->_apps[$app], $hook), + [$this->_apps[$app], $hook], $args ); } catch (Horde_Exception $e) { @@ -87,8 +88,9 @@ public function hookExists($hook, $app = 'horde') if (!class_exists($hook_class, false)) { try { $registry->loadConfigFile('hooks.php', null, $app); - $this->_apps[$app] = new $hook_class; - } catch (Horde_Exception $e) {} + $this->_apps[$app] = new $hook_class(); + } catch (Horde_Exception $e) { + } } } diff --git a/lib/Horde/Core/HordeMap.php b/lib/Horde/Core/HordeMap.php index fd8b440fc..fb4739b09 100644 --- a/lib/Horde/Core/HordeMap.php +++ b/lib/Horde/Core/HordeMap.php @@ -1,4 +1,5 @@ array( + $params = array_merge([ + 'conf' => [ 'language' => $language, 'markerImage' => strval(Horde_Themes::img('map/marker.png')), 'markerBackground' => strval(Horde_Themes::img('map/marker-shadow.png')), 'useMarkerLayer' => true, - ), + ], 'driver' => 'Horde', 'geocoder' => $conf['maps']['geocoder'], 'jsuri' => $registry->get('jsuri', 'horde') . '/map/', 'ssl' => $browser->usingSSLConnection(), - ), $params); + ], $params); // If providers were not specified, use global. We don't merge them // above to allow overriding the global completely. @@ -65,24 +66,24 @@ public static function init(array $params = array()) foreach ($params['providers'] as $layer) { switch ($layer) { - case 'Google': - $params['conf']['apikeys']['google'] = $conf['api']['googlemaps']; - break; + case 'Google': + $params['conf']['apikeys']['google'] = $conf['api']['googlemaps']; + break; } } if (!empty($params['geocoder'])) { switch ($params['geocoder']) { - case 'Google': - $params['conf']['apikeys']['google'] = $conf['api']['googlemaps']; - break; + case 'Google': + $params['conf']['apikeys']['google'] = $conf['api']['googlemaps']; + break; } } $page_output->addScriptFile('map/map.js', 'horde'); - $page_output->addInlineScript(array( - 'HordeMap.initialize(' . Horde_Serialize::serialize($params, HORDE_SERIALIZE::JSON) . ');' - )); + $page_output->addInlineScript([ + 'HordeMap.initialize(' . Horde_Serialize::serialize($params, HORDE_SERIALIZE::JSON) . ');', + ]); } } diff --git a/lib/Horde/Core/Imsp/Utils.php b/lib/Horde/Core/Imsp/Utils.php index 2e301db81..e3a8db870 100644 --- a/lib/Horde/Core/Imsp/Utils.php +++ b/lib/Horde/Core/Imsp/Utils.php @@ -1,4 +1,5 @@ getInstance('Horde_Core_Factory_Imsp')->create('Book', $serverInfo['params']); $books = $imsp->getAddressBookList(); $bCount = count($books); @@ -101,9 +102,9 @@ public static function createBook(array $source, $newName) */ public function synchShares($share_obj, array $serverInfo) { - $found_shares = array(); - $return = array('added' => array(), 'removed' => array()); - $params = array(); + $found_shares = []; + $return = ['added' => [], 'removed' => []]; + $params = []; $imsp = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imsp')->create('Book', $serverInfo['params']); $abooks = $imsp->getAddressBookList(); @@ -128,8 +129,8 @@ public function synchShares($share_obj, array $serverInfo) } } if (!$found) { - $shareparams = array('name' => $abook_uid, - 'source' => 'imsp'); + $shareparams = ['name' => $abook_uid, + 'source' => 'imsp']; $params['uid'] = hash('md5', mt_rand()); $params['name'] = $abook_uid . ' (IMSP)'; @@ -140,9 +141,11 @@ public function synchShares($share_obj, array $serverInfo) } else { $shareparams['default'] = false; } - if (self::_isOwner($abook_uid, - $serverInfo['params']['username'], - $params['acl'])) { + if (self::_isOwner( + $abook_uid, + $serverInfo['params']['username'], + $params['acl'] + )) { $params['owner'] = $GLOBALS['registry']->getAuth(); } else { // TODO: What to do for the owner when it's not current user? @@ -160,15 +163,15 @@ public function synchShares($share_obj, array $serverInfo) } // Now prune any shares that no longer exist on the IMSP server. - $existing = $share_obj->listShares($GLOBALS['registry']->getAuth(), array('perm' => Horde_Perms::READ)); + $existing = $share_obj->listShares($GLOBALS['registry']->getAuth(), ['perm' => Horde_Perms::READ]); foreach ($existing as $share) { $temp = unserialize($share->get('params')); if (is_array($temp)) { $sourceType = $temp['source']; if ($sourceType == 'imsp' && array_search($temp['name'], $found_shares) === false) { - $share_obj->removeShare($share); - $return['removed'][] = $share->getName(); + $share_obj->removeShare($share); + $return['removed'][] = $share->getName(); } } } @@ -224,19 +227,19 @@ protected static function _isOwner($bookName, $username, $acl) */ protected static function _setPerms(&$share, $acl) { - $hPerms = 0; - if (strpos($acl, 'w') !== false) { - $hPerms |= Horde_Perms::EDIT; - } - if (strpos($acl, 'r') !== false) { - $hPerms |= Horde_Perms::READ; - } - if (strpos($acl, 'd') !== false) { - $hPerms |= Horde_Perms::DELETE; - } - if (strpos($acl, 'l') !== false) { - $hPerms |= Horde_Perms::SHOW; - } + $hPerms = 0; + if (strpos($acl, 'w') !== false) { + $hPerms |= Horde_Perms::EDIT; + } + if (strpos($acl, 'r') !== false) { + $hPerms |= Horde_Perms::READ; + } + if (strpos($acl, 'd') !== false) { + $hPerms |= Horde_Perms::DELETE; + } + if (strpos($acl, 'l') !== false) { + $hPerms |= Horde_Perms::SHOW; + } $share->addUserPermission($GLOBALS['registry']->getAuth(), $hPerms); } diff --git a/lib/Horde/Core/Itip/Response/Options/Horde.php b/lib/Horde/Core/Itip/Response/Options/Horde.php index 80aff4542..065588cdf 100644 --- a/lib/Horde/Core/Itip/Response/Options/Horde.php +++ b/lib/Horde/Core/Itip/Response/Options/Horde.php @@ -1,4 +1,5 @@ getType()); if (empty($app)) { Horde::log(sprintf( - 'Unsupported app type: %s', $data->getType()), 'WARN'); + 'Unsupported app type: %s', + $data->getType() + ), 'WARN'); return false; } @@ -44,7 +46,7 @@ public static function getPrefix(Horde_Kolab_Storage_Data $data) ->create($app) ->listAllShares(); - foreach($all_shares as $id => $share) { + foreach ($all_shares as $id => $share) { if ($folder == $share->get('folder')) { $share_id = $id; break; @@ -75,13 +77,13 @@ protected static function _type2app($type) global $registry; if (!isset(self::$_mapping)) { - self::$_mapping = array( + self::$_mapping = [ 'contact' => $registry->hasInterface('contacts'), 'distribution-list' => $registry->hasInterface('contacts'), 'event' => $registry->hasInterface('calendar'), 'note' => $registry->hasInterface('notes'), - 'task' => $registry->hasInterface('tasks') - ); + 'task' => $registry->hasInterface('tasks'), + ]; } return !empty(self::$_mapping[$type]) @@ -89,4 +91,4 @@ protected static function _type2app($type) : false; } -} \ No newline at end of file +} diff --git a/lib/Horde/Core/Log/Logger.php b/lib/Horde/Core/Log/Logger.php index 47c857a33..84103cad3 100644 --- a/lib/Horde/Core/Log/Logger.php +++ b/lib/Horde/Core/Log/Logger.php @@ -1,4 +1,5 @@ details)) { $text .= ' ' . $event->details; } - $trace = array( + $trace = [ 'file' => $event->getFile(), - 'line' => $event->getLine() - ); + 'line' => $event->getLine(), + ]; if (empty($options['notracelog']) && class_exists('Horde_Support_Backtrace')) { @@ -149,7 +153,7 @@ class_exists('Horde_Support_Backtrace')) { } elseif (is_object($event)) { $text = strval($event); if (!is_string($text)) { - $text = is_callable(array($event, 'getMessage')) + $text = is_callable([$event, 'getMessage']) ? $event->getMessage() : ''; } @@ -164,11 +168,11 @@ class_exists('Horde_Support_Backtrace')) { : 0; while ($frame < $trace_count) { if (isset($trace[$frame]['class'])) { - if (!in_array($trace[$frame]['class'], array('Horde_Log_Logger', 'Horde_Core_Log_Logger'))) { + if (!in_array($trace[$frame]['class'], ['Horde_Log_Logger', 'Horde_Core_Log_Logger'])) { break; } } elseif (isset($trace[$frame]['function']) && - !in_array($trace[$frame]['function'], array('call_user_func', 'call_user_func_array'))) { + !in_array($trace[$frame]['function'], ['call_user_func', 'call_user_func_array'])) { break; } ++$frame; @@ -190,12 +194,10 @@ class_exists('Horde_Support_Backtrace')) { ' [pid ' . getmypid(); if (isset($options['file']) || isset($trace['file'])) { - $file = isset($options['file']) - ? $options['file'] - : $trace['file']; - $line = isset($options['line']) - ? $options['line'] - : $trace['line']; + $file = $options['file'] + ?? $trace['file']; + $line = $options['line'] + ?? $trace['line']; $this->_message .= ' on line ' . $line . ' of "' . $file . '"]'; } else { @@ -211,13 +213,13 @@ class_exists('Horde_Support_Backtrace')) { public function __get($name) { switch ($name) { - case 'backtrace': - case 'logged': - case 'message': - case 'priority': - case 'timestamp': - $varname = '_' . $name; - return $this->$varname; + case 'backtrace': + case 'logged': + case 'message': + case 'priority': + case 'timestamp': + $varname = '_' . $name; + return $this->$varname; } } @@ -226,28 +228,28 @@ public function __get($name) public function __set($name, $value) { switch ($name) { - case 'logged': - if ($value && $this->_exception instanceof HordeException) { - $this->_exception->logged = true; - } - $this->_logged = $value; - break; - - case 'message': - $this->_message = strval($value); - break; - - case 'priority': - if (is_integer($value)) { - $this->_priority = $value; - } elseif (defined('Horde_Log::' . $value)) { - $this->_priority = constant('Horde_Log::' . $value); - } - break; + case 'logged': + if ($value && $this->_exception instanceof HordeException) { + $this->_exception->logged = true; + } + $this->_logged = $value; + break; + + case 'message': + $this->_message = strval($value); + break; + + case 'priority': + if (is_integer($value)) { + $this->_priority = $value; + } elseif (defined('Horde_Log::' . $value)) { + $this->_priority = constant('Horde_Log::' . $value); + } + break; - case 'timestamp': - $this->_timestamp = intval($value); - break; + case 'timestamp': + $this->_timestamp = intval($value); + break; } } @@ -260,10 +262,10 @@ public function toArray() { global $conf; - $out = array( + $out = [ 'level' => $this->priority, - 'message' => $this->message - ); + 'message' => $this->message, + ]; if (!empty($conf['log']['time_format'])) { $out['timestamp'] = date($conf['log']['time_format'], $this->timestamp); diff --git a/lib/Horde/Core/Log/Wrapper.php b/lib/Horde/Core/Log/Wrapper.php index f027ec11f..636342df1 100644 --- a/lib/Horde/Core/Log/Wrapper.php +++ b/lib/Horde/Core/Log/Wrapper.php @@ -1,4 +1,5 @@ getInstance('Horde_Log_Logger'), $name), + [$GLOBALS['injector']->getInstance('Horde_Log_Logger'), $name], $arguments ); } diff --git a/lib/Horde/Core/LoginTasks.php b/lib/Horde/Core/LoginTasks.php index 30904ff4e..994038c5a 100644 --- a/lib/Horde/Core/LoginTasks.php +++ b/lib/Horde/Core/LoginTasks.php @@ -1,4 +1,5 @@ getAppDrivers($this->_app, 'LoginTasks_SystemTask'), $GLOBALS['registry']->getAppDrivers($this->_app, 'LoginTasks_Task')) as $val) { $tasks[$val] = $this->_app; @@ -83,12 +84,12 @@ public function getLastRun() try { $lasttask_pref = @unserialize($GLOBALS['prefs']->getValue('last_logintasks')); } catch (Horde_Prefs_Exception $e) { - return array(); + return []; } return is_array($lasttask_pref) ? $lasttask_pref - : array(); + : []; } /** diff --git a/lib/Horde/Core/LoginTasks/SystemTask/Upgrade.php b/lib/Horde/Core/LoginTasks/SystemTask/Upgrade.php index 48c566fd9..157a21614 100644 --- a/lib/Horde/Core/LoginTasks/SystemTask/Upgrade.php +++ b/lib/Horde/Core/LoginTasks/SystemTask/Upgrade.php @@ -1,4 +1,5 @@ _toupgrade[] = $val; @@ -114,7 +115,7 @@ public function skip() { /* Skip task until we are authenticated. */ return ($this->_auth && - !$GLOBALS['registry']->isAuthenticated(array('app' => $this->_app))); + !$GLOBALS['registry']->isAuthenticated(['app' => $this->_app])); } /** @@ -136,17 +137,16 @@ protected function _pref($action) $upgrade = @unserialize($prefs->getValue('upgrade_tasks')); switch ($action) { - case 'get': - $val = isset($upgrade[$key]) - ? $upgrade[$key] - : null; - break; - - case 'set': - $val = $registry->getVersion($this->_app, true); - $upgrade[$key] = $val; - $prefs->setValue('upgrade_tasks', serialize($upgrade)); - break; + case 'get': + $val = $upgrade[$key] + ?? null; + break; + + case 'set': + $val = $registry->getVersion($this->_app, true); + $upgrade[$key] = $val; + $prefs->setValue('upgrade_tasks', serialize($upgrade)); + break; } return $val; diff --git a/lib/Horde/Core/Mime/Headers/Received.php b/lib/Horde/Core/Mime/Headers/Received.php index b4703db6c..1050a15a5 100644 --- a/lib/Horde/Core/Mime/Headers/Received.php +++ b/lib/Horde/Core/Mime/Headers/Received.php @@ -1,4 +1,5 @@ Horde hop (conforms diff --git a/lib/Horde/Core/Mime/Viewer/Syntaxhighlighter.php b/lib/Horde/Core/Mime/Viewer/Syntaxhighlighter.php index 08f9edd56..dd247bd4f 100644 --- a/lib/Horde/Core/Mime/Viewer/Syntaxhighlighter.php +++ b/lib/Horde/Core/Mime/Viewer/Syntaxhighlighter.php @@ -1,4 +1,5 @@ true, 'info' => false, 'inline' => true, - 'raw' => false - ); + 'raw' => false, + ]; /** * URL that can be used as a callback for displaying images. @@ -45,14 +46,14 @@ class Horde_Core_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Base * * @throws InvalidArgumentException */ - public function __construct(Horde_Mime_Part $part, array $conf = array()) + public function __construct(Horde_Mime_Part $part, array $conf = []) { - $this->_required = array_merge($this->_required, array( + $this->_required = array_merge($this->_required, [ 'browser', 'notification', 'prefs', - 'registry' - )); + 'registry', + ]); parent::__construct($part, $conf); } @@ -96,11 +97,11 @@ protected function _renderInline() $data = $this->_mimepart->getContents(); $html = ''; - $title = Horde_Core_Translation::t("vCard"); + $title = Horde_Core_Translation::t('vCard'); $iCal = new Horde_Icalendar(); if (!$iCal->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) { - $notification->push(Horde_Core_Translation::t("There was an error reading the contact data."), 'horde.error'); + $notification->push(Horde_Core_Translation::t('There was an error reading the contact data.'), 'horde.error'); } if (Horde_Util::getFormData('import') && @@ -111,19 +112,24 @@ protected function _renderInline() foreach ($iCal->getComponents() as $c) { if ($c->getType() == 'vcard') { try { - $registry->call('contacts/import', array($c, null, $source)); + $registry->call('contacts/import', [$c, null, $source]); ++$count; } catch (Horde_Exception $e) { - $notification->push(Horde_Core_Translation::t("There was an error importing the contact data:") . ' ' . $e->getMessage(), 'horde.error'); + $notification->push(Horde_Core_Translation::t('There was an error importing the contact data:') . ' ' . $e->getMessage(), 'horde.error'); } } } - $notification->push(sprintf(Horde_Core_Translation::ngettext( - "%d contact was successfully added to your address book.", - "%d contacts were successfully added to your address book.", - $count), - $count), - 'horde.success'); + $notification->push( + sprintf( + Horde_Core_Translation::ngettext( + '%d contact was successfully added to your address book.', + '%d contacts were successfully added to your address book.', + $count + ), + $count + ), + 'horde.success' + ); } $html .= ''; @@ -139,46 +145,55 @@ protected function _renderInline() if (($fullname = $vc->getAttributeDefault('FN', false)) === false) { $fullname = count($addresses) ? $addresses[0]['value'] - : Horde_Core_Translation::t("[No Label]"); + : Horde_Core_Translation::t('[No Label]'); } $html .= htmlspecialchars($fullname) . ''; $n = $vc->printableName(); if (!empty($n)) { - $html .= $this->_row(Horde_Core_Translation::t("Name"), $n); + $html .= $this->_row(Horde_Core_Translation::t('Name'), $n); } try { - $html .= $this->_row(Horde_Core_Translation::t("Alias"), implode("\n", $vc->getAttributeValues('ALIAS'))); - } catch (Horde_Icalendar_Exception $e) {} + $html .= $this->_row(Horde_Core_Translation::t('Alias'), implode("\n", $vc->getAttributeValues('ALIAS'))); + } catch (Horde_Icalendar_Exception $e) { + } try { $birthdays = $vc->getAttributeValues('BDAY'); $birthday = new Horde_Date($birthdays[0]); $html .= $this->_row( - Horde_Core_Translation::t("Birthday"), - $birthday->strftime($prefs->getValue('date_format'))); - } catch (Horde_Icalendar_Exception $e) {} + Horde_Core_Translation::t('Birthday'), + $birthday->strftime($prefs->getValue('date_format')) + ); + } catch (Horde_Icalendar_Exception $e) { + } $photos = $vc->getAllAttributes('PHOTO'); foreach ($photos as $p => $photo) { if (isset($photo['params']['VALUE']) && Horde_String::upper($photo['params']['VALUE']) == 'URI') { - $html .= $this->_row(Horde_Core_Translation::t("Photo"), - '', - false); + $html .= $this->_row( + Horde_Core_Translation::t('Photo'), + '', + false + ); } elseif (isset($photo['params']['ENCODING']) && Horde_String::upper($photo['params']['ENCODING']) == 'B' && isset($photo['params']['TYPE'])) { if ($browser->hasFeature('datauri') === true || $browser->hasFeature('datauri') >= strlen($photo['value'])) { - $html .= $this->_row(Horde_Core_Translation::t("Photo"), - '', - false); + $html .= $this->_row( + Horde_Core_Translation::t('Photo'), + '', + false + ); } elseif ($this->_imageUrl) { - $html .= $this->_row(Horde_Core_Translation::t("Photo"), - '', - false); + $html .= $this->_row( + Horde_Core_Translation::t('Photo'), + '', + false + ); } } } @@ -187,45 +202,45 @@ protected function _renderInline() foreach ($labels as $label) { if (isset($label['params']['TYPE'])) { if (!is_array($label['params']['TYPE'])) { - $label['params']['TYPE'] = array($label['params']['TYPE']); + $label['params']['TYPE'] = [$label['params']['TYPE']]; } } else { $label['params']['TYPE'] = array_keys($label['params']); } - $types = array(); + $types = []; foreach ($label['params']['TYPE'] as $type) { - switch(Horde_String::upper($type)) { - case 'HOME': - $types[] = Horde_Core_Translation::t("Home Address"); - break; - - case 'WORK': - $types[] = Horde_Core_Translation::t("Work Address"); - break; - - case 'DOM': - $types[] = Horde_Core_Translation::t("Domestic Address"); - break; - - case 'INTL': - $types[] = Horde_Core_Translation::t("International Address"); - break; - - case 'POSTAL': - $types[] = Horde_Core_Translation::t("Postal Address"); - break; - - case 'PARCEL': - $types[] = Horde_Core_Translation::t("Parcel Address"); - break; - - case 'PREF': - $types[] = Horde_Core_Translation::t("Preferred Address"); - break; + switch (Horde_String::upper($type)) { + case 'HOME': + $types[] = Horde_Core_Translation::t('Home Address'); + break; + + case 'WORK': + $types[] = Horde_Core_Translation::t('Work Address'); + break; + + case 'DOM': + $types[] = Horde_Core_Translation::t('Domestic Address'); + break; + + case 'INTL': + $types[] = Horde_Core_Translation::t('International Address'); + break; + + case 'POSTAL': + $types[] = Horde_Core_Translation::t('Postal Address'); + break; + + case 'PARCEL': + $types[] = Horde_Core_Translation::t('Parcel Address'); + break; + + case 'PREF': + $types[] = Horde_Core_Translation::t('Preferred Address'); + break; } } if (!count($types)) { - $types = array(Horde_Core_Translation::t("Address")); + $types = [Horde_Core_Translation::t('Address')]; } $html .= $this->_row(implode('/', $types), $label['value']); } @@ -234,21 +249,21 @@ protected function _renderInline() foreach ($adrs as $item) { if (isset($item['params']['TYPE'])) { if (!is_array($item['params']['TYPE'])) { - $item['params']['TYPE'] = array($item['params']['TYPE']); + $item['params']['TYPE'] = [$item['params']['TYPE']]; } } else { $item['params']['TYPE'] = array_keys($item['params']); } $address = $item['values']; - $a = array(); - $a_list = array( + $a = []; + $a_list = [ Horde_Icalendar_Vcard::ADR_STREET, Horde_Icalendar_Vcard::ADR_LOCALITY, Horde_Icalendar_Vcard::ADR_REGION, Horde_Icalendar_Vcard::ADR_POSTCODE, - Horde_Icalendar_Vcard::ADR_COUNTRY - ); + Horde_Icalendar_Vcard::ADR_COUNTRY, + ]; foreach ($a_list as $val) { if (isset($address[$val])) { @@ -256,40 +271,40 @@ protected function _renderInline() } } - $types = array(); + $types = []; foreach ($item['params']['TYPE'] as $type) { - switch(Horde_String::upper($type)) { - case 'HOME': - $types[] = Horde_Core_Translation::t("Home Address"); - break; - - case 'WORK': - $types[] = Horde_Core_Translation::t("Work Address"); - break; - - case 'DOM': - $types[] = Horde_Core_Translation::t("Domestic Address"); - break; - - case 'INTL': - $types[] = Horde_Core_Translation::t("International Address"); - break; - - case 'POSTAL': - $types[] = Horde_Core_Translation::t("Postal Address"); - break; - - case 'PARCEL': - $types[] = Horde_Core_Translation::t("Parcel Address"); - break; - - case 'PREF': - $types[] = Horde_Core_Translation::t("Preferred Address"); - break; + switch (Horde_String::upper($type)) { + case 'HOME': + $types[] = Horde_Core_Translation::t('Home Address'); + break; + + case 'WORK': + $types[] = Horde_Core_Translation::t('Work Address'); + break; + + case 'DOM': + $types[] = Horde_Core_Translation::t('Domestic Address'); + break; + + case 'INTL': + $types[] = Horde_Core_Translation::t('International Address'); + break; + + case 'POSTAL': + $types[] = Horde_Core_Translation::t('Postal Address'); + break; + + case 'PARCEL': + $types[] = Horde_Core_Translation::t('Parcel Address'); + break; + + case 'PREF': + $types[] = Horde_Core_Translation::t('Preferred Address'); + break; } } if (!count($types)) { - $types = array(Horde_Core_Translation::t("Address")); + $types = [Horde_Core_Translation::t('Address')]; } $html .= $this->_row(implode('/', $types), implode("\n", $a)); } @@ -299,36 +314,44 @@ protected function _renderInline() foreach ($numbers as $number) { if (isset($number['params']['TYPE'])) { if (!is_array($number['params']['TYPE'])) { - $number['params']['TYPE'] = array($number['params']['TYPE']); + $number['params']['TYPE'] = [$number['params']['TYPE']]; } foreach ($number['params']['TYPE'] as $type) { $number['params'][Horde_String::upper($type)] = true; } } if (isset($number['params']['FAX'])) { - $html .= $this->_row(Horde_Core_Translation::t("Fax"), $number['value']); + $html .= $this->_row(Horde_Core_Translation::t('Fax'), $number['value']); } else { if (isset($number['params']['HOME'])) { - $html .= $this->_row(Horde_Core_Translation::t("Home Phone"), - $number['value']); + $html .= $this->_row( + Horde_Core_Translation::t('Home Phone'), + $number['value'] + ); } elseif (isset($number['params']['WORK'])) { - $html .= $this->_row(Horde_Core_Translation::t("Work Phone"), - $number['value']); + $html .= $this->_row( + Horde_Core_Translation::t('Work Phone'), + $number['value'] + ); } elseif (isset($number['params']['CELL'])) { - $html .= $this->_row(Horde_Core_Translation::t("Cell Phone"), - $number['value']); + $html .= $this->_row( + Horde_Core_Translation::t('Cell Phone'), + $number['value'] + ); } else { - $html .= $this->_row(Horde_Core_Translation::t("Phone"), - $number['value']); + $html .= $this->_row( + Horde_Core_Translation::t('Phone'), + $number['value'] + ); } } } - $emails = array(); + $emails = []; foreach ($addresses as $address) { if (isset($address['params']['TYPE'])) { if (!is_array($address['params']['TYPE'])) { - $address['params']['TYPE'] = array($address['params']['TYPE']); + $address['params']['TYPE'] = [$address['params']['TYPE']]; } foreach ($address['params']['TYPE'] as $type) { $address['params'][Horde_String::upper($type)] = true; @@ -338,7 +361,8 @@ protected function _renderInline() if ($registry->hasMethod('mail/compose')) { $email .= $registry->call( 'mail/compose', - array(array('to' => $address['value']))); + [['to' => $address['value']]] + ); } else { $email .= 'mailto:' . htmlspecialchars($address['value']); } @@ -351,41 +375,47 @@ protected function _renderInline() } if (count($emails)) { - $html .= $this->_row(Horde_Core_Translation::t("Email"), implode("\n", $emails), false); + $html .= $this->_row(Horde_Core_Translation::t('Email'), implode("\n", $emails), false); } try { $title = $vc->getAttributeValues('TITLE'); - $html .= $this->_row(Horde_Core_Translation::t("Title"), $title[0]); - } catch (Horde_Icalendar_Exception $e) {} + $html .= $this->_row(Horde_Core_Translation::t('Title'), $title[0]); + } catch (Horde_Icalendar_Exception $e) { + } try { $role = $vc->getAttributeValues('ROLE'); - $html .= $this->_row(Horde_Core_Translation::t("Role"), $role[0]); - } catch (Horde_Icalendar_Exception $e) {} + $html .= $this->_row(Horde_Core_Translation::t('Role'), $role[0]); + } catch (Horde_Icalendar_Exception $e) { + } try { $org = $vc->getAttributeValues('ORG'); - $html .= $this->_row(Horde_Core_Translation::t("Company"), $org[0]); + $html .= $this->_row(Horde_Core_Translation::t('Company'), $org[0]); if (isset($org[1])) { - $html .= $this->_row(Horde_Core_Translation::t("Department"), $org[1]); + $html .= $this->_row(Horde_Core_Translation::t('Department'), $org[1]); } - } catch (Horde_Icalendar_Exception $e) {} + } catch (Horde_Icalendar_Exception $e) { + } try { $notes = $vc->getAttributeValues('NOTE'); - $html .= $this->_row(Horde_Core_Translation::t("Notes"), $notes[0]); - } catch (Horde_Icalendar_Exception $e) {} + $html .= $this->_row(Horde_Core_Translation::t('Notes'), $notes[0]); + } catch (Horde_Icalendar_Exception $e) { + } try { $url = $vc->getAttributeValues('URL'); $html .= $this->_row( - Horde_Core_Translation::t("URL"), + Horde_Core_Translation::t('URL'), '' . htmlspecialchars($url[0]) . '', - false); - } catch (Horde_Icalendar_Exception $e) {} + false + ); + } catch (Horde_Icalendar_Exception $e) { + } } $html .= '
'; @@ -400,13 +430,13 @@ protected function _renderInline() . '" value="' . htmlspecialchars($val) . '" />'; } - $sources = $registry->call('contacts/sources', array(true)); + $sources = $registry->call('contacts/sources', [true]); if (count($sources) > 1) { $html .= '' + . Horde_Core_Translation::t('Add to address book:') . '" />' . ' ' + . Horde_Core_Translation::t('Address Book') . '' . '' + . Horde_Core_Translation::t('Add to my address book') . '" />' . ''; } @@ -429,7 +459,7 @@ protected function _renderInline() } Horde::startBuffer(); - $notification->notify(array('listeners' => 'status')); + $notification->notify(['listeners' => 'status']); return $this->_renderReturn( Horde::endBuffer() . $html, diff --git a/lib/Horde/Core/Nosql.php b/lib/Horde/Core/Nosql.php index 41616d25a..e90e237bd 100644 --- a/lib/Horde/Core/Nosql.php +++ b/lib/Horde/Core/Nosql.php @@ -1,4 +1,5 @@ callAppMethod($app, 'nosqlDrivers'); } catch (Horde_Exception $e) { - return array(); + return []; } /* Handle framework-level drivers here. */ if ($app == 'horde') { - $backends = array( - 'Horde_ActiveSync_State_Mongo' => function() use ($injector) { + $backends = [ + 'Horde_ActiveSync_State_Mongo' => function () use ($injector) { return $injector->getInstance('Horde_ActiveSyncState'); }, - 'Horde_Cache_Storage_Mongo' => function() use ($injector) { + 'Horde_Cache_Storage_Mongo' => function () use ($injector) { return $injector->getInstance('Horde_Core_Factory_Cache')->storage; }, - 'Horde_History_Mongo' => function() use ($injector) { + 'Horde_History_Mongo' => function () use ($injector) { return $injector->getInstance('Horde_History'); }, - 'Horde_Lock_Mongo' => function() use ($injector) { + 'Horde_Lock_Mongo' => function () use ($injector) { return $injector->getInstance('Horde_Lock'); }, - 'Horde_Prefs_Storage_Mongo' => function() use ($injector) { + 'Horde_Prefs_Storage_Mongo' => function () use ($injector) { return $injector->getInstance('Horde_Core_Factory_Prefs')->storage; }, - 'Horde_SessionHandler_Storage_Mongo' => function() use ($injector) { + 'Horde_SessionHandler_Storage_Mongo' => function () use ($injector) { return $injector->getInstance('Horde_Core_Factory_SessionHandler')->storage; }, - 'Horde_Token_Mongo' => function() use ($injector) { + 'Horde_Token_Mongo' => function () use ($injector) { return $injector->getInstance('Horde_Token'); }, - 'Horde_Vfs_Mongo' => function() use ($injector) { + 'Horde_Vfs_Mongo' => function () use ($injector) { return $injector->getInstance('Horde_Core_Factory_Vfs')->create(); }, - ); + ]; foreach ($backends as $key => $func) { try { diff --git a/lib/Horde/Core/Notification/Event/Status.php b/lib/Horde/Core/Notification/Event/Status.php index 400cce834..e32354b12 100644 --- a/lib/Horde/Core/Notification/Event/Status.php +++ b/lib/Horde/Core/Notification/Event/Status.php @@ -1,4 +1,5 @@ type) { - case 'horde.alarm': - $alarm = $this->flags['alarm']; - $text = $alarm['title']; - - if (!empty($alarm['params']['notify']['show'])) { - try { - $text = Horde::link(Horde::url($GLOBALS['registry']->linkByPackage($alarm['params']['notify']['show']['__app'], 'show', $alarm['params']['notify']['show'])), $alarm['text']) . $text . ''; - } catch (Horde_Exception $e) { - return $e->getMessage(); - } - } - - if (!empty($alarm['user']) && - $GLOBALS['browser']->hasFeature('xmlhttpreq')) { - try { - $url = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/snooze.php', true); - } catch (Horde_Exception $e) { - return $e->getMessage(); + case 'horde.alarm': + $alarm = $this->flags['alarm']; + $text = $alarm['title']; + + if (!empty($alarm['params']['notify']['show'])) { + try { + $text = Horde::link(Horde::url($GLOBALS['registry']->linkByPackage($alarm['params']['notify']['show']['__app'], 'show', $alarm['params']['notify']['show'])), $alarm['text']) . $text . ''; + } catch (Horde_Exception $e) { + return $e->getMessage(); + } } - $opts = array( - '-1' => Horde_Core_Translation::t("Dismiss"), - '5' => Horde_Core_Translation::t("5 minutes"), - '15' => Horde_Core_Translation::t("15 minutes"), - '60' => Horde_Core_Translation::t("1 hour"), - '360' => Horde_Core_Translation::t("6 hours"), - '1440' => Horde_Core_Translation::t("1 day") - ); - $id = 'snooze_' . hash('md5', $alarm['id']); - $text .= ' [' . Horde_Core_Translation::t("Snooze...") . ']'; - } - - $img = 'alerts/alarm.png'; - $label = Horde_Core_Translation::t("Alarm"); - break; - - case 'horde.error': - $img = 'alerts/error.png'; - $label = Horde_Core_Translation::t("Error"); - break; - - case 'horde.message': - $img = 'alerts/message.png'; - $label = Horde_Core_Translation::t("Message"); - break; - - case 'horde.success': - $img = 'alerts/success.png'; - $label = Horde_Core_Translation::t("Success"); - break; - - case 'horde.warning': - $img = 'alerts/warning.png'; - $label = Horde_Core_Translation::t("Warning"); - break; - - default: - return parent::__toString(); + + $img = 'alerts/alarm.png'; + $label = Horde_Core_Translation::t('Alarm'); + break; + + case 'horde.error': + $img = 'alerts/error.png'; + $label = Horde_Core_Translation::t('Error'); + break; + + case 'horde.message': + $img = 'alerts/message.png'; + $label = Horde_Core_Translation::t('Message'); + break; + + case 'horde.success': + $img = 'alerts/success.png'; + $label = Horde_Core_Translation::t('Success'); + break; + + case 'horde.warning': + $img = 'alerts/warning.png'; + $label = Horde_Core_Translation::t('Warning'); + break; + + default: + return parent::__toString(); } - return Horde_Themes_Image::tag($img, array('alt' => $label)) . + return Horde_Themes_Image::tag($img, ['alt' => $label]) . '
' . (is_null($text) ? parent::__toString() : $text) . '
'; diff --git a/lib/Horde/Core/Notification/Event/Webnotification.php b/lib/Horde/Core/Notification/Event/Webnotification.php index 7f0f5e7bf..86027e7e2 100644 --- a/lib/Horde/Core/Notification/Event/Webnotification.php +++ b/lib/Horde/Core/Notification/Event/Webnotification.php @@ -1,4 +1,5 @@ webnotify = $opts; diff --git a/lib/Horde/Core/Notification/Handler.php b/lib/Horde/Core/Notification/Handler.php index b56f6fd5e..92e57350e 100644 --- a/lib/Horde/Core/Notification/Handler.php +++ b/lib/Horde/Core/Notification/Handler.php @@ -1,4 +1,5 @@ _apps) { foreach ($this->_apps as $key => $val) { @@ -63,12 +63,12 @@ public function attachAllAppHandlers() return; } - $this->_apps = array(); + $this->_apps = []; try { $apps = $registry->listApps(null, false, Horde_Perms::READ); } catch (Horde_Exception $e) { - $apps = array(); + $apps = []; } foreach ($apps as $app) { @@ -100,12 +100,13 @@ public function addAppHandler($app) $registry->callAppMethod( $app, 'setupNotification', - array( - 'args' => array($this), - 'noperms' => true - ) + [ + 'args' => [$this], + 'noperms' => true, + ] ); - } catch (Exception $e) {} + } catch (Exception $e) { + } } } diff --git a/lib/Horde/Core/Notification/Handler/Decorator/Base.php b/lib/Horde/Core/Notification/Handler/Decorator/Base.php index 03df0b1a9..d0f0b8039 100644 --- a/lib/Horde/Core/Notification/Handler/Decorator/Base.php +++ b/lib/Horde/Core/Notification/Handler/Decorator/Base.php @@ -1,4 +1,5 @@ pushApp($this->_app, array( + $pushed = $registry->pushApp($this->_app, [ 'check_perms' => true, - 'logintasks' => false - )); + 'logintasks' => false, + ]); } catch (Exception $e) { return; } @@ -81,17 +82,16 @@ protected function _push(Horde_Notification_Event $event, $options) public function notify( Horde_Notification_Handler $handler, Horde_Notification_Listener $listener - ) - { + ) { global $registry; $error = null; try { - $pushed = $registry->pushApp($this->_app, array( + $pushed = $registry->pushApp($this->_app, [ 'check_perms' => true, - 'logintasks' => false - )); + 'logintasks' => false, + ]); } catch (Exception $e) { return; } @@ -118,8 +118,7 @@ public function notify( protected function _notify( Horde_Notification_Handler $handler, Horde_Notification_Listener $listener - ) - { + ) { parent::notify($handler, $listener); } diff --git a/lib/Horde/Core/Notification/Handler/Decorator/Hordelog.php b/lib/Horde/Core/Notification/Handler/Decorator/Hordelog.php index 504c1dc83..4a5088c61 100644 --- a/lib/Horde/Core/Notification/Handler/Decorator/Hordelog.php +++ b/lib/Horde/Core/Notification/Handler/Decorator/Hordelog.php @@ -1,4 +1,5 @@ addInlineScript(array( - 'window.HordeCore.showNotifications(' . Horde_Serialize::serialize($events, Horde_Serialize::JSON) . ')' - ), true); + $GLOBALS['page_output']->addInlineScript([ + 'window.HordeCore.showNotifications(' . Horde_Serialize::serialize($events, Horde_Serialize::JSON) . ')', + ], true); } } diff --git a/lib/Horde/Core/Notification/Listener/SmartmobileStatus.php b/lib/Horde/Core/Notification/Listener/SmartmobileStatus.php index 46a6a7f06..48cb01c02 100644 --- a/lib/Horde/Core/Notification/Listener/SmartmobileStatus.php +++ b/lib/Horde/Core/Notification/Listener/SmartmobileStatus.php @@ -1,4 +1,5 @@ getInstance('Horde_PageOutput')->addInlineScript(array( + $GLOBALS['injector']->getInstance('Horde_PageOutput')->addInlineScript([ '$(function() {HordeMobile.showNotifications(' . Horde_Serialize::serialize($events, Horde_Serialize::JSON) . - ');});' - )); + ');});', + ]); } } diff --git a/lib/Horde/Core/Notification/Listener/Webnotification.php b/lib/Horde/Core/Notification/Listener/Webnotification.php index 5477b5f87..abe85e4df 100644 --- a/lib/Horde/Core/Notification/Listener/Webnotification.php +++ b/lib/Horde/Core/Notification/Listener/Webnotification.php @@ -1,4 +1,5 @@ set('horde', 'notify/' . $key, $value); } } else { - $this->_cached[] = array($key, $value); + $this->_cached[] = [$key, $value]; } } @@ -65,7 +65,7 @@ public function exists($key) */ public function clear($key) { - $this->_cached = array(); + $this->_cached = []; $GLOBALS['session']->remove('horde', 'notify/' . $key); } @@ -80,7 +80,7 @@ public function push($listener, Horde_Notification_Event $event) $events[] = $event; $session->set('horde', 'notify/' . $listener, $events, Horde_Session::TYPE_OBJECT); } else { - $this->_cached[] = array($listener, $event); + $this->_cached[] = [$listener, $event]; } } @@ -90,7 +90,7 @@ protected function _processCached() { if (!empty($this->_cached) && $GLOBALS['session']->isActive()) { $cached = $this->_cached; - $this->_cached = array(); + $this->_cached = []; foreach ($cached as $val) { if ($val[1] instanceof Horde_Notification_Event) { diff --git a/lib/Horde/Core/Perms.php b/lib/Horde/Core/Perms.php index c4fb09a7c..fe69b682d 100644 --- a/lib/Horde/Core/Perms.php +++ b/lib/Horde/Core/Perms.php @@ -1,4 +1,5 @@ _registry = $registry; $this->_perms = $perms; } @@ -67,7 +69,7 @@ public function getAvailable($name) if (empty($name)) { /* No name passed, so top level permissions are requested. These * can only be applications. */ - $apps = $this->_registry->listApps(array('notoolbar', 'active', 'hidden'), true); + $apps = $this->_registry->listApps(['notoolbar', 'active', 'hidden'], true); foreach (array_keys($apps) as $app) { $apps[$app] = $this->_registry->get('name', $app) . ' (' . $app . ')'; } @@ -99,7 +101,7 @@ public function getAvailable($name) return false; } - $perms_list = array(); + $perms_list = []; foreach (array_keys($children) as $perm_key) { $perms_list[$perm_key] = $perms['title'][$name . ':' . $perm_key]; } @@ -118,7 +120,7 @@ public function getAvailable($name) public function getTitle($name) { if ($name === Horde_Perms::ROOT) { - return Horde_Core_Translation::t("All Permissions"); + return Horde_Core_Translation::t('All Permissions'); } $levels = explode(':', $name); @@ -153,7 +155,8 @@ public function getType($name) if (isset($info['type']) && isset($info['type'][$name])) { $type = $info['type'][$name]; } - } catch (Horde_Perms_Exception $e) {} + } catch (Horde_Perms_Exception $e) { + } } return $type; } @@ -174,7 +177,8 @@ public function getParams($name) if (isset($info['params']) && isset($info['params'][$name])) { $params = $info['params'][$name]; } - } catch (Horde_Perms_Exception $e) {} + } catch (Horde_Perms_Exception $e) { + } } return $params; } @@ -191,9 +195,11 @@ public function getParams($name) */ public function newPermission($name) { - return $this->_perms->newPermission($name, - $this->getType($name), - $this->getParams($name)); + return $this->_perms->newPermission( + $name, + $this->getType($name), + $this->getParams($name) + ); } /** @@ -209,19 +215,19 @@ public function getApplicationPermissions($app) try { $app_perms = $this->_registry->callAppMethod($app, 'perms'); } catch (Horde_Exception $e) { - $app_perms = array(); + $app_perms = []; } if (empty($app_perms)) { - $perms = array(); + $perms = []; } else { - $perms = array( - 'title' => array(), - 'tree' => array( - $app => array() - ), - 'type' => array() - ); + $perms = [ + 'title' => [], + 'tree' => [ + $app => [], + ], + 'type' => [], + ]; foreach ($app_perms as $key => $val) { $ptr = &$perms['tree'][$app]; @@ -265,11 +271,10 @@ public function getApplicationPermissions($app) * * @return mixed The specified permissions. */ - public function hasAppPermission($permission, $opts = array()) + public function hasAppPermission($permission, $opts = []) { - $app = isset($opts['app']) - ? $opts['app'] - : $this->_registry->getApp(); + $app = $opts['app'] + ?? $this->_registry->getApp(); if ($this->_perms->exists($app . ':' . $permission)) { $perms = $this->_perms->getPermissions($app . ':' . $permission, $this->_registry->getAuth()); @@ -277,15 +282,16 @@ public function hasAppPermission($permission, $opts = array()) return false; } - $args = array( + $args = [ $permission, $perms, - isset($opts['opts']) ? $opts['opts'] : array() - ); + $opts['opts'] ?? [], + ]; try { - return $this->_registry->callAppMethod($app, 'hasPermission', array('args' => $args)); - } catch (Horde_Exception $e) {} + return $this->_registry->callAppMethod($app, 'hasPermission', ['args' => $args]); + } catch (Horde_Exception $e) { + } } return true; diff --git a/lib/Horde/Core/Perms/Ui.php b/lib/Horde/Core/Perms/Ui.php index a09dd8698..6429a8de2 100644 --- a/lib/Horde/Core/Perms/Ui.php +++ b/lib/Horde/Core/Perms/Ui.php @@ -1,4 +1,5 @@ _perms = $perms; $this->_corePerms = $corePerms; } @@ -73,48 +75,48 @@ public function renderTree($current = Horde_Perms::ROOT) /* Get the perms tree. */ $nodes = $this->_perms->getTree(); - $perms_node = array('icon' => Horde_Themes::img('perms.png')); + $perms_node = ['icon' => Horde_Themes::img('perms.png')]; $add = Horde::url('admin/perms/addchild.php'); - $add_img = Horde_Themes_Image::tag('plus.png', array('alt' => Horde_Core_Translation::t("Add Permission"))); + $add_img = Horde_Themes_Image::tag('plus.png', ['alt' => Horde_Core_Translation::t('Add Permission')]); $edit = Horde::url('admin/perms/edit.php'); $delete = Horde::url('admin/perms/delete.php'); - $edit_img = Horde_Themes_Image::tag('edit.png', array('alt' => Horde_Core_Translation::t("Edit Permission"))); - $delete_img = Horde_Themes_Image::tag('delete.png', array('alt' => Horde_Core_Translation::t("Delete Permission"))); - $blank_img = Horde_Themes_Image::tag('blank.gif', array('attr' => array('width' => 16, 'height' => 16))); + $edit_img = Horde_Themes_Image::tag('edit.png', ['alt' => Horde_Core_Translation::t('Edit Permission')]); + $delete_img = Horde_Themes_Image::tag('delete.png', ['alt' => Horde_Core_Translation::t('Delete Permission')]); + $blank_img = Horde_Themes_Image::tag('blank.gif', ['attr' => ['width' => 16, 'height' => 16]]); /* Set up the tree. */ - $tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('perms_ui', 'Javascript', array( + $tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('perms_ui', 'Javascript', [ 'alternate' => true, - 'hideHeaders' => true - )); - $tree->setHeader(array( - array( - 'class' => 'horde-tree-spacer' - ) - )); + 'hideHeaders' => true, + ]); + $tree->setHeader([ + [ + 'class' => 'horde-tree-spacer', + ], + ]); foreach ($nodes as $perm_id => $node) { $node_class = ($current == $perm_id) - ? array('class' => 'selected') - : array(); + ? ['class' => 'selected'] + : []; if ($perm_id == Horde_Perms::ROOT) { - $add_link = $add->add('perm_id', $perm_id)->link(array('class' => 'permsAdd', 'title' => Horde_Core_Translation::t("Add New Permission"))) . $add_img . ''; - $base_node_params = array('icon' => Horde_Themes::img('administration.png')); + $add_link = $add->add('perm_id', $perm_id)->link(['class' => 'permsAdd', 'title' => Horde_Core_Translation::t('Add New Permission')]) . $add_img . ''; + $base_node_params = ['icon' => Horde_Themes::img('administration.png')]; - $tree->addNode(array( + $tree->addNode([ 'id' => $perm_id, - 'label' => Horde_Core_Translation::t("All Permissions"), + 'label' => Horde_Core_Translation::t('All Permissions'), 'expanded' => true, 'params' => $base_node_params + $node_class, - 'right' => array($add_link) - )); + 'right' => [$add_link], + ]); } else { $parent_id = $this->_perms->getParent($node); - $perms_extra = array(); + $perms_extra = []; $parents = explode(':', $node); - if (!in_array($parents[0], $GLOBALS['registry']->listApps(array('notoolbar', 'active', 'hidden')))) { + if (!in_array($parents[0], $GLOBALS['registry']->listApps(['notoolbar', 'active', 'hidden']))) { // This backend has permissions for an application that is // not installed. Perhaps the application has been removed // or the backend is shared with other Horde installations. @@ -131,29 +133,29 @@ public function renderTree($current = Horde_Perms::ROOT) if (isset($app_perms['tree']) && is_array(Horde_Array::getElement($app_perms['tree'], $parents))) { - $add_link = $add->add('perm_id', $perm_id)->link(array('class' => 'permsAdd', 'title' => Horde_Core_Translation::t("Add Child Permission"))) . $add_img . ''; + $add_link = $add->add('perm_id', $perm_id)->link(['class' => 'permsAdd', 'title' => Horde_Core_Translation::t('Add Child Permission')]) . $add_img . ''; $perms_extra[] = $add_link; } else { $perms_extra[] = $blank_img; } - $edit_link = $edit->add('perm_id', $perm_id)->link(array('class' => 'permsEdit', 'title' => Horde_Core_Translation::t("Edit Permission"))) . $edit_img . ''; + $edit_link = $edit->add('perm_id', $perm_id)->link(['class' => 'permsEdit', 'title' => Horde_Core_Translation::t('Edit Permission')]) . $edit_img . ''; $perms_extra[] = $edit_link; - $delete_link = $delete->add('perm_id', $perm_id)->link(array('class' => 'permsDelete', 'title' => Horde_Core_Translation::t("Delete Permission"))) . $delete_img . ''; + $delete_link = $delete->add('perm_id', $perm_id)->link(['class' => 'permsDelete', 'title' => Horde_Core_Translation::t('Delete Permission')]) . $delete_img . ''; $perms_extra[] = $delete_link; $name = $this->_corePerms->getTitle($node); $expanded = isset($nodes[$current]) && strpos($nodes[$current], $node) === 0 && $nodes[$current] != $node; - $tree->addNode(array( + $tree->addNode([ 'id' => $perm_id, 'parent' => $parent_id, 'label' => $name, 'expanded' => $expanded, 'params' => $perms_node + $node_class, - 'right' => $perms_extra - )); + 'right' => $perms_extra, + ]); } } @@ -197,8 +199,8 @@ public function setupAddForm($permission, $force_choice = null) /* Initialise form if required. */ $this->_formInit(); - $this->_form->setTitle(sprintf(Horde_Core_Translation::t("Add a child permission to \"%s\""), $this->_corePerms->getTitle($permission->getName()))); - $this->_form->setButtons(Horde_Core_Translation::t("Add")); + $this->_form->setTitle(sprintf(Horde_Core_Translation::t('Add a child permission to "%s"'), $this->_corePerms->getTitle($permission->getName()))); + $this->_form->setButtons(Horde_Core_Translation::t('Add')); $this->_vars->set('perm_id', $this->_perms->getPermissionId($permission)); $this->_form->addHidden('', 'perm_id', 'text', false); @@ -206,12 +208,12 @@ public function setupAddForm($permission, $force_choice = null) $child_perms = $this->_corePerms->getAvailable($permission->getName()); if ($child_perms === false) { /* False, so no childs are to be added below this level. */ - $this->_form->addVariable(Horde_Core_Translation::t("Permission"), 'child', 'invalid', true, false, null, array(Horde_Core_Translation::t("No children can be added to this permission."))); + $this->_form->addVariable(Horde_Core_Translation::t('Permission'), 'child', 'invalid', true, false, null, [Horde_Core_Translation::t('No children can be added to this permission.')]); } elseif (is_array($child_perms)) { if (!empty($force_choice)) { /* Choice array available, but choice being forced. */ $this->_vars->set('child', $force_choice); - $this->_form->addVariable(Horde_Core_Translation::t("Permissions"), 'child', 'enum', true, true, null, array($child_perms)); + $this->_form->addVariable(Horde_Core_Translation::t('Permissions'), 'child', 'enum', true, true, null, [$child_perms]); } else { /* Choice array available, so set up enum field. */ $prefix = $permission->getName() . ':'; @@ -221,7 +223,7 @@ public function setupAddForm($permission, $force_choice = null) unset($child_perms[substr($name, $length)]); } } - $this->_form->addVariable(Horde_Core_Translation::t("Permissions"), 'child', 'enum', true, false, null, array($child_perms)); + $this->_form->addVariable(Horde_Core_Translation::t('Permissions'), 'child', 'enum', true, false, null, [$child_perms]); } } } @@ -254,7 +256,7 @@ public function setupEditForm($permission) /* Initialise form if required. */ $this->_formInit(); - $this->_form->setButtons(Horde_Core_Translation::t("Update"), true); + $this->_form->setButtons(Horde_Core_Translation::t('Update'), true); $this->_vars->set('perm_id', $this->_perms->getPermissionId($permission)); $this->_form->addHidden('', 'perm_id', 'text', false); @@ -264,7 +266,7 @@ public function setupEditForm($permission) /* Default permissions. */ $perm_val = $permission->getDefaultPermissions(); - $this->_form->setSection('default', Horde_Core_Translation::t("All Authenticated Users"), Horde_Themes_Image::tag('perms.png'), false); + $this->_form->setSection('default', Horde_Core_Translation::t('All Authenticated Users'), Horde_Themes_Image::tag('perms.png'), false); /* We MUST use 'deflt' for the variable name because 'default' is a * reserved word in JavaScript. */ @@ -273,8 +275,8 @@ public function setupEditForm($permission) $cols = Horde_Perms::getPermsArray(); /* Define a single matrix row for default perms. */ - $matrix = array(Horde_Perms::integerToArray($perm_val)); - $this->_form->addVariable('', 'deflt', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); + $matrix = [Horde_Perms::integerToArray($perm_val)]; + $this->_form->addVariable('', 'deflt', 'matrix', false, false, null, [$cols, [0 => ''], $matrix]); } else { $var = $this->_form->addVariable('', 'deflt', $this->_type, false, false, null, $params); $var->setDefault($perm_val); @@ -282,12 +284,12 @@ public function setupEditForm($permission) /* Guest permissions. */ $perm_val = $permission->getGuestPermissions(); - $this->_form->setSection('guest', Horde_Core_Translation::t("Guest Permissions"), '', false); + $this->_form->setSection('guest', Horde_Core_Translation::t('Guest Permissions'), '', false); if ($this->_type == 'matrix') { /* Define a single matrix row for guest perms. */ - $matrix = array(Horde_Perms::integerToArray($perm_val)); - $this->_form->addVariable('', 'guest', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); + $matrix = [Horde_Perms::integerToArray($perm_val)]; + $this->_form->addVariable('', 'guest', 'matrix', false, false, null, [$cols, [0 => ''], $matrix]); } else { $var = $this->_form->addVariable('', 'guest', $this->_type, false, false, null, $params); $var->setDefault($perm_val); @@ -295,12 +297,12 @@ public function setupEditForm($permission) /* Object creator permissions. */ $perm_val = $permission->getCreatorPermissions(); - $this->_form->setSection('creator', Horde_Core_Translation::t("Creator Permissions"), Horde_Themes_Image::tag('user.png'), false); + $this->_form->setSection('creator', Horde_Core_Translation::t('Creator Permissions'), Horde_Themes_Image::tag('user.png'), false); if ($this->_type == 'matrix') { /* Define a single matrix row for creator perms. */ - $matrix = array(Horde_Perms::integerToArray($perm_val)); - $this->_form->addVariable('', 'creator', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); + $matrix = [Horde_Perms::integerToArray($perm_val)]; + $this->_form->addVariable('', 'creator', 'matrix', false, false, null, [$cols, [0 => ''], $matrix]); } else { $var = $this->_form->addVariable('', 'creator', $this->_type, false, false, null, $params); $var->setDefault($perm_val); @@ -308,14 +310,14 @@ public function setupEditForm($permission) /* Users permissions. */ $perm_val = $permission->getUserPermissions(); - $this->_form->setSection('users', Horde_Core_Translation::t("Individual Users"), Horde_Themes_Image::tag('user.png'), false); + $this->_form->setSection('users', Horde_Core_Translation::t('Individual Users'), Horde_Themes_Image::tag('user.png'), false); $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create(); - $user_list = array(); + $user_list = []; if ($auth->hasCapability('list')) { /* The auth driver has list capabilities so set up an array which * the matrix field type will recognise to set up an enum box for * adding new users to the permissions matrix. */ - $new_users = array(); + $new_users = []; try { $user_list = $auth->listNames(); @@ -337,19 +339,19 @@ public function setupEditForm($permission) /* Set up the matrix array, breaking up each permission integer * into an array. The keys of this array will be the row * headers. */ - $rows = array(); - $matrix = array(); + $rows = []; + $matrix = []; foreach ($perm_val as $u_id => $u_perms) { - $rows[$u_id] = isset($user_list[$u_id]) ? $user_list[$u_id] : $u_id; + $rows[$u_id] = $user_list[$u_id] ?? $u_id; $matrix[$u_id] = Horde_Perms::integerToArray($u_perms); } - $this->_form->addVariable('', 'u', 'matrix', false, false, null, array($cols, $rows, $matrix, $new_users)); + $this->_form->addVariable('', 'u', 'matrix', false, false, null, [$cols, $rows, $matrix, $new_users]); } else { if ($new_users) { if (is_array($new_users)) { $u_n = Horde_Util::getFormData('u_n'); $u_n = empty($u_n['u']) ? null : $u_n['u']; - $user_html = ''; foreach ($new_users as $new_user => $name) { $user_html .= ''; foreach ($new_groups as $groupId => $group) { $group_html .= '