You are here

function fbconnect_render_js in Facebook Connect 6

Same name and namespace in other branches
  1. 8.2 fbconnect.module \fbconnect_render_js()
  2. 6.2 fbconnect.module \fbconnect_render_js()
  3. 7.2 fbconnect.module \fbconnect_render_js()

This function manage all javascripts used by this module.

1 call to fbconnect_render_js()
fbconnect_init in ./fbconnect.module
Implementation of hook_init().

File

./fbconnect.module, line 522

Code

function fbconnect_render_js() {
  global $base_url;
  global $user;
  $module_path = drupal_get_path('module', 'fbconnect');
  $escaped_urL = drupal_to_js($base_url);
  if ($config = fbconnect_get_config()) {
    unset($config['secret_api_key']);
    $config['fbuid'] = fbconnect_get_fbuid();
    $config['user'] = array(
      'uid' => $user->uid,
      'fbuid' => @$user->fbuid,
    );
    drupal_add_js(array(
      'fbconnect' => $config,
    ), 'setting');
    drupal_add_js($module_path . '/fbconnect.js');
  }
  if ($config && isset($_SESSION['fbconnect_feed'])) {
    $site = variable_get('site_name', $base_url);
    $feed = $_SESSION['fbconnect_feed'];
    switch ($feed['type']) {
      case 'comment':
        $autopublish = 'false';
        $feed_js = array(
          'name' => $feed['title'],
          'href' => $feed['nodeurl'],
          'caption' => t("{*actor*} commented at !site", array(
            "!site" => $site,
          )),
          'description' => strip_tags($feed["comment"]),
          'properties' => array(
            t('read') => array(
              'text' => $feed['title'],
              'href' => $feed['nodeurl'],
            ),
            t('visit') => array(
              'text' => $site,
              'href' => $base_url,
            ),
          ),
        );

        //Action links are currently not working and will be removed from above

        //properties to action links as soon as they're available
        $action_links = array();
        break;
      case 'node':
        $autopublish = 'false';
        $feed_js = array(
          'name' => $feed['title'],
          'href' => $feed['nodeurl'],
          'caption' => t("{*actor*} created some content at !site", array(
            "!site" => $site,
          )),
          'properties' => array(
            t('read') => array(
              'text' => $feed['title'],
              'href' => $feed['nodeurl'],
            ),
            t('visit') => array(
              'text' => $site,
              'href' => $base_url,
            ),
          ),
        );
        $action_links = array();
        break;
      case 'register':
        $autopublish = 'true';
        $feed_js = array(
          'name' => t('Welcome to @site', array(
            '@site' => $site,
          )),
          'href' => $base_url,
          'caption' => t("{*actor*} has registered at !site", array(
            "!site" => $site,
          )),
          'properties' => array(
            t('visit') => array(
              'text' => $site,
              'href' => $base_url,
            ),
          ),
        );

        //Action links are currently not working and will be removed from above

        //properties to action links as soon as they're available
        $action_links = array();
        break;
    }

    /**
     * see http://developers.facebook.com/docs/?u=facebook.jslib.FB.Connect.streamPublish
     * for more info about used params here
     * FB.Connect.streamPublish(user_message, attachment, action_links, target_id, user_management_promt, callback, auto_publish, actor_id)
     */
    $streamPublishArgs = array(
      "",
      $feed_js,
      $action_links,
      "",
      t('Something to say?'),
      "",
      $autopublish,
    );
    drupal_add_js(array(
      'FB.streamPublish' => $streamPublishArgs,
    ), 'setting');
    unset($_SESSION['fbconnect_feed']);
  }
}