2014-05-26 21:45:10 +04:00
|
|
|
<?php
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
class WordPressBridge extends FeedExpander
|
|
|
|
{
|
|
|
|
const NAME = 'Wordpress Bridge';
|
|
|
|
const URI = 'https://wordpress.org/';
|
|
|
|
const DESCRIPTION = 'Returns the newest full posts of a WordPress powered website';
|
2022-10-31 22:59:19 +03:00
|
|
|
const MAINTAINER = 'ORelio';
|
2016-08-04 21:06:53 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
const PARAMETERS = [ [
|
|
|
|
'url' => [
|
|
|
|
'name' => 'Blog URL',
|
2022-10-31 22:59:19 +03:00
|
|
|
'exampleValue' => 'https://wordpress.org/',
|
2022-07-01 16:10:30 +03:00
|
|
|
'required' => true
|
2022-10-31 22:59:19 +03:00
|
|
|
],
|
|
|
|
'limit' => self::LIMIT,
|
|
|
|
'content-selector' => [
|
|
|
|
'name' => 'Content Selector (Optional - Advanced users)',
|
|
|
|
'exampleValue' => '.custom-article-class',
|
|
|
|
],
|
2022-07-01 16:10:30 +03:00
|
|
|
]];
|
2016-08-02 16:46:21 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
private function cleanContent($content)
|
|
|
|
{
|
|
|
|
$content = stripWithDelimiters($content, '<script', '</script>');
|
|
|
|
$content = preg_replace('/<div class="wpa".*/', '', $content);
|
|
|
|
$content = preg_replace('/<form.*\/form>/', '', $content);
|
|
|
|
return $content;
|
|
|
|
}
|
2016-09-15 00:01:54 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
protected function parseItem($newItem)
|
|
|
|
{
|
|
|
|
$item = parent::parseItem($newItem);
|
2016-09-15 00:01:54 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
$article_html = getSimpleHTMLDOMCached($item['uri']);
|
2022-03-28 01:20:44 +03:00
|
|
|
|
2022-10-31 22:59:19 +03:00
|
|
|
// Find article body
|
2022-07-01 16:10:30 +03:00
|
|
|
$article = null;
|
|
|
|
switch (true) {
|
2022-10-31 22:59:19 +03:00
|
|
|
case !empty($this->getInput('content-selector')):
|
|
|
|
// custom contect selector (manually specified by user)
|
|
|
|
$article = $article_html->find($this->getInput('content-selector'), 0);
|
2022-07-01 16:10:30 +03:00
|
|
|
break;
|
|
|
|
case !is_null($article_html->find('[itemprop=articleBody]', 0)):
|
2022-10-31 22:59:19 +03:00
|
|
|
// highest priority content div (used for SEO)
|
2022-07-01 16:10:30 +03:00
|
|
|
$article = $article_html->find('[itemprop=articleBody]', 0);
|
|
|
|
break;
|
2022-10-31 22:59:19 +03:00
|
|
|
case !is_null($article_html->find('.article-content', 0)):
|
|
|
|
// more precise than article when present
|
|
|
|
$article = $article_html->find('.article-content', 0);
|
|
|
|
break;
|
2022-07-01 16:10:30 +03:00
|
|
|
case !is_null($article_html->find('article', 0)):
|
|
|
|
// most common content div
|
|
|
|
$article = $article_html->find('article', 0);
|
|
|
|
break;
|
|
|
|
case !is_null($article_html->find('.single-content', 0)):
|
|
|
|
// another common content div
|
|
|
|
$article = $article_html->find('.single-content', 0);
|
|
|
|
break;
|
|
|
|
case !is_null($article_html->find('.post-content', 0)):
|
|
|
|
// another common content div
|
|
|
|
$article = $article_html->find('.post-content', 0);
|
|
|
|
break;
|
|
|
|
case !is_null($article_html->find('.post', 0)):
|
|
|
|
// for old WordPress themes without HTML5
|
|
|
|
$article = $article_html->find('.post', 0);
|
|
|
|
break;
|
|
|
|
}
|
2016-08-04 21:06:53 +03:00
|
|
|
|
2022-10-31 22:59:19 +03:00
|
|
|
// Remove duplicate title from content
|
|
|
|
foreach ($article->find('h1') as $title) {
|
|
|
|
if (trim(html_entity_decode($title->plaintext) == $item['title'])) {
|
2022-07-01 16:10:30 +03:00
|
|
|
$title->outertext = '';
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2022-10-31 22:59:19 +03:00
|
|
|
// Find article main image
|
2022-11-20 14:41:59 +03:00
|
|
|
$article = convertLazyLoading($article);
|
2022-07-01 16:10:30 +03:00
|
|
|
$article_image = $article_html->find('img.wp-post-image', 0);
|
|
|
|
if (!empty($item['content']) && (!is_object($article_image) || empty($article_image->src))) {
|
|
|
|
$article_image = str_get_html($item['content'])->find('img.wp-post-image', 0);
|
|
|
|
}
|
|
|
|
if (is_object($article_image) && !empty($article_image->src)) {
|
2022-10-31 22:59:19 +03:00
|
|
|
$article_image = $article_image->src;
|
2022-08-06 23:46:28 +03:00
|
|
|
$mime_type = parse_mime_type($article_image);
|
2022-07-01 16:10:30 +03:00
|
|
|
if (strpos($mime_type, 'image') === false) {
|
|
|
|
$article_image .= '#.image'; // force image
|
|
|
|
}
|
|
|
|
if (empty($item['enclosures'])) {
|
|
|
|
$item['enclosures'] = [$article_image];
|
|
|
|
} else {
|
2022-09-06 01:14:20 +03:00
|
|
|
$item['enclosures'] = array_merge($item['enclosures'], (array) $article_image);
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2022-11-20 14:41:59 +03:00
|
|
|
// Unwrap images figures
|
|
|
|
foreach ($article->find('figure.wp-block-image') as $figure) {
|
|
|
|
$figure->outertext = $figure->innertext;
|
|
|
|
}
|
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
if (!is_null($article)) {
|
|
|
|
$item['content'] = $this->cleanContent($article->innertext);
|
|
|
|
$item['content'] = defaultLinkTo($item['content'], $item['uri']);
|
|
|
|
}
|
2016-08-04 22:06:12 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
return $item;
|
|
|
|
}
|
2016-08-04 22:06:12 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
$url = $this->getInput('url');
|
|
|
|
if (empty($url)) {
|
|
|
|
$url = parent::getURI();
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
2016-09-15 12:13:18 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2022-10-31 22:59:19 +03:00
|
|
|
$limit = $this->getInput('limit') ?? 10;
|
2022-07-01 16:10:30 +03:00
|
|
|
if ($this->getInput('url') && substr($this->getInput('url'), 0, strlen('http')) !== 'http') {
|
|
|
|
// just in case someone find a way to access local files by playing with the url
|
|
|
|
returnClientError('The url parameter must either refer to http or https protocol.');
|
|
|
|
}
|
|
|
|
try {
|
2022-10-31 22:59:19 +03:00
|
|
|
$this->collectExpandableDatas($this->getURI() . '/feed/atom/', $limit);
|
2022-07-01 16:10:30 +03:00
|
|
|
} catch (Exception $e) {
|
2022-10-31 22:59:19 +03:00
|
|
|
$this->collectExpandableDatas($this->getURI() . '/?feed=atom', $limit);
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2014-05-26 21:45:10 +04:00
|
|
|
}
|