- http://spenibus.net
- https://github.com/spenibus/rss-filter-php
- https://gitlab.com/spenibus/rss-filter-php
- https://bitbucket.org/spenibus/rss-filter-php
This script aggregates and filters rss feeds to output only desired items as a single feed.
- Configuration files use the xml extension.
- Configuration files must be placed in
./config/- example:
./config/customFeed.xml
- example:
- You can create multiple configuration files
- A configuration file is loaded by calling the
configparameter with the configuration filename without extension- example:
rss-filter/?config=customFeed
- example:
- A configuration file sample is available at
./example.xml - Configuration keywords are case sensitive, details below.
<config>
<title></title>
<ruleSet>
<source></source>
<timeout></timeout>
<userAgent></userAgent>
<titleDuplicateRemove></titleDuplicateRemove>
<linkDuplicateRemove></linkDuplicateRemove>
<rules>
<titleMatch></titleMatch>
<titleMatchNot></titleMatchNot>
<titleMatchMust></titleMatchMust>
<before></before>
<after></after>
</rules>
</ruleSet>
</config>
-
config- root element
- appears only once in entire document
-
title- sets the title of the output feed
- appears only once within
config
-
ruleSet- a configuration block
- can occur multiple times within
config
-
source- a url pointing to a rss feed
- can occur multiple times within
ruleSet
-
timeout- how long to wait for a source
- this is any number above zero
-
userAgent- adds a user agent to the http request for the source
-
titleDuplicateRemove- value: true|false, default: false
- appears only once within
ruleSet - when this is set to
true, if multiple items from sources share the same title, only the most recent is kept
-
linkDuplicateRemove- value: true|false, default: false
- appears only once within
ruleSet - when this is set to
true, if multiple items from sources share the same link, only the most recent is kept
-
rules- a block of rules
- can occur multiple times within
ruleSet
-
titleMatch- a regular expression usable by PCRE (preg_*), ex:
/(foo|bar)/siu - when at least one
titleMatchmatches the title of an item from one of the sources, the item is kept - this works like the logical operator
OR
- a regular expression usable by PCRE (preg_*), ex:
-
titleMatchNot- a regular expression usable by PCRE (preg_*), ex:
/(foo|bar)/siu - when at least one
titleMatchNotmatches the title of an item from one of the sources, the item is discarded - this works like the logical operator
AND NOT
- a regular expression usable by PCRE (preg_*), ex:
-
titleMatchMust- a regular expression usable by PCRE (preg_*), ex:
/(foo|bar)/siu - when at least one
titleMatchMustdoesn't match the title of an item from one of the sources, the item is discarded - this works like the logical operator
AND
- a regular expression usable by PCRE (preg_*), ex:
-
descriptionMatch- a regular expression usable by PCRE (preg_*), ex:
/(foo|bar)/siu - when at least one
descriptionMatchmatches the description of an item from one of the sources, the item is kept - this works like the logical operator
OR
- a regular expression usable by PCRE (preg_*), ex:
-
descriptionMatchNot- a regular expression usable by PCRE (preg_*), ex:
/(foo|bar)/siu - when at least one
descriptionMatchNotmatches the description of an item from one of the sources, the item is discarded - this works like the logical operator
AND NOT
- a regular expression usable by PCRE (preg_*), ex:
-
descriptionMatchMust- a regular expression usable by PCRE (preg_*), ex:
/(foo|bar)/siu - when at least one
descriptionMatchMustdoesn't match the description of an item from one of the sources, the item is discarded - this works like the logical operator
AND
- a regular expression usable by PCRE (preg_*), ex:
-
categoryMatch- a regular expression usable by PCRE (preg_*), ex:
/(foo|bar)/siu - when at least one
categoryMatchmatches any category of an item from one of the sources, the item is kept - this works like the logical operator
OR
- a regular expression usable by PCRE (preg_*), ex:
-
categoryMatchNot- a regular expression usable by PCRE (preg_*), ex:
/(foo|bar)/siu - when at least one
categoryMatchNotmatches any category of an item from one of the sources, the item is discarded - this works like the logical operator
AND NOT
- a regular expression usable by PCRE (preg_*), ex:
-
categoryMatchMust- a regular expression usable by PCRE (preg_*), ex:
/(foo|bar)/siu - when at least one
categoryMatchMustdoesn't match any category of an item from one of the sources, the item is discarded - this works like the logical operator
AND
- a regular expression usable by PCRE (preg_*), ex:
-
before- a string representing time than can be parsed by
strtotime() - personally recommended format:
2014-12-31 23:59:59 +1200 - when an item pubDate is more recent than this, the item is discarded
- a string representing time than can be parsed by
-
after- a string representing time than can be parsed by
strtotime() - personally recommended format:
2014-12-31 23:59:59 +1200 - when an item pubDate is older than this, the item is discarded
- a string representing time than can be parsed by
-
olderThan- a string representing a duration using a number followed by an optional quantifier, ex:
7d - available quantifiers:
sfor secondsmfor minuteshfor hoursdfor days
- default quantifier is
swhen omitted - when an item pubDate is more recent than the current time minus this duration, the item is discarded
- a string representing a duration using a number followed by an optional quantifier, ex:
-
newerThan- a string representing a duration using a number followed by an optional quantifier, ex:
7d - available quantifiers:
sfor secondsmfor minuteshfor hoursdfor days
- default quantifier is
swhen omitted - when an item pubDate is older than the current time minus this duration, the item is discarded
- a string representing a duration using a number followed by an optional quantifier, ex:
-
rulesblocks only apply to items coming from thesourceelements within the sameruletSetblock -
keywords within a
rulesblock only apply to that block, this is important to remember when using multiplerulesblock because while one block can exclude some items, another block can still include them -
multiple identically named keywords can appear in one
rulesblock- multiple
*MatchMustkeywords within onerulesblock are implicitly AND-connected, i.e. all matches must be true in order for a feed item to be added to the output - multiple
*MatchNotkeywords within onerulesblock are implicitly AND-NOT-connected, i.e. all matches must be false in order for a feed item to be added to the output - multiple
*Matchkeywords within onerulesblock are implicitly OR-connected, i.e. at least one match must be true in order for a feed item to be added to the output
- multiple
-
multiple
ruleSetelements are implicitly OR-connected, i.e. at least onerulesblock must be true in order for a feed item to be added to the output
<rules>
<titleMatch>/red/</titleMatch>
</rules>
<rules>
<titleMatchNot>/army/</titleMatchNot>
</rules>
The example above will return "red army" because the first rules block has
already added the item to the output when the second rules block is evaluated.
<rules>
<titleMatch>/red/</titleMatch>
<titleMatchNot>/army/</titleMatchNot>
</rules>
The example above will not return "red army".
<rules>
<titleMatch>/red/</titleMatch>
<titleMatchNot>/army/</titleMatchNot>
</rules>
<rules>
<titleMatch>/.*/</titleMatch>
</rules>
The example above will also return "red army" because even though the first
rules block has discarded the item, the second one will match it.
It is possible to remove unused keywords, as in the example below:
<config>
<ruleSet>
<source></source>
<rules>
<titleMatch></titleMatch>
</rules>
</ruleSet>
</config>