]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18902 reimplemented trusstext support in forum + standardising format column...
authorskodak <skodak>
Mon, 20 Apr 2009 11:36:01 +0000 (11:36 +0000)
committerskodak <skodak>
Mon, 20 Apr 2009 11:36:01 +0000 (11:36 +0000)
mod/forum/backuplib.php
mod/forum/db/install.xml
mod/forum/db/upgrade.php
mod/forum/lib.php
mod/forum/post.php
mod/forum/restorelib.php
mod/forum/rsslib.php
mod/forum/search.php
mod/forum/version.php

index 120ceab882ab025132a810a9bce5f68f1dff1e64..89a4ef251f9c12bc4210b021d3ca087d2e7e5b01 100644 (file)
                 fwrite ($bf,full_tag("MAILED",8,false,$for_pos->mailed));
                 fwrite ($bf,full_tag("SUBJECT",8,false,$for_pos->subject));
                 fwrite ($bf,full_tag("MESSAGE",8,false,$for_pos->message));
-                fwrite ($bf,full_tag("FORMAT",8,false,$for_pos->format));
+                fwrite ($bf,full_tag("FORMAT",8,false,$for_pos->messageformat));
                 fwrite ($bf,full_tag("ATTACHMENT",8,false,$for_pos->attachment));
                 fwrite ($bf,full_tag("TOTALSCORE",8,false,$for_pos->totalscore));
                 fwrite ($bf,full_tag("MAILNOW",8,false,$for_pos->mailnow));
index 7538185ed943880160a57b208ea36099095de7d6..201df61d2d1b202b465a18ea6b1baa084b4114d8 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/forum/db" VERSION="20080908" COMMENT="XMLDB file for Moodle mod/forum"
+<XMLDB PATH="mod/forum/db" VERSION="20090420" COMMENT="XMLDB file for Moodle mod/forum"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
 >
         <FIELD NAME="modified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="created" NEXT="mailed"/>
         <FIELD NAME="mailed" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="modified" NEXT="subject"/>
         <FIELD NAME="subject" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="mailed" NEXT="message"/>
-        <FIELD NAME="message" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="subject" NEXT="format"/>
-        <FIELD NAME="format" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="message" NEXT="attachment"/>
-        <FIELD NAME="attachment" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="format" NEXT="totalscore"/>
+        <FIELD NAME="message" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="subject" NEXT="messageformat"/>
+        <FIELD NAME="messageformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="message" NEXT="messagetrust"/>
+        <FIELD NAME="messagetrust" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="messageformat" NEXT="attachment"/>
+        <FIELD NAME="attachment" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="messagetrust" NEXT="totalscore"/>
         <FIELD NAME="totalscore" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="attachment" NEXT="mailnow"/>
         <FIELD NAME="mailnow" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="totalscore"/>
       </FIELDS>
index 07cb48cf2451054a2f885cda6601a8da31866b58..a40069b1dc294c617afb1ecab1cf8b0fe58e3f5a 100644 (file)
@@ -176,8 +176,51 @@ function xmldb_forum_upgrade($oldversion) {
         upgrade_mod_savepoint($result, 2008090800, 'forum');
     }
 
+    if ($result && $oldversion < 2009042000) {
 
+    /// Rename field format on table forum_posts to messageformat
+        $table = new xmldb_table('forum_posts');
+        $field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null, null, '0', 'message');
 
+    /// Launch rename field format
+        $dbman->rename_field($table, $field, 'messageformat');
+
+    /// forum savepoint reached
+        upgrade_mod_savepoint($result, 2009042000, 'forum');
+    }
+
+    if ($result && $oldversion < 2009042001) {
+
+    /// Define field messagetrust to be added to forum_posts
+        $table = new xmldb_table('forum_posts');
+        $field = new xmldb_field('messagetrust', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'messageformat');
+
+    /// Launch add field messagetrust
+        $dbman->add_field($table, $field);
+
+    /// forum savepoint reached
+        upgrade_mod_savepoint($result, 2009042001, 'forum');
+    }
+    
+    if ($result && $oldversion < 2009042002) {
+        $trustmark = '#####TRUSTTEXT#####';
+        $rs = $DB->get_recordset_sql("SELECT * FROM {forum_posts} WHERE message LIKE '$trustmark%'");
+        foreach ($rs as $post) {
+            if (strpos($post->entrycomment, $trustmark) !== 0) {
+                // probably lowercase in some DBs
+                continue;
+            }
+            $post->message      = trusttext_strip($post->message);
+            $post->messagetrust = 1;
+            $DB->update_record('forum_posts', $post);
+        }
+        $rs->close();
+
+    /// forum savepoint reached
+        upgrade_mod_savepoint($result, 2009042002, 'forum');
+    }
+    
+    
     return $result;
 }
 
index 255f0b90f13036f26fa14a00afb4113a99c9e75c..1645e5cba076905d6ae3334260caaa2351cbbe87 100644 (file)
@@ -58,14 +58,14 @@ function forum_add_instance($forum) {
 
     if ($forum->type == 'single') {  // Create related discussion.
         $discussion = new object();
-        $discussion->course   = $forum->course;
-        $discussion->forum    = $forum->id;
-        $discussion->name     = $forum->name;
-        $discussion->intro    = $forum->intro;
-        $discussion->assessed = $forum->assessed;
-        $discussion->format   = $forum->format;
-        $discussion->mailnow  = false;
-        $discussion->groupid  = -1;
+        $discussion->course        = $forum->course;
+        $discussion->forum         = $forum->id;
+        $discussion->name          = $forum->name;
+        $discussion->intro         = $forum->intro;
+        $discussion->assessed      = $forum->assessed;
+        $discussion->messageformat = $forum->messageformat;
+        $discussion->mailnow       = false;
+        $discussion->groupid       = -1;
 
         $message = '';
 
@@ -132,14 +132,14 @@ function forum_update_instance($forum) {
             } else {
                 // try to recover by creating initial discussion - MDL-16262
                 $discussion = new object();
-                $discussion->course   = $forum->course;
-                $discussion->forum    = $forum->id;
-                $discussion->name     = $forum->name;
-                $discussion->intro    = $forum->intro;
-                $discussion->assessed = $forum->assessed;
-                $discussion->format   = $forum->type;
-                $discussion->mailnow  = false;
-                $discussion->groupid  = -1;
+                $discussion->course          = $forum->course;
+                $discussion->forum           = $forum->id;
+                $discussion->name            = $forum->name;
+                $discussion->intro           = $forum->intro;
+                $discussion->assessed        = $forum->assessed;
+                $discussion->messageformat   = $forum->messageformat;
+                $discussion->mailnow         = false;
+                $discussion->groupid         = -1;
 
                 forum_add_discussion($discussion, null, $message);
 
@@ -959,7 +959,7 @@ function forum_make_mail_text($course, $cm, $forum, $discussion, $post, $userfro
     }
     $posttext .= "\n".$strbynameondate."\n";
     $posttext .= "---------------------------------------------------------------------\n";
-    $posttext .= format_text_email(trusttext_strip($post->message), $post->format);
+    $posttext .= format_text_email($post->message, $post->messageformat);
     $posttext .= "\n\n";
     $posttext .= forum_print_attachments($post, $cm, "text");
 
@@ -2856,7 +2856,7 @@ function forum_make_mail_post($course, $cm, $forum, $discussion, $post, $userfro
     // format the post body
     $options = new object();
     $options->para = true;
-    $formattedtext = format_text(trusttext_strip($post->message), $post->format, $options, $course->id);
+    $formattedtext = format_text($post->message, $post->messageformat, $options, $course->id);
 
     $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">';
 
@@ -3122,11 +3122,11 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
     }
 
     $options = new object();
-    $options->para      = false;
-    $options->trusttext = true;
+    $options->para    = false;
+    $options->trusted = $post->messagetrust;
     if ($link and (strlen(strip_tags($post->message)) > $CFG->forum_longpost)) {
         // Print shortened version
-        echo format_text(forum_shorten_post($post->message), $post->format, $options, $course->id);
+        echo format_text(forum_shorten_post($post->message), $post->messageformat, $options, $course->id);
         $numwords = count_words(strip_tags($post->message));
         echo '<div class="posting"><a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'">';
         echo get_string('readtherest', 'forum');
@@ -3135,9 +3135,9 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
         // Print whole message
         echo '<div class="posting">';
         if ($highlight) {
-            echo highlight($highlight, format_text($post->message, $post->format, $options, $course->id));
+            echo highlight($highlight, format_text($post->message, $post->messageformat, $options, $course->id));
         } else {
-            echo format_text($post->message, $post->format, $options, $course->id);
+            echo format_text($post->message, $post->messageformat, $options, $course->id);
         }
         echo '</div>';
         echo $attachedimages;
@@ -4238,19 +4238,20 @@ function forum_add_discussion($discussion, $mform=null, &$message=null) {
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
     $post = new object();
-    $post->discussion  = 0;
-    $post->parent      = 0;
-    $post->userid      = $USER->id;
-    $post->created     = $timenow;
-    $post->modified    = $timenow;
-    $post->mailed      = 0;
-    $post->subject     = $discussion->name;
-    $post->message     = $discussion->intro;
-    $post->attachments = $discussion->attachments;
-    $post->forum       = $forum->id;     // speedup
-    $post->course      = $forum->course; // speedup
-    $post->format      = $discussion->format;
-    $post->mailnow     = $discussion->mailnow;
+    $post->discussion    = 0;
+    $post->parent        = 0;
+    $post->userid        = $USER->id;
+    $post->created       = $timenow;
+    $post->modified      = $timenow;
+    $post->mailed        = 0;
+    $post->subject       = $discussion->name;
+    $post->message       = $discussion->intro;
+    $post->messageformat = $discussion->messageformat;
+    $post->messagetrust  = $discussion->messagetrust;
+    $post->attachments   = $discussion->attachments;
+    $post->forum         = $forum->id;     // speedup
+    $post->course        = $forum->course; // speedup
+    $post->mailnow       = $discussion->mailnow;
 
     if (! $post->id = $DB->insert_record("forum_posts", $post) ) {
         return 0;
@@ -7425,7 +7426,7 @@ class forum_portfolio_caller extends portfolio_module_caller_base {
         // format the post body
         $options = new object();
         $options->para = true;
-        $formattedtext = format_text(trusttext_strip($post->message), $post->format, $options, $this->get('course')->id);
+        $formattedtext = format_text($post->message, $post->messageformat, $options, $this->get('course')->id);
 
         $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">';
 
index fd184730b8e1295e15f3706d4e02a0a7e6613207..60674e635d91cd9d67a09936f5a21546af4e6fde 100644 (file)
         // Load up the $post variable.
 
         $post = new object();
-        $post->course     = $course->id;
-        $post->forum      = $forum->id;
-        $post->discussion = 0;           // ie discussion # not defined yet
-        $post->parent     = 0;
-        $post->subject    = '';
-        $post->userid     = $USER->id;
-        $post->message    = '';
+        $post->course        = $course->id;
+        $post->forum         = $forum->id;
+        $post->discussion    = 0;           // ie discussion # not defined yet
+        $post->parent        = 0;
+        $post->subject       = '';
+        $post->userid        = $USER->id;
+        $post->message       = '';
+        $post->messageformat = FORMAT_HTML; // TODO: better default
+        $post->messagetrust  = 0; 
 
         if (isset($groupid)) {
             $post->groupid = $groupid;
         $post->forum  = $forum->id;
         $post->groupid = ($discussion->groupid == -1) ? 0 : $discussion->groupid;
 
-        trusttext_prepare_edit($post->message, $post->format, can_use_html_editor(), $modcontext);
+        $post = trusttext_pre_edit($post, 'message', $modcontext);
 
         unset($SESSION->fromdiscussion);
 
 
     if ($USER->id != $post->userid) {   // Not the original author, so add a message to the end
         $data->date = userdate($post->modified);
-        if ($post->format == FORMAT_HTML) {
+        if ($post->messageformat == FORMAT_HTML) {
             $data->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$post->course.'">'.
                            fullname($USER).'</a>';
             $post->message .= '<p>(<span class="edited">'.get_string('editedby', 'forum', $data).'</span>)</p>';
                                         'subject'=>$post->subject,
                                         'message'=>array(
                                             'text'=>$currenttext,
-                                            'format'=>empty($post->format) ? FORMAT_HTML : $post->format, //TODO: add some better default
+                                            'format'=>empty($post->messageformat) ? FORMAT_HTML : $post->messageformat, //TODO: add some better default
                                             'itemid'=>$draftid_editor
                                         ),
                                         'subscribe'=>$subscribe?1:0,
             $errordestination = $SESSION->fromurl;
         }
 
-        trusttext_after_edit($fromform->message['text'], $modcontext);
-        $fromform->format  = $fromform->message['format'];
-        $fromform->itemid  = $fromform->message['itemid'];
-        $fromform->message = $fromform->message['text'];
+        $fromform->itemid        = $fromform->message['itemid'];
+        $fromform->message       = $fromform->message['text'];
+        $fromform->messageformat = $fromform->message['format'];
+        $fromform->messagetrust  = trusttext_trusted($modcontext);
 
         if ($fromform->edit) {           // Updating a post
             unset($fromform->groupid);
         } else if ($fromform->discussion) { // Adding a new post to an existing discussion
             unset($fromform->groupid);
             $message = '';
-            $addpost=$fromform;
+            $addpost = $fromform;
             $addpost->forum=$forum->id;
             if ($fromform->id = forum_add_new_post($addpost, $mform_post, $message)) {
 
index 94cb1a61fe8dc4029f46e4f6302281eaf1005bf9..7fb7f455845c05c8048b314c7d8561eeca962582 100644 (file)
                     $sd->name     = $forum->name;
                     $sd->intro    = $forum->intro;
                     $sd->assessed = $forum->assessed;
-                    $sd->format   = $defaultformat;
+                    $sd->messageformat = $defaultformat;
                     $sd->mailnow  = false;
                     //Insert dicussion/post data
                     $sdid = forum_add_discussion($sd, $sd->intro, $forum);
             $post->mailed = backup_todb($pos_info['#']['MAILED']['0']['#']);
             $post->subject = backup_todb($pos_info['#']['SUBJECT']['0']['#']);
             $post->message = backup_todb($pos_info['#']['MESSAGE']['0']['#']);
-            $post->format = backup_todb($pos_info['#']['FORMAT']['0']['#']);
+            $post->messageformat = backup_todb($pos_info['#']['FORMAT']['0']['#']);
             $post->attachment = backup_todb($pos_info['#']['ATTACHMENT']['0']['#']);
             $post->totalscore = backup_todb($pos_info['#']['TOTALSCORE']['0']['#']);
             $post->mailnow = backup_todb($pos_info['#']['MAILNOW']['0']['#']);
         $status = true;
 
         //Convert forum_posts->message
-        if ($records = $DB->get_records_sql("SELECT p.id, p.message, p.format
+        if ($records = $DB->get_records_sql("SELECT p.id, p.message, p.messageformat
                                                FROM {forum_posts} p,
                                                     {forum_discussions} d,
                                                     {forum} f,
                                               WHERE d.id = p.discussion AND
                                                     f.id = d.forum AND
                                                     f.course = ? AND
-                                                    p.format = ".FORMAT_WIKI. " AND
+                                                    p.messageformat = ".FORMAT_WIKI. " AND
                                                     b.backup_code = ? AND
                                                     b.table_name = 'forum_posts' AND
                                                     b.new_id = p.id", array($restore->course_id, $restore->backup_unique_code))) {
                 //Convert to Markdown
                 $wtm = new WikiToMarkdown();
                 $record->message = $wtm->convert($record->message, $restore->course_id);
-                $record->format = FORMAT_MARKDOWN;
+                $record->messageformat = FORMAT_MARKDOWN;
                 $status = $DB->update_record('forum_posts', $record);
                 //Do some output
                 $i++;
index babf03f288f4f2eb3b347d5224c81443bd57afee..4d7a3392dbb2405d2c05a5b1870ee8cb11a6a3de 100644 (file)
                                              u.lastname AS userlastname,
                                              p.message AS postmessage,
                                              p.created AS postcreated,
-                                             p.format AS postformat
+                                             p.messageformat AS postformat,
+                                             p.messagetrust AS posttrust
                                       FROM {forum_discussions} d,
                                            {forum_posts} p,
                                            {user} u
             $user = NULL;
 
             $formatoptions = new object;
-            $formatoptions->trusttext = true;
+            $formatoptions->trusted = $rec->posttrust;
 
             foreach ($recs as $rec) {
                 unset($item);
                                              p.subject AS postsubject,
                                              p.message AS postmessage,
                                              p.created AS postcreated,
-                                             p.format AS postformat
+                                             p.messageformat AS postformat,
+                                             p.messagetrust AS posttrust
                                       FROM {forum_discussions} d,
                                            {forum_posts} p,
                                            {user} u
             $user = NULL;
 
             $formatoptions = new object;
-            $formatoptions->trusttext = true;
+            $formatoptions->trusted = $rec->posttrust;
 
             foreach ($recs as $rec) {
                 unset($item);
index 3d4b6d7ecab8f91f89b68d8df848dbc95948cdd5..0d8e0df5d3944f24cf3df5a5572827178c9090c2 100644 (file)
         $missing_terms = "";
 
         $options = new object();
-        $options->trusttext = true;
+        $options->trusted = $post->messagetrust;
         $message = highlight($strippedsearch,
-                        format_text($post->message, $post->format, $options, $course->id),
+                        format_text($post->message, $post->messageformat, $options, $course->id),
                         0, '<fgw9sdpq4>', '</fgw9sdpq4>');
 
         foreach ($searchterms as $searchterm) {
index 773e8aa8e2c79c8542f9bfbbdac2002518fb8f2d..9f661283ec71d5db364ca39384bb367bd5fe5b4a 100644 (file)
@@ -5,8 +5,8 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2008090800;
-$module->requires = 2008090800;  // Requires this Moodle version
+$module->version  = 2009042002;
+$module->requires = 2009041700;  // Requires this Moodle version
 $module->cron     = 60;
 
 ?>