Commit 7ec28364 authored by Nicholas Thompson's avatar Nicholas Thompson
Browse files

Fixes for coder module to bring Page Title to better Drupal 6 compatibility

parent 7a5b865e
......@@ -5,7 +5,6 @@ foreach (element_children($form['title']) as $key) {
$row = array();
$row[] = drupal_render($form['title'][$key]);
$row[] = drupal_render($form['pattern'][$key]);
$rows[] = $row;
}
......
<?php
// $Id$
/**
* @file
* The install file for Page Title allows the module to install (and uninstall) itself. This is required as this module uses its own table.
*/
/**
* Implementation of hook_install().
*/
......@@ -26,10 +31,10 @@ function page_title_schema() {
* Implementation of hook_uninstall().
*/
function page_title_uninstall() {
db_query('DROP TABLE {page_title}');
drupal_uninstall_schema('page_title');
variable_del('page_title_individual');
variable_del('page_title_front');
foreach (node_get_types('names') AS $type => $name) {
variable_del("page_title_display_$type");
}
}
\ No newline at end of file
}
......@@ -15,11 +15,11 @@
/**
* Implementation of hook_help().
*/
function page_title_help($section) {
switch ($section) {
function page_title_help($path, $arg) {
switch ($path) {
case 'admin/help#page_title':
$output = t('<p>Provides control over the &lt;title> element on a page using token patterns and an optional textfield to override the node title.</p>');
$output .= t('<p>Below are all the tokens you can use with <strong><em>Page Title</em></strong>:</p>');
$output = '<p>'. t('Provides control over the &lt;title> element on a page using token patterns and an optional textfield to override the node title.') .'</p>';
$output .= '<p>'. t('Below are all the tokens you can use with <strong><em>Page Title</em></strong>:') .'</p>';
$output .= theme('token_help');
break;
case 'admin/content/page_title':
......@@ -32,7 +32,7 @@ function page_title_help($section) {
<p><code>[page-title]</code> will default to the value returned from <code>drupal_get_title</code> if there is no overriden page title.</p>");
break;
case 'admin/content/page_title/types':
$output = t("<p>To display a 'Page Title' field on a node (just below the 'Title' field), you will need to enable it for the appropriate content types below.</p>");
$output = '<p>'. t('To display a <em>Page Title</em> field on a node (just below the <em>Title</em> field), you will need to enable it for the appropriate content types below.') .'</p>';
break;
}
return $output;
......@@ -51,9 +51,11 @@ function page_title_perm() {
* Implementation of hook_menu().
*/
function page_title_menu() {
$items = array();
$items['admin/content/page_title'] = array(
'title' => t('Page titles'),
'description' => t('Enhanced control over the page titles (in the &lt;head&gt; tag).'),
'title' => 'Page titles',
'description' => 'Enhanced control over the page titles (in the &lt;head&gt; tag).',
'page callback' => 'drupal_get_form',
'page arguments' => array('page_title_admin_settings'),
'access callback' => 'user_access',
......@@ -61,16 +63,16 @@ function page_title_menu() {
'type' => MENU_NORMAL_ITEM,
);
$items['admin/content/page_title/settings'] = array(
'title' => t('Default settings'),
'description' => t('Control the page title settings.'),
'title' => 'Default settings',
'description' => '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.'),
'title' => 'Content type settings',
'description' => 'Control the display of the Page title field.',
'page callback' => 'drupal_get_form',
'page arguments' => array('page_title_admin_types'),
'access callback' => 'user_access',
......@@ -83,7 +85,7 @@ function page_title_menu() {
/**
* Implementation of hook_theme
* Implementation of hook_theme().
*/
function page_title_theme() {
return array(
......@@ -109,22 +111,22 @@ 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;
$key = 'page_title_type_'. $type->type;
$form['title'][$key] = array('#type' => 'markup', '#value' => t('Pattern for %type', array('%type' => $type->name)), );
$form['pattern'][$key] = array('#type' => 'textfield', '#default_value' => variable_get($key, ''), '#maxlength' => 128, '#description' => t('If left blank, will inherit from default settings.'));
}
//Add the system buttons to the form
$form = system_settings_form($form);
//Overide the theme function back to our own one
$form['#theme'] = 'page_title_admin_settings';
return $form;
......@@ -164,7 +166,7 @@ function page_title_node_type($op, $info) {
if ($op == 'update' && !empty($info->old_type) and $info->type != $info->old_type) {
//Get the display settings for node types
$display = variable_get('page_title_display', array());
//If the old one is set, set the new one
if ($display[$info->old_type]) {
$display[$info->type] = $info->type;
......@@ -173,23 +175,23 @@ function page_title_node_type($op, $info) {
else {
$display[$info->type] = 0;
}
//Unset the old type
unset($display[$info->old_type]);
//Save the settings
variable_set('page_title_display', $display);
//Get the old pattern, if set
$old_pattern = variable_get('page_title_type_' . $info->old_type, '');
$old_pattern = variable_get('page_title_type_'. $info->old_type, '');
//If it was set then set the new one to whatever the old pattern was
if (!empty($old_pattern)) {
variable_set('page_title_type_' . $info->type, $old_pattern);
variable_set('page_title_type_'. $info->type, $old_pattern);
}
//Delete the old pattern
variable_del('page_title_type_' . $info->old_type);
variable_del('page_title_type_'. $info->old_type);
}
}
......@@ -200,9 +202,9 @@ function page_title_node_type($op, $info) {
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());
//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(
......@@ -227,7 +229,7 @@ function page_title_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
db_query("DELETE FROM {page_title} WHERE nid = %d", $node->nid);
// fallthrough to insert intentional!
case 'insert':
if (isset($node->page_title) && strlen(trim($node->page_title)) > 0) {
if (isset($node->page_title) && drupal_strlen(trim($node->page_title)) > 0) {
db_query("INSERT INTO {page_title} VALUES (%d, '%s')", $node->nid, $node->page_title);
}
break;
......@@ -249,8 +251,8 @@ function page_title_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
*/
function page_title_get_title() {
$display_options = variable_get('page_title_display', array());
$node = ((arg(0) == 'node') && (is_numeric(arg(1)))) ? node_load(arg(1)) : NULL;
$node = ((arg(0) == 'node') && (is_numeric(arg(1)))) ? menu_get_object() : NULL;
if ($display_options[$node->type] && !empty($node->page_title)) {
return check_plain(strip_tags($node->page_title));
}
......@@ -296,16 +298,16 @@ function page_title_page_get_title() {
//Otherwise this is a non-frontpage page title.
else {
//Get the node for this page
$node = ((arg(0) == 'node') && (is_numeric(arg(1)))) ? node_load(arg(1)) : NULL;
$node = ((arg(0) == 'node') && (is_numeric(arg(1)))) ? menu_get_object() : NULL;
//Get the pattern for the node type. If no node type available, assume blank
$page_title_pattern = variable_get('page_title_type_' . (isset($node->type) ? $node->type : ''), '');
$page_title_pattern = variable_get('page_title_type_'. (isset($node->type) ? $node->type : ''), '');
//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]');
}
// Return the title using the node scope if node is set, otherwise default to global scope.
if (isset($node)) {
$title = token_replace($page_title_pattern, 'node', $node);
......@@ -315,37 +317,37 @@ function page_title_page_get_title() {
}
}
}
return $title;
}
/**
* Implementation of hook_token_values
* 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();
}
return $values;
}
/**
* Implementation of hook_token_list
* 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.
*/
......@@ -355,13 +357,13 @@ function page_title_token_list($type = 'all') {
if ($type == 'global' || $type == 'all') {
$tokens['global']['page-title'] = t("The page title.");
}
return $tokens;
}
/**
* Implementation of hook_preprocess_page
* Implementation of hook_preprocess_page().
*/
function page_title_preprocess_page(&$vars) {
$vars['head_title'] = page_title_page_get_title();
......
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