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

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

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