2014-05-26 19:45:10 +02:00
|
|
|
<?php
|
2016-09-14 23:01:54 +02:00
|
|
|
class WordPressBridge extends FeedExpander {
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "aledeg";
|
|
|
|
const NAME = "Wordpress Bridge";
|
|
|
|
const URI = "https://wordpress.org/";
|
2016-09-25 17:04:28 +02:00
|
|
|
const CACHE_TIMEOUT = 10800; // 3h
|
2016-09-15 13:14:24 +02:00
|
|
|
const DESCRIPTION = "Returns the newest full posts of a Wordpress powered website";
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const PARAMETERS = array( array(
|
2016-08-27 21:03:26 +02:00
|
|
|
'url'=>array(
|
|
|
|
'name'=>'Blog URL',
|
|
|
|
'required'=>true
|
|
|
|
)
|
|
|
|
));
|
2016-08-04 20:06:53 +02:00
|
|
|
|
2016-09-14 23:01:54 +02:00
|
|
|
private function clearContent($content) {
|
2016-08-04 21:42:06 +02:00
|
|
|
$content = preg_replace('/<script[^>]*>[^<]*<\/script>/', '', $content);
|
2016-08-04 20:15:28 +02:00
|
|
|
$content = preg_replace('/<div class="wpa".*/', '', $content);
|
2016-08-04 21:42:06 +02:00
|
|
|
$content = preg_replace('/<form.*\/form>/', '', $content);
|
2016-08-04 20:15:28 +02:00
|
|
|
return $content;
|
|
|
|
}
|
2016-08-02 15:46:21 +02:00
|
|
|
|
2016-09-14 23:01:54 +02:00
|
|
|
protected function parseItem($newItem){
|
|
|
|
$item=parent::parseItem($newItem);
|
|
|
|
|
2016-09-25 23:22:33 +02:00
|
|
|
$article_html = getSimpleHTMLDOMCached($item['uri']);
|
2016-09-14 23:01:54 +02:00
|
|
|
|
|
|
|
$article=null;
|
|
|
|
switch(true){
|
|
|
|
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;
|
2016-09-15 12:36:24 +02:00
|
|
|
case !is_null($article_html->find('.post-content',0)):
|
|
|
|
// another common content div
|
|
|
|
$article = $article_html->find('.post-content', 0);
|
|
|
|
break;
|
|
|
|
|
2016-09-14 23:01:54 +02:00
|
|
|
case !is_null($article_html->find('.post',0)):
|
|
|
|
// for old WordPress themes without HTML5
|
|
|
|
$article = $article_html->find('.post', 0);
|
|
|
|
break;
|
2016-08-27 20:42:05 +02:00
|
|
|
}
|
2016-08-04 20:06:53 +02:00
|
|
|
|
2016-09-14 23:01:54 +02:00
|
|
|
if(!is_null($article)){
|
|
|
|
$item['content'] = $this->clearContent($article->innertext);
|
|
|
|
}
|
2016-08-04 21:06:12 +02:00
|
|
|
|
2016-09-14 23:01:54 +02:00
|
|
|
return $item;
|
|
|
|
}
|
2016-08-04 21:06:12 +02:00
|
|
|
|
2016-09-15 11:13:18 +02:00
|
|
|
public function getURI(){
|
|
|
|
$url = $this->getInput('url');
|
2016-09-15 12:35:52 +02:00
|
|
|
if(empty($url)){
|
|
|
|
$url = static::URI;
|
|
|
|
}
|
2016-09-15 11:13:18 +02:00
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2016-09-14 23:01:54 +02:00
|
|
|
public function collectData(){
|
2016-09-15 12:35:52 +02:00
|
|
|
if($this->getInput('url') && substr($this->getInput('url'),0,strlen('http'))!=='http'){
|
2016-09-14 23:01:54 +02:00
|
|
|
// just in case someone find a way to access local files by playing with the url
|
2016-09-25 23:22:33 +02:00
|
|
|
returnClientError('The url parameter must either refer to http or https protocol.');
|
2014-05-26 19:45:10 +02:00
|
|
|
}
|
2017-02-07 11:24:18 +01:00
|
|
|
try{
|
|
|
|
$this->collectExpandableDatas($this->getURI().'/feed/atom/');
|
|
|
|
}catch (HttpException $e){
|
|
|
|
$this->collectExpandableDatas($this->getURI().'/?feed=atom');
|
|
|
|
}
|
2016-08-27 20:42:05 +02:00
|
|
|
|
2014-05-26 19:45:10 +02:00
|
|
|
}
|
|
|
|
}
|