You are here

function fbconnect_stream_publish_render_js in Facebook Connect 8.2

Same name and namespace in other branches
  1. 6.2 fbconnect_stream_publish/fbconnect_stream_publish.module \fbconnect_stream_publish_render_js()
  2. 7.2 fbconnect_stream_publish/fbconnect_stream_publish.module \fbconnect_stream_publish_render_js()

Parameters

array $feed: Properites - type, title, nodeurl[, comment]

2 calls to fbconnect_stream_publish_render_js()
fbconnect_stream_publish_comment_feed_submit in fbconnect_stream_publish/fbconnect_stream_publish.module
Stock informations used by the Facebook feed javascript function.
fbconnect_stream_publish_init in fbconnect_stream_publish/fbconnect_stream_publish.module
Implements hook_init().

File

fbconnect_stream_publish/fbconnect_stream_publish.module, line 192

Code

function fbconnect_stream_publish_render_js($feed) {
  global $base_url;
  $site = variable_get('site_name', $base_url);
  switch ($feed['type']) {
    case 'comment':
      $autopublish = 'false';
      $attachment = array(
        'name' => $feed['title'],
        'href' => $feed['nodeurl'],
        'caption' => t("{*actor*} commented at !site", array(
          "!site" => $site,
        )),
        'description' => strip_tags($feed['comment']),
      );
      $action_links = array(
        array(
          'text' => $site,
          'href' => $base_url,
        ),
      );
      $message = t('I posted a comment on !site_name.', array(
        '!site_name' => variable_get('site_name', 'Drupal'),
      ));
      break;
    case 'node':
      $autopublish = 'false';
      $attachment = array(
        'name' => $feed['title'],
        'href' => $feed['nodeurl'],
        'caption' => t("{*actor*} created some content at !site", array(
          "!site" => $site,
        )),
      );
      $action_links = array(
        array(
          'text' => $site,
          'href' => $base_url,
        ),
      );
      $message = t('I posted new content on !site_name.', array(
        '!site_name' => variable_get('site_name', 'Drupal'),
      ));
      break;
    case 'register':
      $autopublish = 'true';
      $attachment = array(
        'name' => t('Welcome to @site', array(
          '@site' => $site,
        )),
        'href' => $base_url,
        'caption' => t("{*actor*} has registered at !site", array(
          "!site" => $site,
        )),
      );
      $action_links = array(
        array(
          'text' => $site,
          'href' => $base_url,
        ),
      );
      $message = t('I just became a member at !site_name!', array(
        '!site_name' => variable_get('site_name', 'Drupal'),
      ));
  }

  /**
   * @see http://developers.facebook.com/docs/reference/rest/stream.publish
   * @see http://developers.facebook.com/docs/guides/attachments
   */
  $method = 'stream.publish';
  $user_message_prompt = t('Share your thoughts');
  $streamPublishArgs = compact('method', 'message', 'attachment', 'action_links', 'user_message_prompt');

  //  drupal_alter('fbconnect_stream_publish', $streamPublishArgs);
  drupal_add_js(array(
    'FB.streamPublish' => $streamPublishArgs,
  ), array(
    'type' => 'setting',
    'scope' => JS_DEFAULT,
  ));
  drupal_add_js(drupal_get_path('module', 'fbconnect_stream_publish') . '/fbconnect_stream_publish.js');
}