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