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

Dries's avatar
Dries committed
4
/**
Dries's avatar
 
Dries committed
5
 * Implementation of hook_help().
Dries's avatar
Dries committed
6
 */
Dries's avatar
 
Dries committed
7
function story_help($section) {
8
  switch ($section) {
Dries's avatar
 
Dries committed
9
    case 'admin/modules#description':
Dries's avatar
 
Dries committed
10
      return t('Enables users to submit stories, articles or similar content.');
Dries's avatar
 
Dries committed
11
    case 'admin/settings/story':
Dries's avatar
 
Dries committed
12
      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
13
    case 'admin/help#story':
Dries's avatar
 
Dries committed
14
      return t("
Dries's avatar
 
Dries committed
15
      <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>
16
      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
17 18 19
      <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>
Dries's avatar
 
Dries committed
20
      ", array('%story-config' => url('admin/settings/story')));
Dries's avatar
 
Dries committed
21
    case 'node/add/story':
Dries's avatar
 
Dries committed
22
      return variable_get('story_help', '');
Dries's avatar
 
Dries committed
23
    case 'node/add#story':
Dries's avatar
 
Dries committed
24
      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.");
25
  }
Dries's avatar
 
Dries committed
26 27
}

Dries's avatar
Dries committed
28
/**
Dries's avatar
 
Dries committed
29
 * Implementation of hook_settings().
Dries's avatar
Dries committed
30
 */
31
function story_settings() {
Dries's avatar
 
Dries committed
32 33
 $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
34 35 36 37

 return $output;
}

Dries's avatar
Dries committed
38
/**
Dries's avatar
 
Dries committed
39
 * Implementation of hook_node_name().
Dries's avatar
Dries committed
40
 */
Dries's avatar
 
Dries committed
41
function story_node_name($node) {
Dries's avatar
 
Dries committed
42
  return t('story');
Dries's avatar
 
Dries committed
43 44
}

Dries's avatar
Dries committed
45
/**
Dries's avatar
 
Dries committed
46
 * Implementation of hook_perm().
Dries's avatar
Dries committed
47
 */
Dries's avatar
 
Dries committed
48
function story_perm() {
Dries's avatar
Dries committed
49
  return array('create stories', 'maintain personal stories');
Dries's avatar
 
Dries committed
50 51
}

Dries's avatar
Dries committed
52
/**
Dries's avatar
 
Dries committed
53
 * Implementation of hook_access().
Dries's avatar
Dries committed
54
 */
Dries's avatar
 
Dries committed
55
function story_access($op, $node) {
Dries's avatar
Dries committed
56 57
  global $user;

Dries's avatar
 
Dries committed
58
  if ($op == 'view') {
Dries's avatar
 
Dries committed
59 60 61
    return $node->status;
  }

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

Dries's avatar
 
Dries committed
66
  if ($op == 'update') {
Dries's avatar
Dries committed
67 68 69
    return user_access('maintain personal stories') && ($user->uid == $node->uid);
  }

Dries's avatar
 
Dries committed
70
  if ($op == 'delete') {
Dries's avatar
Dries committed
71
    return user_access('maintain personal stories') && ($user->uid == $node->uid);
Dries's avatar
 
Dries committed
72 73 74
  }
}

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

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

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

Dries's avatar
 
Dries committed
91 92 93 94 95 96 97 98 99 100
/**
 * 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;
}

Dries's avatar
Dries committed
101
/**
Dries's avatar
 
Dries committed
102 103 104
 * Implementation of hook_validate().
 *
 * Ensures the story is of adequate length.
Dries's avatar
Dries committed
105
 */
Dries's avatar
 
Dries committed
106
function story_validate(&$node) {
Dries's avatar
 
Dries committed
107
  if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_story_size', 0)) {
Dries's avatar
 
Dries committed
108
    form_set_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
109
  }
Dries's avatar
 
Dries committed
110 111
}

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

Dries's avatar
 
Dries committed
118 119
  if (function_exists('taxonomy_node_form')) {
    $output .= implode('', taxonomy_node_form('story', $node));
120
  }
Dries's avatar
 
Dries committed
121

Dries's avatar
 
Dries committed
122
  $output .= form_textarea(t('Body'), 'body', $node->body, 60, 15, filter_tips_short());
Dries's avatar
 
Dries committed
123 124 125 126

  return $output;
}

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