]> git.mjollnir.org Git - moodle.git/commitdiff
some bug fixes in setHelpButton internals.
authorjamiesensei <jamiesensei>
Thu, 4 Jan 2007 10:23:06 +0000 (10:23 +0000)
committerjamiesensei <jamiesensei>
Thu, 4 Jan 2007 10:23:06 +0000 (10:23 +0000)
added new editorhelpbutton function that can be used to refer to several help topics.

16 files changed:
lang/en_utf8/moodle.php
lib/form/button.php
lib/form/checkbox.php
lib/form/editorhelp.php [new file with mode: 0644]
lib/form/file.php
lib/form/group.php
lib/form/header.php
lib/form/htmleditor.php
lib/form/password.php
lib/form/radio.php
lib/form/select.php
lib/form/static.php
lib/form/text.php
lib/form/textarea.php
lib/weblib.php
mod/forum/post_form.php

index 0b1aea5453e9dc09361c8b0b1abea43688e25e53..6d77db4d58e2fd038b9bb91fd3e79c114bed9b70 100644 (file)
@@ -108,6 +108,7 @@ $string['alphabet'] = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z';
 $string['alphanumerical'] = 'Can only contain alphabetical letters or numbers';
 $string['alreadyconfirmed'] = 'Registration has already been confirmed';
 $string['always'] = 'Always';
+$string['and'] = '$a->one and $a->two';
 $string['answer'] = 'Answer';
 $string['approve'] = 'Approve';
 $string['areyousuretorestorethis'] = 'Do you want to continue?';
@@ -403,6 +404,7 @@ $string['editordefaultfont'] = 'Default font';
 $string['editorenablespelling'] = 'Enable spellchecking';
 $string['editorfontlist'] = 'Fontlist';
 $string['editorfontsize'] = 'Default font-size';
+$string['editorhelptopics'] = 'Editor Help Topics.';
 $string['editorresettodefaults'] = 'Reset to default values';
 $string['editorsettings'] = 'Editor settings';
 $string['editorshortcutkeys'] = 'Editor shortcut keys';
index 514c687116fabb401d8efbf21efd3fdb5bd77464..a58f8d079a42910f03eb421b5f95ea4e61486b9d 100644 (file)
@@ -53,8 +53,10 @@ class MoodleQuickForm_button extends HTML_QuickForm_button
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
index f1eaaa4bd87699aec170a8213208104768895b36..6308f4ab2bca0069b840e1dd573c5aa23f827077 100644 (file)
@@ -29,8 +29,10 @@ class MoodleQuickForm_checkbox extends HTML_QuickForm_checkbox{
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
diff --git a/lib/form/editorhelp.php b/lib/form/editorhelp.php
new file mode 100644 (file)
index 0000000..9a574b6
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+require_once('../../config.php');
+$topics = array();
+$titles = array();
+for ($i=1; ; $i++){
+    $button = optional_param("button$i", '', PARAM_ALPHAEXT);
+    if ($button){
+        switch ($button){
+            case 'reading' :
+                $topics[$i] = helplink('reading', get_string('helpreading'), 'moodle', false, true);
+                break;
+            case 'writing' :
+                $topics[$i] = helplink('writing', get_string('helpwriting'));
+                break;
+            case 'questions' :
+                $topics[$i] = helplink('questions', get_string('helpquestions'));
+                break;
+            case 'emoticons' :
+                $topics[$i] = helplink('emoticons', get_string('helpemoticons'));
+                break;
+            case 'richtext' :
+                $topics[$i] = helplink('richtext', get_string('helprichtext'));
+                break;
+            default :
+                error('Unknown help topic '.$item);
+        }
+    } else {
+        $keyword = optional_param("keyword$i", '', PARAM_ALPHAEXT);
+        if ('' == $keyword) {
+            break;//exit for loop -  no more help items
+        }
+        $title = optional_param("title$i", '', PARAM_NOTAGS);
+        $module = optional_param("module$i", 'moodle', PARAM_ALPHAEXT);
+        $func[$i] = 'helpbutton';
+        $topics[$i] = array($keyword, $title, $module);
+    }
+
+}
+print_header();
+print_simple_box_start('center', '96%');
+print_heading(get_string('editorhelptopics'));
+
+
+echo '<ul>';
+foreach ($topics as $i => $topic){
+    echo('<li>'.$topics[$i].'</li>');
+}
+echo '</ul>';
+print_simple_box_end();
+// End of page.
+close_window_button();
+echo '<p align="center"><a href="help.php?file=index.html">'. get_string('helpindex') .'</a></p>';
+
+$CFG->docroot = '';   // We don't want a doc link here
+print_footer('none');
+die;
+/**
+ * A function to return a simple link to a help page. We don't want a popup here
+ * since these links are displayed in a pop up already.
+ *
+ * @param string $page
+ * @param string $linktext
+ * @param string $module
+ * @return string
+ */
+function helplink($page, $linktext='', $module='moodle'){
+    global $CFG;
+    return "<a href=\"$CFG->wwwroot/help.php?module=$module&amp;file=$page.html\">$linktext</a>";
+}
+
+?>
\ No newline at end of file
index 8790c224870da958f1d0bf6f9393be79cdfc3616..8c18830c6c6f8f59ddc3c189be5b7823b2beb0f9 100644 (file)
@@ -29,8 +29,10 @@ class MoodleQuickForm_file extends HTML_QuickForm_file{
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
@@ -56,6 +58,6 @@ class MoodleQuickForm_file extends HTML_QuickForm_file{
         }
         return parent::onQuickFormEvent($event, $arg, $caller);
     } // end func onQuickFormEvent
-    
+
 }
 ?>
\ No newline at end of file
index 714bdddca404e7b8dc1c46de723df75f0ea6b20e..af8be99528f7c3d4ba4ed1b6bba4e245d09d1c5a 100644 (file)
@@ -35,8 +35,10 @@ class MoodleQuickForm_group extends HTML_QuickForm_group{
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
index d7ef023bc65e555a155442f86c02385e60d1ad26..b2f6b7e408136b143c40f648a86d2130ddb4799c 100644 (file)
@@ -47,8 +47,10 @@ class MoodleQuickForm_header extends HTML_QuickForm_header
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
index 5d5e2f7f4c5383ab692f1312bcf4a34bdf34e1b5..88fdf8f2dc1764604086034235fa9a2be7913ebe 100644 (file)
@@ -4,7 +4,7 @@ require_once("$CFG->libdir/form/textarea.php");
 
 /**
  * HTML class for htmleditor type element
- * 
+ *
  * @author       Jamie Pratt
  * @access       public
  */
@@ -12,7 +12,7 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
     var $_type;
     var $_elementTemplateType='default';
     var $_canUseHtmlEditor;
-    var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>65, 'width'=>0,'height'=>0, 'course'=>0);
+    var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0, 'course'=>0);
     function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){
         parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes);
         // set the options, do not bother setting bogus ones
@@ -36,12 +36,31 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
         }else{
             $this->_type='textarea';
         }
+        $this->_canUseHtmlEditor = $this->_options['canUseHtmlEditor'];
+    }
+    /**
+     * set html for help button
+     *
+     * @access   public
+     * @param array $help array of arguments to make a help button
+     * @param string $function function name to call to get html
+     */
+    function setHelpButton($helpbuttonargs, $function='helpbutton'){
+        if (!$this->_canUseHtmlEditor){
+            if ('editorhelpbutton' == $function){
+                $key = array_search('richtext', $helpbuttonargs);
+                if ($key !== FALSE){
+                    $helpbuttonargs[$key]='emoticons';
+                }
+            }
+        }
+        return parent::setHelpButton($helpbuttonargs, $function);
     }
     function getElementTemplateType(){
         return $this->_elementTemplateType;
     }
     function toHtml(){
-        if ($this->_options['canUseHtmlEditor'] && !$this->_flagFrozen){
+        if ($this->_canUseHtmlEditor && !$this->_flagFrozen){
             ob_start();
             use_html_editor($this->getName(), '', $this->getAttribute('id'));
             $script=ob_get_clean();
@@ -52,7 +71,7 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{
             return $this->getFrozenHtml();
         } else {
             return $this->_getTabs() .
-                    print_textarea($this->_options['canUseHtmlEditor'], 
+                    print_textarea($this->_canUseHtmlEditor,
                                     $this->_options['rows'],
                                     $this->_options['cols'],
                                     $this->_options['width'],
index 183221d6f18665fdf04c164c9e0dfd01b280a7ca..9c0cc08aff0a19b89f466f3637313459ebed9fa6 100644 (file)
@@ -29,8 +29,10 @@ class MoodleQuickForm_password extends HTML_QuickForm_password{
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
index f80244a23233437b0f122f894ee775d0bee0ce47..2fb2cb5798ab79a924537fba2638f514b06236c8 100644 (file)
@@ -29,8 +29,10 @@ class MoodleQuickForm_radio extends HTML_QuickForm_radio{
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
index 245fa338a2c386ffc6455e8cfee32b3efd03ade5..d4f3df8ac6ffafc1b4bda4eab2e03f4e804314ed 100644 (file)
@@ -60,8 +60,10 @@ class MoodleQuickForm_select extends HTML_QuickForm_select{
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
index acc5e0bd09499d9c4c57af7f23842627d32f3dc2..dc0a05baf8d44aa12e2811d3db60b673b940c152 100644 (file)
@@ -29,8 +29,10 @@ class MoodleQuickForm_static extends HTML_QuickForm_static{
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
index c517d1a11194bccee8b74be4f7a0922d5a17b04c..dc9e0db5ba65806b75900ac9c13651a6e4ebf591 100644 (file)
@@ -60,8 +60,10 @@ class MoodleQuickForm_text extends HTML_QuickForm_text{
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
index ebd04cf3e5bce6b434669b5b80d4b2fc115514bb..597cb328bd6a7df501420c79773414591151f914 100644 (file)
@@ -8,6 +8,12 @@ require_once('HTML/QuickForm/textarea.php');
  * @access       public
  */
 class MoodleQuickForm_textarea extends HTML_QuickForm_textarea{
+    /**
+     * Need to store id of form as we may need it for helpbutton
+     *
+     * @var string
+     */
+    var $_formid = '';
     /**
      * html for help button, if empty then no help
      *
@@ -29,8 +35,15 @@ class MoodleQuickForm_textarea extends HTML_QuickForm_textarea{
         }
         //we do this to to return html instead of printing it
         //without having to specify it in every call to make a button.
-        $defaultargs=array('', '', 'moodle', true, false, '', true);
-        $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        } elseif ('editorhelpbutton' == $function){
+            if (in_array('emoticons', $helpbuttonargs)){
+                $SESSION->inserttextform = $this->_formid;
+                $SESSION->inserttextfield = 'id_'.$this->getAttribute('id');
+            }
+        }
         $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
     }
     /**
@@ -42,5 +55,24 @@ class MoodleQuickForm_textarea extends HTML_QuickForm_textarea{
     function getHelpButton(){
         return $this->_helpbutton;
     }
+    /**
+     * Called by HTML_QuickForm whenever form event is made on this element
+     *
+     * @param     string    $event  Name of event
+     * @param     mixed     $arg    event arguments
+     * @param     object    $caller calling object
+     * @since     1.0
+     * @access    public
+     * @return    void
+     */
+    function onQuickFormEvent($event, $arg, &$caller)
+    {
+        switch ($event) {
+            case 'createElement':
+                $this->_formid = $caller->getAttribute('id');
+                break;
+        }
+        return parent::onQuickFormEvent($event, $arg, $caller);
+    } // end func onQuickFormEvent
 }
 ?>
\ No newline at end of file
index 7be801e0bda72115aabe3178ec0055872ae6f9ce..378cf3ff807308e06569b718c743b1121f11d99a 100644 (file)
@@ -137,8 +137,8 @@ function p($var, $strip=false) {
 
 /**
  * Does proper javascript quoting.
- * Do not use addslashes anymore, because it does not work when magic_quotes_sybase is enabled. 
- * 
+ * Do not use addslashes anymore, because it does not work when magic_quotes_sybase is enabled.
+ *
  * @param mixed value
  * @return mixed quoted result
  */
@@ -184,7 +184,7 @@ function get_referer() {
     if (isset($_SERVER['HTTP_REFERER'])) {
         return strip_querystring($_SERVER['HTTP_REFERER']);
     } else {
-        return '';        
+        return '';
     }
 }
 
@@ -1368,14 +1368,14 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL, $courseid=NULL
         if ($oldcacheitem) {                               // See bug 4677 for discussion
             $newcacheitem->id = $oldcacheitem->id;
             @update_record('cache_text', $newcacheitem);   // Update existing record in the cache table
-                                                           // It's unlikely that the cron cache cleaner could have 
+                                                           // It's unlikely that the cron cache cleaner could have
                                                            // deleted this entry in the meantime, as it allows
                                                            // some extra time to cover these cases.
         } else {
             @insert_record('cache_text', $newcacheitem);   // Insert a new record in the cache table
                                                            // Again, it's possible that another user has caused this
-                                                           // record to be created already in the time that it took 
-                                                           // to traverse this function.  That's OK too, as the 
+                                                           // record to be created already in the time that it took
+                                                           // to traverse this function.  That's OK too, as the
                                                            // call above handles duplicate entries, and eventually
                                                            // the cron cleaner will delete them.
         }
@@ -1556,14 +1556,14 @@ function trusttext_present($text) {
  * Please be carefull not to use stripslashes on data from database
  * or twice stripslashes when processing data recieved from user.
  *
- * @param string $text text that may contain TRUSTTEXT marker 
+ * @param string $text text that may contain TRUSTTEXT marker
  * @return text without any TRUSTTEXT marker
  */
 function trusttext_strip($text) {
     global $CFG;
 
     while (true) { //removing nested TRUSTTEXT
-        $orig = $text; 
+        $orig = $text;
         $text = str_replace(TRUSTTEXT, '', $text);
         if (strcmp($orig, $text) === 0) {
             return $text;
@@ -2154,7 +2154,7 @@ function print_header ($title='', $heading='', $navigation='', $focus='',
     }
     @header('Accept-Ranges: none');
 
-    if (empty($usexml)) {       
+    if (empty($usexml)) {
         $direction =  ' xmlns="http://www.w3.org/1999/xhtml"'. $direction;  // See debug_header
     } else {
         $currentlanguage = current_language();
@@ -2245,7 +2245,7 @@ function force_strict_header($output) {
         $ctype = 'Content-Type: ';
         $prolog= "<?xml version='1.0' encoding='utf-8'?>\n";
 
-        if (isset($_SERVER['HTTP_ACCEPT']) 
+        if (isset($_SERVER['HTTP_ACCEPT'])
             && false !== strpos($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml')) {
             //|| false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') //Safari "Entity 'copy' not defined".
             // Firefox et al.
@@ -2302,7 +2302,7 @@ function force_strict_header($output) {
 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
                        $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
 
-    global $COURSE, $CFG;   
+    global $COURSE, $CFG;
 
     $shortname ='';
     if ($COURSE->id != SITEID) {
@@ -2690,7 +2690,7 @@ function user_login_string($course=NULL, $user=NULL) {
     if (empty($course->id)) {
         // $course->id is not defined during installation
         return '';
-    } else if (isset($user->id) and $user->id) { 
+    } else if (isset($user->id) and $user->id) {
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
         $fullname = fullname($user, true);
@@ -2725,13 +2725,13 @@ function user_login_string($course=NULL, $user=NULL) {
  * If not it applies sensible defaults.
  *
  * Accessibility: right and left arrow Unicode characters for breadcrumb, calendar,
- * search forum block, etc. Important: these are 'silent' in a screen-reader 
+ * search forum block, etc. Important: these are 'silent' in a screen-reader
  * (unlike &gt; &raquo;), and must be accompanied by text.
  * @uses $THEME
  */
 function check_theme_arrows() {
     global $THEME;
-    
+
     if (!isset($THEME->rarrow) and !isset($THEME->larrow)) {
         // Default, looks good in Win XP/IE 6, Win/Firefox 1.5, Win/Netscape 8...
         // Also OK in Win 9x/2K/IE 5.x
@@ -2771,7 +2771,7 @@ function check_theme_arrows() {
 function print_navigation ($navigation, $separator=0, $return=false) {
     global $CFG, $THEME;
     $output = '';
-    
+
     check_theme_arrows();
     if (0 === $separator) {
         $separator = $THEME->rarrow;
@@ -2796,7 +2796,7 @@ function print_navigation ($navigation, $separator=0, $return=false) {
         $navigation = "<li>$separator ". str_replace('->', "</li>\n<li>$separator", $navigation) ."</li>\n";
         $output .= '<li class="first"><a'. $target .' href="'. $CFG->wwwroot.((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) && !empty($USER->id) && !empty($CFG->mymoodleredirect) && !isguest())
                                                                        ? '/my' : '') .'/">'. $site->shortname ."</a></li>\n". $navigation;
-        $output .= "</ul>\n";  
+        $output .= "</ul>\n";
     }
 
     if ($return) {
@@ -2916,7 +2916,7 @@ function print_continue($link, $return=false) {
  * See, {@link print_simple_box_start}.
  *
  * @param string $align string, alignment of the box, not the text (default center, left, right).
- * @param string $width string, width of the box, including units %, for example '100%'. 
+ * @param string $width string, width of the box, including units %, for example '100%'.
  * @param string $color string, background colour of the box, for example '#eee'.
  * @param int $padding integer, padding in pixels, specified without units.
  * @param string $class string, space-separated class names.
@@ -3138,7 +3138,7 @@ function print_user_picture($userid, $courseid, $picture, $size=0, $return=false
             $imagealt = $user->imagealt;
         } else {
             $imagealt = get_string('pictureof','',fullname($user));
-        }    
+        }
     }
 
     $output .= "<img class=\"$class\" align=\"middle\" src=\"$src".
@@ -3666,11 +3666,11 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
     $mincols = 65;
     $minrows = 10;
     $str = '';
-    
+
     if ($id === '') {
         $id = 'edit-'.$name;
     }
-    
+
     if ( empty($CFG->editorsrc) ) { // for backward compatibility.
         if (empty($courseid)) {
             if (!empty($course->id)) {  // search for it in global context
@@ -3684,7 +3684,7 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
 
         if ($usehtmleditor) {
             if (!empty($courseid) and has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid))) {
-                // needed for course file area browsing in image insert plugin 
+                // needed for course file area browsing in image insert plugin
                 $str .= ($scriptcount < 1) ? '<script type="text/javascript" src="'.
                 $CFG->wwwroot .'/lib/editor/htmlarea/htmlarea.php?id='. $courseid .'"></script>'."\n" : '';
             } else {
@@ -3714,7 +3714,7 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v
         $str .= s($value);
     }
     $str .= '</textarea>'."\n";
-    
+
        if ($usehtmleditor) {
                $str .= editorshortcutshelpbutton();
        }
@@ -3770,9 +3770,9 @@ function use_html_editor($name='', $editorhidebuttons='', $id='') {
 
 function print_editor_config($editorhidebuttons='', $return=false) {
     global $CFG;
-    
+
     $str = "config.pageStyle = \"body {";
-    
+
     if (!(empty($CFG->editorbackgroundcolor))) {
         $str .= " background-color: $CFG->editorbackgroundcolor;";
     }
@@ -3790,7 +3790,7 @@ function print_editor_config($editorhidebuttons='', $return=false) {
     $str .= (empty($CFG->editorkillword)) ? "false":"true";
     $str .= ';'."\n";
     $str .= 'config.fontname = {'."\n";
-    
+
     $fontlist = isset($CFG->editorfontlist) ? explode(';', $CFG->editorfontlist) : array();
     $i = 1;                     // Counter is used to get rid of the last comma.
 
@@ -3816,7 +3816,7 @@ function print_editor_config($editorhidebuttons='', $return=false) {
     if (!empty($CFG->editorspelling) && !empty($CFG->aspellpath)) {
         $str .= print_speller_code($usehtmleditor=true, true);
     }
-            
+
     if ($return) {
         return $str;
     }
@@ -3881,7 +3881,7 @@ function switchroles_form($courseid) {
             if (!$roles = get_assignable_roles($context)) {
                 return '';   // Nothing to show!
             }
-            return popup_form($CFG->wwwroot.'/course/view.php?id='.$courseid.'&amp;sesskey='.sesskey().'&amp;switchrole=', 
+            return popup_form($CFG->wwwroot.'/course/view.php?id='.$courseid.'&amp;sesskey='.sesskey().'&amp;switchrole=',
                               $roles, 'switchrole', '', get_string('switchroleto'), 'switchrole', '', true);
         } else {
             return '';
@@ -3892,7 +3892,7 @@ function switchroles_form($courseid) {
         $options['sesskey'] = sesskey();
         $options['switchrole'] = 0;
 
-        return print_single_button($CFG->wwwroot.'/course/view.php', $options,  
+        return print_single_button($CFG->wwwroot.'/course/view.php', $options,
                                    get_string('switchrolereturn'), 'post', '_self', true);
     }
 }
@@ -4235,7 +4235,7 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
         if ($mod->section > 0 and $section <> $mod->section) {
             $thissection = $sections[$mod->section];
 
-            if ($thissection->visible or !$course->hiddensections or 
+            if ($thissection->visible or !$course->hiddensections or
                 has_capability('moodle/course:viewhiddensections', $context)) {
                 $thissection->summary = strip_tags(format_string($thissection->summary,true));
                 if ($course->format == 'weeks' or empty($thissection->summary)) {
@@ -4253,7 +4253,7 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
         $section = $mod->section;
 
         //Only add visible or teacher mods to jumpmenu
-        if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', 
+        if ($mod->visible or has_capability('moodle/course:viewhiddenactivities',
                                              get_context_instance(CONTEXT_MODULE, $mod->cm))) {
             $url = $mod->mod .'/view.php?id='. $mod->cm;
             if ($flag) { // the current mod is the "next" mod
@@ -4297,14 +4297,14 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
                     '<img class="icon log" src="'.$CFG->pixpath.'/i/log.gif" alt="'.$logstext.'" /></a>';
 
     }
-    if ($backmod) {     
+    if ($backmod) {
         $backtext= get_string('activityprev', 'access');
         $backmod = '<form action="'.$CFG->wwwroot.'/mod/'.$backmod->mod.'/view.php"'.$target.'><fieldset>'.
                    '<input type="hidden" name="id" value="'.$backmod->cm.'" />'.
                    '<button type="submit" title="'.$backtext.'">'.$THEME->larrow.
                    '<span class="accesshide">'.$backtext.'</span></button></fieldset></form>';
     }
-    if ($nextmod) {    
+    if ($nextmod) {
         $nexttext= get_string('activitynext', 'access');
         $nextmod = '<form action="'.$CFG->wwwroot.'/mod/'.$nextmod->mod.'/view.php" '.$target.'><fieldset>'.
                    '<input type="hidden" name="id" value="'.$nextmod->cm.'" />'.
@@ -4360,7 +4360,7 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
         if ($mod->section >= 0 and $section <> $mod->section) {
             $thissection = $sections[$mod->section];
 
-            if ($thissection->visible or !$course->hiddensections or 
+            if ($thissection->visible or !$course->hiddensections or
                       has_capability('moodle/course:viewhiddensections', $coursecontext)) {
                 $thissection->summary = strip_tags(format_string($thissection->summary,true));
                 if (!empty($doneheading)) {
@@ -4420,7 +4420,7 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
  * @param string $month  fieldname
  * @param string $year  fieldname
  * @param int $currenttime A default timestamp in GMT
- * @param boolean $return 
+ * @param boolean $return
  */
 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
 
@@ -4451,7 +4451,7 @@ function print_date_selector($day, $month, $year, $currenttime=0, $return=false)
  * @param string ? $minute  fieldname
  * @param $currenttime A default timestamp in GMT
  * @param int $step minute spacing
- * @param boolean $return 
+ * @param boolean $return
  */
 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
 
@@ -4478,9 +4478,9 @@ function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=fa
  *
  * @uses $CFG
  * @param int $timelimit default
- * @param string $unit 
- * @param string $name 
- * @param boolean $return 
+ * @param string $unit
+ * @param string $name
+ * @param boolean $return
  */
 function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
 
@@ -4637,10 +4637,10 @@ function error ($message, $link='', $adminroot='') {
         }
     }
     print_continue($link);
-    
+
     if ($adminroot) {
         admin_externalpage_print_footer($adminroot);
-    } else { 
+    } else {
         print_footer();
     }
     for ($i=0;$i<512;$i++) {  // Padding to help IE work with 404
@@ -4684,7 +4684,76 @@ function print_error ($errorcode, $module='', $link='', $a=NULL) {
                  get_string('moreinformation').'</a></p>';
     error($message, $link);
 }
+function editorhelpbutton(){
+    global $CFG, $SESSION;
+    $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");
+        }elseif (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 'emoticons' :
+                    $SESSION->inserttextform = 'mod-forum-post';
+                    $SESSION->inserttextfield = 'message';
 
+                    $titles[] = get_string("helpemoticons");
+                    break;
+                case 'richtext' :
+                    $titles[] = get_string("helprichtext");
+                    break;
+                default :
+                    error('Unknown help topic '.$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.'" src="'.$CFG->pixpath .'/help.gif" />';
+    return link_to_popup_window(s("/lib/form/editorhelp.php?".$paramstring), $alttag, $linkobject, 400, 500, $alttag, 'none', true);
+}
+/*    $helptext = '<ul><li>';
+    $helptext .= helpbutton("reading", get_string("helpreading"), "moodle", true, false, '', true);
+    $helptext .= "</li><li>";
+    $helptext .= helpbutton("writing", get_string("helpwriting"), "moodle", true, false, '', true);
+    $helptext .= "</li><li>";
+    $helptext .= helpbutton("questions", get_string("helpquestions"), "moodle", true, false, '', true);
+    $helptext .= "</li><li>";
+    if ($usehtmleditor) {
+       $helptext .= helpbutton("richtext", get_string("helprichtext"), "moodle", true, false, '', true);
+    } else {
+       $helptext .= emoticonhelpbutton("theform", "message", true);
+    }
+    $helptext .= "</li></ul>";
+    return helpbutton('', get_string('editorhelp'), 'moodle', true, false, $helptext, true);
+}*/
 
 /**
  * Print a help button.
@@ -4721,14 +4790,14 @@ function helpbutton ($page, $title='', $module='moodle', $image=true, $linktext=
     // Accessibility: prefix the alt text/title with 'Help with', strip distracting dots '...'
     // PLEASE DO NOT CHANGE. ('...' is VERY distracting for non-visual users)
     $tooltip = get_string('helpprefix2', '', trim($title, ". \t"));
-    
+
     $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');  
+            $tooltip = get_string('helpwiththis');
         }
         if ($imagetext) {
             $linkobject .= $imagetext;
@@ -4747,7 +4816,7 @@ function helpbutton ($page, $title='', $module='moodle', $image=true, $linktext=
         $url = '/help.php?module='. $module .'&amp;file='. $page .'.html&amp;forcelang='.$forcelang;
     }
 
-    $link = '<span class="helplink">'. 
+    $link = '<span class="helplink">'.
             link_to_popup_window ($url, 'popup', $linkobject, 400, 500, $tooltip, 'none', true).
             '</span>';
 
@@ -4768,7 +4837,7 @@ function helpbutton ($page, $title='', $module='moodle', $image=true, $linktext=
  * @param string $field ?
  * @todo Finish documenting this function
  */
-function emoticonhelpbutton($form, $field) {
+function emoticonhelpbutton($form, $field, $return = false) {
 
     global $CFG, $SESSION;
 
@@ -4776,8 +4845,12 @@ function emoticonhelpbutton($form, $field) {
     $SESSION->inserttextfield = $field;
     $imagetext = '<img src="' . $CFG->pixpath . '/s/smiley.gif" border="0" align="middle" width="15" height="15" alt=""
     class="emoticon" style="margin-left:3px; padding-right:1px;" />';
-
-    helpbutton('emoticons', get_string('helpemoticons'), 'moodle', true, true, '', false, $imagetext);
+    $help = helpbutton('emoticons', get_string('helpemoticons'), 'moodle', true, true, '', true, $imagetext);
+    if (!$return){
+        echo $help;
+    } else {
+        return $help;
+    }
 }
 
 /**
@@ -4820,13 +4893,13 @@ function notice ($message, $link='', $course=NULL, $adminroot='') {
     echo '<br />';
     print_simple_box($message, 'center', '50%', '', '20', 'generalbox', 'notice');
     print_continue($link);
-    
+
     // xhtml strict fix, need to make sure it's the right footer
     if ($adminroot) {
         admin_externalpage_print_footer($adminroot);
         exit;
     }
-    
+
     if (empty($course)) {
         print_footer($SITE);
     } else {
@@ -4888,16 +4961,16 @@ function redirect($url, $message='', $delay=-1) {
     $tmpstr = clean_text('<a href="'.$encodedurl.'" />'); //clean encoded URL
     $encodedurl = substr($tmpstr, 9, strlen($tmpstr)-13);
     $url = html_entity_decode($encodedurl);
-    $surl = addslashes($url); 
+    $surl = addslashes($url);
 
 /// when no message and header printed yet, try to redirect
     if (empty($message) and !defined('HEADER_PRINTED')) {
-        
+
         // Technically, HTTP/1.1 requires Location: header to contain
-        // the absolute path. (In practice browsers accept relative 
+        // the absolute path. (In practice browsers accept relative
         // paths - but still, might as well do it properly.)
-        // This code turns relative into absolute. 
-        if (!preg_match('|^[a-z]+:|', $url)) { 
+        // This code turns relative into absolute.
+        if (!preg_match('|^[a-z]+:|', $url)) {
             // Get host name http://www.wherever.com
             $hostpart = preg_replace('|^(.*?[^:/])/.*$|', '$1', $CFG->wwwroot);
             if (preg_match('|^/|', $url)) {
@@ -4939,7 +5012,7 @@ function redirect($url, $message='', $delay=-1) {
     echo '<p>'. $message .'</p>';
     echo '<p>( <a href="'. $encodedurl .'">'. get_string('continue') .'</a> )</p>';
     echo '</center>';
-// it might be better not to set timeout the same for both types of redirect, so that we can be sure which one wins 
+// it might be better not to set timeout the same for both types of redirect, so that we can be sure which one wins
 ?>
 <script type="text/javascript">
 <!--
@@ -4973,7 +5046,7 @@ function notify($message, $style='notifyproblem', $align='center', $return=false
     $message = clean_text($message);
 
     $output = '<div class="'.$style.'" align="'. $align .'">'. $message .'</div>'."<br />\n";
-    
+
     if ($return) {
         return $output;
     }
@@ -5164,7 +5237,7 @@ function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $fo
 
     if (! empty($heading)) {
         $heading = $skip_link . $heading;
-    } 
+    }
     /*else { //ELSE: I think a single link on a page, "Skip block 4" is too confusing - don't print.
         echo $skip_link;
     }*/
index 89f86d2ec2d3ee4c778ad161a0c92b91a5f49ac4..3a44d956ee0676a7e8a865c50f998f56471af0a7 100644 (file)
@@ -28,6 +28,7 @@ class mod_forum_post_form extends moodleform {
                $mform->addElement('htmleditor', 'message', get_string('message', 'forum'));
                $mform->setType('message', PARAM_RAW);
                $mform->addRule('message', get_string('required'), 'required', null, 'client');
+        $mform->setHelpButton('message', array('reading', 'writing', 'questions', 'richtext'), false, 'editorhelpbutton');
 
         $mform->addElement('format', 'format', get_string('format'));