You are here

function fblikebutton_block in Facebook Like Button 6.2

Same name and namespace in other branches
  1. 6 fblikebutton.module \fblikebutton_block()

Implementation of hook_block()

File

./fblikebutton.module, line 134
Adds Facebook's "Like" button to each selected node type. Adds a block with a global static value where users can "Like" the URL set by admins.

Code

function fblikebutton_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $fullnodedisplay = variable_get('fblikebutton_full_node_display', 0);
      $blocks[0]['info'] = t('Static FB Like Button');
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      if ($fullnodedisplay == 1) {
        $blocks[1]['info'] = t('Dynamic FB Like Button');
        $blocks[1]['cache'] = BLOCK_NO_CACHE;
      }
      return $blocks;
    case 'configure':
      $form = array();
      if ($delta == 0 && user_access('administer fblikebutton block')) {
        $form['fblikebutton_static_block'] = array(
          '#type' => 'fieldset',
          '#title' => t('Static FB Like button block'),
          '#collapsible' => false,
        );
        $form['fblikebutton_static_block']['fblikebutton_static_config'] = array(
          '#type' => 'markup',
          '#value' => '<p>' . t('To configure the URL and the appearance of the button go to the ' . l(t('static Like button settings'), 'admin/settings/fblikebutton/static') . '. Make sure you set the right permissions on the ' . l(t('permissions page'), 'admin/user/permissions') . '.</p>'),
        );
      }
      if ($delta == 1 && user_access('administer fblikebutton block')) {
        $form['fblikebutton_dynamic_block'] = array(
          '#type' => 'fieldset',
          '#title' => t('Dynamic FB Like button block'),
          '#collapsible' => false,
        );
        $form['fblikebutton_dynamic_block']['fblikebutton_dynamic_config'] = array(
          '#markup' => '<p>' . t('To configure the visibility and the appearance of the button go to the ' . l(t('dynamic Like button settings'), 'admin/config/fblikebutton/dynamic') . '. You can enhance the visibility settings by using the settings on this page. Make sure you set the right permissions on the ' . l(t('permissions page'), 'admin/people/permissions') . '.</p>'),
        );
      }
      return $form;
    case 'view':
      global $base_url;
      $node = node_load(arg(1));
      $types = variable_get('fblikebutton_node_types', array());
      if ($node) {
        $show = !empty($types[$node->type]) && user_access('access fblikebutton');
      }
      else {
        $show = NULL;
      }
      $fullnodedisplay = variable_get('fblikebutton_full_node_display', 0);
      if ($delta == 1 && $show && $fullnodedisplay == 1 && $node) {
        $webpage_to_like = url("node/{$node->nid}", array(
          'absolute' => TRUE,
        ));
        $conf = array(
          'layout' => variable_get('fblikebutton_layout', 'standard'),
          'action' => variable_get('fblikebutton_action', 'like'),
          'color_scheme' => variable_get('fblikebutton_color_scheme', 'light'),
          'show_faces' => variable_get('fblikebutton_show_faces', TRUE),
          'font' => variable_get('fblikebutton_font', 'arial'),
          'height' => variable_get('fblikebutton_iframe_height', '80'),
          'width' => variable_get('fblikebutton_iframe_width', '450'),
          'send' => variable_get('fblikebutton_send', 'true'),
          'other_css' => variable_get('fblikebutton_iframe_css', ''),
          'language' => variable_get('fblikebutton_language', 'en_US'),
        );
        $block['content'] = _fblikebutton_field($webpage_to_like, $conf);
      }
      else {
        $block['content'] = NULL;
      }
      if ($delta == 0) {
        $addr = variable_get('fblikebutton_block_url', $base_url);
        $conf = array(
          'layout' => variable_get('fblikebutton_bl_layout', "standard"),
          'action' => variable_get('fblikebutton_bl_action', "like"),
          'color_scheme' => variable_get('fblikebutton_bl_color_scheme', "light"),
          'show_faces' => variable_get('fblikebutton_bl_show_faces', FALSE),
          'font' => variable_get('fblikebutton_bl_font', "arial"),
          'height' => variable_get('fblikebutton_bl_iframe_height', '80'),
          'width' => variable_get('fblikebutton_bl_iframe_width', '450'),
          'other_css' => variable_get('fblikebutton_bl_iframe_css', ''),
          'language' => variable_get('fblikebutton_bl_language', 'en_US'),
        );
        $block['content'] = _fblikebutton_field($addr, $conf);
      }
      return $block;
  }
}