summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/account.module14
-rw-r--r--modules/affiliate-site.module2
-rw-r--r--modules/book.module133
-rw-r--r--modules/book/book.module133
-rw-r--r--modules/drupal-site.module2
-rw-r--r--modules/moderation.module32
-rw-r--r--modules/story.module60
-rw-r--r--modules/story/story.module60
8 files changed, 268 insertions, 168 deletions
diff --git a/modules/account.module b/modules/account.module
index 9823e1585..980080796 100644
--- a/modules/account.module
+++ b/modules/account.module
@@ -58,18 +58,18 @@ function account_blocks($id) {
return $output;
}
-function account_stories($id) {
- $result = db_query("SELECT * FROM stories WHERE author = $id ORDER BY timestamp DESC");
- while ($story = db_fetch_object($result)) {
- $output .= "<LI><A HREF=\"story.php?id=$story->id\">$story->subject</A></LI>\n";
+function account_nodes($id) {
+ $result = db_query("SELECT * FROM nodes WHERE author = $id ORDER BY timestamp DESC");
+ while ($node = db_fetch_object($result)) {
+ $output .= "<LI><A HREF=\"node.php?id=$node->nid\">$node->title</A> ($node->type)</LI>\n";
}
return $output;
}
function account_comments($id) {
- $result = db_query("SELECT * FROM comments WHERE link = 'story' AND author = '$id' ORDER BY timestamp DESC");
+ $result = db_query("SELECT * FROM comments WHERE author = '$id' ORDER BY timestamp DESC");
while ($comment = db_fetch_object($result)) {
- $output .= "<LI><A HREF=\"story.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">$comment->subject</A></LI>\n";
+ $output .= "<LI><A HREF=\"node.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">$comment->subject</A></LI>\n";
}
return $output;
}
@@ -153,7 +153,7 @@ function account_view($name) {
$output .= " <TR><TH>Theme:</TH><TD>". check_output($account->theme) ."</TD></TR>\n";
$output .= " <TR><TH>Timezone:</TH><TD>". check_output($account->timezone / 3600) ."</TD></TR>\n";
$output .= " <TR><TH>Selected blocks:</TH><TD>". check_output(account_blocks($account->id)) ."</TD></TR>\n";
- $output .= " <TR><TH>Submitted stories:</TH><TD>". check_output(account_stories($account->id)) ."</TD></TR>\n";
+ $output .= " <TR><TH>Submitted nodes:</TH><TD>". check_output(account_nodes($account->id)) ."</TD></TR>\n";
$output .= " <TR><TH>Submitted comments:</TH><TD>". check_output(account_comments($account->id)) ."</TD></TR>\n";
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\"><INPUT TYPE=\"hidden\" NAME=\"name\" VALUE=\"$account->userid\"><INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Edit account\"><INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Delete account\"></TD></TR>\n";
$output .= "</TABLE>\n";
diff --git a/modules/affiliate-site.module b/modules/affiliate-site.module
index 3f88c01ba..1f004d11c 100644
--- a/modules/affiliate-site.module
+++ b/modules/affiliate-site.module
@@ -15,7 +15,7 @@ function affiliate_block() {
$result = db_query("SELECT * FROM affiliates ORDER BY name");
- $content .= "<SCRIPT TYPE=\"\">\n";
+ $content .= "<SCRIPT>\n";
$content .= " <!--//\n";
$content .= " function gotosite(site) {\n";
$content .= " if (site != \"\") {\n";
diff --git a/modules/book.module b/modules/book.module
index 7101e0f72..66bedfec9 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -2,8 +2,21 @@
$module = array("find" => "book_find",
"page" => "book_page",
+ "user" => "book_user",
"admin" => "book_admin");
+class Book {
+ function Book($nid, $userid, $title, $body, $parent, $weight, $timestamp) {
+ $this->nid = $nid;
+ $this->userid = $userid;
+ $this->title = $title;
+ $this->body = $body;
+ $this->parent = $parent;
+ $this->weight = $weight;
+ $this->timestamp = $timestamp;
+ }
+}
+
function book_navigation($node) {
if ($node->nid) {
$next = db_fetch_object(db_query("SELECT n.nid, n.title FROM nodes n LEFT JOIN book b ON n.nid = b.node WHERE b.parent = '$node->parent' AND b.weight > $node->weight ORDER BY b.weight ASC"));
@@ -17,49 +30,39 @@ function book_navigation($node) {
$output .= "</TABLE>\n";
return $output;
-
}
-function book_update($node) {
- return ($node->nid ? "<A HREF=\"module.php?mod=book&op=update&id=$node->nid\">". t("update") ."</A>" : t("update"));
-}
-
-function theme_book($node, $small = 0) {
+function theme_book($node) {
global $theme;
- if ($small) {
- print "<A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A>";
+ if ($node->title) {
+ $output .= "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">\n";
+ $output .= " <TR><TD><B><BIG>". check_output($node->title) ."</BIG></B>". ($node->body ? "<BR><SMALL><I>Last updated by ". format_username($node->userid) ." on ". format_date($node->timestamp) ."</I></SMALL> " : "") ."</TD><TD ALIGN=\"right\">". node_info($node) ."</TD></TR>\n";
+ $output .= "</TABLE>\n";
}
- else {
- if ($node->title && $node->body) {
- $output .= "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">\n";
- $output .= " <TR><TD><B><BIG>". check_output($node->title) ."</BIG></B><BR><SMALL><I>Last updated by ". format_username($node->userid) ." on ". format_date($node->timestamp) ."</I></SMALL></TD><TD ALIGN=\"right\">". node_info($node) ."</TD></TR>\n";
- $output .= "</TABLE>\n";
- $output .= "<P>". check_output($node->body, 1) ."</P>";
- }
-
- $theme->box(t("Documentation book"), $output ."". book_overview($node->nid) ."". book_navigation($node));
+ if ($node->body) {
+ $output .= "<P>". check_output($node->body, 1) ."</P>";
}
-}
-function book_view($node) {
- global $op;
+ $theme->box(t("Documentation book"), $output ."". book_overview($node->nid) ."". book_navigation($node));
+}
- if ($op == "view") {
- theme_book($node);
- }
- else {
+function book_view($node, $page = 1) {
+ if ($page) {
global $theme;
$theme->header();
theme_book($node);
$theme->footer();
}
+ else {
+ theme_book($node);
+ }
}
function book_find($keys) {
- global $user;
+ global $status, $user;
$find = array();
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.status = 2 AND n.title LIKE '%". check_input($keys) ."%' ORDER BY n.timestamp DESC LIMIT 20");
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.status = '$status[posted]' AND n.title LIKE '%". check_input($keys) ."%' ORDER BY n.timestamp DESC LIMIT 20");
while ($node = db_fetch_object($result)) {
array_push($find, array("title" => check_output($node->title), "link" => (user_access($user, "book") ? "admin.php?mod=book&op=edit&id=$node->nid" : "node.php?id=$node->nid"), "user" => $node->userid, "date" => $node->timestamp));
}
@@ -73,19 +76,28 @@ function book_search() {
}
function book_form($edit = array()) {
- global $allowed_html, $PHP_SELF, $theme, $user;
+ global $allowed_html, $PHP_SELF, $REQUEST_URI, $status, $theme, $user;
- $output .= "<FORM ACTION=\"$PHP_SELF?mod=book\" METHOD=\"post\">\n";
+ $output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n";
$output .= "<B>". t("Author") .":</B><BR>\n";
+ $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[userid]\" VALUE=\"$edit[userid]\">\n";
$output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."<P>\n";
- $output .= "<B>". t("Category") .":</B><BR>\n";
- $result = db_query("SELECT nid, title FROM nodes WHERE type = 'book'");
- while ($node = db_fetch_object($result)) $options .= "<OPTION VALUE=\"$node->nid\"". ($edit[parent] == $node->nid ? " SELECTED" : "") .">". check_select($node->title) ."</OPTION>";
- if (user_access($user, "book")) $options .= "<OPTION VALUE=\"0\"". ($edit[parent] == 0 ? " SELECTED" : "") .">&nbsp;</OPTION>";
- $output .= "<SELECT NAME=\"edit[parent]\">$options</SELECT><BR>\n";
- $output .= "<SMALL><I>". t("The parent subject or category the book belongs in.") ."</I></SMALL><P>\n";
+ if ($edit[pid]) {
+ $node = node_get_object("nid", $edit[pid]);
+ $output .= "<B>". t("Parent") .":</B><BR>\n";
+ $output .= "<A HREF=\"node.php?id=$node->id\">". check_output($node->title) ."</A><P>\n";
+ $output .= "<SMALL><I>". t("The parent subject or category the new page belongs in.") ."</I></SMALL><P>\n";
+ }
+ else {
+ $output .= "<B>". t("Parent") .":</B><BR>\n";
+ $result = db_query("SELECT nid, title FROM nodes WHERE type = 'book' AND status = '$status[posted]'");
+ while ($node = db_fetch_object($result)) $options2 .= "<OPTION VALUE=\"$node->nid\"". ($edit[parent] == $node->nid ? " SELECTED" : "") .">". check_select($node->title) ."</OPTION>";
+ if (user_access($user, "book")) $options2 .= "<OPTION VALUE=\"0\"". ($edit[parent] == 0 ? " SELECTED" : "") .">&nbsp;</OPTION>";
+ $output .= "<SELECT NAME=\"edit[parent]\">$options2</SELECT><BR>\n";
+ $output .= "<SMALL><I>". t("The parent subject or category the new page belongs in.") ."</I></SMALL><P>\n";
+ }
$output .= "<B>". t("Subject") .":</B><BR>\n";
$output .= "<INPUT TYPE=\"text\" NAME=\"edit[title]\" SIZE=\"50\" MAXLENGTH=\"128\" VALUE=\"". check_textfield($edit[title]) ."\"><P>\n";
@@ -94,17 +106,23 @@ function book_form($edit = array()) {
$output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"edit[body]\" MAXLENGTH=\"20\">". check_textarea($edit[body]) ."</TEXTAREA><BR>\n";
$output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n";
+ if ($edit[pid]) {
+ $output .= "<B>". t("Log message") .":</B><BR>\n";
+ $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"5\" NAME=\"edit[log]\" MAXLENGTH=\"20\">". check_textarea($edit[log]) ."</TEXTAREA><BR>\n";
+ $output .= "<SMALL><I>". t("A brief explanation of your update.") ."</I></SMALL><P>\n";
+ }
+
if (user_access($user, "book")) {
- $status = array(2 => "posted", 1 => "queued", 0 => "dumped");
+ $status = array_intersect($status, array(0, 2, 3));
$output .= "<B>". t("Weight") .":</B><BR>\n";
- for ($count = 0; $count < 25; $count++) $weight .= "<OPTION VALUE=\"$count\"". ($edit[weight] == $count ? " SELECTED" : "") .">$count</OPTION>";
- $output .= "<SELECT NAME=\"edit[weight]\">$weight</SELECT><BR>\n";
+ for ($count = 0; $count < 25; $count++) $options3 .= "<OPTION VALUE=\"$count\"". ($edit[weight] == $count ? " SELECTED" : "") .">$count</OPTION>";
+ $output .= "<SELECT NAME=\"edit[weight]\">$options3</SELECT><BR>\n";
$output .= "<SMALL><I>". t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top.") ."</I></SMALL><P>\n";
$output .= "<B>". t("Status") .":</B><BR>\n";
- foreach ($status as $key=>$value) $status .= "<OPTION VALUE=\"$key\"". ($edit[status] == $key ? " SELECTED" : "") .">$value</OPTION>";
- $output .= "<SELECT NAME=\"edit[status]\">$status</SELECT><P>\n";
+ foreach ($status as $value=>$key) $options4 .= "<OPTION VALUE=\"$key\"". ($edit[status] == $key ? " SELECTED" : "") .">$value</OPTION>";
+ $output .= "<SELECT NAME=\"edit[status]\">$options4</SELECT><P>\n";
}
if (!$edit) {
@@ -119,14 +137,17 @@ function book_form($edit = array()) {
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Submit") ."\">\n";
}
+ $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[pid]\" VALUE=\"$edit[pid]\">\n";
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$edit[nid]\">\n";
+
$output .= "</FORM>\n";
return $output;
}
function book_save($edit) {
- node_save(array_merge($edit, array(type => "book")));
+ $node = ($edit[nid] ? node_get_object("nid", $edit[nid]) : node_get_object("title", $edit[title]));
+ node_save(array_diff(array_merge($edit, array(nid => $node->nid, type => "book")), array(userid => $edit[userid])));
}
function book_delete($id) {
@@ -134,16 +155,16 @@ function book_delete($id) {
}
function book_overview($parent = "", $offset = "") {
- global $PHP_SELF;
+ global $PHP_SELF, $status;
- $result = db_query("SELECT n.*, b.* FROM nodes n LEFT JOIN book b ON n.nid = b.node WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight");
+ $result = db_query("SELECT n.*, b.* FROM nodes n LEFT JOIN book b ON n.nid = b.node WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight");
$output .= "<DL>";
while ($node = db_fetch_object($result)) {
$number++;
if ($offset) $output .= "<DT>$offset$number. <A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A>\n";
else $output .= "<DT><P>$number. <B><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></B>\n";
- if ($PHP_SELF == "/admin.php") $output .= " <SMALL>(<A HREF=\"admin.php?mod=book&op=edit&id=$node->nid\">edit</A> | <A HREF=\"admin.php?mod=book&op=delete&id=$node->nid\">delete</A>)</SMALL>";
+ if ($PHP_SELF == "/admin.php") $output .= " <SMALL>(weight: $node->weight, status: $node->status) (<A HREF=\"admin.php?mod=book&op=edit&id=$node->nid\">edit</A>, <A HREF=\"admin.php?mod=book&op=delete&id=$node->nid\">delete</A>)</SMALL>";
$output .= book_overview($node->nid, "$offset$number.");
}
$output .= "</DL>";
@@ -151,9 +172,9 @@ function book_overview($parent = "", $offset = "") {
}
function book_admin() {
- global $op, $id, $edit;
+ global $op, $id, $edit, $user;
- print "<SMALL><A HREF=\"admin.php?mod=book&op=add\">add new entry</A> | <A HREF=\"admin.php?mod=book&op=search\">search documenation</A> | <A HREF=\"admin.php?mod=book\">overview</A></SMALL><HR>\n";
+ print "<SMALL><A HREF=\"admin.php?mod=book&op=add\">add new page</A> | <A HREF=\"admin.php?mod=book&op=search\">search book</A> | <A HREF=\"admin.php?mod=book\">overview</A></SMALL><HR>\n";
switch ($op) {
case "add":
@@ -170,6 +191,7 @@ function book_admin() {
book_search();
break;
case t("Preview"):
+ book_view(new Book(($edit[nid] ? $edit[nid] : -1), ($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
print book_form($edit);
break;
case t("Submit"):
@@ -186,4 +208,25 @@ function book_page($id = 0) {
book_view(node_get_object("nid", $nid));
}
+function book_user() {
+ global $edit, $id, $op, $theme, $user;
+
+ switch($op) {
+ case "update":
+ $node = node_get_object("nid", $id);
+ $theme->box("Update a book page", book_form(array(nid => -1, pid => $id, title => $node->title, body => $node->body, parent => $node->parent)));
+ break;
+ case t("Preview"):
+ book_view(new Book(($edit[nid] ? $edit[nid] : -1), $user->userid, $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
+ $theme->box("Submit a book page", book_form($edit));
+ break;
+ case t("Submit"):
+ book_save($edit);
+ $theme->box(t("Submit a book page"), t("Thank you for your submission."));
+ break;
+ default:
+ $theme->box("Submit a book page", book_form());
+ }
+}
+
?>
diff --git a/modules/book/book.module b/modules/book/book.module
index 7101e0f72..66bedfec9 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -2,8 +2,21 @@
$module = array("find" => "book_find",
"page" => "book_page",
+ "user" => "book_user",
"admin" => "book_admin");
+class Book {
+ function Book($nid, $userid, $title, $body, $parent, $weight, $timestamp) {
+ $this->nid = $nid;
+ $this->userid = $userid;
+ $this->title = $title;
+ $this->body = $body;
+ $this->parent = $parent;
+ $this->weight = $weight;
+ $this->timestamp = $timestamp;
+ }
+}
+
function book_navigation($node) {
if ($node->nid) {
$next = db_fetch_object(db_query("SELECT n.nid, n.title FROM nodes n LEFT JOIN book b ON n.nid = b.node WHERE b.parent = '$node->parent' AND b.weight > $node->weight ORDER BY b.weight ASC"));
@@ -17,49 +30,39 @@ function book_navigation($node) {
$output .= "</TABLE>\n";
return $output;
-
}
-function book_update($node) {
- return ($node->nid ? "<A HREF=\"module.php?mod=book&op=update&id=$node->nid\">". t("update") ."</A>" : t("update"));
-}
-
-function theme_book($node, $small = 0) {
+function theme_book($node) {
global $theme;
- if ($small) {
- print "<A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A>";
+ if ($node->title) {
+ $output .= "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">\n";
+ $output .= " <TR><TD><B><BIG>". check_output($node->title) ."</BIG></B>". ($node->body ? "<BR><SMALL><I>Last updated by ". format_username($node->userid) ." on ". format_date($node->timestamp) ."</I></SMALL> " : "") ."</TD><TD ALIGN=\"right\">". node_info($node) ."</TD></TR>\n";
+ $output .= "</TABLE>\n";
}
- else {
- if ($node->title && $node->body) {
- $output .= "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">\n";
- $output .= " <TR><TD><B><BIG>". check_output($node->title) ."</BIG></B><BR><SMALL><I>Last updated by ". format_username($node->userid) ." on ". format_date($node->timestamp) ."</I></SMALL></TD><TD ALIGN=\"right\">". node_info($node) ."</TD></TR>\n";
- $output .= "</TABLE>\n";
- $output .= "<P>". check_output($node->body, 1) ."</P>";
- }
-
- $theme->box(t("Documentation book"), $output ."". book_overview($node->nid) ."". book_navigation($node));
+ if ($node->body) {
+ $output .= "<P>". check_output($node->body, 1) ."</P>";
}
-}
-function book_view($node) {
- global $op;
+ $theme->box(t("Documentation book"), $output ."". book_overview($node->nid) ."". book_navigation($node));
+}
- if ($op == "view") {
- theme_book($node);
- }
- else {
+function book_view($node, $page = 1) {
+ if ($page) {
global $theme;
$theme->header();
theme_book($node);
$theme->footer();
}
+ else {
+ theme_book($node);
+ }
}
function book_find($keys) {
- global $user;
+ global $status, $user;
$find = array();
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.status = 2 AND n.title LIKE '%". check_input($keys) ."%' ORDER BY n.timestamp DESC LIMIT 20");
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.status = '$status[posted]' AND n.title LIKE '%". check_input($keys) ."%' ORDER BY n.timestamp DESC LIMIT 20");
while ($node = db_fetch_object($result)) {
array_push($find, array("title" => check_output($node->title), "link" => (user_access($user, "book") ? "admin.php?mod=book&op=edit&id=$node->nid" : "node.php?id=$node->nid"), "user" => $node->userid, "date" => $node->timestamp));
}
@@ -73,19 +76,28 @@ function book_search() {
}
function book_form($edit = array()) {
- global $allowed_html, $PHP_SELF, $theme, $user;
+ global $allowed_html, $PHP_SELF, $REQUEST_URI, $status, $theme, $user;
- $output .= "<FORM ACTION=\"$PHP_SELF?mod=book\" METHOD=\"post\">\n";
+ $output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n";
$output .= "<B>". t("Author") .":</B><BR>\n";
+ $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[userid]\" VALUE=\"$edit[userid]\">\n";
$output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."<P>\n";
- $output .= "<B>". t("Category") .":</B><BR>\n";
- $result = db_query("SELECT nid, title FROM nodes WHERE type = 'book'");
- while ($node = db_fetch_object($result)) $options .= "<OPTION VALUE=\"$node->nid\"". ($edit[parent] == $node->nid ? " SELECTED" : "") .">". check_select($node->title) ."</OPTION>";
- if (user_access($user, "book")) $options .= "<OPTION VALUE=\"0\"". ($edit[parent] == 0 ? " SELECTED" : "") .">&nbsp;</OPTION>";
- $output .= "<SELECT NAME=\"edit[parent]\">$options</SELECT><BR>\n";
- $output .= "<SMALL><I>". t("The parent subject or category the book belongs in.") ."</I></SMALL><P>\n";
+ if ($edit[pid]) {
+ $node = node_get_object("nid", $edit[pid]);
+ $output .= "<B>". t("Parent") .":</B><BR>\n";
+ $output .= "<A HREF=\"node.php?id=$node->id\">". check_output($node->title) ."</A><P>\n";
+ $output .= "<SMALL><I>". t("The parent subject or category the new page belongs in.") ."</I></SMALL><P>\n";
+ }
+ else {
+ $output .= "<B>". t("Parent") .":</B><BR>\n";
+ $result = db_query("SELECT nid, title FROM nodes WHERE type = 'book' AND status = '$status[posted]'");
+ while ($node = db_fetch_object($result)) $options2 .= "<OPTION VALUE=\"$node->nid\"". ($edit[parent] == $node->nid ? " SELECTED" : "") .">". check_select($node->title) ."</OPTION>";
+ if (user_access($user, "book")) $options2 .= "<OPTION VALUE=\"0\"". ($edit[parent] == 0 ? " SELECTED" : "") .">&nbsp;</OPTION>";
+ $output .= "<SELECT NAME=\"edit[parent]\">$options2</SELECT><BR>\n";
+ $output .= "<SMALL><I>". t("The parent subject or category the new page belongs in.") ."</I></SMALL><P>\n";
+ }
$output .= "<B>". t("Subject") .":</B><BR>\n";
$output .= "<INPUT TYPE=\"text\" NAME=\"edit[title]\" SIZE=\"50\" MAXLENGTH=\"128\" VALUE=\"". check_textfield($edit[title]) ."\"><P>\n";
@@ -94,17 +106,23 @@ function book_form($edit = array()) {
$output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"edit[body]\" MAXLENGTH=\"20\">". check_textarea($edit[body]) ."</TEXTAREA><BR>\n";
$output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n";
+ if ($edit[pid]) {
+ $output .= "<B>". t("Log message") .":</B><BR>\n";
+ $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"5\" NAME=\"edit[log]\" MAXLENGTH=\"20\">". check_textarea($edit[log]) ."</TEXTAREA><BR>\n";
+ $output .= "<SMALL><I>". t("A brief explanation of your update.") ."</I></SMALL><P>\n";
+ }
+
if (user_access($user, "book")) {
- $status = array(2 => "posted", 1 => "queued", 0 => "dumped");
+ $status = array_intersect($status, array(0, 2, 3));
$output .= "<B>". t("Weight") .":</B><BR>\n";
- for ($count = 0; $count < 25; $count++) $weight .= "<OPTION VALUE=\"$count\"". ($edit[weight] == $count ? " SELECTED" : "") .">$count</OPTION>";
- $output .= "<SELECT NAME=\"edit[weight]\">$weight</SELECT><BR>\n";
+ for ($count = 0; $count < 25; $count++) $options3 .= "<OPTION VALUE=\"$count\"". ($edit[weight] == $count ? " SELECTED" : "") .">$count</OPTION>";
+ $output .= "<SELECT NAME=\"edit[weight]\">$options3</SELECT><BR>\n";
$output .= "<SMALL><I>". t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top.") ."</I></SMALL><P>\n";
$output .= "<B>". t("Status") .":</B><BR>\n";
- foreach ($status as $key=>$value) $status .= "<OPTION VALUE=\"$key\"". ($edit[status] == $key ? " SELECTED" : "") .">$value</OPTION>";
- $output .= "<SELECT NAME=\"edit[status]\">$status</SELECT><P>\n";
+ foreach ($status as $value=>$key) $options4 .= "<OPTION VALUE=\"$key\"". ($edit[status] == $key ? " SELECTED" : "") .">$value</OPTION>";
+ $output .= "<SELECT NAME=\"edit[status]\">$options4</SELECT><P>\n";
}
if (!$edit) {
@@ -119,14 +137,17 @@ function book_form($edit = array()) {
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Submit") ."\">\n";
}
+ $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[pid]\" VALUE=\"$edit[pid]\">\n";
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$edit[nid]\">\n";
+
$output .= "</FORM>\n";
return $output;
}
function book_save($edit) {
- node_save(array_merge($edit, array(type => "book")));
+ $node = ($edit[nid] ? node_get_object("nid", $edit[nid]) : node_get_object("title", $edit[title]));
+ node_save(array_diff(array_merge($edit, array(nid => $node->nid, type => "book")), array(userid => $edit[userid])));
}
function book_delete($id) {
@@ -134,16 +155,16 @@ function book_delete($id) {
}
function book_overview($parent = "", $offset = "") {
- global $PHP_SELF;
+ global $PHP_SELF, $status;
- $result = db_query("SELECT n.*, b.* FROM nodes n LEFT JOIN book b ON n.nid = b.node WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight");
+ $result = db_query("SELECT n.*, b.* FROM nodes n LEFT JOIN book b ON n.nid = b.node WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight");
$output .= "<DL>";
while ($node = db_fetch_object($result)) {
$number++;
if ($offset) $output .= "<DT>$offset$number. <A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A>\n";
else $output .= "<DT><P>$number. <B><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></B>\n";
- if ($PHP_SELF == "/admin.php") $output .= " <SMALL>(<A HREF=\"admin.php?mod=book&op=edit&id=$node->nid\">edit</A> | <A HREF=\"admin.php?mod=book&op=delete&id=$node->nid\">delete</A>)</SMALL>";
+ if ($PHP_SELF == "/admin.php") $output .= " <SMALL>(weight: $node->weight, status: $node->status) (<A HREF=\"admin.php?mod=book&op=edit&id=$node->nid\">edit</A>, <A HREF=\"admin.php?mod=book&op=delete&id=$node->nid\">delete</A>)</SMALL>";
$output .= book_overview($node->nid, "$offset$number.");
}
$output .= "</DL>";
@@ -151,9 +172,9 @@ function book_overview($parent = "", $offset = "") {
}
function book_admin() {
- global $op, $id, $edit;
+ global $op, $id, $edit, $user;
- print "<SMALL><A HREF=\"admin.php?mod=book&op=add\">add new entry</A> | <A HREF=\"admin.php?mod=book&op=search\">search documenation</A> | <A HREF=\"admin.php?mod=book\">overview</A></SMALL><HR>\n";
+ print "<SMALL><A HREF=\"admin.php?mod=book&op=add\">add new page</A> | <A HREF=\"admin.php?mod=book&op=search\">search book</A> | <A HREF=\"admin.php?mod=book\">overview</A></SMALL><HR>\n";
switch ($op) {
case "add":
@@ -170,6 +191,7 @@ function book_admin() {
book_search();
break;
case t("Preview"):
+ book_view(new Book(($edit[nid] ? $edit[nid] : -1), ($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
print book_form($edit);
break;
case t("Submit"):
@@ -186,4 +208,25 @@ function book_page($id = 0) {
book_view(node_get_object("nid", $nid));
}
+function book_user() {
+ global $edit, $id, $op, $theme, $user;
+
+ switch($op) {
+ case "update":
+ $node = node_get_object("nid", $id);
+ $theme->box("Update a book page", book_form(array(nid => -1, pid => $id, title => $node->title, body => $node->body, parent => $node->parent)));
+ break;
+ case t("Preview"):
+ book_view(new Book(($edit[nid] ? $edit[nid] : -1), $user->userid, $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
+ $theme->box("Submit a book page", book_form($edit));
+ break;
+ case t("Submit"):
+ book_save($edit);
+ $theme->box(t("Submit a book page"), t("Thank you for your submission."));
+ break;
+ default:
+ $theme->box("Submit a book page", book_form());
+ }
+}
+
?>
diff --git a/modules/drupal-site.module b/modules/drupal-site.module
index 63a620f84..d4742b681 100644
--- a/modules/drupal-site.module
+++ b/modules/drupal-site.module
@@ -8,7 +8,7 @@ function drupal_block() {
$result = db_query("SELECT * FROM drupals ORDER BY name");
- $content .= "<SCRIPT TYPE=\"\">\n";
+ $content .= "<SCRIPT>\n";
$content .= " <!--//\n";
$content .= " function gotosite(site) {\n";
$content .= " if (site != \"\") {\n";
diff --git a/modules/moderation.module b/modules/moderation.module
index 3d0b0f4c8..e9380db5f 100644
--- a/modules/moderation.module
+++ b/modules/moderation.module
@@ -4,13 +4,15 @@ $module = array("menu" => "moderation_menu",
"page" => "moderation_page");
include_once "includes/common.inc";
+include_once "includes/node.inc";
function moderation_menu() {
return array("<A HREF=\"module.php?mod=moderation\">". t("moderation queue") ."</A> (<FONT COLOR=\"red\">". moderation_count() ."</FONT>)");
}
function moderation_count() {
- $result = db_query("SELECT COUNT(nid) FROM nodes WHERE status = 1");
+ global $status;
+ $result = db_query("SELECT COUNT(nid) FROM nodes WHERE status = '$status[queued]'");
return ($result) ? db_result($result, 0) : 0;
}
@@ -20,7 +22,7 @@ function moderation_score($id) {
}
function moderation_vote($id, $vote) {
- global $user;
+ global $status, $user;
if (!user_get($user, "history", "n$id")) {
// Update submission's score- and votes-field:
@@ -29,28 +31,27 @@ function moderation_vote($id, $vote) {
// Update user's history record:
$user = user_set($user, "history", "n$id", $vote);
- $result = db_query("SELECT * FROM nodes WHERE nid = $id");
- if ($node = db_fetch_object($result)) {
+ if ($node = node_get_object(nid, $id)) {
if (node_post_threshold($node) <= $node->score) {
- db_query("UPDATE nodes SET status = 2, timestamp = '". time() ."' WHERE nid = $id");
- watchdog("message", "posted node '$node->subject'");
+ node_save(array(nid => $id, pid => $node->pid, type => $node->type, status => $status[posted]));
+ watchdog("message", "posted node '$node->title'");
}
else if (node_dump_threshold($node) >= $node->score) {
- db_query("UPDATE nodes SET status = 0, timestamp = '". time() ."' WHERE nid = $id");
- watchdog("message", "dumped node '$node->subject'");
+ node_save(array(nid => $id, pid => $node->pid, type => $node->type, status => $status[dumped]));
+ watchdog("message", "dumped node '$node->title'");
}
else if (node_timout_threshold($node) <= $node->votes) {
- db_query("UPDATE nodes SET status = 0, timestamp = '". time() ."' WHERE nid = $id");
- watchdog("message", "expired node '$node->subject'");
+ node_save(array(nid => $id, pid => $node->pid, type => $node->type, status => $status[expired]));
+ watchdog("message", "expired node '$node->title'");
}
}
}
}
function moderation_overview() {
- global $theme, $user;
+ global $status, $theme, $user;
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.status = 1");
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.status = '$status[queued]'");
$content .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n";
$content .= " <TR BGCOLOR=\"$bgcolor1\"><TH>". t("Subject") ."</TH><TH>". t("Author") ."</TH><TH>". t("Type") ."</TH><TH>". t("Score") ."</TH></TR>\n";
@@ -74,6 +75,11 @@ function moderation_node($id) {
header("Location: node.php?id=$node->nid");
}
else {
+ if ($node->pid && $n = node_get_object("nid", $node->pid)) {
+ if ($node->pid) $output .= " ". t("The above node is a suggested update for an existing node:") ." \"<A HREF=\"node.php?id=$n->nid\">". check_output($n->title) ."</A>\".";
+ if ($node->log) $output .= " ". t("The log message to accompany this update is given below:") ."<P>". check_output($node->log, 1) ."</P>";
+ }
+
// moderation form:
$output .= "<FORM ACTION=\"module.php?mod=moderation\" METHOD=\"post\">\n";
foreach ($moderation_votes as $key=>$value) $options .= " <OPTION VALUE=\"$value\">$key</OPTION>\n";
@@ -83,7 +89,7 @@ function moderation_node($id) {
$output .= "</FORM>\n";
$theme->header();
- node_view($node, 1);
+ node_view($node, 0);
$theme->box(t("Moderate"), $output);
$theme->footer();
}
diff --git a/modules/story.module b/modules/story.module
index 5623d4fba..bacd83155 100644
--- a/modules/story.module
+++ b/modules/story.module
@@ -21,16 +21,17 @@ class Story {
}
function story_cron() {
- $result = db_query("SELECT * FROM nodes WHERE status = 3 AND timestamp <= ". time() ."");
+ global $status;
+ $result = db_query("SELECT * FROM nodes WHERE status = '$status[scheduled]' AND timestamp <= ". time() ."");
while ($story = db_fetch_object($result)) {
- db_query("UPDATE nodes SET status = '1', timestamp = '". time() ."' WHERE nid = '$story->nid' AND type = 'story'");
+ db_query("UPDATE nodes SET status = '$status[queued]', timestamp = '". time() ."' WHERE nid = '$story->nid' AND type = 'story'");
}
}
function story_find($keys) {
- global $user;
+ global $status, $user;
$find = array();
- $result = db_query("SELECT n.*, s.* FROM story s LEFT JOIN nodes n ON s.node = n.nid WHERE n.status = 2 AND (n.title LIKE '%". check_input($keys) ."%' OR s.abstract LIKE '%". check_input($keys) ."%' OR s.body LIKE '%$keys%') LIMIT 20");
+ $result = db_query("SELECT n.*, s.* FROM story s LEFT JOIN nodes n ON s.node = n.nid WHERE n.status = '$status[posted]' AND (n.title LIKE '%". check_input($keys) ."%' OR s.abstract LIKE '%". check_input($keys) ."%' OR s.body LIKE '%$keys%') LIMIT 20");
while ($story = db_fetch_object($result)) {
array_push($find, array("title" => check_output($story->title), "link" => (user_access($user, "story") ? "admin.php?mod=story&op=edit&id=$story->nid" : "node.php?id=$story->nid"), "user" => $story->userid, "date" => $story->timestamp));
}
@@ -52,10 +53,10 @@ function story_help() {
<?php
}
-function story_view($node, $page = 0) {
+function story_view($node, $page = 1) {
global $id, $cid, $op, $pid, $subject, $comment, $theme, $mode, $order, $threshold;
- if ($page == 0) {
+ if ($page == 1) {
switch($op) {
case t("Preview comment"):
$theme->header();
@@ -106,13 +107,12 @@ function story_view($node, $page = 0) {
}
function story_form($edit = array()) {
- global $allowed_html, $PHP_SELF, $theme, $user;
+ global $allowed_html, $REQUEST_URI, $status, $theme, $user;
- include "includes/story.inc";
-
- $output .= "<FORM ACTION=\"$PHP_SELF?mod=story&id=$edit[id]\" METHOD=\"post\">\n";
+ $output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n";
$output .= "<B>". t("Your name") .":</B><BR>\n";
+ $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[userid]\" VALUE=\"$edit[userid]\">\n";
$output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."<P>";
$output .= "<B>". t("Subject") .":</B><BR>\n";
@@ -132,10 +132,10 @@ function story_form($edit = array()) {
if (user_access($user, "story")) {
$output .= "<B>". t("Status") .":</B><BR>\n";
- $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"3\"". ($edit[status] == 3 ? " CHECKED" : "") ."> scheduled for <INPUT TYPE=\"text\" NAME=\"edit[timestamp]\" SIZE=\"30\" VALUE=\"". date("j F Y G:i", ($edit[timetsamp] ? $edit[timestamp] : time())) ."\"><BR>\n";
- $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"2\"". ($edit[status] == 2 ? " CHECKED" : "") ."> posted<BR>\n";
- $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"1\"". ($edit[status] == 1 ? " CHECKED" : "") ."> queued<BR>\n";
- $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"0\"". ($edit[status] == 0 ? " CHECKED" : "") ."> dumped<BR>\n";
+ $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"$status[scheduled]\"". ($edit[status] == 3 ? " CHECKED" : "") ."> scheduled for <INPUT TYPE=\"text\" NAME=\"edit[timestamp]\" SIZE=\"30\" VALUE=\"". date("j F Y G:i", ($edit[timetsamp] ? $edit[timestamp] : time())) ."\"><BR>\n";
+ $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"$status[posted]\"". ($edit[status] == 2 ? " CHECKED" : "") ."> posted<BR>\n";
+ $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"$status[queued]\"". ($edit[status] == 1 ? " CHECKED" : "") ."> queued<BR>\n";
+ $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"$status[dumped]\"". ($edit[status] == 0 ? " CHECKED" : "") ."> dumped<BR>\n";
$output .= "<SMALL><I>The textfield for scheduled stories expects a string containing an English date format of when you want to have your story automatically published. Example input: '". date("j F Y G:i") ."', '". date("m/d/y H:i") ."', '". date("F j, Y H:i") ."', ...</I></SMALL><P>\n";
}
@@ -172,9 +172,10 @@ function story_form($edit = array()) {
}
function story_save($edit) {
+ global $status;
$node = ($edit[nid] ? node_get_object("nid", $edit[nid]) : node_get_object("title", $edit[title]));
- $edit[timestamp] = ($edit[status] == 3 && strtotime($edit[timestamp]) > time()) ? strtotime($edit[timestamp]) : ($node->timestamp ? $node->timestamp : time());
- node_save(array_merge($edit, array(nid => ($edit[nid] ? $edit[nid] : $node->nid), type => "story")));
+ $edit[timestamp] = ($edit[status] == $status[scheduled] && strtotime($edit[timestamp]) > time()) ? strtotime($edit[timestamp]) : ($node->timestamp ? $node->timestamp : time());
+ node_save(array_diff(array_merge($edit, array(nid => $node->nid, type => "story")), array(userid => $edit[userid])));
}
function story_delete($id) {
@@ -186,7 +187,8 @@ function story_block() {
//
// disabled for now
//
- $result = db_query("SELECT s.id, COUNT(c.cid) AS comments, s.title FROM story s LEFT JOIN comments c ON s.id = c.lid WHERE s.status = 2 AND c.link = 'story' GROUP BY s.id ORDER BY comments DESC LIMIT 10");
+ global $status;
+ $result = db_query("SELECT s.id, COUNT(c.cid) AS comments, s.title FROM story s LEFT JOIN comments c ON s.id = c.lid WHERE s.status = '$status[posted]' AND c.link = 'story' GROUP BY s.id ORDER BY comments DESC LIMIT 10");
while ($story = db_fetch_object($result)) {
$content .= "<LI><A HREF=\"node.php?id=$story->id\">". check_output($story->title) ."</A><BR><SMALL>(". format_plural($story->comments, "comment", "comments") .")</SMALL></LI>\n";
}
@@ -197,7 +199,7 @@ function story_block() {
unset($content);
- $result = db_query("SELECT s.id, COUNT(c.cid) AS comments, s.title FROM story s LEFT JOIN comments c ON s.id = c.lid WHERE s.status = 2 AND c.link = 'story' AND ". time() ." - s.timestamp < 2419200 GROUP BY s.id ORDER BY comments DESC LIMIT 10");
+ $result = db_query("SELECT s.id, COUNT(c.cid) AS comments, s.title FROM story s LEFT JOIN comments c ON s.id = c.lid WHERE s.status = '$status[posted]' AND c.link = 'story' AND ". time() ." - s.timestamp < 2419200 GROUP BY s.id ORDER BY comments DESC LIMIT 10");
while ($story = db_fetch_object($result)) {
$content .= "<LI><A HREF=\"node.php?id=$story->id\">". check_output($story->title) ."</A><BR><SMALL>(". format_plural($story->comments, "comment", "comments") .")</SMALL></LI>\n";
}
@@ -211,31 +213,33 @@ function story_block() {
}
function story_overview() {
+ global $status;
+
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
- // Pending stories:
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = 1 ORDER BY timestamp DESC");
+ // Queued stories:
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = '$status[queued]' ORDER BY timestamp DESC");
$output .= " <TR><TH COLSPAN=\"6\">queued stories</TH></TR>\n";
while ($story = db_fetch_object($result)) {
$output .= " <TR><TD><A HREF=\"node.php?id=$story->nid\">". check_output($story->title) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>votes: $story->votes, score: $story->score</TD><TD><A HREF=\"node.php?id=$story->nid\">view</A></TD><TD><A HREF=\"admin.php?mod=story&op=edit&id=$story->nid\">edit</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=delete&id=$story->nid\">delete</A></TD></TR>\n";
}
// Scheduled stories:
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = 3 ORDER BY timestamp DESC");
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = '$status[scheduled]' ORDER BY timestamp DESC");
$output .= " <TR><TH COLSPAN=\"6\">scheduled stories</TH></TR>\n";
while ($story = db_fetch_object($result)) {
$output .= " <TR><TD><A HREF=\"node.php?id=$story->nid\">". check_output($story->title) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>". date("D, m/d/Y H:i", $story->timestamp) ."<BR><SMALL>(". format_interval($story->timestamp - time()) ." left)</SMALL></TD><TD><A HREF=\"node.php?id=$story->nid\">view</A></TD><TD><A HREF=\"admin.php?mod=story&op=edit&id=$story->nid\">edit</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=delete&id=$story->nid\">delete</A></TD></TR>\n";
}
// Dumped stories:
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = 0 ORDER BY timestamp DESC LIMIT 5");
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = '$status[dumped]' ORDER BY timestamp DESC LIMIT 5");
$output .= " <TR><TH COLSPAN=\"6\">dumped stories</TH></TR>\n";
while ($story = db_fetch_object($result)) {
$output .= " <TR><TD><A HREF=\"node.php?id=$story->nid\">". check_output($story->title) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>". date("D, m/d/Y H:i", $story->timestamp) ."</TD><TD><A HREF=\"node.php?id=$story->nid\">view</A></TD><TD><A HREF=\"admin.php?mod=story&op=edit&id=$story->nid\">edit</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=delete&id=$story->nid\">delete</A></TD></TR>\n";
}
// Posted stories:
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = 2 ORDER BY timestamp DESC LIMIT 15");
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = '$status[posted]' ORDER BY timestamp DESC LIMIT 15");
$output .= " <TR><TH COLSPAN=\"6\">posted stories</TH></TR>\n";
while ($story = db_fetch_object($result)) {
$output .= " <TR><TD><A HREF=\"node.php?id=$story->nid\">". check_output($story->title) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>". date("D, m/d/Y H:i", $story->timestamp) ."</TD><TD><A HREF=\"node.php?id=$story->nid\">view</A></TD><TD><A HREF=\"admin.php?mod=story&op=edit&id=$story->nid\">edit</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=delete&id=$story->nid\">delete</A></TD></TR>\n";
@@ -269,11 +273,11 @@ function story_admin() {
story_search();
break;
case t("Preview"):
- $theme->story(new Story(($edit[author] ? $edit[author] : $user->userid), $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), "[ ". t("reply to this story") ." ]");
+ story_view(new Story(($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
print story_form($edit);
break;
case t("Submit"):
- story_save($edit, check_input($id));
+ story_save($edit);
story_overview();
break;
default:
@@ -283,15 +287,15 @@ function story_admin() {
function story_user() {
- global $edit, $id, $op, $theme, $user;
+ global $edit, $op, $theme, $user;
switch($op) {
case t("Preview"):
- $theme->story(new Story(($edit[author] ? $edit[author] : $user->userid), $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), "[ ". t("reply to this story") ." ]");
+ story_view(new Story($user->userid, $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
$theme->box("Submit a story", story_form($edit));
break;
case t("Submit"):
- story_save($edit, check_input($id));
+ story_save($edit);
$theme->box(t("Submit a story"), t("Thank you for your submission."));
break;
default:
diff --git a/modules/story/story.module b/modules/story/story.module
index 5623d4fba..bacd83155 100644
--- a/modules/story/story.module
+++ b/modules/story/story.module
@@ -21,16 +21,17 @@ class Story {
}
function story_cron() {
- $result = db_query("SELECT * FROM nodes WHERE status = 3 AND timestamp <= ". time() ."");
+ global $status;
+ $result = db_query("SELECT * FROM nodes WHERE status = '$status[scheduled]' AND timestamp <= ". time() ."");
while ($story = db_fetch_object($result)) {
- db_query("UPDATE nodes SET status = '1', timestamp = '". time() ."' WHERE nid = '$story->nid' AND type = 'story'");
+ db_query("UPDATE nodes SET status = '$status[queued]', timestamp = '". time() ."' WHERE nid = '$story->nid' AND type = 'story'");
}
}
function story_find($keys) {
- global $user;
+ global $status, $user;
$find = array();
- $result = db_query("SELECT n.*, s.* FROM story s LEFT JOIN nodes n ON s.node = n.nid WHERE n.status = 2 AND (n.title LIKE '%". check_input($keys) ."%' OR s.abstract LIKE '%". check_input($keys) ."%' OR s.body LIKE '%$keys%') LIMIT 20");
+ $result = db_query("SELECT n.*, s.* FROM story s LEFT JOIN nodes n ON s.node = n.nid WHERE n.status = '$status[posted]' AND (n.title LIKE '%". check_input($keys) ."%' OR s.abstract LIKE '%". check_input($keys) ."%' OR s.body LIKE '%$keys%') LIMIT 20");
while ($story = db_fetch_object($result)) {
array_push($find, array("title" => check_output($story->title), "link" => (user_access($user, "story") ? "admin.php?mod=story&op=edit&id=$story->nid" : "node.php?id=$story->nid"), "user" => $story->userid, "date" => $story->timestamp));
}
@@ -52,10 +53,10 @@ function story_help() {
<?php
}
-function story_view($node, $page = 0) {
+function story_view($node, $page = 1) {
global $id, $cid, $op, $pid, $subject, $comment, $theme, $mode, $order, $threshold;
- if ($page == 0) {
+ if ($page == 1) {
switch($op) {
case t("Preview comment"):
$theme->header();
@@ -106,13 +107,12 @@ function story_view($node, $page = 0) {
}
function story_form($edit = array()) {
- global $allowed_html, $PHP_SELF, $theme, $user;
+ global $allowed_html, $REQUEST_URI, $status, $theme, $user;
- include "includes/story.inc";
-
- $output .= "<FORM ACTION=\"$PHP_SELF?mod=story&id=$edit[id]\" METHOD=\"post\">\n";
+ $output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n";
$output .= "<B>". t("Your name") .":</B><BR>\n";
+ $output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[userid]\" VALUE=\"$edit[userid]\">\n";
$output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."<P>";
$output .= "<B>". t("Subject") .":</B><BR>\n";
@@ -132,10 +132,10 @@ function story_form($edit = array()) {
if (user_access($user, "story")) {
$output .= "<B>". t("Status") .":</B><BR>\n";
- $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"3\"". ($edit[status] == 3 ? " CHECKED" : "") ."> scheduled for <INPUT TYPE=\"text\" NAME=\"edit[timestamp]\" SIZE=\"30\" VALUE=\"". date("j F Y G:i", ($edit[timetsamp] ? $edit[timestamp] : time())) ."\"><BR>\n";
- $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"2\"". ($edit[status] == 2 ? " CHECKED" : "") ."> posted<BR>\n";
- $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"1\"". ($edit[status] == 1 ? " CHECKED" : "") ."> queued<BR>\n";
- $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"0\"". ($edit[status] == 0 ? " CHECKED" : "") ."> dumped<BR>\n";
+ $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"$status[scheduled]\"". ($edit[status] == 3 ? " CHECKED" : "") ."> scheduled for <INPUT TYPE=\"text\" NAME=\"edit[timestamp]\" SIZE=\"30\" VALUE=\"". date("j F Y G:i", ($edit[timetsamp] ? $edit[timestamp] : time())) ."\"><BR>\n";
+ $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"$status[posted]\"". ($edit[status] == 2 ? " CHECKED" : "") ."> posted<BR>\n";
+ $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"$status[queued]\"". ($edit[status] == 1 ? " CHECKED" : "") ."> queued<BR>\n";
+ $output .= "<INPUT TYPE=\"radio\" NAME=\"edit[status]\" VALUE=\"$status[dumped]\"". ($edit[status] == 0 ? " CHECKED" : "") ."> dumped<BR>\n";
$output .= "<SMALL><I>The textfield for scheduled stories expects a string containing an English date format of when you want to have your story automatically published. Example input: '". date("j F Y G:i") ."', '". date("m/d/y H:i") ."', '". date("F j, Y H:i") ."', ...</I></SMALL><P>\n";
}
@@ -172,9 +172,10 @@ function story_form($edit = array()) {
}
function story_save($edit) {
+ global $status;
$node = ($edit[nid] ? node_get_object("nid", $edit[nid]) : node_get_object("title", $edit[title]));
- $edit[timestamp] = ($edit[status] == 3 && strtotime($edit[timestamp]) > time()) ? strtotime($edit[timestamp]) : ($node->timestamp ? $node->timestamp : time());
- node_save(array_merge($edit, array(nid => ($edit[nid] ? $edit[nid] : $node->nid), type => "story")));
+ $edit[timestamp] = ($edit[status] == $status[scheduled] && strtotime($edit[timestamp]) > time()) ? strtotime($edit[timestamp]) : ($node->timestamp ? $node->timestamp : time());
+ node_save(array_diff(array_merge($edit, array(nid => $node->nid, type => "story")), array(userid => $edit[userid])));
}
function story_delete($id) {
@@ -186,7 +187,8 @@ function story_block() {
//
// disabled for now
//
- $result = db_query("SELECT s.id, COUNT(c.cid) AS comments, s.title FROM story s LEFT JOIN comments c ON s.id = c.lid WHERE s.status = 2 AND c.link = 'story' GROUP BY s.id ORDER BY comments DESC LIMIT 10");
+ global $status;
+ $result = db_query("SELECT s.id, COUNT(c.cid) AS comments, s.title FROM story s LEFT JOIN comments c ON s.id = c.lid WHERE s.status = '$status[posted]' AND c.link = 'story' GROUP BY s.id ORDER BY comments DESC LIMIT 10");
while ($story = db_fetch_object($result)) {
$content .= "<LI><A HREF=\"node.php?id=$story->id\">". check_output($story->title) ."</A><BR><SMALL>(". format_plural($story->comments, "comment", "comments") .")</SMALL></LI>\n";
}
@@ -197,7 +199,7 @@ function story_block() {
unset($content);
- $result = db_query("SELECT s.id, COUNT(c.cid) AS comments, s.title FROM story s LEFT JOIN comments c ON s.id = c.lid WHERE s.status = 2 AND c.link = 'story' AND ". time() ." - s.timestamp < 2419200 GROUP BY s.id ORDER BY comments DESC LIMIT 10");
+ $result = db_query("SELECT s.id, COUNT(c.cid) AS comments, s.title FROM story s LEFT JOIN comments c ON s.id = c.lid WHERE s.status = '$status[posted]' AND c.link = 'story' AND ". time() ." - s.timestamp < 2419200 GROUP BY s.id ORDER BY comments DESC LIMIT 10");
while ($story = db_fetch_object($result)) {
$content .= "<LI><A HREF=\"node.php?id=$story->id\">". check_output($story->title) ."</A><BR><SMALL>(". format_plural($story->comments, "comment", "comments") .")</SMALL></LI>\n";
}
@@ -211,31 +213,33 @@ function story_block() {
}
function story_overview() {
+ global $status;
+
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
- // Pending stories:
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = 1 ORDER BY timestamp DESC");
+ // Queued stories:
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = '$status[queued]' ORDER BY timestamp DESC");
$output .= " <TR><TH COLSPAN=\"6\">queued stories</TH></TR>\n";
while ($story = db_fetch_object($result)) {
$output .= " <TR><TD><A HREF=\"node.php?id=$story->nid\">". check_output($story->title) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>votes: $story->votes, score: $story->score</TD><TD><A HREF=\"node.php?id=$story->nid\">view</A></TD><TD><A HREF=\"admin.php?mod=story&op=edit&id=$story->nid\">edit</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=delete&id=$story->nid\">delete</A></TD></TR>\n";
}
// Scheduled stories:
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = 3 ORDER BY timestamp DESC");
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = '$status[scheduled]' ORDER BY timestamp DESC");
$output .= " <TR><TH COLSPAN=\"6\">scheduled stories</TH></TR>\n";
while ($story = db_fetch_object($result)) {
$output .= " <TR><TD><A HREF=\"node.php?id=$story->nid\">". check_output($story->title) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>". date("D, m/d/Y H:i", $story->timestamp) ."<BR><SMALL>(". format_interval($story->timestamp - time()) ." left)</SMALL></TD><TD><A HREF=\"node.php?id=$story->nid\">view</A></TD><TD><A HREF=\"admin.php?mod=story&op=edit&id=$story->nid\">edit</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=delete&id=$story->nid\">delete</A></TD></TR>\n";
}
// Dumped stories:
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = 0 ORDER BY timestamp DESC LIMIT 5");
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = '$status[dumped]' ORDER BY timestamp DESC LIMIT 5");
$output .= " <TR><TH COLSPAN=\"6\">dumped stories</TH></TR>\n";
while ($story = db_fetch_object($result)) {
$output .= " <TR><TD><A HREF=\"node.php?id=$story->nid\">". check_output($story->title) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>". date("D, m/d/Y H:i", $story->timestamp) ."</TD><TD><A HREF=\"node.php?id=$story->nid\">view</A></TD><TD><A HREF=\"admin.php?mod=story&op=edit&id=$story->nid\">edit</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=delete&id=$story->nid\">delete</A></TD></TR>\n";
}
// Posted stories:
- $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = 2 ORDER BY timestamp DESC LIMIT 15");
+ $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = '$status[posted]' ORDER BY timestamp DESC LIMIT 15");
$output .= " <TR><TH COLSPAN=\"6\">posted stories</TH></TR>\n";
while ($story = db_fetch_object($result)) {
$output .= " <TR><TD><A HREF=\"node.php?id=$story->nid\">". check_output($story->title) ."</A></TD><TD>". format_username($story->userid) ."</TD><TD>". date("D, m/d/Y H:i", $story->timestamp) ."</TD><TD><A HREF=\"node.php?id=$story->nid\">view</A></TD><TD><A HREF=\"admin.php?mod=story&op=edit&id=$story->nid\">edit</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=story&op=delete&id=$story->nid\">delete</A></TD></TR>\n";
@@ -269,11 +273,11 @@ function story_admin() {
story_search();
break;
case t("Preview"):
- $theme->story(new Story(($edit[author] ? $edit[author] : $user->userid), $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), "[ ". t("reply to this story") ." ]");
+ story_view(new Story(($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
print story_form($edit);
break;
case t("Submit"):
- story_save($edit, check_input($id));
+ story_save($edit);
story_overview();
break;
default:
@@ -283,15 +287,15 @@ function story_admin() {
function story_user() {
- global $edit, $id, $op, $theme, $user;
+ global $edit, $op, $theme, $user;
switch($op) {
case t("Preview"):
- $theme->story(new Story(($edit[author] ? $edit[author] : $user->userid), $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), "[ ". t("reply to this story") ." ]");
+ story_view(new Story($user->userid, $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), 0);
$theme->box("Submit a story", story_form($edit));
break;
case t("Submit"):
- story_save($edit, check_input($id));
+ story_save($edit);
$theme->box(t("Submit a story"), t("Thank you for your submission."));
break;
default: