Exemplo n.º 1
0
<?php

header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>\n<rss version='2.0'\n    xmlns:w='http://tempuri.org'\n\txmlns:wfw='http://wellformedweb.org/CommentAPI/'\n\txmlns:dc='http://purl.org/dc/elements/1.1/'\n\txmlns:atom='http://www.w3.org/2005/Atom'\n\txmlns:sy='http://purl.org/rss/1.0/modules/syndication/'\n\txmlns:slash='http://purl.org/rss/1.0/modules/slash/'>\n<channel>\n<title>NASA PHOTOS</title>\n<link>https://marspictures.herokuapp.com/</link>\n<description>Nasa Photos</description>\n<atom:link href='https://marspictures.herokuapp.com/feed.php' rel='self' type='application/rss+xml' />\n<language>en-us</language>";
require 'rover.php';
$Mars = new HelloMars();
$today = strtotime(date("Y-m-d"));
$DateToSearch = date("Y-m-d", mt_rand(1080777600, $today));
$RoverPick = mt_rand(0, 2);
$RoverArray = array_keys($Mars->rovers);
$images = json_decode($Mars->getPictures($DateToSearch, $RoverArray[$RoverPick]));
if (isset($images) && !isset($images->photos)) {
    exit;
    //Just to avoid reach the API limit
} else {
    $rssfeed = '';
    foreach ($images as $image) {
        for ($i = 0; $i < count($image); $i++) {
            $rssfeed .= '<item>';
            $rssfeed .= '<title>' . $image[$i]->id . '</title>';
            $rssfeed .= '<guid>' . $image[$i]->img_src . '</guid>';
            $rssfeed .= '<w:id>' . $image[$i]->id . '</w:id>';
            $rssfeed .= '<w:sol>' . $image[$i]->sol . '</w:sol>';
            $rssfeed .= '<w:camera_name>' . $image[$i]->camera->name . '</w:camera_name>';
            $rssfeed .= '<w:img_src>' . $image[$i]->img_src . '</w:img_src>';
            $rssfeed .= '<w:earth_date>' . date("d/m/Y", strtotime($image[$i]->earth_date)) . '</w:earth_date>';
            $rssfeed .= '<w:rover_name>' . $image[$i]->rover->name . '</w:rover_name>';
            $rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($image[$i]->earth_date)) . '</pubDate>';
            $rssfeed .= '</item>';
        }
    }
Exemplo n.º 2
0
<?php

require "rover.php";
$Mars = new HelloMars();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" type="text/css" href="style.css">
    <title>Pesquise as Fotos de Marte</title>

    <!-- Bootstrap -->
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <!-- Google Fonts -->
    <link href='https://fonts.googleapis.com/css?family=Ubuntu:400,500,700,300,300italic,400italic,500italic,700italic' rel='stylesheet' type='text/css'>
</head>
<body>
<a href="https://github.com/joelgarciajr84/nasa-mars-pictures"><img style="position: absolute; top: 0; left: 0; border: 0;" src="images/fork-me.png" alt="Fork me on GitHub" data-canonical-src="images/fork-me.png"></a>

<div class="row row-header" id="top">
  <div class="container">

<?php 
if (!$Mars->CheckConnection()) {
    echo "<p align='center' class='red'></p>";
} else {
    echo "<p align='center' class='green'></p>";