2015-03-03 00:22:02 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Mrss
|
|
|
|
* Documentation Source http://www.rssboard.org/media-rss
|
|
|
|
*/
|
2016-09-10 21:41:11 +03:00
|
|
|
class MrssFormat extends FormatAbstract {
|
2015-03-03 00:22:02 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
public function stringify(){
|
|
|
|
$https = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '';
|
|
|
|
$httpHost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
|
|
|
|
$httpInfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
|
2015-03-03 00:22:02 +03:00
|
|
|
|
2018-10-15 19:14:06 +03:00
|
|
|
$serverRequestUri = isset($_SERVER['REQUEST_URI']) ? $this->xml_encode($_SERVER['REQUEST_URI']) : '';
|
2015-03-03 00:22:02 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
$extraInfos = $this->getExtraInfos();
|
|
|
|
$title = $this->xml_encode($extraInfos['name']);
|
2016-09-10 22:01:02 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
if(!empty($extraInfos['uri'])) {
|
2016-09-10 22:01:02 +03:00
|
|
|
$uri = $this->xml_encode($extraInfos['uri']);
|
|
|
|
} else {
|
2018-05-05 15:55:38 +03:00
|
|
|
$uri = 'https://github.com/RSS-Bridge/rss-bridge';
|
2016-09-10 22:01:02 +03:00
|
|
|
}
|
|
|
|
|
2018-06-30 11:16:16 +03:00
|
|
|
$uriparts = parse_url($uri);
|
|
|
|
$icon = $this->xml_encode($uriparts['scheme'] . '://' . $uriparts['host'] .'/favicon.ico');
|
2015-03-03 00:22:02 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
$items = '';
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach($this->getItems() as $item) {
|
2016-09-10 21:41:11 +03:00
|
|
|
$itemAuthor = isset($item['author']) ? $this->xml_encode($item['author']) : '';
|
|
|
|
$itemTitle = strip_tags(isset($item['title']) ? $this->xml_encode($item['title']) : '');
|
|
|
|
$itemUri = isset($item['uri']) ? $this->xml_encode($item['uri']) : '';
|
|
|
|
$itemTimestamp = isset($item['timestamp']) ? $this->xml_encode(date(DATE_RFC2822, $item['timestamp'])) : '';
|
|
|
|
$itemContent = isset($item['content']) ? $this->xml_encode($this->sanitizeHtml($item['content'])) : '';
|
2016-11-09 20:59:17 +03:00
|
|
|
|
2016-11-13 00:04:42 +03:00
|
|
|
$entryEnclosuresWarning = '';
|
|
|
|
$entryEnclosures = '';
|
2017-07-29 20:28:00 +03:00
|
|
|
if(isset($item['enclosures'])) {
|
2016-11-13 00:04:42 +03:00
|
|
|
$entryEnclosures .= '<enclosure url="'
|
|
|
|
. $this->xml_encode($item['enclosures'][0])
|
Catching up | [Main] Debug mode, parse utils, MIME | [Bridges] Add/Improve 20 bridges (#802)
* Debug mode improvements
- Improve debug warning message
- Restore error reporting in debug mode
- Fix 'notice' messages for unset fields
* Add parsing utility functions
html.php
- extractFromDelimiters
- stripWithDelimiters
- stripRecursiveHTMLSection
- markdownToHtml (partial)
bridges
- remove now-duplicate functions
- call functions from html.php instead
* [Anidex] New bridge
Anime torrent tracker
* [Anime-Ultime] Restore thumbnail
* [CNET] Recreate bridge
Full rewrite as the previous one was broken
* [Dilbert] Minor URI fix
Use new self::URI property
* [EstCeQuonMetEnProd] Fix content extraction
Bridge was broken
* [Facebook] Fix "SpSonsSoriSsés" label
... which was taking space in item title
* [Futura-Sciences] Use HTTPS, More cleanup
Use HTTPS as FS now offer HTTPS
Clean additional useless HTML elements
* [GBATemp] Multiple fixes
- Fix categories: missing "break" statements
- Restore thumbnail as enclosure
- Fix date extraction
- Fix user blog post extraction
- Use getSimpleHTMLDOMCached
* [JapanExpo] Fix bridge, HTTPS, thumbnails
- Fix getSimpleHTMLDOMCached call
- Upgrade to HTTPS as JE now offers HTTPS
- Restore thumbnails as enclosures
* [LeMondeInformatique] Fix bridge, HTTPS
- Upgrade to HTTPS as LMI now offers HTTPS
- Restore thumbnails using small images
- Fix content extraction
- Fix text encoding issue
* [Nextgov] Fix content extraction
- Restore thumbnail and use small image
- Field extraction fixes
* [NextInpact] Add categories and filtering by type
- Offer all RSS feeds
- Allow filtering by article type
- Implement extraction for brief articles
- Remove article limit, many brief articles are publied all at once
* [NyaaTorrents] New bridge
Anime torrent tracker
* [Releases3DS] Cache content, restore thumbnail
- Use getSimpleHTMLDOMCached
- Restore thumbnail as enclosure
* [TheHackerNews] Fix bridge
- Fix content extraction including article body
- Restore thumbnail as enclosure
* [WeLiveSecurity] HTTPS, Fix content extraction
- Upgrade to HTTPS as WLS now offers HTTPS
- Fix content extraction including article body
* [WordPress] Reduce timeout, more content selectors
- Reduce timeout to use default one (1h)
- Add new content selector (articleBody)
- Find thumbnail and set as enclosure
- Fix <script> cleanup
* [YGGTorrent] Increase limit, use cache
- Increase item limit as uploads are very frequent
- Use getSimpleHTMLDOMCached
* [ZDNet] Rewrite with FeedExpander
- Upgrade to HTTPS as ZD now offers HTTPS
- Use FeedExpander for secondary fields
- Fix content extraction for article body
* [Main] Handle MIME type for enclosures
Many feed readers will ignore enclosures (e.g. thumbnails) with no MIME type. This commit adds automatic MIME type detection based on file extension (which may be inaccurate but is the only way without fetching the content).
One can force enclosure type using #.ext anchor (hacky, needs improving)
* [FeedExpander] Improve field extraction
- Add support for passing enclosures
- Improve author and uri extraction
- Fix 'notice' PHP error messages
* [Pull] Coding style fixes for #802
* [Pull] Implementing changes for #802
- Fix coding style issues with str append
- Remove useless CACHE_TIMEOUT
- Use count() instead of $limit
- Use defaultLinkTo() + handle strings
- Use http_build_query()
- Fix missing </em>
- Remove error_reporting(0)
- warning CSS (@LogMANOriginal)
- Fix typo in FeedExpander comment
* [Main] More documentation for markdownToHtml
See #802 for more details
2018-09-09 22:20:13 +03:00
|
|
|
. '" type="' . getMimeType($item['enclosures'][0]) . '" />';
|
2016-11-13 00:04:42 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
if(count($item['enclosures']) > 1) {
|
2016-11-13 00:04:42 +03:00
|
|
|
$entryEnclosures .= PHP_EOL;
|
|
|
|
$entryEnclosuresWarning = '<br>Warning:
|
|
|
|
Some media files might not be shown to you. Consider using the ATOM format instead!';
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach($item['enclosures'] as $enclosure) {
|
2016-11-13 00:04:42 +03:00
|
|
|
$entryEnclosures .= '<atom:link rel="enclosure" href="'
|
Catching up | [Main] Debug mode, parse utils, MIME | [Bridges] Add/Improve 20 bridges (#802)
* Debug mode improvements
- Improve debug warning message
- Restore error reporting in debug mode
- Fix 'notice' messages for unset fields
* Add parsing utility functions
html.php
- extractFromDelimiters
- stripWithDelimiters
- stripRecursiveHTMLSection
- markdownToHtml (partial)
bridges
- remove now-duplicate functions
- call functions from html.php instead
* [Anidex] New bridge
Anime torrent tracker
* [Anime-Ultime] Restore thumbnail
* [CNET] Recreate bridge
Full rewrite as the previous one was broken
* [Dilbert] Minor URI fix
Use new self::URI property
* [EstCeQuonMetEnProd] Fix content extraction
Bridge was broken
* [Facebook] Fix "SpSonsSoriSsés" label
... which was taking space in item title
* [Futura-Sciences] Use HTTPS, More cleanup
Use HTTPS as FS now offer HTTPS
Clean additional useless HTML elements
* [GBATemp] Multiple fixes
- Fix categories: missing "break" statements
- Restore thumbnail as enclosure
- Fix date extraction
- Fix user blog post extraction
- Use getSimpleHTMLDOMCached
* [JapanExpo] Fix bridge, HTTPS, thumbnails
- Fix getSimpleHTMLDOMCached call
- Upgrade to HTTPS as JE now offers HTTPS
- Restore thumbnails as enclosures
* [LeMondeInformatique] Fix bridge, HTTPS
- Upgrade to HTTPS as LMI now offers HTTPS
- Restore thumbnails using small images
- Fix content extraction
- Fix text encoding issue
* [Nextgov] Fix content extraction
- Restore thumbnail and use small image
- Field extraction fixes
* [NextInpact] Add categories and filtering by type
- Offer all RSS feeds
- Allow filtering by article type
- Implement extraction for brief articles
- Remove article limit, many brief articles are publied all at once
* [NyaaTorrents] New bridge
Anime torrent tracker
* [Releases3DS] Cache content, restore thumbnail
- Use getSimpleHTMLDOMCached
- Restore thumbnail as enclosure
* [TheHackerNews] Fix bridge
- Fix content extraction including article body
- Restore thumbnail as enclosure
* [WeLiveSecurity] HTTPS, Fix content extraction
- Upgrade to HTTPS as WLS now offers HTTPS
- Fix content extraction including article body
* [WordPress] Reduce timeout, more content selectors
- Reduce timeout to use default one (1h)
- Add new content selector (articleBody)
- Find thumbnail and set as enclosure
- Fix <script> cleanup
* [YGGTorrent] Increase limit, use cache
- Increase item limit as uploads are very frequent
- Use getSimpleHTMLDOMCached
* [ZDNet] Rewrite with FeedExpander
- Upgrade to HTTPS as ZD now offers HTTPS
- Use FeedExpander for secondary fields
- Fix content extraction for article body
* [Main] Handle MIME type for enclosures
Many feed readers will ignore enclosures (e.g. thumbnails) with no MIME type. This commit adds automatic MIME type detection based on file extension (which may be inaccurate but is the only way without fetching the content).
One can force enclosure type using #.ext anchor (hacky, needs improving)
* [FeedExpander] Improve field extraction
- Add support for passing enclosures
- Improve author and uri extraction
- Fix 'notice' PHP error messages
* [Pull] Coding style fixes for #802
* [Pull] Implementing changes for #802
- Fix coding style issues with str append
- Remove useless CACHE_TIMEOUT
- Use count() instead of $limit
- Use defaultLinkTo() + handle strings
- Use http_build_query()
- Fix missing </em>
- Remove error_reporting(0)
- warning CSS (@LogMANOriginal)
- Fix typo in FeedExpander comment
* [Main] More documentation for markdownToHtml
See #802 for more details
2018-09-09 22:20:13 +03:00
|
|
|
. $enclosure . '" type="' . getMimeType($enclosure) . '" />'
|
2016-11-13 00:04:42 +03:00
|
|
|
. PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
2016-11-09 20:59:17 +03:00
|
|
|
}
|
|
|
|
|
2018-07-16 13:32:24 +03:00
|
|
|
$entryCategories = '';
|
|
|
|
if(isset($item['categories'])) {
|
|
|
|
|
|
|
|
foreach($item['categories'] as $category) {
|
|
|
|
$entryCategories .= '<category>'
|
|
|
|
. $category . '</category>'
|
|
|
|
. PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
$items .= <<<EOD
|
2015-03-03 00:22:02 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
<item>
|
|
|
|
<title>{$itemTitle}</title>
|
|
|
|
<link>{$itemUri}</link>
|
|
|
|
<guid isPermaLink="true">{$itemUri}</guid>
|
|
|
|
<pubDate>{$itemTimestamp}</pubDate>
|
2016-11-13 00:04:42 +03:00
|
|
|
<description>{$itemContent}{$entryEnclosuresWarning}</description>
|
2016-09-10 21:41:11 +03:00
|
|
|
<author>{$itemAuthor}</author>
|
2016-11-13 00:04:42 +03:00
|
|
|
{$entryEnclosures}
|
2018-07-16 13:32:24 +03:00
|
|
|
{$entryCategories}
|
2016-09-10 21:41:11 +03:00
|
|
|
</item>
|
2015-03-03 00:22:02 +03:00
|
|
|
|
|
|
|
EOD;
|
2016-09-10 21:41:11 +03:00
|
|
|
}
|
2015-03-03 00:22:02 +03:00
|
|
|
|
2016-11-07 22:49:44 +03:00
|
|
|
$charset = $this->getCharset();
|
|
|
|
|
2018-09-15 15:13:05 +03:00
|
|
|
/* xml attributes need to have certain characters escaped to be w3c compliant */
|
|
|
|
$imageTitle = htmlspecialchars($title, ENT_COMPAT);
|
2016-09-10 21:41:11 +03:00
|
|
|
/* Data are prepared, now let's begin the "MAGIE !!!" */
|
2016-11-07 22:49:44 +03:00
|
|
|
$toReturn = <<<EOD
|
|
|
|
<?xml version="1.0" encoding="{$charset}"?>
|
|
|
|
<rss version="2.0"
|
|
|
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
|
|
xmlns:media="http://search.yahoo.com/mrss/"
|
2016-09-10 22:01:02 +03:00
|
|
|
xmlns:atom="http://www.w3.org/2005/Atom">
|
2016-09-10 21:41:11 +03:00
|
|
|
<channel>
|
|
|
|
<title>{$title}</title>
|
|
|
|
<link>http{$https}://{$httpHost}{$httpInfo}/</link>
|
|
|
|
<description>{$title}</description>
|
2018-09-15 15:13:05 +03:00
|
|
|
<image url="{$icon}" title="{$imageTitle}" link="{$uri}"/>
|
2016-09-10 21:41:11 +03:00
|
|
|
<atom:link rel="alternate" type="text/html" href="{$uri}" />
|
|
|
|
<atom:link rel="self" href="http{$https}://{$httpHost}{$serverRequestUri}" />
|
|
|
|
{$items}
|
|
|
|
</channel>
|
2015-03-03 00:22:02 +03:00
|
|
|
</rss>
|
|
|
|
EOD;
|
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
// Remove invalid non-UTF8 characters
|
|
|
|
ini_set('mbstring.substitute_character', 'none');
|
2016-11-07 22:49:44 +03:00
|
|
|
$toReturn = mb_convert_encoding($toReturn, $this->getCharset(), 'UTF-8');
|
2016-09-10 21:41:11 +03:00
|
|
|
return $toReturn;
|
|
|
|
}
|
2015-03-03 00:22:02 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
public function display(){
|
|
|
|
$this
|
2016-11-07 22:49:44 +03:00
|
|
|
->setContentType('application/rss+xml; charset=' . $this->getCharset())
|
2016-09-10 21:41:11 +03:00
|
|
|
->callContentType();
|
2015-03-03 00:22:02 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
return parent::display();
|
|
|
|
}
|
2016-08-09 18:05:29 +03:00
|
|
|
|
2016-09-10 21:41:11 +03:00
|
|
|
private function xml_encode($text){
|
|
|
|
return htmlspecialchars($text, ENT_XML1);
|
|
|
|
}
|
2015-03-03 00:22:02 +03:00
|
|
|
}
|