You are here

function page_title_page_get_title in Page Title 6.2

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 page_title.module \page_title_page_get_title()
  5. 7.2 page_title.module \page_title_page_get_title()
  6. 7 page_title.module \page_title_page_get_title()

Determines what title should be sent to the page template.

Call this function from the page hook of function _phptemplate_variables in template.php.

Parameters

$raw: Optional parameter to allow the function to return a raw (unfiltered) result. This should be used with caution...

Return value

string The page's title.

1 call to page_title_page_get_title()
page_title_preprocess_page in ./page_title.module
Implementation of hook_preprocess_page().

File

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

Code

function page_title_page_get_title($raw = FALSE) {
  static $title = NULL;
  if (is_null($title)) {

    // Initialize some variables we need
    $page_title_pattern = '';
    $types = array(
      'global' => NULL,
    );

    // Allow hook_page_title_pattern_alter() to modify the pattern - we cant use drupal_alter as it only supports single arguments (or arrays). We need to pass 2 variables.
    $data = array(
      &$page_title_pattern,
      &$types,
    );
    foreach (module_implements('page_title_pattern_alter') as $module) {
      $function = $module . '_page_title_pattern_alter';
      call_user_func_array($function, $data);
    }

    // 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)) {
      $settings = page_title_get_settings();
      $page_title_pattern = variable_get('page_title_default', $settings['page_title_default']['default']);
    }

    // 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 by resetting the token cache first and then using token_replace_multiple to insert token values
    token_get_values('global', NULL, TRUE);
    $title = token_replace_multiple($page_title_pattern, $types);
  }

  // Trim trailing whitespace from the title
  $title = trim($title);

  // Use filter_xss to remove any tags and to entity encode content.
  return $raw ? $title : filter_xss($title, array());
}