You are here

public function ShareMessage::buildContent in Share Message 7

Overrides Entity::buildContent().

Overrides Entity::buildContent

File

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

Class

ShareMessage

Code

public function buildContent($view_mode = 'full', $langcode = NULL) {
  $profileid = variable_get('sharemessage_addthis_profile_id', 1);
  $context = array(
    'sharemessage' => $this,
    'view_mode' => $view_mode,
  );
  if ($node = menu_get_object()) {
    $context['node'] = $node;
  }
  drupal_alter('sharemessage_token_context', $this, $context);

  // Add OG Tags to the page if there are none added yet and a corresponding
  // view mode was set (or it was altered into such a view mode above).
  $og_view_modes = array(
    'full',
    'only_og_tags',
    'no_attributes',
  );
  if (strpos(drupal_get_html_head(), 'property="og:') == FALSE && in_array($context['view_mode'], $og_view_modes)) {
    $this
      ->addOGTags($context);
  }

  // Add twitter card meta tags if setting is active.
  if (strpos(drupal_get_html_head(), 'property="twitter:') === FALSE && variable_get('sharemessage_add_twitter_card', FALSE)) {
    $this
      ->addTwitterCardTags($context);
  }

  // Add addThis buttons.
  $content = array();
  if ($view_mode != 'only_og_tags') {
    $attributes_view_modes = array(
      'full',
      'attributes_only',
    );
    $type = isset($this->settings['type']) ? $this->settings['type'] : variable_get('sharemessage_default_type', 'addthis');
    if ($type == 'shariff') {
      $settings = _shariff_get_settings();
      if (!empty($settings['services'])) {
        $settings['media_url'] = $this
          ->getImageUrl($context);
        $settings['twitter_via'] = variable_get('sharemessage_twitter_user');
        $settings['url'] = $this
          ->getUrl($context);
        $settings['mail_subject'] = $this
          ->getTokenizedField('sharemessage_title', $context);
        $settings['mail_body'] = $this
          ->getTokenizedField('sharemessage_long', $context);
        $settings['title'] = $this
          ->getTokenizedField('sharemessage_short', $context);
        $content['shariff']['#markup'] = theme('shariff', $settings);
      }
      return $content;
    }
    $content['addthis'] = array(
      '#type' => 'container',
      '#attributes' => in_array($context['view_mode'], $attributes_view_modes) ? $this
        ->buildAdditionalAttributes($context) : $this
        ->buildAttributes(),
      'services' => array(
        '#markup' => $this
          ->build_services_part($context),
      ),
      'additional_services' => array(
        '#markup' => $this
          ->build_additional_services_part(),
      ),
      'addthis_js' => array(
        '#attached' => array(
          'js' => array(
            array(
              'data' => array(
                'addthis_config' => array(
                  'data_track_addressbar' => TRUE,
                ),
              ),
              'type' => 'setting',
            ),
            array(
              'data' => '//s7.addthis.com/js/300/addthis_widget.js#pubid=' . $profileid,
              'type' => 'external',
            ),
          ),
        ),
      ),
    );
  }
  return entity_get_controller($this->entityType)
    ->buildContent($this, $view_mode, $langcode, $content);
}