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