-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetdetailby.php
86 lines (76 loc) · 2.23 KB
/
getdetailby.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
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
<?php
/* See https://github.com/Podcastindex-org/example-code for more examples */
include ("common.php");
//Figure out the query
if (isset($_GET['url'])) {
$url = urldecode($_GET['url']);
if (strpos($url, "tiny.php?url=") !== false) {
$urlparts = explode("tiny.php?url=", $url);
if (isset($urlparts[1])) {
$url = $urlparts[1];
$url = explode("&", $url);
$url = $url[0];
$url = base64url_decode($url);
}
//http://podcasts.webosarchive.org/tiny.php?url=aHR0cHM6Ly9mZWVkcy5tZWdhcGhvbmUuZm0vc3R1ZmZ5b3VzaG91bGRrbm93&max=25
}
$the_query = "byfeedurl?url=" . $url;
}
if (isset($_GET['id'])) {
$the_query = "byfeedid?id=" . $_GET['id'];
}
if (!isset($the_query)) {
$the_query = $_SERVER['QUERY_STRING'];
}
$the_query = "https://api.podcastindex.org/api/1.0/podcasts/" . $the_query;
//API Credentials
include ("secrets.php");
$apiHeaderTime = time();
//Hash them to get the Authorization token
$hash = sha1($apiKey.$apiSecret.$apiHeaderTime);
//Set the required headers
$headers = [
"User-Agent: webOSPodcastDirectory/1.0",
"X-Auth-Key: $apiKey",
"X-Auth-Date: $apiHeaderTime",
"Authorization: $hash"
];
//Make the request to an API endpoint
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $the_query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//Collect and show the results
header('Content-Type: application/json');
$response = curl_exec ($ch);
curl_close ($ch);
$response_obj = json_decode($response);
//Inject any restored feeds
if (isset($_GET['url'])) {
$url = urldecode($_GET['url']);
include ("restorations.php");
if (isset($restorations)) {
foreach ($restorations as $restoration) {
if ($restoration['url'] == $url) {
$response_obj->status = true;
$response_obj->description = "Feed found using a restoration";
$response_obj->feed = $restoration;
}
}
}
}
//Inject any modified feeds
include ("substitutions.php");
if (isset($substitutions)) {
if (isset($response_obj->feed)) {
if (isset($substitutions[$response_obj->feed->url])) {
$new_feed = $substitutions[$response_obj->feed->url];
foreach ($new_feed as $key => $value) {
$response_obj->feed->$key = $value;
}
}
}
}
$response = json_encode($response_obj);
print_r($response);
?>