page_title.module in Page Title 6.2
Same filename and directory in other branches
Enhanced control over the page title (in the head tag).
This module gives you control over the page title. It gives you the chance to provide patterns for how the title should be structured, and on node pages, gives you the chance to specify the page title rather than defaulting to the node title.
File
page_title.moduleView source
<?php
/**
* @file
* Enhanced control over the page title (in the head tag).
*
* This module gives you control over the page title. It gives you the chance
* to provide patterns for how the title should be structured, and on node
* pages, gives you the chance to specify the page title rather than defaulting
* to the node title.
*/
/**
* Implementation of hook_help().
*/
function page_title_help($path, $arg) {
$output = NULL;
switch ($path) {
case 'admin/settings/page-title':
$output = '<p>' . t('Page Title provides control over the <code><title></code> element on a page using token patterns and an optional textfield to override the title of the item (be it a node, term, user or other). The Token Scope column lets you know which tokens are available for this field (Global is always available). Please click on the <strong><em>more help…</em></strong> link below if you need further assistance.') . '</p>';
$output .= '<p>' . l(t('More Help...'), 'admin/help/page_title') . '</p>';
break;
case 'admin/help#page_title':
$output = '<p>' . t('Drupal\'s default page title follows one of two patterns:') . '</p>';
$items = array(
t('<strong>Default Page</strong>: <samp><em>page title</em> | <em>site name</em></samp>'),
t('<strong>Default Frontpage</strong>: <samp><em>site name</em> | <em>site slogan</em></samp>'),
);
$output .= theme('item_list', $items, NULL, 'ol');
$output .= '<p>' . t('The <strong>Page Title</strong> module lets you change these defaults in two ways. First, you can adjust the patterns below using the placeholders given. This will change the way the default page titles are created. Second, on enabled forms (curently node, term & user editing forms) you have the option of specifying a title that is different to the title of the item. This field only appears if the <em>Show Field</em> box is checked for the item. If a value is provided it will be used to generate the <samp>[page-title]</samp> placeholder however if it is left blank the <samp>[page-title]</samp> token will inherit the item\'s own title.') . '</p>';
$output .= '<p>' . t('The <samp>[page-title]</samp> token will default to the value returned from <samp>drupal_get_title</samp> if there is no value specified or no available page title field.') . '</p>';
$output .= '<p>' . t('Certain types of page title pattern have access to special tokens which others do not, depending on their <em>scope</em>. All patterns have access to the <strong>Global</strong> scope. Content type patterns have access to the <strong>Node</strong> tokens, vocabulary patterns have access to the <strong>Taxonomy</strong> tokens and finally the user patterns have access to the <strong>User</strong> tokens.') . '</p>';
break;
}
return $output;
}
/**
* Implementation of hook_requirements().
*/
function page_title_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
// Are we on an old version?
if (!page_title_is_up_to_date()) {
$requirements['page_title_version'] = array(
'title' => t('Page title version'),
'value' => t('Out of date'),
'description' => t('The Page Title module must be updated. You should run the !link immediately.', array(
'!link' => l(t('database update script'), 'update.php'),
)),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Does the old table exist (it is left after the upgrade in case an admin wants to check the upgrade went ok)
if (db_table_exists('page_title_old')) {
$requirements['upgrade_table'] = array(
'title' => t('Page Title upgrade table present'),
'value' => '',
'description' => t('The Page Title upgrade table (<code>page_title_old</code>) is present. You can remove it !link', array(
'!link' => l(t('using this script'), 'admin/settings/page-title/drop-old-table'),
)),
'severity' => REQUIREMENT_WARNING,
);
}
// If the page title module exists, check it has the right columns - there are reports of upgrade issues.
// If the table doesn't exists, reinstall the module!
if (!db_table_exists('page_title') || db_column_exists('page_title', 'nid')) {
$requirements['page_title_version'] = array(
'title' => t('Page title version'),
'value' => t('Incorrect Schema'),
'description' => t('It appears Drupal thinks the module is up to date, however the database schema is incorrect. Please uninstall and reinstall the module.'),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Everything seems ok...
$rows = db_result(db_query('SELECT COUNT(*) FROM {page_title}'));
$requirements['page_title_version'] = array(
'title' => t('Page title version'),
'value' => t('Enabled (<code>page_title</code> table contains !rows)', array(
'!rows' => format_plural($rows, '1 row', '@count rows'),
)),
'severity' => REQUIREMENT_OK,
);
}
}
}
return $requirements;
}
/**
* Implementation of hook_perm().
*/
function page_title_perm() {
return array(
'set page title',
'administer page titles',
);
}
/**
* Implementation of hook_menu().
*/
function page_title_menu() {
$items = array();
$items['admin/settings/page-title'] = array(
'title' => 'Page title',
'description' => 'Configure the page titles for your site (the title in the <head> tag).',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'page_title_admin_settings',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer page titles',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'page_title.admin.inc',
);
if (db_table_exists('page_title_old')) {
$items['admin/settings/page-title/drop-old-table'] = array(
'title' => 'Drop Old Page Title Table?',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'page_title_drop_old_table_form',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_CALLBACK,
'file' => 'page_title.legacy.inc',
);
}
return $items;
}
/**
* Implementation of hook_theme().
*/
function page_title_theme() {
return array(
'page_title_admin_settings' => array(
'template' => 'page_title-admin-settings-form',
'arguments' => array(
'form' => NULL,
),
),
'page_title_preprocess_page' => array(
'arguments' => array(
'vars' => NULL,
),
),
);
}
/**
* Implementation of hook_node_type().
*
* Updates settings after a node type change.
*/
function page_title_node_type($op, $info) {
// Handle a content type rename
if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) {
// Load the old node type settings.
$temp = variable_get('page_title_type_' . $info->old_type, '');
// If the settings aren't empty, then save them into the new type
if (!empty($temp)) {
variable_set('page_title_type_' . $info->type, $temp);
}
// Delete the old setting
variable_del('page_title_type_' . $info->old_type);
// Essentially, do the same as above but with the _showfield suffix for the node type
$temp = variable_get('page_title_type_' . $info->old_type . '_showfield', 0);
if ($temp) {
variable_set('page_title_type_' . $info->type . '_showfield', $temp);
}
variable_del('page_title_type_' . $info->old_type . '_showfield');
}
// If deleted, remove the variables
if ($op == 'delete') {
variable_del('page_title_type_' . $info->type);
variable_del('page_title_type_' . $info->type . '_showfield');
}
}
/**
* Implementation of hook_form_alter().
*/
function page_title_form_alter(&$form, $form_state, $form_id) {
// If we dont have permission to set the title then we need to abort this alter now!
if (!user_access('set page title')) {
return;
}
// Check we're editing a node and also check that the node type's 'show field' is enabled
if ($form['#id'] == 'node-form') {
$key = 'page_title_type_' . $form['type']['#value'] . '_showfield';
if (variable_get($key, 0)) {
$page_title = isset($form['#node']->page_title) ? $form['#node']->page_title : NULL;
// If we have vertical tabs installed, we need to render the form element slightly differently
$show_vertical_tabs = FALSE;
if (module_exists('vertical_tabs')) {
if (arg(0) == 'admin') {
// If its an admin page, we must render it as a fieldset - the vertical tabs allows per-fieldset disabling. We have to render a fieldset to allow the option to disable it.
$show_vertical_tabs = TRUE;
}
else {
// This isn't an admin page, we should decide whether to render the page title fieldset depending on if the setting is set.
$show_vertical_tabs = ($vt_conf = vertical_tabs_get_config($form_id)) && $vt_conf['page_title'] !== 0;
}
}
// If we have decided to show vertical tabs, render the page_title element into a fieldset, otherwise just a textfield with a weight putting it at the top.
if ($show_vertical_tabs) {
$form['page_title'] = array(
'#type' => 'fieldset',
'#title' => t('Page Title settings'),
'#collapsible' => TRUE,
'#collapsed' => empty($page_title),
'#group' => 'additional_settings',
'#weight' => 35,
'#attached' => array(
'js' => array(
'vertical-tabs' => drupal_get_path('module', 'page_title') . '/page_title.js',
),
),
);
$form['page_title']['page_title'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
'#description' => t('Provide a description of this node to appear in the <title> tag which search engines can use in search result listings (optional). It is generally accepted this field should be less than 70 characters.'),
'#default_value' => $page_title,
'#size' => 60,
'#maxlength' => 255,
);
}
else {
$form['page_title'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
'#description' => t('Provide a description of this node to appear in the <title> tag which search engines can use in search result listings (optional). It is generally accepted this field should be less than 70 characters.'),
'#default_value' => $page_title,
'#size' => 60,
'#maxlength' => 255,
'#weight' => -4,
);
}
drupal_add_js(drupal_get_path('module', 'page_title') . '/page_title.js', 'module', 'header', FALSE, TRUE, FALSE);
}
}
}
/**
* Implementation of hook_form_FORM_ID_alter().
*/
function page_title_form_taxonomy_form_term_alter(&$form, &$form_state) {
// Check we're editing a taxonomy term and also check that the terms vocabulary's 'show field' is enabled
$key = 'page_title_vocab_' . $form['vid']['#value'] . '_showfield';
if (variable_get($key, 0)) {
$form['advanced']['page_title'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
'#description' => t('Provide a description of this term to appear in the <title> tag which search engines can use in search result listings (optional). It is generally accepted this field should be less than 70 characters.'),
'#default_value' => isset($form['tid']['#value']) ? page_title_load_title($form['tid']['#value'], 'term') : '',
'#size' => 60,
'#maxlength' => 255,
'#weight' => -20,
);
drupal_add_js(drupal_get_path('module', 'page_title') . '/page_title.js', 'module', 'header', FALSE, TRUE, FALSE);
}
}
/**
* Implementation of hook_form_FORM_ID_alter().
*/
function page_title_form_forum_form_forum_alter(&$form, &$form_state) {
// Check we're editing a forum container or forum "forum" and also check that the terms vocabulary's 'show field' is enabled
$key = 'page_title_vocab_' . $form['vid']['#value'] . '_showfield';
if (variable_get($key, 0)) {
$form['page_title'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
'#description' => t('Provide a description of this forum to appear in the <title> tag which search engines can use in search result listings (optional). It is generally accepted this field should be less than 70 characters.'),
'#default_value' => isset($form['tid']['#value']) ? page_title_load_title($form['tid']['#value'], 'term') : '',
'#size' => 60,
'#maxlength' => 255,
'#weight' => -20,
);
drupal_add_js(drupal_get_path('module', 'page_title') . '/page_title.js', 'module', 'header', FALSE, TRUE, FALSE);
}
}
/**
* Implementation of hook_form_FORM_ID_alter().
*/
function page_title_form_forum_form_container_alter(&$form, &$form_state) {
// Check we're editing a forum container or forum "forum" and also check that the terms vocabulary's 'show field' is enabled
page_title_form_forum_form_forum_alter($form, $form_state);
}
/**
* Implementation of hook_form_FORM_ID_alter().
*/
function page_title_form_user_profile_form_alter(&$form, &$form_state) {
// Check we're editing a user profile and also check that the user settings's have 'show field' enabled
if (variable_get('page_title_user_showfield', 0)) {
$form['account']['page_title'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
'#description' => t('Provide a description of this user to appear in the <title> tag which search engines can use in search result listings (optional). It is generally accepted this field should be less than 70 characters.'),
'#default_value' => page_title_load_title($form['_account']['#value']->uid, 'user'),
'#size' => 60,
'#maxlength' => 255,
'#weight' => 20,
);
drupal_add_js(drupal_get_path('module', 'page_title') . '/page_title.js', 'module', 'header', FALSE, TRUE, FALSE);
}
}
/**
* Implementation of hook_form_FORM_ID_alter().
*/
function page_title_form_node_type_form_alter(&$form, &$form_state) {
// Alter the node type form - allows easy access to the per-content type page title settings
$form['page_title'] = array(
'#type' => 'fieldset',
'#title' => t('Page Title Settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
$form['page_title']['show_field'] = array(
'#type' => 'checkboxes',
'#title' => t('Page Title Field'),
'#description' => t('If checked, the <em>Page Title</em> field will appear on the node edit form for those who have permission to set the title.'),
'#options' => array(
'show_field' => t('Show field'),
),
'#default_value' => variable_get('page_title_type_' . $form['#node_type']->type . '_showfield', 0) ? array(
'show_field',
) : array(),
);
$form['page_title']['pattern'] = array(
'#type' => 'textfield',
'#title' => t('Page Title Pattern'),
'#default_value' => variable_get('page_title_type_' . $form['#node_type']->type, ''),
'#description' => t('Enter the <em>Page Title</em> pattern you want to use for this node type. For more information, please use the !link settings page', array(
'!link' => l('Page Title', 'admin/settings/page-title'),
)),
'#maxlength' => 255,
);
$form['#submit'][] = 'page_title_node_type_form_submit';
}
/**
* Submit handler for the node_type_form element added in the hook_form_alter() above.
*/
function page_title_node_type_form_submit($form, &$form_state) {
$show_field = $form_state['values']['page_title']['show_field']['show_field'] ? 1 : 0;
variable_set('page_title_type_' . $form_state['values']['type'] . '_showfield', $show_field);
variable_set('page_title_type_' . $form_state['values']['type'], $form_state['values']['page_title']['pattern']);
// For some reason the node module adds the fieldset as a separate entry in the variables table... we dont want this!
variable_del('page_title_' . $form_state['values']['type']);
// Flush the settings on update/insert.
page_title_get_settings(TRUE);
}
/**
* Implementation of hook_nodeapi().
*/
function page_title_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'update':
if (isset($node->page_title) && user_access('set page title')) {
db_query("DELETE FROM {page_title} WHERE type = 'node' AND id = %d", $node->nid);
}
// fallthrough to insert intentional!
case 'insert':
if (isset($node->page_title) && drupal_strlen(trim($node->page_title)) > 0 && user_access('set page title')) {
db_query("INSERT INTO {page_title} VALUES ('node', %d, '%s')", $node->nid, $node->page_title);
}
break;
case 'delete':
db_query("DELETE FROM {page_title} WHERE type = 'node' AND id = %d", $node->nid);
break;
case 'load':
$enabled = (bool) variable_get('page_title_type_' . $node->type . '_showfield', FALSE);
return array(
'page_title' => $enabled ? page_title_load_title($node->nid, 'node') : '',
);
}
}
/**
* Implementation of hook_taxonomy().
*/
function page_title_taxonomy($op, $type, $edit) {
if ($type == 'vocabulary') {
switch ($op) {
case 'delete':
case 'update':
case 'insert':
// Flush the settings on update/insert.
page_title_get_settings(TRUE);
break;
}
}
elseif ($type == 'term') {
switch ($op) {
case 'update':
if (isset($edit['page_title']) && user_access('set page title')) {
db_query("DELETE FROM {page_title} WHERE type = 'term' AND id = %d", $edit['tid']);
}
// Fallthrough to insert is intentional!
case 'insert':
if (isset($edit['page_title']) && drupal_strlen(trim($edit['page_title'])) > 0 && user_access('set page title')) {
db_query("INSERT INTO {page_title} VALUES('term', %d, '%s')", $edit['tid'], $edit['page_title']);
}
break;
case 'delete':
db_query("DELETE FROM {page_title} WHERE type = 'term' AND id = %d", $edit['tid']);
break;
}
}
}
/**
* Implementation of hook_user().
*/
function page_title_user($op, &$edit, &$account) {
switch ($op) {
case 'update':
if (isset($edit['page_title']) && user_access('set page title')) {
db_query("DELETE FROM {page_title} WHERE type = 'user' AND id = %d", $account->uid);
}
// Fallthrough to insert is intentional!
case 'insert':
if (isset($edit['page_title']) && drupal_strlen(trim($edit['page_title'])) > 0 && user_access('set page title')) {
db_query("INSERT INTO {page_title} VALUES('user', %d, '%s')", $account->uid, $edit['page_title']);
}
break;
case 'delete':
db_query("DELETE FROM {page_title} WHERE type = 'user' AND id = %d", $account->uid);
break;
}
}
/**
* Simple wrapper function to get the currently set title for a page
*
* @param $raw
* Optional parameter. If TRUE, the result will not be parsed with filter_xss.
*
* @return
* string the title for the current page
*/
function page_title_get_title($raw = FALSE, $flush = FALSE) {
static $title = NULL;
// This is used to internally "cache" the title in case we call the function more than once (which we shouldn't).
if ($flush || is_null($title)) {
// Give other modules the oppertunity to use hook_page_title_alter().
drupal_alter('page_title', $title);
}
// Return the title in a safe form (any tags removed (such as emphasised or strong tags) and eny entiied encoded)
return $raw ? $title : filter_xss($title, array());
}
/**
* Gets the page title for a type & id.
*
* @param $id
* int The objects id.
* @param $type
* string What is the scope (usually 'node', 'term' or 'user').
*
* @return
* string the page title for the given type & id.
*/
function page_title_load_title($id, $type) {
return db_result(db_query("SELECT page_title FROM {page_title} WHERE type = '%s' AND id = %d", $type, $id));
}
/**
* Wrapper for old function...
* NOTE: This has been depricated in favor of page_title_load_title().
*/
function page_title_node_get_title($nid) {
return page_title_load_title($nid, 'node');
}
/**
* Legacy page title setting function...
* NOTE: This has been deprecated in favour of hook_page_title_alter().
*/
function page_title_set_title($title = NULL) {
static $stored_title;
if (isset($title)) {
$stored_title = $title;
}
return $stored_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.
*
* @param $raw
* Optional parameter to allow the function to return a raw (unfiltered) result. This should be used with caution...
*
* @return
* string The page's title.
*/
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());
}
/**
* Implementation of hook_token_values().
*
* @param
* string The type of token being generated
*
* @return
* array An array of Token ID and Token Value pairs
*/
function page_title_token_values($type) {
$values = array();
if ($type == 'global') {
$values['page-title'] = page_title_get_title();
$values['page-title-raw'] = page_title_get_title(TRUE);
}
return $values;
}
/**
* Implementation of hook_token_list().
*
* @param
* string Which type of token list are we generating?
*
* @return
* array Nested array of Token ID and Token Name pairs.
*/
function page_title_token_list($type = 'all') {
$tokens = array();
if ($type == 'global' || $type == 'all') {
$tokens['global']['page-title'] = t("The page title.");
$tokens['global']['page-title-raw'] = t("The page title. WARNING - raw user input");
}
return $tokens;
}
/**
* Implementation of hook_preprocess_page().
*/
function page_title_preprocess_page(&$vars) {
$vars['head_title'] = page_title_page_get_title();
}
/**
* Implementation of hook_content_extra_fields().
*
* This allows CCK to control the weight of the Page Title element as a "non-cck field"
*/
function page_title_content_extra_fields($type_name) {
$extra = array();
if (variable_get('page_title_type_' . $type_name . '_showfield', 0)) {
$extra['page_title'] = array(
'label' => t('Page Title'),
'description' => t('Page Title form.'),
'weight' => -4,
);
}
return $extra;
}
/**
* Internal function for generating a key for a given view and display. Argument Page Title settings are not stored as variables.
* TODO: Should probably clean these up before making the key (so the return value is [a-z0-9\-])
*/
function _page_title_build_views_keys($view_name, $display_id) {
return 'page_title-' . implode('-', array_filter(array(
$view_name,
$display_id,
)));
}
/**
* Form Alter handler for the views ui config form (used for filters and args)
*/
function page_title_form_views_ui_config_item_form_alter(&$form, &$form_state) {
// Don't bother altering non-argument forms
if ($form_state['type'] != 'argument') {
return;
}
$view =& $form_state['view'];
$display_handler =& $view->display_handler;
// Check the display handler is a page - if not, dont bother altering.
if ($display_handler->display->display_plugin != 'page_with_page_title') {
return;
}
// Now check the display has arguments. This ensures we are on an overidden Argument configuration.
if (!isset($display_handler->options['arguments']) || empty($display_handler->options['arguments'])) {
return;
}
// Build a page title options fieldset wrapper
$temp_form['page_title_pattern'] = array(
'#type' => 'fieldset',
'#title' => t('Page Title'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Add the Page Title field
$temp_form['page_title_pattern']['page_title_pattern'] = array(
'#type' => 'textfield',
'#title' => t('Page Title Pattern'),
'#description' => t('Optionally enter a Page Title Pattern for this argument. This will override the main view Page Title Pattern. You can also use the tokens below.'),
'#default_value' => $form_state['handler']->options['page_title_pattern'],
'#parents' => array(
'options',
'page_title_pattern',
),
);
// Add the token help to a collapsed fieldset at the end of the configuration page.
$temp_form['page_title_pattern']['token_help'] = array(
'#type' => 'fieldset',
'#title' => t('Available Tokens List'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$temp_form['page_title_pattern']['token_help']['content'] = array(
'#type' => 'markup',
'#value' => theme('token_help', 'global'),
);
// Splice the temp form into the main form. We do this because there are no weights in the views form meaning Page Title can either be top or bottom (-1 or 1).
$offset = array_search('title', array_keys($form['options']));
$spliced_form = array_splice($form['options'], 0, $offset);
$form['options'] = array_merge($spliced_form, $temp_form, $form['options']);
}
/**
* Implementation of hook_views_api().
*/
function page_title_views_api() {
return array(
'api' => 2,
);
}
/**
* Implementation of hook_views_plugins().
*/
function page_title_views_plugins() {
return array(
'module' => 'page_title',
'display' => array(
'page_with_page_title' => array(
'title' => t('Page (with Page Title)'),
'help' => t('Same as a normal Page, but also includes the Page Title control.'),
'parent' => 'page',
'uses hook menu' => TRUE,
'use ajax' => FALSE,
'use pager' => TRUE,
'accept attachments' => TRUE,
'admin' => t('Page with Page Title'),
'module' => 'page_title',
'path' => drupal_get_path('module', 'page_title') . '/views/plugins',
'file' => 'page_title_plugin_display_page_with_page_title.inc',
'handler' => 'page_title_plugin_display_page_with_page_title',
'theme' => 'views_view',
'theme path' => drupal_get_path('module', 'views') . '/theme',
'theme file' => 'theme.inc',
),
),
);
}
/**
* Get the Page Title settings
*/
function page_title_get_settings($flush = FALSE) {
static $settings = NULL;
// Flush the settings, if set.
if ($flush) {
$settings = NULL;
cache_clear_all('page_title:settings', 'cache');
}
// If we have it statically cached, return it.
if (!empty($settings)) {
return $settings;
}
// Get from Cache
if ($cache = cache_get('page_title:settings')) {
$settings = $cache->data;
return $cache->data;
}
// Ensure that the page title inc files are included before invoking
// This helps avoid the issues in #1567790
page_title_include_api_files();
// Get the settings from hook_page_title_settings().
$settings = module_invoke_all('page_title_settings');
// For each setting, apply a "default" mask (this makes it easier to use
// later as we can assume presence)
foreach ($settings as $k => $v) {
$settings[$k] = (array) $v + array(
'label' => '',
'label arguments' => array(),
'required' => FALSE,
'show field' => FALSE,
'description' => '',
'description arguments' => array(),
'weight' => 0,
'default' => '',
);
}
// Now sort
uasort($settings, '_page_title_settings_sort');
// Cache this so we dont have to do this EVERY time
cache_set('page_title:settings', $settings);
return $settings;
}
/**
* Internal function for sorting the page title settings array.
*/
function _page_title_settings_sort($a, $b) {
// Sort by weight and, failing that, label alphabetical.
return $a['weight'] < $b['weight'] ? -1 : ($a['weight'] > $b['weight'] ? 1 : ($a['label'] < $b['label'] ? -1 : 1));
}
/**
* Implementation of hook_init().
*/
function page_title_init() {
// Include the admin CSS for the report page - TODO: Is there a better way?
if (arg(0) == 'admin' && arg(1) == 'reports' && arg(2) == 'page-title') {
drupal_add_css(drupal_get_path('module', 'page_title') . '/page_title.admin.css');
}
page_title_include_api_files();
}
/**
* Function to ensure API files are included.
* We use a static variable so we can use include, which is faster than include_one
*/
function page_title_include_api_files() {
// Using $runonce, we can ensure the include code below only gets run once.
static $runonce = FALSE;
if ($runonce) {
return;
}
// Include relevant page_title.inc's. We cannot use drupal_load() here due to the folder structure.
// We also avoice using include_once due to its performance hit on the Filesystem
foreach (page_title_get_module_apis() as $module => $info) {
$path = "./{$info['path']}/{$module}.page_title.inc";
if (file_exists($path)) {
include $path;
}
}
$runonce = TRUE;
}
/**
* Get a list of modules that support the current Page Title API.
*/
function page_title_get_module_apis() {
static $cache = NULL;
if (!isset($cache)) {
$cache = array();
foreach (module_implements('page_title_api') as $module) {
$function = $module . '_page_title_api';
$info = $function();
if (isset($info['api']) && $info['api'] == 1.0) {
if (!isset($info['path'])) {
$info['path'] = drupal_get_path('module', $module);
}
$cache[$module] = $info;
}
}
}
return $cache;
}
/**
* Implementation of hook_page_title_api().
*/
function page_title_page_title_api() {
return array(
'api' => 1,
'path' => drupal_get_path('module', 'page_title') . '/modules',
);
}
/**
* Core implementations of hook_page_title_api().
*/
function blog_page_title_api() {
return page_title_page_title_api();
}
function taxonomy_page_title_api() {
return page_title_page_title_api();
}
function node_page_title_api() {
return page_title_page_title_api();
}
function comment_page_title_api() {
return page_title_page_title_api();
}
function forum_page_title_api() {
return page_title_page_title_api();
}
function user_page_title_api() {
return page_title_page_title_api();
}
function views_page_title_api() {
return page_title_page_title_api();
}
function uc_catalog_page_title_api() {
return page_title_page_title_api();
}
/**
* Internal function for checking if Page Title is ok to run
*/
function page_title_is_up_to_date() {
return drupal_get_installed_schema_version('page_title') >= max(drupal_get_schema_versions('page_title'));
}
Functions
Name | Description |
---|---|
blog_page_title_api | Core implementations of hook_page_title_api(). |
comment_page_title_api | |
forum_page_title_api | |
node_page_title_api | |
page_title_content_extra_fields | Implementation of hook_content_extra_fields(). |
page_title_form_alter | Implementation of hook_form_alter(). |
page_title_form_forum_form_container_alter | Implementation of hook_form_FORM_ID_alter(). |
page_title_form_forum_form_forum_alter | Implementation of hook_form_FORM_ID_alter(). |
page_title_form_node_type_form_alter | Implementation of hook_form_FORM_ID_alter(). |
page_title_form_taxonomy_form_term_alter | Implementation of hook_form_FORM_ID_alter(). |
page_title_form_user_profile_form_alter | Implementation of hook_form_FORM_ID_alter(). |
page_title_form_views_ui_config_item_form_alter | Form Alter handler for the views ui config form (used for filters and args) |
page_title_get_module_apis | Get a list of modules that support the current Page Title API. |
page_title_get_settings | Get the Page Title settings |
page_title_get_title | Simple wrapper function to get the currently set title for a page |
page_title_help | Implementation of hook_help(). |
page_title_include_api_files | Function to ensure API files are included. We use a static variable so we can use include, which is faster than include_one |
page_title_init | Implementation of hook_init(). |
page_title_is_up_to_date | Internal function for checking if Page Title is ok to run |
page_title_load_title | Gets the page title for a type & id. |
page_title_menu | Implementation of hook_menu(). |
page_title_nodeapi | Implementation of hook_nodeapi(). |
page_title_node_get_title | Wrapper for old function... NOTE: This has been depricated in favor of page_title_load_title(). |
page_title_node_type | Implementation of hook_node_type(). |
page_title_node_type_form_submit | Submit handler for the node_type_form element added in the hook_form_alter() above. |
page_title_page_get_title | Determines what title should be sent to the page template. |
page_title_page_title_api | Implementation of hook_page_title_api(). |
page_title_perm | Implementation of hook_perm(). |
page_title_preprocess_page | Implementation of hook_preprocess_page(). |
page_title_requirements | Implementation of hook_requirements(). |
page_title_set_title | Legacy page title setting function... NOTE: This has been deprecated in favour of hook_page_title_alter(). |
page_title_taxonomy | Implementation of hook_taxonomy(). |
page_title_theme | Implementation of hook_theme(). |
page_title_token_list | Implementation of hook_token_list(). |
page_title_token_values | Implementation of hook_token_values(). |
page_title_user | Implementation of hook_user(). |
page_title_views_api | Implementation of hook_views_api(). |
page_title_views_plugins | Implementation of hook_views_plugins(). |
taxonomy_page_title_api | |
uc_catalog_page_title_api | |
user_page_title_api | |
views_page_title_api | |
_page_title_build_views_keys | Internal function for generating a key for a given view and display. Argument Page Title settings are not stored as variables. TODO: Should probably clean these up before making the key (so the return value is [a-z0-9\-]) |
_page_title_settings_sort | Internal function for sorting the page title settings array. |