Commit 28dd2513 authored by poltawski's avatar poltawski
Browse files

block/rss_client: MDL-19990 Make feed discovery configurable

Simplepie will try quite aggresively to autodiscover rss feeds by
default. Make this configurable when adding a feed and also store
the autodiscovered location rather than the input location.

I also removed the feed validator as this doesn't make much sense with
feed autodiscovery, and I think we can improve simplepie integration to
do this instead
parent ce60cbc8
......@@ -50,11 +50,10 @@ class feed_edit_form extends moodleform {
$mform->setType('url', PARAM_URL);
$mform->addRule('url', null, 'required');
$validatejs = "''+" .
"getElementById('id_url').value, 'validate', " .
"'width=640,height=480,scrollbars=yes,status=yes,resizable=yes'); return true;";
$validatelink = '<a href="#" onclick="' . $validatejs . '">' . get_string('validatefeed', 'block_rss_client') . '</a>';
$mform->addElement('static', 'validatelink', '', $validatelink);
$mform->addElement('checkbox', 'autodiscovery', get_string('enableautodiscovery', 'block_rss_client'));
$mform->setDefault('autodiscovery', 1);
$mform->setHelpButton('autodiscovery', array('feedautodiscovery', get_string('validatefeed', 'block_rss_client'), 'rss_client'), true);
$mform->addElement('text', 'preferredtitle', get_string('customtitlelabel', 'block_rss_client'), array('size' => 60));
$mform->setType('preferredtitle', PARAM_NOTAGS);
......@@ -71,6 +70,14 @@ class feed_edit_form extends moodleform {
$this->add_action_buttons(true, $submitlabal);
function definition_after_data(){
$mform =& $this->_form;
$mform->applyFilter('url', 'feed_edit_form::autodiscover_feed_url');
function validation($data, $files) {
$errors = parent::validation($data, $files);
......@@ -78,6 +85,8 @@ class feed_edit_form extends moodleform {
// set timeout for longer than normal to try and grab the feed
if ($rss->error()) {
......@@ -93,11 +102,46 @@ class feed_edit_form extends moodleform {
function get_data() {
$data = parent::get_data();
if ($data) {
$data->title = $this->title;
$data->description = $this->description;
$data->title = '';
$data->description = '';
$data->title = $this->title;
$data->description = $this->description;
return $data;
* Autodiscovers a feed url from a given url, to be used by the formslibs
* filter function
* Uses simplepie with autodiscovery set to maximum level to try and find
* a feed to subscribe to.
* See:
* @param string URL to autodiscover a url
* @return string URL of feed or original url if none found
public static function autodiscover_feed_url($url){
$rss = new moodle_simplepie();
// When autodiscovering an RSS feed, simplepie will try lots of
// rss links on a page, so set the timeout high
return $url;
return $rss->subscribe_url();
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);
......@@ -22,6 +22,7 @@ $string['editafeed'] = 'Edit a feed';
$string['editfeeds'] = 'Edit, subscribe or unsubsribe from RSS/Atom news feeds';
$string['editnewsfeeds'] = 'Edit news feeds';
$string['editrssblock'] = 'Edit RSS Headline Block';
$string['enableautodiscovery'] = 'Enable auto-discovery of feeds?';
$string['errorloadingfeed'] = 'Error loading this RSS feed ($a)';
$string['feed'] = 'Feed';
$string['feedadded'] = 'News feed added';
<h1>Feed Auto-discovery</h1>
With this option enabled Moodle will try to automatically discover a feed
on a web page if is not given a direct link to a feed.
<p>For example, when entering the Moodle Docs URL: <pre></pre>
Moodle would automatically discover the recent changes feed to subscribe to:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment