You are here

public static function ShareaholicPublic::insert_content_meta_tags in Share Buttons, Related Posts, Content Analytics - Shareaholic 8

Same name and namespace in other branches
  1. 7.3 public.php \ShareaholicPublic::insert_content_meta_tags()

Inserts the shareaholic content meta tags on the page On all pages, it will insert the standard content meta tags On full post pages, it will insert page specific content meta tags

2 calls to ShareaholicPublic::insert_content_meta_tags()
shareaholic_init in ./shareaholic.module
Implements hook_init() This gets called at the beginning of a non-cached page request Ideal for setting response headers
shareaholic_node_view in includes/node.php
Implements hook_node_view()

File

./public.php, line 112

Class

ShareaholicPublic
This class is all about drawing the stuff in publishers' templates that visitors can see.

Code

public static function insert_content_meta_tags($node = NULL, $view_mode = NULL, $lang_code = NULL) {
  if (isset($view_mode) && $view_mode === 'rss') {
    return;
  }
  $site_name = ShareaholicUtilities::site_name();
  $api_key = ShareaholicUtilities::get_option('api_key');
  $module_version = ShareaholicUtilities::get_version();
  $content_tags = "\n<!-- Shareaholic Content Tags -->";
  if (!empty($site_name)) {
    $content_tags .= "\n<meta name='shareaholic:site_name' content='{$site_name}' />";
  }
  if (empty($lang_code)) {
    if (isset($GLOBALS['language']->language)) {
      $lang_code = $GLOBALS['language']->language;
    }
    $content_tags .= "\n<meta name='shareaholic:language' content='{$lang_code}' />";
  }
  else {
    $content_tags .= "\n<meta name='shareaholic:language' content='{$lang_code}' />";
  }
  if (!empty($api_key)) {
    $content_tags .= "\n<meta name='shareaholic:site_id' content='{$api_key}' />";
  }
  if (!empty($module_version)) {
    $content_tags .= "\n<meta name='shareaholic:drupal_version' content='{$module_version}' />";
  }
  if (empty($view_mode) || isset($view_mode) && ($view_mode === 'teaser' || $view_mode === 'search_result')) {
    $content_tags .= "\n<meta name='shareaholic:article_visibility' content='private' />";
  }
  if (isset($node) && isset($view_mode) && $view_mode === 'full') {
    $url = $GLOBALS['base_root'] . request_uri();
    $published_time = date('c', $node->created);
    $modified_time = date('c', $node->changed);
    $author = user_load($node->uid);
    $author_name = self::get_user_name($author);
    $tags = implode(', ', self::get_keywords_for($node));
    $image_url = self::get_image_url_for($node);
    $visibility = self::get_visibility($node);
    $shareable = self::is_shareable($node);
    $content_tags .= "\n<meta name='shareaholic:url' content='{$url}' />";
    $content_tags .= "\n<meta name='shareaholic:article_published_time' content='{$published_time}' />";
    $content_tags .= "\n<meta name='shareaholic:article_modified_time' content='{$modified_time}' />";
    $content_tags .= "\n<meta name='shareaholic:article_author_name' content='{$author_name}' />";
    if (!empty($tags)) {
      $content_tags .= "\n<meta name='shareaholic:keywords' content='{$tags}' />";
    }
    if (!empty($image_url)) {
      $content_tags .= "\n<meta name='shareaholic:image' content='{$image_url}' />";
    }
    if (!empty($visibility)) {
      $content_tags .= "\n<meta name='shareaholic:article_visibility' content='{$visibility}' />";
    }
    if (!empty($shareable)) {
      $content_tags .= "\n<meta name='shareaholic:shareable_page' content='{$shareable}' />";
    }
  }
  $content_tags .= "\n<!-- Shareaholic Content Tags End -->\n";
  $element = array(
    '#type' => 'markup',
    '#markup' => $content_tags,
  );
  drupal_add_html_head($element, 'shareaholic_content_meta_tags');
}