You are here

function _nodewords_detect_type_and_id in Nodewords: D6 Meta Tags 6

Try to guess the $type and $id by looking at $_GET['q'].

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

File

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

Code

function _nodewords_detect_type_and_id() {
  $arg = arg();
  $default = array(
    'type' => NODEWORDS_TYPE_PAGE,
    'id' => 0,
  );

  // Do not do anything when running in install or update mode.
  if (defined('MAINTENANCE_MODE')) {
    return array(
      'type' => NODEWORDS_TYPE_NONE,
    );
  }
  if (variable_get('site_offline', 0) && !user_access('administer site configuration')) {

    // User will see the site-offline page.
    return array(
      'type' => NODEWORDS_TYPE_OFFLINE,
      'id' => 0,
    );
  }
  $headers = drupal_get_headers();
  if (preg_match('@HTTP/1\\.[01]\\x20+403@', $headers)) {
    return array(
      'type' => NODEWORDS_TYPE_ERRORPAGE,
      'id' => 403,
    );
  }
  if (preg_match('@HTTP/1\\.[01]\\x20+404@', $headers)) {
    return array(
      'type' => NODEWORDS_TYPE_ERRORPAGE,
      'id' => 404,
    );
  }
  $bool = !variable_get('nodewords_list_repeat', FALSE) && isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0;
  if ($bool) {
    return array(
      'type' => NODEWORDS_TYPE_PAGER,
      'id' => 0,
    );
  }
  if (drupal_is_front_page() && variable_get('nodewords_use_frontpage_tags', TRUE)) {
    return array(
      'type' => NODEWORDS_TYPE_FRONTPAGE,
      'id' => 0,
    );
  }
  if (module_exists('blog') && $_GET['q'] == 'blog') {
    return array(
      'type' => NODEWORDS_TYPE_BLOG,
      'id' => 0,
    );
  }
  if (module_exists('forum') && $_GET['q'] == 'forum') {
    return array(
      'type' => NODEWORDS_TYPE_FORUM,
      'id' => 0,
    );
  }

  // Check all of the custom page paths.
  foreach (_nodewords_get_pages_paths() as $pid => $path) {

    // The path is a system path.
    if (drupal_match_path($_GET['q'], $path)) {
      return array(
        'type' => NODEWORDS_TYPE_PAGE,
        'id' => $pid,
      );
    }

    // The path is a URL alias.
    $alias = drupal_get_path_alias($_GET['q']);
    if ($alias != $_GET['q'] && drupal_match_path($alias, $path)) {
      return array(
        'type' => NODEWORDS_TYPE_PAGE,
        'id' => $pid,
      );
    }
  }
  if (!isset($arg[0])) {
    return $default;
  }
  _nodewords_load_all_includes();
  $result = array(
    'type' => NODEWORDS_TYPE_NONE,
    'id' => 0,
  );
  foreach (module_implements('nodewords_type_id') as $module) {
    $function = $module . '_nodewords_type_id';
    $function($result, $arg);
    if ($result['type'] != NODEWORDS_TYPE_NONE) {
      return $result;
    }
  }
  return $default;
}