Beispiel #1
0
<?php

/**
 * MyBB 1.8
 * Copyright 2014 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybb.com
 * License: http://www.mybb.com/about/license
 *
 */
define("IN_MYBB", 1);
define("NO_ONLINE", 1);
define('THIS_SCRIPT', 'css.php');
require_once "./inc/init.php";
require_once MYBB_ROOT . $config['admin_dir'] . '/inc/functions_themes.php';
$stylesheet = $mybb->get_input('stylesheet', MyBB::INPUT_INT);
if ($stylesheet) {
    $options = array("limit" => 1);
    $query = $db->simple_select("themestylesheets", "stylesheet", "sid=" . $stylesheet, $options);
    $stylesheet = $db->fetch_field($query, "stylesheet");
    $plugins->run_hooks("css_start");
    if (!empty($mybb->settings['minifycss'])) {
        $stylesheet = minify_stylesheet($stylesheet);
    }
    $plugins->run_hooks("css_end");
    header("Content-type: text/css");
    echo $stylesheet;
}
exit;
/**
 * Caches a stylesheet to the file system.
 *
 * @param string $tid The theme ID this stylesheet belongs to.
 * @param string $filename The name of the stylesheet.
 * @param string $stylesheet The contents of the stylesheet.
 *
 * @return string The cache file path.
 */
function cache_stylesheet($tid, $filename, $stylesheet)
{
    global $mybb;
    $filename = str_replace('/', '', $filename);
    $tid = (int) $tid;
    $theme_directory = "cache/themes/theme{$tid}";
    // If we're in safe mode save to the main theme folder by default
    if ($mybb->safemode) {
        $theme_directory = "cache/themes";
        $filename = $tid . "_" . $filename;
    } elseif (!is_dir(MYBB_ROOT . $theme_directory)) {
        if (!@mkdir(MYBB_ROOT . $theme_directory)) {
            $theme_directory = "cache/themes";
            $filename = $tid . "_" . $filename;
        } else {
            // Add in empty index.html!
            $fp = @fopen(MYBB_ROOT . $theme_directory . "/index.html", "w");
            @fwrite($fp, "");
            @fclose($fp);
        }
    }
    $theme_vars = array("theme" => $theme_directory);
    $stylesheet = parse_theme_variables($stylesheet, $theme_vars);
    $stylesheet = preg_replace_callback("#url\\((\"|'|)(.*)\\1\\)#", create_function('$matches', 'return fix_css_urls($matches[2]);'), $stylesheet);
    $fp = @fopen(MYBB_ROOT . "{$theme_directory}/{$filename}", "wb");
    if (!$fp) {
        return false;
    }
    @fwrite($fp, $stylesheet);
    @fclose($fp);
    $stylesheet_min = minify_stylesheet($stylesheet);
    $filename_min = str_replace('.css', '.min.css', $filename);
    $fp_min = @fopen(MYBB_ROOT . "{$theme_directory}/{$filename_min}", "wb");
    if (!$fp_min) {
        return false;
    }
    @fwrite($fp_min, $stylesheet_min);
    @fclose($fp_min);
    copy_file_to_cdn(MYBB_ROOT . "{$theme_directory}/{$filename}");
    copy_file_to_cdn(MYBB_ROOT . "{$theme_directory}/{$filename_min}");
    return "{$theme_directory}/{$filename}";
}