-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmm_ui.inc
1558 lines (1424 loc) · 58.6 KB
/
mm_ui.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// $Id: mm_ui.inc 5041 2011-02-16 14:22:32Z vquinn $
/**
* @file
* User interface routines for monster_menus
*/
define('MM_UI_MAX_USERS_IN_GROUP', 20); // max number of users to display (there can be more in the DB)
define('MM_UI_MAX_REORDER_ITEMS', 100); // max number of nodes/subpages to reorder
/**
* Allow the user to edit a node
*
* This code is lifted from node_page() in node.module and modified to use
* callback arguments
*
* @param $node
* Node to delete
* @return
* The HTML code for the results
*/
function mm_ui_node_edit($node) {
if ($_POST['op'] == t('Delete')) {
// Redirect, to make the tabs disappear.
if ($_REQUEST['destination']) {
$destination = drupal_get_destination();
unset($_REQUEST['destination']);
}
mm_goto("node/$node->nid/delete", $destination);
return;
}
return drupal_get_form($node->type .'_node_form', $node);
}
/**
* Allow the user to act upon a list of revisions to a node
*
* @param $mmtid
* The MM tree ID associated with the node
* @param $node
* The node being manipulated
* @param $vid
* (Optional) revision being manipulated
* @param $op
* (Optional) operation to perform, defaults to 'overview'
* @param $compare
* (Optional) when $op = 'compare', the secondary revision to compare with
* @return
* The HTML code for the results
*/
function mm_ui_node_revisions($mmtid, $node, $vid = NULL, $op = 'overview', $compare = NULL) {
if ($vid && $op != 'compare') {
$revision = node_load($node->nid, $vid);
if (!$revision || !$revision->nid) {
drupal_not_found();
return;
}
}
switch ($op) {
case 'overview':
mm_content_add_breadcrumb('');
if (module_exists('diff')) return diff_diffs_overview($node);
module_load_include('inc', 'node', 'node.pages');
return node_revision_overview($node);
case 'view':
mm_content_add_breadcrumb(t('Revision of %title from @date',
array('%title' => $revision->title,
'@date' => format_date($revision->revision_timestamp))));
return mm_node_show($node, 'revisions');
case 'revert':
$return_val = drupal_get_form('node_revision_revert_confirm', $revision);
break;
case 'delete':
$return_val = drupal_get_form('node_revision_delete_confirm', $revision);
break;
case 'compare':
if (module_exists('diff')) {
$return_val = diff_diffs_show($node, $vid, $compare);
}
}
if ($return_val) {
$new_title = drupal_get_title();
mm_content_restore_breadcrumb();
if ($op == 'compare') {
mm_content_add_breadcrumb($new_title);
}
else {
$return_val = "<div>$new_title</div>$return_val";
}
return $return_val;
}
drupal_not_found();
}
/**
* Present a node submission form or a set of links to such forms.
*
* This code is lifted from node_add() in node.module and modified to use
* callback arguments
*
* @param $mmtid
* MM Tree ID to add the node to
* @param $type
* Type of node to create(optional)
* @return
* The HTML code for the results
*/
function mm_ui_node_add($mmtid, $type = '') {
global $user;
if (!mm_content_user_can($mmtid, 'u')) {
$tree = mm_content_get($mmtid);
return t('You are not allowed to assign the page %cat to content.', array('%cat' => mm_content_expand_name($tree->name)));
}
$allowed_node_types = mm_content_resolve_cascaded_setting('allowed_node_types', $mmtid, $types_at, $types_parent);
// If a node type has been specified, validate its existence.
$types = node_get_types();
$type = isset($type) ? str_replace('-', '_', $type) : NULL;
if (isset($types[$type]) && node_access('create', $type) && (user_access('administer all menus') || array_search($type, $allowed_node_types) !== FALSE)) {
$node = (object) array(
'uid' => $user->uid,
'name' => isset($user->name) ? $user->name : '',
'type' => $type,
'language' => '',
);
mm_content_add_breadcrumb(t('Create @name', array('@name' => $types[$type]->name)));
return drupal_get_form($type . '_node_form', $node);
}
else {
// If no (valid) node type has been provided, display a node type overview.
mm_content_add_breadcrumb(t('Add content'));
$hidden_types = mm_get_node_info(MM_NODE_INFO_ADD_HIDDEN);
$admin_only_item = array();
foreach ($types as $type) {
$type_url_str = $type->type;
$title = t('Add a new @s.', array('@s' => $type->name));
$direct_link = "mm/$mmtid/contents/add/$type_url_str";
$out = '<dt>'. l(drupal_ucfirst($type->name), $direct_link, array('attributes' => array('title' => $title))) .'</dt>';
$out .= '<dd>'. filter_xss_admin($type->description) .'</dd>';
if (node_access('create', $type) && array_search($type_url_str, $hidden_types) === FALSE && array_search($type_url_str, $allowed_node_types) !== FALSE) {
$item[$type->name] = $out;
$sole_direct_link = $direct_link;
}
else if (user_access('administer all menus') && array_search($type->type, $allowed_node_types) === FALSE) {
$admin_only_item[$type->name] = $out;
}
}
if (isset($item)) {
if (count($item) == 1 && !user_access('administer all menus')) {
drupal_goto($sole_direct_link);
}
uksort($item, 'strnatcasecmp');
uksort($admin_only_item, 'strnatcasecmp');
$output = '';
if ($mmtid && variable_get('mm_hide_empty_pages', FALSE)) {
$count = db_result(db_query(
'SELECT COUNT(*) FROM {mm_node2tree} t '.
'INNER JOIN {node} n ON t.nid = n.nid '.
'WHERE mmtid = %d AND (n.status = %d OR n.uid = %d)',
$mmtid, 1, $user->uid));
if (!$count) {
$output .= '<div id="message"><div class="messages status">'.
t('Until you have added some content to this page, it will not appear in the menus for anyone who does not also have the ability to add content.') . '</div></div>';
}
}
$output .= t('Choose the type of content to create using this page:') . '<dl>' . implode('', $item) . '</dl>';
if (user_access('administer all menus') && count($admin_only_item) > 0) {
drupal_add_css(drupal_get_path('module', 'monster_menus') . "/monster_menus.css");
$output .= '<br /><div class="mm-admin-types">' . t('The following content types will only be displayed to admin users:') . '<dl>' . implode('', $admin_only_item) . '</dl></div>';
}
return $output;
}
return t('You are not allowed to create content.');
}
}
function mm_ui_comment() {
$args = func_get_args();
$op = array_shift($args);
if ($op == 'edit' || $op == 'delete' || $op == 'reply') {
$this_title = drupal_get_title();
$return_val = call_user_func_array("comment_$op", $args);
if ($return_val) {
$new_title = drupal_get_title();
if ($new_title != $this_title) $return_val = "<div>$new_title</div>$return_val";
mm_content_restore_breadcrumb();
return $return_val;
}
}
drupal_not_found();
}
function mm_ui_comment_redirect($default) {
if (mm_parse_args($mmtids, $oarg_list, $this_mmtid) == 'mm')
return "mm/$this_mmtid";
return $default;
}
/**
* Implementation of hook_form_alter().
*
* Remove some unneeded node creation options, and add some of our own. This
* only works if MM happens to load after the modules that create these form
* elements. This is controlled by the 'weight' column of the 'system' table.
*/
function monster_menus_form_alter(&$form, $form_state, $form_id) {
global $user;
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
$node = $form['#node'];
$mm = mm_parse_args($mmtids, $oarg_list, $this_mmtid);
if (isset($form_state['values'])) { // user clicked Preview button
$values = $form_state['values'];
$everyone = $values['others_w'];
$grouplist = $values['groups_w'];
$userlist = $values['users_w'];
$uid = intval($values['owner']);
$mmlist = $values['mm_catlist'];
$mmlist_restricted = $values['mm_catlist_restricted'];
$mmlist_restricted_link = $values['mm_catlist_restricted_link'];
}
else {
$mmlist = $mmlist_restricted = $mmlist_restricted_link = array();
}
if (isset($form['title'])) {
$form['title']['#description'] .= ' ' . t('To prevent the title from displaying when viewing a page, surround it with square brackets. Example: [My Title]');
}
if (isset($form['nid']['#value'])) { // existing node
if (count($mmtids))
$form['#redirect'] = "mm/$this_mmtid";
if (mm_content_node_is_recycled($node)) {
_mm_ui_form_array_merge($form, 'mm_categories', array(
'#type' => 'fieldset',
'#title' => t('Pages'),
'#weight' => 20,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
));
_mm_ui_recycle_page_list($node, $names, $msg);
if (!count($names))
$msg = t('This content is not associated with a page. If restored, it will be visible only by its direct web address.');
else if (count($names) == 1)
$msg = t('If you restore this content, it will return to the page !title.',
array('!title' => $names[0]));
else
$msg = t('If you restore this content, it will return to the following pages: !list', array('!list' => implode(', ', $names)));
$form['mm_categories']['mm_catlist'] = array(
'#type' => 'value',
'#value' => array(),
);
$form['mm_categories']['mm_catlist_restricted'] = array(
'#type' => 'value',
'#value' => $node->recycle_from_mmtids
);
// Needed for mm_content_node_is_recycled()
$form['mm_categories']['recycle_date'] = array(
'#type' => 'value',
'#value' => $node->recycle_date
);
$form['mm_categories']['mm_catlist_readonly'] = array(
'#type' => 'item',
'#value' => t('The list of pages cannot be changed because this content is in the recycle bin.'),
'#description' => $msg,
);
}
else { // !recycled
$nid = $node->nid;
if ($nid && !isset($values)) {
foreach (mm_content_get(mm_content_get_by_nid($nid)) as $r)
if (mm_content_user_can($r->mmtid, 'u'))
$mmlist[$r->mmtid] = mm_content_expand_name($r->name);
else {
$mmlist_restricted[] = $r->mmtid;
$mmlist_restricted_link[] = l(mm_content_expand_name($r->name), mm_content_get_mmtid_url($r->mmtid));
}
}
_mm_ui_form_array_merge($form, 'mm_categories', array(
'#type' => 'fieldset',
'#title' => t('Pages'),
'#weight' => 20,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
));
$form['mm_categories']['mm_catlist_restricted'] = array(
'#type' => 'value',
'#value' => $mmlist_restricted,
);
$required = TRUE;
if (count($mmlist_restricted)) {
$required = FALSE;
$form['mm_categories']['mm_catlist_warning'] = array(
'#type' => 'item',
'#value' => t('<font color="red">This content will also appear on the !plur !list. You do not have permission to change this fact.</font>', array('!plur' => (count($mmlist_restricted) == 1 ? t('page') : t('pages: ')), '!list' => implode(', ', $mmlist_restricted_link))),
);
}
$form['mm_categories']['mm_catlist'] = array(
'#type' => 'mm_catlist',
'#required' => $required,
'#description' => t('Choose additional pages where this content will appear.'),
'#mm_list_popup_start' => implode('/', $mmtids),
'#default_value' => $mmlist,
);
} // if (not) recycled
if (!isset($values)) {
$everyone = FALSE;
$grouplist = array();
$result = db_query(
'SELECT nw.gid, t.name FROM {mm_node_write} nw '.
'LEFT JOIN {mm_tree} t ON nw.gid = t.mmtid '.
'WHERE nw.gid >= %d AND nid = %d ORDER BY t.name',
0, $node->nid);
while ($r = db_fetch_object($result)) {
if ($r->gid == 0) {
$everyone = TRUE;
}
else {
$members = mm_content_get_users_in_group($r->gid, '<br />', FALSE, 20, TRUE);
if ($members == '') $members = t('(none)');
$grouplist[$r->gid]['name'] = mm_content_expand_name($r->name);
$grouplist[$r->gid]['members'] = $members;
}
}
$userlist = array();
$result = db_query('SELECT gid FROM {mm_node_write} WHERE gid < %d AND nid = %d', 0, $node->nid);
if ($r = db_fetch_object($result)) {
$users = mm_content_get_users_in_group($r->gid, NULL, TRUE, MM_UI_MAX_USERS_IN_GROUP);
if (!is_null($users)) $userlist = $users;
}
if (count($userlist) || count($grouplist)) {
$everyone = FALSE;
}
$uid = $node->uid;
}
_mm_ui_node_form_perms($form, $userlist, $grouplist, $everyone, node_get_types('name', $node), $uid);
}
else { // new node
if (count($mmtids) || count($mmlist)) {
if (!isset($values)) {
$tree = mm_content_get($this_mmtid);
$mmlist = array($this_mmtid => mm_content_expand_name($tree->name));
mm_content_get_default_node_perms($this_mmtid, $grouplist, $userlist, MM_UI_MAX_USERS_IN_GROUP);
$uid = $user->uid;
$everyone = array_search('u', explode(',', $tree->default_mode)) !== FALSE;
$node->show_node_info = $tree->node_info;
$node->comment = $tree->comment;
if (variable_get('mm_finegrain_comment_readability', FALSE)) {
$node->comments_readable = mm_content_resolve_cascaded_setting('comments_readable', $this_mmtid, $cascaded_at, $cascaded_parent);
}
else {
$node->comments_readable = '';
}
}
_mm_ui_form_array_merge($form, 'mm_categories', array(
'#type' => 'fieldset',
'#title' => t('Pages'),
'#weight' => 20,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
));
$form['mm_categories']['mm_catlist'] = array(
'#type' => 'mm_catlist',
'#description' => t('Choose additional pages where this content will appear.'),
'#mm_list_popup_start' => implode('/', $mmtids),
'#default_value' => $mmlist,
);
$form['mm_categories']['mm_catlist_restricted'] = array(
'#type' => 'value',
'#value' => $mmlist_restricted,
);
_mm_ui_node_form_perms($form, $userlist, $grouplist, $everyone, node_get_types('name', $node), $uid, t('The default settings are taken from the settings of the page. '));
// webform sets $form_state['redirect'] after submit, but there's no way
// to tell that before this point, so unfortunately we have to hard code
if ($node->type != 'webform') $form['#redirect'] = "mm/$this_mmtid";
}
} // if existing/new node
$form['mm_catlist_restricted_link'] = array(
'#type' => 'value',
'#value' => $mmlist_restricted_link
);
unset($form['menu']);
unset($form['options']['sticky']);
_mm_ui_form_array_merge($form, 'mm_appearance', array(
'#type' => 'fieldset',
'#title' => t('Appearance'),
'#weight' => 23,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
));
if ($form_id == 'redirect_node_form') { // redirector
unset($form['comment_settings']);
unset($form['attachments']);
$form['comment'] = array(// comments = 'Disabled'
'#type' => 'value',
'#value' => 0,
);
$form['options']['#access'] = FALSE;
unset($form['buttons']['preview']);
}
else {
if (isset($form['comment_settings']['comment']) && !$node->nid) {
$form['comment_settings']['comment']['#default_value'] = $node->comment;
}
// provide alternate 'sticky' checkbox
$form['mm_appearance']['sticky'] = array(
'#type' => 'checkbox',
'#title' => t('Sticky at top of page'),
'#description' => t('Content that is "sticky" will stay at the top of the page, even after other content is added. But the content\'s owner must be listed under %who (see %perm, under the %set tab) in order for this setting to take effect.', array('%who' => t('Who can delete this page or change its settings'), '%perm' => t('Permissions'), '%set' => t('Settings'))),
'#default_value' => $node->sticky,
);
}
$toggle = theme_get_setting('toggle_node_info_' . $node->type);
if (user_access('show/hide post information') && $toggle) {
$form['mm_appearance']['show_node_info'] = array(
'#type' => 'select',
'#title' => t('Attribution style'),
'#options' => _mm_ui_node_info_values(),
'#default_value' => $node->show_node_info,
);
}
else {
if (!$toggle && !isset($form['nid']['#value'])) {
// Always default to off for new nodes when disabled in all nodes of
// this type. This way, if enabled later on for all nodes of this type,
// the end result won't immediately change.
$node->show_node_info = 0;
}
$form['mm_appearance']['show_node_info'] = array(
'#type' => 'value',
'#value' => $node->show_node_info,
);
}
_mm_ui_form_array_merge($form, 'scheduling', array(
'#type' => 'fieldset',
'#title' => t('Scheduling'),
'#weight' => 25,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
));
$publish_on = _mm_ui_date_to_string($node->publish_on);
$unpublish_on = _mm_ui_date_to_string($node->unpublish_on);
if (module_exists('date_popup') && !$values['_via_drupal_execute']) {
_mm_ui_form_array_merge($form['scheduling'], 'publish_on', array(
'#type' => 'date_popup',
'#title' => t('Publish on'),
'#default_value' => $publish_on,
'#description' => t('Leave blank to disable scheduled publishing.'),
'#no_time_default' => '12:00AM', // used in _mm_ui_date_popup_validate
'#element_validate' => array('_mm_ui_date_popup_validate'),
'#date_format' => 'n/j/Y - g:iA', // force here, because jQuery date widget can't handle spaces in time format
));
_mm_ui_form_array_merge($form['scheduling'], 'unpublish_on', array(
'#type' => 'date_popup',
'#title' => t('Unpublish on'),
'#default_value' => $unpublish_on,
'#description' => t('Leave blank to disable scheduled unpublishing.'),
'#no_time_default' => '11:59PM', // used in _mm_ui_date_popup_validate
'#element_validate' => array('_mm_ui_date_popup_validate'),
'#date_format' => 'n/j/Y - g:iA', // force here, because jQuery date widget can't handle spaces in time format
));
}
else {
$t_now = array('%time' => format_date(time(), 'custom', variable_get('date_format_short', 'n/j/Y g:iA')));
_mm_ui_form_array_merge($form['scheduling'], 'publish_on', array(
'#type' => 'textfield',
'#title' => t('Publish on'),
'#maxlength' => 25,
'#default_value' => $publish_on,
'#description' => t('Format: %time. Leave blank to disable scheduled publishing.', $t_now),
));
_mm_ui_form_array_merge($form['scheduling'], 'unpublish_on', array(
'#type' => 'textfield',
'#title' => t('Unpublish on'),
'#maxlength' => 25,
'#default_value' => $unpublish_on,
'#description' => t('Format: %time. Leave blank to disable scheduled unpublishing.', $t_now),
));
}
_mm_ui_form_array_merge($form['scheduling'], 'set_change_date', array(
'#type' => 'checkbox',
'#title' => t('Use <em>Publish on</em> date for attributions'),
'#default_value' => $node->set_change_date,
'#description' => t('Use the date above instead of the content\'s last modified date when showing <em>Submitted on [date]</em> or <em>Submitted by [user] on [date]</em>'),
));
if (isset($form['author'])) {
unset($form['author']['name']);
$form['mm_appearance']['author'] = $form['author'];
unset($form['author']);
if ($form['mm_appearance']['author']['#access'] !== FALSE && isset($form['mm_appearance']['author']['date']) && module_exists('date_popup') && !$values['_via_drupal_execute']) {
$form['mm_appearance']['author']['date']['#type'] = 'date_popup';
$form['mm_appearance']['author']['date']['#description'] = '';
unset($form['mm_appearance']['author']['date']['#maxlength']);
}
}
if (isset($form['taxonomy'])) {
$form['body_field']['#weight'] = -4;
}
// Admin users don't need the set author option, they should use "Who can edit/delete"
if (isset($form['settings_perms']['owner-choose']) && isset($form['author']['name'])) {
$form['author']['name'] = array(
'#value' => t('<p>To change the author, set the %owner in %where, above.</p>',
array(
'%owner' => t('Owner'),
'%where' => t('Who can edit or delete')
))
);
}
if (isset($form['comment_settings'])) {
$form['comment_settings']['#access'] = user_access('enable/disable comments') || user_access('administer comments') || variable_get('mm_finegrain_comment_readability', FALSE);
if (variable_get('mm_finegrain_comment_readability', FALSE)) {
$form['comment_settings']['comments_readable'] = array(
'#type' => 'select',
'#title' => t('Who can read comments'),
'#default_value' => $node->comments_readable,
'#options' => _mm_ui_comment_read_setting_values(t('(use default setting)')),
'#weight' => -1,
);
}
$form['comment_settings']['comment']['#access'] = user_access('enable/disable comments') || user_access('administer comments');
$form['comment_settings']['comment']['#options'] = _mm_ui_comment_write_setting_values();
if (variable_get('mm_finegrain_comment_readability', FALSE)) {
$form['comment_settings']['comment']['#type'] = 'select';
$form['comment_settings']['comment']['#title'] = t('Who can add comments');
}
}
$form['buttons']['required-note'] = array('#type' => 'markup' , '#weight' => 51 , '#value' => t('<div class=\"requiredfields\"><span class="form-required">*</span> denotes required fields</div>'));
}
else if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
// This can't be done in a monster_menus_form_node_type_form_alter() since
// it gets called too early.
if (isset($form['comment']['comment'])) {
$form['comment']['comment']['#description'] = t('Users with the <em>administer comments</em> or <em>enable/disable comments</em> permission will be able to override this setting.');
}
}
}
function monster_menus_form_system_theme_settings_alter(&$form, $form_state) {
$form['node_info']['#description'] = t('Because you are using Monster Menus, the setting for <em>Submitted by [username] on [date]</em> text is controlled independently, within each node. The setting below acts as a global override for all nodes of the given type. If not checked, the text is never displayed for those nodes.');
}
function monster_menus_form_user_admin_role_alter(&$form, $form_state) {
_mm_ui_form_array_merge($form, 'mm_group', array(
'#type' => 'fieldset',
'#title' => t('Add group members'),
'#description' => t('The members of the chosen Monster Menus group will be added to this role.'),
'#collapsible' => TRUE, '#collapsed' => FALSE));
$current = db_fetch_object(db_query('SELECT * FROM {mm_role2group} r2 LEFT JOIN {mm_tree} t ON r2.gid = t.mmtid WHERE r2.rid = %d', $form['rid']['#value']));
if (!$current) $current = (object)array('negative' => 0);
$form['mm_group']['mm_group'] = array(
'#type' => 'mm_grouplist',
'#mm_list_popup_start' => mm_content_groups_mmtid(),
'#mm_list_max' => 1,
'#default_value' => $current->gid ? array($current->gid => mm_content_expand_name($current->name)) : NULL
);
$form['mm_group']['mm_group_direction'] = array(
'#type' => 'radios',
'#options' => array(0 => t('Add all users <b>in</b> this group'),
1 => t('Add all users <b>not in</b> this group')),
'#default_value' => $current->negative
);
$form['#submit'][] = '_mm_ui_submit_role';
$form['submit']['#weight'] = 9998;
$form['delete']['#weight'] = 9999;
}
function _mm_ui_submit_role($form, &$form_state) {
db_query('DELETE FROM {mm_role2group} WHERE rid=%d', $form_state['values']['rid']);
// If the Save button was chosen (instead of Delete)
if ($form_state['values']['submit'] == $form_state['values']['op']) {
$gid = mm_ui_mmlist_key0($form_state['values']['mm_group']);
if ($gid)
db_query('INSERT INTO {mm_role2group} (rid, gid, negative) VALUES (%d, %d, %d)', $form_state['values']['rid'], $gid, $form_state['values']['mm_group_direction']);
}
}
/**
* Implementation of hook_elements().
*
* This hook declares to Drupal what form elements are provided by the module.
*/
function monster_menus_elements() {
$type['mm_catlist'] = $type['mm_grouplist'] = $type['mm_userlist'] = $type['mm_nodelist'] = array(
'#input' => TRUE,
'#default_value' => array(),
'#process' => array('_mm_ui_process_mmlist'),
'#mm_list_min' => 0, // min number of rows
'#mm_list_max' => 0, // max number of rows
'#mm_list_popup_start' => '',
'#mm_list_popup_root' => 1,
'#mm_list_enabled' => '', // in category browser, attribute of cats user can open
'#mm_list_selectable' => 'u', // in category browser, attribute of cats user can choose
'#mm_list_buttons_underneath' => FALSE,
'#mm_list_readonly' => FALSE, // let the user select rows, but not edit them
'#mm_list_no_info' => FALSE, // don't show an item's info when clicked
'#mm_list_browser' => 'mm-browser-load', // path to the popup tree browser
'#mm_list_other_name' => '',
'#mm_list_other_callback' => 'null');
$type['mm_repeatlist'] = array(
'#input' => TRUE,
'#default_value' => array(),
'#mm_list_id' => '', // REQUIRED: form ID of repeatable DIV (mm_repeatlist_div type)
'#mm_list_inputs_per_row' => '', // REQUIRED: number of values per row in repeatable DIV and #default_value
'#mm_list_min' => 1, // min number of rows
'#mm_list_max' => 0, // max number of rows
'#mm_list_add_button' => t('Add a Row'), // text label for the 'add' button
'#mm_list_buttons_underneath' => TRUE,
'#mm_list_readonly' => FALSE, // display the data rows as text instead of form inputs
'#mm_list_reorder' => FALSE); // show the up/down arrows in each row
$type['mm_repeatlist_div'] = array();
$type['mm_help_radios'] = array(
'#input' => TRUE,
'#process' => array('mm_ui_expand_mm_help_radios'));
$type['mm_help_radio'] = array(
'#input' => TRUE);
$type['mm_fake_required'] = array(
'#input' => TRUE,
'#mm_orig_type' => ''); // REQUIRED: '#type' of element to render
return $type;
}
// split result generated by setHiddenElt in mm.js
function _mm_ui_process_mmlist($element, $edit, &$form_state = NULL, $form = NULL) {
if (is_string($edit)) {
$element['#value'] = array();
if (preg_match_all('#(\d+(?:/\d+)?)\{([^}]*)\}#', $edit, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$element['#value'][$match[1]] = $match[2];
}
}
}
return $element;
}
// Kept for backward compatibility. Usually no longer needed, now that
// _mm_ui_process_mmlist handles this automatically.
function _mm_ui_split_mmlist($str) {
if (is_array($str)) {
$matches = array();
foreach ($str as $key => $val) {
$matches[] = array(NULL, $key, $val);
}
return $matches;
}
}
// Return the first array key of an array. Useful when retrieving the first key
// from an mm_list value array.
function mm_ui_mmlist_key0($arr) {
if (!is_array($arr)) return;
reset($arr);
if (count($arr)) {
return key($arr);
}
}
/**
* Parse the hidden data field generated by an mm_repeatlist form element into a
* set of arrays.
*
* @param $str
* Form data to parse
* @param $per_row
* The number of data elements per row (set)
* @return
* An array of arrays. Each inner array represents one set of data entered by
* the user.
*/
function mm_ui_parse_repeatlist($str, $per_row) {
if ($per_row <= 0 || !preg_match_all('/\{:(.*?):\}/', $str, $matches, PREG_PATTERN_ORDER)) return array();
return array_chunk($matches[1], $per_row);
}
function mm_ui_validate_fake_required($elt, $value, $message = NULL) {
if ($elt['#type'] == 'mm_fake_required' && empty($value) && $value !== '0') {
form_error($elt, empty($message) ? t('!name field is required.', array('!name' => $elt['#title'])) : $message);
return FALSE;
}
return TRUE;
}
function mm_ui_expand_mm_help_radios($element, $edit, &$form_state, $form) {
if (count($element['#options']) > 0) {
foreach ($element['#options'] as $key => $choice) {
if (!isset($element[$key])) {
$element[$key] = array('#type' => 'mm_help_radio', '#title' => $choice,
'#return_value' => $key, '#default_value' => $element['#default_value'],
'#attributes' => $element['#attributes'],
'#parents' => $element['#parents'], '#spawned' => TRUE);
}
}
}
return $element;
}
/**
* Get a list of possible variable substitutions
*
* @param $weight
* Weight of the resulting form element
* @param $list
* Array of human-readable field names to which the help text applies
* @param $xvars
* Optional array of system variables which are allowed
* @return
* A form element containing the help text
*/
function mm_ui_vars_help($weight, $list, $xvars = NULL) {
global $user;
$uid = db_result(db_query_range('SELECT uid FROM {users} WHERE uid > 1', 0, 1));
if (!$uid) $uid = $user->uid;
$vars = array();
foreach (user_load(array('uid' => $uid)) as $k => $v)
if (is_scalar($v)) $vars[] = '${' . $k . '}';
sort($vars);
$vars = join("\n", $vars);
foreach ($list as &$l)
$l = theme('placeholder', $l);
$last = array_pop($list);
$list = join(', ', $list) . " or $last";
$ret = array(
'#type' => 'fieldset',
'#title' => t('Variable substitution'),
'#weight' => $weight,
'#collapsible' => TRUE, '#collapsed' => TRUE,
'#description' => t('The variables below can be inserted into the fields !list.<br />Variables which describe the current user:',
array('!list' => $list)) . "<pre>$vars</pre>",
);
if (count($xvars)) {
sort($xvars);
$xvars = '${' . join("}\n\${", $xvars) . '}';
$ret['#description'] .= t("System variables:<pre>$xvars</pre>");
}
return $ret;
}
function mm_ui_mmlist_labels() {
return array(t('Move to top'), t('Move up'), t('Delete this row'),
t('Move to bottom'), t('Move down'), t('Edit'));
}
/**
* Escape certain sequences for output as part of Javascript code
*
* @param $string
* The code to be escaped
* @return
* The escaped code
*/
function mm_ui_js_escape($string) {
return str_replace(
array("\r", "\n", '<', '>', '&', '{', '}', '"'),
array('', '', '\x3c', '\x3e', '\x26', '{', '}', '"'),
addslashes($string));
}
/**
* Return TRUE if content of the given type should show the author (attribution)
*
* @param $type
* Name of the content type to test ('article', 'story', etc.)
* @return
* TRUE if the attribution should be shown
*/
function mm_ui_show_author($type) {
$settings = variable_get('theme_settings', array());
return $settings['toggle_node_info_' . $type];
}
/**
* Implementation of hook_theme().
*/
function monster_menus_theme() {
$themes = array(
'mm_catlist' => array(
'file' => 'mm_theme.inc',
'arguments' => array('elt' => NULL)),
'mm_grouplist' => array(
'file' => 'mm_theme.inc',
'arguments' => array('elt' => NULL)),
'mm_userlist' => array(
'file' => 'mm_theme.inc',
'arguments' => array('elt' => NULL)),
'mm_nodelist' => array(
'file' => 'mm_theme.inc',
'arguments' => array('elt' => NULL)),
'mm_admin_list_blocks' => array(
'file' => 'mm_theme.inc',
'arguments' => array('form' => NULL)),
'mm_admin_verify_integrity' => array(
'file' => 'mm_theme.inc',
'arguments' => array('form' => NULL)),
'tooltip' => array(
'file' => 'mm_theme.inc',
'arguments' => array('text' => NULL, 'title' => NULL, 'tip' => NULL, 'html' => FALSE)),
'mm_repeatlist_div' => array(
'file' => 'mm_theme.inc',
'arguments' => array('elt' => NULL)),
'mm_fake_required' => array(
'file' => 'mm_theme.inc',
'arguments' => array('elt' => NULL)),
'mm_repeatlist' => array(
'file' => 'mm_theme.inc',
'arguments' => array('elt' => NULL)),
'mm_help_radio' => array(
'file' => 'mm_theme.inc',
'arguments' => array('element' => NULL)),
'mm_help_radios' => array(
'file' => 'mm_theme.inc',
'arguments' => array('element' => NULL)),
'mm_ui_mark_yesno' => array(
'file' => 'mm_theme.inc',
'arguments' => array('yes' => NULL)),
'mm_ui_menu_reorder' => array(
'file' => 'mm_theme.inc',
'arguments' => array('element' => NULL)),
'mm_ui_node_reorder' => array(
'file' => 'mm_theme.inc',
'arguments' => array('element' => NULL)),
'mm_ui_permissions' => array(
'file' => 'mm_theme.inc',
'arguments' => array('element' => NULL)),
'mm_ui_node_permissions' => array(
'file' => 'mm_theme.inc',
'arguments' => array('element' => NULL)),
'mm_archive_header' => array(
'file' => 'mm_theme.inc',
'arguments' => array('frequency' => NULL, 'date' => NULL,
'date_in_url' => NULL)),
'mm_archive' => array(
'file' => 'mm_theme.inc',
'arguments' => array('list' => NULL, 'frequency' => NULL,
'this_mmtid' => NULL, 'main_mmtid' => NULL, 'archive_mmtid' => NULL,
'date' => NULL)),
'mm_page_wrapper' => array(
'file' => 'mm_theme.inc',
'arguments' => array('title' => NULL, 'body' => NULL, 'attributes' => NULL, 'wrap_body_with_div' => NULL)),
'mm_tabbed_ui' => array(
'file' => 'mm_theme.inc',
'arguments' => array('title' => NULL, 'outer_id' => NULL, 'tabs' => NULL, 'selected' => '', 'before_tabs' => '')),
);
foreach (mm_node_types() as $type) {
$themes = array_merge($themes, $type['themes']);
}
return $themes;
}
/**
* Return "(untitled)" when a node's title is empty
*
* @param $title
* The title
* @return
* The original title, trimmed, or "(untitled)"
*/
function mm_ui_fix_node_title($title) {
$title = trim($title);
if (empty($title)) return t('(untitled)');
return $title;
}
/**
* Hide a node's title when it is surrounded by [brackets]
*
* @param $title
* The title
* @return
* The (possibly hidden) title
*/
function mm_ui_hide_node_title($title) {
return preg_replace('/^\[.*?\]$/', '', $title);
}
/**
* Modify certain form elements to make them appear read-only to the user
*
* @param $form
* The form array
* @param $field_suffix
* String to be inserted into the field names
*/
function mm_ui_perms_readonly(&$form, $field_suffix) {
unset($form["users_$field_suffix-choose"]);
$form["users_$field_suffix"]['#mm_list_readonly'] = TRUE;
$form["users_$field_suffix"]['#mm_list_no_info'] = TRUE;
$form["users_$field_suffix"]['#mm_list_buttons_underneath'] = TRUE;
$form["groups_$field_suffix"]['#mm_list_readonly'] = TRUE;
// Prevent the vertical bar from appearing when there are no groups
if (!count($form["groups_$field_suffix"]['#default_value']))
$form["groups_$field_suffix"]['#mm_list_buttons_underneath'] = TRUE;
}
/**
* Get a list of times of day
*
* $start
* If set, the starting number of minutes past midnight
* $end
* If set, the ending number of minutes past midnight
* $inc
* If set, the increment, in minutes, between times; the smallest supported
* number is 30 minutes
* @return
* An array of times, indexed by the number of minutes past midnight
*/
function mm_ui_hour_list($start = NULL, $end = NULL, $inc = NULL) {
$out = array(0 => t('midnight'), 30 => t('12:30 AM'), 60 => t('1:00 AM'), 90 => t('1:30 AM'), 120 => t('2:00 AM'), 150 => t('2:30 AM'), 180 => t('3:00 AM'), 210 => t('3:30 AM'), 240 => t('4:00 AM'), 270 => t('4:30 AM'), 300 => t('5:00 AM'), 330 => t('5:30 AM'), 360 => t('6:00 AM'), 390 => t('6:30 AM'), 420 => t('7:00 AM'), 450 => t('7:30 AM'), 480 => t('8:00 AM'), 510 => t('8:30 AM'), 540 => t('9:00 AM'), 570 => t('9:30 AM'), 600 => t('10:00 AM'), 630 => t('10:30 AM'), 660 => t('11:00 AM'), 690 => t('11:30 AM'), 720 => t('noon'), 750 => t('12:30 PM'), 780 => t('1:00 PM'), 810 => t('1:30 PM'), 840 => t('2:00 PM'), 870 => t('2:30 PM'), 900 => t('3:00 PM'), 930 => t('3:30 PM'), 960 => t('4:00 PM'), 990 => t('4:30 PM'), 1020 => t('5:00 PM'), 1050 => t('5:30 PM'), 1080 => t('6:00 PM'), 1110 => t('6:30 PM'), 1140 => t('7:00 PM'), 1170 => t('7:30 PM'), 1200 => t('8:00 PM'), 1230 => t('8:30 PM'), 1260 => t('9:00 PM'), 1290 => t('9:30 PM'), 1320 => t('10:00 PM'), 1350 => t('10:30 PM'), 1380 => t('11:00 PM'), 1410 => '11:30 PM');
foreach (array_keys($out) as $key) {
if ($inc && ($key % $inc) != 0)
unset($out[$key]);
if (!is_null($start) && !is_null($end) && ($key < $start || $key >= $end))
unset($out[$key]);
}
return $out;
}
/**
* Get a list of long week day names
*
* @return
* An array of weekday names, starting with Sunday at element 0
*/
function mm_ui_day_list() {
if (function_exists('date_week_days')) return date_week_days(TRUE);
return array(t('Sunday'), t('Monday'), t('Tuesday'), t('Wednesday'), t('Thursday'), t('Friday'), t('Saturday'));
}
// ****************************************************************************
// * Private functions start here
// ****************************************************************************
function _mm_ui_levels() {
$list[-1] = t('(show all levels)');
$list[0] = t('(show only the currently selected level)');
for ($i = 1; $i <= 10; $i++)
$list[$i] = $i;
return $list;
}
/**
* Validation common to copying/moving and editing a tree entry
*/
function _mm_ui_validate_entry($mmtid, $test_mmtid, $form_values, $is_new, $no_dup) {
$x = mm_ui_strings($is_group = mm_content_is_group($test_mmtid));
$test_tree = mm_content_get_tree($test_mmtid, array(MM_GET_TREE_DEPTH => 1, MM_GET_TREE_FILTER_HIDDEN => TRUE));
if (!$test_mmtid || count($test_tree) < ($is_new ? 1 : 2) || !$is_new && $test_tree[1]->parent != $test_tree[0]->mmtid) {
form_set_error('', t('Unexpected tree structure'));
return 0;