a pastebin project

Paste Description for Drupal Twitter Post Form

Allows user roles with the 'twitter_post access' permission to send sms updates using Twitter.

Drupal Twitter Post Form

  1. <?php
  2. function twitter_post_perm() {
  3.   return array('access twitter_post content');
  4. } // function twitter_post_perm()
  5.  
  6. function twitter_post_menu() {
  7.   $items = array();
  8.   $items[] = array(
  9.     'path' => 'twitterpost',
  10.     'title' => t('Send SMS update'),
  11.     'callback' => 'twitter_post_all',
  12.     'access' => user_access('access twitter_post content'),
  13.     'type' => MENU_NORMAL_ITEM,
  14.     'description' => t('Send messages to Twitter')
  15.   );
  16.  
  17.   return $items;
  18. }
  19.  
  20. function twitter_post_all() {
  21.   return drupal_get_form('twitter_post_form');
  22. }
  23.  
  24. function twitter_post_form() {
  25.   $form['twitter_form'] = array(
  26.     '#type' => 'textfield',
  27.     '#title' => t('text message'),
  28.     '#size' => 60,
  29.     '#maxlength' => 140,
  30.     '#description' => t('text message to send out')
  31.   );
  32.   $form['submit'] = array('#type' => 'submit', '#value' => t('Send'));
  33.   return $form;
  34. }
  35.  
  36. function twitter_post_form_submit($form_id, $form_values) {
  37.   $email = 'mytwitterusername';
  38.   $password = 'mytwitterpassword';
  39.   $status = urlencode($form_values['twitter_form']);
  40.   $url = "http://twitter.com/statuses/update.xml";
  41.  
  42.   $session = curl_init();
  43.   curl_setopt ( $session, CURLOPT_URL, $url );
  44.   curl_setopt ( $session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
  45.   curl_setopt ( $session, CURLOPT_HEADER, false );
  46.   curl_setopt ( $session, CURLOPT_USERPWD, $email . ":" . $password );
  47.   curl_setopt ( $session, CURLOPT_RETURNTRANSFER, 1 );
  48.   curl_setopt ( $session, CURLOPT_POST, 1);
  49.   curl_setopt ( $session, CURLOPT_POSTFIELDS,"status=" . $status);
  50.   $result = curl_exec ( $session );
  51.   curl_close( $session );
  52.   drupal_set_message(t('Message sent.'));
  53. }
  54. ?>

advertising

Create a Paste

Please enter your new post below (or upload a file instead):





Please note that information posted here will not expire by default. If you want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords.

worth-right
fantasy-obligation