diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-03-25 10:57:01 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-03-25 10:57:01 +0000 |
commit | 1f79863053350f1a7d6cb654ac615123bc3b5133 (patch) | |
tree | bacfeada8244f49e0fd7ad38bc7bbbd6ac27bd57 | |
parent | d30751899897dc67f5f0563133ec14164cdfb993 (diff) | |
download | brdo-1f79863053350f1a7d6cb654ac615123bc3b5133.tar.gz brdo-1f79863053350f1a7d6cb654ac615123bc3b5133.tar.bz2 |
- large commit of everything else that has been queued in my backlog:
it's not 100% stable yet
-rw-r--r-- | CHANGELOG | 11 | ||||
-rw-r--r-- | account.php | 48 | ||||
-rw-r--r-- | includes/hostname.conf | 4 | ||||
-rw-r--r-- | includes/node.inc | 54 | ||||
-rw-r--r-- | includes/search.inc | 2 | ||||
-rw-r--r-- | includes/theme.inc | 9 | ||||
-rw-r--r-- | index.php | 2 | ||||
-rw-r--r-- | modules/account.module | 14 | ||||
-rw-r--r-- | modules/affiliate-site.module | 2 | ||||
-rw-r--r-- | modules/book.module | 133 | ||||
-rw-r--r-- | modules/book/book.module | 133 | ||||
-rw-r--r-- | modules/drupal-site.module | 2 | ||||
-rw-r--r-- | modules/moderation.module | 32 | ||||
-rw-r--r-- | modules/story.module | 60 | ||||
-rw-r--r-- | modules/story/story.module | 60 | ||||
-rw-r--r-- | node.php | 26 | ||||
-rw-r--r-- | submit.php | 125 | ||||
-rw-r--r-- | themes/example/example.theme | 2 |
18 files changed, 381 insertions, 338 deletions
@@ -1,3 +1,14 @@ +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: diff --git a/account.php b/account.php index ebfdaea78..791987ae7 100644 --- a/account.php +++ b/account.php @@ -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 .= "<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><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 account_user($uname) { $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>"; diff --git a/includes/hostname.conf b/includes/hostname.conf index 57d5f574c..764c1f52b 100644 --- a/includes/hostname.conf +++ b/includes/hostname.conf @@ -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"); diff --git a/includes/node.inc b/includes/node.inc index 824c83ec2..b682b4e4c 100644 --- a/includes/node.inc +++ b/includes/node.inc @@ -1,5 +1,7 @@ <?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,28 +86,36 @@ 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)"); - if ($lid = db_insert_id()) { - db_query("UPDATE nodes SET lid = '$lid' WHERE nid = '$nid'"); - } - else { - db_query("DELETE FROM nodes WHERE nid = '$nid'"); - } + 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)"); + if ($lid = db_insert_id()) { + db_query("UPDATE nodes SET lid = '$lid' WHERE nid = '$nid'"); + } + else { + 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 node_info($node) { </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 node_info($node) { } 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) { diff --git a/includes/search.inc b/includes/search.inc index 78ec7ed8e..47eefecd9 100644 --- a/includes/search.inc +++ b/includes/search.inc @@ -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"; } diff --git a/includes/theme.inc b/includes/theme.inc index f7fe640dc..6182f8936 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -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 @@ $number = ($user->nodes) ? $user->nodes : 10; $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(); 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" : "") ."> </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" : "") ."> </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" : "") ."> </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" : "") ."> </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: @@ -2,30 +2,32 @@ include "includes/common.inc"; -function node_update($node) { -} - function node_history($node) { + global $status; + if ($node->status == $status[expired] || $node->status == $status[posted]) { + $output .= "<DT><B>". format_date($node->timestamp) ." by ". format_username($node->userid) .":</B></DT><DD>". check_output($node->log, 1) ."<P></DD>"; + } + if ($node->pid) { + $output .= node_history(node_get_object("nid", $node->pid)); + } + return $output; } function node_refers($node) { + print "under construction"; } $node = ($title ? node_get_object(title, check_input($title)) : node_get_object(nid, check_input($id))); if ($node && node_visible($node)) { switch ($op) { - case "update": -// node_update($node); -// break; case "history": -// node_history($node); -// break; - case "referers": -// node_referers($node); -// break; + $theme->header(); + $theme->box(t("History"), node_info($node) ."<DL>". node_history($node) ."</DL>"); + $theme->footer(); + break; default: - node_view($node); + node_view($node, 1); } } else { diff --git a/submit.php b/submit.php index fb06dfc41..3df473832 100644 --- a/submit.php +++ b/submit.php @@ -2,121 +2,36 @@ include_once "includes/common.inc"; -function submit_enter() { - global $anonymous, $allowed_html, $theme, $user; - - // Guidlines: - $output .= "<P>". t("Got some news or some thoughts you would like to share? Fill out this form and they will automatically get whisked away to our submission queue where our moderators will frown at it, poke at it and hopefully post it. Every registered user is automatically a moderator and can vote whether or not your sumbission should be carried to the front page for discussion.") ."</P>\n"; - $output .= "<P>". t("Note that we do not revamp or extend your submission so it is up to you to make sure your submission is well-written: if you don't care enough to be clear and complete, your submission is likely to be moderated down by our army of moderators. Try to be complete, aim for clarity, organize and structure your text, and try to carry out your statements with examples. It is also encouraged to extend your submission with arguments that flow from your unique intellectual capability and experience: offer some insight or explanation as to why you think your submission is interesting. Make sure your submission has some meat on it!") ."</P>\n"; - $output .= "<P>". t("However, if you have bugs to report, complaints, personal questions or anything besides a public submission, we would prefer you to mail us instead, or your message is likely to get lost.") ."</P>\n"; - - // Submission form: - $output .= "<FORM ACTION=\"submit.php\" METHOD=\"post\">\n"; - - $output .= "<B>". t("Your name") .":</B><BR>\n"; - $output .= format_username($user->userid) ."<P>\n"; - - $output .= "<B>". t("Subject") .":</B><BR>\n"; - $output .= "<INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" MAXLENGTH=\"60\"><P>\n"; - - $output .= "<B>". t("Section") .":</B><BR>\n"; - foreach ($sections = section_get() as $value) $options .= " <OPTION VALUE=\"$value\">$value</OPTION>\n"; - $output .= "<SELECT NAME=\"section\">$options</SELECT><P>\n"; - - $output .= "<B>". t("Abstract") .":</B><BR>\n"; - $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"abstract\" MAXLENGTH=\"20\"></TEXTAREA><BR>\n"; - $output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n"; - - $output .= "<B>". t("Extended story") .":</B><BR>\n"; - $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"15\" NAME=\"article\"></TEXTAREA><BR>\n"; - $output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n"; - - $output .= "<SMALL><I>". t("You must preview at least once before you can submit") .":</I></SMALL><BR>\n"; - $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview submission") ."\"><P>\n"; - - $output .= "</FORM>\n"; - - $theme->header(); - $theme->box(t("New submission"), $output); - $theme->footer(); +function submit_type($name, $module) { + global $modules; + if ($module[user]) $modules = array_merge(($modules ? $modules : array()), array($name => $name)); } -function submit_preview($subject, $abstract, $article, $section) { - global $allowed_html, $theme, $user; - - include "includes/story.inc"; - - $output .= "<FORM ACTION=\"submit.php\" METHOD=\"post\">\n"; - - $output .= "<B>". t("Your name") .":</B><BR>\n"; - $output .= format_username($user->userid) ."<P>"; +$theme->header(); - $output .= "<B>". t("Subject") .":</B><BR>\n"; - $output .= "<INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" MAXLENGTH=\"60\" VALUE=\"". check_textfield($subject) ."\"><P>\n"; - - $output .= "<B>". t("Section") .":</B><BR>\n"; - foreach ($sections = section_get() as $value) $options .= " <OPTION VALUE=\"$value\"". ($section == $value ? " SELECTED" : "") .">$value</OPTION>\n"; - $output .= "<SELECT NAME=\"section\">$options</SELECT><P>\n"; - - $output .= "<B>". t("Abstract") .":</B><BR>\n"; - $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"abstract\">". check_textarea($abstract) ."</TEXTAREA><BR>\n"; - $output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n"; - - $output .= "<B>". t("Extended story") .":</B><BR>\n"; - $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"15\" NAME=\"article\">". check_textarea($article) ."</TEXTAREA><BR>\n"; - $output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n"; - - $duplicate = db_result(db_query("SELECT COUNT(id) FROM stories WHERE subject = '". check_input($subject) ."'")); - - if (empty($subject)) { - $output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a subject.") ."</FONT><P>\n"; - $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview submission") ."\">\n"; - } - else if (empty($abstract)) { - $output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply an abstract.") ."</FONT><P>\n"; - $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview submission") ."\">\n"; - } - else if ($duplicate) { - $output .= "<FONT COLOR=\"red\">". t("Warning: there is already a story with that subject.") ."</FONT><P>\n"; - $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview submission") ."\">\n"; +if ($user->id) { + if ($mod) { + module_execute($mod, "user"); } else { - $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview submission") ."\">\n"; - $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Submit submission") ."\">\n"; - } - $output .= "</FORM>\n"; - - $theme->header(); - $theme->story(new Story($user->userid, $subject, $abstract, $article, $section, time()), "[ ". t("reply to this story") ." ]"); - $theme->box(t("Submit a story"), $output); - $theme->footer(); -} + module_iterate("submit_type"); -function submit_submit($subject, $abstract, $article, $section) { - global $user, $theme; + $output .= "<P>". t("If you have written something or if you have some news or thoughts that you would like to share, then this is the place where you can submit new content. Fill out this form and your contribution will automatically get whisked away to our submission queue where our moderators will frown at it, poke at it and hopefully post it.") ."</P>"; - // Add log entry: - watchdog("story", "story: added '$subject'"); + $output .= "<FORM ACTION=\"submit.php\" METHOD=\"get\">\n"; + $output .= "<B>". t("Submission type") .":</B><BR>\n"; + foreach ($modules as $key => $value) $options .= "<OPTION VALUE=\"$key\">$value</OPTION>"; + $output .= "<SELECT NAME=\"mod\">$options</SELECT><P>\n"; + $output .= "<INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"". t("Next step") ."\">\n"; - // Add submission to SQL table: - db_query("INSERT INTO stories (author, subject, abstract, article, section, timestamp) VALUES ('$user->id', '$subject', '$abstract', '$article', '$section', '". time() ."')"); + //» reset « - // Display confirmation message: - $theme->header(); - $theme->box(t("Submission completed"), t("Thank you for your submission. Your submission has been whisked away to our submission queue where our registered users will frown at it, poke at it and hopefully carry it to the front page for discussion.")); - $theme->footer(); + $theme->box("Submit", $output); + } } - -switch($op) { - case t("Preview submission"): - submit_preview(($subject ? check_output($subject) : ""), ($abstract ? check_output($abstract) : ""), ($article ? check_output($article) : ""), check_output($section)); - break; - case t("Submit submission"): - submit_submit(check_input($subject), check_input($abstract), check_input($article), check_input($section)); - break; - default: - submit_enter(); - break; +else { + $theme->box("Submit", t("This page requires a valid user account. Please <A HREF=\"account.php\">login</A> prior to accessing it.")); } +$theme->footer(); ?> diff --git a/themes/example/example.theme b/themes/example/example.theme index 15787c598..02d2ce925 100644 --- a/themes/example/example.theme +++ b/themes/example/example.theme @@ -128,7 +128,7 @@ // Author and date: echo " <TR>"; - echo " <TD>"; + echo " <TD>"; echo t("Author") .":"; echo " </TD>"; echo " <TD COLSPAN=\"2\">"; |