Skip to content

Commit 1528d79

Browse files
authored
Merge pull request #63 from codescribblr/master
Integration with HumanPresence
2 parents 8897b9e + bac3c19 commit 1528d79

17 files changed

+318
-39
lines changed
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

assets/wpuf/css/wpuf-form-builder.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@
218218
background-repeat: repeat-x;
219219
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#660073aa', endColorstr='#ff0073aa', GradientType=0);
220220
}
221+
.fa.fa-humanpresence {
222+
width: 1em;
223+
height: 1em;
224+
background: no-repeat url('images/hp-shield.svg') left top;
225+
background-size: cover;
226+
}
221227
#wpuf-form-builder {
222228
width: calc(100% - 200px);
223229
padding-top: 10px;

assets/wpuf/js-templates/form-components.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
]"
1717
:data-index="index"
1818
data-source="stage"
19+
v-if="'humanpresence' !== field.template"
1920
>
2021
<div v-if="!is_full_width(field.template)" class="wpuf-label">
2122
<label v-if="!is_invisible(field)" :for="'wpuf-' + field.name ? field.name : 'cls'">
@@ -58,7 +59,9 @@
5859
v-for="(field, index) in hidden_fields"
5960
:class="['field-items', parseInt(editing_form_id) === parseInt(field.id) ? 'current-editing' : '']"
6061
>
61-
<strong><?php esc_html_e( 'key', 'wp-user-frontend' ); ?></strong>: {{ field.name }} | <strong><?php esc_html_e( 'value', 'wp-user-frontend' ); ?></strong>: {{ field.meta_value }}
62+
<span v-if="'humanpresence' !== field.template"><strong><?php esc_html_e( 'key', 'wp-user-frontend' ); ?></strong>: {{ field.name }} | <strong><?php esc_html_e( 'value', 'wp-user-frontend' ); ?></strong>: {{ field.meta_value }}</span>
63+
64+
<span v-if="'humanpresence' === field.template"><component v-if="is_template_available(field)" :is="'form-' + field.template" :field="field"></component></span>
6265

6366
<div class="control-buttons">
6467
<p>
@@ -349,10 +352,10 @@ class="option-chooser-radio"
349352

350353
<div v-if="'logged_in' === selected" class="condiotional-logic-container">
351354

352-
<?php $roles = get_editable_roles(); ?>
355+
<?php $roles = get_editable_roles(); ?>
353356

354-
<ul>
355-
<?php
357+
<ul>
358+
<?php
356359
foreach ( $roles as $role => $value ) {
357360
$role_name = $value['name'];
358361

@@ -363,13 +366,13 @@ class="option-chooser-radio"
363366
echo $output;
364367
}
365368
?>
366-
</ul>
369+
</ul>
367370
</div>
368371

369372
<div v-if="'subscribed_users' === selected" class="condiotional-logic-container">
370373

371-
<ul>
372-
<?php
374+
<ul>
375+
<?php
373376

374377
if ( class_exists( 'WPUF_Subscription' ) ) {
375378
$subscriptions = WPUF_Subscription::init()->get_subscriptions();
@@ -387,7 +390,7 @@ class="option-chooser-radio"
387390
}
388391
}
389392
?>
390-
</ul>
393+
</ul>
391394

392395
</div>
393396
</div></script>
@@ -708,14 +711,26 @@ class="button"
708711
</template>
709712

710713
<template v-else>
711-
<div v-if="'invisible_recaptcha' != field.recaptcha_type">
712-
<img class="wpuf-recaptcha-placeholder" src="<?php echo WPUF_ASSET_URI . '/images/recaptcha-placeholder.png'; ?>" alt="">
714+
<div v-if="'invisible_recaptcha' != field.recaptcha_type">
715+
<img class="wpuf-recaptcha-placeholder" src="<?php echo WPUF_ASSET_URI . '/images/recaptcha-placeholder.png'; ?>" alt="">
713716
</div>
714717
<div v-else><p><?php _e( 'Invisible reCaptcha', 'wp-user-frontend' ); ?></p></div>
715718
</template>
716719
</div>
717720
</script>
718721

722+
<script type="text/x-template" id="tmpl-wpuf-form-humanpresence">
723+
<div class="wpuf-fields">
724+
<template v-if="!has_humanpresence_installed">
725+
<p v-html="no_humanpresence_installed_msg"></p>
726+
</template>
727+
728+
<template v-else>
729+
<div><p><i aria-hidden="true" class="fa fa-humanpresence"></i> <?php _e( 'Human Presence Anti-Spam Enabled (only visible to you).', 'wp-user-frontend' ); ?></p></div>
730+
</template>
731+
</div>
732+
</script>
733+
719734
<script type="text/x-template" id="tmpl-wpuf-form-section_break">
720735
<div class="wpuf-section-wrap">
721736
<h2 class="wpuf-section-title">{{ field.label }}</h2>

assets/wpuf/js/wpuf-form-builder-components.js

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
hidden_fields: function hidden_fields() {
2121
return this.$store.state.form_fields.filter(function (item) {
22-
return 'custom_hidden_field' === item.template;
22+
return 'custom_hidden_field' === item.template || 'humanpresence' === item.template;
2323
});
2424
},
2525

@@ -32,6 +32,21 @@
3232
}
3333
},
3434

35+
created: function created() {
36+
var self = this,
37+
humanpresence_field_id = 0,
38+
i = 0;
39+
for(i = 0; i < self.$store.state.form_fields.length; i++) {
40+
if (self.$store.state.form_fields[i].template === 'humanpresence') {
41+
humanpresence_field_id = self.$store.state.form_fields[i].id;
42+
}
43+
}
44+
45+
wpuf_form_builder.event_hub.$on('humanpresence-changed', this.humanpresence_changed);
46+
wpuf_form_builder.event_hub.$on('humanpresence-disabled', this.delete_humanpresence_field);
47+
48+
},
49+
3550
mounted: function mounted() {
3651
var self = this,
3752
in_column_field = false;
@@ -153,16 +168,51 @@
153168
}, function () {});
154169
},
155170

171+
delete_field_no_confirm: function delete_field_no_confirm(index) {
172+
this.$store.commit('delete_form_field_element', index);
173+
},
174+
156175
delete_hidden_field: function delete_hidden_field(field_id) {
157176
var i = 0;
158177

159178
for (i = 0; i < this.form_fields.length; i++) {
160179
if (parseInt(field_id) === parseInt(this.form_fields[i].id)) {
161-
this.delete_field(i);
180+
if(this.form_fields[i].template === 'humanpresence'){
181+
this.delete_field_no_confirm(i);
182+
this.disable_humanpresence_setting();
183+
} else {
184+
this.delete_field(i);
185+
}
162186
}
163187
}
164188
},
165189

190+
delete_humanpresence_field: function delete_humanpresence_field(data) {
191+
var i = 0;
192+
if(data.$store.state.form_fields.length) {
193+
for(i = 0; i < data.$store.state.form_fields.length; i++) {
194+
if(data.$store.state.form_fields[i].template === 'humanpresence') {
195+
this.delete_field_no_confirm(i);
196+
this.disable_humanpresence_setting();
197+
}
198+
}
199+
}
200+
},
201+
202+
disable_humanpresence_setting: function disable_humanpresence_setting() {
203+
var settings = this.$store.state.settings;
204+
settings.humanpresence_enabled = false;
205+
this.$store.commit('set_form_settings', settings);
206+
},
207+
208+
humanpresence_changed: function humanpresence_changed(e, data) {
209+
if(data.$store.state.settings.humanpresence_enabled === 'true'){
210+
wpuf_form_builder.event_hub.$emit('humanpresence-enabled', data);
211+
} else {
212+
wpuf_form_builder.event_hub.$emit('humanpresence-disabled', data);
213+
}
214+
},
215+
166216
is_pro_feature: function is_pro_feature(template) {
167217
return this.field_settings[template] && this.field_settings[template].pro_feature ? true : false;
168218
},
@@ -427,7 +477,8 @@
427477
return {
428478
show_basic_settings: true,
429479
show_advanced_settings: false,
430-
show_quiz_settings: false
480+
show_quiz_settings: false,
481+
show_humanpresence_settings: false
431482
};
432483
},
433484

@@ -436,6 +487,7 @@
436487
this.show_basic_settings = true;
437488
this.show_advanced_settings = false;
438489
this.show_quiz_settings = false;
490+
this.show_humanpresence_settings = false;
439491

440492
return parseInt(this.$store.state.editing_field_id);
441493
},
@@ -503,6 +555,12 @@
503555
});
504556
},
505557

558+
humanpresence_settings: function humanpresence_settings() {
559+
return this.settings.filter(function (item) {
560+
return 'humanpresence' === item.section;
561+
});
562+
},
563+
506564
form_field_type_title: function form_field_type_title() {
507565
var template = this.editing_form_field.template;
508566

@@ -1195,9 +1253,13 @@
11951253
}
11961254
},
11971255

1256+
created: function created() {
1257+
wpuf_form_builder.event_hub.$on('humanpresence-enabled', this.add_humanpresence_field);
1258+
},
1259+
11981260
mounted: function mounted() {
11991261
// bind jquery ui draggable
1200-
$(this.$el).find('.panel-form-field-buttons .button').draggable({
1262+
$(this.$el).find('.panel-form-field-buttons .button').not('[data-form-field="humanpresence"]').draggable({
12011263
connectToSortable: '#form-preview-stage .wpuf-form, .wpuf-column-inner-fields .wpuf-column-fields-sortable-list',
12021264
helper: 'clone',
12031265
revert: 'invalid',
@@ -1240,12 +1302,24 @@
12401302
}
12411303
}
12421304

1305+
if(field_template === 'humanpresence') {
1306+
var settings = this.$store.state.settings;
1307+
settings.humanpresence_enabled = true;
1308+
this.$store.commit('set_form_settings', settings);
1309+
}
1310+
12431311
payload.field = field;
12441312

12451313
// add new form element
12461314
this.$store.commit('add_form_field_element', payload);
12471315
},
12481316

1317+
add_humanpresence_field: function add_humanpresence_field(data) {
1318+
if(!this.containsField('humanpresence')) {
1319+
this.add_form_field('humanpresence');
1320+
}
1321+
},
1322+
12491323
is_pro_feature: function is_pro_feature(field) {
12501324
return this.field_settings[field].pro_feature;
12511325
},
@@ -1371,6 +1445,26 @@
13711445
}
13721446
});
13731447

1448+
/**
1449+
* Field template: HumanPresence
1450+
*/
1451+
Vue.component('form-humanpresence', {
1452+
template: '#tmpl-wpuf-form-humanpresence',
1453+
1454+
mixins: [wpuf_mixins.form_field_mixin],
1455+
1456+
computed: {
1457+
has_humanpresence_installed: function has_humanpresence_installed() {
1458+
return wpuf_form_builder.humanpresence_installed;
1459+
},
1460+
1461+
no_humanpresence_installed_msg: function no_humanpresence_installed_msg() {
1462+
return wpuf_form_builder.field_settings.humanpresence.validator.msg;
1463+
}
1464+
}
1465+
1466+
});
1467+
13741468
/**
13751469
* Field template: Section Break
13761470
*/

assets/wpuf/js/wpuf-form-builder-components.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)