You are here

function nodewords_nodeapi in Nodewords: D6 Meta Tags 6

Same name and namespace in other branches
  1. 5 nodewords.module \nodewords_nodeapi()
  2. 6.3 nodewords.module \nodewords_nodeapi()
  3. 6.2 nodewords.module \nodewords_nodeapi()

Implements hook_nodeapi().

File

./nodewords.module, line 485
Implement an API that other modules can use to implement meta tags.

Code

function nodewords_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  switch ($op) {
    case 'delete':
      nodewords_delete_tags(NODEWORDS_TYPE_NODE, $node->nid);
      break;
    case 'insert':
    case 'update':
      if (isset($node->nodewords)) {
        nodewords_save_tags(NODEWORDS_TYPE_NODE, $node->nid, $node->nodewords, TRUE);
      }
      break;
    case 'load':
      return array(
        'nodewords' => nodewords_load_tags(NODEWORDS_TYPE_NODE, $node->nid),
      );
    case 'prepare translation':
      if (isset($node->translation_source->nodewords)) {
        $node->nodewords = $node->translation_source->nodewords;
      }
      break;
    case 'update index':
      $output_tags = array();
      $tag_options = array(
        'type' => NODEWORDS_TYPE_NODE,
        'id' => $node->nid,
        'output' => 'update index',
      );
      if (isset($node->nodewords)) {

        // Prepare the tags.
        foreach (nodewords_get_possible_tags() as $name => $info) {
          $bool = !empty($info['templates']['search index']) && function_exists($function = $info['callback'] . '_prepare');
          if ($bool) {
            $function($output_tags, isset($node->nodewords[$name]) ? $node->nodewords[$name] : array(), $tag_options);
          }
        }
        drupal_alter('nodewords_tags', $output_tags, $tag_options);
        $output = _nodewords_output_tags($output_tags, 'update index');
        drupal_alter('nodewords_tags_output', $output, $tag_options);
        return $output;
      }
      return '';
  }
}