Rss-Bridge/bridges/DeveloppezDotComBridge.php

57 lines
1.5 KiB
PHP
Raw Normal View History

2014-07-14 19:41:09 +02:00
<?php
class DeveloppezDotComBridge extends FeedExpander {
2014-07-14 19:41:09 +02:00
const MAINTAINER = "polopollo";
const NAME = "Developpez.com Actus (FR)";
const URI = "http://www.developpez.com/";
const DESCRIPTION = "Returns the 15 newest posts from DeveloppezDotCom (full text).";
public function collectData(){
$this->collectExpandableDatas(self::URI . 'index/rss', 15);
}
protected function parseItem($newsItem){
$item = $this->parseRSS_2_0_Item($newsItem);
$item['content'] = $this->DeveloppezDotComExtractContent($item['uri']);
return $item;
}
private function DeveloppezDotComStripCDATA($string) {
$string = str_replace('<![CDATA[', '', $string);
$string = str_replace(']]>', '', $string);
return $string;
}
2014-07-14 19:41:09 +02:00
// F***ing quotes from Microsoft Word badly encoded, here was the trick:
2016-08-03 12:42:57 +02:00
// http://stackoverflow.com/questions/1262038/how-to-replace-microsoft-encoded-quotes-in-php
private function convert_smart_quotes($string)
{
$search = array(chr(145),
chr(146),
chr(147),
chr(148),
chr(151));
2014-07-14 19:41:09 +02:00
$replace = array("'",
"'",
'"',
'"',
'-');
return str_replace($search, $replace, $string);
}
private function DeveloppezDotComExtractContent($url) {
if($this->get_cached_time($url) <= strtotime('-24 hours'))
$this->remove_from_cache($url);
$articleHTMLContent = $this->get_cached($url);
$text = $this->convert_smart_quotes($articleHTMLContent->find('div.content', 0)->innertext);
$text = utf8_encode($text);
return trim($text);
}
2016-08-03 12:42:57 +02:00
public function getCacheDuration(){
return 1800; // 30min
}
2014-07-14 19:41:09 +02:00
}