/**
  * Load all the style sheets and apply the needed replacements
  * @param $plugin_name
  * @param $format
  * @param $template
  * @return string
  */
 public function load($plugin_name, $format, $template)
 {
     global $conf;
     //reusue the CSS dispatcher functions without triggering the main function
     define('SIMPLE_TEST', 1);
     require_once DOKU_INC . 'lib/exe/css.php';
     // Always only use small letters in format
     $format = strtolower($format);
     // prepare CSS files
     $files = array_merge(array(DOKU_INC . 'lib/styles/screen.css' => DOKU_BASE . 'lib/styles/', DOKU_INC . 'lib/styles/print.css' => DOKU_BASE . 'lib/styles/'), css_pluginstyles('all'), $this->css_pluginFormatStyles($format), array(DOKU_PLUGIN . $plugin_name . '/conf/style.css' => DOKU_BASE . 'lib/plugins/' . $plugin_name . '/conf/', DOKU_PLUGIN . $plugin_name . '/tpl/' . $template . '/style.css' => DOKU_BASE . 'lib/plugins/' . $plugin_name . '/tpl/' . $template . '/', DOKU_PLUGIN . $plugin_name . '/conf/style.local.css' => DOKU_BASE . 'lib/plugins/' . $plugin_name . '/conf/'));
     $css = '';
     foreach ($files as $file => $location) {
         $display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
         $css_content = "\n/* XXXXXXXXX {$display} XXXXXXXXX */\n";
         $css_content = css_loadfile($file, $location);
         if (strpos($file, 'screen.css') !== false) {
             $css .= "\n@media screen {\n" . $css_content . "\n}\n";
         } else {
             if (strpos($file, 'style.css') !== false) {
                 $css .= "\n@media screen {\n" . $css_content . "\n}\n";
             } else {
                 if (strpos($file, $format . '.css') !== false) {
                     $css .= "\n@media print {\n" . $css_content . "\n}\n";
                 } else {
                     if (strpos($file, 'print.css') !== false) {
                         $css .= "\n@media print {\n" . $css_content . "\n}\n";
                     } else {
                         $css .= $css_content;
                     }
                 }
             }
         }
     }
     if (function_exists('css_parseless')) {
         // apply pattern replacements
         $styleini = css_styleini($conf['template']);
         $css = css_applystyle($css, $styleini['replacements']);
         // parse less
         $css = css_parseless($css);
     } else {
         // @deprecated 2013-12-19: fix backward compatibility
         $css = css_applystyle($css, DOKU_INC . 'lib/tpl/' . $conf['template'] . '/');
     }
     return $css;
 }
Example #2
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function css_out()
{
    global $conf;
    global $lang;
    global $config_cascade;
    global $INPUT;
    if ($INPUT->str('s') == 'feed') {
        $mediatypes = array('feed');
        $type = 'feed';
    } else {
        $mediatypes = array('screen', 'all', 'print');
        $type = '';
    }
    // decide from where to get the template
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $INPUT->str('t')));
    if (!$tpl) {
        $tpl = $conf['template'];
    }
    // The generated script depends on some dynamic options
    $cache = new cache('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . $INPUT->int('preview') . DOKU_BASE . $tpl . $type, '.css');
    // load styl.ini
    $styleini = css_styleini($tpl, $INPUT->bool('preview'));
    // cache influencers
    $tplinc = tpl_incdir($tpl);
    $cache_files = getConfigFiles('main');
    $cache_files[] = $tplinc . 'style.ini';
    $cache_files[] = DOKU_CONF . "tpl/{$tpl}/style.ini";
    $cache_files[] = __FILE__;
    if ($INPUT->bool('preview')) {
        $cache_files[] = $conf['cachedir'] . '/preview.ini';
    }
    // Array of needed files and their web locations, the latter ones
    // are needed to fix relative paths in the stylesheets
    $files = array();
    foreach ($mediatypes as $mediatype) {
        $files[$mediatype] = array();
        // load core styles
        $files[$mediatype][DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/';
        // load jQuery-UI theme
        if ($mediatype == 'screen') {
            $files[$mediatype][DOKU_INC . 'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE . 'lib/scripts/jquery/jquery-ui-theme/';
        }
        // load plugin styles
        $files[$mediatype] = array_merge($files[$mediatype], css_pluginstyles($mediatype));
        // load template styles
        if (isset($styleini['stylesheets'][$mediatype])) {
            $files[$mediatype] = array_merge($files[$mediatype], $styleini['stylesheets'][$mediatype]);
        }
        // load user styles
        if (!empty($config_cascade['userstyle'][$mediatype])) {
            foreach ($config_cascade['userstyle'][$mediatype] as $userstyle) {
                $files[$mediatype][$userstyle] = DOKU_BASE;
            }
        }
        $cache_files = array_merge($cache_files, array_keys($files[$mediatype]));
    }
    // check cache age & handle conditional request
    // This may exit if a cache can be used
    http_cached($cache->cache, $cache->useCache(array('files' => $cache_files)));
    // start output buffering
    ob_start();
    // build the stylesheet
    foreach ($mediatypes as $mediatype) {
        // print the default classes for interwiki links and file downloads
        if ($mediatype == 'screen') {
            print '@media screen {';
            css_interwiki();
            css_filetypes();
            print '}';
        }
        // load files
        $css_content = '';
        foreach ($files[$mediatype] as $file => $location) {
            $display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
            $css_content .= "\n/* XXXXXXXXX {$display} XXXXXXXXX */\n";
            $css_content .= css_loadfile($file, $location);
        }
        switch ($mediatype) {
            case 'screen':
                print NL . '@media screen { /* START screen styles */' . NL . $css_content . NL . '} /* /@media END screen styles */' . NL;
                break;
            case 'print':
                print NL . '@media print { /* START print styles */' . NL . $css_content . NL . '} /* /@media END print styles */' . NL;
                break;
            case 'all':
            case 'feed':
            default:
                print NL . '/* START rest styles */ ' . NL . $css_content . NL . '/* END rest styles */' . NL;
                break;
        }
    }
    // end output buffering and get contents
    $css = ob_get_contents();
    ob_end_clean();
    // strip any source maps
    stripsourcemaps($css);
    // apply style replacements
    $css = css_applystyle($css, $styleini['replacements']);
    // parse less
    $css = css_parseless($css);
    // compress whitespace and comments
    if ($conf['compress']) {
        $css = css_compress($css);
    }
    // embed small images right into the stylesheet
    if ($conf['cssdatauri']) {
        $base = preg_quote(DOKU_BASE, '#');
        $css = preg_replace_callback('#(url\\([ \'"]*)(' . $base . ')(.*?(?:\\.(png|gif)))#i', 'css_datauri', $css);
    }
    http_cached_finish($cache->cache, $css);
}
Example #3
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function css_out()
{
    global $conf;
    global $lang;
    global $config_cascade;
    $mediatype = 'screen';
    if (isset($_REQUEST['s']) && in_array($_REQUEST['s'], array('all', 'print', 'feed'))) {
        $mediatype = $_REQUEST['s'];
    }
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $_REQUEST['t']));
    if ($tpl) {
        $tplinc = DOKU_INC . 'lib/tpl/' . $tpl . '/';
        $tpldir = DOKU_BASE . 'lib/tpl/' . $tpl . '/';
    } else {
        $tplinc = DOKU_TPLINC;
        $tpldir = DOKU_TPL;
    }
    // The generated script depends on some dynamic options
    $cache = new cache('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tplinc . $mediatype, '.css');
    // load template styles
    $tplstyles = array();
    if (@file_exists($tplinc . 'style.ini')) {
        $ini = parse_ini_file($tplinc . 'style.ini', true);
        foreach ($ini['stylesheets'] as $file => $mode) {
            $tplstyles[$mode][$tplinc . $file] = $tpldir;
        }
    }
    // Array of needed files and their web locations, the latter ones
    // are needed to fix relative paths in the stylesheets
    $files = array();
    // load core styles
    $files[DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/';
    // load jQuery-UI theme
    $files[DOKU_INC . 'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE . 'lib/scripts/jquery/jquery-ui-theme/';
    // load plugin styles
    $files = array_merge($files, css_pluginstyles($mediatype));
    // load template styles
    if (isset($tplstyles[$mediatype])) {
        $files = array_merge($files, $tplstyles[$mediatype]);
    }
    // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility
    if (isset($config_cascade['userstyle']['default'])) {
        $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default'];
    }
    // load user styles
    if (isset($config_cascade['userstyle'][$mediatype])) {
        $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE;
    }
    // load rtl styles
    // @todo: this currently adds the rtl styles only to the 'screen' media type
    //        but 'print' and 'all' should also be supported
    if ($mediatype == 'screen') {
        if ($lang['direction'] == 'rtl') {
            if (isset($tplstyles['rtl'])) {
                $files = array_merge($files, $tplstyles['rtl']);
            }
        }
    }
    $cache_files = array_merge(array_keys($files), getConfigFiles('main'));
    $cache_files[] = $tplinc . 'style.ini';
    $cache_files[] = __FILE__;
    // check cache age & handle conditional request
    // This may exit if a cache can be used
    http_cached($cache->cache, $cache->useCache(array('files' => $cache_files)));
    // start output buffering and build the stylesheet
    ob_start();
    // print the default classes for interwiki links and file downloads
    css_interwiki();
    css_filetypes();
    // load files
    foreach ($files as $file => $location) {
        print css_loadfile($file, $location);
    }
    // end output buffering and get contents
    $css = ob_get_contents();
    ob_end_clean();
    // apply style replacements
    $css = css_applystyle($css, $tplinc);
    // place all @import statements at the top of the file
    $css = css_moveimports($css);
    // compress whitespace and comments
    if ($conf['compress']) {
        $css = css_compress($css);
    }
    // embed small images right into the stylesheet
    if ($conf['cssdatauri']) {
        $base = preg_quote(DOKU_BASE, '#');
        $css = preg_replace_callback('#(url\\([ \'"]*)(' . $base . ')(.*?(?:\\.(png|gif)))#i', 'css_datauri', $css);
    }
    http_cached_finish($cache->cache, $css);
}
Example #4
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function css_out()
{
    global $conf;
    global $lang;
    global $config_cascade;
    $mediatype = 'screen';
    if (isset($_REQUEST['s']) && in_array($_REQUEST['s'], array('all', 'print', 'feed'))) {
        $mediatype = $_REQUEST['s'];
    }
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $_REQUEST['t']));
    if ($tpl) {
        $tplinc = DOKU_INC . 'lib/tpl/' . $tpl . '/';
        $tpldir = DOKU_BASE . 'lib/tpl/' . $tpl . '/';
    } else {
        $tplinc = DOKU_TPLINC;
        $tpldir = DOKU_TPL;
    }
    // The generated script depends on some dynamic options
    $cache = getCacheName('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tplinc . $mediatype, '.css');
    // load template styles
    $tplstyles = array();
    if (@file_exists($tplinc . 'style.ini')) {
        $ini = parse_ini_file($tplinc . 'style.ini', true);
        foreach ($ini['stylesheets'] as $file => $mode) {
            $tplstyles[$mode][$tplinc . $file] = $tpldir;
        }
    }
    // Array of needed files and their web locations, the latter ones
    // are needed to fix relative paths in the stylesheets
    $files = array();
    // load core styles
    $files[DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/';
    // load plugin styles
    $files = array_merge($files, css_pluginstyles($mediatype));
    // load template styles
    if (isset($tplstyles[$mediatype])) {
        $files = array_merge($files, $tplstyles[$mediatype]);
    }
    // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility
    if (isset($config_cascade['userstyle']['default'])) {
        $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default'];
    }
    // load user styles
    if (isset($config_cascade['userstyle'][$mediatype])) {
        $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE;
    }
    // load rtl styles
    // @todo: this currently adds the rtl styles only to the 'screen' media type
    //        but 'print' and 'all' should also be supported
    if ($mediatype == 'screen') {
        if ($lang['direction'] == 'rtl') {
            if (isset($tplstyles['rtl'])) {
                $files = array_merge($files, $tplstyles['rtl']);
            }
        }
    }
    // check cache age & handle conditional request
    header('Cache-Control: public, max-age=3600');
    header('Pragma: public');
    if (css_cacheok($cache, array_keys($files), $tplinc)) {
        http_conditionalRequest(filemtime($cache));
        if ($conf['allowdebug']) {
            header("X-CacheUsed: {$cache}");
        }
        // finally send output
        if ($conf['gzip_output'] && http_gzip_valid($cache)) {
            header('Vary: Accept-Encoding');
            header('Content-Encoding: gzip');
            readfile($cache . ".gz");
        } else {
            if (!http_sendfile($cache)) {
                readfile($cache);
            }
        }
        return;
    } else {
        http_conditionalRequest(time());
    }
    // start output buffering and build the stylesheet
    ob_start();
    // print the default classes for interwiki links and file downloads
    css_interwiki();
    css_filetypes();
    // load files
    foreach ($files as $file => $location) {
        print css_loadfile($file, $location);
    }
    // end output buffering and get contents
    $css = ob_get_contents();
    ob_end_clean();
    // apply style replacements
    $css = css_applystyle($css, $tplinc);
    // place all @import statements at the top of the file
    $css = css_moveimports($css);
    // compress whitespace and comments
    if ($conf['compress']) {
        $css = css_compress($css);
    }
    // save cache file
    io_saveFile($cache, $css);
    if (function_exists('gzopen')) {
        io_saveFile("{$cache}.gz", $css);
    }
    // finally send output
    if ($conf['gzip_output']) {
        header('Vary: Accept-Encoding');
        header('Content-Encoding: gzip');
        print gzencode($css, 9, FORCE_GZIP);
    } else {
        print $css;
    }
}
Example #5
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function epub_css_out($path)
{
    global $conf;
    global $lang;
    global $config_cascade;
    $mediatype = 'screen';
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $conf['template']));
    if ($tpl) {
        $tplinc = DOKU_INC . 'lib/tpl/' . $tpl . '/';
        $tpldir = DOKU_BASE . 'lib/tpl/' . $tpl . '/';
    } else {
        $tplinc = DOKU_TPLINC;
        $tpldir = DOKU_TPL;
    }
    // load template styles
    $tplstyles = array();
    if (@file_exists($tplinc . 'style.ini')) {
        $ini = parse_ini_file($tplinc . 'style.ini', true);
        foreach ($ini['stylesheets'] as $file => $mode) {
            $tplstyles[$mode][$tplinc . $file] = $tpldir;
        }
    }
    // Array of needed files and their web locations, the latter ones
    // are needed to fix relative paths in the stylesheets
    $files = array();
    $files[DOKU_INC . 'lib/styles/style.css'] = DOKU_BASE . 'lib/styles/';
    // load plugin, template, user styles
    $files = array_merge($files, css_pluginstyles('screen'));
    $files = array_merge($files, css_pluginstyles('all'));
    if (isset($tplstyles['screen'])) {
        $files = array_merge($files, $tplstyles['screen']);
    }
    if ($lang['direction'] == 'rtl') {
        if (isset($tplstyles['rtl'])) {
            $files = array_merge($files, $tplstyles['rtl']);
        }
    }
    if (isset($config_cascade['userstyle']['default'])) {
        $files[$config_cascade['userstyle']['default']] = DOKU_BASE;
    }
    if (isset($tplstyles[$mediatype])) {
        $files = array_merge($files, $tplstyles[$mediatype]);
    }
    // load user styles
    if (isset($config_cascade['userstyle'][$mediatype])) {
        $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE;
    }
    // load files
    $css = "";
    foreach ($files as $file => $location) {
        $css .= css_loadfile($file, $location);
    }
    // apply style replacements
    $css = css_applystyle($css, $tplinc);
    // place all @import statements at the top of the file
    $css = css_moveimports($css);
    io_saveFile($path . 'Styles/style.css', $css);
}
Example #6
0
 /**
  * Load all the style sheets and apply the needed replacements
  */
 protected function load_css()
 {
     global $conf;
     //reusue the CSS dispatcher functions without triggering the main function
     define('SIMPLE_TEST', 1);
     require_once DOKU_INC . 'lib/exe/css.php';
     // prepare CSS files
     $files = array_merge(array(DOKU_INC . 'lib/styles/screen.css' => DOKU_BASE . 'lib/styles/', DOKU_INC . 'lib/styles/print.css' => DOKU_BASE . 'lib/styles/'), css_pluginstyles('all'), $this->css_pluginPDFstyles(), array(DOKU_PLUGIN . 'dw2pdf/conf/style.css' => DOKU_BASE . 'lib/plugins/dw2pdf/conf/', DOKU_PLUGIN . 'dw2pdf/tpl/' . $this->tpl . '/style.css' => DOKU_BASE . 'lib/plugins/dw2pdf/tpl/' . $this->tpl . '/', DOKU_PLUGIN . 'dw2pdf/conf/style.local.css' => DOKU_BASE . 'lib/plugins/dw2pdf/conf/'));
     $css = '';
     foreach ($files as $file => $location) {
         $display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
         $css .= "\n/* XXXXXXXXX {$display} XXXXXXXXX */\n";
         $css .= css_loadfile($file, $location);
     }
     if (function_exists('css_parseless')) {
         // apply pattern replacements
         $styleini = css_styleini($conf['template']);
         $css = css_applystyle($css, $styleini['replacements']);
         // parse less
         $css = css_parseless($css);
     } else {
         // @deprecated 2013-12-19: fix backward compatibility
         $css = css_applystyle($css, DOKU_INC . 'lib/tpl/' . $conf['template'] . '/');
     }
     return $css;
 }
Example #7
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function epub_css_out($path)
{
    global $conf;
    global $lang;
    global $config_cascade;
    global $INPUT;
    $mediatypes = array('screen', 'all');
    $type = '';
    // decide from where to get the template
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $INPUT->str('t')));
    if (!$tpl) {
        $tpl = $conf['template'];
    }
    // load styl.ini
    $styleini = css_styleini($tpl);
    // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility
    if (isset($config_cascade['userstyle']['default'])) {
        $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default'];
    }
    // Array of needed files and their web locations, the latter ones
    // are needed to fix relative paths in the stylesheets
    $files = array();
    foreach ($mediatypes as $mediatype) {
        $files[$mediatype] = array();
        // load core styles
        $files[$mediatype][DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/';
        // load jQuery-UI theme
        if ($mediatype == 'screen') {
            $files[$mediatype][DOKU_INC . 'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE . 'lib/scripts/jquery/jquery-ui-theme/';
        }
        // load plugin styles
        $files[$mediatype] = array_merge($files[$mediatype], css_pluginstyles($mediatype));
        // load template styles
        if (isset($styleini['stylesheets'][$mediatype])) {
            $files[$mediatype] = array_merge($files[$mediatype], $styleini['stylesheets'][$mediatype]);
        }
        // load user styles
        if (isset($config_cascade['userstyle'][$mediatype])) {
            $files[$mediatype][$config_cascade['userstyle'][$mediatype]] = DOKU_BASE;
        }
    }
    $css = "";
    // build the stylesheet
    foreach ($mediatypes as $mediatype) {
        // print the default classes for interwiki links and file downloads
        if ($mediatype == 'screen') {
            $css .= '@media screen {';
            css_interwiki($css);
            css_filetypes($css);
            $css .= '}';
        }
        // load files
        $css_content = '';
        foreach ($files[$mediatype] as $file => $location) {
            $display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
            $css_content .= "\n/* XXXXXXXXX {$display} XXXXXXXXX */\n";
            $css_content .= css_loadfile($file, $location);
        }
        switch ($mediatype) {
            case 'screen':
                $css .= NL . '@media screen { /* START screen styles */' . NL . $css_content . NL . '} /* /@media END screen styles */' . NL;
                break;
            case 'all':
            default:
                $css .= NL . '/* START rest styles */ ' . NL . $css_content . NL . '/* END rest styles */' . NL;
                break;
        }
    }
    // apply style replacements
    $css .= css_applystyle($css, $styleini['replacements']);
    // parse less
    $css = css_parseless($css);
    // embed small images right into the stylesheet
    if ($conf['cssdatauri']) {
        $base = preg_quote(DOKU_BASE, '#');
        $css = preg_replace_callback('#(url\\([ \'"]*)(' . $base . ')(.*?(?:\\.(png|gif)))#i', 'css_datauri', $css);
    }
    io_saveFile($path . 'Styles/style.css', $css);
}
Example #8
0
 /**
  * Load all the style sheets and apply the needed replacements
  */
 protected function load_css()
 {
     //reusue the CSS dispatcher functions without triggering the main function
     define('SIMPLE_TEST', 1);
     require_once DOKU_INC . 'lib/exe/css.php';
     // prepare CSS files
     $files = array_merge(array(DOKU_INC . 'lib/styles/screen.css' => DOKU_BASE . 'lib/styles/', DOKU_INC . 'lib/styles/print.css' => DOKU_BASE . 'lib/styles/'), css_pluginstyles('all'), $this->css_pluginPDFstyles(), array(DOKU_PLUGIN . 'dw2pdf/conf/style.css' => DOKU_BASE . 'lib/plugins/dw2pdf/conf/', DOKU_PLUGIN . 'dw2pdf/tpl/' . $this->tpl . '/style.css' => DOKU_BASE . 'lib/plugins/dw2pdf/tpl/' . $this->tpl . '/', DOKU_PLUGIN . 'dw2pdf/conf/style.local.css' => DOKU_BASE . 'lib/plugins/dw2pdf/conf/'));
     $css = '';
     foreach ($files as $file => $location) {
         $css .= css_loadfile($file, $location);
     }
     // apply pattern replacements
     $css = css_applystyle($css, DOKU_INC . 'lib/tpl/' . $conf['template'] . '/');
     return $css;
 }
Example #9
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function css_out()
{
    global $conf;
    global $lang;
    global $config_cascade;
    global $INPUT;
    if ($INPUT->str('s') == 'feed') {
        $mediatypes = array('feed');
        $type = 'feed';
    } else {
        $mediatypes = array('screen', 'all', 'print');
        $type = '';
    }
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $INPUT->str('t')));
    if ($tpl) {
        $tplinc = DOKU_INC . 'lib/tpl/' . $tpl . '/';
        $tpldir = DOKU_BASE . 'lib/tpl/' . $tpl . '/';
    } else {
        $tplinc = tpl_incdir();
        $tpldir = tpl_basedir();
    }
    // used style.ini file
    $styleini = css_styleini($tplinc);
    // The generated script depends on some dynamic options
    $cache = new cache('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tplinc . $type, '.css');
    // load template styles
    $tplstyles = array();
    if ($styleini) {
        foreach ($styleini['stylesheets'] as $file => $mode) {
            $tplstyles[$mode][$tplinc . $file] = $tpldir;
        }
    }
    // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility
    if (isset($config_cascade['userstyle']['default'])) {
        $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default'];
    }
    // Array of needed files and their web locations, the latter ones
    // are needed to fix relative paths in the stylesheets
    $files = array();
    $cache_files = getConfigFiles('main');
    $cache_files[] = $tplinc . 'style.ini';
    $cache_files[] = $tplinc . 'style.local.ini';
    $cache_files[] = __FILE__;
    foreach ($mediatypes as $mediatype) {
        $files[$mediatype] = array();
        // load core styles
        $files[$mediatype][DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/';
        // load jQuery-UI theme
        if ($mediatype == 'screen') {
            $files[$mediatype][DOKU_INC . 'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE . 'lib/scripts/jquery/jquery-ui-theme/';
        }
        // load plugin styles
        $files[$mediatype] = array_merge($files[$mediatype], css_pluginstyles($mediatype));
        // load template styles
        if (isset($tplstyles[$mediatype])) {
            $files[$mediatype] = array_merge($files[$mediatype], $tplstyles[$mediatype]);
        }
        // load user styles
        if (isset($config_cascade['userstyle'][$mediatype])) {
            $files[$mediatype][$config_cascade['userstyle'][$mediatype]] = DOKU_BASE;
        }
        // load rtl styles
        // note: this adds the rtl styles only to the 'screen' media type
        // @deprecated 2012-04-09: rtl will cease to be a mode of its own,
        //     please use "[dir=rtl]" in any css file in all, screen or print mode instead
        if ($mediatype == 'screen') {
            if ($lang['direction'] == 'rtl') {
                if (isset($tplstyles['rtl'])) {
                    $files[$mediatype] = array_merge($files[$mediatype], $tplstyles['rtl']);
                }
                if (isset($config_cascade['userstyle']['rtl'])) {
                    $files[$mediatype][$config_cascade['userstyle']['rtl']] = DOKU_BASE;
                }
            }
        }
        $cache_files = array_merge($cache_files, array_keys($files[$mediatype]));
    }
    // check cache age & handle conditional request
    // This may exit if a cache can be used
    http_cached($cache->cache, $cache->useCache(array('files' => $cache_files)));
    // start output buffering
    ob_start();
    // build the stylesheet
    foreach ($mediatypes as $mediatype) {
        // print the default classes for interwiki links and file downloads
        if ($mediatype == 'screen') {
            print '@media screen {';
            css_interwiki();
            css_filetypes();
            print '}';
        }
        // load files
        $css_content = '';
        foreach ($files[$mediatype] as $file => $location) {
            $css_content .= css_loadfile($file, $location);
        }
        switch ($mediatype) {
            case 'screen':
                print NL . '@media screen { /* START screen styles */' . NL . $css_content . NL . '} /* /@media END screen styles */' . NL;
                break;
            case 'print':
                print NL . '@media print { /* START print styles */' . NL . $css_content . NL . '} /* /@media END print styles */' . NL;
                break;
            case 'all':
            case 'feed':
            default:
                print NL . '/* START rest styles */ ' . NL . $css_content . NL . '/* END rest styles */' . NL;
                break;
        }
    }
    // end output buffering and get contents
    $css = ob_get_contents();
    ob_end_clean();
    // apply style replacements
    $css = css_applystyle($css, $tplinc);
    // place all @import statements at the top of the file
    $css = css_moveimports($css);
    // compress whitespace and comments
    if ($conf['compress']) {
        $css = css_compress($css);
    }
    // embed small images right into the stylesheet
    if ($conf['cssdatauri']) {
        $base = preg_quote(DOKU_BASE, '#');
        $css = preg_replace_callback('#(url\\([ \'"]*)(' . $base . ')(.*?(?:\\.(png|gif)))#i', 'css_datauri', $css);
    }
    http_cached_finish($cache->cache, $css);
}
Example #10
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function css_out()
{
    global $conf;
    global $lang;
    switch ($_REQUEST['s']) {
        case 'all':
        case 'print':
        case 'feed':
            $style = $_REQUEST['s'];
            break;
        default:
            $style = '';
            break;
    }
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $_REQUEST['t']));
    if ($tpl) {
        $tplinc = DOKU_INC . 'lib/tpl/' . $tpl . '/';
        $tpldir = DOKU_BASE . 'lib/tpl/' . $tpl . '/';
    } else {
        $tplinc = DOKU_TPLINC;
        $tpldir = DOKU_TPL;
    }
    // The generated script depends on some dynamic options
    $cache = getCacheName('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tplinc . $style, '.css');
    // load template styles
    $tplstyles = array();
    if (@file_exists($tplinc . 'style.ini')) {
        $ini = parse_ini_file($tplinc . 'style.ini', true);
        foreach ($ini['stylesheets'] as $file => $mode) {
            $tplstyles[$mode][$tplinc . $file] = $tpldir;
        }
    }
    // Array of needed files and their web locations, the latter ones
    // are needed to fix relative paths in the stylesheets
    $files = array();
    //if (isset($tplstyles['all'])) $files = array_merge($files, $tplstyles['all']);
    if (!empty($style)) {
        $files[DOKU_INC . 'lib/styles/' . $style . '.css'] = DOKU_BASE . 'lib/styles/';
        // load plugin, template, user styles
        $files = array_merge($files, css_pluginstyles($style));
        if (isset($tplstyles[$style])) {
            $files = array_merge($files, $tplstyles[$style]);
        }
        $files[DOKU_CONF . 'user' . $style . '.css'] = DOKU_BASE;
    } else {
        $files[DOKU_INC . 'lib/styles/style.css'] = DOKU_BASE . 'lib/styles/';
        if ($conf['spellchecker']) {
            $files[DOKU_INC . 'lib/styles/spellcheck.css'] = DOKU_BASE . 'lib/styles/';
        }
        // load plugin, template, user styles
        $files = array_merge($files, css_pluginstyles('screen'));
        if (isset($tplstyles['screen'])) {
            $files = array_merge($files, $tplstyles['screen']);
        }
        if ($lang['direction'] == 'rtl') {
            if (isset($tplstyles['rtl'])) {
                $files = array_merge($files, $tplstyles['rtl']);
            }
        }
        $files[DOKU_CONF . 'userstyle.css'] = DOKU_BASE;
    }
    // check cache age & handle conditional request
    header('Cache-Control: public, max-age=3600');
    header('Pragma: public');
    if (css_cacheok($cache, array_keys($files), $tplinc)) {
        http_conditionalRequest(filemtime($cache));
        if ($conf['allowdebug']) {
            header("X-CacheUsed: {$cache}");
        }
        // finally send output
        if ($conf['gzip_output'] && http_gzip_valid($cache)) {
            header('Vary: Accept-Encoding');
            header('Content-Encoding: gzip');
            readfile($cache . ".gz");
        } else {
            if (!http_sendfile($cache)) {
                readfile($cache);
            }
        }
        return;
    } else {
        http_conditionalRequest(time());
    }
    // start output buffering and build the stylesheet
    ob_start();
    // print the default classes for interwiki links and file downloads
    css_interwiki();
    css_filetypes();
    // load files
    foreach ($files as $file => $location) {
        print css_loadfile($file, $location);
    }
    // end output buffering and get contents
    $css = ob_get_contents();
    ob_end_clean();
    // apply style replacements
    $css = css_applystyle($css, $tplinc);
    // compress whitespace and comments
    if ($conf['compress']) {
        $css = css_compress($css);
    }
    // save cache file
    io_saveFile($cache, $css);
    copy($cache, "compress.zlib://{$cache}.gz");
    // finally send output
    if ($conf['gzip_output']) {
        header('Vary: Accept-Encoding');
        header('Content-Encoding: gzip');
        print gzencode($css, 9, FORCE_GZIP);
    } else {
        print $css;
    }
}