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

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

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