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