--- loncom/interface/lonrss.pm 2006/04/13 16:23:03 1.14
+++ loncom/interface/lonrss.pm 2006/04/22 20:58:32 1.17
@@ -1,7 +1,7 @@
# The LearningOnline Network
# RSS Feeder
#
-# $Id: lonrss.pm,v 1.14 2006/04/13 16:23:03 www Exp $
+# $Id: lonrss.pm,v 1.17 2006/04/22 20:58:32 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,10 +36,13 @@ use Apache::lontexconvert;
use Apache::lonlocal;
use Apache::lonhtmlcommon;
+
sub filterfeedname {
my $filename=shift;
$filename=~s/(\_rss\.html|\.rss)$//;
$filename=~s/\W//g;
+ $filename=~s/\_rssfeed$//;
+ $filename=~s/^nohist\_//;
return $filename;
}
@@ -100,20 +103,26 @@ sub advertisefeeds {
sub rss_link {
my ($url) = @_;
return qq||;
-
}
{
my $feedcounter;
- sub addentry {
+ sub get_new_feed_id {
$feedcounter++;
- my $id=time.'00000'.$$.'00000'.$feedcounter;
- return &editentry($id,@_);
+ return time().'00000'.$$.'00000'.$feedcounter;
}
}
+sub addentry {
+ my $id=&get_new_feed_id();
+ return &editentry($id,@_);
+}
+
sub editentry {
- my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enclength,$enctype)=@_;
+ 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);
&Apache::lonnet::put('nohist_all_rss_feeds',
{ &filterfeedname($filename) => &displayfeedname($filename,$uname,$udom) },
@@ -123,7 +132,6 @@ sub editentry {
$id.'_description' => $description,
$id.'_link' => $url,
$id.'_enclosureurl' => $encurl,
- $id.'_enclosurelength' => $enclength,
$id.'_enclosuretype' => $enctype,
$id.'_status' => $status},$udom,$uname);
}
@@ -136,7 +144,6 @@ sub changestatus {
$id.'_description',
$id.'_link',
$id.'_enclosureurl',
- $id.'_enclosurelength',
$id.'_enclosuretype',
$id.'_status'],$udom,$uname);
} else {
@@ -154,6 +161,12 @@ sub changed_js {
ENDSCRIPT
}
+sub determine_enclosure_types {
+ my ($url)=@_;
+ my ($ending)=($url=~/\.(\w+)$/);
+ return &Apache::loncommon::filemimetype($ending);
+}
+
sub handler {
my ($r) = @_;
@@ -186,7 +199,6 @@ sub handler {
'force_register' =>
$env{'form.register'}}).
&changed_js());
-
} else {
$r->print("\n".
"\nhttp://".$ENV{'HTTP_HOST'}.'/public/'.$udom.'/'.$uname.'/'.
@@ -195,6 +207,23 @@ sub handler {
&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'});
+ }
+ }
+ }
+ }
+ my $newid = &get_new_feed_id();
# Is this user for real?
my $homeserver=&Apache::lonnet::homeserver($uname,$udom);
if ($html) {
@@ -225,7 +254,7 @@ sub handler {
}
# Get feed items
my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
- foreach my $entry (sort(keys(%newsfeed))) {
+ foreach my $entry (sort(keys(%newsfeed)),$newid.'_status') {
if ($entry=~/^(\d+)\_status$/) {
my $id=$1;
if ($edit) {
@@ -235,10 +264,11 @@ sub handler {
'delete' => 'delete',
'store' => 'Store changes');
my %status=();
+ unless ($newsfeed{$id.'_status'}) { $newsfeed{$id.'_status'}='public'; }
$status{$newsfeed{$id.'_status'}}='checked="checked"';
$r->print(<
-
+
@@ -246,7 +276,7 @@ sub handler {
-
+
@@ -263,10 +293,16 @@ ENDEDIT
"http://".$ENV{'HTTP_HOST'}.
$newsfeed{$id.'_link'}.
($html?("'>".&mt('Read more')."
\n"):"\n"));
+# Enclosure? Get stats
if ($newsfeed{$id.'_enclosureurl'}) {
- $r->print(($html?"".&mt('Enclosure')."":"' />"));
+ my @stat=&Apache::lonnet::stat_file($newsfeed{$id.'_enclosureurl'});
+ if ($stat[7]) {
+# Has non-zero length (and exists)
+ my $enclosuretype=$newsfeed{$id.'_enclosetype'};
+ $r->print(($html?"".&mt('Enclosure')."":"' />"));
+ }
}
if ($html) {
$r->print("\n
\n");
@@ -277,7 +313,7 @@ ENDEDIT
}
}
}
- $r->print("\n".($html?''.($edit?'':'').&Apache::loncommon::end_page():''."\n"));
+ $r->print("\n".($html?''.($edit?'':'').&Apache::loncommon::end_page():''."\n"));
return OK;
}
1;