summaryrefslogtreecommitdiff
path: root/modules/story/story.module
blob: 1042205519725ef5c8fb7f5a19d7e06dffcc7069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
// $Id$

/**
 * Implementation of hook_help().
 */
function story_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Enables users to submit stories, articles or similar content.');
    case 'admin/settings/story':
      return 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.");
    case 'admin/help#story':
      return 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>
      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/settings/story')));
    case 'node/add/story':
      return variable_get('story_help', '');
    case 'node/add#story':
      return 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.");
  }
}

/**
 * Implementation of hook_settings().
 */
function story_settings() {
 $output .= form_textarea(t('Explanation or submission guidelines'), 'story_help', variable_get('story_help', ''), 70, 5, t('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), drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), 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.'));

 return $output;
}

/**
 * Implementation of hook_node_name().
 */
function story_node_name($node) {
  return t('story');
}

/**
 * Implementation of hook_perm().
 */
function story_perm() {
  return array('create stories', 'maintain personal stories');
}

/**
 * Implementation of hook_access().
 */
function story_access($op, $node) {
  global $user;

  if ($op == 'view') {
    return $node->status;
  }

  if ($op == 'create') {
    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);
  }
}

/**
 * Implementation of hook_link().
 */
function story_link($type, $node = 0, $main) {
  $links = array();

  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/$node->nid/edit");
    }
  }

  return $links;
}

/**
 * Implementation of hook_menu().
 */
function story_menu() {
  $items = array();
  $items[] = array('path' => 'node/add/story', 'title' => t('story'),
    'access' => story_access('create', NULL));
  return $items;
}

/**
 * Implementation of hook_validate().
 *
 * Ensures the story is of adequate length.
 */
function story_validate(&$node) {
  if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_story_size', 0)) {
    $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)));
  }

  return $error;
}

/**
 * Implementation of hook_form().
 */
function story_form(&$node, &$error) {
  $output = '';

  if (function_exists('taxonomy_node_form')) {
    $output .= implode('', taxonomy_node_form('story', $node));
  }

  $output .= form_textarea(t('Body'), 'body', $node->body, 60, 15, ($error['body'] ? theme('error', $error['body']) : ''). filter_tips_short());

  return $output;
}

/**
 * Implementation of hook_content().
 */
function story_content($node, $main = 0) {
  return node_prepare($node, $main);
}
?>