You are here

function action_fb_set_ref_fbml in Drupal for Facebook 5

Implementation of an Action.

This action updates reference FBML. http://developer.facebook.com/documentation.php?v=1.0&method=fbml.setRef...

File

./fb_actions.module, line 582
Actions defined here interact with Facebook's API. This makes it possible to notify facebook of various activities as they happen.

Code

function action_fb_set_ref_fbml($op, $edit = array(), $fb_app) {
  if ($op == 'metadata') {
    return array(
      'description' => t('Facebook set reference FBML'),
      'type' => t('Facebook App'),
      'batchable' => FALSE,
      'configurable' => TRUE,
    );
  }
  else {
    if ($op == 'form') {
      $options = fb_get_app_options(TRUE);
      $form['description'] = array(
        '#value' => t('This action will update reference FBML.  See Facebook\'s documentation of the <fb:ref> tag.  Suitable for canvas pages and cron jobs (if infinite session is configured).'),
      );
      $form['fb_app_nid'] = array(
        '#type' => 'select',
        '#title' => t('Application'),
        '#default_value' => $edit['fb_app_nid'],
        '#options' => $options,
        '#description' => t('Log into Facebook as which application?  %current is OK when invoked from canvas pages or cron jobs.', array(
          '%current' => $options[FB_APP_CURRENT],
        )),
      );
      $form['handle'] = array(
        '#type' => 'textfield',
        '#title' => t('Handle'),
        '#default_value' => $edit['handle'],
      );
      $form['body'] = array(
        '#type' => 'textarea',
        '#title' => t('Profile FBML'),
        '#default_value' => $edit['body'],
        '#description' => t('FBML to write to user\'s profile.<br />The following token will be replaced: !token_help', array(
          '!token_help' => theme('token_help', 'fb_app'),
        )),
      );
      $form['body_filter'] = filter_form($edit['body_filter'], NULL, array(
        'body_filter',
      ));
      return $form;
    }
    else {
      if ($op == 'submit') {
        return array(
          'handle' => $edit['handle'],
          'body' => $edit['body'],
          'body_filter' => $edit['body_filter'],
        );
      }
      else {
        if ($op == 'do') {
          if ($GLOBALS['fb_app']->apikey == $fb_app->apikey) {

            // Use global FB api, if set up.
            $fb = $GLOBALS['fb'];
          }
          else {
            $fb = fb_api_init($fb_app, FB_FBU_INFINITE_SESSION);
          }

          // This will be set on canvas pages and Facebook App cron actions.
          if ($fb) {

            // Replace fb_app related tokens
            $body = token_replace($edit['body'], 'fb_app', $fb_app);
            $body = check_markup($body, $edit['body_filter'], FALSE);
            $fb->api_client
              ->fbml_setRefHandle($edit['handle'], $body);

            // TODO: enable filters for body.
            $fb->api_client
              ->profile_setFBML($body, $fbu);
            fb_report_errors($fb);
          }
        }
      }
    }
  }
}