aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--inc/StyleUtils.php107
-rw-r--r--inc/load.php1
-rw-r--r--lib/exe/css.php103
-rw-r--r--lib/plugins/styling/admin.php6
4 files changed, 113 insertions, 104 deletions
diff --git a/inc/StyleUtils.php b/inc/StyleUtils.php
new file mode 100644
index 000000000..494ed8e0c
--- /dev/null
+++ b/inc/StyleUtils.php
@@ -0,0 +1,107 @@
+<?php
+
+namespace dokuwiki;
+
+class StyleUtils
+{
+ /**
+ * Load style ini contents
+ *
+ * Loads and merges style.ini files from template and config and prepares
+ * the stylesheet modes
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $tpl the used template
+ * @param bool $preview load preview replacements
+ * @return array with keys 'stylesheets' and 'replacements'
+ */
+ public function cssStyleini($tpl, $preview=false) {
+ global $conf;
+
+ $stylesheets = array(); // mode, file => base
+ // guaranteed placeholder => value
+ $replacements = array(
+ '__text__' => "#000",
+ '__background__' => "#fff",
+ '__text_alt__' => "#999",
+ '__background_alt__' => "#eee",
+ '__text_neu__' => "#666",
+ '__background_neu__' => "#ddd",
+ '__border__' => "#ccc",
+ '__highlight__' => "#ff9",
+ '__link__' => "#00f",
+ );
+
+ // 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;
+ }
+
+ // replacements
+ if(is_array($data['replacements'])){
+ $replacements = array_merge($replacements, $this->cssFixreplacementurls($data['replacements'],$webbase));
+ }
+ }
+
+ // load configs's style.ini
+ $webbase = DOKU_BASE;
+ $ini = DOKU_CONF."tpl/$tpl/style.ini";
+ $incbase = dirname($ini).'/';
+ if(file_exists($ini)){
+ $data = parse_ini_file($ini, true);
+
+ // stylesheets
+ if(isset($data['stylesheets']) && is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){
+ $stylesheets[$mode][$incbase.$file] = $webbase;
+ }
+
+ // replacements
+ if(isset($data['replacements']) && is_array($data['replacements'])){
+ $replacements = array_merge($replacements, $this->cssFixreplacementurls($data['replacements'],$webbase));
+ }
+ }
+
+ // allow replacement overwrites in preview mode
+ if($preview) {
+ $webbase = DOKU_BASE;
+ $ini = $conf['cachedir'].'/preview.ini';
+ if(file_exists($ini)) {
+ $data = parse_ini_file($ini, true);
+ // replacements
+ if(is_array($data['replacements'])) {
+ $replacements = array_merge($replacements, $this->cssFixreplacementurls($data['replacements'], $webbase));
+ }
+ }
+ }
+
+ return array(
+ 'stylesheets' => $stylesheets,
+ 'replacements' => $replacements
+ );
+ }
+
+
+ /**
+ * Amend paths used in replacement relative urls, refer FS#2879
+ *
+ * @author Chris Smith <chris@jalakai.co.uk>
+ *
+ * @param array $replacements with key-value pairs
+ * @param string $location
+ * @return array
+ */
+ protected function cssFixreplacementurls($replacements, $location) {
+ foreach($replacements as $key => $value) {
+ $replacements[$key] = preg_replace('#(url\([ \'"]*)(?!/|data:|http://|https://| |\'|")#','\\1'.$location,$value);
+ }
+ return $replacements;
+ }
+}
diff --git a/inc/load.php b/inc/load.php
index b6613d698..9d109dcae 100644
--- a/inc/load.php
+++ b/inc/load.php
@@ -82,6 +82,7 @@ function load_autoload($name){
'RemoteAPI' => DOKU_INC.'inc/remote.php',
'RemoteAPICore' => DOKU_INC.'inc/RemoteAPICore.php',
'Subscription' => DOKU_INC.'inc/subscription.php',
+ 'StyleUtil' => DOKU_INC.'inc/StyleUtil.php',
'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php',
'DokuWiki_Admin_Plugin' => DOKU_PLUGIN.'admin.php',
diff --git a/lib/exe/css.php b/lib/exe/css.php
index ae51d9fc0..40eaf99a6 100644
--- a/lib/exe/css.php
+++ b/lib/exe/css.php
@@ -45,7 +45,8 @@ function css_out(){
if(!$tpl) $tpl = $conf['template'];
// load style.ini
- $styleini = css_styleini($tpl, $INPUT->bool('preview'));
+ $styleUtil = new \dokuwiki\StyleUtils();
+ $styleini = $styleUtil->cssStyleini($tpl, $INPUT->bool('preview'));
// cache influencers
$tplinc = tpl_incdir($tpl);
@@ -265,106 +266,6 @@ function css_applystyle($css, $replacements) {
}
/**
- * Load style ini contents
- *
- * Loads and merges style.ini files from template and config and prepares
- * the stylesheet modes
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- *
- * @param string $tpl the used template
- * @param bool $preview load preview replacements
- * @return array with keys 'stylesheets' and 'replacements'
- */
-function css_styleini($tpl, $preview=false) {
- global $conf;
-
- $stylesheets = array(); // mode, file => base
- // guaranteed placeholder => value
- $replacements = array(
- '__text__' => "#000",
- '__background__' => "#fff",
- '__text_alt__' => "#999",
- '__background_alt__' => "#eee",
- '__text_neu__' => "#666",
- '__background_neu__' => "#ddd",
- '__border__' => "#ccc",
- '__highlight__' => "#ff9",
- '__link__' => "#00f",
- );
-
- // 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;
- }
-
- // replacements
- if(is_array($data['replacements'])){
- $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase));
- }
- }
-
- // load configs's style.ini
- $webbase = DOKU_BASE;
- $ini = DOKU_CONF."tpl/$tpl/style.ini";
- $incbase = dirname($ini).'/';
- if(file_exists($ini)){
- $data = parse_ini_file($ini, true);
-
- // stylesheets
- if(isset($data['stylesheets']) && is_array($data['stylesheets'])) foreach($data['stylesheets'] as $file => $mode){
- $stylesheets[$mode][$incbase.$file] = $webbase;
- }
-
- // replacements
- if(isset($data['replacements']) && is_array($data['replacements'])){
- $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'],$webbase));
- }
- }
-
- // allow replacement overwrites in preview mode
- if($preview) {
- $webbase = DOKU_BASE;
- $ini = $conf['cachedir'].'/preview.ini';
- if(file_exists($ini)) {
- $data = parse_ini_file($ini, true);
- // replacements
- if(is_array($data['replacements'])) {
- $replacements = array_merge($replacements, css_fixreplacementurls($data['replacements'], $webbase));
- }
- }
- }
-
- return array(
- 'stylesheets' => $stylesheets,
- 'replacements' => $replacements
- );
-}
-
-/**
- * Amend paths used in replacement relative urls, refer FS#2879
- *
- * @author Chris Smith <chris@jalakai.co.uk>
- *
- * @param array $replacements with key-value pairs
- * @param string $location
- * @return array
- */
-function css_fixreplacementurls($replacements, $location) {
- foreach($replacements as $key => $value) {
- $replacements[$key] = preg_replace('#(url\([ \'"]*)(?!/|data:|http://|https://| |\'|")#','\\1'.$location,$value);
- }
- return $replacements;
-}
-
-/**
* Wrapper for the files, content and mediatype for the event CSS_STYLES_INCLUDED
*
* @author Gerry Weißbach <gerry.w@gammaproduction.de>
diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php
index c747c3130..055ac2279 100644
--- a/lib/plugins/styling/admin.php
+++ b/lib/plugins/styling/admin.php
@@ -57,9 +57,9 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin {
public function form() {
global $conf;
global $ID;
- define('SIMPLE_TEST', 1); // hack, ideally certain functions should be moved out of css.php
- require_once(DOKU_INC.'lib/exe/css.php');
- $styleini = css_styleini($conf['template'], true);
+
+ $styleUtil = new \dokuwiki\StyleUtils();
+ $styleini = $styleUtil->cssStyleini($conf['template'], true);
$replacements = $styleini['replacements'];
if($this->ispopup) {