story.module 4.32 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':
17
      return t("<p>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.</p>");
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':
29
      return t('A story is similar to an article and usually gets promoted to the front page after approval or moderation.');
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 75 76
/**
 * Implementation of hook_menu().
 */
Dries's avatar
 
Dries committed
77
function story_menu($may_cache) {
Dries's avatar
 
Dries committed
78
  $items = array();
Dries's avatar
 
Dries committed
79 80 81

  if ($may_cache) {
    $items[] = array('path' => 'node/add/story', 'title' => t('story'),
82
      'access' => user_access('create stories'));
Dries's avatar
 
Dries committed
83 84
  }

Dries's avatar
 
Dries committed
85 86 87
  return $items;
}

Dries's avatar
Dries committed
88
/**
Dries's avatar
 
Dries committed
89 90 91
 * Implementation of hook_validate().
 *
 * Ensures the story is of adequate length.
Dries's avatar
Dries committed
92
 */
Dries's avatar
 
Dries committed
93
function story_validate(&$node) {
Dries's avatar
 
Dries committed
94
  if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_story_size', 0)) {
Dries's avatar
 
Dries committed
95
    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
96
  }
Dries's avatar
 
Dries committed
97 98
}

Dries's avatar
Dries committed
99
/**
Dries's avatar
 
Dries committed
100
 * Implementation of hook_form().
Dries's avatar
Dries committed
101
 */
Dries's avatar
 
Dries committed
102
function story_form(&$node) {
Dries's avatar
 
Dries committed
103
  $output = '';
Dries's avatar
 
Dries committed
104

Dries's avatar
 
Dries committed
105 106
  if (function_exists('taxonomy_node_form')) {
    $output .= implode('', taxonomy_node_form('story', $node));
107
  }
Dries's avatar
 
Dries committed
108

109
  $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
110
  $output .= filter_form('format', $node->format);
Dries's avatar
 
Dries committed
111 112 113 114 115

  return $output;
}

?>