summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2001-04-29 12:39:55 +0000
committerDries Buytaert <dries@buytaert.net>2001-04-29 12:39:55 +0000
commitef7d5e1201df1aff7b536f798d0a53d616722be3 (patch)
tree186a328d8f1a044f554895292f77d2b310536577
parent828f36cdf1ebbf2580eb00fdfbf55701e4f86156 (diff)
downloadbrdo-ef7d5e1201df1aff7b536f798d0a53d616722be3.tar.gz
brdo-ef7d5e1201df1aff7b536f798d0a53d616722be3.tar.bz2
CHANGES:
- Added new form_* functions to common.inc, used for building forms: it should improve 'stability' (no form typos, every- thing properly escaped/unescaped) and should help providing a very consistent user interface (wrt forms). - Adjusted node.module to use the new form functions. (Can be used as an example.) - Adjusted book.module to use the new form functions. (Can be used as an example.) - Merged function.inc into common.inc! - Slowly removing all global $status and $rstatus variables: use node_status() instead. TODO: - Apart from implementing the permission system, I'll spend some time updating most modules today and tomorrow to use the new form functions.
-rw-r--r--includes/common.inc147
-rw-r--r--includes/function.inc123
-rw-r--r--includes/node.inc5
-rw-r--r--modules/book.module51
-rw-r--r--modules/book/book.module51
-rw-r--r--modules/node.module42
-rw-r--r--modules/node/node.module42
7 files changed, 217 insertions, 244 deletions
diff --git a/includes/common.inc b/includes/common.inc
index adbec64fd..b2e4c3b6c 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1,5 +1,7 @@
<?php
+$na = "<I>na</I>";
+
function conf_init() {
global $HTTP_HOST, $REQUEST_URI;
$file = strtolower(strtr($HTTP_HOST ."". substr($REQUEST_URI, 0, strrpos($REQUEST_URI, "/")), "/:", ".."));
@@ -30,13 +32,156 @@ function throttle($type, $rate) {
}
}
+
+function check_textfield($message) {
+ return strip_tags(str_replace("\"", "&quot;", stripslashes($message)));
+}
+
+function check_select($message) {
+ return check_textfield($message);
+}
+
+function check_export($message) {
+ return check_textfield($message);
+}
+
+function check_textarea($message) {
+ global $allowed_html;
+ return htmlspecialchars(strip_tags(stripslashes($message), $allowed_html));
+}
+
+function check_input($message) {
+ global $allowed_html;
+ return strip_tags(addslashes(stripslashes(substr($message, 0, variable_get(max_input_size, 10000)))), $allowed_html);
+}
+
+function check_code($message) {
+ return $message;
+}
+
+function check_mail($mail) {
+ return eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $mail) ? 1 : 0;
+}
+
+function check_name($name) {
+ return ereg("[^a-zA-Z0-9_-]", $name) ? 0 : 1;
+}
+
+function check_output($message, $nl2br = 0) {
+ global $allowed_html, $na;
+ $var = strip_tags(stripslashes(format_text($message)), $allowed_html);
+ return ($var) ? (($nl2br) ? nl2br($var) : $var) : $na;
+}
+
+function format_plural($count, $singular, $plural) {
+ return ($count == 1) ? "$count ". t($singular) : "$count ". t($plural);
+}
+
+function format_interval($timestamp) {
+ if ($timestamp >= 86400) {
+ $output .= format_plural(floor($timestamp / 86400), "day", "days");
+ $timestamp = $timestamp % 86400;
+ }
+ if ($timestamp >= 3600) {
+ $output .= " ". format_plural(floor($timestamp / 3600), "hour", "hours");
+ $timestamp = $timestamp % 3600;
+ }
+ if ($timestamp >= 60) {
+ $output .= " ". floor($timestamp / 60) ." min";
+ $timestamp = $timestamp % 60;
+ }
+ if ($timestamp > 0) {
+ $output .= " $timestamp sec";
+ }
+ return ($output) ? $output : "0 sec";
+}
+
+function format_date($timestamp, $type = "medium", $format = "") {
+ global $user;
+
+ $timestamp += ($user->timezone) ? $user->timezone - date("Z") : 0;
+
+ switch ($type) {
+ case "small":
+ $date = date("m/d/y - H:i", $timestamp);
+ break;
+ case "medium":
+ $date = t(date("l", $timestamp)) .", ". date("m/d/Y - H:i", $timestamp);
+ break;
+ case "large":
+ $date = t(date("l", $timestamp)) .", ". t(date("F", $timestamp)) ." ". date("d, Y - H:i", $timestamp);
+ break;
+ case "custom":
+ $date = date($format, $timestamp);
+ break;
+ default:
+ $date = t(date("l", $timestamp)) .", ". date("m/d/Y - H:i", $timestamp);
+ }
+ return $date;
+}
+
+function format_username($username) {
+ global $user;
+ if ($username) return (user_access($user, "account") ? "<A HREF=\"admin.php?mod=account&op=view&name=$username\">$username</A>" : "<A HREF=\"account.php?op=view&name=$username\">$username</A>");
+ else return variable_get(anonymous, "Anonymous");
+}
+
+function format_email($address) {
+ global $na;
+ return ($address) ? "<A HREF=\"mailto:$address\">$address</A>" : $na;
+}
+
+function format_url($address, $description = "") {
+ global $na;
+ $description = ($description) ? $description : $address;
+ return ($address) ? "<A HREF=\"$address\">". check_output($description) ."</A>" : $na;
+}
+
+function format_tag($link, $text) {
+ return "'<a href=\"node.php?title='. urlencode('$link') .'\">'. ('$text' ? '$text' : '$link') .'</a>'";
+}
+
+function format_text($text) {
+
+ $src = array( // "/(<\/?)(\w+)([^>]*>)/e", // convert HTML to lower case
+ "/\[\[(([^\|]*?)(\|([^\|]*?))?)\]\]/e"); // [link|description]
+ $dst = array( // "'\\1'. strtolower('\\2') .'\\3'", // convert HTML to lower case
+ format_tag('\\2', '\\4')); // [link|description]
+
+ return preg_replace($src, $dst, $text);
+}
+
+function form_item($title, $value, $description = 0) {
+ return ($description) ? "<B>$title:</B><BR>$value<BR><SMALL><I>$description</I></SMALL><P>" : "<B>$title:</B><BR>$value<P>\n";
+}
+
+function form_textfield($title, $name, $value, $size, $maxlength, $description = 0) {
+ return form_item($title, "<INPUT MAXLENGTH=\"$maxlength\" NAME=\"edit[$name]\" SIZE=\"$size\" VALUE=\"". check_textfield($value) ."\">", $description);
+}
+
+function form_textarea($title, $name, $value, $cols, $rows, $description = 0) {
+ return form_item($title, "<TEXTAREA WRAP=\"virtual\" COLS=\"$cols\" ROWS=\"$rows\" NAME=\"edit[$name]\">". check_textarea($value) ."</TEXTAREA>", $description);
+}
+
+function form_select($title, $name, $options, $value, $description = 0) {
+ foreach ($options as $key=>$choice) $select .= "<OPTION VALUE=\"$key\"". ($key == $value ? " SELECTED" : "") .">". check_select($choice) ."</OPTION>";
+ return form_item($title, "<SELECT NAME=\"edit[$name]\">$select</SELECT>", $description);
+}
+
+function form_hidden($name, $value) {
+ return "<INPUT TYPE=\"hidden\" NAME=\"edit[$name]\" VALUE=\"$value\">";
+}
+
+function form_submit($value) {
+ return "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"$value\">\n";
+}
+
$conf = conf_init();
include_once "includes/$conf.conf";
include_once "includes/structure.inc";
include_once "includes/database.inc";
include_once "includes/variable.inc";
-include_once "includes/function.inc";
include_once "includes/comment.inc";
include_once "includes/module.inc";
include_once "includes/locale.inc";
diff --git a/includes/function.inc b/includes/function.inc
deleted file mode 100644
index c61ef635c..000000000
--- a/includes/function.inc
+++ /dev/null
@@ -1,123 +0,0 @@
-<?php
-
-$na = "<I>na</I>";
-
-function check_textfield($message) {
- return strip_tags(str_replace("\"", "&quot;", stripslashes($message)));
-}
-
-function check_select($message) {
- return check_textfield($message);
-}
-
-function check_export($message) {
- return check_textfield($message);
-}
-
-function check_textarea($message) {
- global $allowed_html;
- return htmlspecialchars(strip_tags(stripslashes($message), $allowed_html));
-}
-
-function check_input($message) {
- global $allowed_html;
- return strip_tags(addslashes(stripslashes(substr($message, 0, variable_get(max_input_size, 10000)))), $allowed_html);
-}
-
-function check_code($message) {
- return $message;
-}
-
-function check_mail($mail) {
- return eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $mail) ? 1 : 0;
-}
-
-function check_name($name) {
- return ereg("[^a-zA-Z0-9_-]", $name) ? 0 : 1;
-}
-
-function check_output($message, $nl2br = 0) {
- global $allowed_html, $na;
- $var = strip_tags(stripslashes(format_text($message)), $allowed_html);
- return ($var) ? (($nl2br) ? nl2br($var) : $var) : $na;
-}
-
-function format_plural($count, $singular, $plural) {
- return ($count == 1) ? "$count ". t($singular) : "$count ". t($plural);
-}
-
-function format_interval($timestamp) {
- if ($timestamp >= 86400) {
- $output .= format_plural(floor($timestamp / 86400), "day", "days");
- $timestamp = $timestamp % 86400;
- }
- if ($timestamp >= 3600) {
- $output .= " ". format_plural(floor($timestamp / 3600), "hour", "hours");
- $timestamp = $timestamp % 3600;
- }
- if ($timestamp >= 60) {
- $output .= " ". floor($timestamp / 60) ." min";
- $timestamp = $timestamp % 60;
- }
- if ($timestamp > 0) {
- $output .= " $timestamp sec";
- }
- return ($output) ? $output : "0 sec";
-}
-
-function format_date($timestamp, $type = "medium", $format = "") {
- global $user;
-
- $timestamp += ($user->timezone) ? $user->timezone - date("Z") : 0;
-
- switch ($type) {
- case "small":
- $date = date("m/d/y - H:i", $timestamp);
- break;
- case "medium":
- $date = t(date("l", $timestamp)) .", ". date("m/d/Y - H:i", $timestamp);
- break;
- case "large":
- $date = t(date("l", $timestamp)) .", ". t(date("F", $timestamp)) ." ". date("d, Y - H:i", $timestamp);
- break;
- case "custom":
- $date = date($format, $timestamp);
- break;
- default:
- $date = t(date("l", $timestamp)) .", ". date("m/d/Y - H:i", $timestamp);
- }
- return $date;
-}
-
-function format_username($username) {
- global $user;
- if ($username) return (user_access($user, "account") ? "<A HREF=\"admin.php?mod=account&op=view&name=$username\">$username</A>" : "<A HREF=\"account.php?op=view&name=$username\">$username</A>");
- else return variable_get(anonymous, "Anonymous");
-}
-
-function format_email($address) {
- global $na;
- return ($address) ? "<A HREF=\"mailto:$address\">$address</A>" : $na;
-}
-
-function format_url($address, $description = "") {
- global $na;
- $description = ($description) ? $description : $address;
- return ($address) ? "<A HREF=\"$address\">". check_output($description) ."</A>" : $na;
-}
-
-function format_tag($link, $text) {
- return "'<a href=\"node.php?title='. urlencode('$link') .'\">'. ('$text' ? '$text' : '$link') .'</a>'";
-}
-
-function format_text($text) {
-
- $src = array( // "/(<\/?)(\w+)([^>]*>)/e", // convert HTML to lower case
- "/\[\[(([^\|]*?)(\|([^\|]*?))?)\]\]/e"); // [link|description]
- $dst = array( // "'\\1'. strtolower('\\2') .'\\3'", // convert HTML to lower case
- format_tag('\\2', '\\4')); // [link|description]
-
- return preg_replace($src, $dst, $text);
-}
-
-?>
diff --git a/includes/node.inc b/includes/node.inc
index 8f43f411d..e594e8554 100644
--- a/includes/node.inc
+++ b/includes/node.inc
@@ -158,8 +158,9 @@ function node_form($node) {
return node_invoke($node, "form");
}
-function node_status($node) {
- return node_invoke($node, "status");
+function node_status($node, $index = -1) {
+ $status = array_intersect(array(dumped, expired, queued, posted), node_invoke($node, "status"));
+ return $index < 0 ? $status : $status[$index];
}
function node_control($node) {
diff --git a/modules/book.module b/modules/book.module
index d284cda3b..70dcd6da4 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -96,60 +96,41 @@ function book_form($edit = array()) {
$output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n";
- $output .= "<B>". t("Author") .":</B><BR>\n";
- $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[userid]\" VALUE=\"$edit[userid]\">\n";
- $output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."<P>\n";
-
- $output .= "<B>". t("Subject") .":</B><BR>\n";
- $output .= "<INPUT TYPE=\"text\" NAME=\"edit[title]\" SIZE=\"50\" MAXLENGTH=\"128\" VALUE=\"". check_textfield($edit[title]) ."\"><P>\n";
-
- $output .= "<B>". t("Category") .":</B><BR>\n";
- $output .= category_form_select("book", $edit) ."<P>";
+ $output .= form_item(t("Author"), format_username(($edit[userid] ? $edit[userid] : $user->userid)));
+ $output .= form_hidden(userid, $edit[userid]);
+ $output .= form_textfield(t("Subject"), "title", $edit[title], 50, 128);
+ $output .= form_item(t("Category"), category_form_select("book", $edit));
if ($edit[pid]) {
$node = node_get_object("nid", $edit[pid]);
- $output .= "<B>". t("Parent") .":</B><BR>\n";
- $output .= "<A HREF=\"node.php?id=$node->id\">". check_output($node->title) ."</A><P>\n";
- $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[parent]\" VALUE=\"$edit[parent]\">\n";
- $output .= "<SMALL><I>". t("The parent subject or category the page belongs in.") ."</I></SMALL><P>\n";
+ $output .= form_item(t("Parent"), "<A HREF=\"node.php?id=$node->id\">". check_output($node->title) ."</A>", t("The parent subject or category the page belongs in."));
+ $output .= form_hidden("parent". $edit[parent]);
}
else {
- $output .= "<B>". t("Parent") .":</B><BR>\n";
- foreach (book_toc() as $key=>$value) $options2 .= "<OPTION VALUE=\"$key\"". ($edit[parent] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
- if (user_access($user, "book")) $options2 .= "<OPTION VALUE=\"0\"". ($edit[parent] == 0 ? " SELECTED" : "") .">&nbsp;</OPTION>";
- $output .= "<SELECT NAME=\"edit[parent]\">$options2</SELECT><BR>\n";
- $output .= "<SMALL><I>". t("The parent subject or category the page belongs in.") ."</I></SMALL><P>\n";
+ $output .= form_select(t("Parent"), "parent", user_access($user, "book") ? array_merge(array(0 => "&nbsp;"), book_toc()) : book_toc(), $edit[parent], t("The parent subject or category the page belongs in."));
}
- $output .= "<B>". t("Content") .":</B><BR>\n";
- $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"edit[body]\" MAXLENGTH=\"20\">". check_textarea($edit[body]) ."</TEXTAREA><BR>\n";
- $output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n";
-
- $output .= "<B>". t("Log message") .":</B><BR>\n";
- $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"5\" NAME=\"edit[log]\" MAXLENGTH=\"20\">". check_textarea($edit[log]) ."</TEXTAREA><BR>\n";
- $output .= "<SMALL><I>". t("An explanation of the additions or updates being made to help the group understand your motivations.") ."</I></SMALL><P>\n";
+ $output .= form_textarea(t("Content"), "body", $edit[body], 50, 10, t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html));
+ $output .= form_textarea(t("Log message"), "log", $edit[log], 50, 5, t("An explanation of the additions or updates being made to help the group understand your motivations."));
if (user_access($user, "book")) {
- $output .= "<B>". t("Weight") .":</B><BR>\n";
- for ($count = 0; $count < 25; $count++) $options3 .= "<OPTION VALUE=\"$count\"". ($edit[weight] == $count ? " SELECTED" : "") .">$count</OPTION>";
- $output .= "<SELECT NAME=\"edit[weight]\">$options3</SELECT><BR>\n";
- $output .= "<SMALL><I>". t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top.") ."</I></SMALL><P>\n";
+ $output .= form_select(t("Weight"), "weight", array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), $edit[weight], t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top."));
}
if (!$edit) {
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
+ $output .= form_submit(t("Preview"));
}
else if (!$edit[title]) {
$output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a title.") ."</FONT><P>\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
+ $output .= form_submit(t("Preview"));
}
else {
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Submit") ."\">\n";
+ $output .= form_submit(t("Preview"));
+ $output .= form_submit(t("Submit"));
}
- $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[pid]\" VALUE=\"$edit[pid]\">\n";
- $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$edit[nid]\">\n";
+ $output .= form_hidden("pid", $edit[pid]);
+ $output .= form_hidden("nid", $edit[nid]);
$output .= "</FORM>\n";
diff --git a/modules/book/book.module b/modules/book/book.module
index d284cda3b..70dcd6da4 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -96,60 +96,41 @@ function book_form($edit = array()) {
$output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n";
- $output .= "<B>". t("Author") .":</B><BR>\n";
- $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[userid]\" VALUE=\"$edit[userid]\">\n";
- $output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."<P>\n";
-
- $output .= "<B>". t("Subject") .":</B><BR>\n";
- $output .= "<INPUT TYPE=\"text\" NAME=\"edit[title]\" SIZE=\"50\" MAXLENGTH=\"128\" VALUE=\"". check_textfield($edit[title]) ."\"><P>\n";
-
- $output .= "<B>". t("Category") .":</B><BR>\n";
- $output .= category_form_select("book", $edit) ."<P>";
+ $output .= form_item(t("Author"), format_username(($edit[userid] ? $edit[userid] : $user->userid)));
+ $output .= form_hidden(userid, $edit[userid]);
+ $output .= form_textfield(t("Subject"), "title", $edit[title], 50, 128);
+ $output .= form_item(t("Category"), category_form_select("book", $edit));
if ($edit[pid]) {
$node = node_get_object("nid", $edit[pid]);
- $output .= "<B>". t("Parent") .":</B><BR>\n";
- $output .= "<A HREF=\"node.php?id=$node->id\">". check_output($node->title) ."</A><P>\n";
- $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[parent]\" VALUE=\"$edit[parent]\">\n";
- $output .= "<SMALL><I>". t("The parent subject or category the page belongs in.") ."</I></SMALL><P>\n";
+ $output .= form_item(t("Parent"), "<A HREF=\"node.php?id=$node->id\">". check_output($node->title) ."</A>", t("The parent subject or category the page belongs in."));
+ $output .= form_hidden("parent". $edit[parent]);
}
else {
- $output .= "<B>". t("Parent") .":</B><BR>\n";
- foreach (book_toc() as $key=>$value) $options2 .= "<OPTION VALUE=\"$key\"". ($edit[parent] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
- if (user_access($user, "book")) $options2 .= "<OPTION VALUE=\"0\"". ($edit[parent] == 0 ? " SELECTED" : "") .">&nbsp;</OPTION>";
- $output .= "<SELECT NAME=\"edit[parent]\">$options2</SELECT><BR>\n";
- $output .= "<SMALL><I>". t("The parent subject or category the page belongs in.") ."</I></SMALL><P>\n";
+ $output .= form_select(t("Parent"), "parent", user_access($user, "book") ? array_merge(array(0 => "&nbsp;"), book_toc()) : book_toc(), $edit[parent], t("The parent subject or category the page belongs in."));
}
- $output .= "<B>". t("Content") .":</B><BR>\n";
- $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"edit[body]\" MAXLENGTH=\"20\">". check_textarea($edit[body]) ."</TEXTAREA><BR>\n";
- $output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n";
-
- $output .= "<B>". t("Log message") .":</B><BR>\n";
- $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"5\" NAME=\"edit[log]\" MAXLENGTH=\"20\">". check_textarea($edit[log]) ."</TEXTAREA><BR>\n";
- $output .= "<SMALL><I>". t("An explanation of the additions or updates being made to help the group understand your motivations.") ."</I></SMALL><P>\n";
+ $output .= form_textarea(t("Content"), "body", $edit[body], 50, 10, t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html));
+ $output .= form_textarea(t("Log message"), "log", $edit[log], 50, 5, t("An explanation of the additions or updates being made to help the group understand your motivations."));
if (user_access($user, "book")) {
- $output .= "<B>". t("Weight") .":</B><BR>\n";
- for ($count = 0; $count < 25; $count++) $options3 .= "<OPTION VALUE=\"$count\"". ($edit[weight] == $count ? " SELECTED" : "") .">$count</OPTION>";
- $output .= "<SELECT NAME=\"edit[weight]\">$options3</SELECT><BR>\n";
- $output .= "<SMALL><I>". t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top.") ."</I></SMALL><P>\n";
+ $output .= form_select(t("Weight"), "weight", array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), $edit[weight], t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top."));
}
if (!$edit) {
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
+ $output .= form_submit(t("Preview"));
}
else if (!$edit[title]) {
$output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a title.") ."</FONT><P>\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
+ $output .= form_submit(t("Preview"));
}
else {
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Submit") ."\">\n";
+ $output .= form_submit(t("Preview"));
+ $output .= form_submit(t("Submit"));
}
- $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[pid]\" VALUE=\"$edit[pid]\">\n";
- $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$edit[nid]\">\n";
+ $output .= form_hidden("pid", $edit[pid]);
+ $output .= form_hidden("nid", $edit[nid]);
$output .= "</FORM>\n";
diff --git a/modules/node.module b/modules/node.module
index 3c377a2a4..af5292fb4 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -24,40 +24,34 @@ function node_admin_view($id) {
$node = node_get_object("nid", $id);
$output .= "<FORM ACTION=\"admin.php?mod=node&id=$node->nid\" METHOD=\"post\">\n";
- $output .= "<B>Title:</B><BR>". check_output($node->title) ."<P>\n";
- $output .= "<B>Author:</B><BR>". format_username($node->userid) ."<P>\n";
- $output .= "<B>Status:</B><BR>". $rstatus[$node->status] ."<P>\n";
- $output .= "<B>Comment:</B><BR>". node_comment_status($node->comment) ."<P>\n";
- $output .= "<B>Promote:</B><BR>". node_promote_status($node->promote) ."<P>\n";
- $output .= "<B>Date:</B><BR>". format_date($node->timestamp) ."<P>\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Edit node\">\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Delete node\">\n";
+ $output .= form_item("Title", check_output($node->title));
+ $output .= form_item("Author", format_username($node->userid));
+ $output .= form_item("Status", $rstatus[$node->status]);
+ $output .= form_item("Comment", node_comment_status($node->comment));
+ $output .= form_item("Promote", node_promote_status($node->promote));
+ $output .= form_item("Date", format_date($node->timestamp));
+ $output .= form_submit("Edit node");
+ $output .= form_submit("Delete node");
$output .= "</FORM>\n";
return $output;
}
function node_admin_edit($id) {
- global $user, $status;
+ global $user;
$node = node_get_object("nid", $id);
- foreach (array($node->userid => $node->author, $user->userid => $user->id) as $value=>$key) $author .= " <OPTION VALUE=\"$key\"". (($node->author == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
- foreach (array(format_date($node->timestamp) ." (original)" => $node->timestamp, format_date(time()) ." (current)" => time()) as $value=>$key) $timestamp .= " <OPTION VALUE=\"$key\"". (($node->timestamp == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
- foreach (node_status($node) as $value) $display .= " <OPTION VALUE=\"". $status[$value] ."\"". (($node->status == $status[$value]) ? " SELECTED" : "") .">$value</OPTION>\n";
- foreach (node_comment_status() as $key=>$value) $comment .= " <OPTION VALUE=\"$key\"". ($node->comment == $key ? " SELECTED" : "") .">$value</OPTION>\n";
- foreach (node_promote_status() as $key=>$value) $promote .= " <OPTION VALUE=\"$key\"". ($node->promote == $key ? " SELECTED" : "") .">$value</OPTION>\n";
-
$output .= "<FORM ACTION=\"admin.php?mod=node&id=$node->nid\" METHOD=\"post\">\n";
- $output .= "<B>Title:</B><BR>". check_output($node->title) ."<P>\n";
- $output .= "<B>Author:</B><BR><SELECT NAME=\"edit[author]\">$author</SELECT><P>\n";
- $output .= "<B>Status:</B><BR><SELECT NAME=\"edit[status]\">$display</SELECT><P>\n";
- $output .= "<B>Comment:</B><BR><SELECT NAME=\"edit[comment]\">$comment</SELECT><P>\n";
- $output .= "<B>Promote:</B><BR><SELECT NAME=\"edit[promote]\">$promote</SELECT><P>\n";
- $output .= "<B>Date:</B><BR><SELECT NAME=\"edit[timestamp]\">$timestamp</SELECT><P>\n";
- $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$node->nid\">\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"View node\">\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save node\">\n";
+ $output .= form_item("Title", check_output($node->title));
+ $output .= form_select("Author", "author", array($node->author => $node->userid, $user->id => $user->userid), $node->author);
+ $output .= form_select("Status", "status", node_status($node), $node->status);
+ $output .= form_select("Comment", "comment", node_comment_status(), $node->comment);
+ $output .= form_select("Promote", "promote", node_promote_status(), $node->promote);
+ $output .= form_select("Date", "timestamp", array($node->timestamp => format_date($node->timestamp) ." (original)", time() => format_date(time()) ." (current)"), $node->timestamp);
+ $output .= form_hidden("nid", $node->nid);
+ $output .= form_submit("View node");
+ $output .= form_submit("Save node");
$output .= "</FORM>\n";
return $output;
diff --git a/modules/node/node.module b/modules/node/node.module
index 3c377a2a4..af5292fb4 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -24,40 +24,34 @@ function node_admin_view($id) {
$node = node_get_object("nid", $id);
$output .= "<FORM ACTION=\"admin.php?mod=node&id=$node->nid\" METHOD=\"post\">\n";
- $output .= "<B>Title:</B><BR>". check_output($node->title) ."<P>\n";
- $output .= "<B>Author:</B><BR>". format_username($node->userid) ."<P>\n";
- $output .= "<B>Status:</B><BR>". $rstatus[$node->status] ."<P>\n";
- $output .= "<B>Comment:</B><BR>". node_comment_status($node->comment) ."<P>\n";
- $output .= "<B>Promote:</B><BR>". node_promote_status($node->promote) ."<P>\n";
- $output .= "<B>Date:</B><BR>". format_date($node->timestamp) ."<P>\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Edit node\">\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Delete node\">\n";
+ $output .= form_item("Title", check_output($node->title));
+ $output .= form_item("Author", format_username($node->userid));
+ $output .= form_item("Status", $rstatus[$node->status]);
+ $output .= form_item("Comment", node_comment_status($node->comment));
+ $output .= form_item("Promote", node_promote_status($node->promote));
+ $output .= form_item("Date", format_date($node->timestamp));
+ $output .= form_submit("Edit node");
+ $output .= form_submit("Delete node");
$output .= "</FORM>\n";
return $output;
}
function node_admin_edit($id) {
- global $user, $status;
+ global $user;
$node = node_get_object("nid", $id);
- foreach (array($node->userid => $node->author, $user->userid => $user->id) as $value=>$key) $author .= " <OPTION VALUE=\"$key\"". (($node->author == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
- foreach (array(format_date($node->timestamp) ." (original)" => $node->timestamp, format_date(time()) ." (current)" => time()) as $value=>$key) $timestamp .= " <OPTION VALUE=\"$key\"". (($node->timestamp == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
- foreach (node_status($node) as $value) $display .= " <OPTION VALUE=\"". $status[$value] ."\"". (($node->status == $status[$value]) ? " SELECTED" : "") .">$value</OPTION>\n";
- foreach (node_comment_status() as $key=>$value) $comment .= " <OPTION VALUE=\"$key\"". ($node->comment == $key ? " SELECTED" : "") .">$value</OPTION>\n";
- foreach (node_promote_status() as $key=>$value) $promote .= " <OPTION VALUE=\"$key\"". ($node->promote == $key ? " SELECTED" : "") .">$value</OPTION>\n";
-
$output .= "<FORM ACTION=\"admin.php?mod=node&id=$node->nid\" METHOD=\"post\">\n";
- $output .= "<B>Title:</B><BR>". check_output($node->title) ."<P>\n";
- $output .= "<B>Author:</B><BR><SELECT NAME=\"edit[author]\">$author</SELECT><P>\n";
- $output .= "<B>Status:</B><BR><SELECT NAME=\"edit[status]\">$display</SELECT><P>\n";
- $output .= "<B>Comment:</B><BR><SELECT NAME=\"edit[comment]\">$comment</SELECT><P>\n";
- $output .= "<B>Promote:</B><BR><SELECT NAME=\"edit[promote]\">$promote</SELECT><P>\n";
- $output .= "<B>Date:</B><BR><SELECT NAME=\"edit[timestamp]\">$timestamp</SELECT><P>\n";
- $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$node->nid\">\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"View node\">\n";
- $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save node\">\n";
+ $output .= form_item("Title", check_output($node->title));
+ $output .= form_select("Author", "author", array($node->author => $node->userid, $user->id => $user->userid), $node->author);
+ $output .= form_select("Status", "status", node_status($node), $node->status);
+ $output .= form_select("Comment", "comment", node_comment_status(), $node->comment);
+ $output .= form_select("Promote", "promote", node_promote_status(), $node->promote);
+ $output .= form_select("Date", "timestamp", array($node->timestamp => format_date($node->timestamp) ." (original)", time() => format_date(time()) ." (current)"), $node->timestamp);
+ $output .= form_hidden("nid", $node->nid);
+ $output .= form_submit("View node");
+ $output .= form_submit("Save node");
$output .= "</FORM>\n";
return $output;