]> git.mjollnir.org Git - moodle.git/commitdiff
Initial attempt at adding html text editor features to these forms.
authormoodler <moodler>
Thu, 10 Oct 2002 07:27:57 +0000 (07:27 +0000)
committermoodler <moodler>
Thu, 10 Oct 2002 07:27:57 +0000 (07:27 +0000)
mod/forum/db/mysql.php
mod/forum/db/mysql.sql
mod/forum/lib.php
mod/forum/post.html
mod/forum/post.php
mod/forum/version.php

index a22eafbc67b4d2d3e304090d7ccce73a8f31f72d..58f758db217bcb1e63de621e6b2276b32da07215 100644 (file)
@@ -46,6 +46,9 @@ function forum_upgrade($oldversion) {
       execute_sql(" UPDATE `forum` SET `open` = 2 WHERE `open` = 1 ");
       execute_sql(" UPDATE `forum` SET `open` = 1 WHERE `open` = 0 ");
   }
+  if ($oldversion < 2002101001) {
+      execute_sql(" ALTER TABLE `forum_posts` ADD `format` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `message` ");
+  }
 
   return true;
 
index 1c67e847cce3cd4343a73c2e1207c012025f27c2..eb831cf90eb69bcfc65b409d651763339c14b338 100644 (file)
@@ -47,6 +47,7 @@ CREATE TABLE forum_posts (
   mailed tinyint(1) unsigned NOT NULL default '0',
   subject varchar(255) NOT NULL default '',
   message text NOT NULL,
+  format tinyint(2) NOT NULL default '0',
   attachment VARCHAR(100) NOT NULL default '',
   totalscore tinyint(4) NOT NULL default '0',
   PRIMARY KEY  (id)
index a427cffdd67de944ae89577a106635c895a85052..f361f6e7c11bd4d253d440bd171d6395b003c1f1 100644 (file)
@@ -24,6 +24,7 @@ $FORUM_OPEN_MODES   = array ("2" => get_string("openmode2", "forum"),
                              "1" => get_string("openmode1", "forum"),
                              "0" => get_string("openmode0", "forum") );
 
+
 $FORUM_SHORT_POST = 300;  // Less than this is "short"
 
 $FORUM_LONG_POST  = 600;  // More than this is "long"
@@ -123,7 +124,7 @@ function forum_make_mail_post(&$post, $user, $touser, $course,
         $output .= "</DIV>";
     }
 
-    $output .= text_to_html($post->message);
+    $output .= format_text($post->message, $post->format);
 
     $output .= "<P ALIGN=right><FONT SIZE=-1>";
 
@@ -202,14 +203,14 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
 
     if ($link && (strlen($post->message) > $FORUM_LONG_POST)) {
         // Print shortened version
-        echo text_to_html(forum_shorten_post($post->message));
+        echo format_text(forum_shorten_post($post->message), $post->format);
         $numwords = count_words($post->message);
         echo "<A HREF=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\">";
         echo get_string("readtherest", "forum");
         echo "</A> (".get_string("numwords", "", $numwords).")...";
     } else {
         // Print whole message
-        echo text_to_html($post->message);
+        echo format_text($post->message, $post->format);
     }
 
     echo "<P ALIGN=right><FONT SIZE=-1>";
index b7842cc3381808347810b020619efa59e40ece68..614377cc462c6411b69ee7fb2765794fc3a387d7 100644 (file)
@@ -1,4 +1,4 @@
-<form name="form" method="post" action="post.php" enctype="multipart/form-data">
+<form name="theform" method="post" action="post.php" <?=$onsubmit ?> enctype="multipart/form-data">
 <table cellpadding=5>
 <tr valign=top>
     <td align=right><P><B><? print_string("subject", "forum"); ?>:</B></P></TD>
 <tr valign=top>
     <td align=right><P><B><? print_string("message", "forum"); ?>:</B><BR><BR><? helpbutton("text", get_string("helptext")) ?></P></TD>
     <td>
-        <textarea name=message rows=15 cols=50 wrap="virtual"><? p($post->message) ?></textarea>
+    <? if ($usehtmleditor) { ?>
+        <object id="richedit" style="BACKGROUND-COLOR: buttonface" data="../../lib/rte/richedit.html"
+            width="595" height="400" type="text/x-scriptlet" VIEWASTEXT>
+        </object>
+        <TEXTAREA style="display:none" NAME="message" ROWS=1 COLS=50><? p($post->message) ?></TEXTAREA>
+     <? } else { ?>
+        <TEXTAREA name=message rows=15 cols=50 wrap="virtual"><? p($post->message) ?></TEXTAREA>
+     <? } ?>
+
     </td>
     <td rowspan=2>
     <FONT SIZE=1>
     </FONT>
     </td>
 </tr>
+<tr valign=top>
+    <td align=right><P><B><? print_string("formattexttype"); ?>:</B></P></TD>
+    <td>
+    <?PHP
+        $POST_FORMATS = format_text_menu();
+        choose_from_menu($POST_FORMATS, "format", $post->format, ""); ?>
+    </td>
+    <td>
+    &nbsp;
+    </td>
+</tr>
 <tr valign=top>
        <td><P><B><? print_string("attachment", "forum") ?>:<BR>(<? print_string("optional") ?>)</B></P></td>
        <td>
 <tr valign=top>
 </table>
 </FORM>
+
+<? if ($usehtmleditor) { ?>
+    <SCRIPT language="JavaScript" event="onload" for="window">
+        document.richedit.options = "history=no;source=no";
+        document.richedit.docHtml = theform.message.innerText;
+    </SCRIPT>
+<? } ?>
+
index c0842eb81b3a8831d0399bc1de022d7d62b556b7..7d7b014efb4eef7af91930543c90d96f7f369c64 100644 (file)
@@ -14,7 +14,7 @@
         $post = (object)$HTTP_POST_VARS;
 
         $post->subject = strip_tags($post->subject);  // Strip all tags
-        $post->message = cleantext($post->message);   // Clean up any bad tags
+        $post->message = clean_text($post->message, $post->format);   // Clean up any bad tags
 
         $post->attachment = $HTTP_POST_FILES["attachment"];
 
 
     $strforums = get_string("modulenameplural", "forum");
 
+    if ($usehtmleditor = can_use_richtext_editor()) {
+        $onsubmit = "onsubmit=\"copyrichtext(theform.message);\"";
+    }
+
     $navmiddle = "<A HREF=\"../forum/index.php?id=$course->id\">$strforums</A> -> <A HREF=\"view.php?f=$forum->id\">$forum->name</A>";
 
     if ($course->category) {
index 1168cda88be4d4b7f264a66bcf8250ce62cdf651..b320fedd205f92186751710031f335b0746851ec 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2002100300;
+$module->version  = 2002101001;
 $module->cron     = 60;
 
 ?>