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