LuckyCoinkydink/serendipity.css.php
Garvin Hicking dd83225447 This is my proposal on implementing the ability to switch frontend and backend templates independently.
- This introduces a new option "template_backend" that will be set to indicate the backend template, defaults to 2k11.
- The "Engine: xxx" line in info.txt still works, but only for the frontend
- The frontend fallback chain defaults to the old "default" template to ensure that themes will work that have "old-style" HTML output
- The backend fallback chain only falls back to 2k11 and then "default"
- In the future, we will remove templates/default/admin once the mechanism is proven stable

To test this in all cases you can:

- Copy 2k11/ to 2k11-custom, edit info.txt, give it a distinct name. Edit the admin/index.tpl file to add some code to ensure that you will see that template in the backend if you pick it, or adjust the style.css or whatever.
- Copy idea/ to idea-custom, edit info.txt, add a "Engine: 2k11" line. Now you can test how a template would look like that fallsback on 2k11 instead of "default"

Those permutations can be checked and come to my mind:

- Backend: 2k11, Frontend: 2k11
- Backend: 2k11-custom, Frontend: 2k11
- Backend: 2k11, Frontend: 2k11-custom

- Backend: 2k11, Frontend: idea
- Backend: 2k11, Frontend: idea-custom

- Backend: 2k11-custom, Frontend: idea
- Backend: 2k11-custom, Frontend: idea-custom

They seem to work.

Currently the display of backend and frontend theme in templates.inc.tpl takes up some larger space. Maybe it could be prettified somehow, maybe put frontend and backend template next to each other, not beneath each other? Maybe @yellowled has some suggestions.

@onli and @ophian - please have a look at this, since you both also worked on the fallback chains. Please tell me if you have issues with this. We can easily revert, if you see this approach as not workable. This is more a "proof of concept" draft.
2014-05-14 12:58:06 +02:00

123 lines
3.7 KiB
PHP

<?php # $Id$
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
# All rights reserved. See LICENSE file for licensing details
/* This is a small hack to allow CSS display during installations and upgrades */
define('IN_installer', true);
define('IN_upgrader', true);
define('IN_CSS', true);
session_cache_limiter('public');
if (!defined('S9Y_FRAMEWORK')) {
include('serendipity_config.inc.php');
}
if (!isset($css_mode)) {
if (!empty($serendipity['GET']['css_mode'])) {
$css_mode = $serendipity['GET']['css_mode'];
} else {
$css_mode = 'serendipity.css';
}
}
switch($css_mode) {
case 'serendipity.css':
default:
$css_hook = 'css';
$css_file = 'style.css';
break;
case 'serendipity_admin.css':
// This constant is needed to properly set the template context for the backend.
@define('IN_serendipity_admin', true);
$css_hook = 'css_backend';
$css_file = 'admin/style.css';
break;
}
function serendipity_printStylesheet($file, $dir = '') {
global $serendipity;
return "/* $dir */\n" . str_replace(
array(
'{TEMPLATE_PATH}',
'{LANG_DIRECTION}'
),
array(
dirname($dir) . '/',
LANG_DIRECTION
),
@file_get_contents($file, 1));
}
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
header('Cache-Control: no-cache');
} else {
header('Cache-Control:');
header('Pragma:');
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time()+3600));
}
header('Content-type: text/css; charset=' . LANG_CHARSET);
if (IS_installed === false) {
if (file_exists(S9Y_INCLUDE_PATH . 'templates/' . $serendipity['defaultTemplate'] . '/' . $css_file)) {
echo serendipity_printStylesheet('templates/' . $serendipity['defaultTemplate'] . '/' . $css_file, 'templates/' . $serendipity['defaultTemplate'] . '/' . $css_file);
}
die();
}
// Use output buffering to capture all output. This is necessary
// because a plugin might call 'echo' directly instead of adding
// the desired output to the hook parameter '$out'.
ob_start();
// First all of our fallback classes, so they can be overridden by the usual template.
$out = serendipity_printStylesheet(
serendipity_getTemplateFile('style_fallback.css', 'serendipityPath'),
serendipity_getTemplateFile('style_fallback.css', '')
);
$out .= serendipity_printStylesheet(
serendipity_getTemplateFile($css_file, 'serendipityPath'),
serendipity_getTemplateFile($css_file, '')
);
serendipity_plugin_api::hook_event($css_hook, $out);
echo $out;
//
// Fetch output buffer containing the CSS output and create eTag header
//
$ob_buffer = ob_get_contents();
if ($ob_buffer) {
// Calculate hash for eTag and get request header. The hash value
// changes with every modification to any part of the CSS styles.
// This includes the installation of a plugin that adds plugin
// specific styles.
// Send ETag header using the hash value of the CSS code
$hashValue = md5($ob_buffer);
@header('ETag: "' . $hashValue . '"');
// Compare value of If-None-Match header (if available) to hash value
if (!empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
// Get request header value and chop off optional quotes
$reqHeader = trim($_SERVER['HTTP_IF_NONE_MATCH'], '"');
if ($hashValue === $reqHeader) {
// Tell client to use the cached version and destroy output buffer
@header('HTTP/1.1 304 Not Modified', true, 304);
ob_clean();
}
}
}
ob_end_flush();
/* vim: set sts=4 ts=4 expandtab : */