Commit 031e4d42 authored by Dries's avatar Dries
Browse files

- Tidied up the field_get() API and improved the implementation of
  both field_set() and field_get().
parent e5c7aefa
......@@ -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";
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -11,6 +11,13 @@ function Node($node) {
}
}
function node_macro($text) {
$src = array("/\[\[(([^\|]*?)(\|([^\|]*?))?)\]\]/e"); // [link|description]
$dst = array(format_tag('\\2', '\\4')); // [link|description]
return preg_replace($src, $dst, $text);
}
function node_overview($query = array()) {
global $user;
......
......@@ -11,6 +11,13 @@ function Node($node) {
}
}
function node_macro($text) {
$src = array("/\[\[(([^\|]*?)(\|([^\|]*?))?)\]\]/e"); // [link|description]
$dst = array(format_tag('\\2', '\\4')); // [link|description]
return preg_replace($src, $dst, $text);
}
function node_overview($query = array()) {
global $user;
......
......@@ -20,7 +20,7 @@ function queue_vote($id, $vote) {
if ($node = node_get_object(nid, $id)) {
if (!field_get($node, "users", $user->userid)) {
if (!field_get($node->users, $user->userid)) {
// Update submission's score- and votes-field:
db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node->users, $user->userid, $vote) ."' WHERE nid = $id");
......@@ -49,7 +49,7 @@ function queue_overview() {
$content .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n";
$content .= " <TR><TH>". t("Subject") ."</TH><TH>". t("Author") ."</TH><TH>". t("Type") ."</TH><TH>". t("Score") ."</TH></TR>\n";
while ($node = db_fetch_object($result)) {
if ($user->id == $node->author || field_get($node, "users", $user->userid)) $content .= " <TR><TD><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\">". queue_score($node->nid) ."</TD></TR>\n";
if ($user->id == $node->author || field_get($node->users, $user->userid)) $content .= " <TR><TD><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\">". queue_score($node->nid) ."</TD></TR>\n";
else $content .= " <TR><TD><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\"><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". t("vote") ."</A></TD></TR>\n";
}
$content .= "</TABLE>\n";
......@@ -65,7 +65,7 @@ function queue_node($id) {
$node = node_get_object(nid, $id);
if ($user->id == $node->author || field_get($node, "users", $user->userid)) {
if ($user->id == $node->author || field_get($node->users, $user->userid)) {
header("Location: node.php?id=$node->nid");
}
else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment