You are here

function rrssb_get_buttons in Ridiculously Responsive Social Sharing Buttons 7.2

Same name and namespace in other branches
  1. 8.2 rrssb.module \rrssb_get_buttons()
  2. 7 rrssb.module \rrssb_get_buttons()

Returns a Drupal render array for the buttons.

Parameters

object $node: The node object you are trying to share.

Return value

string A string of markup for the list of buttons.

2 calls to rrssb_get_buttons()
rrssb_block_view in ./rrssb.module
Implements hook_block_view().
rrssb_node_view in ./rrssb.module
Implements hook_node_view().

File

./rrssb.module, line 505

Code

function rrssb_get_buttons($node = NULL) {
  if (is_null($node)) {
    $node = menu_get_object();
  }

  // Create an array for how we will map [rrssb:XXX] tokens.  The key is the XXX value and the value is an array
  // of other tokens to try in turn until one works.  For the image token, we allow the user to configure the list
  // of tokens.
  $image_tokens = explode('|', variable_get('rrssb_image_tokens', RRSSB_IMAGE_TOKENS_DEFAULT));
  $config = array(
    'url' => array(
      '[node:url]',
      '[current-page:url]',
    ),
    'title' => array(
      '[node:title]',
      '[current-page:title]',
    ),
    'image' => $image_tokens,
  );

  // Replace tokens.
  foreach ($config as $param => $tokens) {
    foreach ($tokens as $token) {
      $rrssb[$param] = token_replace($token, array(
        'node' => $node,
      ), array(
        'clear' => TRUE,
      ));
      if ($rrssb[$param]) {
        break;
      }
    }
  }

  // If the image returned a comma separated list, just take the first entry.
  list($rrssb['image']) = explode(',', $rrssb['image']);
  $items = array(
    '#theme' => 'rrssb_button_list',
  );
  foreach (rrssb_settings() as $name => $button) {
    $items[] = array(
      '#theme' => 'rrssb_button',
      '#name' => $name,
      '#button' => $button,
      '#rrssb' => $rrssb,
    );
  }

  // Add css and js.
  // Use #attached rather than adding directly else block caching is broken.
  $css = variable_get('rrssb_css_file');
  if (!$css) {
    $css = rrssb_gen_css();
  }
  $items['#attached']['libraries_load'][] = array(
    'rrssb-plus',
  );
  $items['#attached']['css'] = array(
    $css,
  );
  $items['#attached']['js'][] = array(
    'type' => 'setting',
    'data' => array(
      'rrssb' => rrssb_appearance(),
    ),
  );
  return $items;
}