Commit 01bdc9a3 authored by Robert Douglass's avatar Robert Douglass
Browse files

#98614 5.0 compatibility by Harry Slaughter

parents
********************************************************************
D R U P A L M O D U L E
********************************************************************
Name: Page title module
Version: 0.1
Author: Robert Douglass
Email: rob ad robshouse dot net
Last update: February 21, 2006
Drupal: 4.7
********************************************************************
DESCRIPTION:
* This module gives you control over the page title. It gives you the chance
* to provide templates 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.
********************************************************************
PERMISSIONS:
This module defines the "set page title" permission. This permission determines
whether a user will se the "Page title" field on node edit forms.
********************************************************************
SYSTEM REQUIREMENTS:
Drupal: 4.7
********************************************************************
INSTALLATION:
1. Place the entire page_title directory into your Drupal modules/
directory.
2. Enable this module by navigating to:
administer > modules
At this point the Drupal install system will attempt to create the database
table page_title. You should see a message confirming success or
proclaiming failure. If the database table creation did not succeed,
you will need to manually add the following table definition to your
database:
CREATE TABLE `page_title` (
`nid` INT NOT NULL ,
`page_title` VARCHAR( 128 ) NOT NULL ,
PRIMARY KEY ( `nid` )
) TYPE = MYISAM /*!40100 DEFAULT CHARACTER SET utf8 */;
3. Optionally configure the two variations of page title by visiting:
administer > settings > page_title
4. The page title is ultimately set at the theme level. To let your PHPTemplate
based theme interact with this module, you need to add some code to the template.php
file that comes with your theme. If there is no template.php file, you can simply
use the one included with this download. Here is the code:
function _phptemplate_variables($hook, $vars) {
$vars = array();
if ($hook == 'page') {
// This is the only important line
$vars['head_title'] = page_title_page_get_title();
}
return $vars;
}
As you can see from the code comment, there is only one important line
of code:
$vars['head_title'] = page_title_page_get_title();
This line needs to be added to the 'page' hook of the _phptemplate_variables
function.
Alternately, you can call page_title_page_get_title() from page.tpl.php
directly at the place where the title tag is generated.
\ No newline at end of file
; $Id$
name = Page Title
description = "Enhanced control over the page title (in the <head> tag)."
package = Content
<?php
function page_title_install() {
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$query1 = db_query("CREATE TABLE IF NOT EXISTS {page_title} (
nid INT NOT NULL,
page_title VARCHAR( 128 ) NOT NULL,
PRIMARY KEY ( `nid` )
) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
if ($query1) {
$created = TRUE;
}
break;
case 'pgsql':
$query1 = db_query("CREATE TABLE {page_title} (
nid integer NOT NULL default '0',
page_title text NOT NULL default ''
);");
if ($query1) {
$created = TRUE;
}
break;
}
if ($created) {
drupal_set_message(t('Page title module installed successfully.'));
}
else {
drupal_set_message(t('Table installation for the Page title module was unsuccessful. The tables may need to be installed by hand. See the README.txt file for a list of the installation queries.'), 'error');
}
}
<?php
/**
* This module gives you control over the page title. It gives you the chance
* to provide templates 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.
*/
define(MODULE_DESCRIPTION, 'Enhanced control over the page title (in the &lt;head&gt; tag).');
function page_title_help($section) {
switch ($section) {
case 'admin/modules#description':
$output = t(MODULE_DESCRIPTION);
break;
case 'admin/help#page_title':
$output = t('<p>Adds an extra form element to node creation forms that allows you to specify the page title.</p>
<p>Allows for better global configuration of the page title.</p>');
break;
case 'admin/settings/page_title':
$output = t("<p>The default page title follows one of two patterns:
<ol><li><em>page title</em> | <em>site name</em></li>
<li><em>site name</em> | <em>site slogan</em></li></ol>
<p>#1 is the common case where the visitor is viewing a specific page whereas #2 is used at least for the default front page (<em>node</em>).</p>
<p>The page_title.module lets you change these defaults in two ways. First, you can adjust the templates below using the placeholders given. This will change the way the default page titles are created. Second, on every node creation form, you can have the option of specifying a title that is different than the title of the node. If a value is provided, this will be used to generate the <code>@page_title</code> placeholder. If left blank, <code>@page_title</code> will be the node's title, as is now the case.</p>");
break;
}
return $output;
}
/**
* Implementation of hook_perm().
*/
function page_title_perm() {
return array('set page title');
}
/**
* Implementation of hook_menu().
*/
function page_title_menu($may_cache) {
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/page_title',
'title' => t('Page title'),
'description' => t(MODULE_DESCRIPTION),
'callback' => 'drupal_get_form',
'callback arguments' => 'page_title_admin_settings',
'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
}
return $items;
}
function page_title_admin_settings() {
$form['page_title'] = array(
'#type' => 'fieldset',
'#title' => t('Page title templates'),
);
$form['page_title']['page_title_individual'] = array(
'#type' => 'textfield',
'#title' => t('Pattern for individual pages'),
'#default_value' => variable_get('page_title_individual', '@page_title | @site_name'),
'#maxlength' => 128,
'#description' => t('Available placeholders: <code>@page_title</code>, <code>@site_name</code>, <code>@site_slogan</code>.'),
);
$form['page_title']['page_title_front'] = array(
'#type' => 'textfield',
'#title' => t('Pattern for front page'),
'#default_value' => variable_get('page_title_front', '@site_name | @site_slogan'),
'#maxlength' => 128,
'#description' => t('Available placeholders: <code>@site_name</code>, <code>@site_slogan</code>.'),
);
return system_settings_form($form);
}
function page_title_form_alter($form_id, &$form) {
if ($form['#id'] == 'node-form' && user_access('set page title')) {
$form['page_title'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
'#default_value' => $form['#node']->page_title,
'#size' => 60,
'#maxlength' => 127,
'#weight' => -4,
);
}
}
function page_title_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'update':
db_query("DELETE FROM {page_title} WHERE nid = %d", $node->nid);
// fallthrough to insert intentional!
case 'insert':
if (strlen(trim($node->page_title)) > 0) {
db_query("INSERT INTO {page_title} VALUES (%d, '%s')", $node->nid, $node->page_title);
}
break;
case 'delete':
db_query('DELETE FROM {page_title} WHERE nid = %d', $node->nid);
break;
case 'load':
$object = new stdClass();
$object->page_title = page_title_node_get_title($node->nid);
return array('page_title' => $object->page_title);
case 'view':
if ($page) {
page_title_set_title($node->page_title);
}
break;
}
}
/**
* Set the page title of the current page, for display on the page and in the title bar.
*/
function page_title_set_title($title = NULL) {
static $stored_title;
if (isset($title)) {
$stored_title = $title;
}
return $stored_title;
}
// Public API (every module's gotta have one =)
/**
* Gets the page title for a node id
*
* @param the node's id
* @return the node's page title.
*/
function page_title_node_get_title($nid) {
$row = db_fetch_object(db_query('SELECT page_title FROM {page_title} WHERE nid = %d', $nid));
return $row->page_title;
}
/**
* Does the logic to see what title should be send to the page template. Call this function from
* the page hook of function _phptemplate_variables in template.php.
*/
function page_title_page_get_title() {
$page_title_individual = variable_get('page_title_individual', '@page_title | @site_name');
$page_title_front = variable_get('page_title_front', '@site_name | @site_slogan');
// this is the normal title. For node pages it is $node->title
$drupal_title = drupal_get_title();
// this is the custom page title. For node pages it is $node->page_title.
$page_title = (page_title_set_title()) ? strip_tags(page_title_set_title()) : $drupal_title;
$site_name = variable_get('site_name', 'drupal');
$site_slogan = variable_get('site_slogan', '');
if ($drupal_title) {
$title = t($page_title_individual, array('@page_title' => $page_title, '@site_name' => $site_name, '@site_slogan' => $site_slogan));
}
else {
$title = t($page_title_front, array('@site_name' => $site_name, '@site_slogan' => $site_slogan));
}
return $title;
}
<?php
function _phptemplate_variables($hook, $vars) {
$vars = array();
if ($hook == 'page') {
if (module_exist('page_title')) {
$vars['head_title'] = page_title_page_get_title();
}
}
return $vars;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment