Commit 1f798630 authored by Dries's avatar Dries

- large commit of everything else that has been queued in my backlog:
  it's not 100% stable yet
parent d3075189
drupal x.xx, xx/xx/xxxx
-----------------------
- major overhaul of the underlying design:
* everything is based on nodes
* introduced links / drupal tags
- refactored submission / moderation queue
- added a "wiki module"
- various updates:
* added preview functionality when submitting new content (such as a story) from the administration pages.
* made the administration section only show those links a user has access to.
drupal 2.00, 15/03/2001
-----------------------
- rewrote the comment/discussion code:
......
......@@ -68,35 +68,35 @@ function account_user_edit() {
$output .= "<B>". t("Username") .":</B><BR>\n";
$output .= "$user->userid<P>\n";
$output .= "<I>". t("Required, unique, and can not be changed.") ."</I><P>\n";
$output .= "<I><SMALL>". t("Required, unique, and can not be changed.") ."</SMALL></I><P>\n";
$output .= "<B>". t("Real name") .":</B><BR>\n";
$output .= "<INPUT NAME=\"edit[name]\" MAXLENGTH=\"55\" SIZE=\"30\" VALUE=\"$user->name\"><BR>\n";
$output .= "<I>". t("Optional") .".</I><P>\n";
$output .= "<I><SMALL>". t("Optional") .".</SMALL></I><P>\n";
$output .= "<B>". t("Real e-mail address") .":</B><BR>\n";
$output .= "$user->real_email<P>\n";
$output .= "<I>". t("Required, unique, can not be changed.") ." ". t("Your real e-mail address is never displayed publicly: only needed in case you lose your password.") ."</I><P>\n";
$output .= "<I><SMALL>". t("Required, unique, can not be changed.") ." ". t("Your real e-mail address is never displayed publicly: only needed in case you lose your password.") ."</SMALL></I><P>\n";
$output .= "<B>". t("Fake e-mail address") .":</B><BR>\n";
$output .= "<INPUT NAME=\"edit[fake_email]\" MAXLENGTH=\"55\" SIZE=\"30\" VALUE=\"$user->fake_email\"><BR>\n";
$output .= "<I>". t("Optional") .". ". t("Displayed publicly so you may spam proof your real e-mail address if you want.") ."</I><P>\n";
$output .= "<I><SMALL>". t("Optional") .". ". t("Displayed publicly so you may spam proof your real e-mail address if you want.") ."</SMALL></I><P>\n";
$output .= "<B>". t("Homepage") .":</B><BR>\n";
$output .= "<INPUT NAME=\"edit[url]\" MAXLENGTH=\"55\" SIZE=\"30\" VALUE=\"$user->url\"><BR>\n";
$output .= "<I>". t("Optional") .". ". t("Make sure you enter fully qualified URLs only. That is, remember to include \"http://\".") ."</I><P>\n";
$output .= "<I><SMALL>". t("Optional") .". ". t("Make sure you enter fully qualified URLs only. That is, remember to include \"http://\".") ."</SMALL></I><P>\n";
$output .= "<B>". t("Bio") .":</B> (". t("maximal 255 characters") .")<BR>\n";
$output .= "<TEXTAREA NAME=\"edit[bio]\" COLS=\"35\" ROWS=\"5\" WRAP=\"virtual\">$user->bio</TEXTAREA><BR>\n";
$output .= "<I>". t("Optional") .". ". t("This biographical information is publicly displayed on your user page.") ."<BR>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I><P>\n";
$output .= "<I><SMALL>". t("Optional") .". ". t("This biographical information is publicly displayed on your user page.") ."<BR>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</SMALL></I><P>\n";
$output .= "<B>". t("Signature") .":</B> (". t("maximal 255 characters") .")<BR>\n";
$output .= "<TEXTAREA NAME=\"edit[signature]\" COLS=\"35\" ROWS=\"5\" WRAP=\"virtual\">$user->signature</TEXTAREA><BR>\n";
$output .= "<I>". t("Optional") .". ". t("This information will be publicly displayed at the end of your comments.") ."<BR>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I><P>\n";
$output .= "<I><SMALL>". t("Optional") .". ". t("This information will be publicly displayed at the end of your comments.") ."<BR>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</SMALL></I><P>\n";
$output .= "<B>". t("Password") .":</B><BR>\n";
$output .= "<INPUT TYPE=\"password\" NAME=\"edit[pass1]\" SIZE=\"10\" MAXLENGTH=\"20\"> <INPUT TYPE=\"password\" NAME=\"edit[pass2]\" SIZE=\"10\" MAXLENGTH=\"20\"><BR>\n";
$output .= "<I>". t("Enter your new password twice if you want to change your current password or leave it blank if you are happy with your current password.") ."</I><P>\n";
$output .= "<I><SMALL>". t("Enter your new password twice if you want to change your current password or leave it blank if you are happy with your current password.") ."</SMALL></I><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Save user information") ."\"><BR>\n";
$output .= "</FORM>\n";
......@@ -131,25 +131,23 @@ function account_site_edit() {
$output .= "<B>". t("Theme") .":</B><BR>\n";
foreach ($themes as $key=>$value) $options1 .= " <OPTION VALUE=\"$key\"". (($user->theme == $key) ? " SELECTED" : "") .">$key - $value[1]</OPTION>\n";
$output .= "<SELECT NAME=\"edit[theme]\">\n$options1</SELECT><BR>\n";
$output .= "<I>". t("Selecting a different theme will change the look and feel of the site.") ."</I><P>\n";
$output .= "<I><SMALL>". t("Selecting a different theme will change the look and feel of the site.") ."</SMALL></I><P>\n";
$output .= "<B>". t("Timezone") .":</B><BR>\n";
$date = time() - date("Z");
for ($zone = -43200; $zone <= 46800; $zone += 3600) $options2 .= " <OPTION VALUE=\"$zone\"". (($user->timezone == $zone) ? " SELECTED" : "") .">". date("l, F dS, Y - h:i A", $date + $zone) ." (GMT ". $zone / 3600 .")</OPTION>\n";
$output .= "<SELECT NAME=\"edit[timezone]\">\n$options2</SELECT><BR>\n";
$output .= "<I>". t("Select what time you currently have and your timezone settings will be set appropriate.") ."</I><P>\n";
$output .= "<I><SMALL>". t("Select what time you currently have and your timezone settings will be set appropriate.") ."</SMALL></I><P>\n";
if ($languages) {
$output .= "<B>". t("Language" ) .":</B><BR>\n";
foreach ($languages as $key=>$value) $options3 .= " <OPTION VALUE=\"$key\"". (($user->language == $key) ? " SELECTED" : "") .">$value - $key</OPTION>\n";
$output .= "<SELECT NAME=\"edit[language]\">\n$options3</SELECT><BR>\n";
$output .= "<I>". t("Selecting a different language will change the language the site.") ."</I><P>\n";
}
$output .= "<I><SMALL>". t("Selecting a different language will change the language the site.") ."</SMALL></I><P>\n";
$output .= "<B>". t("Maximum number of items to display") .":</B><BR>\n";
for ($nodes = 10; $nodes <= 30; $nodes += 5) $options4 .= "<OPTION VALUE=\"$nodes\"". (($user->nodes == $nodes) ? " SELECTED" : "") .">$nodes</OPTION>\n";
$output .= "<SELECT NAME=\"edit[nodes]\">\n$options4</SELECT><BR>\n";
$output .= "<I>". t("The maximum number of nodes that will be displayed on the main page.") ."</I><P>\n";
$output .= "<I><SMALL>". t("The maximum number of nodes that will be displayed on the main page.") ."</SMALL></I><P>\n";
foreach ($cmodes as $key=>$value) $options5 .= "<OPTION VALUE=\"$key\"". ($user->mode == $key ? " SELECTED" : "") .">$value</OPTION>\n";
$output .= "<B>". t("Comment display mode") .":</B><BR>\n";
......@@ -162,7 +160,7 @@ function account_site_edit() {
for ($i = -1; $i < 6; $i++) $options7 .= " <OPTION VALUE=\"$i\"". ($user->threshold == $i ? " SELECTED" : "") .">Filter - $i</OPTION>";
$output .= "<B>". t("Comment filter") .":</B><BR>\n";
$output .= "<SELECT NAME=\"edit[threshold]\">$options7</SELECT><BR>\n";
$output .= "<I>". t("Comments that scored less than this threshold setting will be ignored. Anonymous comments start at 0, comments of people logged on start at 1 and moderators can add and subtract points.") ."</I><P>\n";
$output .= "<I><SMALL>". t("Comments that scored less than this threshold setting will be ignored. Anonymous comments start at 0, comments of people logged on start at 1 and moderators can add and subtract points.") ."</SMALL></I><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Save site settings") ."\"><BR>\n";
$output .= "</FORM>\n";
......@@ -197,7 +195,7 @@ function account_content_edit() {
$entry = db_fetch_object(db_query("SELECT * FROM layout WHERE block = '$block->name' AND user = '$user->id'"));
$output .= "<INPUT TYPE=\"checkbox\" NAME=\"edit[$block->name]\"". ($entry->user ? " CHECKED" : "") ."> ". t($block->name) ."<BR>\n";
}
$output .= "<P><I>". t("Enable the blocks you would like to see displayed in the side bars.") ."</I></P>\n";
$output .= "<P><I><SMALL>". t("Enable the blocks you would like to see displayed in the side bars.") ."</SMALL></I></P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Save content settings") ."\">\n";
$output .= "</FORM>\n";
......@@ -224,7 +222,7 @@ function account_content_save($edit) {
}
function account_user($uname) {
global $user, $theme;
global $user, $status, $theme;
function module($name, $module, $username) {
global $theme;
......@@ -256,7 +254,7 @@ function module($name, $module, $username) {
$block1 .= "</TABLE>\n";
/*
$result = db_query("SELECT c.cid, c.pid, c.lid, c.subject, c.timestamp, n.title AS node FROM comments c LEFT JOIN users u ON u.id = c.author LEFT JOIN nodes ON n.id = c.lid WHERE u.userid = '$uname' AND n.status = 2 AND s.timestamp > ". (time() - 1209600) ." ORDER BY cid DESC LIMIT 10");
$result = db_query("SELECT c.cid, c.pid, c.lid, c.subject, c.timestamp, n.title AS node FROM comments c LEFT JOIN users u ON u.id = c.author LEFT JOIN nodes ON n.id = c.lid WHERE u.userid = '$uname' AND n.status = '$status[posted]' AND s.timestamp > ". (time() - 1209600) ." ORDER BY cid DESC LIMIT 10");
while ($comment = db_fetch_object($result)) {
$block2 .= "<TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"1\">\n";
$block2 .= " <TR><TD ALIGN=\"right\"><B>". t("Comment") .":</B></TD><TD><A HREF=\"node.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</A></TD></TR>\n";
......@@ -427,9 +425,9 @@ function account_track_comments() {
}
function account_track_nodes() {
global $theme, $user;
global $status, $theme, $user;
$result = db_query("SELECT n.nid, n.type, n.title, n.timestamp, COUNT(c.cid) AS count FROM nodes n LEFT JOIN comments c ON c.lid = n.nid WHERE n.status = '2' AND n.author = '$user->id' GROUP BY n.nid DESC");
$result = db_query("SELECT n.nid, n.type, n.title, n.timestamp, COUNT(c.cid) AS count FROM nodes n LEFT JOIN comments c ON c.lid = n.nid WHERE n.status = '$status[posted]' AND n.author = '$user->id' GROUP BY n.nid DESC");
while ($node = db_fetch_object($result)) {
$output .= "<TABLE BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"1\">\n";
......@@ -446,11 +444,11 @@ function account_track_nodes() {
}
function account_track_site() {
global $theme, $user, $site_name;
global $status, $theme, $user, $site_name;
$period = 259200; // 3 days
$sresult = db_query("SELECT n.title, n.nid, COUNT(c.lid) AS count FROM comments c LEFT JOIN nodes n ON c.lid = n.nid WHERE n.status = 2 AND ". time() ." - n.timestamp < $period GROUP BY c.lid ORDER BY n.timestamp DESC LIMIT 10");
$sresult = db_query("SELECT n.title, n.nid, COUNT(c.lid) AS count FROM comments c LEFT JOIN nodes n ON c.lid = n.nid WHERE n.status = '$status[posted]' AND ". time() ." - n.timestamp < $period GROUP BY c.lid ORDER BY n.timestamp DESC LIMIT 10");
while ($node = db_fetch_object($sresult)) {
$output .= "<LI>". format_plural($node->count, "comment", "comments") ." ". t("attached to node") ." '<A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A>':</LI>";
......
......@@ -58,8 +58,8 @@ $themes = array("UnConeD" => array(
#
# Submission moderation votes:
# The keys of this associative array are displayed in each submission's selection box whereas the corresponding values represent the mathematical calculation to be performed to update a comment's value.
# Warning: changing $submission_votes will affect the integrity of all pending stories in the open submission queue. Do not change this setting unless there are no pending stories in the submission queue or unless you know what you are doing.
$submission_votes = array("neutral (+0)" => "+ 0",
# Warning: changing $moderation_votes will affect the integrity of all pending stories in the open submission queue. Do not change this setting unless there are no pending stories in the submission queue or unless you know what you are doing.
$moderation_votes = array("neutral (+0)" => "+ 0",
"post it (+1)" => "+ 1",
"dump it (-1)" => "- 1");
......
<?php
$status = array(dumped => 0, expired => 1, queued => 2, posted => 3, scheduled => 4);
function _node_get($field, $value) {
$result = db_query("SELECT lid, type FROM nodes WHERE $field = '$value'");
if ($node = db_fetch_object($result)) {
......@@ -32,9 +34,9 @@ function node_del_array($field, $value) {
}
function node_save($node) {
global $user;
global $user, $status;
$rows = array(nid, lid, type, title, score, votes, author, status, timestamp);
$rows = array(nid, pid, lid, log, type, title, score, votes, author, status, timestamp);
// insert or update node:
if ($node[nid]) {
......@@ -55,10 +57,12 @@ function node_save($node) {
db_query("UPDATE nodes SET $u1 WHERE nid = '$node[nid]'");
db_query("UPDATE $node[type] SET $u2 WHERE node = '$node[nid]'");
watchdog("message", "modified node '$node[title]'");
}
else {
// setup default values:
$node = array_merge(array(type => "?", title => "?", score => 0, votes => 0, author => $user->id, status => 1, timestamp => time()), $node);
$node = array_merge(array(title => "?", author => $user->id, type => "?", pid => 0, log => "node created", status => $status[queued], score => 0, votes => 0, timestamp => time()), $node);
// prepare queries:
$f1 = array();
......@@ -82,7 +86,6 @@ function node_save($node) {
$f2 = implode(", ", $f2);
$v2 = implode(", ", $v2);
// if (!_node_get("title = $node[title] AND timestamp < ". time() ." - 60")) {
db_query("INSERT INTO nodes ($f1) VALUES ($v1)");
if ($nid = db_insert_id()) {
$lid = db_query("INSERT INTO $node[type] ($f2, node) VALUES ($v2, $nid)");
......@@ -93,17 +96,26 @@ function node_save($node) {
db_query("DELETE FROM nodes WHERE nid = '$nid'");
}
}
// }
watchdog("message", "added node '$node[title]'");
}
if (($node[pid]) && ($node[status] == $status[posted])) {
db_query("UPDATE nodes SET status = '$status[expired]' WHERE nid = '$node[pid]'");
}
}
function node_view($node, $page = 0) {
function node_view($node, $page) {
if ($node->type) {
$function = $node->type ."_view";
$function($node);
return $function($node, $page);
}
else {
print "not found";
}
function node_form($node) {
if ($node[type]) {
$function = $node[type] ."_form";
return $function($node);
}
}
......@@ -122,7 +134,7 @@ function visit(site) {
</SCRIPT>
<?php
$choices = array("/node.php?id=$node->nid" => t("view node"), "/node.php?op=update&id=$node->nid" => t("suggest update"), "/node.php?op=history&id=$node->nid" => t("view history"), "/node.php?op=referer&id=$node->nid" => t("view referers"));
$choices = array("/node.php?id=$node->nid" => t("view node"), "/submit.php?mod=$node->type&op=update&id=$node->nid" => t("suggest update"), "/node.php?op=history&id=$node->nid" => t("view history"));
$output .= "<FORM METHOD=\"get\" ACTION=\"\">\n";
foreach ($choices as $key => $value) $options .= "<OPTION VALUE=\"$key\"". ($key == $REQUEST_URI ? " SELECTED" : "") .">". check_select($value) ."</OPTION>\n";
......@@ -133,8 +145,8 @@ function visit(site) {
}
function node_visible($node) {
global $user;
return ($node->status == 2) || ($node->status == 1 && $user->id) || user_access($user, "node");
global $user, $status;
return ($node->status == $status[posted]) || ($node->status == $status[queued] && $user->id) || user_access($user, "node");
}
function node_post_threshold($node, $threshold = 5) {
......
......@@ -14,7 +14,7 @@ function search_data($keys, $type) {
$result = module_execute($type, "find", $keys);
foreach ($result as $entry) {
$output .= "<P>\n";
$output .= " <B><U><A HREF=\"$entry[link]\">$entry[subject]</A></U></B><BR>";
$output .= " <B><U><A HREF=\"$entry[link]\">$entry[title]</A></U></B><BR>";
$output .= " <SMALL>$site_url$entry[link]". ($entry[user] ? " - ". format_username($entry[user]) : "") ."". ($entry[date] ? " - ". format_date($entry[date], "small") : "") ."</SMALL>";
$output .= "</P>\n";
}
......
......@@ -75,13 +75,13 @@ function theme_account($theme) {
function theme_blocks($region, $theme) {
global $id, $PHP_SELF, $user;
global $id, $PHP_SELF, $status, $user;
switch (strrchr($PHP_SELF, "/")) {
case "/node.php":
if ($region != "left") {
if ($user->id) $node = db_fetch_object(db_query("SELECT * FROM nodes WHERE nid = '$id'"));
if ($node->status == 1) theme_moderation_results($theme, $node);
if ($node->status == $status[queued]) theme_moderation_results($theme, $node);
// else theme_new_headlines($theme);
}
break;
......@@ -113,6 +113,10 @@ function theme_moderation_results($theme, $node) {
}
}
/*
//
// depricated -> new block strategy
//
function theme_new_headlines($theme, $num = 10) {
$result = db_query("SELECT nid, title FROM nodes WHERE status = 2 AND type = 'story' ORDER BY nid DESC LIMIT $num");
while ($node = db_fetch_object($result)) $content .= "<LI><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></LI>\n";
......@@ -132,5 +136,6 @@ function theme_old_headlines($theme, $num = 10) {
}
$theme->box(t("Older headlines"), $content);
}
*/
?>
......@@ -7,7 +7,7 @@
$date = ($date > 0) ? $date : time();
// Perform query:
$result = db_query("SELECT n.*, s.*, u.userid, COUNT(c.lid) AS comments FROM nodes n LEFT JOIN story s ON n.nid = s.node LEFT JOIN comments c ON n.nid = c.lid LEFT JOIN users u ON n.author = u.id WHERE n.status = 2 AND n.type = 'story' ". ($section ? "AND s.section = '$section' " : "") ."AND n.timestamp <= $date GROUP BY n.nid ORDER BY n.timestamp DESC LIMIT $number");
$result = db_query("SELECT n.*, s.*, u.userid, COUNT(c.lid) AS comments FROM nodes n LEFT JOIN story s ON n.nid = s.node LEFT JOIN comments c ON n.nid = c.lid LEFT JOIN users u ON n.author = u.id WHERE n.status = '$status[posted]' AND n.type = 'story' ". ($section ? "AND s.section = '$section' " : "") ."AND n.timestamp <= $date GROUP BY n.nid ORDER BY n.timestamp DESC LIMIT $number");
// Display nodes:
$theme->header();
......
......@@ -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";
......
......@@ -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";
......
......@@ -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>";
}
else {
if ($node->title && $node->body) {
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><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 .= " <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";
}
if ($node->body) {
$output .= "<P>". check_output($node->body, 1) ."</P>";
}
$theme->box(t("Documentation book"), $output ."". book_overview($node->nid) ."". book_navigation($node));
}
}
function book_view($node) {
global $op;
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());
}
}
?>
......@@ -2,8 +2,21 @@
$module = array("find" => "book_find",
"page" => "book_page",
"user" => "book_user",
"admin" => "book_admin");