"story_cron", "help" => "story_help", "find" => "story_find", "user" => "story_user", "queue" => "story_queue", "admin" => "story_admin", "block" => "story_block"); include_once "includes/section.inc"; class Story { function Story($userid, $title, $abstract, $body, $section, $timestamp) { $this->userid = $userid; $this->title = $title; $this->abstract = $abstract; $this->body = $body; $this->section = $section; $this->timestamp = $timestamp; } } function story_cron() { global $status; $result = db_query("SELECT * FROM node WHERE status = '$status[scheduled]' AND timestamp <= ". time() .""); while ($story = db_fetch_object($result)) { db_query("UPDATE node SET status = '$status[queued]', timestamp = '". time() ."' WHERE nid = '$story->nid' AND type = 'story'"); } } function story_find($keys) { global $status, $user; $find = array(); $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"); 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)); } return $find; } function story_search() { global $keys, $mod; print search_form($keys); print search_data($keys, $mod); } function story_help() { ?>

Scheduled stories: stories that are scheduled to be automatically published at a given date and time. Useful when you have to leave the site alone for a while or when you want to regulate the flow of new content.

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.

Posted stories: published stories accessible to all visitors.

Dumped stories: rejected stories that are no longer available to visitors.

header(); comment_preview(check_input($pid), check_input($id), ($subject ? check_output($subject) : ""), ($comment ? check_output($comment) : "")); $theme->footer(); break; case t("Post comment"): comment_post(check_input($pid), check_input($id), check_input($subject), check_input($comment)); $theme->header(); $theme->story($node, "[ nid&pid=0\">". t("reply to this story") ." ]"); comment_render($id, $cid); $theme->footer(); break; case "reply": $theme->header(); comment_reply(check_input($pid), check_input($id)); $theme->footer(); break; case t("Update settings"): comment_settings(check_input($mode), check_input($order), check_input($threshold)); $theme->header(); $theme->story($node, "[ nid&pid=0\">". t("reply to this story") ." ]"); comment_render($id, $cid); $theme->footer(); break; case t("Moderate comments"): comment_moderate($moderate); $theme->header(); $theme->story($node, "[ nid&pid=0\">". t("reply to this story") ." ]"); comment_render($id, $cid); $theme->footer(); break; case "reply": $theme->header(); comment_reply(check_input($pid), check_input($id)); $theme->footer(); break; default: $theme->header(); $theme->story($node, "[ nid&pid=0\">". t("reply to this story") ." ]"); comment_render($id, $cid); $theme->footer(); } } else { $theme->story($node, "[ nid&pid=0\">". t("reply to this story") ." ]"); } } function story_form($edit = array()) { global $allowed_html, $REQUEST_URI, $status, $theme, $user; $output .= "
\n"; $output .= "". t("Your name") .":
\n"; $output .= "\n"; $output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."

"; $output .= "". t("Subject") .":
\n"; $output .= "

\n"; $output .= "". t("Section") .":
\n"; foreach ($sections = section_get() as $value) $options .= " \n"; $output .= "

\n"; $output .= "". t("Abstract") .":
\n"; $output .= "
\n"; $output .= "". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".

\n"; $output .= "". t("Body") .":
\n"; $output .= "
\n"; $output .= "". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".

\n"; if (user_access($user, "story")) { $output .= "". t("Status") .":
\n"; $output .= " scheduled for
\n"; $output .= " posted
\n"; $output .= " queued
\n"; $output .= " dumped
\n"; $output .= "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") ."', ...

\n"; $output .= "\n"; $output .= "\n"; } $duplicate = db_result(db_query("SELECT COUNT(nid) FROM node WHERE title = '$title'")); if (!$edit) { $output .= "\n"; } else if (!$edit[title]) { $output .= "". t("Warning: you did not supply a subject.") ."

\n"; $output .= "\n"; } else if (!$edit[section]) { $output .= "". t("Warning: you did not supply a section.") ."

\n"; $output .= "\n"; } else if (!$edit[abstract]) { $output .= "". t("Warning: you did not supply an abstract.") ."

\n"; $output .= "\n"; } else if (!$edit[nid] && $duplicate) { $output .= "". t("Warning: there is already a story with that subject.") ."

\n"; $output .= "\n"; } else { $output .= "\n"; $output .= "\n"; } $output .= "

\n"; return $output; } function story_save($edit) { global $status; $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 => $edit[nid], type => "story")), array(userid => $edit[userid]))); } function story_delete($id) { return ($node = node_del("nid", $id) ? "story has been deleted" : "failed to delete story: change status to 'dumped' first"); } function story_block() { /* // // disabled for now // global $status; $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"); while ($story = db_fetch_object($result)) { $content .= "
  • id\">". check_output($story->title) ."
    (". format_plural($story->comments, "comment", "comments") .")
  • \n"; } $blocks[0][subject] = "Top 10:
    all stories"; $blocks[0][content] = $content; $blocks[0][info] = "Top 10: all stories"; unset($content); $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"); while ($story = db_fetch_object($result)) { $content .= "
  • id\">". check_output($story->title) ."
    (". format_plural($story->comments, "comment", "comments") .")
  • \n"; } $blocks[1][subject] = "Top 10:
    recent stories"; $blocks[1][content] = $content; $blocks[1][info] = "Top 10: recent stories"; return $blocks; */ } function story_overview() { global $status; $output .= "\n"; // Queued stories: $result = db_query("SELECT n.*, u.userid FROM node n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = '$status[queued]' ORDER BY timestamp DESC"); $output .= " \n"; while ($node = db_fetch_object($result)) { $output .= " \n"; } // Scheduled stories: $result = db_query("SELECT n.*, u.userid FROM node n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'story' AND n.status = '$status[scheduled]' ORDER BY timestamp DESC"); $output .= " \n"; while ($node = db_fetch_object($result)) { $output .= " \n"; } // Dumped stories: $result = db_query("SELECT n.*, u.userid FROM node 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 .= " \n"; while ($node = db_fetch_object($result)) { $output .= " \n"; } // Posted stories: $result = db_query("SELECT n.*, u.userid FROM node 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 .= " \n"; while ($node = db_fetch_object($result)) { $output .= " \n"; } $output .= "
    queued stories
    nid\">". check_output($node->title) ."". format_username($node->userid) ."votes: $node->votes, score: $node->scorenid\">viewnid\">editnid\">delete
    scheduled stories
    nid\">". check_output($node->title) ."". format_username($node->userid) ."". format_date($node->timestamp, "small") ."
    (". format_interval($node->timestamp - time()) ." left)
    nid\">viewnid\">editnid\">delete
    dumped stories
    nid\">". check_output($node->title) ."". format_username($node->userid) ."". format_date($node->timestamp, "small") ."nid\">viewnid\">editnid\">delete
    posted stories
    nid\">". check_output($node->title) ."". format_username($node->userid) ."". format_date($node->timestamp, "small") ."nid\">viewnid\">editnid\">delete
    \n"; print $output; } function story_admin() { global $id, $edit, $op, $theme, $user; print "add new story | overview | search story | help
    \n"; switch ($op) { case "add": print story_form(); break; case "delete": print story_delete($id); story_overview(); break; case "edit": print story_form(node_get_array("nid", check_input($id))); break; case "help": story_help(); break; case "search": story_search(); break; case t("Preview"): 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); story_overview(); break; default: story_overview(); } } function story_user() { global $edit, $op, $theme, $user; switch($op) { case t("Preview"): 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); $theme->box(t("Submit a story"), t("Thank you for your submission.")); break; default: $theme->box("Submit a story", story_form()); } } ?>