--- loncom/interface/lonmeta.pm 2001/12/22 21:59:07 1.9 +++ loncom/interface/lonmeta.pm 2004/05/07 17:17:58 1.77 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Metadata display handler # -# $Id: lonmeta.pm,v 1.9 2001/12/22 21:59:07 www Exp $ +# $Id: lonmeta.pm,v 1.77 2004/05/07 17:17:58 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -24,130 +24,851 @@ # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ -# -# (TeX Content Handler -# -# 05/29/00,05/30,10/11 Gerd Kortemeyer) -# -# 10/19,10/21,10/23,11/27,08/09/01,12/22 Gerd Kortemeyer + package Apache::lonmeta; use strict; +use LONCAPA::lonmetadata(); use Apache::Constants qw(:common); use Apache::lonnet(); +use Apache::loncommon(); +use Apache::lonhtmlcommon(); +use Apache::lonmsg; +use Apache::lonpublisher; +use Apache::lonlocal; +use Apache::lonmysql; +use Apache::lonmsg; -# ----------------------------------------- Fetch and evaluate dynamic metadata +# Fetch and evaluate dynamic metadata sub dynamicmeta { my $url=&Apache::lonnet::declutter(shift); $url=~s/\.meta$//; my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//); - my $regexp=&Apache::lonnet::escape($url); + my $regexp=$url; $regexp=~s/(\W)/\\$1/g; - my %evaldata=&Apache::lonnet::dump - ('resevaldata',$adomain,$aauthor,$regexp); - my %returnhash=(); - foreach (keys %evaldata) { + $regexp='___'.$regexp.'___'; + my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain, + $aauthor,$regexp); + my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata); + my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url, + \%DynamicData); + # + # Deal with 'count' separately + $Data{'count'} = &access_count($url,$aauthor,$adomain); + # + # Debugging code I will probably need later + if (0) { + &Apache::lonnet::logthis('Dynamic Metadata'); + while(my($k,$v)=each(%Data)){ + &Apache::lonnet::logthis(' "'.$k.'"=>"'.$v.'"'); + } + &Apache::lonnet::logthis('-------------------'); } - return %returnhash; + return %Data; } -# ================================================================ Main Handler +sub access_count { + my ($src,$author,$adomain) = @_; + my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain, + $author,$src); + if (! exists($countdata{$src})) { + return &mt('Not Available'); + } else { + return $countdata{$src}; + } +} -sub handler { - my $r=shift; - my %content=(); +# Try to make an alt tag if there is none +sub alttag { + my ($base,$src)=@_; + my $fullpath=&Apache::lonnet::hreflocation($base,$src); + my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '. + &Apache::lonnet::metadata($fullpath,'subject').' '. + &Apache::lonnet::metadata($fullpath,'abstract'); + $alttag=~s/\s+/ /gs; + $alttag=~s/\"//gs; + $alttag=~s/\'//gs; + $alttag=~s/\s+$//gs; + $alttag=~s/^\s+//gs; + if ($alttag) { + return $alttag; + } else { + return &mt('No information available'); + } +} -# ----------------------------------------------------------- Set document type +# Author display +sub authordisplay { + my ($aname,$adom)=@_; + return &Apache::loncommon::aboutmewrapper + (&Apache::loncommon::plainname($aname,$adom), + $aname,$adom,'preview').' ['.$aname.'@'.$adom.']'; +} - $r->content_type('text/html'); - $r->send_http_header; +# Pretty display +sub evalgraph { + my $value=shift; + if (! $value) { + return ''; + } + my $val=int($value*10.+0.5)-10; + my $output='
  | '; + } else { + $output.=''. + ' | '; + } + $output.=' | '; + if ($val>20) { + $output.=' | '. + ' | '; + } else { + $output.=' |   | '; + } + $output.='('.sprintf("%5.2f",$value).') |
$content{'abstract'}-