$value) { if ($key == "passwd") { $query .= "$key=PASSWORD('". addslashes($value) ."'), "; } else { $query .= "$key='". addslashes($value) ."', "; } } $query = substr($query, 0, -2); if (!empty($id)) { db_query("UPDATE $dbase SET $query WHERE id=$id") or die(mysql_error()); return $id; } else { db_query("INSERT INTO $dbase SET $query") or die(mysql_error()); return mysql_insert_id(); } } function load_theme() { global $user, $themes; if ($user->theme && file_exists($themes[$user->theme][0])) { include $themes[$user->theme][0]; } else { include $themes[key($themes)][0]; } return new Theme(); } function check_input($message) { return str_replace("\"", """, stripslashes($message)); } function check_output($message) { global $allowed_html; return nl2br(strip_tags(stripslashes($message), $allowed_html)); } function discussion_num_replies($id, $count = 0) { $result = db_query("SELECT COUNT(cid) FROM comments WHERE pid = $id"); return ($result) ? mysql_result($result, 0) : 0; } function format_plural($count, $one, $more) { return ($count == 1) ? "$count $one" : "$count $more"; } function format_date($timestamp, $type = "medium") { switch ($type) { case "small": $date = date("D, m/d/y - H:i", $timestamp); break; case "medium": $date = date("l, m/d/Y - H:i", $timestamp); break; case "large": $date = date("D, M d, Y - H:i", $timestamp); break; case "extra large": $date = date("l, F dS, Y - H:i", $timestamp); break; default: $date = date("D, M d, Y - H:i", $timestamp); } return $date; } function format_data($field, $replacement = "n/a") { return ($field) ? $field : $replacement; } function format_username($username, $admin = 0) { if ($username) return ($admin) ? "$username" : "$username"; else { global $anonymous; return $anonymous; } } function format_email_address($address) { return ($address) ? "$address" : format_data($address); } function format_url($address, $description = "") { // POSSIBLE EXTENSIONS: // 1. add `http://' in case it's missing. // 2. add a trailing `/' in case it's missing. // 3. remove any parameters in the URI. $description = ($description) ? $description : $address; return ($address) ? "$description" : format_data($address); } function format_story_link($story, $subject = "") { global $user; $output .= "id"; $output .= ($user->umode) ? "&mode=$user->umode" : "&mode=threaded"; $output .= ($user->uorder) ? "&order=$user->uorder" : "&order=0"; $output .= ($user->thold) ? "&thold=$user->thold" : "&thold=0"; $output .= ($subject) ? "\">$subject" : "\">$story->subject"; return $output; } ?>