First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
26
modules/forum/forum-icon.tpl.php
Normal file
26
modules/forum/forum-icon.tpl.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Displays an appropriate icon for a forum post.
|
||||
*
|
||||
* Available variables:
|
||||
* - $new_posts: Indicates whether or not the topic contains new posts.
|
||||
* - $icon_class: The icon to display. May be one of 'hot', 'hot-new', 'new',
|
||||
* 'default', 'closed', or 'sticky'.
|
||||
* - $first_new: Indicates whether this is the first topic with new posts.
|
||||
*
|
||||
* @see template_preprocess_forum_icon()
|
||||
* @see theme_forum_icon()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
?>
|
||||
<div class="topic-status-<?php print $icon_class ?>" title="<?php print $icon_title ?>">
|
||||
<?php if ($first_new): ?>
|
||||
<a id="new"></a>
|
||||
<?php endif; ?>
|
||||
|
||||
<span class="element-invisible"><?php print $icon_title ?></span>
|
||||
|
||||
</div>
|
77
modules/forum/forum-list.tpl.php
Normal file
77
modules/forum/forum-list.tpl.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Displays a list of forums and containers.
|
||||
*
|
||||
* Available variables:
|
||||
* - $forums: An array of forums and containers to display. It is keyed to the
|
||||
* numeric IDs of all child forums and containers. Each $forum in $forums
|
||||
* contains:
|
||||
* - $forum->is_container: TRUE if the forum can contain other forums. FALSE
|
||||
* if the forum can contain only topics.
|
||||
* - $forum->depth: How deep the forum is in the current hierarchy.
|
||||
* - $forum->zebra: 'even' or 'odd' string used for row class.
|
||||
* - $forum->icon_class: 'default' or 'new' string used for forum icon class.
|
||||
* - $forum->icon_title: Text alternative for the forum icon.
|
||||
* - $forum->name: The name of the forum.
|
||||
* - $forum->link: The URL to link to this forum.
|
||||
* - $forum->description: The description of this forum.
|
||||
* - $forum->new_topics: TRUE if the forum contains unread posts.
|
||||
* - $forum->new_url: A URL to the forum's unread posts.
|
||||
* - $forum->new_text: Text for the above URL, which tells how many new posts.
|
||||
* - $forum->old_topics: A count of posts that have already been read.
|
||||
* - $forum->num_posts: The total number of posts in the forum.
|
||||
* - $forum->last_reply: Text representing the last time a forum was posted or
|
||||
* commented in.
|
||||
* - $forum_id: Forum ID for the current forum. Parent to all items within the
|
||||
* $forums array.
|
||||
*
|
||||
* @see template_preprocess_forum_list()
|
||||
* @see theme_forum_list()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
?>
|
||||
<table id="forum-<?php print $forum_id; ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php print t('Forum'); ?></th>
|
||||
<th><?php print t('Topics');?></th>
|
||||
<th><?php print t('Posts'); ?></th>
|
||||
<th><?php print t('Last post'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($forums as $child_id => $forum): ?>
|
||||
<tr id="forum-list-<?php print $child_id; ?>" class="<?php print $forum->zebra; ?>">
|
||||
<td <?php print $forum->is_container ? 'colspan="4" class="container"' : 'class="forum"'; ?>>
|
||||
<?php /* Enclose the contents of this cell with X divs, where X is the
|
||||
* depth this forum resides at. This will allow us to use CSS
|
||||
* left-margin for indenting.
|
||||
*/ ?>
|
||||
<?php print str_repeat('<div class="indent">', $forum->depth); ?>
|
||||
<div class="icon forum-status-<?php print $forum->icon_class; ?>" title="<?php print $forum->icon_title; ?>">
|
||||
<span class="element-invisible"><?php print $forum->icon_title; ?></span>
|
||||
</div>
|
||||
<div class="name"><a href="<?php print $forum->link; ?>"><?php print $forum->name; ?></a></div>
|
||||
<?php if ($forum->description): ?>
|
||||
<div class="description"><?php print $forum->description; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php print str_repeat('</div>', $forum->depth); ?>
|
||||
</td>
|
||||
<?php if (!$forum->is_container): ?>
|
||||
<td class="topics">
|
||||
<?php print $forum->num_topics ?>
|
||||
<?php if ($forum->new_topics): ?>
|
||||
<br />
|
||||
<a href="<?php print $forum->new_url; ?>"><?php print $forum->new_text; ?></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="posts"><?php print $forum->num_posts ?></td>
|
||||
<td class="last-reply"><?php print $forum->last_reply ?></td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
24
modules/forum/forum-rtl.css
Normal file
24
modules/forum/forum-rtl.css
Normal file
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* @file
|
||||
* Right-to-left styling for the Forum module.
|
||||
*/
|
||||
|
||||
#forum td.forum .icon {
|
||||
float: right;
|
||||
margin: 0 0 0 9px;
|
||||
}
|
||||
#forum div.indent {
|
||||
margin-left: 0;
|
||||
margin-right: 20px;
|
||||
}
|
||||
.forum-topic-navigation {
|
||||
padding: 1em 3em 0 0;
|
||||
}
|
||||
.forum-topic-navigation .topic-previous {
|
||||
text-align: left;
|
||||
float: right;
|
||||
}
|
||||
.forum-topic-navigation .topic-next {
|
||||
text-align: right;
|
||||
float: left;
|
||||
}
|
30
modules/forum/forum-submitted.tpl.php
Normal file
30
modules/forum/forum-submitted.tpl.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Formats a forum post submission string.
|
||||
*
|
||||
* The submission string indicates when and by whom a topic was submitted.
|
||||
*
|
||||
* Available variables:
|
||||
* - $author: The author of the post.
|
||||
* - $time: How long ago the post was created.
|
||||
* - $topic: An object with the raw data of the post. Potentially unsafe. Be
|
||||
* sure to clean this data before printing.
|
||||
*
|
||||
* @see template_preprocess_forum_submitted()
|
||||
* @see theme_forum_submitted()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
?>
|
||||
<?php if ($time): ?>
|
||||
<span class="submitted">
|
||||
<?php print t('By !author @time ago', array(
|
||||
'@time' => $time,
|
||||
'!author' => $author,
|
||||
)); ?>
|
||||
</span>
|
||||
<?php else: ?>
|
||||
<?php print t('n/a'); ?>
|
||||
<?php endif; ?>
|
72
modules/forum/forum-topic-list.tpl.php
Normal file
72
modules/forum/forum-topic-list.tpl.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Displays a list of forum topics.
|
||||
*
|
||||
* Available variables:
|
||||
* - $header: The table header. This is pre-generated with click-sorting
|
||||
* information. If you need to change this, see
|
||||
* template_preprocess_forum_topic_list().
|
||||
* - $pager: The pager to display beneath the table.
|
||||
* - $topics: An array of topics to be displayed. Each $topic in $topics
|
||||
* contains:
|
||||
* - $topic->icon: The icon to display.
|
||||
* - $topic->moved: A flag to indicate whether the topic has been moved to
|
||||
* another forum.
|
||||
* - $topic->title: The title of the topic. Safe to output.
|
||||
* - $topic->message: If the topic has been moved, this contains an
|
||||
* explanation and a link.
|
||||
* - $topic->zebra: 'even' or 'odd' string used for row class.
|
||||
* - $topic->comment_count: The number of replies on this topic.
|
||||
* - $topic->new_replies: A flag to indicate whether there are unread
|
||||
* comments.
|
||||
* - $topic->new_url: If there are unread replies, this is a link to them.
|
||||
* - $topic->new_text: Text containing the translated, properly pluralized
|
||||
* count.
|
||||
* - $topic->created: A string representing when the topic was posted. Safe
|
||||
* to output.
|
||||
* - $topic->last_reply: An outputtable string representing when the topic was
|
||||
* last replied to.
|
||||
* - $topic->timestamp: The raw timestamp this topic was posted.
|
||||
* - $topic_id: Numeric ID for the current forum topic.
|
||||
*
|
||||
* @see template_preprocess_forum_topic_list()
|
||||
* @see theme_forum_topic_list()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
?>
|
||||
<table id="forum-topic-<?php print $topic_id; ?>">
|
||||
<thead>
|
||||
<tr><?php print $header; ?></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($topics as $topic): ?>
|
||||
<tr class="<?php print $topic->zebra;?>">
|
||||
<td class="icon"><?php print $topic->icon; ?></td>
|
||||
<td class="title">
|
||||
<div>
|
||||
<?php print $topic->title; ?>
|
||||
</div>
|
||||
<div>
|
||||
<?php print $topic->created; ?>
|
||||
</div>
|
||||
</td>
|
||||
<?php if ($topic->moved): ?>
|
||||
<td colspan="3"><?php print $topic->message; ?></td>
|
||||
<?php else: ?>
|
||||
<td class="replies">
|
||||
<?php print $topic->comment_count; ?>
|
||||
<?php if ($topic->new_replies): ?>
|
||||
<br />
|
||||
<a href="<?php print $topic->new_url; ?>"><?php print $topic->new_text; ?></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="last-reply"><?php print $topic->last_reply; ?></td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php print $pager; ?>
|
352
modules/forum/forum.admin.inc
Normal file
352
modules/forum/forum.admin.inc
Normal file
|
@ -0,0 +1,352 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Administrative page callbacks for the Forum module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page callback: Returns a form for creating a new forum or container.
|
||||
*
|
||||
* @param $type
|
||||
* What is being added. Possible values are 'forum' and 'container'.
|
||||
* @param $edit
|
||||
* (optional) Associative array containing a forum term to be edited.
|
||||
* Defaults to an empty array.
|
||||
*
|
||||
* @return
|
||||
* A form for creating a new forum or container.
|
||||
*
|
||||
* @see forum_menu()
|
||||
*/
|
||||
function forum_form_main($type, $edit = array()) {
|
||||
$edit = (array) $edit;
|
||||
if ((isset($_POST['op']) && $_POST['op'] == t('Delete')) || !empty($_POST['confirm'])) {
|
||||
return drupal_get_form('forum_confirm_delete', $edit['tid']);
|
||||
}
|
||||
switch ($type) {
|
||||
case 'forum':
|
||||
return drupal_get_form('forum_form_forum', $edit);
|
||||
break;
|
||||
case 'container':
|
||||
return drupal_get_form('forum_form_container', $edit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form constructor for adding and editing a forum.
|
||||
*
|
||||
* @param $edit
|
||||
* (optional) Associative array containing a forum term to be added or edited.
|
||||
* Defaults to an empty array.
|
||||
*
|
||||
* @see forum_form_submit()
|
||||
* @ingroup forms
|
||||
*/
|
||||
function forum_form_forum($form, &$form_state, $edit = array()) {
|
||||
$edit += array(
|
||||
'name' => '',
|
||||
'description' => '',
|
||||
'tid' => NULL,
|
||||
'weight' => 0,
|
||||
);
|
||||
$form['name'] = array('#type' => 'textfield',
|
||||
'#title' => t('Forum name'),
|
||||
'#default_value' => $edit['name'],
|
||||
'#maxlength' => 255,
|
||||
'#description' => t('Short but meaningful name for this collection of threaded discussions.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['description'] = array('#type' => 'textarea',
|
||||
'#title' => t('Description'),
|
||||
'#default_value' => $edit['description'],
|
||||
'#description' => t('Description and guidelines for discussions within this forum.'),
|
||||
);
|
||||
$form['parent']['#tree'] = TRUE;
|
||||
$form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'forum');
|
||||
$form['weight'] = array('#type' => 'weight',
|
||||
'#title' => t('Weight'),
|
||||
'#default_value' => $edit['weight'],
|
||||
'#description' => t('Forums are displayed in ascending order by weight (forums with equal weights are displayed alphabetically).'),
|
||||
);
|
||||
|
||||
$form['vid'] = array('#type' => 'hidden', '#value' => variable_get('forum_nav_vocabulary', ''));
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
|
||||
if ($edit['tid']) {
|
||||
$form['actions']['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
|
||||
$form['tid'] = array('#type' => 'hidden', '#value' => $edit['tid']);
|
||||
}
|
||||
$form['#submit'][] = 'forum_form_submit';
|
||||
$form['#theme'] = 'forum_form';
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission handler for forum_form_forum() and forum_form_container().
|
||||
*/
|
||||
function forum_form_submit($form, &$form_state) {
|
||||
if ($form['form_id']['#value'] == 'forum_form_container') {
|
||||
$container = TRUE;
|
||||
$type = t('forum container');
|
||||
}
|
||||
else {
|
||||
$container = FALSE;
|
||||
$type = t('forum');
|
||||
}
|
||||
|
||||
$term = (object) $form_state['values'];
|
||||
$status = taxonomy_term_save($term);
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
if ($container) {
|
||||
$containers = variable_get('forum_containers', array());
|
||||
$containers[] = $term->tid;
|
||||
variable_set('forum_containers', $containers);
|
||||
}
|
||||
$form_state['values']['tid'] = $term->tid;
|
||||
drupal_set_message(t('Created new @type %term.', array('%term' => $form_state['values']['name'], '@type' => $type)));
|
||||
break;
|
||||
case SAVED_UPDATED:
|
||||
drupal_set_message(t('The @type %term has been updated.', array('%term' => $form_state['values']['name'], '@type' => $type)));
|
||||
// Clear the page and block caches to avoid stale data.
|
||||
cache_clear_all();
|
||||
break;
|
||||
}
|
||||
$form_state['redirect'] = 'admin/structure/forum';
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for a forum form.
|
||||
*
|
||||
* By default this does not alter the appearance of a form at all, but is
|
||||
* provided as a convenience for themers.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - form: A render element representing the form.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_forum_form($variables) {
|
||||
return drupal_render_children($variables['form']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form constructor for adding and editing forum containers.
|
||||
*
|
||||
* @param $edit
|
||||
* (optional) Associative array containing a container term to be added or edited.
|
||||
* Defaults to an empty array.
|
||||
*
|
||||
* @see forum_form_submit()
|
||||
* @ingroup forms
|
||||
*/
|
||||
function forum_form_container($form, &$form_state, $edit = array()) {
|
||||
$edit += array(
|
||||
'name' => '',
|
||||
'description' => '',
|
||||
'tid' => NULL,
|
||||
'weight' => 0,
|
||||
);
|
||||
// Handle a delete operation.
|
||||
$form['name'] = array(
|
||||
'#title' => t('Container name'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $edit['name'],
|
||||
'#maxlength' => 255,
|
||||
'#description' => t('Short but meaningful name for this collection of related forums.'),
|
||||
'#required' => TRUE
|
||||
);
|
||||
|
||||
$form['description'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Description'),
|
||||
'#default_value' => $edit['description'],
|
||||
'#description' => t('Description and guidelines for forums within this container.')
|
||||
);
|
||||
$form['parent']['#tree'] = TRUE;
|
||||
$form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'container');
|
||||
$form['weight'] = array(
|
||||
'#type' => 'weight',
|
||||
'#title' => t('Weight'),
|
||||
'#default_value' => $edit['weight'],
|
||||
'#description' => t('Containers are displayed in ascending order by weight (containers with equal weights are displayed alphabetically).')
|
||||
);
|
||||
|
||||
$form['vid'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => variable_get('forum_nav_vocabulary', ''),
|
||||
);
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save')
|
||||
);
|
||||
if ($edit['tid']) {
|
||||
$form['actions']['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
|
||||
$form['tid'] = array('#type' => 'value', '#value' => $edit['tid']);
|
||||
}
|
||||
$form['#submit'][] = 'forum_form_submit';
|
||||
$form['#theme'] = 'forum_form';
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form constructor for confirming deletion of a forum taxonomy term.
|
||||
*
|
||||
* @param $tid
|
||||
* ID of the term to be deleted.
|
||||
*
|
||||
* @see forum_confirm_delete_submit()
|
||||
* @ingroup forms
|
||||
*/
|
||||
function forum_confirm_delete($form, &$form_state, $tid) {
|
||||
$term = taxonomy_term_load($tid);
|
||||
|
||||
$form['tid'] = array('#type' => 'value', '#value' => $tid);
|
||||
$form['name'] = array('#type' => 'value', '#value' => $term->name);
|
||||
|
||||
return confirm_form($form, t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/structure/forum', t('Deleting a forum or container will also delete its sub-forums, if any. To delete posts in this forum, visit <a href="@content">content administration</a> first. This action cannot be undone.', array('@content' => url('admin/content'))), t('Delete'), t('Cancel'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission handler for forum_confirm_delete().
|
||||
*/
|
||||
function forum_confirm_delete_submit($form, &$form_state) {
|
||||
taxonomy_term_delete($form_state['values']['tid']);
|
||||
drupal_set_message(t('The forum %term and all sub-forums have been deleted.', array('%term' => $form_state['values']['name'])));
|
||||
watchdog('content', 'forum: deleted %term and all its sub-forums.', array('%term' => $form_state['values']['name']));
|
||||
|
||||
$form_state['redirect'] = 'admin/structure/forum';
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form constructor for the forum settings page.
|
||||
*
|
||||
* @see forum_menu()
|
||||
* @see system_settings_form()
|
||||
* @ingroup forms
|
||||
*/
|
||||
function forum_admin_settings($form) {
|
||||
$number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500));
|
||||
$form['forum_hot_topic'] = array('#type' => 'select',
|
||||
'#title' => t('Hot topic threshold'),
|
||||
'#default_value' => variable_get('forum_hot_topic', 15),
|
||||
'#options' => $number,
|
||||
'#description' => t('The number of replies a topic must have to be considered "hot".'),
|
||||
);
|
||||
$number = drupal_map_assoc(array(10, 25, 50, 75, 100));
|
||||
$form['forum_per_page'] = array('#type' => 'select',
|
||||
'#title' => t('Topics per page'),
|
||||
'#default_value' => variable_get('forum_per_page', 25),
|
||||
'#options' => $number,
|
||||
'#description' => t('Default number of forum topics displayed per page.'),
|
||||
);
|
||||
$forder = array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4 => t('Posts - least active first'));
|
||||
$form['forum_order'] = array('#type' => 'radios',
|
||||
'#title' => t('Default order'),
|
||||
'#default_value' => variable_get('forum_order', 1),
|
||||
'#options' => $forder,
|
||||
'#description' => t('Default display order for topics.'),
|
||||
);
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form constructor for the forum overview form.
|
||||
*
|
||||
* Returns a form for controlling the hierarchy of existing forums and
|
||||
* containers.
|
||||
*
|
||||
* @see forum_menu()
|
||||
* @ingroup forms
|
||||
*/
|
||||
function forum_overview($form, &$form_state) {
|
||||
module_load_include('inc', 'taxonomy', 'taxonomy.admin');
|
||||
|
||||
$vid = variable_get('forum_nav_vocabulary', '');
|
||||
$vocabulary = taxonomy_vocabulary_load($vid);
|
||||
$form = taxonomy_overview_terms($form, $form_state, $vocabulary);
|
||||
|
||||
foreach (element_children($form) as $key) {
|
||||
if (isset($form[$key]['#term'])) {
|
||||
$term = $form[$key]['#term'];
|
||||
$form[$key]['view']['#href'] = 'forum/' . $term['tid'];
|
||||
if (in_array($form[$key]['#term']['tid'], variable_get('forum_containers', array()))) {
|
||||
$form[$key]['edit']['#title'] = t('edit container');
|
||||
$form[$key]['edit']['#href'] = 'admin/structure/forum/edit/container/' . $term['tid'];
|
||||
}
|
||||
else {
|
||||
$form[$key]['edit']['#title'] = t('edit forum');
|
||||
$form[$key]['edit']['#href'] = 'admin/structure/forum/edit/forum/' . $term['tid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the alphabetical reset.
|
||||
unset($form['actions']['reset_alphabetical']);
|
||||
|
||||
// The form needs to have submit and validate handlers set explicitly.
|
||||
$form['#theme'] = 'taxonomy_overview_terms';
|
||||
$form['#submit'] = array('taxonomy_overview_terms_submit'); // Use the existing taxonomy overview submit handler.
|
||||
$form['#empty_text'] = t('No containers or forums available. <a href="@container">Add container</a> or <a href="@forum">Add forum</a>.', array('@container' => url('admin/structure/forum/add/container'), '@forum' => url('admin/structure/forum/add/forum')));
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a select box for available parent terms.
|
||||
*
|
||||
* @param $tid
|
||||
* ID of the term that is being added or edited.
|
||||
* @param $title
|
||||
* Title for the select box.
|
||||
* @param $child_type
|
||||
* Whether the child is a forum or a container.
|
||||
*
|
||||
* @return
|
||||
* A select form element.
|
||||
*/
|
||||
function _forum_parent_select($tid, $title, $child_type) {
|
||||
|
||||
$parents = taxonomy_get_parents($tid);
|
||||
if ($parents) {
|
||||
$parent = array_shift($parents);
|
||||
$parent = $parent->tid;
|
||||
}
|
||||
else {
|
||||
$parent = 0;
|
||||
}
|
||||
|
||||
$vid = variable_get('forum_nav_vocabulary', '');
|
||||
$children = taxonomy_get_tree($vid, $tid);
|
||||
|
||||
// A term can't be the child of itself, nor of its children.
|
||||
foreach ($children as $child) {
|
||||
$exclude[] = $child->tid;
|
||||
}
|
||||
$exclude[] = $tid;
|
||||
|
||||
$tree = taxonomy_get_tree($vid);
|
||||
$options[0] = '<' . t('root') . '>';
|
||||
if ($tree) {
|
||||
foreach ($tree as $term) {
|
||||
if (!in_array($term->tid, $exclude)) {
|
||||
$options[$term->tid] = str_repeat(' -- ', $term->depth) . $term->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($child_type == 'container') {
|
||||
$description = t('Containers are usually placed at the top (root) level, but may also be placed inside another container or forum.');
|
||||
}
|
||||
elseif ($child_type == 'forum') {
|
||||
$description = t('Forums may be placed at the top (root) level, or inside another container or forum.');
|
||||
}
|
||||
|
||||
return array('#type' => 'select', '#title' => $title, '#default_value' => $parent, '#options' => $options, '#description' => $description, '#required' => TRUE);
|
||||
}
|
54
modules/forum/forum.css
Normal file
54
modules/forum/forum.css
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* @file
|
||||
* Styling for the Forum module.
|
||||
*/
|
||||
|
||||
#forum .description {
|
||||
font-size: 0.9em;
|
||||
margin: 0.5em;
|
||||
}
|
||||
#forum td.created,
|
||||
#forum td.posts,
|
||||
#forum td.topics,
|
||||
#forum td.last-reply,
|
||||
#forum td.replies,
|
||||
#forum td.pager {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#forum td.forum .icon {
|
||||
background-image: url(../../misc/forum-icons.png);
|
||||
background-repeat: no-repeat;
|
||||
float: left; /* LTR */
|
||||
height: 24px;
|
||||
margin: 0 9px 0 0; /* LTR */
|
||||
width: 24px;
|
||||
}
|
||||
#forum td.forum .forum-status-new {
|
||||
background-position: -24px 0;
|
||||
}
|
||||
|
||||
#forum div.indent {
|
||||
margin-left: 20px; /* LTR */
|
||||
}
|
||||
#forum .icon div {
|
||||
background-image: url(../../misc/forum-icons.png);
|
||||
background-repeat: no-repeat;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
}
|
||||
#forum .icon .topic-status-new {
|
||||
background-position: -24px 0;
|
||||
}
|
||||
#forum .icon .topic-status-hot {
|
||||
background-position: -48px 0;
|
||||
}
|
||||
#forum .icon .topic-status-hot-new {
|
||||
background-position: -72px 0;
|
||||
}
|
||||
#forum .icon .topic-status-sticky {
|
||||
background-position: -96px 0;
|
||||
}
|
||||
#forum .icon .topic-status-closed {
|
||||
background-position: -120px 0;
|
||||
}
|
16
modules/forum/forum.info
Normal file
16
modules/forum/forum.info
Normal file
|
@ -0,0 +1,16 @@
|
|||
name = Forum
|
||||
description = Provides discussion forums.
|
||||
dependencies[] = taxonomy
|
||||
dependencies[] = comment
|
||||
package = Core
|
||||
version = VERSION
|
||||
core = 7.x
|
||||
files[] = forum.test
|
||||
configure = admin/structure/forum
|
||||
stylesheets[all][] = forum.css
|
||||
|
||||
; Information added by Drupal.org packaging script on 2017-06-21
|
||||
version = "7.56"
|
||||
project = "drupal"
|
||||
datestamp = "1498069849"
|
||||
|
467
modules/forum/forum.install
Normal file
467
modules/forum/forum.install
Normal file
|
@ -0,0 +1,467 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update, and uninstall functions for the Forum module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function forum_install() {
|
||||
// Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module.
|
||||
db_update('system')
|
||||
->fields(array('weight' => 1))
|
||||
->condition('name', 'forum')
|
||||
->execute();
|
||||
// Forum topics are published by default, but do not have any other default
|
||||
// options set (for example, they are not promoted to the front page).
|
||||
variable_set('node_options_forum', array('status'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function forum_enable() {
|
||||
// If we enable forum at the same time as taxonomy we need to call
|
||||
// field_associate_fields() as otherwise the field won't be enabled until
|
||||
// hook modules_enabled is called which takes place after hook_enable events.
|
||||
field_associate_fields('taxonomy');
|
||||
// Create the forum vocabulary if it does not exist.
|
||||
$vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0));
|
||||
if (!$vocabulary) {
|
||||
$edit = array(
|
||||
'name' => t('Forums'),
|
||||
'machine_name' => 'forums',
|
||||
'description' => t('Forum navigation vocabulary'),
|
||||
'hierarchy' => 1,
|
||||
'module' => 'forum',
|
||||
'weight' => -10,
|
||||
);
|
||||
$vocabulary = (object) $edit;
|
||||
taxonomy_vocabulary_save($vocabulary);
|
||||
variable_set('forum_nav_vocabulary', $vocabulary->vid);
|
||||
}
|
||||
|
||||
// Create the 'taxonomy_forums' field if it doesn't already exist.
|
||||
if (!field_info_field('taxonomy_forums')) {
|
||||
$field = array(
|
||||
'field_name' => 'taxonomy_forums',
|
||||
'type' => 'taxonomy_term_reference',
|
||||
'settings' => array(
|
||||
'allowed_values' => array(
|
||||
array(
|
||||
'vocabulary' => $vocabulary->machine_name,
|
||||
'parent' => 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
field_create_field($field);
|
||||
|
||||
// Create a default forum so forum posts can be created.
|
||||
$edit = array(
|
||||
'name' => t('General discussion'),
|
||||
'description' => '',
|
||||
'parent' => array(0),
|
||||
'vid' => $vocabulary->vid,
|
||||
);
|
||||
$term = (object) $edit;
|
||||
taxonomy_term_save($term);
|
||||
|
||||
// Create the instance on the bundle.
|
||||
$instance = array(
|
||||
'field_name' => 'taxonomy_forums',
|
||||
'entity_type' => 'node',
|
||||
'label' => $vocabulary->name,
|
||||
'bundle' => 'forum',
|
||||
'required' => TRUE,
|
||||
'widget' => array(
|
||||
'type' => 'options_select',
|
||||
),
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'type' => 'taxonomy_term_reference_link',
|
||||
'weight' => 10,
|
||||
),
|
||||
'teaser' => array(
|
||||
'type' => 'taxonomy_term_reference_link',
|
||||
'weight' => 10,
|
||||
),
|
||||
),
|
||||
);
|
||||
field_create_instance($instance);
|
||||
}
|
||||
|
||||
// Ensure the forum node type is available.
|
||||
node_types_rebuild();
|
||||
$types = node_type_get_types();
|
||||
node_add_body_field($types['forum']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function forum_uninstall() {
|
||||
// Load the dependent Taxonomy module, in case it has been disabled.
|
||||
drupal_load('module', 'taxonomy');
|
||||
|
||||
variable_del('forum_containers');
|
||||
variable_del('forum_hot_topic');
|
||||
variable_del('forum_per_page');
|
||||
variable_del('forum_order');
|
||||
variable_del('forum_block_num_active');
|
||||
variable_del('forum_block_num_new');
|
||||
variable_del('node_options_forum');
|
||||
|
||||
field_delete_field('taxonomy_forums');
|
||||
// Purge field data now to allow taxonomy module to be uninstalled
|
||||
// if this is the only field remaining.
|
||||
field_purge_batch(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function forum_schema() {
|
||||
$schema['forum'] = array(
|
||||
'description' => 'Stores the relationship of nodes to forum terms.',
|
||||
'fields' => array(
|
||||
'nid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The {node}.nid of the node.',
|
||||
),
|
||||
'vid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'Primary Key: The {node}.vid of the node.',
|
||||
),
|
||||
'tid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The {taxonomy_term_data}.tid of the forum term assigned to the node.',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'forum_topic' => array('nid', 'tid'),
|
||||
'tid' => array('tid'),
|
||||
),
|
||||
'primary key' => array('vid'),
|
||||
'foreign keys' => array(
|
||||
'forum_node' => array(
|
||||
'table' => 'node',
|
||||
'columns' => array(
|
||||
'nid' => 'nid',
|
||||
'vid' => 'vid',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$schema['forum_index'] = array(
|
||||
'description' => 'Maintains denormalized information about node/term relationships.',
|
||||
'fields' => array(
|
||||
'nid' => array(
|
||||
'description' => 'The {node}.nid this record tracks.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => 'The title of this node, always treated as non-markup plain text.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'tid' => array(
|
||||
'description' => 'The term ID.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'sticky' => array(
|
||||
'description' => 'Boolean indicating whether the node is sticky.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
'default' => 0,
|
||||
'size' => 'tiny',
|
||||
),
|
||||
'created' => array(
|
||||
'description' => 'The Unix timestamp when the node was created.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default'=> 0,
|
||||
),
|
||||
'last_comment_timestamp' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
|
||||
),
|
||||
'comment_count' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The total number of comments on this node.',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'forum_topics' => array('nid', 'tid', 'sticky', 'last_comment_timestamp'),
|
||||
'created' => array('created'),
|
||||
'last_comment_timestamp' => array('last_comment_timestamp'),
|
||||
),
|
||||
'foreign keys' => array(
|
||||
'tracked_node' => array(
|
||||
'table' => 'node',
|
||||
'columns' => array('nid' => 'nid'),
|
||||
),
|
||||
'term' => array(
|
||||
'table' => 'taxonomy_term_data',
|
||||
'columns' => array(
|
||||
'tid' => 'tid',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_update_dependencies().
|
||||
*/
|
||||
function forum_update_dependencies() {
|
||||
$dependencies['forum'][7003] = array(
|
||||
// Forum update 7003 uses field API update functions, so must run after
|
||||
// Field API has been enabled.
|
||||
'system' => 7020,
|
||||
// Forum update 7003 relies on updated taxonomy module schema. Ensure it
|
||||
// runs after all taxonomy updates.
|
||||
'taxonomy' => 7010,
|
||||
);
|
||||
return $dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new index to forum table.
|
||||
*/
|
||||
function forum_update_7000() {
|
||||
db_drop_index('forum', 'nid');
|
||||
db_add_index('forum', 'forum_topic', array('nid', 'tid'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new {forum_index} table.
|
||||
*/
|
||||
function forum_update_7001() {
|
||||
$forum_index = array(
|
||||
'description' => 'Maintains denormalized information about node/term relationships.',
|
||||
'fields' => array(
|
||||
'nid' => array(
|
||||
'description' => 'The {node}.nid this record tracks.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => 'The title of this node, always treated as non-markup plain text.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'tid' => array(
|
||||
'description' => 'The term ID.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'sticky' => array(
|
||||
'description' => 'Boolean indicating whether the node is sticky.',
|
||||
'type' => 'int',
|
||||
'not null' => FALSE,
|
||||
'default' => 0,
|
||||
'size' => 'tiny',
|
||||
),
|
||||
'created' => array(
|
||||
'description' => 'The Unix timestamp when the node was created.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default'=> 0,
|
||||
),
|
||||
'last_comment_timestamp' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
|
||||
),
|
||||
'comment_count' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The total number of comments on this node.',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'forum_topics' => array('tid', 'sticky', 'last_comment_timestamp'),
|
||||
),
|
||||
'foreign keys' => array(
|
||||
'tracked_node' => array(
|
||||
'table' => 'node',
|
||||
'columns' => array('nid' => 'nid'),
|
||||
),
|
||||
'term' => array(
|
||||
'table' => 'taxonomy_term_data',
|
||||
'columns' => array(
|
||||
'tid' => 'tid',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
db_create_table('forum_index', $forum_index);
|
||||
|
||||
$select = db_select('node', 'n');
|
||||
$forum_alias = $select->join('forum', 'f', 'n.vid = f.vid');
|
||||
$ncs_alias = $select->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');
|
||||
$select
|
||||
->fields('n', array('nid', 'title', 'sticky', 'created'))
|
||||
->fields($forum_alias, array('tid'))
|
||||
->fields($ncs_alias, array('last_comment_timestamp', 'comment_count'));
|
||||
|
||||
db_insert('forum_index')
|
||||
->fields(array('nid', 'title', 'sticky', 'created', 'tid', 'last_comment_timestamp', 'comment_count'))
|
||||
->from($select)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @addtogroup updates-7.x-extra
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add new index to forum_index table.
|
||||
*/
|
||||
function forum_update_7002() {
|
||||
db_drop_index('forum_index', 'forum_topics');
|
||||
db_add_index('forum_index', 'forum_topics', array('nid', 'tid', 'sticky', 'last_comment_timestamp'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename field to 'taxonomy_forums'.
|
||||
*/
|
||||
function forum_update_7003() {
|
||||
$messages = array();
|
||||
|
||||
$new_field_name = 'taxonomy_forums';
|
||||
|
||||
// Test to see if the taxonomy_forums field exists.
|
||||
$fields = _update_7000_field_read_fields(array('field_name' => $new_field_name));
|
||||
if ($fields) {
|
||||
// Since the field exists, we're done.
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate the old field name.
|
||||
$vid = variable_get('forum_nav_vocabulary', 0);
|
||||
$vocabulary_machine_name = db_select('taxonomy_vocabulary', 'tv')
|
||||
->fields('tv', array('machine_name'))
|
||||
->condition('vid', $vid)
|
||||
->execute()
|
||||
->fetchField();
|
||||
$old_field_name = 'taxonomy_' . $vocabulary_machine_name;
|
||||
|
||||
// Read the old fields.
|
||||
$old_fields = _update_7000_field_read_fields(array('field_name' => $old_field_name));
|
||||
foreach ($old_fields as $old_field) {
|
||||
if ($old_field['storage']['type'] != 'field_sql_storage') {
|
||||
$messages[] = t('Cannot rename field %id (%old_field_name) to %new_field_name because it does not use the field_sql_storage storage type.', array(
|
||||
'%id' => $old_field['id'],
|
||||
'%old_field_name' => $old_field_name,
|
||||
'%new_field_name' => $new_field_name,
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Update {field_config}.
|
||||
db_update('field_config')
|
||||
->fields(array('field_name' => $new_field_name))
|
||||
->condition('id', $old_field['id'])
|
||||
->execute();
|
||||
|
||||
// Update {field_config_instance}.
|
||||
db_update('field_config_instance')
|
||||
->fields(array('field_name' => $new_field_name))
|
||||
->condition('field_id', $old_field['id'])
|
||||
->execute();
|
||||
|
||||
// The tables that need updating in the form 'old_name' => 'new_name'.
|
||||
$tables = array(
|
||||
'field_data_' . $old_field_name => 'field_data_' . $new_field_name,
|
||||
'field_revision_' . $old_field_name => 'field_revision_' . $new_field_name,
|
||||
);
|
||||
foreach ($tables as $old_table => $new_table) {
|
||||
$old_column_name = $old_field_name . '_tid';
|
||||
$new_column_name = $new_field_name . '_tid';
|
||||
|
||||
// Rename the column.
|
||||
db_drop_index($old_table, $old_column_name);
|
||||
db_change_field($old_table, $old_column_name, $new_column_name, array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => FALSE,
|
||||
));
|
||||
db_drop_index($old_table, $new_column_name);
|
||||
db_add_index($old_table, $new_column_name, array($new_column_name));
|
||||
|
||||
// Rename the table.
|
||||
db_rename_table($old_table, $new_table);
|
||||
}
|
||||
}
|
||||
|
||||
cache_clear_all('*', 'cache_field', TRUE);
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update {forum_index} so that only published nodes are indexed.
|
||||
*/
|
||||
function forum_update_7011() {
|
||||
$select = db_select('node', 'n')
|
||||
->fields('n', array('nid'))
|
||||
->condition('status', 0 );
|
||||
|
||||
db_delete('forum_index')
|
||||
->condition('nid', $select, 'IN')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add 'created' and 'last_comment_timestamp' indexes.
|
||||
*/
|
||||
function forum_update_7012() {
|
||||
db_add_index('forum_index', 'created', array('created'));
|
||||
db_add_index('forum_index', 'last_comment_timestamp', array('last_comment_timestamp'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup updates-7.x-extra".
|
||||
*/
|
1396
modules/forum/forum.module
Normal file
1396
modules/forum/forum.module
Normal file
File diff suppressed because it is too large
Load diff
37
modules/forum/forum.pages.inc
Normal file
37
modules/forum/forum.pages.inc
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* User page callbacks for the Forum module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page callback: Prints a forum listing.
|
||||
*
|
||||
* @param $forum_term
|
||||
* A tree of all forums for a given taxonomy term ID. Defaults to NULL. See
|
||||
* the return object of forum_forum_load() for a complete definition.
|
||||
*
|
||||
* @return
|
||||
* A string containing HTML representing the themed forum listing.
|
||||
*
|
||||
* @see forum_menu()
|
||||
*/
|
||||
function forum_page($forum_term = NULL) {
|
||||
if (!isset($forum_term)) {
|
||||
// On the main page, display all the top-level forums.
|
||||
$forum_term = forum_forum_load(0);
|
||||
}
|
||||
|
||||
$forum_per_page = variable_get('forum_per_page', 25);
|
||||
$sortby = variable_get('forum_order', 1);
|
||||
|
||||
if (empty($forum_term->container)) {
|
||||
$topics = forum_get_topics($forum_term->tid, $sortby, $forum_per_page);
|
||||
}
|
||||
else {
|
||||
$topics = '';
|
||||
}
|
||||
|
||||
return theme('forums', array('forums' => $forum_term->forums, 'topics' => $topics, 'parents' => $forum_term->parents, 'tid' => $forum_term->tid, 'sortby' => $sortby, 'forums_per_page' => $forum_per_page));
|
||||
}
|
687
modules/forum/forum.test
Normal file
687
modules/forum/forum.test
Normal file
|
@ -0,0 +1,687 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for forum.module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides automated tests for the Forum module.
|
||||
*/
|
||||
class ForumTestCase extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* A user with various administrative privileges.
|
||||
*/
|
||||
protected $admin_user;
|
||||
|
||||
/**
|
||||
* A user that can create forum topics and edit its own topics.
|
||||
*/
|
||||
protected $edit_own_topics_user;
|
||||
|
||||
/**
|
||||
* A user that can create, edit, and delete forum topics.
|
||||
*/
|
||||
protected $edit_any_topics_user;
|
||||
|
||||
/**
|
||||
* A user with no special privileges.
|
||||
*/
|
||||
protected $web_user;
|
||||
|
||||
/**
|
||||
* An array representing a container.
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* An array representing a forum.
|
||||
*/
|
||||
protected $forum;
|
||||
|
||||
/**
|
||||
* An array representing a root forum.
|
||||
*/
|
||||
protected $root_forum;
|
||||
|
||||
/**
|
||||
* An array of forum topic node IDs.
|
||||
*/
|
||||
protected $nids;
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Forum functionality',
|
||||
'description' => 'Create, view, edit, delete, and change forum entries and verify its consistency in the database.',
|
||||
'group' => 'Forum',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('taxonomy', 'comment', 'forum');
|
||||
// Create users.
|
||||
$this->admin_user = $this->drupalCreateUser(array(
|
||||
'access administration pages',
|
||||
'administer modules',
|
||||
'administer blocks',
|
||||
'administer forums',
|
||||
'administer menu',
|
||||
'administer taxonomy',
|
||||
'create forum content',
|
||||
));
|
||||
$this->edit_any_topics_user = $this->drupalCreateUser(array(
|
||||
'access administration pages',
|
||||
'create forum content',
|
||||
'edit any forum content',
|
||||
'delete any forum content',
|
||||
));
|
||||
$this->edit_own_topics_user = $this->drupalCreateUser(array(
|
||||
'create forum content',
|
||||
'edit own forum content',
|
||||
'delete own forum content',
|
||||
));
|
||||
$this->web_user = $this->drupalCreateUser(array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests disabling and re-enabling the Forum module.
|
||||
*/
|
||||
function testEnableForumField() {
|
||||
$this->drupalLogin($this->admin_user);
|
||||
|
||||
// Disable the Forum module.
|
||||
$edit = array();
|
||||
$edit['modules[Core][forum][enable]'] = FALSE;
|
||||
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
|
||||
$this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
|
||||
module_list(TRUE);
|
||||
$this->assertFalse(module_exists('forum'), 'Forum module is not enabled.');
|
||||
|
||||
// Attempt to re-enable the Forum module and ensure it does not try to
|
||||
// recreate the taxonomy_forums field.
|
||||
$edit = array();
|
||||
$edit['modules[Core][forum][enable]'] = 'forum';
|
||||
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
|
||||
$this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
|
||||
module_list(TRUE);
|
||||
$this->assertTrue(module_exists('forum'), 'Forum module is enabled.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests forum functionality through the admin and user interfaces.
|
||||
*/
|
||||
function testForum() {
|
||||
//Check that the basic forum install creates a default forum topic
|
||||
$this->drupalGet("/forum");
|
||||
// Look for the "General discussion" default forum
|
||||
$this->assertText(t("General discussion"), "Found the default forum at the /forum listing");
|
||||
|
||||
// Do the admin tests.
|
||||
$this->doAdminTests($this->admin_user);
|
||||
// Generate topics to populate the active forum block.
|
||||
$this->generateForumTopics($this->forum);
|
||||
|
||||
// Login an unprivileged user to view the forum topics and generate an
|
||||
// active forum topics list.
|
||||
$this->drupalLogin($this->web_user);
|
||||
// Verify that this user is shown a message that they may not post content.
|
||||
$this->drupalGet('forum/' . $this->forum['tid']);
|
||||
$this->assertText(t('You are not allowed to post new content in the forum'), "Authenticated user without permission to post forum content is shown message in local tasks to that effect.");
|
||||
|
||||
$this->viewForumTopics($this->nids);
|
||||
|
||||
// Log in, and do basic tests for a user with permission to edit any forum
|
||||
// content.
|
||||
$this->doBasicTests($this->edit_any_topics_user, TRUE);
|
||||
// Create a forum node authored by this user.
|
||||
$any_topics_user_node = $this->createForumTopic($this->forum, FALSE);
|
||||
|
||||
// Log in, and do basic tests for a user with permission to edit only its
|
||||
// own forum content.
|
||||
$this->doBasicTests($this->edit_own_topics_user, FALSE);
|
||||
// Create a forum node authored by this user.
|
||||
$own_topics_user_node = $this->createForumTopic($this->forum, FALSE);
|
||||
// Verify that this user cannot edit forum content authored by another user.
|
||||
$this->verifyForums($this->edit_any_topics_user, $any_topics_user_node, FALSE, 403);
|
||||
|
||||
// Verify that this user is shown a local task to add new forum content.
|
||||
$this->drupalGet('forum');
|
||||
$this->assertLink(t('Add new Forum topic'));
|
||||
$this->drupalGet('forum/' . $this->forum['tid']);
|
||||
$this->assertLink(t('Add new Forum topic'));
|
||||
|
||||
// Login a user with permission to edit any forum content.
|
||||
$this->drupalLogin($this->edit_any_topics_user);
|
||||
// Verify that this user can edit forum content authored by another user.
|
||||
$this->verifyForums($this->edit_own_topics_user, $own_topics_user_node, TRUE);
|
||||
|
||||
// Verify the topic and post counts on the forum page.
|
||||
$this->drupalGet('forum');
|
||||
|
||||
// Verify row for testing forum.
|
||||
$forum_arg = array(':forum' => 'forum-list-' . $this->forum['tid']);
|
||||
|
||||
// Topics cell contains number of topics and number of unread topics.
|
||||
$xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="topics"]', $forum_arg);
|
||||
$topics = $this->xpath($xpath);
|
||||
$topics = trim($topics[0]);
|
||||
$this->assertEqual($topics, '6', 'Number of topics found.');
|
||||
|
||||
// Verify the number of unread topics.
|
||||
$unread_topics = _forum_topics_unread($this->forum['tid'], $this->edit_any_topics_user->uid);
|
||||
$unread_topics = format_plural($unread_topics, '1 new', '@count new');
|
||||
$xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="topics"]//a', $forum_arg);
|
||||
$this->assertFieldByXPath($xpath, $unread_topics, 'Number of unread topics found.');
|
||||
|
||||
// Verify total number of posts in forum.
|
||||
$xpath = $this->buildXPathQuery('//tr[@id=:forum]//td[@class="posts"]', $forum_arg);
|
||||
$this->assertFieldByXPath($xpath, '6', 'Number of posts found.');
|
||||
|
||||
// Test loading multiple forum nodes on the front page.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer content types', 'create forum content')));
|
||||
$this->drupalPost('admin/structure/types/manage/forum', array('node_options[promote]' => 'promote'), t('Save content type'));
|
||||
$this->createForumTopic($this->forum, FALSE);
|
||||
$this->createForumTopic($this->forum, FALSE);
|
||||
$this->drupalGet('node');
|
||||
|
||||
// Test adding a comment to a forum topic.
|
||||
$node = $this->createForumTopic($this->forum, FALSE);
|
||||
$edit = array();
|
||||
$edit['comment_body[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName();
|
||||
$this->drupalPost("node/$node->nid", $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Test editing a forum topic that has a comment.
|
||||
$this->drupalLogin($this->edit_any_topics_user);
|
||||
$this->drupalGet('forum/' . $this->forum['tid']);
|
||||
$this->drupalPost("node/$node->nid/edit", array(), t('Save'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Make sure constructing a forum node programmatically produces no notices.
|
||||
$node = new stdClass;
|
||||
$node->type = 'forum';
|
||||
$node->title = 'Test forum notices';
|
||||
$node->uid = 1;
|
||||
$node->taxonomy_forums[LANGUAGE_NONE][0]['tid'] = $this->root_forum['tid'];
|
||||
node_save($node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that forum nodes can't be added without a parent.
|
||||
*
|
||||
* Verifies that forum nodes are not created without choosing "forum" from the
|
||||
* select list.
|
||||
*/
|
||||
function testAddOrphanTopic() {
|
||||
// Must remove forum topics to test creating orphan topics.
|
||||
$vid = variable_get('forum_nav_vocabulary');
|
||||
$tree = taxonomy_get_tree($vid);
|
||||
foreach ($tree as $term) {
|
||||
taxonomy_term_delete($term->tid);
|
||||
}
|
||||
|
||||
// Create an orphan forum item.
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->drupalPost('node/add/forum', array('title' => $this->randomName(10), 'body[' . LANGUAGE_NONE .'][0][value]' => $this->randomName(120)), t('Save'));
|
||||
|
||||
$nid_count = db_query('SELECT COUNT(nid) FROM {node}')->fetchField();
|
||||
$this->assertEqual(0, $nid_count, 'A forum node was not created when missing a forum vocabulary.');
|
||||
|
||||
// Reset the defaults for future tests.
|
||||
module_enable(array('forum'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs admin tests on the admin user.
|
||||
*
|
||||
* @param object $user
|
||||
* The logged in user.
|
||||
*/
|
||||
private function doAdminTests($user) {
|
||||
// Login the user.
|
||||
$this->drupalLogin($user);
|
||||
|
||||
// Enable the active forum block.
|
||||
$edit = array();
|
||||
$edit['blocks[forum_active][region]'] = 'sidebar_second';
|
||||
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText(t('The block settings have been updated.'), 'Active forum topics forum block was enabled');
|
||||
|
||||
// Enable the new forum block.
|
||||
$edit = array();
|
||||
$edit['blocks[forum_new][region]'] = 'sidebar_second';
|
||||
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText(t('The block settings have been updated.'), '[New forum topics] Forum block was enabled');
|
||||
|
||||
// Retrieve forum menu id.
|
||||
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = 'forum' AND menu_name = 'navigation' AND module = 'system' ORDER BY mlid ASC", 0, 1)->fetchField();
|
||||
|
||||
// Add forum to navigation menu.
|
||||
$edit = array();
|
||||
$this->drupalPost('admin/structure/menu/manage/navigation', $edit, t('Save configuration'));
|
||||
$this->assertResponse(200);
|
||||
|
||||
// Edit forum taxonomy.
|
||||
// Restoration of the settings fails and causes subsequent tests to fail.
|
||||
$this->container = $this->editForumTaxonomy();
|
||||
// Create forum container.
|
||||
$this->container = $this->createForum('container');
|
||||
// Verify "edit container" link exists and functions correctly.
|
||||
$this->drupalGet('admin/structure/forum');
|
||||
$this->clickLink('edit container');
|
||||
$this->assertRaw('Edit container', 'Followed the link to edit the container');
|
||||
// Create forum inside the forum container.
|
||||
$this->forum = $this->createForum('forum', $this->container['tid']);
|
||||
// Verify the "edit forum" link exists and functions correctly.
|
||||
$this->drupalGet('admin/structure/forum');
|
||||
$this->clickLink('edit forum');
|
||||
$this->assertRaw('Edit forum', 'Followed the link to edit the forum');
|
||||
// Navigate back to forum structure page.
|
||||
$this->drupalGet('admin/structure/forum');
|
||||
// Create second forum in container.
|
||||
$this->delete_forum = $this->createForum('forum', $this->container['tid']);
|
||||
// Save forum overview.
|
||||
$this->drupalPost('admin/structure/forum/', array(), t('Save'));
|
||||
$this->assertRaw(t('The configuration options have been saved.'));
|
||||
// Delete this second forum.
|
||||
$this->deleteForum($this->delete_forum['tid']);
|
||||
// Create forum at the top (root) level.
|
||||
$this->root_forum = $this->createForum('forum');
|
||||
|
||||
// Test vocabulary form alterations.
|
||||
$this->drupalGet('admin/structure/taxonomy/forums/edit');
|
||||
$this->assertFieldByName('op', t('Save'), 'Save button found.');
|
||||
$this->assertNoFieldByName('op', t('Delete'), 'Delete button not found.');
|
||||
|
||||
// Test term edit form alterations.
|
||||
$this->drupalGet('taxonomy/term/' . $this->container['tid'] . '/edit');
|
||||
// Test parent field been hidden by forum module.
|
||||
$this->assertNoField('parent[]', 'Parent field not found.');
|
||||
|
||||
// Test tags vocabulary form is not affected.
|
||||
$this->drupalGet('admin/structure/taxonomy/tags/edit');
|
||||
$this->assertFieldByName('op', t('Save'), 'Save button found.');
|
||||
$this->assertFieldByName('op', t('Delete'), 'Delete button found.');
|
||||
// Test tags vocabulary term form is not affected.
|
||||
$this->drupalGet('admin/structure/taxonomy/tags/add');
|
||||
$this->assertField('parent[]', 'Parent field found.');
|
||||
// Test relations fieldset exists.
|
||||
$relations_fieldset = $this->xpath("//fieldset[@id='edit-relations']");
|
||||
$this->assertTrue(isset($relations_fieldset[0]), 'Relations fieldset element found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the forum taxonomy.
|
||||
*/
|
||||
function editForumTaxonomy() {
|
||||
// Backup forum taxonomy.
|
||||
$vid = variable_get('forum_nav_vocabulary', '');
|
||||
$original_settings = taxonomy_vocabulary_load($vid);
|
||||
|
||||
// Generate a random name/description.
|
||||
$title = $this->randomName(10);
|
||||
$description = $this->randomName(100);
|
||||
|
||||
$edit = array(
|
||||
'name' => $title,
|
||||
'description' => $description,
|
||||
'machine_name' => drupal_strtolower(drupal_substr($this->randomName(), 3, 9)),
|
||||
);
|
||||
|
||||
// Edit the vocabulary.
|
||||
$this->drupalPost('admin/structure/taxonomy/' . $original_settings->machine_name . '/edit', $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertRaw(t('Updated vocabulary %name.', array('%name' => $title)), 'Vocabulary was edited');
|
||||
|
||||
// Grab the newly edited vocabulary.
|
||||
entity_get_controller('taxonomy_vocabulary')->resetCache();
|
||||
$current_settings = taxonomy_vocabulary_load($vid);
|
||||
|
||||
// Make sure we actually edited the vocabulary properly.
|
||||
$this->assertEqual($current_settings->name, $title, 'The name was updated');
|
||||
$this->assertEqual($current_settings->description, $description, 'The description was updated');
|
||||
|
||||
// Restore the original vocabulary.
|
||||
taxonomy_vocabulary_save($original_settings);
|
||||
drupal_static_reset('taxonomy_vocabulary_load');
|
||||
$current_settings = taxonomy_vocabulary_load($vid);
|
||||
$this->assertEqual($current_settings->name, $original_settings->name, 'The original vocabulary settings were restored');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a forum container or a forum.
|
||||
*
|
||||
* @param $type
|
||||
* The forum type (forum container or forum).
|
||||
* @param $parent
|
||||
* The forum parent. This defaults to 0, indicating a root forum.
|
||||
* another forum).
|
||||
*
|
||||
* @return
|
||||
* The created taxonomy term data.
|
||||
*/
|
||||
function createForum($type, $parent = 0) {
|
||||
// Generate a random name/description.
|
||||
$name = $this->randomName(10);
|
||||
$description = $this->randomName(100);
|
||||
|
||||
$edit = array(
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'parent[0]' => $parent,
|
||||
'weight' => '0',
|
||||
);
|
||||
|
||||
// Create forum.
|
||||
$this->drupalPost('admin/structure/forum/add/' . $type, $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
$type = ($type == 'container') ? 'forum container' : 'forum';
|
||||
$this->assertRaw(t('Created new @type %term.', array('%term' => $name, '@type' => t($type))), format_string('@type was created', array('@type' => ucfirst($type))));
|
||||
|
||||
// Verify forum.
|
||||
$term = db_query("SELECT * FROM {taxonomy_term_data} t WHERE t.vid = :vid AND t.name = :name AND t.description = :desc", array(':vid' => variable_get('forum_nav_vocabulary', ''), ':name' => $name, ':desc' => $description))->fetchAssoc();
|
||||
$this->assertTrue(!empty($term), 'The ' . $type . ' exists in the database');
|
||||
|
||||
// Verify forum hierarchy.
|
||||
$tid = $term['tid'];
|
||||
$parent_tid = db_query("SELECT t.parent FROM {taxonomy_term_hierarchy} t WHERE t.tid = :tid", array(':tid' => $tid))->fetchField();
|
||||
$this->assertTrue($parent == $parent_tid, 'The ' . $type . ' is linked to its container');
|
||||
|
||||
return $term;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a forum.
|
||||
*
|
||||
* @param $tid
|
||||
* The forum ID.
|
||||
*/
|
||||
function deleteForum($tid) {
|
||||
// Delete the forum.
|
||||
$this->drupalPost('admin/structure/forum/edit/forum/' . $tid, array(), t('Delete'));
|
||||
$this->drupalPost(NULL, array(), t('Delete'));
|
||||
|
||||
// Assert that the forum no longer exists.
|
||||
$this->drupalGet('forum/' . $tid);
|
||||
$this->assertResponse(404, 'The forum was not found');
|
||||
|
||||
// Assert that the associated term has been removed from the
|
||||
// forum_containers variable.
|
||||
$containers = variable_get('forum_containers', array());
|
||||
$this->assertFalse(in_array($tid, $containers), 'The forum_containers variable has been updated.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs basic tests on the indicated user.
|
||||
*
|
||||
* @param $user
|
||||
* The logged in user.
|
||||
* @param $admin
|
||||
* User has 'access administration pages' privilege.
|
||||
*/
|
||||
private function doBasicTests($user, $admin) {
|
||||
// Login the user.
|
||||
$this->drupalLogin($user);
|
||||
// Attempt to create forum topic under a container.
|
||||
$this->createForumTopic($this->container, TRUE);
|
||||
// Create forum node.
|
||||
$node = $this->createForumTopic($this->forum, FALSE);
|
||||
// Verify the user has access to all the forum nodes.
|
||||
$this->verifyForums($user, $node, $admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates forum topic.
|
||||
*
|
||||
* @param array $forum
|
||||
* A forum array.
|
||||
* @param boolean $container
|
||||
* TRUE if $forum is a container; FALSE otherwise.
|
||||
*
|
||||
* @return object
|
||||
* The created topic node.
|
||||
*/
|
||||
function createForumTopic($forum, $container = FALSE) {
|
||||
// Generate a random subject/body.
|
||||
$title = $this->randomName(20);
|
||||
$body = $this->randomName(200);
|
||||
|
||||
$langcode = LANGUAGE_NONE;
|
||||
$edit = array(
|
||||
"title" => $title,
|
||||
"body[$langcode][0][value]" => $body,
|
||||
);
|
||||
$tid = $forum['tid'];
|
||||
|
||||
// Create the forum topic, preselecting the forum ID via a URL parameter.
|
||||
$this->drupalPost('node/add/forum/' . $tid, $edit, t('Save'));
|
||||
|
||||
$type = t('Forum topic');
|
||||
if ($container) {
|
||||
$this->assertNoRaw(t('@type %title has been created.', array('@type' => $type, '%title' => $title)), 'Forum topic was not created');
|
||||
$this->assertRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), 'Error message was shown');
|
||||
return;
|
||||
}
|
||||
else {
|
||||
$this->assertRaw(t('@type %title has been created.', array('@type' => $type, '%title' => $title)), 'Forum topic was created');
|
||||
$this->assertNoRaw(t('The item %title is a forum container, not a forum.', array('%title' => $forum['name'])), 'No error message was shown');
|
||||
}
|
||||
|
||||
// Retrieve node object, ensure that the topic was created and in the proper forum.
|
||||
$node = $this->drupalGetNodeByTitle($title);
|
||||
$this->assertTrue($node != NULL, format_string('Node @title was loaded', array('@title' => $title)));
|
||||
$this->assertEqual($node->taxonomy_forums[LANGUAGE_NONE][0]['tid'], $tid, 'Saved forum topic was in the expected forum');
|
||||
|
||||
// View forum topic.
|
||||
$this->drupalGet('node/' . $node->nid);
|
||||
$this->assertRaw($title, 'Subject was found');
|
||||
$this->assertRaw($body, 'Body was found');
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the logged in user has access to a forum nodes.
|
||||
*
|
||||
* @param $node_user
|
||||
* The user who creates the node.
|
||||
* @param $node
|
||||
* The node being checked.
|
||||
* @param $admin
|
||||
* Boolean to indicate whether the user can 'access administration pages'.
|
||||
* @param $response
|
||||
* The exptected HTTP response code.
|
||||
*/
|
||||
private function verifyForums($node_user, $node, $admin, $response = 200) {
|
||||
$response2 = ($admin) ? 200 : 403;
|
||||
|
||||
// View forum help node.
|
||||
$this->drupalGet('admin/help/forum');
|
||||
$this->assertResponse($response2);
|
||||
if ($response2 == 200) {
|
||||
$this->assertTitle(t('Forum | Drupal'), 'Forum help title was displayed');
|
||||
$this->assertText(t('Forum'), 'Forum help node was displayed');
|
||||
}
|
||||
|
||||
// Verify the forum blocks were displayed.
|
||||
$this->drupalGet('');
|
||||
$this->assertResponse(200);
|
||||
$this->assertText(t('New forum topics'), '[New forum topics] Forum block was displayed');
|
||||
|
||||
// View forum container page.
|
||||
$this->verifyForumView($this->container);
|
||||
// View forum page.
|
||||
$this->verifyForumView($this->forum, $this->container);
|
||||
// View root forum page.
|
||||
$this->verifyForumView($this->root_forum);
|
||||
|
||||
// View forum node.
|
||||
$this->drupalGet('node/' . $node->nid);
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle($node->title . ' | Drupal', 'Forum node was displayed');
|
||||
$breadcrumb = array(
|
||||
l(t('Home'), NULL),
|
||||
l(t('Forums'), 'forum'),
|
||||
l($this->container['name'], 'forum/' . $this->container['tid']),
|
||||
l($this->forum['name'], 'forum/' . $this->forum['tid']),
|
||||
);
|
||||
$this->assertRaw(theme('breadcrumb', array('breadcrumb' => $breadcrumb)), 'Breadcrumbs were displayed');
|
||||
|
||||
// View forum edit node.
|
||||
$this->drupalGet('node/' . $node->nid . '/edit');
|
||||
$this->assertResponse($response);
|
||||
if ($response == 200) {
|
||||
$this->assertTitle('Edit Forum topic ' . $node->title . ' | Drupal', 'Forum edit node was displayed');
|
||||
}
|
||||
|
||||
if ($response == 200) {
|
||||
// Edit forum node (including moving it to another forum).
|
||||
$edit = array();
|
||||
$langcode = LANGUAGE_NONE;
|
||||
$edit["title"] = 'node/' . $node->nid;
|
||||
$edit["body[$langcode][0][value]"] = $this->randomName(256);
|
||||
// Assume the topic is initially associated with $forum.
|
||||
$edit["taxonomy_forums[$langcode]"] = $this->root_forum['tid'];
|
||||
$edit['shadow'] = TRUE;
|
||||
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
||||
$this->assertRaw(t('Forum topic %title has been updated.', array('%title' => $edit["title"])), 'Forum node was edited');
|
||||
|
||||
// Verify topic was moved to a different forum.
|
||||
$forum_tid = db_query("SELECT tid FROM {forum} WHERE nid = :nid AND vid = :vid", array(
|
||||
':nid' => $node->nid,
|
||||
':vid' => $node->vid,
|
||||
))->fetchField();
|
||||
$this->assertTrue($forum_tid == $this->root_forum['tid'], 'The forum topic is linked to a different forum');
|
||||
|
||||
// Delete forum node.
|
||||
$this->drupalPost('node/' . $node->nid . '/delete', array(), t('Delete'));
|
||||
$this->assertResponse($response);
|
||||
$this->assertRaw(t('Forum topic %title has been deleted.', array('%title' => $edit['title'])), 'Forum node was deleted');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies display of forum page.
|
||||
*
|
||||
* @param $forum
|
||||
* A row from the taxonomy_term_data table in an array.
|
||||
* @param $parent
|
||||
* (optional) An array representing the forum's parent.
|
||||
*/
|
||||
private function verifyForumView($forum, $parent = NULL) {
|
||||
// View forum page.
|
||||
$this->drupalGet('forum/' . $forum['tid']);
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle($forum['name'] . ' | Drupal', 'Forum name was displayed');
|
||||
|
||||
$breadcrumb = array(
|
||||
l(t('Home'), NULL),
|
||||
l(t('Forums'), 'forum'),
|
||||
);
|
||||
if (isset($parent)) {
|
||||
$breadcrumb[] = l($parent['name'], 'forum/' . $parent['tid']);
|
||||
}
|
||||
|
||||
$this->assertRaw(theme('breadcrumb', array('breadcrumb' => $breadcrumb)), 'Breadcrumbs were displayed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates forum topics to test the display of an active forum block.
|
||||
*
|
||||
* @param array $forum
|
||||
* The foorum array (a row from taxonomy_term_data table).
|
||||
*/
|
||||
private function generateForumTopics($forum) {
|
||||
$this->nids = array();
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$node = $this->createForumTopic($this->forum, FALSE);
|
||||
$this->nids[] = $node->nid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Views forum topics to test the display of an active forum block.
|
||||
*
|
||||
* @todo The logic here is completely incorrect, since the active forum topics
|
||||
* block is determined by comments on the node, not by views.
|
||||
* @todo DIE
|
||||
*
|
||||
* @param $nids
|
||||
* An array of forum node IDs.
|
||||
*/
|
||||
private function viewForumTopics($nids) {
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
foreach ($nids as $nid) {
|
||||
$this->drupalGet('node/' . $nid);
|
||||
$this->drupalGet('node/' . $nid);
|
||||
$this->drupalGet('node/' . $nid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the forum index listing.
|
||||
*/
|
||||
class ForumIndexTestCase extends DrupalWebTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Forum index',
|
||||
'description' => 'Tests the forum index listing.',
|
||||
'group' => 'Forum',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('taxonomy', 'comment', 'forum');
|
||||
|
||||
// Create a test user.
|
||||
$web_user = $this->drupalCreateUser(array('create forum content', 'edit own forum content', 'edit any forum content', 'administer nodes'));
|
||||
$this->drupalLogin($web_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the forum index for published and unpublished nodes.
|
||||
*/
|
||||
function testForumIndexStatus() {
|
||||
|
||||
$langcode = LANGUAGE_NONE;
|
||||
|
||||
// The forum ID to use.
|
||||
$tid = 1;
|
||||
|
||||
// Create a test node.
|
||||
$title = $this->randomName(20);
|
||||
$edit = array(
|
||||
"title" => $title,
|
||||
"body[$langcode][0][value]" => $this->randomName(200),
|
||||
);
|
||||
|
||||
// Create the forum topic, preselecting the forum ID via a URL parameter.
|
||||
$this->drupalPost('node/add/forum/' . $tid, $edit, t('Save'));
|
||||
|
||||
// Check that the node exists in the database.
|
||||
$node = $this->drupalGetNodeByTitle($title);
|
||||
$this->assertTrue(!empty($node), 'New forum node found in database.');
|
||||
|
||||
// Verify that the node appears on the index.
|
||||
$this->drupalGet('forum/' . $tid);
|
||||
$this->assertText($title, 'Published forum topic appears on index.');
|
||||
|
||||
// Unpublish the node.
|
||||
$edit = array(
|
||||
'status' => FALSE,
|
||||
);
|
||||
$this->drupalPost("node/{$node->nid}/edit", $edit, t('Save'));
|
||||
$this->drupalGet("node/{$node->nid}");
|
||||
$this->assertText(t('Access denied'), 'Unpublished node is no longer accessible.');
|
||||
|
||||
// Verify that the node no longer appears on the index.
|
||||
$this->drupalGet('forum/' . $tid);
|
||||
$this->assertNoText($title, 'Unpublished forum topic no longer appears on index.');
|
||||
}
|
||||
}
|
24
modules/forum/forums.tpl.php
Normal file
24
modules/forum/forums.tpl.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Displays a forum.
|
||||
*
|
||||
* May contain forum containers as well as forum topics.
|
||||
*
|
||||
* Available variables:
|
||||
* - $forums: The forums to display (as processed by forum-list.tpl.php).
|
||||
* - $topics: The topics to display (as processed by forum-topic-list.tpl.php).
|
||||
* - $forums_defined: A flag to indicate that the forums are configured.
|
||||
*
|
||||
* @see template_preprocess_forums()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
?>
|
||||
<?php if ($forums_defined): ?>
|
||||
<div id="forum">
|
||||
<?php print $forums; ?>
|
||||
<?php print $topics; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
Loading…
Add table
Add a link
Reference in a new issue