fb_likebox.module in Facebook Page Plugin 6.2
Same filename and directory in other branches
Simple module that provides a configurable block with Facebook Likebox's plugin.
File
fb_likebox.moduleView source
<?php
/**
* @file
* Simple module that provides a configurable block with Facebook Likebox's plugin.
*/
/**
* Implements hook_block().
*/
function fb_likebox_block($op = 'list', $delta = 0, $edit = array()) {
drupal_add_js(drupal_get_path('module', 'fb_likebox') . '/fb_likebox.js');
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:
$fb_likebox_url = variable_get('fb_likebox_url', 'https://www.facebook.com/FacebookDevelopers');
$fb_likebox_hide_header = variable_get('fb_likebox_hide_header', '0');
$fb_likebox_stream = variable_get('fb_likebox_stream', '0');
$fb_likebox_show_faces = variable_get('fb_likebox_show_faces', '1');
$fb_likebox_title = variable_get('fb_likebox_title', 'Like us on Facebook');
$fb_likebox_width = variable_get('fb_likebox_width', '340');
$fb_likebox_height = variable_get('fb_likebox_height', '500');
$block['subject'] = t('@site_name on Facebook', array(
'@site_name' => variable_get('site_name', 'Default site name'),
));
$block['content'] = theme('fb_likebox_facebook', $fb_likebox_url, $fb_likebox_hide_header, $fb_likebox_stream, $fb_likebox_show_faces, $fb_likebox_width, $fb_likebox_height, $fb_likebox_title);
return $block;
}
break;
case 'configure':
switch ($delta) {
case 0:
$form['fb_likebox_display_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Display options'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$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_hide_header'] = array(
'#type' => 'checkbox',
'#title' => t('Hide cover photo in the header'),
'#default_value' => variable_get('fb_likebox_hide_header', '0'),
);
$form['fb_likebox_display_settings']['fb_likebox_stream'] = array(
'#type' => 'checkbox',
'#title' => t('Show posts from the Page\'s timeline'),
'#default_value' => variable_get('fb_likebox_stream', '0'),
);
$form['fb_likebox_display_settings']['fb_likebox_show_faces'] = array(
'#type' => 'checkbox',
'#title' => t('Show profile photos when friends like this'),
'#default_value' => variable_get('fb_likebox_show_faces', '1'),
);
$form['fb_likebox_display_settings']['fb_likebox_title'] = array(
'#type' => 'textfield',
'#title' => t('iFrame title attribute'),
'#default_value' => variable_get('fb_likebox_title', 'Like us on Facebook'),
'#description' => t('The value of the title attribute.'),
'#required' => TRUE,
);
$form['fb_likebox_display_settings']['fb_likebox_width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => variable_get('fb_likebox_width', '340'),
'#description' => t('The width of the Facebook likebox. Must be a number between 280 and 500, limits included.'),
'#required' => TRUE,
);
$form['fb_likebox_display_settings']['fb_likebox_height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => variable_get('fb_likebox_height', '500'),
'#description' => t('The height of the plugin in pixels. Must be a number bigger than 130.'),
'#required' => TRUE,
);
return $form;
}
break;
case 'save':
switch ($delta) {
case 0:
variable_set('fb_likebox_url', check_url($edit['fb_likebox_url']));
variable_set('fb_likebox_hide_header', check_plain($edit['fb_likebox_hide_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_width', check_plain($edit['fb_likebox_width']));
variable_set('fb_likebox_height', check_plain($edit['fb_likebox_height']));
variable_set('fb_likebox_title', check_plain($edit['fb_likebox_title']));
}
break;
}
}
/**
* Implements hook_theme().
*/
function fb_likebox_theme($existing, $type, $theme, $path) {
return array(
'fb_likebox_facebook' => array(
'arguments' => array(
'fb_likebox_url' => variable_get('fb_likebox_url', 'https://www.facebook.com/FacebookDevelopers'),
'fb_likebox_hide_header' => variable_get('fb_likebox_hide_header', '0'),
'fb_likebox_stream' => variable_get('fb_likebox_stream', '0'),
'fb_likebox_show_faces' => variable_get('fb_likebox_show_faces', '1'),
'fb_likebox_width' => variable_get('fb_likebox_width', '340'),
'fb_likebox_height' => variable_get('fb_likebox_height', '500'),
'fb_likebox_title' => variable_get('fb_likebox_title', 'Like us on Facebook'),
),
'path' => $path . '/templates',
'template' => 'fb_likebox',
),
);
}
/**
* Perform the validation of the block settings.
*/
function _fb_likebox_validate_block_settings(&$form, $form_state) {
// Facebook display settings validation.
$fb_url = $form_state['values']['fb_likebox_url'];
if (!valid_url($fb_url, TRUE)) {
form_set_error('fb_likebox_url', t('Please enter a valid url.'));
}
// Facebook theming settings validation.
$fb_width = $form_state['values']['fb_likebox_width'];
if (!is_numeric($fb_width) || intval($fb_width) < 280 || intval($fb_width) > 500) {
form_set_error('fb_likebox_width', t('Width should be a number between 280 and 500, limits included.'));
}
$fb_height = $form_state['values']['fb_likebox_height'];
if (!is_numeric($fb_height) || intval($fb_height) < 130) {
form_set_error('fb_likebox_height', t('Height should be a number bigger than 130.'));
}
}
Functions
Name | Description |
---|---|
fb_likebox_block | Implements hook_block(). |
fb_likebox_theme | Implements hook_theme(). |
_fb_likebox_validate_block_settings | Perform the validation of the block settings. |