story.module 3.64 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("Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.");
Dries's avatar
 
Dries committed
18
    case 'admin/help#story':
19
      return t("Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles. By default, no menu item, or navigation element is created for a story. An extra feature of a story is, that an administrator can specify a submission guideline and enforce a minimum word count for user submitted stories");
Dries's avatar
 
Dries committed
20
    case 'node/add/story':
Dries's avatar
 
Dries committed
21
      return variable_get('story_help', '');
Dries's avatar
 
Dries committed
22
    case 'node/add#story':
23
      return t('Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.');
24
  }
Dries's avatar
 
Dries committed
25 26
}

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

 return $output;
}

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

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

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

Dries's avatar
 
Dries committed
57
  if ($op == 'create') {
Dries's avatar
Dries committed
58 59 60
    return user_access('create stories');
  }

Dries's avatar
 
Dries committed
61 62 63 64
  if ($op == 'update' || $op == 'delete') {
    if (user_access('edit own stories') && ($user->uid == $node->uid)) {
      return TRUE;
    }
Dries's avatar
 
Dries committed
65 66 67
  }
}

Dries's avatar
 
Dries committed
68 69 70
/**
 * Implementation of hook_menu().
 */
Dries's avatar
 
Dries committed
71
function story_menu($may_cache) {
Dries's avatar
 
Dries committed
72
  $items = array();
Dries's avatar
 
Dries committed
73 74 75

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

Dries's avatar
 
Dries committed
79 80 81
  return $items;
}

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

Dries's avatar
Dries committed
93
/**
Dries's avatar
 
Dries committed
94
 * Implementation of hook_form().
Dries's avatar
Dries committed
95
 */
Dries's avatar
 
Dries committed
96
function story_form(&$node) {
Dries's avatar
 
Dries committed
97
  $output = '';
Dries's avatar
 
Dries committed
98

Dries's avatar
 
Dries committed
99 100
  if (function_exists('taxonomy_node_form')) {
    $output .= implode('', taxonomy_node_form('story', $node));
101
  }
Dries's avatar
 
Dries committed
102

103
  $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
104
  $output .= filter_form('format', $node->format);
Dries's avatar
 
Dries committed
105 106 107 108 109

  return $output;
}

?>