Annotation of loncom/xml/scripttag.pm, revision 1.21

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # <script> definiton
                      3: 
                      4: 
                      5: package Apache::scripttag; 
                      6: 
                      7: use strict;
1.3       albertel    8: use Apache::lonnet;
1.1       albertel    9: 
                     10: sub BEGIN {
1.6       albertel   11:   &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
1.20      sakharuk   12: 						 'parserlib','import',
                     13:                                                  'footnote'));
1.1       albertel   14: }
                     15: 
1.18      albertel   16: $Apache::scripttag::SCRIPT_RESULT='';
1.1       albertel   17: sub start_script {
1.2       albertel   18:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.17      albertel   19:   my $args ='';
                     20:   if ( $#$parstack > -1 ) {
                     21:     $args=$$parstack[$#$parstack];
                     22:   }
                     23:   my $type = &Apache::run::run("{$args;".'return $type}',$safeeval);
1.18      albertel   24:   #&Apache::lonxml::debug("found type of $type");
                     25:   $Apache::scripttag::SCRIPT_RESULT='';
1.17      albertel   26:   if ($type eq "loncapa/perl") {
1.18      albertel   27:     $safeeval->share('$SCRIPT_RESULT');
1.21    ! albertel   28:     my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
1.17      albertel   29:     
                     30:     if ( $target eq "modified" ) {
                     31:     }
                     32:     &Apache::run::run($bodytext,$safeeval);
1.13      albertel   33:     
1.17      albertel   34:     if ($target eq "edit" ) {
1.18      albertel   35:       $Apache::scripttag::SCRIPT_RESULT = 
                     36: 	"<br> &lt;$token->[1]&gt; output: <br>$bodytext<br>Source:<br>";
                     37:       $Apache::scripttag::SCRIPT_RESULT.=&editfield($token->[1],$bodytext);
1.17      albertel   38:     }
                     39:   } else {
1.18      albertel   40:     $Apache::scripttag::SCRIPT_RESULT = $token->[4];
1.13      albertel   41:   }
1.18      albertel   42:   return $Apache::scripttag::SCRIPT_RESULT;
1.17      albertel   43: }
1.13      albertel   44: 
1.17      albertel   45: sub end_script {
                     46:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
                     47:   return $token->[2]; 
1.1       albertel   48: }
1.3       albertel   49: 
                     50: sub start_scriptlib {
                     51:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.5       albertel   52:   my $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
1.3       albertel   53:   my $result ="";
1.13      albertel   54: 
1.18      albertel   55:   $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
                     56: 				   $$parstack[$#$parstack]);
                     57:   my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
                     58: 					     $bodytext);
                     59:   my $script=&Apache::lonnet::getfile($location);
                     60:   if ($script == -1) {
                     61:     &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
                     62:     return "";
                     63:   }
                     64:   &Apache::run::run($script,$safeeval);
                     65:   #&Apache::lonxml::debug("ran $bodytext:<br>".&Apache::lonnet::getfile($bodytext)."<br>");
1.13      albertel   66: 
                     67:   if ($target eq "edit" ) {
                     68:     $result.=&editfield($token->[1],$bodytext);
1.3       albertel   69:   }
                     70:   return $result;
                     71: }
                     72: 
                     73: sub end_scriptlib {}
1.4       albertel   74: 
                     75: sub start_parserlib {
                     76:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.6       albertel   77:   my $bodytext=$$parser[$#$parser]->get_text("/parserlib");
1.7       albertel   78:   my $result ="";
1.13      albertel   79: 
1.18      albertel   80:   $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
                     81: 				  $$parstack[$#$parstack]);
                     82:   my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
                     83: 					     $bodytext);
                     84:   my $styletext=&Apache::lonnet::getfile($location);
                     85:   if ($styletext == -1) {
                     86:     &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
                     87:     return "";
                     88:   }
                     89:   %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
1.13      albertel   90: 
                     91:   if ($target eq "edit" ) {
1.7       albertel   92:     $result=&editfield($token->[1],$bodytext);
                     93:   }
                     94:   return $result;
1.4       albertel   95: }
                     96: 
                     97: sub end_parserlib {
1.6       albertel   98: }
                     99: 
1.19      sakharuk  100: sub start_footnote {
                    101:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.20      sakharuk  102:   my $result = '';
                    103:   $Apache::lonxml::redirection = 0;
1.19      sakharuk  104:   return $result;  
                    105: }
                    106: 
                    107: sub end_footnote {
                    108:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.20      sakharuk  109:   $Apache::lonxml::outputstack =~ s/\"/\&quot\;/g;
                    110:   my $result = "<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<html><head><title>newwindow</title></head><body bgcolor=&quot;#FFFFFF&quot;> $Apache::lonxml::outputstack </body></html>\');newWindow.document.close();void(0);\"><sup>*</sup></a>";
                    111:    $Apache::lonxml::outputstack = "";
                    112:    $Apache::lonxml::redirection = 1;
                    113:   return $result; 
1.19      sakharuk  114: }
                    115: 
1.6       albertel  116: sub start_import {
1.7       albertel  117:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.6       albertel  118:   my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7       albertel  119:   my $result ="";
1.13      albertel  120: 
                    121:   $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.18      albertel  122:   my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
                    123:   my $file=&Apache::lonnet::getfile($location);
                    124:   if ($file == -1) {
                    125:     &Apache::lonxml::error("<b> Unable to find <i>$bodytext $location</i> for import</b>");
                    126:     return "";
1.14      albertel  127:   }
                    128: 
1.18      albertel  129:   my $dir=$location;
                    130:   $dir=~s:/[^/]*$::;
                    131:   &Apache::lonxml::newparser($parser,\$file,$dir);
1.13      albertel  132: 
                    133:   if ($target eq "edit" ) {
                    134:     $result.=&editfield($token->[1],$bodytext);
1.8       albertel  135:     $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br></br>"
1.7       albertel  136:   }
1.6       albertel  137: }
                    138: 
                    139: sub end_import {
1.7       albertel  140: }
                    141: 
                    142: sub editfield {
                    143:   my ($tag,$data)=@_;
                    144:   
                    145:   my $count=0;
                    146:   my $maxlength=-1;
                    147:   map { $count++;
                    148: 	if (length($_) > $maxlength) { $maxlength = length ($_); }
                    149:       } split ("\n", $data);
                    150: 	  
                    151:   return "<br></br>\n&lt;$tag&gt;<br></br>\n&nbsp;&nbsp;&nbsp;<textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea><br></br>\n&lt;/$tag&gt;<br></br>\n";
1.4       albertel  152: }
1.3       albertel  153: 
1.18      albertel  154: sub getfilenothere {
1.3       albertel  155:   my ($filename) = @_;
                    156:   my $a="";
1.11      tsai      157:   
1.12      tsai      158:   $filename=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
1.10      albertel  159:   $filename="/home/httpd/html/res".$filename;
                    160:   if (! -e $filename ) {
                    161:     &Apache::lonnet::subscribe($filename);
                    162:     &Apache::lonnet::repcopy($filename);
                    163:   }
1.14      albertel  164:   if (! -e $filename ) { return -1; };
1.11      tsai      165:   my $fh=Apache::File->new($filename);
                    166:   while (<$fh>) {
1.3       albertel  167:       $a .=$_;
                    168:   }
                    169:   return $a
1.1       albertel  170: }
1.3       albertel  171: 
1.1       albertel  172: 1;
                    173: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>