Annotation of loncom/xml/scripttag.pm, revision 1.47
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # <script> definiton
1.34 albertel 3: # 2/21 Guy
1.1 albertel 4:
1.47 ! albertel 5: package Apache::scripttag;
1.1 albertel 6:
7: use strict;
1.3 albertel 8: use Apache::lonnet;
1.42 sakharuk 9: use Apache::style;
1.1 albertel 10:
1.47 ! albertel 11: #Globals
! 12: # this used to pass around the standard callsub arguments to a tag func
! 13: # so xmlparse can reenter the inner_xmlparse loop.
! 14:
! 15: @Apache::scripttag::parser_env = ();
1.1 albertel 16: sub BEGIN {
1.6 albertel 17: &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
1.20 sakharuk 18: 'parserlib','import',
1.42 sakharuk 19: 'window','display',
20: 'storetc','physnet'));
1.1 albertel 21: }
22:
23: sub start_script {
1.40 albertel 24: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47 ! albertel 25: @Apache::scripttag::parser_env = @_;
1.24 albertel 26: my $result='';
1.39 albertel 27: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
28: &Apache::lonxml::debug("found type of $type");
1.17 albertel 29: if ($type eq "loncapa/perl") {
1.21 albertel 30: my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
1.17 albertel 31: if ( $target eq "modified" ) {
1.41 albertel 32: $result=$token->[4].&Apache::edit::modifiedfield();
1.28 albertel 33: } elsif ( $target eq "web" || $target eq "grade" ) {
34: &Apache::run::run($bodytext,$safeeval);
35: } elsif ($target eq "edit" ) {
1.41 albertel 36: #&Apache::run::run($bodytext,$safeeval);
37: #$result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
38: $result=&Apache::edit::tag_start($target,$token,'Script');
39: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',50,4);
1.17 albertel 40: }
41: } else {
1.28 albertel 42: if ($target ne "meta") { $result = $token->[4]; }
1.13 albertel 43: }
1.24 albertel 44: return $result;
1.17 albertel 45: }
1.13 albertel 46:
1.17 albertel 47: sub end_script {
1.40 albertel 48: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.28 albertel 49: if ( $target eq "meta" ) { return ''; }
1.39 albertel 50: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.29 albertel 51: my $result='';
52: #other script blocks need to survive
53: if ($type ne "loncapa/perl") { return $token->[2]; }
1.41 albertel 54: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
1.28 albertel 55: return '';
1.24 albertel 56: }
57:
58: sub start_display {
1.40 albertel 59: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.39 albertel 60:
1.24 albertel 61: my $bodytext=&Apache::lonxml::get_all_text("/display",$$parser[$#$parser]);
1.39 albertel 62:
1.24 albertel 63: if ( $target eq "modified" ) {
64: }
65: my $result=&Apache::run::run($bodytext,$safeeval);
1.26 albertel 66: if ($target eq 'grade' ) {
67: # grade should produce no output
68: $result='';
69: }
1.24 albertel 70: if ($target eq "edit" ) {
71: $result =
1.33 albertel 72: "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
1.38 albertel 73: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
1.24 albertel 74: }
75: return $result;
76: }
77:
78: sub end_display {
1.38 albertel 79: return ''
1.1 albertel 80: }
1.3 albertel 81:
82: sub start_scriptlib {
1.40 albertel 83: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 84: my $bodytext;
85: my $result ='';
86: my $error='';
87:
88: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
89: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
90: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
91: $$parstack[$#$parstack]);
92: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
93: $bodytext);
94: my $script=&Apache::lonnet::getfile($location);
95: if ($script == -1) {
96: if ($target eq 'edit') {
97: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
98: } else {
99: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
100: return "";
101: }
102: }
103: &Apache::run::run($script,$safeeval);
104: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
1.18 albertel 105: }
1.13 albertel 106: if ($target eq "edit" ) {
1.37 albertel 107: $result=
1.38 albertel 108: &Apache::edit::tag_start($target,$token).
109: &Apache::edit::editfield($token->[1],$bodytext,'New Script Functions',40,1).
1.37 albertel 110: $error;
111: }
112: if ($target eq "modified" ) {
113: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
114: $result=&Apache::edit::modifiedfield($token);
115: &Apache::lonxml::debug($result);
1.3 albertel 116: }
117: return $result;
118: }
119:
1.37 albertel 120: sub end_scriptlib {
1.40 albertel 121: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 122: my $result='';
123: # if ($target eq "edit" ) { $result=" "; }
124: return $result;
125: }
1.4 albertel 126:
127: sub start_parserlib {
1.40 albertel 128: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 129: my $bodytext;
1.7 albertel 130: my $result ="";
1.37 albertel 131: my $error='';
132: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
133: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
134: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
135: $$parstack[$#$parstack]);
136: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
137: $bodytext);
138: my $styletext=&Apache::lonnet::getfile($location);
139: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
140: if ($styletext == -1) {
141: if ($target eq 'edit') {
142: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
143: } else {
144: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
145: return "";
146: }
147: }
148: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
1.18 albertel 149: }
1.13 albertel 150: if ($target eq "edit" ) {
1.37 albertel 151: $result=
1.38 albertel 152: &Apache::edit::tag_start($target,$token).
153: &Apache::edit::editfield($token->[1],$bodytext,"New Tag Definitions",40,1).
1.37 albertel 154: $error;
155: }
156: if ($target eq "modified" ) {
157: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
158: $result=&Apache::edit::modifiedfield($token);
159: &Apache::lonxml::debug($result);
1.7 albertel 160: }
161: return $result;
1.4 albertel 162: }
163:
164: sub end_parserlib {
1.40 albertel 165: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 166: my $result='';
167: # if ($target eq "edit" ) {
1.38 albertel 168: # $result=&Apache::edit::tag_end($target,$token);
1.37 albertel 169: # }
170: return $result;
1.6 albertel 171: }
172:
1.30 sakharuk 173: sub start_window {
1.40 albertel 174: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.20 sakharuk 175: my $result = '';
1.31 albertel 176: if ($target eq 'web') {
1.34 albertel 177: &Apache::lonxml::startredirection;
1.35 sakharuk 178: } elsif ($target eq 'tex') {
1.42 sakharuk 179: $result = '\unskip\footnote{';
1.35 sakharuk 180: }
1.19 sakharuk 181: return $result;
182: }
183:
1.30 sakharuk 184: sub end_window {
1.40 albertel 185: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.30 sakharuk 186: my $result;
1.31 albertel 187: if ($target eq 'web') {
1.34 albertel 188: my $output=&Apache::lonxml::endredirection;
189: $output =~ s/\"/\"\;/g;
1.35 sakharuk 190: $result = "<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200,scrollbars=1\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<html><head><title>newwindow</title></head><body bgcolor="#FFFFFF"> $output </body></html>\');newWindow.document.close();void(0);\"><sup>*</sup></a>";
191: } elsif ($target eq 'tex') {
192: $result = '}';
1.30 sakharuk 193: } else {
1.35 sakharuk 194: $result = '';
1.30 sakharuk 195: }
1.20 sakharuk 196: return $result;
1.19 sakharuk 197: }
198:
1.6 albertel 199: sub start_import {
1.40 albertel 200: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31 albertel 201: my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7 albertel 202: my $result ="";
1.13 albertel 203:
204: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.14 albertel 205:
1.46 albertel 206: if ($target eq 'web' || $target eq 'grade') {
207: # FIXME this probably needs to be smart about construction vs.
208: # non construction space.
209: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
210: my $file=&Apache::lonnet::getfile($location);
211: if ($file == -1) {
212: &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
213: return "";
214: }
1.13 albertel 215:
1.46 albertel 216: my $dir=$location;
217: $dir=~s:/[^/]*$::;
218: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
219: &Apache::lonxml::newparser($parser,\$file,$dir);
220: }
1.13 albertel 221: if ($target eq "edit" ) {
1.46 albertel 222: $result.=&Apache::edit::tag_start($target,$token);
1.38 albertel 223: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
1.46 albertel 224: #FIXME this need to convert $bodytext to be a contruction space reference
225: #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
226: #$result.="Click<a href=\"$location\">here</a> to edit<br />"
1.7 albertel 227: }
1.46 albertel 228: if ($target eq 'modified') {
229: $bodytext=$$parser[$#$parser]->get_text("/import");
230: $result=&Apache::edit::modifiedfield($token);
231: &Apache::lonxml::debug($result);
232: }
233: return $result;
1.6 albertel 234: }
235:
236: sub end_import {
1.45 sakharuk 237: return '';
1.1 albertel 238: }
1.42 sakharuk 239:
240: sub start_storetc {
1.43 albertel 241: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42 sakharuk 242: my $result = '';
243: &Apache::lonxml::startredirection;
244: return $result;
245: }
246:
247: sub end_storetc {
1.43 albertel 248: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42 sakharuk 249: my $result;
250: my $output=&Apache::lonxml::endredirection;
251: $output =~ s/\"/\"\;/g;
252: $result = "{\bf $output.}}\write\tcfile{\protect\tcpc{ $output.}{\the\value{relpage}}}";
253: return $result;
254: }
255:
256:
257: sub start_physnet {
1.45 sakharuk 258: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
259: my $bodytext = '/msu/physnet/cbi.sty';
260: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
261: my $cbistyletext=&Apache::lonnet::getfile($location);
1.42 sakharuk 262:
1.45 sakharuk 263: %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
1.44 albertel 264: if ( defined($$style{'physnet'}) ) {
1.45 sakharuk 265: &Apache::lonxml::newparser($parser,\$$style{'physnet'});
1.44 albertel 266: }
1.45 sakharuk 267: return "";
268: }
1.42 sakharuk 269:
1.45 sakharuk 270: sub end_physnet {
1.47 ! albertel 271: return '';
1.42 sakharuk 272: }
273:
1.47 ! albertel 274: sub xmlparse {
! 275: my ($string) = @_;
! 276: &Apache::lonxml::debug("Got $string");
! 277: my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
! 278: @Apache::scripttag::parser_env;
! 279: my @parser;
! 280: &Apache::lonxml::newparser(\@parser,\$string);
! 281: my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
! 282: $parstack,\@parser,
! 283: $safeeval,$style);
! 284: return $result;
! 285: }
1.3 albertel 286:
1.1 albertel 287: 1;
288: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>