| 1 |
<?php
|
| 2 |
// $Id: jaiku.module,v 1.6 2008/01/03 17:11:21 tomsun Exp $
|
| 3 |
|
| 4 |
|
| 5 |
/**
|
| 6 |
* Posts a Jaiku
|
| 7 |
*
|
| 8 |
* @param string $jaiku_username
|
| 9 |
* @param string $jaiku_api_key
|
| 10 |
* @param string $message
|
| 11 |
* @param array $args
|
| 12 |
* 'icon' Icon to use
|
| 13 |
* 'location' String containg vaues wrapped with <neighborhood>, <city>, <country> tags
|
| 14 |
* 'generated' If set to true, the jaiku will not show up in the user's stream, only as the current presence
|
| 15 |
* @param boolean $put_in_stream
|
| 16 |
* @return boolean
|
| 17 |
*/
|
| 18 |
function jaiku_post($jaiku_username, $jaiku_api_key, $message, $args = array()) {
|
| 19 |
|
| 20 |
$headers = array();
|
| 21 |
|
| 22 |
$data = array();
|
| 23 |
$data['user'] = $jaiku_username;
|
| 24 |
$data['personal_key'] = $jaiku_api_key;
|
| 25 |
$data['method'] = 'presence.send';
|
| 26 |
$data['message'] = $message;
|
| 27 |
|
| 28 |
// Add 'generated' flag.
|
| 29 |
if (!empty($args['generated'])) {
|
| 30 |
$data['generated'] = 'true';
|
| 31 |
}
|
| 32 |
|
| 33 |
// Add icon.
|
| 34 |
if (!empty($args['icon'])) {
|
| 35 |
$data['icon'] = $args['icon'];
|
| 36 |
}
|
| 37 |
|
| 38 |
// Add location info.
|
| 39 |
if (!empty($args['location'])) {
|
| 40 |
$data['location'] = $args['location'];
|
| 41 |
}
|
| 42 |
|
| 43 |
$data_str = '';
|
| 44 |
if (!empty($data)) {
|
| 45 |
$data_str = '';
|
| 46 |
foreach ($data as $key => $val) {
|
| 47 |
if (!empty($data_str)) {
|
| 48 |
$data_str .= '&';
|
| 49 |
}
|
| 50 |
$data_str .= urlencode($key) . '=' . urlencode($val);
|
| 51 |
}
|
| 52 |
}
|
| 53 |
|
| 54 |
$result = drupal_http_request('http://api.jaiku.com/json', $headers, 'POST', $data);
|
| 55 |
|
| 56 |
if ($result == '{"status":"ok"}') {
|
| 57 |
return true;
|
| 58 |
}
|
| 59 |
|
| 60 |
return false;
|
| 61 |
}
|
| 62 |
|
| 63 |
|
| 64 |
/**
|
| 65 |
* Returns a Jaiku stream as a multidimentional array.
|
| 66 |
*
|
| 67 |
* @param string $username
|
| 68 |
* Returns the public stream if omitted.
|
| 69 |
*/
|
| 70 |
function jaiku_get_stream($jaiku_username = '') {
|
| 71 |
|
| 72 |
if (empty($jaiku_username)) {
|
| 73 |
$url = 'http://jaiku.com/feed/json';
|
| 74 |
} else {
|
| 75 |
$url = 'http://' . urlencode($jaiku_username) . '.jaiku.com/feed/json';
|
| 76 |
}
|
| 77 |
$result = drupal_http_request($url, array(), 'GET');
|
| 78 |
return json_decode($result);
|
| 79 |
}
|
| 80 |
|
| 81 |
|
| 82 |
/**
|
| 83 |
* Returns the current presence info for a given user, as a multidimensional array.
|
| 84 |
*
|
| 85 |
* @param string $username
|
| 86 |
*/
|
| 87 |
function jaiku_get_presence($jaiku_username) {
|
| 88 |
$url = 'http://' . urlencode($jaiku_username) . '.jaiku.com/presence/json';
|
| 89 |
$result = drupal_http_request($url, array(), 'GET');
|
| 90 |
return json_decode($result);
|
| 91 |
}
|
| 92 |
|
| 93 |
|
| 94 |
/**
|
| 95 |
* Returns info on a Jaiku user as a multidimensional array.
|
| 96 |
*
|
| 97 |
* @param string $username
|
| 98 |
*/
|
| 99 |
function jaiku_get_user($jaiku_username) {
|
| 100 |
$url = 'http://' . urlencode($jaiku_username) . '.jaiku.com/json';
|
| 101 |
$result = drupal_http_request($url, array(), 'GET');
|
| 102 |
return json_decode($result);
|
| 103 |
}
|