Регистрация    Забыли пароль?        Правила форума    FAQ (читать перед созданием новой темы)
Имя   Пароль  запомнить
  
Просмотр темы
Вернуться на сайт: PHP-Fusion SF Russian Support Site

Форум поддержки PHP-Fusion SF | PHP-Fusion SF - Моды/Плагины | Плагины/Plugins
# 1 Тема: Погода на вашем сайте
PahaW
SF Team

Avatar пользователя




SF Support Team

Любитель Fusion

Сообщений: 148
Зарегистрирован: 02 Июня 2009, 10:04:06
Сказали спасибо 12 раз
Статус: offline
Опубликовано 21 Июля 2012, 16:20:48
Есть интересная статья по ней можно сделать себе на сайт плагин или панельку, кто какую cms использует.
Create A Weather Application With Google API Using PHP
Прочитав статейку я решил сделать панельку для php-fusion
вот что получилось:
php панелька

<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2008 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: welcome_message_panel.php
| Author: Nick Jones (Digitanium)
| Edit by: PahaW
+--------------------------------------------------------+
| Вывод погоды, с прогнозом на три дня
+--------------------------------------------------------*/
if (!defined("IN_FUSION")) { die("Access Denied"); }
add_to_head("<link href='".INFUSIONS."/weather_panel/weather/weather.css' media='screen, projection' rel='stylesheet' type='text/css' />");
opentable("Погода города Хабаровска");
include(INFUSIONS."/weather_panel/weather/index.php");
closetable();
?>




стиль:

body{font-family: 'Droid Sans', sans-serif;background:#eee;color:#888;padding:0;margin:0;font-size: 72.5%; }

/*Headers*/
h1, h1 a, h1 a:hover{ color:#FFF; font-family: Arial; margin:10px;}
h1, h1 a, h1 a:hover, h2, h3, h4, h5, h6 { line-height: 1.1em; color:#444;font-family: 'PT Sans Narrow', Calibri, 'Myriad Pro', Tahoma, Arial; padding: 10px 0; margin:0;}
h1, h1 a, h2 { font-size: 30px; letter-spacing: -1px;}
h3 { font-size: 30px; }
h4 { font-size: 22px; font-weight: normal; padding-bottom: 10px;}

.future_weather {
display: inline-block;
border: 1px solid #eee;
padding: 15px;
margin: 3px;
text-align: center;
}

.now_weather {
display: inline-block;
border: 1px solid #eee;
padding: 15px;
}

strong, b {
font-weight: bold;
}
p {
font-size: 115%;
}

.container {
width: 900px;
margin: 30px auto;
padding: 25px;
min-height: 400px;
height: auto;
background: white;
}






php код

<?php
function getWeather() {
$requestAddress = "http://www.google.com/ig/api?weather=khabarovsk&hl=ru&oe=utf-8";
// скачиваем данные о погоде
$xml_str = file_get_contents($requestAddress,0);
// парсим XML
$xml = new SimplexmlElement($xml_str);
// обрабатываем XML
$count = 0;

$weather = array();
$icons_google = "/ig/images/weather/"; //alte Google-Version
$icons_src = "/";

// Общая информация
#$weather['city'] = $xml->weather->forecast_information->city->attributes()->data;
$weather['date'] = $xml->weather->forecast_information->forecast_date->attributes()->data;
$weather['time'] = $xml->weather->forecast_information->current_date_time->attributes()->data;

// Погода
$weather[0]['state'] = $xml->weather->current_conditions->condition->attributes()->data; // состояние
$weather[0]['temperature'] = $xml->weather->current_conditions->temp_c->attributes()->data; // Температура
$weather[0]['humidity'] = $xml->weather->current_conditions->humidity->attributes()->data; // Влажность
$weather[0]['wind'] = $xml->weather->current_conditions->wind_condition->attributes()->data; // ветер
$weather[0]['icon'] = str_replace($icons_google, $icons_src, $xml->weather->current_conditions->icon->attributes()->data); // Картинка

// Массив прогноза погоды
$i=1;
foreach($xml->weather as $item) {
foreach($item->forecast_conditions as $new) {
$weather[$i]['weeks'] = $new->day_of_week['data'];
$weather[$i]['state'] = $new->condition['data'];
$weather[$i]['mintemperature'] = $new->low['data'];
$weather[$i]['maxtemperature'] = $new->high['data'];
$weather[$i]['icon'] = str_replace($icons_google, $icons_src, $new->icon['data']);
$i++;
}
}
echo '</div>';
return $weather;
}

/*
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<link rel='stylesheet' href='weather.css' type='text/css' media='all' />
<title>weather</title>
";
*/
// Вывод погоды
$weather = getWeather();


echo "<section class='container'>";

// Пример вывода
#echo "<h1>".$weather['city'].":</h1>\n";
echo "<h2>Погода в Хабаровске </h2>\n";
echo "<div class='now_weather'>";
echo "<p><img src=\"http://www.google.com/ig/images/weather".$weather[0]['icon']."\" align=\"left\" alt=\"".$weather[0]['state']."\" />\n";
echo $weather[0]['state']."<br/>\n";
echo "Температура: ".$weather[0]['temperature']."° C<br/>\n";
echo $weather[0]['humidity']."<br/>\n";
echo $weather[0]['wind']."</p>\n";
echo "</div>";

echo "<h4>Прогноз погоды:</h4>\n";
for ($i=1;$i<=4;$i++){
echo "<div class='future_weather'>";
echo "<h2>".$weather[$i]['weeks']."</h2><br/>\n";
echo "<img src=\"http://www.google.com/ig/images/weather".$weather[$i]['icon']."\" alt=\"".$weather[$i]['state']."\" />\n";
echo "<p>".$weather[$i]['state']."</p>\n";
echo "<p>".$weather[$i]['mintemperature']."° C - ".$weather[$i]['maxtemperature']."° C</p>\n";
echo "</div>";
}

echo "</section>";

?>


Прикрепленные файлы
Для просмотра вложения зарегистрируйтесь


--------------------
-> покинул проект
^ наверх ^ paha.khspu.ru/blog
2 пользователей сказали спасибо Вам: snake_oriental, mentaljam
Перейти на форум:


94,175,948 уникальных посетителей
сейчас: 29 Марта 2024, 17:28:06
Генерация страницы: 0.04 сек.