--- loncom/interface/lonrss.pm 2006/04/22 20:58:32 1.17 +++ loncom/interface/lonrss.pm 2006/05/11 15:27:49 1.20 @@ -1,7 +1,7 @@ # The LearningOnline Network # RSS Feeder # -# $Id: lonrss.pm,v 1.17 2006/04/22 20:58:32 www Exp $ +# $Id: lonrss.pm,v 1.20 2006/05/11 15:27:49 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -54,8 +54,8 @@ 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}; } + my %stored=&Apache::lonnet::get('nohist_all_rss_feeds',[$filterfilename,'feed_display_option_'.$filterfilename],$udom,$uname); + if ($stored{$filterfilename}) { return ($stored{$filterfilename},$stored{'feed_display_option_'.$filterfilename}); } # no, construct a name my $name=$filterfilename; if ($name=~/^CourseBlog/) { @@ -66,16 +66,23 @@ sub displayfeedname { } else { $name=~s/\_/ /g; } - return $name; + return ($name,$stored{'feed_display_option_'.$filterfilename}); } -sub renamefeed { +sub namefeed { my ($rawname,$uname,$udom,$newname)=@_; return &Apache::lonnet::put('nohist_all_rss_feeds', { &filterfeedname($rawname) => $newname }, $udom,$uname); } +sub changefeeddisplay { + my ($rawname,$uname,$udom,$newstatus)=@_; + return &Apache::lonnet::put('nohist_all_rss_feeds', + { 'feed_display_option_'.&filterfeedname($rawname) => $newstatus }, + $udom,$uname); +} + sub advertisefeeds { my ($uname,$udom,$edit)=@_; my $feeds=''; @@ -85,12 +92,18 @@ sub advertisefeeds { $mode='adm'; } foreach my $feed (sort(keys(%feednames))) { - if ($feed!~/^error\:/) { + if (($feed!~/^error\:/) && ($feed!~/^feed\_display\_option\_/)) { my $feedurl='http://'.$ENV{'HTTP_HOST'}.'/public/'.$udom.'/'.$uname.'/'.$feed.'.rss'; my $htmlurl='http://'.$ENV{'HTTP_HOST'}.'/'.$mode.'/'.$udom.'/'.$uname.'/'.$feed.'_rss.html'; - $feeds.='<li>'.$feednames{$feed}. - '<br />'.($edit?&mt('Edit'):'HTML').': <a href="'.$htmlurl.'"><tt>'.$htmlurl.'</tt></a>'. - ($edit?'':'<br />RSS: <a href="'.$feedurl.'"><tt>'.$feedurl.'</tt></a>').'</li>'; + if ($feednames{'feed_display_option_'.$feed} eq 'hidden') { + if ($edit) { + $feeds.='<li><i>'.$feednames{$feed}.'</i><br />'.&mt('Hidden').': <a href="'.$htmlurl.'"><tt>'.$htmlurl.'</tt></a></li>'; + } + } else { + $feeds.='<li><b>'.$feednames{$feed}. + '</b><br />'.($edit?&mt('Edit'):'HTML').': <a href="'.$htmlurl.'"><tt>'.$htmlurl.'</tt></a>'. + '<br />RSS: <a href="'.$feedurl.'"><tt>'.$feedurl.'</tt></a></li>'; + } } } if ($feeds) { @@ -192,14 +205,14 @@ sub handler { my $filterfeedname=&filterfeedname($filename); my $feedname=&feedname($filename); - my $displayfeedname=&displayfeedname($filename,$uname,$udom); + my ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom); if ($html) { - $r->print(&Apache::loncommon::start_page($displayfeedname,undef, + $r->print(&Apache::loncommon::start_page(($displayfeedname?$displayfeedname:&mt("Available RSS Feeds and Blogs")),undef, {'domain' => $udom, 'force_register' => $env{'form.register'}}). &changed_js()); - } else { + } else { # render RSS $r->print("<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1'>\n<channel>". "\n<link>http://".$ENV{'HTTP_HOST'}.'/public/'.$udom.'/'.$uname.'/'. $filterfeedname.'_rss.html</link>'. @@ -208,30 +221,39 @@ sub handler { '</description>'); } # 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) { +# Any new feeds or renaming of feeds? + if ($edit) { +# Hide a feed? + if ($env{'form.hidethisblog'}) { + &changefeeddisplay($feedname,$uname,$udom,'hidden'); + ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom); + } +# Advertise a feed? + if ($env{'form.advertisethisblog'}) { + &changefeeddisplay($feedname,$uname,$udom,'public'); + ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom); + } +# New feed? + if ($env{'form.namenewblog'}=~/\w/) { + &namefeed($env{'form.namenewblog'},$uname,$udom,$env{'form.namenewblog'}); + } +# Old feed that is being renamed? + if (($displayfeedname) && ($env{'form.newblogname'}=~/\w/)) { + if ($env{'form.newblogname'} ne $displayfeedname) { + &namefeed($feedname,$uname,$udom,$env{'form.newblogname'}); + ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom); + } + } + } $r->print(&advertisefeeds($uname,$udom,$edit)); } if ($homeserver eq 'no_host') { $r->print(($html?'<h3>':'<title>').&mt('No feed available').($html?'</h3>':'</title>')); - } else { + } else { # is indeed a user # Course or user? my $name=''; if ($uname=~/^\d/) { @@ -240,33 +262,62 @@ sub handler { } else { $name=&Apache::loncommon::nickname($uname,$udom); } - $r->print("\n". - ($html?'<h3>':'<title>'). - &mt('LON-CAPA Feed "[_1]" for [_2]',$displayfeedname,$name). - ($html?'</h3>'.($edit?'<form method="post"><br />'. - &mt('Name of blog/journal'). - ': <input type="text" size="50" name="newblogname" value="'. - $displayfeedname.'" />':'').'<ul>':'</title>')); -# Render private items? - my $viewpubliconly=1; - if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) { - $viewpubliconly=0; +# Add a new feed + if (($html) && ($edit)) { + $r->print('<form method="post">'); + $r->print(&mt('Name for New Blog').": <input type='text' size='40' name='namenewblog' />"); + $r->print('<input type="submit" value="'.&mt('Start a New Blog').'" />'); + $r->print('</form>'); } + 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'}); + } + } + } + } #done storing + + $r->print("\n". + ($html?'<hr /><h3>':'<title>'). + &mt('LON-CAPA Feed "[_1]" for [_2]',$displayfeedname,$name). + ($displayoption eq 'hidden'?' ('.&mt('Hidden').')':''). + ($html?'</h3>'.($edit?'<form method="post"><br />'. + &mt('Name of blog/journal'). + ': <input type="text" size="50" name="newblogname" value="'. + $displayfeedname.'" />':'').'<ul>':'</title>')); +# Render private items? + my $viewpubliconly=1; + if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) { + $viewpubliconly=0; + } # Get feed items - my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname); - foreach my $entry (sort(keys(%newsfeed)),$newid.'_status') { - if ($entry=~/^(\d+)\_status$/) { - my $id=$1; - if ($edit) { - my %lt=&Apache::lonlocal::texthash('public' => 'public', - 'private' => 'private', - 'hidden' => 'hidden', - 'delete' => 'delete', - 'store' => 'Store changes'); - my %status=(); - unless ($newsfeed{$id.'_status'}) { $newsfeed{$id.'_status'}='public'; } - $status{$newsfeed{$id.'_status'}}='checked="checked"'; - $r->print(<<ENDEDIT); + my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname); + foreach my $entry (sort(keys(%newsfeed)),$newid.'_status') { + if ($entry=~/^(\d+)\_status$/) { # is an entry + my $id=$1; + if ($edit) { + my %lt=&Apache::lonlocal::texthash('public' => 'public', + 'private' => 'private', + 'hidden' => 'hidden', + 'delete' => 'delete', + 'store' => 'Store changes', + 'title' => 'Title', + 'link' => 'Link', + 'description' => 'Description'); + my %status=(); + unless ($newsfeed{$id.'_status'}) { $newsfeed{$id.'_status'}='public'; } + $status{$newsfeed{$id.'_status'}}='checked="checked"'; + $r->print(<<ENDEDIT); <li> <label><input name='$id\_modified' type='checkbox' value="modified" /> $lt{'store'}</label> @@ -278,43 +329,55 @@ sub handler { <label><input name='$id\_status' type="radio" value="deleted" onClick="changed(this.form,'$id');" /> $lt{'delete'}</label> <br /> -<input name='$id\_title' type='text' size='80' value='$newsfeed{$id.'_title'}' onChange="changed(this.form,'$id');" /><br /> +$lt{'title'}: +<input name='$id\_title' type='text' size='60' value='$newsfeed{$id.'_title'}' onChange="changed(this.form,'$id');" /><br /> +$lt{'description'}:<br /> <textarea name='$id\_description' rows="6" cols="80" onChange="changed(this.form,'$id');">$newsfeed{$id.'_description'}</textarea><br /> -<input name='$id\_link' type='text' size='80' value='$newsfeed{$id.'_link'}' onChange="changed(this.form,'$id');" /> +$lt{'link'}: +<input name='$id\_link' type='text' size='60' value='$newsfeed{$id.'_link'}' onChange="changed(this.form,'$id');" /> <hr /></li> ENDEDIT - } else { - if (($newsfeed{$id.'_status'} ne 'public') && ($viewpubliconly)) { next; } - if ($newsfeed{$id.'_status'} eq 'hidden') { next; } - $r->print("\n".($html?"\n<li><b>":"<item>\n<title>").$newsfeed{$id.'_title'}. - ($html?"</b><br />\n":"</title>\n<description>"). - $newsfeed{$id.'_description'}. - ($html?"<br />\n<a href='":"</description>\n<link>"). - "http://".$ENV{'HTTP_HOST'}. - $newsfeed{$id.'_link'}. - ($html?("'>".&mt('Read more')."</a><br />\n"):"</link>\n")); + } else { # not in edit mode, just displaying + if (($newsfeed{$id.'_status'} ne 'public') && ($viewpubliconly)) { next; } + if ($newsfeed{$id.'_status'} eq 'hidden') { next; } + $r->print("\n".($html?"\n<li><b>":"<item>\n<title>").$newsfeed{$id.'_title'}. + ($html?"</b><br />\n":"</title>\n<description>"). + $newsfeed{$id.'_description'}. + ($html?"<br />\n<a href='":"</description>\n<link>"). + "http://".$ENV{'HTTP_HOST'}. + $newsfeed{$id.'_link'}. + ($html?("'>".&mt('Read more')."</a><br />\n"):"</link>\n")); # Enclosure? Get stats - if ($newsfeed{$id.'_enclosureurl'}) { - my @stat=&Apache::lonnet::stat_file($newsfeed{$id.'_enclosureurl'}); - if ($stat[7]) { + if ($newsfeed{$id.'_enclosureurl'}) { + 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?"<a href='":"\n<enclosure url='"). - $newsfeed{$id.'_enclosureurl'}."' length='".$stat[7]. - "' type='".$enclosuretype.($html?"'>".&mt('Enclosure')."</a>":"' />")); + my $enclosuretype=$newsfeed{$id.'_enclosetype'}; + $r->print(($html?"<a href='":"\n<enclosure url='"). + $newsfeed{$id.'_enclosureurl'}."' length='".$stat[7]. + "' type='".$enclosuretype.($html?"'>".&mt('Enclosure')."</a>":"' />")); + } } - } - if ($html) { - $r->print("\n<hr /></li>\n"); - } else { - $r->print("\n<guid isPermaLink='false'>".$id.$filterfeedname.'_'.$udom.'_'.$uname."</guid></item>\n"); - } + if ($html) { # is HTML + $r->print("\n<hr /></li>\n"); + } else { # is RSS + $r->print("\n<guid isPermaLink='false'>".$id.$filterfeedname.'_'.$udom.'_'.$uname."</guid></item>\n"); + } + } # end of "in edit mode" + } # end of rendering a real entry + } # end of loop through all keys + if ($html) { + $r->print('</ul>'); + if ($edit) { + $r->print('<input type="hidden" name="newid" value="'.$newid.'"/><input type="submit" value="'.&mt('Store Marked Changes').'" />'. + ($displayoption eq 'hidden'?'<input type="submit" name="advertisethisblog" value="'.&mt('Advertise this Feed').'" />': + '<input type="submit" name="hidethisblog" value="'.&mt('Hide this Feed').'" />')); } } - } - } - $r->print("\n".($html?'</ul>'.($edit?'<input type="hidden" name="newid" value="'.$newid.'"/><input type="submit" value="'.&mt('Store Marked Changes').'" /></form>':'').&Apache::loncommon::end_page():'</channel></rss>'."\n")); + } # was a real display feedname + $r->print(($html?'</form>'.&Apache::loncommon::end_page():'</channel></rss>'."\n")); + } # a real user return OK; -} +} # end handler 1; __END__