View source
<?php
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;
}
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') {
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;
}
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']);
}
}
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&width=%u&height=%u&colorscheme=%s&show_faces=%s&border_color=%s&stream=%s&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&action&width=%u&height=%u&colorscheme=%s&&border_color=%s&header=%s&font&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[] = '&layout=' . $layout;
if ($layout == 'standard') {
$showfaces = variable_get('fb_follow_showface', 'TRUE');
if (!$showfaces) {
$showfaces = 'FALSE';
}
$out[] = '&show_faces=' . $showfaces;
}
$out[] = '&colorscheme=' . variable_get('fb_follow_colorscheme', 'light');
$out[] = '&font=' . variable_get('fb_follow_font', 'arial');
$width = preg_replace('/[^\\d\\s]/', '', variable_get('fb_follow_width', '450'));
$out[] = '&width=' . $width;
$out[] = '&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;
}