You are here

facebook_boxes.module in Facebook Boxes 7

Same filename and directory in other branches
  1. 8 facebook_boxes.module

File

facebook_boxes.module
View source
<?php

/**
 * Implements hook_block_info().
 */
function facebook_boxes_block_info() {
  $blocks['fb_like'] = array(
    'info' => t('Facebook Like Box'),
    'cache' => DRUPAL_CACHE_GLOBAL,
  );
  $blocks['fb_rec'] = array(
    'info' => t('Facebook Recommended Box'),
    'cache' => DRUPAL_CACHE_GLOBAL,
  );
  $blocks['fb_follow'] = array(
    'info' => t('Facebook Follow Me Box'),
    'cache' => DRUPAL_CACHE_GLOBAL,
  );
  return $blocks;
}

/**
 * Implements hook_block_configure().
 */
function facebook_boxes_block_configure($delta = '') {
  global $base_root;
  $form = array();
  if ($delta == 'fb_like') {
    $form['fb_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Facebook Page URL'),
      '#description' => t('The full URL of your Facebook page, e.g. http://www.facebook.com/platform'),
      '#default_value' => variable_get('fb_like_url', 'http://www.facebook.com/platform'),
    );
    $form['fb_width'] = array(
      '#type' => 'textfield',
      '#size' => 6,
      '#maxlength' => 4,
      '#title' => t('Width'),
      '#description' => t('Width, in pixels, of the Facebook box iframe.'),
      '#default_value' => variable_get('fb_like_width', 292),
    );
    $form['fb_height'] = array(
      '#type' => 'textfield',
      '#size' => 6,
      '#maxlength' => 5,
      '#title' => t('Height'),
      '#description' => t('Height, in pixels, of the Facebook box iframe.'),
      '#default_value' => variable_get('fb_like_height', 300),
    );
    $form['fb_colorscheme'] = array(
      '#type' => 'select',
      '#options' => array(
        'light' => t('Light'),
        'dark' => t('Dark'),
      ),
      '#title' => t('Color scheme'),
      '#description' => t('The color scheme used by the plugin.'),
      '#default_value' => variable_get('fb_like_colorscheme', 'light'),
    );
    $form['fb_border'] = array(
      '#type' => 'textfield',
      '#size' => 10,
      '#maxlength' => 7,
      '#title' => t("Border color"),
      '#description' => t('Color of 1px border around iframe, including leading "#" such as #ff0000.'),
      '#default_value' => variable_get('fb_like_border', ''),
    );
    $form['fb_toggles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Configuration'),
      '#options' => array(
        'fb_faces' => 'Show Faces',
        'fb_stream' => 'Show Stream',
        'fb_header' => 'Show FB Header',
      ),
      '#default_value' => variable_get('fb_like_toggles', array(
        'fb_faces',
        'fb_header',
      )),
    );
  }
  elseif ($delta == 'fb_rec') {

    /**
     * recommendations box documentation is at https://developers.facebook.com/docs/reference/plugins/recommendations/
     * It includes options that aren't included here, such as app id, actions, and font
     */
    global $base_path;
    $form['fb_domain'] = array(
      '#type' => 'textfield',
      '#title' => t('Site Domain'),
      '#description' => t('The domain to track activity on, e.g. ' . parse_url($base_root, PHP_URL_HOST)),
      '#default_value' => variable_get('fb_rec_domain', parse_url($base_root, PHP_URL_HOST)),
    );
    $form['fb_width'] = array(
      '#type' => 'textfield',
      '#size' => 6,
      '#maxlength' => 4,
      '#title' => t('Width'),
      '#description' => t('Width, in pixels, of the Facebook box iframe.'),
      '#default_value' => variable_get('fb_rec_width', 292),
    );
    $form['fb_height'] = array(
      '#type' => 'textfield',
      '#size' => 6,
      '#maxlength' => 5,
      '#title' => t('Height'),
      '#description' => t('Height, in pixels, of the Facebook box iframe.'),
      '#default_value' => variable_get('fb_rec_height', 300),
    );
    $form['fb_colorscheme'] = array(
      '#type' => 'select',
      '#options' => array(
        'light' => t('Light'),
        'dark' => t('Dark'),
      ),
      '#title' => t('Color scheme'),
      '#description' => t('The color scheme used by the plugin.'),
      '#default_value' => variable_get('fb_rec_colorscheme', 'light'),
    );
    $form['fb_border'] = array(
      '#type' => 'textfield',
      '#size' => 10,
      '#maxlength' => 7,
      '#title' => t("Border color"),
      '#description' => t('Color of 1px border around iframe, including leading "#" such as #ff0000.'),
      '#default_value' => variable_get('fb_rec_border', ''),
    );
    $form['fb_toggles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Configuration'),
      '#options' => array(
        'fb_blank' => 'Open links in new window/tab',
        'fb_header' => 'Show Facebook Header',
      ),
      '#default_value' => variable_get('fb_like_toggles', array(
        'fb_blank',
        'fb_header',
      )),
    );
  }
  elseif ($delta == 'fb_follow') {
    $form['fb_follow_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Facebook Page URL'),
      '#description' => t('The full URL of your Facebook page, e.g. http://www.facebook.com/newsignature'),
      '#default_value' => variable_get('fb_follow_url', 'http://www.facebook.com/newsignature'),
    );
    $form['fb_follow_layout'] = array(
      '#type' => 'select',
      '#title' => t('Layout'),
      '#options' => array(
        'standard' => 'standard',
        'button_count' => 'button_count',
        'box_count' => 'box_count',
      ),
      '#default_value' => variable_get('fb_follow_layout', 'standard'),
    );
    $form['fb_follow_showface'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show faces'),
      '#description' => t('Specifies whether to display profile photos below the button (standard layout only)'),
      '#return_value' => 1,
      '#default_value' => variable_get('fb_follow_showface', 1),
    );
    $form['fb_follow_colorscheme'] = array(
      '#type' => 'select',
      '#title' => t('Color Scheme'),
      '#options' => array(
        'light' => 'light',
        'dark' => 'dark',
      ),
      '#default_value' => variable_get('fb_follow_colorscheme', 'light'),
    );
    $form['fb_follow_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('fb_follow_font', 'arial'),
    );
    $form['fb_follow_width'] = array(
      '#type' => 'textfield',
      '#size' => 10,
      '#maxlength' => 7,
      '#title' => t('Width'),
      '#description' => t('Width of the plugin'),
      '#default_value' => variable_get('fb_follow_width', '450'),
    );
  }
  return $form;
}

/**
 * Implements hook_block_save()
 */
function facebook_boxes_block_save($delta = '', $edit = array()) {
  if ($delta == 'fb_like') {
    variable_set('fb_like_url', $edit['fb_url']);
    variable_set('fb_like_width', $edit['fb_width']);
    variable_set('fb_like_height', $edit['fb_height']);
    variable_set('fb_like_colorscheme', $edit['fb_colorscheme']);
    variable_set('fb_like_border', $edit['fb_border']);
    $toggles = array();
    foreach ($edit['fb_toggles'] as $key => $val) {
      if ($val) {
        $toggles[] = $key;
      }
    }
    variable_set('fb_like_toggles', $toggles);
  }
  elseif ($delta == 'fb_rec') {
    variable_set('fb_rec_domain', $edit['fb_domain']);
    variable_set('fb_rec_width', $edit['fb_width']);
    variable_set('fb_rec_height', $edit['fb_height']);
    variable_set('fb_rec_colorscheme', $edit['fb_colorscheme']);
    variable_set('fb_rec_border', $edit['fb_border']);
    $toggles = array();
    foreach ($edit['fb_toggles'] as $key => $val) {
      if ($val) {
        $toggles[] = $key;
      }
    }
    variable_set('fb_rec_toggles', $toggles);
  }
  elseif ($delta == 'fb_follow') {
    variable_set('fb_follow_url', $edit['fb_follow_url']);
    variable_set('fb_follow_layout', $edit['fb_follow_layout']);
    variable_set('fb_follow_showface', $edit['fb_follow_showface']);
    variable_set('fb_follow_colorscheme', $edit['fb_follow_colorscheme']);
    variable_set('fb_follow_font', $edit['fb_follow_font']);
    variable_set('fb_follow_width', $edit['fb_follow_width']);
  }
}

/**
 * Implements hook_block_view().
 */
function facebook_boxes_block_view($delta = '') {
  $block = array();
  global $base_root;
  if ($delta == 'fb_like') {
    $url = urlencode(variable_get('fb_like_url', 'http://www.facebook.com/platform'));
    $width = variable_get('fb_like_width', 292);
    $height = variable_get('fb_like_height', 300);
    $colorscheme = urlencode(variable_get('fb_like_colorscheme', 'light'));
    $border = urlencode(variable_get('fb_like_border', ''));
    $opts = variable_get('fb_like_toggles', array(
      'fb_faces',
      'fb_header',
    ));
    $block['subject'] = "On Facebook";
    $block['content'] = array(
      '#markup' => sprintf('<iframe src="//www.facebook.com/plugins/likebox.php?href=%s&amp;width=%u&amp;height=%u&amp;colorscheme=%s&amp;show_faces=%s&amp;border_color=%s&amp;stream=%s&amp;header=%s" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:%spx; height:%spx;" allowTransparency="true"></iframe>', $url, $width, $height, $colorscheme, in_array('fb_faces', $opts) ? 'true' : 'false', $border, in_array('fb_stream', $opts) ? 'true' : 'false', in_array('fb_header', $opts) ? 'true' : 'false', $width, $height),
    );
  }
  elseif ($delta == 'fb_rec') {
    $opts = variable_get('fb_rec_toggles', array(
      'fb_blank',
      'fb_header',
    ));
    $block['subject'] = "Facebook Recommendations";
    $block['content'] = array(
      '#markup' => sprintf('<iframe src="//www.facebook.com/plugins/recommendations.php?site=%s&amp;action&amp;width=%u&amp;height=%u&amp;colorscheme=%s&amp;&amp;border_color=%s&amp;header=%s&amp;font&amp;linktarget=%s" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:%upx; height:%upx;" allowTransparency="true"></iframe>', urlencode(variable_get('fb_rec_domain', parse_url($base_root, PHP_URL_HOST))), variable_get('fb_rec_width', 292), variable_get('fb_rec_height', 300), urlencode(variable_get('fb_rec_colorscheme', 'light')), urlencode(variable_get('fb_rec_border', '')), in_array('fb_header', $opts) ? 'true' : 'false', in_array('fb_target', $opts) ? '_blank' : '_top', variable_get('fb_rec_width', 292), variable_get('fb_rec_height', 300)),
    );
  }
  elseif ($delta == 'fb_follow') {
    $block['subject'] = 'Follow';
    $out = array();
    $url = variable_get('fb_follow_url', 'http://www.facebook.com/newsignature');
    $out[] = '<iframe src="http://www.facebook.com/plugins/follow.php?href=' . $url;
    $layout = variable_get('fb_follow_layout', 'standard');
    $out[] = '&amp;layout=' . $layout;
    if ($layout == 'standard') {
      $showfaces = variable_get('fb_follow_showface', 'TRUE');
      if (!$showfaces) {
        $showfaces = 'FALSE';
      }
      $out[] = '&amp;show_faces=' . $showfaces;
    }
    $out[] = '&amp;colorscheme=' . variable_get('fb_follow_colorscheme', 'light');
    $out[] = '&amp;font=' . variable_get('fb_follow_font', 'arial');
    $width = preg_replace('/[^\\d\\s]/', '', variable_get('fb_follow_width', '450'));
    $out[] = '&amp;width=' . $width;
    $out[] = '&amp;height=80" scrolling="no" frameborder="0" ';
    $out[] = 'style="border:none; overflow:hidden; width:' . $width;
    $out[] = ';height:80px; "allowTransparency="true"></iframe>';
    $block['content'] = array(
      '#markup' => implode('', $out),
    );
  }
  return $block;
}