File:
[LON-CAPA] /
loncom /
xml /
scripttag.pm
Revision
1.13:
download - view:
text,
annotated -
select for diffs
Wed Aug 16 18:32:58 2000 UTC (24 years ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- implemented new get_all_text,
actually works like I'd like $parser->get_text() to.
- started on edit/modified tags
- notice both get_all_text and increasedepth/decresedepth don't like broken
documents, and they aren't very hardy.
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: }
14:
15: sub start_script {
16: my ($target,$token,$parstack,$parser,$safeeval)=@_;
17: my $result="";
18: # my $bodytext=$$parser[$#$parser]->get_text("/script");
19: my $bodytext=&Apache::lonxml::get_all_text("script",$$parser[$#$parser]);
20:
21: if ( $target eq "modified" ) {
22:
23: }
24:
25: # print "<br> script runs $bodytext</br>";
26: $result = &Apache::run::run($bodytext,$safeeval);
27:
28: if ($target eq "edit" ) {
29: $result= "<br> <$token->[1]> output: <br>$bodytext<br>Source:<br>";
30: $result.=&editfield($token->[1],$bodytext);
31: }
32: return $result;
33: }
34:
35: sub end_script {}
36:
37: sub start_scriptlib {
38: my ($target,$token,$parstack,$parser,$safeeval)=@_;
39: my $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
40: my $result ="";
41:
42: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
43: &Apache::run::run(&getfile($bodytext),$safeeval);
44: #print "ran $bodytext:<br>".&getfile($bodytext)."<br>";
45:
46: if ($target eq "edit" ) {
47: $result.=&editfield($token->[1],$bodytext);
48: }
49: return $result;
50: }
51:
52: sub end_scriptlib {}
53:
54: sub start_parserlib {
55: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
56: my $bodytext=$$parser[$#$parser]->get_text("/parserlib");
57: my $result ="";
58:
59: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
60: %$style = ( %$style , &Apache::style::styleparser($target,
61: &getfile($bodytext)));
62:
63: if ($target eq "edit" ) {
64: $result=&editfield($token->[1],$bodytext);
65: }
66: return $result;
67: }
68:
69: sub end_parserlib {
70: }
71:
72: sub start_import {
73: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
74: my $bodytext=$$parser[$#$parser]->get_text("/import");
75: my $result ="";
76:
77: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
78: my $file=&getfile($bodytext);
79: my $tempparser=HTML::TokeParser->new(\$file);
80: push (@$parser,$tempparser);
81:
82: if ($target eq "edit" ) {
83: $result.=&editfield($token->[1],$bodytext);
84: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br></br>"
85: }
86: }
87:
88: sub end_import {
89: }
90:
91: sub editfield {
92: my ($tag,$data)=@_;
93:
94: my $count=0;
95: my $maxlength=-1;
96: map { $count++;
97: if (length($_) > $maxlength) { $maxlength = length ($_); }
98: } split ("\n", $data);
99:
100: 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";
101: }
102:
103: sub getfile {
104: my ($filename) = @_;
105: my $a="";
106:
107: $filename=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
108: $filename="/home/httpd/html/res".$filename;
109: if (! -e $filename ) {
110: &Apache::lonnet::subscribe($filename);
111: &Apache::lonnet::repcopy($filename);
112: }
113: my $fh=Apache::File->new($filename);
114: while (<$fh>) {
115: $a .=$_;
116: }
117: return $a
118: }
119:
120: 1;
121: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>