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

4
function story_help($section = "admin/story/help") {
Dries's avatar
 
Dries committed
5 6
  $output = "";

7 8
  switch ($section) {
    case "admin/system/modules":
Dries's avatar
 
Dries committed
9
      $output = t("Enables users to submit stories, articles or similar content.");
10 11
      break;
    case "admin/system/modules/story":
Dries's avatar
 
Dries committed
12
      $output = t("Stories are like newspaper articles. They tend to follow a publishing flow of <b>submit -&gt; moderate -&gt; post to the main page -&gt; comments</b>. Below you may fix a minimum word count for stories and also write some submission or content guidelines for users wanting to post a story.");
13
      break;
14
    case "admin/story/help":
15
      $output = "<p>The story module lets your users submit articles for consideration by the rest of the community, who can vote on them if moderation is enabled.  Stories usually follow a publishing flow of <b>submit -&gt; moderate -&gt; post to the main page -&gt; comments</b>.  Administrators are able to shortcut this flow as desired.</p>";
Dries's avatar
 
Dries committed
16 17
      $output .= "In %story-config you can set up an introductory text for story authors, and a floor on the number of words which may be included in a story. This is designed to help discourage the submission of trivially short stories.";
      $output = t($output, array("%story-config" => l(t("site configuration &raquo; modules &raquo; story"), "admin/system/modules/story") ));
18 19
      break;
  }
20

Dries's avatar
 
Dries committed
21
  return $output;
Dries's avatar
 
Dries committed
22 23
}

24
function story_system($field){
Dries's avatar
 
Dries committed
25 26 27 28 29 30
  $output = "";

  if ($field == "description") { $output = story_help("admin/system/modules"); }
  else if ($field == "admin_help") { $output = story_help("admin/system/modules/story"); };

  return $output;
31 32
}

33
function story_settings() {
Dries's avatar
 
Dries committed
34 35
 $output .= form_textarea("Explanation or submission guidelines", "story_help", variable_get("story_help", ""), 70, 5, "This text will be displayed at the top of the story submission form.  It is useful for helping or instructing your users.");
 $output .= form_select(t("Minimum number of words"), "minimum_story_size", variable_get("minimum_story_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words",  50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words",  150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a story must be to be considered valid.  This can be useful to rule out submissions that do not meet the site's standards, such as short test posts."));
Dries's avatar
 
Dries committed
36 37 38 39 40 41

 return $output;
}

function story_node($field) {
  $info["name"] = t("story");
Dries's avatar
 
Dries committed
42
  $info["description"] = t("A story is a post that is submitted to the attention of other users and is queued in the submission queue.  Users and moderators vote on the posts they like or dislike, promoting or demoting them.  When a post gets above a certain threshold it automatically gets promoted to the front page.");
Dries's avatar
 
Dries committed
43 44 45
  return $info[$field];
}

Dries's avatar
 
Dries committed
46 47 48 49
function story_perm() {
  return array("create stories");
}

Dries's avatar
 
Dries committed
50 51 52 53 54 55
function story_access($op, $node) {
  if ($op == "view") {
    return $node->status;
  }

  if ($op == "create") {
Dries's avatar
 
Dries committed
56
    return user_access("create stories");
Dries's avatar
 
Dries committed
57 58 59
  }
}

Dries's avatar
 
Dries committed
60
function story_link($type) {
Dries's avatar
 
Dries committed
61 62
  $links = array();

Dries's avatar
 
Dries committed
63 64
  if ($type == "system") {
    if (user_access("create stories")) {
Dries's avatar
 
Dries committed
65
      menu("node/add/story", t("story"), "story_page", NULL, 0);
Dries's avatar
 
Dries committed
66
    }
Dries's avatar
 
Dries committed
67 68
  }

Dries's avatar
 
Dries committed
69
  return $links;
Dries's avatar
 
Dries committed
70 71
}

Dries's avatar
 
Dries committed
72
function story_validate(&$node) {
Dries's avatar
 
Dries committed
73

Dries's avatar
 
Dries committed
74 75 76
  /*
  ** Validate the size of the story:
  */
Dries's avatar
 
Dries committed
77

Dries's avatar
 
Dries committed
78 79 80
  if (isset($node->body) && count(explode(" ", $node->body)) < variable_get("minimum_story_size", 0)) {
print "body : $node->body";
    $error["body"] = "<div class=\"error\">". t("The body of your story is too short.") ."</div>";
Dries's avatar
 
Dries committed
81 82
  }

Dries's avatar
 
Dries committed
83 84 85 86
  return $error;
}

function story_form(&$node, &$help, &$error) {
Dries's avatar
 
Dries committed
87

Dries's avatar
 
Dries committed
88 89 90
  /*
  ** Carry out some explanation or submission guidelines:
  */
Dries's avatar
 
Dries committed
91

Dries's avatar
 
Dries committed
92
  $help = variable_get("story_help", "");
Dries's avatar
 
Dries committed
93

94 95 96
  if (function_exists("taxonomy_node_form")) {
    $output .= implode("", taxonomy_node_form("story", $node));
  }
Dries's avatar
 
Dries committed
97

Dries's avatar
 
Dries committed
98
  $output .= form_textarea(t("Body"), "body", $node->body, 60, 15, $error["body"] ? $error["body"] : form_allowed_tags_text());
Dries's avatar
 
Dries committed
99 100 101 102

  return $output;
}

Dries's avatar
 
Dries committed
103 104 105 106 107
function story_content($node) {
  $node->teaser = check_output($node->teaser);
  $node->body = check_output($node->body);
  return $node;
}
Dries's avatar
 
Dries committed
108
?>