-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
70 lines (51 loc) · 1.94 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Weather Open</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="form-content">
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post">
<h2>Current Weather In Your City</h2>
<input id="text" type="text" name="city" placeholder="Type your city name...">
<input id="submit" name="submit" type="submit" value="Search">
</form>
</div>
<div class="outer">
<div class="inner">
<?php
if(isset($_POST['submit']) && !empty($_POST['city'])):
require('OpenWeather.php');
$openweather = new OpenWeather();
$openweather->cleanData($_POST['city']);
$json = 'http://api.openweathermap.org/data/2.5/weather?q='.htmlspecialchars($_POST['city'])."&units=metric";
$openweather->getJsonData($json);
$openweather->populateJsonData();
//echo $_POST['city'];
?>
<?php
if($openweather->has_data){
echo "<img class='weather-image' src='images/". $openweather->getWeatherImage() ."'>";
echo "<div class='weather-info'>";
echo "<a href='http://openweathermap.org/city/". $openweather->id ."/'>". $openweather->city ."</a>";
echo "<img src='http://openweathermap.org/images/flags/". $openweather->flag_image .".png'>";
echo "<h4 class='temperature'>". round($openweather->temperature,1) ."°С</h4>";
echo "<span>". $openweather->weather ."</span>";
echo "<p>Geo coords <a href='http://openweathermap.org/Maps?zoom=12&lat=". $openweather->coords_lat ."&lon=". $openweather->coords_lon ."&layers=B0FTTFF'>[ ". $openweather->coords_lon .", ". $openweather->coords_lat ." ]</a></p>";
}
else {
echo "<p class='error'>Not found city.</p>";
}
echo "</div>";
?>
<?php
else:
echo "<p class='error'>No data to display.</p>";
endif
?>
</div>
</div>
</body>
</html>