View source
<?php
function fb_social_like_init() {
if (variable_get('fb_social_like_opengraph_tags', 1)) {
$object = menu_get_object();
if (is_object($object) && fb_social_like_type($object->type)) {
$data = '<meta property="og:title" content="' . check_plain($object->title) . '"/>' . "\n";
$data .= '<meta property="og:site_name" content="' . variable_get('site_name', '') . '"/>' . "\n";
drupal_set_html_head($data);
}
}
}
function fb_social_like_menu() {
$items = array();
$items['admin/settings/fb/social/like'] = array(
'type' => MENU_LOCAL_TASK,
'title' => 'like',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'fb_social_like_settings_form',
),
'file' => 'fb_social_like.admin.inc',
'access callback' => 'user_access',
'access arguments' => array(
'administer site configuration',
),
);
return $items;
}
function fb_social_like_fb_social_event_subscribe() {
if (module_exists('googleanalytics')) {
global $user;
$id = variable_get('googleanalytics_account', '');
if (!empty($id) && _googleanalytics_visibility_pages() && _googleanalytics_visibility_user($user)) {
return array(
'FB.Event.subscribe("edge.create", function(href, widget) {',
'_gaq.push(["_trackEvent", "Facebook like", "Drupal", href]);',
'});',
);
}
}
}
function fb_social_like_content_extra_fields($type_name) {
if (fb_social_like_type($type_name) && variable_get('fb_social_like_location', 0)) {
$extras['fb_social_like_widget'] = array(
'label' => t('Facebook socials like widget'),
'description' => t('The facebook like pluging widget'),
'weight' => -10,
);
return $extras;
}
}
function fb_social_like_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'view':
if ($node->status && fb_social_like_type($node->type) && variable_get('fb_social_like_location', 0)) {
if ($a4 || !$a3 || variable_get('fb_social_like_display_teasers', 1) && $a3) {
$output = theme('fb_social_like_widget', fb_social_url('node/' . $node->nid));
$weight = module_exists('content') ? content_extra_field_weight($node->type, 'fb_social_like_widget') : -10;
$node->content['fb_social_like_widget'] = array(
'#weight' => $weight,
'#value' => $output,
);
}
}
break;
}
}
function fb_social_like_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks['like'] = array(
'info' => t('fb like'),
);
return $blocks;
case 'view':
switch ($delta) {
case 'like':
$url = fb_social_url($_GET['q']);
return array(
'subject' => t(''),
'content' => theme('fb_social_like_widget', $url),
);
}
break;
}
}
function fb_social_like_theme() {
return array(
'fb_social_like_widget' => array(
'arguments' => array(
'url' => NULL,
),
),
'fb_social_like_block_like_view' => array(),
);
}
function theme_fb_social_like_widget($url) {
global $_fb_script_init;
$_fb_script_init = TRUE;
$attrs = array(
'href' => $url,
'send' => variable_get('fb_social_like_send_button', 0) ? 'true' : 'false',
'layout' => variable_get('fb_social_like_layout_style', 'button_count'),
'show_faces' => variable_get('fb_social_like_show_faces', 0) ? 'true' : 'false',
'width' => variable_get('fb_social_like_width', 350),
'action' => variable_get('fb_social_like_verb', 'like'),
'font' => variable_get('fb_social_like_font', 'verdana'),
'colorscheme' => variable_get('fb_social_like_color', 'dark'),
);
$attrs = drupal_attributes($attrs);
return '<div class="fb-social-like-widget"><fb:like ' . $attrs . '></fb:like></div>';
}
function fb_social_like_link($type, $object, $teaser = FALSE) {
if ('node' != $type) {
return;
}
if (!$object->status) {
return;
}
if ($teaser && !variable_get('fb_social_like_display_teasers', 1)) {
return;
}
if (variable_get('fb_social_like_location', 0)) {
return;
}
$links = array();
if ($type == 'node' && fb_social_like_type($object->type)) {
$links['fb_social_like'] = array(
'title' => theme('fb_social_like_widget', fb_social_url('node/' . $object->nid)),
'html' => TRUE,
);
}
return $links;
}
function fb_social_like_type($type) {
$fb_like_types = variable_get('fb_social_like_node_types', array());
return isset($fb_like_types[$type]) && $fb_like_types[$type] ? TRUE : FALSE;
}
function fb_social_like_views_api() {
return array(
'api' => '2.0',
);
}