summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/node.inc13
-rw-r--r--includes/section.inc25
-rw-r--r--includes/structure.inc32
-rw-r--r--includes/theme.inc2
-rw-r--r--includes/variable.inc30
5 files changed, 35 insertions, 67 deletions
diff --git a/includes/node.inc b/includes/node.inc
index 3bb47832b..75786cb7f 100644
--- a/includes/node.inc
+++ b/includes/node.inc
@@ -6,7 +6,7 @@ $rstatus = array(0 => dumped, 1 => expired, 2 => queued, 3 => posted);
function _node_get($field, $value) {
$result = db_query("SELECT lid, type FROM node WHERE $field = '$value'");
if ($node = db_fetch_object($result)) {
- return db_query("SELECT n.*, l.*, u.userid FROM node n LEFT JOIN $node->type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id WHERE n.$field = '$value' ORDER BY n.timestamp DESC");
+ return db_query("SELECT n.*, l.*, c.name AS category, t.name AS topic, u.userid FROM node n LEFT JOIN $node->type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id LEFT JOIN category c ON n.cid = c.cid LEFT JOIN topic t ON n.tid = t.tid WHERE n.$field = '$value' ORDER BY n.timestamp DESC");
}
}
@@ -31,10 +31,15 @@ function node_del($field, $value) {
}
}
+function node_get_comments($nid) {
+ $comment = db_fetch_object(db_query("SELECT COUNT(c.lid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.lid WHERE n.nid = '$nid' GROUP BY n.nid", 1));
+ return $comment->number ? $comment->number : 0;
+}
+
function node_save($node) {
global $user, $status;
- $rows = array(nid, pid, lid, log, type, title, score, votes, author, status, timestamp);
+ $rows = array(nid, pid, lid, cid, tid, log, type, title, score, votes, author, status, timestamp);
if ($node[nid] > 0) {
$n = node_get_object("nid", $node[nid]);
@@ -69,7 +74,7 @@ function node_save($node) {
throttle("post node", variable_get(max_node_rate, 900));
// setup default values:
- $node = array_merge(array(title => "?", author => $user->id, type => "?", pid => 0, log => "node created", status => $status[queued], score => 0, votes => 0, timestamp => time()), $node);
+ $node = array_merge(array(title => "?", author => $user->id, type => "?", pid => 0, cid => 0, tid => 0, log => "node created", status => $status[queued], score => 0, votes => 0, timestamp => time()), $node);
// prepare queries:
$f1 = array();
@@ -129,7 +134,7 @@ function node_invoke($node, $name, $arg = 0) {
if ($function) return ($arg ? $function($node) : $function($node, $arg));
}
-function node_view($node, $page) {
+function node_view($node, $page = 0) {
return node_invoke($node, "view", $page);
}
diff --git a/includes/section.inc b/includes/section.inc
deleted file mode 100644
index ad25b179c..000000000
--- a/includes/section.inc
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-
-function section_get() {
- $array = array();
- $result = db_query("SELECT name FROM sections");
- while ($section = db_fetch_object($result)) array_push($array, $section->name);
- return $array;
-}
-
-function section_post_threshold($section, $default) {
- $section = db_fetch_object(db_query("SELECT post AS threshold FROM sections WHERE name = '". check_input($section) ."'"));
- return $section->threshold ? $section->threshold : $default;
-}
-
-function section_dump_threshold($section, $default) {
- $section = db_fetch_object(db_query("SELECT dump AS threshold FROM sections WHERE name = '". check_input($section) ."'"));
- return $section->threshold ? $section->threshold : $default;
-}
-
-function section_timout_threshold($section, $default) {
- $section = db_fetch_object(db_query("SELECT timout AS threshold FROM sections WHERE name = '". check_input($section) ."'"));
- return $section->threshold ? $section->threshold : $default;
-}
-
-?> \ No newline at end of file
diff --git a/includes/structure.inc b/includes/structure.inc
index 838d0e351..4326e092e 100644
--- a/includes/structure.inc
+++ b/includes/structure.inc
@@ -25,19 +25,30 @@ function category_save($edit) {
// delete category $cid:
function category_del($cid) {
db_query("DELETE FROM category WHERE cid = '". check_input($cid) ."'");
- db_query("DELETE FROM node_category WHERE cid = '". check_input($cid) ."'");
+ db_query("UPDATE node SET cid = 0 WHERE cid = '". check_input($cid) ."'");
}
-function category_node($nid, $cid) {
- db_query("INSERT INTO node_category (nid, cid) VALUES ('". check_input($nid) ."', '". check_input($cid) ."')", 1);
+function category_post_threshold($cid, $default) {
+ $category = db_fetch_object(db_query("SELECT post AS threshold FROM category WHERE cid = '". check_input($cid) ."'"));
+ return $category->threshold ? $category->threshold : $default;
+}
+
+function category_dump_threshold($cid, $default) {
+ $category = db_fetch_object(db_query("SELECT dump AS threshold FROM category WHERE cid = '". check_input($cid) ."'"));
+ return $category->threshold ? $category->threshold : $default;
+}
+
+function category_expire_threshold($cid, $default) {
+ $category = db_fetch_object(db_query("SELECT expire AS threshold FROM category WHERE cid = '". check_input($cid) ."'"));
+ return $category->threshold ? $category->threshold : $default;
}
function category_form_select($type, $edit = array(), $size = 1) {
$result = db_query("SELECT * FROM category WHERE type = '$type'");
while ($category = db_fetch_object($result)) {
- $options .= "<OPTION VALUE=\"$category->cid\"". ($edit[$category->cid] ? "SELECTED" : "") .">". check_select($category->name) ."</OPTION>";
+ $options .= "<OPTION VALUE=\"$category->cid\"". ($edit[cid] == $category->cid ? "SELECTED" : "") .">". check_select($category->name) ."</OPTION>";
}
- return "<SELECT NAME=\"category[]\" SIZE=\"$size\"". ($size > 1 ? "MULTIPLE" : "") .">$options</SELECT>\n";
+ return "<SELECT NAME=\"edit[cid]\" SIZE=\"$size\"". ($size > 1 ? "MULTIPLE" : "") .">$options</SELECT>\n";
}
// ----- topic -----
@@ -75,20 +86,15 @@ function topic_tree($parent = 0, $name = "", $tree = array()) {
// delete topic $tid:
function topic_del($tid) {
db_query("DELETE FROM topic WHERE tid = '". check_input($tid) ."'");
- db_query("DELETE FROM node_topic WHERE tid = '". check_input($tid) ."'");
-}
-
-// add node $nid to topic $tid:
-function topic_node($nid, $tid) {
- db_query("INSERT INTO node_topic (nid, tid) VALUES ('". check_input($nid) ."', '". check_input($tid) ."')", 1);
+ db_query("UPDATE node SET tid = 0 WHERE tid = '". check_input($tid) ."'");
}
// renders a HTML form to select one or more topics:
function topic_form_select($edit = array(), $size = 1) {
foreach (topic_tree() as $tid=>$name) {
- $options .= "<OPTION VALUE=\"$tid\"". ($edit[$tid] ? "SELECTED" : "") .">". check_select($name) ."</OPTION>";
+ $options .= "<OPTION VALUE=\"$tid\"". ($edit[tid] == $tid ? "SELECTED" : "") .">". check_select($name) ."</OPTION>";
}
- return "<SELECT NAME=\"topic[]\" SIZE=\"$size\"". ($size > 1 ? "MULTIPLE" : "") .">$options</SELECT>\n";
+ return "<SELECT NAME=\"edit[tid]\" SIZE=\"$size\"". ($size > 1 ? "MULTIPLE" : "") .">$options</SELECT>\n";
}
// ----- structure -----
diff --git a/includes/theme.inc b/includes/theme.inc
index d09ccf2ce..51f42850c 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -97,7 +97,7 @@ function theme_blocks($region, $theme) {
}
function theme_morelink($theme, $node) {
- return ($node->body) ? "[ <A HREF=\"node.php?id=$node->nid\"><FONT COLOR=\"$theme->link\"><B>". t("read more") ."</B></FONT></A> | ". sizeof(explode(" ", $node->body)) ." ". t("words") ." | <A HREF=\"node.php?id=$node->nid\"><FONT COLOR=\"$theme->link\">". format_plural($node->comments, "comment", "comments") ."</FONT></A> ]" : "[ <A HREF=\"node.php?id=$node->nid\"><FONT COLOR=\"$theme->link\">". format_plural($node->comments, "comment", "comments") ."</FONT></A> ]";
+ return ($node->body) ? "[ <A HREF=\"node.php?id=$node->nid\"><FONT COLOR=\"$theme->link\">". t("read more") ."</FONT></A> | ". sizeof(explode(" ", $node->body)) ." ". t("words") ." | <A HREF=\"node.php?id=$node->nid\"><FONT COLOR=\"$theme->link\">". format_plural(node_get_comments($node->nid), "comment", "comments") ."</FONT></A> ]" : "[ <A HREF=\"node.php?id=$node->nid\"><FONT COLOR=\"$theme->link\">". format_plural(node_get_comments($node->nid), "comment", "comments") ."</FONT></A> ]";
}
function theme_moderation_results($theme, $node) {
diff --git a/includes/variable.inc b/includes/variable.inc
index 20beb5efd..083f7d492 100644
--- a/includes/variable.inc
+++ b/includes/variable.inc
@@ -7,33 +7,15 @@ function variable_init($conf = array()) {
}
function handler_post_threshold($node, $default) {
- if ($node->type) {
- $function = $node->type ."_post_threshold";
- return $function($node, $default);
- }
- else {
- return $default;
- }
+ return ($threshold = category_post_threshold($node->cid) ? $threshold : $default);
}
function handler_dump_threshold($node, $default) {
- if ($node->type) {
- $function = $node->type ."_dump_threshold";
- return $function($node, $default);
- }
- else {
- return $default;
- }
+ return ($threshold = category_dump_threshold($node->cid) ? $threshold : $default);
}
-function handler_timout_threshold($node, $default) {
- if ($node->type) {
- $function = $node->type ."_timout_threshold";
- return $function($node, $default);
- }
- else {
- return $default;
- }
+function handler_expire_threshold($node, $default) {
+ return ($threshold = category_expire_threshold($node->cid) ? $threshold : $default);
}
function variable_get($name, $default, $object = 0) {
@@ -44,8 +26,8 @@ function variable_get($name, $default, $object = 0) {
return handler_post_threshold($object, $default);
case "dump_threshold":
return handler_dump_threshold($object, $default);
- case "timout_threshold":
- return handler_timout_threshold($object, $default);
+ case "expire_threshold":
+ return handler_expire_threshold($object, $default);
default:
return ($conf[$name] ? $conf[$name] : $default);
}