"story_cron", "help" => "story_help", "find" => "story_find", "admin" => "story_admin", "block" => "story_block"); include_once "includes/section.inc"; 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_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"); 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)); } 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.

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

    \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"; 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, 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_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"; $output .= "Editor's note/updates:
    \n"; $output .= "
    \n"; $output .= "Allowed HTML tags: ". htmlspecialchars($allowed_html) .".

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

    \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"; 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]) ."', 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]'"); } 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) ."votes: $story->votes, score: $story->scoreid\">edit
    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
    dumped stories
    id\">". check_output($story->subject) ."". format_username($story->userid) ."$story->sectionid\">edit
    posted stories
    id\">". check_output($story->subject) ."". format_username($story->userid) ."$story->sectionid\">edit
    \n"; print $output; } function story_admin() { global $op, $id, $edit; print "add new story | overview | search story | help
    \n"; switch ($op) { case "add": story_add(); break; case "edit": story_edit(check_input($id)); break; case "help": story_help(); break; case "search": story_search(); break; case "Add story": story_add_save($edit); story_display(); break; case "Save story": story_edit_save(check_input($id), $edit); story_display(); break; default: story_display(); } } ?>