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