From c7c9952b02c59d01dcf90ed1c3025cea6579c420 Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Sat, 23 May 2026 00:22:55 +0200 Subject: [PATCH] refactor: Use PSR-4 version of horde/nls Closes issue horde/Model#2 --- .horde.yml | 2 + lib/Horde/Core/Form.php | 109 +- lib/Horde/Core/Form/Renderer.php | 35 +- lib/Horde/Core/Form/Renderer/Html.php | 219 +-- lib/Horde/Core/Form/Type.php | 13 +- lib/Horde/Core/Form/Type/Boolean.php | 1 + lib/Horde/Core/Form/Type/Color.php | 1 + lib/Horde/Core/Form/Type/CreditCard.php | 23 +- lib/Horde/Core/Form/Type/Date.php | 28 +- lib/Horde/Core/Form/Type/DateTime.php | 50 +- lib/Horde/Core/Form/Type/Email.php | 46 +- lib/Horde/Core/Form/Type/EmailConfirm.php | 17 +- lib/Horde/Core/Form/Type/Enum.php | 7 +- lib/Horde/Core/Form/Type/Int.php | 3 +- lib/Horde/Core/Form/Type/Invalid.php | 9 +- lib/Horde/Core/Form/Type/KeyvalMultiEnum.php | 3 +- lib/Horde/Core/Form/Type/MultiEnum.php | 3 +- lib/Horde/Core/Form/Type/Number.php | 11 +- lib/Horde/Core/Form/Type/Octal.php | 3 +- lib/Horde/Core/Form/Type/Password.php | 1 + lib/Horde/Core/Form/Type/PasswordConfirm.php | 1 + lib/Horde/Core/Form/Type/Phone.php | 5 +- lib/Horde/Core/Form/Type/Phone/Mobile.php | 1 + lib/Horde/Core/Form/Type/Set.php | 1 + lib/Horde/Core/Form/Type/String.php | 1 + lib/Horde/Core/Form/Type/Time.php | 7 +- lib/Horde/Core/Form/Variable.php | 102 +- lib/Horde/Core/Form/daterendererchanges.php | 1327 ++++++++++-------- lib/Horde/Form/VarRenderer.php | 9 +- lib/Horde/Form/VarRenderer/Xhtml.php | 1028 ++++++++------ lib/Horde/Model/Translation.php | 3 +- test/NlsLocaleInfoTest.php | 53 + www/test.php | 40 +- 33 files changed, 1842 insertions(+), 1320 deletions(-) create mode 100644 test/NlsLocaleInfoTest.php diff --git a/.horde.yml b/.horde.yml index b31e599..8cf4066 100644 --- a/.horde.yml +++ b/.horde.yml @@ -30,3 +30,5 @@ dependencies: optional: composer: horde/test: ^3 +keywords: [] +vendor: horde diff --git a/lib/Horde/Core/Form.php b/lib/Horde/Core/Form.php index f0b8c88..841b961 100644 --- a/lib/Horde/Core/Form.php +++ b/lib/Horde/Core/Form.php @@ -1,12 +1,13 @@ - * Copyright 2001-2017 Horde LLC (http://www.horde.org/) + * Copyright 2001-2026 Robert E. Coyle + * Copyright 2001-2026 Horde LLC (http://www.horde.org/) * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. @@ -20,13 +21,13 @@ class Horde_Core_Form protected $_name = ''; protected $_title = ''; protected $_vars; - protected $_errors = array(); + protected $_errors = []; protected $_submitted = null; - protected $_sections = array(); + protected $_sections = []; protected $_open_section = null; - protected $_currentSection = array(); - protected $_variables = array(); - protected $_hiddenVariables = array(); + protected $_currentSection = []; + protected $_variables = []; + protected $_hiddenVariables = []; protected $_useFormToken = true; protected $_autofilled = false; protected $_help = false; @@ -103,19 +104,19 @@ public function useToken($token = null) * * @return object Horde_Core_Form_Renderer The form renderer. */ - function getRenderer($params = array()) + public function getRenderer($params = []) { return new Horde_Core_Form_Renderer_Xhtml($params); } - function getType($type, $params = array()) + public function getType($type, $params = []) { $type_class = 'Horde_Core_Form_Type_' . $type; if (!class_exists($type_class)) { throw new Horde_Exception(sprintf('Nonexistant class "%s" for field type "%s"', $type_class, $type)); } $type_ob = new $type_class(); - call_user_func_array(array($type_ob, 'init'), $params); + call_user_func_array([$type_ob, 'init'], $params); return $type_ob; } @@ -170,7 +171,7 @@ public function getSectionExpandedState($section, $boolean = false) } } - public function add($varName, $type, $humanName, $required, $readonly = false, $description = null, $params = array()) + public function add($varName, $type, $humanName, $required, $readonly = false, $description = null, $params = []) { return $this->addVariable($humanName, $varName, $type, $required, $readonly, $description, $params); } @@ -178,31 +179,55 @@ public function add($varName, $type, $humanName, $required, $readonly = false, $ /** * TODO */ - public function addVariable($humanName, $varName, $type, $required, - $readonly = false, $description = null, - $params = array()) - { - return $this->insertVariableBefore(null, $humanName, $varName, $type, - $required, $readonly, $description, - $params); + public function addVariable( + $humanName, + $varName, + $type, + $required, + $readonly = false, + $description = null, + $params = [] + ) { + return $this->insertVariableBefore( + null, + $humanName, + $varName, + $type, + $required, + $readonly, + $description, + $params + ); } /** * TODO */ - public function insertVariableBefore($before, $humanName, $varName, $type, - $required, $readonly = false, - $description = null, $params = array()) - { + public function insertVariableBefore( + $before, + $humanName, + $varName, + $type, + $required, + $readonly = false, + $description = null, + $params = [] + ) { $type = $this->getType($type, $params); - $var = new Horde_Core_Form_Variable($humanName, $varName, $type, - $required, $readonly, $description); + $var = new Horde_Core_Form_Variable( + $humanName, + $varName, + $type, + $required, + $readonly, + $description + ); /* Set the form object reference in the var. */ $var->setFormOb($this); - if ($var->getType() instanceof Horde_Core_Form_Type_Enum && - count($var->getValues()) == 1) { + if ($var->getType() instanceof Horde_Core_Form_Type_Enum + && count($var->getValues()) == 1) { $vals = array_keys($var->getValues()); $this->_vars->add($var->varName, $vals[0]); $var->_autofilled = true; @@ -215,8 +240,8 @@ public function insertVariableBefore($before, $humanName, $varName, $type, $this->_variables[$this->_currentSection][] = &$var; } else { $num = 0; - while (isset($this->_variables[$this->_currentSection][$num]) && - $this->_variables[$this->_currentSection][$num]->getVarName() != $before) { + while (isset($this->_variables[$this->_currentSection][$num]) + && $this->_variables[$this->_currentSection][$num]->getVarName() != $before) { $num++; } if (!isset($this->_variables[$this->_currentSection][$num])) { @@ -224,8 +249,9 @@ public function insertVariableBefore($before, $humanName, $varName, $type, } else { $this->_variables[$this->_currentSection] = array_merge( array_slice($this->_variables[$this->_currentSection], 0, $num), - array(&$var), - array_slice($this->_variables[$this->_currentSection], $num)); + [&$var], + array_slice($this->_variables[$this->_currentSection], $num) + ); } } @@ -251,12 +277,13 @@ public function removeVariable($var) { foreach (array_keys($this->_variables) as $section) { foreach (array_keys($this->_variables[$section]) as $i) { - if ((is_a($var, 'Horde_Core_Form_Variable') && $this->_variables[$section][$i] === $var) || - ($this->_variables[$section][$i]->getVarName() == $var)) { + if ((is_a($var, 'Horde_Core_Form_Variable') && $this->_variables[$section][$i] === $var) + || ($this->_variables[$section][$i]->getVarName() == $var)) { // Slice out the variable to be removed. $this->_variables[$this->_currentSection] = array_merge( array_slice($this->_variables[$this->_currentSection], 0, $i), - array_slice($this->_variables[$this->_currentSection], $i + 1)); + array_slice($this->_variables[$this->_currentSection], $i + 1) + ); return true; } @@ -269,7 +296,7 @@ public function removeVariable($var) /** * TODO */ - public function addHidden($varName, $type, $required, $params = array()) + public function addHidden($varName, $type, $required, $params = []) { $type = $this->getType($type, $params); $var = new Horde_Core_Form_Variable('', $varName, $type, $required); @@ -281,7 +308,7 @@ public function addHidden($varName, $type, $required, $params = array()) public function getVariables($flat = true, $withHidden = false) { if ($flat) { - $vars = array(); + $vars = []; foreach ($this->_variables as $section) { foreach ($section as $var) { $vars[] = $var; @@ -403,7 +430,7 @@ public function validate($canAutoFill = false) public function clearValidation() { - $this->_errors = array(); + $this->_errors = []; } public function getError($var) @@ -413,7 +440,7 @@ public function getError($var) } else { $name = $var; } - return isset($this->_errors[$name]) ? $this->_errors[$name] : null; + return $this->_errors[$name] ?? null; } public function setError($var, $message) @@ -482,13 +509,13 @@ protected function _getInfoFromVariables($variables, $info) } else { if (Horde_Array::getArrayParts($var->getVarName(), $base, $keys)) { if (!isset($info[$base])) { - $info[$base] = array(); + $info[$base] = []; } $pointer = &$info[$base]; while (count($keys)) { $key = array_shift($keys); if (!isset($pointer[$key])) { - $pointer[$key] = array(); + $pointer[$key] = []; } $pointer = &$pointer[$key]; } @@ -545,8 +572,8 @@ public function onSubmit() * submitted if old value and new value differ. */ if ($var->getOption('trackchange')) { $varname = $var->getVarName(); - if (!is_null($this->_vars->get('formname')) && - $this->_vars->get($varname) != $this->_vars->get('__old_' . $varname)) { + if (!is_null($this->_vars->get('formname')) + && $this->_vars->get($varname) != $this->_vars->get('__old_' . $varname)) { $this->_submitted = false; } } diff --git a/lib/Horde/Core/Form/Renderer.php b/lib/Horde/Core/Form/Renderer.php index ace3c0c..9e7b789 100644 --- a/lib/Horde/Core/Form/Renderer.php +++ b/lib/Horde/Core/Form/Renderer.php @@ -1,4 +1,5 @@ - * Copyright 2005-2007 Matt Warden + * Copyright 2001-2026 Robert E. Coyle + * Copyright 2005-2026 Matt Warden * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.horde.org/licenses/lgpl21. @@ -19,16 +20,16 @@ */ abstract class Horde_Core_Form_Renderer { - var $_name; - var $_requiredLegend = false; - var $_helpMarker = '?'; - var $_onLoadJS = array(); - var $_showHeader = true; - var $_cols = 2; - var $_firstField = null; - var $_stripedRows = true; + public $_name; + public $_requiredLegend = false; + public $_helpMarker = '?'; + public $_onLoadJS = []; + public $_showHeader = true; + public $_cols = 2; + public $_firstField = null; + public $_stripedRows = true; - protected $_submit = array(); + protected $_submit = []; protected $_reset = false; /** @@ -38,7 +39,7 @@ abstract class Horde_Core_Form_Renderer * * @var boolean */ - var $_encodeTitle = true; + public $_encodeTitle = true; /** * Construct a new Horde_Form_Renderer::. @@ -47,7 +48,7 @@ abstract class Horde_Core_Form_Renderer * Possible keys: * - 'encode_title': @see $_encodeTitle */ - function __construct($params = array()) + public function __construct($params = []) { if (isset($params['encode_title'])) { $this->encodeTitle($params['encode_title']); @@ -60,10 +61,10 @@ public function setButtons($submit, $reset = false) { if ($submit === true || is_null($submit) || empty($submit)) { /* Default to 'Submit'. */ - $submit = array(Horde_Model_Translation::t("Submit")); + $submit = [Horde_Model_Translation::t("Submit")]; } elseif (!is_array($submit)) { /* Default to array if not passed. */ - $submit = array($submit); + $submit = [$submit]; } /* Only if $reset is strictly true insert default 'Reset'. */ if ($reset === true) { @@ -79,7 +80,7 @@ public function setButtons($submit, $reset = false) public function addButtons($buttons) { if (!is_array($buttons)) { - $buttons = array($buttons); + $buttons = [$buttons]; } $this->_submit = array_merge($this->_submit, $buttons); @@ -100,7 +101,7 @@ public function showHeader($bool) * * @return boolean Whether the form title should be encoded. */ - function encodeTitle($encode = null) + public function encodeTitle($encode = null) { if (!is_null($encode)) { $this->_encodeTitle = $encode; diff --git a/lib/Horde/Core/Form/Renderer/Html.php b/lib/Horde/Core/Form/Renderer/Html.php index c694eae..9d44174 100644 --- a/lib/Horde/Core/Form/Renderer/Html.php +++ b/lib/Horde/Core/Form/Renderer/Html.php @@ -1,4 +1,7 @@ getInstance('Horde_PageOutput')->addScriptFile('form_sections.js', 'horde'); - echo ''; + echo ''; /* Loop through the sections and print out a tab for each. */ echo "
\n"; - $js = array(); + $js = []; foreach ($form->_sections as $section => $val) { $class = ($section == $open_section) ? ' class="horde-active"' : ''; $tabid = htmlspecialchars($form->getName() . '_tab_' . $section); - $js[$linkid] = sprintf('sections_%s.toggle(\'%s\'); return false;"', - $form->getName(), - $section); - printf('%s%s
' . "\n", - $class, - $tabid, - '_tablink_' . $section, - $form->getSectionImage($section), - $form->getSectionDesc($section)); + $js[$linkid] = sprintf( + 'sections_%s.toggle(\'%s\'); return false;"', + $form->getName(), + $section + ); + printf( + '%s%s' . "\n", + $class, + $tabid, + '_tablink_' . $section, + $form->getSectionImage($section), + $form->getSectionDesc($section) + ); } echo "\n"; @@ -76,10 +85,12 @@ protected function _renderSectionBegin($form, $section) // include a general class name for styling purposes. also helps select // ULs, which only get a className currently if they are striped. - printf('
', - htmlspecialchars($form->getName() . '_section_' . $section), - ($open_section == $section ? 'form-sectionshown' : 'form-sectionhidden'), - $class); + printf( + '
', + htmlspecialchars($form->getName() . '_section_' . $section), + ($open_section == $section ? 'form-sectionshown' : 'form-sectionhidden'), + $class + ); } protected function _renderSectionEnd() @@ -100,7 +111,7 @@ public function preserveVarByPost($vars, $varname, $alt_varname = '') } } - function _preserveVarByPost($varname, $value) + public function _preserveVarByPost($varname, $value) { if (is_array($value)) { foreach ($value as $id => $val) { @@ -109,16 +120,18 @@ function _preserveVarByPost($varname, $value) } else { $varname = htmlspecialchars($varname); $value = htmlspecialchars($value); - printf(''."\n", - $varname, - $value); + printf( + '' . "\n", + $varname, + $value + ); } } - function listFormVars($form) + public function listFormVars($form) { $variables = $form->getVariables(true, true); - $vars = array(); + $vars = []; if ($variables) { foreach ($variables as $var) { if (is_object($var)) { @@ -140,10 +153,10 @@ public function renderActive($form, $action, $method = 'get', $enctype = null, $ $this->_name = $form->getName(); echo "
_name) ? '' : ' id="' . $this->_name. '"') + . (empty($this->_name) ? '' : ' id="' . $this->_name . '"') . (is_null($this->_enctype) ? '' : ' enctype="' . $this->_enctype . '"') . ">\n"; - echo Horde_Util::formInput(); + echo Util::formInput(); $this->listFormVars($form); @@ -181,21 +194,21 @@ public function renderActive($form, $action, $method = 'get', $enctype = null, $ if ($focus && !empty($this->_firstField)) { echo ' '; } } - function renderInactive($form) + public function renderInactive($form) { $this->_name = $form->getName(); $this->_renderBeginInactive($form->getTitle()); $this->_renderForm($form, false); } - function _renderForm($form, $active) + public function _renderForm($form, $active) { $vars = $form->getVars(); @@ -206,7 +219,7 @@ function _renderForm($form, $active) /* Check for a form token error. */ if (($tokenError = $form->getError('_formToken')) !== null) { - printf('

%s

'."\n", $tokenError); + printf('

%s

' . "\n", $tokenError); } $error_section = null; @@ -219,43 +232,43 @@ function _renderForm($form, $active) $this->_renderSectionBegin($form, $section_id); foreach ($section as $var) { switch (get_class($var->type)) { - case 'Horde_Form_Type_Header': - $this->_renderHeader($var->getHumanName(), $form->getError($var->getVarName())); - break; - - case 'Horde_Form_Type_Description': - $this->_renderDescription($var->getHumanName()); - break; - - case 'Horde_Form_Type_Spacer': - $this->_renderSpacer(); - break; - - default: - $isInput = ($active && !$var->isReadonly()); - $format = $isInput ? 'Input' : 'Display'; - $begin = "_renderVar${format}Begin"; - $end = "_renderVar${format}End"; - - $this->$begin($form, $var); - echo $this->_varRender($form, $var, $vars, $isInput); - $this->$end($form, $var); - - /* Print any javascript if actions present. */ - if ($var->hasAction()) { - $var->_action->printJavaScript(); - } - - /* Keep first field. */ - if ($active && empty($this->_firstField) && !$var->isReadonly() - && !$var->isHidden()) { - $this->_firstField = $var->getVarName(); - } - - /* Keep section with first error. */ - if (is_null($error_section) && $form->getError($var)) { - $error_section = $section_id; - } + case 'Horde_Form_Type_Header': + $this->_renderHeader($var->getHumanName(), $form->getError($var->getVarName())); + break; + + case 'Horde_Form_Type_Description': + $this->_renderDescription($var->getHumanName()); + break; + + case 'Horde_Form_Type_Spacer': + $this->_renderSpacer(); + break; + + default: + $isInput = ($active && !$var->isReadonly()); + $format = $isInput ? 'Input' : 'Display'; + $begin = "_renderVar{$format}Begin"; + $end = "_renderVar{$format}End"; + + $this->$begin($form, $var); + echo $this->_varRender($form, $var, $vars, $isInput); + $this->$end($form, $var); + + /* Print any javascript if actions present. */ + if ($var->hasAction()) { + $var->_action->printJavaScript(); + } + + /* Keep first field. */ + if ($active && empty($this->_firstField) && !$var->isReadonly() + && !$var->isHidden()) { + $this->_firstField = $var->getVarName(); + } + + /* Keep section with first error. */ + if (is_null($error_section) && $form->getError($var)) { + $error_section = $section_id; + } } } @@ -263,17 +276,19 @@ function _renderForm($form, $active) } if (!is_null($error_section)) { - echo '\n"; + echo '\n"; } echo '
' . $this->_varRenderEnd(); } - function submit($submit = null, $reset = false) + public function submit($submit = null, $reset = false) { if (is_null($submit) || empty($submit)) { $submit = Horde_Model_Translation::t("Submit"); @@ -287,22 +302,22 @@ function submit($submit = null, $reset = false) /** * Implementation specific begin function. */ - function _renderBeginActive($name) + public function _renderBeginActive($name) { - echo '
'."\n"; + echo '
' . "\n"; if ($this->_showHeader) { $this->_renderSectionHeader($name); } if ($this->_requiredLegend) { echo '
' . $this->_requiredMarker - . ' = ' . Horde_Model_Translation::t("Required Field") . '
'."\n"; + . ' = ' . Horde_Model_Translation::t("Required Field") . '' . "\n"; } } /** * Implementation specific begin function. */ - function _renderBeginInactive($name) + public function _renderBeginInactive($name) { echo '
'; if ($this->_showHeader) { @@ -310,41 +325,43 @@ function _renderBeginInactive($name) } } - function _renderHeader($header, $error = '') + public function _renderHeader($header, $error = '') { - echo '
'. $header . '
'; + echo '
' . $header . '
'; if (!empty($error)) { - echo '
'. $error . '
'; + echo '
' . $error . '
'; } } - function _renderDescription($description) + public function _renderDescription($description) { - echo '
'. $description . '
'; + echo '
' . $description . '
'; } - function _renderSpacer() + public function _renderSpacer() { // TODO: fix this later so we're not inserting nonsemantic elements just for spacing // ... maybe append form-spacer to class of next or previous element echo '
 
'; } - function _renderSubmit($submit, $reset) + public function _renderSubmit($submit, $reset) { - echo '
'."\n"; - if (!is_array($submit)) $submit = array($submit); + echo '
' . "\n"; + if (!is_array($submit)) { + $submit = [$submit]; + } foreach ($submit as $submitbutton) { echo ''."\n"; + echo ' />' . "\n"; } if (!empty($reset)) { echo ''."\n"; + value="' . $reset . '" />' . "\n"; } } @@ -356,7 +373,7 @@ function _renderSubmit($submit, $reset) * @author Matt Warden * @author Robert E. Coyle */ - function _renderVarInputBegin($form, $var, $readonly = false) + public function _renderVarInputBegin($form, $var, $readonly = false) { // get error message for variable, if any $message = $form->getError($var); @@ -373,9 +390,11 @@ function _renderVarInputBegin($form, $var, $readonly = false) echo '

', $message, '

', "\n"; } - printf('%s', - ($readonly ? '' : ' for="'. $var->getVarName() .'"'), - $var->getHumanName()); + printf( + '%s', + ($readonly ? '' : ' for="' . $var->getVarName() . '"'), + $var->getHumanName() + ); } /** @@ -386,7 +405,7 @@ function _renderVarInputBegin($form, $var, $readonly = false) * @author Matt Warden * @author Robert E. Coyle */ - function _renderVarInputEnd($form, $var) + public function _renderVarInputEnd($form, $var) { /* Display any help for the field. */ if ($var->hasHelp()) { @@ -416,7 +435,7 @@ function _renderVarInputEnd($form, $var) * @author Matt Warden * @author Robert E. Coyle */ - function _renderVarDisplayBegin($form, $var) + public function _renderVarDisplayBegin($form, $var) { return $this->_renderVarInputBegin($form, $var, true); } @@ -429,7 +448,7 @@ function _renderVarDisplayBegin($form, $var) * @author Matt Warden * @author Robert E. Coyle */ - function _renderVarDisplayEnd() + public function _renderVarDisplayEnd() { echo ''; } @@ -442,12 +461,12 @@ function _renderVarDisplayEnd() * @author Robert E. Coyle * @param string $title section header title */ - function _renderSectionHeader($title) + public function _renderSectionHeader($title) { if (!empty($title)) { - echo "\n".''; + echo "\n" . ''; echo $this->_encodeTitle ? htmlspecialchars($title) : $title; - echo ''."\n"; + echo '' . "\n"; } } } diff --git a/lib/Horde/Core/Form/Type.php b/lib/Horde/Core/Form/Type.php index dc0c38a..5e65b8f 100644 --- a/lib/Horde/Core/Form/Type.php +++ b/lib/Horde/Core/Form/Type.php @@ -1,4 +1,5 @@ _properties = array(); + $this->_properties = []; $vars = array_keys(get_object_vars($this)); foreach ($vars as $var) { $this->_properties[] = substr($var, 1); @@ -36,16 +37,14 @@ abstract public function isValid($var, $vars, $value, $message); /** */ - function getInfo($vars, $var, $info) + public function getInfo($vars, $var, $info) { $info = $var->getValue($vars); } /** */ - public function onSubmit() - { - } + public function onSubmit() {} /** * To get the 'escape' property of a type: diff --git a/lib/Horde/Core/Form/Type/Boolean.php b/lib/Horde/Core/Form/Type/Boolean.php index 1c1cbf3..5cc03a8 100644 --- a/lib/Horde/Core/Form/Type/Boolean.php +++ b/lib/Horde/Core/Form/Type/Boolean.php @@ -1,4 +1,5 @@ = 1) && - ($ccnum[1] <= 5)) { + if (($l == 16) + && ($ccnum[0] == 5) + && ($ccnum[1] >= 1) + && ($ccnum[1] <= 5)) { return 'mastercard'; } // Check for Amex. - if (($l == 15) && - ($ccnum[0] == 3) && - (($ccnum[1] == 4) || ($ccnum[1] == 7))) { + if (($l == 15) + && ($ccnum[0] == 3) + && (($ccnum[1] == 4) || ($ccnum[1] == 7))) { return 'amex'; } // Check for Discover (Novus). - if (strlen($ccnum) == 16 && - substr($ccnum, 0, 4) == '6011') { + if (strlen($ccnum) == 16 + && substr($ccnum, 0, 4) == '6011') { return 'discover'; } diff --git a/lib/Horde/Core/Form/Type/Date.php b/lib/Horde/Core/Form/Type/Date.php index 8ad50cb..e6e139e 100644 --- a/lib/Horde/Core/Form/Type/Date.php +++ b/lib/Horde/Core/Form/Type/Date.php @@ -1,4 +1,5 @@ _format; } if (!empty($timestamp)) { - return \Horde\Date\Format::formatDate($timestamp, $format, $GLOBALS['language'] ?? 'en_US') . ($showago ? self::getAgo($timestamp) : ''); + return Horde\Date\Format::formatDate($timestamp, $format, $GLOBALS['language'] ?? 'en_US') . ($showago ? self::getAgo($timestamp) : ''); } else { return ''; } diff --git a/lib/Horde/Core/Form/Type/DateTime.php b/lib/Horde/Core/Form/Type/DateTime.php index a4e777f..ecfdacd 100644 --- a/lib/Horde/Core/Form/Type/DateTime.php +++ b/lib/Horde/Core/Form/Type/DateTime.php @@ -1,11 +1,12 @@ _date = new Horde_Form_Type_Date(); $this->_date->init($start_year, $end_year, $picker, $format_in, $format_out); @@ -30,16 +36,16 @@ function init($start_year = '', $end_year = '', $picker = true, $this->_time->init($show_seconds); } - function isValid($var, $vars, $value, $message) + public function isValid($var, $vars, $value, $message) { if ($var->required) { - return $this->_date->isValid($var, $vars, $value, $message) && - $this->_time->isValid($var, $vars, $value, $message); + return $this->_date->isValid($var, $vars, $value, $message) + && $this->_time->isValid($var, $vars, $value, $message); } return true; } - function getInfo($vars, $var, $info) + public function getInfo($vars, $var, $info) { /* If any component is empty consider it a bad date and return the * default. */ @@ -57,11 +63,11 @@ function getInfo($vars, $var, $info) if (is_null($this->format_in)) { $info = $date->timestamp(); } else { - $info = $date->format($this->format_in, new \Horde\Date\Formatter\IcuFormatter(), $GLOBALS['language'] ?? 'en_US'); + $info = $date->format($this->format_in, new Horde\Date\Formatter\IcuFormatter(), $GLOBALS['language'] ?? 'en_US'); } } - function __get($property) + public function __get($property) { if ($property == 'show_seconds') { return $this->_time->$property; @@ -70,7 +76,7 @@ function __get($property) } } - function __set($property, $value) + public function __set($property, $value) { if ($property == 'show_seconds') { $this->_time->$property = $value; @@ -79,42 +85,42 @@ function __set($property, $value) } } - function checktime($hour, $minute, $second) + public function checktime($hour, $minute, $second) { return $this->_time->checktime($hour, $minute, $second); } - function getTimeOb($time_in) + public function getTimeOb($time_in) { return $this->_time->getTimeOb($time_in); } - function getTimeParts($time_in) + public function getTimeParts($time_in) { return $this->_time->getTimeParts($time_in); } - function emptyTimeArray($time) + public function emptyTimeArray($time) { return $this->_time->emptyTimeArray($time); } - function emptyDateArray($date) + public function emptyDateArray($date) { return $this->_date->emptyDateArray($date); } - function getDateParts($date_in) + public function getDateParts($date_in) { return $this->_date->getDateParts($date_in); } - function getDateOb($date_in) + public function getDateOb($date_in) { return $this->_date->getDateOb($date_in); } - function formatDate($date) + public function formatDate($date) { if ($date === null) { return ''; diff --git a/lib/Horde/Core/Form/Type/Email.php b/lib/Horde/Core/Form/Type/Email.php index 8508920..6785eb8 100644 --- a/lib/Horde/Core/Form/Type/Email.php +++ b/lib/Horde/Core/Form/Type/Email.php @@ -1,4 +1,5 @@ _allow_multi = $allow_multi; $this->_strip_domain = $strip_domain; $this->_link_compose = $link_compose; @@ -114,15 +118,15 @@ public function isValid($var, $vars, $value, $message) */ public function splitEmailAddresses($string) { - $quotes = array('"', "'"); - $emails = array(); + $quotes = ['"', "'"]; + $emails = []; $pos = 0; $in_quote = null; $in_group = false; $prev = null; if (!strlen($string)) { - return array(); + return []; } $char = $string[0]; @@ -153,9 +157,9 @@ public function splitEmailAddresses($string) } } elseif ($char == ':') { $in_group = true; - } elseif (strpos($this->_delimiters, $char) !== false && - $prev !== '\\' && - is_null($in_quote)) { + } elseif (strpos($this->_delimiters, $char) !== false + && $prev !== '\\' + && is_null($in_quote)) { $emails[] = substr($string, $pos, $i - $pos); $pos = $i + 1; } @@ -198,14 +202,14 @@ public function validateEmailAddress($email) // any more). while (true) { $new = preg_replace("!$comment_regexp!", '', $email); - if (strlen($new) == strlen($email)){ + if (strlen($new) == strlen($email)) { break; } $email = $new; } // Now match what's left. - $result = (bool)preg_match("!^$email_regexp$!", $email); + $result = (bool) preg_match("!^$email_regexp$!", $email); if ($result && $this->_check_smtp) { $result = $this->validateEmailAddressSmtp($email); } @@ -222,11 +226,11 @@ public function validateEmailAddress($email) */ public function validateEmailAddressSmtp($email) { - list(, $maildomain) = explode('@', $email, 2); + [, $maildomain] = explode('@', $email, 2); // Try to get the real mailserver from MX records. - if (function_exists('getmxrr') && - @getmxrr($maildomain, $mxhosts, $mxpriorities)) { + if (function_exists('getmxrr') + && @getmxrr($maildomain, $mxhosts, $mxpriorities)) { // MX record found. array_multisort($mxpriorities, $mxhosts); $mailhost = $mxhosts[0]; diff --git a/lib/Horde/Core/Form/Type/EmailConfirm.php b/lib/Horde/Core/Form/Type/EmailConfirm.php index 6c8b854..0a9f702 100644 --- a/lib/Horde/Core/Form/Type/EmailConfirm.php +++ b/lib/Horde/Core/Form/Type/EmailConfirm.php @@ -1,4 +1,5 @@ parseAddressList($value['original']); switch (count($addr_ob)) { - case 0: - $message = Horde_Model_Translation::t("You did not enter a valid email address."); - return false; + case 0: + $message = Horde_Model_Translation::t("You did not enter a valid email address."); + return false; - case 1: - break; + case 1: + break; - default: - $message = Horde_Model_Translation::t("Only one email address allowed."); - return false; + default: + $message = Horde_Model_Translation::t("Only one email address allowed."); + return false; } return true; diff --git a/lib/Horde/Core/Form/Type/Enum.php b/lib/Horde/Core/Form/Type/Enum.php index 2dc2cd9..3f33d24 100644 --- a/lib/Horde/Core/Form/Type/Enum.php +++ b/lib/Horde/Core/Form/Type/Enum.php @@ -1,4 +1,5 @@ _values) == 0 || isset($this->_values[$value]) || - ($this->_prompt && empty($value))) { + if (count($this->_values) == 0 || isset($this->_values[$value]) + || ($this->_prompt && empty($value))) { return true; } diff --git a/lib/Horde/Core/Form/Type/Int.php b/lib/Horde/Core/Form/Type/Int.php index 729bd37..e8a67be 100644 --- a/lib/Horde/Core/Form/Type/Int.php +++ b/lib/Horde/Core/Form/Type/Int.php @@ -1,4 +1,5 @@ required && empty($value) && ((string)(int)$value !== $value)) { + if ($var->required && empty($value) && ((string) (int) $value !== $value)) { $message = Horde_Model_Translation::t("This field is required."); return false; } diff --git a/lib/Horde/Core/Form/Type/Invalid.php b/lib/Horde/Core/Form/Type/Invalid.php index 2e7058f..cb46d7f 100644 --- a/lib/Horde/Core/Form/Type/Invalid.php +++ b/lib/Horde/Core/Form/Type/Invalid.php @@ -1,14 +1,15 @@ message = $message; } - function isValid($var, $vars, $value, $message) + public function isValid($var, $vars, $value, $message) { return false; } diff --git a/lib/Horde/Core/Form/Type/KeyvalMultiEnum.php b/lib/Horde/Core/Form/Type/KeyvalMultiEnum.php index 4a4e1e5..100bf00 100644 --- a/lib/Horde/Core/Form/Type/KeyvalMultiEnum.php +++ b/lib/Horde/Core/Form/Type/KeyvalMultiEnum.php @@ -1,10 +1,11 @@ get($var->name); - $info = array(); + $info = []; foreach ($value as $key) { $info[$key] = $this->_values[$key]; } diff --git a/lib/Horde/Core/Form/Type/MultiEnum.php b/lib/Horde/Core/Form/Type/MultiEnum.php index f56bfef..496156b 100644 --- a/lib/Horde/Core/Form/Type/MultiEnum.php +++ b/lib/Horde/Core/Form/Type/MultiEnum.php @@ -1,4 +1,5 @@ required) { $message = Horde_Model_Translation::t("This field is required."); return false; diff --git a/lib/Horde/Core/Form/Type/Number.php b/lib/Horde/Core/Form/Type/Number.php index 656bc73..8cd40e9 100644 --- a/lib/Horde/Core/Form/Type/Number.php +++ b/lib/Horde/Core/Form/Type/Number.php @@ -1,16 +1,17 @@ required && empty($value) && ((string)(double)$value !== $value)) { + if ($var->required && empty($value) && ((string) (float) $value !== $value)) { $message = Horde_Model_Translation::t("This field is required."); return false; } elseif (empty($value)) { @@ -31,7 +32,7 @@ public function isValid($var, $vars, $value, $message) public function getInfo($vars, $var, $info) { $value = $vars->get($var->name); - $linfo = Horde_Nls::getLocaleInfo(); + $linfo = (new Horde\Nls\Nls())->getLocaleInfo(); $value = str_replace($linfo['mon_thousands_sep'], '', $value); $info = str_replace($linfo['mon_decimal_point'], '.', $value); } @@ -46,7 +47,7 @@ protected function _getValidationPattern() } /* Get current locale information. */ - $linfo = Horde_Nls::getLocaleInfo(); + $linfo = (new Horde\Nls\Nls())->getLocaleInfo(); /* Build the pattern. */ $pattern = '(-)?'; diff --git a/lib/Horde/Core/Form/Type/Octal.php b/lib/Horde/Core/Form/Type/Octal.php index 1950cf7..70834e1 100644 --- a/lib/Horde/Core/Form/Type/Octal.php +++ b/lib/Horde/Core/Form/Type/Octal.php @@ -1,4 +1,5 @@ required && empty($value) && ((string)(int)$value !== $value)) { + if ($var->required && empty($value) && ((string) (int) $value !== $value)) { $message = Horde_Model_Translation::t("This field is required."); return false; } diff --git a/lib/Horde/Core/Form/Type/Password.php b/lib/Horde/Core/Form/Type/Password.php index 63a38c3..6eb2120 100644 --- a/lib/Horde/Core/Form/Type/Password.php +++ b/lib/Horde/Core/Form/Type/Password.php @@ -1,4 +1,5 @@ required && empty($value) && ((string)(double)$value !== $value)) { + if ($var->required && empty($value) && ((string) (float) $value !== $value)) { $message = Horde_Model_Translation::t("This field is required."); return false; } diff --git a/lib/Horde/Core/Form/Variable.php b/lib/Horde/Core/Form/Variable.php index 78ce736..d55a65b 100644 --- a/lib/Horde/Core/Form/Variable.php +++ b/lib/Horde/Core/Form/Variable.php @@ -1,4 +1,5 @@ humanName = $humanName; $this->varName = $varName; $this->type = $type; @@ -142,7 +148,7 @@ function Horde_Core_Form_Variable($humanName, $varName, $type, $required, * * @param Horde_Core_Form $form The form instance to assign this variable to. */ - function setFormOb($form) + public function setFormOb($form) { $this->form = $form; } @@ -152,7 +158,7 @@ function setFormOb($form) * * @param mixed $value A variable value. */ - function setDefault($value) + public function setDefault($value) { $this->_defValue = $value; } @@ -162,7 +168,7 @@ function setDefault($value) * * @return mixed This variable's default value. */ - function getDefault() + public function getDefault() { return $this->_defValue; } @@ -179,7 +185,7 @@ function getDefault() * * @param Horde_Core_Form_Action $action A {@link Horde_Core_Form_Action} instance. */ - function setAction($action) + public function setAction($action) { $this->_action = $action; } @@ -189,7 +195,7 @@ function setAction($action) * * @return boolean True if this variable has an attached action. */ - function hasAction() + public function hasAction() { return !is_null($this->_action); } @@ -197,7 +203,7 @@ function hasAction() /** * Makes this a hidden variable. */ - function hide() + public function hide() { $this->_hidden = true; } @@ -207,7 +213,7 @@ function hide() * * @return boolean True if this a hidden variable. */ - function isHidden() + public function isHidden() { return $this->_hidden; } @@ -215,7 +221,7 @@ function isHidden() /** * Disables this variable. */ - function disable() + public function disable() { $this->_disabled = true; } @@ -225,7 +231,7 @@ function disable() * * @return boolean True if this variable is disabled. */ - function isDisabled() + public function isDisabled() { return $this->_disabled; } @@ -235,7 +241,7 @@ function isDisabled() * * @return string A short description */ - function getHumanName() + public function getHumanName() { return $this->humanName; } @@ -245,7 +251,7 @@ function getHumanName() * * @return string This variable's internal name. */ - function getVarName() + public function getVarName() { return $this->varName; } @@ -256,7 +262,7 @@ function getVarName() * @return Horde_Core_Form_Type This variable's {@link Horde_Core_Form_Type} * instance. */ - function getType() + public function getType() { return $this->type; } @@ -266,7 +272,7 @@ function getType() * * @return boolean True if this is a required variable. */ - function isRequired() + public function isRequired() { return $this->required; } @@ -276,7 +282,7 @@ function isRequired() * * @return boolean True if this a readonly variable. */ - function isReadonly() + public function isReadonly() { return $this->readonly; } @@ -286,7 +292,7 @@ function isReadonly() * * @return array The possible values of this variable or null. */ - function getValues() + public function getValues() { return $this->type->values; } @@ -296,7 +302,7 @@ function getValues() * * @return boolean True if this variable has a long description. */ - function hasDescription() + public function hasDescription() { return !empty($this->description); } @@ -306,7 +312,7 @@ function hasDescription() * * @return string This variable's long description. */ - function getDescription() + public function getDescription() { return $this->description; } @@ -316,7 +322,7 @@ function getDescription() * * @return boolean True if this an array variable. */ - function isArrayVal() + public function isArrayVal() { return $this->_arrayVal; } @@ -326,7 +332,7 @@ function isArrayVal() * * @return boolean True if variable is to upload a file. */ - function isUpload() + public function isUpload() { return ($this->type instanceof Horde_Core_Form_Type_File); } @@ -336,7 +342,7 @@ function isUpload() * * @param string $help The variable help text. */ - function setHelp($help) + public function setHelp($help) { $this->form->_help = true; $this->help = $help; @@ -347,7 +353,7 @@ function setHelp($help) * * @return boolean True if this variable has a help text. */ - function hasHelp() + public function hasHelp() { return !empty($this->help); } @@ -357,7 +363,7 @@ function hasHelp() * * @return string This variable's help text. */ - function getHelp() + public function getHelp() { return $this->help; } @@ -368,7 +374,7 @@ function getHelp() * @param string $option The option name. * @param mixed $val The option's value. */ - function setOption($option, $val) + public function setOption($option, $val) { $this->_options[$option] = $val; } @@ -380,9 +386,9 @@ function setOption($option, $val) * * @return mixed The option's value. */ - function getOption($option) + public function getOption($option) { - return isset($this->_options[$option]) ? $this->_options[$option] : null; + return $this->_options[$option] ?? null; } /** @@ -397,7 +403,7 @@ function getOption($option) * * @return mixed Depending on the variable type. */ - function getInfo($vars, $info) + public function getInfo($vars, $info) { return $this->type->getInfo($vars, $this, $info); } @@ -413,7 +419,7 @@ function getInfo($vars, $info) * option set or the form wasn't submitted yet. A boolean * indicating whether the variable was changed otherwise. */ - function wasChanged($vars) + public function wasChanged($vars) { if (!$this->getOption('trackchange')) { return null; @@ -436,7 +442,7 @@ function wasChanged($vars) * * @return boolean True if the variable validated. */ - function validate($vars, $message) + public function validate($vars, $message) { if ($this->_arrayVal) { $vals = $this->getValue($vars); @@ -478,7 +484,7 @@ function validate($vars, $message) * * @return mixed The variable or element value. */ - function getValue($vars, $index = null) + public function getValue($vars, $index = null) { if ($this->_arrayVal) { $name = str_replace('[]', '', $this->varName); @@ -495,7 +501,7 @@ function getValue($vars, $index = null) if (!$wasset && !is_array($value)) { $return = $value; } else { - $return = isset($value[$index]) ? $value[$index] : null; + $return = $value[$index] ?? null; } } else { $return = $value; diff --git a/lib/Horde/Core/Form/daterendererchanges.php b/lib/Horde/Core/Form/daterendererchanges.php index 2cff662..2ddcca0 100644 --- a/lib/Horde/Core/Form/daterendererchanges.php +++ b/lib/Horde/Core/Form/daterendererchanges.php @@ -1,8 +1,11 @@ Warning: Unknown variable type ' . - htmlspecialchars($var->getTypeName()); + return 'Warning: Unknown variable type ' + . htmlspecialchars($var->getTypeName()); } protected function _renderVarInput_number($form, $var, $vars) @@ -28,93 +31,101 @@ protected function _renderVarInput_number($form, $var, $vars) if ($var->type->getProperty('fraction')) { $value = sprintf('%01.' . $var->type->getProperty('fraction') . 'f', $value); } - $linfo = Horde_Nls::getLocaleInfo(); + $linfo = (new Horde\Nls\Nls())->getLocaleInfo(); /* Only if there is a mon_decimal_point do the * substitution. */ if (!empty($linfo['mon_decimal_point'])) { $value = str_replace('.', $linfo['mon_decimal_point'], $value); } - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - $value, - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + $value, + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_int($form, $var, $vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($var->getValue($vars)), - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($var->getValue($vars)), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_octal($form, $var, $vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - sprintf('0%o', octdec($var->getValue($vars))), - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + sprintf('0%o', octdec($var->getValue($vars))), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_intlist($form, $var, $vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($var->getValue($vars)), - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($var->getValue($vars)), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_text($form, $var, $vars) { $maxlength = $var->type->getMaxLength(); - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - $var->type->getSize(), - htmlspecialchars($var->getValue($vars)), - $var->isDisabled() ? ' disabled="disabled" ' : '', - empty($maxlength) ? '' : ' maxlength="' . $maxlength . '"', - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + $var->type->getSize(), + htmlspecialchars($var->getValue($vars)), + $var->isDisabled() ? ' disabled="disabled" ' : '', + empty($maxlength) ? '' : ' maxlength="' . $maxlength . '"', + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_stringlist($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($var->getValue($vars)), - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($var->getValue($vars)), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_stringarray($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars(implode(', ', $var->getValue($vars))), - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars(implode(', ', $var->getValue($vars))), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_phone($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($var->getValue($vars)), - $var->isDisabled() ? ' disabled="disabled" ' : '', - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($var->getValue($vars)), + $var->isDisabled() ? ' disabled="disabled" ' : '', + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_cellphone($form, &$var, &$vars) @@ -124,32 +135,36 @@ protected function _renderVarInput_cellphone($form, &$var, &$vars) protected function _renderVarInput_ipaddress($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($var->getValue($vars)), - $var->isDisabled() ? ' disabled="disabled" ' : '', - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($var->getValue($vars)), + $var->isDisabled() ? ' disabled="disabled" ' : '', + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_ip6address($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($var->getValue($vars)), - $var->isDisabled() ? ' disabled="disabled" ' : '', - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($var->getValue($vars)), + $var->isDisabled() ? ' disabled="disabled" ' : '', + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_file($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - $this->_getActionScripts($form, $var)); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + $this->_getActionScripts($form, $var) + ); } /** @@ -165,101 +180,157 @@ protected function _renderVarInput_image($form, &$var, &$vars) /* Check if there is existing img information stored. */ if (isset($image['img'])) { /* Hidden tag to store the preview image id. */ - $html = sprintf('', - htmlspecialchars($var->getVarName()) . '[hash]', - $this->_genID($var->getVarName() . '[hash]', false), - $var->type->getRandomId()); + $html = sprintf( + '', + htmlspecialchars($var->getVarName()) . '[hash]', + $this->_genID($var->getVarName() . '[hash]', false), + $var->type->getRandomId() + ); } /* Output MAX_FILE_SIZE parameter to limit large files. */ if ($var->type->getProperty('max_filesize')) { - $html .= sprintf('', - $var->type->getProperty('max_filesize')); + $html .= sprintf( + '', + $var->type->getProperty('max_filesize') + ); } /* Output the input tag. */ - $html .= sprintf('', - htmlspecialchars($var->getVarName()) . '[new]', - $this->_genID($var->getVarName() . '[new]', false)); + $html .= sprintf( + '', + htmlspecialchars($var->getVarName()) . '[new]', + $this->_genID($var->getVarName() . '[new]', false) + ); /* Output the button to upload/reset the image. */ if ($var->type->getProperty('show_upload')) { $html .= ' '; - $html .= sprintf(' ', - 'do_' . htmlspecialchars($var->getVarName()), - 'do_' . $this->_genID($var->getVarName(), false), - Horde_Core_Translation::t("Upload")); + $html .= sprintf( + ' ', + 'do_' . htmlspecialchars($var->getVarName()), + 'do_' . $this->_genID($var->getVarName(), false), + Horde_Core_Translation::t("Upload") + ); } if (!empty($image['img'])) { $html .= ' '; - $html .= sprintf(' ', - 'remove_' . htmlspecialchars($var->getVarName()), - 'remove_' . $this->_genID($var->getVarName(), false), - Horde_Core_Translation::t("Remove")); + $html .= sprintf( + ' ', + 'remove_' . htmlspecialchars($var->getVarName()), + 'remove_' . $this->_genID($var->getVarName(), false), + Horde_Core_Translation::t("Remove") + ); /* Image information stored, show preview, add buttons for image * manipulation. */ $html .= '
'; $img = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/images/view.php'); if (isset($image['img']['vfs_id'])) { /* Calling an image from VFS. */ - $img->add(array( + $img->add([ 'f' => $image['img']['vfs_id'], 'p' => $image['img']['vfs_path'], - 's' => 'vfs' - )); + 's' => 'vfs', + ]); } else { /* Calling an image from a tmp directory (uploads). */ $img->add('f', $image['img']['file']); } + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ /* Reset. */ $html .= Horde::link('#', Horde_Core_Translation::t("Reset"), '', '', 'showImage(\'' . $img . '\', \'_p_' . $varname . '\', true);') . Horde::img('image/refresh.png', Horde_Core_Translation::t("Reset")) . ''; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ /* Rotate 270. */ - $html .= Horde::link('#', Horde_Core_Translation::t("Rotate Left"), '', '', 'showImage(\'' . $img->copy()->add(array('a' => 'rotate', 'v' => '270')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('image/rotate-270.png', Horde_Core_Translation::t("Rotate Left")) . ''; + $html .= Horde::link('#', Horde_Core_Translation::t("Rotate Left"), '', '', 'showImage(\'' . $img->copy()->add(['a' => 'rotate', 'v' => '270']) . '\', \'_p_' . $varname . '\', true);') . Horde::img('image/rotate-270.png', Horde_Core_Translation::t("Rotate Left")) . ''; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ /* Rotate 180. */ - $html .= Horde::link('#', Horde_Core_Translation::t("Rotate 180"), '', '', 'showImage(\'' . $img->copy()->add(array('a' => 'rotate', 'v' => '180')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('image/rotate-180.png', Horde_Core_Translation::t("Rotate 180")) . ''; + $html .= Horde::link('#', Horde_Core_Translation::t("Rotate 180"), '', '', 'showImage(\'' . $img->copy()->add(['a' => 'rotate', 'v' => '180']) . '\', \'_p_' . $varname . '\', true);') . Horde::img('image/rotate-180.png', Horde_Core_Translation::t("Rotate 180")) . ''; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ /* Rotate 90. */ - $html .= Horde::link('#', Horde_Core_Translation::t("Rotate Right"), '', '', 'showImage(\'' . $img->copy()->add(array('a' => 'rotate', 'v' => '90')) . '\', \'_p_' . $varname . '\', true);') . Horde::img('image/rotate-90.png', Horde_Core_Translation::t("Rotate Right")) . ''; + $html .= Horde::link('#', Horde_Core_Translation::t("Rotate Right"), '', '', 'showImage(\'' . $img->copy()->add(['a' => 'rotate', 'v' => '90']) . '\', \'_p_' . $varname . '\', true);') . Horde::img('image/rotate-90.png', Horde_Core_Translation::t("Rotate Right")) . ''; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ /* Flip image. */ $html .= Horde::link('#', Horde_Core_Translation::t("Flip"), '', '', 'showImage(\'' . $img->copy()->add('a', 'flip') . '\', \'_p_' . $varname . '\', true);') . Horde::img('image/flip.png', Horde_Core_Translation::t("Flip")) . ''; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ /* Mirror image. */ $html .= Horde::link('#', Horde_Core_Translation::t("Mirror"), '', '', 'showImage(\'' . $img->copy()->add('a', 'mirror') . '\', \'_p_' . $varname . '\', true);') . Horde::img('image/mirror.png', Horde_Core_Translation::t("Mirror")) . ''; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ /* Apply grayscale. */ $html .= Horde::link('#', Horde_Core_Translation::t("Grayscale"), '', '', 'showImage(\'' . $img->copy()->add('a', 'grayscale') . '\', \'_p_' . $varname . '\', true);') . Horde::img('image/grayscale.png', Horde_Core_Translation::t("Grayscale")) . ''; /* Resize width. */ - $html .= sprintf('%s', - Horde_Core_Translation::t("w:"), - $img->copy()->add('a', 'resize'), - $varname, - $varname, - $this->_genID('_w_' . $varname)); + $html .= sprintf( + '%s', + Horde_Core_Translation::t("w:"), + $img->copy()->add('a', 'resize'), + $varname, + $varname, + $this->_genID('_w_' . $varname) + ); /* Resize height. */ - $html .= sprintf('%s', - Horde_Core_Translation::t("h:"), - $img->copy()->add('a', 'resize'), - $varname, - $varname, - $this->_genID('_h_' . $varname)); - + $html .= sprintf( + '%s', + Horde_Core_Translation::t("h:"), + $img->copy()->add('a', 'resize'), + $varname, + $varname, + $this->_genID('_h_' . $varname) + ); + + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ /* Apply fixed ratio resize. */ $html .= Horde::link('#', Horde_Core_Translation::t("Fix ratio"), '', '', 'src=getResizeSrc(\'' . $img->copy()->add('a', 'resize') . '\', \'' . $varname . '\', \'1\');showImage(src, \'_p_' . $varname . '\', true);') . Horde::img('ratio.png', Horde_Core_Translation::t("Fix ratio")) . ''; /* Keep also original if it has been requested. */ if ($var->type->getProperty('show_keeporig')) { - $html .= sprintf('%s' . "\n", - htmlspecialchars($var->getVarName()) . '[keep_orig]', - $varname . '[keep_orig]', - !empty($image['keep_orig']) ? ' checked="checked"' : '', - Horde_Core_Translation::t("Keep original?")); + $html .= sprintf( + '%s' . "\n", + htmlspecialchars($var->getVarName()) . '[keep_orig]', + $varname . '[keep_orig]', + !empty($image['keep_orig']) ? ' checked="checked"' : '', + Horde_Core_Translation::t("Keep original?") + ); } /* The preview image element. */ @@ -273,20 +344,23 @@ protected function _renderVarInput_longtext($form, &$var, &$vars) { global $browser; - $html = sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - (int)$var->type->getCols(), - (int)$var->type->getRows(), - $this->_getActionScripts($form, $var), - $var->isDisabled() ? ' disabled="disabled"' : '', - htmlspecialchars($var->getValue($vars))); + $html = sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + (int) $var->type->getCols(), + (int) $var->type->getRows(), + $this->_getActionScripts($form, $var), + $var->isDisabled() ? ' disabled="disabled"' : '', + htmlspecialchars($var->getValue($vars)) + ); if ($var->type->hasHelper('rte')) { $GLOBALS['injector']->getInstance('Horde_Editor')->initialize( - array('id' => $this->_genID($var->getVarName(), false), - 'relativelinks' => $var->type->hasHelper('relativelinks'), - 'config' => array('extraPlugins' => 'syntaxhighlight'))); + ['id' => $this->_genID($var->getVarName(), false), + 'relativelinks' => $var->type->hasHelper('relativelinks'), + 'config' => ['extraPlugins' => 'syntaxhighlight']] + ); } if ($var->type->hasHelper() && $browser->hasFeature('javascript')) { @@ -298,19 +372,24 @@ protected function _renderVarInput_longtext($form, &$var, &$vars) if ($var->type->hasHelper('emoticons')) { $filter = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->create('emoticons'); - $icon_list = array(); + $icon_list = []; foreach (array_flip($filter->getIcons()) as $icon => $string) { - $icon_list[] = array( + $icon_list[] = [ $filter->getIcon($icon), - $string - ); + $string, + ]; } - $page_output->addInlineJsVars(array( - 'Horde_Html_Helper.iconlist' => $icon_list - )); + $page_output->addInlineJsVars([ + 'Horde_Html_Helper.iconlist' => $icon_list, + ]); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= Horde::link('#', Horde_Core_Translation::t("Emoticons"), '', '', 'Horde_Html_Helper.open(\'emoticons\', \'' . $var->getVarName() . '\'); return false;') . Horde::img('emoticons/smile.png', Horde_Core_Translation::t("Emoticons"), 'id="' . $imgId . '"') . ''; } $html .= '
_genID('htmlhelper_' . $var->getVarName()) . ' class="control">
' . "\n"; @@ -321,26 +400,30 @@ protected function _renderVarInput_longtext($form, &$var, &$vars) protected function _renderVarInput_countedtext($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - (int)$var->type->getCols(), - (int)$var->type->getRows(), - $this->_getActionScripts($form, $var), - $var->isDisabled() ? ' disabled="disabled"' : '', - htmlspecialchars($var->getValue($vars))); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + (int) $var->type->getCols(), + (int) $var->type->getRows(), + $this->_getActionScripts($form, $var), + $var->isDisabled() ? ' disabled="disabled"' : '', + htmlspecialchars($var->getValue($vars)) + ); } protected function _renderVarInput_address($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - (int)$var->type->getCols(), - (int)$var->type->getRows(), - $this->_getActionScripts($form, $var), - $var->isDisabled() ? ' disabled="disabled"' : '', - htmlspecialchars($var->getValue($vars))); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + (int) $var->type->getCols(), + (int) $var->type->getRows(), + $this->_getActionScripts($form, $var), + $var->isDisabled() ? ' disabled="disabled"' : '', + htmlspecialchars($var->getValue($vars)) + ); } protected function _renderVarInput_addresslink($form, &$var, &$vars) @@ -365,20 +448,24 @@ protected function _renderVarInput_country($form, &$var, &$vars) protected function _renderVarInput_date($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($var->getValue($vars)), - $this->_getActionScripts($form, $var)); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($var->getValue($vars)), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_time($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($var->getValue($vars)), - $this->_getActionScripts($form, $var)); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($var->getValue($vars)), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_hourminutesecond($form, &$var, &$vars) @@ -386,27 +473,31 @@ protected function _renderVarInput_hourminutesecond($form, &$var, &$vars) $time = $var->type->getTimeParts($var->getValue($vars)); /* Output hours. */ - $hours = array('' => Horde_Core_Translation::t("hh")); + $hours = ['' => Horde_Core_Translation::t("hh")]; for ($i = 0; $i <= 23; $i++) { $hours[$i] = $i; } - $html = sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - $this->_getActionScripts($form, $var), - $this->selectOptions($hours, ($time['hour'] === '') ? '' : $time['hour'])); + $html = sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + $this->_getActionScripts($form, $var), + $this->selectOptions($hours, ($time['hour'] === '') ? '' : $time['hour']) + ); /* Output minutes. */ - $minutes = array('' => Horde_Core_Translation::t("mm")); + $minutes = ['' => Horde_Core_Translation::t("mm")]; for ($i = 0; $i <= 59; $i++) { $m = sprintf('%02d', $i); $minutes[$m] = $m; } - $html .= sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - $this->_getActionScripts($form, $var), - $this->selectOptions($minutes, ($time['minute'] === '') ? '' : sprintf('%02d', $time['minute']))); + $html .= sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + $this->_getActionScripts($form, $var), + $this->selectOptions($minutes, ($time['minute'] === '') ? '' : sprintf('%02d', $time['minute'])) + ); /* Return if seconds are not required. */ if (!$var->type->getProperty('show_seconds')) { @@ -414,35 +505,37 @@ protected function _renderVarInput_hourminutesecond($form, &$var, &$vars) } /* Output seconds. */ - $seconds = array('' => Horde_Core_Translation::t("ss")); + $seconds = ['' => Horde_Core_Translation::t("ss")]; for ($i = 0; $i <= 59; $i++) { $s = sprintf('%02d', $i); $seconds[$s] = $s; } - return $html . sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - $this->_getActionScripts($form, $var), - $this->selectOptions($seconds, ($time['second'] === '') ? '' : sprintf('%02d', $time['second']))); + return $html . sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + $this->_getActionScripts($form, $var), + $this->selectOptions($seconds, ($time['second'] === '') ? '' : sprintf('%02d', $time['second'])) + ); } protected function _renderVarInput_monthyear($form, &$var, &$vars) { - $dates = array(); - $dates['month'] = array('' => Horde_Core_Translation::t("MM"), - 1 => Horde_Core_Translation::t("January"), - 2 => Horde_Core_Translation::t("February"), - 3 => Horde_Core_Translation::t("March"), - 4 => Horde_Core_Translation::t("April"), - 5 => Horde_Core_Translation::t("May"), - 6 => Horde_Core_Translation::t("June"), - 7 => Horde_Core_Translation::t("July"), - 8 => Horde_Core_Translation::t("August"), - 9 => Horde_Core_Translation::t("September"), - 10 => Horde_Core_Translation::t("October"), - 11 => Horde_Core_Translation::t("November"), - 12 => Horde_Core_Translation::t("December")); - $dates['year'] = array('' => Horde_Core_Translation::t("YYYY")); + $dates = []; + $dates['month'] = ['' => Horde_Core_Translation::t("MM"), + 1 => Horde_Core_Translation::t("January"), + 2 => Horde_Core_Translation::t("February"), + 3 => Horde_Core_Translation::t("March"), + 4 => Horde_Core_Translation::t("April"), + 5 => Horde_Core_Translation::t("May"), + 6 => Horde_Core_Translation::t("June"), + 7 => Horde_Core_Translation::t("July"), + 8 => Horde_Core_Translation::t("August"), + 9 => Horde_Core_Translation::t("September"), + 10 => Horde_Core_Translation::t("October"), + 11 => Horde_Core_Translation::t("November"), + 12 => Horde_Core_Translation::t("December")]; + $dates['year'] = ['' => Horde_Core_Translation::t("YYYY")]; if ($var->type->getProperty('start_year') > $var->type->getProperty('end_year')) { for ($i = $var->type->getProperty('start_year'); $i >= $var->type->getProperty('end_year'); $i--) { $dates['year'][$i] = $i; @@ -452,16 +545,20 @@ protected function _renderVarInput_monthyear($form, &$var, &$vars) $dates['year'][$i] = $i; } } - return sprintf('', - $var->type->getMonthVar($var), - $var->type->getMonthVar($var), - $this->_getActionScripts($form, $var), - $this->selectOptions($dates['month'], $vars->get($var->type->getMonthVar($var)))) . - sprintf('', - $var->type->getYearVar($var), - $var->type->getYearVar($var), - $this->_getActionScripts($form, $var), - $this->selectOptions($dates['year'], $vars->get($var->type->getYearVar($var)))); + return sprintf( + '', + $var->type->getMonthVar($var), + $var->type->getMonthVar($var), + $this->_getActionScripts($form, $var), + $this->selectOptions($dates['month'], $vars->get($var->type->getMonthVar($var))) + ) + . sprintf( + '', + $var->type->getYearVar($var), + $var->type->getYearVar($var), + $this->_getActionScripts($form, $var), + $this->selectOptions($dates['year'], $vars->get($var->type->getYearVar($var))) + ); } protected function _renderVarInput_monthdayyear($form, &$var, &$vars) @@ -469,24 +566,31 @@ protected function _renderVarInput_monthdayyear($form, &$var, &$vars) $date = $var->type->getDateParts($var->getValue($vars)); var_dump($date); - $html = sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarNamee(), false), - $this->_getActionScripts($form, $var)); - - if ($var->type->getProperty('picker') && - $GLOBALS['browser']->hasFeature('javascript')) { - $js = "document.observe('Horde_Calendar:select', " . - "function(e) {" . - "var elt = e.element();" . - "elt.up().previous('SELECT[name$=\"[month]\"]').setValue(e.memo.getMonth() + 1);" . - "elt.up().previous('SELECT[name$=\"[day]\"]').setValue(e.memo.getDate());" . - "elt.up().previous('SELECT[name$=\"[year]\"]').setValue(e.memo.getFullYear());" . - "});\n"; + $html = sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarNamee(), false), + $this->_getActionScripts($form, $var) + ); + + if ($var->type->getProperty('picker') + && $GLOBALS['browser']->hasFeature('javascript')) { + $js = "document.observe('Horde_Calendar:select', " + . "function(e) {" + . "var elt = e.element();" + . "elt.up().previous('SELECT[name$=\"[month]\"]').setValue(e.memo.getMonth() + 1);" + . "elt.up().previous('SELECT[name$=\"[day]\"]').setValue(e.memo.getDate());" + . "elt.up().previous('SELECT[name$=\"[year]\"]').setValue(e.memo.getFullYear());" + . "});\n"; $GLOBALS['injector']->getInstance('Horde_PageOutput')->addInlineScript($js, true); Horde_Core_Ui_JsCalendar::init(); $imgId = $this->_genID($var->getVarName(), false) . 'goto'; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= Horde::link('#', Horde_Core_Translation::t("Select a date"), '', '', 'Horde_Calendar.open(\'' . $imgId . '\', null)') . Horde::img('calendar.png', Horde_Core_Translation::t("Calendar"), 'id="' . $imgId . '"') . "\n"; } @@ -495,8 +599,8 @@ protected function _renderVarInput_monthdayyear($form, &$var, &$vars) protected function _renderVarInput_datetime(&$form, &$var, &$vars) { - return $this->_renderVarInput_monthdayyear($form, $var, $vars) . - $this->_renderVarInput_hourminutesecond($form, $var, $vars); + return $this->_renderVarInput_monthdayyear($form, $var, $vars) + . $this->_renderVarInput_hourminutesecond($form, $var, $vars); } protected function _renderVarInput_sound(&$form, &$var, &$vars) @@ -509,7 +613,7 @@ protected function _renderVarInput_sound(&$form, &$var, &$vars) foreach ($var->type->getSounds() as $sound) { $sound = htmlspecialchars($sound); $html .= '
  • ' - . '
  • '; + . ' '; } return $html . ''; } @@ -533,10 +637,20 @@ protected function _renderVarInput_colorpicker($form, &$var, &$vars) . '" />'; if ($browser->hasFeature('javascript')) { $GLOBALS['injector']->getInstance('Horde_PageOutput')->addScriptFile('colorpicker.js', 'horde'); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= '' - . Horde::link('#', Horde_Core_Translation::t("Color Picker"), '', '', - 'new ColorPicker({ color: \'' . htmlspecialchars($color) . '\', offsetParent: Event.element(event), update: [[\'' . $varname . '\', \'value\'], [\'' . $varname . '\', \'background\']] }); return false;') - . Horde::img('colorpicker.png', Horde_Core_Translation::t("Color Picker"), 'height="16"') . ''; + . Horde::link( + '#', + Horde_Core_Translation::t("Color Picker"), + '', + '', + 'new ColorPicker({ color: \'' . htmlspecialchars($color) . '\', offsetParent: Event.element(event), update: [[\'' . $varname . '\', \'value\'], [\'' . $varname . '\', \'background\']] }); return false;' + ) + . Horde::img('colorpicker.png', Horde_Core_Translation::t("Color Picker"), 'height="16"') . ''; } return $html . ''; } @@ -549,19 +663,28 @@ protected function _renderVarInput_sorter($form, &$var, &$vars) $GLOBALS['injector']->getInstance('Horde_PageOutput')->addScriptFile('sorter.js', 'horde'); - return '_genID($var->getVarName() . '_array') . '/>' . - '
    ' . - Horde::link('#', Horde_Core_Translation::t("Move up"), '', '', $instance . '.moveColumnUp(); return false;') . Horde::img('nav/up.png', Horde_Core_Translation::t("Move up")) . '
    ' . - Horde::link('#', Horde_Core_Translation::t("Move up"), '', '', $instance . '.moveColumnDown(); return false;') . Horde::img('nav/down.png', Horde_Core_Translation::t("Move down")) . '
    ' . - '\n", $instance); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ + return '_genID($var->getVarName() . '_array') . '/>' + . '
    ' + . Horde::link('#', Horde_Core_Translation::t("Move up"), '', '', $instance . '.moveColumnUp(); return false;') . Horde::img('nav/up.png', Horde_Core_Translation::t("Move up")) . '
    ' + . Horde::link('#', Horde_Core_Translation::t("Move up"), '', '', $instance . '.moveColumnDown(); return false;') . Horde::img('nav/down.png', Horde_Core_Translation::t("Move down")) . '
    ' + . '\n", $instance); } protected function _renderVarInput_assign($form, &$var, &$vars) @@ -573,28 +696,41 @@ protected function _renderVarInput_assign($form, &$var, &$vars) $name = htmlspecialchars($var->getVarName()); $size = $var->type->getSize(); $width = $var->type->getWidth(); - $lhdr = (bool)$var->type->getHeader(0); - $rhdr = (bool)$var->type->getHeader(1); + $lhdr = (bool) $var->type->getHeader(0); + $rhdr = (bool) $var->type->getHeader(1); $this->_addOnLoadJavascript('Horde_Form_Assign.setField(\'' . $form->getName() . '\', \'' . $var->getVarName() . '\');'); - return '' . - '
    ' . - sprintf('' . - '' . - Horde::img('rhand.png', Horde_Core_Translation::t("Add")) . - '
    ' . - Horde::img('lhand.png', Horde_Core_Translation::t("Remove")) . - '
    ' . - sprintf('
    '; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ + return '' + . '
    ' + . sprintf( + '' + . '' + . Horde::img('rhand.png', Horde_Core_Translation::t("Add")) + . '
    ' + . Horde::img('lhand.png', Horde_Core_Translation::t("Remove")) + . '
    ' + . sprintf( + '
    '; } protected function _renderVarInput_invalid($form, &$var, &$vars) @@ -610,12 +746,14 @@ protected function _renderVarInput_enum($form, &$var, &$vars) if (!empty($prompt)) { $prompt = ''; } - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - $this->_getActionScripts($form, $var), - $prompt, - $this->selectOptions($values, $var->getValue($vars), $htmlchars)); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + $this->_getActionScripts($form, $var), + $prompt, + $this->selectOptions($values, $var->getValue($vars), $htmlchars) + ); } protected function _renderVarInput_mlenum($form, &$var, &$vars) @@ -629,25 +767,29 @@ protected function _renderVarInput_mlenum($form, &$var, &$vars) if (!is_array($selected)) { foreach ($values as $key_1 => $values_2) { if (isset($values_2[$selected])) { - $selected = array('1' => $key_1, '2' => $selected); + $selected = ['1' => $key_1, '2' => $selected]; break; } } } /* Hidden tag to store the current first level. */ - $html = sprintf('', - $hvarname, - htmlspecialchars($selected['1']), - $this->_genID($varname . '_old')); + $html = sprintf( + '', + $hvarname, + htmlspecialchars($selected['1']), + $this->_genID($varname . '_old') + ); /* First level. */ $values_1 = Horde_Array::valuesToKeys(array_keys($values)); - $html .= sprintf('', + $this->_genID($varname . '_1'), + $hvarname, + 'if (this.value) { document.' . $form->getName() . '.formname.value=\'\';' . 'document.' . $form->getName() . '.submit() }', + ($var->hasAction() ? ' ' . $this->_genActionScript($form, $var->_action, $varname) : '') + ); if (!empty($prompts)) { $html .= ''; } @@ -655,14 +797,16 @@ protected function _renderVarInput_mlenum($form, &$var, &$vars) $html .= ''; /* Second level. */ - $html .= sprintf('', + $this->_genID($varname . '_2'), + $hvarname, + ($var->hasAction() ? ' ' . $this->_genActionScript($form, $var->_action, $varname) : '') + ); if (!empty($prompts)) { $html .= ''; } - $values_2 = array(); + $values_2 = []; if (!empty($selected['1'])) { $values_2 = &$values[$selected['1']]; } @@ -676,12 +820,14 @@ protected function _renderVarInput_multienum($form, &$var, &$vars) if (!$wasset) { $selected = $var->getDefault(); } - return sprintf('', - (int)$var->type->size, - htmlspecialchars($var->getVarName()), - $this->_getActionScripts($form, $var), - $this->_multiSelectOptions($values, $selected)) . - "
    \n" . Horde_Core_Translation::t("To select multiple items, hold down the Control (PC) or Command (Mac) key while clicking.") . "\n"; + return sprintf( + '', + (int) $var->type->size, + htmlspecialchars($var->getVarName()), + $this->_getActionScripts($form, $var), + $this->_multiSelectOptions($values, $selected) + ) + . "
    \n" . Horde_Core_Translation::t("To select multiple items, hold down the Control (PC) or Command (Mac) key while clicking.") . "\n"; } protected function _renderVarInput_keyval_multienum($form, &$var, &$vars) @@ -691,47 +837,51 @@ protected function _renderVarInput_keyval_multienum($form, &$var, &$vars) protected function _renderVarInput_radio($form, &$var, &$vars) { - return $this->_radioButtons($var->getVarName(), - $var->getValues(), - $var->getValue($vars), - $this->_getActionScripts($form, $var)); + return $this->_radioButtons( + $var->getVarName(), + $var->getValues(), + $var->getValue($vars), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_set($form, &$var, &$vars) { - $html = $this->_checkBoxes($var->getVarName(), - $var->getValues(), - $var->getValue($vars), - $this->_getActionScripts($form, $var)); + $html = $this->_checkBoxes( + $var->getVarName(), + $var->getValues(), + $var->getValue($vars), + $this->_getActionScripts($form, $var) + ); if ($var->type->getProperty('checkAll')) { $form_name = $form->getName(); $var_name = $var->getVarName() . '[]'; - $function_name = 'select' . $form_name . $var->getVarName(); + $function_name = 'select' . $form_name . $var->getVarName(); $enable = Horde_Core_Translation::t("Select all"); $disable = Horde_Core_Translation::t("Select none"); $invert = Horde_Core_Translation::t("Invert selection"); $html .= << -function $function_name() -{ - for (var i = 0; i < document.$form_name.elements.length; i++) { - f = document.$form_name.elements[i]; - if (f.name != '$var_name') { - continue; - } - if (arguments.length) { - f.checked = arguments[0]; - } else { - f.checked = !f.checked; - } - } -} - -$enable, -$disable, -$invert -EOT; + + $enable, + $disable, + $invert + EOT; } return $html; @@ -749,11 +899,13 @@ protected function _renderVarInput_html($form, &$var, &$vars) protected function _renderVarInput_email($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($var->getValue($vars)), - $this->_getActionScripts($form, $var)); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($var->getValue($vars)), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_matrix($form, &$var, &$vars) @@ -777,16 +929,20 @@ protected function _renderVarInput_matrix($form, &$var, &$vars) if ($new_input) { $html .= ''; if (is_array($new_input)) { - $html .= sprintf('
    ', - $this->_genID($varname . '_n_r'), - htmlspecialchars($var->getVarName()), - Horde_Core_Translation::t("-- select --"), - $this->selectOptions($new_input, $var_array['n']['r'])); + $html .= sprintf( + '
    ', + $this->_genID($varname . '_n_r'), + htmlspecialchars($var->getVarName()), + Horde_Core_Translation::t("-- select --"), + $this->selectOptions($new_input, $var_array['n']['r']) + ); } elseif ($new_input == true) { - $html .= sprintf('', - $this->_genID($varname . '_n_r'), - htmlspecialchars($var->getVarName()), - $var_array['n']['r']); + $html .= sprintf( + '', + $this->_genID($varname . '_n_r'), + htmlspecialchars($var->getVarName()), + $var_array['n']['r'] + ); } $html .= ' '; foreach ($cols as $col_id => $col_title) { @@ -809,61 +965,77 @@ protected function _renderVarInput_matrix($form, &$var, &$vars) protected function _renderVarInput_password($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($var->getValue($vars)), - $this->_getActionScripts($form, $var)); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($var->getValue($vars)), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_emailconfirm($form, &$var, &$vars) { $email = $var->getValue($vars); - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($email['original']), - $this->_getActionScripts($form, $var)) . - ' ' . sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($email['confirm']), - $this->_getActionScripts($form, $var)); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($email['original']), + $this->_getActionScripts($form, $var) + ) + . ' ' . sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($email['confirm']), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_passwordconfirm($form, &$var, &$vars) { $password = $var->getValue($vars); - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($password['original']), - $this->_getActionScripts($form, $var)) . - ' ' . sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - htmlspecialchars($password['confirm']), - $this->_getActionScripts($form, $var)); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($password['original']), + $this->_getActionScripts($form, $var) + ) + . ' ' . sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + htmlspecialchars($password['confirm']), + $this->_getActionScripts($form, $var) + ); } protected function _renderVarInput_boolean($form, &$var, &$vars) { - $html = 'getValue($vars) ? ' checked="checked"' : ''); + $html = 'getValue($vars) ? ' checked="checked"' : ''); if ($var->hasAction()) { - $html .= $this->_genActionScript($form, $var->_action, - $var->getVarName()); + $html .= $this->_genActionScript( + $form, + $var->_action, + $var->getVarName() + ); } return $html . ' />'; } protected function _renderVarInput_creditcard($form, &$var, &$vars) { - $html = 'getVarName()) . '" id="' . $this->_genID($var->getVarName(), false) . '" value="' + . htmlspecialchars($var->getValue($vars)) . '"'; if ($var->hasAction()) { - $html .= $this->_genActionScript($form, $var->_action, - $var->getVarName()); + $html .= $this->_genActionScript( + $form, + $var->_action, + $var->getVarName() + ); } return $html . ' />'; } @@ -887,17 +1059,24 @@ function obrowserCallback(name, oid) } '; - $html .= sprintf('', - htmlspecialchars($varname), - $fieldId, - $this->_getActionScripts($form, $var), - htmlspecialchars($varvalue)); + $html .= sprintf( + '', + htmlspecialchars($varname), + $fieldId, + $this->_getActionScripts($form, $var), + htmlspecialchars($varvalue) + ); if (!empty($varvalue)) { $html .= $varvalue; } if ($GLOBALS['browser']->hasFeature('javascript')) { - $html .= Horde::link($GLOBALS['registry']->get('webroot', 'horde') . '/services/obrowser/', Horde_Core_Translation::t("Select an object"), '', '_blank', 'obrowserWindow = ' . Horde::popupJs($GLOBALS['registry']->get('webroot', 'horde') . '/services/obrowser/', array('urlencode' => true)) . 'obrowserWindowName = obrowserWindow.name; return false;') . Horde::img('tree/leaf.png', Horde_Core_Translation::t("Object")) . "\n"; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ + $html .= Horde::link($GLOBALS['registry']->get('webroot', 'horde') . '/services/obrowser/', Horde_Core_Translation::t("Select an object"), '', '_blank', 'obrowserWindow = ' . Horde::popupJs($GLOBALS['registry']->get('webroot', 'horde') . '/services/obrowser/', ['urlencode' => true]) . 'obrowserWindowName = obrowserWindow.name; return false;') . Horde::img('tree/leaf.png', Horde_Core_Translation::t("Object")) . "\n"; } return $html; @@ -910,24 +1089,28 @@ protected function _renderVarInput_dblookup($form, &$var, &$vars) protected function _renderVarInput_figlet($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - strlen($var->type->getText()), - htmlspecialchars($var->getValue($vars))) . - '
    ' . Horde_Core_Translation::t("Enter the letters below:") . '
    ' . - $this->_renderVarDisplay_figlet($form, $var, $vars); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + strlen($var->type->getText()), + htmlspecialchars($var->getValue($vars)) + ) + . '
    ' . Horde_Core_Translation::t("Enter the letters below:") . '
    ' + . $this->_renderVarDisplay_figlet($form, $var, $vars); } protected function _renderVarInput_captcha($form, &$var, &$vars) { - return sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - strlen($var->type->getText()), - htmlspecialchars($var->getValue($vars))) . - '
    ' . Horde_Core_Translation::t("Enter the letters below:") . '
    ' . - $this->_renderVarDisplay_captcha($form, $var, $vars); + return sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + strlen($var->type->getText()), + htmlspecialchars($var->getValue($vars)) + ) + . '
    ' . Horde_Core_Translation::t("Enter the letters below:") . '
    ' + . $this->_renderVarDisplay_captcha($form, $var, $vars); } protected function _renderVarDisplayDefault($form, &$var, &$vars) @@ -947,9 +1130,9 @@ protected function _renderVarDisplay_email($form, &$var, &$vars) $email_val = $var->getValue($vars); if ($var->type->getProperty('link_compose')) { - $addrs = $GLOBALS['injector']->getInstance('Horde_Mail_Rfc822')->parseAddressList($email_val, array( - 'limit' => $var->type->getProperty('allow_multi') ? 0 : 1 - )); + $addrs = $GLOBALS['injector']->getInstance('Horde_Mail_Rfc822')->parseAddressList($email_val, [ + 'limit' => $var->type->getProperty('allow_multi') ? 0 : 1, + ]); $link = ''; foreach ($addrs as $addr) { @@ -962,7 +1145,7 @@ protected function _renderVarDisplay_email($form, &$var, &$vars) $address = $addr->writeAddress(true); try { - $mail_link = $GLOBALS['registry']->call('mail/compose', array(array('to' => addslashes($address)))); + $mail_link = $GLOBALS['registry']->call('mail/compose', [['to' => addslashes($address)]]); } catch (Horde_Exception $e) { $mail_link = 'mailto:' . urlencode($address); } @@ -976,9 +1159,9 @@ protected function _renderVarDisplay_email($form, &$var, &$vars) return $link; } else { - $addrs = $GLOBALS['injector']->getInstance('Horde_Mail_Rfc822')->parseAddressList($email_val, array( - 'limit' => 1 - )); + $addrs = $GLOBALS['injector']->getInstance('Horde_Mail_Rfc822')->parseAddressList($email_val, [ + 'limit' => 1, + ]); $display_email = $var->type->getProperty('strip_domain') ? $addr->mailbox . ' (at) ' . str_replace('.', ' (dot) ', $addr->host) @@ -1036,7 +1219,7 @@ protected function _renderVarDisplay_multienum($form, &$var, &$vars) if (!count($values) || !count($on)) { return Horde_Core_Translation::t("No values"); } else { - $display = array(); + $display = []; foreach ($values as $value => $name) { if (in_array($value, $on)) { $display[] = $name; @@ -1053,7 +1236,7 @@ protected function _renderVarDisplay_set($form, &$var, &$vars) if (!count($values) || !count($on)) { return Horde_Core_Translation::t("No values"); } else { - $display = array(); + $display = []; foreach ($values as $value => $name) { if (in_array($value, $on)) { $display[] = $name; @@ -1078,17 +1261,22 @@ protected function _renderVarDisplay_image($form, &$var, &$vars) if (isset($image['img']['vfs_id'])) { /* Calling an image from VFS. */ - $img->add(array( + $img->add([ 'f' => $image['img']['vfs_id'], 'p' => $image['img']['vfs_path'], - 's' => 'vfs' - )); + 's' => 'vfs', + ]); } else { /* Calling an image from a tmp directory (uploads). */ $img->add('f', $image['img']['file']); } - return Horde::img((string)$img, '', '', ''); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ + return Horde::img((string) $img, '', '', ''); } protected function _renderVarDisplay_phone($form, &$var, &$vars) @@ -1099,8 +1287,13 @@ protected function _renderVarDisplay_phone($form, &$var, &$vars) $html = htmlspecialchars($number); if ($number && $registry->hasMethod('telephony/dial')) { - $url = $registry->call('telephony/dial', array($number)); + $url = $registry->call('telephony/dial', [$number]); $label = sprintf(Horde_Core_Translation::t("Dial %s"), $number); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= ' ' . Horde::link($url, $label) . Horde::img('phone.png', $label) . ''; } @@ -1115,7 +1308,12 @@ protected function _renderVarDisplay_cellphone($form, &$var, &$vars) $number = $var->getValue($vars); if ($number && $registry->hasMethod('sms/compose')) { - $url = $registry->link('sms/compose', array('to' => $number)); + $url = $registry->link('sms/compose', ['to' => $number]); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= ' ' . Horde::link($url, Horde_Core_Translation::t("Send SMS")) . Horde::img('mobile.png', Horde_Core_Translation::t("Send SMS")) . ''; } @@ -1136,115 +1334,130 @@ protected function _renderVarDisplay_address($form, &$var, &$vars, $text = true) $google_icon = 'map.png'; if (!empty($info['country'])) { switch ($info['country']) { - case 'uk': - /* Multimap.co.uk generated map */ - $mapurl = 'http://www.multimap.com/map/browse.cgi?pc=' - . urlencode($info['zip']); - $desc = Horde_Core_Translation::t("Multimap UK map"); - $icon = 'map.png'; - break; - - case 'au': - /* Whereis.com.au generated map */ - $mapurl = 'http://www.whereis.com.au/whereis/mapping/geocodeAddress.do?'; - $desc = Horde_Core_Translation::t("Whereis Australia map"); - $icon = 'map.png'; - /* See if it's the street number & name. */ - if (isset($info['streetNumber']) && - isset($info['streetName'])) { - $mapurl .= '&streetNumber=' - . urlencode($info['streetNumber']) . '&streetName=' - . urlencode($info['streetName']); - } - /* Look for "Suburb, State". */ - if (isset($info['city'])) { - $mapurl .= '&suburb=' . urlencode($info['city']); - } - /* Look for "State <4 digit postcode>". */ - if (isset($info['state'])) { - $mapurl .= '&state=' . urlencode($info['state']); - } - break; - - case 'us': - case 'ca': - /* American/Canadian address style. */ - /* Mapquest generated map */ - $mapurl = 'http://www.mapquest.com/maps/map.adp?size=big&zoom=7'; - $desc = Horde_Core_Translation::t("MapQuest map"); - $icon = 'map.png'; - if (!empty($info['street'])) { - $mapurl .= '&address=' . urlencode($info['street']); - } - if (!empty($info['city'])) { - $mapurl .= '&city=' . urlencode($info['city']); - } - if (!empty($info['state'])) { - $mapurl .= '&state=' . urlencode($info['state']); - } - if (!empty($info['zip'])) { - if ($info['country'] == 'ca') { - $mapurl .= '&country=CA'; + case 'uk': + /* Multimap.co.uk generated map */ + $mapurl = 'http://www.multimap.com/map/browse.cgi?pc=' + . urlencode($info['zip']); + $desc = Horde_Core_Translation::t("Multimap UK map"); + $icon = 'map.png'; + break; + + case 'au': + /* Whereis.com.au generated map */ + $mapurl = 'http://www.whereis.com.au/whereis/mapping/geocodeAddress.do?'; + $desc = Horde_Core_Translation::t("Whereis Australia map"); + $icon = 'map.png'; + /* See if it's the street number & name. */ + if (isset($info['streetNumber']) + && isset($info['streetName'])) { + $mapurl .= '&streetNumber=' + . urlencode($info['streetNumber']) . '&streetName=' + . urlencode($info['streetName']); } - $mapurl .= '&zipcode=' . urlencode($info['zip']); - } + /* Look for "Suburb, State". */ + if (isset($info['city'])) { + $mapurl .= '&suburb=' . urlencode($info['city']); + } + /* Look for "State <4 digit postcode>". */ + if (isset($info['state'])) { + $mapurl .= '&state=' . urlencode($info['state']); + } + break; - /* Yahoo! generated map. */ - $mapurl2 = 'http://us.rd.yahoo.com/maps/home/submit_a/*-http://maps.yahoo.com/maps?srchtype=a&getmap=Get+Map&'; - $desc2 = Horde_Core_Translation::t("Yahoo! map"); - $icon2 = 'map.png'; - if (!empty($info['street'])) { - $mapurl2 .= '&addr=' . urlencode($info['street']); - } - /* Give precedence to zipcode over city/state */ - if (empty($info['zip']) && - !empty($info['city']) && !empty($info['state'])) { - $mapurl2 .= '&csz=' - . urlencode($info['city'] . ' ' . $info['state']); - } - if (!empty($info['zip'])) { - if (preg_match('|([a-zA-Z]\d[a-zA-Z])\s?(\d[a-zA-Z]\d)|', $info['zip'], $pcParts)) { - $mapurl2 .= '&country=ca'; - /* make sure the postal-code has a space */ - $info['zip'] = $pcParts[1] . ' ' . $pcParts[2]; + case 'us': + case 'ca': + /* American/Canadian address style. */ + /* Mapquest generated map */ + $mapurl = 'http://www.mapquest.com/maps/map.adp?size=big&zoom=7'; + $desc = Horde_Core_Translation::t("MapQuest map"); + $icon = 'map.png'; + if (!empty($info['street'])) { + $mapurl .= '&address=' . urlencode($info['street']); } - $mapurl2 .= '&csz=' . urlencode($info['zip']); - } - break; + if (!empty($info['city'])) { + $mapurl .= '&city=' . urlencode($info['city']); + } + if (!empty($info['state'])) { + $mapurl .= '&state=' . urlencode($info['state']); + } + if (!empty($info['zip'])) { + if ($info['country'] == 'ca') { + $mapurl .= '&country=CA'; + } + $mapurl .= '&zipcode=' . urlencode($info['zip']); + } + + /* Yahoo! generated map. */ + $mapurl2 = 'http://us.rd.yahoo.com/maps/home/submit_a/*-http://maps.yahoo.com/maps?srchtype=a&getmap=Get+Map&'; + $desc2 = Horde_Core_Translation::t("Yahoo! map"); + $icon2 = 'map.png'; + if (!empty($info['street'])) { + $mapurl2 .= '&addr=' . urlencode($info['street']); + } + /* Give precedence to zipcode over city/state */ + if (empty($info['zip']) + && !empty($info['city']) && !empty($info['state'])) { + $mapurl2 .= '&csz=' + . urlencode($info['city'] . ' ' . $info['state']); + } + if (!empty($info['zip'])) { + if (preg_match('|([a-zA-Z]\d[a-zA-Z])\s?(\d[a-zA-Z]\d)|', $info['zip'], $pcParts)) { + $mapurl2 .= '&country=ca'; + /* make sure the postal-code has a space */ + $info['zip'] = $pcParts[1] . ' ' . $pcParts[2]; + } + $mapurl2 .= '&csz=' . urlencode($info['zip']); + } + break; - default: - if (!count($info)) { + default: + if (!count($info)) { + break; + } + /* European address style. */ + $google_icon = 'map_eu.png'; + /* Mapquest generated map. */ + $mapurl2 = 'http://www.mapquest.com/maps/map.adp?country=' . Horde_String::upper($info['country']); + $desc2 = Horde_Core_Translation::t("MapQuest map"); + $icon2 = 'map_eu.png'; + if (!empty($info['street'])) { + $mapurl2 .= '&address=' . urlencode($info['street']); + } + if (!empty($info['zip'])) { + $mapurl2 .= '&zipcode=' . urlencode($info['zip']); + } + if (!empty($info['city'])) { + $mapurl2 .= '&city=' . urlencode($info['city']); + } break; - } - /* European address style. */ - $google_icon = 'map_eu.png'; - /* Mapquest generated map. */ - $mapurl2 = 'http://www.mapquest.com/maps/map.adp?country=' . Horde_String::upper($info['country']); - $desc2 = Horde_Core_Translation::t("MapQuest map"); - $icon2 = 'map_eu.png'; - if (!empty($info['street'])) { - $mapurl2 .= '&address=' . urlencode($info['street']); - } - if (!empty($info['zip'])) { - $mapurl2 .= '&zipcode=' . urlencode($info['zip']); - } - if (!empty($info['city'])) { - $mapurl2 .= '&city=' . urlencode($info['city']); - } - break; } } $html = $text ? nl2br(htmlspecialchars($address)) : ''; if (!empty($mapurl)) { + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= '  ' . Horde::link(Horde::externalUrl($mapurl), $desc, null, '_blank') . Horde::img($icon, $desc) . ''; } if (!empty($mapurl2)) { + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= ' ' . Horde::link(Horde::externalUrl($mapurl2), $desc2, null, '_blank') . Horde::img($icon2, $desc2) . ''; } /* Google generated map. */ if ($address) { + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= ' ' . Horde::link(Horde::externalUrl('http://maps.google.com/maps?q=' . urlencode(preg_replace('/\r?\n/', ',', $address)) . '&hl=en'), Horde_Core_Translation::t("Google Maps"), null, '_blank') . Horde::img($google_icon, Horde_Core_Translation::t("Google Maps")) . ''; } @@ -1262,9 +1475,9 @@ protected function _renderVarDisplay_pgp($form, &$var, &$vars) if (empty($key)) { return ''; } - return '
    ' .
    -            $GLOBALS['injector']->getInstance('Horde_Core_Factory_Crypt')->create('Pgp', $var->type->getPGPParams())->pgpPrettyKey($key) .
    -            '
    '; + return '
    '
    +            . $GLOBALS['injector']->getInstance('Horde_Core_Factory_Crypt')->create('Pgp', $var->type->getPGPParams())->pgpPrettyKey($key)
    +            . '
    '; } protected function _renderVarDisplay_smime($form, &$var, &$vars) @@ -1296,23 +1509,23 @@ protected function _renderVarDisplay_hourminutesecond($form, &$var, &$vars) */ $time = $var->type->getTimeParts($var->getValue($vars)); if (!$var->type->getProperty('show_seconds')) { - return (int)$time['hour'] . ':' . sprintf('%02d', (int)$time['minute']); + return (int) $time['hour'] . ':' . sprintf('%02d', (int) $time['minute']); } else { - return (int)$time['hour'] . ':' . sprintf('%02d', (int)$time['minute']) . ':' . sprintf('%02d', (int)$time['second']); + return (int) $time['hour'] . ':' . sprintf('%02d', (int) $time['minute']) . ':' . sprintf('%02d', (int) $time['second']); } } protected function _renderVarDisplay_monthyear($form, &$var, &$vars) { - return (int)$vars->get($var->getVarName() . '[month]') . ', ' . (int)$vars->get($var->getVarName() . '[year]'); + return (int) $vars->get($var->getVarName() . '[month]') . ', ' . (int) $vars->get($var->getVarName() . '[year]'); } protected function _renderVarDisplay_monthdayyear($form, &$var, &$vars) { $date = $var->getValue($vars); - if ((is_array($date) && !empty($date['year']) && - !empty($date['month']) && !empty($date['day'])) || - (!is_array($date) && !empty($date) && $date != '0000-00-00')) { + if ((is_array($date) && !empty($date['year']) + && !empty($date['month']) && !empty($date['day'])) + || (!is_array($date) && !empty($date) && $date != '0000-00-00')) { return $var->type->formatDate($date); } return ''; @@ -1337,7 +1550,7 @@ protected function _renderVarDisplay_link($form, &$var, &$vars) { $values = $var->type->values; if (!isset($values[0])) { - $values = array($values); + $values = [$values]; } $count = count($values); @@ -1396,9 +1609,13 @@ protected function _renderVarDisplay_captcha($form, &$var, &$vars) $captcha = Text_CAPTCHA::factory('Image'); } - $image = $captcha->init(150, 60, $var->type->getText(), - array('font_path' => dirname($var->type->getFont()) . '/', - 'font_file' => basename($var->type->getFont()))); + $image = $captcha->init( + 150, + 60, + $var->type->getText(), + ['font_path' => dirname($var->type->getFont()) . '/', + 'font_file' => basename($var->type->getFont())] + ); if (is_a($image, 'PEAR_Error')) { return $image->getMessage(); } @@ -1406,8 +1623,8 @@ protected function _renderVarDisplay_captcha($form, &$var, &$vars) $cid = md5($var->type->getText()); $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); - $cache->set($cid, serialize(array('data' => $captcha->getCAPTCHAAsJPEG(), - 'ctype' => 'image/jpeg'))); + $cache->set($cid, serialize(['data' => $captcha->getCAPTCHAAsJPEG(), + 'ctype' => 'image/jpeg'])); $url = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/cacheview.php')->add('cid', $cid); @@ -1418,28 +1635,32 @@ protected function _renderVarDisplay_captcha($form, &$var, &$vars) protected function _renderVarInput_selectFiles($form, &$var, &$vars) { /* Needed for gollem js calls */ - $html = sprintf('', - 'selectlist_selectid', - 'selectlist_selectid', - $var->type->getProperty('selectid')) . - sprintf('', 'actionID', 'actionID') . + $html = sprintf( + '', + 'selectlist_selectid', + 'selectlist_selectid', + $var->type->getProperty('selectid') + ) + . sprintf('', 'actionID', 'actionID') /* Form field. */ - sprintf('', - htmlspecialchars($var->getVarName()), - $this->_genID($var->getVarName(), false), - $var->type->getProperty('selectid')); + . sprintf( + '', + htmlspecialchars($var->getVarName()), + $this->_genID($var->getVarName(), false), + $var->type->getProperty('selectid') + ); /* Open window link. */ - $param = array($var->type->getProperty('link_text'), - $var->type->getProperty('link_style'), - $form->getName(), - $var->type->getProperty('icon'), - $var->type->getProperty('selectid')); + $param = [$var->type->getProperty('link_text'), + $var->type->getProperty('link_style'), + $form->getName(), + $var->type->getProperty('icon'), + $var->type->getProperty('selectid')]; $html .= $GLOBALS['registry']->call('files/selectlistLink', $param) . "
    \n"; if ($var->type->getProperty('selectid')) { - $param = array($var->type->getProperty('selectid')); + $param = [$var->type->getProperty('selectid')]; $files = $GLOBALS['registry']->call('files/selectlistResults', $param); if ($files) { $html .= '
      '; @@ -1448,8 +1669,8 @@ protected function _renderVarInput_selectFiles($form, &$var, &$vars) $filename = current($file); if ($GLOBALS['registry']->hasMethod('files/getViewLink')) { $filename = basename($filename); - $url = $GLOBALS['registry']->call('files/getViewLink', array($dir, $filename)); - $filename = Horde::link($url, Horde_Core_Translation::t("Preview"), null, 'form_file_view') . htmlspecialchars(Horde_Util::realPath($dir . '/' . $filename)) . ''; + $url = $GLOBALS['registry']->call('files/getViewLink', [$dir, $filename]); + $filename = Horde::link($url, Horde_Core_Translation::t("Preview"), null, 'form_file_view') . htmlspecialchars(Util::realPath($dir . '/' . $filename)) . ''; } else { if (!empty($dir) && ($dir != '.')) { $filename = $dir . '/' . $filename; @@ -1474,15 +1695,17 @@ protected function _renderVarInput_category($form, &$var, &$vars) . Horde_Prefs_CategoryManager::getSelect($var->getVarName(), $var->getValue($vars)); } - public function selectOptions(&$values, $selectedValue = false, - $htmlchars = false) - { + public function selectOptions( + &$values, + $selectedValue = false, + $htmlchars = false + ) { $result = ''; $sel = false; foreach ($values as $value => $display) { - if (!is_null($selectedValue) && !$sel && - $value == $selectedValue && - strlen($value) == strlen($selectedValue)) { + if (!is_null($selectedValue) && !$sel + && $value == $selectedValue + && strlen($value) == strlen($selectedValue)) { $selected = ' selected="selected"'; $sel = true; } else { @@ -1505,7 +1728,7 @@ public function selectOptions(&$values, $selectedValue = false, protected function _multiSelectOptions(&$values, $selectedValues) { if (!is_array($selectedValues)) { - $selectedValues = array(); + $selectedValues = []; } else { $selectedValues = array_flip($selectedValues); } @@ -1528,21 +1751,23 @@ protected function _checkBoxes($name, $values, $checkedValues, $actions = '') { $result = ''; if (!is_array($checkedValues)) { - $checkedValues = array(); + $checkedValues = []; } $i = 0; foreach ($values as $value => $display) { $checked = (in_array($value, $checkedValues)) ? ' checked="checked"' : ''; - $result .= sprintf('
      ', - htmlspecialchars($name), - $i, - htmlspecialchars($name), - htmlspecialchars($value), - $checked, - $actions, - htmlspecialchars($name), - $i, - htmlspecialchars($display)); + $result .= sprintf( + '
      ', + htmlspecialchars($name), + $i, + htmlspecialchars($name), + htmlspecialchars($value), + $checked, + $actions, + htmlspecialchars($name), + $i, + htmlspecialchars($display) + ); $i++; } @@ -1555,16 +1780,18 @@ protected function _radioButtons($name, $values, $checkedValue = null, $actions $i = 0; foreach ($values as $value => $display) { $checked = (!is_null($checkedValue) && $value == $checkedValue) ? ' checked="checked"' : ''; - $result .= sprintf('
      ', - htmlspecialchars($name), - $i, - htmlspecialchars($name), - htmlspecialchars($value), - $checked, - $actions, - htmlspecialchars($name), - $i, - htmlspecialchars($display)); + $result .= sprintf( + '
      ', + htmlspecialchars($name), + $i, + htmlspecialchars($name), + htmlspecialchars($value), + $checked, + $actions, + htmlspecialchars($name), + $i, + htmlspecialchars($display) + ); $i++; } @@ -1582,7 +1809,7 @@ protected function _genActionScript($form, $action, $varname) $html = ''; $triggers = $action->getTrigger(); if (!is_array($triggers)) { - $triggers = array($triggers); + $triggers = [$triggers]; } $js = $action->getActionScript($form, $this, $varname); foreach ($triggers as $trigger) { @@ -1603,7 +1830,7 @@ protected function _getActionScripts($form, &$var) $action = &$var->_action; $triggers = $action->getTrigger(); if (!is_array($triggers)) { - $triggers = array($triggers); + $triggers = [$triggers]; } $js = $action->getActionScript($form, $this, $varname); foreach ($triggers as $trigger) { @@ -1625,9 +1852,9 @@ protected function _addOnLoadJavascript($script) public function renderEnd() { if (count($this->_onLoadJS)) { - return ""; + return ""; } else { return ''; } diff --git a/lib/Horde/Form/VarRenderer.php b/lib/Horde/Form/VarRenderer.php index 5b88e0b..5c7e8cf 100644 --- a/lib/Horde/Form/VarRenderer.php +++ b/lib/Horde/Form/VarRenderer.php @@ -1,10 +1,11 @@ + * Copyright 2003-2026 Horde LLC (http://www.horde.org/) + * Copyright 2005-2026 Matt Warden * * See the enclosed file COPYING for license information (LGPL). * @@ -29,9 +30,9 @@ public function render($form, $var, $vars, $isInput = false) } else { $state = 'Display'; } - $method = "_renderVar${state}_" . str_replace('Horde_Form_Type_', '', get_class($var->type)); + $method = "_renderVar{$state}_" . str_replace('Horde_Form_Type_', '', get_class($var->type)); if (!method_exists($this, $method)) { - $method = "_renderVar${state}Default"; + $method = "_renderVar{$state}Default"; } return $this->$method($form, $var, $vars); } diff --git a/lib/Horde/Form/VarRenderer/Xhtml.php b/lib/Horde/Form/VarRenderer/Xhtml.php index eeea504..ae937e8 100644 --- a/lib/Horde/Form/VarRenderer/Xhtml.php +++ b/lib/Horde/Form/VarRenderer/Xhtml.php @@ -1,9 +1,12 @@ + * Copyright 2003-2026 Horde LLC (http://www.horde.org/) + * Copyright 2005-2026 Matt Warden * * See the enclosed file COPYING for license information (LGPL). * @@ -12,7 +15,7 @@ */ class Horde_Form_VarRenderer_Xhtml extends Horde_Form_VarRenderer { - protected $_onLoadJS = array(); + protected $_onLoadJS = []; /** * Handles the end of rendering of variables; writes onload JavaScript. @@ -25,66 +28,70 @@ class Horde_Form_VarRenderer_Xhtml extends Horde_Form_VarRenderer public function renderEnd() { if (count($this->_onLoadJS)) { - return ""; + return ""; } else { return ''; } } - function _renderVarInputDefault($form, $var, $vars) + public function _renderVarInputDefault($form, $var, $vars) { throw new Horde_Form_Exception('Unknown variable type:' . get_class($var->type)); } - function _renderVarInput_number($form, $var, $vars) + public function _renderVarInput_number($form, $var, $vars) { $value = $var->getValue($vars); if ($var->type->fraction) { $value = sprintf('%01.' . $var->type->fraction . 'f', $value); } - $linfo = Horde_Nls::getLocaleInfo(); + $linfo = (new Horde\Nls\Nls())->getLocaleInfo(); /* Only if there is a mon_decimal_point do the * substitution. */ if (!empty($linfo['mon_decimal_point'])) { $value = str_replace('.', $linfo['mon_decimal_point'], $value); } - return sprintf(' ', - $var->getVarName(), - $value, - $this->_getActionScripts($form, $var) - ); + return sprintf( + ' ', + $var->getVarName(), + $value, + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_int($form, $var, $vars) + public function _renderVarInput_int($form, $var, $vars) { - return sprintf(' ', - $var->getVarName(), - $value = $var->getValue($vars), - $this->_getActionScripts($form, $var) - ); + return sprintf( + ' ', + $var->getVarName(), + $value = $var->getValue($vars), + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_octal($form, $var, $vars) + public function _renderVarInput_octal($form, $var, $vars) { - return sprintf('', - $var->getVarName(), - sprintf('0%o', octdec($var->getValue($vars))), - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + $var->getVarName(), + sprintf('0%o', octdec($var->getValue($vars))), + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_intlist($form, $var, $vars) + public function _renderVarInput_intlist($form, $var, $vars) { - return sprintf('', - $var->getVarName(), - $value = $var->getValue($vars), - $this->_getActionScripts($form, $var) - ); + return sprintf( + '', + $var->getVarName(), + $value = $var->getValue($vars), + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_text($form, $var, $vars) + public function _renderVarInput_text($form, $var, $vars) { return sprintf( '', @@ -108,7 +115,7 @@ function _renderVarInput_stringlist($form, $var, $vars) ); } - function _renderVarInput_phone($form, $var, $vars) + public function _renderVarInput_phone($form, $var, $vars) { return sprintf( '', @@ -119,44 +126,49 @@ function _renderVarInput_phone($form, $var, $vars) ); } - function _renderVarInput_cellphone($form, $var, $vars) + public function _renderVarInput_cellphone($form, $var, $vars) { return $this->_renderVarInput_phone($form, $var, $vars); } - function _renderVarInput_ipaddress($form, $var, $vars) + public function _renderVarInput_ipaddress($form, $var, $vars) { - return sprintf(' ', - $var->getVarName(), - htmlspecialchars($var->getValue($vars)), - $var->isDisabled() ? ' disabled="disabled" ' : '', - $this->_getActionScripts($form, $var) - ); + return sprintf( + ' ', + $var->getVarName(), + htmlspecialchars($var->getValue($vars)), + $var->isDisabled() ? ' disabled="disabled" ' : '', + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_file($form, $var, $vars) + public function _renderVarInput_file($form, $var, $vars) { $file = $var->getValue($vars); - return sprintf(' ', - $var->getVarName(), - $this->_getActionScripts($form, $var)); + return sprintf( + ' ', + $var->getVarName(), + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_longtext($form, $var, $vars) + public function _renderVarInput_longtext($form, $var, $vars) { global $browser; - $html = sprintf('', - $var->getVarName(), - $var->type->cols, - $var->type->rows, - $this->_getActionScripts($form, $var), - $var->isDisabled() ? ' disabled="disabled"' : '', - htmlspecialchars($var->getValue($vars))); + $html = sprintf( + '', + $var->getVarName(), + $var->type->cols, + $var->type->rows, + $this->_getActionScripts($form, $var), + $var->isDisabled() ? ' disabled="disabled"' : '', + htmlspecialchars($var->getValue($vars)) + ); if ($var->type->hasHelper('rte')) { - $GLOBALS['injector']->getInstance('Horde_Editor')->initialize(array('id' => $var->getVarName())); + $GLOBALS['injector']->getInstance('Horde_Editor')->initialize(['id' => $var->getVarName()]); } if ($var->type->hasHelper() && $browser->hasFeature('javascript')) { @@ -166,130 +178,149 @@ function _renderVarInput_longtext($form, $var, $vars) $imgId = $var->getVarName() . 'ehelper'; if ($var->type->hasHelper('emoticons')) { $filter = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->create('emoticons'); - $icon_list = array(); + $icon_list = []; foreach (array_flip($filter->getIcons()) as $icon => $string) { - $icon_list[] = array( + $icon_list[] = [ $filter->getIcon($icon), - $string - ); + $string, + ]; } - $page_output->addInlineJsVars(array( - 'Horde_Html_Helper.iconlist' => $icon_list - )); + $page_output->addInlineJsVars([ + 'Horde_Html_Helper.iconlist' => $icon_list, + ]); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= Horde::link('#', Horde_Model_Translation::t("Emoticons"), '', '', 'Horde_Html_Helper.open(\'emoticons\', \'' . $var->getVarName() . '\'); return false;') - . Horde::img('emoticons/smile.png', Horde_Model_Translation::t("Emoticons"), 'id="' . $imgId . '" align="middle"') - . ''."\n"; + . Horde::img('emoticons/smile.png', Horde_Model_Translation::t("Emoticons"), 'id="' . $imgId . '" align="middle"') + . '' . "\n"; } $html .= '
      '."\n"; + . '" class="form-control">' . "\n"; } return $html; } - function _renderVarInput_countedtext($form, $var, $vars) + public function _renderVarInput_countedtext($form, $var, $vars) { - return sprintf('', - $var->getVarName(), - $var->type->cols, - $var->type->rows, - $this->_getActionScripts($form, $var), - $var->isDisabled() ? ' disabled="disabled"' : '', - $var->getValue($vars)); + return sprintf( + '', + $var->getVarName(), + $var->type->cols, + $var->type->rows, + $this->_getActionScripts($form, $var), + $var->isDisabled() ? ' disabled="disabled"' : '', + $var->getValue($vars) + ); } - function _renderVarInput_address($form, $var, $vars) + public function _renderVarInput_address($form, $var, $vars) { - return sprintf('', - $var->getVarName(), - $var->type->cols, - $var->type->rows, - $this->_getActionScripts($form, $var), - $var->isDisabled() ? ' disabled="disabled"' : '', - $var->getValue($vars)); + return sprintf( + '', + $var->getVarName(), + $var->type->cols, + $var->type->rows, + $this->_getActionScripts($form, $var), + $var->isDisabled() ? ' disabled="disabled"' : '', + $var->getValue($vars) + ); } - function _renderVarInput_date($form, $var, $vars) + public function _renderVarInput_date($form, $var, $vars) { - return sprintf(' ', - $var->getVarName(), - $value = $var->getValue($vars), - $this->_getActionScripts($form, $var)); + return sprintf( + ' ', + $var->getVarName(), + $value = $var->getValue($vars), + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_time($form, $var, $vars) + public function _renderVarInput_time($form, $var, $vars) { - return sprintf(' ', - $var->getVarName(), - $value = $var->getValue($vars), - $this->_getActionScripts($form, $var)); + return sprintf( + ' ', + $var->getVarName(), + $value = $var->getValue($vars), + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_hourminutesecond($form, $var, $vars) + public function _renderVarInput_hourminutesecond($form, $var, $vars) { $varname = $var->getVarName(); $time = $var->type->getTimeParts($var->getValue($vars)); /* Output hours. */ - $hours = array('' => Horde_Model_Translation::t("hh")); + $hours = ['' => Horde_Model_Translation::t("hh")]; for ($i = 0; $i <= 23; $i++) { $hours[sprintf('%02d', $i)] = $i; } - $html = sprintf('', - $varname, - $this->_selectOptions($hours, $time['hour']), - $this->_getActionScripts($form, $var)); + $html = sprintf( + '', + $varname, + $this->_selectOptions($hours, $time['hour']), + $this->_getActionScripts($form, $var) + ); /* Output minutes. */ - $minutes = array('' => Horde_Model_Translation::t("mm")); + $minutes = ['' => Horde_Model_Translation::t("mm")]; for ($i = 0; $i <= 59; $i++) { $minutes[sprintf('%02d', $i)] = $i; } - $html .= sprintf('', - $varname, - $this->_selectOptions($minutes, $time['minute']), - $this->_getActionScripts($form, $var)); + $html .= sprintf( + '', + $varname, + $this->_selectOptions($minutes, $time['minute']), + $this->_getActionScripts($form, $var) + ); /* Return if seconds are not required. */ if ($var->type->show_seconds) { /* Output seconds. */ - $seconds = array('' => Horde_Model_Translation::t("ss")); + $seconds = ['' => Horde_Model_Translation::t("ss")]; for ($i = 0; $i <= 59; $i++) { $seconds[sprintf('%02d', $i)] = $i; } - $html .= sprintf('', - $varname, - $this->_getActionScripts($form, $var), - $this->_selectOptions($seconds, $time['second'])); + $html .= sprintf( + '', + $varname, + $this->_getActionScripts($form, $var), + $this->_selectOptions($seconds, $time['second']) + ); } return $html; } - function _renderVarInput_monthyear($form, $var, $vars) - { - $dates = array(); - $dates['month'] = array('' => Horde_Model_Translation::t("MM"), - 1 => Horde_Model_Translation::t("January"), - 2 => Horde_Model_Translation::t("February"), - 3 => Horde_Model_Translation::t("March"), - 4 => Horde_Model_Translation::t("April"), - 5 => Horde_Model_Translation::t("May"), - 6 => Horde_Model_Translation::t("June"), - 7 => Horde_Model_Translation::t("July"), - 8 => Horde_Model_Translation::t("August"), - 9 => Horde_Model_Translation::t("September"), - 10 => Horde_Model_Translation::t("October"), - 11 => Horde_Model_Translation::t("November"), - 12 => Horde_Model_Translation::t("December")); - $dates['year'] = array('' => Horde_Model_Translation::t("YYYY")); + public function _renderVarInput_monthyear($form, $var, $vars) + { + $dates = []; + $dates['month'] = ['' => Horde_Model_Translation::t("MM"), + 1 => Horde_Model_Translation::t("January"), + 2 => Horde_Model_Translation::t("February"), + 3 => Horde_Model_Translation::t("March"), + 4 => Horde_Model_Translation::t("April"), + 5 => Horde_Model_Translation::t("May"), + 6 => Horde_Model_Translation::t("June"), + 7 => Horde_Model_Translation::t("July"), + 8 => Horde_Model_Translation::t("August"), + 9 => Horde_Model_Translation::t("September"), + 10 => Horde_Model_Translation::t("October"), + 11 => Horde_Model_Translation::t("November"), + 12 => Horde_Model_Translation::t("December")]; + $dates['year'] = ['' => Horde_Model_Translation::t("YYYY")]; if ($var->type->start_year > $var->type->end_year) { for ($i = $var->type->start_year; $i >= $var->type->end_year; $i--) { $dates['year'][$i] = $i; @@ -299,40 +330,44 @@ function _renderVarInput_monthyear($form, $var, $vars) $dates['year'][$i] = $i; } } - $html = sprintf('', - $var->type->getMonthVar($var), - $this->_getActionScripts($form, $var), - $this->_selectOptions($dates['month'], $vars->get($var->type->getMonthVar($var)))); + $html = sprintf( + '', + $var->type->getMonthVar($var), + $this->_getActionScripts($form, $var), + $this->_selectOptions($dates['month'], $vars->get($var->type->getMonthVar($var))) + ); - $html .= sprintf('', - $var->type->getYearVar($var), - $this->_getActionScripts($form, $var), - $this->_selectOptions($dates['year'], $vars->get($var->type->getYearVar($var)))); + $html .= sprintf( + '', + $var->type->getYearVar($var), + $this->_getActionScripts($form, $var), + $this->_selectOptions($dates['year'], $vars->get($var->type->getYearVar($var))) + ); return $html; } - function _renderVarInput_monthdayyear($form, $var, $vars) - { - $dates = array(); - $dates['month'] = array('' => Horde_Model_Translation::t("MM"), - '1' => Horde_Model_Translation::t("January"), - '2' => Horde_Model_Translation::t("February"), - '3' => Horde_Model_Translation::t("March"), - '4' => Horde_Model_Translation::t("April"), - '5' => Horde_Model_Translation::t("May"), - '6' => Horde_Model_Translation::t("June"), - '7' => Horde_Model_Translation::t("July"), - '8' => Horde_Model_Translation::t("August"), - '9' => Horde_Model_Translation::t("September"), - '10' => Horde_Model_Translation::t("October"), - '11' => Horde_Model_Translation::t("November"), - '12' => Horde_Model_Translation::t("December")); - $dates['day'] = array('' => Horde_Model_Translation::t("DD")); + public function _renderVarInput_monthdayyear($form, $var, $vars) + { + $dates = []; + $dates['month'] = ['' => Horde_Model_Translation::t("MM"), + '1' => Horde_Model_Translation::t("January"), + '2' => Horde_Model_Translation::t("February"), + '3' => Horde_Model_Translation::t("March"), + '4' => Horde_Model_Translation::t("April"), + '5' => Horde_Model_Translation::t("May"), + '6' => Horde_Model_Translation::t("June"), + '7' => Horde_Model_Translation::t("July"), + '8' => Horde_Model_Translation::t("August"), + '9' => Horde_Model_Translation::t("September"), + '10' => Horde_Model_Translation::t("October"), + '11' => Horde_Model_Translation::t("November"), + '12' => Horde_Model_Translation::t("December")]; + $dates['day'] = ['' => Horde_Model_Translation::t("DD")]; for ($i = 1; $i <= 31; $i++) { $dates['day'][$i] = $i; } - $dates['year'] = array('' => Horde_Model_Translation::t("YYYY")); + $dates['year'] = ['' => Horde_Model_Translation::t("YYYY")]; if ($var->type->start_year > $var->type->end_year) { for ($i = $var->type->start_year; $i >= $var->type->end_year; $i--) { $dates['year'][$i] = $i; @@ -347,25 +382,27 @@ function _renderVarInput_monthdayyear($form, $var, $vars) // TODO: use NLS to get the order right for the Rest Of The // World. $html = ''; - $date_parts = array('month', 'day', 'year'); + $date_parts = ['month', 'day', 'year']; foreach ($date_parts as $part) { $varname = $var->getVarName() . '[' . $part . ']'; - $html .= sprintf('', - $varname, - $this->_getActionScripts($form, $var), - $this->_selectOptions($dates[$part], $date[$part])); + $html .= sprintf( + '', + $varname, + $this->_getActionScripts($form, $var), + $this->_selectOptions($dates[$part], $date[$part]) + ); } return $html; } - function _renderVarInput_datetime($form, $var, $vars) + public function _renderVarInput_datetime($form, $var, $vars) { - return parent::_renderVarInput_monthdayyear($form, $var, $vars) . - parent::_renderVarInput_hourminutesecond($form, $var, $vars); + return parent::_renderVarInput_monthdayyear($form, $var, $vars) + . parent::_renderVarInput_hourminutesecond($form, $var, $vars); } - function _renderVarInput_colorpicker($form, $var, $vars) + public function _renderVarInput_colorpicker($form, $var, $vars) { $html = '
      ' . 'getVarName() .'\'); return false;') - . Horde::img('colorpicker.png', Horde_Model_Translation::t("Color Picker")) . '' - . '
      '; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ + $html .= Horde::img('blank.gif', '', ['class' => 'form-colorpicker-preview', + 'id' => 'colordemo_' . $var->getVarName(), + 'style' => 'background:' . $var->getValue($vars)]) + . Horde::link('#', Horde_Model_Translation::t("Color Picker"), '', '', 'openColorPicker(\'' . $var->getVarName() . '\'); return false;') + . Horde::img('colorpicker.png', Horde_Model_Translation::t("Color Picker")) . '' + . '
      '; } return $html . '
      '; } - function _renderVarInput_sorter($form, $var, $vars) + public function _renderVarInput_sorter($form, $var, $vars) { global $registry; @@ -394,26 +436,35 @@ function _renderVarInput_sorter($form, $var, $vars) $GLOBALS['injector']->getInstance('Horde_PageOutput')->addScriptFile('sorter.js', 'horde'); - return ' '."\n" - . '
      ' - . Horde::link('#', Horde_Model_Translation::t("Move up"), '', '', $instance . '.moveColumnUp(); return false;') - . Horde::img('nav/up.png', Horde_Model_Translation::t("Move up")) - . '
      ' - . Horde::link('#', Horde_Model_Translation::t("Move up"), '', '', $instance . '.moveColumnDown(); return false;') - . Horde::img('nav/down.png', Horde_Model_Translation::t("Move down")) - . '
      ' - . '\n", $instance); - } - - function _renderVarInput_assign($form, $var, $vars) + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ + return ' ' . "\n" + . '
      ' + . Horde::link('#', Horde_Model_Translation::t("Move up"), '', '', $instance . '.moveColumnUp(); return false;') + . Horde::img('nav/up.png', Horde_Model_Translation::t("Move up")) + . '
      ' + . Horde::link('#', Horde_Model_Translation::t("Move up"), '', '', $instance . '.moveColumnDown(); return false;') + . Horde::img('nav/down.png', Horde_Model_Translation::t("Move down")) + . '
      ' + . '\n", $instance); + } + + public function _renderVarInput_assign($form, $var, $vars) { global $registry; @@ -422,39 +473,52 @@ function _renderVarInput_assign($form, $var, $vars) $name = $var->getVarName(); $fname = $form->getName() . '.' . $name; $width = $var->type->width; - $lhdr = (bool)$var->type->getHeader(0); - $rhdr = (bool)$var->type->getHeader(1); + $lhdr = (bool) $var->type->getHeader(0); + $rhdr = (bool) $var->type->getHeader(1); $this->_onLoadJS[] = 'Horde_Form_Assign.setField(\'' . $fname . '\');'; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html = '
      ' - . ' ' - . sprintf(' ' - . '' - . sprintf('
      '; + . ' ' + . sprintf( + ' ' + . '' + . sprintf( + ' '; return $html; } - function _renderVarInput_invalid($form, $var, $vars) + public function _renderVarInput_invalid($form, $var, $vars) { return $this->_renderVarDisplay_invalid($form, $var, $vars); } - function _renderVarInput_enum($form, $var, $vars) + public function _renderVarInput_enum($form, $var, $vars) { $values = $var->getValues(); $prompt = $var->type->prompt; @@ -462,14 +526,16 @@ function _renderVarInput_enum($form, $var, $vars) if ($prompt) { $prompt = ''; } - return sprintf(' ', - $var->getVarName(), - $this->_getActionScripts($form, $var), - $prompt, - $this->_selectOptions($values, $var->getValue($vars), $htmlchars)); + return sprintf( + ' ', + $var->getVarName(), + $this->_getActionScripts($form, $var), + $prompt, + $this->_selectOptions($values, $var->getValue($vars), $htmlchars) + ); } - function _renderVarInput_mlenum($form, $var, $vars) + public function _renderVarInput_mlenum($form, $var, $vars) { $varname = $var->getVarName(); $values = $var->getValues(); @@ -480,23 +546,27 @@ function _renderVarInput_mlenum($form, $var, $vars) if (!is_array($selected)) { foreach ($values as $key_1 => $values_2) { if (isset($values_2[$selected])) { - $selected = array('1' => $key_1, '2' => $selected); + $selected = ['1' => $key_1, '2' => $selected]; break; } } } /* Hidden tag to store the current first level. */ - $html = sprintf(' ', - $varname, - htmlspecialchars($selected['1'])); + $html = sprintf( + ' ', + $varname, + htmlspecialchars($selected['1']) + ); /* First level. */ $values_1 = Horde_Array::valuesToKeys(array_keys($values)); - $html .= sprintf(' ', + $varname, + 'if (this.value) { document.' . $form->getName() . '.formname.value=\'\';' . 'document.' . $form->getName() . '.submit() }', + ($var->hasAction() ? ' ' . $this->_genActionScript($form, $var->_action, $varname) : '') + ); if (!empty($prompts)) { $html .= ''; } @@ -504,108 +574,118 @@ function _renderVarInput_mlenum($form, $var, $vars) $html .= ' '; /* Second level. */ - $html .= sprintf(' ', + $varname, + ($var->hasAction() ? ' ' . $this->_genActionScript($form, $var->_action, $varname) : '') + ); if (!empty($prompts)) { $html .= ''; } - $values_2 = array(); + $values_2 = []; if (!empty($selected['1'])) { $values_2 = $values[$selected['1']]; } return $html . $this->_selectOptions($values_2, $selected['2']) . ' '; } - function _renderVarInput_multienum($form, $var, $vars) + public function _renderVarInput_multienum($form, $var, $vars) { $values = $var->getValues(); $selected = $vars->getExists($var->getVarName(), $wasset); if (!$wasset) { $selected = $var->getDefault(); } - $html = sprintf(' ', - $var->type->size, - $var->getVarName(), - $this->_getActionScripts($form, $var), - $this->_multiSelectOptions($values, $selected)); + $html = sprintf( + ' ', + $var->type->size, + $var->getVarName(), + $this->_getActionScripts($form, $var), + $this->_multiSelectOptions($values, $selected) + ); return $html . '

      ' . Horde_Model_Translation::t("To select multiple items, hold down the Control (PC) or Command (Mac) key while clicking.") . "

      \n"; } - function _renderVarInput_keyval_multienum($form, $var, $vars) + public function _renderVarInput_keyval_multienum($form, $var, $vars) { return $this->_renderVarInput_multienum($form, $var, $vars); } - function _renderVarInput_radio($form, $var, $vars) + public function _renderVarInput_radio($form, $var, $vars) { - return $this->_radioButtons($var->getVarName(), - $var->getValues(), - $var->getValue($vars), - $this->_getActionScripts($form, $var)); + return $this->_radioButtons( + $var->getVarName(), + $var->getValues(), + $var->getValue($vars), + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_set($form, $var, $vars) + public function _renderVarInput_set($form, $var, $vars) { - $html = $this->_checkBoxes($var->getVarName(), - $var->getValues(), - $var->getValue($vars), - $this->_getActionScripts($form, $var)); + $html = $this->_checkBoxes( + $var->getVarName(), + $var->getValues(), + $var->getValue($vars), + $this->_getActionScripts($form, $var) + ); if ($var->type->checkAll) { $form_name = $form->getName(); $var_name = $var->getVarName() . '[]'; - $function_name = 'select' . $form_name . $var->getVarName(); + $function_name = 'select' . $form_name . $var->getVarName(); $enable = Horde_Model_Translation::t("Select all"); $disable = Horde_Model_Translation::t("Select none"); $invert = Horde_Model_Translation::t("Invert selection"); $html .= << -function $function_name() -{ - for (var i = 0; i < document.$form_name.elements.length; i++) { - f = document.$form_name.elements[i]; - if (f.name != '$var_name') { - continue; - } - if (arguments.length) { - f.checked = arguments[0]; - } else { - f.checked = !f.checked; - } - } -} - -$enable, -$disable, -$invert -EOT; + + $enable, + $disable, + $invert + EOT; } return $html; } - function _renderVarInput_link($form, $var, $vars) + public function _renderVarInput_link($form, $var, $vars) { return $this->_renderVarDisplay_link($form, $var, $vars); } - function _renderVarInput_html($form, $var, $vars) + public function _renderVarInput_html($form, $var, $vars) { return $this->_renderVarDisplay_html($form, $var, $vars); } - function _renderVarInput_email($form, $var, $vars) + public function _renderVarInput_email($form, $var, $vars) { - return sprintf(' ', - $var->getVarName(), - $value = $var->getValue($vars), - $this->_getActionScripts($form, $var)); + return sprintf( + ' ', + $var->getVarName(), + $value = $var->getValue($vars), + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_matrix($form, $var, $vars) + public function _renderVarInput_matrix($form, $var, $vars) { $varname = $var->getVarName(); $var_array = $var->getValue($vars); @@ -624,24 +704,28 @@ function _renderVarInput_matrix($form, $var, $vars) /* Offer a new row of data to be added to the matrix? */ if ($new_input) { - $html .= ''."\n"; + $html .= '' . "\n"; if (is_array($new_input)) { - $html .= sprintf(' %s
      '."\n", - ' id="'. $varname .'-n--r-"', - $varname, - Horde_Model_Translation::t("-- select --"), - $this->_selectOptions($new_input, $var_array['n']['r'])); + $html .= sprintf( + ' %s
      ' . "\n", + ' id="' . $varname . '-n--r-"', + $varname, + Horde_Model_Translation::t("-- select --"), + $this->_selectOptions($new_input, $var_array['n']['r']) + ); } elseif ($new_input == true) { - $html .= sprintf(' ', - ' id="'. $varname .'-n--r-', - $varname, - $var_array['n']['r']); + $html .= sprintf( + ' ', + ' id="' . $varname . '-n--r-', + $varname, + $var_array['n']['r'] + ); } $html .= ' '; foreach ($cols as $col_id => $col_title) { $html .= sprintf('', $varname, $col_id); } - $html .= ' '."\n"; + $html .= ' ' . "\n"; } /* Loop through the rows and create checkboxes for each column. */ @@ -650,82 +734,98 @@ function _renderVarInput_matrix($form, $var, $vars) foreach ($cols as $col_id => $col_title) { $html .= sprintf('', $varname, $row_id, $col_id, (!empty($matrix[$row_id][$col_id]) ? ' checked="checked"' : '')); } - $html .= ' '."\n"; + $html .= ' ' . "\n"; } - $html .= ''."\n"; + $html .= '' . "\n"; return $html; } - function _renderVarInput_password($form, $var, $vars) + public function _renderVarInput_password($form, $var, $vars) { - return sprintf('', - $var->getVarName(), - $value = $var->getValue($vars), - $this->_getActionScripts($form, $var)); + return sprintf( + '', + $var->getVarName(), + $value = $var->getValue($vars), + $this->_getActionScripts($form, $var) + ); } - function _renderVarInput_emailconfirm($form, $var, $vars) + public function _renderVarInput_emailconfirm($form, $var, $vars) { $email = $var->getValue($vars); - return '
      • ' . sprintf('', - $var->getVarName(), - $value = $email['original'], - $this->_getActionScripts($form, $var)) . '
      • ' . - sprintf('', - $var->getVarName(), - $value = $email['confirm'], - $this->_getActionScripts($form, $var)) . '
      '; + return '
      • ' . sprintf( + '', + $var->getVarName(), + $value = $email['original'], + $this->_getActionScripts($form, $var) + ) . '
      • ' + . sprintf( + '', + $var->getVarName(), + $value = $email['confirm'], + $this->_getActionScripts($form, $var) + ) . '
      '; } - function _renderVarInput_passwordconfirm($form, $var, $vars) + public function _renderVarInput_passwordconfirm($form, $var, $vars) { $password = $var->getValue($vars); - return '
      • ' . sprintf('', - $var->getVarName(), - $value = $password['original'], - $this->_getActionScripts($form, $var)) . '
      • ' . - sprintf('', - $var->getVarName(), - $value = $password['confirm'], - $this->_getActionScripts($form, $var)) . '
      '; + return '
      • ' . sprintf( + '', + $var->getVarName(), + $value = $password['original'], + $this->_getActionScripts($form, $var) + ) . '
      • ' + . sprintf( + '', + $var->getVarName(), + $value = $password['confirm'], + $this->_getActionScripts($form, $var) + ) . '
      '; } - function _renderVarInput_boolean($form, $var, $vars) + public function _renderVarInput_boolean($form, $var, $vars) { $varName = $var->getVarName(); - $html = ' getValue($vars) ? ' checked="checked"' : ''); if ($var->hasAction()) { - $html .= $this->_genActionScript($form, $var->_action, - $var->getVarName()); + $html .= $this->_genActionScript( + $form, + $var->_action, + $var->getVarName() + ); } $html .= ' />'; return $html; } - function _renderVarInput_creditcard($form, $var, $vars) + public function _renderVarInput_creditcard($form, $var, $vars) { $varName = $var->getVarName(); - $html = ' getValue($vars); + $html = ' getValue($vars); if ($var->hasAction()) { - $html .= $this->_genActionScript($form, $var->_action, - $var->getVarName()); + $html .= $this->_genActionScript( + $form, + $var->_action, + $var->getVarName() + ); } return $html . ' />'; } - function _renderVarInput_obrowser($form, $var, $vars) + public function _renderVarInput_obrowser($form, $var, $vars) { $varname = $var->getVarName(); $varvalue = $vars->get($varname); @@ -744,57 +844,68 @@ function obrowserCallback(name, oid) } '; - $html .= sprintf('', - $varname, - $fieldId, - $this->_getActionScripts($form, $var), - $varvalue); + $html .= sprintf( + '', + $varname, + $fieldId, + $this->_getActionScripts($form, $var), + $varvalue + ); if (!empty($varvalue)) { $html .= $varvalue; } if ($GLOBALS['browser']->hasFeature('javascript')) { - $imgId = $varname .'goto'; + $imgId = $varname . 'goto'; $html .= ''; + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= Horde::link('#', Horde_Model_Translation::t("Select an object"), '', '', 'obrowserWindow = ' . Horde::popupJs($GLOBALS['registry']->get('webroot', 'horde') . '/services/obrowser/') . 'obrowserWindowName = obrowserWindow.name; return false;') . Horde::img('tree/leaf.png', Horde_Model_Translation::t("Object"), 'id="' . $imgId . '" align="middle"') . "\n"; } return $html; } - function _renderVarInput_dblookup($form, $var, $vars) + public function _renderVarInput_dblookup($form, $var, $vars) { return $this->_renderVarInput_enum($form, $var, $vars); } - function _renderVarInput_figlet($form, $var, $vars) + public function _renderVarInput_figlet($form, $var, $vars) { - return sprintf(' ', - $var->getVarName(), - strlen($var->type->text), - htmlspecialchars($var->getValue($vars))) . - '

      ' . Horde_Model_Translation::t("Enter the letters below:") . '

      ' . - $this->_renderVarDisplay_figlet($form, $var, $vars); + return sprintf( + ' ', + $var->getVarName(), + strlen($var->type->text), + htmlspecialchars($var->getValue($vars)) + ) + . '

      ' . Horde_Model_Translation::t("Enter the letters below:") . '

      ' + . $this->_renderVarDisplay_figlet($form, $var, $vars); } - function _renderVarDisplayDefault($form, $var, $vars) + public function _renderVarDisplayDefault($form, $var, $vars) { return nl2br(htmlspecialchars($var->getValue($vars))); } - function _renderVarDisplay_html($form, $var, $vars) + public function _renderVarDisplay_html($form, $var, $vars) { return $var->getValue($vars); } - function _renderVarDisplay_email($form, $var, $vars) + public function _renderVarDisplay_email($form, $var, $vars) { $display_email = $email = $var->getValue($vars); if ($var->type->strip_domain && strpos($email, '@') !== false) { - $display_email = str_replace(array('@', '.'), - array(' (at) ', ' (dot) '), - $email); + $display_email = str_replace( + ['@', '.'], + [' (at) ', ' (dot) '], + $email + ); } if ($var->type->link_compose) { @@ -815,7 +926,7 @@ function _renderVarDisplay_email($form, $var, $vars) // the email address). $address = str_replace('@>', '>', $address); try { - $mail_link = $GLOBALS['registry']->call('mail/compose', array(array('to' => addslashes($address)))); + $mail_link = $GLOBALS['registry']->call('mail/compose', [['to' => addslashes($address)]]); } catch (Horde_Exception $e) { $mail_link = 'mailto:' . urlencode($address); } @@ -827,27 +938,27 @@ function _renderVarDisplay_email($form, $var, $vars) } } - function _renderVarDisplay_password($form, $var, $vars) + public function _renderVarDisplay_password($form, $var, $vars) { return '********'; } - function _renderVarDisplay_passwordconfirm($form, $var, $vars) + public function _renderVarDisplay_passwordconfirm($form, $var, $vars) { return '********'; } - function _renderVarDisplay_octal($form, $var, $vars) + public function _renderVarDisplay_octal($form, $var, $vars) { return sprintf('0%o', octdec($var->getValue($vars))); } - function _renderVarDisplay_boolean($form, $var, $vars) + public function _renderVarDisplay_boolean($form, $var, $vars) { return $var->getValue($vars) ? Horde_Model_Translation::t("Yes") : Horde_Model_Translation::t("No"); } - function _renderVarDisplay_enum($form, $var, $vars) + public function _renderVarDisplay_enum($form, $var, $vars) { $values = $var->getValues(); $value = $var->getValue($vars); @@ -858,7 +969,7 @@ function _renderVarDisplay_enum($form, $var, $vars) } } - function _renderVarDisplay_radio($form, $var, $vars) + public function _renderVarDisplay_radio($form, $var, $vars) { $values = $var->getValues(); if (count($values) == 0) { @@ -868,14 +979,14 @@ function _renderVarDisplay_radio($form, $var, $vars) } } - function _renderVarDisplay_multienum($form, $var, $vars) + public function _renderVarDisplay_multienum($form, $var, $vars) { $values = $var->getValues(); $on = $var->getValue($vars); if (!count($values) || !count($on)) { return Horde_Model_Translation::t("No values"); } else { - $display = array(); + $display = []; foreach ($values as $value => $name) { if (in_array($value, $on)) { $display[] = $name; @@ -885,14 +996,14 @@ function _renderVarDisplay_multienum($form, $var, $vars) } } - function _renderVarDisplay_set($form, $var, $vars) + public function _renderVarDisplay_set($form, $var, $vars) { $values = $var->getValues(); $on = $var->getValue($vars); if (!count($values) || !count($on)) { return Horde_Model_Translation::t("No values"); } else { - $display = array(); + $display = []; foreach ($values as $value => $name) { if (in_array($value, $on)) { $display[] = $name; @@ -902,7 +1013,7 @@ function _renderVarDisplay_set($form, $var, $vars) } } - function _renderVarDisplay_phone($form, $var, $vars) + public function _renderVarDisplay_phone($form, $var, $vars) { global $registry; @@ -910,15 +1021,20 @@ function _renderVarDisplay_phone($form, $var, $vars) $html = htmlspecialchars($number, ENT_QUOTES, $this->_charset); if ($number && $registry->hasMethod('telephony/dial')) { - $url = $registry->call('telephony/dial', array($number)); + $url = $registry->call('telephony/dial', [$number]); $label = sprintf(Horde_Model_Translation::t("Dial %s"), $number); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= ' ' . Horde::link($url, $label) . Horde::img('phone.png', $label) . ''; } return $html; } - function _renderVarDisplay_cellphone($form, $var, $vars) + public function _renderVarDisplay_cellphone($form, $var, $vars) { global $registry; @@ -926,14 +1042,19 @@ function _renderVarDisplay_cellphone($form, $var, $vars) $number = $var->getValue($vars); if ($number && $registry->hasMethod('sms/compose')) { - $url = $registry->link('sms/compose', array('to' => $number)); + $url = $registry->link('sms/compose', ['to' => $number]); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= ' ' . Horde::link($url, Horde_Model_Translation::t("Send SMS")) . Horde::img('mobile.png', Horde_Model_Translation::t("Send SMS")) . ''; } return $html; } - function _renderVarDisplay_address($form, $var, $vars) + public function _renderVarDisplay_address($form, $var, $vars) { global $registry; @@ -1025,17 +1146,17 @@ function _renderVarDisplay_address($form, $var, $vars) $country = array_search(Horde_String::upper($addressParts[2]), $carsigns); /* Map24 generated map. */ - if (in_array($country, array('al', 'ad', 'am', 'az', 'be', 'ba', - 'bg', 'de', 'dk', 'ee', 'fo', 'fi', - 'fr', 'ge', 'gr', 'gb', 'ie', 'is', - 'it', 'hr', 'lv', 'li', 'lt', 'lu', - 'mt', 'mk', 'md', 'mc', 'nl', 'no', - 'pl', 'pt', 'ro', 'ru', 'se', 'ch', - 'cs', 'sk', 'si', 'es', 'cz', 'tr', - 'ua', 'hu', 'by', 'cy', 'at'))) { - if (in_array($country, array('at', 'be', 'ch', 'de', 'dk', - 'es', 'fi', 'fr', 'it', 'nl', - 'no', 'se'))) { + if (in_array($country, ['al', 'ad', 'am', 'az', 'be', 'ba', + 'bg', 'de', 'dk', 'ee', 'fo', 'fi', + 'fr', 'ge', 'gr', 'gb', 'ie', 'is', + 'it', 'hr', 'lv', 'li', 'lt', 'lu', + 'mt', 'mk', 'md', 'mc', 'nl', 'no', + 'pl', 'pt', 'ro', 'ru', 'se', 'ch', + 'cs', 'sk', 'si', 'es', 'cz', 'tr', + 'ua', 'hu', 'by', 'cy', 'at'])) { + if (in_array($country, ['at', 'be', 'ch', 'de', 'dk', + 'es', 'fi', 'fr', 'it', 'nl', + 'no', 'se'])) { $mirror = $country; } else { $mirror = 'uk'; @@ -1071,51 +1192,66 @@ function _renderVarDisplay_address($form, $var, $vars) $html = nl2br(htmlspecialchars($var->getValue($vars))); if (!empty($mapurl)) { + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= '  ' . Horde::link(Horde::externalUrl($mapurl), $desc, null, '_blank') . Horde::img($icon, $desc) . ''; } if (!empty($mapurl2)) { + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= ' ' . Horde::link(Horde::externalUrl($mapurl2), $desc2, null, '_blank') . Horde::img($icon2, $desc2) . ''; } if (!empty($mapurl3)) { + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::img() + * @deprecated Use Horde_Themes_Image::tag() instead + * @see Horde_Deprecated::img() + */ $html .= ' ' . Horde::link(Horde::externalUrl($mapurl3), $desc3, null, '_blank') . Horde::img($icon3, $desc3) . ''; } return $html; } - function _renderVarDisplay_date($form, $var, $vars) + public function _renderVarDisplay_date($form, $var, $vars) { return $var->type->getFormattedTime($var->getValue($vars)); } - function _renderVarDisplay_monthyear($form, $var, $vars) + public function _renderVarDisplay_monthyear($form, $var, $vars) { return $vars->get($var->getVarName() . '[month]') . ', ' . $vars->get($var->getVarName() . '[year]'); } - function _renderVarDisplay_monthdayyear($form, $var, $vars) + public function _renderVarDisplay_monthdayyear($form, $var, $vars) { $date = $var->getValue($vars); - if ((is_array($date) && !empty($date['year']) && - !empty($date['month']) && !empty($date['day'])) + if ((is_array($date) && !empty($date['year']) + && !empty($date['month']) && !empty($date['day'])) || (!is_array($date) && !empty($date))) { return $var->type->formatDate($date); } return ''; } - function _renderVarDisplay_invalid($form, $var, $vars) + public function _renderVarDisplay_invalid($form, $var, $vars) { return '

      ' . htmlspecialchars($var->type->message) . '

      '; } - function _renderVarDisplay_link($form, $var, $vars) + public function _renderVarDisplay_link($form, $var, $vars) { $values = $var->getValues(); if (!isset($values[0])) { - $values = array($values); + $values = [$values]; } @@ -1140,21 +1276,27 @@ function _renderVarDisplay_link($form, $var, $vars) if ($i > 0) { $html .= ' | '; } - $html .= Horde::link($values[$i]['url'], $values[$i]['text'], - 'widget', $values[$i]['target'], $values[$i]['onclick'], - $values[$i]['title'], $values[$i]['accesskey']) + $html .= Horde::link( + $values[$i]['url'], + $values[$i]['text'], + 'widget', + $values[$i]['target'], + $values[$i]['onclick'], + $values[$i]['title'], + $values[$i]['accesskey'] + ) . $values[$i]['text'] . ''; } return $html; } - function _renderVarDisplay_dblookup($form, $var, $vars) + public function _renderVarDisplay_dblookup($form, $var, $vars) { return $this->_renderVarDisplay_enum($form, $var, $vars); } - function _renderVarDisplay_figlet($form, $var, $vars) + public function _renderVarDisplay_figlet($form, $var, $vars) { $figlet = new Text_Figlet(); $result = $figlet->loadFont($var->type->font); @@ -1165,29 +1307,33 @@ function _renderVarDisplay_figlet($form, $var, $vars) return '
      ' . $figlet->lineEcho($var->type->text) . '
      '; } - function _renderVarInput_selectFiles($form, $var, $vars) + public function _renderVarInput_selectFiles($form, $var, $vars) { /* Needed for gollem js calls */ - $html = sprintf('', - 'selectlist_selectid', - $var->type->selectid) + $html = sprintf( + '', + 'selectlist_selectid', + $var->type->selectid + ) . sprintf('', 'actionID'); /* Form field. */ - $html .= sprintf('', - $var->getVarName(), - $var->type->selectid); + $html .= sprintf( + '', + $var->getVarName(), + $var->type->selectid + ); /* Open window link. */ - $param = array($var->type->link_text, - $var->type->link_style, - $form->getName(), - $var->type->icon, - $var->type->selectid); + $param = [$var->type->link_text, + $var->type->link_style, + $form->getName(), + $var->type->icon, + $var->type->selectid]; $html .= "

      \n" . $GLOBALS['registry']->call('files/selectlistLink', $param) . "

      \n"; if ($var->type->selectid) { - $param = array($var->type->selectid); + $param = [$var->type->selectid]; $files = $GLOBALS['registry']->call('files/selectlistResults', $param); if ($files) { $html .= '
        '; @@ -1196,8 +1342,8 @@ function _renderVarInput_selectFiles($form, $var, $vars) $filename = current($file); if ($GLOBALS['registry']->hasMethod('files/getViewLink')) { $filename = basename($filename); - $url = $GLOBALS['registry']->call('files/getViewLink', array($dir, $filename)); - $filename = Horde::link($url, Horde_Model_Translation::t("Preview"), null, 'form_file_view') . htmlspecialchars(Horde_Util::realPath($dir . '/' . $filename), ENT_QUOTES, $this->_charset) . ''; + $url = $GLOBALS['registry']->call('files/getViewLink', [$dir, $filename]); + $filename = Horde::link($url, Horde_Model_Translation::t("Preview"), null, 'form_file_view') . htmlspecialchars(Util::realPath($dir . '/' . $filename), ENT_QUOTES, $this->_charset) . ''; } else { if (!empty($dir) && ($dir != '.')) { $filename = $dir . '/' . $filename; @@ -1213,7 +1359,7 @@ function _renderVarInput_selectFiles($form, $var, $vars) return $html; } - function _selectOptions($values, $selectedValue = false, $htmlchars = true) + public function _selectOptions($values, $selectedValue = false, $htmlchars = true) { $result = ''; $sel = false; @@ -1235,7 +1381,7 @@ function _selectOptions($values, $selectedValue = false, $htmlchars = true) return $result; } - function _multiSelectOptions($values, $selectedValues) + public function _multiSelectOptions($values, $selectedValues) { $result = ''; $sel = false; @@ -1253,11 +1399,11 @@ function _multiSelectOptions($values, $selectedValues) return $result; } - function _checkBoxes($name, $values, $checkedValues, $actions = '') + public function _checkBoxes($name, $values, $checkedValues, $actions = '') { $result = ''; if (!is_array($checkedValues)) { - $checkedValues = array(); + $checkedValues = []; } if (count($values) > 0) { @@ -1267,18 +1413,20 @@ function _checkBoxes($name, $values, $checkedValues, $actions = '') $i = 0; foreach ($values as $value => $display) { $checked = in_array($value, $checkedValues) ? ' checked="checked"' : ''; - $result .= sprintf('
      1. ' - .'' - .' 
      2. '."\n", - $name, - $i, - $value, - $checked, - $actions, - $display); + $result .= sprintf( + '
      3. ' + . '' + . ' 
      4. ' . "\n", + $name, + $i, + $value, + $checked, + $actions, + $display + ); $i++; } @@ -1290,7 +1438,7 @@ function _checkBoxes($name, $values, $checkedValues, $actions = '') return $result; } - function _radioButtons($name, $values, $checkedValue = null, $actions = '') + public function _radioButtons($name, $values, $checkedValue = null, $actions = '') { $result = ''; @@ -1301,18 +1449,20 @@ function _radioButtons($name, $values, $checkedValue = null, $actions = '') $i = 0; foreach ($values as $value => $display) { $checked = (!is_null($checkedValue) && $value == $checkedValue) ? ' checked="checked"' : ''; - $result .= sprintf('
      5. ' - .'' - .' 
      6. '."\n", - $name, - $i, - $value, - $checked, - $actions, - $display); + $result .= sprintf( + '
      7. ' + . '' + . ' 
      8. ' . "\n", + $name, + $i, + $value, + $checked, + $actions, + $display + ); $i++; } @@ -1329,7 +1479,7 @@ function _radioButtons($name, $values, $checkedValue = null, $actions = '') * @author ? * @deprecated */ - function _genID($name, $fulltag = true) + public function _genID($name, $fulltag = true) { return $fulltag ? 'id="' . htmlspecialchars($name) . '"' : $name; } @@ -1342,12 +1492,12 @@ function _genID($name, $fulltag = true) * @return string html representing an attribute with action script as value, * or and empty string, if the action is to happen window.onload */ - function _genActionScript($form, $action, $varname) + public function _genActionScript($form, $action, $varname) { $html = ''; $triggers = $action->getTrigger(); if (!is_array($triggers)) { - $triggers = array($triggers); + $triggers = [$triggers]; } $js = $action->getActionScript($form, $this, $varname); foreach ($triggers as $trigger) { @@ -1368,7 +1518,7 @@ function _genActionScript($form, $action, $varname) * @return string html representing attributes with action script as values, * or and empty string, if the actions are all to happen window.onload */ - function _getActionScripts($form, $var) + public function _getActionScripts($form, $var) { $actions = ''; if ($var->hasAction()) { @@ -1376,7 +1526,7 @@ function _getActionScripts($form, $var) $action = &$var->_action; $triggers = $action->getTrigger(); if (!is_array($triggers)) { - $triggers = array($triggers); + $triggers = [$triggers]; } $js = $action->getActionScript($form, $this, $varname); foreach ($triggers as $trigger) { diff --git a/lib/Horde/Model/Translation.php b/lib/Horde/Model/Translation.php index a6a3ac4..cfde1a5 100644 --- a/lib/Horde/Model/Translation.php +++ b/lib/Horde/Model/Translation.php @@ -1,8 +1,9 @@ assertIsArray($info); + $this->assertArrayHasKey('decimal_point', $info); + $this->assertArrayHasKey('thousands_sep', $info); + $this->assertArrayHasKey('mon_decimal_point', $info); + $this->assertArrayHasKey('mon_thousands_sep', $info); + } + + public function testPsr4GetLocaleInfoReturnsExpectedKeys(): void + { + $nls = new Nls(); + $info = $nls->getLocaleInfo(); + + $this->assertIsArray($info); + $this->assertArrayHasKey('decimal_point', $info); + $this->assertArrayHasKey('thousands_sep', $info); + $this->assertArrayHasKey('mon_decimal_point', $info); + $this->assertArrayHasKey('mon_thousands_sep', $info); + } + + public function testBothReturnSameValues(): void + { + $legacy = Horde_Nls::getLocaleInfo(); + $psr4 = (new Nls())->getLocaleInfo(); + + $this->assertEquals($legacy['decimal_point'], $psr4['decimal_point']); + $this->assertEquals($legacy['thousands_sep'], $psr4['thousands_sep']); + $this->assertEquals($legacy['mon_decimal_point'], $psr4['mon_decimal_point']); + $this->assertEquals($legacy['mon_thousands_sep'], $psr4['mon_thousands_sep']); + } +} diff --git a/www/test.php b/www/test.php index 9dd1d36..953430e 100644 --- a/www/test.php +++ b/www/test.php @@ -11,31 +11,31 @@ $horde_base = '/var/www/h4'; require_once $horde_base . '/lib/Application.php'; -Horde_Registry::appInit('horde', array('authentication' => 'none')); +Horde_Registry::appInit('horde', ['authentication' => 'none']); $vars = Horde_Variables::getDefaultVariables(); $vars->set('example_bar', 'text with a beginning and an end'); $form = new Horde_Core_Form($vars, 'Horde_Form Test'); -$choices = array('big' => 'BIG', - 'small' => 'small', - 'other' => 'Other'); -$form->add('condchoices', 'Enum', _("Select something"), '', true, false, array($choices, true)); +$choices = ['big' => 'BIG', + 'small' => 'small', + 'other' => 'Other']; +$form->add('condchoices', 'Enum', _("Select something"), '', true, false, [$choices, true]); $o = $form->add('other_text', 'String', _("If other, please describe"), '', false); -$params = array('target' => 'condchoices', - 'enabled' => true, - 'values' => array('other')); +$params = ['target' => 'condchoices', + 'enabled' => true, + 'values' => ['other']]; $o->setAction(new Horde_Form_Action_ConditionalEnable($params)); $form->add('color', 'Color', _("Color"), null, false); $vars->set('form', 'add'); -$enum = array('' => _("Select:"), - 1 => _("Yes"), - 0 => _("No")); -$form->add('opciones', 'Enum', _("Simple description"), '', true, false, array($enum)); +$enum = ['' => _("Select:"), + 1 => _("Yes"), + 0 => _("No")]; +$form->add('opciones', 'Enum', _("Simple description"), '', true, false, [$enum]); $form->add('bool', 'Boolean', _("Boolean")); $form->add('number', 'Int', _("Integer")); $form->add('mybday', 'date', _("A Date"), '', false); @@ -44,22 +44,22 @@ $form->add('password', 'password', _("Password")); $form->addHidden('example_hidden', 'int', false); $form->add('some_text', 'String', _("Insert some text"), _("Insert some text in this box"), false); -$choices = array('big' => 'BIG', - 'small' => 'small', - 'mixed' => 'mIxED'); -$form->add('choices', 'enum', _("Select something2"), 'Use the selection box to make your choice', true, false, array($choices, true)); +$choices = ['big' => 'BIG', + 'small' => 'small', + 'mixed' => 'mIxED']; +$form->add('choices', 'enum', _("Select something2"), 'Use the selection box to make your choice', true, false, [$choices, true]); $form->add('email_address', 'email', _("Email")); $form->add('email_address2', 'emailconfirm', _("Email2")); $form->add('a_creditcard', 'creditcard', _("Credit Card")); $form->add('a_password', 'password', _("Password")); $form->add('a_password2', 'passwordconfirm', _("Password with confirmation"), _("type the password twice to confirm")); $form->add('a_octal', 'Octal', _("Octal"), false); -$form->add('a_radiogroup', 'set', _("Radio Group"), '', true, false, array($choices)); +$form->add('a_radiogroup', 'set', _("Radio Group"), '', true, false, [$choices]); -$t = $form->add('example_bar', 'String', _("Bar field"), _("You have to fill in some long text here"), true, false, array(4, 40)); -$t->setAction(new Horde_Form_Action_setcursorpos(array(4))); +$t = $form->add('example_bar', 'String', _("Bar field"), _("You have to fill in some long text here"), true, false, [4, 40]); +$t->setAction(new Horde_Form_Action_setcursorpos([4])); -$form->add('a_checkboxgroup', 'set', _("Checkbox Group"), '', false, false, array($choices)); +$form->add('a_checkboxgroup', 'set', _("Checkbox Group"), '', false, false, [$choices]); //$form->add('a_obrowser', 'obrowser', _("obrowser")); ?>