3 * @file explodelib.php Explode API interface library.
5 * This is a library / reference implementation for interfacing with the explode API.
6 * It should be noted that the Explode API is still under development and is subject to
9 * I will try to keep this sample API up to date, but the website documentation should
10 * be taken as the canonical source.
12 * It is compatible with both PHP4 & 5.
14 * @author Marcus Povey <marcus@dushka.co.uk>
20 * You should not ever have to change this, but this could be useful to developers.
22 $xmlurl = "http://ex.plode.us/mod/explodeapi/";
25 * Encode a raw rest call.
26 * @param $method array An array of 'key' => 'value' of your api parameters.
27 * @return object Query result as a php object.
29 function explode_rawcall($method)
35 $encoded_params = array();
37 // Hard code the format - we're using PHP, so lets use PHP serialisation.
38 $method['format'] = "php";
40 // URL encode all the parameters
41 foreach ($method as $k => $v){
42 $encoded_params[] = urlencode($k).'='.urlencode($v);
45 // Put together the query string
46 $url = $xmlurl."?".implode('&', $encoded_params);
48 // Send the query and get the result and decode.
49 $rsp = file_get_contents($url);
50 return unserialize($rsp);
54 * Get a list of users.
56 * @param $limit int The number of users to return, default 25.
57 * @param $offset int Offset in the search.
59 function users_index($limit = 25, $offset = 0)
63 $param['limit'] = $limit;
64 $param['offset'] = $offset;
65 $param['method'] = "users.index";
67 return explode_rawcall($param);
71 * Get some information about a user.
73 * @param $userid int The user id to display
75 function users_view($userid)
79 $param['userid'] = $userid;
80 $param['method'] = "users.view";
82 return explode_rawcall($param);
86 * Get some information about a user from a username and service.
88 * @param string $username The user to look for.
89 * @param int $service The service id.
91 function users_viewbyusername($username, $service)
95 $param['username'] = $username;
96 $param['service'] = $service;
97 $param['method'] = "users.viewbyusername";
99 return explode_rawcall($param);
103 * Get the user's friends.
105 * @param $userid int The user id to display
107 function users_getfriends($userid)
111 $param['userid'] = $userid;
112 $param['method'] = "users.getfriends";
114 return explode_rawcall($param);
118 * Get the users who have made this user their friend.
120 * @param $userid int The user id to display
122 function users_getfriendsof($userid)
126 $param['userid'] = $userid;
127 $param['method'] = "users.getfriendsof";
129 return explode_rawcall($param);
133 * Get a list of users by interest.
135 * @param $tag string The tag. Multiple tags can be specified by using "and" eg. "music and chocolate".
136 * @param $limit int The number of users to return, default 25.
137 * @param $offset int Offset in the search.
139 function users_findusersbytag($tag, $limit = 25, $offset = 0)
143 $param['method'] = "users.findusersbytag";
144 $param['tag'] = $tag;
145 $param['limit'] = $limit;
146 $param['offset'] = $offset;
148 return explode_rawcall($param);
152 * Search for users by (user)name or name, essentially executing an explode name search.
154 * @param $username string Username to look for.
155 * @param $limit int The number of users to return, default 25.
156 * @param $offset int Offset in the search.
157 * @param $servicelist string Optional service list.
159 function users_findusersbyname($username, $limit = 25, $offset = 0, $servicelist = "")
163 $param['username'] = $username;
164 $param['limit'] = $limit;
165 $param['offset'] = $offset;
166 $param['servicelist'] = $servicelist;
167 $param['method'] = "users.findusersbyname";
169 return explode_rawcall($param);
173 * Get a list of services.
175 * @param $limit int The number of users to return, default 25.
176 * @param $offset int Offset in the search.
178 function services_index($limit = 25, $offset = 0)
182 $param['limit'] = $limit;
183 $param['offset'] = $offset;
184 $param['method'] = "services.index";
186 return explode_rawcall($param);
190 * Get some information about a service.
192 * @param $serviceid int The id of the service
194 function services_view($serviceid)
198 $param['serviceid'] = $serviceid;
199 $param['method'] = "services.view";
201 return explode_rawcall($param);
205 * Search for services by service by either the full or short name.
207 * @param $name string The name of the service
209 function services_findservicesbyname($name)
213 $param['name'] = $name;
214 $param['method'] = "services.findservicesbyname";
216 return explode_rawcall($param);
220 * Get a list of comments (public comment wall).
222 * @param $limit int The number of users to return, default 25.
223 * @param $offset int Offset in the search.
225 function comments_index($limit = 25, $offset = 0)
229 $param['limit'] = $limit;
230 $param['offset'] = $offset;
231 $param['method'] = "comments.index";
233 return explode_rawcall($param);
237 * Get information about a comment.
239 * @param $commentid int The comment id
241 function comments_view($commentid)
245 $param['method'] = "comments.view";
246 $param['commentid'] = $commentid;
248 return explode_rawcall($param);
252 * Get the user's comments (comment wall).
254 * @param $userid int The user id of the user who's comment wall will be retrieved.
255 * @param $limit int The number of users to return, default 25.
256 * @param $offset int Offset in the search.
258 function comments_user($userid, $limit = 25, $offset = 0)
262 $param['userid'] = $userid;
263 $param['limit'] = $limit;
264 $param['offset'] = $offset;
265 $param['method'] = "comments.user";
267 return explode_rawcall($param);