You are here

function sharerich_get_buttons in Sharerich 7.2

Same name and namespace in other branches
  1. 7.3 sharerich.module \sharerich_get_buttons()
  2. 7 sharerich.module \sharerich_get_buttons()

Returns markup with list of share buttons.

Parameters

array $sharerich_set: The set as returned by sharerich_set_load()

object $node: Optional. The node object if returning the set for a node.

string $machinename: Optional. The machine name of the sharerich set if returning the set for a node.

Return value

array

2 calls to sharerich_get_buttons()
sharerich_block_view in ./sharerich.module
Implements hook_block_view().
sharerich_node_view in ./sharerich.module
Implements hook_node_view().

File

./sharerich.module, line 214

Code

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;
  }
}