You are here

function page_title_page_get_title in Page Title 7

Same name and namespace in other branches
  1. 8.2 page_title.module \page_title_page_get_title()
  2. 5.2 page_title.module \page_title_page_get_title()
  3. 5 page_title.module \page_title_page_get_title()
  4. 6.2 page_title.module \page_title_page_get_title()
  5. 6 page_title.module \page_title_page_get_title()
  6. 7.2 page_title.module \page_title_page_get_title()

Determines what title should be sent to the page template.

This function gets called from the implementation of hook_preprocess_html

Return value

string The page's title.

1 call to page_title_page_get_title()
page_title_preprocess_html in ./page_title.module
Implement hook_preprocess_html().

File

./page_title.module, line 442
Enhanced control over the page title (in the head tag).

Code

function page_title_page_get_title() {
  static $title = NULL;
  $types = array(
    'global' => NULL,
  );
  if (is_null($title)) {

    // If frontpage, then use the frontpage pattern and set the title.
    if (drupal_is_front_page()) {

      // Get the frontpage pattern
      $page_title_pattern = variable_get('page_title_front', '[site:name] | [site:slogan]');

      // If the frontpage pattern is empty, fallback to the default.
      if (empty($page_title_pattern)) {
        $page_title_pattern = variable_get('page_title_default', '[site:page-title] | [site:slogan]');
      }

      // Append the pattern for pages with a pager on them
      $page_title_pattern .= isset($_REQUEST['page']) ? variable_get('page_title_pager_pattern', '') : '';

      // Apply the token patterns using the one-level replacer (frontpage is only "global" scope)
      $title = token_replace($page_title_pattern);
    }
    else {

      // Initialize some variables we need
      $page_title_pattern = '';

      // Determine scope
      // Node
      if ($node = menu_get_object()) {
        $types['node'] = $node;

        // TODO: Figure out comment pages. The new Menu API buggers about the arg() and $_GET['q']...
        $page_title_pattern = variable_get('page_title_type_' . $node->type, '');
      }
      elseif (module_exists('taxonomy') && ($term = menu_get_object('taxonomy_term', 2))) {
        $types['taxonomy'] = $term;
        $page_title_pattern = variable_get('page_title_vocab_' . $term->vid, '');
      }
      elseif ($user = menu_get_object('user_uid_optional') || ($user = menu_get_object('user'))) {
        $types['user'] = $user;
        switch (arg(0)) {
          case 'blog':
            $page_title_pattern = variable_get('page_title_blog', '');
            break;
          default:
            $page_title_pattern = variable_get('page_title_user', '');
            break;
        }
      }

      // If pattern is emtpy (either if the type is not overridable or simply not set) fallback to the default pattern
      if (empty($page_title_pattern)) {
        $page_title_pattern = variable_get('page_title_default', '[site:page-title] | [site:name]');
      }

      // Append the pattern for pages with a pager on them
      $page_title_pattern .= isset($_REQUEST['page']) ? variable_get('page_title_pager_pattern', '') : '';

      // Apply token patterns using token_replace
      $title = token_replace($page_title_pattern, $types);
    }
  }
  return strip_tags($title);
}