-
Notifications
You must be signed in to change notification settings - Fork 2
/
cachemanager.php
176 lines (135 loc) · 3.42 KB
/
cachemanager.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/*echo var_dump(getWeatherDetails("Nagpur"));
echo "<br/> Events <br/>";
echo var_dump(getEventDetails("New York"));
echo var_dump(getNewsDetails("Nagpur"));
*/
//echo postLoginAction("jay",21.16,79.06);
//echo postLoginAction("naruto",51.686031,0.280360);
//echo getUserInfo("naruto");
function getUserInfo($userId)
{
include_once "./utils/geo.php";
$tmppath= "./.cache/users/".$userId;
if(file_exists($tmppath))
{
$fh=fopen($tmppath,"r");
$result = fread($fh, 10000);
return $result;
}
else
return "USER IS NOT ONLINE ON OUR SYSTEM!! Seems (s)he doesn't like to have fun! :P";
}
function postLogoutAction($userId)
{
$tmppath= "./.cache/users/".$userId;
if($debug) echo $tmppath;
unlink($tmppath);
}
function postLoginAction($userId, $city)
{
include_once "./utils/geo.php";
//$city = reverseGeocodeCity($lat,$lon);
$weather = getWeatherDetails($city);
$events = getEventDetails($city);
$news = getNewsDetails($city);
$output = "";
//Inserting weather info
$output .= "<h3>Weather at " . $userId . "'s place</h3>";
$output .= $weather->query->results->weather->rss->channel->item->description;
$output .= "<br /><h3>News, Buzz and stuff.. </h3><br/>";
$results = $news->query->results->results;
foreach ($results as $result) {
$output .= "<div class='news'>";
$output .= "<div class='newstitle'>";
$output .= $result->title;
$output .= "</div>";
$output .= "<div class='newscontent'>";
$output .= $result->content;
$output .= "</div>";
$output .= "</div>";
}
$results = $events->query->results->event;
if($results != NULL)
{
$output .= "<div class='heading'> Watch out for these events!! </div><br/>";
foreach ($results as $result) {
$output .= "<div class='newstitle'>";
$output .= $result->name;
$output .= "</div>";
}
}
$tmppath= "./.cache/users/".$userId;
if(!file_exists($tmppath))
{
$fh=fopen($tmppath,"w+");
fwrite($fh, $output);
fclose($fh);
//return $output;
}
}
function getWeatherDetails($city)
{
include_once "./utils/geo.php";
$tmppath= "./.cache/cities/".$city;
if(!file_exists($tmppath))
{
mkdir($tmppath);
}
if(!file_exists("$tmppath/weather"))
{
//echo "Creating weather file";
$fh=fopen("$tmppath/weather","w+");
$res = getWeatherInfo($city);
//var_dump($res);
fwrite($fh, json_encode($res));
fclose($fh);
return $res;
}
$fh=fopen("$tmppath/weather","r");
$res = fread($fh, 10000);
return json_decode($res);
}
function getEventDetails($city)
{
include_once "./utils/geo.php";
$tmppath= "./.cache/cities/".$city;
if(!file_exists($tmppath))
{
mkdir($tmppath);
}
if(!file_exists("$tmppath/events"))
{
//echo "Creating event file";
$fh=fopen("$tmppath/events","w+");
$res = getUpcomingEvents($city);
fwrite($fh, json_encode($res));
fclose($fh);
return $res;
}
$fh=fopen("$tmppath/events","r");
$res = fread($fh, 10000);
return json_decode($res);
}
function getNewsDetails($city)
{
include_once "./utils/geo.php";
$tmppath= "./.cache/cities/".$city;
if(!file_exists($tmppath))
{
mkdir($tmppath);
}
if(!file_exists("$tmppath/news"))
{
//echo "Creating news file";
$fh=fopen("$tmppath/news","w+");
$res = getGoogleNews($city);
fwrite($fh, json_encode($res));
fclose($fh);
return $res;
}
$fh=fopen("$tmppath/news","r");
$res = fread($fh, 10000);
return json_decode($res);
}
?>