summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc147
-rw-r--r--includes/function.inc123
-rw-r--r--includes/node.inc5
3 files changed, 149 insertions, 126 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) {