} $query = $db->simple_select("themestylesheets", "*", "name='" . $db->escape_string($mybb->input['file']) . "' AND tid IN ({$parent_list})", array('order_by' => 'tid', 'order_dir' => 'desc', 'limit' => 1)); $stylesheet = $db->fetch_array($query); // Does the theme not exist? if (!$stylesheet['sid']) { flash_message($lang->error_invalid_stylesheet, 'error'); admin_redirect("index.php?module=style-themes"); } if ($mybb->request_method == "post") { $sid = $stylesheet['sid']; // Theme & stylesheet theme ID do not match, editing inherited - we copy to local theme if ($theme['tid'] != $stylesheet['tid']) { $sid = copy_stylesheet_to_theme($stylesheet, $theme['tid']); } // Now we have the new stylesheet, save it $updated_stylesheet = array("cachefile" => $db->escape_string($stylesheet['name']), "stylesheet" => $db->escape_string(unfix_css_urls($mybb->input['stylesheet'])), "lastmodified" => TIME_NOW); $db->update_query("themestylesheets", $updated_stylesheet, "sid='{$sid}'"); // Cache the stylesheet to the file if (!cache_stylesheet($theme['tid'], $stylesheet['name'], $mybb->input['stylesheet'])) { $db->update_query("themestylesheets", array('cachefile' => "css.php?stylesheet={$sid}"), "sid='{$sid}'", 1); } // Update the CSS file list for this theme update_theme_stylesheet_list($theme['tid']); $plugins->run_hooks("admin_style_themes_edit_stylesheet_advanced_commit"); // Log admin action log_admin_action(htmlspecialchars_uni($theme['name']), $stylesheet['name']); flash_message($lang->success_stylesheet_updated, 'success'); if (!$mybb->input['save_close']) { admin_redirect("index.php?module=style-themes&action=edit_stylesheet&file=" . htmlspecialchars_uni($stylesheet['name']) . "&tid={$theme['tid']}&mode=advanced"); } else { admin_redirect("index.php?module=style-themes&action=edit&tid={$theme['tid']}");
<?php define("IN_MYBB", 1); define("NO_ONLINE", 1); define('THIS_SCRIPT', 'updatecss.php'); require_once "./inc/init.php"; require_once "./admin/inc/functions_themes.php"; $stylesheet = $mybb->input['stylesheet']; $tid = intval($mybb->input['tid']); $name = $mybb->input['name']; if (empty($tid) || empty($name) || empty($stylesheet)) { exit; } $updated_stylesheet = array("stylesheet" => $db->escape_string(unfix_css_urls($stylesheet)), "lastmodified" => TIME_NOW); if ($db->update_query("themestylesheets", $updated_stylesheet, "tid='{$tid}' AND name='{$db->escape_string($name)}'")) { cache_stylesheet($tid, $name, $stylesheet); }
function resync_stylesheet($stylesheet) { global $db; // Try and fix any missing cache file names if (!$stylesheet['cachefile'] && $stylesheet['name']) { $stylesheet['cachefile'] = $stylesheet['name']; $db->update_query("themestylesheets", array('cachefile' => $db->escape_string($stylesheet['name'])), "sid='{$stylesheet['sid']}'"); } // Still don't have the cache file name or is it not a flat file? Return false if (!$stylesheet['cachefile'] || strpos($stylesheet['cachefile'], 'css.php') !== false) { return false; } if (!file_exists(MYBB_ROOT . "cache/themes/theme{$stylesheet['tid']}/{$stylesheet['name']}") && !file_exists(MYBB_ROOT . "cache/themes/{$stylesheet['tid']}_{$stylesheet['name']}")) { if (cache_stylesheet($stylesheet['tid'], $stylesheet['cachefile'], $stylesheet['stylesheet']) !== false) { $db->update_query("themestylesheets", array('cachefile' => $db->escape_string($stylesheet['name'])), "sid='{$stylesheet['sid']}'"); update_theme_stylesheet_list($stylesheet['tid']); if ($stylesheet['sid'] != 1) { $db->update_query("themestylesheets", array('lastmodified' => TIME_NOW), "sid='{$stylesheet['sid']}'"); } } return true; } else { if ($stylesheet['sid'] != 1 && @filemtime(MYBB_ROOT . "cache/themes/theme{$stylesheet['tid']}/{$stylesheet['name']}") > $stylesheet['lastmodified']) { $contents = unfix_css_urls(file_get_contents(MYBB_ROOT . "cache/themes/theme{$stylesheet['tid']}/{$stylesheet['name']}")); $db->update_query("themestylesheets", array('stylesheet' => $db->escape_string($contents), 'lastmodified' => TIME_NOW), "sid='{$stylesheet['sid']}'", 1); return true; } } return false; }