Created
November 2, 2012 10:46
Snipped for Drupal page allowing users to post to site global Twitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!user_access('post to twitter')) { | |
drupal_set_message("You don't have permission to post to our Twitter account, sorry!"); | |
} | |
else { | |
module_load_include('inc', 'twitter'); | |
function twitter_standalone_form() { | |
$form = twitter_post_form(); | |
$form['submit'] = array( | |
'#type' => 'submit', | |
'#value' => t('Post'), | |
); | |
return $form; | |
} | |
function twitter_standalone_form_submit($form, &$form_state) { | |
$twitter_account = twitter_account_load($form_state['values']['account']); | |
$status = $form_state['values']['status']; | |
try { | |
twitter_set_status($twitter_account, $status); | |
drupal_set_message(t('Posted "' . $status . '" to @' . $twitter_account->screen_name)); | |
} | |
catch (TwitterException $e) { | |
drupal_set_message(t('An error occurred when posting to Twitter: @message', | |
array('@message' => $e->getMessage())), 'warning'); | |
} | |
} | |
return drupal_render(drupal_get_form('twitter_standalone_form')); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment