You are here

context_metadata.module in Context Metadata 6

Provides a context reaction

File

context_metadata.module
View source
<?php

/**
 * @file
 * Provides a context reaction
 */

/**
 * Implements hook_context_plugins().
 */
function context_metadata_context_plugins() {
  $plugins = array();
  $plugins['context_metadata_context_reaction'] = array(
    'handler' => array(
      'path' => drupal_get_path('module', 'context_metadata') . '/plugins',
      'file' => 'context_metadata_reaction.inc',
      'class' => 'context_metadata_reaction',
      'parent' => 'context_reaction',
    ),
  );
  return $plugins;
}

/**
 * Implements hook_context_registry().
 */
function context_metadata_context_registry() {
  return array(
    'reactions' => array(
      'context_metadata' => array(
        'title' => t('Meta Data'),
        'plugin' => 'context_metadata_context_reaction',
      ),
    ),
  );
}

/**
 * Implements hook_context_page_reaction().
 */
function context_metadata_context_page_reaction() {
  if ($plugin = context_get_plugin('reaction', 'context_metadata')) {
    $plugin
      ->execute();
  }
}

/**
 * Implements hook_page_title_alter().
 */
function context_metadata_page_title_alter(&$title) {
  $static_metadata_array = context_metadata_static_store();
  if (isset($static_metadata_array['metadata_title'])) {
    if (module_exists('token')) {
      $title = token_replace($static_metadata_array['metadata_title'], $type = 'global', $object = NULL, $leading = '[', $trailing = ']');
    }
    else {
      $title = $static_metadata_array['metadata_title'];
    }
  }
}

/**
 * Implements hook_nodewords_tags_alter().
 */
function context_metadata_nodewords_tags_alter(&$output, $parameters) {
  $static_metadata_array = context_metadata_static_store();

  // Alter the description.
  if (isset($static_metadata_array['metadata_description'])) {
    $output['description'] = $static_metadata_array['metadata_description'];
  }

  // Alter the keywords.
  if (isset($static_metadata_array['metadata_keywords'])) {
    $output['keywords'] = $static_metadata_array['metadata_keywords'];
  }

  // Alter the canonical URL.
  if (isset($static_metadata_array['metadata_canonical'])) {
    $output['canonical'] = $static_metadata_array['metadata_canonical'];
  }
}

/**
 * Static store.
 */
function context_metadata_static_store($static_metadata_array = array()) {
  static $static_array;
  if (!empty($static_metadata_array)) {
    $static_array = $static_metadata_array;
  }
  return $static_array;
}