You are here

public function OAuthHTTPFetcher::sourceForm in Feeds OAuth 7

Same name and namespace in other branches
  1. 6 OAuthHTTPFetcher.inc \OAuthHTTPFetcher::sourceForm()

Expose source form.

File

./OAuthHTTPFetcher.inc, line 248
Definition of the import batch object created on the fetching stage by OAuthHTTPFetcher.

Class

OAuthHTTPFetcher
Support OAuth authentication.

Code

public function sourceForm($source_config) {
  $form = parent::sourceForm($source_config);
  if (empty($source_config)) {
    return $form;
  }

  // FIXME Ugly hack to get caller FeedsSource object. We know a FeedsSource object will call this method.
  $trace = debug_backtrace();
  $source = $trace[1]['object'];

  // Check existence of access tokens.
  $uid = $this
    ->getAuthenticatedUser($source);
  $access_tokens = call_user_func($this->config['authenticator'], $uid, $this->config['site_id'], $this->id);
  if (empty($access_tokens) && !empty($this->config['site_id'])) {
    global $user;
    if ($uid === $user->uid) {

      // user can request new access token
      drupal_set_message(t('Could not find OAuth access tokens for site %site.
          You should <a href="@url">authenticate first</a> to access protected information.', array(
        '%site' => $this->config['site_id'],
        '@url' => url('feeds/oauth' . ($this->two ? '2' : '') . '/authenticate/' . $this->id),
      )), 'warning');
    }
    else {

      // another user was selected, issue warning
      $authenticating_user = user_load($uid);
      drupal_set_message(t('Could not find OAuth access tokens for site %site.
          In addition, the authenticating user for this feed is set to be %username,
          so you cannot import this feed until %username authenticates to %site.', array(
        '%site' => $this->config['site_id'],
        '%username' => $authenticating_user->name,
      )), 'warning');
    }
  }
  return $form;
}