[LON-CAPA-cvs] cvs: loncom /interface lonfeedback.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 03 Aug 2004 21:29:32 -0000


This is a MIME encoded message

--raeburn1091568572
Content-Type: text/plain

raeburn		Tue Aug  3 17:29:32 2004 EDT

  Modified files:              
    /loncom/interface	lonfeedback.pm 
  Log:
  Versions of messages and subjects in discussion posts stored in XML.
  
  
--raeburn1091568572
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20040803172932.txt"

Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.111 loncom/interface/lonfeedback.pm:1.112
--- loncom/interface/lonfeedback.pm:1.111	Sun Aug  1 12:05:14 2004
+++ loncom/interface/lonfeedback.pm	Tue Aug  3 17:29:32 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.111 2004/08/01 16:05:14 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.112 2004/08/03 21:29:32 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,6 +36,7 @@
 use Apache::lontexconvert();
 use Apache::lonlocal; # must not have ()
 use Apache::lonhtmlcommon();
+use HTML::LCParser();
 use Apache::lonspeller();
 
 sub discussion_open {
@@ -268,8 +269,10 @@
                 }
 		my ($message,$subject);
          	if ($idx > 0) {
-                    if ($contrib{$idx.':message'} =~ /.*::::\Q$numoldver\E::::(.+?)$/si) {
-                        $message = $1;
+                    if ($contrib{$idx.':message'} =~ /^<version num="0">/) {
+                        my %versions = (); 
+                        &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
+                        $message = &HTML::Entities::decode($versions{$numoldver});
                     } else {
                         $message = $contrib{$idx.':message'};
                     }
@@ -280,8 +283,10 @@
 		$message=~s/\n/\<br \/\>/g;
 		$message=&Apache::lontexconvert::msgtexconverted($message);
          	if ($idx > 0) {
-                    if ($contrib{$idx.':subject'} =~ /.*::::\Q$numoldver\E::::(.+?)$/si) {
-                        $subject = $1;
+                    if ($contrib{$idx.':subject'} =~ /^<version num="0"/) {
+                        my %versions = ();
+                        &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver);
+                        $subject = &HTML::Entities::decode($versions{$numoldver});
                     } else {
                         $subject = $contrib{$idx.':subject'};
                     }
@@ -966,6 +971,14 @@
 					   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
 					   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
       unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
+          if ($contrib{$idx.':history'}) {
+              if ($contrib{$idx.':history'} =~ /:/) {
+                  my @oldversions = split/:/,$contrib{$idx.':history'};
+                  $numoldver = @oldversions;
+              } else {
+                  $numoldver = 1;
+              }
+          }
           if ($ENV{'form.replydisc'}) {
               if ($contrib{$idx.':history'}) {
                   if ($contrib{$idx.':history'} =~ /:/) {
@@ -977,8 +990,10 @@
               }
               my $message;
               if ($idx > 0) {
-                  if ($contrib{$idx.':message'} =~ /::::\Q$numoldver\E::::(.+?)$/si) {
-                      $message = $1;
+                  if ($contrib{$idx.':message'} =~ /^<version num="0"/) {
+                      my %versions = ();
+                      &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
+                      $message = &HTML::Entities::decode($versions{$numoldver});
                   } else {
                       $message = $contrib{$idx.':message'};
                   }
@@ -988,8 +1003,10 @@
 	      $message=~s/\n/\<br \/\>/g;
 	      $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
               if ($idx > 0) {
-                  if ($contrib{$idx.':subject'} =~ /::::\Q$numoldver\E::::(.+?)$/si) {
-                      $subject = $1;
+                  if ($contrib{$idx.':subject'} =~ /^<version num="0"/) {
+                      my %versions = ();
+                      &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver);
+                      $subject = &HTML::Entities::decode($versions{$numoldver});
                   } else {
                       $subject = $contrib{$idx.':subject'};
                   }
@@ -998,19 +1015,20 @@
               $subject = &HTML::Entities::encode($subject,'<>&"');
           } else {
               $attachmenturls = $contrib{$idx.':attachmenturl'};
-              if ($contrib{$idx.':message'} =~ /.*::::(\d+)::::(.*?)$/si) {
-                  $numoldver = $1;
-                  $comment = $2;
+              if ($contrib{$idx.':message'} =~ /^<version num="0">/) {
+                  my %versions = ();
+                  &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
+                  $comment = $versions{$numoldver};
               } else {
-                  $comment = $contrib{$idx.':message'};
+                  $comment = &HTML::Entities::encode($contrib{$idx.':message'},'<>&"');
               }
-              $comment = &HTML::Entities::encode($comment,'<>&"');
-              if ($contrib{$idx.':subject'} =~ /.*::::\d+::::(.+?)$/si) {
-                  $subject = $1;
+              if ($contrib{$idx.':subject'} =~ /<version num="0">/) {
+                  my %versions = ();
+                  &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver);
+                  $subject = $versions{$numoldver}; 
               } else {
-                  $subject = $contrib{$idx.':subject'};
+                  $subject = &HTML::Entities::encode($contrib{$idx.':subject'},'<>&"');
               }
-              $subject = &HTML::Entities::encode($subject,'<>&"');
               if (defined($contrib{$idx.':replyto'})) {
                   $parentmsg = $contrib{$idx.':replyto'};
               }
@@ -1652,6 +1670,25 @@
 END
 }
 
+sub get_post_versions {
+    my ($versions,$incoming,$numver) = @_;
+    my $p = HTML::LCParser->new(\$incoming);
+    my $done = 0;                                                                       
+    while ( (my $token = $p->get_tag("version")) && (!$done)) {
+        my $num = $token->[1]{num};
+        my $text = $p->get_text("/version");
+        if (defined($numver)) {
+            if ($num == $numver) {
+                $$versions{$numver}=$text;
+                $done = 1;
+            }
+        } else {
+            $$versions{$num}=$text;
+        }
+    }
+    return;
+}
+
 sub fail_redirect {
   my ($r,$feedurl) = @_;
   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
@@ -2014,17 +2051,19 @@
             }
             my $numnewver = $numoldver + 1;
             if (defined($oldcontrib{$oldidx.':subject'})) {
-                if ($oldcontrib{$oldidx.':subject'} =~ /::::\d+::::/) {
-                    $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.'::::'.$numnewver.'::::'.$contrib{'subject'};
+                if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
+                    $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
+                    $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
                 } else {
-                     $contrib{'subject'} = '::::0::::'.$oldcontrib{$oldidx.':subject'}.'::::1::::'.$contrib{'subject'};
+                    $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
                 }
             } 
             if (defined($oldcontrib{$oldidx.':message'})) {
-                if ($oldcontrib{$oldidx.':message'} =~ /::::\d+::::/) {
-                    $contrib{'message'} = $oldcontrib{$oldidx.':message'}.'::::'.$numnewver.'::::'.$contrib{'message'};
+                if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
+                    $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
+                    $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
                 } else {
-                    $contrib{'message'} = '::::0::::'.$oldcontrib{$oldidx.':message'}.'::::1::::'.$contrib{'message'};
+                    $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
                 }
             }
             $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
@@ -2459,12 +2498,16 @@
           if ($contrib{$idx.':history'}) {
               my $attachmenturls = $contrib{$idx.':attachmenturl'};
               my @postversions = ();
+              my %messages = ();
+              my %subjects = ();
               if ($contrib{$idx.':history'} =~ m/:/) {
                   @postversions = split/:/,$contrib{$idx.':history'};
               } else {
                   @postversions = ("$contrib{$idx.':history'}");
               }
               if (@postversions > 0) {
+                  &get_post_versions(\%messages,$contrib{$idx.':message'});
+                  &get_post_versions(\%subjects,$contrib{$idx.':subject'});
                   push @postversions,$contrib{$idx.':timestamp'};
                   my $screenname=&Apache::loncommon::screenname(
                                             $contrib{$idx.':sendername'},
@@ -2485,13 +2528,8 @@
                   for (my $i=0; $i<@postversions; $i++) {
                       my ($timesent,$message,$subject,$attachmsg);
                       $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
-                      if ($i == @postversions-1) {
-                          ($message)=($contrib{$idx.':message'} =~ /.*::::\Q$i\E::::(.+?)$/si);
-                          ($subject)=($contrib{$idx.':subject'} =~ /.*::::\Q$i\E::::(.+?)$/si);
-                      } else { 
-                          ($message)=($contrib{$idx.':message'} =~ /::::\Q$i\E::::(.+?)::::/si);
-                          ($subject)=($contrib{$idx.':subject'} =~ /::::\Q$i\E::::(.+?)::::/si);
-                      }
+                      $message=&HTML::Entities::decode($messages{$i});
+                      $subject=&HTML::Entities::decode($subjects{$i});
                       $message=~s/\n/\<br \/\>/g;
                       $message=&Apache::lontexconvert::msgtexconverted($message);
                       $subject=~s/\n/\<br \/\>/g;

--raeburn1091568572--