private function _fw_check_allowed_colors(&$preset) { if (!isset($preset['position']) or !$this->config->has_position($preset['position'])) { throw new Exception(__("Error: Position doesn't exists. Please check config file.", 'fw')); } $position_allowed_colors = $this->config->get_allowed_color_by_position($preset['position']); //removing invalid data from $preset['sidebars'] $exceptionMsg = __('Error: Sidebars not set', 'fw'); if (isset($preset['sidebars']) and is_array($preset['sidebars'])) { $exception = new _FW_Extension_Sidebars_MissingSidebar_Exception($exceptionMsg); array_walk($preset['sidebars'], array($this, 'clear_preset_sidebars'), $position_allowed_colors); foreach ($preset['sidebars'] as $color => $sidebar_id) { if (empty($sidebar_id)) { //if added invalid sidebarId, add 'color' to exception unset($preset['sidebars'][$color]); $exception->add_color($color); } } if ($exception->has_colors()) { throw $exception; } } else { if (!empty($position_allowed_colors)) { //if not set sidebars, but it is in position throw exception throw new Exception($exceptionMsg); } else { $preset['sidebars'] = array(); } } }
/** * validate ajax params */ private function validate_preset($preset) { $prefix = $this->config->parse_prefix($preset['slug']); $sub_type = $this->config->parse_sub_type($preset['slug']); $type = $this->config->get_type_by_prefix($prefix); if (!$sub_type or !$type) { throw new Exception(__('Error: Type or sub_type error', 'fw')); } $preset['type'] = $type; $preset['sub_type'] = $sub_type; if ($this->config->is_enabled_select_option($type, $sub_type) === false) { throw new Exception(__(sprintf('Error this option (%s) is disabled', $type . '-' . $sub_type), 'fw')); } if (!isset($preset['position']) or !$this->config->has_position($preset['position'])) { throw new Exception(__("Error: Position doesn't exists. Please check config file.", 'fw')); } $position_allowed_colors = $this->config->get_allowed_color_by_position($preset['position']); //removing invalid data from $preset['sidebars'] $exceptionMsg = __('Error: Sidebars not set', 'fw'); if (isset($preset['sidebars']) and is_array($preset['sidebars'])) { $exception = new _FW_Extension_Sidebars_MissingSidebar_Exception($exceptionMsg); array_walk($preset['sidebars'], array($this, 'clear_preset_sidebars'), $position_allowed_colors); foreach ($preset['sidebars'] as $color => $sidebar_id) { if (empty($sidebar_id)) { //if added invalid sidebarId, add 'color' to exception unset($preset['sidebars'][$color]); $exception->add_color($color); } } if ($exception->has_colors()) { throw $exception; } } else { if (!empty($position_allowed_colors)) { //if not set sidebars, but it is in position throw exception throw new Exception($exceptionMsg); } else { $preset['sidebars'] = array(); } } //remove duplicates in array if (is_array($preset['ids'])) { $preset['ids'] = array_unique($preset['ids']); } return $preset; }