00001 <?php
00002
00003
00009 function forum_form_main($type, $edit = array()) {
00010 if ((isset($_POST['op']) && $_POST['op'] == t('Delete')) || !empty($_POST['confirm'])) {
00011 return drupal_get_form('forum_confirm_delete', $edit['tid']);
00012 }
00013 switch ($type) {
00014 case 'forum':
00015 return drupal_get_form('forum_form_forum', $edit);
00016 break;
00017 case 'container':
00018 return drupal_get_form('forum_form_container', $edit);
00019 break;
00020 }
00021 }
00022
00030 function forum_form_forum(&$form_state, $edit = array()) {
00031 $edit += array(
00032 'name' => '',
00033 'description' => '',
00034 'tid' => NULL,
00035 'weight' => 0,
00036 );
00037 $form['name'] = array('#type' => 'textfield',
00038 '#title' => t('Forum name'),
00039 '#default_value' => $edit['name'],
00040 '#maxlength' => 255,
00041 '#description' => t('Short but meaningful name for this collection of threaded discussions.'),
00042 '#required' => TRUE,
00043 );
00044 $form['description'] = array('#type' => 'textarea',
00045 '#title' => t('Description'),
00046 '#default_value' => $edit['description'],
00047 '#description' => t('Description and guidelines for discussions within this forum.'),
00048 );
00049 $form['parent']['#tree'] = TRUE;
00050 $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'forum');
00051 $form['weight'] = array('#type' => 'weight',
00052 '#title' => t('Weight'),
00053 '#default_value' => $edit['weight'],
00054 '#description' => t('Forums are displayed in ascending order by weight (forums with equal weights are displayed alphabetically).'),
00055 );
00056
00057 $form['vid'] = array('#type' => 'hidden', '#value' => variable_get('forum_nav_vocabulary', ''));
00058 $form['submit' ] = array('#type' => 'submit', '#value' => t('Save'));
00059 if ($edit['tid']) {
00060 $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
00061 $form['tid'] = array('#type' => 'hidden', '#value' => $edit['tid']);
00062 }
00063 $form['#submit'][] = 'forum_form_submit';
00064 $form['#theme'] = 'forum_form';
00065
00066 return $form;
00067 }
00068
00072 function forum_form_submit($form, &$form_state) {
00073 if ($form['form_id']['#value'] == 'forum_form_container') {
00074 $container = TRUE;
00075 $type = t('forum container');
00076 }
00077 else {
00078 $container = FALSE;
00079 $type = t('forum');
00080 }
00081
00082 $status = taxonomy_save_term($form_state['values']);
00083 switch ($status) {
00084 case SAVED_NEW:
00085 if ($container) {
00086 $containers = variable_get('forum_containers', array());
00087 $containers[] = $form_state['values']['tid'];
00088 variable_set('forum_containers', $containers);
00089 }
00090 drupal_set_message(t('Created new @type %term.', array('%term' => $form_state['values']['name'], '@type' => $type)));
00091 break;
00092 case SAVED_UPDATED:
00093 drupal_set_message(t('The @type %term has been updated.', array('%term' => $form_state['values']['name'], '@type' => $type)));
00094 break;
00095 }
00096 $form_state['redirect'] = 'admin/build/forum';
00097 return;
00098 }
00099
00107 function forum_form_container(&$form_state, $edit = array()) {
00108 $edit += array(
00109 'name' => '',
00110 'description' => '',
00111 'tid' => NULL,
00112 'weight' => 0,
00113 );
00114
00115 $form['name'] = array(
00116 '#title' => t('Container name'),
00117 '#type' => 'textfield',
00118 '#default_value' => $edit['name'],
00119 '#maxlength' => 255,
00120 '#description' => t('Short but meaningful name for this collection of related forums.'),
00121 '#required' => TRUE
00122 );
00123
00124 $form['description'] = array(
00125 '#type' => 'textarea',
00126 '#title' => t('Description'),
00127 '#default_value' => $edit['description'],
00128 '#description' => t('Description and guidelines for forums within this container.')
00129 );
00130 $form['parent']['#tree'] = TRUE;
00131 $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'container');
00132 $form['weight'] = array(
00133 '#type' => 'weight',
00134 '#title' => t('Weight'),
00135 '#default_value' => $edit['weight'],
00136 '#description' => t('Containers are displayed in ascending order by weight (containers with equal weights are displayed alphabetically).')
00137 );
00138
00139 $form['vid'] = array(
00140 '#type' => 'hidden',
00141 '#value' => variable_get('forum_nav_vocabulary', ''),
00142 );
00143 $form['submit'] = array(
00144 '#type' => 'submit',
00145 '#value' => t('Save')
00146 );
00147 if ($edit['tid']) {
00148 $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
00149 $form['tid'] = array('#type' => 'value', '#value' => $edit['tid']);
00150 }
00151 $form['#submit'][] = 'forum_form_submit';
00152 $form['#theme'] = 'forum_form';
00153
00154 return $form;
00155 }
00156
00162 function forum_confirm_delete(&$form_state, $tid) {
00163 $term = taxonomy_get_term($tid);
00164
00165 $form['tid'] = array('#type' => 'value', '#value' => $tid);
00166 $form['name'] = array('#type' => 'value', '#value' => $term->name);
00167
00168 return confirm_form($form, t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/build/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/node'))), t('Delete'), t('Cancel'));
00169 }
00170
00174 function forum_confirm_delete_submit($form, &$form_state) {
00175 taxonomy_del_term($form_state['values']['tid']);
00176 drupal_set_message(t('The forum %term and all sub-forums have been deleted.', array('%term' => $form_state['values']['name'])));
00177 watchdog('content', 'forum: deleted %term and all its sub-forums.', array('%term' => $form_state['values']['name']));
00178
00179 $form_state['redirect'] = 'admin/build/forum';
00180 return;
00181 }
00182
00188 function forum_admin_settings() {
00189 $form = array();
00190 $number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500));
00191 $form['forum_hot_topic'] = array('#type' => 'select',
00192 '#title' => t('Hot topic threshold'),
00193 '#default_value' => variable_get('forum_hot_topic', 15),
00194 '#options' => $number,
00195 '#description' => t('The number of posts a topic must have to be considered "hot".'),
00196 );
00197 $number = drupal_map_assoc(array(10, 25, 50, 75, 100));
00198 $form['forum_per_page'] = array('#type' => 'select',
00199 '#title' => t('Topics per page'),
00200 '#default_value' => variable_get('forum_per_page', 25),
00201 '#options' => $number,
00202 '#description' => t('Default number of forum topics displayed per page.'),
00203 );
00204 $forder = array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4 => t('Posts - least active first'));
00205 $form['forum_order'] = array('#type' => 'radios',
00206 '#title' => t('Default order'),
00207 '#default_value' => variable_get('forum_order', '1'),
00208 '#options' => $forder,
00209 '#description' => t('Default display order for topics.'),
00210 );
00211 return system_settings_form($form);
00212 }
00213
00217 function forum_overview(&$form_state) {
00218 module_load_include('inc', 'taxonomy', 'taxonomy.admin');
00219
00220 $vid = variable_get('forum_nav_vocabulary', '');
00221 $vocabulary = taxonomy_vocabulary_load($vid);
00222 $form = taxonomy_overview_terms($form_state, $vocabulary);
00223 drupal_set_title('Forums');
00224
00225 foreach (element_children($form) as $key) {
00226 if (isset($form[$key]['#term'])) {
00227 $term = $form[$key]['#term'];
00228 $form[$key]['view']['#value'] = l($term['name'], 'forum/' . $term['tid']);
00229 if (in_array($form[$key]['#term']['tid'], variable_get('forum_containers', array()))) {
00230 $form[$key]['edit']['#value'] = l(t('edit container'), 'admin/build/forum/edit/container/' . $term['tid']);
00231 }
00232 else {
00233 $form[$key]['edit']['#value'] = l(t('edit forum'), 'admin/build/forum/edit/forum/' . $term['tid']);
00234 }
00235 }
00236 }
00237
00238
00239 unset($form['reset_alphabetical']);
00240
00241
00242 $form['#theme'] = 'taxonomy_overview_terms';
00243 $form['#submit'] = array('taxonomy_overview_terms_submit');
00244 $form['#validate'] = array('taxonomy_overview_terms_validate');
00245 $form['#empty_text'] = '<em>' . t('There are no existing containers or forums. Containers and forums may be added using the <a href="@container">add container</a> and <a href="@forum">add forum</a> pages.', array('@container' => url('admin/build/forum/add/container'), '@forum' => url('admin/build/forum/add/forum'))) . '</em>';
00246 return $form;
00247 }
00248
00256 function _forum_parent_select($tid, $title, $child_type) {
00257
00258 $parents = taxonomy_get_parents($tid);
00259 if ($parents) {
00260 $parent = array_shift($parents);
00261 $parent = $parent->tid;
00262 }
00263 else {
00264 $parent = 0;
00265 }
00266
00267 $vid = variable_get('forum_nav_vocabulary', '');
00268 $children = taxonomy_get_tree($vid, $tid);
00269
00270
00271 foreach ($children as $child) {
00272 $exclude[] = $child->tid;
00273 }
00274 $exclude[] = $tid;
00275
00276 $tree = taxonomy_get_tree($vid);
00277 $options[0] = '<' . t('root') . '>';
00278 if ($tree) {
00279 foreach ($tree as $term) {
00280 if (!in_array($term->tid, $exclude)) {
00281 $options[$term->tid] = str_repeat(' -- ', $term->depth) . $term->name;
00282 }
00283 }
00284 }
00285 if ($child_type == 'container') {
00286 $description = t('Containers are usually placed at the top (root) level, but may also be placed inside another container or forum.');
00287 }
00288 else if ($child_type == 'forum') {
00289 $description = t('Forums may be placed at the top (root) level, or inside another container or forum.');
00290 }
00291
00292 return array('#type' => 'select', '#title' => $title, '#default_value' => $parent, '#options' => $options, '#description' => $description, '#required' => TRUE);
00293 }