Version avec modules séparés !

This commit is contained in:
Chouchen
2010-09-27 10:48:53 +00:00
parent 2861556131
commit 734e6f4829
81 changed files with 324 additions and 264 deletions

104
modules/weather/Weather.php Normal file
View File

@@ -0,0 +1,104 @@
<?php
class weather extends Module {
protected $moduleName;
protected $moduleTitle;
protected $pathToModule;
protected static $paramsList = array(
'visibility',
'city',
'x',
'y'
);
public $params = array();
public function __construct($params){
$this->moduleName = get_class();
$this->pathToModule = 'modules/'.$this->moduleName.'/';
$this->setParams($params);
$ville = $params['city'];
include $this->pathToModule.'includes/GoogleMeteo.php';
echo '<script type="text/javascript" src="'.$this->pathToModule.'js/'.$this->moduleName.'.js"></script>
<link rel="stylesheet" type="text/css" href="'.$this->pathToModule.'css/'.$this->moduleName.'.css">';
echo '<div id="weather" style="left:'.$params['x'].'; top:'.$params['y'].';">
'.$city.'<br/>
<div class="weatherpic"></div>
<strong>'.$present_weather.'</strong><br/>
'.$future_weather1.'<br/>
'.$future_weather2.'
</div>';
}
private function setParams($params){
$this->params = $params;
}
public static function start($params){
$weather = new weather($params);
}
/**
*
* Modifie la ville
* @param String $city la ville.
* @return String "ok" ou message d'erreur (effectue aussi l'enregistrement en XML)
*/
public function setCity($city){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='weather']");
$path[0]->city = $city;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setX($x){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='weather']");
$path[0]->x = $x;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setY($y){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='weather']");
$path[0]->y = $y;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setVisibility($visibility){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);
$path = $xmla->xpath("//item[@id='weather']");
$path[0]->visibility = $visibility;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public static function updateConfig($updated){
foreach ($updated as $what=>$withWhat){
if(in_array($what, self::$paramsList)){
call_user_func(array(get_class(), "set".ucfirst($what)), $withWhat);
}
}
}
}

View File

@@ -0,0 +1 @@
#weather .weatherpic{float:left; background:url(../images/weather/pluie.png) top left no-repeat; width:53px; height:53px; margin-right:10px;}

View File

@@ -0,0 +1 @@
#weather .weatherpic{float:left; background:url(../images/weather/nuage.png) top left no-repeat; width:53px; height:53px; margin-right:10px;}

View File

@@ -0,0 +1 @@
#weather .weatherpic{float:left; background:url(../images/weather/peu-nuageux.png) top left no-repeat; width:53px; height:53px; margin-right:10px;}

View File

@@ -0,0 +1 @@
#weather .weatherpic{float:left; background:url(../images/weather/pluie.png) top left no-repeat; width:53px; height:53px; margin-right:10px;}

View File

@@ -0,0 +1 @@
#weather .weatherpic{float:left; background:url(../images/weather/soleil.png) top left no-repeat; width:53px; height:53px; margin-right:10px;}

View File

@@ -0,0 +1,6 @@
#weather {position:absolute; top:10px; left: 100px;padding:5px;-webkit-border-radius: 5px;
-moz-border-radius: 5px;border: 1px solid rgba(0,0,0,0.3);
-webkit-box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.15);
-moz-box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.15);}
#city-submit{cursor:pointer;}

View File

@@ -0,0 +1,38 @@
<?php
require('class/GoogleWeather.class.php');
//ça récupère un truc du style : http://www.google.com/ig/api?weather=paris&hl=fr
if($ville != '' || $ville != null){
$gweather = new GoogleWeatherAPI($ville,'fr');
if($gweather->isFound()) {
$city = $gweather->getCity();
$currentTemp = $gweather->getCurrent();
$forecastTemp = $gweather->getForecast();
$present_weather = 'Actuellement : '.$currentTemp['temp_c'].'°C - '.$currentTemp['condition'];
$i=0;
foreach($forecastTemp as $temp) {
${'future_weather'.$i} = $temp['day_of_week'].' : '.$temp['low'].'°C | '.$temp['high'].'°C - '.$temp['condition'];
$i++;
}
if(strpos(strtolower($present_weather),"soleil") !== false) {?>
<link rel="stylesheet" type="text/css" href="modules/weather/css/soleil.css">
<?}
if(strpos(strtolower($present_weather),"nuage") !== false) {?>
<link rel="stylesheet" type="text/css" href="modules/weather/css/nuage.css">
<?}
if(strpos(strtolower($present_weather),"peu nuageux") !== false) {?>
<link rel="stylesheet" type="text/css" href="modules/weather/css/peunuage.css">
<?}
if((strpos(strtolower($present_weather),"pluie") !== false) || (strpos(strtolower($present_weather),"averse") !== false)) {?>
<link rel="stylesheet" type="text/css" href="modules/weather/css/pluie.css">
<?}
if(strpos(strtolower($present_weather),"neige") !== false) {?>
<link rel="stylesheet" type="text/css" href="modules/weather/css/neige.css">
<?}
}else{ $present_weather = 'Ville non trouvé : '.$city; }
}else
$present_weather = 'Ville non renseignée';

View File

@@ -0,0 +1,26 @@
<?php
if ($weather = simplexml_load_file('http://www.my-meteo.fr/meteo+rss+paris.html')){
$present_weather = $weather->channel->item[0]->title;
$future_weather1 = $weather->channel->item[1]->title;
$future_weather2 = $weather->channel->item[2]->title;
if(strpos(strtolower($present_weather),"soleil") !== false) {?>
<link rel="stylesheet" type="text/css" href="css/soleil.css">
<?}
if(strpos(strtolower($present_weather),"nuage") !== false) {?>
<link rel="stylesheet" type="text/css" href="css/nuage.css">
<?}
if(strpos(strtolower($present_weather),"peu nuageux") !== false) {?>
<link rel="stylesheet" type="text/css" href="css/peunuage.css">
<?}
if((strpos(strtolower($present_weather),"pluie") !== false) || (strpos(strtolower($present_weather),"averse") !== false)) {?>
<link rel="stylesheet" type="text/css" href="css/pluie.css">
<?}
if(strpos(strtolower($present_weather),"neige") !== false) {?>
<link rel="stylesheet" type="text/css" href="css/neige.css">
<?}
}
else
{
die ('Flux RSS non trouvé');
}
?>

View File

@@ -0,0 +1,30 @@
$(document).ready(function(){
$('body').append('<a href="#city" id="city-menu"><img src="images/interface/weather.png" /></a><div style="display:none;"><div id="city"></div></div>');
$('#menu-bar').prepend($('#city-menu'));
$('#city').append('<h3>Quelle ville pour la meteo ?</h3><br/><input type="text" id="cityChoice" name="cityChoice"/><span id="city-submit" class="green-button">Enregistrer</span>');
$('#city-menu').fancybox({
'zoomSpeedIn' : 600,
'zoomSpeedOut' : 500,
'easingIn' : 'easeOutBack',
'easingOut' : 'easeInBack',
'hideOnContentClick': false,
'padding' : 15
});
$('#city-submit').live('click', function(){
var ville = $('#cityChoice').val();
if(ville != '' || ville != null){
$.get('ajax/update.php', {id:'weather', city: ville}, function(msg){
location.reload();
});
}else{
$('#city').append('<span class="error">City can\'t be empty.</span>');
}
});
var tmp;
/* A helper function for converting a set of elements to draggables: */
make_draggable($('#weather'));
});