"story_help",
"find" => "story_find",
"type" => "story_type",
"user" => "story_user",
"queue" => "story_queue",
"admin" => "story_admin",
"block" => "story_block");
class Story {
function Story($story) {
global $user;
$this->userid = $story[userid] ? $story[userid] : $user->userid;
$this->title = $story[title];
$this->abstract = $story[abstract];
$this->body = $story[body];
$this->timestamp = $story[timestamp] ? $story[timestamp] : time();
$this->cid = $story[cid];
$this->tid = $story[tid];
}
}
function story_status() {
return array(dumped, queued, posted);
}
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_help() {
?>
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.
story($node, $main);
}
function story_form($edit = array()) {
global $allowed_html, $REQUEST_URI, $user;
$output .= "\n";
return $output;
}
function story_save($edit) {
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "story", comment => category_comment($edit[cid]))), array(userid => $edit[userid])));
}
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_query($type = "") {
global $status;
$queries = array(array("recent stories", "WHERE n.type = 'story' ORDER BY n.timestamp DESC"), array("posted stories", "WHERE n.type = 'story' AND n.status = '$status[posted]' ORDER BY n.timestamp DESC"), array("queued stories", "WHERE n.type = 'story' AND n.status = '$status[queued]' ORDER BY n.timestamp DESC"), array("dumped stories", "WHERE n.type = 'story' AND n.status = '$status[dumped]' ORDER BY n.timestamp DESC"), array("stories without category (integrity)", "WHERE n.type = 'story' AND n.cid = '0' ORDER BY n.timestamp DESC"), array("stories without topic (integrity)", "WHERE n.type = 'story' AND n.tid = '0' ORDER BY n.timestamp DESC"));
return ($queries[$type] ? $queries[$type] : $queries);
}
function story_overview($query = array()) {
return node_overview($query);
}
function story_admin() {
global $id, $edit, $mod, $keys, $op, $theme, $type, $user;
print "add new story | story listing | search story | overview | help
\n";
$type = ($type ? $type : 0);
switch ($op) {
case "add":
print story_form();
break;
case "delete":
print story_delete($id);
print story_overview(story_query($type));
break;
case "edit":
print story_form(node_get_array("nid", check_input($id)));
break;
case "help":
story_help();
break;
case "listing":
print node_listing(story_query());
break;
case "search":
print search_form($keys);
print search_data($keys, $mod);
break;
case t("Preview"):
story_view(new Story($edit));
print story_form($edit);
break;
case t("Submit"):
story_save($edit);
// fall through:
default:
print story_overview(story_query($type));
}
}
function story_user() {
global $edit, $op, $theme, $user;
switch($op) {
case t("Preview"):
story_view(new Story($edit));
$theme->box(t("Submit"), story_form($edit));
break;
case t("Submit"):
story_save($edit);
$theme->box(t("Submit"), t("Thank you for your submission."));
break;
default:
$theme->box(t("Submit"), story_form());
}
}
?>