Commit fb45a43a authored by Nicholas Thompson's avatar Nicholas Thompson
Browse files

A 'working' Page Title for Drupal 6

parent eb1afc04
; $Id$
name = Page Title
description = "Enhanced control over the page title (in the <head> tag)."
dependencies = token
\ No newline at end of file
dependencies[] = token
core = 6.x
\ No newline at end of file
......@@ -5,33 +5,23 @@
* Implementation of hook_install().
*/
function page_title_install() {
$result = FALSE;
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$result = db_query('CREATE TABLE IF NOT EXISTS {page_title} (
nid INT NOT NULL,
page_title VARCHAR(255) NOT NULL,
PRIMARY KEY (nid)
) /*!40100 DEFAULT CHARACTER SET utf8 */');
break;
drupal_install_schema('page_title');
}
case 'pgsql':
$result = db_query("CREATE TABLE {page_title} (
nid integer NOT NULL default '0',
page_title text NOT NULL default ''
)");
break;
}
if ($result) {
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');
}
function page_title_schema() {
$schema['page_title'] = array(
'fields' => array(
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'page_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')
),
'primary key' => array('nid'),
);
return $schema;
}
/**
* Implementation of hook_uninstall().
*/
......@@ -42,29 +32,4 @@ function page_title_uninstall() {
foreach (node_get_types('names') AS $type => $name) {
variable_del("page_title_display_$type");
}
}
/**
* Increases page title in MySQL to 255 characters and modifies the MySQL table type from MYISAM to the user's default type.
*
* Implementation of hook_update_N().
*/
function page_title_update_1() {
$items = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$items[] = update_sql('ALTER TABLE {page_title} MODIFY COLUMN page_title VARCHAR(255) NOT NULL');
$items[] = update_sql('CREATE TEMPORARY TABLE {page_title_temp} AS SELECT * FROM {page_title}');
$items[] = update_sql('DROP TABLE {page_title}');
$items[] = update_sql('CREATE TABLE {page_title} (
nid INT NOT NULL,
page_title VARCHAR(255) NOT NULL,
PRIMARY KEY (nid)
) /*!40100 DEFAULT CHARACTER SET utf8 */;');
$items[] = update_sql('INSERT INTO {page_title} (nid, page_title)
SELECT nid, page_title FROM {page_title_temp}');
$items[] = update_sql('DROP TABLE {page_title_temp}');
}
return $items;
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@
* to the node title.
*/
/**
* Implementation of hook_help().
*/
......@@ -37,6 +38,7 @@ function page_title_help($section) {
return $output;
}
/**
* Implementation of hook_perm().
*/
......@@ -44,42 +46,55 @@ function page_title_perm() {
return array('set page title', 'administer page titles');
}
/**
* Implementation of hook_menu().
*/
function page_title_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/content/page_title',
'title' => t('Page titles'),
'description' => t('Enhanced control over the page titles (in the <head> tag).'),
'callback' => 'drupal_get_form',
'callback arguments' => array('page_title_admin_settings'),
'access' => user_access('administer page titles'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'admin/content/page_title/settings',
'title' => t('Default settings'),
'description' => t('Control the page title settings.'),
'access' => user_access('administer page titles'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items[] = array(
'path' => 'admin/content/page_title/types',
'title' => t('Content type settings'),
'description' => t('Control the display of the Page title field.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('page_title_admin_types'),
'access' => user_access('administer page titles'),
'type' => MENU_LOCAL_TASK,
);
}
function page_title_menu() {
$items['admin/content/page_title'] = array(
'title' => t('Page titles'),
'description' => t('Enhanced control over the page titles (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,
);
$items['admin/content/page_title/settings'] = array(
'title' => t('Default settings'),
'description' => t('Control the page title settings.'),
'access callback' => 'user_access',
'access arguments' => array('administer page titles'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/content/page_title/types'] = array(
'title' => t('Content type settings'),
'description' => t('Control the display of the Page title field.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('page_title_admin_types'),
'access callback' => 'user_access',
'access arguments' => array('administer page titles'),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* Implementation of hook_theme
*/
function page_title_theme() {
return array(
'page_title_admin_settings' => array(
'template' => 'pt-admin-settings-form',
'arguments' => array('form' => NULL),
),
);
}
/**
* Displays the form for the standard settings tab.
*
......@@ -87,12 +102,15 @@ function page_title_menu($may_cache) {
* array A structured array for use with Forms API.
*/
function page_title_admin_settings() {
//Define the titles
$form['title']['page_title_default'] = array('#type' => 'markup', '#value' => 'Default Pattern');
$form['title']['page_title_front'] = array('#type' => 'markup', '#value' => 'Frontpage Pattern');
//Define the 'default' token patterns
$form['pattern']['page_title_default'] = array('#type' => 'textfield', '#default_value' => variable_get('page_title_default', '[page-title] | [site-name]'), '#maxlength' => 128, '#description' => t('This is the pattern used in a situation where a pattern is not defined specifically for a content type below.'));
$form['pattern']['page_title_front'] = array('#type' => 'textfield', '#default_value' => variable_get('page_title_front', '[site-name] | [site-slogan]'), '#maxlength' => 128, '#description' => t('This is the frontpage pattern.'));
//Definate the patterns per-node-type
$types = node_get_types();
foreach ($types as $type) {
$key = 'page_title_type_' . $type->type;
......@@ -100,27 +118,12 @@ function page_title_admin_settings() {
$form['pattern'][$key] = array('#type' => 'textfield', '#default_value' => variable_get($key, ''), '#maxlength' => 128, '#description' => t('If left blank, will inherit from default settings.'));
}
return system_settings_form($form);
}
function theme_page_title_admin_settings($form) {
$output = '';
$rows = array();
foreach (element_children($form['title']) as $key) {
$row = array();
$row[] = drupal_render($form['title'][$key]);
$row[] = drupal_render($form['pattern'][$key]);
$rows[] = $row;
}
$output = theme_table(array('Page Type', 'Pattern'), $rows);
//Add the system buttons to the form
$form = system_settings_form($form);
$output .= drupal_render($form);
return $output;
//Overide the theme function back to our own one
$form['#theme'] = 'page_title_admin_settings';
return $form;
}
......@@ -147,6 +150,7 @@ function page_title_admin_types() {
return system_settings_form($form);
}
/**
* Implementation of hook_node_type().
*
......@@ -185,13 +189,18 @@ function page_title_node_type($op, $info) {
}
}
/**
* Implementation of hook_form_alter().
*/
function page_title_form_alter($form_id, &$form) {
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;
$display = variable_get('page_title_display', array());
if ($form['#id'] == 'node-form' && user_access('set page title') && $display[$form['type']['#value']]) {
//Check we're editing a node form and also check that the node type 'value' is enabled
if ($form['#id'] == 'node-form' && $display[$form['type']['#value']]) {
$form['page_title'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
......@@ -204,6 +213,7 @@ function page_title_form_alter($form_id, &$form) {
}
}
/**
* Implementation of hook_nodeapi().
*/
......@@ -260,6 +270,7 @@ function page_title_node_get_title($nid) {
return db_result(db_query('SELECT page_title FROM {page_title} WHERE nid = %d', $nid));
}
/**
* Determines what title should be sent to the page template.
*
......@@ -304,6 +315,7 @@ function page_title_page_get_title() {
return $title;
}
/**
* Implementation of hook_token_values
*
......@@ -323,6 +335,7 @@ function page_title_token_values($type) {
return $values;
}
/**
* Implementation of hook_token_list
*
......
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