Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/07/2012, 13:13
jeremiselxi
(Desactivado)
 
Fecha de Ingreso: septiembre-2008
Mensajes: 269
Antigüedad: 15 años, 7 meses
Puntos: 22
Respuesta: problema facebook comments

Aqui esta el codigo del .module.
Código PHP:
<?php

/**
 * Implements of hook_permission().
 */
function facebook_comments_permission() {
  return array(
    
'administer facebook comments' => array(
      
'title' => t('Administer Facebook comments'),
    ),
    
'moderate facebook comments' => array(
      
'title' => t('Enable/disable Facebook comments per node'),
    ),
  );
}

/**
 * Implements of hook_menu().
 */
function facebook_comments_menu() {
  
$items = array();
  
$items['admin/config/content/facebook-comments'] = array(
    
'title' => 'Facebook comments settings',
    
'description' => 'Configure Facebook comments settings like the Facebook App ID.',
    
'page callback' => 'drupal_get_form',
    
'page arguments' => array('facebook_comments_admin'),
    
'access arguments' => array('administer facebook comments'),
  );
  return 
$items;
}

/**
 * Implements hook_block_info().
 */
function facebook_comments_block_info() {
  
$blocks = array();
  
$blocks['facebook-comments'] = array(
    
'info' => t('Facebook comments'),
  );
  return 
$blocks;
}

/**
 * Implements hook_block_view().
 */
function facebook_comments_block_view($delta '') {
  
$block = array();
  if (
$delta == 'facebook-comments') {
    
$width variable_get('facebook_comments_block_width'208);
    
$amount variable_get('facebook_comments_block_amount'15);
    
$block = array(
      
'subject' => t('Facebook comments'),
      
'content' => facebook_comments_display($width$amount),
    );
  }
  return 
$block;
}

/**
 * Configure Facebook comments settings like the Facebook App ID.
 *
 * @see facebook_comments_admin_applyall()
 */
function facebook_comments_admin() {
  
$form = array();
  
$form['facebook_comments_appid'] = array(
    
'#type' => 'textfield',
    
'#title' => t('Facebook App ID'),
    
'#default_value' => variable_get('facebook_comments_appid'''),
    
'#description' => t('Enter the Facebook App ID to ensure that all comments can be grouped for moderation.'),
  );
  
$form['facebook_comments_style'] = array(
    
'#type' => 'select',
    
'#title' => t('Color Scheme'),
    
'#default_value' => variable_get('facebook_comments_style''light'), 
    
'#options' => array('light' => t('Light'), 'dark' => t('Dark')),
  );
  
$form['facebook_comments_viewmode'] = array(
    
'#type' => 'select',
    
'#title' => t('View mode'),
    
'#default_value' => variable_get('facebook_comments_viewmode''full'),
    
'#options' => array('both' => t('Both full node and teaser'), 'full' => t('Full node'), 'teaser' => t('Teaser')),
  );
  
$form['facebook_comments_width'] = array(
    
'#type' => 'textfield',
    
'#title' => t('Facebook comment plugin width (nodes)'),
    
'#default_value' => variable_get('facebook_comments_width'620),
    
'#description' => t('The width of the Facebook comment plugin for nodes, in pixels. Example: 620'),
  );
  
$form['facebook_comments_block_width'] = array(
    
'#type' => 'textfield',
    
'#title' => t('Facebook comment block plugin width (block)'),
    
'#default_value' => variable_get('facebook_comments_block_width'208),
    
'#description' => t('The width of the Facebook comment plugin for the block, in pixels. Example: 250'),
  );
  
$form['facebook_comments_block_amount'] = array(
    
'#type' => 'select',
    
'#title' => t('Amount of comments to display (block)'),
    
'#options' => array(=> 1=> 2=> 3=> 5=> 710 => 1015 => 1520 => 2030 => 30),
    
'#default_value' => variable_get('facebook_comments_block_amount'15),
  );

  
$defaulttypes = array();
  
$types node_type_get_types();
  foreach (
$types as $key => $type) {
    
$defaulttypes[$key] = $type->name;
  }
  
$form['facebook_comments_types'] = array(
    
'#type' => 'checkboxes',
    
'#title' => t('Facebook comment default content types'),
    
'#options' => $defaulttypes,
    
'#default_value' => variable_get('facebook_comments_types', array()),
    
'#description' => t('Check the content types that should have Facebook comments enabled by default.'),
  );
  
$form['facebook_comments_applyall'] = array(
    
'#type' => 'checkbox',
    
'#title' => t('Enable Facebook comments on existing content for the selected content types.'),
    
'#default_value' => FALSE,
  );
  
$form['#submit'][] = 'facebook_comments_admin_applyall';
  return 
system_settings_form($form);
}

/**
 * Form submission handler for facebook_comments_admin().
 *
 * @see facebook_comments_admin()
 */
function facebook_comments_admin_applyall(&$form$form_state) {
  if (
$form_state['values']['facebook_comments_applyall']) {
    
$types = array();
    foreach (
$form_state['values']['facebook_comments_types'] as $key => $value) {
      if (!empty(
$value)) $types[] = $key;
    }
    
$results db_select('node''n')
      ->
fields('n', array('nid'))
      ->
condition('type'$types'IN')
      ->
execute();
    while (
$result $results->fetchAssoc()) {
      
db_merge('facebook_comments')
        ->
key(array('nid' => $result['nid']))
        ->
fields(array('enabled' => 1))
        ->
execute();
    }
    
drupal_set_message('Facebook comments have been enabled on existing content for the selected content types.');
  }
}

/**
 * Implements hook_form_alter().
 *
 * Add the Facebook commenting options for a node.
 */
function facebook_comments_form_node_form_alter(&$form$form_state) {
  
// Check if the user has permission to enabled and disable Facebook comments for this node
  
if (!user_access('moderate facebook comments')) return;
  
// Load the default values
  
$node $form['#node'];
  
// If this is a preview then get the values from the form, not the db
  
if (isset($form_state['values']['op']) && $form_state['values']['op'] == t('Preview')) {
    
$defaults = new StdClass;
    
$defaults->enabled $form_state['values']['facebook_comments_enabled'];
    
$defaults->amount $form_state['values']['facebook_comments_amount'];
  }