Annotation of loncom/interface/lonrss.pm, revision 1.35

1.1       www         1: # The LearningOnline Network
                      2: # RSS Feeder
                      3: #
1.35    ! albertel    4: # $Id: lonrss.pm,v 1.34 2007/01/18 19:27:33 www Exp $
1.1       www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::lonrss;
                     30: 
                     31: use strict;
1.32      albertel   32: use LONCAPA;
1.1       www        33: use Apache::Constants qw(:common);
                     34: use Apache::loncommon;
                     35: use Apache::lonnet;
                     36: use Apache::lontexconvert;
                     37: use Apache::lonlocal;
                     38: use Apache::lonhtmlcommon;
1.33      www        39: use Apache::inputtags();
1.15      www        40: 
1.1       www        41: sub filterfeedname {
                     42:     my $filename=shift;
1.5       www        43:     $filename=~s/(\_rss\.html|\.rss)$//;
1.1       www        44:     $filename=~s/\W//g;
1.15      www        45:     $filename=~s/\_rssfeed$//;
                     46:     $filename=~s/^nohist\_//;
1.1       www        47:     return $filename;
                     48: }
                     49: 
                     50: sub feedname {
                     51:     return 'nohist_'.&filterfeedname(shift).'_rssfeed';
                     52: }
                     53: 
                     54: sub displayfeedname {
1.2       www        55:     my ($rawname,$uname,$udom)=@_;
                     56:     my $filterfilename=&filterfeedname($rawname);
                     57: # do we have a stored name?
1.20      www        58:     my %stored=&Apache::lonnet::get('nohist_all_rss_feeds',[$filterfilename,'feed_display_option_'.$filterfilename],$udom,$uname);
                     59:     if ($stored{$filterfilename}) { return ($stored{$filterfilename},$stored{'feed_display_option_'.$filterfilename}); }
1.2       www        60: # no, construct a name
                     61:     my $name=$filterfilename; 
                     62:     if ($name=~/^CourseBlog/) {
                     63:         $name=&mt('Course Blog');
                     64: 	if ($env{'course.'.$env{'request.course.id'}.'.description'}) {
                     65: 	    $name.=' '.$env{'course.'.$env{'request.course.id'}.'.description'};
                     66: 	}
                     67:     } else {
                     68: 	$name=~s/\_/ /g;
                     69:     }
1.20      www        70:     return ($name,$stored{'feed_display_option_'.$filterfilename});
1.2       www        71: }
                     72: 
1.19      www        73: sub namefeed {
1.2       www        74:     my ($rawname,$uname,$udom,$newname)=@_;
                     75:     return &Apache::lonnet::put('nohist_all_rss_feeds',
                     76: 				{ &filterfeedname($rawname) => $newname },
                     77: 				$udom,$uname);
                     78: }
                     79: 
1.20      www        80: sub changefeeddisplay {
                     81:     my ($rawname,$uname,$udom,$newstatus)=@_;
                     82:     return &Apache::lonnet::put('nohist_all_rss_feeds',
                     83: 				{ 'feed_display_option_'.&filterfeedname($rawname) => $newstatus },
                     84: 				$udom,$uname);
                     85: }
                     86: 
1.2       www        87: sub advertisefeeds {
1.6       www        88:     my ($uname,$udom,$edit)=@_;
1.2       www        89:     my $feeds='';
                     90:     my %feednames=&Apache::lonnet::dump('nohist_all_rss_feeds',$udom,$uname);
1.6       www        91:     my $mode='public';
                     92:     if ($edit) {
                     93: 	$mode='adm';
                     94:     }
1.29      raeburn    95:     my $server = &Apache::lonnet::absolute_url();
1.3       albertel   96:     foreach my $feed (sort(keys(%feednames))) {
1.24      www        97: 	if (($feed!~/^error\:/) && ($feed!~/^feed\_display\_option\_/)) {
1.29      raeburn    98: 	    my $feedurl= $server.'/public/'.$udom.'/'.$uname.'/'.$feed.'.rss';
                     99: 	    my $htmlurl= $server.'/'.$mode.'/'.$udom.'/'.$uname.'/'.$feed.'_rss.html';
1.20      www       100: 	    if ($feednames{'feed_display_option_'.$feed} eq 'hidden') {
                    101: 		if ($edit) {
                    102: 		    $feeds.='<li><i>'.$feednames{$feed}.'</i><br />'.&mt('Hidden').': <a href="'.$htmlurl.'"><tt>'.$htmlurl.'</tt></a></li>';
                    103: 		}
                    104: 	    } else {
                    105: 		$feeds.='<li><b>'.$feednames{$feed}.
                    106: 		    '</b><br />'.($edit?&mt('Edit'):'HTML').': <a href="'.$htmlurl.'"><tt>'.$htmlurl.'</tt></a>'.
1.34      www       107: 		    '<br />'.&mt('Public RSS/podcast (subscribe to)').': <a href="'.$feedurl.'"><tt>'.$feedurl.'</tt></a></li>';
1.20      www       108: 	    }
1.2       www       109: 	}
                    110:     }
                    111:     if ($feeds) {
                    112: 	return '<h4>'.&mt('Available RSS Feeds and Blogs').'</h4><ul>'.$feeds.'</ul>';
                    113:     } else {
                    114:         return '';
                    115:     }
1.1       www       116: }
                    117: 
1.12      albertel  118: sub rss_link {
                    119:     my ($url) = @_;
                    120:     return qq|<link rel="alternate" type="application/rss+xml" title="Course Announcements" href="$url" />|;
                    121: }
                    122: 
1.16      albertel  123: {
                    124:     my $feedcounter;
                    125:     sub get_new_feed_id {
                    126: 	$feedcounter++;
                    127: 	return time().'00000'.$$.'00000'.$feedcounter;
                    128:     }
                    129: }
                    130: 
1.15      www       131: sub addentry {
1.16      albertel  132:     my $id=&get_new_feed_id();
1.15      www       133:     return &editentry($id,@_);
1.2       www       134: }
                    135: 
                    136: sub editentry {
1.17      www       137:     my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enctype)=@_;
1.15      www       138:     if ($status eq 'deleted') {
                    139: 	return &changestatus($id,$uname,$udom,$filename,$status);
                    140:     }
1.2       www       141:     my $feedname=&feedname($filename);
                    142:     &Apache::lonnet::put('nohist_all_rss_feeds',
1.24      www       143: 			 { &filterfeedname($filename) => 
                    144: 			       (&displayfeedname($filename,$uname,$udom))[0] },
1.2       www       145: 			 $udom,$uname);
1.1       www       146:     return &Apache::lonnet::put($feedname,{
                    147: 	$id.'_title' => $title,
                    148: 	$id.'_description' => $description,
                    149: 	$id.'_link' => $url,
                    150: 	$id.'_enclosureurl' => $encurl,
                    151: 	$id.'_enclosuretype' => $enctype,
                    152: 	$id.'_status' => $status},$udom,$uname);
                    153: }
                    154: 
1.2       www       155: sub changestatus {
                    156:     my ($id,$uname,$udom,$filename,$status)=@_;
                    157:     my $feedname=&feedname($filename);
                    158:     if ($status eq 'deleted') {
                    159: 	return &Apache::lonnet::del($feedname,[$id.'_title',
                    160: 					       $id.'_description',
                    161: 					       $id.'_link',
                    162: 					       $id.'_enclosureurl',
                    163: 					       $id.'_enclosuretype',
                    164: 					       $id.'_status'],$udom,$uname);
                    165:     } else {
                    166: 	return &Apache::lonnet::put($feedname,{$id.'_status' => $status},$udom,$uname);
                    167:     }
                    168: }
                    169: 
1.8       albertel  170: sub changed_js {
                    171:     return <<ENDSCRIPT;
                    172: <script type="text/javascript">
                    173:     function changed(tform,id) {
                    174:         tform.elements[id+"_modified"].checked=true;
                    175:     }
                    176: </script>
1.11      albertel  177: ENDSCRIPT
1.8       albertel  178: }
                    179: 
1.17      www       180: sub determine_enclosure_types {
                    181:     my ($url)=@_;
                    182:     my ($ending)=($url=~/\.(\w+)$/);
                    183:     return &Apache::loncommon::filemimetype($ending);
                    184: }
                    185: 
1.21      www       186: sub course_blog_link {
                    187:     my ($id,$title,$description,$url,$encurl,$enctype)=@_;
                    188:     if ($env{'request.course.id'}) {
                    189: 	return &add_blog_entry_link($id,
                    190: 				    $env{'course.'.$env{'request.course.id'}.'.num'},
                    191: 				    $env{'course.'.$env{'request.course.id'}.'.domain'},
                    192: 				    'Course_Announcements',
                    193: 				    $title,$description,$url,'public',$encurl,$enctype,
                    194: 				    &mt('Add to Course Announcements'));
                    195:     } else {
                    196: 	return '';
                    197:     }
                    198: }
                    199: 
                    200: sub add_blog_entry_link {
                    201:     my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enctype,$linktext)=@_;
                    202:     return "<a href='/adm/$udom/$uname/".&filterfeedname($filename).'_rss.html?queryid='.
1.22      albertel  203: 	&escape($id).
1.27      albertel  204: 	'&amp;title='.&escape($title).
                    205: 	'&amp;description='.&escape($description).
                    206: 	'&amp;url='.&escape($url).
                    207: 	'&amp;status='.&escape($status).
                    208: 	'&amp;encurl='.&escape($encurl).
                    209: 	'&amp;enctype='.&escape($enctype).
1.21      www       210: 	"'>".$linktext.'</a>';
                    211: 
                    212: }
                    213: 
1.29      raeburn   214: sub blocking_blogdisplay {
                    215:     my ($uname,$udom,$html,$filterfeedname) = @_;
                    216:     my $user = &Apache::loncommon::plainname($uname,$udom);
                    217:     if ($html) {
                    218:         $user = &Apache::loncommon::aboutmewrapper($user,$uname,$udom);
                    219:     } else {
                    220:         $user = $user.' ('.$uname.':'.$udom.')';
                    221:     }
                    222:     my %setters;
                    223:     my ($blocked,$output,$blockcause);
                    224:     my ($startblock,$endblock) =
                    225:              &Apache::loncommon::blockcheck(\%setters,'blogs');
                    226:     if ($startblock && $endblock) {
                    227:         $blockcause = 'user';
                    228:     } else { 
                    229:         if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                    230:             ($startblock,$endblock) =
                    231:                  &Apache::loncommon::blockcheck(\%setters,'blogs',
                    232:                                                 $uname,$udom);
                    233:             $blockcause = 'blogowner';
                    234:         }
                    235:     }
                    236:     if ($startblock && $endblock) {
                    237:         $blocked = 1;
                    238:         my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                    239:         my $showend = &Apache::lonlocal::locallocaltime($endblock);
                    240:         $output = &mt('Blogs belonging to [_1] are unavailable from [_2] to [_3].',$user,$showstart,$showend);
                    241:         if ($html) {$output.='<br />';}
                    242:         if ($blockcause eq 'user') {
                    243:             $output .= &mt('This is because you are a student in one or more courses in which communication is being blocked.');
                    244:             if ($html) {
                    245:                 $output .= '<br />'.
                    246:                        &Apache::loncommon::build_block_table($startblock,
                    247:                                                         $endblock,\%setters);
                    248:             }
                    249:         } else {
                    250:             $output .= &mt('This is because the blog owner is a student in one or more courses in which communication is being blocked.');
                    251:         }
                    252:         if (!$html) {
                    253:             my $id = &get_new_feed_id();
                    254:             $output = '<title/><item><title/><description>'.$output."</description><link/><guid isPermaLink='false'>".$id.$filterfeedname.'_'.$udom.'_'.$uname.'</guid></item>';
                    255:         }
                    256:     }
                    257:     return ($blocked,$output);
                    258: }
                    259: 
1.1       www       260: sub handler {
1.8       albertel  261:     my ($r) = @_;
1.5       www       262: 
                    263:     my $edit=0;
                    264:     my $html=0;
                    265:     my (undef,$mode,$udom,$uname,$filename)=split(/\//,$r->uri);
                    266:     if (($mode eq 'adm') && ($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
                    267: 	$edit=1;
                    268: 	$html=1;
                    269:     }
1.21      www       270:     if  (($mode eq 'adm') && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
                    271: 	$edit=1;
                    272: 	$html=1;
                    273:     }
1.5       www       274:     if ($filename=~/\.html$/) {
                    275: 	$html=1;
                    276:     }
                    277:     if ($html) {
                    278: 	&Apache::loncommon::content_type($r,'text/html');
                    279:     } else {
                    280: # Workaround Mozilla/Firefox
                    281: #	&Apache::loncommon::content_type($r,'application/rss+xml');
                    282: 	&Apache::loncommon::content_type($r,'text/xml');
                    283:     }
1.1       www       284:     $r->send_http_header;
                    285:     return OK if $r->header_only;
                    286: 
                    287:     my $filterfeedname=&filterfeedname($filename);
                    288:     my $feedname=&feedname($filename);
1.20      www       289:     my ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
1.29      raeburn   290:     my ($blocked,$blocktext);
1.32      albertel  291:     if (!&Apache::lonnet::is_course($udom,$uname)) {
1.29      raeburn   292:         ($blocked,$blocktext) = &blocking_blogdisplay($uname,$udom,$html,$filterfeedname);
                    293:     }
1.5       www       294:     if ($html) {
1.25      albertel  295: 	my $title = $displayfeedname?$displayfeedname
                    296:                                     :"Available RSS Feeds and Blogs";
1.26      albertel  297: 	$r->print(&Apache::loncommon::start_page($title,undef,
1.13      albertel  298: 						 {'domain'         => $udom,
                    299: 						  'force_register' =>
                    300: 						      $env{'form.register'}}).
1.8       albertel  301: 		  &changed_js());
1.18      www       302:     } else { # render RSS
1.29      raeburn   303:         my $server = &Apache::lonnet::absolute_url();
1.5       www       304: 	$r->print("<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1'>\n<channel>".
1.29      raeburn   305: 		  "\n".'<link>'.$server.'/public/'.$udom.'/'.$uname.'/'.
1.5       www       306: 		  $filterfeedname.'_rss.html</link>'.
                    307: 		  "\n<description>".
                    308: 		  &mt('An RSS Feed provided by the LON-CAPA Learning Content Management System').
                    309: 		  '</description>');
                    310:     }
1.21      www       311: # This will be the entry id for new additions to the blog
1.16      albertel  312:     my $newid = &get_new_feed_id();
1.1       www       313: # Is this user for real?
1.6       www       314:     my $homeserver=&Apache::lonnet::homeserver($uname,$udom);
1.29      raeburn   315:     if ($html && !$blocked) {
1.19      www       316: # Any new feeds or renaming of feeds?
                    317: 	if ($edit) {
1.20      www       318: # Hide a feed?
                    319: 	    if ($env{'form.hidethisblog'}) {
                    320: 		&changefeeddisplay($feedname,$uname,$udom,'hidden');
                    321: 		($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
                    322: 	    }
                    323: # Advertise a feed?
                    324: 	    if ($env{'form.advertisethisblog'}) {
                    325: 		&changefeeddisplay($feedname,$uname,$udom,'public');
                    326: 		($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
                    327: 	    }
1.19      www       328: # New feed?
                    329: 	    if ($env{'form.namenewblog'}=~/\w/) {
                    330: 		&namefeed($env{'form.namenewblog'},$uname,$udom,$env{'form.namenewblog'});
                    331: 	    }
                    332: # Old feed that is being renamed?
                    333: 	    if (($displayfeedname) && ($env{'form.newblogname'}=~/\w/)) {
                    334: 		if ($env{'form.newblogname'} ne $displayfeedname) {
                    335: 		    &namefeed($feedname,$uname,$udom,$env{'form.newblogname'});
1.20      www       336: 		    ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
1.19      www       337: 		}
                    338: 	    }
                    339: 	}
1.6       www       340: 	$r->print(&advertisefeeds($uname,$udom,$edit));
                    341:     } 
1.1       www       342:     if ($homeserver eq 'no_host') {
1.5       www       343: 	$r->print(($html?'<h3>':'<title>').&mt('No feed available').($html?'</h3>':'</title>'));
1.29      raeburn   344:     } elsif ($blocked) {
                    345:         $r->print($blocktext);
                    346:         $r->print(($html?&Apache::loncommon::end_page():'</channel></rss>'."\n"));
1.18      www       347:     } else { # is indeed a user
1.1       www       348: # Course or user?
                    349: 	my $name='';
1.32      albertel  350: 	if (&Apache::lonnet::is_course($udom,$uname)) {
1.1       www       351: 	    my %cenv=&Apache::lonnet::dump('environment',$udom,$uname);
                    352: 	    $name=$cenv{'description'};
                    353: 	} else {
                    354: 	    $name=&Apache::loncommon::nickname($uname,$udom);
                    355: 	}
1.19      www       356: # Add a new feed
                    357:         if (($html) && ($edit)) {
1.33      www       358: 	    $r->print('<form method="post" name="makenewfeed">');
1.21      www       359:             $r->print(&mt('Name for New Feed').": <input type='text' size='40' name='namenewblog' />");
                    360: 	    $r->print('<input type="submit" value="'.&mt('Start a New Feed').'" />');
1.19      www       361: 	    $r->print('</form>');
                    362: 	}
1.18      www       363:         if ($displayfeedname) { # this is an existing feed
                    364: # Anything to store?
                    365: 	    if ($edit) {
1.21      www       366: # check if this was called with a query string
                    367: 		&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['queryid']);
                    368: 		if ($env{'form.queryid'}) {
                    369: # yes, collect the remainder
                    370: 		    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    371: 							    ['title',
                    372: 							     'description',
                    373: 							     'url',
                    374: 							     'status',
                    375: 							     'enclosureurl',
                    376: 							     'enclosuretype']);
1.33      www       377: 
1.21      www       378: #    my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enctype)=@_;
                    379: 
1.33      www       380: 
1.21      www       381: 		    &editentry($env{'form.queryid'},
                    382: 			       $uname,$udom,$filename,
                    383: 			       $env{'form.title'},
                    384: 			       $env{'form.description'},
                    385: 			       $env{'form.url'},
                    386: 			       $env{'form.status'},
                    387: 			       $env{'form.encurl'},
                    388: 			       $env{'form.enctype'}
                    389: 			       );
                    390: 		}
1.33      www       391: 
                    392: # store away the fields modified in the online form
1.18      www       393: 		my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
                    394: 		foreach my $entry (sort(keys(%newsfeed)),$env{'form.newid'}.'_status') {
                    395: 		    if ($entry=~/^(\d+)\_status$/) {
                    396: 			my $id=$1;
                    397: 			if ($env{'form.'.$id.'_modified'}) {
                    398: 			    &editentry($id,$uname,$udom,$feedname,
                    399: 				       $env{'form.'.$id.'_title'},
                    400: 				       $env{'form.'.$id.'_description'},
1.28      albertel  401: 				       $env{'form.'.$id.'_link'},
1.21      www       402: 				       $env{'form.'.$id.'_status'},
                    403: 				       $env{'form.'.$id.'_enclosureurl'},
                    404: 				       $env{'form.'.$id.'_enclosuretype'},
                    405: 				       );
1.18      www       406: 			}
                    407: 		    }
                    408: 		}
1.33      www       409: 
                    410: # see if we have any uploaded or portfolio files
                    411:                 my @uploadeditems=();
                    412: 
                    413: 		if ($env{'form.HWFILE0_0'}) {
                    414: # We have an uploaded file - store it away.
                    415: 		    $uploadeditems[0]=&Apache::lonnet::userfileupload('HWFILE0_0',undef,'portfolio/podcasts');
                    416: 		}
                    417: 		if ($env{'form.HWPORT0_0'}) {
                    418: # Selected portfolio files
                    419: 		    foreach my $filename (split(/\,/,$env{'form.HWPORT0_0'})) {
                    420: 			if ($filename) {
                    421: # construct full path and remember
                    422: 			    push(@uploadeditems,'/uploaded/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/portfolio'.$filename);
                    423: 			}
                    424: 		    }
                    425: 		}
                    426: # the zeroth item should be stored together with the last displayed (newid) field
                    427: 		if ($uploadeditems[0]) {
                    428: 		    my $id=$env{'form.newid'};
                    429: 		    &editentry($id,$uname,$udom,$feedname,
                    430: 			       $env{'form.'.$id.'_title'},
                    431: 			       $env{'form.'.$id.'_description'},
                    432: 			       $env{'form.'.$id.'_link'},
                    433: 			       $env{'form.'.$id.'_status'},
                    434: 			       $uploadeditems[0],
                    435: 			       &Apache::loncommon::filemimetype(($uploadeditems[0]=~/\.(\w+)$/)[0]),
                    436: 			       );
                    437: 		    &Apache::lonnet::make_public_indefinitely($uploadeditems[0]);
                    438: 		}
                    439: # if there are more files, they need new entries, since each can only have one enclosure
                    440: 		for (my $i=1; $i<=$#uploadeditems; $i++) {
                    441: 		    my $id = &get_new_feed_id().$i;
                    442: 		    &editentry($id,$uname,$udom,$feedname,
                    443: 			       'New Entry',
                    444: 			       '',
                    445: 			       '',
                    446: 			       'public',
                    447: 			       $uploadeditems[$i],
                    448: 			       &Apache::loncommon::filemimetype(($uploadeditems[$i]=~/\.(\w+)$/)[0]),
                    449: 			       );
                    450: 		    &Apache::lonnet::make_public_indefinitely($uploadeditems[$i]);
                    451: 		}
1.18      www       452: 	    } #done storing
                    453: 
1.29      raeburn   454: # Render private items?
                    455:             my $viewpubliconly=1;
1.18      www       456: 	    $r->print("\n".
1.19      www       457: 		      ($html?'<hr /><h3>':'<title>').
1.18      www       458: 		      &mt('LON-CAPA Feed "[_1]" for [_2]',$displayfeedname,$name).
1.20      www       459: 		      ($displayoption eq 'hidden'?' ('.&mt('Hidden').')':'').
1.33      www       460: 		      ($html?'</h3>'.($edit?'<form method="post" name="lonhomework" enctype="multipart/form-data"><br />'.
1.21      www       461: 				      &mt('Name of this Feed').
1.18      www       462: 				      ': <input type="text" size="50" name="newblogname" value="'.
                    463: 				      $displayfeedname.'" />':'').'<ul>':'</title>'));
                    464: 	    if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
                    465: 		$viewpubliconly=0;
1.29      raeburn   466:             }
1.1       www       467: # Get feed items
1.18      www       468: 	    my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
                    469: 	    foreach my $entry (sort(keys(%newsfeed)),$newid.'_status') {
                    470: 		if ($entry=~/^(\d+)\_status$/) { # is an entry
                    471: 		    my $id=$1;
                    472: 		    if ($edit) {
                    473: 			my %lt=&Apache::lonlocal::texthash('public' => 'public',
                    474: 							   'private' => 'private',
                    475: 							   'hidden' => 'hidden',
                    476: 							   'delete' => 'delete',
1.35    ! albertel  477: 							   'store' => 'Save changes',
1.18      www       478: 							   'title' => 'Title',
                    479: 							   'link' => 'Link',
1.33      www       480: 							   'description' => 'Description',
                    481:                                                            'enc' => 'Podcasted enclosure');
                    482:                         my $uploadlink;
                    483:                         if ($entry==$newid) {
                    484: # Generate upload link only for last (new) entry
                    485: 			    $uploadlink=&Apache::inputtags::file_selector(0,0,'*','both');
                    486: 			} else {
                    487: # Otherwise, display
                    488:                             $uploadlink='<tt>'.$newsfeed{$id.'_enclosureurl'}.'</tt>'.
                    489: 				"<input type='hidden' name='$id\_enclosureurl' value='$newsfeed{$id.'_enclosureurl'}' />".
                    490: 				"<input type='hidden' name='$id\_enclosuretype' value='$newsfeed{$id.'_enclosuretype'}' />";
                    491: 			}
1.18      www       492: 			my %status=();
                    493: 			unless ($newsfeed{$id.'_status'}) { $newsfeed{$id.'_status'}='public'; }
                    494: 			$status{$newsfeed{$id.'_status'}}='checked="checked"';
                    495: 			$r->print(<<ENDEDIT);
1.5       www       496: <li>
1.15      www       497: <label><input name='$id\_modified' type='checkbox' value="modified" /> $lt{'store'}</label>
1.6       www       498: &nbsp;&nbsp;
                    499: <label><input name='$id\_status' type="radio" value="public" $status{'public'} onClick="changed(this.form,'$id');" /> $lt{'public'}</label>
1.5       www       500: &nbsp;&nbsp;
1.6       www       501: <label><input name='$id\_status' type="radio" value="private" $status{'private'} onClick="changed(this.form,'$id');" /> $lt{'private'}</label>
1.5       www       502: &nbsp;&nbsp;
1.6       www       503: <label><input name='$id\_status' type="radio" value="hidden" $status{'hidden'} onClick="changed(this.form,'$id');" /> $lt{'hidden'}</label>
1.5       www       504: &nbsp;&nbsp;
1.15      www       505: <label><input name='$id\_status' type="radio" value="deleted" onClick="changed(this.form,'$id');" /> $lt{'delete'}</label>
1.5       www       506: <br />
1.18      www       507: $lt{'title'}:
                    508: <input name='$id\_title' type='text' size='60' value='$newsfeed{$id.'_title'}' onChange="changed(this.form,'$id');" /><br />
                    509: $lt{'description'}:<br />
1.6       www       510: <textarea name='$id\_description' rows="6" cols="80" onChange="changed(this.form,'$id');">$newsfeed{$id.'_description'}</textarea><br />
1.18      www       511: $lt{'link'}:
1.33      www       512: <input name='$id\_link' type='text' size='60' value='$newsfeed{$id.'_link'}' onChange="changed(this.form,'$id');" /><br />
                    513: $lt{'enc'} -
                    514: $uploadlink
1.6       www       515: <hr /></li>
1.5       www       516: ENDEDIT
1.18      www       517: 		    } else { # not in edit mode, just displaying
                    518: 			if (($newsfeed{$id.'_status'} ne 'public') && ($viewpubliconly)) { next; }
                    519: 			if ($newsfeed{$id.'_status'} eq 'hidden') { next; }
1.28      albertel  520: 			my $link =  $newsfeed{$id.'_link'};
                    521: 			if ($link =~ m|^/| ) {
                    522: 			    $link = "http://".$ENV{'HTTP_HOST'}.$link;
                    523: 			}
1.18      www       524: 			$r->print("\n".($html?"\n<li><b>":"<item>\n<title>").$newsfeed{$id.'_title'}.
                    525: 				  ($html?"</b><br />\n":"</title>\n<description>").
                    526: 				  $newsfeed{$id.'_description'}.
1.33      www       527: 				  ($html?"<br />":"</description>\n").
                    528: 				  ($link?($html?"\n<a href='":"<link>").
1.28      albertel  529: 				  $link.
1.33      www       530: 				  ($html?("'>".&mt('Read more')."</a><br />\n"):"</link>\n"):''));
                    531: 			my $enclosure=$newsfeed{$id.'_enclosureurl'};
1.17      www       532: # Enclosure? Get stats
1.33      www       533: 			if ($enclosure) {
                    534: 			    my @stat=&Apache::lonnet::stat_file($enclosure);
1.18      www       535: 			    if ($stat[7]) {
1.17      www       536: # Has non-zero length (and exists)
1.33      www       537: 				my $enclosuretype=$newsfeed{$id.'_enclosuretype'};
                    538: 				if ($enclosure =~ m|^/| ) {
                    539: 				    $enclosure = "http://".$ENV{'HTTP_HOST'}.$enclosure;
                    540: 				}
1.18      www       541: 				$r->print(($html?"<a href='":"\n<enclosure url='").
1.33      www       542: 					  $enclosure."' length='".$stat[7].
1.18      www       543: 					  "' type='".$enclosuretype.($html?"'>".&mt('Enclosure')."</a>":"' />"));
                    544: 			    }
                    545: 			}
                    546: 			if ($html) { # is HTML
                    547: 			    $r->print("\n<hr /></li>\n");
                    548: 			} else { # is RSS
                    549: 			    $r->print("\n<guid isPermaLink='false'>".$id.$filterfeedname.'_'.$udom.'_'.$uname."</guid></item>\n");
1.17      www       550: 			}
1.18      www       551: 		    } # end of "in edit mode"
                    552: 		} # end of rendering a real entry
                    553: 	    } # end of loop through all keys
                    554: 	    if ($html) {
                    555: 		$r->print('</ul>');
                    556: 		if ($edit) {
1.35    ! albertel  557: 		    $r->print('<input type="hidden" name="newid" value="'.$newid.'"/><input type="submit" value="'.&mt('Save Marked Changes').'" />'.
1.20      www       558: 			      ($displayoption eq 'hidden'?'<input type="submit" name="advertisethisblog" value="'.&mt('Advertise this Feed').'" />':
                    559: 			       '<input type="submit" name="hidethisblog" value="'.&mt('Hide this Feed').'" />'));
1.1       www       560: 		}
                    561: 	    }
1.18      www       562: 	} # was a real display feedname
                    563: 	$r->print(($html?'</form>'.&Apache::loncommon::end_page():'</channel></rss>'."\n"));
                    564:     } # a real user
1.1       www       565:     return OK;
1.18      www       566: } # end handler
1.1       www       567: 1;
                    568: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>