viewfeed.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Script to let a user edit the properties of a particular RSS feed.
  18. *
  19. * @package block_rss_client
  20. * @copyright 2009 Tim Hunt
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once(__DIR__ . '/../../config.php');
  24. require_once($CFG->libdir .'/simplepie/moodle_simplepie.php');
  25. require_login();
  26. if (isguestuser()) {
  27. print_error('guestsarenotallowed');
  28. }
  29. $returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
  30. $courseid = optional_param('courseid', 0, PARAM_INT);
  31. $rssid = required_param('rssid', PARAM_INT);
  32. if ($courseid = SITEID) {
  33. $courseid = 0;
  34. }
  35. if ($courseid) {
  36. $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  37. $PAGE->set_course($course);
  38. $context = $PAGE->context;
  39. } else {
  40. $context = context_system::instance();
  41. $PAGE->set_context($context);
  42. }
  43. $urlparams = array('rssid' => $rssid);
  44. if ($courseid) {
  45. $urlparams['courseid'] = $courseid;
  46. }
  47. if ($returnurl) {
  48. $urlparams['returnurl'] = $returnurl;
  49. }
  50. $PAGE->set_url('/blocks/rss_client/viewfeed.php', $urlparams);
  51. $PAGE->set_pagelayout('popup');
  52. $rssrecord = $DB->get_record('block_rss_client', array('id' => $rssid), '*', MUST_EXIST);
  53. $rss = new moodle_simplepie($rssrecord->url);
  54. if ($rss->error()) {
  55. debugging($rss->error());
  56. print_error('errorfetchingrssfeed');
  57. }
  58. $strviewfeed = get_string('viewfeed', 'block_rss_client');
  59. $PAGE->set_title($strviewfeed);
  60. $PAGE->set_heading($strviewfeed);
  61. $managefeeds = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
  62. $PAGE->navbar->add(get_string('blocks'));
  63. $PAGE->navbar->add(get_string('pluginname', 'block_rss_client'));
  64. $PAGE->navbar->add(get_string('managefeeds', 'block_rss_client'), $managefeeds);
  65. $PAGE->navbar->add($strviewfeed);
  66. echo $OUTPUT->header();
  67. if (!empty($rssrecord->preferredtitle)) {
  68. $feedtitle = $rssrecord->preferredtitle;
  69. } else {
  70. $feedtitle = $rss->get_title();
  71. }
  72. echo '<table align="center" width="50%" cellspacing="1">'."\n";
  73. echo '<tr><td colspan="2"><strong>'. s($feedtitle) .'</strong></td></tr>'."\n";
  74. foreach ($rss->get_items() as $item) {
  75. echo '<tr><td valign="middle">'."\n";
  76. echo '<a href="'.$item->get_link().'" target="_blank"><strong>';
  77. echo s($item->get_title());
  78. echo '</strong></a>'."\n";
  79. echo '</td>'."\n";
  80. echo '</tr>'."\n";
  81. echo '<tr><td colspan="2"><small>';
  82. echo format_text($item->get_description(), FORMAT_HTML) .'</small></td></tr>'."\n";
  83. }
  84. echo '</table>'."\n";
  85. echo $OUTPUT->footer();