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

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

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