File:
[LON-CAPA] /
loncom /
xml /
scripttag.pm
Revision
1.22:
download - view:
text,
annotated -
select for diffs
Mon Oct 30 20:34:25 2000 UTC (23 years, 9 months ago) by
sakharuk
Branches:
MAIN
CVS tags:
HEAD
In londefdef.pm a few tags for tex target were changed: <m>,<p>,...
In lonxml.pm a new global variable textredirection was introduced. It is used for dwitch on and off the metadata output. A few lines of code were added.
1: # The LearningOnline Network with CAPA
2: # <script> definiton
3:
4:
5: package Apache::scripttag;
6:
7: use strict;
8: use Apache::lonnet;
9:
10: sub BEGIN {
11: &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
12: 'parserlib','import',
13: 'footnote'));
14: }
15:
16: $Apache::scripttag::SCRIPT_RESULT='';
17: sub start_script {
18: my ($target,$token,$parstack,$parser,$safeeval)=@_;
19: my $args ='';
20: if ( $#$parstack > -1 ) {
21: $args=$$parstack[$#$parstack];
22: }
23: my $type = &Apache::run::run("{$args;".'return $type}',$safeeval);
24: #&Apache::lonxml::debug("found type of $type");
25: $Apache::scripttag::SCRIPT_RESULT='';
26: if ($type eq "loncapa/perl") {
27: $safeeval->share('$SCRIPT_RESULT');
28: my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
29:
30: if ( $target eq "modified" ) {
31: }
32: &Apache::run::run($bodytext,$safeeval);
33:
34: if ($target eq "edit" ) {
35: $Apache::scripttag::SCRIPT_RESULT =
36: "<br> <$token->[1]> output: <br>$bodytext<br>Source:<br>";
37: $Apache::scripttag::SCRIPT_RESULT.=&editfield($token->[1],$bodytext);
38: }
39: } else {
40: $Apache::scripttag::SCRIPT_RESULT = $token->[4];
41: }
42: return $Apache::scripttag::SCRIPT_RESULT;
43: }
44:
45: sub end_script {
46: my ($target,$token,$parstack,$parser,$safeeval)=@_;
47: return $token->[2];
48: }
49:
50: sub start_scriptlib {
51: my ($target,$token,$parstack,$parser,$safeeval)=@_;
52: my $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
53: my $result ="";
54:
55: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
56: $$parstack[$#$parstack]);
57: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
58: $bodytext);
59: my $script=&Apache::lonnet::getfile($location);
60: if ($script == -1) {
61: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
62: return "";
63: }
64: &Apache::run::run($script,$safeeval);
65: #&Apache::lonxml::debug("ran $bodytext:<br>".&Apache::lonnet::getfile($bodytext)."<br>");
66:
67: if ($target eq "edit" ) {
68: $result.=&editfield($token->[1],$bodytext);
69: }
70: return $result;
71: }
72:
73: sub end_scriptlib {}
74:
75: sub start_parserlib {
76: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
77: my $bodytext=$$parser[$#$parser]->get_text("/parserlib");
78: my $result ="";
79:
80: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
81: $$parstack[$#$parstack]);
82: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
83: $bodytext);
84: my $styletext=&Apache::lonnet::getfile($location);
85: if ($styletext == -1) {
86: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
87: return "";
88: }
89: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
90:
91: if ($target eq "edit" ) {
92: $result=&editfield($token->[1],$bodytext);
93: }
94: return $result;
95: }
96:
97: sub end_parserlib {
98: }
99:
100: sub start_footnote {
101: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
102: my $result = '';
103: $Apache::lonxml::redirection = 0;
104: return $result;
105: }
106:
107: sub end_footnote {
108: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
109: $Apache::lonxml::outputstack =~ s/\"/\"\;/g;
110: my $result = "<a href=\"javascript:newWindow=open(\'\',\'new_W\',\'width=500,height=200\');newWindow.document.open(\'text/html\',\'replace\');newWindow.document.writeln(\'<html><head><title>newwindow</title></head><body bgcolor="#FFFFFF"> $Apache::lonxml::outputstack </body></html>\');newWindow.document.close();void(0);\"><sup>*</sup></a>";
111: if ($target eq 'meta') {$result = '';}
112: $Apache::lonxml::outputstack = "";
113: $Apache::lonxml::redirection = 1;
114: return $result;
115: }
116:
117: sub start_import {
118: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
119: my $bodytext=$$parser[$#$parser]->get_text("/import");
120: my $result ="";
121:
122: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
123: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
124: my $file=&Apache::lonnet::getfile($location);
125: if ($file == -1) {
126: &Apache::lonxml::error("<b> Unable to find <i>$bodytext $location</i> for import</b>");
127: return "";
128: }
129:
130: my $dir=$location;
131: $dir=~s:/[^/]*$::;
132: &Apache::lonxml::newparser($parser,\$file,$dir);
133:
134: if ($target eq "edit" ) {
135: $result.=&editfield($token->[1],$bodytext);
136: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br></br>"
137: }
138: }
139:
140: sub end_import {
141: }
142:
143: sub editfield {
144: my ($tag,$data)=@_;
145:
146: my $count=0;
147: my $maxlength=-1;
148: map { $count++;
149: if (length($_) > $maxlength) { $maxlength = length ($_); }
150: } split ("\n", $data);
151:
152: return "<br></br>\n<$tag><br></br>\n <textarea rows=\"$count\" cols=\"$maxlength\" name=homework_edit_".$Apache::lonxml::curdepth.">$data</textarea><br></br>\n</$tag><br></br>\n";
153: }
154:
155: sub getfilenothere {
156: my ($filename) = @_;
157: my $a="";
158:
159: $filename=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
160: $filename="/home/httpd/html/res".$filename;
161: if (! -e $filename ) {
162: &Apache::lonnet::subscribe($filename);
163: &Apache::lonnet::repcopy($filename);
164: }
165: if (! -e $filename ) { return -1; };
166: my $fh=Apache::File->new($filename);
167: while (<$fh>) {
168: $a .=$_;
169: }
170: return $a
171: }
172:
173: 1;
174: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>