File:
[LON-CAPA] /
loncom /
xml /
scripttag.pm
Revision
1.18:
download - view:
text,
annotated -
select for diffs
Thu Oct 5 19:31:54 2000 UTC (23 years, 9 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- uses new &newparser routine
- uses new lonnet routines &filelocation and &getfile
- new global $Apache::scripttag::SCRIPT_RESULT so the safe enviroment can
report back results.
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: $Apache::scripttag::SCRIPT_RESULT='';
16: sub start_script {
17: my ($target,$token,$parstack,$parser,$safeeval)=@_;
18: my $args ='';
19: if ( $#$parstack > -1 ) {
20: $args=$$parstack[$#$parstack];
21: }
22: my $type = &Apache::run::run("{$args;".'return $type}',$safeeval);
23: #&Apache::lonxml::debug("found type of $type");
24: $Apache::scripttag::SCRIPT_RESULT='';
25: if ($type eq "loncapa/perl") {
26: $safeeval->share('$SCRIPT_RESULT');
27: my $bodytext=&Apache::lonxml::get_all_text("script",$$parser[$#$parser]);
28:
29: if ( $target eq "modified" ) {
30: }
31: &Apache::run::run($bodytext,$safeeval);
32:
33: if ($target eq "edit" ) {
34: $Apache::scripttag::SCRIPT_RESULT =
35: "<br> <$token->[1]> output: <br>$bodytext<br>Source:<br>";
36: $Apache::scripttag::SCRIPT_RESULT.=&editfield($token->[1],$bodytext);
37: }
38: } else {
39: $Apache::scripttag::SCRIPT_RESULT = $token->[4];
40: }
41: return $Apache::scripttag::SCRIPT_RESULT;
42: }
43:
44: sub end_script {
45: my ($target,$token,$parstack,$parser,$safeeval)=@_;
46: return $token->[2];
47: }
48:
49: sub start_scriptlib {
50: my ($target,$token,$parstack,$parser,$safeeval)=@_;
51: my $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
52: my $result ="";
53:
54: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
55: $$parstack[$#$parstack]);
56: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
57: $bodytext);
58: my $script=&Apache::lonnet::getfile($location);
59: if ($script == -1) {
60: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
61: return "";
62: }
63: &Apache::run::run($script,$safeeval);
64: #&Apache::lonxml::debug("ran $bodytext:<br>".&Apache::lonnet::getfile($bodytext)."<br>");
65:
66: if ($target eq "edit" ) {
67: $result.=&editfield($token->[1],$bodytext);
68: }
69: return $result;
70: }
71:
72: sub end_scriptlib {}
73:
74: sub start_parserlib {
75: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
76: my $bodytext=$$parser[$#$parser]->get_text("/parserlib");
77: my $result ="";
78:
79: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
80: $$parstack[$#$parstack]);
81: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
82: $bodytext);
83: my $styletext=&Apache::lonnet::getfile($location);
84: if ($styletext == -1) {
85: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
86: return "";
87: }
88: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
89:
90: if ($target eq "edit" ) {
91: $result=&editfield($token->[1],$bodytext);
92: }
93: return $result;
94: }
95:
96: sub end_parserlib {
97: }
98:
99: sub start_import {
100: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
101: my $bodytext=$$parser[$#$parser]->get_text("/import");
102: my $result ="";
103:
104: $bodytext=Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
105: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
106: my $file=&Apache::lonnet::getfile($location);
107: if ($file == -1) {
108: &Apache::lonxml::error("<b> Unable to find <i>$bodytext $location</i> for import</b>");
109: return "";
110: }
111:
112: my $dir=$location;
113: $dir=~s:/[^/]*$::;
114: &Apache::lonxml::newparser($parser,\$file,$dir);
115:
116: if ($target eq "edit" ) {
117: $result.=&editfield($token->[1],$bodytext);
118: $result.="Click<a href=\"/res/$bodytext\">here</a> to edit<br></br>"
119: }
120: }
121:
122: sub end_import {
123: }
124:
125: sub editfield {
126: my ($tag,$data)=@_;
127:
128: my $count=0;
129: my $maxlength=-1;
130: map { $count++;
131: if (length($_) > $maxlength) { $maxlength = length ($_); }
132: } split ("\n", $data);
133:
134: 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";
135: }
136:
137: sub getfilenothere {
138: my ($filename) = @_;
139: my $a="";
140:
141: $filename=~ s/^\s*(\S+)\s*$/$1/; ## strip off leading and trailing spaces
142: $filename="/home/httpd/html/res".$filename;
143: if (! -e $filename ) {
144: &Apache::lonnet::subscribe($filename);
145: &Apache::lonnet::repcopy($filename);
146: }
147: if (! -e $filename ) { return -1; };
148: my $fh=Apache::File->new($filename);
149: while (<$fh>) {
150: $a .=$_;
151: }
152: return $a
153: }
154:
155: 1;
156: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>