From 49c8c8d27ef95f2554aab0bc484ed79530adad14 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Tue, 4 Aug 2009 02:05:32 +0000 Subject: [PATCH] MDL-19976 Refactored select_menu() into select(), now supporting menu, radio and checkbox rendering. Added radio() and checkbox() functions. --- course/category.php | 12 +- course/report/participation/index.php | 12 +- course/search.php | 12 +- files/index.php | 11 +- grade/edit/tree/index.php | 14 +- grade/edit/tree/lib.php | 12 +- lib/deprecatedlib.php | 179 ++++++++++---- lib/javascript-static.js | 16 +- lib/outputlib.php | 343 ++++++++++++++++++-------- lib/simpletest/testoutputlib.php | 16 +- lib/weblib.php | 175 +++---------- mod/choice/lib.php | 14 +- mod/feedback/analysis_course.php | 12 +- mod/lesson/report.php | 12 +- mod/scorm/locallib.php | 12 +- mod/scorm/report.php | 14 +- mod/wiki/admin.php | 12 +- mod/wiki/view.php | 12 +- user/index.php | 12 +- 19 files changed, 504 insertions(+), 398 deletions(-) diff --git a/course/category.php b/course/category.php index 0f79b1af92..171d6d9a76 100644 --- a/course/category.php +++ b/course/category.php @@ -406,12 +406,12 @@ make_categories_list($movetocategories, $notused, 'moodle/category:manage'); $movetocategories[$category->id] = get_string('moveselectedcoursesto'); echo ''; - $selectmenu = new moodle_select_menu(); - $selectmenu->options = $movetocategories; - $selectmenu->name = 'moveto'; - $selectmenu->selectedvalue = $category->id; - $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'movecourses')); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = $movetocategories; + $select->name = 'moveto'; + $select->selectedvalue = $category->id; + $select->add_action('change', 'submit_form_by_id', array('id' => 'movecourses')); + echo $OUTPUT->select($select); echo ''; echo ''; } diff --git a/course/report/participation/index.php b/course/report/participation/index.php index f376a08b41..26a2dc6aac 100644 --- a/course/report/participation/index.php +++ b/course/report/participation/index.php @@ -273,12 +273,12 @@ echo ''."\n"; } $displaylist['messageselect.php'] = get_string('messageselectadd'); - $selectmenu = new moodle_select_menu(); - $selectmenu->options = $displaylist; - $selectmenu->name = "formaction"; - $selectmenu->label = get_string("withselectedusers"); - $selectmenu->add_action('change', 'conditionalsubmit', array('formid' => 'studentsform')); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = $displaylist; + $select->name = "formaction"; + $select->label = get_string("withselectedusers"); + $select->add_action('change', 'conditionalsubmit', array('formid' => 'studentsform')); + echo $OUTPUT->select($select); helpbutton("participantswithselectedusers", get_string("withselectedusers")); echo ''."\n"; echo ''."\n"; diff --git a/course/search.php b/course/search.php index 0762d67c9f..15d401ed90 100644 --- a/course/search.php +++ b/course/search.php @@ -309,12 +309,12 @@ echo "
"; echo "\n"; echo "\n"; - $selectmenu = new moodle_select_menu(); - $selectmenu->options = $displaylist; - $selectmenu->name = "moveto"; - $selectmenu->label = get_string("moveselectedcoursesto"); - $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'movecourses')); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = $displaylist; + $select->name = "moveto"; + $select->label = get_string("moveselectedcoursesto"); + $select->add_action('change', 'submit_form_by_id', array('id' => 'movecourses')); + echo $OUTPUT->select($select); echo "\n\n"; echo "\n"; diff --git a/files/index.php b/files/index.php index 7e1d733e1a..77b486b0fb 100644 --- a/files/index.php +++ b/files/index.php @@ -46,7 +46,7 @@ if ($courseid) { if (!$context = get_context_instance(CONTEXT_COURSE, $course->id)) { print_error('invalidcontext'); } - redirect('index.php?contextid='.$context->id.'&itemid=0&filearea=course_content'); + redirect(new moodle_url('index.php', array('contextid' => $context->id, 'itemid'=> 0, 'filearea' => 'course_content'))); } if (!$context = get_context_instance_by_id($contextid)) { @@ -82,8 +82,7 @@ $file_info = $browser->get_file_info($context, $filearea, $itemid, $filepath, $f if ($file_info and $file_info->is_directory() and $file_info->is_writable() and $newdirname !== '' and data_submitted() and confirm_sesskey()) { if ($newdir_info = $file_info->create_directory($newdirname, $USER->id)) { $params = $newdir_info->get_params_rawencoded(); - $params = implode('&', $params); - redirect("index.php?$params"); + redirect(new moodle_url('index.php', $params)); } else { $error = "Could not create new dir"; // TODO: localise } @@ -96,8 +95,7 @@ if ($file_info and $file_info->is_directory() and $file_info->is_writable() and try { if ($newfile = $file_info->create_file_from_pathname($newfilename, $_FILES['newfile']['tmp_name'], $USER->id)) { $params = $file_info->get_params_rawencoded(); - $params = implode('&', $params); - redirect("index.php?$params"); + redirect(new moodle_url('index.php', $params)); } else { $error = "Could not create upload file"; // TODO: localise @@ -129,8 +127,7 @@ if ($file_info and $delete) { $error = "Could not delete file!"; // TODO: localise } $params = $parent_info->get_params_rawencoded(); - $params = implode('&', $params); - redirect("index.php?$params", $error); + redirect(new moodle_url('index.php', $params)); } } diff --git a/grade/edit/tree/index.php b/grade/edit/tree/index.php index 7b71f6f536..879e42b6eb 100644 --- a/grade/edit/tree/index.php +++ b/grade/edit/tree/index.php @@ -309,13 +309,13 @@ if (!$moving && count($categories) > 1) { echo '

'; echo ''; echo get_string('moveselectedto', 'grades') . ' '; - $selectmenu = new moodle_select_menu(); - $selectmenu->options = $categories; - $selectmenu->name = 'moveafter'; - $selectmenu->disabled = true; - $selectmenu->id = 'menumoveafter'; - $selectmenu->add_action('change', 'submit_bulk_move'); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = $categories; + $select->name = 'moveafter'; + $select->disabled = true; + $select->id = 'menumoveafter'; + $select->add_action('change', 'submit_bulk_move'); + echo $OUTPUT->select($select); echo '
'; diff --git a/grade/edit/tree/lib.php b/grade/edit/tree/lib.php index c1b71e34ac..551b9d7034 100755 --- a/grade/edit/tree/lib.php +++ b/grade/edit/tree/lib.php @@ -564,12 +564,12 @@ class grade_edit_tree_column_aggregation extends grade_edit_tree_column_category } } - $selectmenu = new moodle_select_menu(); - $selectmenu->options = $options; - $selectmenu->name = 'aggregation_'.$category->id; - $selectmenu->selectedvalue = $category->aggregation; - $selectmenu->add_action('change', 'update_category_aggregation', array('courseid' => $params['id'], 'category' => $category->id, 'sesskey' => sesskey())); - $aggregation = $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = $options; + $select->name = 'aggregation_'.$category->id; + $select->selectedvalue = $category->aggregation; + $select->add_action('change', 'update_category_aggregation', array('courseid' => $params['id'], 'category' => $category->id, 'sesskey' => sesskey())); + $aggregation = $OUTPUT->select($select); if ($this->forced) { $aggregation = $options[$category->aggregation]; diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 9735870e4b..60c42b09ff 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2634,7 +2634,7 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus } $output = $OUTPUT->button($form); - + $icon = new action_icon(); if ($return) { @@ -3080,29 +3080,29 @@ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $sc $id='', $listbox=false, $multiple=false, $class='') { global $OUTPUT; - // debugging('choose_from_menu() has been deprecated. Please change your code to use $OUTPUT->select_menu($selectmenu).'); + // debugging('choose_from_menu() has been deprecated. Please change your code to use $OUTPUT->select($select).'); if ($script) { debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER); } - $selectmenu = new moodle_select_menu(); - $selectmenu->options = $options; - $selectmenu->name = $name; - $selectmenu->selectedvalue = $selected; - $selectmenu->nothinglabel = $nothing; - $selectmenu->nothingvalue = $nothingvalue; - $selectmenu->disabled = $disabled; - $selectmenu->tabindex = $tabindex; - $selectmenu->id = $id; - $selectmenu->listbox = $listbox; - $selectmenu->multiple = $multiple; - $selectmenu->add_classes($class); + $select = new moodle_select(); + $select->options = $options; + $select->name = $name; + $select->selectedvalue = $selected; + $select->nothinglabel = $nothing; + $select->nothingvalue = $nothingvalue; + $select->disabled = $disabled; + $select->tabindex = $tabindex; + $select->id = $id; + $select->listbox = $listbox; + $select->multiple = $multiple; + $select->add_classes($class); if ($nothing == 'choose') { - $selectmenu->nothinglabel = ''; + $select->nothinglabel = ''; } - $output = $OUTPUT->select_menu($selectmenu); + $output = $OUTPUT->select($select); if ($return) { return $output; @@ -3130,17 +3130,17 @@ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $sc */ function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) { - // debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use $OUTPUT->select_menu($selectmenu).'); + // debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use $OUTPUT->select($select).'); global $OUTPUT; if ($script) { debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER); } - $selectmenu = moodle_select_menu::make_yes_no($name, $selected); - $selectmenu->disabled = $disabled; - $selectmenu->tabindex = $tabindex; - $output = $OUTPUT->select_menu($select_menu); + $select = moodle_select::make_yes_no($name, $selected); + $select->disabled = $disabled; + $select->tabindex = $tabindex; + $output = $OUTPUT->select($select); if ($return) { return $output; @@ -3177,23 +3177,23 @@ function choose_from_menu_yesno($name, $selected, $script = '', function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '', $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) { - // debugging('choose_from_menu_nested() has been deprecated. Please change your code to use $OUTPUT->select_menu($selectmenu).'); + // debugging('choose_from_menu_nested() has been deprecated. Please change your code to use $OUTPUT->select($select).'); global $OUTPUT; if ($script) { debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER); } - $selectmenu = moodle_select_menu::make($options, $name, $selected); - $selectmenu->tabindex = $tabindex; - $selectmenu->disabled = $disabled; - $selectmenu->nothingvalue = $nothingvalue; - $selectmenu->nested = true; + $select = moodle_select::make($options, $name, $selected); + $select->tabindex = $tabindex; + $select->disabled = $disabled; + $select->nothingvalue = $nothingvalue; + $select->nested = true; if ($nothing == 'choose') { - $selectmenu->nothinglabel = ''; + $select->nothinglabel = ''; } - $output = $OUTPUT->select_menu($selectmenu); + $output = $OUTPUT->select($select); if ($return) { return $output; @@ -3214,7 +3214,7 @@ function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$ * @return string|bool Depending on value of $return */ function print_scale_menu_helpbutton($courseid, $scale, $return=false) { - // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_button($scaleselectmenu).'); + // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_button($scaleselect).'); global $OUTPUT; $helpbutton = help_button::make_scale_menu($courseid, $scale); @@ -3245,7 +3245,7 @@ function print_scale_menu_helpbutton($courseid, $scale, $return=false) { * @return string|bool Depending on value of $return */ function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) { - throw new coding_exception('print_timer_selector is completely deprecated. Please use $OUTPUT->select_menu($selectmenu) instead'); + throw new coding_exception('print_timer_selector is completely deprecated. Please use $OUTPUT->select($select) instead'); } /** @@ -3261,12 +3261,12 @@ function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $ * @return string|bool Depending on value of $return */ function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) { - // debugging('print_time_selector() has been deprecated. Please change your code to use $OUTPUT->select_menu($timeselector).'); + // debugging('print_time_selector() has been deprecated. Please change your code to use $OUTPUT->select($timeselector).'); global $OUTPUT; - $hourselector = moodle_select_menu::make_time_selector('hours', $hour, $currenttime); - $minuteselector = moodle_select_menu::make_time_selector('minutes', $minute, $currenttime, $step); + $hourselector = moodle_select::make_time_selector('hours', $hour, $currenttime); + $minuteselector = moodle_select::make_time_selector('minutes', $minute, $currenttime, $step); - $output = $OUTPUT->select_menu($hourselector) . $OUTPUT->select_menu($minuteselector); + $output = $OUTPUT->select($hourselector) . $OUTPUT->select($minuteselector); if ($return) { return $output; @@ -3289,14 +3289,14 @@ function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=fa */ function print_date_selector($day, $month, $year, $currenttime=0, $return=false) { - // debugging('print_date_selector() has been deprecated. Please change your code to use $OUTPUT->select_menu($dateselector).'); + // debugging('print_date_selector() has been deprecated. Please change your code to use $OUTPUT->select($dateselector).'); global $OUTPUT; - $dayselector = moodle_select_menu::make_time_selector('days', $day, $currenttime); - $monthselector = moodle_select_menu::make_time_selector('months', $month, $currenttime); - $yearselector = moodle_select_menu::make_time_selector('years', $year, $currenttime); + $dayselector = moodle_select::make_time_selector('days', $day, $currenttime); + $monthselector = moodle_select::make_time_selector('months', $month, $currenttime); + $yearselector = moodle_select::make_time_selector('years', $year, $currenttime); - $output = $OUTPUT->select_menu($dayselector) . $OUTPUT->select_menu($monthselector) . $OUTPUT->select_menu($yearselector); + $output = $OUTPUT->select($dayselector) . $OUTPUT->select($monthselector) . $OUTPUT->select($yearselector); if ($return) { return $output; @@ -3337,7 +3337,7 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose' $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) { global $OUTPUT; - // debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->select_menu($dateselector).'); + // debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->select($dateselector).'); if (!empty($optionsextra)) { debugging('the optionsextra param has been deprecated in popup_form, it will be ignored.', DEBUG_DEVELOPER); @@ -3346,25 +3346,25 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose' if (empty($options)) { return ''; } - $selectmenu = moodle_select_menu::make_popup_form($baseurl, $options, $formid, $submitvalue, $selected); - $selectmenu->disabled = $disabled; - + $select = moodle_select::make_popup_form($baseurl, $options, $formid, $submitvalue, $selected); + $select->disabled = $disabled; + // Extract the last param of the baseurl for the name of the select if (preg_match('/([a-z_]*)=$/', $baseurl, $matches)) { - $selectmenu->name = $matches[1]; - $selectmenu->form->url->remove_params(array($matches[1])); + $select->name = $matches[1]; + $select->form->url->remove_params(array($matches[1])); } if ($nothing == 'choose') { - $selectmenu->nothinglabel = ''; + $select->nothinglabel = ''; } else { - $selectmenu->nothinglabel = $nothing; + $select->nothinglabel = $nothing; } - $selectmenu->set_label($selectlabel, $selectmenu->id); - $selectmenu->set_help_icon($help, $helptext); + $select->set_label($selectlabel, $select->id); + $select->set_help_icon($help, $helptext); - $output = $OUTPUT->select_menu($selectmenu); + $output = $OUTPUT->select($select); if ($return) { return $output; @@ -3387,13 +3387,86 @@ function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose' */ function close_window_button($name='closewindow', $return=false, $reloadopener = false) { global $OUTPUT; - + // debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().'); $output = $OUTPUT->close_window_button(get_string($name)); - + if ($return) { return $output; } else { echo $output; } } + +/** + * Given an array of values, creates a group of radio buttons to be part of a form + * + * @deprecated since Moodle 2.0 + * + * @staticvar int $idcounter + * @param array $options An array of value-label pairs for the radio group (values as keys) + * @param string $name Name of the radiogroup (unique in the form) + * @param string $checked The value that is already checked + * @param bool $return Whether this function should return a string or output + * it (defaults to false) + * @return string|void If $return=true returns string, else echo's and returns void + */ +function choose_from_radio ($options, $name, $checked='', $return=false) { + + // debugging('choose_from_radio() has been deprecated. Please change your code to use $OUTPUT->select($select).'); + global $OUTPUT; + + $select = moodle_select::make($options, $name, $checked); + $select->rendertype = 'radio'; + + $output = $OUTPUT->select($select); + + if ($return) { + return $output; + } else { + echo $output; + } +} + +/** + * Display an standard html checkbox with an optional label + * + * @deprecated since Moodle 2.0 + * + * @staticvar int $idcounter + * @param string $name The name of the checkbox + * @param string $value The valus that the checkbox will pass when checked + * @param bool $checked The flag to tell the checkbox initial state + * @param string $label The label to be showed near the checkbox + * @param string $alt The info to be inserted in the alt tag + * @param string $script If not '', then this is added to the checkbox element + * as an onchange handler. + * @param bool $return Whether this function should return a string or output + * it (defaults to false) + * @return string|void If $return=true returns string, else echo's and returns void + */ +function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '', $script='',$return=false) { + + // debugging('print_checkbox() has been deprecated. Please change your code to use $OUTPUT->checkbox($checkbox).'); + global $OUTPUT; + + if (!empty($script)) { + debugging('The use of the $script param in print_checkbox has not been migrated into $OUTPUT->checkbox. Please use $checkbox->add_action().', DEBUG_DEVELOPER); + } + + $checkbox = new html_select_option(); + $checkbox->value = $value; + $checkbox->selected = $checked; + $checkbox->text = $label; + $checkbox->label->text = $label; + $checkbox->alt = $alt; + + $output = $OUTPUT->checkbox($checkbox, $name); + + if (empty($return)) { + echo $output; + } else { + return $output; + } + +} diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 2dedac9bda..44221394f7 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -210,15 +210,15 @@ function lockoptionsallsetup(formid) { * submits the form designated by args.id. If args.selectid is also * given, it only submits the form if the selected element. If an optgroup element is detected, * this will recursively output its options as well. * - * @param mixed $option a moodle_select_option or moodle_select_optgroup + * @param mixed $option a html_select_option or moodle_select_optgroup * @return string the HTML for the */ public function select_option($option) { @@ -3278,7 +3379,7 @@ class moodle_core_renderer extends moodle_renderer_base { /// COMPONENTS /** - * Base class for classes representing HTML elements, like moodle_select_menu. + * Base class for classes representing HTML elements, like moodle_select. * * Handles the id and class attributes. * @@ -3291,6 +3392,10 @@ class moodle_html_component { * @var string value to use for the id attribute of this HTML tag. */ public $id = ''; + /** + * @var string $alt value to use for the alt attribute of this HTML tag. + */ + public $alt = ''; /** * @var array class names to add to this HTML element. */ @@ -3413,7 +3518,7 @@ class moodle_html_component { /** * Internal method for generating a unique ID for the purpose of event handlers. */ - protected function generate_id() { + public function generate_id() { // Generate an id that is not already used. do { $newid = get_class($this) . '-' . substr(sha1(microtime() * rand(0, 500)), 0, 6); @@ -3429,12 +3534,43 @@ class moodle_html_component { public function get_actions() { return $this->actions; } + + /** + * Adds a descriptive label to the component. + * + * This can be used in two ways: + * + *
+     * $component->set_label($elementid, $elementlabel);
+     * // OR
+     * $label = new html_label();
+     * $label->for = $elementid;
+     * $label->text = $elementlabel;
+     * $component->set_label($label);
+     * 
+ * + * Use the second form when you need to add additional HTML attributes + * to the label and/or JS actions. + * + * @param mixed $text Either the text of the label or a html_label object + * @param text $for The value of the "for" attribute (the associated element's id) + * @return void + */ + public function set_label($text, $for=null) { + if ($text instanceof html_label) { + $this->label = $text; + } else if (!empty($text)) { + $this->label = new html_label(); + $this->label->for = $for; + $this->label->text = $text; + } + } } /** * This class hold all the information required to describe a '. $value .'' . "\n"; - } else { - $output .= ' /> ' . "\n"; - } - $currentradio = ($currentradio + 1) % 2; - } - } - - $output .= '' . "\n"; - - if ($return) { - return $output; - } else { - echo $output; - } -} - -/** - * Display an standard html checkbox with an optional label - * - * @staticvar int $idcounter - * @param string $name The name of the checkbox - * @param string $value The valus that the checkbox will pass when checked - * @param bool $checked The flag to tell the checkbox initial state - * @param string $label The label to be showed near the checkbox - * @param string $alt The info to be inserted in the alt tag - * @param string $script If not '', then this is added to the checkbox element - * as an onchange handler. - * @param bool $return Whether this function should return a string or output - * it (defaults to false) - * @return string|void If $return=true returns string, else echo's and returns void - */ -function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '', $script='',$return=false) { - - static $idcounter = 0; - - if (!$name) { - $name = 'unnamed'; - } - - if ($alt) { - $alt = strip_tags($alt); - } else { - $alt = 'checkbox'; - } - - if ($checked) { - $strchecked = ' checked="checked"'; - } else { - $strchecked = ''; - } - - $htmlid = 'auto-cb'.sprintf('%04d', ++$idcounter); - $output = '"; - $output .= ''; - if(!empty($label)) { - $output .= ' '; - } - $output .= ''."\n"; - - if (empty($return)) { - echo $output; - } else { - return $output; - } - -} - /** * Display an standard html text field with an optional label * @@ -728,7 +629,7 @@ function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '', * @param string $alt The info to be inserted in the alt tag * @param int $size Sets the size attribute of the field. Defaults to 50 * @param int $maxlength Sets the maxlength attribute of the field. Not set by default - * @param bool $return Whether this function should return a string or output + * @param bool $return Whether this function should return a string or output * it (defaults to false) * @return string|void If $return=true returns string, else echo's and returns void */ @@ -1028,12 +929,12 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL } } return $text.$cmt; - + } /** * Converts the text format from the value to the 'internal' - * name or vice versa. + * name or vice versa. * * $key can either be the value or the name and you get the other back. * @@ -1078,7 +979,7 @@ function reset_text_filters_cache() { remove_dir($purifdir, true); } -/** +/** * Given a simple string, this function returns the string * processed by enabled string filters if $CFG->filterall is enabled * @@ -1160,7 +1061,7 @@ function replace_ampersands_not_followed_by_entity($string) { /** * Given a string, replaces all .* by .* and returns the string. - * + * * @param string $string * @return string */ @@ -1180,13 +1081,13 @@ function wikify_links($string) { /** * Replaces non-standard HTML entities - * + * * @param string $string * @return string */ function fix_non_standard_entities($string) { $text = preg_replace('/(&#[0-9]+)(;?)/', '$1;', $string); - $text = preg_replace('/(&#x[0-9a-fA-F]+)(;?)/', '$1;', $text); + $text = preg_replace('/(&#x[0-9a-fA-F]+)(;?)/', '$1;', $text); return $text; } @@ -1304,8 +1205,8 @@ function trusttext_strip($text) { */ function trusttext_pre_edit($object, $field, $context) { $trustfield = $field.'trust'; - $formatfield = $field.'format'; - + $formatfield = $field.'format'; + if (!$object->$trustfield or !trusttext_trusted($context)) { $object->$field = clean_text($object->$field, $object->$formatfield); } @@ -1322,7 +1223,7 @@ function trusttext_pre_edit($object, $field, $context) { * @return bool true if user trusted */ function trusttext_trusted($context) { - return (trusttext_active() and has_capability('moodle/site:trustcontent', $context)); + return (trusttext_active() and has_capability('moodle/site:trustcontent', $context)); } /** @@ -1335,7 +1236,7 @@ function trusttext_trusted($context) { function trusttext_active() { global $CFG; - return !empty($CFG->enabletrusttext); + return !empty($CFG->enabletrusttext); } /** @@ -2425,7 +2326,7 @@ function print_heading_with_help($text, $helppage, $module='moodle', $icon='', $ /** * Print (or return) a collapisble region, that has a caption that can * be clicked to expand or collapse the region. - * + * * If JavaScript is off, then the region will always be exanded. * * @param string $contents the contents of the box. @@ -2630,7 +2531,7 @@ function _print_custom_corners_end($idbase) { * @uses SITEID * @param object $user A {@link $USER} object representing a user * @param object $course A {@link $COURSE} object representing a course - * @param bool $messageselect + * @param bool $messageselect * @param bool $return If set to true then the HTML is returned rather than echo'd * @return string|void Depending on the setting of $return */ @@ -2821,7 +2722,7 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li /** * Display a recent activity note - * + * * @uses CONTEXT_SYSTEM * @staticvar string $strftimerecent * @param object A time object @@ -3317,8 +3218,8 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid * * @global object * @param int $courseid The course ID - * @param string $name - * @param string $current + * @param string $name + * @param string $current * @param boolean $includenograde Include those with no grades * @param boolean $return If set to true returns rather than echo's * @return string|bool Depending on value of $return @@ -3530,7 +3431,7 @@ function notice ($message, $link='', $course=NULL) { * Good practice: You should call this method before starting page * output by using any of the OUTPUT methods. * - * @param mixed $url either a string URL, or a moodle_url to redirect to + * @param moodle_url $url A moodle_url to redirect to. Strings are not to be trusted! * @param string $message The message to display to the user * @param int $delay The delay before redirecting * @return void @@ -3540,6 +3441,8 @@ function redirect($url, $message='', $delay=-1) { if ($url instanceof moodle_url) { $url = $url->out(false, array(), false); + } else { + debugging("String URLs are not safe in redirect(), please use a moodle_url object.", DEBUG_DEVELOPER); } if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) { @@ -3699,7 +3602,7 @@ function rebuildnolinktag($text) { /** * Prints a maintenance message from $CFG->maintenance_message or default if empty - * @return void + * @return void */ function print_maintenance_message() { global $CFG, $SITE, $PAGE; @@ -3751,9 +3654,9 @@ class tabobject { */ var $linkedwhenselected; - /** + /** * A constructor just because I like constructors - * + * * @param string $id * @param string $link * @param string $text @@ -3883,7 +3786,7 @@ function convert_tree_to_html($tree, $row=0) { * @param string $selected The tabrow to select (by id) * @param array $inactive An array of tabrow id's to make inactive * @param array $activated An array of tabrow id's to make active - * @return array The nested array + * @return array The nested array */ function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) { @@ -4140,7 +4043,7 @@ class progress_bar { } /** * Create a new progress bar, this function will output html. - * + * * @return void Echo's output */ function create(){ diff --git a/mod/choice/lib.php b/mod/choice/lib.php index 5f1db1d42a..b0f9eeefcd 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -544,13 +544,13 @@ function choice_show_results($choice, $course, $cm, $allresponses, $forcepublish echo ''.get_string('selectall', 'quiz').' / '; echo ''.get_string('selectnone', 'quiz').' '; echo '  '; - $selectmenu = new moodle_select_menu(); - $selectmenu->options = array('delete' => get_string('delete')); - $selectmenu->name = 'action'; - $selectmenu->button->label = get_string('withselected', 'quiz'); - $selectmenu->id = 'menuaction'; - $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction')); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = array('delete' => get_string('delete')); + $select->name = 'action'; + $select->button->label = get_string('withselected', 'quiz'); + $select->id = 'menuaction'; + $select->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction')); + echo $OUTPUT->select($select); echo ''; diff --git a/mod/feedback/analysis_course.php b/mod/feedback/analysis_course.php index f0c24d1d1e..a3e51df2bc 100644 --- a/mod/feedback/analysis_course.php +++ b/mod/feedback/analysis_course.php @@ -146,12 +146,12 @@ if ($courses = $DB->get_records_sql_menu($sql, $params)) { echo ' ' . get_string('filter_by_course', 'feedback') . ': '; - $selectmenu = new moodle_select_menu(); - $selectmenu->options = $courses; - $selectmenu->name = 'coursefilter'; - $selectmenu->selectedvalue = $coursefilter; - $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'analysis-form')); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = $courses; + $select->name = 'coursefilter'; + $select->selectedvalue = $coursefilter; + $select->add_action('change', 'submit_form_by_id', array('id' => 'analysis-form')); + echo $OUTPUT->select($select); } echo '
'; $itemnr = 0; diff --git a/mod/lesson/report.php b/mod/lesson/report.php index dd6413ddb3..c9fcd06b1f 100644 --- a/mod/lesson/report.php +++ b/mod/lesson/report.php @@ -275,12 +275,12 @@ ''.get_string('selectall').' / '. ''.get_string('deselectall').' '; - $selectmenu = new moodle_select_menu(); - $selectmenu->options = array('delete' => get_string('deleteselected')); - $selectmenu->name = 'attemptaction'; - $selectmenu->selectedvalue = 0; - $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'theform')); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = array('delete' => get_string('deleteselected')); + $select->name = 'attemptaction'; + $select->selectedvalue = 0; + $select->add_action('change', 'submit_form_by_id', array('id' => 'theform')); + echo $OUTPUT->select($select); echo ''; } diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 5253f2da90..e4aacf556b 100755 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -740,12 +740,12 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
options = $orgs; - $selectmenu->name = 'organization'; - $selectmenu->selectedvalue = $organization; - $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'changeorg')); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = $orgs; + $select->name = 'organization'; + $select->selectedvalue = $organization; + $select->add_action('change', 'submit_form_by_id', array('id' => 'changeorg')); + echo $OUTPUT->select($select); ?>
diff --git a/mod/scorm/report.php b/mod/scorm/report.php index a03a715035..a4d2f8ffb6 100755 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -198,13 +198,13 @@ echo ''.get_string('selectall', 'quiz').' / '; echo ''.get_string('selectnone', 'quiz').' '; echo '  '; - $selectmenu = new moodle_select_menu(); - $selectmenu->options = array('delete' => get_string('delete')); - $selectmenu->name = 'action'; - $selectmenu->button->label = get_string('withselected', 'quiz'); - $selectmenu->id = 'menuaction'; - $selectmenu->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction')); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = array('delete' => get_string('delete')); + $select->name = 'action'; + $select->button->label = get_string('withselected', 'quiz'); + $select->id = 'menuaction'; + $select->add_action('change', 'submit_form_by_id', array('id' => 'attemptsform', 'selectid' => 'menuaction')); + echo $OUTPUT->select($select); echo ''; diff --git a/mod/wiki/admin.php b/mod/wiki/admin.php index 73cead33b7..e6e23b1b36 100644 --- a/mod/wiki/admin.php +++ b/mod/wiki/admin.php @@ -285,12 +285,12 @@ while(list($key,$val)=each($wiki_list)) { $wiki_admin_list[$key."&action=$action"]=$val; } - $selectmenu = new moodle_select_menu(); - $selectmenu->options = $wiki_admin_list; - $selectmenu->name = 'wikiselect'; - $selectmenu->selectedvalue = $selected; - $selectmenu->add_action('change', 'go_to_wiki'); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = $wiki_admin_list; + $select->name = 'wikiselect'; + $select->selectedvalue = $selected; + $select->add_action('change', 'go_to_wiki'); + echo $OUTPUT->select($select); echo ''; echo ''; echo ''; diff --git a/mod/wiki/view.php b/mod/wiki/view.php index 785ea9c196..e37149cf32 100644 --- a/mod/wiki/view.php +++ b/mod/wiki/view.php @@ -300,12 +300,12 @@ echo '' .get_string('otherwikis', 'wiki').':  '; - $selectmenu = new moodle_select_menu(); - $selectmenu->options = $wiki_list; - $selectmenu->name = 'wikiselect'; - $selectmenu->selectedvalue = $selected; - $selectmenu->add_action('change', 'go_to_wiki'); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = $wiki_list; + $select->name = 'wikiselect'; + $select->selectedvalue = $selected; + $select->add_action('change', 'go_to_wiki'); + echo $OUTPUT->select($select); echo ''; echo ''; echo ''; diff --git a/user/index.php b/user/index.php index 9d0fd4eb5a..cd3c290653 100644 --- a/user/index.php +++ b/user/index.php @@ -851,12 +851,12 @@ } helpbutton("participantswithselectedusers", get_string("withselectedusers")); - $selectmenu = new moodle_select_menu(); - $selectmenu->options = $displaylist; - $selectmenu->name = "formaction"; - $selectmenu->label = get_string("withselectedusers"); - $selectmenu->add_action('change', 'conditionalsubmit', array('formid' => 'participantsform')); - echo $OUTPUT->select_menu($selectmenu); + $select = new moodle_select(); + $select->options = $displaylist; + $select->name = "formaction"; + $select->label = get_string("withselectedusers"); + $select->add_action('change', 'conditionalsubmit', array('formid' => 'participantsform')); + echo $OUTPUT->select($select); echo ''; echo '
'; echo '
'; -- 2.39.5