/[drupal]/contributions/modules/reptag/reptag_admin.inc
ViewVC logotype

Contents of /contributions/modules/reptag/reptag_admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.16 - (show annotations) (download) (as text)
Wed Jun 4 12:21:06 2008 UTC (17 months, 3 weeks ago) by profix898
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.15: +479 -632 lines
File MIME type: text/x-php
- task: initial version for Drupal 6
1 <?php
2 // $Id: reptag_admin.inc,v 1.12.2.21 2007/07/25 16:14:31 profix898 Exp $
3
4 require_once(drupal_get_path('module', 'reptag') .'/reptag_admin_table.inc');
5
6 /**
7 * Function _reptag_admin_general_form().
8 * (administration pages: general settings)
9 */
10 function _reptag_admin_general_form() {
11 $form['general'] = array(
12 '#type' => 'fieldset',
13 '#title' => t('General - Settings'),
14 '#collapsible' => FALSE,
15 '#collapsed' => FALSE
16 );
17 $form['general']['reptag_preview'] = array(
18 '#type' => 'checkbox',
19 '#title' => t('Enable Rep[lacement]Tags in Preview'),
20 '#default_value' => variable_get('reptag_preview', 1),
21 '#description' => t('Run replacement process for tags on node previews.')
22 );
23 $form['general']['reptag_showhelp'] = array(
24 '#type' => 'checkbox',
25 '#title' => t('Show \'Rep[lacement]Tags - Help\' section on add/edit node pages'),
26 '#default_value' => variable_get('reptag_showhelp', 1),
27 '#description' => t('Display a collapsible fieldset containing all available tags on node forms.')
28 );
29 $form['general']['reptag_tableprio'] = array(
30 '#type' => 'checkbox',
31 '#title' => t('Privilege SiteWide tags over User tags'),
32 '#default_value' => variable_get('reptag_tableprio', 0),
33 '#description' => t('By default users can override site wide tags with their own tags.')
34 );
35
36 // Cache settings
37 $form['general']['cache'] = array(
38 '#type' => 'fieldset',
39 '#title' => t('Cache - Settings'),
40 '#collapsible' => TRUE,
41 '#collapsed' => TRUE,
42 '#weight' => '2'
43 );
44 $form['general']['cache']['reptag_cache'] = array(
45 '#type' => 'checkbox',
46 '#title' => t('Enable Partial PageCache'),
47 '#default_value' => variable_get('reptag_cache', 0),
48 '#description' => t('<i>(recommended at least for high traffic sites)</i><br />
49 Expand static tags on form submission and cache the result. Only dynamic tags are processed on page view.<br />
50 To disable dynamic tags completely check \'Disable Dynamic Replacements\' below.')
51 );
52 $period = drupal_map_assoc(array(CACHE_TEMPORARY, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400, CACHE_PERMANENT), 'format_interval');
53 $period[CACHE_TEMPORARY] = t('none');
54 $period[CACHE_PERMANENT] = t('permanent');
55 $form['general']['cache']['reptag_cache_lifetime'] = array(
56 '#type' => 'select',
57 '#title' => t('Minimum cache lifetime'),
58 '#default_value' => variable_get('reptag_cache_lifetime', CACHE_PERMANENT),
59 '#options' => $period,
60 '#description' => t('Set the minimum cache lifetime before the cache expires.'),
61 '#disabled' => !variable_get('reptag_cache', 0)
62 );
63 $form['general']['cache']['reptag_staticonly'] = array(
64 '#type' => 'checkbox',
65 '#title' => t('Disable Dynamic Replacements'),
66 '#default_value' => variable_get('reptag_staticonly', 0),
67 '#description' => t('Run reptag on form submission only (disables certain modules, e.g. System, Block, ...).<br />
68 Modules affected by this option are marked \'Static\' = \'No\'.'),
69 '#disabled' => !variable_get('reptag_cache', 0)
70 );
71 $form['general']['cache']['reptag_cache_clear_btn'] = array(
72 '#type' => 'submit',
73 '#value' => t('Clear cache'),
74 '#disabled' => !variable_get('reptag_cache', 0),
75 '#submit' => array('_reptag_admin_cache_clear')
76 );
77 // Expert - settings
78 $form['general']['expert'] = array(
79 '#type' => 'fieldset',
80 '#title' => t('Expert - Settings'),
81 '#collapsible' => TRUE,
82 '#collapsed' => TRUE,
83 '#weight' => '3'
84 );
85 $form['general']['expert']['reptag_disabled_nids'] = array(
86 '#type' => 'textfield',
87 '#title' => t('Disable RepTag for certain nodes'),
88 '#default_value' => implode(', ', unserialize(variable_get('reptag_disabled_nids', serialize(array())))),
89 '#size' => 75,
90 '#maxlength' => 255,
91 '#description' => t('Enter a list of comma-separated nids to disable RepTag for these nodes.')
92 );
93 if (module_exists('comment')) {
94 $form['general']['expert']['reptag_enable_comments'] = array(
95 '#type' => 'checkbox',
96 '#title' => t('Enable RepTag-Support for comments.'),
97 '#default_value' => variable_get('reptag_enable_comments', 0),
98 '#description' => t('Check this option to allow replacement tags (static tags only) for comments.')
99 );
100 }
101 $form['general']['expert']['reptag_enable_title'] = array(
102 '#type' => 'checkbox',
103 '#title' => t('Enable RepTag to process node titles'),
104 '#default_value' => variable_get('reptag_enable_title', 0),
105 '#description' => t('<i>(Node title support is not available for full page rendered nodes!)</i><br />
106 With this option enabled you can select node titles for processing under
107 <a href="!content-types-settings">Content Types</a>.',
108 array('!content-types-settings' => url('admin/settings/reptag/admin/content')))
109 );
110 $form['general']['expert']['reptag_debug'] = array(
111 '#type' => 'checkbox',
112 '#title' => t('Enable Debugging'),
113 '#default_value' => variable_get('reptag_debug', 0),
114 '#description' => t('Print debug listings (print_r) of module variables.')
115 );
116 // User Interface
117 $form['general']['ui'] = array(
118 '#type' => 'fieldset',
119 '#title' => t('UserInterface - Settings'),
120 '#collapsible' => TRUE,
121 '#collapsed' => TRUE,
122 '#weight' => '4'
123 );
124 $form['general']['ui']['reptag_javascript'] = array(
125 '#type' => 'checkbox',
126 '#title' => t('Enable Javascript/AJAX - Support'),
127 '#default_value' => variable_get('reptag_javascript', 1),
128 '#description' => t('Enable Javascript/AJAX - Support for administration pages.')
129 );
130 $form['general']['ui']['reptag_textarea'] = array(
131 '#type' => 'checkbox',
132 '#title' => t('Use textareas for replacements'),
133 '#default_value' => variable_get('reptag_textarea', 1),
134 '#description' => t('Use resizable textareas instead of textfields for replacements in tags table.')
135 );
136 // Locale
137 if (module_exists('locale')) {
138 $form['general']['locale'] = array(
139 '#type' => 'fieldset',
140 '#title' => t('Language - Settings'),
141 '#collapsible' => TRUE,
142 '#collapsed' => TRUE,
143 '#weight' => '5'
144 );
145 $form['general']['locale']['reptag_locale_enable'] = array(
146 '#type' => 'checkbox',
147 '#title' => t('Enable multi-lingual tags'),
148 '#default_value' => variable_get('reptag_locale_enable', 0),
149 '#description' => t('Allows you to have different sitewide-/user-tags for your languages.'),
150 '#disabled' => (variable_get('language_count', 1) < 2)
151 );
152 $form['general']['locale']['reptag_locale_binding'] = array(
153 '#type' => 'checkbox',
154 '#title' => t('Bind language to content'),
155 '#default_value' => variable_get('reptag_locale_binding', 0),
156 '#description' => t('Requires \'translation\' module to be enabled. By default the negotiated site or user language
157 is used for replacements. With this option the language of the current node is used instead.'),
158 '#disabled' => !module_exists('translation')
159 );
160 $form['general']['locale']['reptag_locale_mode'] = array(
161 '#type' => 'select',
162 '#title' => t('Language mode'),
163 '#default_value' => variable_get('reptag_locale_mode', REPTAG_LOCALE_STRICT),
164 '#options' => array(
165 REPTAG_LOCALE_STRICT => t('Strict (active language only)'),
166 REPTAG_LOCALE_FALLBACK => t('Fallback (active+default language)')
167 ),
168 '#description' => t('Select \'Fallback\' if you want the tags of the default language to be always available.
169 Otherwise tags that do not exist in the active language remain unaffected.')
170 );
171 }
172 // Integration
173 $form['general']['integration'] = array(
174 '#type' => 'fieldset',
175 '#title' => t('Integration - Settings'),
176 '#collapsible' => TRUE,
177 '#collapsed' => TRUE,
178 '#weight' => '6'
179 );
180 $form['general']['integration']['reptag_workspace'] = array(
181 '#type' => 'checkbox',
182 '#title' => t('Enable Workspace - Integration'),
183 '#default_value' => variable_get('reptag_workspace', 0),
184 '#description' => t('Adds a tab to the user\'s workspace. Available only with \'Workspace\' module installed.'),
185 '#disabled' => !module_exists('workspace')
186 );
187
188 return _reptag_admin_form($form, '_reptag_admin_general');
189 }
190
191 /**
192 * Function _reptag_admin_clear_cache().
193 */
194 function _reptag_admin_cache_clear($form, &$form_state) {
195 _reptag_cache_clear();
196 }
197
198 /**
199 * Function _reptag_admin_general_save().
200 */
201 function _reptag_admin_general_save($form, &$form_state) {
202 // General
203 variable_set('reptag_preview', $form_state['values']['reptag_preview']);
204 variable_set('reptag_showhelp', $form_state['values']['reptag_showhelp']);
205 variable_set('reptag_tableprio', $form_state['values']['reptag_tableprio']);
206 // Cache
207 variable_set('reptag_cache', $form_state['values']['reptag_cache']);
208 variable_set('reptag_cache_lifetime', $form_state['values']['reptag_cache_lifetime']);
209 variable_set('reptag_staticonly', $form_state['values']['reptag_staticonly']);
210 // Expert
211 variable_set('reptag_disabled_nids', serialize(preg_split('/[\s,]+/', $form_state['values']['reptag_disabled_nids'])));
212 variable_set('reptag_enable_comments', $form_state['values']['reptag_enable_comments']);
213 variable_set('reptag_enable_title', $form_state['values']['reptag_enable_title']);
214 variable_set('reptag_debug', $form_state['values']['reptag_debug']);
215 // UI
216 variable_set('reptag_javascript', $form_state['values']['reptag_javascript']);
217 variable_set('reptag_textarea', $form_state['values']['reptag_textarea']);
218 // Locale
219 variable_set('reptag_locale_enable', $form_state['values']['reptag_locale_enable']);
220 variable_set('reptag_locale_mode', $form_state['values']['reptag_locale_mode']);
221 // Integration
222 variable_set('reptag_workspace', $form_state['values']['reptag_workspace']);
223
224 drupal_set_message(t('The configuration options have been saved.'));
225 }
226
227 /**
228 * Function _reptag_admin_general_reset().
229 */
230 function _reptag_admin_general_reset($form, &$form_state) {
231 // General
232 variable_set('reptag_preview', 1);
233 variable_set('reptag_showhelp', 1);
234 variable_set('reptag_tableprio', 0);
235 // Cache
236 variable_set('reptag_cache', 0);
237 variable_set('reptag_cache_lifetime', CACHE_PERMANENT);
238 variable_set('reptag_staticonly', 0);
239 // Expert
240 variable_set('reptag_disabled_nids', serialize(array()));
241 variable_set('reptag_enable_comments', 0);
242 variable_set('reptag_enable_title', 0);
243 variable_set('reptag_debug', 0);
244 // UI
245 variable_set('reptag_javascript', 1);
246 variable_set('reptag_textarea', 1);
247 // Locale
248 variable_set('reptag_locale_enable', 0);
249 variable_set('reptag_locale_mode', REPTAG_LOCALE_STRICT);
250 // Integration
251 variable_set('reptag_workspace', 0);
252
253 drupal_set_message(t('The configuration has been reset to defaults.'));
254 }
255
256 /**
257 * Function _reptag_admin_modules_form().
258 * (administration pages: module settings)
259 */
260 function _reptag_admin_modules_form() {
261 $form['modules'] = array(
262 '#type' => 'fieldset',
263 '#title' => t('Modules'),
264 '#collapsible' => FALSE,
265 '#collapsed' => FALSE,
266 '#tree' => TRUE,
267 '#description' => t('This is a list of your installed modules. A growing number of contibuted modules is available
268 <a href="@contrib">here</a>.', array('@contrib' => 'http://www.profix898.de/drupal/reptag/modules'))
269 );
270
271 // Modules
272 $form['modules']['table'] = array(
273 '#theme' => 'reptag_table',
274 '#header' => array('', t('Enabled'), t('Module'), t('Description'), t('Static'), t('Weight')),
275 '#attributes' => array('id' => 'reptag-modules-table'),
276 '#tabledrag' => 'weight'
277 );
278 $modules = _reptag_module_list(TRUE);
279 foreach ($modules as $module => $details) {
280 $disable_module = variable_get('reptag_cache', 0) && variable_get('reptag_staticonly', 0) && !$details['static'];
281 $form['modules']['table'][$module]['space'] = array('#value' => '');
282 $form['modules']['table'][$module]['enabled'] = array(
283 '#type' => 'checkbox',
284 '#title' => '',
285 '#default_value' => $disable_module ? FALSE : $details['enabled'],
286 '#prefix' => '<div align="center">',
287 '#suffix' => '</div>',
288 '#disabled' => $disable_module
289 );
290 $form['modules']['table'][$module]['module'] = array(
291 '#value' => $module,
292 '#prefix' => '<strong>',
293 '#suffix' => '</strong>'
294 );
295 $form['modules']['table'][$module]['description'] = array(
296 '#value' => $details['description'],
297 '#prefix' => '<i>',
298 '#suffix' => '</i>'
299 );
300 $form['modules']['table'][$module]['static'] = array(
301 '#value' => $details['static'] ? t('Yes') : t('No'),
302 '#prefix' => '<div align="center">',
303 '#suffix' => '</div>'
304 );
305 $form['modules']['table'][$module]['weight'] = array(
306 '#type' => 'weight',
307 '#default_value' => $details['weight']
308 );
309 }
310
311 return _reptag_admin_form($form, '_reptag_admin_modules');
312 }
313
314 /**
315 * Function _reptag_admin_modules_submit().
316 */
317 function _reptag_admin_modules_save($form, &$form_state) {
318 $modules = _reptag_module_list();
319 foreach ($form_state['values']['modules']['table'] as $module => $value) {
320 $modules[$module]['enabled'] = $value['enabled'];
321 $modules[$module]['weight'] = $value['weight'];
322 // Check prerequisites
323 if ($value['enabled']) {
324 if (!_reptag_module_require($modules[$module])) {
325 drupal_set_message(t('Module \'!module\' has been disabled!<br />It does not comply with all requirements
326 (e.g. module dependencies, PEAR packages, ...).', array('!module' => $module)), 'error');
327 $modules[$module]['enabled'] = FALSE;
328 }
329 }
330 }
331 _reptag_module_register($modules);
332
333 drupal_set_message(t('The configuration options have been saved.'));
334 _reptag_cache_clear(t('The cache has been flushed to reflect the new configuration.'));
335 }
336
337 /**
338 * Function _reptag_admin_modules_reset().
339 */
340 function _reptag_admin_modules_reset($form, &$form_state) {
341 _reptag_module_reset();
342
343 drupal_set_message(t('The configuration has been reset to defaults.'));
344 _reptag_cache_clear(t('The cache has been flushed to reflect the new configuration.'));
345 }
346
347 /**
348 * Function _reptag_admin_roles_form().
349 * (administration pages: module settings)
350 */
351 function _reptag_admin_roles_form() {
352 $form['roles'] = array(
353 '#type' => 'fieldset',
354 '#title' => t('Roles / Permissions'),
355 '#collapsible' => FALSE,
356 '#collapsed' => FALSE,
357 '#tree' => TRUE
358 );
359
360 // Modules (.tags)
361 $roles = user_roles();
362 $modules = _reptag_module_list();
363 ksort($modules);
364 $form['roles']['table'] = array(
365 '#theme' => 'reptag_table',
366 '#header' => array_merge(array(t('Option / Module')), array_values($roles))
367 );
368 foreach ($modules as $module => $details) {
369 $form['roles']['table'][$module]['label'] = array(
370 '#value' => t('Module: !module', array('!module' => '<strong>'. $module .'</strong>')),
371 );
372 foreach (array_keys($roles) as $rid) {
373 $form['roles']['table'][$module][$rid] = array(
374 '#type' => 'checkbox',
375 '#title' => '',
376 '#default_value' => in_array($rid, $details['roles']),
377 '#prefix' => '<div align="center">',
378 '#suffix' => '</div>',
379 '#disabled' => $details['enabled'] ? FALSE : TRUE
380 );
381 }
382 }
383 // Spacer
384 $form['roles']['table']['spacerB']['label'] = array('#value' => '');
385 foreach (array_keys($roles) as $rid) {
386 $form['roles']['table']['spacerB'][$rid] = array('#value' => '');
387 }
388 // Additional permissions
389 $form['roles']['table']['plainrep']['label'] = array(
390 '#value' => t('Plain text replacements only'),
391 '#prefix' => '<strong>',
392 '#suffix' => '</strong>'
393 );
394 foreach (array_keys($roles) as $rid) {
395 $form['roles']['table']['plainrep'][$rid] = array(
396 '#type' => 'checkbox',
397 '#title' => '',
398 '#default_value' => in_array($rid, (array)unserialize(variable_get('reptag_plainrep_roles', serialize(array())))),
399 '#prefix' => '<div align="center">',
400 '#suffix' => '</div>'
401 );
402 }
403
404 // Exclude tags
405 $form['roles']['exclude'] = array(
406 '#type' => 'fieldset',
407 '#title' => t('Exclude Tags'),
408 '#collapsible' => TRUE,
409 '#collapsed' => FALSE,
410 '#tree' => TRUE
411 );
412 $form['roles']['exclude']['table'] = array(
413 '#theme' => 'reptag_table',
414 '#header' => array(t('Exclude for role'), t('Tags'), '', ''),
415 '#attributes' => array(
416 'id' => 'reptag-exclude-table',
417 'description' => t('<em>Enter tags to exclude seperated by \'|\', e.g. \'$MYTAG$\' or \'#{BACK}(.*?){/BACK}#s\'.</em>')
418 )
419 );
420 foreach ($roles as $rid => $role) {
421 $form['roles']['exclude']['table'][$rid]['role'] = array(
422 '#value' => $role,
423 '#prefix' => '<strong>',
424 '#suffix' => '</strong>'
425 );
426 $form['roles']['exclude']['table'][$rid]['tags'] = array(
427 '#type' => 'textfield',
428 '#default_value' => _reptag_exclude_loadtags_string($rid),
429 '#size' => 60,
430 '#maxlength' => 1024,
431 '#attributes' => array('class' => 'reptag-exclude-tags'),
432 );
433 $form['roles']['exclude']['table'][$rid]['append'] = array(
434 '#type' => 'button',
435 '#value' => t('Append'),
436 '#attributes' => array('class' => 'reptag-exclude-append')
437 );
438 $form['roles']['exclude']['table'][$rid]['remove'] = array(
439 '#type' => 'button',
440 '#value' => t('Remove'),
441 '#attributes' => array('class' => 'reptag-exclude-remove')
442 );
443 }
444
445 if (variable_get('reptag_javascript', 1)) {
446 $form['roles']['exclude']['exclude-js'] = array(
447 '#type' => 'fieldset',
448 '#title' => t('Exclude Tags Administration'),
449 '#collapsible' => FALSE,
450 '#attributes' => array('class' => 'reptag-exclude-wrapper')
451 );
452 $form['roles']['exclude']['exclude-js']['exclude-add'] = array(
453 '#theme' => 'reptag_table',
454 '#header' => array(t('Enter tag to exclude:'), ''),
455 '#prefix' => '<div id=\'reptag-exclude-add-wrapper\'>',
456 '#suffix' => '</div>'
457 );
458 $form['roles']['exclude']['exclude-js']['exclude-add']['add']['value'] = array(
459 '#type' => 'textfield',
460 '#title' => '',
461 '#default_value' => '',
462 '#size' => 50,
463 '#maxlength' => 128,
464 '#autocomplete_path' => 'reptag/autocomplete_all'
465 );
466 $form['roles']['exclude']['exclude-js']['exclude-add']['add']['button'] = array(
467 '#type' => 'button',
468 '#value' => t('Add'),
469 '#name' => 'add'
470 );
471 //
472 $form['roles']['exclude']['exclude-js']['exclude-remove'] = array(
473 '#value' => '<div id=\'reptag-exclude-remove-wrapper\'></div>',
474 );
475 }
476
477 return _reptag_admin_form($form, '_reptag_admin_roles');
478 }
479
480 /**
481 * Function _reptag_admin_roles_save().
482 */
483 function _reptag_admin_roles_save($form, &$form_state) {
484 // Save roles configuration
485 $modules = _reptag_module_list();
486 foreach ($form_state['values']['roles']['table'] as $module => $role) {
487 $roles = array();
488 foreach ($role as $rid => $value) {
489 if ($value) {
490 $roles[] = $rid;
491 }
492 }
493 if ($module == 'plainrep') {
494 variable_set('reptag_plainrep_roles', serialize($roles));
495 }
496 else {
497 $modules[$module]['roles'] = $roles;
498 }
499 }
500 _reptag_module_register($modules);
501
502 // Save exclude tags
503 foreach ($form_state['values']['roles']['exclude']['table'] as $rid => $data) {
504 if (is_array($data)) {
505 _reptag_exclude_storetags_string($rid, $data['tags']);
506 }
507 else {
508 _reptag_exclude_storetags_string($rid, $data);
509 }
510 }
511
512 drupal_set_message(t('The configuration options have been saved.'));
513 _reptag_cache_clear(t('The cache has been flushed to reflect the new configuration.'));
514 }
515
516 /**
517 * Function _reptag_admin_roles_reset().
518 */
519 function _reptag_admin_roles_reset($form, &$form_state) {
520 // Reset roles configuration
521 $modules = _reptag_module_list();
522 foreach ($form_state['values']['roles']['table'] as $module => $role) {
523 $modules[$module]['roles'] = array();
524 }
525 _reptag_module_register($modules);
526 variable_set('reptag_plainrep_roles', serialize(array(DRUPAL_ANONYMOUS_RID)));
527
528 // Reset exclude tags
529 foreach ($form_state['values']['roles']['exclude']['table'] as $rid => $data) {
530 _reptag_exclude_storetags($rid, array());
531 }
532
533 drupal_set_message(t('The configuration has been reset to defaults.'));
534 _reptag_cache_clear(t('The cache has been flushed to reflect the new configuration.'));
535 }
536
537 /**
538 * Function _reptag_admin_content_form().
539 * (administration pages: content type settings)
540 */
541 function _reptag_admin_content_form() {
542 $form['content'] = array(
543 '#type' => 'fieldset',
544 '#title' => t('Content Types'),
545 '#collapsible' => FALSE,
546 '#collapsed' => FALSE,
547 '#tree' => TRUE,
548 '#description' => t('Choose the content fields to be processed. Reptag can only run on text fields.<br />
549 Unselecting all fields for a content type will disable reptag for that particular type.')
550 );
551
552 if (module_exists('content')) {
553 $content_types = content_types();
554 }
555 else {
556 $content_types = node_get_types('types');
557 drupal_set_message(t('You only have the \'Body\' field available for selection because <a href="@cck">CCK</a>
558 is not installed.', array('@cck' => 'http://drupal.org/project/cck')), 'notice');
559 }
560
561 foreach ($content_types as $type) {
562 $form['content'][$type['type']] = array(
563 '#type' => 'fieldset',
564 '#title' => ucfirst($type['name']),
565 '#collapsible' => TRUE,
566 '#collapsed' => TRUE,
567 '#tree' => TRUE
568 );
569 $form['content'][$type['type']]['table'] = array(
570 '#theme' => 'reptag_table',
571 '#header' => array(t('Field Label'), t('Type / Widget'), t('Process')),
572 '#parents' => array('content', $type['type'])
573 );
574 $fields = (array)unserialize(variable_get('reptag_type_'. $type['type'] .'_fields', serialize(array('content/body/#value'))));
575 // Title field
576 if ($type['has_title'] && variable_get('reptag_enable_title', 0)) {
577 $form['content'][$type['type']]['table']['title']['label'] = array(
578 '#value' => isset($type['title_label']) ? $type['title_label'] : t('Title')
579 );
580 $form['content'][$type['type']]['table']['title']['type'] = array('#value' => t('text'));
581 $form['content'][$type['type']]['table']['title']['process'] = array(
582 '#type' => 'checkbox',
583 '#title' => '',
584 '#default_value' => in_array('title', $fields)
585 );
586 }
587 // Body field
588 if ($type['has_body']) {
589 $form['content'][$type['type']]['table']['content/body/#value']['label'] = array(
590 '#value' => isset($type['body_label']) ? $type['body_label'] : t('Body')
591 );
592 $form['content'][$type['type']]['table']['content/body/#value']['type'] = array('#value' => t('text'));
593 $form['content'][$type['type']]['table']['content/body/#value']['process'] = array(
594 '#type' => 'checkbox',
595 '#title' => '',
596 '#default_value' => in_array('content/body/#value', $fields)
597 );
598 }
599 // CCK fields
600 if (isset($type['fields'])) {
601 // Handle fields in fieldgroups
602 if (module_exists('fieldgroup')) {
603 $group_prefix = array();
604 $groups = fieldgroup_groups($type['type']);
605 foreach ($groups as $group) {
606 foreach ($group['fields'] as $field => $field_info) {
607 $group_prefix[$field] = $field_info['group_name'];
608 }
609 }
610 }
611 foreach ($type['fields'] as $field => $field_info) {
612 // TODO: support for multiple value cck fields
613 //$field_path = 'content/'. $field .'/#value';
614 $field_path = 'content/'. $field .'/items/0/#item/safe';
615 if (isset($group_prefix[$field])) {
616 $field_path = 'content/'. $group_prefix[$field] .'/'. $field .'/items/0/#item/safe';
617 }
618 $form['content'][$type['type']]['table'][$field_path]['label'] = array('#value' => $field_info['widget']['label']);
619 if ($field_info['type'] == $field_info['widget']['type']) {
620 $form['content'][$type['type']]['table'][$field_path]['type'] = array('#value' => $field_info['type']);
621 }
622 else {
623 $form['content'][$type['type']]['table'][$field_path]['type'] = array(
624 '#value' => $field_info['type'] .' / '. $field_info['widget']['type']
625 );
626 }
627 $form['content'][$type['type']]['table'][$field_path]['process'] = array(
628 '#type' => 'checkbox',
629 '#title' => '',
630 '#default_value' => ($field_info['type'] != 'text') ? FALSE : in_array($field_path, $fields),
631 '#disabled' => ($field_info['type'] != 'text') ? TRUE : FALSE
632 );
633 }
634 }
635 }
636
637 return _reptag_admin_form($form, '_reptag_admin_content');
638 }
639
640 /**
641 * Function _reptag_admin_content_save().
642 */
643 function _reptag_admin_content_save($form, &$form_state) {
644 // Save fields configuration
645 foreach ($form_state['values']['content'] as $type => $fields) {
646 $enabled = array();
647 foreach ($fields as $field => $value) {
648 if ($value['process']) {
649 $enabled[] = $field;
650 }
651 }
652 variable_set('reptag_type_'. $type .'_fields', serialize($enabled));
653 }
654
655 drupal_set_message(t('The configuration options have been saved.'));
656 _reptag_cache_clear(t('The cache has been flushed to reflect the new configuration.'));
657 }
658
659 /**
660 * Function _reptag_admin_content_reset().
661 */
662 function _reptag_admin_content_reset($form, &$form_state) {
663 // Reset fields configuration
664 foreach ($form_state['values']['content'] as $type => $fields) {
665 variable_set('reptag_type_'. $type .'_fields', serialize(array('content/body/#value')));
666 }
667
668 drupal_set_message(t('The configuration has been reset to defaults.'));
669 _reptag_cache_clear(t('The cache has been flushed to reflect the new configuration.'));
670 }
671
672 /**
673 * Function _reptag_admin_form().
674 * (add hidden fields for ajax support and default buttons)
675 */
676 function _reptag_admin_form($form, $base = NULL) {
677 // Include JS (if configured)
678 if (variable_get('reptag_javascript', 1)) {
679 $settings = array(
680 'callback' => base_path() .'index.php?q=admin/settings/reptag/ajax/',
681 'images' => base_path() . drupal_get_path('module', 'reptag') .'/images/',
682 'htmlLoad' => theme('reptag_dialog'),
683 'multilingual' => variable_get('reptag_locale_enable', 0) && (variable_get('language_count', 1) >= 2)
684 );
685 drupal_add_js(array('reptag' => $settings), 'setting');
686 drupal_add_js(drupal_get_path('module', 'reptag') .'/js/reptag.js');
687 }
688 // Include CSS
689 drupal_add_css(drupal_get_path('module', 'reptag') .'/css/reptag.css');
690
691 // Default buttons
692 if (isset($base)) {
693 $form['buttons']['submit'] = array(
694 '#type' => 'submit',
695 '#value' => t('Save configuration'),
696 '#submit' => array($base .'_save')
697 );
698 $form['buttons']['reset'] = array(
699 '#type' => 'submit',
700 '#value' => t('Reset to defaults'),
701 '#submit' => array($base .'_reset')
702 );
703 }
704
705 return $form;
706 }
707
708 /**
709 * Function theme_reptag_table().
710 */
711 function theme_reptag_table($form) {
712 $rows = array();
713 $header = isset($form['#header']) ? $form['#header'] : array();
714 $attributes = isset($form['#attributes']) ? $form['#attributes'] : array();
715 $tabledrag = isset($form['#tabledrag']) ? $form['#tabledrag'] : FALSE;
716
717 if ($tabledrag && isset($attributes['id'])) {
718 drupal_add_tabledrag($attributes['id'], 'order', 'sibling', $attributes['id'] .'-'. $tabledrag);
719 }
720
721 if (isset($attributes['description'])) {
722 $rows[] = array(array('data' => $attributes['description'], 'colspan' => count($header), 'class' => 'message'));
723 unset($attributes['description']);
724 }
725
726 foreach (element_children($form) as $key) {
727 $row = array();
728 foreach (element_children($form[$key]) as $item) {
729 if ($tabledrag && $tabledrag == $item) {
730 $form[$key][$item]['#attributes'] = array('class' => $attributes['id'] .'-'. $tabledrag);
731 }
732 $row[] = drupal_render($form[$key][$item]);
733 }
734 $rows[] = $tabledrag ? array('data' => $row, 'class' => 'draggable') : $row;
735 }
736
737 if (empty($rows)) {
738 $message = check_plain(isset($form['#empty']) ? $form['#empty'] : t('There are no items in the table.'));
739 $rows[] = array(array('data' => $message, 'colspan' => count($header), 'align' => 'center', 'class' => 'message'));
740 }
741
742 return count($rows) ? theme('table', $header, $rows, $attributes) : '';
743 }

  ViewVC Help
Powered by ViewVC 1.1.2