function page_title_page_get_title in Page Title 5.2
Same name and namespace in other branches
- 8.2 page_title.module \page_title_page_get_title()
- 5 page_title.module \page_title_page_get_title()
- 6.2 page_title.module \page_title_page_get_title()
- 6 page_title.module \page_title_page_get_title()
- 7.2 page_title.module \page_title_page_get_title()
- 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.
Return value
string The page's title.
2 calls to page_title_page_get_title()
- page_title_preprocess_page in ./
page_title.module - Implementation of hook_preprocess_page().
- _phptemplate_variables in ./
template.php
File
- ./
page_title.module, line 408 - Enhanced control over the page title (in the head tag).
Code
function page_title_page_get_title() {
static $title = 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', '[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', '') : '';
// Give other modules the oppertunity to use hook_page_title_pattern_alter() to modify the title. Only need to pass the pattern, there are no tokens to alter.
foreach (module_implements('page_title_pattern_alter') as $module) {
$function = $module . '_page_title_pattern_alter';
call_user_func_array($function, array(
&$page_title_pattern,
));
}
// Apply the token patterns using the one-level replacer (frontpage is only "global" scope). Need to flush the token cache first.
token_get_values('global', NULL, TRUE);
$title = token_replace($page_title_pattern);
}
else {
// Initialize some variables we need
$page_title_pattern = '';
$types = array(
'global' => NULL,
);
// Determine scope
// Node (either node or comment reply)
if (arg(0) == 'node' && is_numeric(arg(1)) || arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2)) && module_exists('comment')) {
$nid = arg(0) == 'node' ? arg(1) : arg(2);
$types['node'] = node_load($nid);
$page_title_pattern = variable_get('page_title_type_' . $types['node']->type, '');
}
elseif (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) && module_exists('taxonomy')) {
$types['taxonomy'] = taxonomy_get_term(arg(2));
$page_title_pattern = variable_get('page_title_vocab_' . $types['taxonomy']->vid, '');
}
elseif (arg(0) == 'forum' && module_exists('forum')) {
if (is_numeric(arg(1))) {
$types['taxonomy'] = taxonomy_get_term(arg(1));
}
$forum_vid = variable_get('forum_nav_vocabulary', '');
$page_title_pattern = variable_get('page_title_vocab_' . $forum_vid, '');
}
elseif (arg(0) == 'user' && is_numeric(arg(1))) {
$types['user'] = user_load(array(
'uid' => arg(1),
));
$page_title_pattern = variable_get('page_title_user', '');
}
elseif (arg(0) == 'blog' && is_numeric(arg(1))) {
$types['user'] = user_load(array(
'uid' => arg(1),
));
$page_title_pattern = variable_get('page_title_blog', '');
}
// 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', '[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', '') : '';
// Give other modules the oppertunity to use hook_page_title_pattern_alter() to modify the pattern and the tokens.
$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);
}
// Apply token patterns using token_replace_multiple after flushing the token cache
token_get_values('global', NULL, TRUE);
$title = token_replace_multiple($page_title_pattern, $types);
}
}
// Passing an empty array for the allowed tags as we dont want *any* allowed tags - although any tags should have either been removed or entity encoded by now.
return filter_xss($title, array());
}