You are here

function _metatags_quick_add_head in Meta tags quick 7.2

Same name and namespace in other branches
  1. 8.3 metatags_quick.module \_metatags_quick_add_head()
  2. 7 metatags_quick.module \_metatags_quick_add_head()
2 calls to _metatags_quick_add_head()
metatags_quick_add_meta_tag in ./metatags_quick.rules.inc
Rules integraiton function for _metatags_quick_add_head().
metatags_quick_field_formatter_view in ./metatags_quick.module
Implements hook_field_formatter_view().

File

./metatags_quick.module, line 565
Quick and dirty implementation of meta tags for drupal 7 Module defines new field type 'meta'. Fields of this type are not displayed in HTML. Instead, they add html meta to the head section.

Code

function _metatags_quick_add_head($item = FALSE) {
  static $added_meta = array();
  static $meta_data = array();
  if (!empty($added_meta[$item['name']])) {
    return;
  }

  // Only output meta if content is not empty.
  if ($item['content']) {
    $content = $item['content'];
    if (!empty($item['entity_type']) && !empty($item['entity'])) {
      $content = token_replace($content, array(
        $item['entity_type'] => $item['entity'],
      ));
    }
    else {
      $content = token_replace($content);
    }

    // (Not nice) hack to separate multiple tags returned by token.
    $content = preg_replace('/<\\/a><a/', '<\\/a>, <a', $content);
    $content = trim(strip_tags($content));
    $item['content'] = $content;
    $meta_data[] = $item;
    if (empty($item['type'])) {
      $item['type'] = 'default';
    }
    switch ($item['type']) {
      case 'link':

        // Unset an existing html head link with the same rel attribute, assuming that
        // the array key has been built by drupal_add_html_head_link().
        $head_elements =& drupal_static('drupal_add_html_head');
        foreach ($head_elements as $key => $head_element) {

          // If an existing key starts with 'drupal_add_html_head_link:[name]', unset it.
          if (strpos($key, 'drupal_add_html_head_link:' . $item['name']) === 0) {
            $head_elements[$key]['#access'] = FALSE;
          }
        }
        $attributes = array(
          'rel' => $item['name'],
          'href' => url($item['content']),
        );
        drupal_add_html_head_link($attributes);
        break;
      case 'default':
      default:
        $element = array(
          '#tag' => 'meta',
          '#attributes' => array(
            'name' => $item['name'],
            'content' => $item['content'],
          ),
        );
        drupal_add_html_head($element, 'metatags_quick_' . $item['name']);
    }
  }
  $added_meta[$item['name']] = TRUE;
}