story.module 3.58 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?php
Dries's avatar
 
Dries committed
2

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

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

Dries's avatar
 
Dries committed
15
function story_search($keys) {
Dries's avatar
 
Dries committed
16
  global $status, $user;
Dries's avatar
 
Dries committed
17
  $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");
Dries's avatar
 
Dries committed
18
  while ($story = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
19
    $find[$i++] = array("title" => check_output($story->title), "link" => (user_access($user, "story") ? "admin.php?mod=node&type=story&op=edit&id=$story->nid" : "node.php?id=$story->nid"), "user" => $story->userid, "date" => $story->timestamp);
Dries's avatar
 
Dries committed
20 21 22 23
  }
  return $find;
}

Dries's avatar
 
Dries committed
24 25
function story_help() {
 ?>
Dries's avatar
 
Dries committed
26 27 28
  <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
29
 <?php
Dries's avatar
 
Dries committed
30 31
}

Dries's avatar
 
Dries committed
32 33
function story_view($node, $main = 0) {
  global $theme;
34
  $node->body = ((!$main) && ($node->body)) ? "$node->abstract<HR>$node->body" : $node->abstract;
Dries's avatar
 
Dries committed
35
  $theme->node($node, $main);
Dries's avatar
 
Dries committed
36
}
Dries's avatar
 
Dries committed
37

Dries's avatar
 
Dries committed
38
function story_form($edit = array()) {
Dries's avatar
CHANGES  
Dries committed
39
  global $REQUEST_URI, $user;
Dries's avatar
 
Dries committed
40

Dries's avatar
 
Dries committed
41 42 43 44
  $form .= form_item(t("Your name"), format_username(($edit[userid] ? $edit[userid] : $user->userid)));
  $form .= form_hidden("userid", $edit[userid]);
  $form .= form_textfield(t("Subject"), "title", $edit[title], 50, 64);
  $form .= structure_form("story", $edit);
Dries's avatar
CHANGES  
Dries committed
45 46
  $form .= form_textarea(t("Abstract"), "abstract", $edit[abstract], 50, 10, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
  $form .= form_textarea(t("Body"), "body", $edit[body], 50, 15, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
Dries's avatar
 
Dries committed
47

Dries's avatar
 
Dries committed
48 49 50
  if ($edit[nid] > 0) {
    $form .= form_hidden("nid", $edit[nid]);
  }
Dries's avatar
 
Dries committed
51

Dries's avatar
 
Dries committed
52
  if (!$edit) {
Dries's avatar
 
Dries committed
53
    $form .= form_submit(t("Preview"));
Dries's avatar
 
Dries committed
54
  }
Dries's avatar
 
Dries committed
55
  else if (!$edit[title]) {
Dries's avatar
 
Dries committed
56
    $form .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a subject.") ."</FONT><P>\n";
Dries's avatar
 
Dries committed
57
    $form .= form_submit(t("Preview"));
Dries's avatar
 
Dries committed
58
  }
Dries's avatar
 
Dries committed
59
  else if (!$edit[abstract]) {
Dries's avatar
 
Dries committed
60
    $form .= "<FONT COLOR=\"red\">". t("Warning: you did not supply an abstract.") ."</FONT><P>\n";
Dries's avatar
 
Dries committed
61
    $form .= form_submit(t("Preview"));
Dries's avatar
 
Dries committed
62 63
  }
  else {
Dries's avatar
 
Dries committed
64 65
    $form .= form_submit(t("Preview"));
    $form .= form_submit(t("Submit"));
Dries's avatar
 
Dries committed
66
  }
Dries's avatar
 
Dries committed
67

Dries's avatar
 
Dries committed
68
  return form($REQUEST_URI, $form);
Dries's avatar
 
Dries committed
69 70
}

Dries's avatar
 
Dries committed
71
function story_save($edit) {
Dries's avatar
 
Dries committed
72 73 74
  global $status, $user;

  if (!$edit[nid]) {
Dries's avatar
 
Dries committed
75
    node_save($edit, array(abstract, author => $user->id, body, cid, 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]), tid, timestamp => time(), title, type => "story", votes => 0));
Dries's avatar
 
Dries committed
76 77 78 79
  }
  else if (user_access($user)) {
    node_save($edit, array(abstract, body, cid, tid, title, type => "story"));
  }
Dries's avatar
 
Dries committed
80 81
}

Dries's avatar
 
Dries committed
82
function story_user() {
Dries's avatar
 
Dries committed
83
  global $edit, $op, $theme, $user;
Dries's avatar
 
Dries committed
84 85 86

  switch($op) {
    case t("Preview"):
Dries's avatar
CHANGES  
Dries committed
87
      story_view(new Story(node_preview($edit)));
Dries's avatar
 
Dries committed
88
      $theme->box(t("Submit"), story_form($edit));
Dries's avatar
 
Dries committed
89
      break;
Dries's avatar
 
Dries committed
90
    case t("Submit"):
Dries's avatar
 
Dries committed
91
      story_save($edit);
Dries's avatar
 
Dries committed
92
      $theme->box(t("Submit"), t("Thank you for your submission."));
Dries's avatar
 
Dries committed
93 94
      break;
    default:
Dries's avatar
 
Dries committed
95
      $theme->box(t("Submit"), story_form());
Dries's avatar
 
Dries committed
96 97 98
  }
}

Dries's avatar
 
Dries committed
99
?>