/** * Get avaible preset from DB by current page requirements */ private function get_preset_sidebars($data) { if ($this->config->is_enabled_select_option($data['type'], $data['sub_type'])) { $settings = $this->get_db(); if (!empty($data['id'])) { //get by ids preset if (isset($settings['settings'][$data['type']][$data['sub_type']]['saved_ids'])) { //check if id in saved_ids if (in_array($data['id'], $settings['settings'][$data['type']][$data['sub_type']]['saved_ids'])) { $by_ids_presets = $settings['settings'][$data['type']][$data['sub_type']]['by_ids']; usort($by_ids_presets, array($this, 'preset_timestamp_cmp')); foreach ($by_ids_presets as $preset_key => $preset) { if (in_array($data['id'], $preset['ids'])) { $this->current_page_preset = $preset; if (isset($this->current_page_preset['timestamp'])) { unset($this->current_page_preset['timestamp']); } return $this->current_page_preset; } } } } } $this->current_page_preset = fw_akg('settings/' . $data['type'] . '/' . $data['sub_type'] . '/common', $settings, false); if (isset($this->current_page_preset['timestamp'])) { unset($this->current_page_preset['timestamp']); } return $this->current_page_preset; } return false; }
/** * 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; }
/** * 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 (fw()->extensions->get('sidebars')->is_missing_config()) { $this->_fw_check_allowed_replace_positions($preset); } else { $this->_fw_check_allowed_colors($preset); } //remove duplicates in array if (is_array($preset['ids'])) { $preset['ids'] = array_unique($preset['ids']); } return $preset; }