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

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>";
1.22    ! sakharuk  111:   if ($target eq 'meta') {$result = '';}
1.20      sakharuk  112:    $Apache::lonxml::outputstack = "";
                    113:    $Apache::lonxml::redirection = 1;
                    114:   return $result; 
1.19      sakharuk  115: }
                    116: 
1.6       albertel  117: sub start_import {
1.7       albertel  118:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.6       albertel  119:   my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7       albertel  120:   my $result ="";
1.13      albertel  121: 
                    122:   $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.18      albertel  123:   my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
                    124:   my $file=&Apache::lonnet::getfile($location);
                    125:   if ($file == -1) {
                    126:     &Apache::lonxml::error("<b> Unable to find <i>$bodytext $location</i> for import</b>");
                    127:     return "";
1.14      albertel  128:   }
                    129: 
1.18      albertel  130:   my $dir=$location;
                    131:   $dir=~s:/[^/]*$::;
                    132:   &Apache::lonxml::newparser($parser,\$file,$dir);
1.13      albertel  133: 
                    134:   if ($target eq "edit" ) {
                    135:     $result.=&editfield($token->[1],$bodytext);
1.8       albertel  136:     $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br></br>"
1.7       albertel  137:   }
1.6       albertel  138: }
                    139: 
                    140: sub end_import {
1.7       albertel  141: }
                    142: 
                    143: sub editfield {
                    144:   my ($tag,$data)=@_;
                    145:   
                    146:   my $count=0;
                    147:   my $maxlength=-1;
                    148:   map { $count++;
                    149: 	if (length($_) > $maxlength) { $maxlength = length ($_); }
                    150:       } split ("\n", $data);
                    151: 	  
                    152:   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  153: }
1.3       albertel  154: 
1.18      albertel  155: sub getfilenothere {
1.3       albertel  156:   my ($filename) = @_;
                    157:   my $a="";
1.11      tsai      158:   
1.12      tsai      159:   $filename=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
1.10      albertel  160:   $filename="/home/httpd/html/res".$filename;
                    161:   if (! -e $filename ) {
                    162:     &Apache::lonnet::subscribe($filename);
                    163:     &Apache::lonnet::repcopy($filename);
                    164:   }
1.14      albertel  165:   if (! -e $filename ) { return -1; };
1.11      tsai      166:   my $fh=Apache::File->new($filename);
                    167:   while (<$fh>) {
1.3       albertel  168:       $a .=$_;
                    169:   }
                    170:   return $a
1.1       albertel  171: }
1.3       albertel  172: 
1.1       albertel  173: 1;
                    174: __END__

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