MDL-19756 Migrated the following functions from weblib to outputlib:

1. button_to_popup_window
2. link_to_popup_window
3. print_single_button
4. print_spacer
5. print_file_picture (deprecated)
6. print_user_picture
7. print_png (deprecated)
8. helpbutton
9. doclink
10. print_paging_bar
11. notice_yesno
This commit is contained in:
nicolasconnault 2009-07-27 10:33:00 +00:00
parent 9482c0fff6
commit f8065dd287
18 changed files with 2481 additions and 861 deletions

View File

@ -17,6 +17,7 @@ if (!defined('AUTOGROUP_MIN_RATIO')) {
}
$courseid = required_param('courseid', PARAM_INT);
$PAGE->set_url('/group/autogroup.php', array('courseid' => $courseid));
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('invalidcourseid');

View File

@ -45,8 +45,7 @@ class autogroup_form extends moodleform {
$mform->setAdvanced('allocateby');
$mform->addElement('text', 'namingscheme', get_string('namingscheme', 'group'));
$mform->setHelpButton('namingscheme', array(false, get_string('namingschemehelp', 'group'),
false, true, false, get_string('namingschemehelp', 'group')));
$mform->setHelpButton('namingscheme', array('namingscheme', get_string('namingschemehelp', 'group'), 'group'));
$mform->addRule('namingscheme', get_string('required'), 'required', null, 'client');
$mform->setType('namingscheme', PARAM_MULTILANG);
// there must not be duplicate group names in course

View File

@ -19,6 +19,7 @@ $text = optional_param('text', 'No text to display', PARAM_CLEAN);
$module = optional_param('module', 'moodle', PARAM_ALPHAEXT);
$forcelang = optional_param('forcelang', '', PARAM_SAFEDIR);
$skiplocal = optional_param('skiplocal', 0, PARAM_INT); // shall _local help files be skipped?
$fortooltip = optional_param('fortooltip', 0, PARAM_INT);
$PAGE->set_course($COURSE);
@ -62,8 +63,14 @@ if (!empty($file)) {
// Finish buffer
$output = ob_get_contents();
ob_end_clean();
if ($fortooltip) {
echo shorten_text($output, 400, false, '<span class="readmore">' . get_string('clickhelpiconformoreinfo') . '</span>');
die();
}
// Determine title
$title = get_string('help'); // Default is just 'Help'
$matches = array();

View File

@ -66,6 +66,9 @@
add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
}
$PAGE->set_pagetype('site-index');
$PAGE->set_course($SITE);
if (empty($CFG->langmenu)) {
$langmenu = '';
} else {
@ -74,9 +77,6 @@
$langlabel = get_accesshide(get_string('language'));
$langmenu = popup_form($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
}
$PAGE->set_pagetype('site-index');
$PAGE->set_course($SITE);
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
$PAGE->set_url('');
$PAGE->set_docs_path('');

View File

@ -0,0 +1,2 @@
<h2>Naming scheme</h2>
<p>Use @ character to represent the group letter (A-Z) or # to represent the group number.</p>

View File

@ -242,6 +242,7 @@ $string['clamquarantinedirfailed'] = 'Could not move the file into your specifie
$string['clamunknownerror'] = 'There was an unknown error with clam.';
$string['cleaningtempdata'] = 'Cleaning temp data';
$string['clear'] = 'Clear';
$string['clickhelpiconformoreinfo'] = '... continues ... Click on the help icon to read the full article';
$string['clickhere'] = 'Click here ...';
$string['clicktochange'] = 'Click to change';
$string['clicktohideshow'] = 'Click to expand or collapse';

View File

@ -32,7 +32,7 @@
* @param page_requirements_manager $requires The page_requirements_manager to initialise.
*/
function setup_core_javascript(page_requirements_manager $requires) {
global $CFG;
global $CFG, $OUTPUT;
// JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot.
// Otherwise, in some situations, users will get warnings about insecure content
@ -41,6 +41,7 @@ function setup_core_javascript(page_requirements_manager $requires) {
$config = array(
'wwwroot' => $CFG->httpswwwroot, // Yes, really. See above.
'sesskey' => sesskey(),
'loadingicon' => $OUTPUT->old_icon_url('i/loading_small')
);
if (debugging('', DEBUG_DEVELOPER)) {
$config['developerdebug'] = true;
@ -56,6 +57,12 @@ function setup_core_javascript(page_requirements_manager $requires) {
// Note that, as a short-cut, the code
// $js = "document.body.className += ' jsenabled';\n";
// is hard-coded in {@link page_requirements_manager::get_top_of_body_code)
$requires->yui_lib('container');
$requires->yui_lib('connection');
$requires->string_for_js('confirmation', 'moodle');
$requires->string_for_js('cancel', 'moodle');
$requires->string_for_js('yes', 'moodle');
$requires->js_function_call('init_help_icons');
}
@ -364,8 +371,9 @@ class page_requirements_manager {
* @return required_event_handler The event_handler object
*/
public function event_handler($id, $event, $function, $arguments=array()) {
$requirement = new required_event_handler($id, $event, $function, $arguments);
$requirement = new required_event_handler($this, $id, $event, $function, $arguments);
$this->requiredjscode[] = $requirement;
$this->linkedrequirements[] = new required_yui_lib($this, 'event');
return $requirement;
}
@ -1109,7 +1117,6 @@ class required_event_handler extends required_js_code {
* @param array $arguments An optional array of argument parameters to pass to the function
*/
public function __construct(page_requirements_manager $manager, $id, $event, $function, $args=array()) {
$manager->requires->yui_lib('event');
parent::__construct($manager);
$this->id = $id;
$this->event = $event;
@ -1118,7 +1125,7 @@ class required_event_handler extends required_js_code {
}
public function get_js_code() {
$output = "YAHOO.util.Event.addListener($this->id, '$this->event', $this->function";
$output = "YAHOO.util.Event.addListener('$this->id', '$this->event', $this->function";
if (!empty($this->args)) {
$output .= ', ' . json_encode($this->args);
}

View File

@ -2379,3 +2379,599 @@ function print_table($table, $return=false) {
return true;
}
}
/**
* Creates and displays (or returns) a link to a popup window
*
* @deprecated since Moodle 2.0
*
* @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
* @param string $name Name to be assigned to the popup window (this is used by
* client-side scripts to "talk" to the popup window)
* @param string $linkname Text to be displayed as web link
* @param int $height Height to assign to popup window
* @param int $width Height to assign to popup window
* @param string $title Text to be displayed as popup page title
* @param string $options List of additional options for popup window
* @param bool $return If true, return as a string, otherwise print
* @param string $id id added to the element
* @param string $class class added to the element
* @return string html code to display a link to a popup window.
*/
function link_to_popup_window ($url, $name=null, $linkname=null,
$height=400, $width=500, $title=null,
$options=null, $return=false) {
global $OUTPUT;
// debugging('link_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->link_to_popup().');
if ($options == 'none') {
$options = null;
}
if (empty($linkname)) {
throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->link_to_popup() for usage.');
}
// Create a html_link object
$link = new html_link();
$link->text = $linkname;
$link->url = $url;
$link->title = $title;
// Parse the $options string
$popupparams = array();
if (!empty($options)) {
$optionsarray = explode(',', $options);
foreach ($optionsarray as $option) {
if (strstr($option, '=')) {
$parts = explode('=', $option);
if ($parts[1] == '0') {
$popupparams[$parts[0]] = false;
} else {
$popupparams[$parts[0]] = $parts[1];
}
} else {
$popupparams[$option] = true;
}
}
}
$popupaction = new popup_action('click', $url, $name, $popupparams);
$link->add_action_object($popupaction);
// Call the output method
$output = $OUTPUT->link_to_popup($link);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Creates and displays (or returns) a buttons to a popup window.
*
* @deprecated since Moodle 2.0
*
* @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
* @param string $name Name to be assigned to the popup window (this is used by
* client-side scripts to "talk" to the popup window)
* @param string $linkname Text to be displayed as web link
* @param int $height Height to assign to popup window
* @param int $width Height to assign to popup window
* @param string $title Text to be displayed as popup page title
* @param string $options List of additional options for popup window
* @param bool $return If true, return as a string, otherwise print
* @param string $id id added to the element
* @param string $class class added to the element
* @return string html code to display a link to a popup window.
*/
function button_to_popup_window ($url, $name=null, $linkname=null,
$height=400, $width=500, $title=null, $options=null, $return=false,
$id=null, $class=null) {
global $OUTPUT;
// debugging('link_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->link_to_popup().');
if ($options == 'none') {
$options = null;
}
if (empty($linkname)) {
throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->link_to_popup() for usage.');
}
// Create a html_button object
$button = new html_button();
$button->value = $linkname;
$button->url = $url;
$button->id = $id;
$button->add_class($class);
$button->method = 'post';
$button->title = $title;
// Parse the $options string
$popupparams = array();
if (!empty($options)) {
$optionsarray = explode(',', $options);
foreach ($optionsarray as $option) {
if (strstr($option, '=')) {
$parts = explode('=', $option);
if ($parts[1] == '0') {
$popupparams[$parts[0]] = false;
} else {
$popupparams[$parts[0]] = $parts[1];
}
} else {
$popupparams[$option] = true;
}
}
}
if (!empty($height)) {
$popupparams['height'] = $height;
}
if (!empty($width)) {
$popupparams['width'] = $width;
}
$popupaction = new popup_action('click', $url, $name, $popupparams);
$button->add_action_object($popupaction);
$output = $OUTPUT->button($button);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print a self contained form with a single submit button.
*
* @deprecated since Moodle 2.0
*
* @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
* @param array $options these become hidden form fields, so these options get passed to the script at $link.
* @param string $label the caption that appears on the button.
* @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
* @param string $notusedanymore no longer used.
* @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
* @param string $tooltip a tooltip to add to the button as a title attribute.
* @param boolean $disabled if true, the button will be disabled.
* @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
* @param string $formid The id attribute to use for the form
* @return string|void Depending on the $return paramter.
*/
function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
$return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
global $OUTPUT;
// debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->button().');
// Cast $options to array
$options = (array) $options;
$form = new html_form();
$form->url = new moodle_url($link, $options);
$form->button->label = $label;
$form->button->disabled = $disabled;
$form->button->title = $tooltip;
$form->method = $method;
$form->id = $formid;
if ($jsconfirmmessage) {
$confirmaction = new component_action('click', 'confirm_dialog', array($jsconfirmmessage));
$form->button->add_action_object($confirmaction);
}
$output = $OUTPUT->button($form);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print a spacer image with the option of including a line break.
*
* @deprecated since Moodle 2.0
*
* @global object
* @param int $height The height in pixels to make the spacer
* @param int $width The width in pixels to make the spacer
* @param boolean $br If set to true a BR is written after the spacer
*/
function print_spacer($height=1, $width=1, $br=true, $return=false) {
global $CFG, $OUTPUT;
// debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().');
$spacer = new html_spacer();
$spacer->height = $height;
$spacer->width = $width;
$output = $OUTPUT->spacer($spacer);
$output .= '<img class="spacer" height="'. $height .'" width="'. $width .'" src="'. $CFG->wwwroot .'/pix/spacer.gif" alt="" />';
if ($br) {
$output .= '<br />';
}
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Given the path to a picture file in a course, or a URL,
* this function includes the picture in the page.
*
* @deprecated since Moodle 2.0
*/
function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
throw new coding_exception('print_file_picture() has been deprecated since Moodle 2.0. Please use $OUTPUT->action_icon() instead.');
}
/**
* Print the specified user's avatar.
*
* @deprecated since Moodle 2.0
*
* @global object
* @global object
* @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname
* If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
* if at all possible, particularly for reports. It is very bad for performance.
* @param int $courseid The course id. Used when constructing the link to the user's profile.
* @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
* @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
* @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 the user's profile (default true).
* @param string $target link target attribute. Makes the profile open in a popup window.
* @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
* decorative images, or where the username will be printed anyway.)
* @return string|void String or nothing, depending on $return.
*/
function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
global $CFG, $DB, $OUTPUT;
// debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, $link, $popup).');
$userpic = new user_picture();
$userpic->user = $user;
$userpic->courseid = $courseid;
$userpic->size = $size;
$userpic->link = $link;
$userpic->alttext = $alttext;
if (!empty($picture)) {
$userpic->image = new html_image();
$userpic->image->src = $picture;
}
if (!empty($target)) {
$popupaction = new popup_action('click', new moodle_url($target));
$userpic->add_action_object($popupaction);
}
$output = $OUTPUT->user_picture($userpic);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print a png image.
*
* @deprecated since Moodle 2.0: no replacement
*
*/
function print_png() {
throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->image() instead.');
}
/**
* Prints a basic textarea field.
*
* @deprecated since Moodle 2.0
*
* When using this function, you should
*
* @global object
* @param bool $usehtmleditor Enables the use of the htmleditor for this field.
* @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
* @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
* @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored.
* @param null $height (Deprecated) Height of the element; if a value is passe, the minimum value for $rows will be 10. Value is otherwise ignored.
* @param string $name Name to use for the textarea element.
* @param string $value Initial content to display in the textarea.
* @param int $obsolete deprecated
* @param bool $return If false, will output string. If true, will return string value.
* @param string $id CSS ID to add to the textarea element.
* @return string|void depending on the value of $return
*/
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
/// $width and height are legacy fields and no longer used as pixels like they used to be.
/// However, you can set them to zero to override the mincols and minrows values below.
// debugging('print_textarea() has been deprecated. Please change your code to use $OUTPUT->textarea().');
global $CFG;
$mincols = 65;
$minrows = 10;
$str = '';
if ($id === '') {
$id = 'edit-'.$name;
}
if ($usehtmleditor) {
if ($height && ($rows < $minrows)) {
$rows = $minrows;
}
if ($width && ($cols < $mincols)) {
$cols = $mincols;
}
}
if ($usehtmleditor) {
editors_head_setup();
$editor = get_preferred_texteditor(FORMAT_HTML);
$editor->use_editor($id, array('legacy'=>true));
} else {
$editorclass = '';
}
$str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
if ($usehtmleditor) {
$str .= htmlspecialchars($value); // needed for editing of cleaned text!
} else {
$str .= s($value);
}
$str .= '</textarea>'."\n";
if ($return) {
return $str;
}
echo $str;
}
/**
* Print a help button.
*
* @deprecated since Moodle 2.0
*
* @param string $page The keyword that defines a help page
* @param string $title The title of links, rollover tips, alt tags etc
* 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
* @param string $module Which module is the page defined in
* @param mixed $image Use a help image for the link? (true/false/"both")
* @param boolean $linktext If true, display the title next to the help icon.
* @param string $text If defined then this text is used in the page, and
* the $page variable is ignored. DEPRECATED!
* @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
* @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
* @return string|void Depending on value of $return
*/
function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
// debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');
global $OUTPUT;
if (!empty($text)) {
throw new coding_exception('The $text parameter has been deprecated. Please update your code and use $OUTPUT->help_icon() instead. <br />' .
"You will also need to copy the following text into a proper html help file if not already done so: <p>$text</p>");
}
if (!empty($imagetext)) {
throw new coding_exception('The $imagetext parameter has been deprecated. Please update your code and use $OUTPUT->help_icon() instead.');
}
$helpicon = new help_icon();
$helpicon->page = $page;
$helpicon->module = $module;
$helpicon->text = $title;
$helpicon->linktext = $linktext;
// If image is true, the defaults are handled by the helpicon's prepare method
if (!$image) {
$helpicon->image = false;
}
$output = $OUTPUT->help_icon($helpicon);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
* provide this function with the language strings for sortasc and sortdesc.
*
* @deprecated since Moodle 2.0
*
* TODO migrate to outputlib
* If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
*
* @global object
* @param string $direction 'up' or 'down'
* @param string $strsort The language string used for the alt attribute of this image
* @param bool $return Whether to print directly or return the html string
* @return string|void depending on $return
*
*/
function print_arrow($direction='up', $strsort=null, $return=false) {
// debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
global $OUTPUT;
if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
return null;
}
$return = null;
switch ($direction) {
case 'up':
$sortdir = 'asc';
break;
case 'down':
$sortdir = 'desc';
break;
case 'move':
$sortdir = 'asc';
break;
default:
$sortdir = null;
break;
}
// Prepare language string
$strsort = '';
if (empty($strsort) && !empty($sortdir)) {
$strsort = get_string('sort' . $sortdir, 'grades');
}
$return = ' <img src="'.$OUTPUT->old_icon_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
if ($return) {
return $return;
} else {
echo $return;
}
}
/**
* Returns a string containing a link to the user documentation.
* Also contains an icon by default. Shown to teachers and admin only.
*
* @deprecated since Moodle 2.0
*
* @global object
* @param string $path The page link after doc root and language, no leading slash.
* @param string $text The text to be displayed for the link
* @param string $iconpath The path to the icon to be displayed
* @return string Either the link or an empty string
*/
function doc_link($path='', $text='', $iconpath='') {
global $CFG, $OUTPUT;
// debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->action_icon().');
if (empty($CFG->docroot)) {
return '';
}
$icon = new action_icon();
$icon->linktext = $text;
if (!empty($iconpath)) {
$icon->image->src = $iconpath;
$icon->image->alt = $text;
$icon->image->add_class('iconhelp');
} else {
$icon->image->src = $CFG->httpswwwroot . '/pix/docs.gif';
}
$icon->link->url = new moodle_url(get_docs_url($path));
if (!empty($CFG->doctonewwindow)) {
$icon->actions[] = new popup_action('click', $icon->link->url);
}
return $OUTPUT->action_icon($icon);
}
/**
* Prints a single paging bar to provide access to other pages (usually in a search)
*
* @deprecated since Moodle 2.0
*
* @param int $totalcount Thetotal number of entries available to be paged through
* @param int $page The page you are currently viewing
* @param int $perpage The number of entries that should be shown per page
* @param mixed $baseurl If this is a string then it is the url which will be appended with $pagevar, an equals sign and the page number.
* If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
* @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
* @param bool $nocurr do not display the current page as a link
* @param bool $return whether to return an output string or echo now
* @return bool|string depending on $result
*/
function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
global $OUTPUT;
// debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->paging_bar($pagingbar).');
$pagingbar = new moodle_paging_bar();
$pagingbar->totalcount = $totalcount;
$pagingbar->page = $page;
$pagingbar->perpage = $perpage;
$pagingbar->baseurl = $baseurl;
$pagingbar->pagevar = $pagevar;
$pagingbar->nocurr = $nocurr;
$output = $OUTPUT->paging_bar($pagingbar);
if ($return) {
return $output;
}
echo $output;
return true;
}
/**
* Print a message along with "Yes" and "No" links for the user to continue.
*
* @deprecated since Moodle 2.0
*
* @global object
* @param string $message The text to display
* @param string $linkyes The link to take the user to if they choose "Yes"
* @param string $linkno The link to take the user to if they choose "No"
* @param string $optionyes The yes option to show on the notice
* @param string $optionsno The no option to show
* @param string $methodyes Form action method to use if yes [post, get]
* @param string $methodno Form action method to use if no [post, get]
* @return void Output is echo'd
*/
function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
// debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
global $OUTPUT;
$buttoncontinue = new html_button();
$buttoncontinue->url = new moodle_url($linkyes, $optionsyes);
$buttoncontinue->method = $methodyes;
$buttoncancel = new html_button();
$buttoncancel->url = new moodle_url($linkno, $optionsno);
$buttoncancel->method = $methodno;
echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
}
/**
* Prints a scale menu (as part of an existing form) including help button
* @deprecated since Moodle 2.0
*/
function print_scale_menu() {
throw new coding_exception('print_scale_menu() has been deprecated since the Jurassic period. Get with the times!.');
}

View File

@ -94,4 +94,4 @@ class MoodleQuickForm_text extends HTML_QuickForm_text{
return 'default';
}
}
}
}

View File

@ -560,7 +560,7 @@ date_selector_calendar.document_click = function(event) {
date_selector_calendar.currentowner.release_calendar();
}
}
}
}
date_selector_calendar.prototype.claim_calendar = function() {
date_selector_calendar.cancel_any_timeout();
@ -733,12 +733,15 @@ function getElementsByClassName(oElm, strTagName, oClassNames) {
return (arrReturnElements)
}
function openpopup(url, name, options, fullscreen) {
var fullurl = url;
if (!url.match(/https?:\/\//)) {
fullurl = moodle_cfg.wwwroot + url;
function openpopup(event, args) {
YAHOO.util.Event.preventDefault(event);
var fullurl = args.url;
if (!args.url.match(/https?:\/\//)) {
fullurl = moodle_cfg.wwwroot + args.url;
}
var windowobj = window.open(fullurl,name,options);
var windowobj = window.open(fullurl,args.name,args.options);
if (!windowobj) {
return true;
}
@ -812,7 +815,7 @@ function set_user_preference(name, value) {
}
// Make the request.
YAHOO.util.Connect.asyncRequest('GET', url, callback);
YAHOO.util.Connect.asyncRequest('GET', url, callback);
}
}
@ -886,7 +889,7 @@ function collapsible_region(id, userpref, strtooltip, collapsedicon, expandedico
collapsible_region.prototype.userpref = null;
/**
* The key divs that make up this
* The key divs that make up this
* @property div, innerdiv, captiondiv
* @type HTMLDivElement
*/
@ -895,7 +898,7 @@ collapsible_region.prototype.innerdiv = null;
collapsible_region.prototype.captiondiv = null;
/**
* The key divs that make up this
* The key divs that make up this
* @property icon
* @type HTMLImageElement
*/
@ -1102,3 +1105,113 @@ function build_querystring(obj) {
}
return list.join('&');
}
/**
* Finds all help icons on the page and initiates YUI tooltips for
* each of them, which load a truncated version of the help's content
* on-the-fly asynchronously
*/
function init_help_icons() {
// var logger = new YAHOO.widget.LogReader(document.body, {draggable: true});
var iconspans = YAHOO.util.Dom.getElementsByClassName('helplink', 'span');
var tooltip = new YAHOO.widget.Tooltip('help_icon_tooltip', {
context: iconspans,
showdelay: 100,
hidedelay: 150,
autodismissdelay: 50000,
underlay: 'none'
});
tooltip.contextTriggerEvent.subscribe(
function(type, args) {
// Fetch help page contents asynchronously
// Load spinner icon while content is loading
var spinner = document.createElement('img');
spinner.src = moodle_cfg.loadingicon;
this.cfg.setProperty('text', spinner);
var context = args[0];
context.title = '';
var link = context.getElementsByTagName('a')[0];
link.title = '';
YAHOO.util.Dom.getElementsByClassName('iconhelp', 'img', link)[0].title = '';
var thistooltip = this;
var ajaxurl = link.href + '&fortooltip=1';
var callback = {
success: function(o) {
thistooltip.cfg.setProperty('text', o.responseText);
},
failure: function(o) {
var debuginfo = o.statusText;
if (moodle_cfg.developerdebug) {
o.statusText += ' (' + ajaxurl + ')';
}
thistooltip.cfg.setProperty('text', debuginfo);
}
};
var conn = YAHOO.util.Connect.asyncRequest("get", ajaxurl, callback);
}
);
}
/**
* Prints a confirmation dialog in the style of DOM.confirm().
* @param object event A DOM event
* @param string message The message to show in the dialog
* @param string url The URL to forward to if YES is clicked. Disabled if fn is given
* @param function fn A JS function to run if YES is clicked.
*/
function confirm_dialog(event, message) {
YAHOO.util.Event.preventDefault(event);
var simpledialog = new YAHOO.widget.SimpleDialog('confirmdialog',
{ width: '300px',
fixedcenter: true,
modal: true,
visible: false,
draggable: false
}
);
simpledialog.setHeader(mstr.moodle.confirmation);
simpledialog.setBody(message);
simpledialog.cfg.setProperty('icon', YAHOO.widget.SimpleDialog.ICON_WARN);
var handle_cancel = function() {
this.hide();
};
var handle_yes = function() {
this.hide();
var target = event.target;
if (target.tagName.toLowerCase() == 'a') {
window.location = target.href;
} else if (target.tagName.toLowerCase() == 'input') {
var parentelement = target.parentNode;
while (parentelement.tagName.toLowerCase() != 'form' && parentelement.tagName.toLowerCase() != 'body') {
parentelement = parentelement.parentNode;
}
if (parentelement.tagName.toLowerCase() == 'form') {
parentelement.submit();
}
} else if(moodle_cfg.developerdebug) {
alert("Element of type " + target.tagName + " is not supported by the confirm_dialog function. Use A or INPUT");
}
};
var buttons = [ { text: mstr.moodle.cancel, handler: handle_cancel, isDefault: true },
{ text: mstr.moodle.yes, handler: handle_yes } ];
simpledialog.cfg.queueProperty('buttons', buttons);
simpledialog.render(document.body);
simpledialog.show();
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,74 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for ../deprecatedlib.php.
*
* @package moodlecore
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5)
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
require_once($CFG->libdir . '/deprecatedlib.php');
class outputlib_methods_test extends UnitTestCase {
public function test_print_single_button() {
global $PAGE, $CFG;
// Basic params, absolute URL
$link = 'http://www.test.com/index.php';
$options = array('param1' => 'value1');
$label = 'OK';
$method = 'get';
$return = true;
$tooltip = '';
$disabled = false;
$jsconfirmmessage = '';
$formid = '';
$html = print_single_button($link, $options, $label, $method, '', $return, $tooltip, $disabled, $jsconfirmmessage, $formid);
$this->assert(new ContainsTagWithAttributes('form', array('method' => $method, 'action' => $link)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'param1', 'value' => 'value1')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => 'OK')), $html);
// URL with &amp; params
$newlink = $link . '?param1=value1&amp;param2=value2';
$html = print_single_button($newlink, $options, $label, $method, '', $return, $tooltip, $disabled, $jsconfirmmessage, $formid);
$this->assert(new ContainsTagWithAttributes('form', array('method' => $method, 'action' => $link)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'param1', 'value' => 'value1')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => 'OK')), $html);
// URL with & params
$newlink = $link . '?param1=value1&param2=value2';
$html = print_single_button($newlink, $options, $label, $method, '', $return, $tooltip, $disabled, $jsconfirmmessage, $formid);
$this->assert(new ContainsTagWithAttributes('form', array('method' => $method, 'action' => $link)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'param1', 'value' => 'value1')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => 'OK')), $html);
// relative URL with & params
$newlink = 'index.php?param1=value1&param2=value2';
$PAGE->set_url('index.php');
$html = print_single_button($newlink, $options, $label, $method, '', $return, $tooltip, $disabled, $jsconfirmmessage, $formid);
$this->assert(new ContainsTagWithAttributes('form', array('method' => $method, 'action' => $CFG->wwwroot . '/index.php')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'param1', 'value' => 'value1')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => 'OK')), $html);
}
}

View File

@ -578,7 +578,7 @@ class template_renderer_factory_test extends UnitTestCase {
$this->make_theme_template_dir('mytheme');
$this->make_theme_template_dir('parenttheme');
$this->make_theme_template_dir('standardtemplate');
// Exercise SUT.
$factory = new testable_template_renderer_factory($theme, $this->page);
@ -597,7 +597,7 @@ class template_renderer_factory_test extends UnitTestCase {
$theme->parent = 'parenttheme';
$this->make_theme_template_dir('mytheme');
$this->make_theme_template_dir('standardtemplate');
// Exercise SUT.
$factory = new testable_template_renderer_factory($theme, $this->page);
$subfactory = new testable_template_renderer_factory($theme, $this->page, 'subtype');
@ -905,4 +905,252 @@ class moodle_core_renderer_test extends UnitTestCase {
$html = $this->renderer->error_text('');
$this->assertEqual('', $html);
}
public function test_link_to_popup_empty_link() {
// Empty link object: link MUST have a text value
$link = new html_link();
$popupaction = new popup_action('click', 'http://test.com', 'my_popup');
$link->add_action_object($popupaction);
$this->expectException();
$html = $this->renderer->link_to_popup($link);
}
public function test_link_to_popup() {
$link = new html_link();
$link->text = 'Click here';
$link->url = 'http://test.com';
$link->title = 'Popup window';
$popupaction = new popup_action('click', 'http://test.com', 'my_popup');
$link->add_action_object($popupaction);
$html = $this->renderer->link_to_popup($link);
$expectedattributes = array('title' => 'Popup window', 'href' => 'http://test.com');
$this->assert(new ContainsTagWithAttributes('a', $expectedattributes), $html);
$this->assert(new ContainsTagWithContents('a', 'Click here'), $html);
// Try a different url for the link than for the popup
$link->url = 'http://otheraddress.com';
$html = $this->renderer->link_to_popup($link);
$this->assert(new ContainsTagWithAttribute('a', 'title', 'Popup window'), $html);
$this->assert(new ContainsTagWithAttribute('a', 'href', 'http://otheraddress.com'), $html);
$this->assert(new ContainsTagWithContents('a', 'Click here'), $html);
// Give it a moodle_url object instead of a string
$link->url = new moodle_url('http://otheraddress.com');
$html = $this->renderer->link_to_popup($link);
$this->assert(new ContainsTagWithAttribute('a', 'title', 'Popup window'), $html);
$this->assert(new ContainsTagWithAttribute('a', 'href', 'http://otheraddress.com'), $html);
$this->assert(new ContainsTagWithContents('a', 'Click here'), $html);
}
public function test_button() {
global $CFG;
$originalform = new html_form();
$originalform->button->label = 'Click Here';
$originalform->url = '/index.php';
$form = clone($originalform);
$html = $this->renderer->button($form);
$this->assert(new ContainsTagWithAttribute('div', 'class', 'singlebutton'), $html);
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => $CFG->wwwroot . '/index.php')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
$this->assert(new ContainsTagWithAttributes('input', array('value' => 'Click Here', 'type' => 'submit')), $html);
$form = clone($originalform);
$form->button->confirmmessage = 'Are you sure?';
$html = $this->renderer->button($form);
$this->assert(new ContainsTagWithAttribute('div', 'class', 'singlebutton'), $html);
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => $CFG->wwwroot . '/index.php')), $html);
$this->assert(new ContainsTagWithAttribute('input', 'type', 'submit'), $html);
$form = clone($originalform);
$form->url = new moodle_url($form->url, array('var1' => 'value1', 'var2' => 'value2'));
$html = $this->renderer->button($form);
$this->assert(new ContainsTagWithAttributes('input', array('name' => 'var1', 'type' => 'hidden', 'value' => 'value1')), $html);
}
public function test_link() {
$link = new html_link();
$link->url = 'http://test.com';
$link->text = 'Resource 1';
$html = $this->renderer->link($link);
$this->assert(new ContainsTagWithAttribute('a', 'href', 'http://test.com'), $html);
$this->assert(new ContainsTagWithContents('a', 'Resource 1'), $html);
// Add a title
$link->title = 'Link to resource 1';
$html = $this->renderer->link($link);
$this->assert(new ContainsTagWithAttributes('a', array('title' => 'Link to resource 1', 'href' => 'http://test.com')), $html);
$this->assert(new ContainsTagWithContents('a', 'Resource 1'), $html);
// Use a moodle_url object instead of string
$link->url = new moodle_url($link->url);
$html = $this->renderer->link($link);
$this->assert(new ContainsTagWithAttributes('a', array('title' => 'Link to resource 1', 'href' => 'http://test.com')), $html);
$this->assert(new ContainsTagWithContents('a', 'Resource 1'), $html);
// Add a few classes to the link object
$link->add_classes('cool blue');
$html = $this->renderer->link($link);
$this->assert(new ContainsTagWithAttributes('a', array('title' => 'Link to resource 1', 'class' => 'link cool blue', 'href' => 'http://test.com')), $html);
$this->assert(new ContainsTagWithContents('a', 'Resource 1'), $html);
// Simple use of link() without a html_link object
$html = $this->renderer->link($link->url->out(), $link->text);
$expected_html = '<a href="http://test.com">Resource 1</a>';
$this->assert(new ContainsTagWithAttribute('a', 'href', 'http://test.com'), $html);
$this->assert(new ContainsTagWithContents('a', 'Resource 1'), $html);
// Missing second param when first is a string: exception
$this->expectException();
$html = $this->renderer->link($link->url->out());
}
/**
* NOTE: consider the degree of detail in which we test HTML output, because
* the unit tests may be run under a different theme, with different HTML
* renderers. Maybe we should limit unit tests to standardwhite.
*/
public function test_confirm() {
// Basic test with string URLs
$continueurl = 'http://www.test.com/index.php?continue=1';
$cancelurl = 'http://www.test.com/index.php?cancel=1';
$message = 'Are you sure?';
$html = $this->renderer->confirm($message, $continueurl, $cancelurl);
$this->assert(new ContainsTagWithAttributes('div', array('id' => 'notice', 'class' => 'box generalbox')), $html);
$this->assert(new ContainsTagWithContents('p', $message), $html);
$this->assert(new ContainsTagWithAttribute('div', 'class', 'buttons'), $html);
$this->assert(new ContainsTagWithAttribute('div', 'class', 'singlebutton'), $html);
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => 'http://www.test.com/index.php')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'continue', 'value' => 1)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('yes'), 'class' => 'singlebutton')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'cancel', 'value' => 1)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('no'), 'class' => 'singlebutton')), $html);
// Use html_forms with default values, should produce exactly the same output as above
$formcontinue = new html_form();
$formcancel = new html_form();
$formcontinue->url = new moodle_url($continueurl);
$formcancel->url = new moodle_url($cancelurl);
$html = $this->renderer->confirm($message, $formcontinue, $formcancel);
$this->assert(new ContainsTagWithAttributes('div', array('id' => 'notice', 'class' => 'box generalbox')), $html);
$this->assert(new ContainsTagWithContents('p', $message), $html);
$this->assert(new ContainsTagWithAttribute('div', 'class', 'buttons'), $html);
$this->assert(new ContainsTagWithAttribute('div', 'class', 'singlebutton'), $html);
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => 'http://www.test.com/index.php')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'continue', 'value' => 1)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('yes'), 'class' => 'singlebutton')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'cancel', 'value' => 1)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('no'), 'class' => 'singlebutton')), $html);
// Give the buttons some different labels
$formcontinue = new html_form();
$formcancel = new html_form();
$formcontinue->url = new moodle_url($continueurl);
$formcancel->url = new moodle_url($cancelurl);
$formcontinue->button->label = 'Continue anyway';
$formcancel->button->label = 'Wow OK, I get it, backing out!';
$html = $this->renderer->confirm($message, $formcontinue, $formcancel);
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => 'http://www.test.com/index.php')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'continue', 'value' => 1)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => $formcontinue->button->label, 'class' => 'singlebutton')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'cancel', 'value' => 1)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => $formcancel->button->label, 'class' => 'singlebutton')), $html);
// Change the method and add extra variables
$formcontinue = new html_form();
$formcancel = new html_form();
$formcontinue->url = new moodle_url($continueurl, array('var1' => 'val1', 'var2' => 'val2'));
$formcancel->url = new moodle_url($cancelurl, array('var3' => 'val3', 'var4' => 'val4'));
$html = $this->renderer->confirm($message, $formcontinue, $formcancel);
$this->assert(new ContainsTagWithAttributes('form', array('method' => 'post', 'action' => 'http://www.test.com/index.php')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'continue', 'value' => 1)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'var1', 'value' => 'val1')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'var2', 'value' => 'val2')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('yes'), 'class' => 'singlebutton')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'cancel', 'value' => 1)), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'submit', 'value' => get_string('no'), 'class' => 'singlebutton')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'var3', 'value' => 'val3')), $html);
$this->assert(new ContainsTagWithAttributes('input', array('type' => 'hidden', 'name' => 'var4', 'value' => 'val4')), $html);
}
public function test_spacer() {
global $CFG;
$spacer = new html_image();
$html = $this->renderer->spacer($spacer);
$this->assert(new ContainsTagWithAttributes('img', array('class' => 'image spacer',
'src' => $CFG->wwwroot . '/pix/spacer.gif',
'alt' => ''
)), $html);
$spacer = new html_image();
$spacer->src = $this->renderer->old_icon_url('myspacer');
$spacer->alt = 'sometext';
$spacer->add_class('my');
$html = $this->renderer->spacer($spacer);
$this->assert(new ContainsTagWithAttributes('img', array(
'class' => 'my image spacer',
'src' => $this->renderer->old_icon_url('myspacer'),
'alt' => 'sometext')), $html);
}
public function test_paging_bar() {
global $CFG, $OUTPUT;
$totalcount = 5;
$perpage = 4;
$page = 1;
$baseurl = new moodle_url($CFG->wwwroot.'/index.php');
$pagevar = 'mypage';
$pagingbar = new moodle_paging_bar();
$pagingbar->totalcount = $totalcount;
$pagingbar->page = $page;
$pagingbar->perpage = $perpage;
$pagingbar->baseurl = $baseurl;
$pagingbar->pagevar = $pagevar;
$pagingbar->nocurr = true;
$originalbar = clone($pagingbar);
$html = $OUTPUT->paging_bar($pagingbar);
$this->assert(new ContainsTagWithAttribute('div', 'class', 'paging'), $html);
$this->assert(new ContainsTagWithAttributes('a', array('class' => 'previous', 'href' => $baseurl->out().'?mypage=0')), $html);
// One of the links to the previous page must not have the 'previous' class
$this->assert(new ContainsTagWithAttributes('a', array('href' => $baseurl->out().'?mypage=0'), array('class' => 'previous')), $html);
// The link to the current page must not have the 'next' class: it's the last page
$this->assert(new ContainsTagWithAttributes('a', array('href' => $baseurl->out().'?mypage=1'), array('class' => 'next')), $html);
$pagingbar = clone($originalbar); // clone the original bar before each output and set of assertions
$pagingbar->nocurr = false;
$html = $OUTPUT->paging_bar($pagingbar);
$this->assert(new ContainsTagWithAttribute('div', 'class', 'paging'), $html);
$this->assert(new ContainsTagWithAttributes('a', array('href' => $baseurl->out().'?mypage=0'), array('class' => 'previous')), $html);
$this->assert(new ContainsTagWithAttributes('a', array('class' => 'previous', 'href' => $baseurl->out().'?mypage=0')), $html);
$expectation = new ContainsTagWithAttributes('a', array('href' => $baseurl->out().'?mypage=1'), array('class' => 'next'));
$this->assertFalse($expectation->test($html));
// TODO test with more different parameters
}
}

View File

@ -70,7 +70,7 @@ class web_test extends UnitTestCase {
$this->assertEqual(highlight('good', 'This is goodness'), 'This is <span class="highlight">good</span>ness');
}
function test_replace_ampersands() {
function test_replace_ampersands() {
$this->assertEqual(replace_ampersands_not_followed_by_entity("This & that &nbsp;"), "This &amp; that &nbsp;");
$this->assertEqual(replace_ampersands_not_followed_by_entity("This &nbsp that &nbsp;"), "This &amp;nbsp that &nbsp;");
}
@ -92,10 +92,29 @@ class web_test extends UnitTestCase {
$string = "visit http://www.moodle.org";
convert_urls_into_links($string);
$this->assertEqual($string, 'visit <a href="http://www.moodle.org">http://www.moodle.org</a>');
$string = "visit www.moodle.org";
convert_urls_into_links($string);
$this->assertEqual($string, 'visit <a href="http://www.moodle.org">www.moodle.org</a>');
}
function test_prepare_url() {
global $CFG, $PAGE;
$fullexternalurl = 'http://www.externalsite.com/somepage.php';
$fullmoodleurl = $CFG->wwwroot . '/mod/forum/view.php?id=5';
$relativeurl1 = 'edit.php';
$relativeurl2 = '/edit.php';
$this->assertEqual($fullmoodleurl, prepare_url($fullmoodleurl));
$this->assertEqual($fullexternalurl, prepare_url($fullexternalurl));
$this->assertEqual("$CFG->wwwroot/admin/report/unittest/$relativeurl1", prepare_url($relativeurl1));
$this->assertEqual("$CFG->wwwroot$relativeurl2", prepare_url($relativeurl2));
// Use moodle_url object
$this->assertEqual($fullmoodleurl, prepare_url(new moodle_url('/mod/forum/view.php', array('id' => 5))));
$this->assertEqual($fullexternalurl, prepare_url(new moodle_url($fullexternalurl)));
$this->assertEqual("$CFG->wwwroot/admin/report/unittest/$relativeurl1", prepare_url(new moodle_url($relativeurl1)));
$this->assertEqual("$CFG->wwwroot$relativeurl2", prepare_url(new moodle_url($relativeurl2)));
}
}
?>

View File

@ -229,59 +229,96 @@ class ContainsTagWithAttribute extends SimpleExpectation {
/**
* An Expectation that looks to see whether some HMTL contains a tag with an array of attributes.
* All attributes must be present and their values must match the expected values.
* A third parameter can be used to specify attribute=>value pairs which must not be present in a positive match.
*
* @copyright 2009 Nicolas Connault
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class ContainsTagWithAttributes extends SimpleExpectation {
/**
* @var string $tag The name of the Tag to search
*/
protected $tag;
protected $attributes = array();
/**
* @var array $expectedvalues An associative array of parameters, all of which must be matched
*/
protected $expectedvalues = array();
/**
* @var array $forbiddenvalues An associative array of parameters, none of which must be matched
*/
protected $forbiddenvalues = array();
/**
* @var string $failurereason The reason why the test failed: nomatch or forbiddenmatch
*/
protected $failurereason = 'nomatch';
function __construct($tag, $attributes, $message = '%s') {
function __construct($tag, $expectedvalues, $forbiddenvalues=array(), $message = '%s') {
$this->SimpleExpectation($message);
$this->tag = $tag;
$this->attributes = $attributes;
$this->expectedvalues = $expectedvalues;
$this->forbiddenvalues = $forbiddenvalues;
}
function test($html) {
$parser = new DOMDocument();
$parser->validateOnParse = true;
$parser->loadHTML($html);
$list = $parser->getElementsByTagName($this->tag);
$foundamatch = false;
// Iterating through inputs
foreach ($list as $node) {
if (empty($node->attributes) || !is_a($node->attributes, 'DOMNamedNodeMap')) {
continue;
}
$result = true;
// For the current expected attribute under consideration, check that values match
$allattributesmatch = true;
foreach ($this->attributes as $attribute => $expectedvalue) {
if (!$node->attributes->getNamedItem($attribute)) {
break 2;
foreach ($this->expectedvalues as $expectedattribute => $expectedvalue) {
if (!$node->getAttribute($expectedattribute)) {
$this->failurereason = 'nomatch';
continue 2; // Skip this tag, it doesn't have all the expected attributes
}
if ($node->attributes->getNamedItem($attribute)->value != $expectedvalue) {
$result = false;
if ($node->getAttribute($expectedattribute) != $expectedvalue) {
$allattributesmatch = false;
$this->failurereason = 'nomatch';
}
}
if ($result) {
return true;
if ($allattributesmatch) {
$foundamatch = true;
// Now make sure this node doesn't have any of the forbidden attributes either
$nodeattrlist = $node->attributes;
foreach ($nodeattrlist as $domattrname => $domattr) {
if (array_key_exists($domattrname, $this->forbiddenvalues) && $node->getAttribute($domattrname) == $this->forbiddenvalues[$domattrname]) {
$this->failurereason = "forbiddenmatch:$domattrname:" . $node->getAttribute($domattrname);
$foundamatch = false;
}
}
}
}
return false;
return $foundamatch;
}
function testMessage($html) {
$output = 'Content [' . $html . '] does not contain the tag [' . $this->tag . '] with attributes [';
foreach ($this->attributes as $var => $val) {
$output .= "$var=\"$val\" ";
$output = 'Content [' . $html . '] ';
if (preg_match('/forbiddenmatch:(.*):(.*)/', $this->failurereason, $matches)) {
$output .= "contains the tag $this->tag with the forbidden attribute=>value pair: [$matches[1]=>$matches[2]]";
} else if ($this->failurereason == 'nomatch') {
$output .= 'does not contain the tag [' . $this->tag . '] with attributes [';
foreach ($this->expectedvalues as $var => $val) {
$output .= "$var=\"$val\" ";
}
$output = rtrim($output);
$output .= '].';
}
$output = rtrim($output);
$output .= ']';
return $output;
}
}

View File

@ -318,7 +318,7 @@ class moodle_url {
*
* The added params override existing ones if they have the same name.
*
* @param array $params Defaults to null. If null then return value of param 'name'.
* @param array $params Defaults to null. If null then returns all params.
* @return array Array of Params for url.
*/
public function params($params = null) {
@ -483,6 +483,41 @@ class moodle_url {
}
}
/**
* Given an unknown $url type (string or moodle_url), returns a string URL.
* A relative URL is handled with $PAGE->url but gives a debugging error.
*
* @param mixed $url The URL (moodle_url or string)
* @param bool $stripformparams Whether or not to strip the query params from the URL
* @return string
*/
function prepare_url($url, $stripformparams=false) {
global $CFG, $PAGE;
$output = $url;
if ($url instanceof moodle_url) {
$output = $url->out($stripformparams);
}
// Handle relative URLs
if (substr($output, 0, 4) != 'http' && substr($output, 0, 1) != '/') {
if (preg_match('/(.*)\/([A-Za-z0-9-_]*\.php)$/', $PAGE->url->out(true), $matches)) {
debugging('Relative URLs are deprecated, please use an absolute URL in your code', DEBUG_DEVELOPER);
return $matches[1] . "/$output";
} else {
throw new coding_exception('Your page uses bizarre relative URLs which Moodle cannot handle. Please use absolute URLs.');
}
}
// Add wwwroot only if the URL does not already start with http:// or https://
if (!preg_match('|https?://|', $output) ) {
$output = $CFG->wwwroot . $output;
}
return $output;
}
/**
* Determine if there is data waiting to be processed from a form
*
@ -552,157 +587,6 @@ function break_up_long_words($string, $maxsize=20, $cutchar=' ') {
return $output;
}
/**
* This function will print a button/link/etc. form element
* that will work on both Javascript and non-javascript browsers.
*
* Relies on the Javascript function openpopup in javascript.php
* All parameters default to null, only $type and $url are mandatory.
*
* $url must be relative to home page eg /mod/survey/stuff.php
*
* @global object
* @param string $type Can be 'button' or 'link'
* @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
* @param string $name Name to be assigned to the popup window (this is used by
* client-side scripts to "talk" to the popup window)
* @param string $linkname Text to be displayed as web link
* @param int $height Height to assign to popup window
* @param int $width Height to assign to popup window
* @param string $title Text to be displayed as popup page title
* @param string $options List of additional options for popup window
* @param bool $return If true, return as a string, otherwise print
* @param string $id id added to the element
* @param string $class class added to the element
* @return string
*/
function element_to_popup_window ($type=null, $url=null, $name=null, $linkname=null,
$height=400, $width=500, $title=null,
$options=null, $return=false, $id=null, $class=null) {
if (is_null($url)) {
debugging('You must give the url to display in the popup. URL is missing - can\'t create popup window.', DEBUG_DEVELOPER);
}
global $CFG;
if ($options == 'none') { // 'none' is legacy, should be removed in v2.0
$options = null;
}
// add some sane default options for popup windows
if (!$options) {
$options = 'menubar=0,location=0,scrollbars,resizable';
}
if ($width) {
$options .= ',width='. $width;
}
if ($height) {
$options .= ',height='. $height;
}
if ($id) {
$id = ' id="'.$id.'" ';
}
if ($class) {
$class = ' class="'.$class.'" ';
}
if ($name) {
$_name = $name;
if (($name = preg_replace("/\s/", '_', $name)) != $_name) {
debugging('The $name of a popup window shouldn\'t contain spaces - string modified. '. $_name .' changed to '. $name, DEBUG_DEVELOPER);
}
} else {
$name = 'popup';
}
// get some default string, using the localized version of legacy defaults
if (is_null($linkname) || $linkname === '') {
$linkname = get_string('clickhere');
}
if (!$title) {
$title = get_string('popupwindowname');
}
$fullscreen = 0; // must be passed to openpopup
$element = '';
switch ($type) {
case 'button':
$element = '<input type="button" name="'. $name .'" title="'. $title .'" value="'. $linkname .'" '. $id . $class .
"onclick=\"return openpopup('$url', '$name', '$options', $fullscreen);\" />\n";
break;
case 'link':
// Add wwwroot only if the URL does not already start with http:// or https://
if (!preg_match('|https?://|', $url)) {
$url = $CFG->wwwroot . $url;
}
$element = '<a title="'. s(strip_tags($title)) .'" href="'. $url .'" '.
"onclick=\"this.target='$name'; return openpopup('$url', '$name', '$options', $fullscreen);\">$linkname</a>";
break;
default :
print_error('cannotcreatepopupwin');
break;
}
if ($return) {
return $element;
} else {
echo $element;
}
}
/**
* Creates and displays (or returns) a link to a popup window, using element_to_popup_window function.
*
* Simply calls {@link element_to_popup_window()} with type set to 'link'
* @see element_to_popup_window()
*
* @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
* @param string $name Name to be assigned to the popup window (this is used by
* client-side scripts to "talk" to the popup window)
* @param string $linkname Text to be displayed as web link
* @param int $height Height to assign to popup window
* @param int $width Height to assign to popup window
* @param string $title Text to be displayed as popup page title
* @param string $options List of additional options for popup window
* @param bool $return If true, return as a string, otherwise print
* @param string $id id added to the element
* @param string $class class added to the element
* @return string html code to display a link to a popup window.
*/
function link_to_popup_window ($url, $name=null, $linkname=null,
$height=400, $width=500, $title=null,
$options=null, $return=false) {
return element_to_popup_window('link', $url, $name, $linkname, $height, $width, $title, $options, $return, null, null);
}
/**
* Creates and displays (or returns) a buttons to a popup window, using element_to_popup_window function.
*
* Simply calls {@link element_to_popup_window()} with type set to 'button'
* @see element_to_popup_window()
*
* @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
* @param string $name Name to be assigned to the popup window (this is used by
* client-side scripts to "talk" to the popup window)
* @param string $linkname Text to be displayed as web link
* @param int $height Height to assign to popup window
* @param int $width Height to assign to popup window
* @param string $title Text to be displayed as popup page title
* @param string $options List of additional options for popup window
* @param bool $return If true, return as a string, otherwise print
* @param string $id id added to the element
* @param string $class class added to the element
* @return string html code to display a link to a popup window.
*/
function button_to_popup_window ($url, $name=null, $linkname=null,
$height=400, $width=500, $title=null, $options=null, $return=false,
$id=null, $class=null) {
return element_to_popup_window('button', $url, $name, $linkname, $height, $width, $title, $options, $return, $id, $class);
}
/**
* Prints a simple button to close a window
@ -3164,240 +3048,6 @@ function _print_custom_corners_end($idbase) {
}
/**
* Print a self contained form with a single submit button.
*
* @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
* @param array $options these become hidden form fields, so these options get passed to the script at $link.
* @param string $label the caption that appears on the button.
* @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
* @param string $notusedanymore no longer used.
* @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
* @param string $tooltip a tooltip to add to the button as a title attribute.
* @param boolean $disabled if true, the button will be disabled.
* @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
* @param string $formid The id attribute to use for the form
* @return string|void Depending on the $return paramter.
*/
function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
$return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
$output = '';
if ($formid) {
$formid = ' id="' . s($formid) . '"';
}
$link = str_replace('"', '&quot;', $link); //basic XSS protection
$output .= '<div class="singlebutton">';
// taking target out, will need to add later target="'.$target.'"
$output .= '<form action="'. $link .'" method="'. $method .'"' . $formid . '>';
$output .= '<div>';
if ($options) {
foreach ($options as $name => $value) {
$output .= '<input type="hidden" name="'. $name .'" value="'. s($value) .'" />';
}
}
if ($tooltip) {
$tooltip = 'title="' . s($tooltip) . '"';
} else {
$tooltip = '';
}
if ($disabled) {
$disabled = 'disabled="disabled"';
} else {
$disabled = '';
}
if ($jsconfirmmessage){
$jsconfirmmessage = addslashes_js($jsconfirmmessage);
$jsconfirmmessage = 'onclick="return confirm(\''. $jsconfirmmessage .'\');" ';
}
$output .= '<input type="submit" value="'. s($label) ."\" $tooltip $disabled $jsconfirmmessage/></div></form></div>";
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print a spacer image with the option of including a line break.
*
* @global object
* @param int $height The height in pixels to make the spacer
* @param int $width The width in pixels to make the spacer
* @param boolean $br If set to true a BR is written after the spacer
*/
function print_spacer($height=1, $width=1, $br=true, $return=false) {
global $CFG;
$output = '';
$output .= '<img class="spacer" height="'. $height .'" width="'. $width .'" src="'. $CFG->wwwroot .'/pix/spacer.gif" alt="" />';
if ($br) {
$output .= '<br />'."\n";
}
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Given the path to a picture file in a course, or a URL,
* this function includes the picture in the page.
*
* @global object
* @param string $path The path the to the picture
* @param int $courseid The courseid the picture is associated with if any
* @param int $height The height of the picture in pixels if known
* @param int $width The width of the picture in pixels if known
* @param string $link If set the image is wrapped with this link
* @param bool $return If true the HTML is returned rather than being echo'd
* @return string|void Depending on $return
*/
function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
global $CFG;
$output = '';
if ($height) {
$height = 'height="'. $height .'"';
}
if ($width) {
$width = 'width="'. $width .'"';
}
if ($link) {
$output .= '<a href="'. $link .'">';
}
if (substr(strtolower($path), 0, 7) == 'http://') {
$output .= '<img style="height:'.$height.'px;width:'.$width.'px;" src="'. $path .'" />';
} else if ($courseid) {
$output .= '<img style="height:'.$height.'px;width:'.$width.'px;" src="';
require_once($CFG->libdir.'/filelib.php');
$output .= get_file_url("$courseid/$path");
$output .= '" />';
} else {
$output .= 'Error: must pass URL or course';
}
if ($link) {
$output .= '</a>';
}
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print the specified user's avatar.
*
* @global object
* @global object
* @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname
* If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
* if at all possible, particularly for reports. It is very bad for performance.
* @param int $courseid The course id. Used when constructing the link to the user's profile.
* @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
* @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatability
* @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 the user's profile (default true).
* @param string $target link target attribute. Makes the profile open in a popup window.
* @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
* decorative images, or where the username will be printed anyway.)
* @return string|void String or nothing, depending on $return.
*/
function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
global $CFG, $DB, $OUTPUT;
$needrec = false;
// only touch the DB if we are missing data...
if (is_object($user)) {
// Note - both picture and imagealt _can_ be empty
// what we are trying to see here is if they have been fetched
// from the DB. We should use isset() _except_ that some installs
// have those fields as nullable, and isset() will return false
// on null. The only safe thing is to ask array_key_exists()
// which works on objects. property_exists() isn't quite
// what we want here...
if (! (array_key_exists('picture', $user)
&& ($alttext && array_key_exists('imagealt', $user)
|| (isset($user->firstname) && isset($user->lastname)))) ) {
$needrec = true;
$user = $user->id;
}
} else {
if ($alttext) {
// we need firstname, lastname, imagealt, can't escape...
$needrec = true;
} else {
$userobj = new StdClass; // fake it to save DB traffic
$userobj->id = $user;
$userobj->picture = $picture;
$user = clone($userobj);
unset($userobj);
}
}
if ($needrec) {
$user = $DB->get_record('user', array('id'=>$user), 'id,firstname,lastname,imagealt');
}
if ($link) {
$url = '/user/view.php?id='. $user->id .'&amp;course='. $courseid ;
if ($target) {
$target='onclick="return openpopup(\''.$url.'\');"';
}
$output = '<a '.$target.' href="'. $CFG->wwwroot . $url .'">';
} else {
$output = '';
}
if (empty($size)) {
$file = 'f2';
$size = 35;
} else if ($size === true or $size == 1) {
$file = 'f1';
$size = 100;
} else if ($size >= 50) {
$file = 'f1';
} else {
$file = 'f2';
}
$class = "userpicture";
if (is_null($picture)) {
$picture = $user->picture;
}
if ($picture) { // Print custom user picture
require_once($CFG->libdir.'/filelib.php');
$src = get_file_url($user->id.'/'.$file.'.jpg', null, 'user');
} else { // Print default user pictures (use theme version if available)
$class .= " defaultuserpic";
$src = $OUTPUT->old_icon_url('u/' . $file);
}
$imagealt = '';
if ($alttext) {
if (!empty($user->imagealt)) {
$imagealt = $user->imagealt;
} else {
$imagealt = get_string('pictureof','',fullname($user));
}
}
$output .= "<img class=\"$class\" src=\"$src\" height=\"$size\" width=\"$size\" alt=\"".s($imagealt).'" />';
if ($link) {
$output .= '</a>';
}
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Prints a summary of a user in a nice little box.
*
@ -3599,43 +3249,6 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li
}
}
/**
* Print a png image.
*
* @global object
* @staticvar bool $recentIE
* @param string $url The URL of the image to display
* @param int $sizex The width of the image in pixels
* @param int $sizey The height of the image in pixels
* @param boolean $return If true the HTML is returned rather than echo'd
* @param string $parameters Additional HTML attributes to set
* @return string|bool Depending on $return
*/
function print_png($url, $sizex, $sizey, $return, $parameters='alt=""') {
global $OUTPUT;
static $recentIE;
if (!isset($recentIE)) {
$recentIE = check_browser_version('MSIE', '5.0');
}
if ($recentIE) { // work around the HORRIBLE bug IE has with alpha transparencies
$output .= '<img src="'. $OUTPUT->old_icon_url('spacer') . '" width="'. $sizex .'" height="'. $sizey .'"'.
' class="png" style="width: '. $sizex .'px; height: '. $sizey .'px; '.
' filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.
"'$url', sizingMethod='scale') ".
' '. $parameters .' />';
} else {
$output .= '<img src="'. $url .'" style="width: '. $sizex .'px; height: '. $sizey .'px; '. $parameters .' />';
}
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Display a recent activity note
@ -3676,69 +3289,6 @@ function print_recent_activity_note($time, $user, $text, $link, $return=false, $
}
/**
* Prints a basic textarea field.
*
* When using this function, you should
*
* @global object
* @param bool $usehtmleditor Enables the use of the htmleditor for this field.
* @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
* @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
* @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored.
* @param null $height (Deprecated) Height of the element; if a value is passe, the minimum value for $rows will be 10. Value is otherwise ignored.
* @param string $name Name to use for the textarea element.
* @param string $value Initial content to display in the textarea.
* @param int $obsolete deprecated
* @param bool $return If false, will output string. If true, will return string value.
* @param string $id CSS ID to add to the textarea element.
* @return string|void depending on the value of $return
*/
function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
/// $width and height are legacy fields and no longer used as pixels like they used to be.
/// However, you can set them to zero to override the mincols and minrows values below.
global $CFG;
$mincols = 65;
$minrows = 10;
$str = '';
if ($id === '') {
$id = 'edit-'.$name;
}
if ($usehtmleditor) {
if ($height && ($rows < $minrows)) {
$rows = $minrows;
}
if ($width && ($cols < $mincols)) {
$cols = $mincols;
}
}
if ($usehtmleditor) {
editors_head_setup();
$editor = get_preferred_texteditor(FORMAT_HTML);
$editor->use_editor($id, array('legacy'=>true));
} else {
$editorclass = '';
}
$str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
if ($usehtmleditor) {
$str .= htmlspecialchars($value); // needed for editing of cleaned text!
} else {
$str .= s($value);
}
$str .= '</textarea>'."\n";
if ($return) {
return $str;
}
echo $str;
}
/**
* Returns a turn edit on/off button for course in a self contained form.
* Used to be an icon, but it's now a simple form button
@ -4313,6 +3863,7 @@ function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $
* Showing all possible numerical grades and scales
*
* @todo Finish documenting this function
* @todo Deprecate: this is only used in a few contrib modules
*
* @global object
* @param int $courseid The course ID
@ -4353,35 +3904,6 @@ function print_grade_menu($courseid, $name, $current, $includenograde=true, $ret
}
}
/**
* Prints a scale menu (as part of an existing form) including help button
* Just like {@link print_grade_menu()} but without the numeric grades
*
* @global object
* @param int $courseid ?
* @param string $name ?
* @param string $current ?
* @param boolean $return If set to true returns rather than echo's
* @return string|bool Depending on value of $return
*/
function print_scale_menu($courseid, $name, $current, $return=false) {
global $CFG, $OUTPUT;
$output = '';
$strscales = get_string('scales');
$output .= choose_from_menu(get_scales_menu($courseid), $name, $current, '', '', 0, true);
$linkobject = '<span class="helplink"><img class="iconhelp" alt="'.$strscales.'" src="'.$OUTPUT->old_icon_url('help') . '" /></span>';
$output .= link_to_popup_window ('/course/scales.php?id='. $courseid .'&amp;list=true', 'ratingscales',
$linkobject, 400, 500, $strscales, 'none', true);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Prints a help button about a scale
*
@ -4490,95 +4012,6 @@ function editorhelpbutton(){
return link_to_popup_window(s('/lib/form/editorhelp.php?'.$paramstring), 'popup', $linkobject, 400, 500, $alttag, 'none', true);
}
/**
* Print a help button.
*
* @global object
* @global object
* @uses DEBUG_DEVELOPER
* @param string $page The keyword that defines a help page
* @param string $title The title of links, rollover tips, alt tags etc
* 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
* @param string $module Which module is the page defined in
* @param mixed $image Use a help image for the link? (true/false/"both")
* @param boolean $linktext If true, display the title next to the help icon.
* @param string $text If defined then this text is used in the page, and
* the $page variable is ignored.
* @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
* @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
* @return string|void Depending on value of $return
*/
function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false,
$imagetext='') {
global $CFG, $COURSE, $OUTPUT;
//warning if ever $text parameter is used
//$text option won't work properly because the text needs to be always cleaned and,
// when cleaned... html tags always break, so it's unusable.
if ( isset($text) && $text!='') {
debugging('Warning: it\'s not recommended to use $text parameter in helpbutton ($page=' . $page . ', $module=' . $module . ') function', DEBUG_DEVELOPER);
}
// Catch references to the old text.html and emoticons.html help files that
// were renamed in MDL-13233.
if (in_array($page, array('text', 'emoticons', 'richtext'))) {
$oldname = $page;
$page .= '2';
debugging("You are referring to the old help file '$oldname'. " .
"This was renamed to '$page' becuase of MDL-13233. " .
"Please update your code.", DEBUG_DEVELOPER);
}
if ($module == '') {
$module = 'moodle';
}
if ($title == '' && $linktext == '') {
debugging('Error in call to helpbutton function: at least one of $title and $linktext is required');
}
// Warn users about new window for Accessibility
$tooltip = get_string('helpprefix2', '', trim($title, ". \t")) .' ('.get_string('newwindow').')';
$linkobject = '';
if ($image) {
if ($linktext) {
// MDL-7469 If text link is displayed with help icon, change to alt to "help with this".
$linkobject .= $title.'&nbsp;';
$tooltip = get_string('helpwiththis');
}
if ($imagetext) {
$linkobject .= $imagetext;
} else {
$linkobject .= '<img class="iconhelp" alt="'.s(strip_tags($tooltip)).'" src="'.
$OUTPUT->old_icon_url('help') . '" />';
}
} else {
$linkobject .= $tooltip;
}
// fix for MDL-7734
if ($text) {
$url = '/help.php?text='. s(urlencode($text));
} else {
$url = '/help.php?module='. $module .'&amp;file='. $page .'.html';
// fix for MDL-7734
if (!empty($COURSE->lang)) {
$url .= '&amp;forcelang=' . $COURSE->lang;
}
}
$link = '<span class="helplink">' . link_to_popup_window($url, 'popup',
$linkobject, 400, 500, $tooltip, 'none', true) . '</span>';
if ($return) {
return $link;
} else {
echo $link;
}
}
/**
* Print a help button.
*
@ -4664,36 +4097,6 @@ function notice ($message, $link='', $course=NULL) {
exit(1); // general error code
}
/**
* Print a message along with "Yes" and "No" links for the user to continue.
*
* @global object
* @param string $message The text to display
* @param string $linkyes The link to take the user to if they choose "Yes"
* @param string $linkno The link to take the user to if they choose "No"
* @param string $optionyes The yes option to show on the notice
* @param string $optionsno The no option to show
* @param string $methodyes Form action method to use if yes [post, get]
* @param string $methodno Form action method to use if no [post, get]
* @return void Output is echo'd
*/
function notice_yesno ($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
global $CFG;
$message = clean_text($message);
$linkyes = clean_text($linkyes);
$linkno = clean_text($linkno);
print_box_start('generalbox', 'notice');
echo '<p>'. $message .'</p>';
echo '<div class="buttons">';
print_single_button($linkyes, $optionsyes, get_string('yes'), $methodyes, $CFG->framename);
print_single_button($linkno, $optionsno, get_string('no'), $methodno, $CFG->framename);
echo '</div>';
print_box_end();
}
/**
* Redirects the user to another page, after printing a notice
*
@ -4856,93 +4259,6 @@ function obfuscate_mailto($email, $label='', $dimmed=false) {
obfuscate_text($label));
}
/**
* Prints a single paging bar to provide access to other pages (usually in a search)
*
* @param int $totalcount Thetotal number of entries available to be paged through
* @param int $page The page you are currently viewing
* @param int $perpage The number of entries that should be shown per page
* @param mixed $baseurl If this is a string then it is the url which will be appended with $pagevar, an equals sign and the page number.
* If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
* @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
* @param bool $nocurr do not display the current page as a link
* @param bool $return whether to return an output string or echo now
* @return bool|string depending on $result
*/
function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
$maxdisplay = 18;
$output = '';
if ($totalcount > $perpage) {
$output .= '<div class="paging">';
$output .= get_string('page') .':';
if ($page > 0) {
$pagenum = $page - 1;
if (!is_a($baseurl, 'moodle_url')){
$output .= '&nbsp;(<a class="previous" href="'. $baseurl . $pagevar .'='. $pagenum .'">'. get_string('previous') .'</a>)&nbsp;';
} else {
$output .= '&nbsp;(<a class="previous" href="'. $baseurl->out(false, array($pagevar => $pagenum)).'">'. get_string('previous') .'</a>)&nbsp;';
}
}
if ($perpage > 0) {
$lastpage = ceil($totalcount / $perpage);
} else {
$lastpage = 1;
}
if ($page > 15) {
$startpage = $page - 10;
if (!is_a($baseurl, 'moodle_url')){
$output .= '&nbsp;<a href="'. $baseurl . $pagevar .'=0">1</a>&nbsp;...';
} else {
$output .= '&nbsp;<a href="'. $baseurl->out(false, array($pagevar => 0)).'">1</a>&nbsp;...';
}
} else {
$startpage = 0;
}
$currpage = $startpage;
$displaycount = $displaypage = 0;
while ($displaycount < $maxdisplay and $currpage < $lastpage) {
$displaypage = $currpage+1;
if ($page == $currpage && empty($nocurr)) {
$output .= '&nbsp;&nbsp;'. $displaypage;
} else {
if (!is_a($baseurl, 'moodle_url')){
$output .= '&nbsp;&nbsp;<a href="'. $baseurl . $pagevar .'='. $currpage .'">'. $displaypage .'</a>';
} else {
$output .= '&nbsp;&nbsp;<a href="'. $baseurl->out(false, array($pagevar => $currpage)).'">'. $displaypage .'</a>';
}
}
$displaycount++;
$currpage++;
}
if ($currpage < $lastpage) {
$lastpageactual = $lastpage - 1;
if (!is_a($baseurl, 'moodle_url')){
$output .= '&nbsp;...<a href="'. $baseurl . $pagevar .'='. $lastpageactual .'">'. $lastpage .'</a>&nbsp;';
} else {
$output .= '&nbsp;...<a href="'. $baseurl->out(false, array($pagevar => $lastpageactual)).'">'. $lastpage .'</a>&nbsp;';
}
}
$pagenum = $page + 1;
if ($pagenum != $displaypage) {
if (!is_a($baseurl, 'moodle_url')){
$output .= '&nbsp;&nbsp;(<a class="next" href="'. $baseurl . $pagevar .'='. $pagenum .'">'. get_string('next') .'</a>)';
} else {
$output .= '&nbsp;&nbsp;(<a class="next" href="'. $baseurl->out(false, array($pagevar => $pagenum)) .'">'. get_string('next') .'</a>)';
}
}
$output .= '</div>';
}
if ($return) {
return $output;
}
echo $output;
return true;
}
/**
* This function is used to rebuild the <nolink> tag because some formats (PLAIN and WIKI)
* will transform it to html entities
@ -5186,42 +4502,6 @@ function get_docs_url($path) {
return $CFG->docroot . '/' . str_replace('_utf8', '', current_language()) . '/' . $path;
}
/**
* Returns a string containing a link to the user documentation.
* Also contains an icon by default. Shown to teachers and admin only.
*
* @global object
* @param string $path The page link after doc root and language, no leading slash.
* @param string $text The text to be displayed for the link
* @param string $iconpath The path to the icon to be displayed
* @return string Either the link or an empty string
*/
function doc_link($path='', $text='', $iconpath='') {
global $CFG;
if (empty($CFG->docroot)) {
return '';
}
$url = get_docs_url($path);
$target = '';
if (!empty($CFG->doctonewwindow)) {
$target = " onclick=\"window.open('$url'); return false;\"";
}
$str = "<a href=\"$url\"$target>";
if (empty($iconpath)) {
$iconpath = $CFG->httpswwwroot . '/pix/docs.gif';
}
// alt left blank intentionally to prevent repetition in screenreaders
$str .= '<img class="iconhelp" src="' .$iconpath. '" alt="" />' .$text. '</a>';
return $str;
}
/**
* Standard Debugging Function
@ -5325,58 +4605,6 @@ function print_location_comment($file, $line, $return = false)
}
/**
* Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
* provide this function with the language strings for sortasc and sortdesc.
*
* If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
*
* @global object
* @param string $direction 'up' or 'down'
* @param string $strsort The language string used for the alt attribute of this image
* @param bool $return Whether to print directly or return the html string
* @return string|void depending on $return
*
*/
function print_arrow($direction='up', $strsort=null, $return=false) {
global $OUTPUT;
if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
return null;
}
$return = null;
switch ($direction) {
case 'up':
$sortdir = 'asc';
break;
case 'down':
$sortdir = 'desc';
break;
case 'move':
$sortdir = 'asc';
break;
default:
$sortdir = null;
break;
}
// Prepare language string
$strsort = '';
if (empty($strsort) && !empty($sortdir)) {
$strsort = get_string('sort' . $sortdir, 'grades');
}
$return = ' <img src="'.$OUTPUT->old_icon_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
if ($return) {
return $return;
} else {
echo $return;
}
}
/**
* @return boolean true if the current language is right-to-left (Hebrew, Arabic etc)
*/

View File

@ -93,4 +93,7 @@ form.mform textarea {
}
#mod-quiz-edit .reorder .questioncontentcontainer .randomquestioncategory label{
width: 35%;
}
}
#help_icon_tooltip .yui-tt-shadow-visible {
background-color: transparent;
}

View File

@ -595,6 +595,22 @@ div.hide {
margin:0.2em 0pt;
text-align:left;
}
#help_icon_tooltip {
font-size: 0.7em;
}
#help_icon_tooltip h1 {
font-size: 1.1em;
font-weight: bold;
}
#help_icon_tooltip div.bd {
width: 35em;
}
#help_icon_tooltip .readmore {
display: block;
font-style: italic;
margin-top:10px;
}
/***
*** Forms