summaryrefslogtreecommitdiff
path: root/protected
diff options
context:
space:
mode:
authorPatrick Seeger <pseeger@ccwn.org>2012-04-18 21:34:43 +0200
committerPatrick Seeger <pseeger@ccwn.org>2012-04-18 21:34:43 +0200
commit25c813f5eb00d321d5096d2347363a2f58cb1c93 (patch)
tree3d8f06ec3311e307223e762ffc0342fdb455800a /protected
parent6ee1ed2be48a7f3d739aed838f17a30f485851d1 (diff)
Wetter eingebaut
Diffstat (limited to 'protected')
-rw-r--r--protected/config/main.php4
-rw-r--r--protected/extensions/wetter/Wetter.php65
-rw-r--r--protected/extensions/wetter/views/wetter.php21
3 files changed, 90 insertions, 0 deletions
diff --git a/protected/config/main.php b/protected/config/main.php
index ca66538..e9c97aa 100644
--- a/protected/config/main.php
+++ b/protected/config/main.php
@@ -18,6 +18,7 @@ return array(
'application.models.*',
'application.components.*',
'application.extensions.ddeditor.*',
+ 'application.extensions.wetter.*',
),
'modules'=>array(
@@ -38,6 +39,9 @@ return array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
+ 'cache' => array(
+ 'class' => 'system.caching.CDummyCache',
+ ),
// uncomment the following to enable URLs in path-format
/*
'urlManager'=>array(
diff --git a/protected/extensions/wetter/Wetter.php b/protected/extensions/wetter/Wetter.php
new file mode 100644
index 0000000..de2ec93
--- /dev/null
+++ b/protected/extensions/wetter/Wetter.php
@@ -0,0 +1,65 @@
+<?php
+class Wetter extends CWidget {
+
+ public function run(){
+ $wetter = $this->website_wetter('71332','Germany');
+ $this->render('wetter', compact('wetter'));
+ }
+
+ /*
+ Nutzung dieses Scripts nur gestattet, wenn Kommentare in PHP nicht entfernt werden oder ein Link zu folgender Adresse gesetzt wird:
+ URL: http://www.web-spirit.de/webdesign-tutorial/9/Wetter-auf-eigener-Website-mit-Google-Weahter-API
+ Beschreibung: Wettervorhersage auf der eigenen Website mit Zugriff auf die Google Weather API
+ Autor: Sebastian Gollus
+ Internet: http://www.web-spirit.de
+ Version: 1.0.201106
+ */
+
+ // Funktionsaufruf z.B.: $wetter = website_wetter("46562", "Germany", "/images/wetter/icons/", "de");
+
+ private function website_wetter($plz, $land, $icons_src="/", $sprache="de", $ort="")
+ {
+ $icons_google = "/ig/images/weather/"; //alte Google-Version
+ //$icons_google = "http://g0.gstatic.com/images/icons/onebox/"; //neue Google-Version (bzw. zwischenzeitlich geändert)
+
+ if($ort != "")
+ {
+ $station = $ort;
+ }
+ else
+ {
+ $station = $plz."-".$land;
+ }
+
+ $api = simplexml_load_string(utf8_encode(file_get_contents("http://www.google.com/ig/api?weather=".$station."&hl=".$sprache)));
+
+ $wetter = array();
+
+ // Allgemeine Informationen
+ $wetter['stadt'] = $api->weather->forecast_information->city->attributes()->data;
+ $wetter['datum'] = $api->weather->forecast_information->forecast_date->attributes()->data;
+ $wetter['zeit'] = $api->weather->forecast_information->current_date_time->attributes()->data;
+
+ // Aktuelles Wetter
+ $wetter[0]['zustand'] = $api->weather->current_conditions->condition->attributes()->data;
+ $wetter[0]['temperatur'] = $api->weather->current_conditions->temp_c->attributes()->data;
+ $wetter[0]['luftfeuchtigkeit'] = $api->weather->current_conditions->humidity->attributes()->data;
+ $wetter[0]['wind'] = $api->weather->current_conditions->wind_condition->attributes()->data;
+ $wetter[0]['icon'] = str_replace($icons_google, $icons_src, $api->weather->current_conditions->icon->attributes()->data);
+
+ // Wettervorhersage heute, morgen, in zwei und in drei Tagen ($wetter[1] bis $wetter[4])
+ $i = 1;
+ foreach($api->weather->forecast_conditions as $weather)
+ {
+ $wetter[$i]['wochentag'] = $weather->day_of_week->attributes()->data;
+ $wetter[$i]['zustand'] = $weather->condition->attributes()->data;
+ $wetter[$i]['tiefsttemperatur'] = $weather->low->attributes()->data;
+ $wetter[$i]['hoechsttemperatur'] = $weather->high->attributes()->data;
+ $wetter[$i]['icon'] = str_replace($icons_google, $icons_src, $weather->icon->attributes()->data);
+
+ $i++;
+ }
+
+ return $wetter;
+ }
+} \ No newline at end of file
diff --git a/protected/extensions/wetter/views/wetter.php b/protected/extensions/wetter/views/wetter.php
new file mode 100644
index 0000000..0b4c831
--- /dev/null
+++ b/protected/extensions/wetter/views/wetter.php
@@ -0,0 +1,21 @@
+ <div class="ym-grid linearize-level-2">
+ <div class="ym-g50 ym-gl">
+ <div class="ym-gbox-left">
+ <!-- content -->
+
+ <h6>Aktuell</h6>
+ <p><?php echo "<img class=\"float-left bordered\" src=\"https://www.google.com/images/weather/".$wetter[0]['icon']."\" alt=\"".$wetter[0]['zustand']."\" />".$wetter[0]['zustand']." bei ".$wetter[0]['temperatur']."&deg; C"; ?></p>
+ </div>
+ </div>
+ <div class="ym-g50 ym-gr">
+ <div class="ym-gbox-right">
+ <!-- content -->
+ <h6><?php echo $wetter[2]['wochentag'];?></h6>
+ <p ><?php echo "<img class=\"float-left bordered\" src=\"https://www.google.com/images/weather/".$wetter[2]['icon']."\" alt=\"".$wetter[2]['zustand']."\" />".$wetter[2]['zustand']." bei min. ".$wetter[2]['tiefsttemperatur']."&deg; C bis max. ".$wetter[2]['hoechsttemperatur']."&deg; C"; ?></p>
+ </div>
+ </div>
+ </div>
+
+
+
+