-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathog_api.php
More file actions
65 lines (64 loc) · 1.46 KB
/
og_api.php
File metadata and controls
65 lines (64 loc) · 1.46 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
<?
/*
og data api
input:
url
format
output
error
0
1
msg
guid: md5
og:
*/
include('parser.php');
include('opengraph.php');
Class OGAPI {
public static $format;
public static function error($msg){
switch(self::$format){
case "debug":
return sprintf("<xmp>%s</xmp>", print_r(array("error"=>1, "msg"=>$msg), true));
break;
default:
return json_encode(array("error"=>1, "msg"=>$msg));
break;
}
}
public static function request($url, $format="debug"){
self::$format = $format;
if(!$url) return self::error('URL 未指定');
$graph = @OpenGraph::fetch($url);
if(!$graph) return self::error('OG 資訊不存在');
$result = array();
foreach ($graph as $key => $value) {
$result[$key] = $value;
}
if(!$result['url']){
$result['url'] = $url;
}
$result = array(
'error'=>0,
'msg'=>'',
'guid'=>md5($url),
'og'=>$result
);
switch($format){
case "debug":
return sprintf("<xmp>%s</xmp>", print_r($result, true));
break;
default:
return json_encode($result);
break;
}
}
}
$url =$_GET['url'];
$format = $_GET['format'];
if($_SERVER['PHP_SELF'] == "/hackday2013/og_api.php"){
if(!$url) $url = "http://blog.xuite.net/grassboy/Tech/49071851-%5BUglyCode%5D+%E5%BF%AB%E9%80%9F%E5%8F%96%E5%BE%97KeyCode%E7%9A%84%E6%96%B9%E6%B3%95";
exit_r(OGAPI::request($url, 'debug'));
} else {
echo OGAPI::request($url, $format);
}