You are here

function fb_likebox_block in Facebook Page Plugin 6

Same name and namespace in other branches
  1. 6.2 fb_likebox.module \fb_likebox_block()

Implements hook_block().

File

./fb_likebox.module, line 11
Simple module that provides a configurable block with Facebook Likebox's plugin.

Code

function fb_likebox_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0]['info'] = t('@site_name on Facebook', array(
        '@site_name' => variable_get('site_name', 'Default site name'),
      ));
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      return $blocks;
    case 'view':
      switch ($delta) {
        case 0:

          // Get the values given in the admin form.
          $fb_url = variable_get('fb_likebox_url', 'https://www.facebook.com/FacebookDevelopers');
          $fb_colorscheme = variable_get('fb_likebox_colorscheme', 'light');
          $fb_header = variable_get('fb_likebox_header', 'true');
          $fb_stream = variable_get('fb_likebox_stream', 'true');
          $fb_show_faces = variable_get('fb_likebox_show_faces', 'true');
          $fb_scrolling = variable_get('fb_likebox_scrolling', 'no');
          $fb_width = variable_get('fb_likebox_width', '292');
          $fb_width_units = variable_get('fb_likebox_width_units', 'px');
          $fb_height = variable_get('fb_likebox_height', '556');
          $fb_show_border = variable_get('fb_likebox_show_border', 'true');
          $fb_force_wall = variable_get('fb_likebox_force_wall', 'false');
          $fb_iframe_title = variable_get('fb_likebox_iframe_title', 'Like us on Facebook');

          // Set the subject of the block
          $block['subject'] = t('@site_name on Facebook', array(
            '@site_name' => variable_get('site_name', 'Default site name'),
          ));

          // Call to the theming function.
          $block['content'] = theme('fb_likebox_facebook', $fb_url, $fb_colorscheme, $fb_header, $fb_stream, $fb_show_faces, $fb_scrolling, $fb_width, $fb_width_units, $fb_height, $fb_show_border, $fb_force_wall, $fb_iframe_title);
          return $block;
      }
      break;
    case 'configure':
      switch ($delta) {
        case 0:

          // Facebook Widget settings.
          $form['fb_likebox_display_settings'] = array(
            '#type' => 'fieldset',
            '#title' => t('Display options'),
            '#collapsible' => FALSE,
          );
          $form['fb_likebox_theming_settings'] = array(
            '#type' => 'fieldset',
            '#title' => t('Theming Settings'),
            '#collapsible' => FALSE,
          );

          // Display settings.
          $form['fb_likebox_display_settings']['fb_likebox_url'] = array(
            '#type' => 'textfield',
            '#title' => t('Facebook Page URL'),
            '#default_value' => variable_get('fb_likebox_url', 'https://www.facebook.com/FacebookDevelopers'),
            '#description' => t('Enter the Facebook Page URL. I.e.: https://www.facebook.com/FacebookDevelopers'),
            '#required' => TRUE,
          );
          $form['fb_likebox_display_settings']['fb_likebox_colorscheme'] = array(
            '#type' => 'select',
            '#title' => t('Color Scheme'),
            '#default_value' => variable_get('fb_likebox_colorscheme', 'light'),
            '#options' => array(
              'light' => t('Light'),
              'dark' => t('Dark'),
            ),
            '#description' => t("The color scheme for the plugin. Options: 'light', 'dark'."),
            '#required' => TRUE,
          );
          $form['fb_likebox_display_settings']['fb_likebox_header'] = array(
            '#type' => 'select',
            '#title' => t('Header'),
            '#default_value' => variable_get('fb_likebox_header', 'true'),
            '#options' => array(
              'false' => t('No'),
              'true' => t('Yes'),
            ),
            '#description' => t('Specifies whether to display the Facebook header at the top of the plugin.'),
            '#required' => TRUE,
          );
          $form['fb_likebox_display_settings']['fb_likebox_stream'] = array(
            '#type' => 'select',
            '#title' => t('Stream'),
            '#default_value' => variable_get('fb_likebox_stream', 'true'),
            '#options' => array(
              'false' => t('No'),
              'true' => t('Yes'),
            ),
            '#description' => t("Specifies whether to display a stream of the latest posts from the Page's wall."),
            '#required' => TRUE,
          );
          $form['fb_likebox_display_settings']['fb_likebox_show_faces'] = array(
            '#type' => 'select',
            '#title' => t('Show Faces'),
            '#default_value' => variable_get('fb_likebox_show_faces', 'true'),
            '#options' => array(
              'false' => t('No'),
              'true' => t('Yes'),
            ),
            '#description' => t('Specifies whether or not to display profile photos in the plugin.'),
            '#required' => TRUE,
          );
          $form['fb_likebox_display_settings']['fb_likebox_scrolling'] = array(
            '#type' => 'select',
            '#title' => t('Scrolling'),
            '#default_value' => variable_get('fb_likebox_scrolling', 'no'),
            '#options' => array(
              'no' => t('Disabled'),
              'yes' => t('Enabled'),
            ),
            '#description' => t('Enables vertical scrolling'),
            '#required' => TRUE,
          );
          $form['fb_likebox_display_settings']['fb_likebox_force_wall'] = array(
            '#type' => 'select',
            '#title' => t('Force wall'),
            '#default_value' => variable_get('fb_likebox_force_wall', 'false'),
            '#options' => array(
              'false' => t('No'),
              'true' => t('Yes'),
            ),
            '#description' => t('For Places: specifies whether the stream contains posts from the Places wall or just checkins from friends.'),
            '#required' => TRUE,
          );
          $form['fb_likebox_display_settings']['fb_likebox_iframe_title'] = array(
            '#type' => 'textfield',
            '#title' => t('iFrame title attribute'),
            '#default_value' => variable_get('fb_likebox_iframe_title', 'Like us on Facebook'),
            '#description' => t('The value of the iFrame title attribute.'),
            '#required' => TRUE,
          );

          // Theming settings.
          $form['fb_likebox_theming_settings']['fb_likebox_width'] = array(
            '#type' => 'textfield',
            '#title' => t('Width'),
            '#default_value' => variable_get('fb_likebox_width', '292'),
            '#description' => t('The width of the Facebook likebox in pixels.'),
            '#required' => TRUE,
          );
          $form['fb_likebox_theming_settings']['fb_likebox_width_units'] = array(
            '#type' => 'select',
            '#title' => t('Units'),
            '#options' => array(
              'px' => t('px'),
              '%' => t('%'),
            ),
            '#default_value' => variable_get('fb_likebox_width_units', 'px'),
            '#description' => t('The unit for the width of the Facebook likebox, either pixels or percentage.'),
            '#required' => TRUE,
          );
          $form['fb_likebox_theming_settings']['fb_likebox_height'] = array(
            '#type' => 'textfield',
            '#title' => t('Height'),
            '#default_value' => variable_get('fb_likebox_height', '556'),
            '#description' => t('The height of the plugin in pixels. The default height provided by Facebook API varies based on number of faces to display, and whether the stream is displayed. With the stream displayed, and 10 faces the default height is 556px. With no faces, and no stream the default height is 63px. You will need to play with these value if you haved disabled those features and you want the block to be displayed without an empty section.'),
            '#required' => TRUE,
          );
          $form['fb_likebox_theming_settings']['fb_likebox_show_border'] = array(
            '#type' => 'select',
            '#title' => t('Border'),
            '#default_value' => variable_get('fb_likebox_show_border', 'true'),
            '#options' => array(
              'false' => t('No'),
              'true' => t('Yes'),
            ),
            '#description' => t('SpSpecifies whether or not to show a border around the plugin. Set to false to style the iframe with your custom CSS.'),
            '#required' => TRUE,
          );
          return $form;
      }
      break;
    case 'save':
      switch ($delta) {
        case 0:

          // Set the values given in the block form
          variable_set('fb_likebox_url', check_url($edit['fb_likebox_url']));
          variable_set('fb_likebox_colorscheme', check_plain($edit['fb_likebox_colorscheme']));
          variable_set('fb_likebox_header', check_plain($edit['fb_likebox_header']));
          variable_set('fb_likebox_stream', check_plain($edit['fb_likebox_stream']));
          variable_set('fb_likebox_show_faces', check_plain($edit['fb_likebox_show_faces']));
          variable_set('fb_likebox_scrolling', check_plain($edit['fb_likebox_scrolling']));
          variable_set('fb_likebox_width', check_plain($edit['fb_likebox_width']));
          variable_set('fb_likebox_width_units', check_plain($edit['fb_likebox_width_units']));
          variable_set('fb_likebox_height', check_plain($edit['fb_likebox_height']));
          variable_set('fb_likebox_show_border', check_plain($edit['fb_likebox_show_border']));
          variable_set('fb_likebox_force_wall', check_plain($edit['fb_likebox_force_wall']));
          variable_set('fb_likebox_iframe_title', check_plain($edit['fb_likebox_iframe_title']));
      }
      break;
  }
}