* Enable threaded discussions about general topics.
*/
/**
* Implementation of hook_help().
*/
function forum_help($section) {
switch ($section) {
case 'admin/forum':
return t('<p>This is a list of existing containers and forums that you can edit. Containers hold forums and, in turn, forums hold threaded discussions. Both containers and forums can be placed inside other containers and forums. By planning the structure of your containers and forums well, you make it easier for users to find a topic area of interest to them.</p>');
case 'admin/forum/add/container':
return t('<p>Containers help you organize your forums. The job of a container is to hold, or contain, other forums that are related. For example, a container named "Food" might hold two forums named "Fruit" and "Vegetables". Containers are usually placed at the top (root) level of your forum but you can also place a container within another container or forum.</p>');
case 'admin/forum/add/forum':
return t('<p>A forum holds threaded topic discussions that are related. For example, a forum named "Fruit" might contain topic discussions titled "Apples" and "Bananas". You can place a forum into a container, another forum, or at the top (root) level of your forum.</p>');
case 'admin/modules#description':
return t('Enables threaded discussions about general topics.');
case 'admin/forum/configure':
return t('This is where you can configure system-wide options for how your forums act and display.');
case 'node/add#forum':
return t('A forum is a threaded discussion, enabling users to communicate about a particular topic.');
}
}
/**
* Implementation of hook_node_name().
*/
function forum_node_name($node) {
return t('forum topic');
}
/**
* Implementation of hook_access().
*/
function forum_access($op, $node) {
global $user;
if ($op == 'create') {
return user_access('create forum topics');
}
if ($op == 'update' || $op == 'delete') {
if (user_access('edit own forum topics') && ($user->uid == $node->uid)) {
return TRUE;
}
}
}
/**
* Implementation of hook_perm().
*/
function forum_perm() {
return array('create forum topics', 'edit own forum topics', 'administer forums');
}
/**
* Administration page which allows maintaining forums
$results = db_query('SELECT f.nid FROM {forum} f WHERE f.tid = %d', $object->tid);
while ($node = db_fetch_object($results)) {
$edit['nid'] = $node->nid;
$edit['confirm'] = TRUE;
node_delete($edit);
}
}
}
/**
* Returns a confirmation page for deleting a forum taxonomy term
*
* @param $tid ID of the term to be deleted
*/
function _forum_confirm_delete($tid) {
$term = taxonomy_get_term($tid);
$extra = form_hidden('tid', $tid);
$output = theme('confirm',
t('Are you sure you want to delete the forum %name?', array('%name' => '<em>'. $term->name .'</em>')),
'admin/forums',
t('Deleting a forum or container will delete all sub-forums as well. This action cannot be undone.'),
t('Delete'),
t('Cancel'),
$extra);
return $output;
}
/**
* Returns a form for adding a container to the forum vocabulary
*
* @param $edit Associative array containing a container term to be added or edited.
*/
function forum_form_container($edit = array()) {
$form = form_textfield(t('Container name'), 'name', $edit['name'], 50, 64, t('The container name is used on the forum listing page to identify a group of forums.'), NULL, TRUE);
$form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('The description can provide additional information about the forum grouping.'));
$form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier terms (with a larger weight) will sink and the lighter terms will be positioned nearer the top.'));
$form .= form_hidden('vid', _forum_get_vid());
$form .= form_submit(t('Submit'));
if ($edit['tid']) {
$form .= form_submit(t('Delete'));
$form .= form_hidden('tid', $edit['tid']);
}
return form($form);
}
/**
* Returns a form for adding a forum to the forum vocabulary
*
* @param $edit Associative array containing a forum term to be added or edited.
*/
function forum_form_forum($edit = array()) {
$form = form_textfield(t('Forum name'), 'name', $edit['name'], 50, 64, t('The name is used to identify the forum.'), NULL, TRUE);
$form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('The description can be used to provide more information about the forum, or further details about the topic.'));
$form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('In listings, the heavier (with a higher weight value) terms will sink and the lighter terms will be positioned nearer the top.'));
$form .= form_hidden('vid', _forum_get_vid());
$form .= form_submit(t('Submit'));
if ($edit['tid']) {
$form .= form_submit(t('Delete'));
$form .= form_hidden('tid', $edit['tid']);
}
return form($form);
}
/**
* Returns a select box for available parent terms
*
* @param $tid ID of the term which is being added or edited
* @param $title Title to display the select box with
* @param $name Name to use in the forum
*/
function _forum_parent_select($tid, $title, $name) {
$rows[] = array(array('data' => '<em>' . t('There are no existing containers or forums. You may add some on the <a href="%container">add container</a> or <a href="%forum">add forum</a> pages.', array('%container' => url('admin/forum/add/container'), '%forum' => url('admin/forum/add/forum'))) . '</em>', 'colspan' => 2));
}
return theme('table', $header, $rows);
}
/**
* Helper function used to generate indentation for forum list
*
* @param $depth Depth of the indentation
* @param $graphic HTML text to be repeated for each stage of depth
*/
function _forum_depth($depth, $graphic = '--') {
for ($n = 0; $n < $depth; $n++) {
$result .= $graphic;
}
return $result;
}
/**
* Returns the vocabulary id for forum navigation.
*/
function _forum_get_vid() {
$vid = variable_get('forum_nav_vocabulary', '');
if (empty($vid)) {
// Check to see if a forum vocabulary exists
$vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module='%s'", 'forum'));
$output .= form_textfield(t('Forum icon path'), 'forum_icon_path', variable_get('forum_icon_path', ''), 30, 255, t('The path to the forum icons. Leave blank to disable icons. Don\'t add a trailing slash. Default icons are available in the "misc" directory. You may use images of whatever size you wish, but it is recommended to use 15x15 or 16x16. '));
$output .= form_select(t('Hot topic threshold'), 'forum_hot_topic', variable_get('forum_hot_topic', 15), $number, t('The number of posts a topic must have to be considered hot.'));
$output .= form_select(t('Topics per page'), 'forum_per_page', variable_get('forum_per_page', 25), $number, t('The default number of topics displayed per page; links to browse older messages are automatically being displayed.'));
$forder = array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4=> t('Posts - least active first'));
$output .= form_radios(t('Default order'), 'forum_order', variable_get('forum_order', '1'), $forder, t('The default display order for topics.'));
$sql = db_rewrite_sql("SELECT n.nid, n.title, l.last_comment_timestamp, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND n.type='forum' ORDER BY l.last_comment_timestamp DESC");
$sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.type = 'forum' AND n.status = 1 ORDER BY n.nid DESC");
$sql = "SELECT n.nid, n.title, n.sticky, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type = 'forum' ORDER BY n.sticky DESC, ". _forum_get_topic_order_sql(variable_get('forum_order', 1));
$sql = db_rewrite_sql($sql);
$result = db_query($sql, $node->tid);
while ($topic = db_fetch_object($result)) {
if ($stop == 1) {
$next = new StdClass();
$next->nid = $topic->nid;
$next->title = $topic->title;
break;
}
if ($topic->nid == $node->nid) {
$stop = 1;
}
else {
$prev = new StdClass();
$prev->nid = $topic->nid;
$prev->title = $topic->title;
}
}
if ($prev) {
$links[] = l(t('previous forum topic'), "node/$prev->nid", array('title' => check_plain($prev->title)));
}
if ($next) {
$links[] = l(t('next forum topic'), "node/$next->nid", array('title' => check_plain($next->title)));
if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vocabulary))) {
if (in_array($term, $containers)) {
$term = taxonomy_get_term($term);
form_set_error('taxonomy', t('The item %forum is only a container for forums. Please select one of the forums below it.', array('%forum' => theme('placeholder', $term->name))));
$output .= form_checkbox(t('Leave shadow copy'), 'shadow', 1, $shadow, t('If you move this topic, you can leave a link in the old forum to the new forum.'));
$sql = "SELECT r.tid, COUNT(n.nid) AS topic_count, SUM(l.comment_count) AS comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.status = 1 AND n.type = 'forum' GROUP BY r.tid";
$sql = db_rewrite_sql($sql);
$_counts = db_query($sql, $forum->tid);
while ($count = db_fetch_object($_counts)) {
$counts[$count->tid] = $count;
}
}
foreach ($_forums as $forum) {
if (in_array($forum->tid, variable_get('forum_containers', array()))) {
// This query does not use full ANSI syntax since MySQL 3.x does not support
// table1 INNER JOIN table2 INNER JOIN table3 ON table2_criteria ON table3_criteria
// used to join node_comment_statistics to users.
$sql = "SELECT n.nid, l.last_comment_timestamp, IF(l.last_comment_uid, cu.name, l.last_comment_name) as last_comment_name, l.last_comment_uid FROM {node} n, {node_comment_statistics} l /*! USE INDEX (node_comment_timestamp) */, {users} cu, {term_node} r WHERE n.nid = r.nid AND r.tid = %d AND n.status = 1 AND n.type = 'forum' AND l.last_comment_uid = cu.uid AND n.nid = l.nid ORDER BY l.last_comment_timestamp DESC";
// Calculate the number of topics the user has read. Assume all entries older
// than NODE_NEW_LIMIT are read, and include the recent posts that user has
// read.
$sql = "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.created <= %d AND n.status = 1 AND n.type = 'forum'";
$sql = "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {history} h ON n.nid = h.nid AND h.uid = %d INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type = 'forum' AND n.created > %d";
$sql = db_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node} n, {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = %d AND n.uid = u.uid AND n.nid = f.nid");
$sql_count = db_rewrite_sql("SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type = 'forum'");
$sql = "SELECT n.nid FROM {node} n LEFT JOIN {history} h ON n.nid = h.nid AND h.uid = %d INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type = 'forum' AND h.nid IS NULL AND n.created > %d ORDER BY created";