src); $form .= form_hidden("dst", $path->dst); $form .= form_submit(t("Delete")); $form .= form_submit(t("Cancel")); return form(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?"))); } function path_delete($pid) { return db_query("DELETE FROM {path} WHERE pid = '%d'", $pid); } function path_help($section = "admin/path/help") { switch ($section) { case "admin/system/modules": $output = "Enables users to create custom URLs."; break; case "admin/system/modules/path": $output = "Documentation yet to be written."; break; case "admin/path/help": $output = "Documentation yet to be written."; break; } return t($output); } 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/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.")); $form .= form_hidden("pid", $edit["pid"]); $form .= form_submit(t("Create new alias")); if ($edit["pid"]) { $form .= form_submit(t("Delete")); } return form($form); } function path_insert($edit) { return db_query("INSERT INTO {path} SET src = '%s', dst = '%s'", $edit["src"], $edit["dst"]); } # DELETE function path_is_unique($path, $type) { if ($type == "dst") { return !(get_src_url($path)); } elseif ($type == "src") { return !(get_url_alias($path)); } } function path_link($type, $node = NULL) { if ($type == "system" && user_access("alias urls")) { menu("admin/path", t("url aliasing"), "path_admin", "", 4); menu("admin/path/add", t("new alias"), "path_admin", ""); } } function path_perm() { return array("alias urls"); } function path_overview() { $sql = "SELECT * FROM {path}"; $header = array( array ("data" => t("alias"), "field" => "dst", "sort" => "asc"), array ("data" => t("maps to"), "field" => "src"), array("data" => t("operations"), "colspan" => 2) ); $sql .= tablesort_sql($header); $result = pager_query($sql, 50); while ($data = db_fetch_object($result)) { $rows[] = array($data->dst, $data->src, l(t("edit"), "admin/path/edit/$data->pid"), l(t("delete"), "admin/path/delete/$data->pid")); } $pager = pager_display(NULL, 50, 0, "admin", tablesort_pager()); if (!empty($pager)) { $rows[] = array(array("data" => $pager, "colspan" => 3)); } return table($header, $rows); } function path_save($edit) { $dst = path_clean($edit["dst"]); $src = path_clean($edit["src"]); if ($src == NULL || !valid_url($src)) { return t("the specified path is not valid."); } if (db_result(db_query("SELECT COUNT(src) FROM {path} WHERE src = '%s'", $src))) { return t("the specified path is already aliased."); } if ($dst == NULL || !valid_url($dst)) { return t("the specified path alias is not valid."); } if (db_result(db_query("SELECT COUNT(dst) FROM {path} WHERE dst = '%s'", $dst))) { return t("the specified alias is already in use."); } if ($edit["pid"]) { path_update($src, $dst); } else { //Update the path path_insert($edit); } return t("you may access %src via %dst.", array("%src" => url($src), "%dst" => l($dst, url($dst)))); } function path_system($field) { $system["description"] = path_help("admin/system/modules"); $system["admin_help"] = path_help("admin/system/modules/path"); return $system[$field]; } function path_update($edit) { if ($edit["pid"]) { return db_query("UPDATE {path} SET src = '%s', dst = '%s' WHERE pid = '%d'", $edit["src"], $edit["dst"], $edit["pid"]); } else { // intended for nodes return db_query("UPDATE {path} SET dst = '%s' WHERE src = '%s'", $edit["dst"], $edit["src"]); } } function get_path_from_id($id) { return db_fetch_object(db_query("SELECT * FROM {path} WHERE pid = '%d'", $id)); } ?>