| @@ -1,766 +1,2578 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Admin; |
| 4 | 4 | |
| 5 | +if (!defined('ABSPATH')) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | + | |
| 9 | +use BitCode\BitForm\Admin\Form\FrontEndScriptGenerator; | |
| 10 | +use BitCode\BitForm\Admin\Form\Helpers; | |
| 11 | +use BitCode\BitForm\Admin\Form\Template\TemplateProvider; | |
| 12 | +use BitCode\BitForm\Core\Database\FormEntryLogModel; | |
| 13 | +use BitCode\BitForm\Core\Database\FormEntryModel; | |
| 14 | +use BitCode\BitForm\Core\Database\FormModel; | |
| 5 | 15 | use BitCode\BitForm\Core\Form\FormHandler; |
| 16 | +use BitCode\BitForm\Core\Integration\IntegrationHandler; | |
| 6 | 17 | use BitCode\BitForm\Core\Integration\Integrations; |
| 7 | -use BitCode\BitForm\Core\Integration\IntegrationHandler; | |
| 8 | -use BitCode\BitForm\Admin\Form\Template\TemplateProvider; | |
| 18 | +use BitCode\BitForm\Core\Util\IpTool; | |
| 19 | +use BitCode\BitForm\Core\Util\MailConfig; | |
| 20 | +use BitCode\BitForm\Core\Util\MetaBoxService; | |
| 21 | +use BitCode\BitForm\Core\Util\Utilities; | |
| 22 | +use BitCode\BitForm\Frontend\Form\FrontendFormManager; | |
| 23 | +use BitCode\BitForm\GlobalHelper; | |
| 24 | +use WP_Error; | |
| 9 | 25 | |
| 10 | 26 | class AdminAjax |
| 11 | 27 | { |
| 12 | - public function register() | |
| 13 | - { | |
| 14 | - add_action('wp_ajax_bitforms_integrations', array($this, 'integrations')); | |
| 15 | - add_action('wp_ajax_integration', array($this, 'integration')); | |
| 16 | - add_action('wp_ajax_bitforms_update_form', array($this, 'updateForm')); | |
| 17 | - add_action('wp_ajax_bitforms_templates', array($this, 'templates')); | |
| 18 | - add_action('wp_ajax_bitforms_create_new_form', array($this, 'createNewForm')); | |
| 19 | - add_action('wp_ajax_bitforms_get_template', array($this, 'getTemplate')); | |
| 20 | - add_action('wp_ajax_bitforms_change_status', array($this, 'changeFormStatus')); | |
| 21 | - add_action('wp_ajax_bitforms_bulk_status_change', array($this, 'changeBulkFormStatus')); | |
| 22 | - add_action('wp_ajax_bitforms_get_a_form', array($this, 'getAForm')); | |
| 23 | - add_action('wp_ajax_bitforms_bulk_delete_form', array($this, 'deleteBlukForm')); | |
| 24 | - add_action('wp_ajax_bitforms_bulk_delete_form_entries', array($this, 'deleteBlukFormEntries')); | |
| 25 | - add_action('wp_ajax_bitforms_delete_aform', array($this, 'deleteAForm')); | |
| 26 | - add_action('wp_ajax_bitforms_duplicate_aform', array($this, 'duplicateAForm')); | |
| 27 | - add_action('wp_ajax_bitforms_export_aform', array($this, 'exportAForm')); | |
| 28 | - add_action('wp_ajax_bitforms_import_aform', array($this, 'importAForm')); | |
| 29 | - add_action('wp_ajax_bitforms_get_form_entries', array($this, 'getFormEntry')); | |
| 30 | - add_action('wp_ajax_bitforms_duplicate_form_entries', array($this, 'duplicateFormEntry')); | |
| 31 | - add_action('wp_ajax_bitforms_edit_form_entry', array($this, 'editFormEntry')); | |
| 32 | - add_action('wp_ajax_bitforms_update_form_entry', array($this, 'updateFormEntry')); | |
| 33 | - add_action('wp_ajax_bitforms_get_all_form', array($this, 'getAllForms')); | |
| 34 | - add_action('wp_ajax_bitforms_get_all_wp_pages', array($this, 'getAllWPPages')); | |
| 35 | - add_action('wp_ajax_bitforms_delete_success_messsage', array($this, 'deleteSuccessMessage')); | |
| 36 | - add_action('wp_ajax_bitforms_delete_integration', array($this, 'deleteAIntegration')); | |
| 37 | - add_action('wp_ajax_bitforms_delete_workflow', array($this, 'deleteAWorkflow')); | |
| 38 | - add_action('wp_ajax_bitforms_delete_mailtemplate', array($this, 'deleteAMailTemplate')); | |
| 39 | - add_action('wp_ajax_bitforms_duplicate_mailtemplate', array($this, 'duplicateAMailTemplate')); | |
| 40 | - add_action('wp_ajax_bitforms_save_allForm_report_prefs', array($this, 'setAllFormsReport')); | |
| 41 | - add_action('wp_ajax_bitforms_save_grecaptcha', array($this, 'savegReCaptcha')); | |
| 42 | - add_action('wp_ajax_bitforms_form_log_history', array($this, 'getLogHistory')); | |
| 43 | - add_action('wp_ajax_bitforms_import_file_data', array($this, 'importFileData')); | |
| 44 | - add_action('wp_ajax_bitforms_filter_export_data', array($this, 'filterExportEntry')); | |
| 45 | - add_action('wp_ajax_bitforms_api_key', array($this, 'saveApiKey')); | |
| 46 | - | |
| 28 | + public function register() | |
| 29 | + { | |
| 30 | + add_action('wp_ajax_bitforms_integrations', [$this, 'integrations']); | |
| 31 | + add_action('wp_ajax_bitforms_save_connected_integration_apps', [$this, 'saveConnectedIntegrationApps']); | |
| 32 | + add_action('wp_ajax_bitforms_get_connected_integration_apps', [$this, 'getConnectedIntegrationApps']); | |
| 33 | + add_action('wp_ajax_bitforms_delete_connected_app', [$this, 'deleteConnectedApp']); | |
| 34 | + add_action('wp_ajax_bitforms_update_connected_app', [$this, 'updateConnectedApp']); | |
| 35 | + add_action('wp_ajax_bitforms_integration_last_runs', [$this, 'integrationLastRuns']); | |
| 36 | + add_action('wp_ajax_bitforms_update_form', [$this, 'updateForm']); | |
| 37 | + add_action('wp_ajax_bitforms_templates', [$this, 'templates']); | |
| 38 | + add_action('wp_ajax_bitforms_create_new_form', [$this, 'createNewForm']); | |
| 39 | + add_action('wp_ajax_bitforms_save_css', [$this, 'saveCss']); | |
| 40 | + add_action('wp_ajax_bitforms_get_template', [$this, 'getTemplate']); | |
| 41 | + add_action('wp_ajax_bitforms_change_status', [$this, 'changeFormStatus']); | |
| 42 | + add_action('wp_ajax_bitforms_bulk_status_change', [$this, 'changeBulkFormStatus']); | |
| 43 | + add_action('wp_ajax_bitforms_get_a_form', [$this, 'getAForm']); | |
| 44 | + add_action('wp_ajax_bitforms_bulk_delete_form', [$this, 'deleteBlukForm']); | |
| 45 | + add_action('wp_ajax_bitforms_bulk_delete_form_entries', [$this, 'deleteBlukFormEntries']); | |
| 46 | + add_action('wp_ajax_bitforms_delete_aform', [$this, 'deleteAForm']); | |
| 47 | + add_action('wp_ajax_bitforms_duplicate_aform', [$this, 'duplicateAForm']); | |
| 48 | + add_action('wp_ajax_bitforms_export_aform', [$this, 'exportAForm']); | |
| 49 | + add_action('wp_ajax_bitforms_import_aform', [$this, 'importAForm']); | |
| 50 | + add_action('wp_ajax_bitforms_get_form_entries', [$this, 'getFormEntry']); | |
| 51 | + add_action('wp_ajax_bitforms_get_entries_for_report', [$this, 'getEntriesForReport']); | |
| 52 | + add_action('wp_ajax_bitforms_duplicate_form_entries', [$this, 'duplicateFormEntry']); | |
| 53 | + add_action('wp_ajax_bitforms_edit_form_entry', [$this, 'editFormEntry']); | |
| 54 | + add_action('wp_ajax_bitforms_update_form_entry', [$this, 'updateFormEntry']); | |
| 55 | + add_action('wp_ajax_bitforms_get_all_form', [$this, 'getAllForms']); | |
| 56 | + add_action('wp_ajax_bitforms_get_all_wp_pages', [$this, 'getAllWPPages']); | |
| 57 | + add_action('wp_ajax_bitforms_delete_success_messsage', [$this, 'deleteSuccessMessage']); | |
| 58 | + add_action('wp_ajax_bitforms_delete_integration', [$this, 'deleteAIntegration']); | |
| 59 | + add_action('wp_ajax_bitforms_update_integration_status', [$this, 'updateIntegrationStatus']); | |
| 60 | + add_action('wp_ajax_bitforms_delete_workflow', [$this, 'deleteAWorkflow']); | |
| 61 | + add_action('wp_ajax_bitforms_delete_mailtemplate', [$this, 'deleteAMailTemplate']); | |
| 62 | + add_action('wp_ajax_bitforms_duplicate_mailtemplate', [$this, 'duplicateAMailTemplate']); | |
| 63 | + add_action('wp_ajax_bitforms_save_allForm_report_prefs', [$this, 'setAllFormsReport']); | |
| 64 | + add_action('wp_ajax_bitforms_save_grecaptcha', [$this, 'savegReCaptcha']); | |
| 65 | + add_action('wp_ajax_bitforms_form_log_history', [$this, 'getLogHistory']); | |
| 66 | + add_action('wp_ajax_bitforms_filter_export_data', [$this, 'filterExportEntry']); | |
| 67 | + add_action('wp_ajax_bitforms_api_key', [$this, 'saveApiKey']); | |
| 68 | + add_action('wp_ajax_bitforms_form_helpers_state', [$this, 'builerHelperState']); | |
| 69 | + add_action('wp_ajax_bitforms_icn_save_setting', [$this, 'iconUpload']); | |
| 70 | + add_action('wp_ajax_bitforms_get_download_icn', [$this, 'getDownlodedIcons']); | |
| 71 | + add_action('wp_ajax_bitforms_icon_remove', [$this, 'iconRemove']); | |
| 72 | + add_action('wp_ajax_bitforms_add_custom_code', [$this, 'addCustomCode']); | |
| 73 | + add_action('wp_ajax_bitforms_get_custom_code', [$this, 'getCustomCode']); | |
| 74 | + add_action('wp_ajax_bitforms_entry_status_update', [$this, 'updateEntryStatus']); | |
| 75 | + add_action('wp_ajax_bitforms_get_generel_settings', [$this, 'getGenerelSettings']); | |
| 76 | + add_action('wp_ajax_bitforms_save_generel_settings', [$this, 'saveGenerelSettings']); | |
| 77 | + add_action('wp_ajax_bitforms_get_form_entry_count', [$this, 'getFormEntryLabelAndCount']); | |
| 78 | + add_action('wp_ajax_bitforms_save_global_messages', [$this, 'saveGlobalMessages']); | |
| 47 | 79 | |
| 48 | - add_action( | |
| 49 | - 'wp_ajax_bitforms_get_form_entry_count', | |
| 50 | - array($this, 'getFormEntryLabelAndCount') | |
| 51 | - ); | |
| 80 | + // form migrate code | |
| 81 | + add_action('wp_ajax_bitforms_get_migrated_form_contents', [$this, 'migrateFormContents']); | |
| 82 | + add_action('wp_ajax_bitforms_migrate_to_v2_complete', [$this, 'migrationComplete']); | |
| 83 | + // add_action('wp_ajax_bitforms_migrate_back_to_v1', [$this, 'migrationBackToV1']); | |
| 84 | + | |
| 85 | + // PRO TO FREE (SMTP) | |
| 86 | + add_action('wp_ajax_bitforms_get_mail_config', [$this, 'getEmailConfig']); | |
| 87 | + add_action('wp_ajax_bitforms_mail_config', [$this, 'saveEmailConfig']); | |
| 88 | + add_action('wp_ajax_bitforms_test_email', [$this, 'testEmail']); | |
| 89 | + | |
| 90 | + // PODS INTEGRATION | |
| 91 | + add_action('wp_ajax_bitforms_get_pod_field', [$this, 'getPodsField']); | |
| 92 | + add_action('wp_ajax_bitforms_get_pod_type', [$this, 'getPodsType']); | |
| 93 | + | |
| 94 | + // ACF INTEGRATION | |
| 95 | + add_action('wp_ajax_bitforms_get_acf_group_fields', [$this, 'getAcfGroupFields']); | |
| 96 | + add_action('wp_ajax_bitforms_get_custom_field', [$this, 'getCustomField']); | |
| 97 | + | |
| 98 | + // common (get post type) for integration | |
| 99 | + add_action('wp_ajax_bitforms_get_post_type', [$this, 'postTypeByUser']); | |
| 100 | + | |
| 101 | + // WP users and roles (lazy-loaded, not inlined on page load) | |
| 102 | + add_action('wp_ajax_bitforms_get_wp_users', [$this, 'getWPUsers']); | |
| 103 | + add_action('wp_ajax_bitforms_get_user_roles', [$this, 'getUserRoles']); | |
| 104 | + | |
| 105 | + // transient invalidation when users change | |
| 106 | + add_action('user_register', [$this, 'clearUsersTransient']); | |
| 107 | + add_action('deleted_user', [$this, 'clearUsersTransient']); | |
| 108 | + add_action('profile_update', [$this, 'clearUsersTransient']); | |
| 109 | + | |
| 110 | + // Meta Box INTEGRATION | |
| 111 | + add_action('wp_ajax_bitforms_get_metabox_fields', [$this, 'getMetaBoxFields']); | |
| 112 | + | |
| 113 | + // CHANGELOG VERSION OPTIONS | |
| 114 | + add_action('wp_ajax_bitforms_changelog_version', [$this, 'setChangelogVersion']); | |
| 115 | + | |
| 116 | + // Notice Options | |
| 117 | + add_action('wp_ajax_bitforms_handle_notice', [$this, 'handleNotice']); | |
| 118 | + | |
| 119 | + // conversational | |
| 120 | + add_action('wp_ajax_bitforms_save_conversational_css', [$this, 'saveConversationalCSS']); | |
| 121 | + | |
| 122 | + // get form html markup | |
| 123 | + add_action('wp_ajax_bitforms_get_form_html', [$this, 'getFormHtml']); | |
| 124 | + } | |
| 125 | + | |
| 126 | + private function verifyAdminPermission() | |
| 127 | + { | |
| 128 | + if (!current_user_can('manage_bitform') && !current_user_can('manage_options')) { | |
| 129 | + wp_send_json_error(__('Insufficient permissions.', 'bit-form'), 403); | |
| 52 | 130 | } |
| 53 | - /** | |
| 54 | - * Undocumented function | |
| 55 | - * | |
| 56 | - * @return void | |
| 57 | - */ | |
| 58 | - public function integrations() | |
| 59 | - { | |
| 60 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 61 | - $testIntegration = new Integrations(); | |
| 62 | - $allIntegrations = $testIntegration->getAllintegrations(); | |
| 63 | - if ($allIntegrations) { | |
| 64 | - wp_send_json_success($allIntegrations, 200); | |
| 65 | - } else { | |
| 66 | - wp_send_json_error( | |
| 67 | - __('No Integration Found', 'bitform'), | |
| 68 | - 404 | |
| 69 | - ); | |
| 70 | - } | |
| 131 | + } | |
| 132 | + | |
| 133 | + public function getFormHtml() | |
| 134 | + { | |
| 135 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 136 | + $this->verifyAdminPermission(); | |
| 137 | + $formId = isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : ''; | |
| 138 | + | |
| 139 | + $FrontendFormManager = FrontendFormManager::getInstance($formId); | |
| 140 | + if (!$FrontendFormManager->isExist()) { | |
| 141 | + wp_send_json_error(__('Form is not exists.', 'bit-form'), 404); | |
| 142 | + } | |
| 143 | + $formContent = $FrontendFormManager->getFormContentWithValue(); | |
| 144 | + if (!is_object($formContent) || !isset($formContent->fields, $formContent->layout)) { | |
| 145 | + wp_send_json_error(__('Form content is unavailable.', 'bit-form'), 404); | |
| 146 | + } | |
| 147 | + $fields = $formContent->fields; | |
| 148 | + $layout = $formContent->layout; | |
| 149 | + $file = count($FrontendFormManager->getUploadFields()) > 0 ? $FrontendFormManager->getUploadFields() : false; | |
| 150 | + $html = $FrontendFormManager->formView($fields, $file); | |
| 151 | + | |
| 152 | + if (file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles')) { | |
| 153 | + $cssPath = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles' . DIRECTORY_SEPARATOR . "bitform-{$formId}-formid" . '.css'; | |
| 154 | + | |
| 155 | + if (file_exists($cssPath)) { | |
| 156 | + $getCss = file_get_contents($cssPath); | |
| 71 | 157 | } else { |
| 72 | - wp_send_json_error( | |
| 73 | - __( | |
| 74 | - 'Token expired', | |
| 75 | - 'bitform' | |
| 76 | - ), | |
| 77 | - 401 | |
| 78 | - ); | |
| 158 | + $getCss = ''; | |
| 79 | 159 | } |
| 160 | + } | |
| 161 | + | |
| 162 | + $data = [ | |
| 163 | + 'html' => $html, | |
| 164 | + 'css' => $getCss, | |
| 165 | + ]; | |
| 166 | + | |
| 167 | + wp_send_json_success( | |
| 168 | + $data, | |
| 169 | + 200 | |
| 170 | + ); | |
| 171 | + } else { | |
| 172 | + wp_send_json_error( | |
| 173 | + __( | |
| 174 | + 'Token expired', | |
| 175 | + 'bit-form' | |
| 176 | + ), | |
| 177 | + 401 | |
| 178 | + ); | |
| 80 | 179 | } |
| 180 | + } | |
| 81 | 181 | |
| 82 | - public function templates() | |
| 83 | - { | |
| 84 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 85 | - $templateProvider = new TemplateProvider(); | |
| 86 | - $status = $templateProvider->getAllTemplates(); | |
| 87 | - if (is_wp_error($status)) { | |
| 88 | - wp_send_json_error($status->get_error_message(), 411); | |
| 89 | - } else { | |
| 90 | - wp_send_json_success($status, 200); | |
| 91 | - } | |
| 92 | - } else { | |
| 93 | - wp_send_json_error( | |
| 94 | - __( | |
| 95 | - 'Token expired', | |
| 96 | - 'bitform' | |
| 97 | - ), | |
| 98 | - 401 | |
| 99 | - ); | |
| 182 | + /** | |
| 183 | + * Undocumented function | |
| 184 | + * | |
| 185 | + * @return void | |
| 186 | + */ | |
| 187 | + public function integrations() | |
| 188 | + { | |
| 189 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 190 | + $this->verifyAdminPermission(); | |
| 191 | + $testIntegration = Integrations::getInstance(); | |
| 192 | + $allIntegrations = $testIntegration->getAllintegrations(); | |
| 193 | + if ($allIntegrations) { | |
| 194 | + wp_send_json_success($allIntegrations, 200); | |
| 195 | + } else { | |
| 196 | + wp_send_json_error( | |
| 197 | + __('No Integration Found', 'bit-form'), | |
| 198 | + 404 | |
| 199 | + ); | |
| 200 | + } | |
| 201 | + } else { | |
| 202 | + wp_send_json_error( | |
| 203 | + __( | |
| 204 | + 'Token expired', | |
| 205 | + 'bit-form' | |
| 206 | + ), | |
| 207 | + 401 | |
| 208 | + ); | |
| 209 | + } | |
| 210 | + } | |
| 211 | + | |
| 212 | + /** | |
| 213 | + * Undocumented function | |
| 214 | + * | |
| 215 | + * @return void | |
| 216 | + */ | |
| 217 | + public function saveConnectedIntegrationApps() | |
| 218 | + { | |
| 219 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 220 | + $this->verifyAdminPermission(); | |
| 221 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 222 | + // $input = json_decode($inputJSON); | |
| 223 | + GlobalHelper::requirePostMethod(); | |
| 224 | + try { | |
| 225 | + $input = GlobalHelper::formatRequestData(); | |
| 226 | + } catch (\InvalidArgumentException $e) { | |
| 227 | + wp_send_json_error($e->getMessage(), 400); | |
| 228 | + } | |
| 229 | + // wp_send_json_success($input, 200); | |
| 230 | + $integrations = Integrations::getInstance(); | |
| 231 | + $status = $integrations->saveConnectedIntegrationApp($input); | |
| 232 | + | |
| 233 | + // if (isset($input->customCodes)) { | |
| 234 | + // FrontEndScriptGenerator::customCodeFile($formId, $input->customCodes); | |
| 235 | + // } | |
| 236 | + if (is_wp_error($status)) { | |
| 237 | + wp_send_json_error($status->get_error_message(), 411); | |
| 238 | + } else { | |
| 239 | + wp_send_json_success($status, 200); | |
| 240 | + } | |
| 241 | + } else { | |
| 242 | + wp_send_json_error( | |
| 243 | + __( | |
| 244 | + 'Token expired', | |
| 245 | + 'bit-form' | |
| 246 | + ), | |
| 247 | + 401 | |
| 248 | + ); | |
| 249 | + } | |
| 250 | + } | |
| 251 | + | |
| 252 | + /** | |
| 253 | + * Undocumented function | |
| 254 | + * | |
| 255 | + * @return void | |
| 256 | + */ | |
| 257 | + public function getConnectedIntegrationApps() | |
| 258 | + { | |
| 259 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 260 | + $this->verifyAdminPermission(); | |
| 261 | + GlobalHelper::requirePostMethod(); | |
| 262 | + try { | |
| 263 | + $input = GlobalHelper::formatRequestData(); | |
| 264 | + } catch (\InvalidArgumentException $e) { | |
| 265 | + wp_send_json_error($e->getMessage(), 400); | |
| 266 | + } | |
| 267 | + | |
| 268 | + $integrationType = isset($input->integrationType) ? $input->integrationType : null; | |
| 269 | + $testIntegration = Integrations::getInstance(); | |
| 270 | + $allIntegrations = $testIntegration->getConnectedIntegrationApp($integrationType); | |
| 271 | + if ($allIntegrations) { | |
| 272 | + wp_send_json_success($allIntegrations, 200); | |
| 273 | + } else { | |
| 274 | + wp_send_json_error( | |
| 275 | + __('No Connected App Found', 'bit-form'), | |
| 276 | + 404 | |
| 277 | + ); | |
| 278 | + } | |
| 279 | + } else { | |
| 280 | + wp_send_json_error( | |
| 281 | + __( | |
| 282 | + 'Token expired', | |
| 283 | + 'bit-form' | |
| 284 | + ), | |
| 285 | + 401 | |
| 286 | + ); | |
| 287 | + } | |
| 288 | + } | |
| 289 | + | |
| 290 | + public function deleteConnectedApp() | |
| 291 | + { | |
| 292 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 293 | + $this->verifyAdminPermission(); | |
| 294 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 295 | + // $input = json_decode($inputJSON); | |
| 296 | + GlobalHelper::requirePostMethod(); | |
| 297 | + try { | |
| 298 | + $input = GlobalHelper::formatRequestData(); | |
| 299 | + } catch (\InvalidArgumentException $e) { | |
| 300 | + wp_send_json_error($e->getMessage(), 400); | |
| 301 | + } | |
| 302 | + // Nonce verified at handler entry (wp_verify_nonce 'bitforms_save', line 273). | |
| 303 | + $requestedAppId = isset($_REQUEST['appId']) | |
| 304 | + ? sanitize_text_field(wp_unslash($_REQUEST['appId'])) | |
| 305 | + : ''; | |
| 306 | + $appId = $requestedAppId | |
| 307 | + ? $requestedAppId | |
| 308 | + : sanitize_text_field(wp_unslash((string) ($input->appId ?? ''))); | |
| 309 | + $integrationHandler = Integrations::getInstance(); | |
| 310 | + $status = $integrationHandler->deleteConnectedApp($appId); | |
| 311 | + if (is_wp_error($status)) { | |
| 312 | + wp_send_json_error($status->get_error_message(), 411); | |
| 313 | + } else { | |
| 314 | + wp_send_json_success($status, 200); | |
| 315 | + } | |
| 316 | + } else { | |
| 317 | + wp_send_json_error( | |
| 318 | + __( | |
| 319 | + 'Token expired', | |
| 320 | + 'bit-form' | |
| 321 | + ), | |
| 322 | + 401 | |
| 323 | + ); | |
| 324 | + } | |
| 325 | + } | |
| 326 | + | |
| 327 | + /** | |
| 328 | + * Renames a connected account (category connected_integration_apps, form_id 0). | |
| 329 | + * Only integration_name is writable; updateIntegration would overwrite the rest. | |
| 330 | + * | |
| 331 | + * @return void | |
| 332 | + */ | |
| 333 | + public function updateConnectedApp() | |
| 334 | + { | |
| 335 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 336 | + $this->verifyAdminPermission(); | |
| 337 | + GlobalHelper::requirePostMethod(); | |
| 338 | + try { | |
| 339 | + $input = GlobalHelper::formatRequestData(); | |
| 340 | + } catch (\InvalidArgumentException $e) { | |
| 341 | + wp_send_json_error($e->getMessage(), 400); | |
| 342 | + } | |
| 343 | + $appId = !empty($input->appId) ? sanitize_text_field((string) $input->appId) : ''; | |
| 344 | + $name = isset($input->name) ? sanitize_text_field((string) $input->name) : ''; | |
| 345 | + if (empty($appId) || '' === trim($name)) { | |
| 346 | + wp_send_json_error(__('Invalid request', 'bit-form'), 400); | |
| 347 | + } | |
| 348 | + $integrations = Integrations::getInstance(); | |
| 349 | + $status = $integrations->renameConnectedApp($appId, $name); | |
| 350 | + if (is_wp_error($status)) { | |
| 351 | + wp_send_json_error($status->get_error_message(), 411); | |
| 352 | + } else { | |
| 353 | + wp_send_json_success($status, 200); | |
| 354 | + } | |
| 355 | + } else { | |
| 356 | + wp_send_json_error( | |
| 357 | + __( | |
| 358 | + 'Token expired', | |
| 359 | + 'bit-form' | |
| 360 | + ), | |
| 361 | + 401 | |
| 362 | + ); | |
| 363 | + } | |
| 364 | + } | |
| 365 | + | |
| 366 | + /** | |
| 367 | + * Last execution per integration of a form, for the integrations list Last Run column. | |
| 368 | + * | |
| 369 | + * @return void | |
| 370 | + */ | |
| 371 | + public function integrationLastRuns() | |
| 372 | + { | |
| 373 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 374 | + $this->verifyAdminPermission(); | |
| 375 | + GlobalHelper::requirePostMethod(); | |
| 376 | + try { | |
| 377 | + $input = GlobalHelper::formatRequestData(); | |
| 378 | + } catch (\InvalidArgumentException $e) { | |
| 379 | + wp_send_json_error($e->getMessage(), 400); | |
| 380 | + } | |
| 381 | + $formID = !empty($input->formID) ? absint($input->formID) : 0; | |
| 382 | + if (empty($formID)) { | |
| 383 | + wp_send_json_error(__('Invalid request', 'bit-form'), 400); | |
| 384 | + } | |
| 385 | + $logModel = new FormEntryLogModel(); | |
| 386 | + $rows = $logModel->getIntegrationLastRuns($formID); | |
| 387 | + if (is_wp_error($rows)) { | |
| 388 | + // result_empty means nothing has run yet, which is a success. Any other | |
| 389 | + // error is a failed query — answering [] would paint every integration | |
| 390 | + // as never executed. Message stays generic: no DB detail to the browser. | |
| 391 | + if ('result_empty' !== $rows->get_error_code()) { | |
| 392 | + wp_send_json_error(__('Could not load integration run history', 'bit-form'), 500); | |
| 100 | 393 | } |
| 394 | + $rows = []; | |
| 395 | + } | |
| 396 | + wp_send_json_success($rows, 200); | |
| 397 | + } else { | |
| 398 | + wp_send_json_error( | |
| 399 | + __( | |
| 400 | + 'Token expired', | |
| 401 | + 'bit-form' | |
| 402 | + ), | |
| 403 | + 401 | |
| 404 | + ); | |
| 101 | 405 | } |
| 102 | - public function getTemplate() | |
| 103 | - { | |
| 104 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 105 | - $inputJSON = file_get_contents('php://input'); | |
| 106 | - $input = json_decode($inputJSON); | |
| 107 | - $formHandler = FormHandler::getInstance(); | |
| 108 | - $status = $formHandler->admin->getTemplate($_REQUEST, $input); | |
| 109 | - if (is_wp_error($status)) { | |
| 110 | - wp_send_json_error($status->get_error_message(), 411); | |
| 111 | - } else { | |
| 112 | - wp_send_json_success($status, 200); | |
| 113 | - } | |
| 114 | - } else { | |
| 115 | - wp_send_json_error( | |
| 116 | - __( | |
| 117 | - 'Token expired', | |
| 118 | - 'bitform' | |
| 119 | - ), | |
| 120 | - 401 | |
| 121 | - ); | |
| 406 | + } | |
| 407 | + | |
| 408 | + public function templates() | |
| 409 | + { | |
| 410 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 411 | + $this->verifyAdminPermission(); | |
| 412 | + $templateProvider = new TemplateProvider(); | |
| 413 | + $status = $templateProvider->getAllTemplates(); | |
| 414 | + if (is_wp_error($status)) { | |
| 415 | + wp_send_json_error($status->get_error_message(), 411); | |
| 416 | + } else { | |
| 417 | + wp_send_json_success($status, 200); | |
| 418 | + } | |
| 419 | + } else { | |
| 420 | + wp_send_json_error( | |
| 421 | + __( | |
| 422 | + 'Token expired', | |
| 423 | + 'bit-form' | |
| 424 | + ), | |
| 425 | + 401 | |
| 426 | + ); | |
| 427 | + } | |
| 428 | + } | |
| 429 | + | |
| 430 | + public function builerHelperState() | |
| 431 | + { | |
| 432 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 433 | + $this->verifyAdminPermission(); | |
| 434 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 435 | + // $input = json_decode($inputJSON); | |
| 436 | + | |
| 437 | + GlobalHelper::requirePostMethod(); | |
| 438 | + try { | |
| 439 | + $input = GlobalHelper::formatRequestData(); | |
| 440 | + } catch (\InvalidArgumentException $e) { | |
| 441 | + wp_send_json_error($e->getMessage(), 400); | |
| 442 | + } | |
| 443 | + | |
| 444 | + $formID = $input->formID; | |
| 445 | + $formHandler = FormHandler::getInstance(); | |
| 446 | + $results = $formHandler->admin->builerHelperState($formID); | |
| 447 | + if (is_wp_error($results)) { | |
| 448 | + wp_send_json_error($results, 411); | |
| 449 | + } else { | |
| 450 | + wp_send_json_success($results, 200); | |
| 451 | + } | |
| 452 | + } else { | |
| 453 | + wp_send_json_error( | |
| 454 | + __( | |
| 455 | + 'Token expired', | |
| 456 | + 'bit-form' | |
| 457 | + ), | |
| 458 | + 401 | |
| 459 | + ); | |
| 460 | + } | |
| 461 | + } | |
| 462 | + | |
| 463 | + public function getTemplate() | |
| 464 | + { | |
| 465 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 466 | + $this->verifyAdminPermission(); | |
| 467 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 468 | + // $input = json_decode($inputJSON); | |
| 469 | + GlobalHelper::requirePostMethod(); | |
| 470 | + try { | |
| 471 | + $input = GlobalHelper::formatRequestData(); | |
| 472 | + } catch (\InvalidArgumentException $e) { | |
| 473 | + wp_send_json_error($e->getMessage(), 400); | |
| 474 | + } | |
| 475 | + $formHandler = FormHandler::getInstance(); | |
| 476 | + $sanitized_request = [ | |
| 477 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 478 | + ]; | |
| 479 | + $status = $formHandler->admin->getTemplate($sanitized_request, $input); | |
| 480 | + if (is_wp_error($status)) { | |
| 481 | + wp_send_json_error($status->get_error_message(), 411); | |
| 482 | + } else { | |
| 483 | + wp_send_json_success($status, 200); | |
| 484 | + } | |
| 485 | + } else { | |
| 486 | + wp_send_json_error( | |
| 487 | + __( | |
| 488 | + 'Token expired', | |
| 489 | + 'bit-form' | |
| 490 | + ), | |
| 491 | + 401 | |
| 492 | + ); | |
| 493 | + } | |
| 494 | + } | |
| 495 | + | |
| 496 | + public function getAllForms() | |
| 497 | + { | |
| 498 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 499 | + $this->verifyAdminPermission(); | |
| 500 | + $formHandler = FormHandler::getInstance(); | |
| 501 | + $all_forms = $formHandler->admin->getAllForm(); | |
| 502 | + if (is_wp_error($all_forms)) { | |
| 503 | + wp_send_json_error($all_forms->get_error_message(), 411); | |
| 504 | + } else { | |
| 505 | + wp_send_json_success($all_forms, 200); | |
| 506 | + } | |
| 507 | + } else { | |
| 508 | + wp_send_json_error( | |
| 509 | + __( | |
| 510 | + 'Token expired', | |
| 511 | + 'bit-form' | |
| 512 | + ), | |
| 513 | + 401 | |
| 514 | + ); | |
| 515 | + } | |
| 516 | + } | |
| 517 | + | |
| 518 | + public function migrateFormContents() | |
| 519 | + { | |
| 520 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 521 | + $this->verifyAdminPermission(); | |
| 522 | + $all_forms = get_transient('bitforms_v1_form_contents'); | |
| 523 | + wp_send_json_success($all_forms, 200); | |
| 524 | + } else { | |
| 525 | + wp_send_json_error( | |
| 526 | + __( | |
| 527 | + 'Token expired', | |
| 528 | + 'bit-form' | |
| 529 | + ), | |
| 530 | + 401 | |
| 531 | + ); | |
| 532 | + } | |
| 533 | + } | |
| 534 | + | |
| 535 | + public function setChangelogVersion() | |
| 536 | + { | |
| 537 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 538 | + $this->verifyAdminPermission(); | |
| 539 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 540 | + // $input = json_decode($inputJSON); | |
| 541 | + GlobalHelper::requirePostMethod(); | |
| 542 | + try { | |
| 543 | + $input = GlobalHelper::formatRequestData(); | |
| 544 | + } catch (\InvalidArgumentException $e) { | |
| 545 | + wp_send_json_error($e->getMessage(), 400); | |
| 546 | + } | |
| 547 | + | |
| 548 | + $version = isset($input->version) ? $input->version : ''; | |
| 549 | + update_option('bitforms_changelog_version', $version); | |
| 550 | + wp_send_json_success($version, 200); | |
| 551 | + } else { | |
| 552 | + wp_send_json_error( | |
| 553 | + __( | |
| 554 | + 'Token expired', | |
| 555 | + 'bit-form' | |
| 556 | + ), | |
| 557 | + 401 | |
| 558 | + ); | |
| 559 | + } | |
| 560 | + } | |
| 561 | + | |
| 562 | + public function handleNotice() | |
| 563 | + { | |
| 564 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 565 | + $this->verifyAdminPermission(); | |
| 566 | + GlobalHelper::requirePostMethod(); | |
| 567 | + try { | |
| 568 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 569 | + // $input = json_decode($inputJSON); | |
| 570 | + $input = GlobalHelper::formatRequestData(); | |
| 571 | + $optionName = isset($input->optionName) ? $input->optionName : ''; | |
| 572 | + $optionValue = isset($input->optionValue) ? $input->optionValue : ''; | |
| 573 | + $allowedNoticeKeys = ['bitforms_hide_cashback', 'bitforms_hide_announcement']; | |
| 574 | + if (!in_array($optionName, $allowedNoticeKeys, true)) { | |
| 575 | + wp_send_json_error(__('Invalid option', 'bit-form'), 400); | |
| 122 | 576 | } |
| 577 | + update_option($optionName, (bool) $optionValue); | |
| 578 | + wp_send_json_success([$optionName, (bool) $optionValue], 200); | |
| 579 | + } catch (\Exception | \InvalidArgumentException $e) { | |
| 580 | + wp_send_json_error($e->getMessage(), 400); | |
| 581 | + } | |
| 582 | + } else { | |
| 583 | + wp_send_json_error( | |
| 584 | + __( | |
| 585 | + 'Token expired', | |
| 586 | + 'bit-form' | |
| 587 | + ), | |
| 588 | + 401 | |
| 589 | + ); | |
| 123 | 590 | } |
| 124 | - public function getAllForms() | |
| 125 | - { | |
| 126 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 127 | - $formHandler = FormHandler::getInstance(); | |
| 128 | - $all_forms = $formHandler->admin->getAllForm(); | |
| 129 | - if (is_wp_error($all_forms)) { | |
| 130 | - wp_send_json_error($all_forms->get_error_message(), 411); | |
| 131 | - } else { | |
| 132 | - wp_send_json_success($all_forms, 200); | |
| 133 | - } | |
| 134 | - } else { | |
| 135 | - wp_send_json_error( | |
| 136 | - __( | |
| 137 | - 'Token expired', | |
| 138 | - 'bitform' | |
| 139 | - ), | |
| 140 | - 401 | |
| 141 | - ); | |
| 591 | + } | |
| 592 | + | |
| 593 | + private function formatFormContentForUpdate($formContents) | |
| 594 | + { | |
| 595 | + $updatedFormContents = (object) []; | |
| 596 | + $updatedPaths = [ | |
| 597 | + 'id' => 'id', | |
| 598 | + 'form_name' => 'form_name', | |
| 599 | + 'layout' => 'form_content->layout', | |
| 600 | + 'fields' => 'form_content->fields', | |
| 601 | + 'additional' => 'additional', | |
| 602 | + 'workFlows' => 'workFlows', | |
| 603 | + 'formStyle' => null, | |
| 604 | + 'style' => null, | |
| 605 | + 'staticStyles' => null, | |
| 606 | + 'themeColors' => null, | |
| 607 | + 'themeVars' => null, | |
| 608 | + 'breakpointSize' => null, | |
| 609 | + 'customCodes' => null, | |
| 610 | + 'builderSettings' => null, | |
| 611 | + 'layoutChanged' => null, | |
| 612 | + 'rowHeight' => null, | |
| 613 | + 'formSettings' => 'formSettings', | |
| 614 | + ]; | |
| 615 | + foreach ($updatedPaths as $key => $value) { | |
| 616 | + if (!is_null($value)) { | |
| 617 | + $value = Helpers::getDataFromNestedPath($formContents, $value); | |
| 618 | + } | |
| 619 | + $updatedFormContents->$key = $value; | |
| 620 | + } | |
| 621 | + | |
| 622 | + foreach ($formContents['reports'] as $report) { | |
| 623 | + if ('1' === $report['isDefault']) { | |
| 624 | + $updatedFormContents->currentReport = $report; | |
| 625 | + $updatedFormContents->report_id = $report['id']; | |
| 626 | + } | |
| 627 | + } | |
| 628 | + | |
| 629 | + $updatedFormContents = json_decode(wp_json_encode($updatedFormContents)); | |
| 630 | + | |
| 631 | + $updatedFormContents->formSettings->theme = 'default'; | |
| 632 | + | |
| 633 | + return $updatedFormContents; | |
| 634 | + } | |
| 635 | + | |
| 636 | + public function getEmailConfig() | |
| 637 | + { | |
| 638 | + Utilities::ignoreUserAbort(); | |
| 639 | + | |
| 640 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 641 | + $this->verifyAdminPermission(); | |
| 642 | + $ipTool = new IpTool(); | |
| 643 | + $user_details = $ipTool->getUserDetail(); | |
| 644 | + $integrationHandler = new IntegrationHandler(0, $user_details); | |
| 645 | + $user_details = $ipTool->getUserDetail(); | |
| 646 | + $formIntegrations = $integrationHandler->getAllIntegration('mail', 'smtp'); | |
| 647 | + if (is_wp_error($formIntegrations)) { | |
| 648 | + wp_send_json_error($formIntegrations->get_error_message(), 411); | |
| 649 | + } | |
| 650 | + if (isset($formIntegrations[0]->integration_details) && is_string($formIntegrations[0]->integration_details)) { | |
| 651 | + $formIntegrations[0]->integration_details = wp_unslash($formIntegrations[0]->integration_details); | |
| 652 | + } | |
| 653 | + wp_send_json_success($formIntegrations, 200); | |
| 654 | + } else { | |
| 655 | + wp_send_json_error( | |
| 656 | + __( | |
| 657 | + 'Token expired', | |
| 658 | + 'bit-form' | |
| 659 | + ), | |
| 660 | + 401 | |
| 661 | + ); | |
| 662 | + } | |
| 663 | + } | |
| 664 | + | |
| 665 | + public function saveEmailConfig() | |
| 666 | + { | |
| 667 | + Utilities::ignoreUserAbort(); | |
| 668 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 669 | + $this->verifyAdminPermission(); | |
| 670 | + GlobalHelper::requirePostMethod(); | |
| 671 | + $ipTool = new IpTool(); | |
| 672 | + $user_details = $ipTool->getUserDetail(); | |
| 673 | + $integrationHandler = new IntegrationHandler(0, $user_details); | |
| 674 | + try { | |
| 675 | + $formattedData = GlobalHelper::formatRequestData(); | |
| 676 | + } catch (\InvalidArgumentException $e) { | |
| 677 | + wp_send_json_error($e->getMessage(), 400); | |
| 678 | + } | |
| 679 | + $status = isset($formattedData->status) ? $formattedData->status : null; | |
| 680 | + $integrationDetails = json_encode($formattedData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); | |
| 681 | + $user_details = $ipTool->getUserDetail(); | |
| 682 | + $integrationName = 'smtp'; | |
| 683 | + $integrationType = 'smtp'; | |
| 684 | + $formIntegrations = $integrationHandler->getAllIntegration('mail', 'smtp'); | |
| 685 | + if (isset($formIntegrations->errors['result_empty'])) { | |
| 686 | + $integrationHandler->saveIntegration($integrationName, $integrationType, $integrationDetails, 'mail', $status); | |
| 687 | + } else { | |
| 688 | + $integrationHandler->updateIntegration($formIntegrations[0]->id, $integrationName, $integrationType, $integrationDetails, 'mail', $status); | |
| 689 | + } | |
| 690 | + wp_send_json_success($formIntegrations, 200); | |
| 691 | + } else { | |
| 692 | + wp_send_json_error( | |
| 693 | + __( | |
| 694 | + 'Token expired', | |
| 695 | + 'bit-form' | |
| 696 | + ), | |
| 697 | + 401 | |
| 698 | + ); | |
| 699 | + } | |
| 700 | + } | |
| 701 | + | |
| 702 | + public function testEmail() | |
| 703 | + { | |
| 704 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 705 | + $this->verifyAdminPermission(); | |
| 706 | + GlobalHelper::requirePostMethod(); | |
| 707 | + | |
| 708 | + try { | |
| 709 | + $formattedData = GlobalHelper::formatRequestData(); | |
| 710 | + } catch (\InvalidArgumentException $e) { | |
| 711 | + wp_send_json_error($e->getMessage(), 400); | |
| 712 | + } | |
| 713 | + | |
| 714 | + $to = isset($formattedData->to) ? sanitize_email($formattedData->to) : ''; | |
| 715 | + $subject = isset($formattedData->subject) ? sanitize_text_field($formattedData->subject) : ''; | |
| 716 | + $message = isset($formattedData->message) ? sanitize_textarea_field($formattedData->message) : ''; | |
| 717 | + | |
| 718 | + if (!empty($to) && !empty($subject) && !empty($message)) { | |
| 719 | + try { | |
| 720 | + (new MailConfig())->sendMail(); | |
| 721 | + add_action('wp_mail_failed', function ($error) { | |
| 722 | + $data = []; | |
| 723 | + $data['errors'] = $error->errors['wp_mail_failed']; | |
| 724 | + wp_send_json_error($data, 400); | |
| 725 | + }); | |
| 726 | + $result = wp_mail($to, $subject, $message); | |
| 727 | + wp_send_json_success($result, 200); | |
| 728 | + } catch (\Exception $e) { | |
| 729 | + wp_send_json_error($e->getMessage(), 400); | |
| 142 | 730 | } |
| 731 | + } else { | |
| 732 | + wp_send_json_error( | |
| 733 | + __( | |
| 734 | + 'Some of the test fields are empty or an invalid email supplied', | |
| 735 | + 'bit-form' | |
| 736 | + ), | |
| 737 | + 401 | |
| 738 | + ); | |
| 739 | + } | |
| 740 | + } else { | |
| 741 | + wp_send_json_error( | |
| 742 | + __( | |
| 743 | + 'Token expired', | |
| 744 | + 'bit-form' | |
| 745 | + ), | |
| 746 | + 401 | |
| 747 | + ); | |
| 143 | 748 | } |
| 749 | + } | |
| 144 | 750 | |
| 145 | - public function importDataStore() | |
| 146 | - { | |
| 147 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 148 | - $inputJSON = file_get_contents('php://input'); | |
| 149 | - $input = json_decode($inputJSON); | |
| 150 | - echo json_encode($input); | |
| 151 | - die; | |
| 152 | - // $formHandler = FormHandler::getInstance(); | |
| 153 | - // $status = $formHandler->admin->getFormEntryLabelAndCount($_REQUEST, $input); | |
| 154 | - // if (is_wp_error($status)) { | |
| 155 | - // wp_send_json_error($status->get_error_message(), 411); | |
| 156 | - // } else { | |
| 157 | - // wp_send_json_success($status, 200); | |
| 158 | - // } | |
| 159 | - } else { | |
| 160 | - wp_send_json_error( | |
| 161 | - __( | |
| 162 | - 'Token expired', | |
| 163 | - 'bitform' | |
| 164 | - ), | |
| 165 | - 401 | |
| 166 | - ); | |
| 167 | - } | |
| 751 | + public function migrationComplete() | |
| 752 | + { | |
| 753 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 754 | + $this->verifyAdminPermission(); | |
| 755 | + delete_transient('bitforms_v1_form_contents'); | |
| 756 | + delete_option('bitforms_migrating_to_v2'); | |
| 757 | + update_option('bitforms_migrated_to_v2', true); | |
| 758 | + wp_send_json_success(__('Migration Complete', 'bit-form'), 200); | |
| 759 | + } else { | |
| 760 | + wp_send_json_error( | |
| 761 | + __( | |
| 762 | + 'Token expired', | |
| 763 | + 'bit-form' | |
| 764 | + ), | |
| 765 | + 401 | |
| 766 | + ); | |
| 168 | 767 | } |
| 169 | - public function getFormEntryLabelAndCount() | |
| 170 | - { | |
| 171 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 172 | - $inputJSON = file_get_contents('php://input'); | |
| 173 | - $input = json_decode($inputJSON); | |
| 174 | - $formHandler = FormHandler::getInstance(); | |
| 175 | - $status = $formHandler->admin->getFormEntryLabelAndCount($_REQUEST, $input); | |
| 176 | - if (is_wp_error($status)) { | |
| 177 | - wp_send_json_error($status->get_error_message(), 411); | |
| 178 | - } else { | |
| 179 | - wp_send_json_success($status, 200); | |
| 180 | - } | |
| 181 | - } else { | |
| 182 | - wp_send_json_error( | |
| 183 | - __( | |
| 184 | - 'Token expired', | |
| 185 | - 'bitform' | |
| 186 | - ), | |
| 187 | - 401 | |
| 188 | - ); | |
| 189 | - } | |
| 768 | + } | |
| 769 | + | |
| 770 | + public function importDataStore() | |
| 771 | + { | |
| 772 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 773 | + $this->verifyAdminPermission(); | |
| 774 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 775 | + // $input = json_decode($inputJSON); | |
| 776 | + GlobalHelper::requirePostMethod(); | |
| 777 | + try { | |
| 778 | + $input = GlobalHelper::formatRequestData(); | |
| 779 | + } catch (\InvalidArgumentException $e) { | |
| 780 | + wp_send_json_error($e->getMessage(), 400); | |
| 781 | + } | |
| 782 | + echo wp_json_encode($input); | |
| 783 | + die; | |
| 784 | + } else { | |
| 785 | + wp_send_json_error( | |
| 786 | + __( | |
| 787 | + 'Token expired', | |
| 788 | + 'bit-form' | |
| 789 | + ), | |
| 790 | + 401 | |
| 791 | + ); | |
| 190 | 792 | } |
| 191 | - public function getFormEntry() | |
| 192 | - { | |
| 193 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 194 | - $inputJSON = file_get_contents('php://input'); | |
| 195 | - $input = json_decode($inputJSON); | |
| 196 | - $formHandler = FormHandler::getInstance(); | |
| 197 | - $status = $formHandler->admin->getFormEntry($_REQUEST, $input); | |
| 198 | - if (is_wp_error($status)) { | |
| 199 | - wp_send_json_error($status->get_error_message(), 411); | |
| 200 | - } else { | |
| 201 | - wp_send_json_success($status, 200); | |
| 202 | - } | |
| 203 | - } else { | |
| 204 | - wp_send_json_error(__('Token expired', 'bitform'), 401); | |
| 205 | - } | |
| 793 | + } | |
| 794 | + | |
| 795 | + public function getFormEntryLabelAndCount() | |
| 796 | + { | |
| 797 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 798 | + $this->verifyAdminPermission(); | |
| 799 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 800 | + // $input = json_decode($inputJSON); | |
| 801 | + GlobalHelper::requirePostMethod(); | |
| 802 | + try { | |
| 803 | + $input = GlobalHelper::formatRequestData(); | |
| 804 | + } catch (\InvalidArgumentException $e) { | |
| 805 | + wp_send_json_error($e->getMessage(), 400); | |
| 806 | + } | |
| 807 | + | |
| 808 | + $formHandler = FormHandler::getInstance(); | |
| 809 | + $status = $formHandler->admin->getFormEntryLabelAndCount($_REQUEST, $input); | |
| 810 | + if (is_wp_error($status)) { | |
| 811 | + wp_send_json_error($status->get_error_message(), 411); | |
| 812 | + } else { | |
| 813 | + wp_send_json_success($status, 200); | |
| 814 | + } | |
| 815 | + } else { | |
| 816 | + wp_send_json_error( | |
| 817 | + __( | |
| 818 | + 'Token expired', | |
| 819 | + 'bit-form' | |
| 820 | + ), | |
| 821 | + 401 | |
| 822 | + ); | |
| 206 | 823 | } |
| 824 | + } | |
| 207 | 825 | |
| 208 | - public function filterExportEntry() | |
| 209 | - { | |
| 210 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 211 | - $inputJSON = file_get_contents('php://input'); | |
| 212 | - $input = json_decode($inputJSON); | |
| 213 | - $formHandler = FormHandler::getInstance(); | |
| 214 | - $status = $formHandler->admin->getExportEntry($input->data); | |
| 215 | - if (is_wp_error($status)) { | |
| 216 | - wp_send_json_error($status->get_error_message(), 411); | |
| 217 | - } else { | |
| 218 | - wp_send_json_success($status, 200); | |
| 219 | - } | |
| 220 | - } else { | |
| 221 | - wp_send_json_error(__('Token expired', 'bitform'), 401); | |
| 222 | - } | |
| 826 | + public function getFormEntry() | |
| 827 | + { | |
| 828 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 829 | + $this->verifyAdminPermission(); | |
| 830 | + GlobalHelper::requirePostMethod(); | |
| 831 | + try { | |
| 832 | + $input = GlobalHelper::formatRequestData(); | |
| 833 | + } catch (\InvalidArgumentException $e) { | |
| 834 | + wp_send_json_error($e->getMessage(), 400); | |
| 835 | + } | |
| 836 | + $formHandler = FormHandler::getInstance(); | |
| 837 | + $sanitized_request = [ | |
| 838 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 839 | + ]; | |
| 840 | + $status = $formHandler->admin->getFormEntry($sanitized_request, $input); | |
| 841 | + if (is_wp_error($status)) { | |
| 842 | + wp_send_json_error($status->get_error_message(), 411); | |
| 843 | + } else { | |
| 844 | + wp_send_json_success($status, 200); | |
| 845 | + } | |
| 846 | + } else { | |
| 847 | + wp_send_json_error(__('Token expired', 'bit-form'), 401); | |
| 223 | 848 | } |
| 849 | + } | |
| 224 | 850 | |
| 225 | - /** | |
| 226 | - * Undocumented function | |
| 227 | - * | |
| 228 | - * @return void | |
| 229 | - */ | |
| 230 | - public function updateForm() | |
| 231 | - { | |
| 232 | - \ignore_user_abort(); | |
| 233 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 234 | - $inputJSON = file_get_contents('php://input'); | |
| 235 | - $input = json_decode($inputJSON); | |
| 236 | - $formHandler = FormHandler::getInstance(); | |
| 237 | - $status = $formHandler->admin->updateForm($_REQUEST, $input); | |
| 238 | - if (is_wp_error($status)) { | |
| 239 | - wp_send_json_error($status->get_error_message(), 411); | |
| 240 | - } else { | |
| 241 | - wp_send_json_success($status, 200); | |
| 242 | - } | |
| 243 | - } else { | |
| 244 | - wp_send_json_error( | |
| 245 | - __( | |
| 246 | - 'Token expired', | |
| 247 | - 'bitform' | |
| 248 | - ), | |
| 249 | - 401 | |
| 250 | - ); | |
| 251 | - } | |
| 851 | + public function getEntriesForReport() | |
| 852 | + { | |
| 853 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 854 | + $this->verifyAdminPermission(); | |
| 855 | + GlobalHelper::requirePostMethod(); | |
| 856 | + try { | |
| 857 | + $input = GlobalHelper::formatRequestData(); | |
| 858 | + } catch (\InvalidArgumentException $e) { | |
| 859 | + wp_send_json_error($e->getMessage(), 400); | |
| 860 | + } | |
| 861 | + $formHandler = FormHandler::getInstance(); | |
| 862 | + $sanitized_request = [ | |
| 863 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 864 | + ]; | |
| 865 | + $status = $formHandler->admin->getEntriesForReport($sanitized_request, $input); | |
| 866 | + if (is_wp_error($status)) { | |
| 867 | + wp_send_json_error($status->get_error_message(), 411); | |
| 868 | + } else { | |
| 869 | + wp_send_json_success($status, 200); | |
| 870 | + } | |
| 871 | + } else { | |
| 872 | + wp_send_json_error(__('Token expired', 'bit-form'), 401); | |
| 252 | 873 | } |
| 253 | - public function createNewForm() | |
| 254 | - { | |
| 255 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 256 | - $inputJSON = file_get_contents('php://input'); | |
| 257 | - $input = json_decode($inputJSON); | |
| 258 | - $formHandler = FormHandler::getInstance(); | |
| 259 | - $status = $formHandler->admin->createNewForm($_REQUEST, $input); | |
| 260 | - if (is_wp_error($status)) { | |
| 261 | - wp_send_json_error($status->get_error_message(), 411); | |
| 262 | - } else { | |
| 263 | - wp_send_json_success($status, 200); | |
| 264 | - } | |
| 265 | - } else { | |
| 266 | - wp_send_json_error( | |
| 267 | - __( | |
| 268 | - 'Token expired', | |
| 269 | - 'bitform' | |
| 270 | - ), | |
| 271 | - 401 | |
| 272 | - ); | |
| 273 | - } | |
| 874 | + } | |
| 875 | + | |
| 876 | + public function filterExportEntry() | |
| 877 | + { | |
| 878 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 879 | + $this->verifyAdminPermission(); | |
| 880 | + GlobalHelper::requirePostMethod(); | |
| 881 | + try { | |
| 882 | + $input = GlobalHelper::formatRequestData(); | |
| 883 | + } catch (\InvalidArgumentException $e) { | |
| 884 | + wp_send_json_error($e->getMessage(), 400); | |
| 885 | + } | |
| 886 | + $formHandler = FormHandler::getInstance(); | |
| 887 | + $status = $formHandler->admin->getExportEntry($input->data); | |
| 888 | + if (is_wp_error($status)) { | |
| 889 | + wp_send_json_error($status->get_error_message(), 411); | |
| 890 | + } else { | |
| 891 | + wp_send_json_success($status, 200); | |
| 892 | + } | |
| 893 | + } else { | |
| 894 | + wp_send_json_error(__('Token expired', 'bit-form'), 401); | |
| 274 | 895 | } |
| 275 | - public function changeFormStatus() | |
| 276 | - { | |
| 277 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 278 | - $inputJSON = file_get_contents('php://input'); | |
| 279 | - $input = json_decode($inputJSON); | |
| 280 | - $formHandler = FormHandler::getInstance(); | |
| 281 | - $status = $formHandler->admin->changeFormStatus($_REQUEST, $input); | |
| 282 | - if (is_wp_error($status)) { | |
| 283 | - wp_send_json_error($status->get_error_message(), 411); | |
| 284 | - } else { | |
| 285 | - wp_send_json_success($status, 200); | |
| 286 | - } | |
| 287 | - } else { | |
| 288 | - wp_send_json_error( | |
| 289 | - __( | |
| 290 | - 'Token expired', | |
| 291 | - 'bitform' | |
| 292 | - ), | |
| 293 | - 401 | |
| 294 | - ); | |
| 295 | - } | |
| 896 | + } | |
| 897 | + | |
| 898 | + /** | |
| 899 | + * Undocumented function | |
| 900 | + * | |
| 901 | + * @return void | |
| 902 | + */ | |
| 903 | + public function updateForm() | |
| 904 | + { | |
| 905 | + Utilities::ignoreUserAbort(); | |
| 906 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 907 | + $this->verifyAdminPermission(); | |
| 908 | + GlobalHelper::requirePostMethod(); | |
| 909 | + try { | |
| 910 | + $input = GlobalHelper::formatRequestData(); | |
| 911 | + } catch (\InvalidArgumentException $e) { | |
| 912 | + wp_send_json_error($e->getMessage(), 400); | |
| 913 | + } | |
| 914 | + $formHandler = FormHandler::getInstance(); | |
| 915 | + $status = $formHandler->admin->updateForm([], $input); | |
| 916 | + if (isset($input->customCodes)) { | |
| 917 | + FrontEndScriptGenerator::customCodeFile($input->id, $input->customCodes); | |
| 918 | + } | |
| 919 | + if (is_wp_error($status)) { | |
| 920 | + wp_send_json_error($status->get_error_message(), 411); | |
| 921 | + } else { | |
| 922 | + wp_send_json_success($status, 200); | |
| 923 | + } | |
| 924 | + } else { | |
| 925 | + wp_send_json_error( | |
| 926 | + __( | |
| 927 | + 'Token expired', | |
| 928 | + 'bit-form' | |
| 929 | + ), | |
| 930 | + 401 | |
| 931 | + ); | |
| 296 | 932 | } |
| 297 | - public function changeBulkFormStatus() | |
| 298 | - { | |
| 299 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 300 | - $inputJSON = file_get_contents('php://input'); | |
| 301 | - $input = json_decode($inputJSON); | |
| 302 | - $formHandler = FormHandler::getInstance(); | |
| 303 | - $status = $formHandler->admin->changeBulkFormStatus($_REQUEST, $input); | |
| 304 | - if (is_wp_error($status)) { | |
| 305 | - wp_send_json_error($status->get_error_message(), 411); | |
| 306 | - } else { | |
| 307 | - wp_send_json_success($status, 200); | |
| 308 | - } | |
| 309 | - } else { | |
| 310 | - wp_send_json_error( | |
| 311 | - __( | |
| 312 | - 'Token expired', | |
| 313 | - 'bitform' | |
| 314 | - ), | |
| 315 | - 401 | |
| 316 | - ); | |
| 933 | + } | |
| 934 | + | |
| 935 | + public function saveCss() | |
| 936 | + { | |
| 937 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 938 | + $this->verifyAdminPermission(); | |
| 939 | + GlobalHelper::requirePostMethod(); | |
| 940 | + try { | |
| 941 | + $input = GlobalHelper::formatRequestData(); | |
| 942 | + } catch (\InvalidArgumentException $e) { | |
| 943 | + wp_send_json_error($e->getMessage(), 400); | |
| 944 | + } | |
| 945 | + | |
| 946 | + $formId = isset($input->form_id) ? sanitize_text_field($input->form_id) : ''; | |
| 947 | + if (!filter_var($formId, FILTER_VALIDATE_INT)) { | |
| 948 | + wp_send_json_error(__('Invalid form id', 'bit-form'), 400); | |
| 949 | + } | |
| 950 | + if (isset($input->atomicCssText)) { | |
| 951 | + $status = FrontEndScriptGenerator::saveCssFile($formId, $input->atomicCssText); | |
| 952 | + } | |
| 953 | + if (isset($input->atomicCssWithFormIdText)) { | |
| 954 | + $status = FrontEndScriptGenerator::saveCssFile("{$formId}-formid", $input->atomicCssWithFormIdText); | |
| 955 | + } | |
| 956 | + if (isset($input->atomicClassMap) || isset($input->atomicClassMap)) { | |
| 957 | + $formModel = new FormModel(); | |
| 958 | + $atomicClsMap = [ | |
| 959 | + 'atomic_class_map' => isset($input->atomicClassMap) ? $input->atomicClassMap : (object) [], | |
| 960 | + 'atomic_class_map_with_form_id' => isset($input->atomicClassMapWithFormId) ? $input->atomicClassMapWithFormId : (object) [], | |
| 961 | + ]; | |
| 962 | + $updateData['atomic_class_map'] = wp_json_encode($atomicClsMap); | |
| 963 | + $formModel->update( | |
| 964 | + $updateData, | |
| 965 | + [ | |
| 966 | + 'id' => $formId, | |
| 967 | + ] | |
| 968 | + ); | |
| 969 | + } | |
| 970 | + if (is_wp_error($status)) { | |
| 971 | + wp_send_json_error($status->get_error_message(), 411); | |
| 972 | + } else { | |
| 973 | + wp_send_json_success($status, 200); | |
| 974 | + } | |
| 975 | + } else { | |
| 976 | + wp_send_json_error( | |
| 977 | + __( | |
| 978 | + 'Token expired', | |
| 979 | + 'bit-form' | |
| 980 | + ), | |
| 981 | + 401 | |
| 982 | + ); | |
| 983 | + } | |
| 984 | + } | |
| 985 | + | |
| 986 | + public function createNewForm() | |
| 987 | + { | |
| 988 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 989 | + $this->verifyAdminPermission(); | |
| 990 | + GlobalHelper::requirePostMethod(); | |
| 991 | + try { | |
| 992 | + $input = GlobalHelper::formatRequestData(); | |
| 993 | + } catch (\InvalidArgumentException $e) { | |
| 994 | + wp_send_json_error($e->getMessage(), 400); | |
| 995 | + } | |
| 996 | + $formHandler = FormHandler::getInstance(); | |
| 997 | + $sanitized_request = [ | |
| 998 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 999 | + ]; | |
| 1000 | + $status = $formHandler->admin->createNewForm($sanitized_request, $input); | |
| 1001 | + $formId = sanitize_text_field($input->form_id); | |
| 1002 | + if (isset($input->customCodes)) { | |
| 1003 | + FrontEndScriptGenerator::customCodeFile($formId, $input->customCodes); | |
| 1004 | + } | |
| 1005 | + if (is_wp_error($status)) { | |
| 1006 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1007 | + } else { | |
| 1008 | + wp_send_json_success($status, 200); | |
| 1009 | + } | |
| 1010 | + } else { | |
| 1011 | + wp_send_json_error( | |
| 1012 | + __( | |
| 1013 | + 'Token expired', | |
| 1014 | + 'bit-form' | |
| 1015 | + ), | |
| 1016 | + 401 | |
| 1017 | + ); | |
| 1018 | + } | |
| 1019 | + } | |
| 1020 | + | |
| 1021 | + public function updateEntryStatus() | |
| 1022 | + { | |
| 1023 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1024 | + $this->verifyAdminPermission(); | |
| 1025 | + GlobalHelper::requirePostMethod(); | |
| 1026 | + try { | |
| 1027 | + $input = GlobalHelper::formatRequestData(); | |
| 1028 | + } catch (\InvalidArgumentException $e) { | |
| 1029 | + wp_send_json_error($e->getMessage(), 400); | |
| 1030 | + } | |
| 1031 | + $formId = $input->formId; | |
| 1032 | + $entryId = $input->entryId; | |
| 1033 | + $formEntryModel = new FormEntryModel(); | |
| 1034 | + $updatedTime = current_time('mysql'); | |
| 1035 | + $status = $formEntryModel->update( | |
| 1036 | + [ | |
| 1037 | + 'status' => 0, | |
| 1038 | + 'updated_at' => $updatedTime, | |
| 1039 | + ], | |
| 1040 | + [ | |
| 1041 | + 'form_id' => $formId, | |
| 1042 | + 'id' => $entryId, | |
| 1043 | + ] | |
| 1044 | + ); | |
| 1045 | + if (is_wp_error($status)) { | |
| 1046 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1047 | + } else { | |
| 1048 | + wp_send_json_success(['update_at_time' => $updatedTime], 200); | |
| 1049 | + } | |
| 1050 | + } else { | |
| 1051 | + wp_send_json_error( | |
| 1052 | + __( | |
| 1053 | + 'Token expired', | |
| 1054 | + 'bit-form' | |
| 1055 | + ), | |
| 1056 | + 401 | |
| 1057 | + ); | |
| 1058 | + } | |
| 1059 | + } | |
| 1060 | + | |
| 1061 | + public function changeFormStatus() | |
| 1062 | + { | |
| 1063 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1064 | + $this->verifyAdminPermission(); | |
| 1065 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1066 | + // $input = json_decode($inputJSON); | |
| 1067 | + | |
| 1068 | + GlobalHelper::requirePostMethod(); | |
| 1069 | + try { | |
| 1070 | + $input = GlobalHelper::formatRequestData(); | |
| 1071 | + } catch (\InvalidArgumentException $e) { | |
| 1072 | + wp_send_json_error($e->getMessage(), 400); | |
| 1073 | + } | |
| 1074 | + | |
| 1075 | + $formHandler = FormHandler::getInstance(); | |
| 1076 | + $sanitized_request = [ | |
| 1077 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1078 | + ]; | |
| 1079 | + $status = $formHandler->admin->changeFormStatus($sanitized_request, $input); | |
| 1080 | + if (is_wp_error($status)) { | |
| 1081 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1082 | + } else { | |
| 1083 | + wp_send_json_success($status, 200); | |
| 1084 | + } | |
| 1085 | + } else { | |
| 1086 | + wp_send_json_error( | |
| 1087 | + __( | |
| 1088 | + 'Token expired', | |
| 1089 | + 'bit-form' | |
| 1090 | + ), | |
| 1091 | + 401 | |
| 1092 | + ); | |
| 1093 | + } | |
| 1094 | + } | |
| 1095 | + | |
| 1096 | + public function changeBulkFormStatus() | |
| 1097 | + { | |
| 1098 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1099 | + $this->verifyAdminPermission(); | |
| 1100 | + GlobalHelper::requirePostMethod(); | |
| 1101 | + try { | |
| 1102 | + $input = GlobalHelper::formatRequestData(); | |
| 1103 | + } catch (\InvalidArgumentException $e) { | |
| 1104 | + wp_send_json_error($e->getMessage(), 400); | |
| 1105 | + } | |
| 1106 | + $formHandler = FormHandler::getInstance(); | |
| 1107 | + $sanitized_request = [ | |
| 1108 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1109 | + ]; | |
| 1110 | + $status = $formHandler->admin->changeBulkFormStatus($sanitized_request, $input); | |
| 1111 | + if (is_wp_error($status)) { | |
| 1112 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1113 | + } else { | |
| 1114 | + wp_send_json_success($status, 200); | |
| 1115 | + } | |
| 1116 | + } else { | |
| 1117 | + wp_send_json_error( | |
| 1118 | + __( | |
| 1119 | + 'Token expired', | |
| 1120 | + 'bit-form' | |
| 1121 | + ), | |
| 1122 | + 401 | |
| 1123 | + ); | |
| 1124 | + } | |
| 1125 | + } | |
| 1126 | + | |
| 1127 | + public function getAForm() | |
| 1128 | + { | |
| 1129 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1130 | + $this->verifyAdminPermission(); | |
| 1131 | + GlobalHelper::requirePostMethod(); | |
| 1132 | + try { | |
| 1133 | + $input = GlobalHelper::formatRequestData(); | |
| 1134 | + } catch (\InvalidArgumentException $e) { | |
| 1135 | + wp_send_json_error($e->getMessage(), 400); | |
| 1136 | + } | |
| 1137 | + $formHandler = FormHandler::getInstance(); | |
| 1138 | + $sanitized_request = [ | |
| 1139 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1140 | + ]; | |
| 1141 | + $status = $formHandler->admin->getAForm($sanitized_request, $input); | |
| 1142 | + if (is_wp_error($status)) { | |
| 1143 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1144 | + } else { | |
| 1145 | + wp_send_json_success($status, 200); | |
| 1146 | + } | |
| 1147 | + } else { | |
| 1148 | + wp_send_json_error( | |
| 1149 | + __( | |
| 1150 | + 'Token expired', | |
| 1151 | + 'bit-form' | |
| 1152 | + ), | |
| 1153 | + 401 | |
| 1154 | + ); | |
| 1155 | + } | |
| 1156 | + } | |
| 1157 | + | |
| 1158 | + public function duplicateAForm() | |
| 1159 | + { | |
| 1160 | + Utilities::ignoreUserAbort(); | |
| 1161 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1162 | + $this->verifyAdminPermission(); | |
| 1163 | + GlobalHelper::requirePostMethod(); | |
| 1164 | + try { | |
| 1165 | + $input = GlobalHelper::formatRequestData(); | |
| 1166 | + } catch (\InvalidArgumentException $e) { | |
| 1167 | + wp_send_json_error($e->getMessage(), 400); | |
| 1168 | + } | |
| 1169 | + $formHandler = FormHandler::getInstance(); | |
| 1170 | + $sanitized_request = [ | |
| 1171 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1172 | + ]; | |
| 1173 | + $status = $formHandler->admin->duplicateAForm($sanitized_request, $input); | |
| 1174 | + if (is_wp_error($status)) { | |
| 1175 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1176 | + } else { | |
| 1177 | + wp_send_json_success($status, 200); | |
| 1178 | + } | |
| 1179 | + } else { | |
| 1180 | + wp_send_json_error( | |
| 1181 | + __( | |
| 1182 | + 'Token expired', | |
| 1183 | + 'bit-form' | |
| 1184 | + ), | |
| 1185 | + 401 | |
| 1186 | + ); | |
| 1187 | + } | |
| 1188 | + } | |
| 1189 | + | |
| 1190 | + public function importAForm() | |
| 1191 | + { | |
| 1192 | + Utilities::ignoreUserAbort(); | |
| 1193 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1194 | + $this->verifyAdminPermission(); | |
| 1195 | + GlobalHelper::requirePostMethod(); | |
| 1196 | + try { | |
| 1197 | + $input = GlobalHelper::formatRequestData(); | |
| 1198 | + } catch (\InvalidArgumentException $e) { | |
| 1199 | + wp_send_json_error($e->getMessage(), 400); | |
| 1200 | + } | |
| 1201 | + $formHandler = FormHandler::getInstance(); | |
| 1202 | + $status = $formHandler->admin->importAForm($input); | |
| 1203 | + if (is_wp_error($status)) { | |
| 1204 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1205 | + } else { | |
| 1206 | + wp_send_json_success($status, 200); | |
| 1207 | + } | |
| 1208 | + } else { | |
| 1209 | + wp_send_json_error( | |
| 1210 | + __( | |
| 1211 | + 'Token expired', | |
| 1212 | + 'bit-form' | |
| 1213 | + ), | |
| 1214 | + 401 | |
| 1215 | + ); | |
| 1216 | + } | |
| 1217 | + } | |
| 1218 | + | |
| 1219 | + // public function exportAForm() { | |
| 1220 | + // if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1221 | + // $formHandler = FormHandler::getInstance(); | |
| 1222 | + // $status = $formHandler->admin->exportAForm($_REQUEST); | |
| 1223 | + // if (is_wp_error($status)) { | |
| 1224 | + // wp_send_json_error($status->get_error_message(), 411); | |
| 1225 | + // } | |
| 1226 | + // } else { | |
| 1227 | + // wp_send_json_error( | |
| 1228 | + // __( | |
| 1229 | + // 'Token expired', | |
| 1230 | + // 'bit-form' | |
| 1231 | + // ), | |
| 1232 | + // 401 | |
| 1233 | + // ); | |
| 1234 | + // } | |
| 1235 | + // } | |
| 1236 | + public function exportAForm() | |
| 1237 | + { | |
| 1238 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1239 | + $this->verifyAdminPermission(); | |
| 1240 | + GlobalHelper::requirePostMethod(); | |
| 1241 | + try { | |
| 1242 | + $input = GlobalHelper::formatRequestData(); | |
| 1243 | + } catch (\InvalidArgumentException $e) { | |
| 1244 | + wp_send_json_error($e->getMessage(), 400); | |
| 1245 | + } | |
| 1246 | + $formHandler = FormHandler::getInstance(); | |
| 1247 | + $sanitized_request = [ | |
| 1248 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1249 | + ]; | |
| 1250 | + $status = $formHandler->admin->exportAForm($sanitized_request, $input); | |
| 1251 | + if (is_wp_error($status)) { | |
| 1252 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1253 | + } else { | |
| 1254 | + wp_send_json_success($status); | |
| 1255 | + } | |
| 1256 | + } else { | |
| 1257 | + wp_send_json_error( | |
| 1258 | + __( | |
| 1259 | + 'Token expired', | |
| 1260 | + 'bit-form' | |
| 1261 | + ), | |
| 1262 | + 401 | |
| 1263 | + ); | |
| 1264 | + } | |
| 1265 | + } | |
| 1266 | + | |
| 1267 | + public function deleteAForm() | |
| 1268 | + { | |
| 1269 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1270 | + $this->verifyAdminPermission(); | |
| 1271 | + GlobalHelper::requirePostMethod(); | |
| 1272 | + try { | |
| 1273 | + $input = GlobalHelper::formatRequestData(); | |
| 1274 | + } catch (\InvalidArgumentException $e) { | |
| 1275 | + wp_send_json_error($e->getMessage(), 400); | |
| 1276 | + } | |
| 1277 | + $formHandler = FormHandler::getInstance(); | |
| 1278 | + $sanitized_request = [ | |
| 1279 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1280 | + 'id' => isset($_REQUEST['id']) ? absint($_REQUEST['id']) : 0, | |
| 1281 | + ]; | |
| 1282 | + $status = $formHandler->admin->deleteAForm($sanitized_request, $input); | |
| 1283 | + if (is_wp_error($status)) { | |
| 1284 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1285 | + } else { | |
| 1286 | + wp_send_json_success($status, 200); | |
| 1287 | + } | |
| 1288 | + } else { | |
| 1289 | + wp_send_json_error( | |
| 1290 | + __( | |
| 1291 | + 'Token expired', | |
| 1292 | + 'bit-form' | |
| 1293 | + ), | |
| 1294 | + 401 | |
| 1295 | + ); | |
| 1296 | + } | |
| 1297 | + } | |
| 1298 | + | |
| 1299 | + public function deleteBlukForm() | |
| 1300 | + { | |
| 1301 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1302 | + $this->verifyAdminPermission(); | |
| 1303 | + GlobalHelper::requirePostMethod(); | |
| 1304 | + try { | |
| 1305 | + $input = GlobalHelper::formatRequestData(); | |
| 1306 | + } catch (\InvalidArgumentException $e) { | |
| 1307 | + wp_send_json_error($e->getMessage(), 400); | |
| 1308 | + } | |
| 1309 | + $formHandler = FormHandler::getInstance(); | |
| 1310 | + $sanitized_request = [ | |
| 1311 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1312 | + 'entries' => isset($_REQUEST['entries']) && is_array($_REQUEST['entries']) | |
| 1313 | + ? array_map('absint', $_REQUEST['entries']) | |
| 1314 | + : [], | |
| 1315 | + ]; | |
| 1316 | + $status = $formHandler->admin->deleteBlukForm($sanitized_request, $input); | |
| 1317 | + if (is_wp_error($status)) { | |
| 1318 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1319 | + } else { | |
| 1320 | + wp_send_json_success($status, 200); | |
| 1321 | + } | |
| 1322 | + } else { | |
| 1323 | + wp_send_json_error( | |
| 1324 | + __( | |
| 1325 | + 'Token expired', | |
| 1326 | + 'bit-form' | |
| 1327 | + ), | |
| 1328 | + 401 | |
| 1329 | + ); | |
| 1330 | + } | |
| 1331 | + } | |
| 1332 | + | |
| 1333 | + public function deleteBlukFormEntries() | |
| 1334 | + { | |
| 1335 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1336 | + $this->verifyAdminPermission(); | |
| 1337 | + GlobalHelper::requirePostMethod(); | |
| 1338 | + try { | |
| 1339 | + $input = GlobalHelper::formatRequestData(); | |
| 1340 | + } catch (\InvalidArgumentException $e) { | |
| 1341 | + wp_send_json_error($e->getMessage(), 400); | |
| 1342 | + } | |
| 1343 | + $formHandler = FormHandler::getInstance(); | |
| 1344 | + $sanitized_request = [ | |
| 1345 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1346 | + 'entries' => isset($_REQUEST['entries']) && is_array($_REQUEST['entries']) | |
| 1347 | + ? array_map('absint', $_REQUEST['entries']) | |
| 1348 | + : [], | |
| 1349 | + ]; | |
| 1350 | + $status = $formHandler->admin->deleteBlukFormEntries($sanitized_request, $input); | |
| 1351 | + if (is_wp_error($status)) { | |
| 1352 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1353 | + } else { | |
| 1354 | + wp_send_json_success($status, 200); | |
| 1355 | + } | |
| 1356 | + } else { | |
| 1357 | + wp_send_json_error( | |
| 1358 | + __( | |
| 1359 | + 'Token expired', | |
| 1360 | + 'bit-form' | |
| 1361 | + ), | |
| 1362 | + 401 | |
| 1363 | + ); | |
| 1364 | + } | |
| 1365 | + } | |
| 1366 | + | |
| 1367 | + public function duplicateFormEntry() | |
| 1368 | + { | |
| 1369 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1370 | + $this->verifyAdminPermission(); | |
| 1371 | + GlobalHelper::requirePostMethod(); | |
| 1372 | + try { | |
| 1373 | + $input = GlobalHelper::formatRequestData(); | |
| 1374 | + } catch (\InvalidArgumentException $e) { | |
| 1375 | + wp_send_json_error($e->getMessage(), 400); | |
| 1376 | + } | |
| 1377 | + $formHandler = FormHandler::getInstance(); | |
| 1378 | + $sanitized_request = [ | |
| 1379 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1380 | + 'entries' => isset($_REQUEST['entries']) && is_array($_REQUEST['entries']) | |
| 1381 | + ? array_map('absint', $_REQUEST['entries']) | |
| 1382 | + : [], | |
| 1383 | + ]; | |
| 1384 | + $status = $formHandler->admin->duplicateFormEntry($sanitized_request, $input); | |
| 1385 | + if (is_wp_error($status)) { | |
| 1386 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1387 | + } else { | |
| 1388 | + wp_send_json_success($status, 200); | |
| 1389 | + } | |
| 1390 | + } else { | |
| 1391 | + wp_send_json_error( | |
| 1392 | + __( | |
| 1393 | + 'Token expired', | |
| 1394 | + 'bit-form' | |
| 1395 | + ), | |
| 1396 | + 401 | |
| 1397 | + ); | |
| 1398 | + } | |
| 1399 | + } | |
| 1400 | + | |
| 1401 | + public function editFormEntry() | |
| 1402 | + { | |
| 1403 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1404 | + $this->verifyAdminPermission(); | |
| 1405 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1406 | + // $input = json_decode($inputJSON); | |
| 1407 | + GlobalHelper::requirePostMethod(); | |
| 1408 | + try { | |
| 1409 | + $input = GlobalHelper::formatRequestData(); | |
| 1410 | + } catch (\InvalidArgumentException $e) { | |
| 1411 | + wp_send_json_error($e->getMessage(), 400); | |
| 1412 | + } | |
| 1413 | + $formHandler = FormHandler::getInstance(); | |
| 1414 | + $sanitized_request = [ | |
| 1415 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1416 | + 'entryID' => isset($_REQUEST['entryID']) ? absint($_REQUEST['entryID']) : 0, | |
| 1417 | + ]; | |
| 1418 | + $status = $formHandler->admin->editFormEntry($sanitized_request, $input); | |
| 1419 | + if (is_wp_error($status)) { | |
| 1420 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1421 | + } else { | |
| 1422 | + wp_send_json_success($status, 200); | |
| 1423 | + } | |
| 1424 | + } else { | |
| 1425 | + wp_send_json_error( | |
| 1426 | + __( | |
| 1427 | + 'Token expired', | |
| 1428 | + 'bit-form' | |
| 1429 | + ), | |
| 1430 | + 401 | |
| 1431 | + ); | |
| 1432 | + } | |
| 1433 | + } | |
| 1434 | + | |
| 1435 | + public function getLogHistory() | |
| 1436 | + { | |
| 1437 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1438 | + $this->verifyAdminPermission(); | |
| 1439 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1440 | + // $input = json_decode($inputJSON); | |
| 1441 | + | |
| 1442 | + GlobalHelper::requirePostMethod(); | |
| 1443 | + try { | |
| 1444 | + $input = GlobalHelper::formatRequestData(); | |
| 1445 | + } catch (\InvalidArgumentException $e) { | |
| 1446 | + wp_send_json_error($e->getMessage(), 400); | |
| 1447 | + } | |
| 1448 | + | |
| 1449 | + $formHandler = FormHandler::getInstance(); | |
| 1450 | + $sanitized_request = [ | |
| 1451 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1452 | + 'entryID' => isset($_REQUEST['entryID']) ? absint($_REQUEST['entryID']) : 0, | |
| 1453 | + ]; | |
| 1454 | + $status = $formHandler->admin->getLogHistory($sanitized_request, $input); | |
| 1455 | + if (is_wp_error($status)) { | |
| 1456 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1457 | + } else { | |
| 1458 | + wp_send_json_success($status, 200); | |
| 1459 | + } | |
| 1460 | + } else { | |
| 1461 | + wp_send_json_error( | |
| 1462 | + __( | |
| 1463 | + 'Token expired', | |
| 1464 | + 'bit-form' | |
| 1465 | + ), | |
| 1466 | + 401 | |
| 1467 | + ); | |
| 1468 | + } | |
| 1469 | + } | |
| 1470 | + | |
| 1471 | + public function updateFormEntry() | |
| 1472 | + { | |
| 1473 | + Utilities::ignoreUserAbort(); | |
| 1474 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1475 | + $this->verifyAdminPermission(); | |
| 1476 | + $formHandler = FormHandler::getInstance(); | |
| 1477 | + $sanitized_request = [ | |
| 1478 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1479 | + 'entryID' => isset($_REQUEST['entryID']) ? absint($_REQUEST['entryID']) : 0, | |
| 1480 | + ]; | |
| 1481 | + $status = $formHandler->admin->updateFormEntry($sanitized_request, wp_unslash($_POST)); | |
| 1482 | + | |
| 1483 | + if (is_wp_error($status)) { | |
| 1484 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1485 | + } else { | |
| 1486 | + $status = IntegrationHandler::maybeSetCronForIntegration($status, 'update'); | |
| 1487 | + wp_send_json_success($status, 200); | |
| 1488 | + } | |
| 1489 | + } else { | |
| 1490 | + wp_send_json_error( | |
| 1491 | + __( | |
| 1492 | + 'Token expired', | |
| 1493 | + 'bit-form' | |
| 1494 | + ), | |
| 1495 | + 401 | |
| 1496 | + ); | |
| 1497 | + } | |
| 1498 | + } | |
| 1499 | + | |
| 1500 | + public function getAllWPPages() | |
| 1501 | + { | |
| 1502 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1503 | + $this->verifyAdminPermission(); | |
| 1504 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1505 | + // $input = json_decode($inputJSON); | |
| 1506 | + | |
| 1507 | + GlobalHelper::requirePostMethod(); | |
| 1508 | + try { | |
| 1509 | + $input = GlobalHelper::formatRequestData(); | |
| 1510 | + } catch (\InvalidArgumentException $e) { | |
| 1511 | + wp_send_json_error($e->getMessage(), 400); | |
| 1512 | + } | |
| 1513 | + | |
| 1514 | + $formHandler = FormHandler::getInstance(); | |
| 1515 | + $sanitized_request = [ | |
| 1516 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1517 | + ]; | |
| 1518 | + $status = $formHandler->admin->getAllWPPages($sanitized_request, $input); | |
| 1519 | + if (is_wp_error($status)) { | |
| 1520 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1521 | + } else { | |
| 1522 | + wp_send_json_success($status, 200); | |
| 1523 | + } | |
| 1524 | + } else { | |
| 1525 | + wp_send_json_error( | |
| 1526 | + __( | |
| 1527 | + 'Token expired', | |
| 1528 | + 'bit-form' | |
| 1529 | + ), | |
| 1530 | + 401 | |
| 1531 | + ); | |
| 1532 | + } | |
| 1533 | + } | |
| 1534 | + | |
| 1535 | + public function deleteSuccessMessage() | |
| 1536 | + { | |
| 1537 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1538 | + $this->verifyAdminPermission(); | |
| 1539 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1540 | + // $input = json_decode($inputJSON); | |
| 1541 | + GlobalHelper::requirePostMethod(); | |
| 1542 | + try { | |
| 1543 | + $input = GlobalHelper::formatRequestData(); | |
| 1544 | + } catch (\InvalidArgumentException $e) { | |
| 1545 | + wp_send_json_error($e->getMessage(), 400); | |
| 1546 | + } | |
| 1547 | + $formHandler = FormHandler::getInstance(); | |
| 1548 | + $sanitized_request = [ | |
| 1549 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1550 | + 'id' => isset($_REQUEST['id']) ? absint($_REQUEST['id']) : 0, | |
| 1551 | + ]; | |
| 1552 | + $status = $formHandler->admin->deleteSuccessMessage($sanitized_request, $input); | |
| 1553 | + if (is_wp_error($status)) { | |
| 1554 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1555 | + } else { | |
| 1556 | + wp_send_json_success($status, 200); | |
| 1557 | + } | |
| 1558 | + } else { | |
| 1559 | + wp_send_json_error( | |
| 1560 | + __( | |
| 1561 | + 'Token expired', | |
| 1562 | + 'bit-form' | |
| 1563 | + ), | |
| 1564 | + 401 | |
| 1565 | + ); | |
| 1566 | + } | |
| 1567 | + } | |
| 1568 | + | |
| 1569 | + public function deleteAIntegration() | |
| 1570 | + { | |
| 1571 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1572 | + $this->verifyAdminPermission(); | |
| 1573 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1574 | + // $input = json_decode($inputJSON); | |
| 1575 | + | |
| 1576 | + GlobalHelper::requirePostMethod(); | |
| 1577 | + try { | |
| 1578 | + $input = GlobalHelper::formatRequestData(); | |
| 1579 | + } catch (\InvalidArgumentException $e) { | |
| 1580 | + wp_send_json_error($e->getMessage(), 400); | |
| 1581 | + } | |
| 1582 | + | |
| 1583 | + $formHandler = FormHandler::getInstance(); | |
| 1584 | + $sanitized_request = [ | |
| 1585 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1586 | + 'id' => isset($_REQUEST['id']) ? absint($_REQUEST['id']) : 0, | |
| 1587 | + ]; | |
| 1588 | + $status = $formHandler->admin->deleteAIntegration($sanitized_request, $input); | |
| 1589 | + if (is_wp_error($status)) { | |
| 1590 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1591 | + } else { | |
| 1592 | + wp_send_json_success($status, 200); | |
| 1593 | + } | |
| 1594 | + } else { | |
| 1595 | + wp_send_json_error( | |
| 1596 | + __( | |
| 1597 | + 'Token expired', | |
| 1598 | + 'bit-form' | |
| 1599 | + ), | |
| 1600 | + 401 | |
| 1601 | + ); | |
| 1602 | + } | |
| 1603 | + } | |
| 1604 | + | |
| 1605 | + public function updateIntegrationStatus() | |
| 1606 | + { | |
| 1607 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1608 | + $this->verifyAdminPermission(); | |
| 1609 | + GlobalHelper::requirePostMethod(); | |
| 1610 | + try { | |
| 1611 | + $input = GlobalHelper::formatRequestData(); | |
| 1612 | + } catch (\InvalidArgumentException $e) { | |
| 1613 | + wp_send_json_error($e->getMessage(), 400); | |
| 1614 | + } | |
| 1615 | + $formID = isset($input->formID) ? sanitize_text_field(wp_unslash($input->formID)) : ''; | |
| 1616 | + $integrationID = isset($input->id) ? absint($input->id) : 0; | |
| 1617 | + $status = isset($input->status) ? absint($input->status) : 0; | |
| 1618 | + if (empty($formID) || empty($integrationID)) { | |
| 1619 | + wp_send_json_error(__('Invalid request', 'bit-form'), 400); | |
| 1620 | + } | |
| 1621 | + $integrationHandler = new IntegrationHandler($formID); | |
| 1622 | + $result = $integrationHandler->updateIntegrationStatus($integrationID, $status); | |
| 1623 | + if (is_wp_error($result) && 'result_empty' !== $result->get_error_code()) { | |
| 1624 | + wp_send_json_error($result->get_error_message(), 411); | |
| 1625 | + } else { | |
| 1626 | + wp_send_json_success(['id' => $integrationID, 'status' => $status], 200); | |
| 1627 | + } | |
| 1628 | + } else { | |
| 1629 | + wp_send_json_error(__('Token expired', 'bit-form'), 401); | |
| 1630 | + } | |
| 1631 | + } | |
| 1632 | + | |
| 1633 | + public function deleteAWorkflow() | |
| 1634 | + { | |
| 1635 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1636 | + $this->verifyAdminPermission(); | |
| 1637 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1638 | + // $input = json_decode($inputJSON); | |
| 1639 | + GlobalHelper::requirePostMethod(); | |
| 1640 | + | |
| 1641 | + try { | |
| 1642 | + $input = GlobalHelper::formatRequestData(); | |
| 1643 | + } catch (\InvalidArgumentException $e) { | |
| 1644 | + wp_send_json_error($e->getMessage(), 400); | |
| 1645 | + } | |
| 1646 | + | |
| 1647 | + $formHandler = FormHandler::getInstance(); | |
| 1648 | + $sanitized_request = [ | |
| 1649 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1650 | + 'id' => isset($_REQUEST['id']) ? absint($_REQUEST['id']) : 0, | |
| 1651 | + ]; | |
| 1652 | + $status = $formHandler->admin->deleteAWorkflow($sanitized_request, $input); | |
| 1653 | + if (is_wp_error($status)) { | |
| 1654 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1655 | + } else { | |
| 1656 | + wp_send_json_success($status, 200); | |
| 1657 | + } | |
| 1658 | + } else { | |
| 1659 | + wp_send_json_error( | |
| 1660 | + __( | |
| 1661 | + 'Token expired', | |
| 1662 | + 'bit-form' | |
| 1663 | + ), | |
| 1664 | + 401 | |
| 1665 | + ); | |
| 1666 | + } | |
| 1667 | + } | |
| 1668 | + | |
| 1669 | + public function deleteAMailTemplate() | |
| 1670 | + { | |
| 1671 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1672 | + $this->verifyAdminPermission(); | |
| 1673 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1674 | + // $input = json_decode($inputJSON); | |
| 1675 | + GlobalHelper::requirePostMethod(); | |
| 1676 | + | |
| 1677 | + try { | |
| 1678 | + $input = GlobalHelper::formatRequestData(); | |
| 1679 | + } catch (\InvalidArgumentException $e) { | |
| 1680 | + wp_send_json_error($e->getMessage(), 400); | |
| 1681 | + } | |
| 1682 | + | |
| 1683 | + $formHandler = FormHandler::getInstance(); | |
| 1684 | + $sanitized_request = [ | |
| 1685 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1686 | + 'id' => isset($_REQUEST['id']) ? absint($_REQUEST['id']) : 0, | |
| 1687 | + ]; | |
| 1688 | + $status = $formHandler->admin->deleteAMailTemplate($sanitized_request, $input); | |
| 1689 | + if (is_wp_error($status)) { | |
| 1690 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1691 | + } else { | |
| 1692 | + wp_send_json_success($status, 200); | |
| 1693 | + } | |
| 1694 | + } else { | |
| 1695 | + wp_send_json_error( | |
| 1696 | + __( | |
| 1697 | + 'Token expired', | |
| 1698 | + 'bit-form' | |
| 1699 | + ), | |
| 1700 | + 401 | |
| 1701 | + ); | |
| 1702 | + } | |
| 1703 | + } | |
| 1704 | + | |
| 1705 | + public function duplicateAMailTemplate() | |
| 1706 | + { | |
| 1707 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1708 | + $this->verifyAdminPermission(); | |
| 1709 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1710 | + // $input = json_decode($inputJSON); | |
| 1711 | + | |
| 1712 | + GlobalHelper::requirePostMethod(); | |
| 1713 | + try { | |
| 1714 | + $input = GlobalHelper::formatRequestData(); | |
| 1715 | + } catch (\InvalidArgumentException $e) { | |
| 1716 | + wp_send_json_error($e->getMessage(), 400); | |
| 1717 | + } | |
| 1718 | + $formHandler = FormHandler::getInstance(); | |
| 1719 | + $sanitized_request = [ | |
| 1720 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1721 | + 'id' => isset($_REQUEST['id']) ? absint($_REQUEST['id']) : 0, | |
| 1722 | + ]; | |
| 1723 | + $status = $formHandler->admin->duplicateAMailTemplate($sanitized_request, $input); | |
| 1724 | + if (is_wp_error($status)) { | |
| 1725 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1726 | + } else { | |
| 1727 | + wp_send_json_success($status, 200); | |
| 1728 | + } | |
| 1729 | + } else { | |
| 1730 | + wp_send_json_error( | |
| 1731 | + __( | |
| 1732 | + 'Token expired', | |
| 1733 | + 'bit-form' | |
| 1734 | + ), | |
| 1735 | + 401 | |
| 1736 | + ); | |
| 1737 | + } | |
| 1738 | + } | |
| 1739 | + | |
| 1740 | + public function setAllFormsReport() | |
| 1741 | + { | |
| 1742 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1743 | + $this->verifyAdminPermission(); | |
| 1744 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1745 | + // $input = json_decode($inputJSON); | |
| 1746 | + | |
| 1747 | + GlobalHelper::requirePostMethod(); | |
| 1748 | + | |
| 1749 | + try { | |
| 1750 | + $input = GlobalHelper::formatRequestData(); | |
| 1751 | + } catch (\InvalidArgumentException $e) { | |
| 1752 | + wp_send_json_error($e->getMessage(), 400); | |
| 1753 | + } | |
| 1754 | + | |
| 1755 | + $formHandler = FormHandler::getInstance(); | |
| 1756 | + $sanitized_request = [ | |
| 1757 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1758 | + ]; | |
| 1759 | + $status = $formHandler->admin->setAllFormsReport($sanitized_request, $input); | |
| 1760 | + if (is_wp_error($status)) { | |
| 1761 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1762 | + } else { | |
| 1763 | + wp_send_json_success($status, 200); | |
| 1764 | + } | |
| 1765 | + } else { | |
| 1766 | + wp_send_json_error( | |
| 1767 | + __( | |
| 1768 | + 'Token expired', | |
| 1769 | + 'bit-form' | |
| 1770 | + ), | |
| 1771 | + 401 | |
| 1772 | + ); | |
| 1773 | + } | |
| 1774 | + } | |
| 1775 | + | |
| 1776 | + public function savegReCaptcha() | |
| 1777 | + { | |
| 1778 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1779 | + $this->verifyAdminPermission(); | |
| 1780 | + GlobalHelper::requirePostMethod(); | |
| 1781 | + | |
| 1782 | + try { | |
| 1783 | + $input = GlobalHelper::formatRequestData(); | |
| 1784 | + } catch (\InvalidArgumentException $e) { | |
| 1785 | + wp_send_json_error($e->getMessage(), 400); | |
| 1786 | + } | |
| 1787 | + | |
| 1788 | + $formHandler = FormHandler::getInstance(); | |
| 1789 | + $sanitized_request = [ | |
| 1790 | + 'formID' => isset($_REQUEST['formID']) ? sanitize_text_field(wp_unslash($_REQUEST['formID'])) : '', | |
| 1791 | + ]; | |
| 1792 | + $status = $formHandler->admin->savegReCaptcha($sanitized_request, $input); | |
| 1793 | + if (is_wp_error($status)) { | |
| 1794 | + wp_send_json_error($status->get_error_message(), 411); | |
| 1795 | + } else { | |
| 1796 | + wp_send_json_success($status, 200); | |
| 1797 | + } | |
| 1798 | + } else { | |
| 1799 | + wp_send_json_error( | |
| 1800 | + __( | |
| 1801 | + 'Token expired', | |
| 1802 | + 'bit-form' | |
| 1803 | + ), | |
| 1804 | + 401 | |
| 1805 | + ); | |
| 1806 | + } | |
| 1807 | + } | |
| 1808 | + | |
| 1809 | + public function saveApiKey() | |
| 1810 | + { | |
| 1811 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1812 | + $this->verifyAdminPermission(); | |
| 1813 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1814 | + // $input = json_decode($inputJSON); | |
| 1815 | + | |
| 1816 | + GlobalHelper::requirePostMethod(); | |
| 1817 | + try { | |
| 1818 | + $input = GlobalHelper::formatRequestData(); | |
| 1819 | + } catch (\InvalidArgumentException $e) { | |
| 1820 | + wp_send_json_error($e->getMessage(), 400); | |
| 1821 | + } | |
| 1822 | + | |
| 1823 | + if (empty($input->api_key)) { | |
| 1824 | + $api_key = get_option('bitform_secret_api_key'); | |
| 1825 | + } elseif (!empty($input->api_key)) { | |
| 1826 | + update_option('bitform_secret_api_key', sanitize_text_field($input->api_key)); | |
| 1827 | + $api_key = $input->api_key; | |
| 1828 | + } | |
| 1829 | + if (!$api_key) { | |
| 1830 | + // The generated key authenticates the whole bitform/v1 data API. It was | |
| 1831 | + // previously a constant (sha1 of a fixed string), so every install that | |
| 1832 | + // never set one explicitly shared the same secret. Existing stored keys | |
| 1833 | + // are left untouched — only first-time generation changes. | |
| 1834 | + $api_key = wp_generate_password(64, false, false); | |
| 1835 | + update_option('bitform_secret_api_key', $api_key); | |
| 1836 | + } | |
| 1837 | + wp_send_json_success($api_key, 200); | |
| 1838 | + } else { | |
| 1839 | + wp_send_json_error( | |
| 1840 | + __( | |
| 1841 | + 'Token expired', | |
| 1842 | + 'bit-form' | |
| 1843 | + ), | |
| 1844 | + 401 | |
| 1845 | + ); | |
| 1846 | + } | |
| 1847 | + } | |
| 1848 | + | |
| 1849 | + private function checkExtensionWithURL($urlStr) | |
| 1850 | + { | |
| 1851 | + // Extension is mandatory (no optional group): the URL must end in a known image extension, | |
| 1852 | + // otherwise any http(s) URL would pass and be fetched. | |
| 1853 | + $pattern = '/^https?:\/\/.*\.(svg|png|jpg|jpeg|gif)$/i'; | |
| 1854 | + | |
| 1855 | + return preg_match($pattern, $urlStr); | |
| 1856 | + } | |
| 1857 | + | |
| 1858 | + public function iconUpload() | |
| 1859 | + { | |
| 1860 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1861 | + $this->verifyAdminPermission(); | |
| 1862 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1863 | + // $input = json_decode($inputJSON); | |
| 1864 | + | |
| 1865 | + GlobalHelper::requirePostMethod(); | |
| 1866 | + try { | |
| 1867 | + $input = GlobalHelper::formatRequestData(); | |
| 1868 | + } catch (\InvalidArgumentException $e) { | |
| 1869 | + wp_send_json_error($e->getMessage(), 400); | |
| 1870 | + } | |
| 1871 | + | |
| 1872 | + $sanitize_url = sanitize_url($input->src); | |
| 1873 | + | |
| 1874 | + if (!$this->checkExtensionWithURL($sanitize_url)) { | |
| 1875 | + return new WP_Error( | |
| 1876 | + 'type_error', | |
| 1877 | + __('Invalid file type', 'bit-form') | |
| 1878 | + ); | |
| 1879 | + } | |
| 1880 | + | |
| 1881 | + $uploadDirInfo = wp_upload_dir(); | |
| 1882 | + $wpUploadbaseDir = $uploadDirInfo['basedir']; | |
| 1883 | + $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons'; | |
| 1884 | + | |
| 1885 | + if (!is_dir($icnDir)) { | |
| 1886 | + wp_mkdir_p($icnDir); | |
| 1887 | + } | |
| 1888 | + | |
| 1889 | + $response = wp_safe_remote_get($sanitize_url); | |
| 1890 | + if (is_wp_error($response) || 200 !== (int) wp_remote_retrieve_response_code($response)) { | |
| 1891 | + wp_send_json_error(__('Unable to fetch icon', 'bit-form'), 400); | |
| 1892 | + } | |
| 1893 | + $imageUrlData = wp_remote_retrieve_body($response); | |
| 1894 | + | |
| 1895 | + $filename = sanitize_file_name($input->id . '-' . basename($sanitize_url)); | |
| 1896 | + | |
| 1897 | + $validation = wp_check_filetype($filename); | |
| 1898 | + $type = $validation['type']; | |
| 1899 | + $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); | |
| 1900 | + $is_svg = 'svg' === $ext; // Check if the file is an SVG | |
| 1901 | + if ($type && 0 === strpos($type, 'image/') || $is_svg) { | |
| 1902 | + if ($is_svg) { | |
| 1903 | + $imageUrlData = (new \BitCode\BitForm\enshrined\svgSanitize\Sanitizer())->sanitize($imageUrlData); | |
| 1904 | + if (false === $imageUrlData) { | |
| 1905 | + wp_send_json_error(__('Invalid file type', 'bit-form'), 400); | |
| 1906 | + } | |
| 317 | 1907 | } |
| 318 | - } | |
| 1908 | + $uploaded = file_put_contents($icnDir . '/' . $filename, $imageUrlData); | |
| 319 | 1909 | |
| 320 | - public function getAForm() | |
| 321 | - { | |
| 322 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 323 | - $inputJSON = file_get_contents('php://input'); | |
| 324 | - $input = json_decode($inputJSON); | |
| 325 | - $formHandler = FormHandler::getInstance(); | |
| 326 | - $status = $formHandler->admin->getAForm($_REQUEST, $input); | |
| 327 | - if (is_wp_error($status)) { | |
| 328 | - wp_send_json_error($status->get_error_message(), 411); | |
| 329 | - } else { | |
| 330 | - wp_send_json_success($status, 200); | |
| 331 | - } | |
| 332 | - } else { | |
| 333 | - wp_send_json_error( | |
| 334 | - __( | |
| 335 | - 'Token expired', | |
| 336 | - 'bitform' | |
| 337 | - ), | |
| 338 | - 401 | |
| 339 | - ); | |
| 1910 | + if ($uploaded) { | |
| 1911 | + $uploadedFile = BITFORMS_UPLOAD_BASE_URL . '/' . 'icons' . '/' . $filename; | |
| 1912 | + wp_send_json_success($uploadedFile, 200); | |
| 340 | 1913 | } |
| 1914 | + } else { | |
| 1915 | + wp_send_json_error( | |
| 1916 | + __( | |
| 1917 | + 'Invalid file type', | |
| 1918 | + 'bit-form' | |
| 1919 | + ), | |
| 1920 | + 401 | |
| 1921 | + ); | |
| 1922 | + } | |
| 1923 | + } else { | |
| 1924 | + wp_send_json_error( | |
| 1925 | + __( | |
| 1926 | + 'Token expired', | |
| 1927 | + 'bit-form' | |
| 1928 | + ), | |
| 1929 | + 401 | |
| 1930 | + ); | |
| 341 | 1931 | } |
| 342 | - public function duplicateAForm() | |
| 343 | - { | |
| 344 | - \ignore_user_abort(); | |
| 345 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 346 | - $inputJSON = file_get_contents('php://input'); | |
| 347 | - $input = json_decode($inputJSON); | |
| 348 | - $formHandler = FormHandler::getInstance(); | |
| 349 | - $status = $formHandler->admin->duplicateAForm($_REQUEST, $input); | |
| 350 | - if (is_wp_error($status)) { | |
| 351 | - wp_send_json_error($status->get_error_message(), 411); | |
| 352 | - } else { | |
| 353 | - wp_send_json_success($status, 200); | |
| 354 | - } | |
| 355 | - } else { | |
| 356 | - wp_send_json_error( | |
| 357 | - __( | |
| 358 | - 'Token expired', | |
| 359 | - 'bitform' | |
| 360 | - ), | |
| 361 | - 401 | |
| 362 | - ); | |
| 1932 | + } | |
| 1933 | + | |
| 1934 | + private function getFiles() | |
| 1935 | + { | |
| 1936 | + $uploadDirInfo = wp_upload_dir(); | |
| 1937 | + $wpUploadbaseDir = $uploadDirInfo['basedir']; | |
| 1938 | + $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons'; | |
| 1939 | + $files = []; | |
| 1940 | + if (file_exists($icnDir)) { | |
| 1941 | + $openDir = opendir($icnDir . DIRECTORY_SEPARATOR); | |
| 1942 | + | |
| 1943 | + while (false !== ($fileName = readdir($openDir))) { | |
| 1944 | + $ext = substr($fileName, strrpos($fileName, '.') + 1); | |
| 1945 | + if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'svg'])) { | |
| 1946 | + $files[] = $fileName; | |
| 363 | 1947 | } |
| 1948 | + } | |
| 1949 | + | |
| 1950 | + closedir($openDir); | |
| 364 | 1951 | } |
| 365 | - public function importAForm() | |
| 366 | - { | |
| 367 | - \ignore_user_abort(); | |
| 368 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 369 | - $inputJSON = file_get_contents('php://input'); | |
| 370 | - $input = json_decode($inputJSON); | |
| 371 | - $formHandler = FormHandler::getInstance(); | |
| 372 | - $status = $formHandler->admin->importAForm($input); | |
| 373 | - if (is_wp_error($status)) { | |
| 374 | - wp_send_json_error($status->get_error_message(), 411); | |
| 375 | - } else { | |
| 376 | - wp_send_json_success($status, 200); | |
| 377 | - } | |
| 378 | - } else { | |
| 379 | - wp_send_json_error( | |
| 380 | - __( | |
| 381 | - 'Token expired', | |
| 382 | - 'bitform' | |
| 383 | - ), | |
| 384 | - 401 | |
| 385 | - ); | |
| 386 | - } | |
| 1952 | + return $files; | |
| 1953 | + } | |
| 1954 | + | |
| 1955 | + public function getDownlodedIcons() | |
| 1956 | + { | |
| 1957 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1958 | + $this->verifyAdminPermission(); | |
| 1959 | + $files = $this->getFiles(); | |
| 1960 | + wp_send_json_success($files, 200); | |
| 1961 | + } else { | |
| 1962 | + wp_send_json_error( | |
| 1963 | + __( | |
| 1964 | + 'Token expired', | |
| 1965 | + 'bit-form' | |
| 1966 | + ), | |
| 1967 | + 401 | |
| 1968 | + ); | |
| 387 | 1969 | } |
| 388 | - public function exportAForm() | |
| 389 | - { | |
| 390 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 391 | - $formHandler = FormHandler::getInstance(); | |
| 392 | - $status = $formHandler->admin->exportAForm($_REQUEST); | |
| 393 | - if (is_wp_error($status)) { | |
| 394 | - wp_send_json_error($status->get_error_message(), 411); | |
| 395 | - } | |
| 396 | - } else { | |
| 397 | - wp_send_json_error( | |
| 398 | - __( | |
| 399 | - 'Token expired', | |
| 400 | - 'bitform' | |
| 401 | - ), | |
| 402 | - 401 | |
| 403 | - ); | |
| 404 | - } | |
| 1970 | + } | |
| 1971 | + | |
| 1972 | + public function iconRemove() | |
| 1973 | + { | |
| 1974 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 1975 | + $this->verifyAdminPermission(); | |
| 1976 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 1977 | + // $input = json_decode($inputJSON); | |
| 1978 | + | |
| 1979 | + GlobalHelper::requirePostMethod(); | |
| 1980 | + | |
| 1981 | + try { | |
| 1982 | + $input = GlobalHelper::formatRequestData(); | |
| 1983 | + } catch (\InvalidArgumentException $e) { | |
| 1984 | + wp_send_json_error($e->getMessage(), 400); | |
| 1985 | + } | |
| 1986 | + | |
| 1987 | + $uploadDirInfo = wp_upload_dir(); | |
| 1988 | + | |
| 1989 | + $wpUploadbaseDir = $uploadDirInfo['basedir']; | |
| 1990 | + $icnDir = $wpUploadbaseDir . DIRECTORY_SEPARATOR . 'bitforms' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR; | |
| 1991 | + $sanitizeFileName = sanitize_file_name($input->file); | |
| 1992 | + $filePath = $icnDir . $sanitizeFileName; | |
| 1993 | + if (file_exists($filePath)) { | |
| 1994 | + wp_delete_file($filePath); | |
| 1995 | + wp_send_json_success($this->getFiles(), 200); | |
| 1996 | + } | |
| 1997 | + } else { | |
| 1998 | + wp_send_json_error( | |
| 1999 | + __( | |
| 2000 | + 'Token expired', | |
| 2001 | + 'bit-form' | |
| 2002 | + ), | |
| 2003 | + 401 | |
| 2004 | + ); | |
| 405 | 2005 | } |
| 406 | - public function deleteAForm() | |
| 407 | - { | |
| 408 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 409 | - $inputJSON = file_get_contents('php://input'); | |
| 410 | - $input = json_decode($inputJSON); | |
| 411 | - $formHandler = FormHandler::getInstance(); | |
| 412 | - $status = $formHandler->admin->deleteAForm($_REQUEST, $input); | |
| 413 | - if (is_wp_error($status)) { | |
| 414 | - wp_send_json_error($status->get_error_message(), 411); | |
| 415 | - } else { | |
| 416 | - wp_send_json_success($status, 200); | |
| 417 | - } | |
| 2006 | + } | |
| 2007 | + | |
| 2008 | + public function addCustomCode() | |
| 2009 | + { | |
| 2010 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2011 | + $this->verifyAdminPermission(); | |
| 2012 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 2013 | + // $input = json_decode($inputJSON); | |
| 2014 | + | |
| 2015 | + GlobalHelper::requirePostMethod(); | |
| 2016 | + | |
| 2017 | + try { | |
| 2018 | + $input = GlobalHelper::formatRequestData(); | |
| 2019 | + } catch (\InvalidArgumentException $e) { | |
| 2020 | + wp_send_json_error($e->getMessage(), 400); | |
| 2021 | + } | |
| 2022 | + | |
| 2023 | + $formId = sanitize_text_field($input->form_id); | |
| 2024 | + if (filter_var($formId, FILTER_VALIDATE_INT)) { | |
| 2025 | + FrontEndScriptGenerator::customCodeFile($formId, $input->customCodes); | |
| 2026 | + $status = ['message' => 'File Update Successfully..']; | |
| 2027 | + if (is_wp_error($status)) { | |
| 2028 | + wp_send_json_error($status->get_error_message(), 411); | |
| 418 | 2029 | } else { |
| 419 | - wp_send_json_error( | |
| 420 | - __( | |
| 421 | - 'Token expired', | |
| 422 | - 'bitform' | |
| 423 | - ), | |
| 424 | - 401 | |
| 425 | - ); | |
| 2030 | + wp_send_json_success($status, 200); | |
| 426 | 2031 | } |
| 2032 | + } else { | |
| 2033 | + wp_send_json_error( | |
| 2034 | + __( | |
| 2035 | + 'Invalid form id', | |
| 2036 | + 'bit-form' | |
| 2037 | + ), | |
| 2038 | + 401 | |
| 2039 | + ); | |
| 2040 | + } | |
| 2041 | + } else { | |
| 2042 | + wp_send_json_error( | |
| 2043 | + __( | |
| 2044 | + 'Token expired', | |
| 2045 | + 'bit-form' | |
| 2046 | + ), | |
| 2047 | + 401 | |
| 2048 | + ); | |
| 427 | 2049 | } |
| 428 | - public function deleteBlukForm() | |
| 429 | - { | |
| 430 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 431 | - $inputJSON = file_get_contents('php://input'); | |
| 432 | - $input = json_decode($inputJSON); | |
| 433 | - $formHandler = FormHandler::getInstance(); | |
| 434 | - $status = $formHandler->admin->deleteBlukForm($_REQUEST, $input); | |
| 435 | - if (is_wp_error($status)) { | |
| 436 | - wp_send_json_error($status->get_error_message(), 411); | |
| 437 | - } else { | |
| 438 | - wp_send_json_success($status, 200); | |
| 439 | - } | |
| 2050 | + } | |
| 2051 | + | |
| 2052 | + public function getCustomCode() | |
| 2053 | + { | |
| 2054 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2055 | + $this->verifyAdminPermission(); | |
| 2056 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 2057 | + // $input = json_decode($inputJSON); | |
| 2058 | + | |
| 2059 | + GlobalHelper::requirePostMethod(); | |
| 2060 | + | |
| 2061 | + try { | |
| 2062 | + $input = GlobalHelper::formatRequestData(); | |
| 2063 | + } catch (\InvalidArgumentException $e) { | |
| 2064 | + wp_send_json_error($e->getMessage(), 400); | |
| 2065 | + } | |
| 2066 | + | |
| 2067 | + $formId = sanitize_text_field($input->form_id); | |
| 2068 | + | |
| 2069 | + if (filter_var($formId, FILTER_VALIDATE_INT)) { | |
| 2070 | + $status = FrontEndScriptGenerator::getCustomCodes($formId); | |
| 2071 | + if (is_wp_error($status)) { | |
| 2072 | + wp_send_json_error($status->get_error_message(), 411); | |
| 440 | 2073 | } else { |
| 441 | - wp_send_json_error( | |
| 442 | - __( | |
| 443 | - 'Token expired', | |
| 444 | - 'bitform' | |
| 445 | - ), | |
| 446 | - 401 | |
| 447 | - ); | |
| 2074 | + wp_send_json_success($status, 200); | |
| 448 | 2075 | } |
| 2076 | + } else { | |
| 2077 | + wp_send_json_error( | |
| 2078 | + __( | |
| 2079 | + 'Invalid form id', | |
| 2080 | + 'bit-form' | |
| 2081 | + ), | |
| 2082 | + 401 | |
| 2083 | + ); | |
| 2084 | + } | |
| 2085 | + } else { | |
| 2086 | + wp_send_json_error( | |
| 2087 | + __( | |
| 2088 | + 'Token expired', | |
| 2089 | + 'bit-form' | |
| 2090 | + ), | |
| 2091 | + 401 | |
| 2092 | + ); | |
| 449 | 2093 | } |
| 450 | - public function deleteBlukFormEntries() | |
| 451 | - { | |
| 452 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 453 | - $inputJSON = file_get_contents('php://input'); | |
| 454 | - $input = json_decode($inputJSON); | |
| 455 | - $formHandler = FormHandler::getInstance(); | |
| 456 | - $status = $formHandler->admin->deleteBlukFormEntries($_REQUEST, $input); | |
| 457 | - if (is_wp_error($status)) { | |
| 458 | - wp_send_json_error($status->get_error_message(), 411); | |
| 459 | - } else { | |
| 460 | - wp_send_json_success($status, 200); | |
| 461 | - } | |
| 462 | - } else { | |
| 463 | - wp_send_json_error( | |
| 464 | - __( | |
| 465 | - 'Token expired', | |
| 466 | - 'bitform' | |
| 467 | - ), | |
| 468 | - 401 | |
| 469 | - ); | |
| 2094 | + } | |
| 2095 | + | |
| 2096 | + public function getGenerelSettings() | |
| 2097 | + { | |
| 2098 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2099 | + $this->verifyAdminPermission(); | |
| 2100 | + $data = get_option('bitform_app_config', (object) ['cache_plugin' => true, 'delete_table' => 0]); | |
| 2101 | + | |
| 2102 | + if (is_wp_error($data)) { | |
| 2103 | + wp_send_json_error($data->get_error_message(), 411); | |
| 2104 | + } else { | |
| 2105 | + if (empty($data)) { | |
| 2106 | + $data = (object)[]; | |
| 470 | 2107 | } |
| 2108 | + wp_send_json_success($data, 200); | |
| 2109 | + } | |
| 2110 | + } else { | |
| 2111 | + wp_send_json_error( | |
| 2112 | + __( | |
| 2113 | + 'Token expired', | |
| 2114 | + 'bit-form' | |
| 2115 | + ), | |
| 2116 | + 401 | |
| 2117 | + ); | |
| 471 | 2118 | } |
| 472 | - public function duplicateFormEntry() | |
| 473 | - { | |
| 474 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 475 | - $inputJSON = file_get_contents('php://input'); | |
| 476 | - $input = json_decode($inputJSON); | |
| 477 | - $formHandler = FormHandler::getInstance(); | |
| 478 | - $status = $formHandler->admin->duplicateFormEntry($_REQUEST, $input); | |
| 479 | - if (is_wp_error($status)) { | |
| 480 | - wp_send_json_error($status->get_error_message(), 411); | |
| 481 | - } else { | |
| 482 | - wp_send_json_success($status, 200); | |
| 483 | - } | |
| 484 | - } else { | |
| 485 | - wp_send_json_error( | |
| 486 | - __( | |
| 487 | - 'Token expired', | |
| 488 | - 'bitform' | |
| 489 | - ), | |
| 490 | - 401 | |
| 491 | - ); | |
| 2119 | + } | |
| 2120 | + | |
| 2121 | + public function saveGenerelSettings() | |
| 2122 | + { | |
| 2123 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2124 | + $this->verifyAdminPermission(); | |
| 2125 | + GlobalHelper::requirePostMethod(); | |
| 2126 | + | |
| 2127 | + try { | |
| 2128 | + $inputData = GlobalHelper::formatRequestData(); | |
| 2129 | + } catch (\InvalidArgumentException $e) { | |
| 2130 | + wp_send_json_error($e->getMessage(), 400); | |
| 2131 | + return; | |
| 2132 | + } | |
| 2133 | + | |
| 2134 | + $status = update_option('bitform_app_config', $inputData->config); | |
| 2135 | + if (is_wp_error($status)) { | |
| 2136 | + wp_send_json_error($status->get_error_message(), 411); | |
| 2137 | + } else { | |
| 2138 | + if (Helpers::property_exists_nested($inputData, 'config->cache_plugin', true)) { | |
| 2139 | + $formHandler = FormHandler::getInstance(); | |
| 2140 | + $formHandler->admin->updateGeneratedScriptPageIds(); | |
| 492 | 2141 | } |
| 2142 | + wp_send_json_success(__('Save successfully done', 'bit-form')); | |
| 2143 | + } | |
| 2144 | + } else { | |
| 2145 | + wp_send_json_error( | |
| 2146 | + __( | |
| 2147 | + 'Token expired', | |
| 2148 | + 'bit-form' | |
| 2149 | + ), | |
| 2150 | + 401 | |
| 2151 | + ); | |
| 493 | 2152 | } |
| 494 | - public function editFormEntry() | |
| 495 | - { | |
| 496 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 497 | - $inputJSON = file_get_contents('php://input'); | |
| 498 | - $input = json_decode($inputJSON); | |
| 499 | - $formHandler = FormHandler::getInstance(); | |
| 500 | - $status = $formHandler->admin->editFormEntry($_REQUEST, $input); | |
| 501 | - if (is_wp_error($status)) { | |
| 502 | - wp_send_json_error($status->get_error_message(), 411); | |
| 503 | - } else { | |
| 504 | - wp_send_json_success($status, 200); | |
| 505 | - } | |
| 506 | - } else { | |
| 507 | - wp_send_json_error( | |
| 508 | - __( | |
| 509 | - 'Token expired', | |
| 510 | - 'bitform' | |
| 511 | - ), | |
| 512 | - 401 | |
| 513 | - ); | |
| 514 | - } | |
| 2153 | + } | |
| 2154 | + | |
| 2155 | + public function saveGlobalMessages() | |
| 2156 | + { | |
| 2157 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2158 | + $this->verifyAdminPermission(); | |
| 2159 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 2160 | + // $inputData = json_decode($inputJSON); | |
| 2161 | + | |
| 2162 | + GlobalHelper::requirePostMethod(); | |
| 2163 | + | |
| 2164 | + try { | |
| 2165 | + $inputData = GlobalHelper::formatRequestData(); | |
| 2166 | + } catch (\InvalidArgumentException $e) { | |
| 2167 | + wp_send_json_error($e->getMessage(), 400); | |
| 2168 | + return; | |
| 2169 | + } | |
| 2170 | + | |
| 2171 | + $appSettings = get_option('bitform_app_settings', (object) []); | |
| 2172 | + | |
| 2173 | + $appSettings->globalMessages = $inputData; | |
| 2174 | + $status = update_option('bitform_app_settings', $appSettings); | |
| 2175 | + // delete_option('bitform_app_settings'); | |
| 2176 | + if (is_wp_error($status)) { | |
| 2177 | + wp_send_json_error($status->get_error_message(), 411); | |
| 2178 | + } else { | |
| 2179 | + $formHandler = FormHandler::getInstance(); | |
| 2180 | + $formHandler->admin->replaceAllFormsErrorMessagesByGlobalMessages(); | |
| 2181 | + wp_send_json_success(__('Save successfully done', 'bit-form')); | |
| 2182 | + } | |
| 2183 | + } else { | |
| 2184 | + wp_send_json_error( | |
| 2185 | + __( | |
| 2186 | + 'Token expired', | |
| 2187 | + 'bit-form' | |
| 2188 | + ), | |
| 2189 | + 401 | |
| 2190 | + ); | |
| 515 | 2191 | } |
| 2192 | + } | |
| 516 | 2193 | |
| 517 | - public function getLogHistory() | |
| 518 | - { | |
| 519 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 520 | - $inputJSON = file_get_contents('php://input'); | |
| 521 | - $input = json_decode($inputJSON); | |
| 522 | - $formHandler = FormHandler::getInstance(); | |
| 523 | - $status = $formHandler->admin->getLogHistory($_REQUEST, $input); | |
| 524 | - if (is_wp_error($status)) { | |
| 525 | - wp_send_json_error($status->get_error_message(), 411); | |
| 526 | - } else { | |
| 527 | - wp_send_json_success($status, 200); | |
| 528 | - } | |
| 529 | - } else { | |
| 530 | - wp_send_json_error( | |
| 531 | - __( | |
| 532 | - 'Token expired', | |
| 533 | - 'bitform' | |
| 534 | - ), | |
| 535 | - 401 | |
| 536 | - ); | |
| 2194 | + public function getPodsField() | |
| 2195 | + { | |
| 2196 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2197 | + $this->verifyAdminPermission(); | |
| 2198 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 2199 | + // $input = json_decode($inputJSON); | |
| 2200 | + GlobalHelper::requirePostMethod(); | |
| 2201 | + try { | |
| 2202 | + $input = GlobalHelper::formatRequestData(); | |
| 2203 | + } catch (\InvalidArgumentException $e) { | |
| 2204 | + wp_send_json_error($e->getMessage(), 400); | |
| 2205 | + } | |
| 2206 | + $podsAdminExists = is_plugin_active('pods/init.php'); | |
| 2207 | + | |
| 2208 | + $podField = []; | |
| 2209 | + if ($podsAdminExists) { | |
| 2210 | + $pods = pods($input->pod_type); | |
| 2211 | + $i = 0; | |
| 2212 | + foreach ($pods->fields as $field) { | |
| 2213 | + $i++; | |
| 2214 | + $podField[$i]['key'] = $field['name']; | |
| 2215 | + $podField[$i]['name'] = $field['label']; | |
| 2216 | + $podField[$i]['is-repeatable'] = $field['repeatable'] ?? 0; | |
| 2217 | + $podField[$i]['required'] = 1 === $field['options']['required'] ? true : false; | |
| 537 | 2218 | } |
| 2219 | + } | |
| 2220 | + | |
| 2221 | + if (is_wp_error($podField)) { | |
| 2222 | + wp_send_json_error($podField, 411); | |
| 2223 | + } else { | |
| 2224 | + wp_send_json_success($podField, 200); | |
| 2225 | + } | |
| 2226 | + } else { | |
| 2227 | + wp_send_json_error( | |
| 2228 | + __( | |
| 2229 | + 'Token expired', | |
| 2230 | + 'bit-form' | |
| 2231 | + ), | |
| 2232 | + 401 | |
| 2233 | + ); | |
| 538 | 2234 | } |
| 539 | - public function updateFormEntry() | |
| 540 | - { | |
| 541 | - \ignore_user_abort(); | |
| 542 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 543 | - $formHandler = FormHandler::getInstance(); | |
| 544 | - $status = $formHandler->admin->updateFormEntry($_REQUEST, $_POST); | |
| 2235 | + } | |
| 545 | 2236 | |
| 546 | - if (is_wp_error($status)) { | |
| 547 | - wp_send_json_error($status->get_error_message(), 411); | |
| 548 | - } else { | |
| 549 | - $status = IntegrationHandler::maybeSetCronForIntegration($status, 'update'); | |
| 550 | - wp_send_json_success($status, 200); | |
| 551 | - } | |
| 552 | - } else { | |
| 553 | - wp_send_json_error( | |
| 554 | - __( | |
| 555 | - 'Token expired', | |
| 556 | - 'bitform' | |
| 557 | - ), | |
| 558 | - 401 | |
| 559 | - ); | |
| 2237 | + public function getPodsType() | |
| 2238 | + { | |
| 2239 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2240 | + $this->verifyAdminPermission(); | |
| 2241 | + $users = get_users(['fields' => ['ID', 'display_name']]); | |
| 2242 | + $pods = []; | |
| 2243 | + $podsAdminExists = is_plugin_active('pods/init.php'); | |
| 2244 | + if ($podsAdminExists) { | |
| 2245 | + $allPods = pods_api()->load_pods(); | |
| 2246 | + foreach ($allPods as $key => $pod) { | |
| 2247 | + $pods[$key]['name'] = $pod['name']; | |
| 2248 | + $pods[$key]['label'] = $pod['label']; | |
| 560 | 2249 | } |
| 2250 | + } | |
| 2251 | + $data = ['users' => $users, 'post_types' => $pods]; | |
| 2252 | + wp_send_json_success($data, 200); | |
| 2253 | + } else { | |
| 2254 | + wp_send_json_error( | |
| 2255 | + __( | |
| 2256 | + 'Token expired', | |
| 2257 | + 'bit-form' | |
| 2258 | + ), | |
| 2259 | + 401 | |
| 2260 | + ); | |
| 561 | 2261 | } |
| 562 | - public function getAllWPPages() | |
| 563 | - { | |
| 564 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 565 | - $inputJSON = file_get_contents('php://input'); | |
| 566 | - $input = json_decode($inputJSON); | |
| 567 | - $formHandler = FormHandler::getInstance(); | |
| 568 | - $status = $formHandler->admin->getAllWPPages($_REQUEST, $input); | |
| 569 | - if (is_wp_error($status)) { | |
| 570 | - wp_send_json_error($status->get_error_message(), 411); | |
| 571 | - } else { | |
| 572 | - wp_send_json_success($status, 200); | |
| 573 | - } | |
| 574 | - } else { | |
| 575 | - wp_send_json_error( | |
| 576 | - __( | |
| 577 | - 'Token expired', | |
| 578 | - 'bitform' | |
| 579 | - ), | |
| 580 | - 401 | |
| 581 | - ); | |
| 582 | - } | |
| 2262 | + } | |
| 2263 | + | |
| 2264 | + public function postTypeByUser() | |
| 2265 | + { | |
| 2266 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2267 | + $this->verifyAdminPermission(); | |
| 2268 | + $users = get_users( | |
| 2269 | + [ | |
| 2270 | + 'fields' => ['ID', 'display_name', 'user_login', 'user_email', 'user_nicename'], | |
| 2271 | + ] | |
| 2272 | + ); | |
| 2273 | + | |
| 2274 | + $postTypes = $this->getPostTypes(); | |
| 2275 | + | |
| 2276 | + $data = ['post_types' => $postTypes, 'users' => $users]; | |
| 2277 | + wp_send_json_success($data, 200); | |
| 2278 | + } else { | |
| 2279 | + wp_send_json_error( | |
| 2280 | + __( | |
| 2281 | + 'Token expired', | |
| 2282 | + 'bit-form' | |
| 2283 | + ), | |
| 2284 | + 401 | |
| 2285 | + ); | |
| 583 | 2286 | } |
| 584 | - public function deleteSuccessMessage() | |
| 585 | - { | |
| 586 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 587 | - $inputJSON = file_get_contents('php://input'); | |
| 588 | - $input = json_decode($inputJSON); | |
| 589 | - $formHandler = FormHandler::getInstance(); | |
| 590 | - $status = $formHandler->admin->deleteSuccessMessage($_REQUEST, $input); | |
| 591 | - if (is_wp_error($status)) { | |
| 592 | - wp_send_json_error($status->get_error_message(), 411); | |
| 593 | - } else { | |
| 594 | - wp_send_json_success($status, 200); | |
| 595 | - } | |
| 596 | - } else { | |
| 597 | - wp_send_json_error( | |
| 598 | - __( | |
| 599 | - 'Token expired', | |
| 600 | - 'bitform' | |
| 601 | - ), | |
| 602 | - 401 | |
| 603 | - ); | |
| 2287 | + } | |
| 2288 | + | |
| 2289 | + public function getWPUsers() | |
| 2290 | + { | |
| 2291 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2292 | + $this->verifyAdminPermission(); | |
| 2293 | + | |
| 2294 | + $users = get_transient('bitforms_admin_users_list'); | |
| 2295 | + if (false === $users) { | |
| 2296 | + $rawUsers = get_users(['fields' => ['ID', 'user_nicename', 'user_email', 'display_name']]); | |
| 2297 | + $userMail = []; | |
| 2298 | + $userNames = []; | |
| 2299 | + foreach ($rawUsers as $key => $value) { | |
| 2300 | + $userMail[$key] = [ | |
| 2301 | + 'label' => !empty($value->display_name) ? $value->display_name : '', | |
| 2302 | + 'value' => !empty($value->user_email) ? $value->user_email : '', | |
| 2303 | + 'id' => $value->ID, | |
| 2304 | + ]; | |
| 2305 | + $userNames[$value->ID] = [ | |
| 2306 | + 'name' => $value->display_name, | |
| 2307 | + 'url' => admin_url('user-edit.php?user_id=' . absint($value->ID)), | |
| 2308 | + ]; | |
| 604 | 2309 | } |
| 2310 | + $users = ['userMail' => $userMail, 'user' => $userNames]; | |
| 2311 | + set_transient('bitforms_admin_users_list', $users, 10 * MINUTE_IN_SECONDS); | |
| 2312 | + } | |
| 2313 | + | |
| 2314 | + wp_send_json_success($users, 200); | |
| 2315 | + } else { | |
| 2316 | + wp_send_json_error(__('Token expired', 'bit-form'), 401); | |
| 605 | 2317 | } |
| 606 | - public function deleteAIntegration() | |
| 607 | - { | |
| 608 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 609 | - $inputJSON = file_get_contents('php://input'); | |
| 610 | - $input = json_decode($inputJSON); | |
| 611 | - $formHandler = FormHandler::getInstance(); | |
| 612 | - $status = $formHandler->admin->deleteAIntegration($_REQUEST, $input); | |
| 613 | - if (is_wp_error($status)) { | |
| 614 | - wp_send_json_error($status->get_error_message(), 411); | |
| 615 | - } else { | |
| 616 | - wp_send_json_success($status, 200); | |
| 617 | - } | |
| 618 | - } else { | |
| 619 | - wp_send_json_error( | |
| 620 | - __( | |
| 621 | - 'Token expired', | |
| 622 | - 'bitform' | |
| 623 | - ), | |
| 624 | - 401 | |
| 625 | - ); | |
| 626 | - } | |
| 2318 | + } | |
| 2319 | + | |
| 2320 | + public function getUserRoles() | |
| 2321 | + { | |
| 2322 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2323 | + $this->verifyAdminPermission(); | |
| 2324 | + wp_send_json_success(['userRoles' => get_editable_roles()], 200); | |
| 2325 | + } else { | |
| 2326 | + wp_send_json_error(__('Token expired', 'bit-form'), 401); | |
| 627 | 2327 | } |
| 2328 | + } | |
| 628 | 2329 | |
| 629 | - public function deleteAWorkflow() | |
| 630 | - { | |
| 631 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 632 | - $inputJSON = file_get_contents('php://input'); | |
| 633 | - $input = json_decode($inputJSON); | |
| 634 | - $formHandler = FormHandler::getInstance(); | |
| 635 | - $status = $formHandler->admin->deleteAWorkflow($_REQUEST, $input); | |
| 636 | - if (is_wp_error($status)) { | |
| 637 | - wp_send_json_error($status->get_error_message(), 411); | |
| 638 | - } else { | |
| 639 | - wp_send_json_success($status, 200); | |
| 640 | - } | |
| 641 | - } else { | |
| 642 | - wp_send_json_error( | |
| 643 | - __( | |
| 644 | - 'Token expired', | |
| 645 | - 'bitform' | |
| 646 | - ), | |
| 647 | - 401 | |
| 648 | - ); | |
| 649 | - } | |
| 2330 | + public function clearUsersTransient(): void | |
| 2331 | + { | |
| 2332 | + delete_transient('bitforms_admin_users_list'); | |
| 2333 | + } | |
| 2334 | + | |
| 2335 | + private function getPostTypes() | |
| 2336 | + { | |
| 2337 | + $all_cpt = get_post_types([ | |
| 2338 | + 'public' => true, | |
| 2339 | + 'exclude_from_search' => false, | |
| 2340 | + '_builtin' => false, | |
| 2341 | + 'capability_type' => 'post', | |
| 2342 | + | |
| 2343 | + ], 'objects'); | |
| 2344 | + $cpt = []; | |
| 2345 | + | |
| 2346 | + foreach ($all_cpt as $key => $post_type) { | |
| 2347 | + $cpt[$key]['name'] = $post_type->name; | |
| 2348 | + $cpt[$key]['label'] = $post_type->label; | |
| 650 | 2349 | } |
| 651 | - public function deleteAMailTemplate() | |
| 652 | - { | |
| 653 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 654 | - $inputJSON = file_get_contents('php://input'); | |
| 655 | - $input = json_decode($inputJSON); | |
| 656 | - $formHandler = FormHandler::getInstance(); | |
| 657 | - $status = $formHandler->admin->deleteAMailTemplate($_REQUEST, $input); | |
| 658 | - if (is_wp_error($status)) { | |
| 659 | - wp_send_json_error($status->get_error_message(), 411); | |
| 660 | - } else { | |
| 661 | - wp_send_json_success($status, 200); | |
| 662 | - } | |
| 663 | - } else { | |
| 664 | - wp_send_json_error( | |
| 665 | - __( | |
| 666 | - 'Token expired', | |
| 667 | - 'bitform' | |
| 668 | - ), | |
| 669 | - 401 | |
| 670 | - ); | |
| 671 | - } | |
| 2350 | + $wp_post_types = get_post_types([ | |
| 2351 | + 'public' => true, | |
| 2352 | + '_builtin' => true, | |
| 2353 | + ]); | |
| 2354 | + | |
| 2355 | + $wp_all_post_types = []; | |
| 2356 | + | |
| 2357 | + foreach ($wp_post_types as $key => $post_type) { | |
| 2358 | + if ('attachment' !== $post_type) { | |
| 2359 | + $wp_all_post_types[$key]['name'] = $post_type; | |
| 2360 | + $wp_all_post_types[$key]['label'] = ucwords($post_type); | |
| 2361 | + } | |
| 672 | 2362 | } |
| 673 | - public function duplicateAMailTemplate() | |
| 674 | - { | |
| 675 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 676 | - $inputJSON = file_get_contents('php://input'); | |
| 677 | - $input = json_decode($inputJSON); | |
| 678 | - $formHandler = FormHandler::getInstance(); | |
| 679 | - $status = $formHandler->admin->duplicateAMailTemplate($_REQUEST, $input); | |
| 680 | - if (is_wp_error($status)) { | |
| 681 | - wp_send_json_error($status->get_error_message(), 411); | |
| 682 | - } else { | |
| 683 | - wp_send_json_success($status, 200); | |
| 2363 | + return array_merge($wp_all_post_types, $cpt); | |
| 2364 | + } | |
| 2365 | + | |
| 2366 | + public function getAcfGroupFields() | |
| 2367 | + { | |
| 2368 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2369 | + $this->verifyAdminPermission(); | |
| 2370 | + $acfFields = []; | |
| 2371 | + $types = ['select', 'checkbox', 'radio']; | |
| 2372 | + | |
| 2373 | + $field_groups = get_posts(['post_type' => 'acf-field-group']); | |
| 2374 | + | |
| 2375 | + if ($field_groups) { | |
| 2376 | + $groups = acf_get_field_groups(); | |
| 2377 | + foreach ($groups as $group) { | |
| 2378 | + foreach (acf_get_fields($group['key']) as $acfField) { | |
| 2379 | + if (in_array($acfField['type'], $types)) { | |
| 2380 | + array_push($acfFields, [ | |
| 2381 | + 'key' => $acfField['key'], | |
| 2382 | + 'name' => $acfField['label'], | |
| 2383 | + 'choices' => $acfField['choices'], | |
| 2384 | + 'group_title' => $group['title'], | |
| 2385 | + 'location' => $group['location'], | |
| 2386 | + ]); | |
| 684 | 2387 | } |
| 685 | - } else { | |
| 686 | - wp_send_json_error( | |
| 687 | - __( | |
| 688 | - 'Token expired', | |
| 689 | - 'bitform' | |
| 690 | - ), | |
| 691 | - 401 | |
| 692 | - ); | |
| 2388 | + } | |
| 693 | 2389 | } |
| 2390 | + } | |
| 2391 | + | |
| 2392 | + wp_send_json_success($acfFields, 200); | |
| 2393 | + } else { | |
| 2394 | + wp_send_json_error( | |
| 2395 | + __( | |
| 2396 | + 'Token expired', | |
| 2397 | + 'bit-form' | |
| 2398 | + ), | |
| 2399 | + 401 | |
| 2400 | + ); | |
| 694 | 2401 | } |
| 695 | - public function setAllFormsReport() | |
| 696 | - { | |
| 697 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 698 | - $inputJSON = file_get_contents('php://input'); | |
| 699 | - $input = json_decode($inputJSON); | |
| 700 | - $formHandler = FormHandler::getInstance(); | |
| 701 | - $status = $formHandler->admin->setAllFormsReport($_REQUEST, $input); | |
| 702 | - if (is_wp_error($status)) { | |
| 703 | - wp_send_json_error($status->get_error_message(), 411); | |
| 704 | - } else { | |
| 705 | - wp_send_json_success($status, 200); | |
| 2402 | + } | |
| 2403 | + | |
| 2404 | + public function getCustomField() | |
| 2405 | + { | |
| 2406 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2407 | + $this->verifyAdminPermission(); | |
| 2408 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 2409 | + // $input = json_decode($inputJSON); | |
| 2410 | + | |
| 2411 | + GlobalHelper::requirePostMethod(); | |
| 2412 | + | |
| 2413 | + try { | |
| 2414 | + $input = GlobalHelper::formatRequestData(); | |
| 2415 | + } catch (\InvalidArgumentException $e) { | |
| 2416 | + wp_send_json_error($e->getMessage(), 400); | |
| 2417 | + } | |
| 2418 | + $acfFields = []; | |
| 2419 | + $acfFiles = []; | |
| 2420 | + | |
| 2421 | + $allowedFields = [ | |
| 2422 | + 'repeater', | |
| 2423 | + 'text', | |
| 2424 | + 'textarea', | |
| 2425 | + 'password', | |
| 2426 | + 'wysiwyg', | |
| 2427 | + 'number', | |
| 2428 | + 'radio', | |
| 2429 | + 'color_picker', | |
| 2430 | + 'oembed', | |
| 2431 | + 'email', | |
| 2432 | + 'url', | |
| 2433 | + 'date_picker', | |
| 2434 | + 'true_false', | |
| 2435 | + 'date_time_picker', | |
| 2436 | + 'time_picker', | |
| 2437 | + 'message', | |
| 2438 | + 'checkbox', | |
| 2439 | + 'select', | |
| 2440 | + 'post_object', | |
| 2441 | + 'user', | |
| 2442 | + 'file', | |
| 2443 | + 'image', | |
| 2444 | + 'gallery' | |
| 2445 | + ]; | |
| 2446 | + | |
| 2447 | + $field_groups = get_posts(['post_type' => 'acf-field-group']); | |
| 2448 | + | |
| 2449 | + if ($field_groups) { | |
| 2450 | + $groups = acf_get_field_groups(['post_type' => $input->post_type]); | |
| 2451 | + | |
| 2452 | + foreach ($groups as $group) { | |
| 2453 | + foreach (acf_get_fields($group['key']) as $acfField) { | |
| 2454 | + if (in_array($acfField['type'], $allowedFields)) { | |
| 2455 | + if ('repeater' === $acfField['type']) { | |
| 2456 | + foreach ($acfField['sub_fields'] as $subField) { | |
| 2457 | + if (in_array($subField['type'], $allowedFields)) { | |
| 2458 | + array_push($acfFields, [ | |
| 2459 | + 'key' => $acfField['key'] . '.' . $subField['key'], | |
| 2460 | + 'name' => $acfField['label'] . '-' . $subField['label'], | |
| 2461 | + 'required' => $subField['required'], | |
| 2462 | + ]); | |
| 2463 | + } | |
| 2464 | + } | |
| 2465 | + } elseif (in_array($acfField['type'], ['file', 'image', 'gallery'])) { | |
| 2466 | + array_push($acfFiles, [ | |
| 2467 | + 'key' => $acfField['key'], | |
| 2468 | + 'name' => $acfField['label'], | |
| 2469 | + 'required' => $acfField['required'], | |
| 2470 | + ]); | |
| 2471 | + } else { | |
| 2472 | + array_push($acfFields, [ | |
| 2473 | + 'key' => $acfField['key'], | |
| 2474 | + 'name' => $acfField['label'], | |
| 2475 | + 'required' => $acfField['required'], | |
| 2476 | + ]); | |
| 2477 | + } | |
| 706 | 2478 | } |
| 707 | - } else { | |
| 708 | - wp_send_json_error( | |
| 709 | - __( | |
| 710 | - 'Token expired', | |
| 711 | - 'bitform' | |
| 712 | - ), | |
| 713 | - 401 | |
| 714 | - ); | |
| 2479 | + } | |
| 715 | 2480 | } |
| 2481 | + } | |
| 2482 | + | |
| 2483 | + wp_send_json_success(['acfFields' => $acfFields, 'acfFile' => $acfFiles], 200); | |
| 2484 | + } else { | |
| 2485 | + wp_send_json_error( | |
| 2486 | + __( | |
| 2487 | + 'Token expired', | |
| 2488 | + 'bit-form' | |
| 2489 | + ), | |
| 2490 | + 401 | |
| 2491 | + ); | |
| 716 | 2492 | } |
| 717 | - public function savegReCaptcha() | |
| 718 | - { | |
| 719 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 720 | - $inputJSON = file_get_contents('php://input'); | |
| 721 | - $input = json_decode($inputJSON); | |
| 722 | - $formHandler = FormHandler::getInstance(); | |
| 723 | - $status = $formHandler->admin->savegReCaptcha($_REQUEST, $input); | |
| 724 | - if (is_wp_error($status)) { | |
| 725 | - wp_send_json_error($status->get_error_message(), 411); | |
| 726 | - } else { | |
| 727 | - wp_send_json_success($status, 200); | |
| 728 | - } | |
| 729 | - } else { | |
| 730 | - wp_send_json_error( | |
| 731 | - __( | |
| 732 | - 'Token expired', | |
| 733 | - 'bitform' | |
| 734 | - ), | |
| 735 | - 401 | |
| 736 | - ); | |
| 737 | - } | |
| 2493 | + } | |
| 2494 | + | |
| 2495 | + public function getMetaBoxFields() | |
| 2496 | + { | |
| 2497 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2498 | + $this->verifyAdminPermission(); | |
| 2499 | + if (!function_exists('rwmb_meta')) { | |
| 2500 | + wp_send_json_error(__('Meta Box must be activated!', 'bit-form')); | |
| 2501 | + } | |
| 2502 | + | |
| 2503 | + GlobalHelper::requirePostMethod(); | |
| 2504 | + | |
| 2505 | + try { | |
| 2506 | + $input = GlobalHelper::formatRequestData(); | |
| 2507 | + } catch (\InvalidArgumentException $e) { | |
| 2508 | + wp_send_json_error($e->getMessage(), 400); | |
| 2509 | + } | |
| 2510 | + | |
| 2511 | + $metaBoxFields = rwmb_get_object_fields($input->post_type); | |
| 2512 | + | |
| 2513 | + $metaBoxFields = MetaBoxService::getMetaBoxFields($input->post_type); | |
| 2514 | + | |
| 2515 | + wp_send_json_success( | |
| 2516 | + [ | |
| 2517 | + 'metaboxFields' => array_values($metaBoxFields['text_fields']), | |
| 2518 | + 'metaboxFile' => array_values($metaBoxFields['file_fields']), | |
| 2519 | + ], | |
| 2520 | + 200 | |
| 2521 | + ); | |
| 2522 | + } else { | |
| 2523 | + wp_send_json_error( | |
| 2524 | + __( | |
| 2525 | + 'Token expired', | |
| 2526 | + 'bit-form' | |
| 2527 | + ), | |
| 2528 | + 401 | |
| 2529 | + ); | |
| 738 | 2530 | } |
| 2531 | + } | |
| 739 | 2532 | |
| 740 | - public function saveApiKey() | |
| 741 | - { | |
| 742 | - if (wp_verify_nonce(sanitize_text_field($_REQUEST['_ajax_nonce']), 'bitforms_save')) { | |
| 743 | - $inputJSON = file_get_contents('php://input'); | |
| 744 | - $input = json_decode($inputJSON); | |
| 745 | - if (empty($input->api_key)) { | |
| 746 | - $api_key = get_option('bitform_secret_api_key'); | |
| 747 | - } elseif (!empty($input->api_key)) { | |
| 748 | - update_option('bitform_secret_api_key', $input->api_key); | |
| 749 | - $api_key = $input->api_key; | |
| 750 | - } | |
| 751 | - if (!$api_key) { | |
| 752 | - $api_key = hash('sha1', base64_encode(12345)); | |
| 753 | - update_option('bitform_secret_api_key', $api_key); | |
| 754 | - } | |
| 755 | - wp_send_json_success($api_key, 200); | |
| 756 | - } else { | |
| 757 | - wp_send_json_error( | |
| 758 | - __( | |
| 759 | - 'Token expired', | |
| 760 | - 'bitform' | |
| 761 | - ), | |
| 762 | - 401 | |
| 763 | - ); | |
| 764 | - } | |
| 2533 | + public function saveConversationalCSS() | |
| 2534 | + { | |
| 2535 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 2536 | + $this->verifyAdminPermission(); | |
| 2537 | + // $inputJSON = wp_unslash($_POST['data']); | |
| 2538 | + // $requestsParams = json_decode($inputJSON); | |
| 2539 | + GlobalHelper::requirePostMethod(); | |
| 2540 | + try { | |
| 2541 | + $requestsParams = GlobalHelper::formatRequestData(); | |
| 2542 | + } catch (\InvalidArgumentException $e) { | |
| 2543 | + wp_send_json_error($e->getMessage(), 400); | |
| 2544 | + } | |
| 2545 | + $formId = sanitize_text_field($requestsParams->formID); | |
| 2546 | + $css = $requestsParams->css; | |
| 2547 | + | |
| 2548 | + if (filter_var($formId, FILTER_VALIDATE_INT)) { | |
| 2549 | + $path = 'form-styles'; | |
| 2550 | + $fileName = "bitform-conversational-$formId.css"; | |
| 2551 | + FrontEndScriptGenerator::customCodeFileSaveOrDelete($css, $path, $fileName); | |
| 2552 | + wp_send_json_success( | |
| 2553 | + __( | |
| 2554 | + 'Conversational CSS Saved Successfully!', | |
| 2555 | + 'bit-form' | |
| 2556 | + ), | |
| 2557 | + 200 | |
| 2558 | + ); | |
| 2559 | + } else { | |
| 2560 | + wp_send_json_error( | |
| 2561 | + __( | |
| 2562 | + 'Invalid form id', | |
| 2563 | + 'bit-form' | |
| 2564 | + ), | |
| 2565 | + 401 | |
| 2566 | + ); | |
| 2567 | + } | |
| 2568 | + } else { | |
| 2569 | + wp_send_json_error( | |
| 2570 | + __( | |
| 2571 | + 'Token expired', | |
| 2572 | + 'bit-form' | |
| 2573 | + ), | |
| 2574 | + 401 | |
| 2575 | + ); | |
| 765 | 2576 | } |
| 2577 | + } | |
| 766 | 2578 | } |