--- twitter.module	2007-01-23 18:05:50.000000000 +0100
+++ twitterNew.module	2009-10-21 18:46:49.000000000 +0200
@@ -4,34 +4,44 @@
 define('TWITTER_URL', 'http://twitter.com/statuses/update.xml');
 
 /**
+ * Implementation of hook_perm().
+ */
+function twitter_perm() {
+  return array('access twitter');
+}
+
+
+/**
  * Implementation of hook_user()
  */
 function twitter_user($op, &$edit, &$account, $category = NULL) {
-  switch ($op) {
-    case 'form':
-      $form['twitter'] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Twitter settings'));
-      $form['twitter']['twitter_user'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Username'),
-        '#default_value' => $edit['twitter_user'],
-        '#description' => t('The username (email address) associated with your twitter.com account'));
-      $form['twitter']['twitter_pass'] = array(
-        '#type' => 'password',
-        '#title' => t('Password'));
-      $form['twitter']['twitter_text'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Text format'),
-        '#default_value' => $edit['twitter_text'],
-        '#description' => t('Format of the text to submit. Use !title and !url for the post title and url respectively.'));
-      return $form;
-    case 'insert':
-    case 'update':
-      if (!empty($edit['twitter_user']) && !empty($edit['twitter_pass'])) {
-        $edit['twitter_encrypted'] = base64_encode($edit['twitter_user'] .':'. $edit['twitter_pass']);
-      }
-      unset($edit['twitter_pass']);
+  if (user_access('access twitter')) {
+    switch ($op) {
+      case 'form':
+        $form['twitter'] = array(
+          '#type' => 'fieldset',
+          '#title' => t('Twitter settings'));
+        $form['twitter']['twitter_user'] = array(
+          '#type' => 'textfield',
+          '#title' => t('Username'),
+          '#default_value' => $edit['twitter_user'],
+          '#description' => t('The username (email address) associated with your twitter.com account'));
+        $form['twitter']['twitter_pass'] = array(
+          '#type' => 'password',
+          '#title' => t('Password'));
+        $form['twitter']['twitter_text'] = array(
+          '#type' => 'textfield',
+          '#title' => t('Text format'),
+          '#default_value' => $edit['twitter_text'],
+          '#description' => t('Format of the text to submit. Use !title and !url for the post title and url respectively.'));
+        return $form;
+      case 'insert':
+      case 'update':
+        if (!empty($edit['twitter_user']) && !empty($edit['twitter_pass'])) {
+          $edit['twitter_encrypted'] = base64_encode($edit['twitter_user'] .':'. $edit['twitter_pass']);
+        }
+        unset($edit['twitter_pass']);
+    }
   }
 }
 
@@ -64,4 +74,4 @@ function twitter_post($node, $account) {
 
   $result = drupal_http_request(TWITTER_URL, $headers, 'POST', $data);
   drupal_set_message(t('Posted to twitter.com'));
-}
\ No newline at end of file
+}
