You are here

opengraph_meta.drupal7-hooks.inc in Open Graph meta tags 7

Same filename and directory in other branches
  1. 6 opengraph_meta.drupal7-hooks.inc

File

opengraph_meta.drupal7-hooks.inc
View source
<?php

/** Drupal 7 hooks. */

/**
 * Implements hook_permission().
 */
function opengraph_meta_permission() {
  return array(
    OPENGRAPH_META_PERM_ADMIN => array(
      'title' => t('Administer Open Graph meta tags'),
      'description' => t('Administer default Open Graph meta tags options'),
    ),
    OPENGRAPH_META_PERM_EDIT => array(
      'title' => t('Edit Open Graph meta tags'),
      'description' => t('Edit Open Graph meta tags on a node'),
    ),
  );
}

/**
 * Implements hook_node_load().
 */
function opengraph_meta_node_load($nodes, $types) {
  foreach ($nodes as &$node) {
    if (OpenGraphMeta::instance()
      ->tags_are_enabled_for_content_type($node->type)) {
      $node->opengraph_meta = OpenGraphMeta::instance()
        ->load_node_data($node);
    }
  }
}

/**
 * Implements hook_node_view().
 */
function opengraph_meta_node_view($node, $view_mode, $langcode) {

  // only show meta tags if viewing full node as a page
  if (!empty($node->opengraph_meta) && node_is_page($node)) {
    OpenGraphMeta::instance()
      ->render_data($node, $node->opengraph_meta);
  }
}

/**
 * Implements hook_node_insert().
 */
function opengraph_meta_node_insert($node) {
  opengraph_meta_node_update($node);
}

/**
 * Implements hook_node_update().
 */
function opengraph_meta_node_update($node) {
  if (!empty($node->opengraph_meta)) {
    OpenGraphMeta::instance()
      ->save_node_data($node->nid, $node->opengraph_meta);
  }
}

/**
 * Implements hook_node_delete().
 */
function opengraph_meta_node_delete($node) {
  OpenGraphMeta::instance()
    ->delete_node_data($node->nid);
}