From 554d9b080b4be1c3ddfae75d79a0789da8c80cf2 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 7 Jan 2001 19:21:28 +0000 Subject: - fixed 2 small bugs in account.php - drastically improved administration section - drastically revamped story administration: added new feature to schedule the publishing of stories - applied correct naming conventions to submission.php - fixed 1 small glitch in boxes - somewhat expanded the documentation = changed one SQL table - updated the faq with info on drupal - ... and more things I forgot about --- modules/story.module | 201 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 142 insertions(+), 59 deletions(-) (limited to 'modules/story.module') diff --git a/modules/story.module b/modules/story.module index 5a18671a1..3e7d6a8b2 100644 --- a/modules/story.module +++ b/modules/story.module @@ -1,10 +1,28 @@ "story_block", +$module = array("cron" => "story_cron", + "help" => "story_help", + "block" => "story_block", "admin" => "story_admin"); +function story_cron() { + $result = db_query("SELECT * FROM stories 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'"); + } +} + +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 to frown at it. Moderators vote whether or not a story should be carried 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.

+ id\">$story->subject
(". format_plural($story->comments, "comment", "comments") .")\n"; } @@ -15,7 +33,7 @@ function story_block() { unset($content); - $result = db_query("select s.id, COUNT(s.id) as comments, s.subject from stories s left join comments c on s.id = c.sid WHERE s.status = 2 AND ". time() ." - s.timestamp < 2419200 GROUP BY s.id ORDER BY comments DESC LIMIT 10"); + $result = db_query("SELECT s.id, COUNT(s.id) AS comments, s.subject FROM stories s LEFT JOIN comments c ON s.id = c.sid WHERE s.status = 2 AND ". time() ." - s.timestamp < 2419200 GROUP BY s.id ORDER BY comments DESC LIMIT 10"); while ($story = db_fetch_object($result)) { $content .= "
  • id\">$story->subject
    (". format_plural($story->comments, "comment", "comments") .")
  • \n"; } @@ -27,13 +45,68 @@ function story_block() { return $blocks; } +function story_add() { + global $allowed_html, $categories; + + $output .= "
    \n"; + + $output .= "

    \n"; + $output .= " Subject:
    \n"; + $output .= "
    \n"; + $output .= "

    \n"; + + $output .= "

    Category:
    \n"; + $output .= " \n"; + $output .= "

    \n"; + + $output .= "

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

    \n"; + + $output .= "

    \n"; + $output .= " Extended story:
    \n"; + $output .= "
    \n"; + $output .= " Allowed HTML tags: ". htmlspecialchars($allowed_html) .".\n"; + $output .= "

    \n"; + + $output .= "

    \n"; + $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"; + $output .= "

    \n"; + + $output .= "

    \n"; + $output .= " \n"; + $output .= "

    \n"; + + $output .= "
    \n"; + + print $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, category, status, timestamp) VALUES ('$user->id', '". check_input($edit[subject]) ."', '". check_input($edit[abstract]) ."', '". check_input($edit[article]) ."', '". check_input($edit[category]) ."', '$edit[status]', '$timestamp')"); + watchdog("story", "story: added '$edit[subject]'"); +} + function story_edit($id) { - global $categories; + global $allowed_html, $categories; $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 .= "\n"; $output .= "

    \n"; $output .= " Author:
    \n"; @@ -42,40 +115,43 @@ function story_edit($id) { $output .= "

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

    \n"; - $output .= "

    Category:
    \n"; - $output .= " \n"; for ($i = 0; $i < sizeof($categories); $i++) { - $output .= " \n"; + $output .= " \n"; } $output .= "\n"; $output .= "

    \n"; $output .= "

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

    \n"; $output .= "

    \n"; - $output .= "Editor's note/updates:
    \n"; - $output .= "
    \n"; + $output .= " Editor's note/updates:
    \n"; + $output .= "
    \n"; + $output .= " Allowed HTML tags: ". htmlspecialchars($allowed_html) .".\n"; $output .= "

    \n"; $output .= "

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

    \n"; - $output .= "

    Status:
    \n"; - $output .= " \n"; + $output .= "

    \n"; + $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"; $output .= "

    \n"; $output .= "

    \n"; @@ -86,63 +162,70 @@ function story_edit($id) { print $output; } -function story_save($id, $subject, $abstract, $updates, $article, $category, $status) { - db_query("UPDATE stories SET subject = '". check_input($subject) ."', abstract = '". check_input($abstract) ."', updates = '". check_input($updates) ."', article = '". check_input($article) ."', category = '". check_input($category) ."', status = '$status' WHERE id = $id"); +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]) ."', category = '". check_input($edit[category]) ."', 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]) ."', category = '". check_input($edit[category]) ."', status = '$edit[status]' WHERE id = '$id'"); watchdog("message", "story: modified `$subject'"); } -function story_display($order = "date") { - // Initialize variables: - $status = array("deleted", "pending", "public"); - $fields = array("author" => "author", "category" => "category", "date" => "timestamp DESC", "status" => "status DESC"); - - // Perform SQL query: - $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author ORDER BY s.$fields[$order]"); - - // Display stories: +function story_display() { $output .= "\n"; - $output .= " \n"; - $output .= " \n"; + while ($story = db_fetch_object($result)) { + $output .= " \n"; } - $output .= " \n"; - $output .= " \n"; - $output .= " \n"; - $output .= " \n"; - $output .= " \n"; - - $output .= " \n"; - $output .= " \n"; - $output .= " \n"; - $output .= " \n"; - $output .= " \n"; - $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"; 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"; + while ($story = db_fetch_object($result)) { + $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"; + while ($story = db_fetch_object($result)) { + $output .= " \n"; + } + $output .= "
    \n"; - $output .= " \n"; - $output .= "
    queued stories
    id\">". check_output($story->subject) ."". format_username($story->userid, 1) ."votes: $story->votes, score: $story->scoreid\">edit
    subjectauthorcategorystatusoperations
    scheduled stories
    id\">". check_output($story->subject) ."". format_username($story->userid, 1) ."$story->category". $status[$story->status] ."id\">edit
    id\">". check_output($story->subject) ."". format_username($story->userid, 1) ."". date("D, m/d/Y H:i", $story->timestamp) ." - ". format_interval($story->timestamp - time()) ." leftid\">edit
    dumped stories
    id\">". check_output($story->subject) ."". format_username($story->userid, 1) ."$story->categoryid\">edit
    posted stories
    id\">". check_output($story->subject) ."". format_username($story->userid, 1) ."$story->categoryid\">edit
    \n"; print $output; } function story_admin() { - global $op, $id, $subject, $abstract, $updates, $article, $category, $status, $order; + global $op, $id, $edit; + + print "add new story | overview | help


    \n"; + switch ($op) { + case "add": + story_add(); + break; case "edit": story_edit($id); break; - case "Save story": - story_save($id, $subject, $abstract, $updates, $article, $category, $status); - story_edit($id); + case "help": + story_help(); break; - case "Update": - story_display($order); + case "Add story": + story_add_save($edit); + story_display(); + break; + case "Save story": + story_edit_save($id, $edit); + story_display(); break; default: story_display(); -- cgit v1.2.3