--- loncom/interface/lonrss.pm 2005/11/18 13:35:30 1.2
+++ loncom/interface/lonrss.pm 2006/04/13 17:57:17 1.15
@@ -1,7 +1,7 @@
# The LearningOnline Network
# RSS Feeder
#
-# $Id: lonrss.pm,v 1.2 2005/11/18 13:35:30 www Exp $
+# $Id: lonrss.pm,v 1.15 2006/04/13 17:57:17 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,12 +36,14 @@ use Apache::lontexconvert;
use Apache::lonlocal;
use Apache::lonhtmlcommon;
-my $feedcounter=0;
+my $feedcounter;
sub filterfeedname {
my $filename=shift;
- $filename=~s/\.rss$//;
+ $filename=~s/(\_rss\.html|\.rss)$//;
$filename=~s/\W//g;
+ $filename=~s/\_rssfeed$//;
+ $filename=~s/^nohist\_//;
return $filename;
}
@@ -76,14 +78,20 @@ sub renamefeed {
}
sub advertisefeeds {
- my ($uname,$udom)=@_;
+ my ($uname,$udom,$edit)=@_;
my $feeds='';
my %feednames=&Apache::lonnet::dump('nohist_all_rss_feeds',$udom,$uname);
- foreach (sort keys %feednames) {
- if ($_!~/^error\:/) {
- my $url='feed://'.$ENV{'HTTP_HOST'}.'/public/'.$udom.'/'.$uname.'/'.$_.'.rss';
- $feeds.='
'.
- $feednames{$_}.' '.$url.' ';
+ my $mode='public';
+ if ($edit) {
+ $mode='adm';
+ }
+ foreach my $feed (sort(keys(%feednames))) {
+ if ($feed!~/^error\:/) {
+ my $feedurl='http://'.$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) {
@@ -93,6 +101,11 @@ sub advertisefeeds {
}
}
+sub rss_link {
+ my ($url) = @_;
+ return qq| |;
+}
+
sub addentry {
$feedcounter++;
my $id=time.'00000'.$$.'00000'.$feedcounter;
@@ -101,6 +114,9 @@ sub addentry {
sub editentry {
my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enclength,$enctype)=@_;
+ if ($status eq 'deleted') {
+ return &changestatus($id,$uname,$udom,$filename,$status);
+ }
my $feedname=&feedname($filename);
&Apache::lonnet::put('nohist_all_rss_feeds',
{ &filterfeedname($filename) => &displayfeedname($filename,$uname,$udom) },
@@ -131,23 +147,81 @@ sub changestatus {
}
}
+sub changed_js {
+ return <
+ function changed(tform,id) {
+ tform.elements[id+"_modified"].checked=true;
+ }
+
+ENDSCRIPT
+}
+
sub handler {
- my $r = shift;
- &Apache::loncommon::content_type($r,'text/xml');
+ my ($r) = @_;
+
+ 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,$uname,$udom);
- $r->print("\n".
- "\n http://".$ENV{'HTTP_HOST'}.'/'.
- "\n".&mt('An RSS Feed provided by the LON-CAPA Learning Content Management System').' ');
+ if ($html) {
+ $r->print(&Apache::loncommon::start_page($displayfeedname,undef,
+ {'domain' => $udom,
+ 'force_register' =>
+ $env{'form.register'}}).
+ &changed_js());
+ } else {
+ $r->print("\n".
+ "\n http://".$ENV{'HTTP_HOST'}.'/public/'.$udom.'/'.$uname.'/'.
+ $filterfeedname.'_rss.html'.
+ "\n".
+ &mt('An RSS Feed provided by the LON-CAPA Learning Content Management System').
+ ' ');
+ }
+# Do we have stuff to store?
+ if ($edit) {
+ my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
+ foreach my $entry (sort(keys(%newsfeed)),$env{'form.newid'}.'_status') {
+ if ($entry=~/^(\d+)\_status$/) {
+ my $id=$1;
+ if ($env{'form.'.$id.'_modified'}) {
+ &editentry($id,$uname,$udom,$feedname,
+ $env{'form.'.$id.'_title'},
+ $env{'form.'.$id.'_description'},
+ $env{'form.'.$id.'_url'},
+ $env{'form.'.$id.'_status'});
+ }
+ }
+ }
+ }
+ $feedcounter++;
+ my $newid=time.'00000'.$$.'00000'.$feedcounter;
# 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='';
@@ -157,7 +231,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?' ':'').&Apache::loncommon::end_page():' '."\n"));
return OK;
}
-
1;
__END__