From ef7d5e1201df1aff7b536f798d0a53d616722be3 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 29 Apr 2001 12:39:55 +0000 Subject: 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. --- includes/function.inc | 123 -------------------------------------------------- 1 file changed, 123 deletions(-) delete mode 100644 includes/function.inc (limited to 'includes/function.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 @@ -na"; - -function check_textfield($message) { - return strip_tags(str_replace("\"", """, 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") ? "$username" : "$username"); - else return variable_get(anonymous, "Anonymous"); -} - -function format_email($address) { - global $na; - return ($address) ? "$address" : $na; -} - -function format_url($address, $description = "") { - global $na; - $description = ($description) ? $description : $address; - return ($address) ? "". check_output($description) ."" : $na; -} - -function format_tag($link, $text) { - return "''. ('$text' ? '$text' : '$link') .''"; -} - -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); -} - -?> -- cgit v1.2.3