You are here

function fb_feed_register_template in Drupal for Facebook 5.2

3 calls to fb_feed_register_template()
fb_feed_insert in ./fb_feed.module
fb_feed_register_cb in ./fb_feed.module
fb_feed_update in ./fb_feed.module

File

./fb_feed.module, line 366
Helpers for Facebook feeds (http://wiki.developers.facebook.com/index.php/New_Design_Feed_Wall)

Code

function fb_feed_register_template($node) {
  $fb_app = fb_get_app(array(
    'nid' => $node->fb_app_nid,
  ));

  // Login to facebook as either the current user or the infinite session
  if ($fb_app) {
    $fb = fb_api_init($fb_app, FB_FBU_ANY);
    if ($fb) {

      // Clean up the data before sending to facebook.  Send no empty templates.
      $lines = array();
      foreach ($node->fb_feed_data['line'] as $line) {
        if ($line) {
          $lines[] = $line;
        }
      }
      $shorts = array();
      foreach ($node->fb_feed_data['short'] as $item) {
        if ($item['template_title']) {
          $shorts[] = $item;
        }
      }
      $full = array();
      if ($node->fb_feed_data['full']['template_title']) {
        $full = $node->fb_feed_data['full'];
      }
      if ($fb) {
        try {
          $bundle_id = $fb->api_client
            ->feed_registerTemplateBundle($lines, $shorts, $full);
        } catch (Exception $e) {
          fb_log_exception($e, t('Error attempting to register template bundle.'), $fb);
        }
        if ($bundle_id) {
          drupal_set_message(t('Registered template bundle %bundle_id with Facebook.', array(
            '%bundle_id' => $bundle_id,
          )));
        }
        else {
          drupal_set_message(t('Failed to register the template.'), 'error');
        }
        if ($bundle_id && $node->nid) {
          db_query("UPDATE {fb_feed_template} fft SET bundle_id=%f WHERE nid=%d", $bundle_id, $node->nid);
        }
        return $bundle_id;
      }
    }
  }

  // TODO: report failure to connect to facebook api
  drupal_set_message(t('Failed to connect to Facebook for application %app.', array(
    '%app' => $fb_app->title,
  )), 'error');
}