Annotation of loncom/interface/lonrss.pm, revision 1.1

1.1     ! www         1: # The LearningOnline Network
        !             2: # RSS Feeder
        !             3: #
        !             4: # $Id: lonsyllabus.pm,v 1.41 2005/06/06 02:29:46 albertel Exp $
        !             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: #
        !            28: 
        !            29: package Apache::lonrss;
        !            30: 
        !            31: use strict;
        !            32: use Apache::Constants qw(:common);
        !            33: use Apache::loncommon;
        !            34: use Apache::lonnet;
        !            35: use Apache::lontexconvert;
        !            36: use Apache::lonfeedback;
        !            37: use Apache::lonannounce;
        !            38: use Apache::lonlocal;
        !            39: use Apache::lonhtmlcommon;
        !            40: use Apache::lonspeller();
        !            41: 
        !            42: my $feedcounter=0;
        !            43: 
        !            44: sub filterfeedname {
        !            45:     my $filename=shift;
        !            46:     $filename=~s/\.rss$//;
        !            47:     $filename=~s/\W//g;
        !            48:     return $filename;
        !            49: }
        !            50: 
        !            51: sub feedname {
        !            52:     return 'nohist_'.&filterfeedname(shift).'_rssfeed';
        !            53: }
        !            54: 
        !            55: sub displayfeedname {
        !            56:     my $filename=&filterfeedname(shift);
        !            57:     $filename=~s/\_/ /g;
        !            58:     return $filename;
        !            59: }
        !            60: 
        !            61: sub addentry {
        !            62:     my ($uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enclength,$enctype)=@_;
        !            63:     my $feedname=&feedname($filename);
        !            64:     $feedcounter++;
        !            65:     my $id=time.'00000'.$$.'00000'.$feedcounter;
        !            66:     return &Apache::lonnet::put($feedname,{
        !            67: 	$id.'_title' => $title,
        !            68: 	$id.'_description' => $description,
        !            69: 	$id.'_link' => $url,
        !            70: 	$id.'_enclosureurl' => $encurl,
        !            71: 	$id.'_enclosurelength' => $enclength,
        !            72: 	$id.'_enclosuretype' => $enctype,
        !            73: 	$id.'_status' => $status},$udom,$uname);
        !            74: }
        !            75: 
        !            76: sub handler {
        !            77:     my $r = shift;
        !            78:     &Apache::loncommon::content_type($r,'text/xml');
        !            79:     $r->send_http_header;
        !            80:     return OK if $r->header_only;
        !            81: 
        !            82:     my (undef,undef,$udom,$uname,$filename)=split(/\//,$r->uri);
        !            83:     my $filterfeedname=&filterfeedname($filename);
        !            84:     my $feedname=&feedname($filename);
        !            85:     my $displayfeedname=&displayfeedname($filename);
        !            86:     $r->print("<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1'>\n<channel>".
        !            87: 	      "\n<link>http://".$ENV{'HTTP_HOST'}.'/</link>'.
        !            88: 	      "\n<description>".&mt('An RSS Feed provided by the LON-CAPA Learning Content Management System').'</description>');
        !            89: # Is this user for real?
        !            90:     my $homeserver=&Apache::lonnet::homeserver($uname,$udom); 
        !            91:     if ($homeserver eq 'no_host') {
        !            92: 	$r->print('<title>'.&mt('No feed available').'</title>');
        !            93:     } else {
        !            94: # Course or user?
        !            95: 	my $name='';
        !            96: 	if ($uname=~/^\d/) {
        !            97: 	    my %cenv=&Apache::lonnet::dump('environment',$udom,$uname);
        !            98: 	    $name=$cenv{'description'};
        !            99: 	} else {
        !           100: 	    $name=&Apache::loncommon::nickname($uname,$udom);
        !           101: 	}
        !           102:         $r->print("\n<title>".&mt('LON-CAPA RSS Feed "[_1]" for [_2]',$displayfeedname,$name).'</title>');
        !           103: # Render private items?
        !           104:         my $viewpubliconly=1;
        !           105:         if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
        !           106: 	    $viewpubliconly=0;
        !           107: 	}
        !           108: # Get feed items
        !           109:         my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
        !           110: 	foreach (sort keys %newsfeed) {
        !           111: 	    if ($_=~/^(\d+)\_status$/) {
        !           112: 		my $id=$1;
        !           113: 		if (($newsfeed{$id.'_status'} ne 'public') && ($viewpubliconly)) { next; }
        !           114: 		$r->print("\n<item>\n<title>".$newsfeed{$id.'_title'}."</title>\n<description>".
        !           115: 			  $newsfeed{$id.'_description'}."</description>\n<link>".
        !           116: 			  $newsfeed{$id.'_link'}."</link>\n");
        !           117: 		if ($newsfeed{$id.'_enclosureurl'}) {
        !           118: 		    $r->print("\n<enclosure url='".$newsfeed{$id.'_enclosureurl'}."' length='".$newsfeed{$id.'_enclosurelength'}.
        !           119: 			      "' type='".$newsfeed{$id.'_enclosuretype'}."' />");
        !           120: 		}
        !           121: 		$r->print("\n<guid>".$id.$filterfeedname.'_'.$udom.'_'.$uname."</guid></item>\n");
        !           122: 	    }
        !           123: 	}
        !           124:     }
        !           125:     $r->print("\n</channel></rss>\n");
        !           126:     return OK;
        !           127: } 
        !           128: 
        !           129: 1;
        !           130: __END__

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