From 6d504dc07fcde21fe1cf0d1ce769b644be447a47 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 19 Jul 2010 08:38:28 +0000 Subject: [PATCH] MDL-19698 deprecated assign new by ref in QuickForms --- lib/pear/HTML/QuickForm/RuleRegistry.php | 26 +++++----- lib/pear/HTML/QuickForm/date.php | 26 +++++----- lib/pear/HTML/QuickForm/group.php | 46 +++++++++--------- lib/pear/HTML/QuickForm/hierselect.php | 60 ++++++++++++------------ lib/pear/README_MOODLE.txt | 6 ++- 5 files changed, 84 insertions(+), 80 deletions(-) diff --git a/lib/pear/HTML/QuickForm/RuleRegistry.php b/lib/pear/HTML/QuickForm/RuleRegistry.php index 9bb849e20ef..6e65362e812 100644 --- a/lib/pear/HTML/QuickForm/RuleRegistry.php +++ b/lib/pear/HTML/QuickForm/RuleRegistry.php @@ -38,7 +38,7 @@ class HTML_QuickForm_RuleRegistry * Returns a singleton of HTML_QuickForm_RuleRegistry * * Usually, only one RuleRegistry object is needed, this is the reason - * why it is recommended to use this method to get the validation object. + * why it is recommended to use this method to get the validation object. * * @access public * @static @@ -115,7 +115,7 @@ class HTML_QuickForm_RuleRegistry if (!empty($path)) { include_once($path); } - $this->_rules[$class] =& new $class(); + $this->_rules[$class] = new $class(); } $this->_rules[$class]->setName($ruleName); return $this->_rules[$class]; @@ -125,7 +125,7 @@ class HTML_QuickForm_RuleRegistry * Performs validation on the given values * * @param string $ruleName Name of the rule to be used - * @param mixed $values Can be a scalar or an array of values + * @param mixed $values Can be a scalar or an array of values * to be validated * @param mixed $options Options used by the rule * @param mixed $multiple Whether to validate an array of values altogether @@ -176,21 +176,21 @@ class HTML_QuickForm_RuleRegistry $jsField = isset($ruleData['group'])? $ruleData['group']: $elementName; list ($jsPrefix, $jsCheck) = $rule->getValidationScript($ruleData['format']); if (!isset($ruleData['howmany'])) { - $js = $jsValue . "\n" . $jsPrefix . + $js = $jsValue . "\n" . $jsPrefix . " if (" . str_replace('{jsVar}', 'value', $jsCheck) . " && !errFlag['{$jsField}']) {\n" . " errFlag['{$jsField}'] = true;\n" . " _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" . $jsReset . " }\n"; } else { - $js = $jsValue . "\n" . $jsPrefix . + $js = $jsValue . "\n" . $jsPrefix . " var res = 0;\n" . " for (var i = 0; i < value.length; i++) {\n" . " if (!(" . str_replace('{jsVar}', 'value[i]', $jsCheck) . ")) {\n" . " res++;\n" . " }\n" . - " }\n" . - " if (res < {$ruleData['howmany']} && !errFlag['{$jsField}']) {\n" . + " }\n" . + " if (res < {$ruleData['howmany']} && !errFlag['{$jsField}']) {\n" . " errFlag['{$jsField}'] = true;\n" . " _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" . $jsReset . @@ -201,8 +201,8 @@ class HTML_QuickForm_RuleRegistry /** - * Returns JavaScript to get and to reset the element's value - * + * Returns JavaScript to get and to reset the element's value + * * @access private * @param object HTML_QuickForm_element element being processed * @param string element's name @@ -228,7 +228,7 @@ class HTML_QuickForm_RuleRegistry " var valueIdx = 0;\n" . " for (var i = 0; i < frm.elements.length; i++) {\n" . " var _element = frm.elements[i];\n" . - " if (_element.name in _qfGroups['{$elementName}']) {\n" . + " if (_element.name in _qfGroups['{$elementName}']) {\n" . " switch (_element.type) {\n" . " case 'checkbox':\n" . " case 'radio':\n" . @@ -262,7 +262,7 @@ class HTML_QuickForm_RuleRegistry $tmp_reset = " for (var i = 0; i < frm.elements.length; i++) {\n" . " var _element = frm.elements[i];\n" . - " if (_element.name in _qfGroups['{$elementName}']) {\n" . + " if (_element.name in _qfGroups['{$elementName}']) {\n" . " switch (_element.type) {\n" . " case 'checkbox':\n" . " case 'radio':\n" . @@ -287,7 +287,7 @@ class HTML_QuickForm_RuleRegistry $value = " value{$jsIndex} = new Array();\n" . " var valueIdx = 0;\n" . - " for (var i = 0; i < frm.elements['{$elementName}'].options.length; i++) {\n" . + " for (var i = 0; i < frm.elements['{$elementName}'].options.length; i++) {\n" . " if (frm.elements['{$elementName}'].options[i].selected) {\n" . " value{$jsIndex}[valueIdx++] = frm.elements['{$elementName}'].options[i].value;\n" . " }\n" . @@ -296,7 +296,7 @@ class HTML_QuickForm_RuleRegistry $value = " value{$jsIndex} = frm.elements['{$elementName}'].selectedIndex == -1? '': frm.elements['{$elementName}'].options[frm.elements['{$elementName}'].selectedIndex].value;\n"; } if ($reset) { - $tmp_reset .= + $tmp_reset .= " for (var i = 0; i < field.options.length; i++) {\n" . " field.options[i].selected = field.options[i].defaultSelected;\n" . " }\n"; diff --git a/lib/pear/HTML/QuickForm/date.php b/lib/pear/HTML/QuickForm/date.php index 9ece169f418..495e76ebcff 100644 --- a/lib/pear/HTML/QuickForm/date.php +++ b/lib/pear/HTML/QuickForm/date.php @@ -25,10 +25,10 @@ require_once 'HTML/QuickForm/select.php'; /** * Class for a group of elements used to input dates (and times). - * + * * Inspired by original 'date' element but reimplemented as a subclass * of HTML_QuickForm_group - * + * * @author Alexey Borzov * @access public */ @@ -38,7 +38,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group /** * Various options to control the element's display. - * + * * Currently known options are * 'language': date language * 'format': Format of the date, based on PHP's date() function. @@ -64,7 +64,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group * 'emptyOptionValue': The value passed by the empty option. * 'emptyOptionText': The text displayed for the empty option. * 'optionIncrement': Step to increase the option values by (works for 'i' and 's') - * + * * @access private * @var array */ @@ -88,10 +88,10 @@ class HTML_QuickForm_date extends HTML_QuickForm_group /** * Options in different languages - * + * * Note to potential translators: to avoid encoding problems please send * your translations with "weird" letters encoded as HTML Unicode entities - * + * * @access private * @var array */ @@ -259,7 +259,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group /** * Class constructor - * + * * @access public * @param string Element's name * @param mixed Label(s) for an element @@ -331,7 +331,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group case 'Y': $options = $this->_createOptionList( $this->_options['minYear'], - $this->_options['maxYear'], + $this->_options['maxYear'], $this->_options['minYear'] > $this->_options['maxYear']? -1: 1 ); break; @@ -341,7 +341,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group $this->_options['maxYear'], $this->_options['minYear'] > $this->_options['maxYear']? -1: 1 ); - array_walk($options, create_function('&$v,$k','$v = substr($v,-2);')); + array_walk($options, create_function('&$v,$k','$v = substr($v,-2);')); break; case 'h': $options = $this->_createOptionList(1, 12); @@ -376,7 +376,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group $separator .= (' ' == $sign? ' ': $sign); $loadSelect = false; } - + if ($loadSelect) { if (0 < count($this->_elements)) { $this->_separator[] = $separator; @@ -385,7 +385,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group } $separator = ''; // Should we add an empty option to the top of the select? - if (!is_array($this->_options['addEmptyOption']) && $this->_options['addEmptyOption'] || + if (!is_array($this->_options['addEmptyOption']) && $this->_options['addEmptyOption'] || is_array($this->_options['addEmptyOption']) && !empty($this->_options['addEmptyOption'][$sign])) { // Using '+' array operator to preserve the keys @@ -395,7 +395,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group $options = array($this->_options['emptyOptionValue'] => $this->_options['emptyOptionText']) + $options; } } - $this->_elements[] =& new HTML_QuickForm_select($sign, null, $options, $this->getAttributes()); + $this->_elements[] = new HTML_QuickForm_select($sign, null, $options, $this->getAttributes()); } } } @@ -463,7 +463,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group function toHtml() { include_once('HTML/QuickForm/Renderer/Default.php'); - $renderer =& new HTML_QuickForm_Renderer_Default(); + $renderer = new HTML_QuickForm_Renderer_Default(); $renderer->setElementTemplate('{element}'); parent::accept($renderer); return $this->_wrap[0] . $renderer->toHtml() . $this->_wrap[1]; diff --git a/lib/pear/HTML/QuickForm/group.php b/lib/pear/HTML/QuickForm/group.php index f24fe37cc0a..229d6979e84 100644 --- a/lib/pear/HTML/QuickForm/group.php +++ b/lib/pear/HTML/QuickForm/group.php @@ -23,7 +23,7 @@ require_once("HTML/QuickForm/element.php"); /** * HTML class for a form element group - * + * * @author Adam Daniel * @author Bertrand Mansion * @version 1.0 @@ -33,7 +33,7 @@ require_once("HTML/QuickForm/element.php"); class HTML_QuickForm_group extends HTML_QuickForm_element { // {{{ properties - + /** * Name of the element * @var string @@ -67,7 +67,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element var $_required = array(); /** - * Whether to change elements' names to $groupName[$elementName] or leave them as is + * Whether to change elements' names to $groupName[$elementName] or leave them as is * @var bool * @since 3.0 * @access private @@ -79,14 +79,14 @@ class HTML_QuickForm_group extends HTML_QuickForm_element /** * Class constructor - * + * * @param string $elementName (optional)Group name * @param array $elementLabel (optional)Group label * @param array $elements (optional)Group elements * @param mixed $separator (optional)Use a string for one separator, * use an array to alternate the separators. * @param bool $appendName (optional)whether to change elements' names to - * the form $groupName[$elementName] or leave + * the form $groupName[$elementName] or leave * them as is. * @since 1.0 * @access public @@ -106,13 +106,13 @@ class HTML_QuickForm_group extends HTML_QuickForm_element $this->_appendName = $appendName; } } //end constructor - + // }}} // {{{ setName() /** * Sets the group name - * + * * @param string $name Group name * @since 1.0 * @access public @@ -122,13 +122,13 @@ class HTML_QuickForm_group extends HTML_QuickForm_element { $this->_name = $name; } //end func setName - + // }}} // {{{ getName() /** * Returns the group name - * + * * @since 1.0 * @access public * @return string @@ -143,7 +143,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element /** * Sets values for group's elements - * + * * @param mixed Values for group's elements * @since 1.0 * @access public @@ -172,7 +172,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element } } } //end func setValue - + // }}} // {{{ getValue() @@ -189,10 +189,10 @@ class HTML_QuickForm_group extends HTML_QuickForm_element foreach (array_keys($this->_elements) as $key) { $element =& $this->_elements[$key]; switch ($element->getType()) { - case 'radio': + case 'radio': $v = $element->getChecked()? $element->getValue(): null; break; - case 'checkbox': + case 'checkbox': $v = $element->getChecked()? true: null; break; default: @@ -282,7 +282,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element /** * Returns Html for the group - * + * * @since 1.0 * @access public * @return string @@ -290,18 +290,18 @@ class HTML_QuickForm_group extends HTML_QuickForm_element function toHtml() { include_once('HTML/QuickForm/Renderer/Default.php'); - $renderer =& new HTML_QuickForm_Renderer_Default(); + $renderer = new HTML_QuickForm_Renderer_Default(); $renderer->setElementTemplate('{element}'); $this->accept($renderer); return $renderer->toHtml(); } //end func toHtml - + // }}} // {{{ getElementName() /** * Returns the element name inside the group such as found in the html form - * + * * @param mixed $index Element name or element index in the group * @since 3.0 * @access public @@ -345,7 +345,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element /** * Returns the value of field without HTML tags - * + * * @since 1.3 * @access public * @return string @@ -420,7 +420,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element * @param bool Whether a group is required * @param string An error message associated with a group * @access public - * @return void + * @return void */ function accept(&$renderer, $required = false, $error = null) { @@ -429,7 +429,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element $name = $this->getName(); foreach (array_keys($this->_elements) as $key) { $element =& $this->_elements[$key]; - + if ($this->_appendName) { $elementName = $element->getName(); if (isset($elementName)) { @@ -505,12 +505,12 @@ class HTML_QuickForm_group extends HTML_QuickForm_element /** * Creates the group's elements. - * - * This should be overriden by child classes that need to create their + * + * This should be overriden by child classes that need to create their * elements. The method will be called automatically when needed, calling * it from the constructor is discouraged as the constructor is usually * called _twice_ on element creation, first time with _no_ parameters. - * + * * @access private * @abstract */ diff --git a/lib/pear/HTML/QuickForm/hierselect.php b/lib/pear/HTML/QuickForm/hierselect.php index 8c0f31eb24c..25de46686df 100644 --- a/lib/pear/HTML/QuickForm/hierselect.php +++ b/lib/pear/HTML/QuickForm/hierselect.php @@ -36,7 +36,7 @@ require_once('HTML/QuickForm/select.php'); * @access public */ class HTML_QuickForm_hierselect extends HTML_QuickForm_group -{ +{ // {{{ properties /** @@ -59,7 +59,7 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group * $select2[2][0] = 'Pantheist'; * $select2[2][1] = 'Skepticism'; * - * // If only need two selects + * // If only need two selects * // - and using the depracated functions * $sel =& $form->addElement('hierselect', 'cds', 'Choose CD:'); * $sel->setMainOptions($select1); @@ -77,12 +77,12 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group * // You can now use * $sel =& $form->addElement('hierselect', 'cds', 'Choose CD:'); * $sel->setOptions(array($select1, $select2, $select3)); - * + * * @var array * @access private */ var $_options = array(); - + /** * Number of select elements on this group * @@ -104,10 +104,10 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group /** * Class constructor - * + * * @param string $elementName (optional)Input field name attribute * @param string $elementLabel (optional)Input field label in form - * @param mixed $attributes (optional)Either a typical HTML attribute string + * @param mixed $attributes (optional)Either a typical HTML attribute string * or an associative array. Date format is passed along the attributes. * @param mixed $separator (optional)Use a string for one separator, * use an array to alternate the separators. @@ -149,17 +149,17 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group // check if all elements have been created $totalNbElements = count($this->_options); for ($i = $this->_nbElements; $i < $totalNbElements; $i ++) { - $this->_elements[] =& new HTML_QuickForm_select($i, null, array(), $this->getAttributes()); + $this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes()); $this->_nbElements++; } } - + $this->_setOptions(); } // end func setMainOptions // }}} // {{{ setMainOptions() - + /** * Sets the options for the first select element. Deprecated. setOptions() should be used. * @@ -178,10 +178,10 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group $this->_createElements(); } } // end func setMainOptions - + // }}} // {{{ setSecOptions() - + /** * Sets the options for the second select element. Deprecated. setOptions() should be used. * The main _options array is initialized and the _setOptions function is called. @@ -204,17 +204,17 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group // check if all elements have been created $totalNbElements = 2; for ($i = $this->_nbElements; $i < $totalNbElements; $i ++) { - $this->_elements[] =& new HTML_QuickForm_select($i, null, array(), $this->getAttributes()); + $this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes()); $this->_nbElements++; } } - + $this->_setOptions(); } // end func setSecOptions - + // }}} // {{{ _setOptions() - + /** * Sets the options for each select element * @@ -236,13 +236,13 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group } } } // end func _setOptions - + // }}} // {{{ setValue() /** * Sets values for group's elements - * + * * @param array $value An array of 2 or more values, for the first, * the second, the third etc. select * @@ -251,27 +251,27 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group */ function setValue($value) { - // fix for bug #6766. Hope this doesn't break anything more + // fix for bug #6766. Hope this doesn't break anything more // after bug #7961. Forgot that _nbElements was used in - // _createElements() called in several places... + // _createElements() called in several places... $this->_nbElements = max($this->_nbElements, count($value)); parent::setValue($value); $this->_setOptions(); } // end func setValue - + // }}} // {{{ _createElements() /** * Creates all the elements for the group - * + * * @access private * @return void */ function _createElements() { for ($i = 0; $i < $this->_nbElements; $i++) { - $this->_elements[] =& new HTML_QuickForm_select($i, null, array(), $this->getAttributes()); + $this->_elements[] = new HTML_QuickForm_select($i, null, array(), $this->getAttributes()); } } // end func _createElements @@ -292,7 +292,7 @@ class HTML_QuickForm_hierselect extends HTML_QuickForm_group array('onchange' => '_hs_swapOptions(this.form, \'' . $this->_escapeString($this->getName()) . '\', ' . $keys[$i] . ');' . $onChange[$i]) ); } - + // create the js function to call if (!defined('HTML_QUICKFORM_HIERSELECT_EXISTS')) { $this->_js .= <<_convertArrayToJavascript($values, false) . ";\n"; } include_once('HTML/QuickForm/Renderer/Default.php'); - $renderer =& new HTML_QuickForm_Renderer_Default(); + $renderer = new HTML_QuickForm_Renderer_Default(); $renderer->setElementTemplate('{element}'); parent::accept($renderer); @@ -524,7 +524,7 @@ JAVASCRIPT; $js = implode(', ', $items); return $assoc? '{ ' . $js . ' }': '[' . $js . ']'; } - + // }}} // {{{ _convertScalarToJavascript() @@ -555,7 +555,7 @@ JAVASCRIPT; // {{{ _escapeString() /** - * Quotes the string so that it can be used in Javascript string constants + * Quotes the string so that it can be used in Javascript string constants * * @access private * @param string diff --git a/lib/pear/README_MOODLE.txt b/lib/pear/README_MOODLE.txt index 7268819ae25..423db10a804 100644 --- a/lib/pear/README_MOODLE.txt +++ b/lib/pear/README_MOODLE.txt @@ -18,7 +18,7 @@ and documented for Moodle at: * http://cvs.moodle.org/moodle/lib/excel/Parser.php.diff?r1=1.1&r2=1.2 * http://cvs.moodle.org/moodle/lib/excel/Worksheet.php.diff?r1=1.1&r2=1.2 -Such modifications should be carefuly each time the Excel PEAR package is updated +Such modifications should be carefully each time the Excel PEAR package is updated to a new release within Moodle. XML/Parser @@ -37,3 +37,7 @@ To run the codesniffer, you can call the runsniffer script using your command-li Example: /usr/bin/php lib/pear/PHP/runsniffer mod/forum +Quickforms +========== +Full of our custom hacks, no way to upgrade to latest upstream. +Most probably we will stop using this library in the future.