Annotation of loncom/xml/scripttag.pm, revision 1.172.2.2.2.1
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # <script> definiton
1.58 www 3: #
1.172.2.2.2.1! (raeburn 4:: # $Id: scripttag.pm,v 1.172.2.2 2016/09/14 14:55:06 raeburn Exp $
1.58 www 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: #
1.116 www 28:
1.47 albertel 29: package Apache::scripttag;
1.1 albertel 30:
31: use strict;
1.3 albertel 32: use Apache::lonnet;
1.172.2.2.2.1! (raeburn 33:: use Apache::loncommon;
1.145 albertel 34: use Apache::lonlocal;
1.167 raeburn 35: use Apache::lonxml();
36: use Apache::londefdef();
1.145 albertel 37: use Apache::style();
1.1 albertel 38:
1.47 albertel 39: #Globals
40: # this used to pass around the standard callsub arguments to a tag func
41: # so xmlparse can reenter the inner_xmlparse loop.
42:
43: @Apache::scripttag::parser_env = ();
1.61 harris41 44: BEGIN {
1.62 albertel 45: &Apache::lonxml::register('Apache::scripttag',
46: ('script','scriptlib','parserlib','import',
1.163 www 47: 'window','windowlink','togglebox','display','storetc','physnet',
1.123 albertel 48: 'standalone','comment','num','parse','algebra',
1.86 albertel 49: 'LONCAPA_INTERNAL_TURN_STYLE_ON',
1.150 raeburn 50: 'LONCAPA_INTERNAL_TURN_STYLE_OFF'));
1.81 albertel 51: }
52:
53: sub start_LONCAPA_INTERNAL_TURN_STYLE_ON {
54: $Apache::lonxml::usestyle=1;
1.89 albertel 55: $Apache::lonxml::style_values='';
1.81 albertel 56: return ('','no');
57: }
58:
59: sub end_LONCAPA_INTERNAL_TURN_STYLE_ON {
1.91 albertel 60: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
61: my $end=&Apache::lonxml::get_param('end',$parstack,$safeeval);
62: if (defined($end)) {
63: &Apache::lonxml::end_tag($tagstack,$parstack,$token);
64: }
1.100 albertel 65: return ('','no');
66: }
67:
68: sub start_LONCAPA_INTERNAL_TURN_STYLE_OFF {
69: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
70: $Apache::lonxml::usestyle=0;
71: my $end=&Apache::lonxml::get_param('end',$parstack,$safeeval);
72: if (!$end) {
73: $Apache::lonxml::style_values=$$parstack[-1];
74: $Apache::lonxml::style_end_values=$$parstack[-1];
75: } else {
76: $Apache::lonxml::style_values=$Apache::lonxml::style_end_values;
77: $Apache::lonxml::style_end_values='';
78: }
79: return ('','no');
80: }
81:
82: sub end_LONCAPA_INTERNAL_TURN_STYLE_OFF {
1.86 albertel 83: return ('','no');
84: }
85:
1.1 albertel 86: sub start_script {
1.40 albertel 87: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.47 albertel 88: @Apache::scripttag::parser_env = @_;
1.24 albertel 89: my $result='';
1.39 albertel 90: my $type= &Apache::lonxml::get_param('type',$parstack,$safeeval);
91: &Apache::lonxml::debug("found type of $type");
1.17 albertel 92: if ($type eq "loncapa/perl") {
93: if ( $target eq "modified" ) {
1.103 albertel 94: $result=$token->[4].&Apache::edit::modifiedfield('/script',$parser);
1.54 albertel 95: } elsif ( $target eq 'web' || $target eq 'tex' ||
1.130 albertel 96: $target eq 'grade' || $target eq 'webgrade' ||
97: $target eq 'answer' || $target eq 'analyze' ) {
1.107 albertel 98: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.79 albertel 99: if (!$Apache::lonxml::default_homework_loaded) {
100: &Apache::lonxml::default_homework_load($safeeval);
101: }
102: &Apache::run::run($bodytext,$safeeval);
1.88 albertel 103: if (($target eq 'answer') &&
1.126 albertel 104: ($env{'form.answer_output_mode'} ne 'tex') &&
1.88 albertel 105: ($Apache::lonhomework::viewgrades == 'F')) {
1.79 albertel 106: $Apache::lonxml::evaluate--;
1.138 albertel 107: my (undef,undef,$udom,$uname)=&Apache::lonnet::whichuser();
1.140 albertel 108: $uname =~s/\W//g;
109: $udom =~s/\W//g;
1.145 albertel 110: my $function_name =
111: join('_','LONCAPA_scriptvars',$uname,$udom,
112: $env{'form.counter'},$Apache::lonxml::curdepth);
1.158 www 113: &Apache::lonxml::add_script_result(
1.159 www 114: &Apache::loncommon::modal_adhoc_window($function_name,500,500,
1.166 raeburn 115: '<pre style="background-color:#ffffff;">'.
116: &Apache::run::dump($target,$safeeval).'</pre>',
1.159 www 117: &mt('Script Vars'))."<br />");
1.79 albertel 118: }
1.28 albertel 119: } elsif ($target eq "edit" ) {
1.41 albertel 120: #&Apache::run::run($bodytext,$safeeval);
121: #$result="<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
1.107 albertel 122: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.103 albertel 123: $result=&Apache::edit::tag_start($target,$token,'Script');
1.172.2.2 raeburn 124:
125: my $depth = $Apache::lonxml::curdepth;
126: $result.='<span id="LC_edit_problem_codemirror">';
1.172.2.2.2.1! (raeburn 127:: my $nocodemirror = &Apache::loncommon::nocodemirror();
! 128:: unless ($nocodemirror) {
1.172.2.2 raeburn 129: # only show button if codemirror activated
130: $result.='<input type="button" id="fitsize'.$depth.'" value="'.&mt("Dynamic size").
131: '" onclick="autosize(\''.$depth.'\')" />';
132: }
133: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4).'</span>';
134:
1.172.2.2.2.1! (raeburn 135:: unless ($nocodemirror) {
1.172.2.2 raeburn 136: $result.='<script type="text/javascript">
137: var cm'.$depth.' = CodeMirror.fromTextArea(document.getElementById("homework_edit_'.$depth.'"),
138: {
139: mode: "perl",
140: lineWrapping: true,
141: lineNumbers: true,
142: tabSize: 4,
143: indentUnit: 4,
144: autoCloseBrackets: true,
145: styleActiveLine: true,
146:
147: extraKeys: {
148: "Tab": "indentMore",
149: "Shift-Tab": "indentLess"
150: }
151: });
152: if(sessionStorage.getItem("autosized_'.$depth.'") != null) {
153: document.getElementById("fitsize'.$depth.'").value = "'.&mt("Fixed size").'";
154: cm'.$depth.'.setSize("","auto");
155: }
156: </script>';
157: }
158:
1.107 albertel 159: } elsif ($target eq 'meta') {
160: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.17 albertel 161: }
162: } else {
1.108 matthew 163: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/script",$parser);
1.144 albertel 164: if ($target ne "meta" && $target ne 'tex' && $target ne 'answer') {
1.112 albertel 165: $result = $token->[4];
166: $result.=$bodytext;
1.168 raeburn 167: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
168: my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
169: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
170: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
171: if ($src ne '') {
172: if ($src !~ m{^(/|https?://)}) {
173: my $cleanhref = &Apache::londefdef::clean_docs_httpref($src,$url,$cdom,$cnum);
174: if ($cleanhref) {
175: &Apache::lonxml::extlink($cleanhref);
1.167 raeburn 176: }
1.168 raeburn 177: }
178: } elsif (($type eq 'text/javascript') && ($bodytext ne '')) {
1.172 raeburn 179: if ($url =~ m{^\Q/uploaded/$cdom/$cnum/\E(docs|supplemental)/}) {
1.171 raeburn 180: if ($bodytext =~ m{\.addMediaSrc\((["'])((?!\1).)+\1\);}) {
1.170 raeburn 181: my $quote = $1;
182: if ($bodytext =~ m{\Q.addMediaSrc($quote\E([^$quote]+)\Q$quote)\E}) {
183: my $fname = $1;
184: my $cleanhref =
185: &Apache::londefdef::clean_docs_httpref($fname,$url,$cdom,$cnum);
186: if ($cleanhref) {
187: &Apache::lonxml::extlink($cleanhref);
188: }
189: }
190: }
1.168 raeburn 191: if ($bodytext =~ m{\.set\w+(Src|Swf)\(["']}i) {
192: my @srcs = split(/\.set/,$bodytext);
193: if (scalar(@srcs) > 1) {
194: foreach my $item (@srcs) {
195: if ($item =~ m{^(FlashPlayerSwf|MediaSrc|XMPSrc|ConfigurationSrc|PosterImageSrc)\((['"])(?:(?!\2).)+\2\)}is) {
196: my $srctype = $1;
197: my $quote = $2;
198: my ($fname) = ($item =~ m{^\Q$srctype($quote\E([^$quote]+)\Q$quote)\E});
1.169 raeburn 199: my $cleanhref =
200: &Apache::londefdef::clean_docs_httpref($fname,$url,$cdom,$cnum);
1.168 raeburn 201: if ($cleanhref) {
202: &Apache::lonxml::extlink($cleanhref);
1.169 raeburn 203: if ($srctype eq 'ConfigurationSrc') {
204: if ($cleanhref =~ m{^(.+/)configuration_express\.xml$}) {
205: #
206: # Camtasia 8.1: express_show/spritesheet.png needed, and included in zip archive.
207: # Not referenced directly in <main>.html or <main>_player.html files,
208: # so call lonxml::extlink() here to include httpref for the uploaded file.
209: # (where <main> is name user gave to file/archive).
210: #
211:
212: my $spritesheet = $1.'express_show/spritesheet.png';
213: if (&Apache::lonnet::repcopy_userfile($spritesheet) eq 'ok') {
214: &Apache::lonxml::extlink($spritesheet);
215: }
216: }
1.170 raeburn 217: #
218: # Camtasia 8.4: express_show/spritesheet.min.css needed, and included in zip archive.
219: # Not referenced directly in <main>.html or <main>_player.html files,
220: # so call lonxml::extlink() here to include httpref for the uploaded file.
221: # (where <main> is name user gave to file/archive).
222: #
223: my $spritesheet_css = $1.'express_show/spritesheet.min.css';
224: if (&Apache::lonnet::repcopy_userfile($spritesheet_css) eq 'ok') {
225: &Apache::lonxml::extlink($spritesheet_css);
226: }
1.169 raeburn 227: } elsif ($srctype eq 'PosterImageSrc') {
228: if ($fname =~ m{^(.+)_First_Frame\.png$}) {
229: my $prefix = $1;
230: my ($path) = ($cleanhref =~ m{^(.+/)\Q$fname\E});
231: #
232: # Camtasia 8.1: <main>_Thumbnails.png needed, and included in zip archive.
233: # Not referenced directly in <main>.html or <main>_player.html files,
234: # so call lonxml::extlink() here to include httpref for the uploaded file
235: # (where <main> is name user gave to file/archive).
236: #
237: my $thumbnail = $path.$prefix.'_Thumbnails.png';
238: if (&Apache::lonnet::repcopy_userfile($thumbnail) eq 'ok') {
239: &Apache::lonxml::extlink($thumbnail);
240: }
241: }
242: }
1.167 raeburn 243: }
244: }
1.165 raeburn 245: }
246: }
247: }
1.170 raeburn 248: if ($bodytext =~ /\(document,\s*(['"])script\1,\s*\[([^\]]+)\]\);/s) {
249: my $scriptslist = $2;
250: my @srcs = split(/\s*,\s*/,$scriptslist);
251: foreach my $src (@srcs) {
252: if ($src =~ /(["'])(?:(?!\1).)+\.js\1/) {
253: my $quote = $1;
254: my ($fname) = ($src =~ m/\Q$quote\E([^$quote]+)\Q$quote\E/);
255: my $cleanhref =
256: &Apache::londefdef::clean_docs_httpref($fname,$url,$cdom,$cnum);
257: if ($cleanhref) {
258: &Apache::lonxml::extlink($cleanhref);
259: }
260: }
261: }
262: }
1.171 raeburn 263: if ($bodytext =~ m{loadScript\(\s*(['"])((?:(?!\1).)+\.js)\1,\s*function}is) {
264: my $fname = $2;
265: if ($fname) {
266: my $cleanhref =
267: &Apache::londefdef::clean_docs_httpref($fname,$url,$cdom,$cnum);
268: if ($cleanhref) {
269: &Apache::lonxml::extlink($cleanhref);
270: }
271: }
272: }
1.165 raeburn 273: }
274: }
1.112 albertel 275: }
1.13 albertel 276: }
1.24 albertel 277: return $result;
1.17 albertel 278: }
1.13 albertel 279:
1.17 albertel 280: sub end_script {
1.40 albertel 281: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.28 albertel 282: if ( $target eq "meta" ) { return ''; }
1.39 albertel 283: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.29 albertel 284: my $result='';
285: #other script blocks need to survive
1.115 albertel 286: if ($type ne "loncapa/perl" && $target ne 'tex') {
1.53 albertel 287: return $token->[2];
288: } elsif ($target eq 'edit' ) {
289: return &Apache::edit::end_table();
1.78 albertel 290: } elsif ($target eq 'answer') {
1.53 albertel 291: $Apache::lonxml::evaluate++;
292: }
1.28 albertel 293: return '';
1.24 albertel 294: }
295:
296: sub start_display {
1.40 albertel 297: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.119 albertel 298: @Apache::scripttag::parser_env = @_;
1.48 albertel 299: my $result;
1.39 albertel 300:
1.24 albertel 301: if ( $target eq "modified" ) {
1.103 albertel 302: $result=$token->[4].&Apache::edit::modifiedfield("/display",$parser);
1.54 albertel 303: } elsif ( $target eq 'web' || $target eq 'tex' ||
1.130 albertel 304: $target eq 'grade' || $target eq 'webgrade' ||
305: $target eq 'answer' || $target eq 'analyze') {
1.107 albertel 306: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.80 albertel 307: if (!$Apache::lonxml::default_homework_loaded) {
308: &Apache::lonxml::default_homework_load($safeeval);
309: }
310: $result=&Apache::run::run($bodytext,$safeeval);
311: if ($target eq 'grade' || $target eq 'answer' ||
312: $target eq 'analyze') {
1.114 albertel 313: # grade/answer/analyxe should produce no output but if we
314: # are redirecting, the redirecter should know what to do
315: # with the output
316: if (!$Apache::lonxml::redirection) { $result=''; }
1.80 albertel 317: }
1.101 albertel 318: $Apache::lonxml::post_evaluate=0;
1.48 albertel 319: } elsif ($target eq "edit" ) {
1.110 albertel 320: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.48 albertel 321: #$result =
322: # "<br /> <$token->[1]> output: <br />$bodytext<br />Source:<br />";
323: #$result.=&Apache::edit::editfield($token->[1],$bodytext,'',40,1);
324: $result=&Apache::edit::tag_start($target,$token,'Script With Display');
1.77 albertel 325: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,1)
1.107 albertel 326: } elsif ($target eq 'meta') {
327: my $bodytext=&Apache::lonxml::get_all_text_unbalanced("/display",$parser);
1.24 albertel 328: }
329: return $result;
330: }
331:
332: sub end_display {
1.48 albertel 333: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
334: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
335: return '';
1.1 albertel 336: }
1.3 albertel 337:
338: sub start_scriptlib {
1.40 albertel 339: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 340: my $bodytext;
341: my $result ='';
342: my $error='';
343:
1.106 albertel 344: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
345: $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
1.137 albertel 346: $target eq 'analyze' || $target eq 'webgrade') {
1.37 albertel 347: $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
348: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
349: $$parstack[$#$parstack]);
350: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
351: $bodytext);
352: my $script=&Apache::lonnet::getfile($location);
353: if ($script == -1) {
354: if ($target eq 'edit') {
1.145 albertel 355: $error='</tr><tr><td>'.&mt('Errors').'</td><td colspan="2"><b>'.&mt(' Unable to find [_1]','<span class="LC_filename">'.$location.'</span>').'</b></td>'."\n";
1.37 albertel 356: } else {
357: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for scriptlib</b>");
358: return "";
359: }
360: }
361: &Apache::run::run($script,$safeeval);
362: #&Apache::lonxml::debug("ran $bodytext:<br />".&Apache::lonnet::getfile($bodytext)."<br />");
1.18 albertel 363: }
1.13 albertel 364: if ($target eq "edit" ) {
1.37 albertel 365: $result=
1.49 albertel 366: &Apache::edit::tag_start($target,$token,'New Script Functions').
1.83 matthew 367: &Apache::edit::editline($token->[1],$bodytext,'scriptlib',40).
368: &Apache::edit::browse(undef,'textnode').
1.49 albertel 369: $error.'</td></tr>'.
370: &Apache::edit::end_table();
1.37 albertel 371: }
372: if ($target eq "modified" ) {
1.103 albertel 373: $result=$token->[4].&Apache::edit::modifiedfield("/scriptlib",$parser);
1.3 albertel 374: }
375: return $result;
376: }
377:
1.37 albertel 378: sub end_scriptlib {
1.40 albertel 379: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.49 albertel 380: my @result;
381: if ($target eq "edit" ) { $result[1]='no'; }
382: return @result;
1.37 albertel 383: }
1.4 albertel 384:
385: sub start_parserlib {
1.40 albertel 386: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.37 albertel 387: my $bodytext;
1.7 albertel 388: my $result ="";
1.37 albertel 389: my $error='';
1.106 albertel 390: if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
391: $target eq 'meta' || $target eq 'edit' || $target eq 'answer' ||
1.137 albertel 392: $target eq 'analyze' || $target eq 'webgrade') {
1.37 albertel 393: $bodytext=$$parser[$#$parser]->get_text("/parserlib");
394: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
395: $$parstack[$#$parstack]);
396: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
397: $bodytext);
398: my $styletext=&Apache::lonnet::getfile($location);
399: #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
400: if ($styletext == -1) {
401: if ($target eq 'edit') {
402: $error='</tr><tr><td>Errors</td><td colspan="2"><b> Unable to find <i>'.$location.'</i></b></td>'."\n";
403: } else {
404: &Apache::lonxml::error("<b> Unable to find <i>$location</i> for parserlib</b>");
405: return "";
406: }
407: }
408: %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
1.18 albertel 409: }
1.13 albertel 410: if ($target eq "edit" ) {
1.37 albertel 411: $result=
1.49 albertel 412: &Apache::edit::tag_start($target,$token,'New Tag Definitions').
1.68 albertel 413: &Apache::edit::editline($token->[1],$bodytext,'',40).
1.49 albertel 414: $error.'</td></tr>'.
415: &Apache::edit::end_table();
1.37 albertel 416: }
417: if ($target eq "modified" ) {
1.103 albertel 418: $result=$token->[4].&Apache::edit::modifiedfield("/parserlib",$parser);
1.7 albertel 419: }
420: return $result;
1.4 albertel 421: }
422:
423: sub end_parserlib {
1.40 albertel 424: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.49 albertel 425: my @result;
426: if ($target eq "edit" ) { $result[1]='no'; }
427: return @result;
1.6 albertel 428: }
429:
1.30 sakharuk 430: sub start_window {
1.105 albertel 431: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
432: my $result = '';
1.137 albertel 433: if ($target eq 'web' || $target eq 'webgrade') {
1.105 albertel 434: &Apache::lonxml::startredirection;
435: } elsif ($target eq 'tex') {
1.164 www 436: my $printtext=&Apache::lonxml::get_param('printtext',$parstack,$safeeval);
437: if ($printtext=~/\w/) {
438: # If printtext is given, do not output any intervening information
439: &Apache::lonxml::startredirection;
440: } else {
441: $result = '\unskip\footnote{';
442: }
1.105 albertel 443: } elsif ($target eq 'edit') {
444: $result.=&Apache::edit::tag_start($target,$token);
445: $result.=&Apache::edit::text_arg('Text of Link:','linktext',$token,70);
1.131 albertel 446: $result.=&Apache::edit::text_arg('Height:','height',$token,5);
447: $result.=&Apache::edit::text_arg('Width:','width',$token,5);
1.164 www 448: $result.=&Apache::edit::text_arg('Printed text (optional):','printtext',$token,20);
1.105 albertel 449: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
450: } elsif ($target eq 'modified') {
451: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.129 raeburn 452: $safeeval,'linktext',
1.161 www 453: 'width','height');
1.105 albertel 454: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
455: }
456: return $result;
1.19 sakharuk 457: }
458:
1.30 sakharuk 459: sub end_window {
1.40 albertel 460: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.30 sakharuk 461: my $result;
1.137 albertel 462: if ($target eq 'web' || $target eq 'webgrade') {
1.34 albertel 463: my $output=&Apache::lonxml::endredirection;
1.92 albertel 464: my $linktext= &Apache::lonxml::get_param('linktext',$parstack,$safeeval);
465: if (!$linktext) { $linktext='<sup>*</sup>'; }
466: my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
467: if (!$width) { $width='500'; }
468: my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
469: if (!$height) { $height='200'; }
1.160 www 470: $result=&Apache::loncommon::modal_adhoc_window
471: ("LONCAPA_newwindow_$Apache::lonxml::curdepth",$width,$height,$output,$linktext);
1.35 sakharuk 472: } elsif ($target eq 'tex') {
1.164 www 473: my $printtext=&Apache::lonxml::get_param('printtext',$parstack,$safeeval);
474: if ($printtext=~/\w/) {
475: # If a "printtext" is given, proceed to retrieve all intervening information and trash it
476: my $output=&Apache::lonxml::endredirection;
477: # Use printtext instead
478: $result=$printtext;
479: } else {
480: $result='}';
481: }
1.30 sakharuk 482: } else {
1.35 sakharuk 483: $result = '';
1.30 sakharuk 484: }
1.20 sakharuk 485: return $result;
1.19 sakharuk 486: }
487:
1.161 www 488:
1.163 www 489: sub start_windowlink {
490: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
491: my $result = '';
492: if ($target eq 'web' || $target eq 'webgrade') {
493: &Apache::lonxml::startredirection;
494: } elsif ($target eq 'edit') {
495: $result.=&Apache::edit::tag_start($target,$token);
496: $result.=&Apache::edit::text_arg('Link:','href',$token,70);
497: $result.=&Apache::edit::text_arg('Height:','height',$token,5);
498: $result.=&Apache::edit::text_arg('Width:','width',$token,5);
499: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
500: } elsif ($target eq 'modified') {
501: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
502: $safeeval,'href',
503: 'width','height');
504: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
505: }
506: return $result;
507: }
508:
509: sub end_windowlink {
510: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
511: my $result;
512: if ($target eq 'web' || $target eq 'webgrade') {
513: my $output=&Apache::lonxml::endredirection;
514: my $href= &Apache::lonxml::get_param('href',$parstack,$safeeval);
515: if (!$href) { $href='/adm/rat/empty.html'; }
516: my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
517: if (!$width) { $width='500'; }
518: my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
519: if (!$height) { $height='200'; }
520: $result=&Apache::loncommon::modal_link($href,$output,$width,$height);
521: } else {
522: $result = '';
523: }
524: return $result;
525: }
526:
527:
1.161 www 528: sub start_togglebox {
529: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
530: my $result = '';
531: if ($target eq 'web' || $target eq 'webgrade') {
532: my $id="LONCAPA_togglebox_$Apache::lonxml::curdepth";
533: my $heading=&Apache::lonxml::get_param('heading',$parstack,$safeeval);
534: unless ($heading) { $heading=''; } else { $heading.=' '; }
535: my $showtext=&Apache::lonxml::get_param('showtext',$parstack,$safeeval);
536: my $hidetext=&Apache::lonxml::get_param('hidetext',$parstack,$safeeval);
537: my $headerbg=&Apache::lonxml::get_param('headerbg',$parstack,$safeeval);
1.162 www 538: $result=&Apache::loncommon::start_togglebox($id,$heading,$headerbg,$hidetext,$showtext);
1.161 www 539: } elsif ($target eq 'tex') {
540: my $heading=&Apache::lonxml::get_param('heading',$parstack,$safeeval);
541: unless ($heading) { $heading=''; } else { $heading.=' '; }
542: $result = "\n\n".'\fbox{{\bf '.$heading.'} \qquad '."\n";
543: } elsif ($target eq 'edit') {
544: $result.=&Apache::edit::tag_start($target,$token);
545: $result.=&Apache::edit::text_arg('Heading:','heading',$token,70);
546: $result.=&Apache::edit::text_arg('Header Background:','headerbg',$token,7);
547: $result.=&Apache::edit::text_arg('Show text:','showtext',$token,10);
548: $result.=&Apache::edit::text_arg('Hide text:','hidetext',$token,10);
549: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
550: } elsif ($target eq 'modified') {
551: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
552: $safeeval,'heading',
553: 'showtext','hidetext',
554: 'headerbg','textbg');
555: if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
556: }
557: return $result;
558: }
559:
560: sub end_togglebox {
561: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
562: my $result;
563: if ($target eq 'web' || $target eq 'webgrade') {
1.162 www 564: $result=&Apache::loncommon::end_togglebox();
1.161 www 565: } elsif ($target eq 'tex') {
566: $result = "}\n\n";
567: } else {
568: $result = '';
569: }
570: return $result;
571: }
572:
573:
574:
1.6 albertel 575: sub start_import {
1.40 albertel 576: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.31 albertel 577: my $bodytext=$$parser[$#$parser]->get_text("/import");
1.7 albertel 578: my $result ="";
1.13 albertel 579:
1.153 www 580: $bodytext=&Apache::run::evaluate($bodytext,$safeeval,$$parstack[$#$parstack]);
1.14 albertel 581:
1.135 albertel 582: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade'
583: || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze' ) {
1.46 albertel 584: # FIXME this probably needs to be smart about construction vs.
585: # non construction space.
586: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
587: my $file=&Apache::lonnet::getfile($location);
588: if ($file == -1) {
589: &Apache::lonxml::error("<b> Unable to find <i>$bodytext as $location</i> for import</b>");
590: return "";
591: }
1.153 www 592: my $importmode=&Apache::lonxml::get_param('importmode',$parstack,$safeeval);
1.154 www 593: if (($importmode eq 'problem') || ($importmode eq 'part')) {
594: # We are using import to import published problems
595: if (($importmode eq 'problem') || ($file=~/<part[^<]*>/s)) {
596: # We explicitly don't want this to be a separate part or the problem already has parts
597: $file=~s/^\s*<problem>/<library>/s;
598: $file=~s/<\/problem>\s*$/<\/library>/s;
599: } else {
600: # We want this to be a separate part, but it currently is not
1.155 www 601: $file=~s/^\s*<problem>/<library><part>/s;
1.154 www 602: $file=~s/<\/problem>\s*$/<\/part><\/library>/s;
603: }
1.153 www 604: }
1.46 albertel 605: my $dir=$location;
606: $dir=~s:/[^/]*$::;
607: # &Apache::lonxml::debug("directory $dir $location file $file \n<b>END</b>\n");
1.142 albertel 608: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
1.57 albertel 609: if (!$id) { $id=$Apache::lonxml::curdepth; }
610: push(@Apache::inputtags::import,$id);
1.90 albertel 611: push(@Apache::inputtags::importlist,$id);
1.87 sakharuk 612:
1.144 albertel 613: &Apache::lonxml::newparser($parser,\$file,$dir);
1.87 sakharuk 614:
1.56 albertel 615: } elsif ($target eq "edit" ) {
1.46 albertel 616: $result.=&Apache::edit::tag_start($target,$token);
1.153 www 617: my $location=$token->[1];
618: $location=~s/^\s*//s;
619: $location=~s/\s*$//s;
620: $result.=&Apache::edit::editline($location,$bodytext,'',40);
1.83 matthew 621: $result.=&Apache::edit::browse(undef,'textnode');
1.154 www 622: $result.= ' <label>'.&mt('Import as:').
1.153 www 623: '<select name="importmode_'.$Apache::lonxml::curdepth.'">';
1.154 www 624: my %options=&Apache::lonlocal::texthash('' => 'as standard library',
625: 'problem' => 'as problem',
626: 'part' => 'as problem part(s)');
627: foreach my $option (sort(keys(%options))) {
1.153 www 628: $result.='<option value="'.$option.'"';
629: if ($option eq &Apache::lonxml::get_param('importmode',$parstack,$safeeval)) {
630: $result.=' selected="selected"';
631: }
1.154 www 632: $result.='>'.$options{$option}.'</option>';
1.153 www 633: }
634: $result.='</select></label>';
1.46 albertel 635: #FIXME this need to convert $bodytext to be a contruction space reference
636: #my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
637: #$result.="Click<a href=\"$location\">here</a> to edit<br />"
1.56 albertel 638: } elsif ($target eq 'modified') {
1.153 www 639: &Apache::edit::get_new_args($token,$parstack,$safeeval,'importmode');
640: $result='<import id="'.$token->[2]{'id'}.'" importmode="'.$token->[2]{'importmode'}.'">';
641: $result.=&Apache::edit::modifiedfield("/import",$parser);
1.56 albertel 642: } elsif ($target eq 'meta') {
1.142 albertel 643: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
1.57 albertel 644: $result.='<import part="'.$Apache::inputtags::part;
645: if ($id) {
646: $result.='" id="'.$id;
647: }
1.156 www 648: $result.='" importmode="'.$token->[2]{'importmode'}.'">';
1.56 albertel 649: $result.=$bodytext;
650: $result.='</import>';
1.46 albertel 651: }
652: return $result;
1.6 albertel 653: }
654:
655: sub end_import {
1.69 albertel 656: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.57 albertel 657: pop(@Apache::inputtags::import);
1.69 albertel 658: my $result;
1.120 albertel 659: if ($target eq 'edit' ) { $result=&Apache::edit::end_row.
660: &Apache::edit::end_table(); }
1.69 albertel 661: return $result;
1.1 albertel 662: }
1.42 sakharuk 663:
664: sub start_storetc {
1.43 albertel 665: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42 sakharuk 666: my $result = '';
667: &Apache::lonxml::startredirection;
668: return $result;
669: }
670:
671: sub end_storetc {
1.43 albertel 672: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.42 sakharuk 673: my $result;
674: my $output=&Apache::lonxml::endredirection;
675: $output =~ s/\"/\"\;/g;
1.52 albertel 676: $result = '{\bf '.$output.'.}}\write\tcfile{\protect\tcpc{ '.$output.'.}{\the\value{relpage}}}';
677: return $result;
1.42 sakharuk 678: }
679:
680:
681: sub start_physnet {
1.45 sakharuk 682: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.172.2.1 raeburn 683: my $bodytext = '/res/adm/includes/physnet.sty';
1.45 sakharuk 684: my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],$bodytext);
685: my $cbistyletext=&Apache::lonnet::getfile($location);
1.42 sakharuk 686:
1.45 sakharuk 687: %$style = (%$style,&Apache::style::styleparser($target,$cbistyletext));
1.172.2.1 raeburn 688: if (keys(%$style) && (($target eq 'web') || ($target eq 'tex'))) {
689: $$parser['-1']->unget_token($token);
690: }
1.59 albertel 691: # if ( defined($$style{'physnet'}) ) {
692: # &Apache::lonxml::newparser($parser,\$$style{'physnet'});
693: # }
1.45 sakharuk 694: return "";
695: }
1.42 sakharuk 696:
1.45 sakharuk 697: sub end_physnet {
1.47 albertel 698: return '';
1.42 sakharuk 699: }
1.62 albertel 700:
701: sub start_standalone {
702: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.75 albertel 703: my $result='';
1.137 albertel 704: if ($target eq 'web' || $target eq 'webgrade') {
1.126 albertel 705: if ( $env{'request.course.id'} ) {
1.133 albertel 706: my $inside = &Apache::lonxml::get_all_text("/standalone",$parser,$style);
1.75 albertel 707: } else {
708: $result='<table bgcolor="#E1E1E1" border="2"><tr><td>';
709: }
1.62 albertel 710: }
1.75 albertel 711: return $result;
1.62 albertel 712: }
713:
714: sub end_standalone {
1.75 albertel 715: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
716: my $result='';
1.137 albertel 717: if ($target eq 'web' || $target eq 'webgrade' ) {
1.126 albertel 718: if ( $env{'request.course.id'} ) {
1.75 albertel 719: } else {
720: $result='</td></tr></table>';
721: }
722: }
723: return $result;
1.74 albertel 724: }
725:
726: sub start_comment {
727: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
728: my $result='';
729: if ($target eq 'edit') {
730: $result=&Apache::edit::tag_start($target,$token);
1.133 albertel 731: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
1.77 albertel 732: $result.=&Apache::edit::editfield($token->[1],$bodytext,'',80,4)
1.74 albertel 733: } elsif ( $target eq 'modified') {
1.103 albertel 734: $result=$token->[4].&Apache::edit::modifiedfield("/comment",$parser);
1.137 albertel 735: } elsif ( $target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
736: $target eq 'answer' || $target eq 'meta' || $target eq 'analyze' ||
737: $target eq 'webgrade') {
1.74 albertel 738: #normally throw away comments
1.133 albertel 739: my $bodytext=&Apache::lonxml::get_all_text("/comment",$parser,$style);
1.74 albertel 740: }
741: return $result;
742: }
743:
744: sub end_comment {
745: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
746: if ($target eq 'edit' ) { return &Apache::edit::end_table(); }
1.62 albertel 747: return '';
748: }
749:
1.42 sakharuk 750:
1.47 albertel 751: sub xmlparse {
752: my ($string) = @_;
1.111 albertel 753: &Apache::lonxml::debug("xmlparse recursion starting with $string");
1.113 albertel 754: # Apache::run::evaluate does an 'eval' on the name of the subroutine
755: # if it detects something that looks like a subroutine, this ends up calling
756: # things without any arguments and since perl is nice enough to pass
757: # along the default arguments when you don't explicitly say no arguments
758: # if you call &xmlparse, it gets &xmlparse passed as it argument.
759: # Same thing soccurs with &chemparse.
1.111 albertel 760: if ($string eq '&xmlparse') { return '&xmlparse'; }
1.113 albertel 761: if ($string eq '&chemparse') { return '&chemparse'; }
1.47 albertel 762: my ($target,$token,$tagstack,$parstack,$oldparser,$safeeval,$style)=
763: @Apache::scripttag::parser_env;
764: my @parser;
765: &Apache::lonxml::newparser(\@parser,\$string);
1.132 albertel 766: &Apache::lonxml::startredirection();
1.47 albertel 767: my $result=&Apache::lonxml::inner_xmlparse($target,$tagstack,
768: $parstack,\@parser,
769: $safeeval,$style);
1.132 albertel 770: $result.=&Apache::lonxml::endredirection();
1.122 albertel 771: &Apache::lonxml::debug("target is $target xmlparse recursion ending with $result");
1.47 albertel 772: return $result;
773: }
1.3 albertel 774:
1.122 albertel 775: sub start_num {
776: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
777: my $result = '';
778: my $inside = &Apache::lonxml::get_all_text_unbalanced("/num",$parser);
1.137 albertel 779: if ($target eq 'tex' || $target eq 'web' || $target eq 'webgrade') {
1.122 albertel 780: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
781: if (!$Apache::lonxml::default_homework_loaded) {
782: &Apache::lonxml::default_homework_load($safeeval);
783: }
784: @Apache::scripttag::parser_env = @_;
785: my $format=&Apache::lonxml::get_param('format',$parstack,$safeeval);
786: $result=&Apache::run::run("return &prettyprint(q\0$inside\0,q\0$format\0);",$safeeval);
787: }
788: return $result;
789: }
790:
791: sub end_num {
792: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
793: my $result = '';
794: return $result;
795: }
796:
797: sub start_parse {
798: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
799: my $result = '';
1.137 albertel 800: if ( $target eq 'web' || $target eq 'tex' ||
801: $target eq 'grade' || $target eq 'answer' ||
802: $target eq 'analyze'|| $target eq 'webgrade') {
1.122 albertel 803: my $inside = &Apache::lonxml::get_all_text_unbalanced("/parse",$parser);
804: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
805: if (!$Apache::lonxml::default_homework_loaded) {
806: &Apache::lonxml::default_homework_load($safeeval);
807: }
808: @Apache::scripttag::parser_env = @_;
809: $result=&Apache::run::run("return &xmlparse(q\0$inside\0);",$safeeval);
1.134 albertel 810: if ($target eq 'grade' || $target eq 'answer' ||
811: $target eq 'analyze') {
812: # grade/answer/analyxe should produce no output but if we
813: # are redirecting, the redirecter should know what to do
814: # with the output
815: if (!$Apache::lonxml::redirection) { $result=''; }
816: }
1.122 albertel 817: }
818: return $result;
819: }
820:
821: sub end_parse {
822: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
823: my $result = '';
824: return $result;
825: }
1.123 albertel 826:
827: sub start_algebra {
828: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
829: my $result = '';
1.137 albertel 830: if ( $target eq 'web' || $target eq 'tex' ||
831: $target eq 'grade' || $target eq 'answer' ||
832: $target eq 'analyze' || $target eq 'webgrade') {
1.123 albertel 833: my $inside = &Apache::lonxml::get_all_text_unbalanced("/algebra",$parser);
834: $inside = &Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
835: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.125 albertel 836: my $style=&Apache::lonxml::get_param('style',$parstack,$safeeval);
1.157 raeburn 837: $result=&Apache::lontexconvert::algebra($inside,$target,$style,$parstack,$safeeval);
1.123 albertel 838: }
839: $Apache::lonxml::post_evaluate=0;
840: }
841: return $result;
842: }
843:
844: sub end_algebra {
845: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
846: my $result = '';
847: return $result;
848: }
849:
1.1 albertel 850: 1;
851: __END__
1.149 jms 852:
853: =pod
854:
855: =head1 NAME
856:
857: Apache::scripttag.pm
858:
859: =head1 SYNOPSIS
860:
861: implements <script>, <scriptlib>, <parserlib>,
862: and <import>
863:
864: This is part of the LearningOnline Network with CAPA project
865: described at http://www.lon-capa.org.
866:
867: =cut
868:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>