html_title.module in HTML Title 6
Same filename and directory in other branches
This module enables limited HTML to be used in node titles. It strips title markup from RSS feeds to eliminate unsightly markup in feed readers.
File
html_title.moduleView source
<?php
/**
* @defgroup html_title HTML Title
*/
/**
* @file
* This module enables limited HTML to be used in node titles. It strips title
* markup from RSS feeds to eliminate unsightly markup in feed readers.
*/
/**
* Implementation of hook_menu()
*/
function html_title_menu() {
$items['admin/settings/html_title'] = array(
'title' => 'HTML Title settings',
'description' => 'Configure HTML tags used in node titles.',
'access arguments' => array(
'administer site configuration',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'html_title_admin_settings',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'html_title.admin.inc',
);
return $items;
}
/**
* Implementation of hook_theme_registry_alter()
*/
function html_title_theme_registry_alter(&$theme_registry) {
// Re-order search result pre-processing so ours always runs last
if (module_exists('search') && is_array($theme_registry['search_result']['preprocess functions'])) {
foreach ($theme_registry['search_result']['preprocess functions'] as $value) {
if ($value != 'html_title_preprocess_search_result') {
$callbacks[] = $value;
}
}
$callbacks[] = 'html_title_preprocess_search_result';
$theme_registry['search_result']['preprocess functions'] = $callbacks;
}
}
/**
* Implementation of hook_preprocess_page()
*/
function html_title_preprocess_page(&$vars) {
if (array_key_exists('node', $vars)) {
$elements = variable_get('html_title_allowed_elements', array(
'em',
'sub',
'sup',
));
// Reset title to allow safe HTML
$vars['title'] = filter_xss($vars['node']->title, $elements);
// Strip HTML from head title
$vars['head_title'] = strip_tags($vars['node']->title);
drupal_set_title($vars['head_title']);
}
}
/**
* Implementation of hook_preprocess_node()
*/
function html_title_preprocess_node(&$node) {
if (isset($node['html_title_raw'])) {
$elements = variable_get('html_title_allowed_elements', array(
'em',
'sub',
'sup',
));
$node['title'] = filter_xss($node['html_title_raw'], $elements);
}
}
/**
* Implementation of hook_preprocess_search_result()
*/
function html_title_preprocess_search_result(&$vars) {
if (isset($vars['result']['title'])) {
$elements = variable_get('html_title_allowed_elements', array(
'em',
'sub',
'sup',
));
$vars['title'] = filter_xss($vars['result']['title'], $elements);
}
}
/**
* Implementation of hook_nodeapi()
*/
function html_title_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'load':
// Capture original title for use in hook_preprocess_node
return array(
'html_title_raw' => $node->title,
);
break;
case 'rss item':
// Strip html from titles
$node->title = strip_tags($node->title);
break;
case 'view':
// Strip html from titles for views feeds using 'node' rendering
case 'alter':
// Strip html from titles for views feeds using other rendering
if ($node->build_mode == NODE_BUILD_RSS) {
$node->title = strip_tags($node->title);
}
break;
}
}
/**
* Implementation hook_views_api()
*/
function html_title_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'html_title') . '/views',
);
}
Functions
Name | Description |
---|---|
html_title_menu | Implementation of hook_menu() |
html_title_nodeapi | Implementation of hook_nodeapi() |
html_title_preprocess_node | Implementation of hook_preprocess_node() |
html_title_preprocess_page | Implementation of hook_preprocess_page() |
html_title_preprocess_search_result | Implementation of hook_preprocess_search_result() |
html_title_theme_registry_alter | Implementation of hook_theme_registry_alter() |
html_title_views_api | Implementation hook_views_api() |