You are here

function facebook_comments_block_block_view in Facebook Comments Block 7

Same name and namespace in other branches
  1. 7.2 facebook_comments_block.module \facebook_comments_block_block_view()

Implements hook_block_view().

File

./facebook_comments_block.module, line 322
Code for the Facebook Comments Block module.

Code

function facebook_comments_block_block_view($delta = '') {
  global $base_url;
  $main_domain = $base_url;
  if (variable_get('facebook_comments_block_settings_domain', '') !== '') {
    $main_domain = variable_get('facebook_comments_block_settings_domain', '');
  }
  $block = array();
  switch ($delta) {
    case 'fb_comments':
      $url = $main_domain . '/' . current_path();
      $facebook_app_id = variable_get('facebook_comments_block_settings_app_id', '');
      $facebook_app_id_script = $facebook_app_id != '' ? "&appId={$facebook_app_id}" : '';
      $facebook_app_lang = variable_get('facebook_comments_block_settings_lang', 'en_US');
      $js_vars = array(
        'facebook_app_id' => $facebook_app_id,
        'facebook_app_id_script' => $facebook_app_id_script,
        'facebook_app_lang' => $facebook_app_lang,
      );
      $theme_vars = array(
        'facebook' => array(
          'data_attributes' => array(
            'href' => $url,
            'data-href' => $url,
            'data-width' => variable_get('facebook_comments_block_settings_width', '500'),
            'data-numposts' => variable_get('facebook_comments_block_settings_number_of_posts', '5'),
            'data-colorscheme' => variable_get('facebook_comments_block_settings_color_schema', 'light'),
            'data-order-by' => variable_get('facebook_comments_block_settings_order', 'top'),
          ),
        ),
      );
      $facebook_app_id_meta = array(
        '#type' => 'html_tag',
        '#tag' => 'meta',
        '#attributes' => array(
          'property' => 'fb:app_id',
          'content' => $facebook_app_id,
        ),
      );
      drupal_add_html_head($facebook_app_id_meta, 'facebook_app_id_meta');
      $block = array(
        'subject' => t('Facebook comments'),
        'content' => theme('facebook_comments__block', $theme_vars),
      );
      drupal_add_js(array(
        'facebook_comments_block' => array(
          'facebook_settings' => $js_vars,
        ),
      ), array(
        'type' => 'setting',
      ));
      drupal_add_js(drupal_get_path('module', 'facebook_comments_block') . '/js/facebook_comments_block.js', array(
        'scope' => 'footer',
        'type' => 'file',
      ));
      break;
  }
  return $block;
}