-
Notifications
You must be signed in to change notification settings - Fork 0
/
pi.fhpics.php
106 lines (85 loc) · 2.36 KB
/
pi.fhpics.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
99
100
101
102
103
104
105
106
<?php
class Plugin_fhpics extends Plugin
{
var $meta = array(
'name' => 'FHPics',
'version' => '1',
'author' => 'Ramon Lapenta',
'author_url' => 'http://ramonlapenta.com'
);
public function photos()
{
$consumer_key = $this->fetchParam('consumer_key', null);
$feature = $this->fetchParam('feature', 'user');
$user = $this->fetchParam('user', null);
$count = $this->fetchParam('count', 5, 'is_numeric');
$image_size = $this->fetchParam('image_size', 3, 'is_numeric');
$sort = $this->fetchParam('sort', 'created_at');
$only = $this->fetchParam('only', null);
$exclude = $this->fetchParam('exclude', null);
$params = "photos?consumer_key=$consumer_key&feature=$feature&username=$user&sort=$sort&rpp=$count&image_size=$image_size";
if(isset($only))
{
$params .= '&only='.urlencode($only);
}
if(isset($exclude))
{
$params .= '&exclude='.urlencode($exclude);
}
if ($response = $this->fhp_curl($params))
{
return object_to_array($response);
}
return false;
}
public function photo()
{
$consumer_key = $this->fetchParam('consumer_key', null);
$id = $this->fetchParam('id', null);
$image_size = $this->fetchParam('image_size', 4, 'is_numeric');
$comments = $this->fetchParam('comments', null);
$params = "photos/$id?consumer_key=$consumer_key&image_size=$image_size";
if(isset($comments))
{
$params .= '&comments='.urlencode($comments);
}
if ($response = $this->fhp_curl($params))
{
$photo = object_to_array($response);
return $photo['photo'];
}
return false;
}
// Request query
function fhp_curl($params)
{
$host = 'https://api.500px.com/v1/';
$request = curl_init($host.$params);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($request);
if ($contents)
{
return json_decode($contents);
}
else
{
echo "500px requires the CURL library to be installed.";
}
}
}
# Convert results
function object_to_array($d)
{
if (is_object($d))
{
$d = get_object_vars($d);
}
if (is_array($d))
{
return array_map(__FUNCTION__, $d);
}
else
{
return $d;
}
}