Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   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 manage their RSS feeds.
  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 . '/tablelib.php');
  27  
  28  require_login();
  29  
  30  $returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
  31  $courseid = optional_param('courseid', 0, PARAM_INT);
  32  $deleterssid = optional_param('deleterssid', 0, PARAM_INT);
  33  
  34  if ($courseid == SITEID) {
  35      $courseid = 0;
  36  }
  37  if ($courseid) {
  38      $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  39      $PAGE->set_course($course);
  40      $context = $PAGE->context;
  41  } else {
  42      $context = context_system::instance();
  43      $PAGE->set_context($context);
  44  }
  45  
  46  $managesharedfeeds = has_capability('block/rss_client:manageanyfeeds', $context);
  47  if (!$managesharedfeeds) {
  48      require_capability('block/rss_client:manageownfeeds', $context);
  49  }
  50  
  51  $urlparams = array();
  52  $extraparams = '';
  53  if ($courseid) {
  54      $urlparams['courseid'] = $courseid;
  55      $extraparams = '&courseid=' . $courseid;
  56  }
  57  if ($returnurl) {
  58      $urlparams['returnurl'] = $returnurl;
  59      $extraparams = '&returnurl=' . $returnurl;
  60  }
  61  $baseurl = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
  62  $PAGE->set_url($baseurl);
  63  
  64  // Process any actions
  65  if ($deleterssid && confirm_sesskey()) {
  66      $DB->delete_records('block_rss_client', array('id'=>$deleterssid));
  67  
  68      redirect($PAGE->url, get_string('feeddeleted', 'block_rss_client'));
  69  }
  70  
  71  // Display the list of feeds.
  72  if ($managesharedfeeds) {
  73      $select = '(userid = ' . $USER->id . ' OR shared = 1)';
  74  } else {
  75      $select = 'userid = ' . $USER->id;
  76  }
  77  $feeds = $DB->get_records_select('block_rss_client', $select, null, $DB->sql_order_by_text('title'));
  78  
  79  $strmanage = get_string('managefeeds', 'block_rss_client');
  80  
  81  $PAGE->set_pagelayout('standard');
  82  $PAGE->set_title($strmanage);
  83  $PAGE->set_heading($strmanage);
  84  
  85  $managefeeds = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
  86  $PAGE->navbar->add(get_string('blocks'));
  87  $PAGE->navbar->add(get_string('pluginname', 'block_rss_client'));
  88  $PAGE->navbar->add(get_string('managefeeds', 'block_rss_client'), $managefeeds);
  89  echo $OUTPUT->header();
  90  
  91  $table = new flexible_table('rss-display-feeds');
  92  
  93  $table->define_columns(array('feed', 'actions'));
  94  $table->define_headers(array(get_string('feed', 'block_rss_client'), get_string('actions', 'moodle')));
  95  $table->define_baseurl($baseurl);
  96  
  97  $table->set_attribute('cellspacing', '0');
  98  $table->set_attribute('id', 'rssfeeds');
  99  $table->set_attribute('class', 'generaltable generalbox');
 100  $table->column_class('feed', 'feed');
 101  $table->column_class('actions', 'actions');
 102  
 103  $table->setup();
 104  
 105  foreach($feeds as $feed) {
 106      if (!empty($feed->preferredtitle)) {
 107          $feedtitle = s($feed->preferredtitle);
 108      } else {
 109          $feedtitle = $feed->title;
 110      }
 111  
 112      $viewlink = html_writer::link($CFG->wwwroot .'/blocks/rss_client/viewfeed.php?rssid=' . $feed->id . $extraparams, $feedtitle);
 113  
 114      $feedinfo = '<div class="title">' . $viewlink . '</div>' .
 115          '<div class="url">' . html_writer::link($feed->url, $feed->url) .'</div>' .
 116          '<div class="description">' . $feed->description . '</div>';
 117      if ($feed->skipuntil) {
 118          $skipuntil = userdate($feed->skipuntil, get_string('strftimedatetime', 'langconfig'));
 119          $skipmsg = get_string('failedfeed', 'block_rss_client', $skipuntil);
 120          $notification = new \core\output\notification($skipmsg, 'error');
 121          $notification->set_show_closebutton(false);
 122          $feedinfo .= $OUTPUT->render($notification);
 123      }
 124  
 125      $editurl = new moodle_url('/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams);
 126      $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')));
 127  
 128      $deleteurl = new moodle_url('/blocks/rss_client/managefeeds.php?deleterssid=' . $feed->id . '&sesskey=' . sesskey() . $extraparams);
 129      $deleteicon = new pix_icon('t/delete', get_string('delete'));
 130      $deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action(get_string('deletefeedconfirm', 'block_rss_client')));
 131  
 132      $feedicons = $editaction . ' ' . $deleteaction;
 133  
 134      $table->add_data(array($feedinfo, $feedicons));
 135  }
 136  
 137  $table->print_html();
 138  
 139  $url = $CFG->wwwroot . '/blocks/rss_client/editfeed.php?' . substr($extraparams, 1);
 140  echo '<div class="actionbuttons">' . $OUTPUT->single_button($url, get_string('addnewfeed', 'block_rss_client'), 'get') . '</div>';
 141  
 142  
 143  if ($returnurl) {
 144      echo '<div class="backlink">' . html_writer::link($returnurl, get_string('back')) . '</div>';
 145  }
 146  
 147  echo $OUTPUT->footer();