Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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  /**
  18   * Script to let a user edit the properties of a particular RSS feed.
  19   *
  20   * @package   block_rss_client
  21   * @copyright 2009 Tim Hunt
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../../config.php');
  26  require_once($CFG->libdir .'/simplepie/moodle_simplepie.php');
  27  
  28  require_login();
  29  if (isguestuser()) {
  30      print_error('guestsarenotallowed');
  31  }
  32  
  33  $returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
  34  $courseid = optional_param('courseid', 0, PARAM_INT);
  35  $rssid = required_param('rssid', PARAM_INT);
  36  
  37  if ($courseid = SITEID) {
  38      $courseid = 0;
  39  }
  40  if ($courseid) {
  41      $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  42      $PAGE->set_course($course);
  43      $context = $PAGE->context;
  44  } else {
  45      $context = context_system::instance();
  46      $PAGE->set_context($context);
  47  }
  48  
  49  $urlparams = array('rssid' => $rssid);
  50  if ($courseid) {
  51      $urlparams['courseid'] = $courseid;
  52  }
  53  if ($returnurl) {
  54      $urlparams['returnurl'] = $returnurl;
  55  }
  56  $PAGE->set_url('/blocks/rss_client/viewfeed.php', $urlparams);
  57  $PAGE->set_pagelayout('popup');
  58  
  59  $rssrecord = $DB->get_record('block_rss_client', array('id' => $rssid), '*', MUST_EXIST);
  60  
  61  $rss = new moodle_simplepie($rssrecord->url);
  62  
  63  if ($rss->error()) {
  64      debugging($rss->error());
  65      print_error('errorfetchingrssfeed');
  66  }
  67  
  68  $strviewfeed = get_string('viewfeed', 'block_rss_client');
  69  
  70  $PAGE->set_title($strviewfeed);
  71  $PAGE->set_heading($strviewfeed);
  72  
  73  $managefeeds = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
  74  $PAGE->navbar->add(get_string('blocks'));
  75  $PAGE->navbar->add(get_string('pluginname', 'block_rss_client'));
  76  $PAGE->navbar->add(get_string('managefeeds', 'block_rss_client'), $managefeeds);
  77  $PAGE->navbar->add($strviewfeed);
  78  echo $OUTPUT->header();
  79  
  80  if (!empty($rssrecord->preferredtitle)) {
  81      $feedtitle = $rssrecord->preferredtitle;
  82  } else {
  83      $feedtitle =  $rss->get_title();
  84  }
  85  echo '<table align="center" width="50%" cellspacing="1">'."\n";
  86  echo '<tr><td colspan="2"><strong>'. s($feedtitle) .'</strong></td></tr>'."\n";
  87  foreach ($rss->get_items() as $item) {
  88      echo '<tr><td valign="middle">'."\n";
  89      echo '<a href="'.$item->get_link().'" target="_blank"><strong>';
  90      echo s($item->get_title());
  91      echo '</strong></a>'."\n";
  92      echo '</td>'."\n";
  93      echo '</tr>'."\n";
  94      echo '<tr><td colspan="2"><small>';
  95      echo format_text($item->get_description(), FORMAT_HTML) .'</small></td></tr>'."\n";
  96  }
  97  echo '</table>'."\n";
  98  
  99  echo $OUTPUT->footer();