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