public function get_feed($feedrecord, $maxentries, $showtitle) {
        global $CFG;
        require_once($CFG->libdir.'/simplepie/moodle_simplepie.php');

        if ($feedrecord->skipuntil) {
            // Last attempt to gather this feed via cron failed - do not try to fetch it now.
            $this->hasfailedfeeds = true;
            return null;
        }

        $simplepiefeed = new moodle_simplepie($feedrecord->url);

        if(isset($CFG->block_rss_client_timeout)){
            $simplepiefeed->set_cache_duration($CFG->block_rss_client_timeout * 60);
        }

        if ($simplepiefeed->error()) {
            debugging($feedrecord->url .' Failed with code: '.$simplepiefeed->error());
            return null;
        }

        if(empty($feedrecord->preferredtitle)){
            // Simplepie does escape HTML entities.
            $feedtitle = $this->format_title($simplepiefeed->get_title());
        }else{
            // Moodle custom title does not does escape HTML entities.
            $feedtitle = $this->format_title(s($feedrecord->preferredtitle));
        }

        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);
        }

        $feed = new \block_rss_client\output\feed($feedtitle, $showtitle, $this->config->block_rss_client_show_channel_image);

        if ($simplepieitems = $simplepiefeed->get_items(0, $maxentries)) {
            foreach ($simplepieitems as $simplepieitem) {
                try {
                    $item = new \block_rss_client\output\item(
                        $simplepieitem->get_id(),
                        new moodle_url($simplepieitem->get_link()),
                        $simplepieitem->get_title(),
                        $simplepieitem->get_description(),
                        new moodle_url($simplepieitem->get_permalink()),
                        $simplepieitem->get_date('U'),
                        $this->config->display_description
                    );

                    $feed->add_item($item);
                } catch (moodle_exception $e) {
                    // If there is an error with the RSS item, we don't
                    // want to crash the page. Specifically, moodle_url can
                    // throw an exception of the param is an extremely
                    // malformed url.
                    debugging($e->getMessage());
                }
            }
        }

        // Feed image.
        if ($imageurl = $simplepiefeed->get_image_url()) {
            try {
                $image = new \block_rss_client\output\channel_image(
                    new moodle_url($imageurl),
                    $simplepiefeed->get_image_title(),
                    new moodle_url($simplepiefeed->get_image_link())
                );

                $feed->set_image($image);
            } catch (moodle_exception $e) {
                // If there is an error with the RSS image, we don'twant to
                // crash the page. Specifically, moodle_url can throw an
                // exception if the param is an extremely malformed url.
                debugging($e->getMessage());
            }
        }

        return $feed;
    }
public function get_feed($feedrecord, $maxentries, $showtitle) {
        global $CFG;
        require_once($CFG->libdir.'/simplepie/moodle_simplepie.php');

        if ($feedrecord->skipuntil) {
            // Last attempt to gather this feed via cron failed - do not try to fetch it now.
            $this->hasfailedfeeds = true;
            return null;
        }

        $simplepiefeed = new moodle_simplepie($feedrecord->url);

        if(isset($CFG->block_rss_client_timeout)){
            $simplepiefeed->set_cache_duration($CFG->block_rss_client_timeout * 60);
        }

        if ($simplepiefeed->error()) {
            debugging($feedrecord->url .' Failed with code: '.$simplepiefeed->error());
            return null;
        }

        if(empty($feedrecord->preferredtitle)){
            // Simplepie does escape HTML entities.
            $feedtitle = $this->format_title($simplepiefeed->get_title());
        }else{
            // Moodle custom title does not does escape HTML entities.
            $feedtitle = $this->format_title(s($feedrecord->preferredtitle));
        }

        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);
        }

        $feed = new \block_rss_client\output\feed($feedtitle, $showtitle, $this->config->block_rss_client_show_channel_image);

        if ($simplepieitems = $simplepiefeed->get_items(0, $maxentries)) {
            foreach ($simplepieitems as $simplepieitem) {
                try {
                    $item = new \block_rss_client\output\item(
                        $simplepieitem->get_id(),
                        new moodle_url($simplepieitem->get_link()),
                        $simplepieitem->get_title(),
                        $simplepieitem->get_description(),
                        new moodle_url($simplepieitem->get_permalink()),
                        $simplepieitem->get_date('U'),
                        $this->config->display_description
                    );

                    $feed->add_item($item);
                } catch (moodle_exception $e) {
                    // If there is an error with the RSS item, we don't
                    // want to crash the page. Specifically, moodle_url can
                    // throw an exception of the param is an extremely
                    // malformed url.
                    debugging($e->getMessage());
                }
            }
        }

        // Feed image.
        if ($imageurl = $simplepiefeed->get_image_url()) {
            try {
                $image = new \block_rss_client\output\channel_image(
                    new moodle_url($imageurl),
                    $simplepiefeed->get_image_title(),
                    new moodle_url($simplepiefeed->get_image_link())
                );

                $feed->set_image($image);
            } catch (moodle_exception $e) {
                // If there is an error with the RSS image, we don'twant to
                // crash the page. Specifically, moodle_url can throw an
                // exception if the param is an extremely malformed url.
                debugging($e->getMessage());
            }
        }

        return $feed;
    }
public function get_feed ( $ feedrecord , $ maxentries , $ showtitle ) { global $ CFG ; require_once ( $ CFG -> libdir . '/simplepie/moodle_simplepie.php' ) ; if ( $ feedrecord -> skipuntil ) { // Last attempt to gather this feed via cron failed - do not try to fetch it now. $ this -> hasfailedfeeds = true ; return null ; } $ simplepiefeed = new moodle_simplepie ( $ feedrecord -> url ) ; if ( isset ( $ CFG -> block_rss_client_timeout ) ) { $ simplepiefeed -> set_cache_duration ( $ CFG -> block_rss_client_timeout * 60 ) ; } if ( $ simplepiefeed -> error ( ) ) { debugging ( $ feedrecord -> url . ' Failed with code: ' . $ simplepiefeed -> error ( ) ) ; return null ; } if ( empty ( $ feedrecord -> preferredtitle ) ) { // Simplepie does escape HTML entities. $ feedtitle = $ this -> format_title ( $ simplepiefeed -> get_title ( ) ) ; } else { // Moodle custom title does not does escape HTML entities. $ feedtitle = $ this -> format_title ( s ( $ feedrecord -> preferredtitle ) ) ; } 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 ) ; } $ feed = new \ block_rss_client \ output \ feed ( $ feedtitle , $ showtitle , $ this -> config -> block_rss_client_show_channel_image ) ; if ( $ simplepieitems = $ simplepiefeed -> get_items ( 0 , $ maxentries ) ) { foreach ( $ simplepieitems as $ simplepieitem ) { try { $ item = new \ block_rss_client \ output \ item ( $ simplepieitem -> get_id ( ) , new moodle_url ( $ simplepieitem -> get_link ( ) ) , $ simplepieitem -> get_title ( ) , $ simplepieitem -> get_description ( ) , new moodle_url ( $ simplepieitem -> get_permalink ( ) ) , $ simplepieitem -> get_date ( 'U' ) , $ this -> config -> display_description ) ; $ feed -> add_item ( $ item ) ; } catch ( moodle_exception $ e ) { // If there is an error with the RSS item, we don't // want to crash the page. Specifically, moodle_url can // throw an exception of the param is an extremely // malformed url. debugging ( $ e -> getMessage ( ) ) ; } } } // Feed image. if ( $ imageurl = $ simplepiefeed -> get_image_url ( ) ) { try { $ image = new \ block_rss_client \ output \ channel_image ( new moodle_url ( $ imageurl ) , $ simplepiefeed -> get_image_title ( ) , new moodle_url ( $ simplepiefeed -> get_image_link ( ) ) ) ; $ feed -> set_image ( $ image ) ; } catch ( moodle_exception $ e ) { // If there is an error with the RSS image, we don'twant to // crash the page. Specifically, moodle_url can throw an // exception if the param is an extremely malformed url. debugging ( $ e -> getMessage ( ) ) ; } } return $ feed ; }
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 block_rss_client\output\feed|null The renderable feed or null of there is an error
Returns the html of a feed to be displaed in the block