summaryrefslogtreecommitdiff
path: root/lib/exe
diff options
context:
space:
mode:
Diffstat (limited to 'lib/exe')
-rw-r--r--lib/exe/css.php205
-rw-r--r--lib/exe/fetch.php1
-rw-r--r--lib/exe/js.php19
-rw-r--r--lib/exe/mediamanager.php7
4 files changed, 183 insertions, 49 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php
index 768c8eda4..9e1e22e1a 100644
--- a/lib/exe/css.php
+++ b/lib/exe/css.php
@@ -40,43 +40,32 @@ 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);
// 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[] = $tplinc.'style.local.ini'; // @deprecated
+ $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 +77,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 +90,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;
}
}
@@ -131,6 +120,8 @@ function css_out(){
// 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) {
@@ -152,9 +143,12 @@ 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);
- // place all @import statements at the top of the file
+ // place all remaining @import statements at the top of the file
$css = css_moveimports($css);
// compress whitespace and comments
@@ -172,40 +166,157 @@ function css_out(){
}
/**
+ * Uses phpless to parse LESS in our CSS
+ *
+ * most of this function is error handling to show a nice useful error when
+ * LESS compilation fails
+ *
+ * @param $css
+ * @return string
+ */
+function css_parseless($css) {
+ $less = new lessc();
+ try {
+ return $less->compile($css);
+ } catch(Exception $e) {
+ // get exception message
+ $msg = str_replace(array("\n", "\r", "'"), array(), $e->getMessage());
+
+ // try to use line number to find affected file
+ if(preg_match('/line: (\d+)$/', $msg, $m)){
+ $msg = substr($msg, 0, -1* strlen($m[0])); //remove useless linenumber
+ $lno = $m[1];
+
+ // walk upwards to last include
+ $lines = explode("\n", $css);
+ for($i=$lno-1; $i>=0; $i--){
+ if(preg_match('/\/(\* XXXXXXXXX )(.*?)( XXXXXXXXX \*)\//', $lines[$i], $m)){
+ // we found it, add info to message
+ $msg .= ' in '.$m[2].' at line '.($lno-$i);
+ break;
+ }
+ }
+ }
+
+ // something went wrong
+ $error = 'A fatal error occured during compilation of the CSS files. '.
+ 'If you recently installed a new plugin or template it '.
+ 'might be broken and you should try disabling it again. ['.$msg.']';
+
+ echo ".dokuwiki:before {
+ content: '$error';
+ background-color: red;
+ display: block;
+ background-color: #fcc;
+ border-color: #ebb;
+ color: #000;
+ padding: 0.5em;
+ }";
+
+ exit;
+ }
+}
+
+/**
* Does placeholder replacements in the style according to
* the ones defined in a templates style.ini file
*
+ * This also adds the ini defined placeholders as less variables
+ * (sans the surrounding __ and with a ini_ prefix)
+ *
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function css_applystyle($css,$tplinc){
- $styleini = css_styleini($tplinc);
-
- if($styleini){
- $css = strtr($css,$styleini['replacements']);
+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, $replacements);
+
+ // 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
*
- * @author Anika Henke <anika@selfthinker.org>
+ * 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
+ * @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;
+ }
+
+ // replacements
+ if(is_array($data['replacements'])){
+ $replacements = array_merge($replacements, $data['replacements']);
+ }
+ }
- foreach (array($tplinc.'style.ini', $tplinc.'style.local.ini') as $ini) {
- $tmp = (@file_exists($ini)) ? parse_ini_file($ini, true) : array();
+ // load template's style.local.ini
+ // @deprecated 2013-08-03
+ $ini = $incbase.'style.local.ini';
+ if(file_exists($ini)){
+ $data = parse_ini_file($ini, true);
- 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;
- }
+ // 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;
+
+ // 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(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 array(
+ 'stylesheets' => $stylesheets,
+ 'replacements' => $replacements
+ );
}
/**
@@ -333,9 +444,11 @@ function css_pluginstyles($mediatype='screen'){
$plugins = plugin_list();
foreach ($plugins as $p){
$list[DOKU_PLUGIN."$p/$mediatype.css"] = DOKU_BASE."lib/plugins/$p/";
+ $list[DOKU_PLUGIN."$p/$mediatype.less"] = DOKU_BASE."lib/plugins/$p/";
// alternative for screen.css
if ($mediatype=='screen') {
$list[DOKU_PLUGIN."$p/style.css"] = DOKU_BASE."lib/plugins/$p/";
+ $list[DOKU_PLUGIN."$p/style.less"] = DOKU_BASE."lib/plugins/$p/";
}
// @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
diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php
index 7a2250373..5967494bf 100644
--- a/lib/exe/fetch.php
+++ b/lib/exe/fetch.php
@@ -60,6 +60,7 @@ if (defined('SIMPLE_TEST')) {
if($evt->advise_before()) {
// redirects
if($data['status'] > 300 && $data['status'] <= 304) {
+ if (defined('SIMPLE_TEST')) return; //TestResponse doesn't recognize redirects
send_redirect($data['statusmessage']);
}
// send any non 200 status
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 06769d895..4b4b598de 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -96,6 +96,10 @@ function js_out(){
// load JS specific translations
$json = new JSON();
$lang['js']['plugins'] = js_pluginstrings();
+ $templatestrings = js_templatestrings();
+ if(!empty($templatestrings)) {
+ $lang['js']['template'] = $templatestrings;
+ }
echo 'LANG = '.$json->encode($lang['js']).";\n";
// load toolbar
@@ -210,6 +214,21 @@ function js_pluginstrings()
return $pluginstrings;
}
+function js_templatestrings() {
+ global $conf;
+ $templatestrings = array();
+ if (@file_exists(tpl_incdir()."lang/en/lang.php")) {
+ include tpl_incdir()."lang/en/lang.php";
+ }
+ if (isset($conf['lang']) && $conf['lang']!='en' && @file_exists(tpl_incdir()."lang/".$conf['lang']."/lang.php")) {
+ include tpl_incdir()."lang/".$conf['lang']."/lang.php";
+ }
+ if (isset($lang['js'])) {
+ $templatestrings[$conf['template']] = $lang['js'];
+ }
+ return $templatestrings;
+}
+
/**
* Escapes a String to be embedded in a JavaScript call, keeps \n
* as newline
diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php
index 66e5ddc82..d9e4a6b04 100644
--- a/lib/exe/mediamanager.php
+++ b/lib/exe/mediamanager.php
@@ -29,12 +29,13 @@
$IMG = null;
}
- global $INFO;
+ global $INFO, $JSINFO;
$INFO = !empty($INFO) ? array_merge($INFO, mediainfo()) : mediainfo();
+ $JSINFO = array('id' => '', 'namespace' => '');
$AUTH = $INFO['perm']; // shortcut for historical reasons
- trigger_event('MEDIAMANAGER_STARTED',$tmp=array());
- session_write_close(); //close session
+ trigger_event('MEDIAMANAGER_STARTED',$tmp=array());
+ session_write_close(); //close session
// do not display the manager if user does not have read access
if($AUTH < AUTH_READ && !$fullscreen) {