/** * Gets the footer, which is the channel link of the last feed in our list of feeds * * @param array $feedrecords The feed records from the database. * @return block_rss_client\output\footer|null The renderable footer or null if none should be displayed. */ protected function get_footer($feedrecords) { $footer = null; if ($this->config->block_rss_client_show_channel_link) { global $CFG; require_once $CFG->libdir . '/simplepie/moodle_simplepie.php'; $feedrecord = array_pop($feedrecords); $feed = new moodle_simplepie($feedrecord->url); $channellink = new moodle_url($feed->get_link()); if (!empty($channellink)) { $footer = new block_rss_client\output\footer($channellink); } } return $footer; }
/** * Returns the html of a feed to be displaed in the block * * @param mixed feedrecord The feed record from the database * @param int maxentries The maximum number of entries to be displayed * @param boolean showtitle Should the feed title be displayed in html * @return string html representing the rss feed content */ function get_feed_html($feedrecord, $maxentries, $showtitle) { global $CFG; require_once $CFG->libdir . '/simplepie/moodle_simplepie.php'; $feed = new moodle_simplepie($feedrecord->url); if (isset($CFG->block_rss_client_timeout)) { $feed->set_cache_duration($CFG->block_rss_client_timeout * 60); } if (debugging() && $feed->error()) { return '<p>' . $feedrecord->url . ' Failed with code: ' . $feed->error() . '</p>'; } $r = ''; // return string if ($this->config->block_rss_client_show_channel_image) { if ($image = $feed->get_image_url()) { $imagetitle = s($feed->get_image_title()); $imagelink = $feed->get_image_link(); $r .= '<div class="image" title="' . $imagetitle . '">' . "\n"; if ($imagelink) { $r .= '<a href="' . $imagelink . '">'; } $r .= '<img src="' . $image . '" alt="' . $imagetitle . '" />' . "\n"; if ($imagelink) { $r .= '</a>'; } $r .= '</div>'; } } if (empty($feedrecord->preferredtitle)) { $feedtitle = $this->format_title($feed->get_title()); } else { $feedtitle = $this->format_title($feedrecord->preferredtitle); } if ($showtitle) { $r .= '<div class="title">' . $feedtitle . '</div>'; } $r .= '<ul class="list no-overflow">' . "\n"; $feeditems = $feed->get_items(0, $maxentries); foreach ($feeditems as $item) { $r .= $this->get_item_html($item); } $r .= '</ul>'; if ($this->config->block_rss_client_show_channel_link) { $channellink = $feed->get_link(); if (!empty($channellink)) { //NOTE: this means the 'last feed' display wins the block title - but //this is exiting behaviour.. $this->content->footer = '<a href="' . htmlspecialchars(clean_param($channellink, PARAM_URL)) . '">' . get_string('clientchannellink', 'block_rss_client') . '</a>'; } } if (empty($this->config->title)) { //NOTE: this means the 'last feed' displayed wins the block title - but //this is exiting behaviour.. $this->title = strip_tags($feedtitle); } return $r; }
function test_redirect() { global $CFG; $feed = new moodle_simplepie(moodlesimplepie_test::REDIRECTURL); $this->assertFalse($feed->error()); $this->assertEqual($feed->get_title(), 'Moodle News'); $this->assertEqual($feed->get_link(), 'http://moodle.org/mod/forum/view.php?f=1'); }
function test_redirect() { global $CFG; $feed = new moodle_simplepie(); $feed->set_timeout(self::TIMEOUT); $feed->set_feed_url(self::REDIRECTURL); $feed->init(); $this->assertNull($feed->error()); $this->assertEquals($feed->get_title(), 'Moodle News'); $this->assertEquals($feed->get_link(), 'http://moodle.org/mod/forum/view.php?f=1'); }
public function test_redirect() { $feed = new moodle_simplepie($this->getExternalTestFileUrl('/rss_redir.php'), self::TIMEOUT); $this->assertNull($feed->error()); $this->assertSame('Moodle News', $feed->get_title()); $this->assertSame('http://moodle.org/mod/forum/view.php?f=1', $feed->get_link()); }