2001-03-10 11:07:52 +00:00
<?php
2000-12-14 14:13:37 +00:00
2001-03-24 16:56:10 +00:00
class Story {
2001-04-16 11:38:12 +00:00
function Story($story) {
2001-05-05 13:57:29 +00:00
$this = new Node($story);
2001-04-15 17:01:32 +00:00
$this->abstract = $story[abstract];
$this->body = $story[body];
2001-03-24 16:56:10 +00:00
}
}
2001-04-07 15:02:28 +00:00
function story_status() {
return array(dumped, queued, posted);
}
2001-05-09 18:28:09 +00:00
function story_search($keys) {
2001-03-25 10:57:01 +00:00
global $status, $user;
2001-03-29 19:50:31 +00:00
$result = db_query("SELECT n.*, s.* FROM story s LEFT JOIN node n ON n.nid = s.nid AND n.lid = s.lid WHERE n.status = '$status[posted]' AND (n.title LIKE '%$keys%' OR s.abstract LIKE '%$keys%' OR s.body LIKE '%$keys%') LIMIT 20");
2001-02-07 22:01:57 +00:00
while ($story = db_fetch_object($result)) {
2001-05-09 18:28:09 +00:00
$find[$i++] = 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);
2001-02-07 22:01:57 +00:00
}
return $find;
}
2001-01-07 19:21:28 +00:00
function story_help() {
?>
2001-02-05 16:42:38 +00:00
<P>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</P>
<P>Posted stories: published stories accessible to all visitors.</P>
<P>Dumped stories: rejected stories that are no longer available to visitors.</P>
2001-03-10 11:07:52 +00:00
<?php
2001-01-07 19:21:28 +00:00
}
2001-04-16 18:21:22 +00:00
function story_view($node, $main = 0) {
global $theme;
$theme->story($node, $main);
2001-03-24 16:56:10 +00:00
}
2000-12-24 15:44:29 +00:00
2001-04-16 11:38:12 +00:00
function story_form($edit = array()) {
2001-05-20 13:51:40 +00:00
global $REQUEST_URI, $user;
2000-12-24 15:44:29 +00:00
2001-04-30 17:13:08 +00:00
$form .= form_item(t("Your name"), format_username(($edit[userid] ? $edit[userid] : $user->userid)));
$form .= form_hidden("userid", $edit[userid]);
$form .= form_textfield(t("Subject"), "title", $edit[title], 50, 64);
$form .= structure_form("story", $edit);
2001-05-20 13:51:40 +00:00
$form .= form_textarea(t("Abstract"), "abstract", $edit[abstract], 50, 10, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
$form .= form_textarea(t("Body"), "body", $edit[body], 50, 15, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
2001-03-24 16:56:10 +00:00
2001-05-02 20:52:19 +00:00
// hidden fields:
2001-05-15 18:38:57 +00:00
if ($edit[nid] > 0) {
$form .= form_hidden("nid", $edit[nid]);
}
2001-02-17 15:52:40 +00:00
2001-04-16 11:38:12 +00:00
if (!$edit) {
2001-04-30 17:13:08 +00:00
$form .= form_submit(t("Preview"));
2001-03-24 16:56:10 +00:00
}
2001-04-16 11:38:12 +00:00
else if (!$edit[title]) {
2001-05-12 21:06:13 +00:00
$form .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a subject.") ."</FONT><P>\n";
2001-04-30 17:13:08 +00:00
$form .= form_submit(t("Preview"));
2001-03-24 16:56:10 +00:00
}
2001-04-16 11:38:12 +00:00
else if (!$edit[abstract]) {
2001-05-12 21:06:13 +00:00
$form .= "<FONT COLOR=\"red\">". t("Warning: you did not supply an abstract.") ."</FONT><P>\n";
2001-04-30 17:13:08 +00:00
$form .= form_submit(t("Preview"));
2001-03-24 16:56:10 +00:00
}
else {
2001-04-30 17:13:08 +00:00
$form .= form_submit(t("Preview"));
$form .= form_submit(t("Submit"));
2001-03-24 16:56:10 +00:00
}
2001-01-07 19:21:28 +00:00
2001-04-30 17:13:08 +00:00
return form($REQUEST_URI, $form);
2001-01-07 19:21:28 +00:00
}
2001-04-16 11:38:12 +00:00
function story_save($edit) {
2001-05-15 18:38:57 +00:00
global $status, $user;
if (!$edit[nid]) {
node_save($edit, array(abstract, author => $user->id, body, cid, comment => category_comment($edit[cid]), moderate => topic_moderate($edit[tid]), promote => category_promote($edit[cid]), score => 0, status => (category_submission($edit[cid]) ? $status[queued] : $status[posted]), tid, timestamp => time(), title, type => "story", votes => 0));
}
else if (user_access($user)) {
node_save($edit, array(abstract, body, cid, tid, title, type => "story"));
}
2001-01-07 19:21:28 +00:00
}
2001-03-24 16:56:10 +00:00
function story_block() {
/*
//
// disabled for now
//
2001-03-25 10:57:01 +00:00
global $status;
2001-03-29 19:50:31 +00:00
$result = db_query("SELECT s.lid, COUNT(c.cid) AS comments, s.title FROM story s LEFT JOIN comments c ON s.lid = c.lid WHERE s.status = '$status[posted]' AND c.link = 'story' GROUP BY s.lid ORDER BY comments DESC LIMIT 10");
2001-03-24 16:56:10 +00:00
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";
}
2001-03-03 15:31:01 +00:00
2001-03-28 07:03:47 +00:00
$blocks[0][subject] = "Top 10:<BR>all stories";
$blocks[0][content] = $content;
$blocks[0][info] = "Top 10: all stories";
2001-03-03 15:31:01 +00:00
2001-03-24 16:56:10 +00:00
unset($content);
2001-03-03 15:31:01 +00:00
2001-03-29 19:50:31 +00:00
$result = db_query("SELECT s.lid, COUNT(c.cid) AS comments, s.title FROM story s LEFT JOIN comments c ON s.lid = c.lid WHERE s.status = '$status[posted]' AND c.link = 'story' AND ". time() ." - s.timestamp < 2419200 GROUP BY s.lid ORDER BY comments DESC LIMIT 10");
2001-03-24 16:56:10 +00:00
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";
}
2001-01-26 13:31:41 +00:00
2001-03-28 07:03:47 +00:00
$blocks[1][subject] = "Top 10:<BR>recent stories";
$blocks[1][content] = $content;
$blocks[1][info] = "Top 10: recent stories";
2000-12-14 14:13:37 +00:00
2001-03-24 16:56:10 +00:00
return $blocks;
*/
2000-12-14 14:13:37 +00:00
}
2001-04-10 20:07:27 +00:00
function story_query($type = "") {
global $status;
2001-04-16 13:26:38 +00:00
$queries = array(array("recent stories", "WHERE n.type = 'story' ORDER BY n.timestamp DESC"), array("posted stories", "WHERE n.type = 'story' AND n.status = '$status[posted]' ORDER BY n.timestamp DESC"), array("queued stories", "WHERE n.type = 'story' AND n.status = '$status[queued]' ORDER BY n.timestamp DESC"), array("dumped stories", "WHERE n.type = 'story' AND n.status = '$status[dumped]' ORDER BY n.timestamp DESC"), array("stories without category (integrity)", "WHERE n.type = 'story' AND n.cid = '0' ORDER BY n.timestamp DESC"), array("stories without topic (integrity)", "WHERE n.type = 'story' AND n.tid = '0' ORDER BY n.timestamp DESC"));
2001-04-10 20:07:27 +00:00
return ($queries[$type] ? $queries[$type] : $queries);
}
function story_overview($query = array()) {
return node_overview($query);
2000-12-14 14:13:37 +00:00
}
function story_admin() {
2001-04-16 11:38:12 +00:00
global $id, $edit, $mod, $keys, $op, $theme, $type, $user;
2001-04-10 20:07:27 +00:00
print "<SMALL><A HREF=\"admin.php?mod=story&op=add\">add new story</A> | <A HREF=\"admin.php?mod=story&op=listing\">story listing</A> | <A HREF=\"admin.php?mod=story&op=search\">search story</A> | <A HREF=\"admin.php?mod=story\">overview</A> | <A HREF=\"admin.php?mod=story&op=help\">help</A></SMALL><HR>\n";
2001-01-07 19:21:28 +00:00
2001-04-10 20:07:27 +00:00
$type = ($type ? $type : 0);
2001-01-07 19:21:28 +00:00
2000-12-14 14:13:37 +00:00
switch ($op) {
2001-01-07 19:21:28 +00:00
case "add":
2001-03-24 16:56:10 +00:00
print story_form();
break;
case "delete":
print story_delete($id);
2001-04-10 20:07:27 +00:00
print story_overview(story_query($type));
2001-01-07 19:21:28 +00:00
break;
2000-12-14 14:13:37 +00:00
case "edit":
2001-05-20 16:47:50 +00:00
print story_form(node_get_array(array("nid" => check_input($id))));
2000-12-14 14:13:37 +00:00
break;
2001-01-07 19:21:28 +00:00
case "help":
story_help();
2000-12-14 14:13:37 +00:00
break;
2001-04-10 20:07:27 +00:00
case "listing":
2001-04-11 19:44:24 +00:00
print node_listing(story_query());
2001-04-10 20:07:27 +00:00
break;
2001-03-24 16:56:10 +00:00
case "search":
2001-04-04 21:09:24 +00:00
print search_form($keys);
print search_data($keys, $mod);
2001-02-10 11:59:06 +00:00
break;
2001-03-24 16:56:10 +00:00
case t("Preview"):
2001-05-20 13:51:40 +00:00
story_view(new Story(node_preview($edit)));
2001-04-16 11:38:12 +00:00
print story_form($edit);
2001-03-24 16:56:10 +00:00
break;
case t("Submit"):
2001-04-16 11:38:12 +00:00
story_save($edit);
2001-04-10 20:07:27 +00:00
// fall through:
2001-03-24 16:56:10 +00:00
default:
2001-04-10 20:07:27 +00:00
print story_overview(story_query($type));
2001-03-24 16:56:10 +00:00
}
}
function story_user() {
2001-04-16 11:38:12 +00:00
global $edit, $op, $theme, $user;
2001-03-24 16:56:10 +00:00
switch($op) {
case t("Preview"):
2001-05-20 13:51:40 +00:00
story_view(new Story(node_preview($edit)));
2001-04-16 11:38:12 +00:00
$theme->box(t("Submit"), story_form($edit));
2001-01-07 19:21:28 +00:00
break;
2001-03-24 16:56:10 +00:00
case t("Submit"):
2001-04-16 11:38:12 +00:00
story_save($edit);
2001-04-15 17:01:32 +00:00
$theme->box(t("Submit"), t("Thank you for your submission."));
2000-12-14 14:13:37 +00:00
break;
default:
2001-04-16 11:38:12 +00:00
$theme->box(t("Submit"), story_form());
2000-12-14 14:13:37 +00:00
}
}
2000-12-24 15:44:29 +00:00
?>