View source
<?php
function fb_social_comments_theme() {
return array(
'fb_social_comments_block_comments_view' => array(),
);
}
function fb_social_comments_menu() {
$items = array();
$items['admin/settings/fb/social/comments'] = array(
'type' => MENU_LOCAL_TASK,
'title' => 'comments',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'fb_social_comments_settings_form',
),
'file' => 'fb_social_comments.admin.inc',
'access callback' => 'user_access',
'access arguments' => array(
'administer site configuration',
),
);
return $items;
}
function fb_social_comments_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks['comments'] = array(
'info' => t('fb comments'),
);
return $blocks;
case 'view':
switch ($delta) {
case 'comments':
$node = menu_get_object();
if (is_object($node) && $node->status && $node->nid && arg(2) != "edit") {
return array(
'subject' => t(''),
'content' => theme('fb_social_comments_block_comments_view', fb_social_url('node/' . $node->nid)),
);
}
}
break;
}
}
function fb_social_comments_content_extra_fields($type_name) {
if (fb_social_comments_type($type_name)) {
$extras['fb_social_comments_widget'] = array(
'label' => t('Facebook socials comments widget'),
'description' => t('The facebook comments pluging widget'),
'weight' => 20,
);
return $extras;
}
}
function fb_social_comments_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'view':
if ($node->status && fb_social_comments_type($node->type)) {
if ($a4) {
$output = theme('fb_social_comments_block_comments_view', fb_social_url('node/' . $node->nid));
$weight = module_exists('content') ? content_extra_field_weight($node->type, 'fb_social_comments_widget') : 20;
$node->content['fb_social_comments_widget'] = array(
'#weight' => $weight,
'#value' => $output,
);
}
}
break;
}
}
function theme_fb_social_comments_block_comments_view($url) {
global $_fb_script_init;
$_fb_script_init = TRUE;
$xid = url($_GET['q'], array(
'absolute' => TRUE,
'alias' => TRUE,
));
$attrs = array(
'xid' => urlencode($xid),
'title' => $node->title,
'numposts' => variable_get('fb_social_comments_numposts', 10),
'width' => variable_get('fb_social_comments_width', 420),
'colorscheme' => variable_get('fb_social_comments_colorscheme', 'light'),
);
$migrated = variable_get('fb_social_comments_migrated', 0);
if ($migrated) {
$attrs['migrated'] = '1';
}
else {
$attrs['href'] = $url;
}
if ($css = variable_get('fb_social_comments_css', '')) {
$attrs['css'] = $css;
}
$res = '<div id="fb-social-comments">';
$res .= '<fb:comments ' . drupal_attributes($attrs) . '>';
$res .= '</fb:comments>';
$res .= '</div>';
return $res;
}
function fb_social_comments_type($type) {
$fb_like_types = variable_get('fb_social_comments_node_types', array());
return isset($fb_like_types[$type]) && $fb_like_types[$type] ? TRUE : FALSE;
}