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

Dries's avatar
 
Dries committed
4 5 6 7 8
/**
 * @file
 * Enables users to submit stories, articles or similar content.
 */

Dries's avatar
Dries committed
9
/**
Dries's avatar
 
Dries committed
10
 * Implementation of hook_help().
Dries's avatar
Dries committed
11
 */
Dries's avatar
 
Dries committed
12
function story_help($section) {
13
  switch ($section) {
Dries's avatar
 
Dries committed
14
    case 'admin/modules#description':
Dries's avatar
 
Dries committed
15
      return t('Enables users to submit stories, articles or similar content.');
Dries's avatar
 
Dries committed
16
    case 'admin/settings/story':
Dries's avatar
 
Dries committed
17
      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.");
Dries's avatar
 
Dries committed
18
    case 'admin/help#story':
Dries's avatar
 
Dries committed
19
      return t("
Dries's avatar
 
Dries committed
20
      <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>
21
      In <a href=\"%story-config\">administer &raquo; settings &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>
Dries's avatar
Dries committed
22 23
      <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>
Dries's avatar
 
Dries committed
24
      <p><strong>edit own 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>
Dries's avatar
 
Dries committed
25
      ", array('%story-config' => url('admin/settings/story')));
Dries's avatar
 
Dries committed
26
    case 'node/add/story':
Dries's avatar
 
Dries committed
27
      return variable_get('story_help', '');
Dries's avatar
 
Dries committed
28
    case 'node/add#story':
Dries's avatar
 
Dries committed
29
      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.");
30
  }
Dries's avatar
 
Dries committed
31 32
}

Dries's avatar
Dries committed
33
/**
Dries's avatar
 
Dries committed
34
 * Implementation of hook_settings().
Dries's avatar
Dries committed
35
 */
36
function story_settings() {
Dries's avatar
 
Dries committed
37 38
 $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.'));
Dries's avatar
 
Dries committed
39 40 41 42

 return $output;
}

Dries's avatar
Dries committed
43
/**
Dries's avatar
 
Dries committed
44
 * Implementation of hook_node_name().
Dries's avatar
Dries committed
45
 */
Dries's avatar
 
Dries committed
46
function story_node_name($node) {
Dries's avatar
 
Dries committed
47
  return t('story');
Dries's avatar
 
Dries committed
48 49
}

Dries's avatar
Dries committed
50
/**
Dries's avatar
 
Dries committed
51
 * Implementation of hook_perm().
Dries's avatar
Dries committed
52
 */
Dries's avatar
 
Dries committed
53
function story_perm() {
Dries's avatar
 
Dries committed
54
  return array('create stories', 'edit own stories');
Dries's avatar
 
Dries committed
55 56
}

Dries's avatar
Dries committed
57
/**
Dries's avatar
 
Dries committed
58
 * Implementation of hook_access().
Dries's avatar
Dries committed
59
 */
Dries's avatar
 
Dries committed
60
function story_access($op, $node) {
Dries's avatar
Dries committed
61 62
  global $user;

Dries's avatar
 
Dries committed
63
  if ($op == 'create') {
Dries's avatar
Dries committed
64 65 66
    return user_access('create stories');
  }

Dries's avatar
 
Dries committed
67 68 69 70
  if ($op == 'update' || $op == 'delete') {
    if (user_access('edit own stories') && ($user->uid == $node->uid)) {
      return TRUE;
    }
Dries's avatar
 
Dries committed
71 72 73
  }
}

Dries's avatar
Dries committed
74
/**
Dries's avatar
 
Dries committed
75
 * Implementation of hook_link().
Dries's avatar
Dries committed
76 77
 */
function story_link($type, $node = 0, $main) {
Dries's avatar
 
Dries committed
78 79
  $links = array();

Dries's avatar
Dries committed
80
  if ($type == 'node' && $node->type == 'story') {
Dries's avatar
 
Dries committed
81
    // Don't display a redundant edit link if they are node administrators.
Dries's avatar
 
Dries committed
82
    if (story_access('update', $node) && !user_access('administer nodes')) {
Dries's avatar
 
Dries committed
83
      $links[] = l(t('edit this story'), "node/$node->nid/edit");
Dries's avatar
Dries committed
84 85 86
    }
  }

Dries's avatar
 
Dries committed
87
  return $links;
Dries's avatar
 
Dries committed
88 89
}

Dries's avatar
 
Dries committed
90 91 92
/**
 * Implementation of hook_menu().
 */
Dries's avatar
 
Dries committed
93
function story_menu($may_cache) {
Dries's avatar
 
Dries committed
94
  $items = array();
Dries's avatar
 
Dries committed
95 96 97 98 99 100

  if ($may_cache) {
    $items[] = array('path' => 'node/add/story', 'title' => t('story'),
      'access' => story_access('create', NULL));
  }

Dries's avatar
 
Dries committed
101 102 103
  return $items;
}

Dries's avatar
Dries committed
104
/**
Dries's avatar
 
Dries committed
105 106 107
 * Implementation of hook_validate().
 *
 * Ensures the story is of adequate length.
Dries's avatar
Dries committed
108
 */
Dries's avatar
 
Dries committed
109
function story_validate(&$node) {
Dries's avatar
 
Dries committed
110
  if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_story_size', 0)) {
Dries's avatar
 
Dries committed
111
    form_set_error('body', t('The body of your story is too short. You need at least %words words to submit your story.', array('%words' => variable_get('minimum_story_size', 0))));
Dries's avatar
 
Dries committed
112
  }
Dries's avatar
 
Dries committed
113 114
}

Dries's avatar
Dries committed
115
/**
Dries's avatar
 
Dries committed
116
 * Implementation of hook_form().
Dries's avatar
Dries committed
117
 */
Dries's avatar
 
Dries committed
118
function story_form(&$node) {
Dries's avatar
 
Dries committed
119
  $output = '';
Dries's avatar
 
Dries committed
120

Dries's avatar
 
Dries committed
121 122
  if (function_exists('taxonomy_node_form')) {
    $output .= implode('', taxonomy_node_form('story', $node));
123
  }
Dries's avatar
 
Dries committed
124

125
  $output .= form_textarea(t('Body'), 'body', $node->body, 60, 15, '', NULL, TRUE);
Dries's avatar
 
Dries committed
126 127 128 129

  return $output;
}

Dries's avatar
Dries committed
130
/**
Dries's avatar
 
Dries committed
131
 * Implementation of hook_content().
Dries's avatar
Dries committed
132
 */
Dries's avatar
 
Dries committed
133 134
function story_content($node, $main = 0) {
  return node_prepare($node, $main);
Dries's avatar
 
Dries committed
135
}
Dries's avatar
 
Dries committed
136
?>