Repository navigation
Expand file tree
/
Copy pathdiscovery.php
More file actions
128 lines (116 loc) · 5.18 KB
/
Copy pathdiscovery.php
File metadata and controls
128 lines (116 loc) · 5.18 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
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
<?php
header('Content-type: application/json; charset=utf-8');
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
include_once 'Config.php';
include_once CLASSES . 'Response.class.php';
include_once CLASSES . 'ResponseDataset.class.php';
include_once CLASSES . 'ResponseError.class.php';
include_once CLASSES . 'PoisDataset.class.php';
include_once CLASSES . 'Util.class.php';
include_once CLASSES . 'App.class.php';
include_once CLASSES . 'Filter.class.php';
include_once CLASSES . 'Database.class.php';
include_once CLASSES . 'AppGeneratorException.class.php';
$filters = array();
$keys = array();
$app_datasets = array();
try {
if (isset($_POST['uid'])) {
Database::connect();
if ($app = App::createFromDb($_POST['uid'])) {
$name = $app->name;
$cityIdParam = "";
$cityName = "";
$datasetIdsQueryString = "?format=json&datasetIds=";
$datasetids = ($_POST['datasetIds']);
foreach ($datasetids as $id) {
$datasetId = ($id);
$datasetIdsQueryString .= $datasetId . ",";
}
// Removing the trailing comma
$datasetIdsQueryString = rtrim($datasetIdsQueryString, ",");
// We will call a service that will give us a set of datasets, based on the datasetIds
// we provide it with
if (PROXYUSE) {
$aContext = array(
'http' => array(
'proxy' => 'tcp://' . PROXYNAME . ':' . PROXYPORT,
'request_fulluri' => true,
),
);
$cxContext = stream_context_create($aContext);
}
else
$cxContext = null;
$datasetsInfoResponse = file_get_contents(DATASETS_SERVICE . $datasetIdsQueryString, False, $cxContext);
$response = json_decode($datasetsInfoResponse, true);
$count = 0;
foreach ($response["datasets"] as $dataset) {
if ($count > 1 ) {
break;
}
if (strpos($dataset['url'],'PropertyAgent') !== false && strpos($dataset['url'], '.json') == true) {
$count++;
$type = $dataset['category'];
$cityId = $_POST['cityId'];
// handle datasets with empty spaces in their filename
$json = file_get_contents(str_replace(" ", "%20", $dataset['url']), False, $cxContext);
$json = utf8_encode ( $json );
$assocArray = json_decode($json, true);
$poisDataset = ResponseDataset::createFromArray(DatasetTypes::Poi, $assocArray);
$status = 'success';
$poisCounter = 0;
foreach ($poisDataset->poi as $poi) {
$poi->cityId = $cityId;
$filterExists = false;
foreach ($poi->category as $cat) {
$filterExists = false;
$upperCat = ucfirst($cat);
if (!empty($filters)) {
foreach ($filters as $filter) {
if (($filter->cityId == $cityId) && ($filter->name == $upperCat)) {
$filterExists = true;
break;
}
}
}
if (!$filterExists) {
$filters[] = new Filter($upperCat, false, $type, $cityId, true, $poisCounter);
}
}
foreach ($filters as $filter) {
if ($upperCat == $filter->name) {
$filter->poisCounter++;
}
}
}
array_push($app_datasets, new ResponseDataset($poisDataset, $name));
}
}
/* sort filters array alphabetically by category name */
usort($filters, function($a, $b) {
return strcmp($a->name, $b->name);
});
/* only the first filter appears to be checked */
$filters[0]->selected = true;
Util::printJsonObj(new Response($app_datasets, $name, $filters, $status));
}
else
{
Util::printJsonObj(new ResponseError("failed", "invalid application id", "Application doesn't exist!"));
Database::disconnect();
}
}
else
Util::printJsonObj(new ResponseError("failed", "missing application id", "Application doesn't exist!"));
} catch (AppGeneratorException $e) {
$status = 'failed';
$error = $e->errorMessageForDevelopper();
$message = $e->errorMessageForUser();
Util::printJsonObj(new ResponseError($status, $error, $message));
}
?>