You are here

function nodewords_detect_type_id in Nodewords: D6 Meta Tags 6.2

Same name and namespace in other branches
  1. 6.3 nodewords.module \nodewords_detect_type_id()

Try to guess the type and the ID associated with the viewed page.

Parameters

$options: An array of parameters that describe the page to check. If the array is is not passed, the function will return the type of the currently viewed page.

Return value

An array containing information about the type of the page.

1 call to nodewords_detect_type_id()
nodewords_preprocess_page in ./nodewords.module
Implements hook_preprocess_page().

File

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

Code

function nodewords_detect_type_id($options = array()) {
  $options += array(
    'page' => isset($_REQUEST['page']) ? $_REQUEST['page'] : -1,
    'headers' => drupal_get_headers(),
    'q' => $_GET['q'],
  );
  $arg = explode('/', $options['q']) + array_fill(0, MENU_MAX_PARTS, NULL);

  // Start out with the default type.
  $result = array(
    'type' => NODEWORDS_TYPE_DEFAULT,
    'id' => 0,
  );
  if (variable_get('site_offline', 0) && !user_access('administer site configuration')) {

    // Offline page always has the highest weight.
    $result['type'] = NODEWORDS_TYPE_OFFLINE;
  }
  elseif (preg_match('@HTTP/1\\.[01]\\x20+(403|404)[^a-zA-Z0-9]@', $options['headers'], $matches)) {

    // Error pages (403 or 404s)
    $result['type'] = NODEWORDS_TYPE_ERRORPAGE;
    $result['id'] = (int) $matches[1];
  }
  elseif (!variable_get('nodewords_list_repeat', FALSE) && intval($options['page']) > 0) {
    $result['type'] = NODEWORDS_TYPE_PAGER;
  }
  elseif (!isset($arg[0])) {

    // @todo WTF is this doing?
    $result['type'] = NODEWORDS_TYPE_NONE;
  }
  else {

    // Allow other modules to alter the current page context.
    _nodewords_load_hook_files();
    foreach (module_implements('nodewords_type_id') as $module) {
      $function = $module . '_nodewords_type_id';
      $function($result, $arg);
      if ($result['type'] != NODEWORDS_TYPE_DEFAULT) {
        break;
      }
    }
  }
  return $result;
}