MDL-21217, MDL-21198 simplified/improved outputlib help icon related apis + several fixed regresions

This commit is contained in:
Petr Skoda 2009-12-30 15:19:55 +00:00
parent 48a67d9f01
commit 4bcc51185c
113 changed files with 442 additions and 970 deletions

View file

@ -2401,127 +2401,6 @@ function mdie($msg='', $errorcode=1) {
exit($errorcode);
}
/**
* Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
* Should be used only with htmleditor or textarea.
*
* @global object
* @global object
* @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
* helpbutton.
* @return string Link to help button
*/
function editorhelpbutton(){
global $CFG, $SESSION, $OUTPUT;
$items = func_get_args();
$i = 1;
$urlparams = array();
$titles = array();
foreach ($items as $item){
if (is_array($item)){
$urlparams[] = "keyword$i=".urlencode($item[0]);
$urlparams[] = "title$i=".urlencode($item[1]);
if (isset($item[2])){
$urlparams[] = "module$i=".urlencode($item[2]);
}
$titles[] = trim($item[1], ". \t");
} else if (is_string($item)) {
$urlparams[] = "button$i=".urlencode($item);
switch ($item) {
case 'reading' :
$titles[] = get_string("helpreading");
break;
case 'writing' :
$titles[] = get_string("helpwriting");
break;
case 'questions' :
$titles[] = get_string("helpquestions");
break;
case 'emoticons2' :
$titles[] = get_string("helpemoticons");
break;
case 'richtext2' :
$titles[] = get_string('helprichtext');
break;
case 'text2' :
$titles[] = get_string('helptext');
break;
default :
print_error('unknownhelp', '', '', $item);
}
}
$i++;
}
if (count($titles)>1){
//join last two items with an 'and'
$a = new object();
$a->one = $titles[count($titles) - 2];
$a->two = $titles[count($titles) - 1];
$titles[count($titles) - 2] = get_string('and', '', $a);
unset($titles[count($titles) - 1]);
}
$alttag = join (', ', $titles);
$paramstring = join('&', $urlparams);
$linkobject = '<img alt="'.$alttag.'" class="iconhelp" src="'.$OUTPUT->pix_url('help') . '" />';
$link = html_link::make(s('/lib/form/editorhelp.php?'.$paramstring), $linkobject);
$link->add_action(new popup_action('click', $link->url, 'popup', array('height' => 400, 'width' => 500)));
$link->title = $alttag;
return $OUTPUT->link($link);
}
/**
* Print a help button.
*
* Prints a special help button that is a link to the "live" emoticon popup
*
* @todo Finish documenting this function
*
* @global object
* @global object
* @param string $form ?
* @param string $field ?
* @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
* @return string|void Depending on value of $return
*/
function emoticonhelpbutton($form, $field, $return = false) {
global $SESSION, $OUTPUT;
$SESSION->inserttextform = $form;
$SESSION->inserttextfield = $field;
$helpicon = moodle_help_icon::make('emoticons2', get_string('helpemoticons'), 'moodle', true);
$helpicon->image->src = $OUTPUT->pix_url('s/smiley');
$helpicon->image->add_class('emoticon');
$helpicon->style = "margin-left:3px; padding-right:1px;width:15px;height:15px;";
$help = $OUTPUT->help_icon($helpicon);
if (!$return){
echo $help;
} else {
return $help;
}
}
/**
* Print a help button.
*
* Prints a special help button for html editors (htmlarea in this case)
*
* @todo Write code into this function! detect current editor and print correct info
* @global object
* @return string Only returns an empty string at the moment
*/
function editorshortcutshelpbutton() {
global $CFG;
//TODO: detect current editor and print correct info
/* $imagetext = '<img src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
get_string('editorshortcutkeys').'" class="iconkbhelp" />';
return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);*/
return '';
}
/**
* Returns html code to be used as help icon of modgrade form element
*