You are here

function twitter_user_settings in Twitter 6.5

Same name and namespace in other branches
  1. 6.2 twitter.pages.inc \twitter_user_settings()
  2. 6.3 twitter.pages.inc \twitter_user_settings()
  3. 6.4 twitter.pages.inc \twitter_user_settings()
  4. 7.6 twitter.pages.inc \twitter_user_settings()
  5. 7.3 twitter.pages.inc \twitter_user_settings()
  6. 7.4 twitter.pages.inc \twitter_user_settings()
  7. 7.5 twitter.pages.inc \twitter_user_settings()

Form builder that lists Twitter accounts.

Parameters

object $account: Optional user account.

Return value

A list of Twitter accounts and a form to add more.

1 string reference to 'twitter_user_settings'
twitter_menu in ./twitter.module
Implements hook_menu().

File

./twitter.pages.inc, line 126
Page callbacks for Twitter module.

Code

function twitter_user_settings($account = NULL) {

  // Verify OAuth keys.
  if (!twitter_api_keys()) {
    $variables = array(
      '@twitter-settings' => url('admin/settings/twitter/settings'),
    );
    $output = '<p>' . t('You need to authenticate at least one Twitter account in order to use the Twitter API. Please fill out the OAuth fields at <a href="@twitter-settings">Twitter Settings</a> and then return here.', $variables) . '</p>';
  }
  else {
    module_load_include('inc', 'twitter');
    if (!$account) {
      $twitter_accounts = twitter_load_accounts();
    }
    else {
      $twitter_accounts = twitter_twitter_accounts($account);
    }
    $output = '<p>';
    if (count($twitter_accounts)) {

      // List Twitter accounts.
      if (user_access('administer site configuration')) {
        $variables = array(
          '@run-cron' => url('admin/reports/status/run-cron', array(
            'query' => array(
              'destination' => 'admin/settings/twitter',
            ),
          )),
        );
        $output .= t('Tweets are pulled from Twitter by <a href="@run-cron">running cron</a>.', $variables) . ' ';
      }
      $variables = array(
        '@tweets' => url('tweets'),
      );
      $output .= t('You can view the full list of tweets at the <a href="@tweets">Tweets</a> view.', $variables);
      $output .= '</p>';
      $output .= drupal_get_form('twitter_account_list_form', $twitter_accounts);
    }
    else {

      // No accounts added. Inform about how to add one.
      $output = '<p>' . t('No Twitter accounts have been added yet. Click on the following button to add one.') . '</p>';
    }
    $add_account = array(
      '#type' => 'fieldset',
      '#title' => t('Add Twitter accounts'),
      '#weight' => 5,
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#children' => '',
    );
    if (user_access('add authenticated twitter accounts')) {
      $add_account['#children'] .= drupal_get_form('twitter_auth_account_form');
    }
    if (user_access('add twitter accounts')) {
      $add_account['#children'] .= drupal_get_form('twitter_non_auth_account_form');
    }
    $output .= drupal_render($add_account);
  }
  return $output;
}