function mysite_type_forum($get_options = TRUE) {
if (module_exists('forum')) {
$type = array(
'name' => t('Forums'),
'description' => t('<b>Forum Topics</b>: Forum posts within a specific topic.'),
'include' => 'forum',
'prefix' => t(''),
'suffix' => t('forum posts'),
'category' => t('Content'),
'weight' => 0,
'form' => FALSE,
'label' => t('Add Forum Topic'),
'help' => t('You can track posts within a forum. Type a keyword to search for matching forum topics, or select from the list provided.'),
'search' => TRUE
);
$basic_settings = variable_get('mysite_basic_forum_settings', array());
$type = array_merge($type, $basic_settings);
if ($get_options) {
$type['options'] = mysite_type_forum_options();
}
return $type;
}
}
function mysite_type_forum_active($type) {
$tree = taxonomy_get_tree(_forum_get_vid());
$value = TRUE;
$message = '';
$br = '';
if (empty($tree)) {
$value = FALSE;
$message = l('There are no no existing containers or forums.', 'admin/content/forum');
$br = '<br />';
}
$result = db_query("SELECT perm FROM {permission}");
$check = '';
while ($perms = db_fetch_object($result)) {
$check .= $perms->perm;
}
if (!stristr($check, 'create forum topics') && !stristr($check, 'edit own forum topics')) {
$value = FALSE;
$message .= $br . l(t('There are no users with create or edit forum permissions.'), 'admin/user/access');
}
return array($type => $value, 'message' => $message);
}
function mysite_type_forum_options() {
$options = array();
$forum = variable_get('forum_nav_vocabulary', 0);
$forums = taxonomy_get_tree($forum);
$key = '';
foreach ($forums as $term) {
if ($term->parents[0] == 0) {
$key = $term->name;
}
$depth = str_repeat('-', $term->depth) .' ';
$options['group'][] = $key;
$options['name'][] = mysite_type_forum_title($term->tid, $depth . $term->name);
$options['type_id'][] = $term->tid;
$options['type'][] = 'forum';
$options['icon'][] = mysite_get_icon('forum', $term->tid);
}
return $options;
}
function mysite_type_forum_title($type_id = NULL, $title = NULL) {
if (!empty($type_id)) {
if (is_null($title)) {
$forum = taxonomy_get_term($type_id);
$title = $forum->name;
}
$type = mysite_type_forum(FALSE);
$title = $type['prefix'] .' '. $title .' '. $type['suffix'];
$title = trim(rtrim($title));
return $title;
}
drupal_set_message(t('Could not find forum title'), 'error');
return;
}
function mysite_type_forum_data($type_id = NULL, $settings = NULL) {
if (!empty($type_id)) {
$forum = variable_get('forum_nav_vocabulary', 0);
$terms = taxonomy_get_tree($forum, $type_id);
$term_list = array($type_id);
foreach ($terms as $term) {
$term_list[] = $term->tid;
}
$implode = "(". implode(", ", $term_list) .")";
$sql = db_rewrite_sql("SELECT n.nid, n.changed, t.tid FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid WHERE n.status = 1 AND n.type = 'forum' AND t.tid IN %s ORDER BY n.changed DESC");
$result = db_query_range($sql, $implode, 0, variable_get('mysite_elements', 5));
$data = array(
'base' => 'forum/'. $type_id,
'xml' => 'forum/'. $type_id .'/feed'
);
$items = array();
$i = 0;
$type = mysite_type_forum(FALSE);
while ($nid = db_fetch_object($result)) {
$node = node_load($nid->nid);
$term = taxonomy_get_term($nid->tid);
$items[$i]['type'] = $node->type;
$items[$i]['link'] = l($node->title, 'node/'. $nid->nid, array('target' => $type['link_target']));
$items[$i]['title'] = check_plain($node->title);
if (count($term_list) > 1) {
$items[$i]['subtitle'] = l(mysite_type_forum_title($term->tid, $term->name), 'forum/'. $term->tid);
}
$items[$i]['date'] = $node->changed;
$items[$i]['uid'] = $node->uid;
$items[$i]['author'] = check_plain($node->name);
$items[$i]['teaser'] = mysite_teaser($node);
$items[$i]['nid'] = $node->nid;
$i++;
}
$data['items'] = $items;
return $data;
}
drupal_set_message(t('Could not find forum data'), 'error');
return;
}
function mysite_type_forum_block($arg, $op = 'view') {
global $user;
if (user_access('edit mysite') && $arg[0] == 'forum' && is_numeric($arg[1])) {
$forum = taxonomy_get_term($arg[1]);
$data = array();
$data['uid'] = $user->uid;
$data['type'] = 'forum';
$data['type_id'] = $forum->tid;
$content = mysite_block_handler($data);
return $content;
}
}
function mysite_type_forum_block_node($nid, $type) {
if ($type == 'forum') {
global $user;
$sql = db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t INNER JOIN {forum} f ON f.tid = t.tid WHERE f.nid = %d", 't', 'tid');
$forum = db_fetch_object(db_query($sql, $nid));
$data = array();
$data['uid'] = $user->uid;
$data['type'] = $type;
$data['type_id'] = $forum->tid;
$content = mysite_block_handler($data);
return $content;
}
}
function mysite_type_forum_search($uid = NULL) {
if (!is_null($uid)) {
$output .= drupal_get_form('mysite_type_forum_search_form', $uid);
return $output;
}
}
function mysite_type_forum_search_form($uid) {
$form['add_forum']['forum_title'] = array('#type' => 'textfield',
'#title' => t('Forum title'),
'#default_value' => $edit['forum_title'],
'#maxlength' => 64,
'#size' => 40,
'#description' => t('The name of the forum you wish to add.'),
'#required' => TRUE,
'#autocomplete_path' => 'autocomplete/mysite/forum'
);
$form['add_forum']['uid'] = array('#type' => 'hidden', '#value' => $uid);
$form['add_forum']['type'] = array('#type' => 'hidden', '#value' => 'forum');
$form['add_forum']['submit'] = array('#type' => 'submit', '#value' => t('Add Forum Topic'));
return $form;
}
function mysite_type_forum_search_form_submit($form_id, $form_values) {
$forum = variable_get('forum_nav_vocabulary', 0);
$sql = db_rewrite_sql("SELECT t.tid, t.name, t.description FROM {term_data} t WHERE LOWER(t.name) LIKE LOWER('%s%%') AND t.vid = %d", 't', 'tid');
$result = db_query($sql, $form_values['forum_title'], $forum);
$count = 0;
while ($forum = db_fetch_object($result)) {
$data[$count]['uid'] = $form_values['uid'];
$data[$count]['type'] = $form_values['type'];
$data[$count]['type_id'] = $forum->tid;
$data[$count]['title'] = mysite_type_forum_title($forum->tid, $forum->name);
$data[$count]['description'] = $forum->description;
$count++;
}
mysite_search_handler($data, 'forum');
return;
}
function mysite_type_forum_autocomplete($string) {
$matches = array();
$forum = variable_get('forum_nav_vocabulary', 0);
$sql = db_rewrite_sql("SELECT t.tid, t.name, t.description FROM {term_data} t WHERE LOWER(t.name) LIKE LOWER('%s%%') AND t.vid = %d", 't', 'tid');
$result = db_query_range($sql, $string, $forum, 0, 10);
while ($forum = db_fetch_object($result)) {
$matches[$forum->name] = check_plain($forum->name);
}
return $matches;
}
function mysite_type_forum_clear($type) {
$sql = "SELECT mid, uid, type_id, title FROM {mysite_data} WHERE type = '%s'";
$result = db_query($sql, $type);
$data = array();
while ($item = db_fetch_array($result)) {
$sql = "SELECT tid FROM {term_data} WHERE tid = %d";
$check = db_fetch_object(db_query($sql, $item['type_id']));
if (empty($check->tid)) {
$data[$item['mid']] = $item;
}
}
return $data;
}