You are here

function tweet_feed_feeds_form in Tweet Feed 7.2

Same name and namespace in other branches
  1. 7.3 tweet_feed_admin.inc \tweet_feed_feeds_form()
1 string reference to 'tweet_feed_feeds_form'
tweet_feed_menu in ./tweet_feed.module
Implements hook_menu().

File

./tweet_feed_admin.inc, line 274

Code

function tweet_feed_feeds_form($form, &$form_state, $fid = 0) {
  $breadcrumbs = array();
  $breadcrumbs[] = l('Home', '<front>');
  $breadcrumbs[] = l('Administration', 'admin');
  $breadcrumbs[] = l('Configuration', 'admin/config');
  $breadcrumbs[] = l('Web Services', 'admin/config/services');
  $breadcrumbs[] = l('Tweet Feed Feeds', 'admin/config/services/tweet_feed/feeds');
  $breadcrumbs[] = l('Tweet Feed Feeds Form', substr(request_uri(), 1));
  drupal_set_breadcrumb($breadcrumbs);

  // If we are being passed an aid, then we are updating the form and need to repopulate
  // the values and tell the processor that we are updating and not creating new.
  if (!empty($fid)) {
    $result = db_select('tweet_feeds', 'f')
      ->fields('f')
      ->condition('f.fid', $fid)
      ->execute()
      ->fetchObject();
    $fid = $result->fid;
    $aid = $result->aid;
    $feed_name = $result->feed_name;
    $query_type = $result->query_type;
    $timeline_id = $result->timeline_id;
    $search_term = $result->search_term;
    $list_name = $result->list_name;
    $pull_count = $result->pull_count;
    $clear_prior = $result->clear_prior;
    $new_window = $result->new_window;
  }
  else {

    // Otherwise just initialize the form so we do not have a swath of errors
    $fid = $aid = $query_type = $search_term = $list_name = $feed_name = NULL;
    $twitter_user_id = $pull_count = $new_window = $clear_prior = $timeline_id = NULL;
  }

  // Set up our settings for this particular feed (or update if it already exists)
  if (!empty($fid)) {
    $form['fid'] = array(
      '#type' => 'hidden',
      '#value' => $fid,
    );
  }
  $form['tweet_feed_query_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Twitter Query Settings'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#weight' => 2,
  );
  $form['tweet_feed_query_settings']['feed_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Feed Name'),
    '#description' => t('The name of the feed as it will appear on administrative forms'),
    '#default_value' => $feed_name,
    '#required' => TRUE,
  );

  // Get a list of the configured accounts so we can assign this feed to a particular
  // API account for pulling and allow user to select which one to use.
  $accounts = array();
  $result = db_select('tweet_accounts', 'a')
    ->fields('a', array(
    'aid',
    'account_name',
  ))
    ->orderBy('account_name', 'ASC')
    ->execute();
  while ($adata = $result
    ->fetchObject()) {
    $accounts[$adata->aid] = $adata->account_name;
  }

  // You must have an account to add a feed. If you don't then everything falls apart.
  // Warn the user here if they are trying to add a feed without an account.
  if (count($accounts) < 1) {
    drupal_set_message('You cannot create a feed until you have added an account. Please add an account here before proceeding to add a feed.', 'error');
    drupal_goto('admin/config/services/tweet_feed/accounts');
  }
  $form['tweet_feed_query_settings']['aid'] = array(
    '#type' => 'select',
    '#title' => t('API Account To Use For Pulling This Feed'),
    '#options' => $accounts,
    '#default_value' => $aid,
    '#required' => TRUE,
  );
  $form['tweet_feed_query_settings']['query_type'] = array(
    '#type' => 'radios',
    '#title' => t('Type of Twitter Query'),
    '#options' => array(
      QUERY_SEARCH => t('Twitter Search'),
      QUERY_TIMELINE => t('User Timeline Display'),
      QUERY_LIST => t('User List Display'),
    ),
    '#required' => TRUE,
    '#default_value' => $query_type,
  );
  $form['tweet_feed_query_settings']['search_term'] = array(
    '#type' => 'textfield',
    '#title' => t('Twitter Search Term'),
    '#max_length' => 64,
    '#default_value' => $search_term,
    '#states' => array(
      'visible' => array(
        ':input[name="query_type"]' => array(
          'value' => QUERY_SEARCH,
        ),
      ),
    ),
  );
  $form['tweet_feed_query_settings']['timeline_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Exact Twitter User ID For Timline Query'),
    '#description' => t('You can get this by going to mytwitterid.com'),
    '#max_length' => 64,
    '#default_value' => $timeline_id,
    '#states' => array(
      'visible' => array(
        ':input[name="query_type"]' => array(
          array(
            'value' => QUERY_TIMELINE,
          ),
          array(
            'value' => QUERY_LIST,
          ),
        ),
      ),
    ),
  );
  $form['tweet_feed_query_settings']['list_name'] = array(
    '#type' => 'textfield',
    '#title' => t('List name'),
    '#description' => t('Enter the list name exactly as it appears on twitter.com'),
    '#max_length' => 64,
    '#default_value' => $list_name,
    '#states' => array(
      'visible' => array(
        ':input[name="query_type"]' => array(
          'value' => QUERY_LIST,
        ),
      ),
    ),
  );
  $form['tweet_feed_query_settings']['pull_count'] = array(
    '#type' => 'select',
    '#title' => t('Number of Items to Pull'),
    '#max_length' => 2,
    '#options' => array(
      '100' => '100',
      '200' => '200',
      '300' => '300',
      '400' => '400',
      '500' => '500',
      '600' => '600',
      '700' => '700',
      '800' => '800',
      '900' => '900',
      '1000' => '1000',
    ),
    '#description' => t('Twitter limits tweet pulling to 1500 every 15 minutes. Keep this in mind when setting the pull count in conjunction with the frequency of cron/drush runs.'),
    '#required' => TRUE,
    '#default_value' => $pull_count,
  );
  $form['tweet_feed_query_settings']['new_window'] = array(
    '#type' => 'checkbox',
    '#title' => t('Open tweeted links, hashtags and mentions in a new window.'),
    '#default_value' => $new_window,
  );
  $form['tweet_feed_query_settings']['clear_prior'] = array(
    '#type' => 'checkbox',
    '#title' => t('Remove all tweets in this feed prior to import.'),
    '#default_value' => $clear_prior,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit Settings Form'),
    '#weight' => 3,
  );
  return $form;
}