-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.php
56 lines (47 loc) · 1.71 KB
/
api.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
<?php
session_start();
require "EmonLogger.php";
error_reporting(E_ALL);
ini_set('display_errors', 'on');
require "PHPFina.php";
$phpfina = new PHPFina();
$query = $_GET['q'];
$dirset = false;
$dir = "";
switch ($query)
{
case "scandir":
$dirset = true;
$dir = $_GET['dir'];
$_SESSION['last_saved_dir'] = $dir;
$scan = scandir($dir);
$phpfina->dir = $dir;
$feeds = array();
foreach ($scan as $item) {
if (strpos($item,".dat")!==false) {
$parts = explode(".",$item);
$feedid = (int) $parts[0];
$meta = $phpfina->get_meta($feedid);
$timeval = $phpfina->lastvalue($feedid);
$feeds[] = array(
"feedid"=>$feedid,
"interval"=>$meta->interval,
"start"=>$meta->start_time,
"npoints"=>$phpfina->get_npoints($feedid),
"lastvalue"=>$timeval["value"],
"size"=>$phpfina->get_feed_size($feedid)
);
}
}
print json_encode($feeds);
break;
case "data":
$dir = $_GET['dir'];
$feedid = (int) $_GET['id'];
$start = (int) $_GET['start'];
$end = (int) $_GET['end'];
$interval = (int) $_GET['interval'];
$phpfina->dir = $dir;
print json_encode($phpfina->get_data($feedid,$start,$end,$interval,1,1));
break;
}