Annotation of loncom/xml/scripttag.pm, revision 1.38
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # <script> definiton
1.34 albertel 3: # 2/21 Guy
1.1 albertel 4:
5: package Apache::scripttag;
6:
7: use strict;
1.3 albertel 8: use Apache::lonnet;
1.1 albertel 9:
10: sub BEGIN {
1.6 albertel 11: &Apache::lonxml::register('Apache::scripttag',('script','scriptlib',
1.20 sakharuk 12: 'parserlib','import',
1.32 albertel 13: 'window','display'));
1.1 albertel 14: }
15:
16: sub start_script {
1.2 albertel 17: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.17 albertel 18: my $args ='';
1.29 albertel 19: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
1.17 albertel 20: my $type = &Apache::run::run("{$args;".'return $type}',$safeeval);
1.24 albertel 21: my $result='';
1.18 albertel 22: #&Apache::lonxml::debug("found type of $type");
1.17 albertel 23: if ($type eq "loncapa/perl") {
1.21 albertel 24: my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
1.17 albertel 25:
26: if ( $target eq "modified" ) {
1.37 albertel 27: $result=$token->[4].$bodytext;
1.28 albertel 28: } elsif ( $target eq "web" || $target eq "grade" ) {
29: &Apache::run::run($bodytext,$safeeval);
30: } elsif ($target eq "edit" ) {
31: &Apache::run::run($bodytext,$safeeval);
1.33 albertel 32: $result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
1.38 ! albertel 33: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',50,5);
1.17 albertel 34: }
35: } else {
1.28 albertel 36: if ($target ne "meta") { $result = $token->[4]; }
1.13 albertel 37: }
1.24 albertel 38: return $result;
1.17 albertel 39: }
1.13 albertel 40:
1.17 albertel 41: sub end_script {
42: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.28 albertel 43: if ( $target eq "meta" ) { return ''; }
1.29 albertel 44: my $args ='';
45: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
46: my $type = &Apache::run::run("{$args;".'return $type}',$safeeval);
47: my $result='';
48: #other script blocks need to survive
49: if ($type ne "loncapa/perl") { return $token->[2]; }
1.28 albertel 50: return '';
1.24 albertel 51: }
52:
53: sub start_display {
54: my ($target,$token,$parstack,$parser,$safeeval)=@_;
55: my $args ='';
56: if ( $#$parstack > -1 ) {
57: $args=$$parstack[$#$parstack];
58: }
59: my $bodytext=&Apache::lonxml::get_all_text("/display",$$parser[$#$parser]);
60:
61: if ( $target eq "modified" ) {
62: }
63: my $result=&Apache::run::run($bodytext,$safeeval);
1.26 albertel 64: if ($target eq 'grade' ) {
65: # grade should produce no output
66: $result='';
67: }
1.24 albertel 68: if ($target eq "edit" ) {
69: $result =
1.33 albertel 70: "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
1.38 ! albertel 71: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
1.24 albertel 72: }
73: return $result;
74: }
75:
76: sub end_display {
1.38 ! albertel 77: return ''
1.1 albertel 78: }
1.3 albertel 79:
80: sub start_scriptlib {
1.37 albertel 81: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
82: my $bodytext;
83: my $result ='';
84: my $error='';
85:
86: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
87: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
88: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
89: $$parstack[$#$parstack]);
90: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
91: $bodytext);
92: my $script=&Apache::lonnet::getfile($location);
93: if ($script == -1) {
94: if ($target eq 'edit') {
95: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
96: } else {
97: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
98: return "";
99: }
100: }
101: &Apache::run::run($script,$safeeval);
102: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
1.18 albertel 103: }
1.13 albertel 104: if ($target eq "edit" ) {
1.37 albertel 105: $result=
1.38 ! albertel 106: &Apache::edit::tag_start($target,$token).
! 107: &Apache::edit::editfield($token->[1],$bodytext,'New Script Functions',40,1).
1.37 albertel 108: $error;
109: }
110: if ($target eq "modified" ) {
111: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
112: $result=&Apache::edit::modifiedfield($token);
113: &Apache::lonxml::debug($result);
1.3 albertel 114: }
115: return $result;
116: }
117:
1.37 albertel 118: sub end_scriptlib {
119: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
120: my $result='';
121: # if ($target eq "edit" ) { $result=" "; }
122: return $result;
123: }
1.4 albertel 124:
125: sub start_parserlib {
126: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 127: my $bodytext;
1.7 albertel 128: my $result ="";
1.37 albertel 129: my $error='';
1.13 albertel 130:
1.37 albertel 131: if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
132: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
133: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
134: $$parstack[$#$parstack]);
135: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
136: $bodytext);
137: my $styletext=&Apache::lonnet::getfile($location);
138: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
139: if ($styletext == -1) {
140: if ($target eq 'edit') {
141: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
142: } else {
143: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
144: return "";
145: }
146: }
147: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
1.18 albertel 148: }
1.13 albertel 149: if ($target eq "edit" ) {
1.37 albertel 150: $result=
1.38 ! albertel 151: &Apache::edit::tag_start($target,$token).
! 152: &Apache::edit::editfield($token->[1],$bodytext,"New Tag Definitions",40,1).
1.37 albertel 153: $error;
154: }
155: if ($target eq "modified" ) {
156: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
157: $result=&Apache::edit::modifiedfield($token);
158: &Apache::lonxml::debug($result);
1.7 albertel 159: }
160: return $result;
1.4 albertel 161: }
162:
163: sub end_parserlib {
1.37 albertel 164: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
165: my $result='';
166: # if ($target eq "edit" ) {
1.38 ! albertel 167: # $result=&Apache::edit::tag_end($target,$token);
1.37 albertel 168: # }
169: return $result;
1.6 albertel 170: }
171:
1.30 sakharuk 172: sub start_window {
1.19 sakharuk 173: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.20 sakharuk 174: my $result = '';
1.31 albertel 175: if ($target eq 'web') {
1.34 albertel 176: &Apache::lonxml::startredirection;
1.35 sakharuk 177: } elsif ($target eq 'tex') {
178: $result = '\footnote{';
179: }
1.19 sakharuk 180: return $result;
181: }
182:
1.30 sakharuk 183: sub end_window {
1.19 sakharuk 184: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.30 sakharuk 185: my $result;
1.31 albertel 186: if ($target eq 'web') {
1.34 albertel 187: my $output=&Apache::lonxml::endredirection;
188: $output =~ s/\"/\"\;/g;
1.35 sakharuk 189: $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>";
190: } elsif ($target eq 'tex') {
191: $result = '}';
1.30 sakharuk 192: } else {
1.35 sakharuk 193: $result = '';
1.30 sakharuk 194: }
1.20 sakharuk 195: return $result;
1.19 sakharuk 196: }
197:
1.6 albertel 198: sub start_import {
1.7 albertel 199: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.31 albertel 200: my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7 albertel 201: my $result ="";
1.13 albertel 202:
203: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.18 albertel 204: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
205: my $file=&Apache::lonnet::getfile($location);
206: if ($file == -1) {
207: &Apache::lonxml::error("<b> Unable to find <i>$bodytext $location</i> for import</b>");
208: return "";
1.14 albertel 209: }
210:
1.18 albertel 211: my $dir=$location;
1.30 sakharuk 212: $dir=~s:/[^/]*$::;
213: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
1.18 albertel 214: &Apache::lonxml::newparser($parser,\$file,$dir);
1.13 albertel 215:
216: if ($target eq "edit" ) {
1.38 ! albertel 217: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
1.33 albertel 218: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br />"
1.7 albertel 219: }
1.27 albertel 220: return '';
1.6 albertel 221: }
222:
223: sub end_import {
1.7 albertel 224: }
1.30 sakharuk 225:
226: sub start_meta {
227: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
228: my $result = '';
229: if ($target ne 'meta') {
230: $result = &Apache::lonxml::get_all_text("/meta",$$parser[$#$parser]);
231: $result = '';
232: return $result;
233: } else {
234: return $result;
235: }
236: }
237:
238: sub end_meta {
1.4 albertel 239: }
1.3 albertel 240:
1.18 albertel 241: sub getfilenothere {
1.3 albertel 242: my ($filename) = @_;
243: my $a="";
1.11 tsai 244:
1.12 tsai 245: $filename=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
1.10 albertel 246: $filename="/home/httpd/html/res".$filename;
247: if (! -e $filename ) {
248: &Apache::lonnet::subscribe($filename);
249: &Apache::lonnet::repcopy($filename);
250: }
1.14 albertel 251: if (! -e $filename ) { return -1; };
1.11 tsai 252: my $fh=Apache::File->new($filename);
253: while (<$fh>) {
1.3 albertel 254: $a .=$_;
255: }
256: return $a
1.1 albertel 257: }
1.3 albertel 258:
1.1 albertel 259: 1;
260: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>