-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.php
98 lines (75 loc) · 1.72 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
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
<?php
/*
TODO: error handling and propagating
status=error|ok
-----htaccess
RewriteRule ^api\.(.*)\.php?(.*)$ api.php?$2&format=$1
#optinal (to see behaivour under tests cases)
RewriteRule ^api.php?(.*)$ api.php?format=plain
----/htaccess
*/
include_once ("base.php");
include_once ("utils.php");
$url = is_url($_GET["url"]);
$format = $_GET["format"]; // NEW
$get_data = array(
"max_hits" => 0,
"notes" => "",
"email" => ""
);
$strkey = store_url($url, $get_data, gather_meta());
$result = "";
$url_data = parse_url($url);
if($format == "xml") {
header("Content-Type: text/xml");
$new_XML = generate_xml($url_data);
$result = $new_XML;
} else if($format == "json")
$result = json_encode($url_data);
else
$result = complete_url($strkey);
echo $result;
/*
$get_data = array(
"max_hits" => 0,
"notes" => "",
"email" => ""
);
$url = is_url($_GET["url"]);
$strkey = store_url($url, $get_data, gather_meta());
if(isset($_GET["url"])) {
$get_data = array(
"max_hits" => 0,
"notes" => "",
"email" => ""
);
$url = is_url($_GET["url"]);
$strkey = store_url($url, $get_data, gather_meta());
echo complete_url($strkey);
}
if(isset($_GET["xml"])) {
header("Content-Type: text/xml");
$get_data = array(
"max_hits" => 0,
"notes" => "",
"email" => ""
);
$url = is_url($_GET["xml"]);
store_url($url, $get_data, gather_meta());
$url_data = parse_url($_GET["xml"]);
$new_XML = generate_xml($url_data);
echo $new_XML;
}
if(isset($_GET["json"])) {
$get_data = array(
"max_hits" => 0,
"notes" => "",
"email" => ""
);
$url = is_url($_GET["json"]);
store_url($url, $get_data, gather_meta());
$url_data = parse_url($_GET["json"]);
echo json_encode($url_data);
}
*/
?>