SexactuBridge.php 3.2 KB

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