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

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

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