/
CFDBViewShortCodeBuilder.php
1612 lines (1493 loc) · 85.6 KB
/
CFDBViewShortCodeBuilder.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
/*
"Contact Form to Database" Copyright (C) 2011-2014 Michael Simpson (email : michael.d.simpson@gmail.com)
This file is part of Contact Form to Database.
Contact Form to Database is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Contact Form to Database is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Contact Form to Database.
If not, see <http://www.gnu.org/licenses/>.
*/
require_once('CF7DBPlugin.php');
require_once('CFDBView.php');
require_once('CFDBShortCodeContentParser.php');
class CFDBViewShortCodeBuilder extends CFDBView {
/**
* @param $plugin CF7DBPlugin
* @return void
*/
function display(&$plugin) {
if ($plugin == null) {
$plugin = new CF7DBPlugin;
}
$this->pageHeader($plugin);
$siteUrl = get_option('home');
$user = wp_get_current_user();
$userName = $user ? $user->user_login : '';
// Identify which forms have data in the database
global $wpdb;
$tableName = $plugin->getSubmitsTableName();
$rows = $wpdb->get_results("select distinct `form_name` from `$tableName` order by `form_name`");
// if ($rows == null || count($rows) == 0) {
// _e('No form submissions in the database', 'contact-form-7-to-database-extension');
// return;
// }
// Collect any values in $_REQUEST to pre-populate the page controls
$postedForm = $this->getRequestParam('form');
$postedEnc = $this->getRequestParam('enc');
$postedSC = $this->getRequestParam('sc');
$postedTrans = $this->getRequestParam('trans');
$postedShow = $this->getRequestParam('show');
$postedHide = $this->getRequestParam('hide');
$postedRole = $this->getRequestParam('role');
$postedPermissionmsg = $this->getRequestParam('permissionmsg');
$postedSearch = $this->getRequestParam('search');
$postedFilter = $this->getRequestParam('filter');
$postedTSearch = $this->getRequestParam('tsearch');
$postedTFilter = $this->getRequestParam('tfilter');
$postedLimit = $this->getRequestParam('limit');
$postedTLimit = $this->getRequestParam('tlimit');
$postedLimitComponents = explode(',', $postedLimit);
$postedLimitStart = '';
$postedLimitNumRows = '';
switch (count($postedLimitComponents)) {
case 2:
$postedLimitStart = $postedLimitComponents[0];
$postedLimitNumRows = $postedLimitComponents[1];
break;
case 1:
$postedLimitNumRows = $postedLimitComponents[0];
break;
default:
break;
}
$postedUnbuffered = $this->getRequestParam('unbuffered');
$postedRandom = $this->getRequestParam('random');
$postedOrderby = $this->getRequestParam('orderby');
$postedTOrderby = $this->getRequestParam('torderby');
$postedHeader = $this->getRequestParam('header');
$postedHeaders = $this->getRequestParam('headers');
$postedItemtitle = $this->getRequestParam('itemtitle');
$postedId = $this->getRequestParam('id');
$postedClass = $this->getRequestParam('class');
$postedStyle = $this->getRequestParam('style');
$postedEdit = $this->getRequestParam('edit');
$postedDtOptions = $this->getRequestParam('dt_options');
$postedVar = $this->getRequestParam('var');
$postedFormat = $this->getRequestParam('format');
$postedFunction = $this->getRequestParam('function');
$postedDelimiter = $this->getRequestParam('delimiter');
$postedFilelinks = $this->getRequestParam('filelinks');
$postedWpautop = $this->getRequestParam('wpautop');
$postedStripbr = $this->getRequestParam('stripbr');
$postedContent = $this->getRequestParam('content');
$postedContentBefore = '';
$postedContentAfter = '';
if ($postedContent) {
$parser = new CFDBShortCodeContentParser;
list($postedContentBefore, $postedContent, $postedContentAfter) = $parser->parseBeforeContentAfter($postedContent);
}
$postedUrlonly = $this->getRequestParam('urlonly');
$postedLinktext = $this->getRequestParam('linktext');
$infoImg = $plugin->getPluginFileUrl('/img/info.jpg');
?>
<script type="text/javascript" language="JavaScript">
var shortCodeDocUrls = {
'' : 'http://cfdbplugin.com/?page_id=89',
'[cfdb-html]' : 'http://cfdbplugin.com/?page_id=284',
'[cfdb-table]' : 'http://cfdbplugin.com/?page_id=93',
'[cfdb-datatable]' : 'http://cfdbplugin.com/?page_id=91',
'[cfdb-value]' : 'http://cfdbplugin.com/?page_id=98',
'[cfdb-count]' : 'http://cfdbplugin.com/?page_id=278',
'[cfdb-json]' : 'http://cfdbplugin.com/?page_id=96',
'[cfdb-export-link]' : 'http://cfdbplugin.com/?page_id=419'
};
function showHideOptionDivs() {
var shortcode = jQuery('#shortcode_ctrl').val();
jQuery('#doc_url_tag').attr('href', shortCodeDocUrls[shortcode]);
jQuery('#doc_url_tag').html(shortcode + " <?php _e('Documentation', 'contact-form-7-to-database-extension'); ?>");
switch (shortcode) {
case "[cfdb-html]":
jQuery('#show_hide_div').show();
jQuery('#limitorder_div').show();
jQuery('#html_format_div').hide();
jQuery('#dt_options_div').hide();
jQuery('#json_div').hide();
jQuery('#value_div').hide();
jQuery('#template_div').show();
jQuery('#url_link_div').hide();
jQuery('#headers_div').hide();
break;
case "[cfdb-table]":
jQuery('#show_hide_div').show();
jQuery('#limitorder_div').show();
jQuery('#html_format_div').show();
jQuery('#dt_options_div').hide();
jQuery('#json_div').hide();
jQuery('#value_div').hide();
jQuery('#template_div').hide();
jQuery('#url_link_div').hide();
jQuery('#headers_div').show();
break;
case "[cfdb-datatable]":
jQuery('#show_hide_div').show();
jQuery('#limitorder_div').show();
jQuery('#html_format_div').show();
jQuery('#dt_options_div').show();
jQuery('#json_div').hide();
jQuery('#value_div').hide();
jQuery('#template_div').hide();
jQuery('#url_link_div').hide();
jQuery('#headers_div').show();
break;
case "[cfdb-value]":
jQuery('#show_hide_div').show();
jQuery('#limitorder_div').show();
jQuery('#html_format_div').hide();
jQuery('#dt_options_div').hide();
jQuery('#json_div').hide();
jQuery('#value_div').show();
jQuery('#template_div').hide();
jQuery('#url_link_div').hide();
jQuery('#headers_div').hide();
break;
case "[cfdb-count]":
jQuery('#show_hide_div').hide();
jQuery('#limitorder_div').hide();
jQuery('#html_format_div').hide();
jQuery('#dt_options_div').hide();
jQuery('#json_div').hide();
jQuery('#value_div').hide();
jQuery('#template_div').hide();
jQuery('#url_link_div').hide();
jQuery('#headers_div').hide();
break;
case "[cfdb-json]":
jQuery('#show_hide_div').show();
jQuery('#limitorder_div').show();
jQuery('#html_format_div').hide();
jQuery('#dt_options_div').hide();
jQuery('#json_div').show();
jQuery('#value_div').hide();
jQuery('#template_div').hide();
jQuery('#url_link_div').hide();
jQuery('#headers_div').show();
break;
case "[cfdb-export-link]":
jQuery('#show_hide_div').show();
jQuery('#limitorder_div').show();
jQuery('#html_format_div').hide();
jQuery('#dt_options_div').hide();
jQuery('#json_div').hide();
jQuery('#value_div').hide();
jQuery('#template_div').hide();
jQuery('#url_link_div').show();
jQuery('#headers_div').show();
break;
default:
jQuery('#show_hide_div').show();
jQuery('#limitorder_div').show();
jQuery('#html_format_div').hide();
jQuery('#dt_options_div').hide();
jQuery('#json_div').hide();
jQuery('#value_div').hide();
jQuery('#template_div').hide();
jQuery('#url_link_div').hide();
jQuery('#headers_div').hide();
break;
}
var exportSelected = jQuery('#export_cntl').val();
jQuery('#label_export_link').show();
jQuery('#label_gld_function').hide();
jQuery('#userpass_span_msg').show();
jQuery('#gld_userpass_span_msg').hide();
if (exportSelected) {
if (exportSelected == 'RSS') {
jQuery('#itemtitle_span').show();
}
else {
jQuery('#itemtitle_span').hide();
jQuery('#headers_div').show();
if (exportSelected == "GLD") {
jQuery('#userpass_span_msg').hide();
jQuery('#gld_userpass_span_msg').show();
jQuery('#label_export_link').hide();
jQuery('#label_gld_function').show();
}
if (exportSelected == "JSON") {
jQuery('#json_div').show();
}
else {
jQuery('#json_div').hide();
}
}
} else {
jQuery('#itemtitle_span').hide();
jQuery('#userpass_span_msg').show();
jQuery('#gld_userpass_span_msg').hide();
jQuery('#label_gld_script').hide();
}
}
function getValue(attr, value, errors) {
if (value) {
if (errors && value.indexOf('"') > -1) {
errors.push('<?php _e('Error: "', 'contact-form-7-to-database-extension'); ?>'
+ attr +
'<?php _e('" should not contain double-quotes (")', 'contact-form-7-to-database-extension'); ?>');
value = value.replace('"', "'");
}
return attr + '="' + value + '"';
}
return '';
}
function pushNameValue(attr, value, array, errors) {
if (value) {
if (errors && value.indexOf('"') > -1) {
errors.push('<?php _e('Error: "', 'contact-form-7-to-database-extension'); ?>'
+ attr +
'<?php _e('" should not contain double-quotes (")', 'contact-form-7-to-database-extension'); ?>');
value = value.replace('"', "'");
}
array.push(attr);
array.push(value);
return true;
}
return false;
}
function getValueUrl(attr, value) {
if (value) {
return attr + '=' + encodeURIComponent(value)
}
return '';
}
function join(arr, delim) {
if (delim == null) {
delim = ' ';
}
var tmp = [];
for (idx=0; idx<arr.length; idx++) {
if (arr[idx] != '') {
tmp.push(arr[idx]);
}
}
return tmp.join(delim);
}
function chopLastChar(text) {
return text ? text.substr(0, text.length - 1) : text;
}
function createShortCodeAndExportLink() {
var scElements = [];
var scUrlElements = [];
var scValidationErrors = [];
var exportUrlElements = [];
var exportValidationErrors = [];
var googleScriptElements = [];
var googleScriptValidationErrors = [];
var shortcode = jQuery('#shortcode_ctrl').val();
if (shortcode == '') {
jQuery('#shortcode_result_text').html('');
}
scElements.push(chopLastChar(shortcode));
var pushErrorMessagesToAll = function(errMsg) {
scValidationErrors.push(errMsg);
exportValidationErrors.push(errMsg);
googleScriptValidationErrors.push(errMsg);
};
var formName = jQuery('#form_name_cntl').val();
var errMsg;
if (!formName) {
errMsg = '<?php _e('Error: no form is chosen', 'contact-form-7-to-database-extension') ?>';
jQuery('#form_validations_text').html(errMsg);
pushErrorMessagesToAll(errMsg);
}
else {
jQuery('#form_validations_text').html('');
scElements.push('form="' + formName + '"');
scUrlElements.push('form=' + encodeURIComponent(formName));
exportUrlElements.push('form=' + encodeURIComponent(formName));
googleScriptElements.push('<?php echo $siteUrl ?>');
googleScriptElements.push(formName);
googleScriptElements.push('<?php echo is_user_logged_in() ?
wp_get_current_user()->user_login :
'user' ?>');
googleScriptElements.push('<password>');
}
var pushValueToAll = function(name, val) {
scElements.push(getValue(name, val, scValidationErrors));
scUrlElements.push(getValueUrl(name, val));
exportUrlElements.push(getValueUrl(name, val));
pushNameValue(name, val, googleScriptElements, googleScriptValidationErrors);
};
var val;
if (shortcode != '[cfdb-count]') {
val = jQuery('#show_cntl').val();
pushValueToAll('show', val);
val = jQuery('#hide_cntl').val();
pushValueToAll('hide', val);
}
val = jQuery('#role_cntl').val();
pushValueToAll('role', val);
val = jQuery('#permissionmsg_cntl').val();
pushValueToAll('permissionmsg', val);
val = jQuery('#trans_cntl').val();
pushValueToAll('trans', val);
var handleFilterSearch = function(filterName, filter, searchName, search) {
if (filter) {
pushValueToAll(filterName, filter);
if (search) {
var errMsg = '<?php _e('Warning: "search" field ignored because FIELD is used (use one but not both)', 'contact-form-7-to-database-extension'); ?>'.replace('FIELD', filterName);
pushErrorMessagesToAll(errMsg);
}
}
else {
pushValueToAll(searchName, search);
}
};
var filter = jQuery('#filter_cntl').val();
var search = jQuery('#search_cntl').val();
handleFilterSearch('filter', filter, 'search', search);
var tfilter = jQuery('#tfilter_cntl').val();
var tsearch = jQuery('#tsearch_cntl').val();
handleFilterSearch('tfilter', tfilter, 'tsearch', tsearch);
if (shortcode != '[cfdb-count]') {
var handleLimit = function (limitName, limitRows, limitStart) {
if (limitStart && !limitRows) {
errMsg = '<?php _e('Error: "FIELD": if you provide a value for "Start Row" then you must also provide a value for "Num Rows"', 'contact-form-7-to-database-extension'); ?>'.replace('FIELD', limitName);
pushErrorMessagesToAll(errMsg);
}
if (limitRows) {
if (!/^\d+$/.test(limitRows)) {
errMsg = '<?php _e('Error: "FIELD": "Num Rows" must be a positive integer', 'contact-form-7-to-database-extension'); ?>'.replace('FIELD', limitName);
pushErrorMessagesToAll(errMsg);
}
else {
var limitOption = '';
var limitOptionUrl = limitName + '=';
if (limitStart) {
if (!/^\d+$/.test(limitStart)) {
errMsg = '<?php _e('Error: "FIELD": "Start Row" must be a positive integer', 'contact-form-7-to-database-extension'); ?>'.replace('FIELD', limitName);
pushErrorMessagesToAll(errMsg);
}
else {
limitOption += limitStart + ",";
limitOptionUrl += encodeURIComponent(limitStart + ",");
}
}
limitOption += limitRows;
limitOptionUrl += limitRows;
scElements.push(limitName + '="' + limitOption + '"');
scUrlElements.push(limitOptionUrl);
exportUrlElements.push(limitOptionUrl);
pushNameValue(limitName, limitOption, googleScriptElements, googleScriptValidationErrors);
}
}
};
var limitRows = jQuery('#limit_rows_cntl').val();
var limitStart = jQuery('#limit_start_cntl').val();
handleLimit('limit', limitRows, limitStart);
var tlimitRows = jQuery('#tlimit_rows_cntl').val();
var tlimitStart = jQuery('#tlimit_start_cntl').val();
handleLimit('tlimit', tlimitRows, tlimitStart);
val = jQuery('#random_cntl').val();
scElements.push(getValue('random', val, scValidationErrors));
scUrlElements.push(getValueUrl('random', val));
pushNameValue("random", val, googleScriptElements, googleScriptValidationErrors);
if (jQuery('#unbuffered_cntl').is(':checked')) {
scElements.push('unbuffered="true"');
scUrlElements.push(getValueUrl('unbuffered', 'true'));
exportUrlElements.push('unbuffered=true');
pushNameValue("unbuffered", "true", googleScriptElements, googleScriptValidationErrors);
}
var handleOrderBy = function (name, val) {
if (val) {
var orderByElem = getValue(name, val, scValidationErrors);
var orderByElemUrl = getValueUrl(name, val);
var orderByDir = jQuery('#' + name + 'dir_cntl').val();
if (orderByDir) {
orderBy += ' ' + orderByDir;
orderByElem = chopLastChar(orderByElem) + ' ' + orderByDir + '"';
orderByElemUrl = orderByElemUrl + encodeURIComponent(' ' + orderByDir);
}
scElements.push(orderByElem);
scUrlElements.push(orderByElemUrl);
exportUrlElements.push(orderByElemUrl);
pushNameValue(name, orderBy, googleScriptElements, googleScriptValidationErrors);
}
};
var orderBy = jQuery('#orderby_cntl').val();
handleOrderBy('orderby', orderBy);
var torderBy = jQuery('#torderby_cntl').val();
handleOrderBy('torderby', torderBy);
}
var scText;
switch (shortcode) {
case '[cfdb-html]':
val = jQuery('#filelinks_cntl').val();
scElements.push(getValue('filelinks', val, scValidationErrors));
scUrlElements.push(getValueUrl('filelinks', val));
val = jQuery('#wpautop_cntl').val();
scElements.push(getValue('wpautop', val, scValidationErrors));
scUrlElements.push(getValueUrl('wpautop', val));
val = jQuery('#stripbr_cntl').val();
scElements.push(getValue('stripbr', val, scValidationErrors));
scUrlElements.push(getValueUrl('stripbr', val));
var template = jQuery('#content_cntl').val();
var content = template;
var contentBefore = jQuery('#before_cntl').val();
var contentAfter = jQuery('#after_cntl').val();
if (contentBefore) {
content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER ?>" + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER ?>" + content;
}
if (contentAfter) {
content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER ?>" + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER ?>";
}
scUrlElements.push('content=' + encodeURIComponent(content));
scUrlElements.push('enc=HTMLTemplate');
scText = join(scElements) + ']' +
// Escape html tags for display on page
content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') +
'[/cfdb-html]';
if (template == "") {
scValidationErrors.push('<?php _e('Error: [cfdb-html] has empty Template. It will not output anything. ', 'contact-form-7-to-database-extension'); ?>');
jQuery('#content_cntl').addClass('validation'); // highlight template area
}
else {
jQuery('#content_cntl').removeClass('validation'); // remove highlight template area
}
break;
case '[cfdb-table]':
if (!jQuery('#header_cntl').is(':checked')) {
scElements.push('header="false"');
scUrlElements.push(getValueUrl('header', 'false'));
pushNameValue("header", "false", googleScriptElements, googleScriptValidationErrors);
}
val = jQuery('#headers_cntl').val();
scElements.push(getValue('headers', val, scValidationErrors));
scUrlElements.push(getValueUrl('headers', val));
val = jQuery('#id_cntl').val();
scElements.push(getValue('id', val, scValidationErrors));
scUrlElements.push(getValueUrl('id', val));
val = jQuery('#class_cntl').val();
scElements.push(getValue('class', val, scValidationErrors));
scUrlElements.push(getValueUrl('class',val));
val = jQuery('#style_cntl').val();
scElements.push(getValue('style', val, scValidationErrors));
scUrlElements.push(getValueUrl('style', val));
var contentBefore = jQuery('#before_cntl').val();
var contentAfter = jQuery('#after_cntl').val();
var content = '';
if (contentBefore) {
content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER ?>" + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER ?>" + content;
}
if (contentAfter) {
content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER ?>" + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER ?>";
}
scUrlElements.push('content=' + encodeURIComponent(content));
scUrlElements.push('enc=HTML');
scText = join(scElements) + ']';
if (content) {
// Escape html tags for display on page
scText += content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') +
'[/cfdb-table]';
}
break;
case '[cfdb-datatable]':
if (!jQuery('#header_cntl').is(':checked')) {
scElements.push('header="false"');
scUrlElements.push(getValueUrl('header', 'false'));
}
val = jQuery('#headers_cntl').val();
scElements.push(getValue('headers', val, scValidationErrors));
scUrlElements.push(getValueUrl('headers', val));
val = jQuery('#id_cntl').val();
scElements.push(getValue('id', val, scValidationErrors));
scUrlElements.push(getValueUrl('id', val));
val = jQuery('#class_cntl').val();
scElements.push(getValue('class', val, scValidationErrors));
scUrlElements.push(getValueUrl('class', val));
val = jQuery('#style_cntl').val();
scElements.push(getValue('style', val, scValidationErrors));
scUrlElements.push(getValueUrl('style', val));
if (jQuery('#edit_mode_cntl').attr('checked')) {
scElements.push('edit="true"');
scUrlElements.push('edit=true');
}
val = jQuery('#dt_options_cntl').val();
scElements.push(getValue('dt_options', val, scValidationErrors));
scUrlElements.push(getValueUrl('dt_options', val));
var contentBefore = jQuery('#before_cntl').val();
var contentAfter = jQuery('#after_cntl').val();
var content = '';
if (contentBefore) {
content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER ?>" + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER ?>" + content;
}
if (contentAfter) {
content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER ?>" + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER ?>";
}
scUrlElements.push('content=' + encodeURIComponent(content));
scUrlElements.push('enc=DT');
scText = join(scElements) + ']';
if (content) {
// Escape html tags for display on page
scText += content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') +
'[/cfdb-datatable]';
}
break;
case '[cfdb-value]':
val = jQuery('#function_cntl').val();
scElements.push(getValue('function', val, scValidationErrors));
scUrlElements.push(getValueUrl('function', val));
val = jQuery('#delimiter_cntl').val();
scElements.push(getValue('delimiter', val, scValidationErrors));
scUrlElements.push(getValueUrl('delimiter', val));
var contentBefore = jQuery('#before_cntl').val();
var contentAfter = jQuery('#after_cntl').val();
var content = '';
if (contentBefore) {
content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER ?>" + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER ?>" + content;
}
if (contentAfter) {
content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER ?>" + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER ?>";
}
scUrlElements.push('content=' + encodeURIComponent(content));
scUrlElements.push('enc=VALUE');
scText = join(scElements) + ']';
if (content) {
// Escape html tags for display on page
scText += content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') +
'[/cfdb-value]';
}
break;
case '[cfdb-count]':
var contentBefore = jQuery('#before_cntl').val();
var contentAfter = jQuery('#after_cntl').val();
var content = '';
if (contentBefore) {
content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER ?>" + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER ?>" + content;
}
if (contentAfter) {
content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER ?>" + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER ?>";
}
scUrlElements.push('content=' + encodeURIComponent(content));
scUrlElements.push('enc=COUNT');
scText = join(scElements) + ']'; // hopLastChar(scElements.join(' ')) + ']';
if (content) {
// Escape html tags for display on page
scText += content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') +
'[/cfdb-count]';
}
break;
case '[cfdb-json]':
if (!jQuery('#header_cntl').is(':checked')) {
scElements.push('header="false"');
scUrlElements.push(getValueUrl('header', 'false'));
pushNameValue("header", "false", googleScriptElements, googleScriptValidationErrors);
}
val = jQuery('#headers_cntl').val();
scElements.push(getValue('headers', val, scValidationErrors));
scUrlElements.push(getValueUrl('headers', val));
val = jQuery('#var_cntl').val();
scElements.push(getValue('var', val, scValidationErrors));
scUrlElements.push(getValueUrl('var', val));
val = jQuery('#format_cntl').val();
scElements.push(getValue('format', val, scValidationErrors));
scUrlElements.push(getValueUrl('format', val));
var contentBefore = jQuery('#before_cntl').val();
var contentAfter = jQuery('#after_cntl').val();
var content = '';
if (contentBefore) {
content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER ?>" + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER ?>" + content;
}
if (contentAfter) {
content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER ?>" + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER ?>";
}
scUrlElements.push('content=' + encodeURIComponent(content));
scUrlElements.push('enc=JSON');
scText = join(scElements) + ']';
if (content) {
// Escape html tags for display on page
scText += content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') +
'[/cfdb-json]';
}
break;
case '[cfdb-export-link]':
val = jQuery('#enc_cntl').val();
scElements.push(getValue('enc', val, scValidationErrors));
scUrlElements.push(getValueUrl('enc', val));
scElements.push(getValue('urlonly', jQuery('#urlonly_cntl').val(), scValidationErrors));
scElements.push(getValue('linktext', jQuery('#linktext_cntl').val(), scValidationErrors));
if (!jQuery('#header_cntl').is(':checked')) {
scElements.push('header="false"');
scUrlElements.push(getValueUrl('header', 'false'));
}
val = jQuery('#headers_cntl').val();
scElements.push(getValue('headers', val, scValidationErrors));
scUrlElements.push(getValueUrl('headers', val));
scText = join(scElements) + ']';
break;
default:
scText = shortcode;
break;
}
var urlBase = '<?php echo admin_url('admin-ajax.php') ?>?action=cfdb-export&';
if (shortcode) {
// Output short code text
var scUrl = urlBase + join(scUrlElements, '&');
jQuery('#shortcode_result_text').html('<a target="_cfdb_sc_results" href="' + scUrl + '">' + scText + '</a>');
// Output short code errors
jQuery('#shortcode_validations_text').html(scValidationErrors.join('<br/>'));
}
else {
// Don't report errors
jQuery('#shortcode_validations_text').html('');
}
// Export link or Google Spreadsheet function call
var exportSelection = jQuery('#export_cntl').val();
if (exportSelection) {
if (exportSelection != 'GLD') {
exportUrlElements.push(getValueUrl('enc', exportSelection));
}
if (exportSelection == 'RSS') {
exportUrlElements.push(getValueUrl('itemtitle', jQuery('#add_itemtitle').val()));
} else {
if (!jQuery('#header_cntl').is(':checked')) {
exportUrlElements.push(getValueUrl('header', 'false'));
pushNameValue("header", "false", googleScriptElements, googleScriptValidationErrors);
}
val = jQuery('#headers_cntl').val();
exportUrlElements.push(getValueUrl('headers', val, scValidationErrors));
pushNameValue("headers", val, googleScriptElements, googleScriptValidationErrors);
exportUrlElements.push(getValueUrl('format', jQuery('#format_cntl').val(), scValidationErrors));
}
var user = jQuery("#gld_user").val();
var pass = jQuery("#gld_pass").val();
var obfuscate = jQuery('#obfuscate_cntl').is(':checked')
if (user || pass) {
if (obfuscate) {
var key = 'kx82XcPjq8q8S!xafx%$&7p6';
exportUrlElements.push("l=" + encodeURI(printHex(des(key, user + "/" + pass, 1))));
} else {
exportUrlElements.push("user_login=" + encodeURI(user));
exportUrlElements.push("user_password=" + encodeURI(pass));
}
urlBase = '<?php echo admin_url('admin-ajax.php') ?>?action=cfdb-login&cfdb-action=cfdb-export&';
exportValidationErrors.push("<?php _e('Warning: the function includes your WP login information. Avoid sharing it.') ?>");
}
// Output
var exportUrl = urlBase + join(exportUrlElements, '&');
if (exportSelection == 'GLD') {
if (!user || !pass) {
exportValidationErrors.push("<?php _e('Error: WP User and Password are required for the Google Spreadsheet to pull data from your WordPress site.') ?>");
}
if (exportUrl.length > 255) {
exportValidationErrors.push("<?php _e('Because the generated URL would be too long, you must use this alternative function and add its script to your Google Spreadsheet') ?>");
jQuery('#label_gld_script').show();
jQuery('#label_gld_function').hide();
jQuery('#export_result_text').html(formName ?
("=cfdbdata(\"" + googleScriptElements.join("\", \"") + "\")") :
"");
} else {
jQuery('#export_result_text').html(formName ?
("<a target='_cfdb_exp_results' href='" + exportUrl + "'>=IMPORTDATA(\"" + exportUrl + "\")</a>") :
"");
}
} else {
jQuery('#export_result_text').html(formName ? ('<a target="_cfdb_exp_results" href="' + exportUrl + '">' + exportUrl + '</a>') : '');
}
// Output export errors
jQuery('#export_validations_text').html(exportValidationErrors.join('<br/>'));
} else {
jQuery('#export_result_text').html('');
// Don't report errors
jQuery('#export_validations_text').html('');
}
}
var getFormFieldsUrlBase = '<?php echo $plugin->getFormFieldsAjaxUrlBase() ?>';
function getFormFields() {
jQuery('[id^=add]').attr('disabled', 'disabled');
jQuery('[id^=btn]').attr('disabled', 'disabled');
var formName = jQuery('#form_name_cntl').val();
var url = getFormFieldsUrlBase + encodeURIComponent(formName);
jQuery.ajax({
dataType: "json",
url: url,
async: false,
success: function(json) {
var optionsHtml = '<option value=""></option>';
jQuery(json).each(function () {
optionsHtml += '<option value="' + this + '">' + this + '</option>';
});
optionsHtml += '<option value="$_POST(param)">$_POST(param)</option>';
optionsHtml += '<option value="$_GET(param)">$_GET(param)</option>';
optionsHtml += '<option value="$_COOKIE(param)">$_COOKIE(param)</option>';
jQuery('[id^=add]').html(optionsHtml).removeAttr('disabled');
jQuery('[id^=btn]').removeAttr('disabled');
}
});
}
function validateSubmitTime() {
var url = "<?php echo $plugin->getValidateSubmitTimeAjaxUrlBase() ?>" + jQuery('#filter_val').val();
jQuery.get(url, function(data) {
alert(data);
});
}
function showValidateSubmitTimeHelp(show) {
if (show) {
jQuery('#span_validate_submit_time').show();
}
else {
jQuery('#span_validate_submit_time').hide();
}
}
function addFieldToShow() {
var value = jQuery('#show_cntl').val();
if (value) {
value += ',';
}
jQuery('#show_cntl').val(value + jQuery('#add_show').val());
createShortCodeAndExportLink();
}
function addFieldToHide() {
var value = jQuery('#hide_cntl').val();
if (value) {
value += ',';
}
jQuery('#hide_cntl').val(value + jQuery('#add_hide').val());
createShortCodeAndExportLink();
}
function addFieldToOrderBy(field) {
var value = jQuery('#' + field + '_cntl').val();
if (value) {
value += ',';
}
jQuery('#' + field + '_cntl').val(value + jQuery('#add_' + field).val());
createShortCodeAndExportLink();
}
function addFieldToFilter(field) {
var value = jQuery('#' + field + '_cntl').val();
if (value) {
value += jQuery('#' + field + '_bool').val();
}
value += jQuery('#add_' + field).val() + jQuery('#' + field + '_op').val() + jQuery('#' + field + '_val').val();
jQuery('#' + field + '_cntl').val(value);
createShortCodeAndExportLink();
}
function addToTrans() {
var value = jQuery('#trans_cntl').val();
if (value) {
value += "&&";
}
var field = jQuery('#add_trans').val();
if (field) {
value += field;
value += "="
}
value += jQuery('#trans_val').val();
jQuery('#trans_cntl').val(value);
createShortCodeAndExportLink();
}
function addFieldToHeaders() {
var col = jQuery('#add_headers').val();
var disp = jQuery('#headers_val').val();
if (!col || !disp) {
return;
}
var value = jQuery('#headers_cntl').val();
if (value) {
value += ',';
}
value += col + '=' + disp;
jQuery('#headers_cntl').val(value);
createShortCodeAndExportLink();
}
function addFieldToContent() {
jQuery('#content_cntl').val(jQuery('#content_cntl').val() + '${' + jQuery('#add_content').val() + '}');
}
function reset() {
// Form
jQuery('#form_name_cntl').val(<?php echo json_encode($postedForm) ?>);
getFormFields();
// Export File
jQuery('#export_cntl').val(<?php echo json_encode($postedEnc) ?>);
jQuery('#add_itemtitle').val(<?php echo json_encode($postedItemtitle) ?>);
// Short Code
jQuery('#shortcode_ctrl').val(<?php echo json_encode($postedSC) ?>);
jQuery('#show_cntl').val(<?php echo json_encode($postedShow) ?>);
jQuery('#hide_cntl').val(<?php echo json_encode($postedHide) ?>);
jQuery('#role_cntl').val(<?php echo json_encode($postedRole) ?>);
jQuery('#permissionmsg_cntl').val(<?php echo json_encode($postedPermissionmsg) ?>);
jQuery('#trans_cntl').val(<?php echo json_encode($postedTrans) ?>);
jQuery('#search_cntl').val(<?php echo json_encode($postedSearch) ?>);
jQuery('#filter_cntl').val(<?php echo json_encode($postedFilter) ?>);
jQuery('#tsearch_cntl').val(<?php echo json_encode($postedTSearch) ?>);
jQuery('#tfilter_cntl').val(<?php echo json_encode($postedTFilter) ?>);
jQuery('#limit_rows_cntl').val(<?php echo json_encode($postedLimitNumRows) ?>);
jQuery('#limit_start_cntl').val(<?php echo json_encode($postedLimitStart) ?>);
jQuery('#random_cntl').val(<?php echo json_encode($postedRandom) ?>);
jQuery('#unbuffered_cntl').attr("checked", false);
jQuery('#orderby_cntl').val(<?php echo json_encode($postedOrderby) ?>);
jQuery('#torderby_cntl').val(<?php echo json_encode($postedTOrderby) ?>);
jQuery('#header_cntl').prop("checked", <?php echo $postedHeader == 'false' ? 'false' : 'true' ?>); // default = true
jQuery('#headers_cntl').val(<?php echo json_encode($postedHeaders) ?>);
jQuery('#id_cntl').val(<?php echo json_encode($postedId) ?>);
jQuery('#class_cntl').val(<?php echo json_encode($postedClass) ?>);
jQuery('#style_cntl').val(<?php echo json_encode($postedStyle) ?>);
jQuery('#edit_mode_cntl').prop('checked', <?php echo $postedEdit == 'true' ? 'true' : 'false' ?>); // default = false
jQuery('#dt_options_cntl').val(<?php echo json_encode($postedDtOptions) ?>);
jQuery('#var_cntl').val(<?php echo json_encode($postedVar) ?>);
jQuery('#format_cntl').val(<?php echo json_encode($postedFormat) ?>);
jQuery('#function_cntl').val(<?php echo json_encode($postedFunction) ?>);
jQuery('#delimiter_cntl').val(<?php echo json_encode($postedDelimiter) ?>);
jQuery('#filelinks_cntl').val(<?php echo json_encode($postedFilelinks) ?>);
jQuery('#wpautop_cntl').val(<?php echo json_encode($postedWpautop) ?>);
jQuery('#stripbr_cntl').val(<?php echo json_encode($postedStripbr) ?>);
jQuery('#content_cntl').val(<?php echo json_encode($postedContent) ?>);
jQuery('#before_cntl').val(<?php echo json_encode($postedContentBefore) ?>);
jQuery('#after_cntl').val(<?php echo json_encode($postedContentAfter) ?>);
jQuery('#enc_cntl').val(<?php echo json_encode($postedEnc) ?>);
jQuery('#urlonly_cntl').val(<?php echo json_encode($postedUrlonly) ?>);
jQuery('#linktext_cntl').val(<?php echo json_encode($postedLinktext) ?>);
showValidateSubmitTimeHelp(false);
showHideOptionDivs();
createShortCodeAndExportLink();
}
jQuery.ajaxSetup({
cache: false
});
jQuery(document).ready(function() {
reset();
showHideOptionDivs();
createShortCodeAndExportLink();
jQuery('#shortcode_ctrl').change(showHideOptionDivs);
jQuery('#shortcode_ctrl').change(createShortCodeAndExportLink);
jQuery('select[id$="cntl"]').change(createShortCodeAndExportLink);
jQuery('input[id$="cntl"]').keyup(createShortCodeAndExportLink);
jQuery('textarea[id$="cntl"]').keyup(createShortCodeAndExportLink);
jQuery('#form_name_cntl').change(getFormFields);
jQuery('#btn_show').click(addFieldToShow);
jQuery('#btn_hide').click(addFieldToHide);
jQuery('#btn_orderby').click(function () {
addFieldToOrderBy('orderby');
});
jQuery('#btn_torderby').click(function () {
addFieldToOrderBy('torderby');
});
jQuery('#btn_filter').click(function () {
addFieldToFilter('filter');
});
jQuery('#btn_tfilter').click(function () {
addFieldToFilter('tfilter');
});
jQuery('#btn_trans').click(addToTrans);
jQuery('#header_cntl').click(createShortCodeAndExportLink);
jQuery('#unbuffered_cntl').click(createShortCodeAndExportLink);
jQuery('#edit_mode_cntl').click(createShortCodeAndExportLink);
jQuery('#btn_headers').click(addFieldToHeaders);
jQuery('#btn_content').click(function() {
addFieldToContent();
createShortCodeAndExportLink();
});
jQuery('#enc_cntl').click(createShortCodeAndExportLink);
jQuery('#urlonly_cntl').click(createShortCodeAndExportLink);
jQuery('#reset_button').click(reset);
jQuery('#btn_validate_submit_time').click(validateSubmitTime);
jQuery('#add_filter').change(function() {