function SetThemeSettings() { global $txt, $context, $settings, $modSettings, $sourcedir, $smcFunc; if (empty($_GET['th']) && empty($_GET['id'])) { return ThemeAdmin(); } $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; // Select the best fitting tab. $context[$context['admin_menu_name']]['current_subsection'] = 'list'; loadLanguage('Admin'); isAllowedTo('admin_forum'); // Validate inputs/user. if (empty($_GET['th'])) { fatal_lang_error('no_theme', false); } // Fetch the smiley sets... $sets = explode(',', 'none,' . $modSettings['smiley_sets_known']); $set_names = explode("\n", $txt['smileys_none'] . "\n" . $modSettings['smiley_sets_names']); $context['smiley_sets'] = array('' => $txt['smileys_no_default']); foreach ($sets as $i => $set) { $context['smiley_sets'][$set] = htmlspecialchars($set_names[$i]); } $old_id = $settings['theme_id']; $old_settings = $settings; loadTheme($_GET['th'], false); // Sadly we really do need to init the template. loadSubTemplate('init', 'ignore'); // Also load the actual themes language file - in case of special settings. loadLanguage('Settings', '', true, true); // Let the theme take care of the settings. loadTemplate('Settings'); loadSubTemplate('settings'); // Submitting! if (isset($_POST['submit'])) { checkSession(); if (empty($_POST['options'])) { $_POST['options'] = array(); } if (empty($_POST['default_options'])) { $_POST['default_options'] = array(); } // Make sure items are cast correctly. foreach ($context['theme_settings'] as $item) { // Disregard this item if this is just a separator. if (!is_array($item)) { continue; } foreach (array('options', 'default_options') as $option) { if (!isset($_POST[$option][$item['id']])) { continue; } elseif (empty($item['type'])) { $_POST[$option][$item['id']] = $_POST[$option][$item['id']] ? 1 : 0; } elseif ($item['type'] == 'number') { $_POST[$option][$item['id']] = (int) $_POST[$option][$item['id']]; } } } // Set up the sql query. $inserts = array(); foreach ($_POST['options'] as $opt => $val) { $inserts[] = array(0, $_GET['th'], $opt, is_array($val) ? implode(',', $val) : $val); } foreach ($_POST['default_options'] as $opt => $val) { $inserts[] = array(0, 1, $opt, is_array($val) ? implode(',', $val) : $val); } // If we're actually inserting something.. if (!empty($inserts)) { $smcFunc['db_insert']('replace', '{db_prefix}themes', array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'), $inserts, array('id_member', 'id_theme', 'variable')); } cache_put_data('theme_settings-' . $_GET['th'], null, 90); cache_put_data('theme_settings-1', null, 90); // Invalidate the cache. updateSettings(array('settings_updated' => time())); redirectexit('action=admin;area=theme;sa=settings;th=' . $_GET['th'] . ';' . $context['session_var'] . '=' . $context['session_id']); } $context['sub_template'] = 'set_settings'; $context['page_title'] = $txt['theme_settings']; foreach ($settings as $setting => $dummy) { if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url', 'template_dirs'))) { $settings[$setting] = htmlspecialchars__recursive($settings[$setting]); } } $context['settings'] = $context['theme_settings']; $context['theme_settings'] = $settings; foreach ($context['settings'] as $i => $setting) { // Separators are dummies, so leave them alone. if (!is_array($setting)) { continue; } if (!isset($setting['type']) || $setting['type'] == 'bool') { $context['settings'][$i]['type'] = 'checkbox'; } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') { $context['settings'][$i]['type'] = 'number'; } elseif ($setting['type'] == 'string') { $context['settings'][$i]['type'] = 'text'; } if (isset($setting['options'])) { $context['settings'][$i]['type'] = 'list'; } $context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']]; } // Do we support variants? if (!empty($settings['theme_variants'])) { $context['theme_variants'] = array(); foreach ($settings['theme_variants'] as $variant) { // Have any text, old chap? $context['theme_variants'][$variant] = array('label' => isset($txt['variant_' . $variant]) ? $txt['variant_' . $variant] : $variant, 'thumbnail' => !file_exists($settings['theme_dir'] . '/images/thumbnail.gif') || file_exists($settings['theme_dir'] . '/images/thumbnail_' . $variant . '.gif') ? $settings['images_url'] . '/thumbnail_' . $variant . '.gif' : $settings['images_url'] . '/thumbnail.gif'); } $context['default_variant'] = !empty($settings['default_variant']) && isset($context['theme_variants'][$settings['default_variant']]) ? $settings['default_variant'] : $settings['theme_variants'][0]; } // Restore the current theme. loadTheme($old_id, false); // Reinit just incase. loadSubTemplate('init', 'ignore'); $settings = $old_settings; loadTemplate('Themes'); }
function SetThemeSettings() { global $txt, $sc, $context, $settings, $db_prefix, $modSettings; if (empty($_GET['th']) && empty($_GET['id'])) { return ThemeAdmin(); } $_GET['th'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; // Select the best fitting tab. $context['admin_tabs']['tabs']['list']['is_selected'] = true; loadLanguage('Admin'); isAllowedTo('admin_forum'); // Just for navigation, show some nice bar on the left. adminIndex($settings['theme_id'] == $_GET['th'] ? 'edit_theme_settings' : 'manage_themes'); // Validate inputs/user. if (empty($_GET['th'])) { fatal_lang_error('theme3', false); } // Submitting! if (isset($_POST['submit'])) { checkSession(); if (empty($_POST['options'])) { $_POST['options'] = array(); } if (empty($_POST['default_options'])) { $_POST['default_options'] = array(); } // Set up the sql query. $setString = ''; foreach ($_POST['options'] as $opt => $val) { $setString .= "\n\t\t\t\t(0, {$_GET['th']}, SUBSTRING('{$opt}', 1, 255), SUBSTRING('" . (is_array($val) ? implode(',', $val) : $val) . "', 1, 65534)),"; } foreach ($_POST['default_options'] as $opt => $val) { $setString .= "\n\t\t\t\t(0, 1, SUBSTRING('{$opt}', 1, 255), SUBSTRING('" . (is_array($val) ? implode(',', $val) : $val) . "', 1, 65534)),"; } // If we're actually inserting something.. if ($setString != '') { // Get rid of the last comma. $setString = substr($setString, 0, -1); db_query("\n\t\t\t\tREPLACE INTO {$db_prefix}themes\n\t\t\t\t\t(ID_MEMBER, ID_THEME, variable, value)\n\t\t\t\tVALUES {$setString}", __FILE__, __LINE__); } cache_put_data('theme_settings-' . $_GET['th'], null, 90); cache_put_data('theme_settings-1', null, 90); redirectexit('action=theme;sa=settings;th=' . $_GET['th'] . ';sesc=' . $sc); } checkSession('get'); // Fetch the smiley sets... $sets = explode(',', 'none,' . $modSettings['smiley_sets_known']); $set_names = explode("\n", $txt['smileys_none'] . "\n" . $modSettings['smiley_sets_names']); $context['smiley_sets'] = array('' => $txt['smileys_no_default']); foreach ($sets as $i => $set) { $context['smiley_sets'][$set] = $set_names[$i]; } $old_id = $settings['theme_id']; $old_settings = $settings; loadTheme($_GET['th'], false); // Let the theme take care of the settings. loadTemplate('Settings'); loadSubTemplate('settings'); $context['sub_template'] = 'set_settings'; $context['page_title'] = $txt['theme4']; foreach ($settings as $setting => $dummy) { if (!in_array($setting, array('theme_url', 'theme_dir', 'images_url'))) { $settings[$setting] = htmlspecialchars($settings[$setting]); } } $context['settings'] = $context['theme_settings']; $context['theme_settings'] = $settings; foreach ($context['settings'] as $i => $setting) { if (!isset($setting['type']) || $setting['type'] == 'bool') { $context['settings'][$i]['type'] = 'checkbox'; } elseif ($setting['type'] == 'int' || $setting['type'] == 'integer') { $context['settings'][$i]['type'] = 'number'; } elseif ($setting['type'] == 'string') { $context['settings'][$i]['type'] = 'text'; } if (isset($setting['options'])) { $context['settings'][$i]['type'] = 'list'; } $context['settings'][$i]['value'] = !isset($settings[$setting['id']]) ? '' : $settings[$setting['id']]; } // Restore the current theme. loadTheme($old_id, false); $settings = $old_settings; loadTemplate('Themes'); }