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

www lon-capa-cvs@mail.lon-capa.org
Mon, 03 Apr 2006 02:04:56 -0000


www		Sun Apr  2 22:04:56 2006 EDT

  Modified files:              
    /loncom/interface	lonhelp.pm 
  Log:
  Include foreign language help files in Search, escape XML in quotes
  
  
Index: loncom/interface/lonhelp.pm
diff -u loncom/interface/lonhelp.pm:1.24 loncom/interface/lonhelp.pm:1.25
--- loncom/interface/lonhelp.pm:1.24	Sun Mar 19 18:09:20 2006
+++ loncom/interface/lonhelp.pm	Sun Apr  2 22:04:55 2006
@@ -72,10 +72,10 @@
     if (&Apache::lonnavmaps::advancedUser()) {
 	my $search=&mt('Search LON-CAPA help');
 	my $about=&mt('About LON-CAPA help and More Help');
-
+        my $query=&mt('Search');
 	$r->print(<<FOOTER);
     <hr /><form method="post">
-$search: <input type="text" name="searchterm" size="40" /><br />
+$search: <input type="text" name="searchterm" size="40" /><input type="submit" value="$query" /><br />
 <a href="/adm/help/abouthelp.html">$about</a>
 FOOTER
  
@@ -142,12 +142,13 @@
 }
 
 sub listmatches {
-    my ($docroot,$term) =@_;
+    my ($docroot,$term,$subdir) =@_;
+    unless ($subdir) { $subdir=''; }
     my $output='';
-    opendir(DIR,$docroot.'/adm/help/tex/');
+    opendir(DIR,$docroot.'/adm/help/tex/'.$subdir);
     foreach my $filename (sort readdir(DIR)) {
 	if ($filename=~/\.tex$/) {
-	    open(FH,$docroot.'/adm/help/tex/'.$filename);
+	    open(FH,$docroot.'/adm/help/tex/'.$subdir.$filename);
 	    my $quote='';
 	    while (my $line=<FH>) {
 		if ($line=~/\Q$term\E/i) {
@@ -156,6 +157,8 @@
 		    $line=~s/\}//gs;
 		    $line=~s/\\/ /gs;
 		    $line=~s/(\Q$term\E)/\<b\>$1\<\/b\>/gsi;
+                    $line=~s/\</\&lt\;/gs;
+                    $line=~s/\>/\&gt\;/gs;
 		    $quote.='<br />...'.$line.'...';
 		}
 	    }
@@ -165,12 +168,12 @@
                 $title=~s/\_/ /gs;
                 $title=~s/\.tex$//;
                 $filename=~s/\.tex$/\.hlp/;
-		$output.='<li><a href="/adm/help/tex/'.$filename.'">'.$title.'</a>'.$quote.'</li>';
+		$output.='<li><a href="/adm/help/tex/'.$subdir.$filename.'">'.$title.'</a>'.$quote.'</li>';
 	    }
 	}
     }
     closedir(DIR);
-    return ($output?'<ul>'.$output.'</ul>':&mt('"[_1]" not found',$term));
+    return (($output?'<ul>'.$output.'</ul>':&mt('"[_1]" not found',$term)),$output);
 }
 
 sub handler {
@@ -183,7 +186,15 @@
      my $text='';
      if ($env{'form.searchterm'}=~/\w/) {
 	 &Apache::loncommon::content_type($r,"text/html");
-	 $text=&listmatches($docroot,$env{'form.searchterm'});
+	 ($text,my $matches)=&listmatches($docroot,$env{'form.searchterm'},&Apache::lonlocal::current_language().'/');
+         if ($matches) {
+             my ($englishresult,$englishmatches)=&listmatches($docroot,$env{'form.searchterm'});
+             if ($englishmatches) {
+                $text.='<hr />'.$englishresult;
+             }
+         } else {
+             $text=&listmatches($docroot,$env{'form.searchterm'}); 
+         }
      } else {
 	 my $filenames = &Apache::lonnet::unescape(substr ($ENV{'REQUEST_URI'} , 
 							   rindex($ENV{'REQUEST_URI'}, '/') + 1, -4));