-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeed.php
51 lines (43 loc) · 1.25 KB
/
feed.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
<?php
session_start();
include_once dirname(__DIR__) . '/config.inc';
// Feed url.
$url = $config['harvester_url'] . $config['harvester_api_path'] . 'entries.json?group=user';
// Conditionals.
if (!empty($_GET['from'])) {
$url .= '&from=' . $_GET['from'];
}
if (!empty($_GET['to'])) {
$url .= '&to=' . $_GET['to'];
}
if (!empty($_GET['month'])) {
$url .= '&month=' . $_GET['month'];
}
if (!empty($_GET['year'])) {
$url .= '&year=' . $_GET['year'];
}
// Add token to URL if logged in.
if (!empty($_SESSION['harvester_pass'])) {
$name = $_SESSION['harvester_name'];
$pass = $_SESSION['harvester_pass'];
$url = $url . "&email=" . $name . "&password=" . $pass;
}
// Wrap response.
function get_contents($url) {
$headers = get_headers($url, TRUE);
// Fetch HTTP response code from header.
preg_match('!\d{3}!', $headers[0], $matches);
$code = (int) reset($matches);
if (isset($headers['Content-Type'])) {
header('Content-Type: ' . $headers['Content-Type']);
}
if ($code !== 200) {
// Set HTTP response according to remote.
http_response_code($code);
}
else {
return file_get_contents($url);
}
}
// Output result.
print get_contents($url);