From 93f66c06d3658361beee54ea9e7f2be57f5e219b Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 24 Mar 2001 16:56:10 +0000 Subject: - added nodified story module: story extends node - removed includes/story.inc as we no longer need it: story.module is *really* modular now. --- modules/story.module | 307 ++++++++++++++++++++++++++++----------------- modules/story/story.module | 307 ++++++++++++++++++++++++++++----------------- 2 files changed, 386 insertions(+), 228 deletions(-) (limited to 'modules') diff --git a/modules/story.module b/modules/story.module index 907ac16ea..5623d4fba 100644 --- a/modules/story.module +++ b/modules/story.module @@ -3,24 +3,36 @@ $module = array("cron" => "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() { - $result = db_query("SELECT * FROM stories WHERE status = 3 AND timestamp <= ". time() .""); + $result = db_query("SELECT * FROM nodes WHERE status = 3 AND timestamp <= ". time() .""); while ($story = db_fetch_object($result)) { - db_query("UPDATE stories SET status = '1', timestamp = '". time() ."' WHERE id = '$story->id'"); + db_query("UPDATE nodes SET status = '1', timestamp = '". time() ."' WHERE nid = '$story->nid' AND type = 'story'"); } } function story_find($keys) { global $user; $find = array(); - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.status = 2 AND (s.subject LIKE '%". check_input($keys) ."%' OR s.abstract LIKE '%". check_input($keys) ."%' OR s.article LIKE '%$keys%') ORDER BY s.timestamp DESC LIMIT 20"); + $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"); while ($story = db_fetch_object($result)) { - array_push($find, array("subject" => check_output($story->subject), "link" => (user_access($user, "story") ? "admin.php?mod=story&op=edit&id=$story->id" : "story.php?id=$story->id"), "user" => $story->userid, "date" => $story->timestamp)); + 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; } @@ -40,148 +52,193 @@ function story_help() { id\">". check_output($story->subject) ."
(". format_plural($story->comments, "comment", "comments") .")\n"; +function story_view($node, $page = 0) { + global $id, $cid, $op, $pid, $subject, $comment, $theme, $mode, $order, $threshold; + + if ($page == 0) { + switch($op) { + case t("Preview comment"): + $theme->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(); + } } - - $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.id, COUNT(c.cid) AS comments, s.subject FROM stories 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"); - while ($story = db_fetch_object($result)) { - $content .= "
  • id\">". check_output($story->subject) ."
    (". format_plural($story->comments, "comment", "comments") .")
  • \n"; + else { + $theme->story($node, "[ nid&pid=0\">". t("reply to this story") ." ]"); } +} - $blocks[1]["subject"] = "Top 10:
    recent stories"; - $blocks[1]["content"] = $content; - $blocks[1]["info"] = "Top 10: recent stories"; +function story_form($edit = array()) { + global $allowed_html, $PHP_SELF, $theme, $user; - return $blocks; -} + include "includes/story.inc"; -function story_add() { - global $allowed_html; + $output .= "
    \n"; - $output .= "\n"; + $output .= "". t("Your name") .":
    \n"; + $output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."

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

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

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

    \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 .= "Extended story:
    \n"; - $output .= "
    \n"; - $output .= "Allowed HTML tags: ". htmlspecialchars($allowed_html) .".

    \n"; + $duplicate = db_result(db_query("SELECT COUNT(nid) FROM nodes WHERE title = '$title'")); - $output .= "Status:
    \n"; - $output .= "scheduled story for
    \n"; - $output .= "posted story
    \n"; - $output .= "queued story
    \n"; - $output .= "dumped story
    \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"; + 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"; + $output .= "\n"; $output .= "

    \n"; - print $output; + return $output; } -function story_add_save($edit) { - global $user; - $timestamp = ($edit[status] == 3 && strtotime($edit[date]) > time()) ? strtotime($edit[date]) : time(); - db_query("INSERT INTO stories (author, subject, abstract, article, section, status, timestamp) VALUES ('$user->id', '". check_input($edit[subject]) ."', '". check_input($edit[abstract]) ."', '". check_input($edit[article]) ."', '". check_input($edit[section]) ."', '$edit[status]', '$timestamp')"); - watchdog("story", "story: added '$edit[subject]'"); +function story_save($edit) { + $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"))); } -function story_edit($id) { - global $allowed_html; - - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.id = '$id'"); - $story = db_fetch_object($result); - - $output .= "
    \n"; - - $output .= "Author:
    \n"; - $output .= format_username($story->userid) ."

    \n"; - - $output .= "Subject:
    \n"; - $output .= "subject) ."\">

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

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

    \n"; +function story_delete($id) { + node_del_object("nid", $id); +} - $output .= "Editor's note/updates:
    \n"; - $output .= "
    \n"; - $output .= "Allowed HTML tags: ". htmlspecialchars($allowed_html) .".

    \n"; +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"); + while ($story = db_fetch_object($result)) { + $content .= "

  • id\">". check_output($story->title) ."
    (". format_plural($story->comments, "comment", "comments") .")
  • \n"; + } - $output .= "Extended story:
    \n"; - $output .= "
    \n"; - $output .= "Allowed HTML tags: ". htmlspecialchars($allowed_html) .".

    \n"; + $blocks[0]["subject"] = "Top 10:
    all stories"; + $blocks[0]["content"] = $content; + $blocks[0]["info"] = "Top 10: all stories"; - $output .= "Status:
    \n"; - $output .= "status == 3 ? " CHECKED" : "") .">scheduled story for timestamp) ."\">
    \n"; - $output .= "status == 2 ? " CHECKED" : "") .">posted story
    \n"; - $output .= "status == 1 ? " CHECKED" : "") .">queued story
    \n"; - $output .= "status == 0 ? " CHECKED" : "") .">dumped story
    \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"; + unset($content); - $output .= "\n"; - $output .= "

    \n"; + $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"); + while ($story = db_fetch_object($result)) { + $content .= "
  • id\">". check_output($story->title) ."
    (". format_plural($story->comments, "comment", "comments") .")
  • \n"; + } - print $output; -} + $blocks[1]["subject"] = "Top 10:
    recent stories"; + $blocks[1]["content"] = $content; + $blocks[1]["info"] = "Top 10: recent stories"; -function story_edit_save($id, $edit) { - if ($edit[status] == 3 && strtotime($edit[date]) > time()) db_query("UPDATE stories SET subject = '". check_input($edit[subject]) ."', abstract = '". check_input($edit[abstract]) ."', updates = '". check_input($edit[updates]) ."', article = '". check_input($edit[article]) ."', section = '". check_input($edit[section]) ."', status = '$edit[status]', timestamp = '". strtotime($edit[date]) ."' WHERE id = '$id'"); - else db_query("UPDATE stories SET subject = '". check_input($edit[subject]) ."', abstract = '". check_input($edit[abstract]) ."', updates = '". check_input($edit[updates]) ."', article = '". check_input($edit[article]) ."', section = '". check_input($edit[section]) ."', status = '$edit[status]' WHERE id = '$id'"); - watchdog("message", "story: modified '$edit[subject]'"); + return $blocks; +*/ } -function story_display() { +function story_overview() { $output .= "\n"; // Pending stories: - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 1 ORDER BY timestamp DESC"); - $output .= " \n"; + $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"); + $output .= " \n"; while ($story = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } // Scheduled stories: - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 3 ORDER BY timestamp"); - $output .= " \n"; + $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"); + $output .= " \n"; while ($story = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } // Dumped stories: - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 0 ORDER BY timestamp DESC LIMIT 5"); - $output .= " \n"; + $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"); + $output .= " \n"; while ($story = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } // Posted stories: - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 2 ORDER BY timestamp DESC LIMIT 15"); - $output .= " \n"; + $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"); + $output .= " \n"; while ($story = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } $output .= "
    queued stories
    queued stories
    id\">". check_output($story->subject) ."". format_username($story->userid) ."votes: $story->votes, score: $story->scoreid\">edit
    nid\">". check_output($story->title) ."". format_username($story->userid) ."votes: $story->votes, score: $story->scorenid\">viewnid\">editnid\">delete
    scheduled stories
    scheduled stories
    id\">". check_output($story->subject) ."". format_username($story->userid) ."". date("D, m/d/Y H:i", $story->timestamp) ." - ". format_interval($story->timestamp - time()) ." leftid\">edit
    nid\">". check_output($story->title) ."". format_username($story->userid) ."". date("D, m/d/Y H:i", $story->timestamp) ."
    (". format_interval($story->timestamp - time()) ." left)
    nid\">viewnid\">editnid\">delete
    dumped stories
    dumped stories
    id\">". check_output($story->subject) ."". format_username($story->userid) ."$story->sectionid\">edit
    nid\">". check_output($story->title) ."". format_username($story->userid) ."". date("D, m/d/Y H:i", $story->timestamp) ."nid\">viewnid\">editnid\">delete
    posted stories
    posted stories
    id\">". check_output($story->subject) ."". format_username($story->userid) ."$story->sectionid\">edit
    nid\">". check_output($story->title) ."". format_username($story->userid) ."". date("D, m/d/Y H:i", $story->timestamp) ."nid\">viewnid\">editnid\">delete
    \n"; @@ -190,33 +247,55 @@ function story_display() { } function story_admin() { - global $op, $id, $edit; + global $id, $edit, $op, $theme, $user; print "add new story | overview | search story | help
    \n"; switch ($op) { case "add": - story_add(); + print story_form(); + break; + case "delete": + print story_delete($id); + story_overview(); break; case "edit": - story_edit(check_input($id)); + print story_form(node_get_array("nid", check_input($id))); break; case "help": story_help(); break; - case "search": + case "search": story_search(); break; - case "Add story": - story_add_save($edit); - story_display(); + 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") ." ]"); + print story_form($edit); + break; + case t("Submit"): + story_save($edit, check_input($id)); + story_overview(); + break; + default: + story_overview(); + } +} + + +function story_user() { + global $edit, $id, $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") ." ]"); + $theme->box("Submit a story", story_form($edit)); break; - case "Save story": - story_edit_save(check_input($id), $edit); - story_display(); + case t("Submit"): + story_save($edit, check_input($id)); + $theme->box(t("Submit a story"), t("Thank you for your submission.")); break; default: - story_display(); + $theme->box("Submit a story", story_form()); } } diff --git a/modules/story/story.module b/modules/story/story.module index 907ac16ea..5623d4fba 100644 --- a/modules/story/story.module +++ b/modules/story/story.module @@ -3,24 +3,36 @@ $module = array("cron" => "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() { - $result = db_query("SELECT * FROM stories WHERE status = 3 AND timestamp <= ". time() .""); + $result = db_query("SELECT * FROM nodes WHERE status = 3 AND timestamp <= ". time() .""); while ($story = db_fetch_object($result)) { - db_query("UPDATE stories SET status = '1', timestamp = '". time() ."' WHERE id = '$story->id'"); + db_query("UPDATE nodes SET status = '1', timestamp = '". time() ."' WHERE nid = '$story->nid' AND type = 'story'"); } } function story_find($keys) { global $user; $find = array(); - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.status = 2 AND (s.subject LIKE '%". check_input($keys) ."%' OR s.abstract LIKE '%". check_input($keys) ."%' OR s.article LIKE '%$keys%') ORDER BY s.timestamp DESC LIMIT 20"); + $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"); while ($story = db_fetch_object($result)) { - array_push($find, array("subject" => check_output($story->subject), "link" => (user_access($user, "story") ? "admin.php?mod=story&op=edit&id=$story->id" : "story.php?id=$story->id"), "user" => $story->userid, "date" => $story->timestamp)); + 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; } @@ -40,148 +52,193 @@ function story_help() { id\">". check_output($story->subject) ."
    (". format_plural($story->comments, "comment", "comments") .")\n"; +function story_view($node, $page = 0) { + global $id, $cid, $op, $pid, $subject, $comment, $theme, $mode, $order, $threshold; + + if ($page == 0) { + switch($op) { + case t("Preview comment"): + $theme->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(); + } } - - $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.id, COUNT(c.cid) AS comments, s.subject FROM stories 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"); - while ($story = db_fetch_object($result)) { - $content .= "
  • id\">". check_output($story->subject) ."
    (". format_plural($story->comments, "comment", "comments") .")
  • \n"; + else { + $theme->story($node, "[ nid&pid=0\">". t("reply to this story") ." ]"); } +} - $blocks[1]["subject"] = "Top 10:
    recent stories"; - $blocks[1]["content"] = $content; - $blocks[1]["info"] = "Top 10: recent stories"; +function story_form($edit = array()) { + global $allowed_html, $PHP_SELF, $theme, $user; - return $blocks; -} + include "includes/story.inc"; -function story_add() { - global $allowed_html; + $output .= "
    \n"; - $output .= "\n"; + $output .= "". t("Your name") .":
    \n"; + $output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."

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

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

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

    \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 .= "Extended story:
    \n"; - $output .= "
    \n"; - $output .= "Allowed HTML tags: ". htmlspecialchars($allowed_html) .".

    \n"; + $duplicate = db_result(db_query("SELECT COUNT(nid) FROM nodes WHERE title = '$title'")); - $output .= "Status:
    \n"; - $output .= "scheduled story for
    \n"; - $output .= "posted story
    \n"; - $output .= "queued story
    \n"; - $output .= "dumped story
    \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"; + 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"; + $output .= "\n"; $output .= "

    \n"; - print $output; + return $output; } -function story_add_save($edit) { - global $user; - $timestamp = ($edit[status] == 3 && strtotime($edit[date]) > time()) ? strtotime($edit[date]) : time(); - db_query("INSERT INTO stories (author, subject, abstract, article, section, status, timestamp) VALUES ('$user->id', '". check_input($edit[subject]) ."', '". check_input($edit[abstract]) ."', '". check_input($edit[article]) ."', '". check_input($edit[section]) ."', '$edit[status]', '$timestamp')"); - watchdog("story", "story: added '$edit[subject]'"); +function story_save($edit) { + $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"))); } -function story_edit($id) { - global $allowed_html; - - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.id = '$id'"); - $story = db_fetch_object($result); - - $output .= "
    \n"; - - $output .= "Author:
    \n"; - $output .= format_username($story->userid) ."

    \n"; - - $output .= "Subject:
    \n"; - $output .= "subject) ."\">

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

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

    \n"; +function story_delete($id) { + node_del_object("nid", $id); +} - $output .= "Editor's note/updates:
    \n"; - $output .= "
    \n"; - $output .= "Allowed HTML tags: ". htmlspecialchars($allowed_html) .".

    \n"; +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"); + while ($story = db_fetch_object($result)) { + $content .= "

  • id\">". check_output($story->title) ."
    (". format_plural($story->comments, "comment", "comments") .")
  • \n"; + } - $output .= "Extended story:
    \n"; - $output .= "
    \n"; - $output .= "Allowed HTML tags: ". htmlspecialchars($allowed_html) .".

    \n"; + $blocks[0]["subject"] = "Top 10:
    all stories"; + $blocks[0]["content"] = $content; + $blocks[0]["info"] = "Top 10: all stories"; - $output .= "Status:
    \n"; - $output .= "status == 3 ? " CHECKED" : "") .">scheduled story for timestamp) ."\">
    \n"; - $output .= "status == 2 ? " CHECKED" : "") .">posted story
    \n"; - $output .= "status == 1 ? " CHECKED" : "") .">queued story
    \n"; - $output .= "status == 0 ? " CHECKED" : "") .">dumped story
    \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"; + unset($content); - $output .= "\n"; - $output .= "

    \n"; + $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"); + while ($story = db_fetch_object($result)) { + $content .= "
  • id\">". check_output($story->title) ."
    (". format_plural($story->comments, "comment", "comments") .")
  • \n"; + } - print $output; -} + $blocks[1]["subject"] = "Top 10:
    recent stories"; + $blocks[1]["content"] = $content; + $blocks[1]["info"] = "Top 10: recent stories"; -function story_edit_save($id, $edit) { - if ($edit[status] == 3 && strtotime($edit[date]) > time()) db_query("UPDATE stories SET subject = '". check_input($edit[subject]) ."', abstract = '". check_input($edit[abstract]) ."', updates = '". check_input($edit[updates]) ."', article = '". check_input($edit[article]) ."', section = '". check_input($edit[section]) ."', status = '$edit[status]', timestamp = '". strtotime($edit[date]) ."' WHERE id = '$id'"); - else db_query("UPDATE stories SET subject = '". check_input($edit[subject]) ."', abstract = '". check_input($edit[abstract]) ."', updates = '". check_input($edit[updates]) ."', article = '". check_input($edit[article]) ."', section = '". check_input($edit[section]) ."', status = '$edit[status]' WHERE id = '$id'"); - watchdog("message", "story: modified '$edit[subject]'"); + return $blocks; +*/ } -function story_display() { +function story_overview() { $output .= "\n"; // Pending stories: - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 1 ORDER BY timestamp DESC"); - $output .= " \n"; + $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"); + $output .= " \n"; while ($story = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } // Scheduled stories: - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 3 ORDER BY timestamp"); - $output .= " \n"; + $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"); + $output .= " \n"; while ($story = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } // Dumped stories: - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 0 ORDER BY timestamp DESC LIMIT 5"); - $output .= " \n"; + $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"); + $output .= " \n"; while ($story = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } // Posted stories: - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author WHERE s.status = 2 ORDER BY timestamp DESC LIMIT 15"); - $output .= " \n"; + $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"); + $output .= " \n"; while ($story = db_fetch_object($result)) { - $output .= " \n"; + $output .= " \n"; } $output .= "
    queued stories
    queued stories
    id\">". check_output($story->subject) ."". format_username($story->userid) ."votes: $story->votes, score: $story->scoreid\">edit
    nid\">". check_output($story->title) ."". format_username($story->userid) ."votes: $story->votes, score: $story->scorenid\">viewnid\">editnid\">delete
    scheduled stories
    scheduled stories
    id\">". check_output($story->subject) ."". format_username($story->userid) ."". date("D, m/d/Y H:i", $story->timestamp) ." - ". format_interval($story->timestamp - time()) ." leftid\">edit
    nid\">". check_output($story->title) ."". format_username($story->userid) ."". date("D, m/d/Y H:i", $story->timestamp) ."
    (". format_interval($story->timestamp - time()) ." left)
    nid\">viewnid\">editnid\">delete
    dumped stories
    dumped stories
    id\">". check_output($story->subject) ."". format_username($story->userid) ."$story->sectionid\">edit
    nid\">". check_output($story->title) ."". format_username($story->userid) ."". date("D, m/d/Y H:i", $story->timestamp) ."nid\">viewnid\">editnid\">delete
    posted stories
    posted stories
    id\">". check_output($story->subject) ."". format_username($story->userid) ."$story->sectionid\">edit
    nid\">". check_output($story->title) ."". format_username($story->userid) ."". date("D, m/d/Y H:i", $story->timestamp) ."nid\">viewnid\">editnid\">delete
    \n"; @@ -190,33 +247,55 @@ function story_display() { } function story_admin() { - global $op, $id, $edit; + global $id, $edit, $op, $theme, $user; print "add new story | overview | search story | help
    \n"; switch ($op) { case "add": - story_add(); + print story_form(); + break; + case "delete": + print story_delete($id); + story_overview(); break; case "edit": - story_edit(check_input($id)); + print story_form(node_get_array("nid", check_input($id))); break; case "help": story_help(); break; - case "search": + case "search": story_search(); break; - case "Add story": - story_add_save($edit); - story_display(); + 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") ." ]"); + print story_form($edit); + break; + case t("Submit"): + story_save($edit, check_input($id)); + story_overview(); + break; + default: + story_overview(); + } +} + + +function story_user() { + global $edit, $id, $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") ." ]"); + $theme->box("Submit a story", story_form($edit)); break; - case "Save story": - story_edit_save(check_input($id), $edit); - story_display(); + case t("Submit"): + story_save($edit, check_input($id)); + $theme->box(t("Submit a story"), t("Thank you for your submission.")); break; default: - story_display(); + $theme->box("Submit a story", story_form()); } } -- cgit v1.2.3