story.module 3.79 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?php
2
// $Id$
Dries's avatar
 
Dries committed
3

Dries's avatar
 
Dries committed
4
class Story {
Dries's avatar
 
Dries committed
5
  function Story($story) {
Dries's avatar
 
Dries committed
6
    $this = new Node($story);
Dries's avatar
 
Dries committed
7 8
    $this->abstract = $story[abstract];
    $this->body = $story[body];
Dries's avatar
 
Dries committed
9 10 11
  }
}

Dries's avatar
 
Dries committed
12 13 14 15
function story_status() {
  return array(dumped, queued, posted);
}

Dries's avatar
 
Dries committed
16
function story_search($keys) {
Dries's avatar
 
Dries committed
17
  global $PHP_SELF, $status;
Dries's avatar
 
Dries committed
18
  $result = db_query("SELECT n.*, s.* FROM story s LEFT JOIN node n ON n.nid = s.nid WHERE n.status = '$status[posted]' AND (n.title LIKE '%$keys%' OR s.abstract LIKE '%$keys%' OR s.body LIKE '%$keys%') ORDER BY n.timestamp DESC LIMIT 20");
Dries's avatar
 
Dries committed
19
  while ($story = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
20
    $find[$i++] = array("title" => check_output($story->title), "link" => (strstr($PHP_SELF, "admin.php") ? "admin.php?mod=node&type=story&op=edit&id=$story->nid" : "node.php?id=$story->nid"), "user" => $story->name, "date" => $story->timestamp);
Dries's avatar
 
Dries committed
21 22 23 24
  }
  return $find;
}

Dries's avatar
 
Dries committed
25 26
function story_help() {
 ?>
Dries's avatar
 
Dries committed
27 28 29
  <P>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.</P>
  <P>Posted stories: published stories accessible to all visitors.</P>
  <P>Dumped stories: rejected stories that are no longer available to visitors.</P>
Dries's avatar
 
Dries committed
30
 <?php
Dries's avatar
 
Dries committed
31 32
}

Dries's avatar
 
Dries committed
33 34 35 36
function story_summary($node) {
  return $node->abstract;
}

Dries's avatar
 
Dries committed
37 38
function story_view($node, $main = 0) {
  global $theme;
39
  $node->body = ((!$main) && ($node->body)) ? "$node->abstract<HR>$node->body" : $node->abstract;
Dries's avatar
 
Dries committed
40
  $theme->node($node, $main);
Dries's avatar
 
Dries committed
41
}
Dries's avatar
 
Dries committed
42

Dries's avatar
 
Dries committed
43
function story_form($edit = array()) {
Dries's avatar
 
Dries committed
44
  global $user;
Dries's avatar
 
Dries committed
45

Dries's avatar
 
Dries committed
46 47 48 49
  if ($edit[title]) {
    story_view(new Story(node_preview($edit)));
  }

Dries's avatar
 
Dries committed
50
  $form .= form_item(t("Your name"), ($edit[name] ? $edit[name] : ($user->name ? $user->name : variable_get(anonymous, "Anonymous"))));
Dries's avatar
 
Dries committed
51
  $form .= form_hidden("name", $edit[name]);
Dries's avatar
 
Dries committed
52
  $form .= form_textfield(t("Subject"), "title", $edit[title], 50, 64);
Dries's avatar
 
Dries committed
53
  $form .= node_attributes_edit("story", $edit);
Dries's avatar
 
Dries committed
54 55
  $form .= form_textarea(t("Abstract"), "abstract", $edit[abstract], 70, 10, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
  $form .= form_textarea(t("Body"), "body", $edit[body], 70, 20, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
Dries's avatar
 
Dries committed
56

Dries's avatar
 
Dries committed
57 58 59
  if ($edit[nid] > 0) {
    $form .= form_hidden("nid", $edit[nid]);
  }
Dries's avatar
 
Dries committed
60

Dries's avatar
 
Dries committed
61 62 63 64
  if (!$edit) {
    $form .= form_submit(t("Preview"));
  }
  else if ($edit && !$edit[title]) {
Dries's avatar
 
Dries committed
65
    $form .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a subject.") ."</FONT><P>\n";
Dries's avatar
 
Dries committed
66
    $form .= form_submit(t("Preview"));
Dries's avatar
 
Dries committed
67
  }
Dries's avatar
 
Dries committed
68
  else if ($edit && !$edit[abstract]) {
Dries's avatar
 
Dries committed
69
    $form .= "<FONT COLOR=\"red\">". t("Warning: you did not supply an abstract.") ."</FONT><P>\n";
Dries's avatar
 
Dries committed
70
    $form .= form_submit(t("Preview"));
Dries's avatar
 
Dries committed
71 72
  }
  else {
Dries's avatar
 
Dries committed
73 74
    $form .= form_submit(t("Preview"));
    $form .= form_submit(t("Submit"));
Dries's avatar
 
Dries committed
75
  }
Dries's avatar
 
Dries committed
76

Dries's avatar
 
Dries committed
77
  return form($form);
Dries's avatar
 
Dries committed
78 79
}

Dries's avatar
 
Dries committed
80
function story_save($edit) {
Dries's avatar
 
Dries committed
81 82 83
  global $status, $user;

  if (!$edit[nid]) {
Dries's avatar
 
Dries committed
84
    node_save($edit, array(abstract, attributes => node_attributes_save("story", $edit), uid => $user->uid, body, comment => variable_get("story_comment", 0), moderate => variable_get("story_moderate", ""), promote => variable_get("story_promote", 0), score => 0, status => variable_get("story_status", $status[queued]), timestamp => time(), title, type => "story", votes => 0));
Dries's avatar
 
Dries committed
85
  }
Dries's avatar
 
Dries committed
86
  else if (user_access("administer nodes")) {
Dries's avatar
 
Dries committed
87
    node_save($edit, array(abstract, attributes => node_attributes_save("story", $edit), body, title, type => "story"));
Dries's avatar
 
Dries committed
88
  }
Dries's avatar
 
Dries committed
89 90
}

Dries's avatar
 
Dries committed
91
function story_user() {
Dries's avatar
 
Dries committed
92
  global $edit, $op, $theme;
Dries's avatar
 
Dries committed
93 94 95

  switch($op) {
    case t("Preview"):
Dries's avatar
 
Dries committed
96
      $theme->box(t("Submit"), story_form($edit));
Dries's avatar
 
Dries committed
97
      break;
Dries's avatar
 
Dries committed
98
    case t("Submit"):
Dries's avatar
 
Dries committed
99
      story_save($edit);
Dries's avatar
 
Dries committed
100
      $theme->box(t("Submit"), t("Thank you for your submission."));
Dries's avatar
 
Dries committed
101 102
      break;
    default:
Dries's avatar
 
Dries committed
103
      $theme->box(t("Submit"), story_form());
Dries's avatar
 
Dries committed
104 105
  }
}
106

Dries's avatar
 
Dries committed
107
?>