You are here

function twitter_actions_set_status in Twitter 7.3

Same name and namespace in other branches
  1. 7.6 twitter_actions/twitter_actions.rules.inc \twitter_actions_set_status()
  2. 7.4 twitter_actions/twitter_actions.rules.inc \twitter_actions_set_status()
  3. 7.5 twitter_actions/twitter_actions.rules.inc \twitter_actions_set_status()

Fetches Twitter account info and submits with the message to the Twitter API

Parameters

$message: The message to post

$sender: The Drupal user that has a Twitter account

1 string reference to 'twitter_actions_set_status'
twitter_actions_rules_action_info in twitter_actions/twitter_actions.rules.inc
Implements hook_rules_action_info() on behalf of the twitter module.

File

twitter_actions/twitter_actions.rules.inc, line 41
Provide better intergration into the rules module

Code

function twitter_actions_set_status($message, $sender) {
  if ($twitter_uid = db_query("SELECT twitter_uid FROM {twitter_account} WHERE uid = :uid", array(
    ':uid' => $sender->uid,
  ))
    ->fetchField()) {
    module_load_include('inc', 'twitter');
    $twitter_account = twitter_account_load($twitter_uid);
    try {
      twitter_set_status($twitter_account, $message);
      drupal_set_message(t('Successfully posted to Twitter'));
    } catch (TwitterException $e) {
      drupal_set_message(t('An error occurred when posting to Twitter: @message', array(
        '@message' => $e
          ->getMessage(),
      )), 'warning');
    }
  }
  else {
    watchdog('twitter', 'Could not find the Twitter account to be used for posting. Please review the rule settings.', array(), WATCHDOG_ERROR);
  }
}