You are here

function fblikebutton_block in Facebook Like Button 6

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

Implementation of hook_block().

File

./fblikebutton.module, line 110
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':
      $blocks[0]['info'] = t('FB Like Button');
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      return $blocks;
    case 'configure':
      global $base_url, $language;
      $block_lang_abbr = $language->language;
      $fblikebutton_block_lang = $block_lang_abbr . '_' . drupal_strtoupper($block_lang_abbr);
      if ($delta == 0 && user_access('users may administer Like button block')) {
        $form['fblikebutton_block_url'] = array(
          '#title' => t('URL to display'),
          '#type' => 'textfield',
          '#default_value' => variable_get('fblikebutton_block_url', $base_url),
          '#description' => t('URL of the webpage to like (default is the base URL of this site: @site). This value will remain the same throughout your site.', array(
            '@site' => $base_url,
          )),
        );
        $form['fblikebutton_block'] = array(
          '#type' => 'fieldset',
          '#title' => 'Block configuration',
          '#collapsible' => false,
        );
        $form['fblikebutton_block']['fblikebutton_bl_layout'] = array(
          '#type' => 'select',
          '#title' => t('Layout style'),
          '#options' => array(
            'standard' => t('Standard'),
            'box_count' => t('Box Count'),
            'button_count' => t('Button Count'),
          ),
          '#default_value' => variable_get('fblikebutton_bl_layout', 'standard'),
          '#description' => t('Determines the size and amount of social context next to the button.'),
        );
        $form['fblikebutton_block']['fblikebutton_bl_show_faces'] = array(
          '#type' => 'select',
          '#title' => t('Display faces in the box'),
          '#options' => array(
            'showz' => t('Show faces'),
            'hide' => t('Do not show faces'),
          ),
          '#default_value' => variable_get('fblikebutton_bl_show_faces', 'true'),
          '#description' => t('Show profile pictures below the button. Only works if <em>Layout style</em> found above is set to <em>Standard</em> (otherwise, value is ignored).'),
        );
        $form['fblikebutton_block']['fblikebutton_bl_action'] = array(
          '#type' => 'select',
          '#title' => t('Verb to display'),
          '#options' => array(
            'like' => t('Like'),
            'recommend' => t('Recommend'),
          ),
          '#default_value' => variable_get('fblikebutton_bl_action', 'like'),
          '#description' => t('The verbiage to display inside the button itself.'),
        );
        $form['fblikebutton_block']['fblikebutton_bl_font'] = array(
          '#type' => 'select',
          '#title' => t('Font'),
          '#options' => array(
            'arial' => 'Arial',
            'lucida+grande' => 'Lucida Grande',
            'segoe+ui' => 'Segoe UI',
            'tahoma' => 'Tahoma',
            'trebuchet+ms' => 'Trebuchet MS',
            'verdana' => 'Verdana',
          ),
          '#default_value' => variable_get('fblikebutton_bl_font', 'arial'),
          '#description' => t('The font with which to display the text of the button.'),
        );
        $form['fblikebutton_block']['fblikebutton_bl_color_scheme'] = array(
          '#type' => 'select',
          '#title' => t('Color scheme'),
          '#options' => array(
            'light' => t('Light'),
            'dark' => t('Dark'),
          ),
          '#default_value' => variable_get('fblikebutton_bl_color_scheme', 'light'),
          '#description' => t('The color scheme of the box environtment.'),
        );
        $form['fblikebutton_block']['fblikebutton_bl_language'] = array(
          '#type' => 'textfield',
          '#title' => t('Language'),
          '#default_value' => variable_get('fblikebutton_bl_language', $fblikebutton_block_lang),
          '#description' => t('Specific language to use. Default for this site is <em>@lang</em>. Examples:<br/>French (France): <em>fr_FR</em><br/>French (Canada): <em>fr_CA</em>', array(
            '@lang' => $fblikebutton_block_lang,
          )),
        );
      }
      return $form;
    case 'save':
      if ($delta == 0) {
        variable_set('fblikebutton_bl_layout', $edit['fblikebutton_bl_layout']);
        variable_set('fblikebutton_bl_show_faces', $edit['fblikebutton_bl_show_faces']);
        variable_set('fblikebutton_bl_action', $edit['fblikebutton_bl_action']);
        variable_set('fblikebutton_bl_font', $edit['fblikebutton_bl_font']);
        variable_set('fblikebutton_bl_color_scheme', $edit['fblikebutton_bl_color_scheme']);
        variable_set('fblikebutton_bl_language', $edit['fblikebutton_bl_language']);
      }
      break;
    case 'view':
      global $base_url, $language;
      $block_lang_abbr = $language->language;
      $fblikebutton_block_lang = $block_lang_abbr . '_' . drupal_strtoupper($block_lang_abbr);
      $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"),
        'language' => variable_get('fblikebutton_bl_language', $fblikebutton_block_lang),
      );
      if (user_access('users may access Like button')) {
        $block['subject'] = t('');
        $block['content'] = _fblikebutton_field($addr, $conf);
        return $block;
      }
  }
}