diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-05-17 20:50:15 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-05-17 20:50:15 +0000 |
commit | 031e4d420891a4a7b9e3b18623cae4e2400b7691 (patch) | |
tree | f4d7e1f574bcab7383e86680273e5b60cf5a373f /includes | |
parent | e5c7aefa5bea9bb4153155e414279985ccc8e0e5 (diff) | |
download | brdo-031e4d420891a4a7b9e3b18623cae4e2400b7691.tar.gz brdo-031e4d420891a4a7b9e3b18623cae4e2400b7691.tar.bz2 |
- Tidied up the field_get() API and improved the implementation of
both field_set() and field_get().
Diffstat (limited to 'includes')
-rw-r--r-- | includes/comment.inc | 4 | ||||
-rw-r--r-- | includes/common.inc | 38 | ||||
-rw-r--r-- | includes/user.inc | 2 |
3 files changed, 15 insertions, 29 deletions
diff --git a/includes/comment.inc b/includes/comment.inc index 0f7d31ccf..9ecc1c690 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -34,7 +34,7 @@ function comment_moderate($moderate) { if ($vote != $comment_votes[$none]) { $id = check_input($id); $vote = check_input($vote); $comment = db_fetch_object(db_query("SELECT * FROM comments WHERE cid = '$id'")); - if ($comment && !field_get($comment, "users", $user->userid)) { + if ($comment && !field_get($comment->users, $user->userid)) { $result = db_query("UPDATE comments SET score = score $vote, votes = votes + 1, users = '". field_set($comment->users, $user->userid, $vote) ."' WHERE cid = '$id'"); } } @@ -162,7 +162,7 @@ function comment_moderation($comment) { // preview comment: $output .= " "; } - else if ($user->id && $user->userid != $comment->userid && !field_get($comment, "users", $user->userid)) { + else if ($user->id && $user->userid != $comment->userid && !field_get($comment->users, $user->userid)) { // comment hasn't been moderated yet: foreach ($comment_votes as $key=>$value) $options .= " <OPTION VALUE=\"$value\">$key</OPTION>\n"; $output .= "<SELECT NAME=\"moderate[$comment->cid]\">$options</SELECT>\n"; diff --git a/includes/common.inc b/includes/common.inc index 1c5ea330b..9fb36b820 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -88,7 +88,7 @@ function check_name($name) { function check_output($message, $nl2br = 0) { global $allowed_html, $na; - $var = strip_tags(stripslashes(format_text($message)), $allowed_html); + $var = strip_tags(stripslashes(node_macro($message)), $allowed_html); return ($var) ? (($nl2br) ? nl2br($var) : $var) : $na; } @@ -163,16 +163,6 @@ 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($action, $form, $method = "post", $options = 0) { return "<FORM ACTION=\"$action\" METHOD=\"$method\"". ($options ? " $options" : "") .">\n$form</FORM>\n"; } @@ -206,36 +196,32 @@ function form_submit($value) { return "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". check_textfield($value) ."\">\n"; } -function field_get($object, $variable, $field) { - $data = explode(";", $object->$variable); - for (reset($data); current($data); next($data)) { - $entry = explode(":", current($data)); - if (reset($entry) == $field) $rval = end($entry); +function field_get($string, $name) { + foreach (explode(";", $string) as $data) { + $entry = explode(":", $data); + if ($entry[0] == $name) return $entry[1]; } - return $rval; } -function field_set($field, $name, $value) { +function field_set($string, $name, $value) { if (!$value) { // remove entry: - $data = explode(";", $field); - for (reset($data); current($data); next($data)) { - $entry = explode(":", current($data)); + foreach (explode(";", $string) as $data) { + $entry = explode(":", $data); if ($entry[0] != $name) $rval .= "$entry[0]:$entry[1];"; } } - else if (strstr($field, "$name:")) { + else if (strstr($string, "$name:")) { // found: update exsisting entry: - $data = explode(";", $field); - for (reset($data); current($data); next($data)) { - $entry = explode(":", current($data)); + foreach (explode(";", $string) as $data) { + $entry = explode(":", $data); if ($entry[0] == $name) $entry[1] = $value; $rval .= "$entry[0]:$entry[1];"; } } else { // not found: - $rval = "$field$name:$value;"; + $rval = "$string$name:$value;"; } return $rval; diff --git a/includes/user.inc b/includes/user.inc index 74254dc2b..307a3f33c 100644 --- a/includes/user.inc +++ b/includes/user.inc @@ -54,7 +54,7 @@ function user_save($account, $array) { function user_access($account, $section = 0) { global $user; - if ($section) return (field_get($account, "access", $section) || $account->id == 1); + if ($section) return (field_get($account->access, $section) || $account->id == 1); else return ($account->access || $account->id == 1); } |