2014-02-04 17:54:18 +01:00
|
|
|
<?php
|
2016-09-14 10:23:35 +02:00
|
|
|
class SexactuBridge extends BridgeAbstract{
|
2014-02-04 17:54:18 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "Riduidel";
|
|
|
|
const NAME = "Sexactu";
|
2016-09-14 10:23:35 +02:00
|
|
|
const URI = "https://www.gqmagazine.fr";
|
2016-09-25 17:04:28 +02:00
|
|
|
const CACHE_TIMEOUT = 7200; // 2h
|
2016-08-30 11:23:55 +02:00
|
|
|
const DESCRIPTION = "Sexactu via rss-bridge";
|
2015-11-05 12:20:11 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2014-02-20 08:42:40 +01:00
|
|
|
$find = array('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'novembre', 'décembre');
|
|
|
|
$replace = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
|
|
|
|
|
2016-09-25 23:22:33 +02:00
|
|
|
$html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not request '.$this->getURI());
|
2014-02-18 11:55:47 +01:00
|
|
|
|
|
|
|
foreach($html->find('.content-holder') as $contentHolder) {
|
2016-07-08 19:06:35 +02:00
|
|
|
// only use first list as second one only contains pages numbers
|
2014-02-18 11:55:47 +01:00
|
|
|
$articles = $contentHolder->find('ul', 0);
|
|
|
|
foreach($articles->find('li') as $element) {
|
|
|
|
// if you ask about that method_exists, there seems to be a bug in simple html dom
|
|
|
|
// see stackoverflow for more details : http://stackoverflow.com/a/10828479/15619
|
|
|
|
if(is_object($element)) {
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
2014-02-18 11:55:47 +01:00
|
|
|
// various metadata
|
|
|
|
$titleBlock = $element->find('.title-holder', 0);
|
|
|
|
if(is_object($titleBlock)) {
|
2014-02-20 08:42:40 +01:00
|
|
|
$titleDetails = $titleBlock->find('.article-title',0);
|
|
|
|
$titleData = $titleDetails->find('h2', 0)->find('a',0);
|
|
|
|
$titleTimestamp =$titleDetails->find('h4',0);
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['title'] = $this->correctCase(trim($titleData->innertext));
|
2016-08-30 11:23:55 +02:00
|
|
|
$item['uri'] = self::URI.$titleData->href;
|
2014-02-18 11:55:47 +01:00
|
|
|
|
2014-02-20 08:42:40 +01:00
|
|
|
// Fugly date parsing due to the fact my DNS-323 doesn't support php intl extension
|
|
|
|
$dateText = $titleTimestamp->innertext;
|
|
|
|
$dateText = substr($dateText, strpos($dateText,',')+1);
|
|
|
|
$dateText = str_replace($find, $replace, strtolower($dateText));
|
2016-07-08 19:06:35 +02:00
|
|
|
$date = strtotime($dateText);
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['timestamp'] = $date;
|
2014-02-20 08:42:40 +01:00
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['author'] = "Maïa Mazaurette";
|
2014-02-18 11:55:47 +01:00
|
|
|
$elementText = $element->find('.text-container', 0);
|
|
|
|
// don't forget to replace images server url with gq one
|
|
|
|
foreach($elementText->find('img') as $image) {
|
2016-08-30 11:23:55 +02:00
|
|
|
$image->src = self::URI.$image->src;
|
2014-02-18 11:55:47 +01:00
|
|
|
}
|
2016-08-22 18:55:59 +02:00
|
|
|
$item['content'] = $elementText->innertext;
|
2014-02-18 11:55:47 +01:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2014-02-18 11:55:47 +01:00
|
|
|
}
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2014-02-18 11:55:47 +01:00
|
|
|
}
|
2014-02-04 17:54:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI(){
|
2016-08-30 11:23:55 +02:00
|
|
|
return self::URI.'/sexactu';
|
2014-02-04 17:54:18 +01:00
|
|
|
}
|
|
|
|
|
2016-08-06 16:00:56 +02:00
|
|
|
private function correctCase($str) {
|
2014-02-20 08:42:40 +01:00
|
|
|
$sentences=explode('.', mb_strtolower($str, "UTF-8"));
|
|
|
|
$str="";
|
|
|
|
$sep="";
|
|
|
|
foreach ($sentences as $sentence)
|
|
|
|
{
|
|
|
|
//upper case first char
|
|
|
|
$sentence=ucfirst(trim($sentence));
|
2016-07-08 19:06:35 +02:00
|
|
|
|
2014-02-20 08:42:40 +01:00
|
|
|
//append sentence to output
|
|
|
|
$str=$str.$sep.$sentence;
|
|
|
|
$sep=". ";
|
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
}
|
2014-02-04 17:54:18 +01:00
|
|
|
}
|