if ($mybb->request_method == "post") { // Remove special characters $mybb->input['name'] = preg_replace('#([^a-z0-9-_\\.]+)#i', '', $mybb->input['name']); if (!$mybb->input['name'] || $mybb->input['name'] == ".css") { $errors[] = $lang->error_missing_stylesheet_name; } // Get 30 chars only because we don't want more than that $mybb->input['name'] = my_substr($mybb->input['name'], 0, 30); if (get_extension($mybb->input['name']) != "css") { // Does not end with '.css' $errors[] = $lang->sprintf($lang->error_missing_stylesheet_extension, $mybb->input['name']); } if (!$errors) { if ($mybb->input['add_type'] == 1) { // Import from a current stylesheet $parent_list = make_parent_theme_list($theme['tid']); $parent_list = implode(',', $parent_list); $query = $db->simple_select("themestylesheets", "stylesheet", "name='" . $db->escape_string($mybb->input['import']) . "' AND tid IN ({$parent_list})", array('limit' => 1, 'order_by' => 'tid', 'order_dir' => 'desc')); $stylesheet = $db->fetch_field($query, "stylesheet"); } else { // Custom stylesheet $stylesheet = $mybb->input['stylesheet']; } $attached = array(); if ($mybb->input['attach'] == 1) { // Our stylesheet is attached to custom pages in MyBB foreach ($mybb->input as $id => $value) { $actions_list = ""; $attached_to = ""; if (strpos($id, 'attached_') !== false) { // We have a custom attached file
function make_parent_theme_list($tid) { static $themes_by_parent; $themes = array(); if (!is_array($themes_by_parent)) { $theme_cache = cache_themes(); foreach ($theme_cache as $key => $theme) { if ($key == "default") { continue; } $themes_by_parent[$theme['tid']][$theme['pid']] = $theme; } } if (!isset($themes_by_parent[$tid])) { return false; } reset($themes_by_parent); reset($themes_by_parent[$tid]); $themes = array(); foreach ($themes_by_parent[$tid] as $key => $theme) { $themes[] = $theme['tid']; $parents = make_parent_theme_list($theme['pid']); if (is_array($parents)) { $themes = array_merge($themes, $parents); } } return $themes; }