I will place this in cvs when my account is activated, till then here it is for those who might have a use for it
This is a simple module to provide node aliases.
Note, node aliases have no visiable content, they use the content of the source node.
When defining a node alias you define a node source
Either a node id (nid)
or if the path module is enable, you can provide a path alias
Written for two primary purposes
1) Allows a node to stand alone and have it's content appear in a book
When you add a node to a book with the outline tab, it always shows as part of the book from then on (i.e. contains the book naviagation at the bottom)
We have pages that can be reached from different pages plus exist with in a book
This allows use to link to the orginal node from other nodes (pages, stories, etc) and the user sees the content without the book module naviagation.
To add to the book add an alias for the node and outline the node alias.
Now the content of the original node shows in the book and the book navigation only appears in the context of the book
2) We have cases where we want to place a single piece on content in multiple books
Create the original node (say a page)
Make an alias, outline and place in book 1
Make another alias, outline and place in book 2
WARNING: Aliased nodes show the title for the node alias (not the original node title)
Send comments to nevets@mailbag.com
Module source (sql below) place in a file called nodealias.module in the module directory
<?php
/**
* @file
* Allows module to be nodealiasd giving it an alias.
*
*/
/**
* Implementation of hook_help().
*/
function nodealias_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Enables users to make a node alias');
case 'admin/help#nodealias':
return t("Need something here");
case 'node/add/nodealias':
return variable_get('nodealias_help', '');
case 'node/add#nodealias':
return t("A node aliasd node provides an alias to a node");
}
}
/**
* Implementation of hook_node_name().
*/
function nodealias_node_name($node) {
return t('node alias');
}
/**
* Implementation of hook_perm().
*/
function nodealias_perm() {
return array('create node alias', 'edit own node alias');
}
/**
* Implementation of hook_access().
*/
function nodealias_access($op, $node) {
global $user;
if ($op == 'create') {
return user_access('create node alias');
}
if ($op == 'update' || $op == 'delete') {
if (user_access('edit own node alias') && ($user->uid == $node->uid)) {
return TRUE;
}
}
}
/**
* Implementation of hook_link().
*/
function nodealias_link($type, $node = 0, $main) {
$links = array();
if ($type == 'node' && $node->type == 'nodealias') {
// Don't display a redundant edit link if they are node administrators.
if (nodealias_access('update', $node) && !user_access('administer nodes')) {
$links[] = l(t('edit this node alias'), "node/$node->nid/edit");
}
}
else if ($type == 'node' && $node->orig_type == 'nodealias')
{
$func = $node->type . '_access';
if ( function_exists($func) )
{
if ( $func('update', $node) )
{
$links[] = l(t('edit orginal'), "node/" . nodealias_get_nid($node->node_source) . "/edit");
}
}
}
return $links;
}
/**
* Implementation of hook_menu().
*/
function nodealias_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'node/add/nodealias', 'title' => t('alert'),
'access' => nodealias_access('create', NULL));
}
return $items;
}
/**
* Loads all of the nodealias specific information when an event node is viewed.
*
* @ingroup nodealias_node
* @param &$node The node being viewed.
* @return An array of event-specific information.
*/
function nodealias_load(&$node)
{
$nodealias = db_fetch_object(db_query("SELECT * FROM {nodealias} WHERE nid = %d", $node->nid));
return $nodealias;
}
/**
* Implementation of hook_form().
*/
function nodealias_form(&$node)
{
$output = '';
$output .= form_textfield(t('Node Source'), 'node_source', $node->node_source, 32, 32, 'Node id (ex; 6) or node path if path module is enabled', NULL, TRUE);
return $output;
}
/**
* Updates the nodealias database table when event nodes are inserted.
*
* @ingroup event_node
* @param @$node The node that is being inserted.
*/
function nodealias_insert(&$node)
{
db_query("INSERT INTO {nodealias} (nid, node_source) VALUES (%d, '%s')", $node->nid, $node->node_source);
}
/**
* Updates the nodealias database table when event nodes are updated.
*
* @ingroup nodealias_node
* @param &$node The node that is being updated.
*/
function nodealias_update(&$node)
{
db_query("UPDATE {nodealias} SET node_source = '%s'", $node->node_source);
}
/**
* Deletes rows from the event database table when event nodes are deleted.
*
* @ingroup event_node
* @param &$node The node that is being deleted.
*/
function nodealias_delete(&$node) {
db_query("DELETE FROM {nodealias} WHERE nid = %d", $node->nid);
}
/**
* Prepares a nodealias for viewing.
*
* @ingroup nodealias_node
* @param &$node the event to be prepared
* @param $main whether or not the main page is requesting the node
* @param $page whether or not the event is being viewed by itself
* @return a string containing the event after it has been passed through the theme subsystem
*/
function nodealias_view(&$node, $main = 0, $page = 0)
{
$nid = nodealias_get_nid($node->node_source);
$orig_type = $node->type;
if ( $nid > 0 )
{
$nodealias = node_load(array('nid' => $nid));
if ( $nodealias )
{
nodealias_node_view($nodealias, $main, $page);
if ( $node->title == '=' )
{
$node->title = $nodealias->title;
}
foreach ( $nodealias as $field => $value )
{
if ( $field != 'nid' )
{
$node->$field = $nodealias->$field;
}
}
$node->orig_type = $orig_type;
}
else
{
$node->title = "Page Not Found";
$node->body = "";
$node->teaser = "";
return "";
}
}
else
{
$node->title = "Page Not Found";
$node->body = "";
$node->teaser = "";
return "";
}
}
function nodealias_node_view(&$node, $teaser = FALSE, $page = FALSE) {
$node = array2object($node);
// Remove the delimiter (if any) that separates the teaser from the body.
// TODO: this strips legitimate uses of '<!--break-->' also.
$node->body = str_replace('<!--break-->', '', $node->body);
// The 'view' hook can be implemented to overwrite the default function
// to display nodes.
if (node_hook($node, 'view')) {
node_invoke($node, 'view', $teaser, $page);
}
else {
$node = node_prepare($node, $teaser);
}
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', $teaser, $page);
return theme('node', $node, $teaser, $page);
}
function nodealias_get_nid($node_source)
{
if ( is_numeric($node_source) )
{
$nid = $node_source;
}
else
{
$path = drupal_get_normal_path($node_source);
if ( strpos($path, 'node/') != 0 )
{
return 0;
}
$nid = substr($path, 5);
}
return $nid;
}
?>
SQL - load into your database before enabling the module
CREATE TABLE nodealias (
nid int(10) unsigned NOT NULL default '0',
node_source text NOT NULL default '',
PRIMARY KEY (nid)
);