Twitter-инструментарий на Ruby on Rails
Виджет amoCRM: экспорт данных в Google Docs
Alternative caching Joomla module
API Яндекс Метрика и Highcharts
JavaScript SELECT. Динамические списки
Extended weather informer. Weather Underground
Снова про курс валют Центробанка, про cross-origin и джаваскрипты
jTriad contact form - контактная форма для Joomla
jExchange rates CBR, модуль Joomla 3
Joomla: интернет-магазин без VirtueMart. K2Store
jWeather by ip. Погода по ip для Joomla!
CSV Improved. Настройка импорта из csv-файла в VirtueMart
Подарок бухгалтеру, или КЛАДР для Community Builder
Joomla и SuperJob: вакансии по API
<?php
function randomImage(){
$best_images = Array(
"http://apod.nasa.gov/apod/image/1210/geyseraurora_howell_2163.jpg",
"http://apod.nasa.gov/apod/image/1210/meteorviolet_salomonsen_1200.jpg",
"http://apod.nasa.gov/apod/image/1010/hartley2pacman_fernandez.jpg",
"http://apod.nasa.gov/apod/image/1007/ISS023-E-58455lrg.jpg"
);
return $best_images[rand(0, count($best_images)-1)];
}
function isNotFound($url){
$response = get_headers($url, 1);
$response = explode(" ", $response[0]);
$response = $response[1];
if ($response=="404") return true;
else return false;
}
include('simple_html_dom.php');
$url="http://apod.nasa.gov";
$html=file_get_html($url);
$img = $html->find('img', 0)->parent->href;
if ($img=='') $img = randomImage();
else{
$img="http://apod.nasa.gov/apod/".$img;
if (isNotFound($img)) $img = randomImage();
}
header("location: ".$img);
?>
<?
$json = file_get_contents('https://api.data.gov/nasa/planetary/apod?concept_tags=True&api_key=VASH_API_KEY');
$obj = json_decode($json);
?>
<style type="text/css">
.exp {
font-style: italic;
}
.img_apod img {
width: 600px;
}
</style>
<div class="img_apod"><?='<img src="' . $obj->url . '"/>';?></div>
<p> </p>
<div class="exp"><?=($obj->date);?></div>
<div class="exp"><?=($obj->explanation);?></div>
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Aleksej пишет: здесь же публикую два скрипта, о которых...
Hi Alex,
I'm looping in the NASA team.
Gray
Hi Alex, Working on it. Something strange is going on for today's APOD, but it will certainly work tomorrow. Sorry about this.
Dan
<?
$best_images = Array(
"http://apod.nasa.gov/apod/image/1210/geyseraurora_howell_2163.jpg",
"http://apod.nasa.gov/apod/image/1210/meteorviolet_salomonsen_1200.jpg",
"http://apod.nasa.gov/apod/image/1010/hartley2pacman_fernandez.jpg",
"http://apod.nasa.gov/apod/image/1007/ISS023-E-58455lrg.jpg"
);
$json = file_get_contents('https://api.data.gov/nasa/planetary/apod?concept_tags=True&api_key=VASH_API_KEY');
$obj = json_decode($json);
if(empty($json)){
$rand_keys = array_rand($best_images, 1);
echo '<img src="' . $best_images[$rand_keys] . '"/>';
}
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Aleksej пишет: Допишем проверку на пустоту для JSON
{"message": "Your request could not be processed. Admins have been notified.", "error": "No APOD imagery for the given date."}
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
<?
$best_images = Array(
"http://apod.nasa.gov/apod/image/1210/geyseraurora_howell_2163.jpg",
"http://apod.nasa.gov/apod/image/1210/meteorviolet_salomonsen_1200.jpg",
"http://apod.nasa.gov/apod/image/1010/hartley2pacman_fernandez.jpg",
"http://apod.nasa.gov/apod/image/1007/ISS023-E-58455lrg.jpg"
);
$json = file_get_contents('https://api.data.gov/nasa/planetary/apod?concept_tags=True&api_key=VASH_API_KEY');
$obj = json_decode($json);
if (array_key_exists('message', $obj)) {
$rand_keys = array_rand($best_images, 1);
echo '<img src="' . $best_images[$rand_keys] . '"/>';
}
else {
?>
<style type="text/css">
.exp {
font-style: italic;
}
.img_apod img {
width: auto;
}
</style>
<div class="img_apod"><?='<img src="' . $obj->url . '"/>';?></div>
<p> </p>
<div class="exp"><?=($obj->date);?></div>
<div class="exp"><?=($obj->explanation);?></div>
<?
}
?>
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
<style type="text/css">
.exp {
font-style: italic;
}
.img_apod img {
width: 70%;
}
</style>
<?
$url = 'https://api.nasa.gov/planetary/apod?api_key=******************************';
$obj = json_decode(file_get_contents($url));
$headers = @get_headers($obj->url);
$rest = substr($headers[1], 10);
if(!preg_match("|200|", $headers[5])) {
$best_images = Array(
"https://apod.nasa.gov/apod/image/1210/geyseraurora_howell_2163.jpg",
"https://apod.nasa.gov/apod/image/1210/meteorviolet_salomonsen_1200.jpg",
"https://apod.nasa.gov/apod/image/1010/hartley2pacman_fernandez.jpg",
"https://apod.nasa.gov/apod/image/1007/ISS023-E-58455lrg.jpg"
);
$rand_keys = array_rand($best_images, 1);
echo '<div class="img_apod"><img src="' . $best_images[$rand_keys] . '"/>';
} else {
?>
<p> </p>
<div class="img_apod"><?='<img src="' . $rest . '"/>';?></div>
<p> </p>
<div class="exp"><?=($obj->date);?></div>
<p> </p>
<div class="exp"><?=($obj->explanation);?></div>
<?
}
?>
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
<style type="text/css">
.exp {
font-style: italic;
}
.img_apod img {
width: 70%;
}
</style>
<?
$url = 'https://api.nasa.gov/planetary/apod?api_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$obj = json_decode(file_get_contents($url));
if (strpos($obj->media_type, 'video') !== false) {
preg_match('#(\.be/|/embed/|/v/|/watch\?v=)([A-Za-z0-9_-]{5,11})#', $obj->url, $matches);
if (isset($matches[2]) && $matches[2] != '') {
$YoutubeCode = $matches[2];
}
echo '<iframe src="https://www.youtube.com/embed/' . $YoutubeCode . '" type="text/html" width="640" height="360" frameborder="0"></iframe>';
?>
<p> </p>
<div class="exp"><?= ($obj->date); ?></div>
<p> </p>
<div class="exp"><?= ($obj->explanation); ?></div>
<?
} elseif (@fopen($obj->url, 'r')) {
?>
<p> </p>
<div class="img_apod"><?= '<img src="' . $obj->url . '"/>'; ?></div>
<p> </p>
<div class="exp"><?= ($obj->date); ?></div>
<p> </p>
<div class="exp"><?= ($obj->explanation); ?></div>
<?
} else {
$best_images = Array(
"https://apod.nasa.gov/apod/image/1210/geyseraurora_howell_2163.jpg",
"https://apod.nasa.gov/apod/image/1210/meteorviolet_salomonsen_1200.jpg",
"https://apod.nasa.gov/apod/image/1010/hartley2pacman_fernandez.jpg",
"https://apod.nasa.gov/apod/image/1007/ISS023-E-58455lrg.jpg"
);
$rand_keys = array_rand($best_images, 1);
echo '<div class="img_apod"><img src="' . $best_images[$rand_keys] . '"/>';
}
?>
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Masterpro.ws © 2009 - 2020 Ruby and PHP Development. Web Studio