--- loncom/homework/randomlabel.pm 2010/02/04 18:42:41 1.95
+++ loncom/homework/randomlabel.pm 2025/01/26 16:29:03 1.98
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# random labelling tool
#
-# $Id: randomlabel.pm,v 1.95 2010/02/04 18:42:41 raeburn Exp $
+# $Id: randomlabel.pm,v 1.98 2025/01/26 16:29:03 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -110,6 +110,8 @@ use Apache::File();
use Apache::Constants qw(:common :http);
use Image::Magick;
use Apache::lonplot;
+use Apache::lonlocal;
+use Apache::lonmeta;
use LONCAPA;
@@ -162,20 +164,21 @@ sub extract_tag_sizes {
}
-my ($height_param,$width_param);
+my ($height_param,$width_param,$alt_param);
sub start_randomlabel {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result='';
push (@Apache::lonxml::namespace,'randomlabel');
($height_param,$width_param)=(0,0);
+ $alt_param = '';
$label_xscale = 1.0; # Assume image size not overridden.
$label_yscale = 1.0;
my $bgimg= &Apache::lonxml::get_param('bgimg',$parstack,$safeeval);
if ( defined($bgimg) && $bgimg !~ /^https?\:/ ) {
$bgimg=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$bgimg);
if (&Apache::lonnet::repcopy($bgimg) ne 'ok') {
- $bgimg='/home/httpd/html/adm/lonKaputt/lonlogo_broken.gif';
+ $bgimg=$Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonKaputt/lonlogo_broken.gif';
}
}
$Apache::randomlabel::obj_cnt=0;
@@ -185,6 +188,13 @@ sub start_randomlabel {
$args{"cgi.$cgi_id.BGIMG"}=&escape($bgimg);
$height_param = &Apache::lonxml::get_param('height',$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)) {
$result.=&make_eps_image($bgimg,$parstack,$safeeval);
} elsif ($target eq 'edit') {
@@ -193,9 +203,10 @@ sub start_randomlabel {
$Apache::edit::bgimgsrc=
&Apache::lonxml::get_param('bgimg',$parstack,$safeeval);
$Apache::edit::bgimgsrccurdepth=$Apache::lonxml::curdepth;
- $result.=&Apache::edit::text_arg('Image:','bgimg',$token,75).' ';
- $result.=&Apache::edit::browse('bgimg',undef,undef,$only).' ';
- $result.=&Apache::edit::search('bgimg').'
'.
+ $result.=&Apache::edit::text_arg('Image:','bgimg',$token,75).' '.
+ &Apache::edit::browse_or_search('bgimg',undef,undef,$only,undef,1).
+ '
'.
+ &Apache::edit::text_arg('Description:' ,'alt' ,$token,40).'
'.
&Apache::edit::text_arg('Width(pixel):' ,'width' ,$token,6).
&Apache::edit::text_arg('Height(pixel):','height' ,$token,6).
&Apache::edit::text_arg('TeXWidth(mm):' ,'texwidth',$token,6).
@@ -203,7 +214,7 @@ sub start_randomlabel {
} elsif ($target eq 'modified') {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,
$safeeval,'bgimg','width',
- 'height','texwidth');
+ 'height','texwidth','alt');
if ($constructtag) {
$result = &Apache::edit::rebuild_tag($token);
}
@@ -217,9 +228,16 @@ sub end_randomlabel {
my $count;
pop @Apache::lonxml::namespace;
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;
if( $count != 0) { $args{"cgi.$cgi_id.OBJCOUNT"}=$count; }
- $result.='
'."\n";
+ $result.='
'."\n";
&Apache::lonnet::appenv(\%args);
} elsif ($target eq 'tex') {
$result='\end{picture}\\\\';