You are here

function messaging_twitter_user_destination in Messaging 6.4

Same name and namespace in other branches
  1. 6 messaging_twitter/messaging_twitter.module \messaging_twitter_user_destination()
  2. 6.2 messaging_twitter/messaging_twitter.module \messaging_twitter_user_destination()
  3. 6.3 messaging_twitter/messaging_twitter.module \messaging_twitter_user_destination()

Map user account to twitter screen name

Parameters

$account: User account object or uid

1 string reference to 'messaging_twitter_user_destination'
messaging_twitter_messaging in messaging_twitter/messaging_twitter.module
Implementation of hook_messaging

File

messaging_twitter/messaging_twitter.module, line 57
Messaging Twitter sending method

Code

function messaging_twitter_user_destination($account) {
  static $cache = array();
  $uid = messaging_user_uid($account);
  if (!array_key_exists($uid, $cache)) {
    _messaging_twitter_include();
    $twitter_accounts = twitter_get_user_accounts($uid);
    if (is_array($twitter_accounts) && !empty($twitter_accounts)) {
      reset($twitter_accounts);
      $first = current($twitter_accounts);

      // It used to be an array, for 6.x-3.x it is an object
      $cache[$uid] = is_object($first) ? $first->screen_name : $first['screen_name'];
    }
    else {
      $cache[$uid] = NULL;
    }
  }
  return $cache[$uid];
}