You are here

function twitter_user_settings in Twitter 7.5

Same name and namespace in other branches
  1. 6.5 twitter.pages.inc \twitter_user_settings()
  2. 6.2 twitter.pages.inc \twitter_user_settings()
  3. 6.3 twitter.pages.inc \twitter_user_settings()
  4. 6.4 twitter.pages.inc \twitter_user_settings()
  5. 7.6 twitter.pages.inc \twitter_user_settings()
  6. 7.3 twitter.pages.inc \twitter_user_settings()
  7. 7.4 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 132
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/config/services/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 = array();
    if (count($twitter_accounts)) {

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

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

  // Give a chance to other modules to alter the output.
  drupal_alter('twitter_user_settings', $output);
  return $output;
}