2001-12-06 17:33:05 +00:00
<?php
// $Id$
2004-08-21 06:42:38 +00:00
/**
* @file
* Enables users to submit stories, articles or similar content.
*/
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_help().
2004-03-10 09:32:46 +00:00
*/
2004-05-08 07:17:47 +00:00
function story_help($section) {
2003-08-21 18:21:15 +00:00
switch ($section) {
2004-06-18 15:04:37 +00:00
case 'admin/modules#description':
2004-05-08 07:17:47 +00:00
return t('Enables users to submit stories, articles or similar content.');
2004-06-18 15:04:37 +00:00
case 'admin/settings/story':
2004-05-08 07:17:47 +00:00
return t("Stories are like newspaper articles. They tend to follow a publishing flow of <strong>submit -> moderate -> post to the main page -> 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.");
2003-10-09 18:53:22 +00:00
case 'admin/help#story':
2004-05-08 07:17:47 +00:00
return t("
2004-01-23 18:42:43 +00:00
<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 -> moderate -> post to the main page -> comments</strong>. Administrators are able to shortcut this flow as desired.</p>
2004-06-21 08:26:20 +00:00
In <a href=\"%story-config\">administer » settings » 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>
2004-03-10 09:32:46 +00:00
<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>
2004-07-13 20:40:46 +00:00
<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>
2004-06-18 15:04:37 +00:00
", array('%story-config' => url('admin/settings/story')));
2004-01-17 09:07:00 +00:00
case 'node/add/story':
2004-05-08 07:17:47 +00:00
return variable_get('story_help', '');
2004-01-27 18:47:07 +00:00
case 'node/add#story':
2004-05-08 07:17:47 +00:00
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.");
2003-08-21 18:21:15 +00:00
}
2002-02-25 20:26:38 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_settings().
2004-03-10 09:32:46 +00:00
*/
2003-02-11 20:01:17 +00:00
function story_settings() {
2004-05-08 07:17:47 +00:00
$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.'));
2001-12-06 17:33:05 +00:00
return $output;
}
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_node_name().
2004-03-10 09:32:46 +00:00
*/
2004-01-27 18:47:07 +00:00
function story_node_name($node) {
2004-05-08 07:17:47 +00:00
return t('story');
2001-12-06 17:33:05 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_perm().
2004-03-10 09:32:46 +00:00
*/
2002-12-10 20:35:20 +00:00
function story_perm() {
2004-07-13 20:40:46 +00:00
return array('create stories', 'edit own stories');
2002-12-10 20:35:20 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_access().
2004-03-10 09:32:46 +00:00
*/
2001-12-06 17:33:05 +00:00
function story_access($op, $node) {
2004-03-10 09:32:46 +00:00
global $user;
2004-05-08 07:17:47 +00:00
if ($op == 'create') {
2004-03-10 09:32:46 +00:00
return user_access('create stories');
}
2004-07-31 09:30:09 +00:00
if ($op == 'update' || $op == 'delete') {
if (user_access('edit own stories') && ($user->uid == $node->uid)) {
return TRUE;
}
2001-12-06 17:33:05 +00:00
}
}
2004-03-10 09:32:46 +00:00
/**
2004-04-21 13:56:38 +00:00
* Implementation of hook_link().
2004-03-10 09:32:46 +00:00
*/
function story_link($type, $node = 0, $main) {
2003-04-21 14:55:03 +00:00
$links = array();
2004-03-10 09:32:46 +00:00
if ($type == 'node' && $node->type == 'story') {
2004-06-18 15:04:37 +00:00
// Don't display a redundant edit link if they are node administrators.
2004-04-21 13:56:38 +00:00
if (story_access('update', $node) && !user_access('administer nodes')) {
2004-06-18 15:04:37 +00:00
$links[] = l(t('edit this story'), "node/$node->nid/edit");
2004-03-10 09:32:46 +00:00
}
}
2003-04-21 14:55:03 +00:00
return $links;
2002-01-31 20:23:44 +00:00
}
2004-06-18 15:04:37 +00:00
/**
* Implementation of hook_menu().
*/
2004-09-16 07:17:56 +00:00
function story_menu($may_cache) {
2004-06-18 15:04:37 +00:00
$items = array();
2004-09-16 07:17:56 +00:00
if ($may_cache) {
$items[] = array('path' => 'node/add/story', 'title' => t('story'),
'access' => story_access('create', NULL));
}
2004-06-18 15:04:37 +00:00
return $items;
}
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_validate().
*
* Ensures the story is of adequate length.
2004-03-10 09:32:46 +00:00
*/
2003-09-20 16:03:05 +00:00
function story_validate(&$node) {
2004-05-08 07:17:47 +00:00
if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_story_size', 0)) {
2004-08-18 19:57:27 +00:00
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))));
2001-12-06 17:33:05 +00:00
}
2003-09-20 16:03:05 +00:00
}
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_form().
2004-03-10 09:32:46 +00:00
*/
2004-07-04 16:50:02 +00:00
function story_form(&$node) {
2004-05-08 07:17:47 +00:00
$output = '';
2001-12-06 17:33:05 +00:00
2004-05-08 07:17:47 +00:00
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('story', $node));
2002-05-19 23:05:05 +00:00
}
2003-09-20 16:03:05 +00:00
The Input formats - filter patch has landed. I still need to make update instructions for modules and update the hook docs.
Here's an overview of the changes:
1) Multiple Input formats: they are complete filter configurations (what filters to use, in what order and with which settings). Input formats are admin-definable, and usage of them is role-dependant. For example, you can set it up so that regular users can only use limited HTML, while admins can free HTML without any tag limitations.
The input format can be chosen per content item (nodes, comments, blocks, ...) when you add/edit them. If only a single format is available, there is no choice, and nothing changes with before.
The default install (and the upgrade) contains a basic set of formats which should satisfy the average user's needs.
2) Filters have toggles
Because now you might want to enable a filter only on some input formats, an explicit toggle is provided by the filter system. Modules do not need to worry about it and filters that still have their own on/off switch should get rid of it.
3) Multiple filters per module
This was necessary to accomodate the next change, and it's also a logical extension of the filter system.
4) Embedded PHP is now a filter
Thanks to the multiple input formats, I was able to move the 'embedded PHP' feature from block.module, page.module and book.module into a simple filter which executes PHP code. This filter is part of filter.module, and by default there is an input format 'PHP', restricted to the administrator only, which contains this filter.
This change means that block.module now passes custom block contents through the filter system.
As well as from reducing code duplication and avoiding two type selectors for page/book nodes, you can now combine PHP code with other filters.
5) User-supplied PHP code now requires <?php ?> tags.
This is required for teasers to work with PHP code. Because PHP evaluation is now just another step in the filter process, we can't do this. Also, because teasers are generated before filtering, this would result in errors when the teaser generation would cut off a piece of PHP code.
Also, regular PHP syntax explicitly includes the <?php ?> tags for PHP files, so it makes sense to use the same convention for embedded PHP in Drupal.
6) Filter caching was added.
Benchmarking shows that even for a simple setup (basic html filtering + legacy URL rewriting), filtercache can offer speedups. Unlike the old filtercache, this uses the normal cache table.
7) Filtertips were moved from help into a hook_filter_tips(). This was required to accomodate the fact that there are multiple filters per module, and that filter settings are format dependant. Shoehorning filter tips into _help was ugly and silly. The display of the filter tips is done through the input format selector, so filter_tips_short() no longer exists.
8) A more intelligent linebreak convertor was added, which doesn't stop working if you use block-level tags and which adds <p> tags.
2004-08-10 18:34:29 +00:00
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 15, '', NULL, TRUE);
2001-12-06 17:33:05 +00:00
return $output;
}
2004-03-10 09:32:46 +00:00
/**
2004-05-08 07:17:47 +00:00
* Implementation of hook_content().
2004-03-10 09:32:46 +00:00
*/
2004-01-11 20:16:26 +00:00
function story_content($node, $main = 0) {
return node_prepare($node, $main);
2003-09-20 15:11:41 +00:00
}
2001-12-06 17:33:05 +00:00
?>