forked from hunk/Magic-Fields
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCCWP_WritePostPage.php
1976 lines (1632 loc) · 69.1 KB
/
RCCWP_WritePostPage.php
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
/**
* This class content all type of fields for the panels
*/
// traversal
function RelatedTypeFieldsFilter($fields) {
return "*";
}
function RelatedTypeWhereFilter($where) {
echo $where;
return $where;
}
function RelatedTypeOrderByFilter($orderby) {
global $wpdb;
$orderby = "$wpdb->postmeta.meta_value,$wpdb->posts.post_title";
return $orderby;
}
class RCCWP_WritePostPage {
function mf_category_order($cats,$parent=0,$depth = 0,$resp = array() ){
foreach($cats as $k => $cat){
if($cat->parent == $parent){
$term_id = $cat->term_id;
$resp[$term_id]->term_id = $term_id;
$resp[$term_id]->name = sprintf('%s%s',str_repeat(' ', $depth * 4),$cat->slug);
unset($cats[$k]);
$resp = RCCWP_WritePostPage::mf_category_order($cats,$term_id,$depth+1,$resp);
}
}
return $resp;
}
public static function ApplyWritePanelAssignedCategoriesOrTemplate(){
global $CUSTOM_WRITE_PANEL,$post,$wp_version;
if(substr($wp_version, 0, 3) < 3.0){
$check = "draft";
}else{
$check = "auto-draft";
}
if($post->post_status == $check){
if($post->post_type == "post"){
$assignedCategoryIds = RCCWP_CustomWritePanel::GetAssignedCategoryIds($CUSTOM_WRITE_PANEL->id);
foreach($assignedCategoryIds as $key => $cat){
if((int)$cat == 0){
$tc = get_category_by_slug($cat);
$assignedCategoryIds[$key] = $tc->cat_ID;
}
}
$assignedCategoryIds = apply_filters('mf_extra_categories',$assignedCategoryIds);
?>
<script type="text/javascript">
var mf_categories = new Array(<?php echo '"'.implode('","',$assignedCategoryIds).'"' ?>);
</script>
<?php
wp_enqueue_script( 'magic_set_categories',
MF_URI.'js/custom_fields/categories.js',
array('jquery')
);
}else{
$customParentPage = RCCWP_CustomWritePanel::GetParentPage($CUSTOM_WRITE_PANEL->name);
$customThemePage = RCCWP_CustomWritePanel::GetThemePage($CUSTOM_WRITE_PANEL->name);
?>
<script type="text/javascript">
var mf_parent = <?php printf("'%s'",$customParentPage); ?>;
var mf_theme = <?php printf("'%s'",$customThemePage); ?>;
</script>
<?php
wp_enqueue_script( 'magic_set_categories',
MF_URI.'js/custom_fields/template.js',
array('jquery')
);
}
}
}
public static function FormError(){
global $mf_domain;
if (RCCWP_Application::InWritePostPanel()){
echo "<div id='mf-publish-error-message' class='error' style='display:none;'><p><strong>".__("Post was not published - ",$mf_domain)."</strong> ".__("You have errors in some fields, please check the fields below.",$mf_domain)."</p></div>";
}
}
public static function CustomFieldsCSS(){
?>
<link
rel="stylesheet"
href="<?php echo MF_URI;?>css/base.css"
type="text/css" media="screen" charset="utf-8"
/>
<link
rel="stylesheet"
href="<?php echo MF_URI;?>css/datepicker/ui.datepicker.css"
type="text/css" media="screen" charset="utf-8"
/>
<link rel="stylesheet" type="text/css" href="<?php echo MF_URI;?>js/colorpicker/css/colorpicker.css" media="screen" charset="utf-8" />
<link rel="stylesheet" type="text/css" href="<?php echo MF_URI;?>css/jscrollpane.css" media="screen" charset="utf-8" />
<link rel="stylesheet" type="text/css" href="<?php echo MF_URI; ?>js/markitup/skins/markitup/style.css" />
<link rel="stylesheet" type="text/css" href="<?php echo MF_URI; ?>js/markitup/sets/html/style.css" />
<?php
}
public static function CustomFieldsJavascript(){
global $CUSTOM_WRITE_PANEL;
?>
<script type="text/javascript">
var mf_path = "<?php echo MF_URI ?>" ;
<?php
$nonce_ajax_upload = wp_create_nonce('once_ajax_uplooad');
$nonce_ajax_duplicate = wp_create_nonce('nonce_ajax_duplicate');
if( !( is_user_logged_in() && current_user_can('upload_files') ) ) {
$nonce_ajax_upload = 'Ah ah ah, you didn\'t say the magic word';
$nonce_ajax_duplicate = 'Ah ah ah, you didn\'t say the magic word';
}
?>
var nonce_ajax_upload = "<?php echo $nonce_ajax_upload; ?>";
var nonce_ajax_duplicate = "<?php echo $nonce_ajax_duplicate; ?>";
<?php $mceString = 'Control'; if(is_wp39()){ $mceString = 'Editor'; } ?>
var mceString = "<?php echo $mceString ?>";
</script>
<?php
wp_enqueue_script('jquery-ui-sortable');
//loading jquery ui datepicker
wp_enqueue_script( 'datepicker',
MF_URI.'js/ui.datepicker.js',
array('jquery','jquery-ui-core')
);
//loading core of the datepicker
wp_enqueue_script( 'mf_datepicker',
MF_URI.'js/custom_fields/datepicker.js'
);
$slider_js = MF_URI.'js/ui.slider.js';
//load slider for wp31
if(is_wp31()) $slider_js = MF_URI.'js/jquery.ui.slider.js';
//loading jquery ui slider
wp_enqueue_script( 'slider',
$slider_js,
array('jquery','jquery-ui-core')
,NULL,true
);
//loading the code for delete images
wp_enqueue_script( 'mf_colorpicker',
MF_URI.'js/custom_fields/colorpicker.js'
);
//loading the code for delete images
wp_enqueue_script( 'mf_image',
MF_URI.'js/custom_fields/image.js'
);
//loading handler for upload files
wp_enqueue_script( 'mf_upload',
MF_URI.'js/upload.js'
);
//loading handler for metadata
wp_enqueue_script( 'mf_metadata',
MF_URI.'js/jquery.metadata.js'
);
///loading handler for validate
wp_enqueue_script( 'mf_validate',
MF_URI.'js/jquery.validate.pack.js'
);
//loading the code for validation
wp_enqueue_script( 'mf_validate_fields',
MF_URI.'js/custom_fields/validate.js'
);
//loading jquery scrollpane (group summaries)
wp_enqueue_script( 'jscrollpane',
MF_URI.'js/jquery.jscrollpane.js'
);
//loading jquery scrollpane (group summaries)
wp_enqueue_script( 'windowopen',
MF_URI.'js/jquery.windowopen.min.js'
);
//loading jquery template plugin
wp_enqueue_script( 'tmpl',
MF_URI.'js/jquery.tmpl.js'
);
//loading jquery colorpicker plugin
wp_enqueue_script( 'jquerycolorpicker',
MF_URI.'js/jquery.colorpicker.js'
);
//load affix plugin (for tooltips)
wp_enqueue_script( 'jqueryaffix',
MF_URI.'js/jquery.affix.min.js'
);
//load reveal plugin (for tooltips)
wp_enqueue_script( 'jqueryreveal',
MF_URI.'js/jquery.reveal.min.js'
);
$hide_visual_editor = RCCWP_Options::Get('hide-visual-editor');
if ($hide_visual_editor == '' || $hide_visual_editor == 0){
//loading the code for textarea in validation
wp_enqueue_script( 'mf_editor_validate',
MF_URI.'js/custom_fields/editor_validate.js'
);
}
//markitup
wp_enqueue_script('markitup',
MF_URI.'js/markitup/jquery.markitup.js',
array('jquery')
);
wp_enqueue_script('markitup_set_markdown',
MF_URI.'js/markitup/sets/html/set.js',
array('markitup')
);
wp_enqueue_script('valums_file_uploader',
MF_URI.'js/valumsfileuploader.js'
);
wp_enqueue_script('markitup_setup',
MF_URI.'js/markitup/jquery.markitup.setup.js',
array('markitup')
);
//load script for custom magicfields
if (file_exists(MF_UPLOAD_FILES_DIR.DIRECTORY_SEPARATOR."js".DIRECTORY_SEPARATOR."magic_fields.js")) {
wp_enqueue_script('custom_magic_fields',
MF_FILES_URI.'js/magic_fields.js'
);
}
//load script for custom write panel
if (file_exists(MF_UPLOAD_FILES_DIR.DIRECTORY_SEPARATOR."js".DIRECTORY_SEPARATOR.$CUSTOM_WRITE_PANEL->capability_name.".js")) {
wp_enqueue_script('custom_wp'.$CUSTOM_WRITE_PANEL->capability_name,
MF_FILES_URI.'js/'.$CUSTOM_WRITE_PANEL->capability_name.'.js'
);
}
}
public static function ApplyCustomWritePanelHeader() {
global $CUSTOM_WRITE_PANEL;
global $mf_domain;
// Validate capability
require_once ('RCCWP_Options.php');
$assignToRole = RCCWP_Options::Get('assign-to-role');
$requiredPostsCap = 'edit_posts';
$requiredPagesCap = 'edit_pages';
if ($assignToRole == 1){
$requiredPostsCap = $CUSTOM_WRITE_PANEL->capability_name;
$requiredPagesCap = $CUSTOM_WRITE_PANEL->capability_name;
}
if ($CUSTOM_WRITE_PANEL->type == "post")
$requiredCap = $requiredPostsCap;
else
$requiredCap = $requiredPagesCap;
if (!current_user_can($requiredCap)) wp_die( __('You do not have sufficient permissions to access this custom write panel.',$mf_domain) );
?>
<script type="text/javascript">
var mf_path = "<?php echo MF_URI ?>" ;
var JS_MF_FILES_PATH = '<?php echo MF_FILES_URI ?>';
var swf_authentication = "<?php if ( function_exists('is_ssl') && is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>" ;
var swf_nonce = "<?php echo wp_create_nonce('media-form'); ?>" ;
var lan_editor = "<?php echo ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); ?>";
</script>
<script type="text/javascript" src="<?php echo MF_URI?>js/groups.js"></script>
<script type="text/javascript">
var JS_MF_FILES_PATH = '<?php echo MF_FILES_URI ?>';
var wp_root = "<?php echo get_bloginfo('wpurl');?>";
var mf_path = "<?php echo MF_URI; ?>";
var mf_relative = "<?php echo MF_URI_RELATIVE;?>";
var phpthumb = "<?php echo PHPTHUMB;?>";
var swf_authentication = "<?php if ( function_exists('is_ssl') && is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>" ;
var swf_nonce = "<?php echo wp_create_nonce('media-form'); ?>" ;
var lan_editor = "<?php echo ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); ?>";
</script>
<?php
//change title
global $post,$title;
if($post->ID == 0){
$blu = RCCWP_CustomWritePanel::Get($CUSTOM_WRITE_PANEL->id);
if($post->post_type == "post"){ $name_title = "Post";}
else{$name_title = "Page";}
$title="Write ".$name_title." >> " .$blu->name;
}else{
$blu = RCCWP_CustomWritePanel::Get($CUSTOM_WRITE_PANEL->id);
if($post->post_type == "post"){ $name_title = "Post";}
else{$name_title = "Page";}
$title="Edit " .Inflect::singularize($blu->name);
}
// Show/Hide Panel fields
global $STANDARD_FIELDS;
$standardFields = RCCWP_CustomWritePanel::GetStandardFields($CUSTOM_WRITE_PANEL->id);
$hideCssIds = array();
foreach($STANDARD_FIELDS as $standardField){
if (!in_array($standardField->id, $standardFields)){
foreach($standardField->cssId as $cssID)
array_push($hideCssIds, $cssID);
}
}
if (empty($hideCssIds))
return;
array_walk($hideCssIds, create_function('&$item1, $key', '$item1 = "#" . $item1;'));
$hideCssIdString = implode(', ', $hideCssIds);
?>
<style type="text/css">
<?php echo $hideCssIdString?> {display: none !important;}
</style>
<?php
}
/**
* Drawing our custom fields
*/
public static function CustomFieldCollectionInterface(){
global $CUSTOM_WRITE_PANEL,$wpdb,$mf_domain,$post;
if(empty($CUSTOM_WRITE_PANEL)){
return false;
}
//getting information of the CustomWrite Panel
$groups = RCCWP_CustomWritePanel::GetCustomGroups($CUSTOM_WRITE_PANEL->id, "id");
foreach($groups as $group){
//Only is drawed the group if has at least one field
$hasfields = RCCWP_CustomGroup::HasCustomfields($group->id);
if(!$hasfields){
continue;
}
if($group->name == "__default"){
$lang = get_bloginfo('language');
$name = "Magic Fields Custom Fields";
if($lang == "en-US"){
$name = Inflect::singularize($CUSTOM_WRITE_PANEL->name);
}
}else{
$name = $group->name;
}
add_meta_box(
'panel_'.$group->id,
$name,
array('RCCWP_WritePostPage','metaboxContent'),
$CUSTOM_WRITE_PANEL->type,
'normal',
'high',
$group
);
}
}
public static function metaboxContent($temp,$group) {
global $mf_domain;
global $wpdb;
global $post;
global $CUSTOM_WRITE_PANEL;
$mf_post_id = apply_filters('mf_source_post_data', @$_REQUEST['post']);
//we are passing the group_id in the args of the add_meta_box
$group = $group['args'];
//render the elements
$customFields = RCCWP_CustomGroup::GetCustomFields($group->id);
//when will be edit the Post
if(isset( $mf_post_id ) && count($customFields) > 0){
//using the first field name we can know
//the order of the groups
$firstFieldName = $customFields[0]->name;
$order = RCCWP_CustomField::GetOrderDuplicates($mf_post_id,$firstFieldName);
?>
<div class="write_panel_wrapper" id="write_panel_wrap_<?php echo $group->id;?>">
<?php if ($group->duplicate) : ?>
<div class="mf-group-controls">
<div class="mf-group-count"></div>
<div class="buttons">
<a href="#" class="mf-expand-all-button"><?php _e('Expand All', $mf_domain);?></a>
<a href="#" class="mf-collapse-all-button"><?php _e('Collapse All', $mf_domain);?></a>
</div>
</div>
<?php endif; ?>
<div class="mf-group-save-warning"><?php _e("Note: to save your changes you must also <strong>Publish</strong> or <strong>Update</strong>",$mf_domain);?><?php //echo $post->post_type;?>.</div>
<?php
//build the group duplicates
foreach($order as $key => $element){
RCCWP_WritePostPage::GroupDuplicate($group,$element,$key,false);
}
//knowing what is the biggest duplicate group
if(!empty($order)){
$tmp = $order;
sort($tmp);
$top = $tmp[count($tmp) -1];
}else{
$top = 0;
}
?>
<input type='hidden' name='g<?php echo $group->id?>counter' id='g<?php echo $group->id?>counter' value='<?php echo $top ?>' />
</div>
<?php
}else{
?>
<div class="write_panel_wrapper" id="write_panel_wrap_<?php echo $group->id;?>">
<?php if ($group->duplicate) : ?>
<div class="mf-group-controls">
<div class="mf-group-count"></div>
<div class="buttons">
<a href="#" class="mf-expand-all-button">Expand All</a>
<a href="#" class="mf-collapse-all-button">Collapse All</a>
</div>
</div>
<?php endif; ?>
<div class="mf-group-save-warning"><?php _e("Note: to save your changes you must also <strong>Publish</strong> or <strong>Update</strong>",$mf_domain);?><?php //echo $post->post_type;?>.</div>
<?php
RCCWP_WritePostPage::GroupDuplicate($group,1,1,false);
$gc = 1;
?>
<input type='hidden' name='g<?php echo $group->id;?>counter' id='g<?php echo $group->id?>counter' value='<?php echo $gc?>' />
</div>
<?php
}
}
/**
*
* @param object $customGroup
* @param integer $groupCounter
* @param boolean $fromAjax
*
*/
public static function GroupDuplicate($customGroup, $groupCounter,$order,$fromAjax=true){
global $mf_domain;
global $CUSTOM_WRITE_PANEL;
$ex_class = $customGroup->expanded ? "mf-group-expanded" : '';
if ($customGroup->name == "__default") {
// for the default group (top level), check the expand flag on the WRITE PANEL instead
$ex_class = $CUSTOM_WRITE_PANEL->expanded ? "mf-group-expanded" : '';
}
$mf_post_id = apply_filters('mf_source_post_data', @$_REQUEST['post']);
//getting the custom fields
$customFields = RCCWP_CustomGroup::GetCustomFields($customGroup->id);
//if don't have fields then finish
if (count($customFields) == 0) return;
require_once("RC_Format.php");
if( $customGroup->duplicate != 0 ){
$add_class_rep="mf_duplicate_group";}else{$add_class_rep="";
}
?>
<div class="magicfield_group <?php echo $add_class_rep;?> <?php echo $ex_class ?>" id="freshpostdiv_group_<?php
echo $customGroup->id.'_'.$groupCounter;?>">
<a id="collapse_<?php echo $customGroup->id."Duplicate"."_".$customGroup->id."_".$order;?>" class="collapse_button" href="javascript:void(0);">Collapse</a>
<div class="mf-group-loading"><?php _e('Loading Data…', $mf_domain);?></div>
<div>
<div class="inside">
<div class="mf-fields">
<?php
foreach ($customFields as $field) {
$customFieldName = $field->name;
$customFieldTitle = esc_attr($field->description);
$groupId = $customGroup->id;
$inputName = $field->id."_".$groupCounter."_1_".$groupId."_".$customFieldName;
if(isset($mf_post_id)){
$fc = RCCWP_CustomField::GetFieldDuplicates($mf_post_id,$field->name,$groupCounter);
$fields_order = RCCWP_CustomField::GetFieldsOrder($mf_post_id,$field->name,$groupCounter);
foreach($fields_order as $element){
RCCWP_WritePostPage::CustomFieldInterface($field->id,$groupCounter,$element,$customGroup->id);
}
}else{
RCCWP_WritePostPage::CustomFieldInterface($field->id,$groupCounter,1,$customGroup->id);
$fc = 1;
}
if(!empty($fields_order)){
$tmp = $fields_order;
sort($tmp);
$top = $tmp[count($tmp) -1];
}else{
$top = 1;
}
?>
<span style="display:none" id="<?php echo "c".$inputName."Duplicate"?>">
<input type="text" name="c<?php echo $inputName ?>Counter" id="c<?php echo $inputName ?>Counter" value='<?php echo $top ?>' />
</span>
<?php } ?>
</div>
<!-- /.mf-fields -->
<?php
if( $customGroup->duplicate != 0 ){
$sgn = Inflect::singularize($customGroup->name);
?>
<div class="mf_toolbox">
<span class="mf_counter sortable_mf" id="counter_<?php echo $customGroup->id;?>_<?php echo $groupCounter;?>"><?php echo $order;?></span>
<span class="hndle sortable_mf row_mf"> </span>
<span class="mf_toolbox_controls">
<?php
if($groupCounter != 1):
?>
<a class ="delete_duplicate_button { lang: { confirm: '<?php _e("Are you sure?", $mf_domain) ?>' } }" href="javascript:void(0);" id="delete_duplicate-freshpostdiv_group_<?php echo $customGroup->id.'_'.$groupCounter; ?>"><span><?php _e('Remove', $mf_domain); ?></span> <?php echo $sgn ?></a>
<?php else:?>
<a id="add_duplicate_<?php echo $customGroup->id."Duplicate"."_".$customGroup->id."_".$order;?>" class="duplicate_button" href="javascript:void(0);" title="<?php _e('Note: hold down the SHIFT key as you click to collapse this item before the new item is added', $mf_domain); ?>"><span><?php _e('Add Another', $mf_domain);?></span> <?=$sgn?></a>
<?php endif;?>
</span>
</div>
<?php
}
?>
</div>
</div>
<input type="hidden" name="order_<?php echo $customGroup->id?>_<?php echo $groupCounter;?>" id="order_<?php echo $customGroup->id?>_<?php echo $groupCounter;?>" value="<?php echo $order?>" />
</div>
<?php
}
/**
* @todo Add documentation
*/
public static function CustomFieldInterface($customFieldId, $groupCounter=1, $fieldCounter=1,$customGroup_id=0){
global $mf_domain;
require_once("RC_Format.php");
$customField = RCCWP_CustomField::Get($customFieldId);
$customFieldName = $customField->name;
$customFieldTitle = esc_attr($customField->description);
$customFieldHelp = $customField->help_text; // htmlentities($customField->help_text,ENT_COMPAT,'UTF-8');
$groupId = $customGroup_id;
$inputCustomName = $customFieldId."_".$groupCounter."_".$fieldCounter."_".$groupId."_".$customFieldName; // Create input tag name
$inputName = "magicfields[{$customFieldName}][{$groupCounter}][{$fieldCounter}]";
if( $fieldCounter > 1 && $customField->duplicate == 0 ) return ;
if( $fieldCounter > 1) $titleCounter = " (<span class='counter_{$customFieldName}_{$groupCounter}'>$fieldCounter</span>)";
$field_group = RCCWP_CustomGroup::Get($customField->group_id);
/*
* Add the lang attribute if last part of the field name matches defined languages
*
* define( 'ADMIN_LANGS', 'en|fr|de' );
* example: field name 'the_about_text_en' matches 'en' and sets ' lang="en"'
*
*/
if( defined( 'ADMIN_LANGS' ) ) {
$customFieldNameParts = explode( '_', $customFieldName );
$lang_switch = ( preg_match( '/'.ADMIN_LANGS.'/', $customFieldNameParts[ sizeof( $customFieldNameParts) - 1 ] ) ) ? ' lang="'.$customFieldNameParts[ sizeof( $customFieldNameParts) - 1 ].'"' : '';
}else {
$lang_switch = '';
}
if( isset( $customField->properties['strict-max-length'] ) && $customField->properties['strict-max-length'] == 1 ) {
$fieldMaxLengthClass = ' maxlength';
}else {
$fieldMaxLengthClass = '';
}
$fieldCustomClass = "mf-field-$customFieldName"; // allows some special styling in wordpress filters
$duplicateClass = "";
if ($fieldCounter > 1) {
$duplicateClass = "mf-field-duplicate";
}
?>
<div class="mf-field <?php echo $duplicateClass ?> <?php echo $fieldCustomClass ?> mf-t-<?php echo strtolower(str_replace(" ","-",$customField->type)); ?> <?php echo str_replace(" ","_",$customField->type); echo $fieldMaxLengthClass; ?>" id="row_<?php echo $inputCustomName?>"<?php echo $lang_switch;?>>
<div class="mf-field-title">
<label for="<?php echo $inputCustomName?>">
<?php
if(empty($titleCounter)){
$titleCounter = "";
}
?>
<span class="name"><?php echo $customFieldTitle?><em><?php echo $titleCounter ?></em></span>
<?php
if( $customField->required_field == 1 ) { ?> <span class="required">*</span><?php }
if (!empty($customFieldHelp)) {?>
<small class="tip"><?php _e("what's this?",$mf_domain);?><span class="field_help"><?php echo $customFieldHelp; ?></span></small>
<?php }
if( isset( $customField->properties['strict-max-length'] ) && $customField->properties['strict-max-length'] == 1 ) {
if( $customField->type == 'Multiline Textbox' ) {
$charsRemainingSize = $customField->properties['height']*$customField->properties['width'];
}else {
$charsRemainingSize = $customField->properties['size'];
}
?><small class="remaining"><?php _e( 'Characters left', $mf_domain )?>: <span class="charsRemaining" title="<?php _e('Characters left', $mf_domain); ?>"><?=$charsRemainingSize?></span></small><?php
}
?>
</label>
</div>
<!-- /.mf-field-title -->
<div>
<p class="error_msg_txt" id="fieldcellerror_<?php echo $inputCustomName?>" style="display:none"></p>
<?php
switch ($customField->type) {
case 'Textbox' :
RCCWP_WritePostPage::TextboxInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Multiline Textbox' :
RCCWP_WritePostPage::MultilineTextboxInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Checkbox' :
RCCWP_WritePostPage::CheckboxInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Checkbox List' :
RCCWP_WritePostPage::CheckboxListInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Radiobutton List' :
RCCWP_WritePostPage::RadiobuttonListInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Dropdown List' :
RCCWP_WritePostPage::DropdownListInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Listbox' :
RCCWP_WritePostPage::ListboxInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'File' :
RCCWP_WritePostPage::FileInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Image' :
RCCWP_WritePostPage::PhotoInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Date' :
RCCWP_WritePostPage::DateInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Audio' :
RCCWP_WritePostPage::AudioInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Color Picker' :
RCCWP_WritePostPage::ColorPickerInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Slider' :
RCCWP_WritePostPage::SliderInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Related Type' :
RCCWP_WritePostPage::RelatedTypeInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Markdown Textbox' :
RCCWP_WritePostPage::MarkdownTextboxInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
case 'Image (Upload Media)' :
RCCWP_WritePostPage::MediaPhotoInterface($customField, $inputName, $groupCounter, $fieldCounter);
break;
default:
;
}
?>
<div class="mf-duplicate-controls">
<?php
$cfd = Inflect::singularize($customField->description);
if($fieldCounter == 1) {
?>
<?php if($customField->duplicate != 0 ){ ?>
<a href="javascript:void(0);" id="type_handler-<?php echo $inputCustomName ?>" class="typeHandler duplicate_field"><span><?php _e('Add Another', $mf_domain); ?></span> <?php echo $cfd ?></a>
<?php } ?>
<?php
}
else {
?>
<a class="delete_duplicate_field" href="javascript:void(0)" id="delete_field_repeat-<?php echo $inputCustomName?>"><span><?php _e('Remove', $mf_domain); ?></span> <?php echo $cfd ?></a>
<?php
}
?>
</div>
<!-- ./title-controls -->
</div>
</div>
<?php
}
public static function CheckboxInterface($customField, $inputName, $groupCounter, $fieldCounter) {
$customFieldId = '';
$idField = RCCWP_WritePostPage::changeNameInput($inputName);
$mf_post_id = apply_filters('mf_source_post_data', @$_REQUEST['post']);
if (isset($mf_post_id))
{
$customFieldId = $customField->id;
$value = RCCWP_CustomField::GetCustomFieldValues(true, $mf_post_id, $customField->name, $groupCounter, $fieldCounter);
$checked = $value == 'true' ? 'checked="checked"' : '';
}else{
$checked = "";
}
?>
<div class="mf_custom_field">
<input type="hidden" name="<?php echo $inputName?>_1" value="false" />
<input tabindex="3" class="checkbox checkbox_mf" <?php if ($customField->required_field) echo 'validate="required:true"'; ?> name="<?php echo $inputName?>" value="true" id="<?php echo $idField;?>" type="checkbox" <?php echo $checked?> /></div>
<?php if ($customField->required_field){ ?>
<div class="mf_message_error"><label for="<?php echo $inputName?>" class="error_magicfields error block"><?php _e("This field is required",$mf_domain)?></label></div>
<?php }
}
public static function CheckboxListInterface($customField, $inputName, $groupCounter, $fieldCounter) {
$mf_post_id = apply_filters('mf_source_post_data', @$_REQUEST['post']);
$customFieldId = '';
$defClass = '';
$idField = RCCWP_WritePostPage::changeNameInput($inputName);
$values = array();
if (isset($mf_post_id)) {
$customFieldId = $customField->id;
$values = (array) RCCWP_CustomField::GetCustomFieldValues(false, $mf_post_id, $customField->name, $groupCounter, $fieldCounter);
}else{
$defClass = "mf-default";
$values = $customField->default_value;
}
?>
<div class="mf_custom_field <?php echo $defClass ?>">
<?php
foreach ($customField->options as $option) :
$checked = in_array($option, (array)$values) ? 'checked="checked"' : '';
$option = esc_attr(trim($option));
?>
<label for="<?php echo $inputName.'_'.$option;?>" class="selectit mf-checkbox-list">
<input tabindex="3" <?php if ($customField->required_field) echo 'validate="required:true"'; ?> class="checkbox_list_mf" id="<?php echo $inputName.'_'.$option;?>" name="<?php echo $inputName?>[]" value="<?php echo $option?>" type="checkbox" <?php echo $checked?> />
<?php echo esc_attr($option)?>
</label><br />
<?php
endforeach;
?></div>
<?php if ($customField->required_field){ ?>
<div class="mf_message_error"><label for="<?php echo $inputName?>[]" class="error_magicfields error"><?php _e("This field is required",$mf_domain)?></label></div>
<?php } ?>
<?php
}
public static function DropdownListInterface($customField, $inputName, $groupCounter, $fieldCounter)
{
global $mf_domain;
$customFieldId = '';
$mf_post_id = apply_filters('mf_source_post_data', @$_REQUEST['post']);
$defClass = '';
if (isset($mf_post_id)) {
$customFieldId = $customField->id;
$value = esc_attr(RCCWP_CustomField::GetCustomFieldValues(true, $mf_post_id, $customField->name, $groupCounter, $fieldCounter));
} else {
$defClass = "mf-default";
$value = $customField->default_value[0];
}
$requiredClass = "";
if ($customField->required_field) $requiredClass = "field_required";
?>
<div class="mf_custom_field <?php echo $defClass ?>">
<select tabindex="3" <?php if ($customField->required_field) echo 'validate="required:true"'; ?> class="<?php echo $requiredClass;?> listbox_mf" name="<?php echo $inputName?>">
<option value=""><?php _e('--Select--', $mf_domain); ?></option>
<?php
foreach ($customField->options as $option) :
$selected = esc_attr($option) == $value ? 'selected="selected"' : '';
$option = esc_attr(trim($option));
?>
<option value="<?php echo $option?>" <?php echo $selected?>><?php echo $option?></option>
<?php
endforeach;
?>
</select> </div>
<?php if ($customField->required_field){ ?>
<div class="mf_message_error"><label for="<?php echo $inputName?>" class="error_magicfields error"><?php _e("This field is required",$mf_domain)?></label></div>
<?php }
}
//eeble
public static function RelatedTypeInterface($customField, $inputName, $groupCounter, $fieldCounter) {
global $mf_domain, $wpdb;
$mf_post_id = apply_filters('mf_source_post_data', @$_REQUEST['post']);
$customFieldId = '';
if (isset($mf_post_id)) {
$customFieldId = $customField->id;
$value = esc_attr(RCCWP_CustomField::GetCustomFieldValues(true, $mf_post_id, $customField->name, $groupCounter, $fieldCounter));
} else {
$value = $customField->default_value[0];
}
//get id of related type / panel
$panel_id = (int)$customField->properties['panel_id'];
$requiredClass = "";
if ($customField->required_field) { $requiredClass = "field_required"; }
?>
<div class="mf_custom_field">
<select tabindex="3" <?php if ($customField->required_field) echo 'validate="required:true"'; ?> class="<?php echo $requiredClass;?> listbox_mf" name="<?php echo $inputName?>">
<option value=""><?php _e('--Select--', $mf_domain); ?></option>
<?php
$pn_cache = array(); // setup a panel name cache (so we only look up the panel name ONCe for each panel ID)
if($panel_id == -4){
$options=get_posts("post_type=post&numberposts=-1&order=ASC&orderby=title");
}elseif($panel_id == -3){
$options=get_posts("post_type=page&numberposts=-1&order=ASC&orderby=title");
}elseif($panel_id == -2){
$options=get_posts("post_type=post&meta_key=_mf_write_panel_id&numberposts=-1&order=ASC&orderby=title");
}elseif($panel_id == -1){
$options=get_posts("post_type=page&meta_key=_mf_write_panel_id&numberposts=-1&order=ASC&orderby=title");
}elseif($panel_id == -6){
$options=get_posts("post_type=any&numberposts=-1");
}elseif($panel_id == -7){
$options=get_categories("hide_empty=0");
$options = RCCWP_WritePostPage::mf_category_order($options,0,0);
}elseif($panel_id == -5){
remove_filter('posts_where', array('RCCWP_Query','ExcludeWritepanelsPosts'));
add_filter('posts_fields', 'RelatedTypeFieldsFilter');
add_filter('posts_orderby', 'RelatedTypeOrderByFilter');
$options = get_posts( array(
'suppress_filters' => false,
'post_type' => 'any',
'meta_key' => '_mf_write_panel_id',
'nopaging' => true,
'order' => 'ASC'
));
remove_filter('posts_fields', 'RelatedTypeFieldsFilter');
remove_filter('posts_orderby', 'RelatedTypeOrderByFilter');
add_filter('posts_where', array('RCCWP_Query','ExcludeWritepanelsPosts'));
}else{
$options=get_posts("post_type=any&meta_key=_mf_write_panel_id&numberposts=-1&meta_value=$panel_id&order=ASC&orderby=title");
}
$last_panel_name = ""; // traversal (for grouping)
foreach ($options as $option) :
/* TRAVERSAL ADDITION - Adds grouping of related type fields when all write panels are listed -- */
$panel_name = "";
$display_panel_name = "";
if ( $panel_id == -5 || $panel_id == -2 || $panel_id == -1 ) {
$panel_name = $pn_cache[$option->meta_value];
if (!$panel_name) {
// look it up
$sql = $wpdb->prepare( "SELECT name FROM ".MF_TABLE_PANELS." WHERE id = %d", array( $option->meta_value ) );
$panel_name = $wpdb->get_var($sql);
if ($panel_name) {
$pn_cache[$option->meta_value] = $panel_name;
}
}
$panel = RCCWP_CustomWritePanel::Get($option->meta_value);
if (!$panel_name) {
$panel_name = "";
$display_panel_name = "";
} else {
if ($panel->single) {
$display_panel_name = "";
}
else {
$display_panel_name = " ".Inflect::singularize($panel_name)." - ";
}
}
if ($panel_name != "" && $panel_name != $last_panel_name) {
if ($last_panel_name != "") {
echo "</optgroup>";
}
if ($panel->single) {
$last_panel_name = "";
} else {
echo '<optgroup label="'.Inflect::pluralize($panel_name).'">';
$last_panel_name = $panel_name;
}
}
}
/* END TRAVERSAL ADDITION */
if( $panel_id == -7 ) {
$selected = $option->term_id == $value ? 'selected="selected"' : '';
?>
<option value="<?php echo $option->term_id ?>" <?php echo $selected?>><?php echo $display_panel_name.$option->name ?></option><!-- TRAVERSAL UPDATE, adds display panel name as prefix -->
<?php
}else {
$selected = $option->ID == $value ? 'selected="selected"' : '';
?>
<option value="<?php echo $option->ID ?>" <?php echo $selected?>><?php echo $display_panel_name.$option->post_title ?></option><!-- TRAVERSAL UPDATE, adds display panel name as prefix -->
<?php
}
endforeach;
// TRAVERSAL ADDITION, closes optgroup
if ($last_panel_name != "") {
echo "</optgroup>";
}
// END TRAVERSAL ADDITION
?>