| @@ -1,406 +1,405 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * The Assets Class | |
| 5 | - */ | |
| 6 | -class WeForms_Form_Builder_Assets { | |
| 7 | - | |
| 8 | - public function __construct() { | |
| 9 | - $this->init_actions(); | |
| 10 | - } | |
| 11 | - | |
| 12 | - public function init_actions() { | |
| 13 | - add_action( 'in_admin_header', [ $this, 'remove_admin_notices' ] ); | |
| 14 | - add_action( 'admin_enqueue_scripts', [ $this, 'builder_enqueue_scripts' ], 2000 ); | |
| 15 | - add_action( 'admin_print_scripts', [ $this, 'builder_mixins_script' ] ); | |
| 16 | - add_action( 'admin_footer', [ $this, 'admin_footer_js_templates' ] ); | |
| 17 | - | |
| 18 | - add_action( 'wpuf-form-builder-template-builder-stage-submit-area', [ $this, 'add_form_submit_area' ] ); | |
| 19 | - | |
| 20 | - add_action( 'wpuf-form-builder-tabs-contact_form', [ $this, 'add_primary_tabs' ] ); | |
| 21 | - add_action( 'wpuf-form-builder-tab-contents-contact_form', [ $this, 'add_primary_tab_contents' ] ); | |
| 22 | - | |
| 23 | - add_action( 'wpuf-form-builder-settings-tabs-contact_form', [ $this, 'add_settings_tabs' ] ); | |
| 24 | - add_action( 'wpuf-form-builder-settings-tab-contents-contact_form', [ $this, 'add_settings_tab_contents' ] ); | |
| 25 | - | |
| 26 | - do_action( 'weforms_form_builder_init' ); | |
| 27 | - } | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * Remove all kinds of admin notices | |
| 31 | - * | |
| 32 | - * Since we don't have much space left on top of the page, | |
| 33 | - * we have to remove all kinds of admin notices | |
| 34 | - * | |
| 35 | - * @since 1.2.6 | |
| 36 | - * | |
| 37 | - * @return void | |
| 38 | - */ | |
| 39 | - public function remove_admin_notices() { | |
| 40 | - remove_all_actions( 'network_admin_notices' ); | |
| 41 | - remove_all_actions( 'user_admin_notices' ); | |
| 42 | - remove_all_actions( 'admin_notices' ); | |
| 43 | - remove_all_actions( 'all_admin_notices' ); | |
| 44 | - } | |
| 45 | - | |
| 46 | - public function builder_enqueue_scripts() { | |
| 47 | - $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; | |
| 48 | - | |
| 49 | - weforms()->scripts->enqueue_backend(); | |
| 50 | - | |
| 51 | - $recaptcha = weforms_get_settings( 'recaptcha' ); | |
| 52 | - | |
| 53 | - $wpuf_form_builder = apply_filters( 'wpuf-form-builder-localize-script', [ | |
| 54 | - 'i18n' => $this->i18n(), | |
| 55 | - 'panel_sections' => weforms()->fields->get_field_groups(), | |
| 56 | - 'field_settings' => weforms()->fields->get_js_settings(), | |
| 57 | - 'pro_link' => self::get_pro_url(), | |
| 58 | - 'site_url' => site_url( '/' ), | |
| 59 | - 'defaultNotification' => [ | |
| 60 | - 'active' => 'true', | |
| 61 | - 'type' => 'email', | |
| 62 | - 'smsTo' => '', | |
| 63 | - 'smsText' => '[{form_name}] ' . __( 'New Form Submission', 'weforms' ) . ' #{entry_id}', | |
| 64 | - 'name' => 'Admin Notification', | |
| 65 | - 'subject' => '[{form_name}] New Form Submission #{entry_id}', | |
| 66 | - 'to' => '{admin_email}', | |
| 67 | - 'replyTo' => '', | |
| 68 | - 'message' => '{all_fields}', | |
| 69 | - 'fromName' => '', | |
| 70 | - 'fromAddress' => '{admin_email}', | |
| 71 | - 'cc' => '', | |
| 72 | - 'bcc' => '', | |
| 73 | - 'weforms_cond' => [ | |
| 74 | - 'condition_status' => 'no', | |
| 75 | - 'cond_logic' => 'any', | |
| 76 | - 'conditions' => [ | |
| 77 | - [ | |
| 78 | - 'name' => '', | |
| 79 | - 'operator' => '=', | |
| 80 | - 'option' => '', | |
| 81 | - ], | |
| 82 | - ], | |
| 83 | - ], | |
| 84 | - ], | |
| 85 | - 'integrations' => weforms()->integrations->get_integration_js_settings(), | |
| 86 | - 'recaptcha_site' => isset( $recaptcha->key ) ? $recaptcha->key : '', | |
| 87 | - 'recaptcha_secret' => isset( $recaptcha->secret ) ? $recaptcha->secret : '', | |
| 88 | - ] ); | |
| 89 | - | |
| 90 | - // mixins | |
| 91 | - $wpuf_mixins = [ | |
| 92 | - 'root' => apply_filters( 'weforms-builder-js-root-mixins', [ 'weforms_mixin_builder_root' ] ), | |
| 93 | - 'builder_stage' => apply_filters( 'weforms-builder-js-builder-stage-mixins', [ 'weforms_mixin_builder_stage' ] ), | |
| 94 | - 'form_fields' => apply_filters( 'weforms-builder-js-form-fields-mixins', [] ), | |
| 95 | - 'field_options' => apply_filters( 'weforms-builder-js-field-options-mixins', [] ), | |
| 96 | - ]; | |
| 97 | - | |
| 98 | - $weforms = apply_filters( 'weforms_localized_script', [ | |
| 99 | - 'nonce' => wp_create_nonce( 'weforms' ), | |
| 100 | - 'confirm' => __( 'Are you sure?', 'weforms' ), | |
| 101 | - 'is_pro' => class_exists( 'WeForms_Pro' ) ? 'true' : 'false', | |
| 102 | - 'has_payment' => class_exists( 'WeForms_Payment' ) ? 'true' : 'false', | |
| 103 | - 'has_sms' => class_exists( 'WeForms_SMS_Notification' ) ? 'true' : 'false', | |
| 104 | - 'routes' => $this->get_vue_routes(), | |
| 105 | - 'routeComponents' => [ 'default' => null ], | |
| 106 | - 'mixins' => [ 'default' => null ], | |
| 107 | - 'assetsURL' => WEFORMS_ASSET_URI, | |
| 108 | - 'shortcodes' => $this->shortcodes(), | |
| 109 | - 'settings' => [ | |
| 110 | - 'recaptcha' => weforms_get_settings( 'recaptcha' ), | |
| 111 | - ], | |
| 112 | - ] ); | |
| 113 | - | |
| 114 | - wp_localize_script( 'weforms-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder ); | |
| 115 | - wp_localize_script( 'weforms-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins ); | |
| 116 | - wp_localize_script( 'weforms-mixins', 'weForms', $weforms ); | |
| 117 | - | |
| 118 | - do_action( 'weforms_admin_after_scripts_loaded' ); | |
| 119 | - } | |
| 120 | - | |
| 121 | - /** | |
| 122 | - * The pro url | |
| 123 | - * | |
| 124 | - * @return string | |
| 125 | - */ | |
| 126 | - public static function get_pro_url() { | |
| 127 | - $link = 'https://weformspro.com/'; | |
| 128 | - | |
| 129 | - if ( $aff = get_option( '_weforms_aff_ref' ) ) { | |
| 130 | - $link = add_query_arg( [ 'ref' => $aff ], $link ); | |
| 131 | - } | |
| 132 | - | |
| 133 | - return $link; | |
| 134 | - } | |
| 135 | - | |
| 136 | - /** | |
| 137 | - * SPA Routes | |
| 138 | - * | |
| 139 | - * @return array | |
| 140 | - */ | |
| 141 | - public function get_vue_routes() { | |
| 142 | - $routes = [ | |
| 143 | - [ | |
| 144 | - 'path' => '/', | |
| 145 | - 'name' => 'home', | |
| 146 | - 'component' => 'Home', | |
| 147 | - ], | |
| 148 | - [ | |
| 149 | - 'path' => '/form/:id', | |
| 150 | - 'component' => 'FormHome', | |
| 151 | - 'children' => [ | |
| 152 | - [ | |
| 153 | - 'path' => '', | |
| 154 | - 'name' => 'form', | |
| 155 | - 'component' => 'SingleForm', | |
| 156 | - ], | |
| 157 | - [ | |
| 158 | - 'path' => 'entries', | |
| 159 | - 'component' => 'FormEntriesHome', | |
| 160 | - 'children' => [ | |
| 161 | - [ | |
| 162 | - 'path' => '', | |
| 163 | - 'name' => 'formEntries', | |
| 164 | - 'component' => 'FormEntries', | |
| 165 | - 'props' => true, | |
| 166 | - ], | |
| 167 | - [ | |
| 168 | - 'path' => ':entryid', | |
| 169 | - 'name' => 'formEntriesSingle', | |
| 170 | - 'component' => 'FormEntriesSingle', | |
| 171 | - ], | |
| 172 | - ], | |
| 173 | - ], | |
| 174 | - [ | |
| 175 | - 'path' => 'edit', | |
| 176 | - 'name' => 'edit', | |
| 177 | - 'component' => 'FormEditComponent', | |
| 178 | - ], | |
| 179 | - ], | |
| 180 | - ], | |
| 181 | - [ | |
| 182 | - 'path' => '/tools', | |
| 183 | - 'name' => 'tools', | |
| 184 | - 'component' => 'Tools', | |
| 185 | - ], | |
| 186 | - [ | |
| 187 | - 'path' => '/entries', | |
| 188 | - 'name' => 'entries', | |
| 189 | - 'component' => 'Entries', | |
| 190 | - ], | |
| 191 | - [ | |
| 192 | - 'path' => '/help', | |
| 193 | - 'name' => 'help', | |
| 194 | - 'component' => 'Help', | |
| 195 | - ], | |
| 196 | - [ | |
| 197 | - 'path' => '/privacy', | |
| 198 | - 'name' => 'privacy', | |
| 199 | - 'component' => 'Privacy', | |
| 200 | - ], | |
| 201 | - [ | |
| 202 | - 'path' => '/premium', | |
| 203 | - 'name' => 'premium', | |
| 204 | - 'component' => 'Premium', | |
| 205 | - ], | |
| 206 | - [ | |
| 207 | - 'path' => '/settings', | |
| 208 | - 'name' => 'settings', | |
| 209 | - 'component' => 'Settings', | |
| 210 | - ], | |
| 211 | - ]; | |
| 212 | - | |
| 213 | - return apply_filters( 'weforms_vue_routes', $routes ); | |
| 214 | - } | |
| 215 | - | |
| 216 | - /** | |
| 217 | - * Print js scripts in admin head | |
| 218 | - * | |
| 219 | - * @since 2.5 | |
| 220 | - * | |
| 221 | - * @return void | |
| 222 | - */ | |
| 223 | - public function builder_mixins_script() { | |
| 224 | - ?> | |
| 225 | - <script> | |
| 226 | - if (!window.Promise) { | |
| 227 | - var promise_polyfill = document.createElement('script'); | |
| 228 | - promise_polyfill.setAttribute('src','https://cdn.polyfill.io/v2/polyfill.min.js'); | |
| 229 | - document.head.appendChild(promise_polyfill); | |
| 230 | - } | |
| 231 | - </script> | |
| 232 | - | |
| 233 | - <script> | |
| 234 | - var wpuf_form_builder_mixins = function(mixins, mixin_parent) { | |
| 235 | - if (!mixins || !mixins.length) { | |
| 236 | - return []; | |
| 237 | - } | |
| 238 | - | |
| 239 | - if (!mixin_parent) { | |
| 240 | - mixin_parent = window; | |
| 241 | - } | |
| 242 | - | |
| 243 | - return mixins.map(function (mixin) { | |
| 244 | - return mixin_parent[mixin]; | |
| 245 | - }); | |
| 246 | - }; | |
| 247 | - </script> | |
| 248 | - <?php | |
| 249 | - } | |
| 250 | - | |
| 251 | - /** | |
| 252 | - * Include vue component templates | |
| 253 | - * | |
| 254 | - * @since 2.5 | |
| 255 | - * | |
| 256 | - * @return void | |
| 257 | - */ | |
| 258 | - public function admin_footer_js_templates() { | |
| 259 | - if ( !defined( 'WPUF_ASSET_URI' ) ) { | |
| 260 | - define( 'WPUF_ASSET_URI', WEFORMS_ROOT_URI . '/assets' ); | |
| 261 | - } | |
| 262 | - | |
| 263 | - include WEFORMS_ROOT . '/assets/wpuf/js-templates/form-components.php'; | |
| 264 | - include WEFORMS_ROOT . '/assets/js-templates/form-components.php'; | |
| 265 | - include WEFORMS_ROOT . '/assets/js-templates/spa-components.php'; | |
| 266 | - | |
| 267 | - do_action( 'wpuf-form-builder-add-js-templates' ); | |
| 268 | - } | |
| 269 | - | |
| 270 | - /** | |
| 271 | - * i18n translatable strings | |
| 272 | - * | |
| 273 | - * @since 2.5 | |
| 274 | - * | |
| 275 | - * @return array | |
| 276 | - */ | |
| 277 | - private function i18n() { | |
| 278 | - return apply_filters( 'wpuf-form-builder-i18n', [ | |
| 279 | - 'advanced_options' => __( 'Advanced Options', 'weforms' ), | |
| 280 | - 'quiz_options' => __( 'Quiz Options', 'weforms' ), | |
| 281 | - 'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'weforms' ), | |
| 282 | - 'yes_delete_it' => __( 'Yes, delete it', 'weforms' ), | |
| 283 | - 'no_cancel_it' => __( 'No, cancel it', 'weforms' ), | |
| 284 | - 'ok' => __( 'OK', 'weforms' ), | |
| 285 | - 'cancel' => __( 'Cancel', 'weforms' ), | |
| 286 | - 'close' => __( 'Close', 'weforms' ), | |
| 287 | - 'disable' => __( 'Disable', 'weforms' ), | |
| 288 | - 'last_choice_warn_msg' => __( 'This field must contain at least one choice', 'weforms' ), | |
| 289 | - 'option' => __( 'Option', 'weforms' ), | |
| 290 | - 'row' => __( 'Row', 'weforms' ), | |
| 291 | - 'column' => __( 'Column', 'weforms' ), | |
| 292 | - 'last_column_warn_msg' => __( 'This field must contain at least one column', 'weforms' ), | |
| 293 | - 'is_a_pro_feature' => __( 'is available in Pro version', 'weforms' ), | |
| 294 | - 'pro_feature_msg' => __( 'Please upgrade to the Pro version to unlock all these awesome features', 'weforms' ), | |
| 295 | - 'upgrade_to_pro' => __( 'Get the Pro version', 'weforms' ), | |
| 296 | - 'select' => __( 'Select', 'weforms' ), | |
| 297 | - 'saved_form_data' => __( 'Saved form data', 'weforms' ), | |
| 298 | - 'unsaved_changes' => __( 'You have unsaved changes.', 'weforms' ), | |
| 299 | - 'areYouSureToLeave' => __( 'Are you sure to leave this page?', 'weforms' ), | |
| 300 | - 'copy_shortcode' => __( 'Click to copy shortcode', 'weforms' ), | |
| 301 | - | |
| 302 | - 'selectAnImage' => __( 'Select an image', 'weforms' ), | |
| 303 | - 'pleaseSelectAnImage' => __( 'Please select an image', 'weforms' ), | |
| 304 | - 'uploadAnImage' => __( 'Upload an image', 'weforms' ), | |
| 305 | - | |
| 306 | - 'shareYourForm' => __( 'Share Your Form', 'weforms' ), | |
| 307 | - 'shareYourFormDesc' => __( 'Sharing your form enables <strong>anyone</strong> to view and submit the form without inserting the shortcode to a page.', 'weforms' ), | |
| 308 | - 'shareYourFormText' => __( 'Anyone with this URL will be able to view and submit this form.', 'weforms' ), | |
| 309 | - 'areYouSure' => __( 'Are you sure?', 'weforms' ), | |
| 310 | - 'selectNotification' => __( 'You must select a notification', 'weforms' ), | |
| 311 | - 'areYouSureDesc' => __( 'Anyone with existing URL won\'t be able to view and submit the form anymore.', 'weforms' ), | |
| 312 | - 'disableSharing' => __( 'Disable Sharing', 'weforms' ), | |
| 313 | - ] ); | |
| 314 | - } | |
| 315 | - | |
| 316 | - /** | |
| 317 | - * Add buttons in form submit area | |
| 318 | - * | |
| 319 | - * @return void | |
| 320 | - */ | |
| 321 | - public function add_form_submit_area() { | |
| 322 | - ?> | |
| 323 | - <input @click.prevent="" type="submit" name="submit" class="button button-primary" v-model="settings.submit_text"> | |
| 324 | - <?php | |
| 325 | - } | |
| 326 | - | |
| 327 | - /** | |
| 328 | - * Additional primary tabs | |
| 329 | - * | |
| 330 | - * @return void | |
| 331 | - */ | |
| 332 | - public function add_primary_tabs() { | |
| 333 | - $tabs = apply_filters( 'wpuf_contact_form_editor_tabs', [ | |
| 334 | - 'notification' => __( 'Notifications', 'weforms' ), | |
| 335 | - 'integration' => __( 'Integrations', 'weforms' ), | |
| 336 | - ] ); | |
| 337 | - | |
| 338 | - foreach ( $tabs as $key => $label ) { | |
| 339 | - ?> | |
| 340 | - <a href="#wpuf-form-builder-tab-<?php echo esc_attr( $key ); ?>" :class="['nav-tab', isActiveTab( '<?php echo esc_attr( $key ); ?>' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActive('<?php echo esc_attr( $key ); ?>')"><?php echo esc_attr( $label ); ?></a> | |
| 341 | - <?php | |
| 342 | - } | |
| 343 | - } | |
| 344 | - | |
| 345 | - public function add_primary_tab_contents() { | |
| 346 | - include __DIR__ . '/views/notification-integration.php'; | |
| 347 | - } | |
| 348 | - | |
| 349 | - /** | |
| 350 | - * Add settings tabs | |
| 351 | - * | |
| 352 | - * @return void | |
| 353 | - */ | |
| 354 | - public function add_settings_tabs() { | |
| 355 | - ?> | |
| 356 | - | |
| 357 | - <a href="#" :class="['nav-tab', isActiveSettingsTab( 'form' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'form' )" class="nav-tab"><?php esc_html_e( 'Form Settings', 'weforms' ); ?></a> | |
| 358 | - <a href="#" :class="['nav-tab', isActiveSettingsTab( 'restriction' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'restriction' )" class="nav-tab"><?php esc_html_e( 'Submission Restriction', 'weforms' ); ?></a> | |
| 359 | - <a href="#" :class="['nav-tab', isActiveSettingsTab( 'display' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'display' )" class="nav-tab"><?php esc_html_e( 'Display Settings', 'weforms' ); ?></a> | |
| 360 | - | |
| 361 | - <?php do_action( 'wpuf_contact_form_settings_tab' ); ?> | |
| 362 | - | |
| 363 | - <?php | |
| 364 | - } | |
| 365 | - | |
| 366 | - /** | |
| 367 | - * Add settings tabs | |
| 368 | - * | |
| 369 | - * @return void | |
| 370 | - */ | |
| 371 | - public function add_settings_tab_contents() { | |
| 372 | - ?> | |
| 373 | - <div id="wpuf-metabox-settings" class="tab-content" v-show="isActiveSettingsTab('form')"> | |
| 374 | - <?php include_once __DIR__ . '/views/form-settings.php'; ?> | |
| 375 | - </div> | |
| 376 | - | |
| 377 | - <div id="wpuf-metabox-settings-restriction" class="tab-content" v-show="isActiveSettingsTab('restriction')"> | |
| 378 | - <?php include_once __DIR__ . '/views/submission-restriction.php'; ?> | |
| 379 | - </div> | |
| 380 | - | |
| 381 | - <div id="wpuf-metabox-settings-display" class="tab-content" v-show="isActiveSettingsTab('display')"> | |
| 382 | - <?php include_once __DIR__ . '/views/display-settings.php'; ?> | |
| 383 | - </div> | |
| 384 | - | |
| 385 | - <?php do_action( 'wpuf_contact_form_settings_tab_content' ); ?> | |
| 386 | - | |
| 387 | - <?php | |
| 388 | - } | |
| 389 | - | |
| 390 | - public function shortcodes( $type = '' ) { | |
| 391 | - $shortcodes = []; | |
| 392 | - | |
| 393 | - $shortcodes['user'] = [ | |
| 394 | - 'title' => __( 'User', 'weforms' ), | |
| 395 | - 'codes' => [ | |
| 396 | - 'first_name' => [ 'title' => __( 'First Name', 'weforms' ), 'default' => 'reader' ], | |
| 397 | - ], | |
| 398 | - ]; | |
| 399 | - | |
| 400 | - if ( !empty( $type ) && !empty( $shortcodes[ $type ] ) ) { | |
| 401 | - return $shortcodes[ $type ]; | |
| 402 | - } | |
| 403 | - | |
| 404 | - return $shortcodes; | |
| 405 | - } | |
| 406 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * The Assets Class | |
| 5 | + */ | |
| 6 | +class WeForms_Form_Builder_Assets { | |
| 7 | + | |
| 8 | + public function __construct() { | |
| 9 | + $this->init_actions(); | |
| 10 | + } | |
| 11 | + | |
| 12 | + public function init_actions() { | |
| 13 | + | |
| 14 | + add_action( 'in_admin_header', array( $this, 'remove_admin_notices' ) ); | |
| 15 | + add_action( 'admin_enqueue_scripts', array( $this, 'builder_enqueue_scripts' ), 2000 ); | |
| 16 | + add_action( 'admin_print_scripts', array( $this, 'builder_mixins_script' ) ); | |
| 17 | + add_action( 'admin_footer', array( $this, 'admin_footer_js_templates' ) ); | |
| 18 | + | |
| 19 | + add_action( 'wpuf-form-builder-template-builder-stage-submit-area', array( $this, 'add_form_submit_area' ) ); | |
| 20 | + | |
| 21 | + add_action( 'wpuf-form-builder-tabs-contact_form', array( $this, 'add_primary_tabs' ) ); | |
| 22 | + add_action( 'wpuf-form-builder-tab-contents-contact_form', array( $this, 'add_primary_tab_contents' ) ); | |
| 23 | + | |
| 24 | + add_action( 'wpuf-form-builder-settings-tabs-contact_form', array( $this, 'add_settings_tabs' ) ); | |
| 25 | + add_action( 'wpuf-form-builder-settings-tab-contents-contact_form', array( $this, 'add_settings_tab_contents' ) ); | |
| 26 | + | |
| 27 | + do_action( 'weforms_form_builder_init' ); | |
| 28 | + } | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Remove all kinds of admin notices | |
| 32 | + * | |
| 33 | + * Since we don't have much space left on top of the page, | |
| 34 | + * we have to remove all kinds of admin notices | |
| 35 | + * | |
| 36 | + * @since 1.2.6 | |
| 37 | + * | |
| 38 | + * @return void | |
| 39 | + */ | |
| 40 | + public function remove_admin_notices() { | |
| 41 | + remove_all_actions( 'network_admin_notices' ); | |
| 42 | + remove_all_actions( 'user_admin_notices' ); | |
| 43 | + remove_all_actions( 'admin_notices' ); | |
| 44 | + remove_all_actions( 'all_admin_notices' ); | |
| 45 | + } | |
| 46 | + | |
| 47 | + | |
| 48 | + public function builder_enqueue_scripts() { | |
| 49 | + $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; | |
| 50 | + | |
| 51 | + weforms()->scripts->enqueue_backend(); | |
| 52 | + | |
| 53 | + $recaptcha = weforms_get_settings( 'recaptcha' ); | |
| 54 | + | |
| 55 | + $wpuf_form_builder = apply_filters( 'wpuf-form-builder-localize-script', array( | |
| 56 | + 'i18n' => $this->i18n(), | |
| 57 | + 'panel_sections' => weforms()->fields->get_field_groups(), | |
| 58 | + 'field_settings' => weforms()->fields->get_js_settings(), | |
| 59 | + 'pro_link' => self::get_pro_url(), | |
| 60 | + 'site_url' => site_url('/'), | |
| 61 | + 'defaultNotification' => array( | |
| 62 | + 'active' => 'true', | |
| 63 | + | |
| 64 | + 'type' => 'email', | |
| 65 | + 'smsTo' => '', | |
| 66 | + 'smsText' => '[{form_name}] ' . __( 'New Form Submission', 'weforms' ) . ' #{entry_id}', | |
| 67 | + | |
| 68 | + 'name' => 'Admin Notification', | |
| 69 | + 'subject' => '[{form_name}] New Form Submission #{entry_id}', | |
| 70 | + 'to' => '{admin_email}', | |
| 71 | + 'replyTo' => '', | |
| 72 | + 'message' => '{all_fields}', | |
| 73 | + 'fromName' => '', | |
| 74 | + 'fromAddress' => '{admin_email}', | |
| 75 | + 'cc' => '', | |
| 76 | + 'bcc' => '', | |
| 77 | + 'weforms_cond' => array( | |
| 78 | + 'condition_status' => 'no', | |
| 79 | + 'cond_logic' => 'any', | |
| 80 | + 'conditions' => array( | |
| 81 | + array( | |
| 82 | + 'name' => '', | |
| 83 | + 'operator' => '=', | |
| 84 | + 'option' => '' | |
| 85 | + ) | |
| 86 | + ) | |
| 87 | + ) | |
| 88 | + ), | |
| 89 | + 'integrations' => weforms()->integrations->get_integration_js_settings(), | |
| 90 | + 'recaptcha_site' => isset( $recaptcha->key ) ? $recaptcha->key : '', | |
| 91 | + 'recaptcha_secret' => isset( $recaptcha->secret ) ? $recaptcha->secret : '', | |
| 92 | + ) ); | |
| 93 | + | |
| 94 | + // mixins | |
| 95 | + $wpuf_mixins = array( | |
| 96 | + 'root' => apply_filters( 'weforms-builder-js-root-mixins', array( 'weforms_mixin_builder_root' ) ), | |
| 97 | + 'builder_stage' => apply_filters( 'weforms-builder-js-builder-stage-mixins', array( 'weforms_mixin_builder_stage' ) ), | |
| 98 | + 'form_fields' => apply_filters( 'weforms-builder-js-form-fields-mixins', array() ), | |
| 99 | + 'field_options' => apply_filters( 'weforms-builder-js-field-options-mixins', array() ), | |
| 100 | + ); | |
| 101 | + | |
| 102 | + $weforms = apply_filters( 'weforms_localized_script', array( | |
| 103 | + 'nonce' => wp_create_nonce( 'weforms' ), | |
| 104 | + 'confirm' => __( 'Are you sure?', 'weforms' ), | |
| 105 | + 'is_pro' => class_exists( 'WeForms_Pro' ) ? 'true' : 'false', | |
| 106 | + 'has_payment' => class_exists( 'WeForms_Payment' ) ? 'true' : 'false', | |
| 107 | + 'has_sms' => class_exists( 'WeForms_SMS_Notification' ) ? 'true' : 'false', | |
| 108 | + 'routes' => $this->get_vue_routes(), | |
| 109 | + 'routeComponents' => array( 'default' => null ), | |
| 110 | + 'mixins' => array( 'default' => null ), | |
| 111 | + 'assetsURL' => WEFORMS_ASSET_URI, | |
| 112 | + 'shortcodes' => $this->shortcodes(), | |
| 113 | + ) ); | |
| 114 | + | |
| 115 | + wp_localize_script( 'weforms-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder ); | |
| 116 | + wp_localize_script( 'weforms-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins ); | |
| 117 | + wp_localize_script( 'weforms-mixins', 'weForms', $weforms ); | |
| 118 | + | |
| 119 | + do_action( 'weforms_admin_after_scripts_loaded' ); | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * The pro url | |
| 124 | + * | |
| 125 | + * @return string | |
| 126 | + */ | |
| 127 | + public static function get_pro_url() { | |
| 128 | + $link = 'https://wedevs.com/weforms-upgrade/'; | |
| 129 | + | |
| 130 | + if ( $aff = get_option( '_weforms_aff_ref' ) ) { | |
| 131 | + $link = add_query_arg( array( 'ref' => $aff ), $link ); | |
| 132 | + } | |
| 133 | + | |
| 134 | + return $link; | |
| 135 | + } | |
| 136 | + | |
| 137 | + /** | |
| 138 | + * SPA Routes | |
| 139 | + * | |
| 140 | + * @return array | |
| 141 | + */ | |
| 142 | + public function get_vue_routes() { | |
| 143 | + $routes = array( | |
| 144 | + array( | |
| 145 | + 'path' => '/', | |
| 146 | + 'name' => 'home', | |
| 147 | + 'component' => 'Home' | |
| 148 | + ), | |
| 149 | + array( | |
| 150 | + 'path' => '/form/:id', | |
| 151 | + 'component' => 'FormHome', | |
| 152 | + 'children' => array( | |
| 153 | + array( | |
| 154 | + 'path' => '', | |
| 155 | + 'name' => 'form', | |
| 156 | + 'component' => 'SingleForm' | |
| 157 | + ), | |
| 158 | + array( | |
| 159 | + 'path' => 'entries', | |
| 160 | + 'component' => 'FormEntriesHome', | |
| 161 | + 'children' => array( | |
| 162 | + array( | |
| 163 | + 'path' => '', | |
| 164 | + 'name' => 'formEntries', | |
| 165 | + 'component' => 'FormEntries', | |
| 166 | + 'props' => true | |
| 167 | + ), | |
| 168 | + array( | |
| 169 | + 'path' => ':entryid', | |
| 170 | + 'name' => 'formEntriesSingle', | |
| 171 | + 'component' => 'FormEntriesSingle' | |
| 172 | + ) | |
| 173 | + ) | |
| 174 | + ), | |
| 175 | + array( | |
| 176 | + 'path' => 'edit', | |
| 177 | + 'name' => 'edit', | |
| 178 | + 'component' => 'FormEditComponent' | |
| 179 | + ) | |
| 180 | + ) | |
| 181 | + ), | |
| 182 | + array( | |
| 183 | + 'path' => '/tools', | |
| 184 | + 'name' => 'tools', | |
| 185 | + 'component' => 'Tools' | |
| 186 | + ), | |
| 187 | + array( | |
| 188 | + 'path' => '/entries', | |
| 189 | + 'name' => 'entries', | |
| 190 | + 'component' => 'Entries' | |
| 191 | + ), | |
| 192 | + array( | |
| 193 | + 'path' => '/help', | |
| 194 | + 'name' => 'help', | |
| 195 | + 'component' => 'Help' | |
| 196 | + ), | |
| 197 | + array( | |
| 198 | + 'path' => '/premium', | |
| 199 | + 'name' => 'premium', | |
| 200 | + 'component' => 'Premium' | |
| 201 | + ), | |
| 202 | + array( | |
| 203 | + 'path' => '/settings', | |
| 204 | + 'name' => 'settings', | |
| 205 | + 'component' => 'Settings' | |
| 206 | + ), | |
| 207 | + ); | |
| 208 | + | |
| 209 | + return apply_filters( 'weforms_vue_routes', $routes ); | |
| 210 | + } | |
| 211 | + | |
| 212 | + /** | |
| 213 | + * Print js scripts in admin head | |
| 214 | + * | |
| 215 | + * @since 2.5 | |
| 216 | + * | |
| 217 | + * @return void | |
| 218 | + */ | |
| 219 | + public function builder_mixins_script() { | |
| 220 | + ?> | |
| 221 | + <script> | |
| 222 | + if (!window.Promise) { | |
| 223 | + var promise_polyfill = document.createElement('script'); | |
| 224 | + promise_polyfill.setAttribute('src','https://cdn.polyfill.io/v2/polyfill.min.js'); | |
| 225 | + document.head.appendChild(promise_polyfill); | |
| 226 | + } | |
| 227 | + </script> | |
| 228 | + | |
| 229 | + <script> | |
| 230 | + var wpuf_form_builder_mixins = function(mixins, mixin_parent) { | |
| 231 | + if (!mixins || !mixins.length) { | |
| 232 | + return []; | |
| 233 | + } | |
| 234 | + | |
| 235 | + if (!mixin_parent) { | |
| 236 | + mixin_parent = window; | |
| 237 | + } | |
| 238 | + | |
| 239 | + return mixins.map(function (mixin) { | |
| 240 | + return mixin_parent[mixin]; | |
| 241 | + }); | |
| 242 | + }; | |
| 243 | + </script> | |
| 244 | + <?php | |
| 245 | + } | |
| 246 | + | |
| 247 | + /** | |
| 248 | + * Include vue component templates | |
| 249 | + * | |
| 250 | + * @since 2.5 | |
| 251 | + * | |
| 252 | + * @return void | |
| 253 | + */ | |
| 254 | + public function admin_footer_js_templates() { | |
| 255 | + | |
| 256 | + if ( ! defined( 'WPUF_ASSET_URI' ) ) { | |
| 257 | + define( 'WPUF_ASSET_URI', WEFORMS_ROOT_URI . '/assets' ); | |
| 258 | + } | |
| 259 | + | |
| 260 | + include WEFORMS_ROOT . '/assets/wpuf/js-templates/form-components.php'; | |
| 261 | + include WEFORMS_ROOT . '/assets/js-templates/form-components.php'; | |
| 262 | + include WEFORMS_ROOT . '/assets/js-templates/spa-components.php'; | |
| 263 | + | |
| 264 | + do_action( 'wpuf-form-builder-add-js-templates' ); | |
| 265 | + } | |
| 266 | + | |
| 267 | + /** | |
| 268 | + * i18n translatable strings | |
| 269 | + * | |
| 270 | + * @since 2.5 | |
| 271 | + * | |
| 272 | + * @return array | |
| 273 | + */ | |
| 274 | + private function i18n() { | |
| 275 | + return apply_filters( 'wpuf-form-builder-i18n', array( | |
| 276 | + 'advanced_options' => __( 'Advanced Options', 'weforms' ), | |
| 277 | + 'quiz_options' => __( 'Quiz Options', 'weforms' ), | |
| 278 | + 'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'weforms' ), | |
| 279 | + 'yes_delete_it' => __( 'Yes, delete it', 'weforms' ), | |
| 280 | + 'no_cancel_it' => __( 'No, cancel it', 'weforms' ), | |
| 281 | + 'ok' => __( 'OK', 'weforms' ), | |
| 282 | + 'cancel' => __( 'Cancel', 'weforms' ), | |
| 283 | + 'close' => __( 'Close', 'weforms' ), | |
| 284 | + 'disable' => __( 'Disable', 'weforms' ), | |
| 285 | + 'last_choice_warn_msg' => __( 'This field must contain at least one choice', 'weforms' ), | |
| 286 | + 'option' => __( 'Option', 'weforms' ), | |
| 287 | + 'row' => __( 'Row', 'weforms' ), | |
| 288 | + 'column' => __( 'Column', 'weforms' ), | |
| 289 | + 'last_column_warn_msg' => __( 'This field must contain at least one column', 'weforms' ), | |
| 290 | + 'is_a_pro_feature' => __( 'is available in Pro version', 'weforms' ), | |
| 291 | + 'pro_feature_msg' => __( 'Please upgrade to the Pro version to unlock all these awesome features', 'weforms' ), | |
| 292 | + 'upgrade_to_pro' => __( 'Get the Pro version', 'weforms' ), | |
| 293 | + 'select' => __( 'Select', 'weforms' ), | |
| 294 | + 'saved_form_data' => __( 'Saved form data', 'weforms' ), | |
| 295 | + 'unsaved_changes' => __( 'You have unsaved changes.', 'weforms' ), | |
| 296 | + 'areYouSureToLeave' => __( 'Are you sure to leave this page?', 'weforms' ), | |
| 297 | + 'copy_shortcode' => __( 'Click to copy shortcode', 'weforms' ), | |
| 298 | + | |
| 299 | + 'selectAnImage' => __( 'Select an image', 'weforms' ), | |
| 300 | + 'pleaseSelectAnImage' => __( 'Please select an image', 'weforms' ), | |
| 301 | + 'uploadAnImage' => __( 'Upload an image', 'weforms' ), | |
| 302 | + | |
| 303 | + 'shareYourForm' => __( 'Share Your Form', 'weforms' ), | |
| 304 | + 'shareYourFormDesc' => __( "Sharing your form enables <strong>anyone</strong> to view and submit the form without inserting the shortcode to a page.", 'weforms' ), | |
| 305 | + 'shareYourFormText' => __( "Anyone with this URL will be able to view and submit this form.", 'weforms' ), | |
| 306 | + 'areYouSure' => __( 'Are you sure?', 'weforms' ), | |
| 307 | + 'selectNotification' => __( 'You must select a notification', 'weforms' ), | |
| 308 | + 'areYouSureDesc' => __( 'Anyone with existing URL won\'t be able to view and submit the form anymore.', 'weforms' ), | |
| 309 | + 'disableSharing' => __( 'Disable Sharing', 'weforms' ), | |
| 310 | + | |
| 311 | + ) ); | |
| 312 | + } | |
| 313 | + | |
| 314 | + /** | |
| 315 | + * Add buttons in form submit area | |
| 316 | + * | |
| 317 | + * @return void | |
| 318 | + */ | |
| 319 | + public function add_form_submit_area() { | |
| 320 | + ?> | |
| 321 | + <input @click.prevent="" type="submit" name="submit" class="button button-primary" v-model="settings.submit_text"> | |
| 322 | + <?php | |
| 323 | + } | |
| 324 | + | |
| 325 | + /** | |
| 326 | + * Additional primary tabs | |
| 327 | + * | |
| 328 | + * @return void | |
| 329 | + */ | |
| 330 | + public function add_primary_tabs() { | |
| 331 | + $tabs = apply_filters( 'wpuf_contact_form_editor_tabs', array( | |
| 332 | + 'notification' => __( 'Notifications', 'weforms' ), | |
| 333 | + 'integration' => __( 'Integrations', 'weforms' ) | |
| 334 | + ) ); | |
| 335 | + | |
| 336 | + foreach ($tabs as $key => $label) { | |
| 337 | + ?> | |
| 338 | + <a href="#wpuf-form-builder-tab-<?php echo $key; ?>" :class="['nav-tab', isActiveTab( '<?php echo $key; ?>' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActive('<?php echo $key; ?>')"><?php echo $label; ?></a> | |
| 339 | + <?php | |
| 340 | + } | |
| 341 | + } | |
| 342 | + | |
| 343 | + public function add_primary_tab_contents() { | |
| 344 | + include dirname( __FILE__ ) . '/views/notification-integration.php'; | |
| 345 | + } | |
| 346 | + | |
| 347 | + /** | |
| 348 | + * Add settings tabs | |
| 349 | + * | |
| 350 | + * @return void | |
| 351 | + */ | |
| 352 | + public function add_settings_tabs() { | |
| 353 | + ?> | |
| 354 | + | |
| 355 | + <a href="#" :class="['nav-tab', isActiveSettingsTab( 'form' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'form' )" class="nav-tab"><?php _e( 'Form Settings', 'weforms' ); ?></a> | |
| 356 | + <a href="#" :class="['nav-tab', isActiveSettingsTab( 'restriction' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'restriction' )" class="nav-tab"><?php _e( 'Submission Restriction', 'weforms' ); ?></a> | |
| 357 | + <a href="#" :class="['nav-tab', isActiveSettingsTab( 'display' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'display' )" class="nav-tab"><?php _e( 'Display Settings', 'weforms' ); ?></a> | |
| 358 | + | |
| 359 | + <?php do_action( 'wpuf_contact_form_settings_tab' ); ?> | |
| 360 | + | |
| 361 | + <?php | |
| 362 | + } | |
| 363 | + | |
| 364 | + /** | |
| 365 | + * Add settings tabs | |
| 366 | + * | |
| 367 | + * @return void | |
| 368 | + */ | |
| 369 | + public function add_settings_tab_contents() { | |
| 370 | + ?> | |
| 371 | + <div id="wpuf-metabox-settings" class="tab-content" v-show="isActiveSettingsTab('form')"> | |
| 372 | + <?php include_once dirname( __FILE__ ) . '/views/form-settings.php'; ?> | |
| 373 | + </div> | |
| 374 | + | |
| 375 | + <div id="wpuf-metabox-settings-restriction" class="tab-content" v-show="isActiveSettingsTab('restriction')"> | |
| 376 | + <?php include_once dirname( __FILE__ ) . '/views/submission-restriction.php'; ?> | |
| 377 | + </div> | |
| 378 | + | |
| 379 | + <div id="wpuf-metabox-settings-display" class="tab-content" v-show="isActiveSettingsTab('display')"> | |
| 380 | + <?php include_once dirname( __FILE__ ) . '/views/display-settings.php'; ?> | |
| 381 | + </div> | |
| 382 | + | |
| 383 | + <?php do_action( 'wpuf_contact_form_settings_tab_content' ); ?> | |
| 384 | + | |
| 385 | + <?php | |
| 386 | + } | |
| 387 | + | |
| 388 | + | |
| 389 | + public function shortcodes( $type = '' ) { | |
| 390 | + $shortcodes = []; | |
| 391 | + | |
| 392 | + $shortcodes['user'] = [ | |
| 393 | + 'title' => __( 'User', 'weforms' ), | |
| 394 | + 'codes' => [ | |
| 395 | + 'first_name' => [ 'title' => __( 'First Name', 'weforms' ), 'default' => 'reader' ], | |
| 396 | + ] | |
| 397 | + ]; | |
| 398 | + | |
| 399 | + if ( !empty( $type ) && !empty( $shortcodes[ $type ] ) ) { | |
| 400 | + return $shortcodes[ $type ]; | |
| 401 | + } | |
| 402 | + | |
| 403 | + return $shortcodes; | |
| 404 | + } | |
| 405 | +} | |