? LICENSE.txt ? images ? twitter.install Index: twitter.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/twitter/twitter.info,v retrieving revision 1.1.2.1 diff -u -p -r1.1.2.1 twitter.info --- twitter.info 18 Jun 2007 23:07:10 -0000 1.1.2.1 +++ twitter.info 22 Apr 2009 21:58:24 -0000 @@ -1,5 +1,11 @@ ; $Id: twitter.info,v 1.1.2.1 2007/06/18 23:07:10 dww Exp $ name = Twitter -description = This module posts blog updates to twitter.com +description = This module posts website updates to twitter.com + +; Information added by drupal.org packaging script on 2007-06-19 +version = "5.x-1.x-dev" +project = "twitter" +datestamp = "1182212751" + Index: twitter.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/twitter/twitter.module,v retrieving revision 1.1 diff -u -p -r1.1 twitter.module --- twitter.module 23 Jan 2007 17:05:50 -0000 1.1 +++ twitter.module 22 Apr 2009 21:58:25 -0000 @@ -3,6 +3,78 @@ define('TWITTER_URL', 'http://twitter.com/statuses/update.xml'); + +/** + * Implementation of hook_menu(). + */ +function twitter_menu($may_cache) { + $items = array(); + if ($may_cache) { + $items[] = array('path' => 'admin/settings/twitter', 'title' => t('Twitter'), + 'callback' => 'drupal_get_form', + 'callback arguments' => 'twitter_admin_settings', + 'description' => t('Configure the website twitter account.'), + 'access' => user_access('administer twitter'), + 'type' => MENU_NORMAL_ITEM,); + } + return $items; +} + + +/** + * Implementation of hook_perm(). + */ +function twitter_perm() { + $array = array('administer twitter'); + + return $array; +} + +/** + * Controller for twitter administrative settings. + */ +function twitter_admin_settings() { + // only administrators can access this module + if (!user_access('administer site configuration')) { + return message_access(); + } + $form['twitter'] = array( + '#type' => 'fieldset', + '#title' => t('Twitter Website settings')); + $form['twitter']['twitter_website_user'] = array( + '#type' => 'textfield', + '#title' => t('Username'), + '#default_value' => variable_get('twitter_website_user',''), + '#description' => t('The username (email address) associated with your twitter.com account')); + $form['twitter']['twitter_website_pass'] = array( + '#type' => 'password', + '#default_value' => variable_get('twitter_website_pass',''), + '#title' => t('Password')); + $form['twitter']['twitter_website_text'] = array( + '#type' => 'textfield', + '#title' => t('Text format'), + '#default_value' => variable_get('twitter_website_text',''), + '#description' => t('Format of the text to submit. Use !title and !url for the post title and url respectively.')); + + if(function_exists('content_types')){ + $content_types = content_types(); + foreach($content_types as $content_type => $info){ + $content_types_options[$content_type]= $content_type; + } + $form['twitter']['twitter_website_content_types'] = array( + '#type' => 'checkboxes', + '#title' => t('Configure Content Types'), + '#default_value' => variable_get('twitter_website_content_types',''), + '#options' => $content_types_options, + '#description' => t('Enable/Disable content type to post to Twitter.'), + '#required' => FALSE + ); + + } + + return system_settings_form($form); +} + /** * Implementation of hook_user() */ @@ -38,30 +110,102 @@ function twitter_user($op, &$edit, &$acc function twitter_nodeapi(&$node, $op) { switch ($op) { case 'insert': + //twitter post using user account if available global $user; if ($node->status == 1) { - twitter_post($node, $user); + //twitter post using user account if available + twitter_user_post($node, $user); + //twitter post using website account if available + twitter_website_post($node); } + + } } + /** * Implements the twitter posting API per: * http://twitter.com/help/api */ -function twitter_post($node, $account) { +function twitter_website_post($node) { + + //Check Content Type + $twitter_website_content_types = variable_get('twitter_website_content_types',''); + if(!$twitter_website_content_types[$node->type]){ + return false; + } + + $twitter_website_user = variable_get('twitter_website_user',''); + $twitter_website_pass = variable_get('twitter_website_pass',''); + $twitter_website_text = variable_get('twitter_website_text',''); + + if (!empty($twitter_website_user) && !empty($twitter_website_pass)) { + $twitter_website_encrypted = base64_encode($twitter_website_user .':'. $twitter_website_pass); + } else { + return false; + } + $text = ($twitter_website_text) ? $twitter_website_text : 'New post: !title (!url)'; + $text = t($text, array('!title' => $node->title, + '!url' => url(drupal_get_path_alias('node/' . $node->nid), NULL, NULL, TRUE))); + + $headers = array('Authorization' => 'Basic '. $twitter_website_encrypted, + 'Content-type' => 'application/x-www-form-urlencoded'); + $data = 'status='. urlencode($text); + + $result = drupal_http_request(TWITTER_URL, $headers, 'POST', $data); + drupal_set_message(t('Posted to twitter.com by website')); +} + +/** + * Implements the twitter posting API per: + * http://twitter.com/help/api + */ +function twitter_user_post($node, $account) { if (empty($account->twitter_encrypted)) { return false; } $text = ($account->twitter_text) ? $account->twitter_text : 'New post: !title (!url)'; $text = t($text, array('!title' => $node->title, - '!url' => url('node/' . $node->nid, NULL, NULL, TRUE))); - + '!url' => url(drupal_get_path_alias('node/' . $node->nid), NULL, NULL, TRUE))); + $headers = array('Authorization' => 'Basic '. $account->twitter_encrypted, 'Content-type' => 'application/x-www-form-urlencoded'); $data = 'status='. urlencode($text); $result = drupal_http_request(TWITTER_URL, $headers, 'POST', $data); - drupal_set_message(t('Posted to twitter.com')); + drupal_set_message(t('Posted to twitter.com using your user account')); +} + +function twitter_block($op = 'list', $delta = 0, $edit = array()) { + + switch ($op) { + + case 'list': + $blocks[0]['info'] = t('Twitter your site'); + return $blocks; + break; + case 'view': + switch ($delta) { + case 0: + $twitter_website_user = variable_get('twitter_website_user',''); + if($twitter_website_user){ + $block['subject'] = t('Twitter your site'); + $block['content'] = theme_twitter_block($twitter_website_user); + } + break; + } + return $block; + } +} + +function theme_twitter_block($user){ + $module_path = drupal_get_path('module','twitter'); + + $output = ' '; + $link.= t('Follow') . ' @' . $user . ' ' . t("on Twitter"); + $output.= l($link,'http://www.twitter.com/'. $user,array('target' => '_blank')); + + return $output; } \ No newline at end of file