Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
/lib/ -> rsslib.php (source)

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

This file contains all the common stuff to be used in RSS System

Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 530 lines (18 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 20 functions


Functions that are not part of a class:

rss_add_http_header($context, $componentname, $componentinstance, $title)   X-Ref
Build the URL for the RSS feed and add it as a header

param: stdClass    $context           The context under which the URL should be created
param: string      $componentname     The name of the component for which the RSS feed exists
param: stdClass    $componentinstance The instance of the component
param: string      $title             Name for the link to be added to the page header

rss_get_link($contextid, $userid, $componentname, $id, $tooltiptext='')   X-Ref
Print the link for the RSS feed with the correct RSS icon

param: stdClass    $contextid     The id of the context under which the URL should be created
param: int         $userid        The source of the RSS feed (site/course/group/user)
param: string      $componentname The name of the component for which the feed exists
param: string      $id            The name by which to call the RSS File
param: string      $tooltiptext   The tooltip to be displayed with the link
return: string HTML output for the RSS link

rss_get_url($contextid, $userid, $componentname, $additionalargs)   X-Ref
This function returns the URL for the RSS XML file.

param: int    $contextid      the course id
param: int    $userid         the current user id
param: string $componentname  the name of the current component. For example "forum"
param: string $additionalargs For modules, module instance id
return: string the url of the RSS feed

rss_print_link($contextid, $userid, $componentname, $id, $tooltiptext='')   X-Ref
Print the link for the RSS feed with the correct RSS icon (Theme based)

param: stdClass    $contextid     The id of the context under which the URL should be created
param: int         $userid        The source of the RSS feed (site/course/group/user)
param: string      $componentname The name of the component for which the feed exists
param: string      $id            The name by which to call the RSS File
param: string      $tooltiptext   The tooltip to be displayed with the link

rss_delete_file($componentname, $instance)   X-Ref
Given an object, deletes all RSS files associated with it.

param: string   $componentname the name of the module ie 'forum'. Used to construct the cache path.
param: stdClass $instance      An object with an id member variable ie $forum, $glossary.

rss_enabled_for_mod($modname, $instance=null, $hasrsstype=true, $hasrssarticles=true)   X-Ref
Are RSS feeds enabled for the supplied module instance?

param: string   $modname        The name of the module to be checked
param: stdClass $instance       An instance of an activity module ie $forum, $glossary.
param: bool     $hasrsstype     Should there be a rsstype member variable?
param: bool     $hasrssarticles Should there be a rssarticles member variable?
return: bool whether or not RSS is enabled for the module

rss_save_file($componentname, $filename, $contents, $expandfilename=true)   X-Ref
This function saves to file the rss feed specified in the parameters

param: string $componentname  the module name ie forum. Used to create a cache directory.
param: string $filename       the name of the file to be created ie "rss.xml"
param: string $contents       the data to be written to the file
param: bool   $expandfilename whether or not the fullname of the RSS file should be used
return: bool whether the save was successful or not

rss_get_file_full_name($componentname, $filename)   X-Ref
Retrieve the location and file name of a cached RSS feed

param: string $componentname the name of the component the RSS feed is being created for
param: string $filename the name of the RSS FEED
return: string The full name and path of the RSS file

rss_get_file_name($instance, $sql, $params = array()   X-Ref
Construct the file name of the RSS File

param: stdClass $instance the instance of the source of the RSS feed
param: string $sql the SQL used to produce the RSS feed
param: array $params the parameters used in the SQL query
return: string the name of the RSS file

rss_standard_header($title = NULL, $link = NULL, $description = NULL)   X-Ref
This function return all the common headers for every rss feed in the site

param: string $title       the title for the RSS Feed
param: string $link        the link for the origin of the RSS feed
param: string $description the description of the contents of the RSS feed
return: bool|string the standard header for the RSS feed

rss_add_items($items)   X-Ref
Generates the rss XML code for every item passed in the array

item->title: The title of the item
item->author: The author of the item. Optional !!
item->pubdate: The pubdate of the item
item->link: The link url of the item
item->description: The content of the item

param: array $items an array of item objects
return: bool|string the rss XML code for every item passed in the array

rss_standard_footer()   X-Ref
This function return all the common footers for every rss feed in the site.

return: string

rss_geterrorxmlfile($errortype = 'rsserror')   X-Ref
This function return an error xml file (string) to be sent when a rss is required (file.php) and something goes wrong

param: string $errortype Type of error to send, default is rsserror
return: stdClass returns a XML Feed with an error message in it

rss_get_userid_from_token($token)   X-Ref
Get the ID of the user from a given RSS Token

param: string $token the RSS token you would like to use to find the user id
return: int The user id

rss_get_token($userid)   X-Ref
Get the RSS Token from a given user id

param: int $userid The user id
return: string the RSS token for the user

rss_delete_token($userid)   X-Ref
Removes the token for the given user from the DB

param: int $userid The user id for the token you wish to delete

rss_start_tag($tag,$level=0,$endline=false,$attributes=null)   X-Ref
Return the xml start tag

param: string $tag        the xml tag name
param: int    $level      the indentation level
param: bool   $endline    whether or not to start new tags on a new line
param: array  $attributes the attributes of the xml tag
return: string the xml start tag

rss_end_tag($tag,$level=0,$endline=true)   X-Ref
Return the xml end tag

param: string $tag        the xml tag name
param: int    $level      the indentation level
param: bool   $endline    whether or not to start new tags on a new line
return: string the xml end tag

rss_full_tag($tag, $level, $endline, $content, $attributes = null)   X-Ref
Return the while xml element, including content

param: string $tag        the xml tag name
param: int    $level      the indentation level
param: bool   $endline    whether or not to start new tags on a new line
param: string $content    the text to go inside the tag
param: array  $attributes the attributes of the xml tag
return: string the whole xml element

rss_add_enclosures($item)   X-Ref
Adds RSS Media Enclosures for "podcasting" by including attachments that
are specified in the item->attachments field.

param: stdClass $item representing an RSS item
return: string RSS enclosure tags