Diff for /loncom/homework/randomlabel.pm between versions 1.96 and 1.98

version 1.96, 2011/11/14 02:17:47 version 1.98, 2025/01/26 16:29:03
Line 110  use Apache::File(); Line 110  use Apache::File();
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
 use Image::Magick;  use Image::Magick;
 use Apache::lonplot;  use Apache::lonplot;
   use Apache::lonlocal;
   use Apache::lonmeta;
 use LONCAPA;  use LONCAPA;
     
   
Line 162  sub extract_tag_sizes { Line 164  sub extract_tag_sizes {
   
 }  }
   
 my ($height_param,$width_param);  my ($height_param,$width_param,$alt_param);
 sub start_randomlabel {  sub start_randomlabel {
   
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result='';      my $result='';
     push (@Apache::lonxml::namespace,'randomlabel');      push (@Apache::lonxml::namespace,'randomlabel');
     ($height_param,$width_param)=(0,0);      ($height_param,$width_param)=(0,0);
       $alt_param = '';
     $label_xscale = 1.0; # Assume image size not overridden.      $label_xscale = 1.0; # Assume image size not overridden.
     $label_yscale = 1.0;      $label_yscale = 1.0;
     my $bgimg= &Apache::lonxml::get_param('bgimg',$parstack,$safeeval);      my $bgimg= &Apache::lonxml::get_param('bgimg',$parstack,$safeeval);
Line 185  sub start_randomlabel { Line 188  sub start_randomlabel {
  $args{"cgi.$cgi_id.BGIMG"}=&escape($bgimg);   $args{"cgi.$cgi_id.BGIMG"}=&escape($bgimg);
  $height_param = &Apache::lonxml::get_param('height',$parstack, $safeeval);   $height_param = &Apache::lonxml::get_param('height',$parstack, $safeeval);
  $width_param  = &Apache::lonxml::get_param('width', $parstack, $safeeval);   $width_param  = &Apache::lonxml::get_param('width', $parstack, $safeeval);
           $alt_param    = &Apache::lonxml::get_param('alt',   $parstack, $safeeval);
           if ($alt_param eq '') {
               unless (($bgimg =~ m{^data\:image/gif;base64,}) || ($bgimg =~ /^https?\:/) ||
                       ($bgimg eq $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonKaputt/lonlogo_broken.gif')) {
                   $alt_param = &Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$bgimg);
               }
           }
     } elsif ($target eq 'tex' && defined($bgimg)) {      } elsif ($target eq 'tex' && defined($bgimg)) {
  $result.=&make_eps_image($bgimg,$parstack,$safeeval);   $result.=&make_eps_image($bgimg,$parstack,$safeeval);
     } elsif ($target eq 'edit') {      } elsif ($target eq 'edit') {
Line 193  sub start_randomlabel { Line 203  sub start_randomlabel {
  $Apache::edit::bgimgsrc=   $Apache::edit::bgimgsrc=
     &Apache::lonxml::get_param('bgimg',$parstack,$safeeval);      &Apache::lonxml::get_param('bgimg',$parstack,$safeeval);
  $Apache::edit::bgimgsrccurdepth=$Apache::lonxml::curdepth;   $Apache::edit::bgimgsrccurdepth=$Apache::lonxml::curdepth;
  $result.=&Apache::edit::text_arg('Image:','bgimg',$token,75).' ';   $result.=&Apache::edit::text_arg('Image:','bgimg',$token,75).' '.
  $result.=&Apache::edit::browse('bgimg',undef,undef,$only).' ';           &Apache::edit::browse_or_search('bgimg',undef,undef,$only,undef,1).
  $result.=&Apache::edit::search('bgimg').'<br />'.           '<br />'.
               &Apache::edit::text_arg('Description:'  ,'alt'     ,$token,40).'<br />'.
     &Apache::edit::text_arg('Width(pixel):' ,'width'   ,$token,6).      &Apache::edit::text_arg('Width(pixel):' ,'width'   ,$token,6).
     &Apache::edit::text_arg('Height(pixel):','height'  ,$token,6).      &Apache::edit::text_arg('Height(pixel):','height'  ,$token,6).
     &Apache::edit::text_arg('TeXWidth(mm):' ,'texwidth',$token,6).      &Apache::edit::text_arg('TeXWidth(mm):' ,'texwidth',$token,6).
Line 203  sub start_randomlabel { Line 214  sub start_randomlabel {
     } elsif ($target eq 'modified') {      } elsif ($target eq 'modified') {
  my $constructtag=&Apache::edit::get_new_args($token,$parstack,   my $constructtag=&Apache::edit::get_new_args($token,$parstack,
      $safeeval,'bgimg','width',       $safeeval,'bgimg','width',
      'height','texwidth');       'height','texwidth','alt');
  if ($constructtag) {   if ($constructtag) {
     $result = &Apache::edit::rebuild_tag($token);      $result = &Apache::edit::rebuild_tag($token);
  }   }
Line 217  sub end_randomlabel { Line 228  sub end_randomlabel {
     my $count;      my $count;
     pop @Apache::lonxml::namespace;      pop @Apache::lonxml::namespace;
     if ($target eq 'web') {      if ($target eq 'web') {
           my $alttext;
           if ($alt_param eq '') {
               $alttext = &mt('labeled image');
           } else {
               $alttext = $alt_param;
           }
           $alttext = &HTML::Entities::encode($alttext,'<>&"');
  $count = $Apache::randomlabel::obj_cnt;   $count = $Apache::randomlabel::obj_cnt;
  if( $count != 0) { $args{"cgi.$cgi_id.OBJCOUNT"}=$count; }   if( $count != 0) { $args{"cgi.$cgi_id.OBJCOUNT"}=$count; }
  $result.='<img src="/adm/randomlabel.png?token='.$cgi_id.'" /><br />'."\n";   $result.='<img src="/adm/randomlabel.png?token='.$cgi_id.'" alt="'.$alttext.'" /><br />'."\n";
  &Apache::lonnet::appenv(\%args);   &Apache::lonnet::appenv(\%args);
     } elsif ($target eq 'tex') {      } elsif ($target eq 'tex') {
  $result='\end{picture}\\\\';   $result='\end{picture}\\\\';

Removed from v.1.96  
changed lines
  Added in v.1.98


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