You are here

sharerich.module in Sharerich 7.3

Same filename and directory in other branches
  1. 8 sharerich.module
  2. 7 sharerich.module
  3. 7.2 sharerich.module

File

sharerich.module
View source
<?php

/**
 * @file
 * Module file for Sharerich.
 */
require_once 'includes/sharerich.tokens.inc';

/**
 * Implementation of hook_ctools_plugin_api().
 *
 * Tell CTools that we support the default_mymodule_presets API.
 */
function sharerich_ctools_plugin_api($owner, $api) {
  if ($owner == 'sharerich' && $api == 'default_sharerich_sets') {
    return array(
      'version' => 1,
    );
  }
}

/**
 * Implements hook_ctools_plugin_directory().
 *
 * Telling CTools that we want to define an 'export_ui' plugin.
 */
function sharerich_ctools_plugin_directory($module, $type) {

  // Load the export_ui plugin.
  if ($type == 'export_ui') {
    return 'plugins/export_ui';
  }
}

/**
 * Implements hook_libraries_info().
 */
function sharerich_libraries_info() {
  return array(
    'rrssb' => array(
      'title' => 'Ridiculously Responsive Social Share Buttons',
      'vendor url' => 'http://kurtnoble.com/labs/rrssb/',
      'download url' => 'https://github.com/kni-labs/rrssb',
      'version arguments' => array(
        'file' => 'bower.json',
        'pattern' => '/version"\\s*:\\s*"([0-9\\.]+)",$/',
      ),
      'callbacks' => array(
        'pre-load' => array(
          'sharerich_libraries_preload',
        ),
      ),
      'files' => array(
        'js' => array(
          'js/rrssb.js',
        ),
        'css' => array(
          'css/rrssb.css',
        ),
      ),
      'variants' => array(
        'minified' => array(
          'files' => array(
            'css' => array(
              'css/rrssb.css',
            ),
            'js' => array(
              'js/rrssb.min.js',
            ),
          ),
        ),
        'source' => array(
          'files' => array(
            'css' => array(
              'css/normalize.min.css',
            ),
            'js' => array(
              'js/rrssb.js',
            ),
          ),
        ),
      ),
    ),
  );
}

/**
 * Use a callback function to move any JavaScript to the footer.
 */
function sharerich_libraries_preload(&$library) {
  foreach ($library['files']['js'] as $file => $options) {
    $library['files']['js'][$file]['scope'] = 'footer';
  }
}

/**
 * Implements hook_menu().
 */
function sharerich_menu() {
  $items['admin/structure/sharerich/settings'] = array(
    'title' => 'Global Sharerich Settings',
    'type' => MENU_LOCAL_TASK,
    'description' => "Configure your sitewide Sharerich settings.",
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'sharerich_admin_form',
    ),
    'access arguments' => array(
      'administer sharerich',
    ),
    'file' => 'sharerich.admin.inc',
    'weight' => 5,
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function sharerich_permission() {
  return array(
    'administer sharerich' => array(
      'title' => t('Administer Sharerich'),
      'description' => t('Permission to allow user to configure Sharerich.'),
      'restrict access' => TRUE,
    ),
  );
}

/**
 * Implements hook_theme().
 */
function sharerich_theme($existing, $type, $theme, $path) {
  return array(
    'sharerich_buttons' => array(
      'render element' => 'element',
      'path' => $path . '/theme',
      'template' => 'sharerich-buttons',
    ),
    'sharerich_manage_services' => array(
      'render element' => 'form',
    ),
  );
}

/**
 * Implements hook_block_info().
 */
function sharerich_block_info() {
  $sharerich_sets = sharerich_sets_load_all();
  $blocks = array();
  $hashes = array();
  foreach ($sharerich_sets as $sharerich_set) {
    if (!$sharerich_set->block) {
      continue;
    }

    // Create a hash when the machine name is too big.
    //
    // This issue is fixed starting with drupal 7.33 release
    // https://www.drupal.org/node/466576
    // Keeping the workaround for older releases.
    if (drupal_strlen($sharerich_set->machinename) >= 32) {
      $delta = md5($sharerich_set->machinename);
      $hashes[$delta] = $sharerich_set->machinename;
    }
    else {
      $delta = $sharerich_set->machinename;
    }
    $blocks[$delta]['info'] = t('Sharerich set: @name', array(
      '@name' => $sharerich_set->machinename,
    ));
    $blocks[$delta]['cache'] = DRUPAL_CACHE_PER_PAGE;
  }

  // Only save hashes if they have changed.
  $old_hashes = variable_get('sharerich_block_hashes', array());
  if ($hashes != $old_hashes) {
    variable_set('sharerich_block_hashes', $hashes);
  }
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function sharerich_block_view($delta = '') {
  $block = array();

  // If this is 32, this should be an md5 hash.
  if (drupal_strlen($delta) == 32) {
    $hashes = variable_get('sharerich_block_hashes', array());
    if (!empty($hashes[$delta])) {
      $delta = $hashes[$delta];
    }
  }
  $sharerich_set = sharerich_set_load($delta);
  $block['content'] = sharerich_get_buttons($sharerich_set, NULL);
  return $block;
}

/**
 * Returns markup with list of share buttons.
 *
 * @param  array $sharerich_set
 *   The set as returned by sharerich_set_load()
 * @param  object $node
 *   Optional. The node object if returning the set for a node.
 * @param  string $machinename
 *   Optional. The machine name of the sharerich set if returning the set for a
 *   node.
 * @return array
 */
function sharerich_get_buttons($sharerich_set, $node = NULL, $machinename = '') {

  // Ignore set if it is disabled.
  if (isset($sharerich_set->disabled) && $sharerich_set->disabled) {
    return NULL;
  }

  // Create a unique $key in order to render all the whims.
  if (!is_null($node)) {
    $key = $node->nid . $machinename;
  }
  else {
    $key = $sharerich_set->machinename;
  }
  $buttons =& drupal_static(__FUNCTION__ . $key, array());
  if (empty($buttons) && !empty($sharerich_set->services)) {
    foreach ($sharerich_set->services as $service_name => $service) {
      if (empty($service['enabled'])) {
        continue;
      }
      $buttons[$service_name] = array(
        'data' => $service['markup'],
        'class' => array(
          $service_name,
        ),
        'weight' => $service['weight'],
      );
    }
    uasort($buttons, 'drupal_sort_weight');

    // Allow other modules to alter the buttons markup.
    drupal_alter('sharerich_buttons', $buttons, $node);

    // Tokens replacements.
    foreach ($buttons as $key => $button) {
      unset($buttons[$key]['weight']);
      $buttons[$key]['data'] = token_replace($button['data'], array(
        'node' => $node,
      ));
    }
  }
  if (count($buttons) > 0) {

    // Create an item list for the button links.
    $item_list = array(
      '#theme' => 'item_list',
      '#items' => $buttons,
      '#type' => 'ul',
      '#attributes' => array(
        'class' => array(
          'sharerich-buttons',
          'rrssb-buttons',
          'clearfix',
        ),
      ),
    );

    // Output using the sharerich_buttons theme.
    $sharerich_buttons = array(
      'buttons' => $item_list,
      '#theme' => 'sharerich_buttons',
      '#title' => !empty($sharerich_set->title) ? $sharerich_set->title : FALSE,
      '#sharerich_set' => $sharerich_set->raw,
    );
    return $sharerich_buttons;
  }
}

/**
 * Preprocess the sharerich buttons.
 */
function template_preprocess_sharerich_buttons(&$variables) {
  $element = $variables['element'];

  // Provide default template suggestions.
  $variables['theme_hook_suggestions'][] = 'sharerich_buttons__' . $element['#sharerich_set']->machinename;

  // Configure default template variables.
  $variables['title'] = $element['#title'];
  $variables['buttons'] = $element['buttons'];
  $attributes = array(
    'class' => array(
      'sharerich-wrapper',
      drupal_html_class('sharerich-' . $element['#sharerich_set']->machinename . '-wrapper'),
    ),
  );

  // Merge incoming attributes with default ones.
  $variables['attributes_array'] = array_merge_recursive($attributes, !empty($element['attributes_array']) ? $element['attributes_array'] : array());
}

/**
 * Helper to scan the services folder.
 * @return A list of file names.
 */
function sharerich_get_services() {
  $dir = drupal_get_path('module', 'sharerich') . '/services';
  $list = file_scan_directory($dir, '/.inc/', array(), 0);
  return array_map(function ($service) {
    return $service->name;
  }, $list);
}

/**
 * Helper to load services from the disk.
 */
function sharerich_load_service($service_name) {
  $dir = drupal_get_path('module', 'sharerich') . '/services';
  $service_name = $dir . '/' . $service_name . '.inc';
  if (file_exists($service_name)) {
    return file_get_contents($service_name);
  }
  return FALSE;
}

/**
 * Helper to get the service content from file or ctools object.
 */
function sharerich_get_service_content($service_name, $set_name = '') {
  $sharerich_set = sharerich_set_load($set_name);
  if (!empty($sharerich_set->services[$service_name]['markup'])) {
    return $sharerich_set->services[$service_name]['markup'];
  }

  // Load services from templates.
  return sharerich_load_service($service_name);
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function sharerich_form_node_type_form_alter(&$form, &$form_state) {
  $form['sharerich'] = array(
    '#type' => 'fieldset',
    '#title' => t('Sharerich'),
    '#collapsible' => TRUE,
    '#group' => 'additional_settings',
    '#weight' => 20,
    '#attributes' => array(
      'class' => array(
        'sharerich-node-type-settings-form',
      ),
    ),
    '#access' => user_access('administer nodes'),
  );
  $entity_type = $form['#node_type']->type;
  $sharerich_show_options = drupal_map_assoc(array(
    0,
    1,
    2,
    3,
    4,
    5,
  ));
  $sharerich_show_options[0] = t('Disabled');
  $form['sharerich']['show'] = array(
    '#type' => 'select',
    '#options' => $sharerich_show_options,
    '#title' => t('Enable Sharerich for this content type.'),
    '#description' => t('Select desired number of sharerich extra fields.'),
    '#default_value' => variable_get('sharerich_node_' . $entity_type, 0),
    '#suffix' => t('After enabling Sharerich you need to configure each' . ' display on Manage display set.<br/>Sets are located ' . '<a href="@url">here</a>.', array(
      '@url' => url('admin/structure/sharerich/list'),
    )),
  );
  $form['#submit'][] = 'sharerich_node_type_callback';
}

/**
 * Custom handler to save sharerich info.
 */
function sharerich_node_type_callback(&$form, &$form_state) {
  $entity_type = $form['#node_type']->type;
  $node_type = 'sharerich_node_' . $form_state['values']['type'];
  $enabled_node_type = variable_get($node_type, 0);
  $show = $form_state['complete form']['sharerich']['show']['#value'];

  // When Sharerich is enabled for the first time on this content type,
  // redirect to the display settings.
  if (empty($enabled_node_type) && $show == TRUE) {
    drupal_set_message(t('Please configure the field Sharerich for each Display.'));
    $form_state['redirect'] = 'admin/structure/types/manage/' . $entity_type . '/display';
  }
  variable_set($node_type, $show);

  // Clear cache.
  field_info_cache_clear();
}

/**
 * Implements hook_node_view().
 */
function sharerich_node_view($node, $view_mode, $langcode) {
  $extra = sharerich_field_extra_fields(0, $node->type);

  // Check that we're supporting the node type being viewed.
  if (empty($extra)) {
    return;
  }

  // Get current configuration for the node type.
  $config = field_bundle_settings('node', $node->type);

  // Fall back to default view mode if custom settings are disabled.
  $view_mode_compat = isset($config['view_modes'][$view_mode]) && $config['view_modes'][$view_mode]['custom_settings'] ? $view_mode : 'default';
  foreach ($extra['node'][$node->type]['display'] as $sharerich_name => $default_instance) {

    // Check if the specified button set is configured for that type.
    if (!isset($config['extra_fields']['display'][$sharerich_name][$view_mode_compat]) || isset($config['extra_fields']['display'][$sharerich_name][$view_mode_compat]) && empty($config['extra_fields']['display'][$sharerich_name][$view_mode_compat]['settings']['sharerich_sets'])) {
      continue;
    }
    $machinename = $config['extra_fields']['display'][$sharerich_name][$view_mode_compat]['settings']['sharerich_sets'];

    // Only add the set if it is visible and the button set can be loaded.
    $visible = $config['extra_fields']['display'][$sharerich_name][$view_mode_compat]['visible'];
    if ($visible && ($sharerich_set = sharerich_set_load($machinename))) {
      if ($buttons = sharerich_get_buttons($sharerich_set, $node, $machinename)) {
        $node->content[$sharerich_name] = $buttons;
        $node->content[$sharerich_name]['attributes_array'] = array(
          'class' => array(
            drupal_html_class($sharerich_name),
          ),
        );
      }
    }
  }
}

/**
 * Implements hook_field_extra_fields().
 *
 * @param bool   $get_defaults
 *    Set TRUE to return default confs.
 * @param string $type
 *    Node type to filter results to.
 * @return array
 */
function sharerich_field_extra_fields($get_defaults = 0, $type = NULL) {
  if ($get_defaults) {
    $defaults = _sharerich_extra_field_default_info($get_defaults);
    return array(
      'extra_fields' => $defaults,
    );
  }
  $extra = array();
  if ($type) {
    $count = (int) variable_get('sharerich_node_' . $type, 0);
    _sharerich_extra_field_default_info_set($extra, $type, $count);
  }
  else {
    foreach (node_type_get_types() as $node) {
      $count = (int) variable_get('sharerich_node_' . $node->type, 0);
      _sharerich_extra_field_default_info_set($extra, $node->type, $count);
    }
  }
  return $extra;
}

/**
 * Helper function to generate sharerich extra fields info.
 *
 * @param  integer $id
 *   The instance identifier to use. Defaults to 1.
 * @return array
 */
function _sharerich_extra_field_default_info($id = 1) {
  return array(
    'display' => array(
      'sharerich_' . $id => array(
        'label' => t('Sharerich #!num', array(
          '!num' => $id,
        )),
        'description' => t('This is a extra field, you can configure it on each Display.'),
        'weight' => 100,
        'visible' => FALSE,
        'settings' => array(
          'sharerich_sets' => 0,
        ),
      ),
    ),
  );
}

/**
 * Get a set of Sharerich extra fields information for a specific node type.
 *
 * @param  array $info
 *   Extra field info passed by reference.
 * @param  string $type
 *   The node type in use.
 * @param  integer $size
 *   The number of instances to generate.
 */
function _sharerich_extra_field_default_info_set(&$info, $type, $size) {
  if ($size > 0) {
    for ($i = 1; $i <= $size; $i++) {
      $info = drupal_array_merge_deep($info, array(
        'node' => array(
          $type => _sharerich_extra_field_default_info($i),
        ),
      ));
    }
  }
}

/**
 * Implements hook_page_build().
 */
function sharerich_page_build() {
  if (path_is_admin(current_path())) {
    return;
  }

  // Backwards compatibility to jQuery.live.
  $js = <<<JS
(function(\$) {
  typeof \$ && typeof \$.fn.on !== "function" && \$.fn.extend({
    on: function(event, callback, fallback) {
      switch (typeof callback) {
        case "function": return this.live(event, callback);
        case "string"  : return \$(callback).live(event, fallback);
      }
    }
  });
}(jQuery));
JS;
  drupal_add_js($js, array(
    'type' => 'inline',
    'scope' => 'header',
  ));
  if (!variable_get('sharerich_skip_js', FALSE)) {

    // Load the library via the libraries module.
    libraries_load('rrssb', variable_get('sharerich_library_variant', 'minified'));
  }
  else {
    if ($library = libraries_detect('rrssb')) {
      foreach ($library['files']['css'] as $path => $value) {
        drupal_add_css($library['library path'] . '/' . $path);
      }
    }
  }

  // Add the module css.
  drupal_add_css(drupal_get_path('module', 'sharerich') . '/css/sharerich.css');
}

/**
 * Implements hook_google_analytics_et_api().
 */
function sharerich_google_analytics_et_api() {
  $selectors = array(
    array(
      'event' => 'mousedown',
      'selector' => '.sharerich-buttons li',
      'category' => 'Share Button',
      'action' => '!text',
      'label' => '!currentPage',
      'value' => 0,
      'noninteraction' => FALSE,
    ),
  );
  return $selectors;
}

/**
 * Load function.
 *
 * @param string $machinename
 *
 * @return object
 */
function sharerich_set_load($machinename) {
  ctools_include('export');
  $sets =& drupal_static(__FUNCTION__, array());
  if (!isset($sets[$machinename])) {

    // Load the set.
    $result = ctools_export_load_object('sharerich_sets', 'names', array(
      $machinename,
    ));
    if (isset($result[$machinename])) {
      $set = $result[$machinename];
    }
    else {
      return NULL;
    }

    // Store the original set. This is used by the set edit form.
    $set->raw = clone $set;

    // Allow modules to alter the raw set object.
    drupal_alter('sharerich_set_load', $set);

    // Configure this set based on the defined settings.
    $set->wrapper_id = 'sharerich-set-' . $set->machinename . '-wrapper';
    $set->placeholder_id = 'sharerich-set-' . $set->machinename;

    // Allow modules to alter the fully-loaded set object.
    drupal_alter('sharerich_set', $set);

    // Statically cache the fully loaded set.
    $sets[$machinename] = $set;
  }
  else {

    // Use the statically cached set object.
    $set = $sets[$machinename];
  }
  return $set;
}

/**
 * Load all sharerich sets.
 *
 * @param boolean $include_disabled
 *
 * @return array of sets.
 */
function sharerich_sets_load_all($include_disabled = FALSE) {
  ctools_include('export');
  $sets = ctools_export_crud_load_all('sharerich_sets');
  foreach ($sets as $key => $set) {
    if (!$include_disabled && isset($set->disabled) && $set->disabled) {
      unset($sets[$key]);
    }
  }
  return $sets;
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Add configuration form for sharerich field extras.
 */
function sharerich_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {

  // Modified part copy from field_ui_display_overview_form() at /modules/field_ui/field_ui.admin.inc
  // Base button element for the various formatter settings actions.
  foreach (_sharerich_get_field_names($form['fields']) as $sharerich_id => $field_name) {
    $base_button = array(
      '#submit' => array(
        'field_ui_display_overview_multistep_submit',
      ),
      '#ajax' => array(
        'callback' => 'field_ui_display_overview_multistep_js',
        'wrapper' => 'field-display-overview-wrapper',
        'effect' => 'fade',
      ),
      '#field_name' => $field_name,
    );
    $summary = isset($form_state['formatter_settings'][$field_name]) ? $form_state['formatter_settings'][$field_name] : NULL;
    if ($form_state['formatter_settings_edit'] == $field_name) {
      $form['fields'][$field_name]['#region_callback'] = 'field_ui_display_overview_row_region';
      $form['fields'][$field_name]['format']['#cell_attributes'] = array(
        'colspan' => 3,
      );
      $form['fields'][$field_name]['format']['settings_edit_form'] = array(
        '#type' => 'container',
        '#attributes' => array(
          'class' => array(
            'field-formatter-settings-edit-form',
          ),
        ),
        '#parents' => array(
          'fields',
          $field_name,
          'settings_edit_form',
        ),
        'label' => array(
          '#markup' => t('Format settings:') . ' <span class="formatter-name">' . t('Sharerich #!num', array(
            '!num' => $sharerich_id,
          )) . '</span>',
        ),
        'settings' => sharerich_field_formatter_settings_form($form, $sharerich_id, $field_name, $summary),
        'actions' => array(
          '#type' => 'actions',
          'save_settings' => $base_button + array(
            '#type' => 'submit',
            '#name' => 'sharerich_' . $sharerich_id . '_formatter_settings_update',
            '#value' => t('Update'),
            '#op' => 'update',
          ),
          'cancel_settings' => $base_button + array(
            '#type' => 'submit',
            '#name' => 'sharerich_' . $sharerich_id . '_formatter_settings_cancel',
            '#value' => t('Cancel'),
            '#op' => 'cancel',
            // Do not check errors for the 'Cancel' button, but make sure we
            // get the value of the 'formatter type' select.
            '#limit_validation_errors' => array(
              array(
                'fields',
                $field_name,
                'type',
              ),
            ),
          ),
        ),
      );
      $form['fields'][$field_name]['#attributes']['class'][] = 'field-formatter-settings-editing';
    }
    elseif (variable_get('sharerich_node_' . $form['#bundle'], FALSE) && isset($form['#entity_type']) && in_array($form['#entity_type'], array(
      'node',
    ))) {
      $form['fields'][$field_name]['#region_callback'] = 'field_ui_display_overview_row_region';
      $form['fields'][$field_name]['settings_summary'] = array(
        '#markup' => '<div class="field-formatter-summary">' . sharerich_field_formatter_settings_summary($form, $sharerich_id, $field_name, $summary) . '</div>',
        '#cell_attributes' => array(
          'class' => array(
            'field-formatter-summary-cell',
          ),
        ),
      );
      $form['fields'][$field_name]['settings_edit'] = $base_button + array(
        '#type' => 'image_button',
        '#name' => 'sharerich_' . $sharerich_id . '_formatter_settings_edit',
        '#src' => 'misc/configure.png',
        '#attributes' => array(
          'class' => array(
            'field-formatter-settings-edit',
          ),
          'alt' => t('Edit'),
        ),
        '#op' => 'edit',
        // Do not check errors for the 'Edit' button, but make sure we get
        // the value of the 'formatter type' select.
        '#limit_validation_errors' => array(
          array(
            'fields',
            $field_name,
            'type',
          ),
        ),
        '#prefix' => '<div class="field-formatter-settings-edit-wrapper">',
        '#suffix' => '</div>',
      );
    }
    if (empty($form_state['formatter_settings'][$field_name])) {
      $bundle_settings = field_bundle_settings($form['#entity_type'], $form['#bundle']);
      if (isset($bundle_settings['extra_fields']['display'][$field_name][$form['#view_mode']]['settings'])) {
        $form_state['formatter_settings'][$field_name] = $bundle_settings['extra_fields']['display'][$field_name][$form['#view_mode']]['settings'];
      }
      else {
        $display_defaults = sharerich_field_extra_fields($sharerich_id);
        $form_state['formatter_settings'][$field_name] = $display_defaults['extra_fields']['display'][$field_name]['settings'];
      }
    }
  }
  $form['#submit'][] = '_sharerich_display_overview_form_submit';
}

/**
 * Pseudo hook_field_formatter_settings_form().
 */
function sharerich_field_formatter_settings_form($build, $sharerich_id, $field_name, $summary = NULL) {
  $display_stored = field_bundle_settings($build['#entity_type'], $build['#bundle']);
  if (!empty($summary)) {
    $display['settings'] = $summary;
  }
  elseif (isset($display_stored['extra_fields']['display'][$field_name][$build['#view_mode']])) {
    $display = $display_stored['extra_fields']['display'][$field_name][$build['#view_mode']];
  }
  else {
    $display_defaults = sharerich_field_extra_fields($sharerich_id);
    $display = $display_defaults['extra_fields']['display'][$field_name];
  }
  $form['sharerich_sets'] = array(
    '#type' => 'select',
    '#title' => t('Sharerich set'),
    '#default_value' => !empty($display['settings']['sharerich_sets']) ? $display['settings']['sharerich_sets'] : '',
    '#options' => _sharerich_get_sets(),
    '#description' => t('Note: Disabled sets are not listed.'),
  );
  return $form;
}

/**
 * Sharerich field_ui_display_overview_form submit handler.
 */
function _sharerich_display_overview_form_submit($form, &$form_state) {

  // Get current bundle settings.
  $bundle_settings = field_bundle_settings($form['#entity_type'], $form['#bundle']);
  foreach (_sharerich_get_field_names($form['fields']) as $field_name) {
    $bundle_settings['extra_fields']['display'][$field_name][$form['#view_mode']] = array(
      'settings' => $form_state['formatter_settings'][$field_name],
      'weight' => $form_state['values']['fields'][$field_name]['weight'],
      'visible' => $form_state['values']['fields'][$field_name]['type'] == 'visible',
    );
  }

  // Save updated bundle settings.
  field_bundle_settings($form['#entity_type'], $form['#bundle'], $bundle_settings);
}

/**
 * Helper function to get sharerich extra field instances from a display.
 * @param  array  $source Drupal FAPI
 * @return array  $names  Sharerich related fields
 */
function _sharerich_get_field_names($source = array()) {
  $names = array();
  if (is_array($source)) {
    foreach ($source as $key => $value) {
      if (preg_match('/^sharerich_(\\d+).*$/', $key, $matches)) {
        $names[$matches[1]] = $matches[0];
      }
    }
  }
  return $names;
}

/**
 * Pseudo hook_field_formatter_settings_summary().
 */
function sharerich_field_formatter_settings_summary($build, $sharerich_id, $field_name, $summary = NULL) {
  $display_stored = field_bundle_settings($build['#entity_type'], $build['#bundle']);
  if (!empty($summary)) {
    $display['settings'] = $summary;
  }
  elseif (isset($display_stored['extra_fields']['display'][$field_name][$build['#view_mode']])) {
    $display = $display_stored['extra_fields']['display'][$field_name][$build['#view_mode']];
  }
  else {
    $display_defaults = sharerich_field_extra_fields($sharerich_id);
    $display = $display_defaults['extra_fields']['display'][$field_name];
  }
  $summary = array();
  if (!empty($display['settings']['sharerich_sets'])) {
    $summary[] = t('Sharerich set') . ': ' . $display['settings']['sharerich_sets'];
  }
  else {
    $summary[] = t('No set selected.');
  }
  return implode('<br />', $summary);
}

/**
 * Helper function for grabbing Sharerich set list.
 */
function _sharerich_get_sets() {
  $sharerich_sets =& drupal_static(__FUNCTION__);
  if (!isset($sharerich_sets)) {
    $sharerich_sets = sharerich_sets_load_all();
    $sharerich_sets = !empty($sharerich_sets) ? drupal_map_assoc(array_keys($sharerich_sets)) : array(
      0 => 'None',
    );
  }
  return $sharerich_sets;
}

Functions

Namesort descending Description
sharerich_block_info Implements hook_block_info().
sharerich_block_view Implements hook_block_view().
sharerich_ctools_plugin_api Implementation of hook_ctools_plugin_api().
sharerich_ctools_plugin_directory Implements hook_ctools_plugin_directory().
sharerich_field_extra_fields Implements hook_field_extra_fields().
sharerich_field_formatter_settings_form Pseudo hook_field_formatter_settings_form().
sharerich_field_formatter_settings_summary Pseudo hook_field_formatter_settings_summary().
sharerich_form_field_ui_display_overview_form_alter Implements hook_form_FORM_ID_alter().
sharerich_form_node_type_form_alter Implements hook_form_FORM_ID_alter().
sharerich_get_buttons Returns markup with list of share buttons.
sharerich_get_services Helper to scan the services folder.
sharerich_get_service_content Helper to get the service content from file or ctools object.
sharerich_google_analytics_et_api Implements hook_google_analytics_et_api().
sharerich_libraries_info Implements hook_libraries_info().
sharerich_libraries_preload Use a callback function to move any JavaScript to the footer.
sharerich_load_service Helper to load services from the disk.
sharerich_menu Implements hook_menu().
sharerich_node_type_callback Custom handler to save sharerich info.
sharerich_node_view Implements hook_node_view().
sharerich_page_build Implements hook_page_build().
sharerich_permission Implements hook_permission().
sharerich_sets_load_all Load all sharerich sets.
sharerich_set_load Load function.
sharerich_theme Implements hook_theme().
template_preprocess_sharerich_buttons Preprocess the sharerich buttons.
_sharerich_display_overview_form_submit Sharerich field_ui_display_overview_form submit handler.
_sharerich_extra_field_default_info Helper function to generate sharerich extra fields info.
_sharerich_extra_field_default_info_set Get a set of Sharerich extra fields information for a specific node type.
_sharerich_get_field_names Helper function to get sharerich extra field instances from a display.
_sharerich_get_sets Helper function for grabbing Sharerich set list.