aps_functions = $aps_functions; $this->config = $config; $this->config_text = $config_text; $this->language = $language; $this->log = $log; $this->parser = $parser; $this->request = $request; $this->template = $template; $this->user = $user; $this->utils = $utils; $this->root_path = $root_path; $this->php_ext = $php_ext; } /** * Handle and display the "Settings" ACP mode. * * @return void * @access public */ public function settings() { $this->language->add_lang(['ass_acp_common', 'ass_common'], 'phpbbstudio/ass'); $errors = []; $submit = $this->request->is_set_post('submit'); $form_key = 'shop_settings'; add_form_key($form_key); if ($submit) { if (!check_form_key($form_key)) { $errors[] = $this->language->lang('FORM_INVALID'); } } if ($this->request->variable('action', '', true) === 'locations') { $this->link_locations(); } $banner_sizes = ['small', 'tiny']; $banner_colours = ['blue', 'red', 'green', 'orange', 'aqua', 'yellow', 'pink', 'violet', 'purple', 'gold', 'silver', 'bronze']; $icon_colours = ['blue', 'red', 'green', 'orange', 'aqua', 'yellow', 'pink', 'violet', 'purple', 'gold', 'silver', 'bronze', 'bluegray', 'gray', 'lightgray', 'black', 'white', 'lighten', 'darken']; $panels = [ 'featured' => ['limit' => ['min' => 0, 'max' => 10], 'order' => ['min' => 1, 'max' => 6], 'width' => ['min' => 4, 'max' => 6]], 'sale' => ['limit' => ['min' => 0, 'max' => 10], 'order' => ['min' => 1, 'max' => 6], 'width' => ['min' => 4, 'max' => 6]], 'featured_sale' => ['limit' => ['min' => 0, 'max' => 4], 'order' => ['min' => 1, 'max' => 6], 'width' => ['min' => 4, 'max' => 6]], 'random' => ['limit' => ['min' => 0, 'max' => 20], 'order' => ['min' => 1, 'max' => 6], 'width' => ['min' => 3, 'max' => 4]], 'recent' => ['limit' => ['min' => 0, 'max' => 10], 'order' => ['min' => 1, 'max' => 6], 'width' => ['min' => 4, 'max' => 6]], 'limited' => ['limit' => ['min' => 0, 'max' => 10], 'order' => ['min' => 1, 'max' => 6], 'width' => ['min' => 4, 'max' => 6]], ]; $options = ['banner_size', 'banner_colour', 'icon_colour', 'icon', 'limit', 'order', 'width']; $settings = [ 'int' => ['enabled', 'active', 'gift_enabled', 'deactivate_conflicts', 'purge_cache', 'items_per_page', 'logs_per_page', 'carousel_arrows', 'carousel_dots', 'carousel_fade', 'carousel_play', 'carousel_play_speed', 'carousel_speed'], 'string' => ['shop_icon', 'inventory_icon', 'no_image_icon', 'gift_icon'], ]; // General settings foreach ($settings as $type => $data) { foreach ($data as $name) { $config_name = "ass_{$name}"; $default = $this->config[$config_name]; settype($default, $type); $this->template->assign_var(utf8_strtoupper($name), $default); if ($submit && empty($errors)) { $value = $this->request->variable($name, '', $type === 'string'); if ($value !== $default) { $this->config->set($config_name, $value); } } } } // Panel settings $variables = []; foreach ($panels as $panel => $data) { foreach ($options as $option) { $name = "{$panel}_{$option}"; $config_name = "ass_panel_{$name}"; $default = $this->config[$config_name]; $variables[utf8_strtoupper($option)][$panel] = $default; if ($submit && empty($errors)) { $value = $this->request->variable($name, $default); if (isset($data[$option])) { if ($value < $data[$option]['min']) { $field = $this->language->lang('ACP_ASS_PANEL_' . utf8_strtoupper($panel)); $field .= $this->language->lang('COLON'); $field .= ' ' . $this->language->lang('ACP_ASS_PANEL_' . utf8_strtoupper($option)); $errors[] = $this->language->lang('ASS_ERROR_TOO_LOW', $field, $data[$option]['min'], $value); continue; } if ($value > $data[$option]['max']) { $field = $this->language->lang('ACP_ASS_PANEL_' . utf8_strtoupper($panel)); $field .= $this->language->lang('COLON'); $field .= ' ' . $this->language->lang('ACP_ASS_PANEL_' . utf8_strtoupper($option)); $errors[] = $this->language->lang('ASS_ERROR_TOO_HIGH', $field, $data[$option]['max'], $value); continue; } } if ($value != $default) { $this->config->set($config_name, $value); } } } } uksort($panels, function($a, $b) { if ($this->config["ass_panel_{$a}_order"] == $this->config["ass_panel_{$b}_order"]) { return 0; } return $this->config["ass_panel_{$a}_order"] < $this->config["ass_panel_{$b}_order"] ? -1 : 1; }); if ($submit && empty($errors)) { $message = $this->request->variable('inactive_desc', '', true); $message = $this->parser->parse($message); $this->config_text->set('ass_inactive_desc', $message); meta_refresh(3, $this->u_action); trigger_error($this->language->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); } $message = $this->config_text->get('ass_inactive_desc'); $message = $this->utils->unparse($message); $this->generate_bbcodes(); $this->template->assign_vars(array_merge($variables, [ 'ERRORS' => $errors, 'INACTIVE_DESC' => $message, 'SHOP_BLOCKS' => $panels, 'SHOP_ICON_COLOURS' => $icon_colours, 'SHOP_BANNER_COLOURS' => $banner_colours, 'SHOP_BANNER_SIZES' => $banner_sizes, 'U_ACTION' => $this->u_action, 'U_LOCATIONS' => $this->u_action . '&action=locations', ])); } /** * Generate BBCodes for a textarea editor. * * @return void * @access protected */ protected function generate_bbcodes() { include_once $this->root_path . 'includes/functions_display.' . $this->php_ext; $this->language->add_lang('posting'); display_custom_bbcodes(); $this->template->assign_vars([ 'S_BBCODE_IMG' => true, 'S_BBCODE_QUOTE' => true, 'S_BBCODE_FLASH' => true, 'S_LINKS_ALLOWED' => true, ]); } /** * Handles the link locations from the settings page. * * @return void * @access protected */ protected function link_locations() { $this->language->add_lang('aps_acp_common', 'phpbbstudio/aps'); $locations = $this->aps_functions->get_link_locations('ass_link_locations'); $variables = ['S_ASS_LOCATIONS' => true]; foreach ($locations as $location => $status) { $variables[$location] = (bool) $status; } $this->template->assign_vars($variables); if ($this->request->is_set_post('submit_locations')) { $links = []; foreach (array_keys($locations) as $location) { $links[$location] = $this->request->variable((string) $location, false); } $this->aps_functions->set_link_locations($links, 'ass_link_locations'); $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_ACP_ASS_LOCATIONS'); trigger_error($this->language->lang('ACP_APS_LOCATIONS_SUCCESS') . adm_back_link($this->u_action)); } } /** * Set custom form action. * * @param string $u_action Custom form action * @return self $this This controller for chaining calls * @access public */ public function set_page_url($u_action) { $this->u_action = $u_action; return $this; } }