';
+ } else {
+ return '';
+ }
+}
+
+sub rss_link {
+ my ($url) = @_;
+ return qq||;
+}
+
+{
+ my $feedcounter;
+ sub get_new_feed_id {
+ $feedcounter++;
+ return time().'00000'.$$.'00000'.$feedcounter;
+ }
}
sub addentry {
- my ($uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enclength,$enctype)=@_;
+ my $id=&get_new_feed_id();
+ return &editentry($id,@_);
+}
+
+sub editentry {
+ my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enctype)=@_;
+ if ($status eq 'deleted') {
+ return &changestatus($id,$uname,$udom,$filename,$status);
+ }
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,
$id.'_link' => $url,
$id.'_enclosureurl' => $encurl,
- $id.'_enclosurelength' => $enclength,
$id.'_enclosuretype' => $enctype,
$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.'_enclosuretype',
+ $id.'_status'],$udom,$uname);
+ } else {
+ return &Apache::lonnet::put($feedname,{$id.'_status' => $status},$udom,$uname);
+ }
+}
+
+sub changed_js {
+ return <
+ function changed(tform,id) {
+ tform.elements[id+"_modified"].checked=true;
+ }
+
+ENDSCRIPT
+}
+
+sub determine_enclosure_types {
+ my ($url)=@_;
+ my ($ending)=($url=~/\.(\w+)$/);
+ return &Apache::loncommon::filemimetype($ending);
+}
+
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);
- $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::loncommon::start_page($displayfeedname,undef,
+ {'domain' => $udom,
+ 'force_register' =>
+ $env{'form.register'}}).
+ &changed_js());
+ } else { # render RSS
+ $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').
+ '');
+ }
+# Do we have stuff to store?
+ my $newid = &get_new_feed_id();
# 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').'');
- } else {
+ $r->print(($html?'
':'').&mt('No feed available').($html?'
':''));
+ } else { # is indeed a user
# Course or user?
my $name='';
if ($uname=~/^\d/) {
@@ -99,32 +225,116 @@ sub handler {
} else {
$name=&Apache::loncommon::nickname($uname,$udom);
}
- $r->print("\n".&mt('LON-CAPA RSS Feed "[_1]" for [_2]',$displayfeedname,$name).'');
+ if ($displayfeedname) { # this is an existing feed
+# Anything 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'});
+ }
+ }
+ }
+ if ($env{'form.newblogname'} ne $displayfeedname) {
+ &Apache::lonnet::put('nohist_all_rss_feeds',{ $filterfeedname => $env{'form.newblogname'} },$udom,$uname);
+ $displayfeedname=&displayfeedname($filename,$uname,$udom);
+ }
+ } #done storing
+
+ $r->print("\n".
+ ($html?'
':'').
+ &mt('LON-CAPA Feed "[_1]" for [_2]',$displayfeedname,$name).
+ ($html?'
'.($edit?'\n");
+ } # was a real display feedname
+ $r->print(($html?''.&Apache::loncommon::end_page():''."\n"));
+ } # a real user
return OK;
-}
-
+} # end handler
1;
__END__