Documentation

Feed
in package
implements ActionInterface, Routable uses ActionRouter, ActionTrait

This class contains the code necessary to display XML feeds.

Outputs xml data representing recent information or a profile.

Can be passed subactions which decide what is output: 'recent' for recent posts, 'news' for news topics, 'members' for recently registered members, 'profile' for a member's profile. 'posts' for a member's posts. 'personal_messages' for a member's personal messages.

When displaying a member's profile or posts, the u parameter identifies which member. Defaults to the current user's id. To display a member's personal messages, the u parameter must match the id of the current user.

Outputs can be in RSS 0.92, RSS 2, Atom, RDF, or our own custom XML format. Default is RSS 2.

Accessed via ?action=.xml.

Does not use any templates, sub templates, or template layers.

Uses Stats, Profile, Post, and PersonalMessage language files.

Table of Contents

Interfaces

ActionInterface
Interface for all action classes.
Routable
Classes implementing this interface can build routes from URL query parameters and parse routes back into URL query parameters.

Constants

MIME_TYPES  = ['rss' => 'application/rss+xml', 'rss2' => 'application/rss+xml', 'atom' => 'application/atom+xml', 'rdf' => 'application/rdf+xml', 'smf' => 'text/xml']
An array of MIME types for feed formats.
XML_NAMESPACES  = ['rss' => [], 'rss2' => ['atom' => 'htt' . 'p:/' . '/ww' . 'w.w3.o' . 'rg/2005/Atom'], 'atom' => ['' => 'htt' . 'p:/' . '/ww' . 'w.w3.o' . 'rg/2005/Atom'], 'rdf' => ['' => 'htt' . 'p:/' . '/purl.o' . 'rg/rss/1.0/', 'rdf' => 'htt' . 'p:/' . '/ww' . 'w.w3.o' . 'rg/1999/02/22-rdf-syntax-ns#', 'dc' => 'htt' . 'p:/' . '/purl.o' . 'rg/dc/elements/1.1/'], 'smf' => ['smf' => 'htt' . 'p:/' . '/ww' . 'w.simple' . 'machines.o' . 'rg/xml/%1s']]
An array of sprintf() strings to define XML namespaces.

Properties

$ascending  : bool
$boards  : array<string|int, mixed>
$data  : array<string|int, mixed>
$format  : string
$limit  : int
$member  : int
$metadata  : array<string|int, mixed>
$query_this_board  : string
$start_after  : int
$subaction  : string
$subactions  : array<string|int, mixed>
$xml  : array<string|int, mixed>
$host  : string
$obj  : static
$optimize_msg  : array<string|int, mixed>

Methods

__construct()  : mixed
Constructor.
build()  : array<string|int, mixed>
Builds the XML from the data.
buildRoute()  : array<string|int, mixed>
Builds a routing path based on URL query parameters.
call()  : void
Convenience method to load() and execute() an instance of this class.
canBeLogged()  : bool
Determines whether this action can be logged in the online log.
canShowDebuggingInfo()  : bool
Determines whether debugging info should be shown.
canShowInMaintenanceMode()  : bool
Determines whether this action allows access in maintenance mode.
cdataParse()  : string
Ensures supplied data is properly encapsulated in cdata xml tags
emit()  : void
Emits the feed as an XML file.
execute()  : void
Fetches the data based on the sub-action, builds the XML, and emits it.
getData()  : array<string|int, mixed>
Retrieve the correct type of data based on $this->subaction.
getOutputType()  : OutputTypeInterface
Gets the output type for this action.
getXmlMembers()  : array<string|int, mixed>
Retrieve the list of members from database.
getXmlNews()  : array<string|int, mixed>
Get the latest topics information from a specific board, to display later.
getXmlPMs()  : array<string|int, mixed>
Get a user's personal messages.
getXmlPosts()  : array<string|int, mixed>
Get a user's posts.
getXmlProfile()  : array<string|int, mixed>
Get the profile information for member into an array, which will be generated to match the xml_format.
getXmlRecent()  : array<string|int, mixed>
Get the recent topics to display.
isAgreementAction()  : bool
Determines whether this action can be accessed without accepting the registration agreement and privacy policy.
isRestrictedGuestAccessAllowed()  : bool
Determines whether this action allows access if guest access is restricted.
isSimpleAction()  : bool
Determines whether this is a simple action.
load()  : static
Static wrapper for constructor.
parseRoute()  : array<string|int, mixed>
Parses a route to get URL query parameters.
buildActionRoute()  : array<string|int, mixed>
Builds a routing path for an action based on URL query parameters.
checkEnabled()  : void
Checks whether feeds are enabled
dumpTags()  : void
Populates Utils::$context['feed']['items'].
fixPossibleUrl()  : string
Called from self::dumpTags to convert data to XML.
parseActionRoute()  : array<string|int, mixed>
Parses a route for an action to get URL query parameters.
setFormat()  : void
Sets the format based on $_GET['type']
setlimit()  : void
Sets the limit for determining how many items to show
setMember()  : void
Sets the member property. This is the ID of the person viewing it or the person whose profile feed we're viewing
setSubaction()  : void
Sets the subaction property

Constants

MIME_TYPES

An array of MIME types for feed formats.

public mixed MIME_TYPES = ['rss' => 'application/rss+xml', 'rss2' => 'application/rss+xml', 'atom' => 'application/atom+xml', 'rdf' => 'application/rdf+xml', 'smf' => 'text/xml']

XML_NAMESPACES

An array of sprintf() strings to define XML namespaces.

public mixed XML_NAMESPACES = ['rss' => [], 'rss2' => ['atom' => 'htt' . 'p:/' . '/ww' . 'w.w3.o' . 'rg/2005/Atom'], 'atom' => ['' => 'htt' . 'p:/' . '/ww' . 'w.w3.o' . 'rg/2005/Atom'], 'rdf' => ['' => 'htt' . 'p:/' . '/purl.o' . 'rg/rss/1.0/', 'rdf' => 'htt' . 'p:/' . '/ww' . 'w.w3.o' . 'rg/1999/02/22-rdf-syntax-ns#', 'dc' => 'htt' . 'p:/' . '/purl.o' . 'rg/dc/elements/1.1/'], 'smf' => ['smf' => 'htt' . 'p:/' . '/ww' . 'w.simple' . 'machines.o' . 'rg/xml/%1s']]

Do NOT change any of these to HTTPS addresses! Not even the SMF one.

Why? Because XML namespace names must be both unique and invariant once defined. They look like URLs merely because that's a convenient way to ensure uniqueness, but they are not used as URLs. They are used as case-sensitive identifier strings. If the string changes in any way, XML processing software (including PHP's own XML functions) will interpret the two versions of the string as entirely different namespaces, which could cause it to mangle the XML horrifically during processing.

These strings have been broken up and concatenated to help prevent any automatic search and replace attempts from changing them.

Properties

$ascending

public bool $ascending = false

Whether data is in ascending order or not. Only relevant for some sub-actions.

$boards

public array<string|int, mixed> $boards = []

Boards to fetch posts from.

$data

public array<string|int, mixed> $data = []

Main data in this feed.

$format

public string $format = 'rss2'

The requested feed format (e.g. RSS2, Atom, etc.)

$limit

public int $limit = 5

Maximum number of items to fetch. Range: 1 - 255.

Only relevant for some sub-actions.

$member

public int $member

ID of a member. Used by members, profile, posts, and personal_messages sub-actions.

$metadata

public array<string|int, mixed> $metadata = []

Metadata about this feed.

$query_this_board

public string $query_this_board = ''

Part of an SQL WHERE clause. Restricts query to only fetch posts from certain boards.

$start_after

public int $start_after = 0

ID of item to start after. Only relevant for posts and personal_messages sub-actions.

$subaction

public string $subaction = 'recent'

The requested sub-action.

$subactions

public static array<string|int, mixed> $subactions = ['recent' => 'getXmlRecent', 'news' => 'getXmlNews', 'members' => 'getXmlMembers', 'profile' => 'getXmlProfile', 'posts' => 'getXmlPosts', 'personal_messages' => 'getXmlPMs']

List all the different types of data they can pull.

$xml

public array<string|int, mixed> $xml = ['header' => '', 'items' => '', 'footer' => '']

The constructed XML.

$host

protected string $host = ''

Host extracted from $scripturl. Used to generate globally unique identifiers.

$obj

protected static static $obj

An instance of this class. This is used by the load() method to prevent multiple instantiations.

$optimize_msg

protected array<string|int, mixed> $optimize_msg = ['highest' => 'm.id_msg <= b.id_last_msg', 'lowest' => 'm.id_msg >= 0']

Used to optimize SQL queries.

Methods

__construct()

Constructor.

public __construct([string $subaction = null ][, int $member = null ]) : mixed
Parameters
$subaction : string = null

Sets the sub-action to call. If null, will try $_GET['sa'] and then the default sub-action.

$member : int = null

The member whose data is being requested. If null, will try $_GET['u'] and then User::$me->id.

build()

Builds the XML from the data.

public static build(string $format, array<string|int, mixed> $data, array<string|int, mixed> $metadata, string $subaction) : array<string|int, mixed>

Returns an array containing three parts: the feed's header section, its items section, and its footer section. For convenience, the array is also made available as Utils::$context['feed'].

This method is static for the sake of the ExportProfileData task, which needs to do a lot of custom manipulation of the XML.

Parameters
$format : string

A supported feed format.

$data : array<string|int, mixed>

Structured data to build as XML.

$metadata : array<string|int, mixed>

Metadata about the feed.

$subaction : string

The sub-action that was requested.

Return values
array<string|int, mixed>

The feed's header, items, and footer.

buildRoute()

Builds a routing path based on URL query parameters.

public static buildRoute(array<string|int, mixed> $params) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

URL query parameters.

Return values
array<string|int, mixed>

Contains two elements: ['route' => [], 'params' => []]. The 'route' element contains the routing path. The 'params' element contains any $params that weren't incorporated into the route.

call()

Convenience method to load() and execute() an instance of this class.

public static call() : void

canBeLogged()

Determines whether this action can be logged in the online log.

public canBeLogged() : bool
Return values
bool

canShowDebuggingInfo()

Determines whether debugging info should be shown.

public canShowDebuggingInfo() : bool
Return values
bool

canShowInMaintenanceMode()

Determines whether this action allows access in maintenance mode.

public canShowInMaintenanceMode() : bool
Return values
bool

True if access is allowed, false otherwise.

cdataParse()

Ensures supplied data is properly encapsulated in cdata xml tags

public static cdataParse(string $data[, string $ns = '' ][, bool $force = false ]) : string
Parameters
$data : string

XML data

$ns : string = ''

A namespace prefix for the XML data elements (used by mods, maybe)

$force : bool = false

If true, enclose the XML data in cdata tags no matter what (used by mods, maybe)

Return values
string

The XML data enclosed in cdata tags when necessary

emit()

Emits the feed as an XML file.

public emit() : void

execute()

Fetches the data based on the sub-action, builds the XML, and emits it.

public execute() : void

getData()

Retrieve the correct type of data based on $this->subaction.

public getData() : array<string|int, mixed>

The array will be structured to match $this->format.

Return values
array<string|int, mixed>

An array of arrays of feed items. Each array has keys corresponding to the appropriate tags for the specified format.

getXmlMembers()

Retrieve the list of members from database.

public getXmlMembers() : array<string|int, mixed>

The array will be generated to match $this->format.

Tags
todo

get the list of members from Subs-Members.

Return values
array<string|int, mixed>

An array of arrays of feed items. Each array has keys corresponding to the appropriate tags for the specified format.

getXmlNews()

Get the latest topics information from a specific board, to display later.

public getXmlNews() : array<string|int, mixed>

The returned array will be generated to match the xml_format.

Return values
array<string|int, mixed>

An array of arrays of topic data for the feed. Each array has keys corresponding to the tags for the specified format.

getXmlPMs()

Get a user's personal messages.

public getXmlPMs() : array<string|int, mixed>

Only the user can do this, and no one else -- not even the admin!

Return values
array<string|int, mixed>

An array of arrays containing data for the feed. Each array has keys corresponding to the appropriate tags for the specified format.

getXmlPosts()

Get a user's posts.

public getXmlPosts() : array<string|int, mixed>

The returned array will be generated to match the xml_format.

Return values
array<string|int, mixed>

An array of arrays containing data for the feed. Each array has keys corresponding to the appropriate tags for the specified format.

getXmlProfile()

Get the profile information for member into an array, which will be generated to match the xml_format.

public getXmlProfile() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array profile data

getXmlRecent()

Get the recent topics to display.

public getXmlRecent() : array<string|int, mixed>

The returned array will be generated to match the xml_format.

Return values
array<string|int, mixed>

An array of arrays containing data for the feed. Each array has keys corresponding to the appropriate tags for the specified format.

isAgreementAction()

Determines whether this action can be accessed without accepting the registration agreement and privacy policy.

public isAgreementAction() : bool
Return values
bool

isRestrictedGuestAccessAllowed()

Determines whether this action allows access if guest access is restricted.

public isRestrictedGuestAccessAllowed() : bool
Return values
bool

True if access is allowed, false otherwise.

isSimpleAction()

Determines whether this is a simple action.

public isSimpleAction() : bool
Return values
bool

load()

Static wrapper for constructor.

public static load() : static
Return values
static

An instance of this class.

parseRoute()

Parses a route to get URL query parameters.

public static parseRoute(array<string|int, mixed> $route[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>
Parameters
$route : array<string|int, mixed>

Array of routing path components.

$params : array<string|int, mixed> = []

Any existing URL query parameters.

Return values
array<string|int, mixed>

URL query parameters

buildActionRoute()

Builds a routing path for an action based on URL query parameters.

protected static buildActionRoute(array<string|int, mixed> &$params) : array<string|int, mixed>

The 'action', 'area', and 'sa' parameters will be mapped to route path components in that order. The 'action' parameter is required, whereas 'area' and 'sa' are optional and will be silently skipped if not set.

The parameters are passed by reference and parameters are removed from the array when recognized. This lets wrapper methods continue parsing the remainder of the parameters without worrying about duplicate elements.

Parameters
$params : array<string|int, mixed>

URL query parameters.

Return values
array<string|int, mixed>

The route path elements.

checkEnabled()

Checks whether feeds are enabled

protected checkEnabled() : void

dumpTags()

Populates Utils::$context['feed']['items'].

protected static dumpTags(array<string|int, mixed> $data, int $i[, string $format = '' ][, array<string|int, mixed> $forceCdataKeys = [] ][, array<string|int, mixed> $nsKeys = [] ]) : void

Formats data retrieved in other functions into XML format. Additionally formats data based on the specific format passed. This function is recursively called to handle sub arrays of data.

Parameters
$data : array<string|int, mixed>

The array to output as XML data.

$i : int

The amount of indentation to use.

$format : string = ''

The format to use ('atom', 'rss', 'rss2' or 'smf')

$forceCdataKeys : array<string|int, mixed> = []

A list of keys on which to force cdata wrapping (used by mods, maybe)

$nsKeys : array<string|int, mixed> = []

Key-value pairs of namespace prefixes to pass to self::cdataParse() (used by mods, maybe)

fixPossibleUrl()

Called from self::dumpTags to convert data to XML.

protected static fixPossibleUrl(string $val) : string

Finds URLs for local site and sanitizes them.

Parameters
$val : string

A string containing a possible URL.

Return values
string

$val The string with any possible URLs sanitized.

parseActionRoute()

Parses a route for an action to get URL query parameters.

protected static parseActionRoute(array<string|int, mixed> &$route) : array<string|int, mixed>

The first element of the route path is mapped to the 'action' parameter.

For the 'admin', 'moderate', and 'profile' actions, the second element of the route is mapped to the 'area' parameter and the third element is mapped to the 'sa' parameter.

For all other actions, the second element of the route path is mapped to the 'sa' parameter.

The route passed by reference and route path elements are removed from the route when recognized. This lets wrapper methods continue parsing the remainder of the route without worrying about duplicate elements.

Parameters
$route : array<string|int, mixed>

Array of routing path components.

Return values
array<string|int, mixed>

URL query parameters

setFormat()

Sets the format based on $_GET['type']

protected setFormat() : void

setlimit()

Sets the limit for determining how many items to show

protected setlimit() : void

setMember()

Sets the member property. This is the ID of the person viewing it or the person whose profile feed we're viewing

protected setMember([int|null $member = 0 ]) : void
Parameters
$member : int|null = 0

setSubaction()

Sets the subaction property

protected setSubaction(string|null $subaction) : void
Parameters
$subaction : string|null

The subaction. If not set, checks $_GET['sa'] first, then picks the first value in self::$subactions


        
On this page

Search results