function twitter_nodeapi in Twitter 6.2
Same name and namespace in other branches
- 5 twitter.module \twitter_nodeapi()
- 6.3 twitter_post/twitter_post.module \twitter_nodeapi()
- 6.4 twitter_post/twitter_post.module \twitter_nodeapi()
Implementation of hook_nodeapi().
Intercepts newly published nodes and posts noticed to Twitter.
File
- ./
twitter.module, line 107
Code
function twitter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
module_load_include('inc', 'twitter');
switch ($op) {
case 'insert':
case 'update':
if (!empty($node->status) && !empty($node->twitter) && !empty($node->twitter['post'])) {
$twitter_accounts = twitter_get_user_accounts($node->uid, TRUE);
$pass = $twitter_accounts[$node->twitter['account']]['password'];
$status = _twitter_replace_tokens($node->twitter['status'], $node);
$result = twitter_set_status($node->twitter['account'], $pass, $status);
if (_twitter_request_failure($result)) {
drupal_set_message(t('An error occurred when posting to twitter: %code %error', array(
'%code' => $result->code,
'%error' => $result->error,
)), 'warning');
}
else {
drupal_set_message(t('Successfully posted to Twitter'));
}
}
break;
}
}