"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"; } $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(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"; } $blocks[1]["subject"] = "Top 10:
    recent stories"; $blocks[1]["content"] = $content; $blocks[1]["info"] = "Top 10: recent stories"; 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 $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 .= " Author:
    \n"; $output .= " ". format_username($story->userid) ."\n"; $output .= "

    \n"; $output .= "

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

    \n"; $output .= "
    \n"; print $output; } 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() { $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"; while ($story = db_fetch_object($result)) { $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"; } // 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 .= "
    queued stories
    id\">". check_output($story->subject) ."". format_username($story->userid, 1) ."votes: $story->votes, score: $story->scoreid\">edit
    scheduled stories
    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, $edit; print "add new story | overview | help
    \n"; switch ($op) { case "add": story_add(); break; case "edit": story_edit($id); break; case "help": story_help(); break; case "Add story": story_add_save($edit); story_display(); break; case "Save story": story_edit_save($id, $edit); story_display(); break; default: story_display(); } } ?>