--- loncom/interface/lonrss.pm 2005/11/17 21:40:52 1.1
+++ loncom/interface/lonrss.pm 2005/11/20 19:37:44 1.6
@@ -1,7 +1,7 @@
# The LearningOnline Network
# RSS Feeder
#
-# $Id: lonrss.pm,v 1.1 2005/11/17 21:40:52 www Exp $
+# $Id: lonrss.pm,v 1.6 2005/11/20 19:37:44 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,17 +33,12 @@ use Apache::Constants qw(:common);
use Apache::loncommon;
use Apache::lonnet;
use Apache::lontexconvert;
-use Apache::lonfeedback;
-use Apache::lonannounce;
use Apache::lonlocal;
use Apache::lonhtmlcommon;
-use Apache::lonspeller();
-
-my $feedcounter=0;
sub filterfeedname {
my $filename=shift;
- $filename=~s/\.rss$//;
+ $filename=~s/(\_rss\.html|\.rss)$//;
$filename=~s/\W//g;
return $filename;
}
@@ -53,16 +48,70 @@ sub feedname {
}
sub displayfeedname {
- my $filename=&filterfeedname(shift);
- $filename=~s/\_/ /g;
- return $filename;
+ 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,$edit)=@_;
+ my $feeds='';
+ my %feednames=&Apache::lonnet::dump('nohist_all_rss_feeds',$udom,$uname);
+ my $mode='public';
+ if ($edit) {
+ $mode='adm';
+ }
+ foreach my $feed (sort(keys(%feednames))) {
+ if ($feed!~/^error\:/) {
+ my $feedurl='feed://'.$ENV{'HTTP_HOST'}.'/public/'.$udom.'/'.$uname.'/'.$feed.'.rss';
+ my $htmlurl='http://'.$ENV{'HTTP_HOST'}.'/'.$mode.'/'.$udom.'/'.$uname.'/'.$feed.'_rss.html';
+ $feeds.='
'.$feednames{$feed}.
+ '
'.($edit?&mt('Edit'):'HTML').': '.$htmlurl.''.
+ ($edit?'':'
RSS: '.$feedurl.'').'';
+ }
+ }
+ if ($feeds) {
+ return ''.&mt('Available RSS Feeds and Blogs').'
';
+ } else {
+ return '';
+ }
}
-sub addentry {
- my ($uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enclength,$enctype)=@_;
+{
+ my $feedcounter;
+ sub addentry {
+ $feedcounter++;
+ my $id=time.'00000'.$$.'00000'.$feedcounter;
+ return &editentry($id,@_);
+ }
+}
+
+sub editentry {
+ my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enclength,$enctype)=@_;
my $feedname=&feedname($filename);
- $feedcounter++;
- my $id=time.'00000'.$$.'00000'.$feedcounter;
+ &Apache::lonnet::put('nohist_all_rss_feeds',
+ { &filterfeedname($filename) => &displayfeedname($filename,$uname,$udom) },
+ $udom,$uname);
return &Apache::lonnet::put($feedname,{
$id.'_title' => $title,
$id.'_description' => $description,
@@ -73,23 +122,73 @@ sub addentry {
$id.'_status' => $status},$udom,$uname);
}
+sub changestatus {
+ my ($id,$uname,$udom,$filename,$status)=@_;
+ my $feedname=&feedname($filename);
+ if ($status eq 'deleted') {
+ return &Apache::lonnet::del($feedname,[$id.'_title',
+ $id.'_description',
+ $id.'_link',
+ $id.'_enclosureurl',
+ $id.'_enclosurelength',
+ $id.'_enclosuretype',
+ $id.'_status'],$udom,$uname);
+ } else {
+ return &Apache::lonnet::put($feedname,{$id.'_status' => $status},$udom,$uname);
+ }
+}
+
sub handler {
my $r = shift;
- &Apache::loncommon::content_type($r,'text/xml');
+
+ my $edit=0;
+ my $html=0;
+ my (undef,$mode,$udom,$uname,$filename)=split(/\//,$r->uri);
+ if (($mode eq 'adm') && ($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
+ $edit=1;
+ $html=1;
+ }
+ if ($filename=~/\.html$/) {
+ $html=1;
+ }
+ if ($html) {
+ &Apache::loncommon::content_type($r,'text/html');
+ } else {
+# Workaround Mozilla/Firefox
+# &Apache::loncommon::content_type($r,'application/rss+xml');
+ &Apache::loncommon::content_type($r,'text/xml');
+ }
$r->send_http_header;
return OK if $r->header_only;
- my (undef,undef,$udom,$uname,$filename)=split(/\//,$r->uri);
my $filterfeedname=&filterfeedname($filename);
my $feedname=&feedname($filename);
- my $displayfeedname=&displayfeedname($filename);
- $r->print("\n".
- "\nhttp://".$ENV{'HTTP_HOST'}.'/'.
- "\n".&mt('An RSS Feed provided by the LON-CAPA Learning Content Management System').'');
+ my $displayfeedname=&displayfeedname($filename,$uname,$udom);
+ if ($html) {
+ $r->print(&Apache::lonxml::xmlbegin().&Apache::loncommon::bodytag
+ ($displayfeedname,'','','',$udom,
+ $env{'form.register'}).<
+ function changed(tform,id) {
+ tform.elements[id+"_modified"].checked=true;
+ }
+
+ENDSCRIPT
+ } else {
+ $r->print("\n".
+ "\nhttp://".$ENV{'HTTP_HOST'}.'/public/'.$udom.'/'.$uname.'/'.
+ $filterfeedname.'_rss.html'.
+ "\n".
+ &mt('An RSS Feed provided by the LON-CAPA Learning Content Management System').
+ '');
+ }
# Is this user for real?
- my $homeserver=&Apache::lonnet::homeserver($uname,$udom);
+ my $homeserver=&Apache::lonnet::homeserver($uname,$udom);
+ if ($html) {
+ $r->print(&advertisefeeds($uname,$udom,$edit));
+ }
if ($homeserver eq 'no_host') {
- $r->print(''.&mt('No feed available').'');
+ $r->print(($html?'':'').&mt('No feed available').($html?'
':''));
} else {
# Course or user?
my $name='';
@@ -99,7 +198,13 @@ sub handler {
} else {
$name=&Apache::loncommon::nickname($uname,$udom);
}
- $r->print("\n".&mt('LON-CAPA RSS Feed "[_1]" for [_2]',$displayfeedname,$name).'');
+ $r->print("\n".
+ ($html?'':'').
+ &mt('LON-CAPA Feed "[_1]" for [_2]',$displayfeedname,$name).
+ ($html?'
'.($edit?'\n");
+ $r->print("\n".($html?''.($edit?'':'').'