-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocialService.php
More file actions
57 lines (39 loc) · 1.35 KB
/
Copy pathsocialService.php
File metadata and controls
57 lines (39 loc) · 1.35 KB
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
<?php
$registeredService = array();
$data = array();
$expTime = 1; // In minutes
include('functions.php');
include('services/flickr.php');
include('services/facebook.php');
include('services/twitter.php');
$apiResponseCode = array(
0 => array('HTTP Response' => 400, 'Message' => 'Unknown Error'),
1 => array('HTTP Response' => 200, 'Message' => 'Success'),
2 => array('HTTP Response' => 404, 'Message' => 'Invalid Request'),
3 => array('HTTP Response' => 400, 'Message' => 'Invalid Response Format')
);
list($methodParam, $methodParamStr) = setQueryVars('method');
$cachePath = 'cache/';
$cacheName = fileNameFriendly($_SERVER['QUERY_STRING']);
if (in_array($methodParam, $registeredService)) {
if(checkCache($cacheName, $cachePath, $expTime)) {
$response = getCache($cacheName, $cachePath);
} else {
$init = $methodParam . '_init';
$serviceResponse = $init($data, $apiResponseCode);
$responseStatus = $serviceResponse['status'];
$data = $serviceResponse['data'];
array_push($data, $init($data, $apiResponseCode));
if ($responseStatus == 200) {
setCache($cacheName, $cachePath, $data);
}
$response = $data;
}
} else {
$data['code'] = 2;
$data['status'] = 404;
$data['data'] = NULL;
$response = $data;
}
response($response);
?>