Sexactu.php 3.5 KB

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