2003-04-24 21:56:12 +00:00
<?php
2003-09-25 07:27:22 +00:00
// $Id$
2003-04-24 21:56:12 +00:00
2003-10-03 14:55:27 +00:00
function title_help($section) {
$output = "";
switch ($section) {
2003-10-07 18:16:41 +00:00
case 'admin/system/modules#description':
2003-10-03 14:55:27 +00:00
$output = t("Enables users to link to stories, articles or similar content by title.");
break;
}
return $output;
2003-04-24 21:56:12 +00:00
}
2003-11-20 21:51:23 +00:00
function title_link($type) {
if ($type == "system") {
if (user_access("access content")) {
2003-12-17 22:27:23 +00:00
menu("title", t("search"), "title_page", 0, MENU_HIDE);
2003-11-20 21:51:23 +00:00
}
}
}
2003-04-24 21:56:12 +00:00
function title_page() {
if (user_access("access content")) {
$title = urldecode(arg(1));
2003-09-09 18:18:43 +00:00
$result = db_query("SELECT n.*, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.title = '%s' AND n.status = 1 ORDER BY n.created DESC", $title);
2003-07-12 10:36:56 +00:00
2003-04-24 21:56:12 +00:00
if (db_num_rows($result) == 0) {
// No node with exact title found, try substring.
2004-02-01 17:55:11 +00:00
$result = db_query("SELECT n.*, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.title LIKE '%%%s%%' AND n.status = 1 ORDER BY n.created DESC", $title);
2003-04-28 21:36:43 +00:00
}
2003-07-12 10:36:56 +00:00
2003-04-28 21:36:43 +00:00
if (db_num_rows($result) == 0 && module_exist("search")) {
2003-04-24 21:56:12 +00:00
// still no matches ... return a full text search
search_view($title);
}
2003-04-28 21:36:43 +00:00
else if (db_num_rows($result) == 1) {
2003-04-24 21:56:12 +00:00
$node = db_fetch_object($result);
2003-06-14 16:18:40 +00:00
$node = node_load(array("nid" => $node->nid));
2003-12-07 10:28:20 +00:00
print theme("page", node_show($node, NULL), $node->title);
2003-04-28 21:36:43 +00:00
}
2003-04-24 21:56:12 +00:00
else {
$header = array(t("Type"), t("Title"), t("Author"));
while ($node = db_fetch_object($result)) {
$type = ucfirst(module_invoke($node->type, "node", "name"));
2003-09-30 17:01:34 +00:00
$title = l($node->title, "node/view/$node->nid");
2003-04-24 21:56:12 +00:00
$author = format_name($node);
$rows[] = array(array("data" => $type, "class" => "type"), array("data" => $title, "class" => "content"), array("data" => $author, "class" => "author"));
}
2003-04-28 21:36:43 +00:00
$output = "<div id=\"title\">";
2003-11-13 19:52:54 +00:00
$output .= theme("table", $header, $rows);
2003-04-24 21:56:12 +00:00
$output .= "</div>";
2003-11-23 10:41:04 +00:00
drupal_set_title(t("Matching Posts"));
2003-11-25 19:26:21 +00:00
print theme("page", $output);
2003-04-24 21:56:12 +00:00
}
}
else {
2003-11-25 19:26:21 +00:00
print theme("page", message_access());
2003-04-24 21:56:12 +00:00
}
}
2004-02-06 19:07:56 +00:00
function title_filter($op, $text = "") {
switch ($op) {
case "name":
return t("Title filter");
case "process":
return _title_filter_process($text);
case "settings":
return _title_filter_settings($text);
default:
return $text;
}
}
2003-04-24 21:56:12 +00:00
// filter [node title|description] links. '|description' is optional.
2004-02-06 19:07:56 +00:00
function _title_filter_process($text) {
2004-01-26 18:59:42 +00:00
$pattern = '\[([^\|\]]+)(?>\|?)(.*?)\]'; // $1 == title: matches at least 1 char up to the first '|' or ']'
2003-04-24 21:56:12 +00:00
// $2 == text: matches all after a following '|' (if there is) up to the next ']'. may include '|'s.
2004-01-26 18:59:42 +00:00
$replacement = 'l("$2" ? "$2" : "$1", "title/". urlencode("$1"))';
return preg_replace("/$pattern/e", $replacement, $text);
2003-04-24 21:56:12 +00:00
}
2004-02-06 19:07:56 +00:00
function _title_filter_settings() {
2004-01-26 18:59:42 +00:00
return form_group(t("Title filter"), t("Wiki-like [node title|text] links are enabled. These shortcuts generate a link labeled 'text' to the node with the title 'node title'. If you omit '|text', the label becomes 'node title'. You may use a substring of a node title if desired. When multiple matching titles are found, a list of matching nodes will be displayed. If no matching titles are found, a full-text search is returned."));
2003-04-24 21:56:12 +00:00
}
function title_compose_tips() {
2004-01-26 18:59:42 +00:00
return array(t("You may quickly link to another node using this syntax: <em>[node title|text]</em>. This will generate a link labeled 'text' to the node with the title 'node title'. If you omit '|text', the label becomes 'node title'."));
2003-04-28 21:36:43 +00:00
}
2003-04-24 21:56:12 +00:00
?>