From da4124beabfabb6331e9fedd54de8b508dc322d5 Mon Sep 17 00:00:00 2001 From: moquist Date: Thu, 10 Aug 2006 06:41:38 +0000 Subject: [PATCH] Added $return=false parameter to the following functions: print_navigation() print_headline() print_heading() print_heading_with_help() print_heading_block() print_continue() print_simple_box() print_simple_box_start() print_simple_box_end() print_single_button() print_spacer() print_file_picture() print_user() print_recent_activity_note() print_group_menu() print_grade_menu() print_scale_menu() print_scale_menu_helpbutton() Changed $returnstring parameter to $return (for consistency) in the following functions: print_user_picture() print_group_picture() --- lib/weblib.php | 368 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 247 insertions(+), 121 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index 1faac597cb..09a164d246 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -585,7 +585,8 @@ function frmchecked(&$var, $true_value = 'checked', $false_value = '') { * @uses $CFG */ function link_to_popup_window ($url, $name='popup', $linkname='click here', - $height=400, $width=500, $title='Popup window', $options='none', $return=false) { + $height=400, $width=500, $title='Popup window', + $options='none', $return=false) { global $CFG; @@ -2127,7 +2128,7 @@ function print_header_simple($title='', $heading='', $navigation='', $focus='', } $output = print_header($course->shortname .': '. $title, $course->fullname .' '. $heading, $shortname .' '. $navigation, $focus, $meta, - $cache, $button, $menu, $usexml, $bodytags, $return); + $cache, $button, $menu, $usexml, $bodytags, true); if ($return) { return $output; @@ -2501,22 +2502,30 @@ function user_login_string($course=NULL, $user=NULL) { * @uses $CFG * @param string $navigation The breadcrumbs string to be printed */ -function print_navigation ($navigation) { - global $CFG, $USER; - - if ($navigation) { - //Accessibility: breadcrumb links now in a list, » replaced with image. - $nav_text = get_string('youarehere','access'); - echo '

'.$nav_text.",

\n"; + } + + if ($return) { + return $output; + } else { + echo $output; + } } /** @@ -2525,8 +2534,13 @@ function print_navigation ($navigation) { * @param string $text The text to be displayed * @param int $size The size to set the font for text display. */ -function print_headline($text, $size=2) { - print_heading($text, 'left', $size); +function print_headline($text, $size=2, $return=false) { + $output = print_heading($text, 'left', $size, true); + if ($return) { + return $output; + } else { + echo $output; + } } /** @@ -2536,14 +2550,20 @@ function print_headline($text, $size=2) { * @param string $align The alignment of the printed paragraph of text * @param int $size The size to set the font for text display. */ -function print_heading($text, $align='', $size=2, $class='main') { +function print_heading($text, $align='', $size=2, $class='main', $return=false) { if ($align) { $align = ' align="'.$align.'"'; } if ($class) { $class = ' class="'.$class.'"'; } - echo "".stripslashes_safe($text).""; + $output = "".stripslashes_safe($text).""; + + if ($return) { + return $output; + } else { + echo $output; + } } /** @@ -2555,16 +2575,29 @@ function print_heading($text, $align='', $size=2, $class='main') { * @param string $module The module whose help should be linked to * @param string $icon Image to display if needed */ -function print_heading_with_help($text, $helppage, $module='moodle', $icon='') { - echo '

'.$icon.stripslashes_safe($text); - helpbutton($helppage, $text, $module); - echo '

'; +function print_heading_with_help($text, $helppage, $module='moodle', $icon='', $return=false) { + $output = ''; + $output .= '

'.$icon.stripslashes_safe($text); + $output .= helpbutton($helppage, $text, $module, true, false, '', true); + $output .= '

'; + + if ($return) { + return $output; + } else { + echo $output; + } } -function print_heading_block($heading, $class='') { +function print_heading_block($heading, $class='', $return=false) { //Accessibility: 'headingblock' is now H1, see theme/standard/styles_*.css: ?? - echo '

'.stripslashes($heading).'

'; + $output = '

'.stripslashes($heading).'

'; + + if ($return) { + return $output; + } else { + echo $output; + } } @@ -2574,17 +2607,25 @@ function print_heading_block($heading, $class='') { * @uses $CFG * @param string $link The url to create a link to. */ -function print_continue($link) { +function print_continue($link, $return=false) { global $CFG; + $output = ''; + if (!$link) { $link = $_SERVER['HTTP_REFERER']; } - echo '
'; - print_single_button($link, NULL, get_string('continue'), 'post', $CFG->framename); - echo '
'."\n"; + $output .= '
'; + $output .= print_single_button($link, NULL, get_string('continue'), 'post', $CFG->framename, true); + $output .= '
'."\n"; + + if ($return) { + return $output; + } else { + echo $output; + } } /** @@ -2598,10 +2639,17 @@ function print_continue($link) { * @param string $class string, space-separated class names. * @todo Finish documenting this function */ -function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='') { - print_simple_box_start($align, $width, $color, $padding, $class, $id); - echo stripslashes_safe($message); - print_simple_box_end(); +function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) { + $output = ''; + $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true); + $output .= stripslashes_safe($message); + $output .= print_simple_box_end(true); + + if ($return) { + return $output; + } else { + echo $output; + } } /** @@ -2614,7 +2662,9 @@ function print_simple_box($message, $align='', $width='', $color='', $padding=5, * @param int $padding integer, padding in pixels, specified without units. * @param string $class string, space-separated class names. */ -function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='') { +function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) { + + $output = ''; if ($color) { $color = 'bgcolor="'. $color .'"'; @@ -2628,15 +2678,26 @@ function print_simple_box_start($align='', $width='', $color='', $padding=5, $cl if ($id) { $id = 'id="'. $id .'"'; } - echo "". + $output .= "
". "
"; + + if ($return) { + return $output; + } else { + echo $output; + } } /** * Print the end portion of a standard themed box. */ -function print_simple_box_end() { - echo '
'; +function print_simple_box_end($return=false) { + $output = ''; + if ($return) { + return $output; + } else { + echo $output; + } } @@ -2649,15 +2710,22 @@ function print_simple_box_end() { * @param string $method ? * @todo Finish documenting this function */ -function print_single_button($link, $options, $label='OK', $method='get', $target='_self') { - echo '
'; - echo '
'; +function print_single_button($link, $options, $label='OK', $method='get', $target='_self', $return=false) { + $output = ''; + $output .= '
'; + $output .= ''; if ($options) { foreach ($options as $name => $value) { - echo ''; + $output .= ''; } } - echo '
'; + $output .= '
'; + + if ($return) { + return $output; + } else { + echo $output; + } } /** @@ -2668,11 +2736,19 @@ function print_single_button($link, $options, $label='OK', $method='get', $targe * @param boolean $br ? * @todo Finish documenting this function */ -function print_spacer($height=1, $width=1, $br=true) { +function print_spacer($height=1, $width=1, $br=true, $return=false) { global $CFG; - echo ''; + $output = ''; + + $output .= ''; if ($br) { - echo '
'."\n"; + $output .= '
'."\n"; + } + + if ($return) { + return $output; + } else { + echo $output; } } @@ -2687,8 +2763,9 @@ function print_spacer($height=1, $width=1, $br=true) { * @param string $link ? * @todo Finish documenting this function */ -function print_file_picture($path, $courseid=0, $height='', $width='', $link='') { +function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) { global $CFG; + $output = ''; if ($height) { $height = 'height="'. $height .'"'; @@ -2697,24 +2774,30 @@ function print_file_picture($path, $courseid=0, $height='', $width='', $link='') $width = 'width="'. $width .'"'; } if ($link) { - echo ''; + $output .= ''; } if (substr(strtolower($path), 0, 7) == 'http://') { - echo ''; + $output .= ''; } else if ($courseid) { - echo ''; + $output .= '" />'; } else { - echo 'Error: must pass URL or course'; + $output .= 'Error: must pass URL or course'; } if ($link) { - echo ''; + $output .= ''; + } + + if ($return) { + return $output; + } else { + echo $output; } } @@ -2725,12 +2808,12 @@ function print_file_picture($path, $courseid=0, $height='', $width='', $link='') * @param int $courseid ? * @param boolean $picture Print the user picture? * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatability - * @param boolean $returnstring If false print picture to current page, otherwise return the output as string + * @param boolean $return If false print picture to current page, otherwise return the output as string * @param boolean $link Enclose printed image in a link to view specified course? * return string * @todo Finish documenting this function */ -function print_user_picture($userid, $courseid, $picture, $size=0, $returnstring=false, $link=true, $target='') { +function print_user_picture($userid, $courseid, $picture, $size=0, $return=false, $link=true, $target='') { global $CFG; if ($link) { @@ -2769,7 +2852,7 @@ function print_user_picture($userid, $courseid, $picture, $size=0, $returnstring $output .= ''; } - if ($returnstring) { + if ($return) { return $output; } else { echo $output; @@ -2784,10 +2867,12 @@ function print_user_picture($userid, $courseid, $picture, $size=0, $returnstring * @param user $user A {@link $USER} object representing a user * @param course $course A {@link $COURSE} object representing a course */ -function print_user($user, $course, $messageselect=false) { +function print_user($user, $course, $messageselect=false, $return=false) { global $CFG, $USER; + $output = ''; + static $string; static $datestring; static $countries; @@ -2829,73 +2914,79 @@ function print_user($user, $course, $messageselect=false) { $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); } - echo ''; - echo ''; - echo ''; - echo '
'; - print_user_picture($user->id, $course->id, $user->picture, true); - echo ''; - echo '
'.fullname($user, $isteacher).'
'; - echo '
'; + $output .= ''; + $output .= ''; + $output .= ''; + $output .= '
'; + $output .= print_user_picture($user->id, $course->id, $user->picture, true, true); + $output .= ''; + $output .= '
'.fullname($user, $isteacher).'
'; + $output .= '
'; if (!empty($user->role) and ($user->role <> $course->teacher)) { - echo $string->role .': '. $user->role .'
'; + $output .= $string->role .': '. $user->role .'
'; } if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category and !isguest()) or $isteacher) { - echo $string->email .': '. $user->email .'
'; + $output .= $string->email .': '. $user->email .'
'; } if (($user->city or $user->country) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) { - echo $string->location .': '; + $output .= $string->location .': '; if ($user->city && !isset($hiddenfields['city'])) { - echo $user->city; + $output .= $user->city; } if (!empty($countries[$user->country]) && !isset($hiddenfields['country'])) { if ($user->city && !isset($hiddenfields['city'])) { - echo ', '; + $output .= ', '; } - echo $countries[$user->country]; + $output .= $countries[$user->country]; } - echo '
'; + $output .= '
'; } if (!isset($hiddenfields['lastaccess'])) { if ($user->lastaccess) { - echo $string->lastaccess .': '. userdate($user->lastaccess); - echo '  ('. format_time(time() - $user->lastaccess, $datestring) .')'; + $output .= $string->lastaccess .': '. userdate($user->lastaccess); + $output .= '  ('. format_time(time() - $user->lastaccess, $datestring) .')'; } else { - echo $string->lastaccess .': '. $string->never; + $output .= $string->lastaccess .': '. $string->never; } } - echo '
'; + $output .= '
'; + + if ($return) { + return $output; + } else { + echo $output; + } } /** @@ -2904,12 +2995,12 @@ function print_user($user, $course, $messageselect=false) { * @param group $group A {@link group} object representing a group or array of groups * @param int $courseid ? * @param boolean $large ? - * @param boolean $returnstring ? + * @param boolean $return ? * @param boolean $link ? * @return string * @todo Finish documenting this function */ -function print_group_picture($group, $courseid, $large=false, $returnstring=false, $link=true) { +function print_group_picture($group, $courseid, $large=false, $return=false, $link=true) { global $CFG; if (is_array($group)) { @@ -2917,7 +3008,7 @@ function print_group_picture($group, $courseid, $large=false, $returnstring=fals foreach($group as $g) { $output .= print_group_picture($g, $courseid, $large, true, $link); } - if ($returnstring) { + if ($return) { return $output; } else { echo $output; @@ -2960,7 +3051,7 @@ function print_group_picture($group, $courseid, $large=false, $returnstring=fals $output .= ''; } - if ($returnstring) { + if ($return) { return $output; } else { echo $output; @@ -2973,11 +3064,11 @@ function print_group_picture($group, $courseid, $large=false, $returnstring=fals * @param string $url ? * @param int $sizex ? * @param int $sizey ? - * @param boolean $returnstring ? + * @param boolean $return ? * @param string $parameters ? * @todo Finish documenting this function */ -function print_png($url, $sizex, $sizey, $returnstring, $parameters='alt=""') { +function print_png($url, $sizex, $sizey, $return, $parameters='alt=""') { global $CFG; static $recentIE; @@ -2996,7 +3087,7 @@ function print_png($url, $sizex, $sizey, $returnstring, $parameters='alt=""') { ' '. $parameters .' />'; } - if ($returnstring) { + if ($return) { return $output; } else { echo $output; @@ -3242,9 +3333,11 @@ function make_table($table) { return $output; } -function print_recent_activity_note($time, $user, $isteacher, $text, $link) { +function print_recent_activity_note($time, $user, $isteacher, $text, $link, $return=false) { static $strftimerecent; + $output = ''; + if (empty($strftimerecent)) { $strftimerecent = get_string('strftimerecent'); } @@ -3252,11 +3345,17 @@ function print_recent_activity_note($time, $user, $isteacher, $text, $link) { $date = userdate($time, $strftimerecent); $name = fullname($user, $isteacher); - echo '
'; - echo '
'.$date.'
'. + $output .= '
'; + $output .= '
'.$date.'
'. '
'.fullname($user, $isteacher).'
'; - echo '
'; - echo ''; + $output .= '
'; + $output .= '
'.format_string($text,true).'
'; + + if ($return) { + return $output; + } else { + echo $output; + } } @@ -3678,7 +3777,9 @@ function update_groups_button($courseid) { * @param boolean $showall: if set to 0, it is a student in separate groups, do not display all participants * @todo Finish documenting this function */ -function print_group_menu($groups, $groupmode, $currentgroup, $urlroot, $showall=1) { +function print_group_menu($groups, $groupmode, $currentgroup, $urlroot, $showall=1, $return=false) { + + $output = ''; /// Add an "All groups" to the start of the menu if ($showall){ @@ -3688,16 +3789,22 @@ function print_group_menu($groups, $groupmode, $currentgroup, $urlroot, $showall $groupsmenu[$key] = $groupname; } - echo '
'; + $output .= '
'; if ($groupmode == VISIBLEGROUPS) { - print_string('groupsvisible'); + $output .= get_string('groupsvisible'); } else { - print_string('groupsseparate'); + $output .= get_string('groupsseparate'); + } + $output .= ':'; + $output .= ''; + $output .= popup_form($urlroot.'&group=', $groupsmenu, 'selectgroup', $currentgroup, '', '', '', true, 'self'); + $output .= '
'; + + if ($return) { + return $output; + } else { + echo $output; } - echo ':'; - echo '
'; - popup_form($urlroot.'&group=', $groupsmenu, 'selectgroup', $currentgroup, '', '', '', false, 'self'); - echo '
'; } @@ -4024,10 +4131,11 @@ function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $ * @param boolean $includenograde ? * @todo Finish documenting this function */ -function print_grade_menu($courseid, $name, $current, $includenograde=true) { +function print_grade_menu($courseid, $name, $current, $includenograde=true, $return=false) { global $CFG; + $output = ''; $strscale = get_string('scale'); $strscales = get_string('scales'); @@ -4041,11 +4149,17 @@ function print_grade_menu($courseid, $name, $current, $includenograde=true) { for ($i=100; $i>=1; $i--) { $grades[$i] = $i; } - choose_from_menu($grades, $name, $current, ''); + $output .= choose_from_menu($grades, $name, $current, '', '', 0, true); $linkobject = ''.$strscales.''; - link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true', 'ratingscales', - $linkobject, 400, 500, $strscales); + $output .= link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true', 'ratingscales', + $linkobject, 400, 500, $strscales, 'none', true); + + if ($return) { + return $output; + } else { + echo $output; + } } /** @@ -4057,16 +4171,22 @@ function print_grade_menu($courseid, $name, $current, $includenograde=true) { * @param string $current ? * @todo Finish documenting this function */ -function print_scale_menu($courseid, $name, $current) { +function print_scale_menu($courseid, $name, $current, $return=false) { global $CFG; + $output = ''; $strscales = get_string('scales'); - choose_from_menu(get_scales_menu($courseid), $name, $current, ''); + $output .= choose_from_menu(get_scales_menu($courseid), $name, $current, '', '', 0, true); $linkobject = ''.$strscales.''; - link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true', 'ratingscales', - $linkobject, 400, 500, $strscales); + $output .= link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true', 'ratingscales', + $linkobject, 400, 500, $strscales, 'none', true); + if ($return) { + return $output; + } else { + echo $output; + } } /** @@ -4077,15 +4197,21 @@ function print_scale_menu($courseid, $name, $current) { * @param object $scale ? * @todo Finish documenting this function */ -function print_scale_menu_helpbutton($courseid, $scale) { +function print_scale_menu_helpbutton($courseid, $scale, $return=false) { global $CFG; + $output = ''; $strscales = get_string('scales'); $linkobject = ''.$scale->name.''; - link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true&scaleid='. $scale->id, 'ratingscale', - $linkobject, 400, 500, $scale->name); + $output .= link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true&scaleid='. $scale->id, 'ratingscale', + $linkobject, 400, 500, $scale->name, 'none', true); + if ($return) { + return $output; + } else { + echo $output; + } } /** -- 2.39.5