This repository was archived by the owner on Dec 19, 2023. It is now read-only.
forked from ffansbach/de-map
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.php
More file actions
121 lines (101 loc) · 3.05 KB
/
Copy pathdata.php
File metadata and controls
121 lines (101 loc) · 3.05 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
<?php
/**
* ajax response with parseresult
*
* this will try to load a cched result if not older than 24h
*/
$offset = 1 * 60 * 60;
header('Cache-Control: public, max-age='.$offset);
header ("Expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT");
header('Content-Type: application/json');
error_reporting(-1);
ini_set('display_errors', 'On');
require 'config.php';
if(!isset($_REQUEST[$forceReparseKey]))
{
// fetch cached result - the shortcut
$response = array(
'communities' => getFromCache('communities'),
'allTheRouters' => getFromCache('routers'),
'metaCommunities' => getFromCache('metacommunities'),
'isCachedresult' => true,
);
}
else
{
// reparse requested
// actually parse now
require 'lib/simpleCachedCurl.inc.php';
require 'lib/nodelistparser.php';
require 'lib/jsv4/jsv4.php';
require 'lib/log.php';
$apiUrl = 'https://raw.githubusercontent.com/freifunk/directory.api.freifunk.net/master/directory.json';
$parser = new nodeListParser();
// uncomment to enable debugoutput from simplecachedcurl
// $parser->setDebug(true);
$parser->setCachePath(dirname(__FILE__).'/cache/');
$parser->setSource($apiUrl);
$ffnw = new stdClass;
$ffnw->name = 'Freifunk NordWest';
$ffnw->nameShort = 'Freifunk NordWest';
$ffnw->url = 'https://netmon.nordwest.freifunk.net/';
$ffnw->parser = 'Netmon';
$parser->addAdditional('ffnw', $ffnw);
$ffj = new stdClass;
$ffj->name = 'Freifunk Jena';
$ffj->nameShort = 'Freifunk Jena';
$ffj->url = 'https://freifunk-jena.de/ffmap/';
$ffj->parser = 'Ffmap';
$parser->addAdditional('ffj', $ffj);
$ffffm = new stdClass;
$ffffm->name = 'Frankfurt am Main';
$ffffm->nameShort = 'Frankfurt am Main';
$ffffm->url = 'http://map.ffm.freifunk.net/';
$ffffm->parser = 'Ffmap';
$parser->addAdditional('ffffm', $ffffm);
$ff_ruhrg_fb = new stdClass;
$ff_ruhrg_fb->name = 'Freifunk Ruhrgebiet - FB';
$ff_ruhrg_fb->nameShort = 'Freifunk Ruhrgebiet - FB';
$ff_ruhrg_fb->url = 'http://map.freifunk-ruhrgebiet.de/data/';
$ff_ruhrg_fb->parser = 'Ffmap';
$parser->addAdditional('ff_ruhrg_fb', $ff_ruhrg_fb);
$parseResult = $parser->getParsed(true);
$response = array(
'communities' => $parseResult['communities'],
'allTheRouters' => $parseResult['routerList']
);
if(is_array($dbAccess))
{
$db = new mysqli($dbAccess['host'], $dbAccess['user'], $dbAccess['pass'], $dbAccess['db']);
$log = new log($db);
$log->add(sizeof($parseResult['routerList']));
}
}
/**
* if processonly is set we handle a reparse cron request
*/
if(isset($_REQUEST['processonly']) && isset($parser))
{
$report = array(
'communities' => sizeof($response['communities']),
'nodes' => sizeof($response['allTheRouters']),
'stats' => $parser->getParseStatistics(),
);
echo json_encode($report, JSON_PRETTY_PRINT);
}
else
{
echo json_encode($response, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
}
function getFromCache($key)
{
$filename = dirname(__FILE__).'/cache/result_'.$key.'.json';
if ( !file_exists($filename) )
{
return false;
}
else
{
return json_decode(file_get_contents($filename));
}
}