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

1.1       www         1: # The LearningOnline Network
                      2: # RSS Feeder
                      3: #
1.48    ! kalberla    4: # $Id: lonrss.pm,v 1.47 2009/04/20 15:20:23 amueller 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.37      albertel   97: 	next if ($feed =~/^\s*$/    ||
                     98: 		 $feed =~ /^error:/ ||
                     99: 		 $feed =~ /^feed_display_option_/);
                    100: 
                    101: 	my $feedurl= $server.'/public/'.$udom.'/'.$uname.'/'.$feed.'.rss';
                    102: 	my $htmlurl= $server.'/'.$mode.'/'.$udom.'/'.$uname.'/'.$feed.'_rss.html';
                    103: 	if ($feednames{'feed_display_option_'.$feed} eq 'hidden') {
                    104: 	    if ($edit) {
                    105: 		$feeds.='<li><i>'.$feednames{$feed}.'</i><br />'.&mt('Hidden').': <a href="'.$htmlurl.'"><tt>'.$htmlurl.'</tt></a></li>';
1.20      www       106: 	    }
1.37      albertel  107: 	} else {
                    108: 	    $feeds.='<li><b>'.$feednames{$feed}.
1.38      amueller  109: 		'</b><br />'.($edit?&mt('Edit'):'HTML').': <a href="'.$htmlurl.'"><tt>'.$feednames{$feed}.' HTML</tt></a>'.
                    110: 		'<br />'.&mt('Public RSS/podcast (subscribe to)').': <a href="'.$feedurl.'"><tt>'.$feednames{$feed}.' RSS/Podcast</tt></a></li>';
1.2       www       111: 	}
                    112:     }
                    113:     if ($feeds) {
                    114: 	return '<h4>'.&mt('Available RSS Feeds and Blogs').'</h4><ul>'.$feeds.'</ul>';
                    115:     } else {
                    116:         return '';
                    117:     }
1.1       www       118: }
                    119: 
1.12      albertel  120: sub rss_link {
1.37      albertel  121:     my ($uname,$udom)=@_;
                    122:     my $result;
                    123:     my $server = &Apache::lonnet::absolute_url();
                    124:     my %feednames=&Apache::lonnet::dump('nohist_all_rss_feeds',$udom,$uname);
                    125:     foreach my $feed (sort(keys(%feednames))) {
                    126: 	next if ($feed =~/^\s*$/    ||
                    127: 		 $feed =~ /^error:/ ||
                    128: 		 $feed =~/^feed_display_option_/ );
                    129: 	my $url= $server.'/public/'.$udom.'/'.$uname.'/'.$feed.'.rss';
                    130: 	my $title = $feed;
                    131: 	$title =~ s/_/ /g;
                    132: 	$result.=qq|
                    133: <link rel="alternate" type="application/rss+xml" title="$title" href="$url" />
                    134: |;
                    135:     }
                    136:     return $result;
1.12      albertel  137: }
                    138: 
1.16      albertel  139: {
                    140:     my $feedcounter;
                    141:     sub get_new_feed_id {
                    142: 	$feedcounter++;
                    143: 	return time().'00000'.$$.'00000'.$feedcounter;
                    144:     }
                    145: }
                    146: 
1.15      www       147: sub addentry {
1.16      albertel  148:     my $id=&get_new_feed_id();
1.15      www       149:     return &editentry($id,@_);
1.2       www       150: }
                    151: 
                    152: sub editentry {
1.17      www       153:     my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enctype)=@_;
1.15      www       154:     if ($status eq 'deleted') {
                    155: 	return &changestatus($id,$uname,$udom,$filename,$status);
                    156:     }
1.2       www       157:     my $feedname=&feedname($filename);
                    158:     &Apache::lonnet::put('nohist_all_rss_feeds',
1.24      www       159: 			 { &filterfeedname($filename) => 
                    160: 			       (&displayfeedname($filename,$uname,$udom))[0] },
1.2       www       161: 			 $udom,$uname);
1.1       www       162:     return &Apache::lonnet::put($feedname,{
                    163: 	$id.'_title' => $title,
                    164: 	$id.'_description' => $description,
                    165: 	$id.'_link' => $url,
                    166: 	$id.'_enclosureurl' => $encurl,
                    167: 	$id.'_enclosuretype' => $enctype,
                    168: 	$id.'_status' => $status},$udom,$uname);
                    169: }
                    170: 
1.2       www       171: sub changestatus {
                    172:     my ($id,$uname,$udom,$filename,$status)=@_;
                    173:     my $feedname=&feedname($filename);
                    174:     if ($status eq 'deleted') {
                    175: 	return &Apache::lonnet::del($feedname,[$id.'_title',
                    176: 					       $id.'_description',
                    177: 					       $id.'_link',
                    178: 					       $id.'_enclosureurl',
                    179: 					       $id.'_enclosuretype',
                    180: 					       $id.'_status'],$udom,$uname);
                    181:     } else {
                    182: 	return &Apache::lonnet::put($feedname,{$id.'_status' => $status},$udom,$uname);
                    183:     }
                    184: }
                    185: 
1.8       albertel  186: sub changed_js {
                    187:     return <<ENDSCRIPT;
                    188: <script type="text/javascript">
                    189:     function changed(tform,id) {
                    190:         tform.elements[id+"_modified"].checked=true;
                    191:     }
                    192: </script>
1.11      albertel  193: ENDSCRIPT
1.8       albertel  194: }
                    195: 
1.17      www       196: sub determine_enclosure_types {
                    197:     my ($url)=@_;
                    198:     my ($ending)=($url=~/\.(\w+)$/);
                    199:     return &Apache::loncommon::filemimetype($ending);
                    200: }
                    201: 
1.21      www       202: sub course_blog_link {
                    203:     my ($id,$title,$description,$url,$encurl,$enctype)=@_;
                    204:     if ($env{'request.course.id'}) {
                    205: 	return &add_blog_entry_link($id,
                    206: 				    $env{'course.'.$env{'request.course.id'}.'.num'},
                    207: 				    $env{'course.'.$env{'request.course.id'}.'.domain'},
                    208: 				    'Course_Announcements',
                    209: 				    $title,$description,$url,'public',$encurl,$enctype,
                    210: 				    &mt('Add to Course Announcements'));
                    211:     } else {
                    212: 	return '';
                    213:     }
                    214: }
                    215: 
                    216: sub add_blog_entry_link {
                    217:     my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enctype,$linktext)=@_;
                    218:     return "<a href='/adm/$udom/$uname/".&filterfeedname($filename).'_rss.html?queryid='.
1.22      albertel  219: 	&escape($id).
1.27      albertel  220: 	'&amp;title='.&escape($title).
                    221: 	'&amp;description='.&escape($description).
                    222: 	'&amp;url='.&escape($url).
                    223: 	'&amp;status='.&escape($status).
                    224: 	'&amp;encurl='.&escape($encurl).
                    225: 	'&amp;enctype='.&escape($enctype).
1.21      www       226: 	"'>".$linktext.'</a>';
                    227: 
                    228: }
                    229: 
1.29      raeburn   230: sub blocking_blogdisplay {
                    231:     my ($uname,$udom,$html,$filterfeedname) = @_;
                    232:     my $user = &Apache::loncommon::plainname($uname,$udom);
                    233:     if ($html) {
                    234:         $user = &Apache::loncommon::aboutmewrapper($user,$uname,$udom);
                    235:     } else {
                    236:         $user = $user.' ('.$uname.':'.$udom.')';
                    237:     }
                    238:     my %setters;
                    239:     my ($blocked,$output,$blockcause);
                    240:     my ($startblock,$endblock) =
                    241:              &Apache::loncommon::blockcheck(\%setters,'blogs');
                    242:     if ($startblock && $endblock) {
                    243:         $blockcause = 'user';
                    244:     } else { 
                    245:         if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                    246:             ($startblock,$endblock) =
                    247:                  &Apache::loncommon::blockcheck(\%setters,'blogs',
                    248:                                                 $uname,$udom);
                    249:             $blockcause = 'blogowner';
                    250:         }
                    251:     }
                    252:     if ($startblock && $endblock) {
                    253:         $blocked = 1;
                    254:         my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                    255:         my $showend = &Apache::lonlocal::locallocaltime($endblock);
                    256:         $output = &mt('Blogs belonging to [_1] are unavailable from [_2] to [_3].',$user,$showstart,$showend);
                    257:         if ($html) {$output.='<br />';}
                    258:         if ($blockcause eq 'user') {
                    259:             $output .= &mt('This is because you are a student in one or more courses in which communication is being blocked.');
                    260:             if ($html) {
1.48    ! kalberla  261:                 #$output .= '<br />'.
        !           262:                        #&Apache::loncommon::build_block_table($startblock,
        !           263:                        #                                 $endblock,\%setters);
        !           264:                  my ($blocked, $blocktext) = Apache::loncommon::blocking_status('blogs');
        !           265:                  $output .= '<br /><br />'.$blocktext;
1.29      raeburn   266:             }
                    267:         } else {
                    268:             $output .= &mt('This is because the blog owner is a student in one or more courses in which communication is being blocked.');
                    269:         }
                    270:         if (!$html) {
                    271:             my $id = &get_new_feed_id();
                    272:             $output = '<title/><item><title/><description>'.$output."</description><link/><guid isPermaLink='false'>".$id.$filterfeedname.'_'.$udom.'_'.$uname.'</guid></item>';
                    273:         }
                    274:     }
                    275:     return ($blocked,$output);
                    276: }
                    277: 
1.1       www       278: sub handler {
1.8       albertel  279:     my ($r) = @_;
1.5       www       280: 
                    281:     my $edit=0;
                    282:     my $html=0;
                    283:     my (undef,$mode,$udom,$uname,$filename)=split(/\//,$r->uri);
                    284:     if (($mode eq 'adm') && ($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
                    285: 	$edit=1;
                    286: 	$html=1;
                    287:     }
1.21      www       288:     if  (($mode eq 'adm') && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
                    289: 	$edit=1;
                    290: 	$html=1;
                    291:     }
1.5       www       292:     if ($filename=~/\.html$/) {
                    293: 	$html=1;
                    294:     }
                    295:     if ($html) {
                    296: 	&Apache::loncommon::content_type($r,'text/html');
                    297:     } else {
                    298: # Workaround Mozilla/Firefox
                    299: #	&Apache::loncommon::content_type($r,'application/rss+xml');
                    300: 	&Apache::loncommon::content_type($r,'text/xml');
                    301:     }
1.1       www       302:     $r->send_http_header;
                    303:     return OK if $r->header_only;
                    304: 
                    305:     my $filterfeedname=&filterfeedname($filename);
                    306:     my $feedname=&feedname($filename);
1.20      www       307:     my ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
1.39      raeburn   308:     my ($blocked,$blocktext,$disabled,$disabletext);
1.32      albertel  309:     if (!&Apache::lonnet::is_course($udom,$uname)) {
1.29      raeburn   310:         ($blocked,$blocktext) = &blocking_blogdisplay($uname,$udom,$html,$filterfeedname);
1.44      raeburn   311:         if (&Apache::lonnet::usertools_access($uname,$udom,'blog')) {
                    312:             $disabled = 0;
                    313:         } else {
1.43      raeburn   314:             $disabled = 1;
1.39      raeburn   315:             if ($html) {
                    316:                 $disabletext = '<h2>'.&mt('No user blog available') .'</h2>'.
                    317:                                &mt('This is a result of one of the following:').'<ul>'.
                    318:                                '<li>'.&mt('The administrator of this domain has disabled blog functionality for this specific user.').'</li>'.
                    319:                                '<li>'.&mt('The domain has been configured to disable, by default, blog functionality for all users in the domain.').'</li>'.
                    320:                                '</ul>';
                    321:             } else {
                    322:                 $disabletext = &mt('No user blog available');
                    323:             }
                    324:         }
1.29      raeburn   325:     }
1.5       www       326:     if ($html) {
1.46      schafran  327: #	my $title = $displayfeedname?$displayfeedname:"Available RSS Feeds and Blogs";
                    328:         my $title = "My Space";
1.37      albertel  329: 	my $rss_link = &Apache::lonrss::rss_link($uname,$udom);
1.42      raeburn   330: 	my $brcrumb = [{href=>$rss_link,text=>"Available RSS Feeds and Blogs"}];
1.37      albertel  331: 	$r->print(&Apache::loncommon::start_page($title,$rss_link,
1.42      raeburn   332: 			 {'bread_crumbs'   => $brcrumb,
                    333: 			  'domain'         => $udom,
                    334: 			  'force_register' => $env{'form.register'}}).
1.8       albertel  335: 		  &changed_js());
1.18      www       336:     } else { # render RSS
1.29      raeburn   337:         my $server = &Apache::lonnet::absolute_url();
1.5       www       338: 	$r->print("<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1'>\n<channel>".
1.29      raeburn   339: 		  "\n".'<link>'.$server.'/public/'.$udom.'/'.$uname.'/'.
1.5       www       340: 		  $filterfeedname.'_rss.html</link>'.
                    341: 		  "\n<description>".
                    342: 		  &mt('An RSS Feed provided by the LON-CAPA Learning Content Management System').
                    343: 		  '</description>');
                    344:     }
1.21      www       345: # This will be the entry id for new additions to the blog
1.16      albertel  346:     my $newid = &get_new_feed_id();
1.1       www       347: # Is this user for real?
1.6       www       348:     my $homeserver=&Apache::lonnet::homeserver($uname,$udom);
1.41      raeburn   349:     if ($html && !$blocked && !$disabled) {
1.19      www       350: # Any new feeds or renaming of feeds?
                    351: 	if ($edit) {
1.20      www       352: # Hide a feed?
                    353: 	    if ($env{'form.hidethisblog'}) {
                    354: 		&changefeeddisplay($feedname,$uname,$udom,'hidden');
                    355: 		($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
                    356: 	    }
                    357: # Advertise a feed?
                    358: 	    if ($env{'form.advertisethisblog'}) {
                    359: 		&changefeeddisplay($feedname,$uname,$udom,'public');
                    360: 		($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
                    361: 	    }
1.19      www       362: # New feed?
                    363: 	    if ($env{'form.namenewblog'}=~/\w/) {
                    364: 		&namefeed($env{'form.namenewblog'},$uname,$udom,$env{'form.namenewblog'});
                    365: 	    }
                    366: # Old feed that is being renamed?
                    367: 	    if (($displayfeedname) && ($env{'form.newblogname'}=~/\w/)) {
                    368: 		if ($env{'form.newblogname'} ne $displayfeedname) {
                    369: 		    &namefeed($feedname,$uname,$udom,$env{'form.newblogname'});
1.20      www       370: 		    ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
1.19      www       371: 		}
                    372: 	    }
                    373: 	}
1.6       www       374: 	$r->print(&advertisefeeds($uname,$udom,$edit));
                    375:     } 
1.1       www       376:     if ($homeserver eq 'no_host') {
1.5       www       377: 	$r->print(($html?'<h3>':'<title>').&mt('No feed available').($html?'</h3>':'</title>'));
1.29      raeburn   378:     } elsif ($blocked) {
                    379:         $r->print($blocktext);
                    380:         $r->print(($html?&Apache::loncommon::end_page():'</channel></rss>'."\n"));
1.39      raeburn   381:     } elsif ($disabled) {
                    382:         $r->print($disabletext);
                    383:         $r->print(($html?&Apache::loncommon::end_page():'</channel></rss>'."\n"));
1.18      www       384:     } else { # is indeed a user
1.1       www       385: # Course or user?
                    386: 	my $name='';
1.32      albertel  387: 	if (&Apache::lonnet::is_course($udom,$uname)) {
1.1       www       388: 	    my %cenv=&Apache::lonnet::dump('environment',$udom,$uname);
                    389: 	    $name=$cenv{'description'};
                    390: 	} else {
                    391: 	    $name=&Apache::loncommon::nickname($uname,$udom);
                    392: 	}
1.19      www       393: # Add a new feed
                    394:         if (($html) && ($edit)) {
1.47      amueller  395: 	    $r->print('<h4>' . &mt('New RSS Feed or Blog'). '</h4>');
1.33      www       396: 	    $r->print('<form method="post" name="makenewfeed">');
1.45      schafran  397:             $r->print(&mt('Name').": <input type='text' size='40' name='namenewblog' />");
                    398: 	    $r->print('<input type="submit" value="'.&mt('New Feed').'" />');
1.19      www       399: 	    $r->print('</form>');
                    400: 	}
1.18      www       401:         if ($displayfeedname) { # this is an existing feed
                    402: # Anything to store?
                    403: 	    if ($edit) {
1.21      www       404: # check if this was called with a query string
                    405: 		&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['queryid']);
                    406: 		if ($env{'form.queryid'}) {
                    407: # yes, collect the remainder
                    408: 		    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    409: 							    ['title',
                    410: 							     'description',
                    411: 							     'url',
                    412: 							     'status',
                    413: 							     'enclosureurl',
                    414: 							     'enclosuretype']);
1.33      www       415: 
1.21      www       416: #    my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enctype)=@_;
                    417: 
1.33      www       418: 
1.21      www       419: 		    &editentry($env{'form.queryid'},
                    420: 			       $uname,$udom,$filename,
                    421: 			       $env{'form.title'},
                    422: 			       $env{'form.description'},
                    423: 			       $env{'form.url'},
                    424: 			       $env{'form.status'},
                    425: 			       $env{'form.encurl'},
                    426: 			       $env{'form.enctype'}
                    427: 			       );
                    428: 		}
1.33      www       429: 
                    430: # store away the fields modified in the online form
1.18      www       431: 		my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
                    432: 		foreach my $entry (sort(keys(%newsfeed)),$env{'form.newid'}.'_status') {
                    433: 		    if ($entry=~/^(\d+)\_status$/) {
                    434: 			my $id=$1;
                    435: 			if ($env{'form.'.$id.'_modified'}) {
                    436: 			    &editentry($id,$uname,$udom,$feedname,
                    437: 				       $env{'form.'.$id.'_title'},
                    438: 				       $env{'form.'.$id.'_description'},
1.28      albertel  439: 				       $env{'form.'.$id.'_link'},
1.21      www       440: 				       $env{'form.'.$id.'_status'},
                    441: 				       $env{'form.'.$id.'_enclosureurl'},
                    442: 				       $env{'form.'.$id.'_enclosuretype'},
                    443: 				       );
1.18      www       444: 			}
                    445: 		    }
                    446: 		}
1.33      www       447: 
                    448: # see if we have any uploaded or portfolio files
                    449:                 my @uploadeditems=();
                    450: 
                    451: 		if ($env{'form.HWFILE0_0'}) {
                    452: # We have an uploaded file - store it away.
                    453: 		    $uploadeditems[0]=&Apache::lonnet::userfileupload('HWFILE0_0',undef,'portfolio/podcasts');
                    454: 		}
                    455: 		if ($env{'form.HWPORT0_0'}) {
                    456: # Selected portfolio files
                    457: 		    foreach my $filename (split(/\,/,$env{'form.HWPORT0_0'})) {
                    458: 			if ($filename) {
                    459: # construct full path and remember
                    460: 			    push(@uploadeditems,'/uploaded/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/portfolio'.$filename);
                    461: 			}
                    462: 		    }
                    463: 		}
                    464: # the zeroth item should be stored together with the last displayed (newid) field
                    465: 		if ($uploadeditems[0]) {
                    466: 		    my $id=$env{'form.newid'};
                    467: 		    &editentry($id,$uname,$udom,$feedname,
                    468: 			       $env{'form.'.$id.'_title'},
                    469: 			       $env{'form.'.$id.'_description'},
                    470: 			       $env{'form.'.$id.'_link'},
                    471: 			       $env{'form.'.$id.'_status'},
                    472: 			       $uploadeditems[0],
                    473: 			       &Apache::loncommon::filemimetype(($uploadeditems[0]=~/\.(\w+)$/)[0]),
                    474: 			       );
                    475: 		    &Apache::lonnet::make_public_indefinitely($uploadeditems[0]);
                    476: 		}
                    477: # if there are more files, they need new entries, since each can only have one enclosure
                    478: 		for (my $i=1; $i<=$#uploadeditems; $i++) {
                    479: 		    my $id = &get_new_feed_id().$i;
                    480: 		    &editentry($id,$uname,$udom,$feedname,
                    481: 			       'New Entry',
                    482: 			       '',
                    483: 			       '',
                    484: 			       'public',
                    485: 			       $uploadeditems[$i],
                    486: 			       &Apache::loncommon::filemimetype(($uploadeditems[$i]=~/\.(\w+)$/)[0]),
                    487: 			       );
                    488: 		    &Apache::lonnet::make_public_indefinitely($uploadeditems[$i]);
                    489: 		}
1.18      www       490: 	    } #done storing
                    491: 
1.29      raeburn   492: # Render private items?
                    493:             my $viewpubliconly=1;
1.18      www       494: 	    $r->print("\n".
1.19      www       495: 		      ($html?'<hr /><h3>':'<title>').
1.18      www       496: 		      &mt('LON-CAPA Feed "[_1]" for [_2]',$displayfeedname,$name).
1.20      www       497: 		      ($displayoption eq 'hidden'?' ('.&mt('Hidden').')':'').
1.33      www       498: 		      ($html?'</h3>'.($edit?'<form method="post" name="lonhomework" enctype="multipart/form-data"><br />'.
1.21      www       499: 				      &mt('Name of this Feed').
1.18      www       500: 				      ': <input type="text" size="50" name="newblogname" value="'.
                    501: 				      $displayfeedname.'" />':'').'<ul>':'</title>'));
                    502: 	    if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
                    503: 		$viewpubliconly=0;
1.29      raeburn   504:             }
1.1       www       505: # Get feed items
1.18      www       506: 	    my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
1.36      albertel  507: 	    foreach my $entry (sort {$b cmp $a} (keys(%newsfeed)),$newid.'_status') {
1.18      www       508: 		if ($entry=~/^(\d+)\_status$/) { # is an entry
                    509: 		    my $id=$1;
                    510: 		    if ($edit) {
                    511: 			my %lt=&Apache::lonlocal::texthash('public' => 'public',
                    512: 							   'private' => 'private',
                    513: 							   'hidden' => 'hidden',
                    514: 							   'delete' => 'delete',
1.45      schafran  515: 							   'store' => 'Select',
1.18      www       516: 							   'title' => 'Title',
                    517: 							   'link' => 'Link',
1.33      www       518: 							   'description' => 'Description',
                    519:                                                            'enc' => 'Podcasted enclosure');
                    520:                         my $uploadlink;
                    521:                         if ($entry==$newid) {
                    522: # Generate upload link only for last (new) entry
                    523: 			    $uploadlink=&Apache::inputtags::file_selector(0,0,'*','both');
                    524: 			} else {
                    525: # Otherwise, display
                    526:                             $uploadlink='<tt>'.$newsfeed{$id.'_enclosureurl'}.'</tt>'.
                    527: 				"<input type='hidden' name='$id\_enclosureurl' value='$newsfeed{$id.'_enclosureurl'}' />".
                    528: 				"<input type='hidden' name='$id\_enclosuretype' value='$newsfeed{$id.'_enclosuretype'}' />";
                    529: 			}
1.18      www       530: 			my %status=();
                    531: 			unless ($newsfeed{$id.'_status'}) { $newsfeed{$id.'_status'}='public'; }
                    532: 			$status{$newsfeed{$id.'_status'}}='checked="checked"';
                    533: 			$r->print(<<ENDEDIT);
1.5       www       534: <li>
1.15      www       535: <label><input name='$id\_modified' type='checkbox' value="modified" /> $lt{'store'}</label>
1.6       www       536: &nbsp;&nbsp;
                    537: <label><input name='$id\_status' type="radio" value="public" $status{'public'} onClick="changed(this.form,'$id');" /> $lt{'public'}</label>
1.5       www       538: &nbsp;&nbsp;
1.6       www       539: <label><input name='$id\_status' type="radio" value="private" $status{'private'} onClick="changed(this.form,'$id');" /> $lt{'private'}</label>
1.5       www       540: &nbsp;&nbsp;
1.6       www       541: <label><input name='$id\_status' type="radio" value="hidden" $status{'hidden'} onClick="changed(this.form,'$id');" /> $lt{'hidden'}</label>
1.5       www       542: &nbsp;&nbsp;
1.15      www       543: <label><input name='$id\_status' type="radio" value="deleted" onClick="changed(this.form,'$id');" /> $lt{'delete'}</label>
1.5       www       544: <br />
1.18      www       545: $lt{'title'}:
                    546: <input name='$id\_title' type='text' size='60' value='$newsfeed{$id.'_title'}' onChange="changed(this.form,'$id');" /><br />
                    547: $lt{'description'}:<br />
1.6       www       548: <textarea name='$id\_description' rows="6" cols="80" onChange="changed(this.form,'$id');">$newsfeed{$id.'_description'}</textarea><br />
1.18      www       549: $lt{'link'}:
1.33      www       550: <input name='$id\_link' type='text' size='60' value='$newsfeed{$id.'_link'}' onChange="changed(this.form,'$id');" /><br />
                    551: $lt{'enc'} -
                    552: $uploadlink
1.6       www       553: <hr /></li>
1.5       www       554: ENDEDIT
1.18      www       555: 		    } else { # not in edit mode, just displaying
                    556: 			if (($newsfeed{$id.'_status'} ne 'public') && ($viewpubliconly)) { next; }
                    557: 			if ($newsfeed{$id.'_status'} eq 'hidden') { next; }
1.28      albertel  558: 			my $link =  $newsfeed{$id.'_link'};
                    559: 			if ($link =~ m|^/| ) {
                    560: 			    $link = "http://".$ENV{'HTTP_HOST'}.$link;
                    561: 			}
1.18      www       562: 			$r->print("\n".($html?"\n<li><b>":"<item>\n<title>").$newsfeed{$id.'_title'}.
                    563: 				  ($html?"</b><br />\n":"</title>\n<description>").
                    564: 				  $newsfeed{$id.'_description'}.
1.33      www       565: 				  ($html?"<br />":"</description>\n").
                    566: 				  ($link?($html?"\n<a href='":"<link>").
1.28      albertel  567: 				  $link.
1.33      www       568: 				  ($html?("'>".&mt('Read more')."</a><br />\n"):"</link>\n"):''));
                    569: 			my $enclosure=$newsfeed{$id.'_enclosureurl'};
1.17      www       570: # Enclosure? Get stats
1.33      www       571: 			if ($enclosure) {
                    572: 			    my @stat=&Apache::lonnet::stat_file($enclosure);
1.18      www       573: 			    if ($stat[7]) {
1.17      www       574: # Has non-zero length (and exists)
1.33      www       575: 				my $enclosuretype=$newsfeed{$id.'_enclosuretype'};
                    576: 				if ($enclosure =~ m|^/| ) {
                    577: 				    $enclosure = "http://".$ENV{'HTTP_HOST'}.$enclosure;
                    578: 				}
1.18      www       579: 				$r->print(($html?"<a href='":"\n<enclosure url='").
1.33      www       580: 					  $enclosure."' length='".$stat[7].
1.18      www       581: 					  "' type='".$enclosuretype.($html?"'>".&mt('Enclosure')."</a>":"' />"));
                    582: 			    }
                    583: 			}
                    584: 			if ($html) { # is HTML
                    585: 			    $r->print("\n<hr /></li>\n");
                    586: 			} else { # is RSS
                    587: 			    $r->print("\n<guid isPermaLink='false'>".$id.$filterfeedname.'_'.$udom.'_'.$uname."</guid></item>\n");
1.17      www       588: 			}
1.18      www       589: 		    } # end of "in edit mode"
                    590: 		} # end of rendering a real entry
                    591: 	    } # end of loop through all keys
                    592: 	    if ($html) {
                    593: 		$r->print('</ul>');
                    594: 		if ($edit) {
1.45      schafran  595: 		    $r->print('<input type="hidden" name="newid" value="'.$newid.'"/><input type="submit" value="'.&mt('Save Selected').'" />'.
1.20      www       596: 			      ($displayoption eq 'hidden'?'<input type="submit" name="advertisethisblog" value="'.&mt('Advertise this Feed').'" />':
                    597: 			       '<input type="submit" name="hidethisblog" value="'.&mt('Hide this Feed').'" />'));
1.1       www       598: 		}
                    599: 	    }
1.18      www       600: 	} # was a real display feedname
                    601: 	$r->print(($html?'</form>'.&Apache::loncommon::end_page():'</channel></rss>'."\n"));
                    602:     } # a real user
1.1       www       603:     return OK;
1.18      www       604: } # end handler
1.1       www       605: 1;
                    606: __END__

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