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

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

Dries's avatar
Dries committed
9
/**
10
 * Implementation of hook_help().
Dries's avatar
Dries committed
11
 */
12
function story_help($section) {
13
  switch ($section) {
14 15 16 17 18 19 20 21 22 23 24
    case 'admin/help#story':
      $output = '<p>'. t('The story module is used to create a content post type called <em>stories.</em> Stories are articles in their simplest form: they have a title, a teaser and a body. Stories are typically used to post news articles or as a group blog. ') .'</p>';
      $output .= '<p>'. t('The story administration interface allows for complex configuration. It provides a submission form, workflow, default view permission, default edit permission, permissions for permission, and attachments.  Trackbacks can also be enabled.') .'</p>';
      $output .= t('<p>You can</p>
<ul>
<li>post a story at <a href="%node-add-story">create content &gt;&gt; story</a>.</li>
<li>configure story at <a href="%admin-node-configure-types"> administer &gt;&gt; content &gt;&gt; configure types &gt;&gt; story configure</a>.</li>
</ul>
', array('%node-add-story' => url('node/add/story'), '%admin-node-configure-types' => url('admin/node/configure/types')));
      $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%story">Story page</a>.', array('%story' => 'http://www.drupal.org/handbook/modules/story/')) .'</p>';
      return $output;
Dries's avatar
Dries committed
25
    case 'admin/modules#description':
26
      return t('Allows users to submit stories, articles or similar content.');
27
    case 'node/add#story':
28
      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.');
29
  }
30 31
}

Dries's avatar
Dries committed
32
/**
33
 * Implementation of hook_node_info().
Dries's avatar
Dries committed
34
 */
35
function story_node_info() {
36
  return array('story' => array('name' => t('story'), 'base' => 'story'));
Dries's avatar
Dries committed
37 38
}

Dries's avatar
Dries committed
39
/**
40
 * Implementation of hook_perm().
Dries's avatar
Dries committed
41
 */
Dries's avatar
Dries committed
42
function story_perm() {
43
  return array('create stories', 'edit own stories');
Dries's avatar
Dries committed
44 45
}

Dries's avatar
Dries committed
46
/**
47
 * Implementation of hook_access().
Dries's avatar
Dries committed
48
 */
Dries's avatar
Dries committed
49
function story_access($op, $node) {
Dries's avatar
Dries committed
50 51
  global $user;

52
  if ($op == 'create') {
Dries's avatar
Dries committed
53 54 55
    return user_access('create stories');
  }

56 57 58 59
  if ($op == 'update' || $op == 'delete') {
    if (user_access('edit own stories') && ($user->uid == $node->uid)) {
      return TRUE;
    }
Dries's avatar
Dries committed
60 61 62
  }
}

Dries's avatar
Dries committed
63 64 65
/**
 * Implementation of hook_menu().
 */
66
function story_menu($may_cache) {
Dries's avatar
Dries committed
67
  $items = array();
68 69 70

  if ($may_cache) {
    $items[] = array('path' => 'node/add/story', 'title' => t('story'),
71
      'access' => user_access('create stories'));
72 73
  }

Dries's avatar
Dries committed
74 75 76
  return $items;
}

77 78 79
/**
 * Implementation of hook_validate().
 */
80
function story_validate($node) {
81 82 83
  node_validate_title($node);
}

Dries's avatar
Dries committed
84
/**
85
 * Implementation of hook_form().
Dries's avatar
Dries committed
86
 */
87
function story_form(&$node) {
88
  $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5);
89
  $form['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
90
  $form['format'] = filter_form($node->format);
91
  return $form;
Dries's avatar
Dries committed
92 93
}