Plugin Directory

Changeset 3207535


Ignore:
Timestamp:
12/13/2024 10:44:52 AM (16 months ago)
Author:
staticsnap
Message:

Release 0.3.0 version

Location:
static-snap
Files:
500 added
10 edited

Legend:

Unmodified
Added
Removed
  • static-snap/trunk/assets/js/contact-form-7.asset.php

    r3191166 r3207535  
    1 <?php return array('dependencies' => array(), 'version' => '09d69513e01d45a2b8e1');
     1<?php return array('dependencies' => array('wp-i18n'), 'version' => '6a06ac157e253cdb46a3');
  • static-snap/trunk/assets/js/contact-form-7.js

    r3191166 r3207535  
    1515/* harmony import */ var _staticsnap_frontend__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @staticsnap/frontend */ "@staticsnap/frontend");
    1616/* harmony import */ var _staticsnap_frontend__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_staticsnap_frontend__WEBPACK_IMPORTED_MODULE_0__);
     17/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
     18/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
     19
    1720
    1821class ContactForm7 extends _staticsnap_frontend__WEBPACK_IMPORTED_MODULE_0__.FormBase {
     
    2629    super('[data-static-snap-type="form"][data-static-snap-form-type="contact-form-7"]');
    2730  }
    28   onSubmit(_e, form, _submitData) {
    29     this.setMessage(form, 'success');
     31  onSubmit(_e, form, _submitData, responseData) {
     32    const settings = this.getFormSettings(responseData);
     33    this.setMessage(form, responseData.type === 'item' && responseData?.data?.saved ? 'success' : 'error', settings);
    3034  }
    3135  onError(_e, form, _error) {
    32     this.setMessage(form, 'error');
     36    this.setMessage(form, 'error', {
     37      messages: {
     38        error: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('An error occurred, please try again later.', 'static-snap'),
     39        invalid: '',
     40        required: '',
     41        success: ''
     42      }
     43    });
    3344  }
    34   setMessage(form, type) {
     45  setMessage(form, type, settings) {
     46    const matchTypeToMessage = {
     47      error: settings?.messages?.error,
     48      field_error: settings?.messages?.required,
     49      invalid_error: settings?.messages?.invalid,
     50      success: settings?.messages?.success
     51    };
    3552    const noticeElement = this.getNoticeElement(form);
    36     const message = this.getNoticeMessageOrRedirect(form, type);
     53    const message = matchTypeToMessage[type] || (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('An error occurred, please try again later.', 'static-snap');
    3754    noticeElement.textContent = message;
    3855    const messageClass = this.extensionMessagesClasses[type];
     
    6481
    6582module.exports = StaticSnapFrontendClasses;
     83
     84/***/ }),
     85
     86/***/ "@wordpress/i18n":
     87/*!******************************!*\
     88  !*** external ["wp","i18n"] ***!
     89  \******************************/
     90/***/ ((module) => {
     91
     92module.exports = window["wp"]["i18n"];
    6693
    6794/***/ })
  • static-snap/trunk/assets/js/contact-form-7.js.map

    r3191166 r3207535  
    1 {"version":3,"file":"contact-form-7.js","mappings":";;;;;;;;;;;;;;;;AAA8E;AAE/D,MAAMC,YAAY,SAASD,0DAAQ,CAAC;EACzCE,wBAAwB,GAAiD;IAC/EC,KAAK,EAAE,QAAQ;IACfC,WAAW,EAAE,QAAQ;IACrBC,aAAa,EAAE,QAAQ;IACvBC,OAAO,EAAE;EACX,CAAC;EAEDC,WAAWA,CAAA,EAAG;IACZ,KAAK,CAAC,6EAA6E,CAAC;EACtF;EAEUC,QAAQA,CAACC,EAAS,EAAEC,IAAqB,EAAEC,WAAoB,EAAQ;IAC/E,IAAI,CAACC,UAAU,CAACF,IAAI,EAAE,SAAS,CAAC;EAClC;EAEUG,OAAOA,CAACJ,EAAS,EAAEC,IAAqB,EAAEI,MAAe,EAAQ;IACzE,IAAI,CAACF,UAAU,CAACF,IAAI,EAAE,OAAO,CAAC;EAChC;EAEQE,UAAUA,CAACF,IAAqB,EAAEK,IAAkC,EAAQ;IAClF,MAAMC,aAAa,GAAG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CAAC,C","sources":["webpack://static-snap/./src/extensions/forms/contact-form-7/app/src/contact-form-7.ts","webpack://static-snap/external var \"StaticSnapFrontendClasses\"","webpack://static-snap/webpack/bootstrap","webpack://static-snap/webpack/runtime/compat get default export","webpack://static-snap/webpack/runtime/define property getters","webpack://static-snap/webpack/runtime/hasOwnProperty shorthand","webpack://static-snap/webpack/runtime/make namespace object","webpack://static-snap/./src/extensions/forms/contact-form-7/app/src/init.ts"],"sourcesContent":["import { FormBase, FormBaseGetNoticeMessageType } from '@staticsnap/frontend';\n\nexport default class ContactForm7 extends FormBase {\n  private extensionMessagesClasses: Record<FormBaseGetNoticeMessageType, string> = {\n    error: 'failed',\n    field_error: 'failed',\n    invalid_error: 'failed',\n    success: 'sent',\n  };\n\n  constructor() {\n    super('[data-static-snap-type=\"form\"][data-static-snap-form-type=\"contact-form-7\"]');\n  }\n\n  protected onSubmit(_e: Event, form: HTMLFormElement, _submitData: unknown): void {\n    this.setMessage(form, 'success');\n  }\n\n  protected onError(_e: Event, form: HTMLFormElement, _error: unknown): void {\n    this.setMessage(form, 'error');\n  }\n\n  private setMessage(form: HTMLFormElement, type: FormBaseGetNoticeMessageType): void {\n    const noticeElement = this.getNoticeElement(form);\n    const message = this.getNoticeMessageOrRedirect(form, type);\n    noticeElement.textContent = message;\n    const messageClass = this.extensionMessagesClasses[type];\n    // remove other form classes\n    Object.values(this.extensionMessagesClasses).forEach((messageClass) => {\n      form.classList.remove(messageClass);\n    });\n    form.classList.remove('init');\n    form.classList.add(messageClass);\n  }\n\n  private getNoticeElement(form: HTMLFormElement): Element {\n    let noticeElement = form.querySelector(' .wpcf7-response-output');\n\n    if (!noticeElement) {\n      noticeElement = document.createElement('div');\n      noticeElement.classList.add('wpcf7-response-output');\n      form.appendChild(noticeElement);\n    }\n    return noticeElement;\n  }\n}\n","module.exports = StaticSnapFrontendClasses;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import ContactForm7 from './contact-form-7';\n\nnew ContactForm7();\n"],"names":["FormBase","ContactForm7","extensionMessagesClasses","error","field_error","invalid_error","success","constructor","onSubmit","_e","form","_submitData","setMessage","onError","_error","type","noticeElement","getNoticeElement","message","getNoticeMessageOrRedirect","textContent","messageClass","Object","values","forEach","classList","remove","add","querySelector","document","createElement","appendChild"],"sourceRoot":""}
     1{"version":3,"file":"contact-form-7.js","mappings":";;;;;;;;;;;;;;;;;;AAK8B;AAEO;AAEtB,MAAME,YAAY,SAASF,0DAAQ,CAAC;EACzCG,wBAAwB,GAAiD;IAC/EC,KAAK,EAAE,QAAQ;IACfC,WAAW,EAAE,QAAQ;IACrB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W,GAAGD,OAAO;IACnC,MAAME,YAAY,GAAG,IAAI,CAAC3B,wBAAwB,CAACc,IAAI,CAAC;IACxD;IACAc,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC7B,wBAAwB,CAAC,CAAC8B,OAAO,CAAEH,YAAY,IAAK;MACrEnB,IAAI,CAACuB,SAAS,CAACC,MAAM,CAACL,YAAY,CAAC;IACrC,CAAC,CAAC;IACFnB,IAAI,CAACuB,SAAS,CAACC,MAAM,CAAC,MAAM,CAAC;IAC7BxB,IAAI,CAACuB,SAAS,CAACE,GAAG,CAACN,YAAY,CAAC;EAClC;EAEQH,gBAAgBA,CAAChB,IAAqB,EAAW;IACvD,IAAIe,aAAa,GAAGf,IAAI,CAAC0B,aAAa,CAAC,yBAAyB,CAAC;IAEjE,IAAI,CAACX,aAAa,EAAE;MAClBA,aAAa,GAAGY,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;MAC7Cb,aAAa,CAACQ,SAAS,CAACE,GAAG,CAAC,uBAAuB,CAAC;MACpDzB,IAAI,CAAC6B,WAAW,CAACd,aAAa,CAAC;IACjC;IACA,OAAOA,aAAa;EACtB;AACF;;;;;;;;;;ACnFA;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;ACN4C;AAE5C,IAAIxB,uDAAY,CAAC,CAAC,C","sources":["webpack://static-snap/./src/extensions/forms/contact-form-7/app/src/contact-form-7.ts","webpack://static-snap/external var \"StaticSnapFrontendClasses\"","webpack://static-snap/external window [\"wp\",\"i18n\"]","webpack://static-snap/webpack/bootstrap","webpack://static-snap/webpack/runtime/compat get default export","webpack://static-snap/webpack/runtime/define property getters","webpack://static-snap/webpack/runtime/hasOwnProperty shorthand","webpack://static-snap/webpack/runtime/make namespace object","webpack://static-snap/./src/extensions/forms/contact-form-7/app/src/init.ts"],"sourcesContent":["import {\n  FormBase,\n  FormBaseGetNoticeMessageType,\n  FormSubmitResponseInterface,\n  WebsiteFormSettings,\n} from '@staticsnap/frontend';\nimport ApiResponseInterface from '@staticsnap/frontend/src/interfaces/api-response.interface';\nimport { __ } from '@wordpress/i18n';\n\nexport default class ContactForm7 extends FormBase {\n  private extensionMessagesClasses: Record<FormBaseGetNoticeMessageType, string> = {\n    error: 'failed',\n    field_error: 'failed',\n    invalid_error: 'failed',\n    success: 'sent',\n  };\n\n  constructor() {\n    super('[data-static-snap-type=\"form\"][data-static-snap-form-type=\"contact-form-7\"]');\n  }\n\n  protected onSubmit(\n    _e: Event,\n    form: HTMLFormElement,\n    _submitData: unknown,\n    responseData: ApiResponseInterface<FormSubmitResponseInterface>\n  ): void {\n    const settings = this.getFormSettings(responseData);\n\n    this.setMessage(\n      form,\n      responseData.type === 'item' && responseData?.data?.saved ? 'success' : 'error',\n      settings\n    );\n  }\n\n  protected onError(_e: Event, form: HTMLFormElement, _error: unknown): void {\n    this.setMessage(form, 'error', {\n      messages: {\n        error: __('An error occurred, please try again later.', 'static-snap'),\n        invalid: '',\n        required: '',\n        success: '',\n      },\n    });\n  }\n\n  private setMessage(\n    form: HTMLFormElement,\n    type: FormBaseGetNoticeMessageType,\n    settings: WebsiteFormSettings\n  ): void {\n    const matchTypeToMessage = {\n      error: settings?.messages?.error,\n      field_error: settings?.messages?.required,\n      invalid_error: settings?.messages?.invalid,\n      success: settings?.messages?.success,\n    };\n\n    const noticeElement = this.getNoticeElement(form);\n    const message =\n      matchTypeToMessage[type] || __('An error occurred, please try again later.', 'static-snap');\n\n    noticeElement.textContent = message;\n    const messageClass = this.extensionMessagesClasses[type];\n    // remove other form classes\n    Object.values(this.extensionMessagesClasses).forEach((messageClass) => {\n      form.classList.remove(messageClass);\n    });\n    form.classList.remove('init');\n    form.classList.add(messageClass);\n  }\n\n  private getNoticeElement(form: HTMLFormElement): Element {\n    let noticeElement = form.querySelector(' .wpcf7-response-output');\n\n    if (!noticeElement) {\n      noticeElement = document.createElement('div');\n      noticeElement.classList.add('wpcf7-response-output');\n      form.appendChild(noticeElement);\n    }\n    return noticeElement;\n  }\n}\n","module.exports = StaticSnapFrontendClasses;","module.exports = window[\"wp\"][\"i18n\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import ContactForm7 from './contact-form-7';\n\nnew ContactForm7();\n"],"names":["FormBase","__","ContactForm7","extensionMessagesClasses","error","field_error","invalid_error","success","constructor","onSubmit","_e","form","_submitData","responseData","settings","getFormSettings","setMessage","type","data","saved","onError","_error","messages","invalid","required","matchTypeToMessage","noticeElement","getNoticeElement","message","textContent","messageClass","Object","values","forEach","classList","remove","add","querySelector","document","createElement","appendChild"],"sourceRoot":""}
  • static-snap/trunk/assets/js/wp-forms.asset.php

    r3191166 r3207535  
    1 <?php return array('dependencies' => array(), 'version' => '391424632d17a58b3881');
     1<?php return array('dependencies' => array('wp-i18n'), 'version' => 'af2030d83c7e18ddbfdb');
  • static-snap/trunk/assets/js/wp-forms.js

    r3191166 r3207535  
    1515/* harmony import */ var _staticsnap_frontend__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @staticsnap/frontend */ "@staticsnap/frontend");
    1616/* harmony import */ var _staticsnap_frontend__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_staticsnap_frontend__WEBPACK_IMPORTED_MODULE_0__);
     17/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
     18/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
     19
    1720
    1821class WpForm extends _staticsnap_frontend__WEBPACK_IMPORTED_MODULE_0__.FormBase {
     
    2427  };
    2528  constructor() {
    26     super('[data-static-snap-type="form"][data-static-snap-form-type="wpform"]');
     29    super('[data-static-snap-type="form"][data-static-snap-form-type="wp-forms"]');
    2730  }
    28   onSubmit(_e, form, _submitData) {
    29     this.setMessage(form, 'success');
     31  onSubmit(_e, form, _submitData, responseData) {
     32    const settings = this.getFormSettings(responseData);
     33    this.setMessage(form, responseData.type === 'item' && responseData?.data?.saved ? 'success' : 'error', settings);
     34
     35    // TODO: add webhook support
     36    const knowSubmitActions = ['redirect'];
     37    settings?.submit_actions?.some(action => {
     38      if (knowSubmitActions.includes(action)) {
     39        if (action === 'redirect') {
     40          this.onRedirect(settings);
     41        }
     42      }
     43    });
     44  }
     45  onRedirect(settings) {
     46    if (settings.redirect_to) {
     47      window.location.href = settings.redirect_to;
     48    }
    3049  }
    3150  onError(_e, form, _error) {
    3251    //console.log('ElementorForms onError', e, form, error);
    33     this.setMessage(form, 'error');
     52    this.setMessage(form, 'error', {
     53      messages: {
     54        error: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('An error occurred, please try again later.', 'static-snap'),
     55        invalid: '',
     56        required: '',
     57        success: ''
     58      }
     59    });
    3460  }
    35   setMessage(form, type) {
     61  setMessage(form, type, settings) {
     62    const matchTypeToMessage = {
     63      error: settings?.messages?.error,
     64      field_error: settings?.messages?.required,
     65      invalid_error: settings?.messages?.invalid,
     66      success: settings?.messages?.success
     67    };
    3668    const noticeElement = this.getNoticeElement(form);
    37     const message = this.getNoticeMessageOrRedirect(form, type);
    38     noticeElement.innerHTML = `<p>${message}</p>`;
     69    const message = matchTypeToMessage[type] || (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.sprintf)('<p>%s</p>', (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__.__)('An error occurred, please try again later.', 'static-snap'));
     70    noticeElement.innerHTML = message;
    3971    const messageClass = this.extensionMessagesClasses[type];
    4072    // remove other form classes
     
    6496
    6597module.exports = StaticSnapFrontendClasses;
     98
     99/***/ }),
     100
     101/***/ "@wordpress/i18n":
     102/*!******************************!*\
     103  !*** external ["wp","i18n"] ***!
     104  \******************************/
     105/***/ ((module) => {
     106
     107module.exports = window["wp"]["i18n"];
    66108
    67109/***/ })
  • static-snap/trunk/assets/js/wp-forms.js.map

    r3191166 r3207535  
    1 {"version":3,"file":"wp-forms.js","mappings":";;;;;;;;;;;;;;;;AAA8E;AAE/D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cd,aAAa,CAACS,SAAS,CAACE,GAAG,CAAC,0BAA0B,CAAC;MACvDjB,IAAI,CAACqB,WAAW,CAACf,aAAa,CAAC;IACjC;IACA,OAAOA,aAAa;EACtB;AACF;;;;;;;;;;AC/CA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;ACN+B;AAE/B,IAAIf,gDAAM,CAAC,CAAC,C","sources":["webpack://static-snap/./src/extensions/forms/wp-forms/app/src/wp-form.ts","webpack://static-snap/external var \"StaticSnapFrontendClasses\"","webpack://static-snap/webpack/bootstrap","webpack://static-snap/webpack/runtime/compat get default export","webpack://static-snap/webpack/runtime/define property getters","webpack://static-snap/webpack/runtime/hasOwnProperty shorthand","webpack://static-snap/webpack/runtime/make namespace object","webpack://static-snap/./src/extensions/forms/wp-forms/app/src/init.ts"],"sourcesContent":["import { FormBase, FormBaseGetNoticeMessageType } from '@staticsnap/frontend';\n\nexport default class WpForm extends FormBase {\n  private extensionMessagesClasses: Record<FormBaseGetNoticeMessageType, string> = {\n    error: 'wpforms-error-alert',\n    field_error: 'wpforms-error-alert',\n    invalid_error: 'wpforms-error-alert',\n    success: 'wpforms-confirmation-container-full',\n  };\n\n  constructor() {\n    super('[data-static-snap-type=\"form\"][data-static-snap-form-type=\"wpform\"]');\n  }\n\n  protected onSubmit(_e: Event, form: HTMLFormElement, _submitData: unknown): void {\n    this.setMessage(form, 'success');\n  }\n\n  protected onError(_e: Event, form: HTMLFormElement, _error: unknown): void {\n    //console.log('ElementorForms onError', e, form, error);\n    this.setMessage(form, 'error');\n  }\n\n  private setMessage(form: HTMLFormElement, type: FormBaseGetNoticeMessageType): void {\n    const noticeElement = this.getNoticeElement(form);\n    const message = this.getNoticeMessageOrRedirect(form, type);\n\n    noticeElement.innerHTML = `<p>${message}</p>`;\n    const messageClass = this.extensionMessagesClasses[type];\n    // remove other form classes\n    Object.values(this.extensionMessagesClasses).forEach((messageClass) => {\n      form.classList.remove(messageClass);\n    });\n\n    noticeElement.classList.add(messageClass);\n  }\n\n  private getNoticeElement(form: HTMLFormElement): Element {\n    let noticeElement = form.querySelector(' .wpforms-notice-container');\n\n    if (!noticeElement) {\n      noticeElement = document.createElement('div');\n      noticeElement.classList.add('wpforms-notice-container');\n      form.appendChild(noticeElement);\n    }\n    return noticeElement;\n  }\n}\n","module.exports = StaticSnapFrontendClasses;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import WpForm from './wp-form';\n\nnew WpForm();\n"],"names":["FormBase","WpForm","extensionMessagesClasses","error","field_error","invalid_error","success","constructor","onSubmit","_e","form","_submitData","setMessage","onError","_error","type","noticeElement","getNoticeElement","message","getNoticeMessageOrRedirect","innerHTML","messageClass","Object","values","forEach","classList","remove","add","querySelector","document","createElement","appendChild"],"sourceRoot":""}
     1{"version":3,"file":"wp-forms.js","mappings":";;;;;;;;;;;;;;;;;;AAK8B;AAEgB;AAE/B,MAAMG,MAAM,SAASH,0DAAQ,CAAC;EACnCI,wBAAwB,GAAiD;IAC/EC,KAAK,EAAE,qBAAqB;IAC5BC,WAAW,EAAE,qBAAqB;IAClCC,aAAa,EAAE,qBAAqB;IACpCC,OAAO,EAAE;EACX,CAAC;EAEDC,WAAWA,CAAA,EAAG;IACZ,KAAK,CAAC,uEAAuE,CAAC;EAChF;EAEUC,QAAQA,CAChBC,EAAS,EACTC,IAAqB,EACrBC,WAAoB,EACpBC,YAA+D,EACzD;IACN,MAAMC,QAAQ,GAAG,IAAI,CAACC,eAAe,CAACF,YAAY,CAAC;IACnD,IAAI,CAACG,UAAU,CACbL,IAAI,EACJE,YAAY,CAACI,IAAI,KAAK,MAAM,IAAIJ,YAAY,EAAEK,IAAI,EAAEC,KAAK,GAAG,SAAS,GAAG,OAAO,EAC/EL,QACF,CAAC;;IAED;IACA,MAAMM,iBAAiB,GAAG,CAAC,UAAU,CAAC;IAEtCN,QAAQ,EAAEO,cAAc,EAAEC,IAAI,CAAEC,MAAM,IAAK;MACzC,IAAIH,iBAAiB,CAACI,QAAQ,CAACD,MAAM,CAAC,EAAE;QACtC,IAAIA,MAAM,KAAK,UAAU,EAAE;UACzB,IAAI,CAACE,UAAU,CAACX,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Y,IAAK;MACrE7B,IAAI,CAACiC,SAAS,CAACC,MAAM,CAACL,YAAY,CAAC;IACrC,CAAC,CAAC;IAEFJ,aAAa,CAACQ,SAAS,CAACE,GAAG,CAACN,YAAY,CAAC;EAC3C;EAEQH,gBAAgBA,CAAC1B,IAAqB,EAAW;IACvD,IAAIyB,aAAa,GAAGzB,IAAI,CAACoC,aAAa,CAAC,4BAA4B,CAAC;IAEpE,IAAI,CAACX,aAAa,EAAE;MAClBA,aAAa,GAAGY,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;MAC7Cb,aAAa,CAACQ,SAAS,CAACE,GAAG,CAAC,0BAA0B,CAAC;MACvDnC,IAAI,CAACuC,WAAW,CAACd,aAAa,CAAC;IACjC;IACA,OAAOA,aAAa;EACtB;AACF;;;;;;;;;;ACpGA;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;ACN+B;AAE/B,IAAIlC,gDAAM,CAAC,CAAC,C","sources":["webpack://static-snap/./src/extensions/forms/wp-forms/app/src/wp-form.ts","webpack://static-snap/external var \"StaticSnapFrontendClasses\"","webpack://static-snap/external window [\"wp\",\"i18n\"]","webpack://static-snap/webpack/bootstrap","webpack://static-snap/webpack/runtime/compat get default export","webpack://static-snap/webpack/runtime/define property getters","webpack://static-snap/webpack/runtime/hasOwnProperty shorthand","webpack://static-snap/webpack/runtime/make namespace object","webpack://static-snap/./src/extensions/forms/wp-forms/app/src/init.ts"],"sourcesContent":["import {\n  FormBase,\n  FormBaseGetNoticeMessageType,\n  FormSubmitResponseInterface,\n  WebsiteFormSettings,\n} from '@staticsnap/frontend';\nimport ApiResponseInterface from '@staticsnap/frontend/src/interfaces/api-response.interface';\nimport { __, sprintf } from '@wordpress/i18n';\n\nexport default class WpForm extends FormBase {\n  private extensionMessagesClasses: Record<FormBaseGetNoticeMessageType, string> = {\n    error: 'wpforms-error-alert',\n    field_error: 'wpforms-error-alert',\n    invalid_error: 'wpforms-error-alert',\n    success: 'wpforms-confirmation-container-full',\n  };\n\n  constructor() {\n    super('[data-static-snap-type=\"form\"][data-static-snap-form-type=\"wp-forms\"]');\n  }\n\n  protected onSubmit(\n    _e: Event,\n    form: HTMLFormElement,\n    _submitData: unknown,\n    responseData: ApiResponseInterface<FormSubmitResponseInterface>\n  ): void {\n    const settings = this.getFormSettings(responseData);\n    this.setMessage(\n      form,\n      responseData.type === 'item' && responseData?.data?.saved ? 'success' : 'error',\n      settings\n    );\n\n    // TODO: add webhook support\n    const knowSubmitActions = ['redirect'];\n\n    settings?.submit_actions?.some((action) => {\n      if (knowSubmitActions.includes(action)) {\n        if (action === 'redirect') {\n          this.onRedirect(settings);\n        }\n      }\n    });\n  }\n\n  protected onRedirect(settings: WebsiteFormSettings): void {\n    if (settings.redirect_to) {\n      window.location.href = settings.redirect_to;\n    }\n  }\n\n  protected onError(_e: Event, form: HTMLFormElement, _error: unknown): void {\n    //console.log('ElementorForms onError', e, form, error);\n    this.setMessage(form, 'error', {\n      messages: {\n        error: __('An error occurred, please try again later.', 'static-snap'),\n        invalid: '',\n        required: '',\n        success: '',\n      },\n    });\n  }\n\n  private setMessage(\n    form: HTMLFormElement,\n    type: FormBaseGetNoticeMessageType,\n    settings: WebsiteFormSettings\n  ): void {\n    const matchTypeToMessage = {\n      error: settings?.messages?.error,\n      field_error: settings?.messages?.required,\n      invalid_error: settings?.messages?.invalid,\n      success: settings?.messages?.success,\n    };\n    const noticeElement = this.getNoticeElement(form);\n    const message =\n      matchTypeToMessage[type] ||\n      sprintf('<p>%s</p>', __('An error occurred, please try again later.', 'static-snap'));\n\n    noticeElement.innerHTML = message;\n    const messageClass = this.extensionMessagesClasses[type];\n    // remove other form classes\n    Object.values(this.extensionMessagesClasses).forEach((messageClass) => {\n      form.classList.remove(messageClass);\n    });\n\n    noticeElement.classList.add(messageClass);\n  }\n\n  private getNoticeElement(form: HTMLFormElement): Element {\n    let noticeElement = form.querySelector(' .wpforms-notice-container');\n\n    if (!noticeElement) {\n      noticeElement = document.createElement('div');\n      noticeElement.classList.add('wpforms-notice-container');\n      form.appendChild(noticeElement);\n    }\n    return noticeElement;\n  }\n}\n","module.exports = StaticSnapFrontendClasses;","module.exports = window[\"wp\"][\"i18n\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import WpForm from './wp-form';\n\nnew WpForm();\n"],"names":["FormBase","__","sprintf","WpForm","extensionMessagesClasses","error","field_error","invalid_error","success","constructor","onSubmit","_e","form","_submitData","responseData","settings","getFormSettings","setMessage","type","data","saved","knowSubmitActions","submit_actions","some","action","includes","onRedirect","redirect_to","window","location","href","onError","_error","messages","invalid","required","matchTypeToMessage","noticeElement","getNoticeElement","message","innerHTML","messageClass","Object","values","forEach","classList","remove","add","querySelector","document","createElement","appendChild"],"sourceRoot":""}
  • static-snap/trunk/readme.txt

    r3206486 r3207535  
    44Requires at least: 6.5.0
    55Tested up to: 6.7.1
    6 Stable tag: 0.2.9
     6Stable tag: 0.3.0
    77Requires PHP: 7.4
    88License: GPLv3
     
    4949
    5050== Changelog ==
     51= 0.3.0 - 2024-12-13 =
     52* Add support for WP Forms Lite
     53
    5154= 0.2.9 - 2024-12-11 =
    5255* Add support for Contact Form 7 email notifications.
  • static-snap/trunk/src/extensions/forms/wp-forms/class-wp-forms-extension.php

    r3206486 r3207535  
    88namespace StaticSnap\Extensions\Forms\WP_Forms;
    99
     10use StaticSnap\API\API;
    1011use StaticSnap\Forms\Form_Extension_Base;
    1112use StaticSnap\Application;
     
    4445
    4546        $atts['atts']['data-static-snap-type']      = 'form';
    46         $atts['atts']['data-static-snap-form-type'] = 'wpform';
     47        $atts['atts']['data-static-snap-form-type'] = $this->get_name();
    4748        $expected_confirmation_settings             = array(
    4849            'type'     => 'message',
     
    9697        $this->add_hidden_field( self::FORM_NAME_FIELD_NAME, $form_data['settings']['form_title'] );
    9798        $this->add_hidden_field( self::FORM_ID_FIELD_NAME, $form_data['id'] );
    98         $this->add_hidden_field( self::FORM_TYPE_FIELD_NAME, 'wpforms' );
     99        $this->add_hidden_field( self::FORM_TYPE_FIELD_NAME, $this->get_name() );
    99100    }
    100101
     
    114115        wp_enqueue_script( 'static-snap-wp-forms', STATIC_SNAP_PLUGIN_URL . '/assets/js/wp-forms.js', $asset_dependencies, $asset_file['version'], true );
    115116    }
     117
     118
     119    /**
     120     * Build placeholders
     121     *
     122     * @param object $form The form.
     123     * @return array
     124     */
     125    /**
     126     * Build placeholders
     127     *
     128     * @param object $form The form.
     129     * @return array
     130     */
     131    public function build_placeholders( $form ) {
     132
     133        $placeholders = array(
     134            // Basic Smart Tags.
     135            '{admin_email}'         => get_option( 'admin_email' ),
     136            '{form_id}'             => $form->ID,
     137            '{form_name}'           => $form->post_name,
     138            '{page_title}'          => get_the_title(),
     139            '{page_url}'            => get_site_url(),
     140            '{date format="m/d/Y"}' => gmdate( 'm/d/Y' ),
     141            '{unique_value}'        => uniqid(),
     142
     143            // Author Details.
     144            '{author_id}'           => get_the_author_meta( 'ID' ),
     145            '{author_display}'      => get_the_author(),
     146            '{author_email}'        => get_the_author_meta( 'email' ),
     147
     148            // User Management.
     149            '{user_display}'        => wp_get_current_user()->display_name ?? '',
     150            '{user_full_name}'      => trim( wp_get_current_user()->first_name . ' ' . wp_get_current_user()->last_name ),
     151            '{user_first_name}'     => wp_get_current_user()->first_name ?? '',
     152            '{user_last_name}'      => wp_get_current_user()->last_name ?? '',
     153            '{user_email}'          => wp_get_current_user()->user_email ?? '',
     154
     155            '{url_login}'           => wp_login_url(),
     156            '{url_logout}'          => wp_logout_url(),
     157            '{url_register}'        => wp_registration_url(),
     158            '{url_lost_password}'   => wp_lostpassword_url(),
     159
     160            // User Registration.
     161            '{site_name}'           => get_bloginfo( 'name' ),
     162
     163        );
     164
     165        return $placeholders;
     166    }
     167
     168    /**
     169     * Replace placeholders
     170     * This method is used to replace placeholders in the form settings
     171     *
     172     * @param string $str The string to replace the placeholders in.
     173     * @param array  $placeholders The placeholders to replace.
     174     */
     175    public function replace_placeholders( $str, $placeholders ) {
     176        foreach ( $placeholders as $placeholder => $value ) {
     177            $str = str_replace( $placeholder, $value, $str );
     178        }
     179        return $str;
     180    }
     181
     182    /**
     183     * Sync forms settings
     184     */
     185    public function sync_forms_settings() {
     186
     187        if ( ! is_plugin_active( 'wpforms-lite/wpforms.php' ) ) {
     188            return;
     189        }
     190        $website_form_settings = array();
     191
     192        $forms = \WPForms()->form->get();
     193        foreach ( $forms as $index => $form ) {
     194            $email_settings    = array();
     195            $redirect_settings = null;
     196            $popup_settings    = array();
     197            $webhooks_settings = array();
     198            $success_message   = null;
     199            try {
     200                $decoded_form_json = json_decode( $form->post_content, true );
     201                $placeholders      = $this->build_placeholders( $form );
     202
     203                if ( ! is_array( $decoded_form_json ) ) {
     204                    continue;
     205                }
     206                $form_settings = $decoded_form_json['settings'] ?? array();
     207
     208                if ( ! is_array( $form_settings ) ) {
     209                    continue;
     210                }
     211
     212                // check confirmations.
     213                $confirmations = $form_settings['confirmations'] ?? array();
     214
     215                foreach ( $confirmations as $confirmation ) {
     216                    if ( 'message' === $confirmation['type'] ) {
     217                        $success_message = $this->replace_placeholders( $confirmation['message'], $placeholders );
     218                    }
     219                    if ( 'redirect' === $confirmation['type'] ) {
     220                        $redirect_settings = $confirmation['redirect'];
     221                    }
     222                    if ( 'page' === $confirmation['type'] ) {
     223                        $redirect_settings = get_permalink( $confirmation['page'] );
     224                    }
     225                }
     226
     227                $notifications = $form_settings['notifications'] ?? array();
     228
     229                foreach ( $notifications as $notification ) {
     230                    $email_settings = array(
     231                        'to'        => $this->replace_placeholders( $notification['email'], $placeholders ),
     232                        'subject'   => $this->replace_placeholders( $notification['subject'], $placeholders ),
     233                        'from_name' => $this->replace_placeholders( $notification['sender_name'], $placeholders ),
     234                        'content'   => $this->replace_placeholders( $notification['message'], $placeholders ),
     235                    );
     236                }
     237
     238                $website_form_settings[] = array(
     239                    'website_form_website_id'     => Application::instance()->get_wp_installation_md5(),
     240                    'website_form_name'           => $form->post_name,
     241                    'website_form_id'             => strval( $form->ID ),
     242                    'webiste_form_extension_name' => $this->get_name(),
     243                    'website_form_settings'       => array(
     244                        'submit_actions' => empty( $email_settings ) ? array() : array( 'email' ),
     245                        'email'          => $email_settings,
     246                        'redirect_to'    => $redirect_settings,
     247                        'popup'          => $popup_settings,
     248                        'webhooks'       => $webhooks_settings,
     249                        'messages'       => array(
     250                            'success' => $success_message,
     251                        ),
     252                    ),
     253                );
     254
     255            } catch ( \Exception $e ) {
     256                continue;
     257            }
     258
     259            $api = new API();
     260            $api->post(
     261                '/website-forms/sync/' . $this->get_name(),
     262                array(
     263                    'website_id' => Application::instance()->get_wp_installation_md5(),
     264                    'data'       => $website_form_settings,
     265                )
     266            );
     267        }
     268
     269        return true;
     270    }
    116271}
  • static-snap/trunk/static-snap.php

    r3206486 r3207535  
    1313 * Plugin URI:      https://staticsnap.com/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash
    1414 * Description:     Static Snap transforms WordPress into a powerful tool for creating static websites.
    15  * Version:         0.2.9
     15 * Version:         0.3.0
    1616 * Author:          Static Snap
    1717 * Author URI:      https://staticsnap.com/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wp-dash
  • static-snap/trunk/vendor/composer/installed.php

    r3206486 r3207535  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '5227b992f545e82dd2fb3476a0306641da7533fa',
     6        'reference' => '21a957f7896fdb6afc318dc863dd44cc74d7d94d',
    77        'type' => 'project',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '5227b992f545e82dd2fb3476a0306641da7533fa',
     16            'reference' => '21a957f7896fdb6afc318dc863dd44cc74d7d94d',
    1717            'type' => 'project',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.