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

1.1       www         1: # The LearningOnline Network
                      2: # RSS Feeder
                      3: #
1.50    ! raeburn     4: # $Id: lonrss.pm,v 1.49 2009/11/04 15:38:27 raeburn 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');
1.49      raeburn    64:         if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Community') {
                     65:             $name = &mt('Community Blog'); 
                     66:         }
1.2       www        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) {
1.48      kalberla  264:                 #$output .= '<br />'.
                    265:                        #&Apache::loncommon::build_block_table($startblock,
                    266:                        #                                 $endblock,\%setters);
                    267:                  my ($blocked, $blocktext) = Apache::loncommon::blocking_status('blogs');
                    268:                  $output .= '<br /><br />'.$blocktext;
1.29      raeburn   269:             }
                    270:         } else {
                    271:             $output .= &mt('This is because the blog owner is a student in one or more courses in which communication is being blocked.');
                    272:         }
                    273:         if (!$html) {
                    274:             my $id = &get_new_feed_id();
                    275:             $output = '<title/><item><title/><description>'.$output."</description><link/><guid isPermaLink='false'>".$id.$filterfeedname.'_'.$udom.'_'.$uname.'</guid></item>';
                    276:         }
                    277:     }
                    278:     return ($blocked,$output);
                    279: }
                    280: 
1.1       www       281: sub handler {
1.8       albertel  282:     my ($r) = @_;
1.5       www       283: 
                    284:     my $edit=0;
                    285:     my $html=0;
                    286:     my (undef,$mode,$udom,$uname,$filename)=split(/\//,$r->uri);
                    287:     if (($mode eq 'adm') && ($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
                    288: 	$edit=1;
                    289: 	$html=1;
                    290:     }
1.50    ! raeburn   291:     if  (($mode eq 'adm') && (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))
        !           292:         && ($uname eq $env{'course.'.$env{'request.course.id'}.'.num'} &&
        !           293:             $udom eq $env{'course.'.$env{'request.course.id'}.'.domain'})) {
1.21      www       294: 	$edit=1;
                    295: 	$html=1;
                    296:     }
1.5       www       297:     if ($filename=~/\.html$/) {
                    298: 	$html=1;
                    299:     }
                    300:     if ($html) {
                    301: 	&Apache::loncommon::content_type($r,'text/html');
                    302:     } else {
                    303: # Workaround Mozilla/Firefox
                    304: #	&Apache::loncommon::content_type($r,'application/rss+xml');
                    305: 	&Apache::loncommon::content_type($r,'text/xml');
                    306:     }
1.1       www       307:     $r->send_http_header;
                    308:     return OK if $r->header_only;
                    309: 
                    310:     my $filterfeedname=&filterfeedname($filename);
                    311:     my $feedname=&feedname($filename);
1.20      www       312:     my ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
1.39      raeburn   313:     my ($blocked,$blocktext,$disabled,$disabletext);
1.32      albertel  314:     if (!&Apache::lonnet::is_course($udom,$uname)) {
1.29      raeburn   315:         ($blocked,$blocktext) = &blocking_blogdisplay($uname,$udom,$html,$filterfeedname);
1.44      raeburn   316:         if (&Apache::lonnet::usertools_access($uname,$udom,'blog')) {
                    317:             $disabled = 0;
                    318:         } else {
1.43      raeburn   319:             $disabled = 1;
1.39      raeburn   320:             if ($html) {
                    321:                 $disabletext = '<h2>'.&mt('No user blog available') .'</h2>'.
                    322:                                &mt('This is a result of one of the following:').'<ul>'.
                    323:                                '<li>'.&mt('The administrator of this domain has disabled blog functionality for this specific user.').'</li>'.
                    324:                                '<li>'.&mt('The domain has been configured to disable, by default, blog functionality for all users in the domain.').'</li>'.
                    325:                                '</ul>';
                    326:             } else {
                    327:                 $disabletext = &mt('No user blog available');
                    328:             }
                    329:         }
1.29      raeburn   330:     }
1.5       www       331:     if ($html) {
1.46      schafran  332: #	my $title = $displayfeedname?$displayfeedname:"Available RSS Feeds and Blogs";
                    333:         my $title = "My Space";
1.37      albertel  334: 	my $rss_link = &Apache::lonrss::rss_link($uname,$udom);
1.42      raeburn   335: 	my $brcrumb = [{href=>$rss_link,text=>"Available RSS Feeds and Blogs"}];
1.37      albertel  336: 	$r->print(&Apache::loncommon::start_page($title,$rss_link,
1.42      raeburn   337: 			 {'bread_crumbs'   => $brcrumb,
                    338: 			  'domain'         => $udom,
                    339: 			  'force_register' => $env{'form.register'}}).
1.8       albertel  340: 		  &changed_js());
1.18      www       341:     } else { # render RSS
1.29      raeburn   342:         my $server = &Apache::lonnet::absolute_url();
1.5       www       343: 	$r->print("<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1'>\n<channel>".
1.29      raeburn   344: 		  "\n".'<link>'.$server.'/public/'.$udom.'/'.$uname.'/'.
1.5       www       345: 		  $filterfeedname.'_rss.html</link>'.
                    346: 		  "\n<description>".
                    347: 		  &mt('An RSS Feed provided by the LON-CAPA Learning Content Management System').
                    348: 		  '</description>');
                    349:     }
1.21      www       350: # This will be the entry id for new additions to the blog
1.16      albertel  351:     my $newid = &get_new_feed_id();
1.1       www       352: # Is this user for real?
1.6       www       353:     my $homeserver=&Apache::lonnet::homeserver($uname,$udom);
1.41      raeburn   354:     if ($html && !$blocked && !$disabled) {
1.19      www       355: # Any new feeds or renaming of feeds?
                    356: 	if ($edit) {
1.20      www       357: # Hide a feed?
                    358: 	    if ($env{'form.hidethisblog'}) {
                    359: 		&changefeeddisplay($feedname,$uname,$udom,'hidden');
                    360: 		($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
                    361: 	    }
                    362: # Advertise a feed?
                    363: 	    if ($env{'form.advertisethisblog'}) {
                    364: 		&changefeeddisplay($feedname,$uname,$udom,'public');
                    365: 		($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
                    366: 	    }
1.19      www       367: # New feed?
                    368: 	    if ($env{'form.namenewblog'}=~/\w/) {
                    369: 		&namefeed($env{'form.namenewblog'},$uname,$udom,$env{'form.namenewblog'});
                    370: 	    }
                    371: # Old feed that is being renamed?
                    372: 	    if (($displayfeedname) && ($env{'form.newblogname'}=~/\w/)) {
                    373: 		if ($env{'form.newblogname'} ne $displayfeedname) {
                    374: 		    &namefeed($feedname,$uname,$udom,$env{'form.newblogname'});
1.20      www       375: 		    ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
1.19      www       376: 		}
                    377: 	    }
                    378: 	}
1.6       www       379: 	$r->print(&advertisefeeds($uname,$udom,$edit));
                    380:     } 
1.1       www       381:     if ($homeserver eq 'no_host') {
1.5       www       382: 	$r->print(($html?'<h3>':'<title>').&mt('No feed available').($html?'</h3>':'</title>'));
1.29      raeburn   383:     } elsif ($blocked) {
                    384:         $r->print($blocktext);
                    385:         $r->print(($html?&Apache::loncommon::end_page():'</channel></rss>'."\n"));
1.39      raeburn   386:     } elsif ($disabled) {
                    387:         $r->print($disabletext);
                    388:         $r->print(($html?&Apache::loncommon::end_page():'</channel></rss>'."\n"));
1.18      www       389:     } else { # is indeed a user
1.1       www       390: # Course or user?
                    391: 	my $name='';
1.32      albertel  392: 	if (&Apache::lonnet::is_course($udom,$uname)) {
1.1       www       393: 	    my %cenv=&Apache::lonnet::dump('environment',$udom,$uname);
                    394: 	    $name=$cenv{'description'};
                    395: 	} else {
                    396: 	    $name=&Apache::loncommon::nickname($uname,$udom);
                    397: 	}
1.19      www       398: # Add a new feed
                    399:         if (($html) && ($edit)) {
1.47      amueller  400: 	    $r->print('<h4>' . &mt('New RSS Feed or Blog'). '</h4>');
1.33      www       401: 	    $r->print('<form method="post" name="makenewfeed">');
1.45      schafran  402:             $r->print(&mt('Name').": <input type='text' size='40' name='namenewblog' />");
                    403: 	    $r->print('<input type="submit" value="'.&mt('New Feed').'" />');
1.19      www       404: 	    $r->print('</form>');
                    405: 	}
1.18      www       406:         if ($displayfeedname) { # this is an existing feed
                    407: # Anything to store?
                    408: 	    if ($edit) {
1.21      www       409: # check if this was called with a query string
                    410: 		&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['queryid']);
                    411: 		if ($env{'form.queryid'}) {
                    412: # yes, collect the remainder
                    413: 		    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    414: 							    ['title',
                    415: 							     'description',
                    416: 							     'url',
                    417: 							     'status',
                    418: 							     'enclosureurl',
                    419: 							     'enclosuretype']);
1.33      www       420: 
1.21      www       421: #    my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enctype)=@_;
                    422: 
1.33      www       423: 
1.21      www       424: 		    &editentry($env{'form.queryid'},
                    425: 			       $uname,$udom,$filename,
                    426: 			       $env{'form.title'},
                    427: 			       $env{'form.description'},
                    428: 			       $env{'form.url'},
                    429: 			       $env{'form.status'},
                    430: 			       $env{'form.encurl'},
                    431: 			       $env{'form.enctype'}
                    432: 			       );
                    433: 		}
1.33      www       434: 
                    435: # store away the fields modified in the online form
1.18      www       436: 		my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
                    437: 		foreach my $entry (sort(keys(%newsfeed)),$env{'form.newid'}.'_status') {
                    438: 		    if ($entry=~/^(\d+)\_status$/) {
                    439: 			my $id=$1;
                    440: 			if ($env{'form.'.$id.'_modified'}) {
                    441: 			    &editentry($id,$uname,$udom,$feedname,
                    442: 				       $env{'form.'.$id.'_title'},
                    443: 				       $env{'form.'.$id.'_description'},
1.28      albertel  444: 				       $env{'form.'.$id.'_link'},
1.21      www       445: 				       $env{'form.'.$id.'_status'},
                    446: 				       $env{'form.'.$id.'_enclosureurl'},
                    447: 				       $env{'form.'.$id.'_enclosuretype'},
                    448: 				       );
1.18      www       449: 			}
                    450: 		    }
                    451: 		}
1.33      www       452: 
                    453: # see if we have any uploaded or portfolio files
                    454:                 my @uploadeditems=();
                    455: 
                    456: 		if ($env{'form.HWFILE0_0'}) {
                    457: # We have an uploaded file - store it away.
                    458: 		    $uploadeditems[0]=&Apache::lonnet::userfileupload('HWFILE0_0',undef,'portfolio/podcasts');
                    459: 		}
                    460: 		if ($env{'form.HWPORT0_0'}) {
                    461: # Selected portfolio files
                    462: 		    foreach my $filename (split(/\,/,$env{'form.HWPORT0_0'})) {
                    463: 			if ($filename) {
                    464: # construct full path and remember
                    465: 			    push(@uploadeditems,'/uploaded/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/portfolio'.$filename);
                    466: 			}
                    467: 		    }
                    468: 		}
                    469: # the zeroth item should be stored together with the last displayed (newid) field
                    470: 		if ($uploadeditems[0]) {
                    471: 		    my $id=$env{'form.newid'};
                    472: 		    &editentry($id,$uname,$udom,$feedname,
                    473: 			       $env{'form.'.$id.'_title'},
                    474: 			       $env{'form.'.$id.'_description'},
                    475: 			       $env{'form.'.$id.'_link'},
                    476: 			       $env{'form.'.$id.'_status'},
                    477: 			       $uploadeditems[0],
                    478: 			       &Apache::loncommon::filemimetype(($uploadeditems[0]=~/\.(\w+)$/)[0]),
                    479: 			       );
                    480: 		    &Apache::lonnet::make_public_indefinitely($uploadeditems[0]);
                    481: 		}
                    482: # if there are more files, they need new entries, since each can only have one enclosure
                    483: 		for (my $i=1; $i<=$#uploadeditems; $i++) {
                    484: 		    my $id = &get_new_feed_id().$i;
                    485: 		    &editentry($id,$uname,$udom,$feedname,
                    486: 			       'New Entry',
                    487: 			       '',
                    488: 			       '',
                    489: 			       'public',
                    490: 			       $uploadeditems[$i],
                    491: 			       &Apache::loncommon::filemimetype(($uploadeditems[$i]=~/\.(\w+)$/)[0]),
                    492: 			       );
                    493: 		    &Apache::lonnet::make_public_indefinitely($uploadeditems[$i]);
                    494: 		}
1.18      www       495: 	    } #done storing
                    496: 
1.29      raeburn   497: # Render private items?
                    498:             my $viewpubliconly=1;
1.18      www       499: 	    $r->print("\n".
1.19      www       500: 		      ($html?'<hr /><h3>':'<title>').
1.18      www       501: 		      &mt('LON-CAPA Feed "[_1]" for [_2]',$displayfeedname,$name).
1.20      www       502: 		      ($displayoption eq 'hidden'?' ('.&mt('Hidden').')':'').
1.33      www       503: 		      ($html?'</h3>'.($edit?'<form method="post" name="lonhomework" enctype="multipart/form-data"><br />'.
1.21      www       504: 				      &mt('Name of this Feed').
1.18      www       505: 				      ': <input type="text" size="50" name="newblogname" value="'.
                    506: 				      $displayfeedname.'" />':'').'<ul>':'</title>'));
                    507: 	    if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
                    508: 		$viewpubliconly=0;
1.29      raeburn   509:             }
1.1       www       510: # Get feed items
1.18      www       511: 	    my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
1.36      albertel  512: 	    foreach my $entry (sort {$b cmp $a} (keys(%newsfeed)),$newid.'_status') {
1.18      www       513: 		if ($entry=~/^(\d+)\_status$/) { # is an entry
                    514: 		    my $id=$1;
                    515: 		    if ($edit) {
                    516: 			my %lt=&Apache::lonlocal::texthash('public' => 'public',
                    517: 							   'private' => 'private',
                    518: 							   'hidden' => 'hidden',
                    519: 							   'delete' => 'delete',
1.45      schafran  520: 							   'store' => 'Select',
1.18      www       521: 							   'title' => 'Title',
                    522: 							   'link' => 'Link',
1.33      www       523: 							   'description' => 'Description',
                    524:                                                            'enc' => 'Podcasted enclosure');
                    525:                         my $uploadlink;
                    526:                         if ($entry==$newid) {
                    527: # Generate upload link only for last (new) entry
                    528: 			    $uploadlink=&Apache::inputtags::file_selector(0,0,'*','both');
                    529: 			} else {
                    530: # Otherwise, display
                    531:                             $uploadlink='<tt>'.$newsfeed{$id.'_enclosureurl'}.'</tt>'.
                    532: 				"<input type='hidden' name='$id\_enclosureurl' value='$newsfeed{$id.'_enclosureurl'}' />".
                    533: 				"<input type='hidden' name='$id\_enclosuretype' value='$newsfeed{$id.'_enclosuretype'}' />";
                    534: 			}
1.18      www       535: 			my %status=();
                    536: 			unless ($newsfeed{$id.'_status'}) { $newsfeed{$id.'_status'}='public'; }
                    537: 			$status{$newsfeed{$id.'_status'}}='checked="checked"';
                    538: 			$r->print(<<ENDEDIT);
1.5       www       539: <li>
1.15      www       540: <label><input name='$id\_modified' type='checkbox' value="modified" /> $lt{'store'}</label>
1.6       www       541: &nbsp;&nbsp;
                    542: <label><input name='$id\_status' type="radio" value="public" $status{'public'} onClick="changed(this.form,'$id');" /> $lt{'public'}</label>
1.5       www       543: &nbsp;&nbsp;
1.6       www       544: <label><input name='$id\_status' type="radio" value="private" $status{'private'} onClick="changed(this.form,'$id');" /> $lt{'private'}</label>
1.5       www       545: &nbsp;&nbsp;
1.6       www       546: <label><input name='$id\_status' type="radio" value="hidden" $status{'hidden'} onClick="changed(this.form,'$id');" /> $lt{'hidden'}</label>
1.5       www       547: &nbsp;&nbsp;
1.15      www       548: <label><input name='$id\_status' type="radio" value="deleted" onClick="changed(this.form,'$id');" /> $lt{'delete'}</label>
1.5       www       549: <br />
1.18      www       550: $lt{'title'}:
                    551: <input name='$id\_title' type='text' size='60' value='$newsfeed{$id.'_title'}' onChange="changed(this.form,'$id');" /><br />
                    552: $lt{'description'}:<br />
1.6       www       553: <textarea name='$id\_description' rows="6" cols="80" onChange="changed(this.form,'$id');">$newsfeed{$id.'_description'}</textarea><br />
1.18      www       554: $lt{'link'}:
1.33      www       555: <input name='$id\_link' type='text' size='60' value='$newsfeed{$id.'_link'}' onChange="changed(this.form,'$id');" /><br />
                    556: $lt{'enc'} -
                    557: $uploadlink
1.6       www       558: <hr /></li>
1.5       www       559: ENDEDIT
1.18      www       560: 		    } else { # not in edit mode, just displaying
                    561: 			if (($newsfeed{$id.'_status'} ne 'public') && ($viewpubliconly)) { next; }
                    562: 			if ($newsfeed{$id.'_status'} eq 'hidden') { next; }
1.28      albertel  563: 			my $link =  $newsfeed{$id.'_link'};
                    564: 			if ($link =~ m|^/| ) {
                    565: 			    $link = "http://".$ENV{'HTTP_HOST'}.$link;
                    566: 			}
1.18      www       567: 			$r->print("\n".($html?"\n<li><b>":"<item>\n<title>").$newsfeed{$id.'_title'}.
                    568: 				  ($html?"</b><br />\n":"</title>\n<description>").
                    569: 				  $newsfeed{$id.'_description'}.
1.33      www       570: 				  ($html?"<br />":"</description>\n").
                    571: 				  ($link?($html?"\n<a href='":"<link>").
1.28      albertel  572: 				  $link.
1.33      www       573: 				  ($html?("'>".&mt('Read more')."</a><br />\n"):"</link>\n"):''));
                    574: 			my $enclosure=$newsfeed{$id.'_enclosureurl'};
1.17      www       575: # Enclosure? Get stats
1.33      www       576: 			if ($enclosure) {
                    577: 			    my @stat=&Apache::lonnet::stat_file($enclosure);
1.18      www       578: 			    if ($stat[7]) {
1.17      www       579: # Has non-zero length (and exists)
1.33      www       580: 				my $enclosuretype=$newsfeed{$id.'_enclosuretype'};
                    581: 				if ($enclosure =~ m|^/| ) {
                    582: 				    $enclosure = "http://".$ENV{'HTTP_HOST'}.$enclosure;
                    583: 				}
1.18      www       584: 				$r->print(($html?"<a href='":"\n<enclosure url='").
1.33      www       585: 					  $enclosure."' length='".$stat[7].
1.18      www       586: 					  "' type='".$enclosuretype.($html?"'>".&mt('Enclosure')."</a>":"' />"));
                    587: 			    }
                    588: 			}
                    589: 			if ($html) { # is HTML
                    590: 			    $r->print("\n<hr /></li>\n");
                    591: 			} else { # is RSS
                    592: 			    $r->print("\n<guid isPermaLink='false'>".$id.$filterfeedname.'_'.$udom.'_'.$uname."</guid></item>\n");
1.17      www       593: 			}
1.18      www       594: 		    } # end of "in edit mode"
                    595: 		} # end of rendering a real entry
                    596: 	    } # end of loop through all keys
                    597: 	    if ($html) {
                    598: 		$r->print('</ul>');
                    599: 		if ($edit) {
1.45      schafran  600: 		    $r->print('<input type="hidden" name="newid" value="'.$newid.'"/><input type="submit" value="'.&mt('Save Selected').'" />'.
1.20      www       601: 			      ($displayoption eq 'hidden'?'<input type="submit" name="advertisethisblog" value="'.&mt('Advertise this Feed').'" />':
                    602: 			       '<input type="submit" name="hidethisblog" value="'.&mt('Hide this Feed').'" />'));
1.1       www       603: 		}
                    604: 	    }
1.18      www       605: 	} # was a real display feedname
                    606: 	$r->print(($html?'</form>'.&Apache::loncommon::end_page():'</channel></rss>'."\n"));
                    607:     } # a real user
1.1       www       608:     return OK;
1.18      www       609: } # end handler
1.1       www       610: 1;
                    611: __END__

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