Diff for /loncom/xml/lonxml.pm between versions 1.155 and 1.161

version 1.155, 2002/03/06 20:28:19 version 1.161, 2002/03/22 17:52:20
Line 62  package Apache::lonxml; Line 62  package Apache::lonxml;
 use vars   use vars 
 qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace);  qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace);
 use strict;  use strict;
 use HTML::TokeParser;  use HTML::TokeParser();
 use HTML::TreeBuilder;  use HTML::TreeBuilder();
 use Safe;  use HTML::Entities();
 use Safe::Hole;  use Safe();
 use Math::Cephes qw(:trigs :hypers :bessels erf erfc);  use Safe::Hole();
 use Math::Random qw(:all);  use Math::Cephes();
 use Opcode;  use Math::Random();
   use Opcode();
   
 sub register {  sub register {
   my ($space,@taglist) = @_;    my ($space,@taglist) = @_;
Line 89  sub deregister { Line 90  sub deregister {
 }  }
   
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::lontexconvert;  use Apache::lontexconvert();
 use Apache::style;  use Apache::style();
 use Apache::run;  use Apache::run();
 use Apache::londefdef;  use Apache::londefdef();
 use Apache::scripttag;  use Apache::scripttag();
 use Apache::edit;  use Apache::edit();
 use Apache::lonnet;  use Apache::lonnet();
 use Apache::File;  use Apache::File();
 use Apache::loncommon;  use Apache::loncommon();
   
 #==================================================   Main subroutine: xmlparse    #==================================================   Main subroutine: xmlparse  
 #debugging control, to turn on debugging modify the correct handler  #debugging control, to turn on debugging modify the correct handler
Line 318  sub registerurl { Line 319  sub registerurl {
     my $forcereg=shift;      my $forcereg=shift;
     my $target = shift;      my $target = shift;
     my $result = '';      my $result = '';
     if ($ENV{'request.publicaccess'}) {      if (($ENV{'request.publicaccess'}) || 
          ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html')) {
  return    return 
          '<script>function LONCAPAreg(){} function LONCAPAstale(){}</script>';           '<script>function LONCAPAreg(){} function LONCAPAstale(){}</script>';
     }      }
     if ($Apache::lonxml::registered && !$forcereg) { return ''; }      if ($Apache::lonxml::registered && !$forcereg) { return ''; }
     $Apache::lonxml::registered=1;      $Apache::lonxml::registered=1;
       my $nothing='';
       if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
     if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {      if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
         my $hwkadd='';          my $hwkadd='';
         if ($ENV{'REQUEST_URI'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {          if ($ENV{'REQUEST_URI'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
Line 355  ENDPARM Line 359  ENDPARM
 // BEGIN LON-CAPA Internal  // BEGIN LON-CAPA Internal
   
     function LONCAPAreg() {      function LONCAPAreg() {
   menu=window.open("","LONCAPAmenu");    menu=window.open("$nothing","LONCAPAmenu","",false);
           menu.clearTimeout(menu.menucltim);            menu.clearTimeout(menu.menucltim);
   menu.currentURL=window.location.pathname;    menu.currentURL=window.location.pathname;
           menu.currentStale=0;            menu.currentStale=0;
Line 382  ENDPARM Line 386  ENDPARM
     }      }
   
     function LONCAPAstale() {      function LONCAPAstale() {
   menu=window.open("","LONCAPAmenu");    menu=window.open("$nothing","LONCAPAmenu","",false);
           menu.currentStale=1;            menu.currentStale=1;
           menu.switchbutton            menu.switchbutton
              (3,1,'reload.gif','return','location','go(currentURL)');               (3,1,'reload.gif','return','location','go(currentURL)');
Line 407  ENDREGTHIS Line 411  ENDREGTHIS
 // BEGIN LON-CAPA Internal  // BEGIN LON-CAPA Internal
   
     function LONCAPAreg() {      function LONCAPAreg() {
   menu=window.open("","LONCAPAmenu");    menu=window.open("$nothing","LONCAPAmenu","",false);
           menu.currentStale=1;            menu.currentStale=1;
           menu.clearbut(2,1);            menu.clearbut(2,1);
           menu.clearbut(2,3);            menu.clearbut(2,3);
Line 430  ENDREGTHIS Line 434  ENDREGTHIS
 ENDDONOTREGTHIS  ENDDONOTREGTHIS
     }      }
     if ($target eq 'edit') {      if ($target eq 'edit') {
    # Javascript routines for construction space:
    # openbrowser and opensearcher will start the file browser
    # (lonindexer) and searcher (lonsearchcat) respectively.
    # Inputs are the name of the html form being used
    # and the name of the element the selected URL should
    # be placed in.
         $result .=<<"ENDBROWSERSCRIPT";          $result .=<<"ENDBROWSERSCRIPT";
 <script>  <script>
     var editform;      var editbrowser;
     function openbrowser(formname,elementname) {      function openbrowser(formname,elementname) {
         var url = '/res/?';          var url = '/res/?';
         if (editform == null) {          if (editbrowser == null) {
             url += 'launch=1&';              url += 'launch=1&';
         }          }
         url += 'catalogmode=interactive&';          url += 'catalogmode=interactive&';
Line 445  ENDDONOTREGTHIS Line 455  ENDDONOTREGTHIS
         var title = 'Browser';          var title = 'Browser';
         var options = 'scrollbars=1,resizable=1,menubar=0';          var options = 'scrollbars=1,resizable=1,menubar=0';
         options += ',width=700,height=600';          options += ',width=700,height=600';
         editform = open(url,title,options,'1');          editbrowser = open(url,title,options,'1');
         editform.focus();          editbrowser.focus();
       }
       var editsearcher;
       function opensearcher(formname,elementname) {
           var url = '/adm/searchcat?';
           if (editsearcher == null) {
               url += 'launch=1&';
           }
           url += 'catalogmode=interactive&';
           url += 'mode=edit&';
           url += 'form=' + formname + '&';
           url += 'element=' + elementname + '';
           var title = 'Search';
           var options = 'scrollbars=1,resizable=1,menubar=0';
           options += ',width=700,height=600';
           editsearcher = open(url,title,options,'1');
           editsearcher.focus();
     }      }
 </script>  </script>
 ENDBROWSERSCRIPT  ENDBROWSERSCRIPT
Line 509  sub htmlclean { Line 535  sub htmlclean {
   
     my $output= $tree->as_HTML(undef,' ');      my $output= $tree->as_HTML(undef,' ');
   
     $output=~s/\<(br|hr|img|meta|allow)([^\>\/]*)\>/\<$1$2 \/\>/gis;      $output=~s/\<(br|hr|img|meta|allow)(.*?)\>/\<$1$2 \/\>/gis;
     $output=~s/\<\/(br|hr|img|meta|allow)\>//gis;      $output=~s/\<\/(br|hr|img|meta|allow)\>//gis;
     unless ($full) {      unless ($full) {
        $output=~s/\<[\/]*(body|head|html)\>//gis;         $output=~s/\<[\/]*(body|head|html)\>//gis;
Line 1065  SIMPLECONTENT Line 1091  SIMPLECONTENT
   
 sub inserteditinfo {  sub inserteditinfo {
       my ($result,$filecontents)=@_;        my ($result,$filecontents)=@_;
       $filecontents =~ s:</textarea>:&lt;/textarea&gt;:ig;        $filecontents = &HTML::Entities::encode($filecontents);
 #      my $editheader='<a href="#editsection">Edit below</a><hr />';  #      my $editheader='<a href="#editsection">Edit below</a><hr />';
         my $buttons=(<<BUTTONS);
   <input type="submit" name="attemptclean" 
          value="Save and then attempt to clean HTML" />
   <input type="submit" name="savethisfile" value="Save this" />
   <input type="submit" name="viewmode" value="View" />
   BUTTONS
       my $editfooter=(<<ENDFOOTER);        my $editfooter=(<<ENDFOOTER);
 <hr />  <hr />
 <a name="editsection" />  <a name="editsection" />
 <form method="post">  <form method="post">
   <input type="hidden" name="editmode" value="Edit" />
   $buttons
 <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>  <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>
   $buttons
 <br />  <br />
 <input type="hidden" name="showmode" value="Edit" />  
 <input type="submit" name="attemptclean"   
        value="Save and then attempt to clean HTML" />  
 <input type="submit" name="savethisfile" value="Save this" />  
 <input type="submit" name="showmode" value="View" />  
 </form>  </form>
 ENDFOOTER  ENDFOOTER
 #      $result=~s/(\<body[^\>]*\>)/$1$editheader/is;  #      $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
Line 1156  ENDNOTFOUND Line 1186  ENDNOTFOUND
     $filecontents='';      $filecontents='';
     if ($ENV{'request.state'} ne 'published') {      if ($ENV{'request.state'} ne 'published') {
       $filecontents=&createnewhtml();        $filecontents=&createnewhtml();
       $ENV{'form.showmode'}='Edit'; #force edit mode        $ENV{'form.editmode'}='Edit'; #force edit mode
     }      }
   } else {    } else {
     unless ($ENV{'request.state'} eq 'published') {      unless ($ENV{'request.state'} eq 'published') {
Line 1164  ENDNOTFOUND Line 1194  ENDNOTFOUND
  $filecontents=&htmlclean($filecontents,1);   $filecontents=&htmlclean($filecontents,1);
       }        }
     }      }
     if ($ENV{'form.showmode'} ne 'Edit') {      if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) {
       $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);        $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
     }      }
   }    }
Line 1173  ENDNOTFOUND Line 1203  ENDNOTFOUND
 # Edit action? Insert editing commands  # Edit action? Insert editing commands
 #  #
   unless ($ENV{'request.state'} eq 'published') {    unless ($ENV{'request.state'} eq 'published') {
     if ($ENV{'form.showmode'} eq 'Edit') {      if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
       $result='<html><body bgcolor="#FFFFFF"></body></html>';        $result='<html><body bgcolor="#FFFFFF"></body></html>';
       $result=&inserteditinfo($result,$filecontents);        $result=&inserteditinfo($result,$filecontents);
     }      }
Line 1228  sub get_param { Line 1258  sub get_param {
   if ( ! $context ) { $context = -1; }    if ( ! $context ) { $context = -1; }
   my $args ='';    my $args ='';
   if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }    if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
     if ( ! $args ) { return undef; }
   if ( $args =~ /my \$$param=\"/ ) {    if ( $args =~ /my \$$param=\"/ ) {
     return &Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'      return &Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
   } else {    } else {

Removed from v.1.155  
changed lines
  Added in v.1.161


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>