Commit 9e43afad authored by Dries's avatar Dries

- Patch by Matt: made it possible to alias an URL multiple times.
parent bbb41d0f
......@@ -394,8 +394,7 @@ CREATE TABLE url_alias (
src varchar(128) NOT NULL default '',
dst varchar(128) NOT NULL default '',
PRIMARY KEY (pid),
UNIQUE KEY dst (dst),
UNIQUE KEY src (src)
UNIQUE KEY dst (dst)
) TYPE=MyISAM;
--
......
......@@ -407,7 +407,6 @@ CREATE TABLE url_alias (
src varchar(128) NOT NULL default '',
PRIMARY KEY (pid)
);
CREATE INDEX url_alias_src_idx ON url_alias(src);
CREATE INDEX url_alias_dst_idx ON url_alias(dst);
--
-- Table structure for permission
......
......@@ -63,7 +63,8 @@
"2004-06-18" => "update_89",
"2004-06-27" => "update_90",
"2004-06-30" => "update_91",
"2004-07-07" => "update_92"
"2004-07-07" => "update_92",
"2004-07-10" => "update_93",
);
function update_32() {
......@@ -1149,6 +1150,17 @@ function update_92() {
return $ret;
}
function update_93() {
$ret = array();
if ($GLOBALS['db_type'] == 'pgsql') {
$ret[] = update_sql('DROP INDEX url_alias_src_idx');
}
else {
$ret[] = update_sql('ALTER TABLE {url_alias} DROP INDEX src');
}
return $ret;
}
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);
......
......@@ -9,9 +9,9 @@ function path_help($section) {
case 'admin/modules#description':
return t('Enables users to rename URLs.');
case 'admin/path':
return t("Drupal provides users complete control over URLs through aliasing. This feature is typically used to make URLs human-readable or easy to remember. For example, one could map the relative URL 'node/1' onto 'about'.");
return t("Drupal provides users complete control over URLs through aliasing. This feature is typically used to make URLs human-readable or easy to remember. For example, one could map the relative URL 'node/1' onto 'about'. Each system path can have multiple aliases.");
case 'admin/path/add':
return t('Enter the path you wish to create the alias for, followed by the name of the new alias. Each path can be associated with only one alias.');
return t('Enter the path you wish to create the alias for, followed by the name of the new alias.');
case 'admin/help#path':
return t("
<h3>Background</h3>
......@@ -26,7 +26,14 @@ function path_help($section) {
node/3 => contact
</pre>
<p>This functionality integrates seamlessly into node forms and also provides the administrator an interface to view all aliases that have been created.</p>
<p>Aliases have a 1 to 1 relationship with their original Drupal URLs. In other words you cannot have an alias map to more than one path. Likewise, a Drupal URL can't be mapped to more than one alias.</p>
<p>Aliases have a many to one relationship with their original Drupal URLs. In other words you can have many different aliases map to a single path. An example of where a multiple aliases come in handy is creating a standard RSS feed URL:</p>
<pre>
node/feed => rss.xml
node/feed => index.rdf
</pre>
<p>When Drupal generates links for a path with multiple aliases it will choose the first alias created per system URL. So in our above example, Drupal would use rss.xml as the default alias rather than index.rdf. To change this behavior, delete the aliases for node/feed and create the index.rdf alias before rss.xml.</p>
<h3>Permissions</h3>
<p>Two permissions are related to URL aliasing: <em>create url aliases</em> and <em>administer url aliases</em>.</p>
......@@ -87,18 +94,18 @@ function path_admin() {
*/
function path_admin_edit($pid = 0) {
if ($_POST['op'] == t('Create new alias') || $_POST['op'] == t('Update alias')) {
path_save($_POST['edit']);
$output = path_save($_POST['edit']);
}
else {
if ($pid) {
elseif ($pid) {
$alias = path_load($pid);
$title = $alias['dst'];
$output = path_form(path_load($pid));
}
else {
$output = path_form();
}
print theme('page', $output);
}
print theme('page', $output, $title);
}
/**
......@@ -119,7 +126,7 @@ function path_admin_help() {
/**
* Set an aliased path for a given Drupal path, preventing duplicates.
*/
function path_set_alias($path = NULL, $alias = NULL) {
function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) {
if ($path && !$alias) {
db_query("DELETE FROM {url_alias} WHERE src = '%s'", $path);
drupal_rebuild_path_map();
......@@ -137,8 +144,13 @@ function path_set_alias($path = NULL, $alias = NULL) {
db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias);
drupal_rebuild_path_map();
}
else if ($path_count == 1 && $alias_count == 0) {
db_query("UPDATE {url_alias} SET dst = '%s' WHERE src = '%s'", $alias, $path);
else if ($path_count >= 1 && $alias_count == 0) {
if ($pid) {
db_query("UPDATE {url_alias} SET dst = '%s', src = '%s' WHERE pid = %d", $alias, $path, $pid);
}
else {
db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias);
}
drupal_rebuild_path_map();
}
else if ($path_count == 0 && $alias_count == 1) {
......@@ -159,7 +171,7 @@ function path_set_alias($path = NULL, $alias = NULL) {
*/
function path_form($edit = '') {
$form .= form_textfield(t('Existing path'), 'src', $edit['src'], 50, 64, t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/page/or/1,2.'));
$form .= form_textfield(t('Existing system path'), 'src', $edit['src'], 50, 64, t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/page/or/1,2.'));
$form .= form_textfield(t('New path alias'), 'dst', $edit['dst'], 50, 64, t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
if ($edit['pid']) {
......@@ -206,7 +218,11 @@ function path_nodeapi(&$node, $op, $arg) {
break;
case 'form pre':
return form_textfield(t('Path alias'), 'path', $node->path, 60, 250, t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
$output = form_textfield(t('Path alias'), 'path', $node->path, 60, 250, t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
if ($node->path) {
$output .= form_hidden('pid', db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $node->path)));
}
return $output;
case 'insert':
// Don't try to insert if path is NULL. We may have already set
......@@ -216,7 +232,7 @@ function path_nodeapi(&$node, $op, $arg) {
}
break;
case 'update':
path_set_alias("node/$node->nid", $node->path);
path_set_alias("node/$node->nid", $node->path, $node->pid);
break;
case 'delete':
......@@ -243,7 +259,7 @@ function path_overview() {
$sql = 'SELECT * FROM {url_alias}';
$header = array(
array('data' => t('alias'), 'field' => 'dst', 'sort' => 'asc'),
array('data' => t('normal'), 'field' => 'src'),
array('data' => t('system'), 'field' => 'src'),
array('data' => t('operations'), 'colspan' => 2)
);
$sql .= tablesort_sql($header);
......@@ -288,11 +304,7 @@ function path_save($edit) {
$pid = $edit['pid'];
if (!valid_url($src)) {
form_set_error('src', t('the normal path "%src" is invalid.', array('%src' => $src)));
}
if (db_result(db_query("SELECT COUNT(src) FROM {url_alias} WHERE pid != %d AND src = '%s'", $pid, $src))) {
form_set_error('src', t('the normal path "%src" is already aliased.', array('%src' => $src)));
form_set_error('src', t('the system path "%src" is invalid.', array('%src' => $src)));
}
if (!valid_url($dst)) {
......@@ -307,16 +319,7 @@ function path_save($edit) {
return path_form($edit);
}
else {
// Normally, you would use path_set_alias() to update the paths table,
// but this is a special case. We want to modify a specific row and the only
// way to do that is with pid.
if ($pid) {
db_query("UPDATE {url_alias} SET src = '%s', dst = '%s' WHERE pid = %d", $src, $dst, $pid);
}
else {
path_set_alias($src, $dst);
}
path_set_alias($src, $dst, $pid);
drupal_set_message(t('the alias has been saved.'));
drupal_goto('admin/path');
......
......@@ -9,9 +9,9 @@ function path_help($section) {
case 'admin/modules#description':
return t('Enables users to rename URLs.');
case 'admin/path':
return t("Drupal provides users complete control over URLs through aliasing. This feature is typically used to make URLs human-readable or easy to remember. For example, one could map the relative URL 'node/1' onto 'about'.");
return t("Drupal provides users complete control over URLs through aliasing. This feature is typically used to make URLs human-readable or easy to remember. For example, one could map the relative URL 'node/1' onto 'about'. Each system path can have multiple aliases.");
case 'admin/path/add':
return t('Enter the path you wish to create the alias for, followed by the name of the new alias. Each path can be associated with only one alias.');
return t('Enter the path you wish to create the alias for, followed by the name of the new alias.');
case 'admin/help#path':
return t("
<h3>Background</h3>
......@@ -26,7 +26,14 @@ function path_help($section) {
node/3 => contact
</pre>
<p>This functionality integrates seamlessly into node forms and also provides the administrator an interface to view all aliases that have been created.</p>
<p>Aliases have a 1 to 1 relationship with their original Drupal URLs. In other words you cannot have an alias map to more than one path. Likewise, a Drupal URL can't be mapped to more than one alias.</p>
<p>Aliases have a many to one relationship with their original Drupal URLs. In other words you can have many different aliases map to a single path. An example of where a multiple aliases come in handy is creating a standard RSS feed URL:</p>
<pre>
node/feed => rss.xml
node/feed => index.rdf
</pre>
<p>When Drupal generates links for a path with multiple aliases it will choose the first alias created per system URL. So in our above example, Drupal would use rss.xml as the default alias rather than index.rdf. To change this behavior, delete the aliases for node/feed and create the index.rdf alias before rss.xml.</p>
<h3>Permissions</h3>
<p>Two permissions are related to URL aliasing: <em>create url aliases</em> and <em>administer url aliases</em>.</p>
......@@ -87,18 +94,18 @@ function path_admin() {
*/
function path_admin_edit($pid = 0) {
if ($_POST['op'] == t('Create new alias') || $_POST['op'] == t('Update alias')) {
path_save($_POST['edit']);
$output = path_save($_POST['edit']);
}
else {
if ($pid) {
elseif ($pid) {
$alias = path_load($pid);
$title = $alias['dst'];
$output = path_form(path_load($pid));
}
else {
$output = path_form();
}
print theme('page', $output);
}
print theme('page', $output, $title);
}
/**
......@@ -119,7 +126,7 @@ function path_admin_help() {
/**
* Set an aliased path for a given Drupal path, preventing duplicates.
*/
function path_set_alias($path = NULL, $alias = NULL) {
function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) {
if ($path && !$alias) {
db_query("DELETE FROM {url_alias} WHERE src = '%s'", $path);
drupal_rebuild_path_map();
......@@ -137,8 +144,13 @@ function path_set_alias($path = NULL, $alias = NULL) {
db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias);
drupal_rebuild_path_map();
}
else if ($path_count == 1 && $alias_count == 0) {
db_query("UPDATE {url_alias} SET dst = '%s' WHERE src = '%s'", $alias, $path);
else if ($path_count >= 1 && $alias_count == 0) {
if ($pid) {
db_query("UPDATE {url_alias} SET dst = '%s', src = '%s' WHERE pid = %d", $alias, $path, $pid);
}
else {
db_query("INSERT INTO {url_alias} (src, dst) VALUES ('%s', '%s')", $path, $alias);
}
drupal_rebuild_path_map();
}
else if ($path_count == 0 && $alias_count == 1) {
......@@ -159,7 +171,7 @@ function path_set_alias($path = NULL, $alias = NULL) {
*/
function path_form($edit = '') {
$form .= form_textfield(t('Existing path'), 'src', $edit['src'], 50, 64, t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/page/or/1,2.'));
$form .= form_textfield(t('Existing system path'), 'src', $edit['src'], 50, 64, t('Specify the existing path you wish to alias. For example: node/28, forum/1, taxonomy/page/or/1,2.'));
$form .= form_textfield(t('New path alias'), 'dst', $edit['dst'], 50, 64, t('Specify an alternative path by which this data can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
if ($edit['pid']) {
......@@ -206,7 +218,11 @@ function path_nodeapi(&$node, $op, $arg) {
break;
case 'form pre':
return form_textfield(t('Path alias'), 'path', $node->path, 60, 250, t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
$output = form_textfield(t('Path alias'), 'path', $node->path, 60, 250, t('Optionally specify an alternative URL by which this node can be accessed. For example, type "about" when writing an about page. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'));
if ($node->path) {
$output .= form_hidden('pid', db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $node->path)));
}
return $output;
case 'insert':
// Don't try to insert if path is NULL. We may have already set
......@@ -216,7 +232,7 @@ function path_nodeapi(&$node, $op, $arg) {
}
break;
case 'update':
path_set_alias("node/$node->nid", $node->path);
path_set_alias("node/$node->nid", $node->path, $node->pid);
break;
case 'delete':
......@@ -243,7 +259,7 @@ function path_overview() {
$sql = 'SELECT * FROM {url_alias}';
$header = array(
array('data' => t('alias'), 'field' => 'dst', 'sort' => 'asc'),
array('data' => t('normal'), 'field' => 'src'),
array('data' => t('system'), 'field' => 'src'),
array('data' => t('operations'), 'colspan' => 2)
);
$sql .= tablesort_sql($header);
......@@ -288,11 +304,7 @@ function path_save($edit) {
$pid = $edit['pid'];
if (!valid_url($src)) {
form_set_error('src', t('the normal path "%src" is invalid.', array('%src' => $src)));
}
if (db_result(db_query("SELECT COUNT(src) FROM {url_alias} WHERE pid != %d AND src = '%s'", $pid, $src))) {
form_set_error('src', t('the normal path "%src" is already aliased.', array('%src' => $src)));
form_set_error('src', t('the system path "%src" is invalid.', array('%src' => $src)));
}
if (!valid_url($dst)) {
......@@ -307,16 +319,7 @@ function path_save($edit) {
return path_form($edit);
}
else {
// Normally, you would use path_set_alias() to update the paths table,
// but this is a special case. We want to modify a specific row and the only
// way to do that is with pid.
if ($pid) {
db_query("UPDATE {url_alias} SET src = '%s', dst = '%s' WHERE pid = %d", $src, $dst, $pid);
}
else {
path_set_alias($src, $dst);
}
path_set_alias($src, $dst, $pid);
drupal_set_message(t('the alias has been saved.'));
drupal_goto('admin/path');
......
......@@ -17,11 +17,21 @@ function tracker_help($section) {
* Implementation of hook_menu().
*/
function tracker_menu() {
global $user;
$items = array();
$items[] = array('path' => 'tracker', 'title' => t('recent posts'),
'callback' => 'tracker_page',
'access' => user_access('access content'),
'callback' => 'tracker_page', 'access' => user_access('access content'),
'weight' => 1);
// Tabs:
if ($user->uid) {
$items[] = array('path' => 'tracker/all', 'title' => t('all recent posts'),
'type' => MENU_DEFAULT_LOCAL_TASK);
$items[] = array('path' => "tracker/$user->uid", 'title' => t('my recent posts'),
'type' => MENU_LOCAL_TASK);
}
return $items;
}
......@@ -33,13 +43,6 @@ function tracker_page($uid = 0) {
$output .= '';
if ($user->uid) {
$output .= '<ul>';
$output .= ' <li>'. l(t('My active posts and discussions'), "tracker/$user->uid") .'</li>';
$output .= ' <li>'. l(t('All active posts and discussions'), 'tracker') .'</li>';
$output .= '</ul>';
}
if ($uid) {
$uid = check_query($uid);
......
......@@ -17,11 +17,21 @@ function tracker_help($section) {
* Implementation of hook_menu().
*/
function tracker_menu() {
global $user;
$items = array();
$items[] = array('path' => 'tracker', 'title' => t('recent posts'),
'callback' => 'tracker_page',
'access' => user_access('access content'),
'callback' => 'tracker_page', 'access' => user_access('access content'),
'weight' => 1);
// Tabs:
if ($user->uid) {
$items[] = array('path' => 'tracker/all', 'title' => t('all recent posts'),
'type' => MENU_DEFAULT_LOCAL_TASK);
$items[] = array('path' => "tracker/$user->uid", 'title' => t('my recent posts'),
'type' => MENU_LOCAL_TASK);
}
return $items;
}
......@@ -33,13 +43,6 @@ function tracker_page($uid = 0) {
$output .= '';
if ($user->uid) {
$output .= '<ul>';
$output .= ' <li>'. l(t('My active posts and discussions'), "tracker/$user->uid") .'</li>';
$output .= ' <li>'. l(t('All active posts and discussions'), 'tracker') .'</li>';
$output .= '</ul>';
}
if ($uid) {
$uid = check_query($uid);
......
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