You are here

function _easy_social_prepare_node_links in Easy Social 6

Load the share buttons according the node I am in

1 call to _easy_social_prepare_node_links()
easy_social_preprocess_node in ./easy_social.module
Prepare node to display easy social

File

./easy_social.module, line 292
This is the file description for Easy Social module.

Code

function _easy_social_prepare_node_links($node) {

  //Get Types where it is available
  $node_types_variable = variable_get('easysocial_global_node_types', array());

  //Cleanup array
  $node_types_variable = array_filter($node_types_variable);

  //Certify the node can display the easy social
  if ($node_types_variable[$node->type]) {

    //Check if this type has a custom setting
    if (variable_get('easysocial_' . $node->type . '_override', '') == 1) {
      $type = variable_get('easysocial_' . $node->type . '_typebtn', '');
      $buttons = variable_get('easysocial_' . $node->type . '_social_buttons', array());
      $position = variable_get('easysocial_' . $node->type . '_btn_positioning', array(
        'bottom',
      ));
      $display = variable_get('easysocial_' . $node->type . '_node_view', array(
        'teaser',
        'fullnode',
      ));
    }
    else {
      $type = variable_get('easysocial_global_typebtn', '');
      $buttons = variable_get('easysocial_global_social_buttons', array());
      $position = variable_get('easysocial_global_btn_positioning', array(
        'bottom',
      ));
      $display = variable_get('easysocial_global_node_view', array(
        'teaser',
        'fullnode',
      ));
    }
    $buttons = array_filter($buttons);

    //Url to be shared
    $url = url('node/' . $node->nid, array(
      'absolute' => TRUE,
    ));
    $social_links = array();

    //Load Js files and generate respective markups
    foreach ($buttons as $service) {
      if (is_string($service)) {
        $lang = $node->language;
        eval("_easysocial_js_add_{$service}();");
        eval("\$social_links[\$service] = _easysocial_button_{$service}_markup(\$url, \$type, \$lang);");
      }
    }
    $output = "";

    //If at least one button is selected, go on
    if (count($social_links) > 0) {
      $output .= theme('easy_social_links', $social_links);
    }
  }
  $return = array(
    'html' => $output,
  );
  if ($position) {
    $return += array(
      'position' => array_filter($position),
    );
  }
  if ($display) {
    $return += array(
      'display' => array_filter($display),
    );
  }
  return $return;
}