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

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

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