2014-05-26 19:45:10 +02:00
|
|
|
<?php
|
2016-08-04 20:06:53 +02:00
|
|
|
define('WORDPRESS_TYPE_ATOM', 1); // Content is of type ATOM
|
|
|
|
define('WORDPRESS_TYPE_RSS', 2); // Content is of type RSS
|
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/";
|
|
|
|
const DESCRIPTION = "Returns the 3 newest full posts of a Wordpress blog";
|
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);
|
|
|
|
|
|
|
|
$article_html = $this->getSimpleHTMLDOMCached($item['uri']);
|
|
|
|
|
|
|
|
$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;
|
|
|
|
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-15 11:13:18 +02:00
|
|
|
$this->returnClientError('The url parameter must either refer to http or https protocol.');
|
2014-05-26 19:45:10 +02:00
|
|
|
}
|
|
|
|
|
2016-09-15 11:13:18 +02:00
|
|
|
$this->collectExpandableDatas($this->getURI().'/feed/atom/');
|
2016-08-27 20:42:05 +02:00
|
|
|
|
2014-05-26 19:45:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration() {
|
|
|
|
return 3600*3; // 3 hours
|
|
|
|
}
|
|
|
|
}
|