esc_html__('Add', 'affieasy'), 'addAffliateLink' => esc_html__('Add affiliate link', 'affieasy'), 'addColumnAfterThisOne' => esc_html__('Add a column after this one', 'affieasy'), 'addRowAfterThisOne' => esc_html__('Add a row after this one', 'affieasy'), 'cancel' => esc_html__('Cancel', 'affieasy'), 'close' => esc_html__('Close', 'affieasy'), 'createAffiliationLink' => esc_html__('Create affiliation link', 'affieasy'), 'delete' => esc_html__('Delete', 'affieasy'), 'deleteColumn' => esc_html__('Delete column', 'affieasy'), 'deleteRow' => esc_html__('Delete row', 'affieasy'), 'dragAndDropColumn' => esc_html__($canUsePremiumCode ? 'Keep the mouse pressed to drag and drop the column' : 'Get the premium version to drag and drop the column', 'affieasy'), 'dragAndDropRow' => esc_html__($canUsePremiumCode ? 'Keep the mouse pressed to drag and drop the row' : 'Get the premium version to drag and drop the row', 'affieasy'), 'edit' => esc_html__('Edit', 'affieasy'), 'editAffiliateLink' => esc_html__('Edit affiliate link', 'affieasy'), 'editAffiliationLink' => esc_html__('Edit affiliation link', 'affieasy'), 'editHeaderOptions' => esc_html__('Edit header options', 'affieasy'), 'removeImage' => esc_html__('Remove image', 'affieasy'), 'selectImage' => esc_html__('Select image', 'affieasy'), 'selectOrUploadImage' => esc_html__('Select or Upload new image', 'affieasy'), 'productLinkLabel' => esc_html__('Product link', 'affieasy'), 'optionalLabel' => esc_html__('Optional', 'affieasy'), 'unknownType' => esc_html__('Unknown type', 'affieasy'), 'validate' => esc_html__('Validate', 'affieasy'), )); wp_localize_script('edit-table-script', 'afesEditTable', array( 'ajaxUrl' => admin_url('admin-ajax.php'), 'detectWebshopNonce' => wp_create_nonce('afes_detect_webshop_nonce'), )); wp_enqueue_media(); $table = new AFES_Table( isset($_POST['id']) ? sanitize_key($_POST['id']) : null, isset($_POST['name']) ? sanitize_text_field($_POST['name']) : null, isset($_POST['header-type']) ? sanitize_text_field($_POST['header-type']) : null, isset($_POST['header-options']) ? AFES_Utils::sanitize_header_options($_POST['header-options']) : null, isset($_POST['content']) ? AFES_Utils::sanitize_content($_POST['content']) : null, isset($_POST['responsive-breakpoint']) ? sanitize_key($_POST['responsive-breakpoint']) : null, isset($_POST['max-width']) ? sanitize_key($_POST['max-width']) : null, isset($_POST['background-color']) ? sanitize_hex_color($_POST['background-color']) : null ); $errors = array(); $dbManager = new AFES_DbManager(); $webshops = $dbManager->get_webshop_list(); $hasNoWebShop = empty($webshops); $submit = isset($_POST['submit']) ? sanitize_key($_POST['submit']) : null; $isFromSaveAction = $submit === 'save-action'; if ($isFromSaveAction) { $nonce = isset($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : null; if (wp_verify_nonce( $nonce, 'edit-table-nonce')){ if (empty($table->getName())) { array_push($errors, esc_html__('Name must not be empty', 'affieasy')); } $isNullTableContent = $table->getContent() == null; $isTableWithColumnHeader = in_array($table->getHeaderType(), array('COLUMN_HEADER', 'BOTH')); $tableContentSize = $isNullTableContent ? 0 : count($table->getContent()); if ($isTableWithColumnHeader && $tableContentSize < 2 || !$isTableWithColumnHeader && $tableContentSize < 1) { array_push($errors, esc_html__('Table must contains at least one row', 'affieasy')); } $responsiveBreakpoint = $table->getResponsiveBreakpoint(); if ($responsiveBreakpoint !== '' && (!is_numeric($responsiveBreakpoint) || $responsiveBreakpoint < 0)) { array_push($errors, esc_html__('Responsive breakpoint must be a positive number', 'affieasy')); } $maxWidth = $table->getMaxWidth(); if ($maxWidth !== '' && (!is_numeric($maxWidth) || $maxWidth < 0)) { array_push($errors, esc_html__('Max width must be a positive number', 'affieasy')); } if (count($errors) == 0) { $table = $dbManager->edit_table($table); } else { if ($isNullTableContent) { $table->initDefaultContent(); } } } // fin check nonce } else { $id = isset($_GET['id']) ? sanitize_key($_GET['id']) : null; if (!empty($id)) { $table = $dbManager->get_table_by_id($id); } if (empty($table->getId())) { $table->initDefaultContent(); } } $firstRow = $table->getContent()[0]; $tableId = $table->getId(); $tableName = $table->getName(); $headerType = $table->getHeaderType(); $headerOptions = $table->getHeaderOptions(); $hasHeaderOptions = !empty($headerOptions); $isTableWithColumnHeader = in_array($headerType, array('COLUMN_HEADER', 'BOTH')); $isTableWithRowHeader = in_array($headerType, array('ROW_HEADER', 'BOTH')); $isFromSaveActionOrNotNew = $isFromSaveAction || !empty($table->getId()); ?>
| getUrl()); ?> |