You are here

nodewords_custom_pages.module in Nodewords: D6 Meta Tags 6.2

Allow to set meta tags for any pages for which is known the URL.

File

nodewords_custom_pages/nodewords_custom_pages.module
View source
<?php

/**
 * @file
 * Allow to set meta tags for any pages for which is known the URL.
 */

/**
 *  Implements hook_help().
 */
function nodewords_custom_pages_help($path, $arg) {
  if ($path == 'admin/content/nodewords/custom') {
    $output = '<p>' . t('On this page you can enter the meta tags for other pages of your site. The meta tags set in these page are used before the ones set for nodes or user profiles, and they can ovverride those meta tags.') . '</p>';
  }
  else {
    $output = '';
  }
  return $output;
}

/**
 * Implements hook_menu_alter().
 */
function nodewords_custom_pages_menu_alter(&$items) {
  $admin_access = array(
    'administer meta tags',
  );
  if (module_exists('nodewords_admin')) {
    $items['admin/content/nodewords/custom'] = array(
      'title' => 'Custom pages meta tags',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'nodewords_custom_pages_overview',
      ),
      'access arguments' => $admin_access,
      'type' => MENU_LOCAL_TASK,
      'weight' => 5,
      'file' => 'nodewords_custom_pages.admin.inc',
      'module' => 'nodewords_custom_pages',
    );
    $items['admin/content/nodewords/custom/list'] = array(
      'title' => 'List',
      'access arguments' => $admin_access,
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -1,
      'file' => 'nodewords_custom_pages.admin.inc',
      'module' => 'nodewords_custom_pages',
    );
    $items['admin/content/nodewords/custom/add'] = array(
      'title' => 'Add',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'nodewords_custom_pages_edit',
      ),
      'access arguments' => $admin_access,
      'type' => MENU_LOCAL_TASK,
      'file' => 'nodewords_custom_pages.admin.inc',
      'module' => 'nodewords_custom_pages',
    );
    $items['admin/content/nodewords/custom/%nodewords_custom_pages/delete'] = array(
      'title' => 'Delete custom pages meta tags',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'nodewords_custom_pages_confirm_delete',
        4,
      ),
      'access arguments' => $admin_access,
      'parent' => 'admin/content/nodewords/custom',
      'type' => MENU_CALLBACK,
      'file' => 'nodewords_custom_pages.admin.inc',
      'module' => 'nodewords_custom_pages',
    );
    $items['admin/content/nodewords/custom/%nodewords_custom_pages/edit'] = array(
      'title' => 'Edit custom pages meta tags',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'nodewords_custom_pages_edit',
        4,
      ),
      'access arguments' => $admin_access,
      'parent' => 'admin/content/nodewords/custom',
      'type' => MENU_CALLBACK,
      'file' => 'nodewords_custom_pages.admin.inc',
      'module' => 'nodewords_custom_pages',
    );
  }
}

/**
 * Implements hook_nodewords_api().
 */
function nodewords_custom_pages_nodewords_api() {
  return array(
    'version' => '1.14',
    'path' => '',
  );
}

/**
 * Implements hook_theme().
 */
function nodewords_custom_pages_theme() {
  return array(
    'nodewords_custom_pages_overview' => array(
      'arguments' => array(
        'form' => array(),
      ),
      'file' => 'nodewords_custom_pages.admin.inc',
    ),
  );
}

/**
 * Menu callback loader.
 */
function nodewords_custom_pages_load($pid) {
  $page = db_fetch_object(db_query("SELECT * FROM {nodewords_custom} WHERE pid = %d", $pid));
  $page->tags = nodewords_load_tags(array(
    'type' => NODEWORDS_TYPE_PAGE,
    'id' => $page->pid,
  ));
  return $page;
}

/**
 * Load all page meta tags from the database.
 *
 * @param $enabled
 *   A boolean that if TRUE will only load enabled pages. Default is TRUE.
 */
function nodewords_custom_pages_load_all($enabled = TRUE) {
  if ($enabled) {
    $query = db_query("SELECT * FROM {nodewords_custom} WHERE enabled = 1 ORDER BY weight ASC");
  }
  else {
    $query = db_query("SELECT * FROM {nodewords_custom} ORDER BY weight ASC");
  }
  $pages = array();
  while ($page = db_fetch_object($query)) {
    $page->tags = nodewords_load_tags(array(
      'type' => NODEWORDS_TYPE_PAGE,
      'id' => $page->pid,
    ));
    $pages[$page->pid] = $page;
  }
  return $pages;
}