You are here

fb_social_send.module in Facebook social plugins integration 6

File

modules/fb_social_send/fb_social_send.module
View source
<?php

/**
 * Implementation of hook_menu
 */
function fb_social_send_menu() {
  $items = array();
  $items['admin/settings/fb/social/send'] = array(
    'type' => MENU_LOCAL_TASK,
    'title' => 'send',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'fb_social_send_settings_form',
    ),
    'file' => 'fb_social_send.admin.inc',
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer site configuration',
    ),
  );
  return $items;
}

/**
 * Implementation of hook_content_extra_fields.
 */
function fb_social_send_content_extra_fields($type_name) {
  if (fb_social_send_type($type_name) && variable_get('fb_social_send_location', 0)) {
    $extras['fb_social_send_widget'] = array(
      'label' => t('Facebook socials send widget'),
      'description' => t('The facebook send pluging widget'),
      'weight' => -10,
    );
    return $extras;
  }
}

/**
 * Implementation of hook_nodeapi().
 */
function fb_social_send_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'view':
      if ($node->status && fb_social_send_type($node->type) && variable_get('fb_social_send_location', 0)) {
        if ($a4 || !$a3 || variable_get('fb_social_send_display_teasers', 1) && $a3) {
          $output = theme('fb_social_send_widget', fb_social_url('node/' . $node->nid));
          $weight = module_exists('content') ? content_extra_field_weight($node->type, 'fb_social_send_widget') : -10;
          $node->content['fb_social_send_widget'] = array(
            '#weight' => $weight,
            '#value' => $output,
          );
        }
      }
      break;
  }
}

/**
 * Implementation of hook_block
 */
function fb_social_send_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks['send'] = array(
        'info' => t('fb social: send'),
      );
      return $blocks;
    case 'view':
      switch ($delta) {
        case 'send':
          $url = fb_social_url($_GET['q']);
          return array(
            'subject' => t(''),
            'content' => theme('fb_social_send_widget', $url),
          );
      }
      break;
  }
}

/**
 * Implementation of hook_theme
 */
function fb_social_send_theme() {
  return array(
    'fb_social_send_widget' => array(
      'arguments' => array(
        'url' => NULL,
      ),
    ),
    'fb_social_send_block_send_view' => array(),
  );
}

/**
 * returns the fbml content of the widget
 */
function theme_fb_social_send_widget($url) {
  global $_fb_script_init;
  $_fb_script_init = TRUE;
  $attrs = array(
    'href' => $url,
    'font' => variable_get('fb_social_send_font', ""),
    'colorscheme' => variable_get('fb_social_send_colorscheme', 'light'),
  );
  $attrs = drupal_attributes($attrs);
  return '<div class="fb-social-send-widget"><fb:send ' . $attrs . '></fb:send></div>';
}

/**
 * Implementation of hook_link
 */
function fb_social_send_link($type, $object, $teaser = FALSE) {

  //only nodes are supported
  if ('node' != $type) {
    return;
  }

  // dont send unpublished nodes
  if (!$object->status) {
    return;
  }

  // if no widget on teasers return
  if ($teaser && !variable_get('fb_social_send_display_teasers', 1)) {
    return;
  }

  // widget is not to be displayed in the node links. return
  if (variable_get('fb_social_send_location', 0)) {
    return;
  }

  // good to go
  $links = array();
  if ($type == 'node' && fb_social_send_type($object->type)) {
    $links['fb_social_send'] = array(
      'title' => theme('fb_social_send_widget', fb_social_url('node/' . $object->nid)),
      'html' => TRUE,
    );
  }
  return $links;
}

/**
 * helper function for testing wether $type 
 * is selected to be a fb_social_send type
 */
function fb_social_send_type($type) {
  $fb_send_types = variable_get('fb_social_send_node_types', array());
  return isset($fb_send_types[$type]) && $fb_send_types[$type] ? TRUE : FALSE;
}

/**
 * Implementation of hook_views_api().
 */
function fb_social_send_views_api() {
  return array(
    'api' => '2.0',
  );
}

Functions

Namesort descending Description
fb_social_send_block Implementation of hook_block
fb_social_send_content_extra_fields Implementation of hook_content_extra_fields.
fb_social_send_link Implementation of hook_link
fb_social_send_menu Implementation of hook_menu
fb_social_send_nodeapi Implementation of hook_nodeapi().
fb_social_send_theme Implementation of hook_theme
fb_social_send_type helper function for testing wether $type is selected to be a fb_social_send type
fb_social_send_views_api Implementation of hook_views_api().
theme_fb_social_send_widget returns the fbml content of the widget