'callback' => array($this, 'render_dropdown'), 'dropdown_options' => array_combine($currencies, $currencies), 'default' => 'USD', ), 'domain' => array( 'title' => __('Default merchant domain', 'content-egg') . ' *', 'description' => sprintf(__('For example: %s', 'content-egg'), 'saturn.de'), 'callback' => array($this, 'render_input'), 'default' => '', 'validator' => array( array( 'call' => array('\ContentEgg\application\helpers\FormValidator', 'required'), 'when' => 'is_active', 'message' => sprintf(__('The field "%s" can not be empty.', 'content-egg'), 'Default merchant domain'), ), array( 'call' => array($this, 'sanitizeDomain'), 'type' => 'filter', ), ), ), 'mapping' => array( 'title' => __('Field mapping', 'content-egg') . ' *', 'description' => '', 'callback' => array($this, 'render_mapping_block'), 'validator' => array( array( 'call' => array($this, 'mappingSanitize'), 'type' => 'filter', ), array( 'call' => array($this, 'mappingValidate'), 'when' => 'is_active', 'message' => __('Please fill out all required mapping fields.', 'content-egg'), ), ), ), 'deeplink' => array( 'title' => __('Deeplink', 'content-egg'), 'description' => __('Set this option only if your feed does not contain affiliate links.', 'content-egg'), 'callback' => array($this, 'render_input'), 'default' => '', 'validator' => array( 'trim', ), 'section' => 'default', ), 'search_type' => array( 'title' => __('Search type', 'content-egg') . ' *', 'callback' => array($this, 'render_dropdown'), 'dropdown_options' => array( 'full' => 'Full text search (relevance)', 'strict' => 'Full text search (strict mode)', 'exact' => 'Exact phrase search', ), 'default' => 'full', ), 'in_stock' => array( 'title' => __('In stock', 'content-egg'), 'description' => __('Search only products in stock.', 'content-egg'), 'callback' => array($this, 'render_checkbox'), 'default' => true, 'section' => 'default', ), ); $options = array_merge(parent::options(), $options); return self::moveRequiredUp($options); } public function render_mapping_row($args) { $field_name = $args['_field_name']; $value = isset($args['value'][$field_name]) ? $args['value'][$field_name] : ''; $display_name = $field_name; if ($field_name == 'product node') { $display_name .= ' ' . __('(required for XML/JSON feed only)', 'content-egg'); } elseif (self::isMappingFieldRequared($field_name)) { $display_name .= ' ' . __('(required)', 'content-egg'); } else { $display_name .= ' ' . __('(optional)', 'content-egg'); } echo ''; echo ' › '; echo ''; } public function render_mapping_block($args) { if (!$args['value']) $args['value'] = array(); foreach (array_keys(self::mappingFields()) as $str) { echo '
'; $args['_field_name'] = $str; $this->render_mapping_row($args); echo '
'; } if ($args['description']) echo '

' . esc_html($args['description']) . '

'; } public static function mappingFields() { return array( 'product node' => false, 'id' => true, 'title' => true, 'description' => true, 'affiliate link' => true, 'image ​​link' => true, 'price' => true, 'sale price' => false, 'currency' => false, 'availability' => false, 'is in stock' => false, 'direct link' => false, 'brand' => false, 'category' => false, 'short description' => false, 'isbn' => false, 'gtin' => false, 'shipping cost' => false, 'attributes' => false, ); } public static function isMappingFieldRequared($field) { $fields = self::mappingFields(); if (isset($fields[$field]) && $fields[$field]) { return true; } else { return false; } } public function mappingSanitize($values) { foreach ($values as $k => $value) { $values[$k] = trim(\sanitize_text_field($value)); } return $values; } public function mappingValidate($values) { foreach ($values as $field => $value) { if (self::isMappingFieldRequared($field) && !$value) { return false; } } return true; } public function sanitizeDomain($value) { $value = trim(\sanitize_text_field($value)); if ($host = TextHelper::getHostName($value)) { $value = $host; } $value = strtolower($value); $value = str_replace('www.', '', $value); $value = trim($value, "/"); return $value; } public function validateFeedUrl($value) { if (filter_var($value, FILTER_VALIDATE_URL) === false) { return false; } else { return true; } } }