Annotation of loncom/interface/lonrss.pm, revision 1.57
1.1 www 1: # The LearningOnline Network
2: # RSS Feeder
3: #
1.57 ! raeburn 4: # $Id: lonrss.pm,v 1.56 2017/01/01 13:50:06 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.56 raeburn 131: } elsif (!$edit) {
1.55 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: '&title='.&escape($title).
237: '&description='.&escape($description).
238: '&url='.&escape($url).
239: '&status='.&escape($status).
240: '&encurl='.&escape($encurl).
241: '&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.57 ! raeburn 348: my $head_extra = $rss_link.'<script type="text/javascript" '
! 349: 'src="/res/adm/includes/file_upload.js"></script>';
1.42 raeburn 350: my $brcrumb = [{href=>$rss_link,text=>"Available RSS Feeds and Blogs"}];
1.54 musolffc 351: $r->print(&Apache::loncommon::start_page($title,$head_extra,
1.42 raeburn 352: {'bread_crumbs' => $brcrumb,
353: 'domain' => $udom,
354: 'force_register' => $env{'form.register'}}).
1.8 albertel 355: &changed_js());
1.18 www 356: } else { # render RSS
1.29 raeburn 357: my $server = &Apache::lonnet::absolute_url();
1.5 www 358: $r->print("<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1'>\n<channel>".
1.29 raeburn 359: "\n".'<link>'.$server.'/public/'.$udom.'/'.$uname.'/'.
1.5 www 360: $filterfeedname.'_rss.html</link>'.
361: "\n<description>".
362: &mt('An RSS Feed provided by the LON-CAPA Learning Content Management System').
363: '</description>');
364: }
1.21 www 365: # This will be the entry id for new additions to the blog
1.16 albertel 366: my $newid = &get_new_feed_id();
1.1 www 367: # Is this user for real?
1.6 www 368: my $homeserver=&Apache::lonnet::homeserver($uname,$udom);
1.41 raeburn 369: if ($html && !$blocked && !$disabled) {
1.19 www 370: # Any new feeds or renaming of feeds?
371: if ($edit) {
1.20 www 372: # Hide a feed?
373: if ($env{'form.hidethisblog'}) {
374: &changefeeddisplay($feedname,$uname,$udom,'hidden');
375: ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
376: }
377: # Advertise a feed?
378: if ($env{'form.advertisethisblog'}) {
379: &changefeeddisplay($feedname,$uname,$udom,'public');
380: ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
381: }
1.19 www 382: # New feed?
383: if ($env{'form.namenewblog'}=~/\w/) {
384: &namefeed($env{'form.namenewblog'},$uname,$udom,$env{'form.namenewblog'});
385: }
386: # Old feed that is being renamed?
387: if (($displayfeedname) && ($env{'form.newblogname'}=~/\w/)) {
388: if ($env{'form.newblogname'} ne $displayfeedname) {
389: &namefeed($feedname,$uname,$udom,$env{'form.newblogname'});
1.20 www 390: ($displayfeedname,$displayoption)=&displayfeedname($filename,$uname,$udom);
1.19 www 391: }
392: }
393: }
1.6 www 394: $r->print(&advertisefeeds($uname,$udom,$edit));
395: }
1.1 www 396: if ($homeserver eq 'no_host') {
1.5 www 397: $r->print(($html?'<h3>':'<title>').&mt('No feed available').($html?'</h3>':'</title>'));
1.29 raeburn 398: } elsif ($blocked) {
399: $r->print($blocktext);
400: $r->print(($html?&Apache::loncommon::end_page():'</channel></rss>'."\n"));
1.39 raeburn 401: } elsif ($disabled) {
402: $r->print($disabletext);
403: $r->print(($html?&Apache::loncommon::end_page():'</channel></rss>'."\n"));
1.18 www 404: } else { # is indeed a user
1.1 www 405: # Course or user?
406: my $name='';
1.32 albertel 407: if (&Apache::lonnet::is_course($udom,$uname)) {
1.1 www 408: my %cenv=&Apache::lonnet::dump('environment',$udom,$uname);
409: $name=$cenv{'description'};
410: } else {
411: $name=&Apache::loncommon::nickname($uname,$udom);
412: }
1.19 www 413: # Add a new feed
414: if (($html) && ($edit)) {
1.47 amueller 415: $r->print('<h4>' . &mt('New RSS Feed or Blog'). '</h4>');
1.52 raeburn 416: $r->print('<form method="post" name="makenewfeed" action="">');
1.45 schafran 417: $r->print(&mt('Name').": <input type='text' size='40' name='namenewblog' />");
418: $r->print('<input type="submit" value="'.&mt('New Feed').'" />');
1.19 www 419: $r->print('</form>');
420: }
1.18 www 421: if ($displayfeedname) { # this is an existing feed
422: # Anything to store?
423: if ($edit) {
1.21 www 424: # check if this was called with a query string
425: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['queryid']);
426: if ($env{'form.queryid'}) {
427: # yes, collect the remainder
428: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
429: ['title',
430: 'description',
431: 'url',
432: 'status',
433: 'enclosureurl',
434: 'enclosuretype']);
1.33 www 435:
1.21 www 436: # my ($id,$uname,$udom,$filename,$title,$description,$url,$status,$encurl,$enctype)=@_;
437:
1.33 www 438:
1.21 www 439: &editentry($env{'form.queryid'},
440: $uname,$udom,$filename,
441: $env{'form.title'},
442: $env{'form.description'},
443: $env{'form.url'},
444: $env{'form.status'},
445: $env{'form.encurl'},
446: $env{'form.enctype'}
447: );
448: }
1.33 www 449:
450: # store away the fields modified in the online form
1.18 www 451: my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
452: foreach my $entry (sort(keys(%newsfeed)),$env{'form.newid'}.'_status') {
453: if ($entry=~/^(\d+)\_status$/) {
454: my $id=$1;
455: if ($env{'form.'.$id.'_modified'}) {
456: &editentry($id,$uname,$udom,$feedname,
457: $env{'form.'.$id.'_title'},
458: $env{'form.'.$id.'_description'},
1.28 albertel 459: $env{'form.'.$id.'_link'},
1.21 www 460: $env{'form.'.$id.'_status'},
461: $env{'form.'.$id.'_enclosureurl'},
462: $env{'form.'.$id.'_enclosuretype'},
463: );
1.18 www 464: }
465: }
466: }
1.33 www 467:
468: # see if we have any uploaded or portfolio files
469: my @uploadeditems=();
470:
471: if ($env{'form.HWFILE0_0'}) {
472: # We have an uploaded file - store it away.
473: $uploadeditems[0]=&Apache::lonnet::userfileupload('HWFILE0_0',undef,'portfolio/podcasts');
474: }
475: if ($env{'form.HWPORT0_0'}) {
476: # Selected portfolio files
477: foreach my $filename (split(/\,/,$env{'form.HWPORT0_0'})) {
478: if ($filename) {
479: # construct full path and remember
480: push(@uploadeditems,'/uploaded/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/portfolio'.$filename);
481: }
482: }
483: }
484: # the zeroth item should be stored together with the last displayed (newid) field
485: if ($uploadeditems[0]) {
486: my $id=$env{'form.newid'};
487: &editentry($id,$uname,$udom,$feedname,
488: $env{'form.'.$id.'_title'},
489: $env{'form.'.$id.'_description'},
490: $env{'form.'.$id.'_link'},
491: $env{'form.'.$id.'_status'},
492: $uploadeditems[0],
493: &Apache::loncommon::filemimetype(($uploadeditems[0]=~/\.(\w+)$/)[0]),
494: );
495: &Apache::lonnet::make_public_indefinitely($uploadeditems[0]);
496: }
497: # if there are more files, they need new entries, since each can only have one enclosure
498: for (my $i=1; $i<=$#uploadeditems; $i++) {
499: my $id = &get_new_feed_id().$i;
500: &editentry($id,$uname,$udom,$feedname,
501: 'New Entry',
502: '',
503: '',
504: 'public',
505: $uploadeditems[$i],
506: &Apache::loncommon::filemimetype(($uploadeditems[$i]=~/\.(\w+)$/)[0]),
507: );
508: &Apache::lonnet::make_public_indefinitely($uploadeditems[$i]);
509: }
1.18 www 510: } #done storing
511:
1.29 raeburn 512: # Render private items?
513: my $viewpubliconly=1;
1.18 www 514: $r->print("\n".
1.19 www 515: ($html?'<hr /><h3>':'<title>').
1.18 www 516: &mt('LON-CAPA Feed "[_1]" for [_2]',$displayfeedname,$name).
1.20 www 517: ($displayoption eq 'hidden'?' ('.&mt('Hidden').')':'').
1.52 raeburn 518: ($html?'</h3>'.($edit?'<form method="post" name="lonhomework" enctype="multipart/form-data" action=""><br />'.
1.21 www 519: &mt('Name of this Feed').
1.18 www 520: ': <input type="text" size="50" name="newblogname" value="'.
521: $displayfeedname.'" />':'').'<ul>':'</title>'));
522: if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
523: $viewpubliconly=0;
1.29 raeburn 524: }
1.1 www 525: # Get feed items
1.18 www 526: my %newsfeed=&Apache::lonnet::dump($feedname,$udom,$uname);
1.36 albertel 527: foreach my $entry (sort {$b cmp $a} (keys(%newsfeed)),$newid.'_status') {
1.18 www 528: if ($entry=~/^(\d+)\_status$/) { # is an entry
529: my $id=$1;
530: if ($edit) {
531: my %lt=&Apache::lonlocal::texthash('public' => 'public',
532: 'private' => 'private',
533: 'hidden' => 'hidden',
534: 'delete' => 'delete',
1.45 schafran 535: 'store' => 'Select',
1.18 www 536: 'title' => 'Title',
537: 'link' => 'Link',
1.33 www 538: 'description' => 'Description',
1.57 ! raeburn 539: 'enc' => 'Podcasted enclosure');
! 540: my $uploadlink;
! 541: if ($entry==$newid) {
1.33 www 542: # Generate upload link only for last (new) entry
1.57 ! raeburn 543: # Calculate the quota space available in the user's portfolio
! 544: my $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
! 545: $env{'user.domain'}); # expressed in MB
! 546: my $portfolio_root = '/userfiles/portfolio';
! 547: my $getpropath = 1;
! 548: my $current_disk_usage = &Apache::lonnet::diskusage(
! 549: $env{'user.domain'}, $env{'user.name'},
! 550: $portfolio_root, $getpropath); # Expressed in kB
! 551: # Convert to MB for use in file_selector()
! 552: my $free_space = $disk_quota - ($current_disk_usage / 1024.);
! 553: # Format this number since it will be displayed onscreen
! 554: $free_space = sprintf("%.1f", $free_space);
! 555: $uploadlink=&Apache::inputtags::file_selector(0,0,'*','both','',$free_space);
1.33 www 556: } else {
557: # Otherwise, display
558: $uploadlink='<tt>'.$newsfeed{$id.'_enclosureurl'}.'</tt>'.
559: "<input type='hidden' name='$id\_enclosureurl' value='$newsfeed{$id.'_enclosureurl'}' />".
560: "<input type='hidden' name='$id\_enclosuretype' value='$newsfeed{$id.'_enclosuretype'}' />";
561: }
1.18 www 562: my %status=();
563: unless ($newsfeed{$id.'_status'}) { $newsfeed{$id.'_status'}='public'; }
564: $status{$newsfeed{$id.'_status'}}='checked="checked"';
565: $r->print(<<ENDEDIT);
1.5 www 566: <li>
1.15 www 567: <label><input name='$id\_modified' type='checkbox' value="modified" /> $lt{'store'}</label>
1.6 www 568:
1.53 bisitz 569: <label><input name='$id\_status' type="radio" value="public" $status{'public'} onclick="changed(this.form,'$id');" /> $lt{'public'}</label>
1.5 www 570:
1.53 bisitz 571: <label><input name='$id\_status' type="radio" value="private" $status{'private'} onclick="changed(this.form,'$id');" /> $lt{'private'}</label>
1.5 www 572:
1.53 bisitz 573: <label><input name='$id\_status' type="radio" value="hidden" $status{'hidden'} onclick="changed(this.form,'$id');" /> $lt{'hidden'}</label>
1.5 www 574:
1.53 bisitz 575: <label><input name='$id\_status' type="radio" value="deleted" onclick="changed(this.form,'$id');" /> $lt{'delete'}</label>
1.5 www 576: <br />
1.18 www 577: $lt{'title'}:
1.53 bisitz 578: <input name='$id\_title' type='text' size='60' value='$newsfeed{$id.'_title'}' onchange="changed(this.form,'$id');" /><br />
1.18 www 579: $lt{'description'}:<br />
1.53 bisitz 580: <textarea name='$id\_description' rows="6" cols="80" onchange="changed(this.form,'$id');">$newsfeed{$id.'_description'}</textarea><br />
1.18 www 581: $lt{'link'}:
1.53 bisitz 582: <input name='$id\_link' type='text' size='60' value='$newsfeed{$id.'_link'}' onchange="changed(this.form,'$id');" /><br />
1.33 www 583: $lt{'enc'} -
584: $uploadlink
1.6 www 585: <hr /></li>
1.5 www 586: ENDEDIT
1.18 www 587: } else { # not in edit mode, just displaying
588: if (($newsfeed{$id.'_status'} ne 'public') && ($viewpubliconly)) { next; }
589: if ($newsfeed{$id.'_status'} eq 'hidden') { next; }
1.28 albertel 590: my $link = $newsfeed{$id.'_link'};
591: if ($link =~ m|^/| ) {
592: $link = "http://".$ENV{'HTTP_HOST'}.$link;
593: }
1.18 www 594: $r->print("\n".($html?"\n<li><b>":"<item>\n<title>").$newsfeed{$id.'_title'}.
595: ($html?"</b><br />\n":"</title>\n<description>").
596: $newsfeed{$id.'_description'}.
1.33 www 597: ($html?"<br />":"</description>\n").
598: ($link?($html?"\n<a href='":"<link>").
1.28 albertel 599: $link.
1.33 www 600: ($html?("'>".&mt('Read more')."</a><br />\n"):"</link>\n"):''));
601: my $enclosure=$newsfeed{$id.'_enclosureurl'};
1.17 www 602: # Enclosure? Get stats
1.33 www 603: if ($enclosure) {
604: my @stat=&Apache::lonnet::stat_file($enclosure);
1.18 www 605: if ($stat[7]) {
1.17 www 606: # Has non-zero length (and exists)
1.33 www 607: my $enclosuretype=$newsfeed{$id.'_enclosuretype'};
608: if ($enclosure =~ m|^/| ) {
609: $enclosure = "http://".$ENV{'HTTP_HOST'}.$enclosure;
610: }
1.18 www 611: $r->print(($html?"<a href='":"\n<enclosure url='").
1.33 www 612: $enclosure."' length='".$stat[7].
1.18 www 613: "' type='".$enclosuretype.($html?"'>".&mt('Enclosure')."</a>":"' />"));
614: }
615: }
616: if ($html) { # is HTML
617: $r->print("\n<hr /></li>\n");
618: } else { # is RSS
619: $r->print("\n<guid isPermaLink='false'>".$id.$filterfeedname.'_'.$udom.'_'.$uname."</guid></item>\n");
1.17 www 620: }
1.18 www 621: } # end of "in edit mode"
622: } # end of rendering a real entry
623: } # end of loop through all keys
624: if ($html) {
625: $r->print('</ul>');
626: if ($edit) {
1.45 schafran 627: $r->print('<input type="hidden" name="newid" value="'.$newid.'"/><input type="submit" value="'.&mt('Save Selected').'" />'.
1.20 www 628: ($displayoption eq 'hidden'?'<input type="submit" name="advertisethisblog" value="'.&mt('Advertise this Feed').'" />':
629: '<input type="submit" name="hidethisblog" value="'.&mt('Hide this Feed').'" />'));
1.1 www 630: }
1.52 raeburn 631: $r->print('</form>');
1.1 www 632: }
1.18 www 633: } # was a real display feedname
1.52 raeburn 634: $r->print(($html?&Apache::loncommon::end_page():'</channel></rss>'."\n"));
1.18 www 635: } # a real user
1.1 www 636: return OK;
1.18 www 637: } # end handler
1.1 www 638: 1;
639: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>