status || ($node->type != 'story')) return; $username = 'your_username'; $password = 'your_password'; $status = url('node/'.$node->nid, NULL, NULL, TRUE); if (drupal_strlen($status) < TWITTER_MAX-strlen(TWITTER_SPACER)) { $status = drupal_substr($node->title, 0, TWITTER_MAX-strlen(TWITTER_SPACER)-drupal_strlen($status)) . TWITTER_SPACER . $status; } $socket = fsockopen('twitter.com', 80, $errno, $errstr, 20); if (!$socket) { drupal_watchdog(t('Could not ping twitter on insert of node %node', array('%node' => $node->nid))); return; } $postdata = 'status='.urlencode($status); $out = "POST /statuses/update.xml HTTP/1.0\r\n"; $out .= "Host: twitter.com\r\n"; $out .= "Authorization: Basic ".base64_encode($username.':'.$password)."\r\n"; $out .= "Content-Type: application/x-www-form-urlencoded\r\n"; $out .= "Content-Length: ".strlen($postdata)."\r\n"; $out .= "Connection: Close\r\n\r\n"; $out .= $postdata; fwrite($socket, $out); fclose($socket); }