/** * Validates and sanitizes the current popup details. * * @since 4.6 */ protected function validate_data() { $styles = apply_filters('popup-styles', array()); // Color. if (!is_array($this->color)) { $this->color = array(); } if (!isset($this->color['col1'])) { $this->color['col1'] = ''; } if (!isset($this->color['col2'])) { $this->color['col2'] = ''; } if (!empty($this->color['col1']) && $this->color['col1'][0] !== '#') { $this->color['col1'] = '#' . $this->color['col1']; } if (!empty($this->color['col2']) && $this->color['col2'][0] !== '#') { $this->color['col2'] = '#' . $this->color['col2']; } // Size. if (!is_array($this->size)) { $this->size = array(); } if (!isset($this->size['width'])) { $this->size['width'] = ''; } if (!isset($this->size['height'])) { $this->size['height'] = ''; } // Style. if (!isset($styles[$this->style])) { $this->style = 'minimal'; } // default style. $this->deprecated_style = @$styles[$this->style]->deprecated; // Boolean types. $this->custom_size = true == $this->custom_size; $this->custom_colors = true == $this->custom_colors; $this->deprecated_style = true == $this->deprecated_style; $this->round_corners = true == $this->round_corners; $this->scroll_body = true == $this->scroll_body; $this->can_hide = true == $this->can_hide; $this->close_hides = true == $this->close_hides; $this->overlay_close = true == $this->overlay_close; $this->inline = true == $this->inline; // Numeric types. $this->hide_expire = absint($this->hide_expire); $this->display_data['delay'] = absint(@$this->display_data['delay']); $this->display_data['scroll'] = absint(@$this->display_data['scroll']); $this->display_data['delay_type'] = @$this->display_data['delay_type']; $this->display_data['scroll_type'] = @$this->display_data['scroll_type']; $this->display_data['anchor'] = @$this->display_data['anchor']; // Display behavior. if (!in_array($this->display, self::$display_opts)) { $this->display = 'delay'; } if ('m' != $this->display_data['delay_type']) { $this->display_data['delay_type'] = 's'; } if ('px' != $this->display_data['scroll_type']) { $this->display_data['scroll_type'] = '%'; } // Rules. if (!is_array($this->rule)) { $this->rule = array(); } $this->rule_files = array(); foreach ($this->rule as $ind => $key) { if (empty($key)) { unset($this->rule[$ind]); } // Set rule-files. $file = IncPopupRules::file_for_rule($key); if ($file && !in_array($file, $this->rule_files)) { $this->rule_files[] = $file; } } if (!is_array($this->rule_data)) { $this->rule_data = array(); } foreach ($this->rule_data as $ind => $key) { if (empty($key)) { unset($this->rule_data[$ind]); } } // Generate unique ID. $this->code = (object) array(); $this->code->id = 'a' . md5($this->id . date('dis')); $this->code->cls = 'wdpu-' . $this->id; // Display data (legacy code for old styles). if ($this->custom_colors) { $this->code->colors = 'color:' . $this->color['col2'] . ';background:' . $this->color['col1'] . ';'; } else { $this->code->colors = 'color:#000000;background:#FFFFFF;'; } // Display data. if (!$this->custom_colors || empty($this->color['col1'])) { $this->code->color1 = '#488CFD'; } else { $this->code->color1 = $this->color['col1']; } if (!$this->custom_colors || empty($this->color['col2'])) { $this->code->color2 = '#FFFFFF'; } else { $this->code->color2 = $this->color['col2']; } // Very rough validation that makes sure that the field does not close // the <style> tag manually. $this->custom_css = str_replace('</s', 's', $this->custom_css); $this->class = lib2()->array->get($this->class); $this->script_data['html_id'] = $this->code->id; $this->script_data['popup_id'] = $this->id; $this->script_data['close_hide'] = $this->close_hides; $this->script_data['expiry'] = $this->hide_expire; $this->script_data['custom_size'] = $this->custom_size; $this->script_data['width'] = trim(str_replace('px', '', $this->size['width'])); $this->script_data['height'] = trim(str_replace('px', '', $this->size['height'])); $this->script_data['overlay_close'] = $this->overlay_close; $this->script_data['display'] = $this->display; $this->script_data['display_data'] = $this->display_data; $this->script_data['scroll_body'] = $this->scroll_body; $this->script_data['form_submit'] = $this->form_submit; $this->script_data['animation_in'] = $this->animation_in; $this->script_data['animation_out'] = $this->animation_out; $this->script_data['inline'] = $this->inline; // Validation only done when editing popups. if (!$this->is_upfront && is_admin() && $this->id >= 0) { // Name. if (empty($this->name)) { $this->name = __('New PopUp', PO_LANG); } // Order. if (empty($this->id) || empty($this->order)) { $this->order = IncPopupDatabase::next_order(); } // Rule-files. $this->rule_files = array(); foreach ($this->rule as $ind => $key) { $file = IncPopupRules::file_for_rule($key); if ($file && !in_array($file, $this->rule_files)) { $this->rule_files[] = $file; } } // Check if the "id" is valid! if ($this->id > 0 && self::POST_TYPE !== get_post_type($this->id)) { $this->id = 0; } } }