managefeeds.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 manage their RSS feeds.
  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 . '/tablelib.php');
  25. require_login();
  26. $returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
  27. $courseid = optional_param('courseid', 0, PARAM_INT);
  28. $deleterssid = optional_param('deleterssid', 0, PARAM_INT);
  29. if ($courseid == SITEID) {
  30. $courseid = 0;
  31. }
  32. if ($courseid) {
  33. $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  34. $PAGE->set_course($course);
  35. $context = $PAGE->context;
  36. } else {
  37. $context = context_system::instance();
  38. $PAGE->set_context($context);
  39. }
  40. $managesharedfeeds = has_capability('block/rss_client:manageanyfeeds', $context);
  41. if (!$managesharedfeeds) {
  42. require_capability('block/rss_client:manageownfeeds', $context);
  43. }
  44. $urlparams = array();
  45. $extraparams = '';
  46. if ($courseid) {
  47. $urlparams['courseid'] = $courseid;
  48. $extraparams = '&courseid=' . $courseid;
  49. }
  50. if ($returnurl) {
  51. $urlparams['returnurl'] = $returnurl;
  52. $extraparams = '&returnurl=' . $returnurl;
  53. }
  54. $baseurl = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
  55. $PAGE->set_url($baseurl);
  56. // Process any actions
  57. if ($deleterssid && confirm_sesskey()) {
  58. $DB->delete_records('block_rss_client', array('id'=>$deleterssid));
  59. redirect($PAGE->url, get_string('feeddeleted', 'block_rss_client'));
  60. }
  61. // Display the list of feeds.
  62. if ($managesharedfeeds) {
  63. $select = '(userid = ' . $USER->id . ' OR shared = 1)';
  64. } else {
  65. $select = 'userid = ' . $USER->id;
  66. }
  67. $feeds = $DB->get_records_select('block_rss_client', $select, null, $DB->sql_order_by_text('title'));
  68. $strmanage = get_string('managefeeds', 'block_rss_client');
  69. $PAGE->set_pagelayout('standard');
  70. $PAGE->set_title($strmanage);
  71. $PAGE->set_heading($strmanage);
  72. $managefeeds = new moodle_url('/blocks/rss_client/managefeeds.php', $urlparams);
  73. $PAGE->navbar->add(get_string('blocks'));
  74. $PAGE->navbar->add(get_string('pluginname', 'block_rss_client'));
  75. $PAGE->navbar->add(get_string('managefeeds', 'block_rss_client'), $managefeeds);
  76. echo $OUTPUT->header();
  77. $table = new flexible_table('rss-display-feeds');
  78. $table->define_columns(array('feed', 'actions'));
  79. $table->define_headers(array(get_string('feed', 'block_rss_client'), get_string('actions', 'moodle')));
  80. $table->define_baseurl($baseurl);
  81. $table->set_attribute('cellspacing', '0');
  82. $table->set_attribute('id', 'rssfeeds');
  83. $table->set_attribute('class', 'generaltable generalbox');
  84. $table->column_class('feed', 'feed');
  85. $table->column_class('actions', 'actions');
  86. $table->setup();
  87. foreach($feeds as $feed) {
  88. if (!empty($feed->preferredtitle)) {
  89. $feedtitle = s($feed->preferredtitle);
  90. } else {
  91. $feedtitle = s($feed->title);
  92. }
  93. $viewlink = html_writer::link($CFG->wwwroot .'/blocks/rss_client/viewfeed.php?rssid=' . $feed->id . $extraparams, $feedtitle);
  94. $feedinfo = '<div class="title">' . $viewlink . '</div>' .
  95. '<div class="url">' . html_writer::link($feed->url, $feed->url) .'</div>' .
  96. '<div class="description">' . $feed->description . '</div>';
  97. $editurl = new moodle_url('/blocks/rss_client/editfeed.php?rssid=' . $feed->id . $extraparams);
  98. $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')));
  99. $deleteurl = new moodle_url('/blocks/rss_client/managefeeds.php?deleterssid=' . $feed->id . '&sesskey=' . sesskey() . $extraparams);
  100. $deleteicon = new pix_icon('t/delete', get_string('delete'));
  101. $deleteaction = $OUTPUT->action_icon($deleteurl, $deleteicon, new confirm_action(get_string('deletefeedconfirm', 'block_rss_client')));
  102. $feedicons = $editaction . ' ' . $deleteaction;
  103. $table->add_data(array($feedinfo, $feedicons));
  104. }
  105. $table->print_html();
  106. $url = $CFG->wwwroot . '/blocks/rss_client/editfeed.php?' . substr($extraparams, 1);
  107. echo '<div class="actionbuttons">' . $OUTPUT->single_button($url, get_string('addnewfeed', 'block_rss_client'), 'get') . '</div>';
  108. if ($returnurl) {
  109. echo '<div class="backlink">' . html_writer::link($returnurl, get_string('back')) . '</div>';
  110. }
  111. echo $OUTPUT->footer();