-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_cg_meteo.php
118 lines (107 loc) · 4.44 KB
/
mod_cg_meteo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Simple meteo module
* Version : 2.1.0
* Package : Joomla 4.x/5.x
* copyright : Copyright (C) 2023 ConseilGouz. All rights reserved.
* license : http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
defined( '_JEXEC' ) or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use ConseilGouz\Module\CGMeteo\Site\Helper\MeteoHelper;
$modulefield = 'media/mod_cg_meteo/';
$helper = new MeteoHelper;
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseStyle('cgstyle', $modulefield.'css/style.css');
$wa->registerAndUseStyle('cgup', $modulefield.'css/up.css');
if ($params->get("country","fr") == "fr") {
$ville = $params->get('ville');
$long = $params->get('long');
$lat = $params->get('lat');
} else {
$ville = $params->get('ville_wd');
$long = $params->get('long_wd');
$lat = $params->get('lat_wd');
}
$output = "<div id='cg_meteo_".$module->id."' name='cg_meteo_".$module->id."' method=get class='mod_cg_meteo".$params->get( 'moduleclass_sfx' )."'>\n";
if ($params->get('temp_unit') == 'f') { $temp_unit = 'f'; } else { $temp_unit = 'c'; };
if ($params->get('meteo_api','open') == "open" ) {
if ($params->get('needopen','0') == 1) {
$helper->meteo_open($lat,$long, $ville, $temp_unit,$params->get('openkey') );
} else {
$helper->meteo_open($lat,$long, $ville, $temp_unit);
}
}
if ($params->get('meteo_api','open') == "yahoo" ) {
$helper->meteo_yahoo($params->get('woeid'), $temp_unit);
}
if ($params->get('meteo_api','yahoo') == "xu" ){
if ($params->get('needxu','0') == 1) {
$helper->meteo_xu($lat,$long, $ville,$temp_unit,$params->get('xukey'));
} else {
$helper->meteo_xu($lat,$long, $ville,$temp_unit);
}
}
if ($params->get('meteo_api','open') == "bit" ){
if ($params->get('needbit','0') == 1) {
$helper->meteo_bit($lat,$long, $ville,$temp_unit,$params->get('bitkey'));
} else {
$helper->meteo_bit($lat,$long, $ville,$temp_unit);
}
}
if ($params->get('meteo_api','open') == "darksky" ){
$helper->meteo_open($lat,$long, $ville, $temp_unit );
//if ($params->get('needdarksky','0') == 1) {
// $helper->meteo_darksky($lat,$long, $ville,$temp_unit,$params->get('darkskykey'));
// } else {
// $helper->meteo_darksky($lat,$long, $ville,$temp_unit);
// }
}
if ($helper->isfound()) {
$icon_path = URI::Base(false)."media/mod_cg_meteo/icons/";
$actuelle = $helper->getCurrent();
$img_margin = "5px 0";
if ($params->get('img_align')=="left") { $img_margin = "0 10px 5px 0"; }
if ($params->get('img_align')=="right") { $img_margin = "0 0 5px 10px"; }
$now = date('');
if ($params->get('afficher_date', 0)) $output .= "<div class='cg_meteo_date'>".HTMLHelper::date( $now, Text::_($params->get('afficher_date')))."</div>";
if ($params->get('afficher_ville', 1)) $output .= "<div class='cg_meteo_city'>".$helper->getCity()."</div>";
switch ($params->get('temp_unit')) {
case 'c':
$tmp_actuelle = $actuelle['temp']." °C";
$unit = "C";
break;
case 'f':
$tmp_actuelle = $actuelle['temp']." °F";
$unit = "F";
break;
default:
if ($helper->getUnit_system() == 'C') {
$tmp_actuelle = "( ".round(($actuelle['temp']*9/5)+32)." °F / ";
$tmp_actuelle .= $actuelle['temp']." °C )";
$unit = false;
} else {
$tmp_actuelle = "( ".$actuelle['temp']." °F / ";
$tmp_actuelle .= round(($actuelle['temp']-32)*5/9)." °C )";
$unit = false;
}
}
// output previsions
$previsions = $helper->getForecast();
$unit_system = $helper->getUnit_system();
if (!$unit) $unit = ($unit_system=="US") ? "F" : "C";
if ($params->get('meteo_api','yahoo') == "open" ) $output .= include dirname(__FILE__).'/tmpl/previsions_open.php';
if ($params->get('meteo_api','yahoo') == "yahoo" ) $output .= include dirname(__FILE__).'/tmpl/previsions_yahoo.php';
if ($params->get('meteo_api','yahoo') == "xu" ) $output .= include dirname(__FILE__).'/tmpl/previsions_xu.php';
if ($params->get('meteo_api','yahoo') == "darksky" ) $output .= include dirname(__FILE__).'/tmpl/previsions_open.php';
if ($params->get('meteo_api','yahoo') == "bit" ) $output .= include dirname(__FILE__).'/tmpl/previsions_bit.php';
} else {
$output .=error_get_last()['message'];
}
$output .= "</div>";
echo $output;
?>