summaryrefslogtreecommitdiff
path: root/lib/exe
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2013-08-03 14:42:05 +0200
committerAndreas Gohr <andi@splitbrain.org>2013-08-03 14:42:05 +0200
commitafb2c08218345dc3604024c829a5c408e3f39277 (patch)
treefd912a383026921f00457a61465e2170dd67c2e2 /lib/exe
parent354c39ffc9aa3bbd7d59d5e182a36d1f390c5b7e (diff)
downloadrpg-afb2c08218345dc3604024c829a5c408e3f39277.tar.gz
rpg-afb2c08218345dc3604024c829a5c408e3f39277.tar.bz2
allow for a style.ini in conf/<tpl>/style.ini
This is another go at what pull request #227 tried to do. This removes support for a style.local.ini in the template file in preference of a style.ini in the conf folder
Diffstat (limited to 'lib/exe')
-rw-r--r--lib/exe/css.php139
1 files changed, 79 insertions, 60 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php
index 83972d407..ce6a83fea 100644
--- a/lib/exe/css.php
+++ b/lib/exe/css.php
@@ -40,43 +40,33 @@ function css_out(){
$type = '';
}
+ // decide from where to get the template
$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);
+ if(!$tpl) $tpl = $conf['template'];
// The generated script depends on some dynamic options
- $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tplinc.$type,'.css');
+ $cache = new cache('styles'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tpl.$type,'.css');
- // load template styles
- $tplstyles = array();
- if ($styleini) {
- foreach($styleini['stylesheets'] as $file => $mode) {
- $tplstyles[$mode][$tplinc.$file] = $tpldir;
- }
- }
+ // load styl.ini
+ $styleini = css_styleini($tpl);
+
+ print_r($styleini);
// 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 influencers
+ $tplinc = tpl_basedir($tpl);
$cache_files = getConfigFiles('main');
$cache_files[] = $tplinc.'style.ini';
- $cache_files[] = $tplinc.'style.local.ini';
+ $cache_files[] = DOKU_CONF."tpl/$tpl/style.ini";
$cache_files[] = __FILE__;
+ // 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
@@ -88,8 +78,8 @@ function css_out(){
// 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]);
+ if (isset($styleini['stylesheets'][$mediatype])) {
+ $files[$mediatype] = array_merge($files[$mediatype], $styleini['stylesheets'][$mediatype]);
}
// load user styles
if(isset($config_cascade['userstyle'][$mediatype])){
@@ -101,7 +91,7 @@ function css_out(){
// 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($styleini['stylesheets']['rtl'])) $files[$mediatype] = array_merge($files[$mediatype], $styleini['stylesheets']['rtl']);
if (isset($config_cascade['userstyle']['rtl'])) $files[$mediatype][$config_cascade['userstyle']['rtl']] = DOKU_BASE;
}
}
@@ -154,7 +144,7 @@ function css_out(){
ob_end_clean();
// apply style replacements
- $css = css_applystyle($css,$tplinc);
+ $css = css_applystyle($css, $styleini['replacements']);
// parse less
$css = css_parseless($css);
@@ -200,7 +190,6 @@ function css_parseless($css) {
// walk upwards to last include
$lines = explode("\n", $css);
- $count = count($lines);
for($i=$lno-1; $i>=0; $i--){
if(preg_match('/\/(\* XXXXXXXXX )(.*?)( XXXXXXXXX \*)\//', $lines[$i], $m)){
// we found it, add info to message
@@ -238,50 +227,80 @@ function css_parseless($css) {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function css_applystyle($css,$tplinc){
- $styleini = css_styleini($tplinc);
-
- if($styleini){
- // we convert ini replacements to LESS variable names
- // and build a list of variable: value; pairs
- $less = '';
- foreach($styleini['replacements'] as $key => $value){
- $lkey = trim($key, '_');
- $lkey = '@ini_'.$lkey;
- $less .= "$lkey: $value;\n";
-
- $styleini['replacements'][$key] = $lkey;
- }
+function css_applystyle($css, $replacements) {
+ // we convert ini replacements to LESS variable names
+ // and build a list of variable: value; pairs
+ $less = '';
+ foreach((array) $replacements as $key => $value) {
+ $lkey = trim($key, '_');
+ $lkey = '@ini_'.$lkey;
+ $less .= "$lkey: $value;\n";
+
+ $replacements[$key] = $lkey;
+ }
- // we now replace all old ini replacements with LESS variables
- $css = strtr($css, $styleini['replacements']);
+ // we now replace all old ini replacements with LESS variables
+ $css = strtr($css, $replacements);
- // now prepend the list of LESS variables as the very first thing
- $css = $less.$css;
- }
+ // now prepend the list of LESS variables as the very first thing
+ $css = $less.$css;
return $css;
}
/**
- * Get contents of merged style.ini and style.local.ini as an array.
+ * Load style ini contents
+ *
+ * Loads and merges style.ini files from template and config and prepares
+ * the stylesheet modes
*
- * @author Anika Henke <anika@selfthinker.org>
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @param string $tpl the used template
+ * @return array with keys 'stylesheets' and 'replacements'
*/
-function css_styleini($tplinc) {
- $styleini = array();
+function css_styleini($tpl) {
+ $stylesheets = array(); // mode, file => base
+ $replacements = array(); // placeholder => value
+
+ // load template's style.ini
+ $incbase = tpl_incdir($tpl);
+ $webbase = tpl_basedir($tpl);
+ $ini = $incbase.'style.ini';
+ if(file_exists($ini)){
+ $data = parse_ini_file($ini, true);
+
+ // stylesheets
+ if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){
+ $stylesheets[$mode][$incbase.$file] = $webbase;
+ }
- foreach (array($tplinc.'style.ini', $tplinc.'style.local.ini') as $ini) {
- $tmp = (@file_exists($ini)) ? parse_ini_file($ini, true) : array();
+ // replacements
+ if(is_array($data['replacements'])){
+ $replacements = array_merge($replacements, $data['replacements']);
+ }
+ }
- foreach($tmp as $key => $value) {
- if(array_key_exists($key, $styleini) && is_array($value)) {
- $styleini[$key] = array_merge($styleini[$key], $tmp[$key]);
- } else {
- $styleini[$key] = $value;
- }
+ // load configs's style.ini
+ $incbase = dirname($ini).'/';
+ $webbase = DOKU_BASE;
+ $ini = DOKU_CONF."/tpl/$tpl/style.ini";
+ if(file_exists($ini)){
+ $data = parse_ini_file($ini, true);
+
+ // stylesheets
+ if(is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){
+ $stylesheets[$mode][$incbase.$file] = $webbase;
+ }
+
+ // replacements
+ if(is_array($data['replacements'])){
+ $replacements = array_merge($replacements, $data['replacements']);
}
}
- return $styleini;
+
+ return array(
+ 'stylesheets' => $stylesheets,
+ 'replacements' => $replacements
+ );
}
/**