source: sipes/cord/modules/forum/forum.admin.inc @ b354002

stableversion-3.0
Last change on this file since b354002 was b354002, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio del cord

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