forum.admin.inc

Administrative page callbacks for the forum module.

Archivo

drupal-6.x/modules/forum/forum.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Administrative page callbacks for the forum module.
  5. */
  6. function forum_form_main($type, $edit = array()) {
  7. if ((isset($_POST['op']) && $_POST['op'] == t('Delete')) || !empty($_POST['confirm'])) {
  8. return drupal_get_form('forum_confirm_delete', $edit['tid']);
  9. }
  10. switch ($type) {
  11. case 'forum':
  12. return drupal_get_form('forum_form_forum', $edit);
  13. break;
  14. case 'container':
  15. return drupal_get_form('forum_form_container', $edit);
  16. break;
  17. }
  18. }
  19. /**
  20. * Returns a form for adding a forum to the forum vocabulary
  21. *
  22. * @param $edit Associative array containing a forum term to be added or edited.
  23. * @ingroup forms
  24. * @see forum_form_submit()
  25. */
  26. function forum_form_forum(&$form_state, $edit = array()) {
  27. $edit += array(
  28. 'name' => '',
  29. 'description' => '',
  30. 'tid' => NULL,
  31. 'weight' => 0,
  32. );
  33. $form['name'] = array('#type' => 'textfield',
  34. '#title' => t('Forum name'),
  35. '#default_value' => $edit['name'],
  36. '#maxlength' => 255,
  37. '#description' => t('Short but meaningful name for this collection of threaded discussions.'),
  38. '#required' => TRUE,
  39. );
  40. $form['description'] = array('#type' => 'textarea',
  41. '#title' => t('Description'),
  42. '#default_value' => $edit['description'],
  43. '#description' => t('Description and guidelines for discussions within this forum.'),
  44. );
  45. $form['parent']['#tree'] = TRUE;
  46. $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'forum');
  47. $form['weight'] = array('#type' => 'weight',
  48. '#title' => t('Weight'),
  49. '#default_value' => $edit['weight'],
  50. '#description' => t('Forums are displayed in ascending order by weight (forums with equal weights are displayed alphabetically).'),
  51. );
  52. $form['vid'] = array('#type' => 'hidden', '#value' => variable_get('forum_nav_vocabulary', ''));
  53. $form['submit' ] = array('#type' => 'submit', '#value' => t('Save'));
  54. if ($edit['tid']) {
  55. $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
  56. $form['tid'] = array('#type' => 'hidden', '#value' => $edit['tid']);
  57. }
  58. $form['#submit'][] = 'forum_form_submit';
  59. $form['#theme'] = 'forum_form';
  60. return $form;
  61. }
  62. /**
  63. * Process forum form and container form submissions.
  64. */
  65. function forum_form_submit($form, &$form_state) {
  66. if ($form['form_id']['#value'] == 'forum_form_container') {
  67. $container = TRUE;
  68. $type = t('forum container');
  69. }
  70. else {
  71. $container = FALSE;
  72. $type = t('forum');
  73. }
  74. $status = taxonomy_save_term($form_state['values']);
  75. switch ($status) {
  76. case SAVED_NEW:
  77. if ($container) {
  78. $containers = variable_get('forum_containers', array());
  79. $containers[] = $form_state['values']['tid'];
  80. variable_set('forum_containers', $containers);
  81. }
  82. drupal_set_message(t('Created new @type %term.', array('%term' => $form_state['values']['name'], '@type' => $type)));
  83. break;
  84. case SAVED_UPDATED:
  85. drupal_set_message(t('The @type %term has been updated.', array('%term' => $form_state['values']['name'], '@type' => $type)));
  86. break;
  87. }
  88. $form_state['redirect'] = 'admin/content/forum';
  89. return;
  90. }
  91. /**
  92. * Returns a form for adding a container to the forum vocabulary
  93. *
  94. * @param $edit Associative array containing a container term to be added or edited.
  95. * @ingroup forms
  96. * @see forum_form_submit()
  97. */
  98. function forum_form_container(&$form_state, $edit = array()) {
  99. $edit += array(
  100. 'name' => '',
  101. 'description' => '',
  102. 'tid' => NULL,
  103. 'weight' => 0,
  104. );
  105. // Handle a delete operation.
  106. $form['name'] = array(
  107. '#title' => t('Container name'),
  108. '#type' => 'textfield',
  109. '#default_value' => $edit['name'],
  110. '#maxlength' => 255,
  111. '#description' => t('Short but meaningful name for this collection of related forums.'),
  112. '#required' => TRUE
  113. );
  114. $form['description'] = array(
  115. '#type' => 'textarea',
  116. '#title' => t('Description'),
  117. '#default_value' => $edit['description'],
  118. '#description' => t('Description and guidelines for forums within this container.')
  119. );
  120. $form['parent']['#tree'] = TRUE;
  121. $form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'container');
  122. $form['weight'] = array(
  123. '#type' => 'weight',
  124. '#title' => t('Weight'),
  125. '#default_value' => $edit['weight'],
  126. '#description' => t('Containers are displayed in ascending order by weight (containers with equal weights are displayed alphabetically).')
  127. );
  128. $form['vid'] = array(
  129. '#type' => 'hidden',
  130. '#value' => variable_get('forum_nav_vocabulary', ''),
  131. );
  132. $form['submit'] = array(
  133. '#type' => 'submit',
  134. '#value' => t('Save')
  135. );
  136. if ($edit['tid']) {
  137. $form['delete'] = array('#type' => 'submit', '#value' => t('Delete'));
  138. $form['tid'] = array('#type' => 'value', '#value' => $edit['tid']);
  139. }
  140. $form['#submit'][] = 'forum_form_submit';
  141. $form['#theme'] = 'forum_form';
  142. return $form;
  143. }
  144. /**
  145. * Returns a confirmation page for deleting a forum taxonomy term.
  146. *
  147. * @param $tid ID of the term to be deleted
  148. */
  149. function forum_confirm_delete(&$form_state, $tid) {
  150. $term = taxonomy_get_term($tid);
  151. $form['tid'] = array('#type' => 'value', '#value' => $tid);
  152. $form['name'] = array('#type' => 'value', '#value' => $term->name);
  153. return confirm_form($form, t('Are you sure you want to delete the forum %name?', array('%name' => $term->name)), 'admin/content/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'));
  154. }
  155. /**
  156. * Implementation of forms api _submit call. Deletes a forum after confirmation.
  157. */
  158. function forum_confirm_delete_submit($form, &$form_state) {
  159. taxonomy_del_term($form_state['values']['tid']);
  160. drupal_set_message(t('The forum %term and all sub-forums and associated posts have been deleted.', array('%term' => $form_state['values']['name'])));
  161. watchdog('content', 'forum: deleted %term and all its sub-forums and associated posts.', array('%term' => $form_state['values']['name']));
  162. $form_state['redirect'] = 'admin/content/forum';
  163. return;
  164. }
  165. /**
  166. * Form builder for the forum settings page.
  167. *
  168. * @see system_settings_form()
  169. */
  170. function forum_admin_settings() {
  171. $form = array();
  172. $number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500));
  173. $form['forum_hot_topic'] = array('#type' => 'select',
  174. '#title' => t('Hot topic threshold'),
  175. '#default_value' => variable_get('forum_hot_topic', 15),
  176. '#options' => $number,
  177. '#description' => t('The number of posts a topic must have to be considered "hot".'),
  178. );
  179. $number = drupal_map_assoc(array(10, 25, 50, 75, 100));
  180. $form['forum_per_page'] = array('#type' => 'select',
  181. '#title' => t('Topics per page'),
  182. '#default_value' => variable_get('forum_per_page', 25),
  183. '#options' => $number,
  184. '#description' => t('Default number of forum topics displayed per page.'),
  185. );
  186. $forder = array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4 => t('Posts - least active first'));
  187. $form['forum_order'] = array('#type' => 'radios',
  188. '#title' => t('Default order'),
  189. '#default_value' => variable_get('forum_order', '1'),
  190. '#options' => $forder,
  191. '#description' => t('Default display order for topics.'),
  192. );
  193. return system_settings_form($form);
  194. }
  195. /**
  196. * Returns an overview list of existing forums and containers
  197. */
  198. function forum_overview(&$form_state) {
  199. module_load_include('inc', 'taxonomy', 'taxonomy.admin');
  200. $vid = variable_get('forum_nav_vocabulary', '');
  201. $vocabulary = taxonomy_vocabulary_load($vid);
  202. $form = taxonomy_overview_terms($form_state, $vocabulary);
  203. foreach (element_children($form) as $key) {
  204. if (isset($form[$key]['#term'])) {
  205. $term = $form[$key]['#term'];
  206. $form[$key]['view']['#value'] = l($term['name'], 'forum/'. $term['tid']);
  207. if (in_array($form[$key]['#term']['tid'], variable_get('forum_containers', array()))) {
  208. $form[$key]['edit']['#value'] = l(t('edit container'), 'admin/content/forum/edit/container/'. $term['tid']);
  209. }
  210. else {
  211. $form[$key]['edit']['#value'] = l(t('edit forum'), 'admin/content/forum/edit/forum/'. $term['tid']);
  212. }
  213. }
  214. }
  215. // Remove the alphabetical reset.
  216. unset($form['reset_alphabetical']);
  217. // The form needs to have submit and validate handlers set explicitly.
  218. $form['#theme'] = 'taxonomy_overview_terms';
  219. $form['#submit'] = array('taxonomy_overview_terms_submit'); // Use the existing taxonomy overview submit handler.
  220. $form['#validate'] = array('taxonomy_overview_terms_validate');
  221. $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/content/forum/add/container'), '@forum' => url('admin/content/forum/add/forum'))) .'</em>';
  222. return $form;
  223. }
  224. /**
  225. * Returns a select box for available parent terms
  226. *
  227. * @param $tid ID of the term which is being added or edited
  228. * @param $title Title to display the select box with
  229. * @param $child_type Whether the child is forum or container
  230. */
  231. function _forum_parent_select($tid, $title, $child_type) {
  232. $parents = taxonomy_get_parents($tid);
  233. if ($parents) {
  234. $parent = array_shift($parents);
  235. $parent = $parent->tid;
  236. }
  237. else {
  238. $parent = 0;
  239. }
  240. $vid = variable_get('forum_nav_vocabulary', '');
  241. $children = taxonomy_get_tree($vid, $tid);
  242. // A term can't be the child of itself, nor of its children.
  243. foreach ($children as $child) {
  244. $exclude[] = $child->tid;
  245. }
  246. $exclude[] = $tid;
  247. $tree = taxonomy_get_tree($vid);
  248. $options[0] = '<'. t('root') .'>';
  249. if ($tree) {
  250. foreach ($tree as $term) {
  251. if (!in_array($term->tid, $exclude)) {
  252. $options[$term->tid] = str_repeat(' -- ', $term->depth) . $term->name;
  253. }
  254. }
  255. }
  256. if ($child_type == 'container') {
  257. $description = t('Containers are usually placed at the top (root) level, but may also be placed inside another container or forum.');
  258. }
  259. else if ($child_type == 'forum') {
  260. $description = t('Forums may be placed at the top (root) level, or inside another container or forum.');
  261. }
  262. return array('#type' => 'select', '#title' => $title, '#default_value' => $parent, '#options' => $options, '#description' => $description, '#required' => TRUE);
  263. }

Functions

Nombreorden descendente Descripción
forum_admin_settings Form builder for the forum settings page.
forum_confirm_delete Returns a confirmation page for deleting a forum taxonomy term.
forum_confirm_delete_submit Implementation of forms api _submit call. Deletes a forum after confirmation.
forum_form_container Returns a form for adding a container to the forum vocabulary
forum_form_forum Returns a form for adding a forum to the forum vocabulary
forum_form_main
forum_form_submit Process forum form and container form submissions.
forum_overview Returns an overview list of existing forums and containers
_forum_parent_select Returns a select box for available parent terms