File:
[LON-CAPA] /
loncom /
xml /
scripttag.pm
Revision
1.86:
download - view:
text,
annotated -
select for diffs
Mon Feb 24 23:32:32 2003 UTC (21 years, 3 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- making it easy to moke the port lonhttpd is on, now a config option in loncapa_apache.conf, probably should be moved to loncapa.conf and added to the install questions
- added tag <LONCAPA_INTERNAL_LONHTTPD_PORT /> that gets replaced by a bit of javascript that sets the var lonhttpdport to the correct value
- lonhttpd reads the conf files on start up ad configures intself to the proper port, if the port is set to 80 it exits assuming that Apache is running there
- header image references reference the proper port
- finally making use of the fact that menu.html is parsed before sent out
- everything assumes a default value of 8080 if it can't find a set value
1: # The LearningOnline Network with CAPA
2: # <script> definiton
3: #
4: # $Id: scripttag.pm,v 1.86 2003/02/24 23:32:32 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # 2/21 Guy
29: # 8/20 Gerd Kortemeyer
30:
31: package Apache::scripttag;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::style;
36:
37: #Globals
38: # this used to pass around the standard callsub arguments to a tag func
39: # so xmlparse can reenter the inner_xmlparse loop.
40:
41: @Apache::scripttag::parser_env = ();
42: BEGIN {
43: &Apache::lonxml::register('Apache::scripttag',
44: ('script','scriptlib','parserlib','import',
45: 'window','display','storetc','physnet',
46: 'standalone','comment',
47: 'LONCAPA_INTERNAL_TURN_STYLE_ON',
48: 'LONCAPA_INTERNAL_LONHTTPD_PORT'));
49: }
50:
51: sub start_LONCAPA_INTERNAL_TURN_STYLE_ON {
52: $Apache::lonxml::usestyle=1;
53: return ('','no');
54: }
55:
56: sub end_LONCAPA_INTERNAL_TURN_STYLE_ON {
57: return ('','no');
58: }
59:
60: sub start_LONCAPA_INTERNAL_LONHTTPD_PORT {
61: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
62: if ($target eq 'web') {
63: my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
64: if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
65: return '<script type="text/javascript">var lonhttpdport=\''.
66: $lonhttpdPort.'\';</script>';
67: }
68: return ('','no');
69: }
70:
71: sub end_LONCAPA_INTERNAL_LONHTTPD_PORT {
72: return ('','no');
73: }
74:
75: sub start_script {
76: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
77: @Apache::scripttag::parser_env = @_;
78: my $result='';
79: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
80: &Apache::lonxml::debug("found type of $type");
81: if ($type eq "loncapa/perl") {
82: my $bodytext=&Apache::lonxml::get_all_text("/script",$parser);
83: if ( $target eq "modified" ) {
84: $result=$token->[4].&Apache::edit::modifiedfield();
85: } elsif ( $target eq 'web' || $target eq 'tex' ||
86: $target eq 'grade' || $target eq 'answer' ||
87: $target eq 'analyze' ) {
88: if (!$Apache::lonxml::default_homework_loaded) {
89: &Apache::lonxml::default_homework_load($safeeval);
90: }
91: &Apache::run::run($bodytext,$safeeval);
92: if (($target eq 'answer') && ($Apache::lonhomework::viewgrades == 'F')) {
93: $Apache::lonxml::evaluate--;
94: $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>";
95: my $listing= &HTML::Entities::encode(&Apache::run::dump($target,$safeeval));
96:
97: $result.=$listing;
98: $result.= "</pre></body></html>\');newWindow.document.close();void(0);\">Script Vars</a><br />";
99: }
100: } elsif ($target eq "edit" ) {
101: #&Apache::run::run($bodytext,$safeeval);
102: #$result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
103: $result=&Apache::edit::tag_start($target,$token,'Script');
104: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4);
105: }
106: } else {
107: if ($target ne "meta") {
108: $result = $token->[4];
109: my $bodytext=&Apache::lonxml::get_all_text("/script",$parser);
110: $result.=$bodytext;
111: }
112: }
113: return $result;
114: }
115:
116: sub end_script {
117: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
118: if ( $target eq "meta" ) { return ''; }
119: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
120: my $result='';
121: #other script blocks need to survive
122: if ($type ne "loncapa/perl") {
123: return $token->[2];
124: } elsif ($target eq 'edit' ) {
125: return &Apache::edit::end_table();
126: } elsif ($target eq 'answer') {
127: $Apache::lonxml::evaluate++;
128: }
129: return '';
130: }
131:
132: sub start_display {
133: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
134:
135: my $result;
136: my $bodytext=&Apache::lonxml::get_all_text("/display",$parser);
137:
138: if ( $target eq "modified" ) {
139: $result=$token->[4].&Apache::edit::modifiedfield();
140: } elsif ( $target eq 'web' || $target eq 'tex' ||
141: $target eq 'grade' || $target eq 'answer' ||
142: $target eq 'analyze') {
143: if (!$Apache::lonxml::default_homework_loaded) {
144: &Apache::lonxml::default_homework_load($safeeval);
145: }
146: $result=&Apache::run::run($bodytext,$safeeval);
147: if ($target eq 'grade' || $target eq 'answer' ||
148: $target eq 'analyze') {
149: $result=''; # grade should produce no output
150: }
151: } elsif ($target eq "edit" ) {
152: #$result =
153: # "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
154: #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
155: $result=&Apache::edit::tag_start($target,$token,'Script With Display');
156: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
157: }
158: return $result;
159: }
160:
161: sub end_display {
162: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
163: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
164: return '';
165: }
166:
167: sub start_scriptlib {
168: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
169: my $bodytext;
170: my $result ='';
171: my $error='';
172:
173: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' ||
174: $target eq 'edit' || $target eq 'answer' || $target eq 'analyze') {
175: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
176: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
177: $$parstack[$#$parstack]);
178: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
179: $bodytext);
180: my $script=&Apache::lonnet::getfile($location);
181: if ($script == -1) {
182: if ($target eq 'edit') {
183: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
184: } else {
185: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
186: return "";
187: }
188: }
189: &Apache::run::run($script,$safeeval);
190: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
191: }
192: if ($target eq "edit" ) {
193: $result=
194: &Apache::edit::tag_start($target,$token,'New Script Functions').
195: &Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
196: &Apache::edit::browse(undef,'textnode').
197: $error.'</td></tr>'.
198: &Apache::edit::end_table();
199: }
200: if ($target eq "modified" ) {
201: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
202: $result=$token->[4].&Apache::edit::modifiedfield($token);
203: &Apache::lonxml::debug($result);
204: }
205: return $result;
206: }
207:
208: sub end_scriptlib {
209: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
210: my @result;
211: if ($target eq "edit" ) { $result[1]='no'; }
212: return @result;
213: }
214:
215: sub start_parserlib {
216: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
217: my $bodytext;
218: my $result ="";
219: my $error='';
220: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' ||
221: $target eq 'edit' || $target eq 'answer' || $target eq 'analyze') {
222: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
223: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
224: $$parstack[$#$parstack]);
225: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
226: $bodytext);
227: my $styletext=&Apache::lonnet::getfile($location);
228: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
229: if ($styletext == -1) {
230: if ($target eq 'edit') {
231: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
232: } else {
233: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
234: return "";
235: }
236: }
237: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
238: }
239: if ($target eq "edit" ) {
240: $result=
241: &Apache::edit::tag_start($target,$token,'New Tag Definitions').
242: &Apache::edit::editline($token->[1],$bodytext,'',40).
243: $error.'</td></tr>'.
244: &Apache::edit::end_table();
245: }
246: if ($target eq "modified" ) {
247: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
248: $result=$token->[4].&Apache::edit::modifiedfield($token);
249: &Apache::lonxml::debug($result);
250: }
251: return $result;
252: }
253:
254: sub end_parserlib {
255: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
256: my @result;
257: if ($target eq "edit" ) { $result[1]='no'; }
258: return @result;
259: }
260:
261: sub start_window {
262: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
263: my $result = '';
264: if ($target eq 'web') {
265: &Apache::lonxml::startredirection;
266: } elsif ($target eq 'tex') {
267: $result = '\unskip\footnote{';
268: }
269: return $result;
270: }
271:
272: sub end_window {
273: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
274: my $result;
275: if ($target eq 'web') {
276: my $output=&Apache::lonxml::endredirection;
277: $output =~ s/\"/\"\;/g;
278: $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>";
279: } elsif ($target eq 'tex') {
280: $result = '}';
281: } else {
282: $result = '';
283: }
284: return $result;
285: }
286:
287: sub start_import {
288: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
289: my $bodytext=$$parser[$#$parser]->get_text("/import");
290: my $result ="";
291:
292: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
293:
294: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
295: $target eq 'tex' || $target eq 'analyze' ) {
296: # FIXME this probably needs to be smart about construction vs.
297: # non construction space.
298: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
299: my $file=&Apache::lonnet::getfile($location);
300: if ($file == -1) {
301: &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
302: return "";
303: }
304:
305: my $dir=$location;
306: $dir=~s:/[^/]*$::;
307: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
308: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
309: if (!$id) { $id=$Apache::lonxml::curdepth; }
310: push(@Apache::inputtags::import,$id);
311: &Apache::lonxml::newparser($parser,\$file,$dir);
312: } elsif ($target eq "edit" ) {
313: $result.=&Apache::edit::tag_start($target,$token);
314: $result.=&Apache::edit::editline($token->[1],$bodytext,'',40);
315: $result.=&Apache::edit::browse(undef,'textnode');
316: #FIXME this need to convert $bodytext to be a contruction space reference
317: #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
318: #$result.="Click<a href=\"$location\">here</a> to edit<br />"
319: } elsif ($target eq 'modified') {
320: $bodytext=$$parser[$#$parser]->get_text("/import");
321: $result=$token->[4].&Apache::edit::modifiedfield($token);
322: &Apache::lonxml::debug($result);
323: } elsif ($target eq 'meta') {
324: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
325: $result.='<import part="'.$Apache::inputtags::part;
326: if ($id) {
327: $result.='" id="'.$id;
328: }
329: $result.='">';
330: $result.=$bodytext;
331: $result.='</import>';
332: }
333: return $result;
334: }
335:
336: sub end_import {
337: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
338: pop(@Apache::inputtags::import);
339: my $result;
340: if ($target eq 'edit' ) { $result=&Apache::edit::end_table(); }
341: return $result;
342: }
343:
344: sub start_storetc {
345: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
346: my $result = '';
347: &Apache::lonxml::startredirection;
348: return $result;
349: }
350:
351: sub end_storetc {
352: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
353: my $result;
354: my $output=&Apache::lonxml::endredirection;
355: $output =~ s/\"/\"\;/g;
356: $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
357: return $result;
358: }
359:
360:
361: sub start_physnet {
362: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
363: my $bodytext = '/adm/includes/physnet.sty';
364: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
365: my $cbistyletext=&Apache::lonnet::getfile($location);
366:
367: %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
368: $$parser['-1']->unget_token($token);
369: # if ( defined($$style{'physnet'}) ) {
370: # &Apache::lonxml::newparser($parser,\$$style{'physnet'});
371: # }
372: return "";
373: }
374:
375: sub end_physnet {
376: return '';
377: }
378:
379: sub start_standalone {
380: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
381: my $result='';
382: if ($target eq 'web' ) {
383: if ( $ENV{'request.course.id'} ) {
384: my $inside = &Apache::lonxml::get_all_text("/standalone",$parser);
385: } else {
386: $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
387: }
388: }
389: return $result;
390: }
391:
392: sub end_standalone {
393: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
394: my $result='';
395: if ($target eq 'web' ) {
396: if ( $ENV{'request.course.id'} ) {
397: } else {
398: $result='</td></tr></table>';
399: }
400: }
401: return $result;
402: }
403:
404: sub start_comment {
405: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
406: my $result='';
407: if ($target eq 'edit') {
408: $result=&Apache::edit::tag_start($target,$token);
409: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser);
410: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
411: } elsif ( $target eq 'modified') {
412: $result=$token->[4].&Apache::edit::modifiedfield($token);
413: } elsif ( $target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
414: $target eq 'answer' || $target eq 'meta' || $target eq 'analyze') {
415: #normally throw away comments
416: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser);
417: }
418: return $result;
419: }
420:
421: sub end_comment {
422: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
423: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
424: return '';
425: }
426:
427:
428: sub xmlparse {
429: my ($string) = @_;
430: &Apache::lonxml::debug("Got $string");
431: my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
432: @Apache::scripttag::parser_env;
433: my @parser;
434: &Apache::lonxml::newparser(\@parser,\$string);
435: my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
436: $parstack,\@parser,
437: $safeeval,$style);
438: return $result;
439: }
440:
441: 1;
442: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>