<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>寱语</title>
  <subtitle>kzeng's blog</subtitle>
  <link rel="alternate" type="text/html" href="http://www.kzeng.info/node/696"/>
  <link rel="self" type="application/atom+xml" href="http://www.kzeng.info/node/696/atom/feed"/>
  <id>http://www.kzeng.info/node/696/atom/feed</id>
  <updated>2005-03-13T01:37:44-05:00</updated>
  <entry>
    <title>Node Alias模块</title>
    <link rel="alternate" type="text/html" href="http://www.kzeng.info/node/696" />
    <id>http://www.kzeng.info/node/696</id>
    <published>2005-03-13T01:36:44-05:00</published>
    <updated>2005-03-13T01:37:44-05:00</updated>
    <author>
      <name>kzeng</name>
    </author>
    <category term="drupal模块" />
    <category term="node_alias模块" />
    <category term="Drupal" />
    <summary type="html"><![CDATA[<p>
<p><?php<br />
/**<br />
* @file<br />
* Allows module to be nodealiasd giving it an alias.<br />
*<br />
*/<br />
/**<br />
* Implementation of hook_help().<br />
*/<br />
function nodealias_help($section) {<br />
switch ($section) {<br />
case 'admin/modules#description':<br />
return t('Enables users to make a node alias');<br />
case 'admin/help#nodealias':<br />
return t("Need something here");<br />
case 'node/add/nodealias':<br />
return variable_get('nodealias_help', '');<br />
case 'node/add#nodealias':<br />
return t("A node aliasd node provides an alias to a node");<br />
}<br />
}<br />
/**<br />
* Implementation of hook_node_name().<br />
*/<br />
function nodealias_node_name($node) {<br />
return t('node alias');
</p>
</p>
    ]]></summary>
    <content type="html"><![CDATA[<p><?php<br />
/**<br />
* @file<br />
* Allows module to be nodealiasd giving it an alias.<br />
*<br />
*/<br />
/**<br />
* Implementation of hook_help().<br />
*/<br />
function nodealias_help($section) {<br />
switch ($section) {<br />
case 'admin/modules#description':<br />
return t('Enables users to make a node alias');<br />
case 'admin/help#nodealias':<br />
return t("Need something here");<br />
case 'node/add/nodealias':<br />
return variable_get('nodealias_help', '');<br />
case 'node/add#nodealias':<br />
return t("A node aliasd node provides an alias to a node");<br />
}<br />
}<br />
/**<br />
* Implementation of hook_node_name().<br />
*/<br />
function nodealias_node_name($node) {<br />
return t('node alias');<br />
}<br />
/**<br />
* Implementation of hook_perm().<br />
*/<br />
function nodealias_perm() {<br />
return array('create node alias', 'edit own node alias');<br />
}<br />
/**<br />
* Implementation of hook_access().<br />
*/<br />
function nodealias_access($op, $node) {<br />
global $user;<br />
if ($op == 'create') {<br />
return user_access('create node alias');<br />
}<br />
if ($op == 'update' || $op == 'delete') {<br />
if (user_access('edit own node alias') &amp;& ($user->uid == $node->uid)) {<br />
return TRUE;<br />
}<br />
}<br />
}<br />
/**<br />
* Implementation of hook_link().<br />
*/<br />
function nodealias_link($type, $node = 0, $main) {<br />
$links = array();<br />
if ($type == 'node' &amp;& $node->type == 'nodealias') {<br />
// Don't display a redundant edit link if they are node administrators.<br />
if (nodealias_access('update', $node) &amp;& !user_access('administer nodes')) {<br />
$links[] = l(t('edit this node alias'), "node/$node->nid/edit");<br />
}<br />
}<br />
else if ($type == 'node' &amp;& $node->orig_type == 'nodealias')<br />
{<br />
$func = $node->type . '_access';<br />
if ( function_exists($func) )<br />
{<br />
if ( $func('update', $node) )<br />
{<br />
$links[] = l(t('edit orginal'), "node/" . nodealias_get_nid($node->node_source) . "/edit");<br />
}<br />
}<br />
}<br />
return $links;<br />
}<br />
/**<br />
* Implementation of hook_menu().<br />
*/<br />
function nodealias_menu($may_cache) {<br />
$items = array();<br />
if ($may_cache) {<br />
$items[] = array('path' => 'node/add/nodealias', 'title' => t('alert'),<br />
'access' => nodealias_access('create', NULL));<br />
}<br />
return $items;<br />
}<br />
/**<br />
* Loads all of the nodealias specific information when an event node is viewed.<br />
*<br />
* @ingroup nodealias_node<br />
* @param &amp;$node The node being viewed.<br />
* @return An array of event-specific information.<br />
*/<br />
function nodealias_load(&amp;$node)<br />
{<br />
$nodealias = db_fetch_object(db_query("SELECT * FROM {nodealias} WHERE nid = %d", $node->nid));<br />
return $nodealias;<br />
}<br />
/**<br />
* Implementation of hook_form().<br />
*/<br />
function nodealias_form(&amp;$node)<br />
{<br />
$output = '';<br />
$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);<br />
return $output;<br />
}<br />
/**<br />
* Updates the nodealias database table when event nodes are inserted.<br />
*<br />
* @ingroup event_node<br />
* @param @$node The node that is being inserted.<br />
*/<br />
function nodealias_insert(&amp;$node)<br />
{<br />
db_query("INSERT INTO {nodealias} (nid, node_source) VALUES (%d, '%s')", $node->nid, $node->node_source);<br />
}<br />
/**<br />
* Updates the nodealias database table when event nodes are updated.<br />
*<br />
* @ingroup nodealias_node<br />
* @param &amp;$node The node that is being updated.<br />
*/<br />
function nodealias_update(&amp;$node)<br />
{<br />
db_query("UPDATE {nodealias} SET node_source = '%s'", $node->node_source);<br />
}<br />
/**<br />
* Deletes rows from the event database table when event nodes are deleted.<br />
*<br />
* @ingroup event_node<br />
* @param &amp;$node The node that is being deleted.<br />
*/<br />
function nodealias_delete(&amp;$node) {<br />
db_query("DELETE FROM {nodealias} WHERE nid = %d", $node->nid);<br />
}<br />
/**<br />
* Prepares a nodealias for viewing.<br />
*<br />
* @ingroup nodealias_node<br />
* @param &amp;$node the event to be prepared<br />
* @param $main whether or not the main page is requesting the node<br />
* @param $page whether or not the event is being viewed by itself<br />
* @return a string containing the event after it has been passed through the theme subsystem<br />
*/<br />
function nodealias_view(&amp;$node, $main = 0, $page = 0)<br />
{<br />
$nid = nodealias_get_nid($node->node_source);<br />
$orig_type = $node->type;<br />
if ( $nid > 0 )<br />
{<br />
$nodealias = node_load(array('nid' => $nid));<br />
if ( $nodealias )<br />
{<br />
nodealias_node_view($nodealias, $main, $page);<br />
if ( $node->title == '=' )<br />
{<br />
$node->title = $nodealias->title;<br />
}<br />
foreach ( $nodealias as $field => $value )<br />
{<br />
if ( $field != 'nid' )<br />
{<br />
$node->$field = $nodealias->$field;<br />
}<br />
}<br />
$node->orig_type = $orig_type;<br />
}<br />
else<br />
{<br />
$node->title = "Page Not Found";<br />
$node->body = "";<br />
$node->teaser = "";<br />
return "";<br />
}<br />
}<br />
else<br />
{<br />
$node->title = "Page Not Found";<br />
$node->body = "";<br />
$node->teaser = "";<br />
return "";<br />
}<br />
}<br />
function nodealias_node_view(&amp;$node, $teaser = FALSE, $page = FALSE) {<br />
$node = array2object($node);<br />
// Remove the delimiter (if any) that separates the teaser from the body.<br />
// TODO: this strips legitimate uses of '' also.<br />
$node->body = str_replace('', '', $node->body);<br />
// The 'view' hook can be implemented to overwrite the default function<br />
// to display nodes.<br />
if (node_hook($node, 'view')) {<br />
node_invoke($node, 'view', $teaser, $page);<br />
}<br />
else {<br />
$node = node_prepare($node, $teaser);<br />
}<br />
// Allow modules to change $node->body before viewing.<br />
node_invoke_nodeapi($node, 'view', $teaser, $page);<br />
return theme('node', $node, $teaser, $page);<br />
}<br />
function nodealias_get_nid($node_source)<br />
{<br />
if ( is_numeric($node_source) )<br />
{<br />
$nid = $node_source;<br />
}<br />
else<br />
{<br />
$path = drupal_get_normal_path($node_source);<br />
if ( strpos($path, 'node/') != 0 )<br />
{<br />
return 0;<br />
}<br />
$nid = substr($path, 5);<br />
}<br />
return $nid;<br />
}<br />
?></p>
<p>它的SQL文件的源码如下：</p>
<p>CREATE TABLE nodealias (<br />
nid int(10) unsigned NOT NULL default '0',<br />
node_source text NOT NULL default '',<br />
PRIMARY KEY (nid)<br />
);
</p>
    ]]></content>
  </entry>
</feed>
