You are here

function oauthconnector_list_provider in OAuth Connector 7

Same name and namespace in other branches
  1. 6 oauthconnector.admin.inc \oauthconnector_list_provider()

Output a list of providers.

1 string reference to 'oauthconnector_list_provider'
oauthconnector_menu in ./oauthconnector.module
Implements hook_menu().

File

./oauthconnector.admin.inc, line 64
Administrative functions for the OAuth Connector module.

Code

function oauthconnector_list_provider($js = NULL) {
  $build = array();
  $build['presets'] = drupal_get_form('oauthconnector_presets_form');
  $header = array(
    array(
      'data' => t('Title') . '/' . t('URL'),
      'class' => 'oauthconnector-provider-title',
    ),
    array(
      'data' => t('Connect URL'),
      'class' => 'oauthconnector-provider-connect-url',
    ),
    array(
      'data' => t('Callback URL'),
      'class' => 'oauthconnector-provider-callback-url',
    ),
    array(
      'data' => t('Storage'),
      'class' => 'oauthconnector-provider-storage',
    ),
    array(
      'data' => t('Operations'),
      'class' => 'oauthconnector-provider-operations',
    ),
  );
  $providers = oauthconnector_provider_load_all();
  $rows = array();
  foreach ($providers as $provider) {
    $operations = array();
    if (empty($provider->disabled)) {
      $operations[] = array(
        'title' => t('Edit'),
        'href' => 'admin/structure/oauthconnector/' . $provider->name . '/edit',
      );
      $operations[] = array(
        'title' => t('Export'),
        'href' => 'admin/structure/oauthconnector/' . $provider->name . '/export',
      );
    }
    if ($provider->export_type == (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) {
      $operations[] = array(
        'title' => t('Revert'),
        'href' => 'admin/structure/oauthconnector/' . $provider->name . '/delete',
      );
    }
    elseif ($provider->export_type != EXPORT_IN_CODE) {
      $operations[] = array(
        'title' => t('Delete'),
        'href' => 'admin/structure/oauthconnector/' . $provider->name . '/delete',
      );
    }
    elseif (empty($provider->disabled)) {
      $operations[] = array(
        'title' => t('Disable'),
        'href' => 'admin/structure/oauthconnector/' . $provider->name . '/disable',
        'query' => drupal_get_destination(),
      );
    }
    else {
      $operations[] = array(
        'title' => t('Enable'),
        'href' => 'admin/structure/oauthconnector/' . $provider->name . '/enable',
        'query' => drupal_get_destination(),
      );
    }
    $callbackurl = empty($provider->csid) ? '' : l('oauth/authorized/' . $provider->csid, 'oauth/authorized/' . $provider->csid);
    if ($provider->consumer_advanced['oauth2']) {
      $callbackurl = empty($provider->csid) ? '' : l('oauth/authorized2/' . $provider->csid, 'oauth/authorized2/' . $provider->csid);
    }
    $connect_url = 'connect/oauthconnector_' . $provider->name;
    $connect_url = empty($provider->csid) ? '' : l($connect_url, $connect_url);
    $rows[$provider->name] = array(
      'data' => array(
        'title' => check_plain($provider->title) . '<br/>' . l($provider->url, $provider->url),
        'connect_url' => $connect_url,
        'callback_url' => $callbackurl,
        'storage' => $provider->type,
        'operations' => theme('links', array(
          'links' => $operations,
          'attributes' => array(
            'class' => array(
              'links',
              'inline',
            ),
          ),
        )),
      ),
      'class' => !empty($provider->disabled) ? array(
        'oauthconnector-provider-disabled',
      ) : '',
    );
    if (empty($rows[$provider->name]['data']['callback_url'])) {
      $rows[$provider->name]['data']['callback_url'] = array(
        'data' => t('Missing consumer key') . (empty($provider->disabled) ? ' (' . l(t('Add'), 'admin/structure/oauthconnector/' . $provider->name . '/edit') . ')' : ''),
        'class' => 'oauthconnector-provider-warning',
      );
    }
  }
  $build['table'] = array(
    '#markup' => theme('table', array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'id' => 'oauthconnector-list-provider',
      ),
    )),
  );
  drupal_add_css(drupal_get_path('module', 'oauthconnector') . '/oauthconnector.admin.css');
  return $build;
}