Merge branch 'ImproveCore' of https://github.com/logmanoriginal/rss-bridge
This commit is contained in:
commit
8f3c56b184
4 changed files with 23 additions and 10 deletions
|
@ -16,7 +16,7 @@ class AcrimedBridge extends FeedExpander {
|
||||||
|
|
||||||
$articlePage = getSimpleHTMLDOM($newsItem->link);
|
$articlePage = getSimpleHTMLDOM($newsItem->link);
|
||||||
$article = sanitize($articlePage->find('article.article1', 0)->innertext);
|
$article = sanitize($articlePage->find('article.article1', 0)->innertext);
|
||||||
$article = defaultImageSrcTo($article, static::URI);
|
$article = defaultLinkTo($article, static::URI);
|
||||||
$item['content'] = $article;
|
$item['content'] = $article;
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
|
|
|
@ -63,7 +63,7 @@ class WorldOfTanksBridge extends BridgeAbstract {
|
||||||
debugMessage('loading page ' . $item['uri']);
|
debugMessage('loading page ' . $item['uri']);
|
||||||
$articlePage = getSimpleHTMLDOMCached($item['uri']);
|
$articlePage = getSimpleHTMLDOMCached($item['uri']);
|
||||||
$content = $articlePage->find('.l-content', 0);
|
$content = $articlePage->find('.l-content', 0);
|
||||||
defaultImageSrcTo($content, self::URI);
|
defaultLinkTo($content, self::URI);
|
||||||
$item['title'] = $content->find('h1', 0)->innertext;
|
$item['title'] = $content->find('h1', 0)->innertext;
|
||||||
$item['content'] = $content->find('.b-content', 0)->innertext;
|
$item['content'] = $content->find('.b-content', 0)->innertext;
|
||||||
$item['timestamp'] = $content->find('.b-statistic_time', 0)->getAttribute("data-timestamp");
|
$item['timestamp'] = $content->find('.b-statistic_time', 0)->getAttribute("data-timestamp");
|
||||||
|
|
|
@ -8,11 +8,13 @@ class FileCache implements CacheInterface {
|
||||||
protected $param;
|
protected $param;
|
||||||
|
|
||||||
public function loadData(){
|
public function loadData(){
|
||||||
return json_decode(file_get_contents($this->getCacheFile()), true);
|
return unserialize(file_get_contents($this->getCacheFile()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveData($datas){
|
public function saveData($datas){
|
||||||
$writeStream = file_put_contents($this->getCacheFile(), json_encode($datas, JSON_PRETTY_PRINT));
|
// Notice: We use plain serialize() here to reduce memory footprint on
|
||||||
|
// large input data.
|
||||||
|
$writeStream = file_put_contents($this->getCacheFile(), serialize($datas));
|
||||||
|
|
||||||
if($writeStream === false) {
|
if($writeStream === false) {
|
||||||
throw new \Exception("Cannot write the cache... Do you have the right permissions ?");
|
throw new \Exception("Cannot write the cache... Do you have the right permissions ?");
|
||||||
|
@ -39,7 +41,7 @@ class FileCache implements CacheInterface {
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($cacheIterator as $cacheFile){
|
foreach($cacheIterator as $cacheFile){
|
||||||
if(in_array($cacheFile->getBasename(), array('.', '..')))
|
if(in_array($cacheFile->getBasename(), array('.', '..', '.gitkeep')))
|
||||||
continue;
|
continue;
|
||||||
elseif($cacheFile->isFile()){
|
elseif($cacheFile->isFile()){
|
||||||
if(filemtime($cacheFile->getPathname()) < time() - $duration)
|
if(filemtime($cacheFile->getPathname()) < time() - $duration)
|
||||||
|
@ -110,6 +112,8 @@ class FileCache implements CacheInterface {
|
||||||
throw new \Exception('Call "setParameters" first!');
|
throw new \Exception('Call "setParameters" first!');
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash('md5', http_build_query($this->param)) . '.cache';
|
// Change character when making incompatible changes to prevent loading
|
||||||
|
// errors due to incompatible file contents \|/
|
||||||
|
return hash('md5', http_build_query($this->param) . 'A') . '.cache';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
lib/html.php
17
lib/html.php
|
@ -278,12 +278,21 @@ $keptText = array()){
|
||||||
return $htmlContent;
|
return $htmlContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultImageSrcTo($content, $server){
|
function defaultLinkTo($content, $server){
|
||||||
foreach($content->find('img') as $image){
|
foreach($content->find('img') as $image){
|
||||||
if(is_null(strpos($image->src, "http"))
|
if(strpos($image->src, 'http') === false
|
||||||
&& is_null(strpos($image->src, "//"))
|
&& strpos($image->src, '//') === false
|
||||||
&& is_null(strpos($image->src, "data:")))
|
&& strpos($image->src, 'data:') === false)
|
||||||
$image->src = $server . $image->src;
|
$image->src = $server . $image->src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach($content->find('a') as $anchor){
|
||||||
|
if(strpos($anchor->href, 'http') === false
|
||||||
|
&& strpos($anchor->href, '//') === false
|
||||||
|
&& strpos($anchor->href, '#') !== 0
|
||||||
|
&& strpos($anchor->href, '?') !== 0)
|
||||||
|
$anchor->href = $server . $anchor->href;
|
||||||
|
}
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue