You are here

function fb_admin_app_page in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb.admin.inc \fb_admin_app_page()
  2. 6.2 fb.admin.inc \fb_admin_app_page()
1 string reference to 'fb_admin_app_page'
fb_menu in ./fb.module
Implements hook_menu().

File

./fb.admin.inc, line 110
Admin pages and forms for Drupal for Facebook.

Code

function fb_admin_app_page($fb_app = NULL) {
  fb_get_app_data($fb_app);
  fb_admin_get_app_info($fb_app);
  $fb = fb_api_init($fb_app);

  // @TODO use an actual theme function and make render more appealing.
  // Hide a couple things...
  unset($fb_app->secret);
  unset($fb_app->data);

  // Warn user if values have changed since last edit.
  foreach (array(
    'namespace' => 'canvas',
    'name' => 'title',
  ) as $prop => $key) {
    if (isset($fb_app->{$prop}) && isset($fb_app->{$key}) && $fb_app->{$prop} != $fb_app->{$key}) {
      if (module_exists('fb_app')) {
        drupal_set_message(t("The property %prop has been changed to %value on facebook.  Go to the Edit tab, confirm values are correct and hit Save button to syncronize the local values.", array(
          '%prop' => $prop,
          '%value' => $fb_app->{$prop},
        )), 'error');
      }
    }
  }
  $props_map = array(
    t('Name') => 'name',
    t('Label') => 'label',
    t('Namespace') => 'namespace',
    t('ID') => 'id',
    t('Secret') => 'secret',
  );
  $output = "<dl>\n";

  // Render props learned from facebook and stored in $fb_app object.
  $props_map = fb_invoke(FB_ADMIN_OP_LIST_PROPERTIES, array(
    'fb_app' => $fb_app,
  ), $props_map, FB_ADMIN_HOOK);
  foreach ($props_map as $name => $key) {
    if (isset($fb_app->{$key})) {
      $output .= "<dt>{$name}</dt><dd>{$fb_app->{$key}}</dd>\n";
    }
  }

  // This clause belongs in fb_canvas.module.  But currently no hook for that tab to add a "property" that is not a true facebook property.
  if (!empty($fb_app->namespace) && !empty($fb_app->callback_url)) {
    $canvas_url = '//apps.facebook.com/' . $fb_app->namespace;
    $output .= '<dt>' . t('Canvas pages') . '</dt><dd>' . "<a href=\"{$canvas_url}\">{$canvas_url}</a>" . '</dd>';
  }

  // This clause belongs in fb_tab.module.  But currently no hook for that tab to add a "property" that is not a true facebook property.
  if ($fb_app->page_tab_url && module_exists('fb_tab')) {

    // This app can be added to a page.  Provide a link to do so.
    $add_url = "http://www.facebook.com/dialog/pagetab?app_id={$fb_app->id}&next=" . url(FB_TAB_PATH_ADDED . '/' . $fb_app->label, array(
      'absolute' => TRUE,
      'language' => NULL,
    ));
    $output .= '<dt>' . t('Add to page link') . '</dt><dd>' . l($add_url, $add_url) . '</dd>';
  }

  // Render additional properties
  $token = fb_get_token($fb);
  $output .= '<dt>' . t('Access Token') . '</dt><dd>' . $token . "</dd>\n";

  // Still more properties, i.e. restrictions.
  $result = fb_graph($fb_app->id, array(
    'fields' => 'restrictions,migrations',
    'access_token' => fb_get_token($fb),
  ), 'GET', $fb);
  unset($result['id']);

  // redundant.
  foreach ($result as $key => $value) {
    if (!empty($value)) {
      $output .= '<dt>' . t($key) . '</dt><dd><pre>' . print_r($value, 1) . "</pre></dd>\n";
    }
  }
  $output .= "</dl>\n";

  //$output .=  '<pre>' . print_r($fb_app, 1) . '</pre>'; // debug
  return $output;
}