View source
<?php
function mediafront_user_service() {
return array(
array(
'#method' => 'mediafront.setUserStatus',
'#callback' => 'mediafront_user_set_status',
'#args' => array(
array(
'#name' => 'verb',
'#type' => 'string',
'#description' => t('What this person is doing. "Travis is <strong>listening to</strong>."'),
),
array(
'#name' => 'noun',
'#type' => 'string',
'#description' => t('The noun associated with the verb. "Travis is listening to <strong>music</strong>"'),
),
),
'#return' => 'bool',
'#help' => t('Returns if a successful status was made.'),
),
);
}
function mediafront_user_set_status($verb, $noun) {
global $user;
if ($user->uid) {
if (db_result(db_query("SELECT COUNT(*) FROM {mediafront_user} WHERE uid=%d", $user->uid)) > 0) {
db_query("UPDATE {mediafront_user} SET verb='%s', noun='%s' WHERE uid=%d", $verb, $noun, $user->uid);
}
else {
db_query("INSERT INTO {mediafront_user} (uid, verb, noun) VALUES (%d, '%s', '%s')", $user->uid, $verb, $noun);
}
}
return true;
}
function mediafront_user_get_status($uid) {
return db_fetch_object(db_query("SELECT * FROM {mediafront_user} WHERE uid=%d", $uid));
}
function mediafront_user_token_list($type = 'all') {
if ($type == 'user' || $type == 'all') {
$tokens['user']['user-verb'] = t('What this person is doing. "Travis is <strong>listening to</strong>."');
$tokens['user']['user-noun'] = t('The noun associated with the verb. "Travis is listening to <strong>music</strong>"');
return $tokens;
}
}
function mediafront_user_token_values($type, $object = NULL) {
switch ($type) {
case 'user':
case 'all':
if (isset($object)) {
$object = (object) $object;
$uid = $object->uid;
}
else {
global $user;
$uid = $user->uid;
}
$status = mediafront_user_get_status($uid);
$values['user-verb'] = check_plain($status->verb);
$values['user-noun'] = check_plain($status->noun);
return $values;
}
}