Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

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
Saturday, September 15th, 2007 at 8:38:01am MDT 

  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. ?>

Paste Details

Tags: drupal

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not 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. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
worth-right
fantasy-obligation