'dashplayer.setUserStatus', '#callback' => 'dashplayer_user_set_status', '#access arguments' => 'access content', '#args' => array( array( '#name' => 'verb', '#type' => 'string', '#description' => t('What this person is doing. "Travis is listening to."')), array( '#name' => 'noun', '#type' => 'string', '#description' => t('The noun associated with the verb. "Travis is listening to music"')) ), '#return' => 'bool', '#help' => t('Returns if a successful status was made.') ) ); } function dashplayer_user_set_status($verb, $noun) { global $user; if( $user->uid ) { // Look for an existing status by looking for the same user & verb. if( db_result( db_query("SELECT COUNT(*) FROM {dashplayer_user} WHERE uid=%d", $user->uid )) > 0 ) { // We just need to update the current status. db_query( "UPDATE {dashplayer_user} SET verb='%s', noun='%s' WHERE uid=%d", $verb, $noun, $user->uid ); } else { // Insert a new user status into the dashplayer_user database. db_query( "INSERT INTO {dashplayer_user} (uid, verb, noun) VALUES (%d, '%s', '%s')", $user->uid, $verb, $noun ); } } return true; } /** * Returns the user status. */ function dashplayer_user_get_status( $uid ) { return db_fetch_object( db_query( "SELECT * FROM {dashplayer_user} WHERE uid=%d", $uid ) ); } /** * Implementation of hook_token_list(). */ function dashplayer_user_token_list($type = 'all') { if ($type == 'user' || $type == 'all') { $tokens['user']['user-verb'] = t('What this person is doing. "Travis is listening to."'); $tokens['user']['user-noun'] = t('The noun associated with the verb. "Travis is listening to music"'); return $tokens; } } /** * Implementation of hook_token_values(). */ function dashplayer_user_token_values($type, $object = NULL) { switch ($type) { case 'user': case 'all' : // Get the user... if (isset($object)) { $object = (object)$object; $uid = $object->uid; } else { global $user; $uid = $user->uid; } // Get the user status. $status = dashplayer_user_get_status( $uid ); // Set the verb and noun of this token. $values['user-verb'] = check_plain( $status->verb ); $values['user-noun'] = check_plain( $status->noun ); return $values; } } ?>