mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-12-18 08:54:20 +03:00
a4b9611e66
- Do not add spaces after opening or before closing parenthesis // Wrong if( !is_null($var) ) { ... } // Right if(!is_null($var)) { ... } - Add space after closing parenthesis // Wrong if(true){ ... } // Right if(true) { ... } - Add body into new line - Close body in new line // Wrong if(true) { ... } // Right if(true) { ... } Notice: Spaces after keywords are not detected: // Wrong (not detected) // -> space after 'if' and missing space after 'else' if (true) { ... } else{ ... } // Right if(true) { ... } else { ... }
44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
class NasaApodBridge extends BridgeAbstract {
|
|
|
|
const MAINTAINER = 'corenting';
|
|
const NAME = 'NASA APOD Bridge';
|
|
const URI = 'https://apod.nasa.gov/apod/';
|
|
const CACHE_TIMEOUT = 43200; // 12h
|
|
const DESCRIPTION = 'Returns the 3 latest NASA APOD pictures and explanations';
|
|
|
|
public function collectData(){
|
|
|
|
$html = getSimpleHTMLDOM(self::URI . 'archivepix.html')
|
|
or returnServerError('Error while downloading the website content');
|
|
|
|
$list = explode("<br>", $html->find('b', 0)->innertext);
|
|
|
|
for($i = 0; $i < 3; $i++) {
|
|
$line = $list[$i];
|
|
$item = array();
|
|
|
|
$uri_page = $html->find('a', $i + 3)->href;
|
|
$uri = self::URI . $uri_page;
|
|
$item['uri'] = $uri;
|
|
|
|
$picture_html = getSimpleHTMLDOM($uri);
|
|
$picture_html_string = $picture_html->innertext;
|
|
|
|
//Extract image and explanation
|
|
$media = $picture_html->find('p', 1)->innertext;
|
|
$media = strstr($media, '<br>');
|
|
$media = preg_replace('/<br>/', '', $media, 1);
|
|
$explanation = $picture_html->find('p', 2)->innertext;
|
|
|
|
//Extract date from the picture page
|
|
$date = explode(" ", $picture_html->find('p', 1)->innertext);
|
|
$item['timestamp'] = strtotime($date[4] . $date[3] . $date[2]);
|
|
|
|
//Other informations
|
|
$item['content'] = $media . '<br />' . $explanation;
|
|
$item['title'] = $picture_html->find('b', 0)->innertext;
|
|
$this->items[] = $item;
|
|
}
|
|
}
|
|
}
|