You are here

function easy_social_node_view in Easy Social 7

Same name and namespace in other branches
  1. 7.2 easy_social.module \easy_social_node_view()

Implements hook_node_view(). Certify to load the buttons in the moment I want

File

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

Code

function easy_social_node_view($node, $view_mode, $langcode) {

  // Check if the path is ignored
  $urls_ignored = variable_get_value('easysocial_ignore_paths');
  $page_match = FALSE;
  $path = drupal_get_path_alias($_GET['q']);

  // Compare with the internal and path alias (if any).
  $page_match = drupal_match_path($path, $urls_ignored);
  if ($path != $_GET['q']) {
    $page_match = $page_match || drupal_match_path($_GET['q'], $urls_ignored);
  }
  if (!$page_match) {

    //Check if this type has a custom setting
    if (variable_get_value('easysocial_' . $node->type . '_override') == 1) {
      $type = variable_get_value('easysocial_' . $node->type . '_typebtn');
      $buttons = variable_get_value('easysocial_' . $node->type . '_social_buttons');
    }
    else {
      $type = variable_get_value('easysocial_global_typebtn');
      $buttons = variable_get_value('easysocial_global_social_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)) {
        $data = array(
          'nid' => $node->nid,
          'title' => $node->title,
        );
        eval("_easysocial_js_add_{$service}();");
        eval("\$social_links[\$service] = _easysocial_button_{$service}_markup(\$url, \$type, \$data);");
      }
    }

    //If at least one button is selected, go on
    if (count($social_links) > 0) {
      $node->content['easy_social'] = array(
        '#theme' => 'easy_social_links',
        '#social_links' => $social_links,
        '#weight' => 999,
      );
    }
  }
}