** Replace two or more sequential slashes with only one slashes.
*/
$path=preg_replace("'//*'","/",$path);
/*
** Remove beginning and trailing slashes.
*/
$path=trim($path,"/");
return$path;
functionpath_set_alias($path=NULL,$alias=NULL){
if($path&&!$alias){
db_query("DELETE FROM {path} WHERE src = '%s'",$path);
drupal_rebuild_path_map();
}
elseif(!$path&&$alias){
db_query("DELETE FROM {path} WHERE dst = '%s'",$alias);
drupal_rebuild_path_map();
}
elseif($path&&$alias){
$path_count=db_result(db_query("SELECT COUNT(src) FROM {path} WHERE src = '%s'",$path));
$alias_count=db_result(db_query("SELECT COUNT(dst) FROM {path} WHERE dst = '%s'",$alias));
// We have an insert:
if($path_count==0&&$alias_count==0){
db_query("INSERT INTO {path} SET src = '%s', dst = '%s'",$path,$alias);
drupal_rebuild_path_map();
}
elseif($path_count==1&&$alias_count==0){
db_query("UPDATE {path} SET dst = '%s' WHERE src = '%s'",$alias,$path);
drupal_rebuild_path_map();
}
elseif($path_count==0&&$alias_count==1){
db_query("UPDATE {path} SET src = '%s' WHERE dst = '%s'",$path,$alias);
drupal_rebuild_path_map();
}
elseif($path_count==1&&$alias_count==1){
// This will delete the path that alias was originally pointing to:
path_set_alias(NULL,$alias);
path_set_alias($path);
path_set_alias($path,$alias);
}
}
}
functionpath_confirm_delete($id){
$path=get_path_from_id($id);
functionpath_form($edit="",$error=""){
$form.=form_hidden("confirm",1);
$form.=form_hidden("pid",$id);
$form.=form_hidden("src",$path->src);
$form.=form_hidden("dst",$path->dst);
$form.=form_submit(t("Delete"));
$form.=form_submit(t("Cancel"));
if($error){
foreach($erroras$message){
$form.=theme("theme_error",$message);
}
}
returnform(form_item(t("Delete alias '%dst' that maps to '%src'",array("%dst"=>$path->dst,"%src"=>$path->src)),$form,t("Are you sure you want to delete this alias?")));
}
$form.=form_textfield(t("Existing path"),"src",$edit["src"],50,64,t("Specify the existing path you wish to alias. For example: node/view/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."));
functionpath_delete($pid){
returndb_query("DELETE FROM {path} WHERE pid = '%d'",$pid);
if($edit["pid"]){
$form.=form_hidden("pid",$edit["pid"]);
$form.=form_submit(t("Update alias"));
}
else{
$form.=form_submit(t("Create new alias"));
}
returnform($form);
}
functionpath_help($section="admin/path/help"){
...
...
@@ -102,61 +115,89 @@ function path_help($section = "admin/path/help") {
case"admin/system/modules":
$output="Enables users to create custom URLs.";
break;
case"admin/system/modules/path":
$output="Documentation yet to be written.";
case"admin/path":
$output="Drupal provides users complete control over URLs through aliasing. While the original Drupal URLs are always created and accessible, advanced users have the option to override these normal paths.";
break;
case"admin/path/add":
$output="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.";
break;
case"admin/path/help":
$output="Documentation yet to be written.";
$output.="<h3>Background</h3><p>URL aliasing gives users the ability to have control over all Drupal paths. This functionality will integrate seamlessly into node forms and also provide 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 otherwards 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>";
$output.="<h3>Permissions</h3><p>Two new permissions are introduced for aliasing URLs: <i>create url aliases</i> and <i>administer url aliases</i>.</p>";
$output.="<ol><li><b>create url aliases</b> - Allows users to create aliases for nodes. Enabling this permission will display a new path field to the user in any node form, allowing them to enter an alias for that node. They will be able to edit/delete the alias after it is created using the same form.</li><li><b>administer url aliases</b> - Allows users to access the alias administration interface. They must also have the <i>access administration pages</i> permission set as well. This interface displays all aliases and provides a way to create and modify them as well. This is also the location to build aliases for things other than nodes. For example, you can create an alias for a taxonomy URL or even re-map the admin path (although the original admin path will still be accessible since aliases do not cancel out original paths).</li></ol>";
break;
}
returnt($output);
}
functionpath_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/view/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."));
returnform_textfield(t("Path alias"),"path",$edit["path"],60,250,$error["path"]?$error["path"]: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."));
** Replace two or more sequential slashes with only one slashes.
*/
$path=preg_replace("'//*'","/",$path);
/*
** Remove beginning and trailing slashes.
*/
$path=trim($path,"/");
return$path;
functionpath_set_alias($path=NULL,$alias=NULL){
if($path&&!$alias){
db_query("DELETE FROM {path} WHERE src = '%s'",$path);
drupal_rebuild_path_map();
}
elseif(!$path&&$alias){
db_query("DELETE FROM {path} WHERE dst = '%s'",$alias);
drupal_rebuild_path_map();
}
elseif($path&&$alias){
$path_count=db_result(db_query("SELECT COUNT(src) FROM {path} WHERE src = '%s'",$path));
$alias_count=db_result(db_query("SELECT COUNT(dst) FROM {path} WHERE dst = '%s'",$alias));
// We have an insert:
if($path_count==0&&$alias_count==0){
db_query("INSERT INTO {path} SET src = '%s', dst = '%s'",$path,$alias);
drupal_rebuild_path_map();
}
elseif($path_count==1&&$alias_count==0){
db_query("UPDATE {path} SET dst = '%s' WHERE src = '%s'",$alias,$path);
drupal_rebuild_path_map();
}
elseif($path_count==0&&$alias_count==1){
db_query("UPDATE {path} SET src = '%s' WHERE dst = '%s'",$path,$alias);
drupal_rebuild_path_map();
}
elseif($path_count==1&&$alias_count==1){
// This will delete the path that alias was originally pointing to:
path_set_alias(NULL,$alias);
path_set_alias($path);
path_set_alias($path,$alias);
}
}
}
functionpath_confirm_delete($id){
$path=get_path_from_id($id);
functionpath_form($edit="",$error=""){
$form.=form_hidden("confirm",1);
$form.=form_hidden("pid",$id);
$form.=form_hidden("src",$path->src);
$form.=form_hidden("dst",$path->dst);
$form.=form_submit(t("Delete"));
$form.=form_submit(t("Cancel"));
if($error){
foreach($erroras$message){
$form.=theme("theme_error",$message);
}
}
returnform(form_item(t("Delete alias '%dst' that maps to '%src'",array("%dst"=>$path->dst,"%src"=>$path->src)),$form,t("Are you sure you want to delete this alias?")));
}
$form.=form_textfield(t("Existing path"),"src",$edit["src"],50,64,t("Specify the existing path you wish to alias. For example: node/view/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."));
functionpath_delete($pid){
returndb_query("DELETE FROM {path} WHERE pid = '%d'",$pid);