You are here

private function ShareMessage::addOGTags in Share Message 7

Function that adds OG tags in the header of the page.

1 call to ShareMessage::addOGTags()
ShareMessage::buildContent in includes/sharemessage.entity.inc
Overrides Entity::buildContent().

File

includes/sharemessage.entity.inc, line 98
Definition of ShareMessage entity class.

Class

ShareMessage

Code

private function addOGTags($context) {

  // Basic Metadata (og:title, og:type, og:image, og:url).
  // OG: Title.
  $og_title = array(
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:title',
      'content' => $this
        ->getTokenizedField('sharemessage_title', $context),
    ),
  );
  drupal_add_html_head($og_title, 'og_title');

  // Base value for og:type meta tag.
  $type = 'website';

  // Add Multiple og tags used for sharing of videos.
  if ($video_url = $this
    ->getTokenizedField('sharemessage_video_url', $context, NULL)) {
    $og_video = array(
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'property' => 'og:video',
        'content' => $video_url . '?fs=1',
      ),
    );
    drupal_add_html_head($og_video, 'og_video');
    $og_video = array(
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'property' => 'og:video:width',
        'content' => variable_get('sharemessage_shared_video_width', 360),
      ),
    );
    drupal_add_html_head($og_video, 'og_video_width');
    $og_video = array(
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'property' => 'og:video:height',
        'content' => variable_get('sharemessage_shared_video_height', 270),
      ),
    );
    drupal_add_html_head($og_video, 'og_video_height');
    $og_video = array(
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'property' => 'og:video:type',
        'content' => 'application/x-shockwave-flash',
      ),
    );
    drupal_add_html_head($og_video, 'og_video_type');

    // Override og:type to video.
    $type = 'video';
  }

  // OG: Image, can be used for video thumbnails as well.
  if ($this
    ->getImageUrl($context)) {
    $og_image = array(
      '#type' => 'html_tag',
      '#tag' => 'meta',
      '#attributes' => array(
        'property' => 'og:image',
        'content' => $this
          ->getImageUrl($context),
      ),
    );
    drupal_add_html_head($og_image, 'og_image');
  }

  // OG: Type.
  $og_type = array(
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:type',
      'content' => $type,
    ),
  );
  drupal_add_html_head($og_type, 'og_type');

  // OG: URL.
  $og_url = array(
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:url',
      'content' => $this
        ->getUrl($context),
    ),
  );
  drupal_add_html_head($og_url, 'og_url');

  // OG: Description.
  $og_description = array(
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:description',
      'content' => $this
        ->getTokenizedField('sharemessage_long', $context),
    ),
  );
  drupal_add_html_head($og_description, 'og_description');
}