# The LearningOnline Network
# RSS Feeder
#
# $Id: lonrss.pm,v 1.4 2005/11/18 19:32:05 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::lonrss;
use strict;
use Apache::Constants qw(:common);
use Apache::loncommon;
use Apache::lonnet;
use Apache::lontexconvert;
use Apache::lonlocal;
use Apache::lonhtmlcommon;
sub filterfeedname {
my $filename=shift;
$filename=~s/\.rss$//;
$filename=~s/\W//g;
return $filename;
}
sub feedname {
return 'nohist_'.&filterfeedname(shift).'_rssfeed';
}
sub displayfeedname {
my ($rawname,$uname,$udom)=@_;
my $filterfilename=&filterfeedname($rawname);
# do we have a stored name?
my %stored=&Apache::lonnet::get('nohist_all_rss_feeds',[$filterfilename],$udom,$uname);
if ($stored{$filterfilename}) { return $stored{$filterfilename}; }
# no, construct a name
my $name=$filterfilename;
if ($name=~/^CourseBlog/) {
$name=&mt('Course Blog');
if ($env{'course.'.$env{'request.course.id'}.'.description'}) {
$name.=' '.$env{'course.'.$env{'request.course.id'}.'.description'};
}
} else {
$name=~s/\_/ /g;
}
return $name;
}
sub renamefeed {
my ($rawname,$uname,$udom,$newname)=@_;
return &Apache::lonnet::put('nohist_all_rss_feeds',
{ &filterfeedname($rawname) => $newname },
$udom,$uname);
}
sub advertisefeeds {
my ($uname,$udom)=@_;
my $feeds='';
my %feednames=&Apache::lonnet::dump('nohist_all_rss_feeds',$udom,$uname);
foreach my $feed (sort(keys(%feednames))) {
if ($feed!~/^error\:/) {
my $url='feed://'.$ENV{'HTTP_HOST'}.'/public/'.$udom.'/'.$uname.'/'.$feed.'.rss';
$feeds.='