Plugin Directory

Changeset 3299719


Ignore:
Timestamp:
05/24/2025 08:40:04 AM (10 months ago)
Author:
mosparo
Message:

Added the module for WS Form forms.

Location:
mosparo-integration
Files:
4 added
4 edited
64 copied

Legend:

Unmodified
Added
Removed
  • mosparo-integration/tags/1.14.0/mosparo-integration.php

    r3285077 r3299719  
    1515 * Author URI:        https://mosparo.io/
    1616 * License:           MIT
    17  * Version:           1.13.6
     17 * Version:           1.14.0
    1818 * Text Domain:       mosparo-integration
    1919 * Domain Path:       /languages
  • mosparo-integration/tags/1.14.0/readme.txt

    r3285077 r3299719  
    55Tested up to: 6.8.1
    66Requires PHP: 7.4
    7 Stable tag: 1.13.6
     7Stable tag: 1.14.0
    88License: MIT
    99
     
    105105== Changelog ==
    106106
     107= 1.14.0 =
     108*Release Date: 24th May 2025*
     109
     110* [Enhancement] Added a module to protect WS Form forms
     111
    107112= 1.13.6 =
    108113*Release Date: 30th April 2025*
  • mosparo-integration/tags/1.14.0/src/MosparoIntegration/Helper/FrontendHelper.php

    r3244107 r3299719  
    122122    public function generateField(Connection $connection, $options = [], $field = null)
    123123    {
    124         $this->registerResources($connection);
    125 
    126124        $instanceId = uniqid();
    127125
    128         $options = $this->getFrontendOptions($options, $connection);
    129         $additionalCode = $this->prepareAdditionalJavaScriptCode($instanceId, $field);
     126        $script = $this->getScript($connection, $instanceId, $options, $field);
    130127
    131128        $html = sprintf('
    132129            <div id="mosparo-box-%s"></div>
    133130            <script>
    134                 if (typeof mosparoInstances == "undefined") {
    135                     var mosparoInstances = [];
     131                %s
     132            </script>',
     133            esc_attr($instanceId),
     134            $script
     135        );
     136
     137        return $html;
     138    }
     139
     140    public function getScript(Connection $connection, $instanceId, $options = [], $field = null)
     141    {
     142        $this->registerResources($connection);
     143
     144        $options = $this->getFrontendOptions($options, $connection);
     145        $additionalCode = $this->prepareAdditionalJavaScriptCode($instanceId, $field);
     146
     147        return sprintf('
     148            if (typeof mosparoInstances == "undefined") {
     149                var mosparoInstances = [];
     150            }
     151           
     152            (function () {
     153                let scriptEl = null;
     154                if (typeof mosparo == "undefined") {
     155                    scriptEl = document.createElement("script");
     156                    scriptEl.setAttribute("src", "%s");
     157                    document.body.appendChild(scriptEl);
    136158                }
    137159               
    138                 (function () {
    139                     let scriptEl = null;
    140                     if (typeof mosparo == "undefined") {
    141                         scriptEl = document.createElement("script");
    142                         scriptEl.setAttribute("src", "%s");
    143                         document.body.appendChild(scriptEl);
    144                     }
    145                    
    146                     let initializeMosparo = function () {
    147                         let id = "mosparo-box-%s";
    148                         if (typeof mosparoInstances[id] !== "undefined") {
     160                let initializeMosparo = function () {
     161                    let id = "mosparo-box-%s";
     162                    if (typeof mosparoInstances[id] !== "undefined") {
     163                        return;
     164                    }
     165                   
     166                    let mosparoFieldEl = document.getElementById(id);
     167                    if (!mosparoFieldEl) {
     168                        return;
     169                    }
     170                   
     171                    let formEl = null;
     172                    let el = mosparoFieldEl;
     173                    while ((el = el.parentNode) && el !== document) {
     174                        if (el.matches("form")) {
     175                            formEl = el;
     176                            break;
     177                        }
     178                    }
     179               
     180                    let options = %s;
     181                    let resetMosparoField = function () {
     182                        if (!mosparoInstances[id]) {
    149183                            return;
    150184                        }
    151185                       
    152                         let mosparoFieldEl = document.getElementById(id);
    153                         let el = mosparoFieldEl;
    154                         let formEl = null;
    155                         while ((el = el.parentNode) && el !== document) {
    156                             if (el.matches("form")) {
    157                                 formEl = el;
    158                                 break;
    159                             }
    160                         }
    161                    
    162                         let options = %s;
    163                         let resetMosparoField = function () {
    164                             if (!mosparoInstances[id]) {
    165                                 return;
    166                             }
    167                            
    168                             mosparoInstances[id].resetState();
    169                             mosparoInstances[id].requestSubmitToken();
    170                         };
    171                        
    172                         %s
    173                        
    174                         mosparoInstances[id] = new mosparo(id, "%s", "%s", "%s", options);
    175                     };
    176                    
    177                     if (scriptEl !== null) {
    178                         scriptEl.addEventListener("load", function () {
    179                             initializeMosparo();
    180                         });
    181                     } else if (document.readyState !== "loading") {
     186                        mosparoInstances[id].resetState();
     187                        mosparoInstances[id].requestSubmitToken();
     188                    };
     189                   
     190                    %s
     191                   
     192                    mosparoInstances[id] = new mosparo(id, "%s", "%s", "%s", options);
     193                };
     194               
     195                if (scriptEl !== null) {
     196                    scriptEl.addEventListener("load", function () {
    182197                        initializeMosparo();
    183                     } else {
    184                         document.addEventListener("DOMContentLoaded", initializeMosparo);
    185                     }
    186                     document.addEventListener("mosparo_integration_initialize_fields", initializeMosparo);
    187                    
    188                     %s
    189                 })();
    190             </script>',
    191             esc_attr($instanceId),
     198                    });
     199                } else if (document.readyState !== "loading") {
     200                    initializeMosparo();
     201                } else {
     202                    document.addEventListener("DOMContentLoaded", initializeMosparo);
     203                }
     204                document.addEventListener("mosparo_integration_initialize_fields", initializeMosparo);
     205               
     206                %s
     207            })();',
    192208            $this->getJavaScriptUrl($connection),
    193209            esc_attr($instanceId),
     
    199215            $additionalCode['after']
    200216        );
    201 
    202         return $html;
    203217    }
    204218
     
    319333        }
    320334
     335        if ($field === 'wsform') {
     336            return [
     337                'before' => '
     338                    options.onGetFormData = function (formElement, formData) {
     339                        let ignoredFields = [];
     340                        for (let key of formData.ignoredFields) {
     341                            if (key.indexOf("wsf_") === -1) {
     342                                ignoredFields.push(key);
     343                            }
     344                        }
     345                       
     346                        formData.ignoredFields = ignoredFields;
     347                       
     348                        return formData;
     349                    };
     350                ',
     351                'after' => sprintf('
     352                    jQuery(document).on("wsf-rendered", function (event, formObject, formId, instanceId, eventFormEl, formCanvasEl) {
     353                        let mosparoEl = jQuery("#mosparo-box-%s");
     354                        let formEl = mosparoEl.parents("form");
     355                        if (formEl.data("id") == formId) {
     356                            initializeMosparo();
     357                        }
     358                    });               
     359                ', $instanceId),
     360            ];
     361        }
     362
    321363        return ['before' => '', 'after' => ''];
    322364    }
  • mosparo-integration/tags/1.14.0/src/MosparoIntegration/Helper/ModuleHelper.php

    r3242780 r3299719  
    1717use MosparoIntegration\Module\NinjaForms\NinjaFormsModule;
    1818use MosparoIntegration\Module\WPForms\WPFormsModule;
     19use MosparoIntegration\Module\WSForm\WSFormModule;
    1920use MosparoIntegration\Module\WooCommerceAccount\WooCommerceAccountModule;
    2021
     
    3738        WooCommerceAccountModule::class,
    3839        WPFormsModule::class,
     40        WSFormModule::class,
    3941    ];
    4042    protected $activeModules = [];
  • mosparo-integration/trunk/mosparo-integration.php

    r3285077 r3299719  
    1515 * Author URI:        https://mosparo.io/
    1616 * License:           MIT
    17  * Version:           1.13.6
     17 * Version:           1.14.0
    1818 * Text Domain:       mosparo-integration
    1919 * Domain Path:       /languages
  • mosparo-integration/trunk/readme.txt

    r3285077 r3299719  
    55Tested up to: 6.8.1
    66Requires PHP: 7.4
    7 Stable tag: 1.13.6
     7Stable tag: 1.14.0
    88License: MIT
    99
     
    105105== Changelog ==
    106106
     107= 1.14.0 =
     108*Release Date: 24th May 2025*
     109
     110* [Enhancement] Added a module to protect WS Form forms
     111
    107112= 1.13.6 =
    108113*Release Date: 30th April 2025*
  • mosparo-integration/trunk/src/MosparoIntegration/Helper/FrontendHelper.php

    r3244107 r3299719  
    122122    public function generateField(Connection $connection, $options = [], $field = null)
    123123    {
    124         $this->registerResources($connection);
    125 
    126124        $instanceId = uniqid();
    127125
    128         $options = $this->getFrontendOptions($options, $connection);
    129         $additionalCode = $this->prepareAdditionalJavaScriptCode($instanceId, $field);
     126        $script = $this->getScript($connection, $instanceId, $options, $field);
    130127
    131128        $html = sprintf('
    132129            <div id="mosparo-box-%s"></div>
    133130            <script>
    134                 if (typeof mosparoInstances == "undefined") {
    135                     var mosparoInstances = [];
     131                %s
     132            </script>',
     133            esc_attr($instanceId),
     134            $script
     135        );
     136
     137        return $html;
     138    }
     139
     140    public function getScript(Connection $connection, $instanceId, $options = [], $field = null)
     141    {
     142        $this->registerResources($connection);
     143
     144        $options = $this->getFrontendOptions($options, $connection);
     145        $additionalCode = $this->prepareAdditionalJavaScriptCode($instanceId, $field);
     146
     147        return sprintf('
     148            if (typeof mosparoInstances == "undefined") {
     149                var mosparoInstances = [];
     150            }
     151           
     152            (function () {
     153                let scriptEl = null;
     154                if (typeof mosparo == "undefined") {
     155                    scriptEl = document.createElement("script");
     156                    scriptEl.setAttribute("src", "%s");
     157                    document.body.appendChild(scriptEl);
    136158                }
    137159               
    138                 (function () {
    139                     let scriptEl = null;
    140                     if (typeof mosparo == "undefined") {
    141                         scriptEl = document.createElement("script");
    142                         scriptEl.setAttribute("src", "%s");
    143                         document.body.appendChild(scriptEl);
    144                     }
    145                    
    146                     let initializeMosparo = function () {
    147                         let id = "mosparo-box-%s";
    148                         if (typeof mosparoInstances[id] !== "undefined") {
     160                let initializeMosparo = function () {
     161                    let id = "mosparo-box-%s";
     162                    if (typeof mosparoInstances[id] !== "undefined") {
     163                        return;
     164                    }
     165                   
     166                    let mosparoFieldEl = document.getElementById(id);
     167                    if (!mosparoFieldEl) {
     168                        return;
     169                    }
     170                   
     171                    let formEl = null;
     172                    let el = mosparoFieldEl;
     173                    while ((el = el.parentNode) && el !== document) {
     174                        if (el.matches("form")) {
     175                            formEl = el;
     176                            break;
     177                        }
     178                    }
     179               
     180                    let options = %s;
     181                    let resetMosparoField = function () {
     182                        if (!mosparoInstances[id]) {
    149183                            return;
    150184                        }
    151185                       
    152                         let mosparoFieldEl = document.getElementById(id);
    153                         let el = mosparoFieldEl;
    154                         let formEl = null;
    155                         while ((el = el.parentNode) && el !== document) {
    156                             if (el.matches("form")) {
    157                                 formEl = el;
    158                                 break;
    159                             }
    160                         }
    161                    
    162                         let options = %s;
    163                         let resetMosparoField = function () {
    164                             if (!mosparoInstances[id]) {
    165                                 return;
    166                             }
    167                            
    168                             mosparoInstances[id].resetState();
    169                             mosparoInstances[id].requestSubmitToken();
    170                         };
    171                        
    172                         %s
    173                        
    174                         mosparoInstances[id] = new mosparo(id, "%s", "%s", "%s", options);
    175                     };
    176                    
    177                     if (scriptEl !== null) {
    178                         scriptEl.addEventListener("load", function () {
    179                             initializeMosparo();
    180                         });
    181                     } else if (document.readyState !== "loading") {
     186                        mosparoInstances[id].resetState();
     187                        mosparoInstances[id].requestSubmitToken();
     188                    };
     189                   
     190                    %s
     191                   
     192                    mosparoInstances[id] = new mosparo(id, "%s", "%s", "%s", options);
     193                };
     194               
     195                if (scriptEl !== null) {
     196                    scriptEl.addEventListener("load", function () {
    182197                        initializeMosparo();
    183                     } else {
    184                         document.addEventListener("DOMContentLoaded", initializeMosparo);
    185                     }
    186                     document.addEventListener("mosparo_integration_initialize_fields", initializeMosparo);
    187                    
    188                     %s
    189                 })();
    190             </script>',
    191             esc_attr($instanceId),
     198                    });
     199                } else if (document.readyState !== "loading") {
     200                    initializeMosparo();
     201                } else {
     202                    document.addEventListener("DOMContentLoaded", initializeMosparo);
     203                }
     204                document.addEventListener("mosparo_integration_initialize_fields", initializeMosparo);
     205               
     206                %s
     207            })();',
    192208            $this->getJavaScriptUrl($connection),
    193209            esc_attr($instanceId),
     
    199215            $additionalCode['after']
    200216        );
    201 
    202         return $html;
    203217    }
    204218
     
    319333        }
    320334
     335        if ($field === 'wsform') {
     336            return [
     337                'before' => '
     338                    options.onGetFormData = function (formElement, formData) {
     339                        let ignoredFields = [];
     340                        for (let key of formData.ignoredFields) {
     341                            if (key.indexOf("wsf_") === -1) {
     342                                ignoredFields.push(key);
     343                            }
     344                        }
     345                       
     346                        formData.ignoredFields = ignoredFields;
     347                       
     348                        return formData;
     349                    };
     350                ',
     351                'after' => sprintf('
     352                    jQuery(document).on("wsf-rendered", function (event, formObject, formId, instanceId, eventFormEl, formCanvasEl) {
     353                        let mosparoEl = jQuery("#mosparo-box-%s");
     354                        let formEl = mosparoEl.parents("form");
     355                        if (formEl.data("id") == formId) {
     356                            initializeMosparo();
     357                        }
     358                    });               
     359                ', $instanceId),
     360            ];
     361        }
     362
    321363        return ['before' => '', 'after' => ''];
    322364    }
  • mosparo-integration/trunk/src/MosparoIntegration/Helper/ModuleHelper.php

    r3242780 r3299719  
    1717use MosparoIntegration\Module\NinjaForms\NinjaFormsModule;
    1818use MosparoIntegration\Module\WPForms\WPFormsModule;
     19use MosparoIntegration\Module\WSForm\WSFormModule;
    1920use MosparoIntegration\Module\WooCommerceAccount\WooCommerceAccountModule;
    2021
     
    3738        WooCommerceAccountModule::class,
    3839        WPFormsModule::class,
     40        WSFormModule::class,
    3941    ];
    4042    protected $activeModules = [];
Note: See TracChangeset for help on using the changeset viewer.