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

Dries's avatar
Dries committed
4
5
6
/**
 * Provide online user help
 */
Dries's avatar
   
Dries committed
7
function story_help($section = "admin/help#story") {
Dries's avatar
   
Dries committed
8
9
  $output = "";

10
  switch ($section) {
Dries's avatar
   
Dries committed
11
    case 'admin/system/modules#description':
Dries's avatar
   
Dries committed
12
      $output = t("Enables users to submit stories, articles or similar content.");
13
      break;
Dries's avatar
   
Dries committed
14
    case 'admin/system/modules/story':
15
      $output = t("Stories are like newspaper articles. They tend to follow a publishing flow of <strong>submit -&gt; moderate -&gt; post to the main page -&gt; comments</strong>. 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.");
16
      break;
Dries's avatar
   
Dries committed
17
    case 'admin/help#story':
Dries's avatar
   
Dries committed
18
19
      $output = t("
      <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 <strong>submit -&gt; moderate -&gt; post to the main page -&gt; comments</strong>.  Administrators are able to shortcut this flow as desired.</p>
Dries's avatar
Dries committed
20
21
22
23
24
      In <a href=\"%story-config\">administer &raquo; configuration &raquo; modules &raquo; story</a> 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.</p>
      <h3>User access permissions for stories</h3>
      <p><strong>create stories:</strong> Allows a role to create stories. They cannot edit or delete stories, even if they are the authors. You must enable this permission to in order for a role to create a story.</p>
      <p><strong>maintain personal stories:</strong> Allows a role to add/edit stories if they own the story. Use this permission if you want users to be able to edit and maintain their own stories.</p>
      ", array("%story-config" => url("admin/system/modules/story")));
25
      break;
Dries's avatar
   
Dries committed
26
27
28
    case 'node/add/story':
      $output = variable_get('story_help', '');
      break;
Dries's avatar
   
Dries committed
29
    case 'node/add#story':
Dries's avatar
Dries committed
30
      $output = t("A story is similar to a newspaper article. If stories are moderated, the post will be submitted to the attention of other users and be 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
31
      break;
32
  }
33

Dries's avatar
   
Dries committed
34
  return $output;
Dries's avatar
   
Dries committed
35
36
}

Dries's avatar
Dries committed
37
38
39
/**
 * Declare administrative settings for a module.
 */
40
function story_settings() {
Dries's avatar
   
Dries committed
41
42
 $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
43
44
45
46

 return $output;
}

Dries's avatar
Dries committed
47
48
49
/**
 * Define the human-readable name of a node type.
 */
Dries's avatar
   
Dries committed
50
51
function story_node_name($node) {
  return t("story");
Dries's avatar
   
Dries committed
52
53
}

Dries's avatar
Dries committed
54
55
56
/**
 * Define user permissions.
 */
Dries's avatar
   
Dries committed
57
function story_perm() {
Dries's avatar
Dries committed
58
  return array('create stories', 'maintain personal stories');
Dries's avatar
   
Dries committed
59
60
}

Dries's avatar
Dries committed
61
62
63
/**
 * Define access restrictions
 */
Dries's avatar
   
Dries committed
64
function story_access($op, $node) {
Dries's avatar
Dries committed
65
66
  global $user;

Dries's avatar
   
Dries committed
67
68
69
70
71
  if ($op == "view") {
    return $node->status;
  }

  if ($op == "create") {
Dries's avatar
Dries committed
72
73
74
75
76
77
78
79
80
    return user_access('create stories');
  }

  if ($op == "update") {
    return user_access('maintain personal stories') && ($user->uid == $node->uid);
  }

  if ($op == "delete") {
    return user_access('maintain personal stories') && ($user->uid == $node->uid);
Dries's avatar
   
Dries committed
81
82
83
  }
}

Dries's avatar
Dries committed
84
85
86
87
/**
 * Define internal Drupal links.
 */
function story_link($type, $node = 0, $main) {
Dries's avatar
   
Dries committed
88
89
  $links = array();

Dries's avatar
   
Dries committed
90
  if ($type == "system") {
Dries's avatar
Dries committed
91
    if (story_access('create', $node)) {
Dries's avatar
   
Dries committed
92
      menu("node/add/story", t("story"), "node_page", 0);
Dries's avatar
   
Dries committed
93
    }
Dries's avatar
   
Dries committed
94
95
  }

Dries's avatar
Dries committed
96
97
98
99
100
101
102
  if ($type == 'node' && $node->type == 'story') {
    /* Don't display a redundant edit link if they are node administrators */
    if (story_access("update", $node) && !user_access('administer nodes')) {
      $links[] = l(t('edit this story'), "node/edit/$node->nid");
    }
  }

Dries's avatar
   
Dries committed
103
  return $links;
Dries's avatar
   
Dries committed
104
105
}

Dries's avatar
Dries committed
106
107
108
/**
 * Verify a node editing form.
 */
Dries's avatar
   
Dries committed
109
function story_validate(&$node) {
Dries's avatar
   
Dries committed
110

Dries's avatar
   
Dries committed
111
112
113
  /*
  ** Validate the size of the story:
  */
Dries's avatar
   
Dries committed
114

Dries's avatar
   
Dries committed
115
  if (isset($node->body) && count(explode(" ", $node->body)) < variable_get("minimum_story_size", 0)) {
Dries's avatar
Dries committed
116
    $error["body"] = t("The body of your story is too short. You need at least %word_count words to submit your story.", array('%word_count' => variable_get("minimum_story_size", 0)));
Dries's avatar
   
Dries committed
117
118
  }

Dries's avatar
   
Dries committed
119
120
121
  return $error;
}

Dries's avatar
Dries committed
122
123
124
/**
 * Display a node editing form
 */
Dries's avatar
   
Dries committed
125
function story_form(&$node, &$error) {
Dries's avatar
   
Dries committed
126

127
128
129
  if (function_exists("taxonomy_node_form")) {
    $output .= implode("", taxonomy_node_form("story", $node));
  }
Dries's avatar
   
Dries committed
130

Dries's avatar
Dries committed
131
  $output .= form_textarea(t("Body"), "body", $node->body, 60, 15, ($error["body"] ? theme('error', $error["body"]) : ''). filter_tips_short());
Dries's avatar
   
Dries committed
132
133
134
135

  return $output;
}

Dries's avatar
Dries committed
136
137
138
/**
 * Prepare a node's body content for viewing
 */
Dries's avatar
   
Dries committed
139
140
function story_content($node, $main = 0) {
  return node_prepare($node, $main);
Dries's avatar
   
Dries committed
141
}
Dries's avatar
   
Dries committed
142
?>