reformat /lib/exe/ folder
This commit is contained in:
parent
62b265e622
commit
5a5ec05346
197
lib/exe/css.php
197
lib/exe/css.php
|
@ -5,18 +5,19 @@
|
|||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
|
||||
use dokuwiki\StyleUtils;
|
||||
use dokuwiki\Cache\Cache;
|
||||
use dokuwiki\Extension\Event;
|
||||
|
||||
if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__ .'/../../');
|
||||
if(!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
|
||||
if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here
|
||||
if(!defined('NL')) define('NL', "\n");
|
||||
require_once(DOKU_INC.'inc/init.php');
|
||||
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
|
||||
if (!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
|
||||
if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here
|
||||
if (!defined('NL')) define('NL', "\n");
|
||||
require_once(DOKU_INC . 'inc/init.php');
|
||||
|
||||
// Main (don't run when UNIT test)
|
||||
if(!defined('SIMPLE_TEST')){
|
||||
if (!defined('SIMPLE_TEST')) {
|
||||
header('Content-Type: text/css; charset=utf-8');
|
||||
css_out();
|
||||
}
|
||||
|
@ -46,7 +47,9 @@ function css_out()
|
|||
|
||||
// decide from where to get the template
|
||||
$tpl = trim(preg_replace('/[^\w-]+/', '', $INPUT->str('t')));
|
||||
if(!$tpl) $tpl = $conf['template'];
|
||||
if (!$tpl) {
|
||||
$tpl = $conf['template'];
|
||||
}
|
||||
|
||||
// load style.ini
|
||||
$styleUtil = new StyleUtils($tpl, $INPUT->bool('preview'));
|
||||
|
@ -55,24 +58,26 @@ function css_out()
|
|||
// 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[] = $tplinc . 'style.ini';
|
||||
$cache_files[] = DOKU_CONF . "tpl/$tpl/style.ini";
|
||||
$cache_files[] = __FILE__;
|
||||
if($INPUT->bool('preview')) $cache_files[] = $conf['cachedir'].'/preview.ini';
|
||||
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
|
||||
$media_files = [];
|
||||
foreach($mediatypes as $mediatype) {
|
||||
foreach ($mediatypes as $mediatype) {
|
||||
$files = [];
|
||||
|
||||
// load core styles
|
||||
$files[DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/';
|
||||
$files[DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/';
|
||||
|
||||
// load jQuery-UI theme
|
||||
if ($mediatype == 'screen') {
|
||||
$files[DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] =
|
||||
DOKU_BASE.'lib/scripts/jquery/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));
|
||||
|
@ -81,8 +86,8 @@ function css_out()
|
|||
$files = array_merge($files, $styleini['stylesheets'][$mediatype]);
|
||||
}
|
||||
// load user styles
|
||||
if(isset($config_cascade['userstyle'][$mediatype]) && is_array($config_cascade['userstyle'][$mediatype])) {
|
||||
foreach($config_cascade['userstyle'][$mediatype] as $userstyle) {
|
||||
if (isset($config_cascade['userstyle'][$mediatype]) && is_array($config_cascade['userstyle'][$mediatype])) {
|
||||
foreach ($config_cascade['userstyle'][$mediatype] as $userstyle) {
|
||||
$files[$userstyle] = DOKU_BASE;
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +97,7 @@ function css_out()
|
|||
$CSSEvt = new Event('CSS_STYLES_INCLUDED', $media_files[$mediatype]);
|
||||
|
||||
// Make it preventable.
|
||||
if ( $CSSEvt->advise_before() ) {
|
||||
if ($CSSEvt->advise_before()) {
|
||||
$cache_files = array_merge($cache_files, array_keys($media_files[$mediatype]['files']));
|
||||
} else {
|
||||
// unset if prevented. Nothing will be printed for this mediatype.
|
||||
|
@ -134,7 +139,7 @@ function css_out()
|
|||
foreach ($mediatypes as $mediatype) {
|
||||
|
||||
// Check if there is a wrapper set for this type.
|
||||
if ( !isset($media_files[$mediatype]) ) {
|
||||
if (!isset($media_files[$mediatype])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -142,20 +147,25 @@ function css_out()
|
|||
|
||||
// Print the styles.
|
||||
print NL;
|
||||
if ( $cssData['encapsulate'] === true ) print $cssData['encapsulationPrefix'] . ' {';
|
||||
print '/* START '.$cssData['mediatype'].' styles */'.NL;
|
||||
if ($cssData['encapsulate'] === true) {
|
||||
print $cssData['encapsulationPrefix'] . ' {';
|
||||
}
|
||||
print '/* START ' . $cssData['mediatype'] . ' styles */' . NL;
|
||||
|
||||
// load files
|
||||
foreach($cssData['files'] as $file => $location){
|
||||
foreach ($cssData['files'] as $file => $location) {
|
||||
$display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
|
||||
print "\n/* XXXXXXXXX $display XXXXXXXXX */\n";
|
||||
print css_loadfile($file, $location);
|
||||
}
|
||||
|
||||
print NL;
|
||||
if ( $cssData['encapsulate'] === true ) print '} /* /@media ';
|
||||
else print '/*';
|
||||
print ' END '.$cssData['mediatype'].' styles */'.NL;
|
||||
if ($cssData['encapsulate'] === true) {
|
||||
print '} /* /@media ';
|
||||
} else {
|
||||
print '/*';
|
||||
}
|
||||
print ' END ' . $cssData['mediatype'] . ' styles */' . NL;
|
||||
}
|
||||
|
||||
// end output buffering and get contents
|
||||
|
@ -172,14 +182,14 @@ function css_out()
|
|||
$css = css_parseless($css);
|
||||
|
||||
// compress whitespace and comments
|
||||
if($conf['compress']){
|
||||
if ($conf['compress']) {
|
||||
$css = css_compress($css);
|
||||
}
|
||||
|
||||
// embed small images right into the stylesheet
|
||||
if($conf['cssdatauri']){
|
||||
if ($conf['cssdatauri']) {
|
||||
$base = preg_quote(DOKU_BASE, '#');
|
||||
$css = preg_replace_callback('#(url\([ \'"]*)('.$base.')(.*?(?:\.(png|gif)))#i', 'css_datauri', $css);
|
||||
$css = preg_replace_callback('#(url\([ \'"]*)(' . $base . ')(.*?(?:\.(png|gif)))#i', 'css_datauri', $css);
|
||||
}
|
||||
|
||||
http_cached_finish($cache->cache, $css);
|
||||
|
@ -202,36 +212,36 @@ function css_parseless($css)
|
|||
$less->importDir = [DOKU_INC];
|
||||
$less->setPreserveComments(!$conf['compress']);
|
||||
|
||||
if (defined('DOKU_UNITTEST')){
|
||||
if (defined('DOKU_UNITTEST')) {
|
||||
$less->importDir[] = TMP_DIR;
|
||||
}
|
||||
|
||||
try {
|
||||
return $less->compile($css);
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
// get exception message
|
||||
$msg = str_replace(["\n", "\r", "'"], [], $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
|
||||
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)){
|
||||
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);
|
||||
$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.']';
|
||||
$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';
|
||||
|
@ -254,20 +264,20 @@ function css_parseless($css)
|
|||
* This also adds the ini defined placeholders as less variables
|
||||
* (sans the surrounding __ and with a ini_ prefix)
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @param string $css
|
||||
* @param array $replacements array(placeholder => value)
|
||||
* @param array $replacements array(placeholder => value)
|
||||
* @return string
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
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) {
|
||||
foreach ((array)$replacements as $key => $value) {
|
||||
$lkey = trim($key, '_');
|
||||
$lkey = '@ini_'.$lkey;
|
||||
$lkey = '@ini_' . $lkey;
|
||||
$less .= "$lkey: $value;\n";
|
||||
|
||||
$replacements[$key] = $lkey;
|
||||
|
@ -277,37 +287,37 @@ function css_applystyle($css, $replacements)
|
|||
$css = strtr($css, $replacements);
|
||||
|
||||
// now prepend the list of LESS variables as the very first thing
|
||||
$css = $less.$css;
|
||||
$css = $less . $css;
|
||||
return $css;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the files, content and mediatype for the event CSS_STYLES_INCLUDED
|
||||
*
|
||||
* @author Gerry Weißbach <gerry.w@gammaproduction.de>
|
||||
*
|
||||
* @param string $mediatype type ofthe current media files/content set
|
||||
* @param array $files set of files that define the current mediatype
|
||||
* @return array
|
||||
*
|
||||
* @author Gerry Weißbach <gerry.w@gammaproduction.de>
|
||||
*/
|
||||
function css_filewrapper($mediatype, $files = [])
|
||||
{
|
||||
return [
|
||||
'files' => $files,
|
||||
'mediatype' => $mediatype,
|
||||
'encapsulate' => $mediatype != 'all',
|
||||
'encapsulationPrefix' => '@media '.$mediatype
|
||||
'files' => $files,
|
||||
'mediatype' => $mediatype,
|
||||
'encapsulate' => $mediatype != 'all',
|
||||
'encapsulationPrefix' => '@media ' . $mediatype
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the @media encapsulated default styles of DokuWiki
|
||||
*
|
||||
* @author Gerry Weißbach <gerry.w@gammaproduction.de>
|
||||
*
|
||||
* This function is being called by a CSS_STYLES_INCLUDED event
|
||||
* The event can be distinguished by the mediatype which is:
|
||||
* DW_DEFAULT
|
||||
*
|
||||
* @author Gerry Weißbach <gerry.w@gammaproduction.de>
|
||||
*/
|
||||
function css_defaultstyles()
|
||||
{
|
||||
|
@ -334,7 +344,7 @@ function css_interwiki()
|
|||
|
||||
// default style
|
||||
echo 'a.interwiki {';
|
||||
echo ' background: transparent url('.DOKU_BASE.'lib/images/interwiki.svg) 0 0 no-repeat;';
|
||||
echo ' background: transparent url(' . DOKU_BASE . 'lib/images/interwiki.svg) 0 0 no-repeat;';
|
||||
echo ' background-size: 1.2em;';
|
||||
echo ' padding: 0 0 0 1.4em;';
|
||||
echo '}';
|
||||
|
@ -366,7 +376,7 @@ function css_filetypes()
|
|||
|
||||
// default style
|
||||
echo '.mediafile {';
|
||||
echo ' background: transparent url('.DOKU_BASE.'lib/images/fileicons/svg/file.svg) 0px 1px no-repeat;';
|
||||
echo ' background: transparent url(' . DOKU_BASE . 'lib/images/fileicons/svg/file.svg) 0px 1px no-repeat;';
|
||||
echo ' background-size: 1.2em;';
|
||||
echo ' padding-left: 1.5em;';
|
||||
echo '}';
|
||||
|
@ -374,18 +384,18 @@ function css_filetypes()
|
|||
// additional styles when icon available
|
||||
// scan directory for all icons
|
||||
$exts = [];
|
||||
if($dh = opendir(DOKU_INC.'lib/images/fileicons/svg')){
|
||||
while(false !== ($file = readdir($dh))){
|
||||
if(preg_match('/(.*?)\.svg$/i', $file, $match)){
|
||||
if ($dh = opendir(DOKU_INC . 'lib/images/fileicons/svg')) {
|
||||
while (false !== ($file = readdir($dh))) {
|
||||
if (preg_match('/(.*?)\.svg$/i', $file, $match)) {
|
||||
$exts[] = strtolower($match[1]);
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
foreach($exts as $ext){
|
||||
foreach ($exts as $ext) {
|
||||
$class = preg_replace('/[^_\-a-z0-9]+/', '_', $ext);
|
||||
echo ".mf_$class {";
|
||||
echo ' background-image: url('.DOKU_BASE.'lib/images/fileicons/svg/'.$ext.'.svg)';
|
||||
echo ' background-image: url(' . DOKU_BASE . 'lib/images/fileicons/svg/' . $ext . '.svg)';
|
||||
echo '}';
|
||||
}
|
||||
}
|
||||
|
@ -405,9 +415,9 @@ function css_loadfile($file, $location = '')
|
|||
}
|
||||
|
||||
/**
|
||||
* Helper class to abstract loading of css/less files
|
||||
* Helper class to abstract loading of css/less files
|
||||
*
|
||||
* @author Chris Smith <chris@jalakai.co.uk>
|
||||
* @author Chris Smith <chris@jalakai.co.uk>
|
||||
*/
|
||||
class DokuCssFile
|
||||
{
|
||||
|
@ -426,8 +436,8 @@ class DokuCssFile
|
|||
* relative to the dokuwiki root: the web root (DOKU_BASE) for most files; the file system root (DOKU_INC)
|
||||
* for less files.
|
||||
*
|
||||
* @param string $location base url for this file
|
||||
* @return string the CSS/Less contents of the file
|
||||
* @param string $location base url for this file
|
||||
* @return string the CSS/Less contents of the file
|
||||
*/
|
||||
public function load($location = '')
|
||||
{
|
||||
|
@ -461,7 +471,7 @@ class DokuCssFile
|
|||
}
|
||||
|
||||
$basedir = array_map('preg_quote_cb', $basedir);
|
||||
$regex = '/^('.implode('|', $basedir).')/';
|
||||
$regex = '/^(' . implode('|', $basedir) . ')/';
|
||||
$this->relative_path = preg_replace($regex, '', dirname($this->filepath));
|
||||
}
|
||||
|
||||
|
@ -472,7 +482,7 @@ class DokuCssFile
|
|||
* preg_replace callback to adjust relative urls from relative to this file to relative
|
||||
* to the appropriate dokuwiki root location as described in the code
|
||||
*
|
||||
* @param array see http://php.net/preg_replace_callback
|
||||
* @param array $match see http://php.net/preg_replace_callback
|
||||
* @return string see http://php.net/preg_replace_callback
|
||||
*/
|
||||
public function replacements($match)
|
||||
|
@ -504,44 +514,44 @@ function css_datauri($match)
|
|||
{
|
||||
global $conf;
|
||||
|
||||
$pre = unslash($match[1]);
|
||||
$base = unslash($match[2]);
|
||||
$url = unslash($match[3]);
|
||||
$ext = unslash($match[4]);
|
||||
$pre = unslash($match[1]);
|
||||
$base = unslash($match[2]);
|
||||
$url = unslash($match[3]);
|
||||
$ext = unslash($match[4]);
|
||||
|
||||
$local = DOKU_INC.$url;
|
||||
$size = @filesize($local);
|
||||
if($size && $size < $conf['cssdatauri']){
|
||||
$local = DOKU_INC . $url;
|
||||
$size = @filesize($local);
|
||||
if ($size && $size < $conf['cssdatauri']) {
|
||||
$data = base64_encode(file_get_contents($local));
|
||||
}
|
||||
if (!empty($data)){
|
||||
$url = 'data:image/'.$ext.';base64,'.$data;
|
||||
}else{
|
||||
$url = $base.$url;
|
||||
if (!empty($data)) {
|
||||
$url = 'data:image/' . $ext . ';base64,' . $data;
|
||||
} else {
|
||||
$url = $base . $url;
|
||||
}
|
||||
return $pre.$url;
|
||||
return $pre . $url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of possible Plugin Styles (no existance check here)
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @param string $mediatype
|
||||
* @return array
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
*/
|
||||
function css_pluginstyles($mediatype = 'screen')
|
||||
{
|
||||
$list = [];
|
||||
$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/";
|
||||
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/";
|
||||
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/";
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
|
@ -550,10 +560,10 @@ function css_pluginstyles($mediatype = 'screen')
|
|||
/**
|
||||
* Very simple CSS optimizer
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @param string $css
|
||||
* @return string
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
*/
|
||||
function css_compress($css)
|
||||
{
|
||||
|
@ -562,7 +572,7 @@ function css_compress($css)
|
|||
|
||||
$quote_cb = function ($match) use (&$quote_storage) {
|
||||
$quote_storage[] = $match[0];
|
||||
return '"STR'.(count($quote_storage)-1).'"';
|
||||
return '"STR' . (count($quote_storage) - 1) . '"';
|
||||
};
|
||||
|
||||
$css = preg_replace_callback('/(([\'"]).*?(?<!\\\\)\2)/', $quote_cb, $css);
|
||||
|
@ -640,14 +650,15 @@ function css_compress($css)
|
|||
*
|
||||
* Keeps short comments (< 5 chars) to maintain typical browser hacks
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @param array $matches
|
||||
* @return string
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
*/
|
||||
function css_comment_cb($matches)
|
||||
{
|
||||
if(strlen($matches[2]) > 4) return '';
|
||||
if (strlen($matches[2]) > 4) return '';
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
|
@ -666,17 +677,17 @@ function css_onelinecomment_cb($matches)
|
|||
$i = 0;
|
||||
$len = strlen($line);
|
||||
|
||||
while ($i< $len){
|
||||
while ($i < $len) {
|
||||
$nextcom = strpos($line, '//', $i);
|
||||
$nexturl = stripos($line, 'url(', $i);
|
||||
|
||||
if($nextcom === false) {
|
||||
if ($nextcom === false) {
|
||||
// no more comments, we're done
|
||||
$i = $len;
|
||||
break;
|
||||
}
|
||||
|
||||
if($nexturl === false || $nextcom < $nexturl) {
|
||||
if ($nexturl === false || $nextcom < $nexturl) {
|
||||
// no url anymore, strip comment and be done
|
||||
$i = $nextcom;
|
||||
break;
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
use dokuwiki\Extension\Event;
|
||||
|
||||
if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__.'/../../');
|
||||
if(!defined('DOKU_MEDIADETAIL')) define('DOKU_MEDIADETAIL', 1);
|
||||
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
|
||||
if (!defined('DOKU_MEDIADETAIL')) define('DOKU_MEDIADETAIL', 1);
|
||||
|
||||
// define all DokuWiki globals here (needed within test requests but also helps to keep track)
|
||||
global $INPUT, $IMG, $ID, $REV, $SRC, $ERROR, $AUTH;
|
||||
|
||||
require_once(DOKU_INC.'inc/init.php');
|
||||
require_once(DOKU_INC . 'inc/init.php');
|
||||
|
||||
$IMG = getID('media');
|
||||
$ID = cleanID($INPUT->str('id'));
|
||||
$REV = $INPUT->int('rev');
|
||||
$IMG = getID('media');
|
||||
$ID = cleanID($INPUT->str('id'));
|
||||
$REV = $INPUT->int('rev');
|
||||
|
||||
// this makes some general info available as well as the info about the
|
||||
// "parent" page
|
||||
|
@ -27,15 +27,15 @@ session_write_close();
|
|||
$ERROR = false;
|
||||
// check image permissions
|
||||
$AUTH = auth_quickaclcheck($IMG);
|
||||
if($AUTH >= AUTH_READ){
|
||||
if ($AUTH >= AUTH_READ) {
|
||||
// check if image exists
|
||||
$SRC = mediaFN($IMG, $REV);
|
||||
if(!file_exists($SRC)){
|
||||
if (!file_exists($SRC)) {
|
||||
//doesn't exist!
|
||||
http_status(404);
|
||||
$ERROR = 'File not found';
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
// no auth
|
||||
$ERROR = p_locale_xhtml('denied');
|
||||
}
|
||||
|
|
|
@ -5,123 +5,122 @@
|
|||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
|
||||
use dokuwiki\Input\Input;
|
||||
use dokuwiki\Extension\Event;
|
||||
|
||||
if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__.'/../../');
|
||||
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
|
||||
if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1);
|
||||
require_once(DOKU_INC.'inc/init.php');
|
||||
require_once(DOKU_INC . 'inc/init.php');
|
||||
session_write_close(); //close session
|
||||
|
||||
require_once(DOKU_INC.'inc/fetch.functions.php');
|
||||
require_once(DOKU_INC . 'inc/fetch.functions.php');
|
||||
|
||||
if (defined('SIMPLE_TEST')) {
|
||||
$INPUT = new Input();
|
||||
}
|
||||
|
||||
// BEGIN main
|
||||
$mimetypes = getMimeTypes();
|
||||
$mimetypes = getMimeTypes();
|
||||
|
||||
//get input
|
||||
$MEDIA = stripctl(getID('media', false)); // no cleaning except control chars - maybe external
|
||||
$CACHE = calc_cache($INPUT->str('cache'));
|
||||
$WIDTH = $INPUT->int('w');
|
||||
$HEIGHT = $INPUT->int('h');
|
||||
$REV = & $INPUT->ref('rev');
|
||||
//sanitize revision
|
||||
$REV = preg_replace('/[^0-9]/', '', $REV);
|
||||
//get input
|
||||
$MEDIA = stripctl(getID('media', false)); // no cleaning except control chars - maybe external
|
||||
$CACHE = calc_cache($INPUT->str('cache'));
|
||||
$WIDTH = $INPUT->int('w');
|
||||
$HEIGHT = $INPUT->int('h');
|
||||
$REV = &$INPUT->ref('rev');
|
||||
//sanitize revision
|
||||
$REV = preg_replace('/[^0-9]/', '', $REV);
|
||||
|
||||
[$EXT, $MIME, $DL] = mimetype($MEDIA, false);
|
||||
if($EXT === false) {
|
||||
$EXT = 'unknown';
|
||||
$MIME = 'application/octet-stream';
|
||||
$DL = true;
|
||||
[$EXT, $MIME, $DL] = mimetype($MEDIA, false);
|
||||
if ($EXT === false) {
|
||||
$EXT = 'unknown';
|
||||
$MIME = 'application/octet-stream';
|
||||
$DL = true;
|
||||
}
|
||||
|
||||
// check for permissions, preconditions and cache external files
|
||||
[$STATUS, $STATUSMESSAGE] = checkFileStatus($MEDIA, $FILE, $REV, $WIDTH, $HEIGHT);
|
||||
|
||||
// prepare data for plugin events
|
||||
$data = [
|
||||
'media' => $MEDIA,
|
||||
'file' => $FILE,
|
||||
'orig' => $FILE,
|
||||
'mime' => $MIME,
|
||||
'download' => $DL,
|
||||
'cache' => $CACHE,
|
||||
'ext' => $EXT,
|
||||
'width' => $WIDTH,
|
||||
'height' => $HEIGHT,
|
||||
'status' => $STATUS,
|
||||
'statusmessage' => $STATUSMESSAGE,
|
||||
'ispublic' => media_ispublic($MEDIA),
|
||||
'csp' => [
|
||||
'default-src' => "'none'",
|
||||
'style-src' => "'unsafe-inline'",
|
||||
'media-src' => "'self'",
|
||||
'object-src' => "'self'",
|
||||
'font-src' => "'self' data:",
|
||||
'form-action' => "'none'",
|
||||
'frame-ancestors' => "'self'",
|
||||
]
|
||||
];
|
||||
|
||||
// handle the file status
|
||||
$evt = new Event('FETCH_MEDIA_STATUS', $data);
|
||||
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
|
||||
if ($data['status'] != 200) {
|
||||
http_status($data['status'], $data['statusmessage']);
|
||||
}
|
||||
// die on errors
|
||||
if ($data['status'] > 203) {
|
||||
print $data['statusmessage'];
|
||||
if (defined('SIMPLE_TEST')) return;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$evt->advise_after();
|
||||
unset($evt);
|
||||
|
||||
// check for permissions, preconditions and cache external files
|
||||
[$STATUS, $STATUSMESSAGE] = checkFileStatus($MEDIA, $FILE, $REV, $WIDTH, $HEIGHT);
|
||||
|
||||
// prepare data for plugin events
|
||||
$data = [
|
||||
'media' => $MEDIA,
|
||||
'file' => $FILE,
|
||||
'orig' => $FILE,
|
||||
'mime' => $MIME,
|
||||
'download' => $DL,
|
||||
'cache' => $CACHE,
|
||||
'ext' => $EXT,
|
||||
'width' => $WIDTH,
|
||||
'height' => $HEIGHT,
|
||||
'status' => $STATUS,
|
||||
'statusmessage' => $STATUSMESSAGE,
|
||||
'ispublic' => media_ispublic($MEDIA),
|
||||
'csp' => [
|
||||
'default-src' => "'none'",
|
||||
'style-src' => "'unsafe-inline'",
|
||||
'media-src' => "'self'",
|
||||
'object-src' => "'self'",
|
||||
'font-src' => "'self' data:",
|
||||
'form-action' => "'none'",
|
||||
'frame-ancestors' => "'self'",
|
||||
]
|
||||
];
|
||||
|
||||
// handle the file status
|
||||
$evt = new Event('FETCH_MEDIA_STATUS', $data);
|
||||
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
|
||||
if($data['status'] != 200) {
|
||||
http_status($data['status'], $data['statusmessage']);
|
||||
}
|
||||
// die on errors
|
||||
if($data['status'] > 203) {
|
||||
print $data['statusmessage'];
|
||||
if (defined('SIMPLE_TEST')) return;
|
||||
exit;
|
||||
//handle image resizing/cropping
|
||||
$evt = new Event('MEDIA_RESIZE', $data);
|
||||
if ($evt->advise_before()) {
|
||||
if (
|
||||
$MIME != 'image/svg+xml' &&
|
||||
(substr($MIME, 0, 5) == 'image') &&
|
||||
($WIDTH || $HEIGHT)
|
||||
) {
|
||||
if ($HEIGHT && $WIDTH) {
|
||||
$data['file'] = $FILE = media_crop_image($data['file'], $EXT, $WIDTH, $HEIGHT);
|
||||
} else {
|
||||
$data['file'] = $FILE = media_resize_image($data['file'], $EXT, $WIDTH, $HEIGHT);
|
||||
}
|
||||
}
|
||||
$evt->advise_after();
|
||||
unset($evt);
|
||||
}
|
||||
$evt->advise_after();
|
||||
unset($evt);
|
||||
|
||||
//handle image resizing/cropping
|
||||
$evt = new Event('MEDIA_RESIZE', $data);
|
||||
if($evt->advise_before()) {
|
||||
if(
|
||||
$MIME != 'image/svg+xml' &&
|
||||
(substr($MIME, 0, 5) == 'image') &&
|
||||
($WIDTH || $HEIGHT)
|
||||
) {
|
||||
if($HEIGHT && $WIDTH) {
|
||||
$data['file'] = $FILE = media_crop_image($data['file'], $EXT, $WIDTH, $HEIGHT);
|
||||
} else {
|
||||
$data['file'] = $FILE = media_resize_image($data['file'], $EXT, $WIDTH, $HEIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
$evt->advise_after();
|
||||
unset($evt);
|
||||
|
||||
// finally send the file to the client
|
||||
$evt = new Event('MEDIA_SENDFILE', $data);
|
||||
if($evt->advise_before()) {
|
||||
sendFile(
|
||||
$data['file'],
|
||||
$data['mime'],
|
||||
$data['download'],
|
||||
$data['cache'],
|
||||
$data['ispublic'],
|
||||
$data['orig'],
|
||||
$data['csp']
|
||||
);
|
||||
}
|
||||
// Do something after the download finished.
|
||||
$evt->advise_after(); // will not be emitted on 304 or x-sendfile
|
||||
// finally send the file to the client
|
||||
$evt = new Event('MEDIA_SENDFILE', $data);
|
||||
if ($evt->advise_before()) {
|
||||
sendFile(
|
||||
$data['file'],
|
||||
$data['mime'],
|
||||
$data['download'],
|
||||
$data['cache'],
|
||||
$data['ispublic'],
|
||||
$data['orig'],
|
||||
$data['csp']
|
||||
);
|
||||
}
|
||||
// Do something after the download finished.
|
||||
$evt->advise_after(); // will not be emitted on 304 or x-sendfile
|
||||
|
||||
// END DO main
|
||||
|
||||
//Setup VIM: ex: et ts=2 :
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
use dokuwiki\Cache\Cache;
|
||||
|
||||
if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
|
||||
if(!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
|
||||
if(!defined('NL')) define('NL', "\n");
|
||||
if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here
|
||||
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
|
||||
if (!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
|
||||
if (!defined('NL')) define('NL', "\n");
|
||||
if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here
|
||||
require_once(DOKU_INC . 'inc/init.php');
|
||||
|
||||
// MAIN
|
||||
|
@ -36,8 +36,8 @@ function jquery_out()
|
|||
http_cached($cache->cache, $cache_ok);
|
||||
|
||||
$js = '';
|
||||
foreach($files as $file) {
|
||||
$js .= file_get_contents($file)."\n";
|
||||
foreach ($files as $file) {
|
||||
$js .= file_get_contents($file) . "\n";
|
||||
}
|
||||
stripsourcemaps($js);
|
||||
|
||||
|
|
187
lib/exe/js.php
187
lib/exe/js.php
|
@ -5,20 +5,21 @@
|
|||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
|
||||
use dokuwiki\Utf8\PhpString;
|
||||
use dokuwiki\Cache\Cache;
|
||||
use dokuwiki\Extension\Event;
|
||||
use splitbrain\JSStrip\Exception as JSStripException;
|
||||
use splitbrain\JSStrip\JSStrip;
|
||||
|
||||
if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__ .'/../../');
|
||||
if(!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
|
||||
if(!defined('NL')) define('NL', "\n");
|
||||
if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here
|
||||
require_once(DOKU_INC.'inc/init.php');
|
||||
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
|
||||
if (!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
|
||||
if (!defined('NL')) define('NL', "\n");
|
||||
if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here
|
||||
require_once(DOKU_INC . 'inc/init.php');
|
||||
|
||||
// Main (don't run when UNIT test)
|
||||
if(!defined('SIMPLE_TEST')){
|
||||
if (!defined('SIMPLE_TEST')) {
|
||||
header('Content-Type: application/javascript; charset=utf-8');
|
||||
js_out();
|
||||
}
|
||||
|
@ -40,40 +41,40 @@ function js_out()
|
|||
|
||||
// decide from where to get the template
|
||||
$tpl = trim(preg_replace('/[^\w-]+/', '', $INPUT->str('t')));
|
||||
if(!$tpl) $tpl = $conf['template'];
|
||||
if (!$tpl) $tpl = $conf['template'];
|
||||
|
||||
// array of core files
|
||||
$files = [
|
||||
DOKU_INC.'lib/scripts/jquery/jquery.cookie.js',
|
||||
DOKU_INC.'inc/lang/'.$conf['lang'].'/jquery.ui.datepicker.js',
|
||||
DOKU_INC."lib/scripts/fileuploader.js",
|
||||
DOKU_INC."lib/scripts/fileuploaderextended.js",
|
||||
DOKU_INC.'lib/scripts/helpers.js',
|
||||
DOKU_INC.'lib/scripts/delay.js',
|
||||
DOKU_INC.'lib/scripts/cookie.js',
|
||||
DOKU_INC.'lib/scripts/script.js',
|
||||
DOKU_INC.'lib/scripts/qsearch.js',
|
||||
DOKU_INC.'lib/scripts/search.js',
|
||||
DOKU_INC.'lib/scripts/tree.js',
|
||||
DOKU_INC.'lib/scripts/index.js',
|
||||
DOKU_INC.'lib/scripts/textselection.js',
|
||||
DOKU_INC.'lib/scripts/toolbar.js',
|
||||
DOKU_INC.'lib/scripts/edit.js',
|
||||
DOKU_INC.'lib/scripts/editor.js',
|
||||
DOKU_INC.'lib/scripts/locktimer.js',
|
||||
DOKU_INC.'lib/scripts/linkwiz.js',
|
||||
DOKU_INC.'lib/scripts/media.js',
|
||||
DOKU_INC.'lib/scripts/compatibility.js',
|
||||
DOKU_INC . 'lib/scripts/jquery/jquery.cookie.js',
|
||||
DOKU_INC . 'inc/lang/' . $conf['lang'] . '/jquery.ui.datepicker.js',
|
||||
DOKU_INC . "lib/scripts/fileuploader.js",
|
||||
DOKU_INC . "lib/scripts/fileuploaderextended.js",
|
||||
DOKU_INC . 'lib/scripts/helpers.js',
|
||||
DOKU_INC . 'lib/scripts/delay.js',
|
||||
DOKU_INC . 'lib/scripts/cookie.js',
|
||||
DOKU_INC . 'lib/scripts/script.js',
|
||||
DOKU_INC . 'lib/scripts/qsearch.js',
|
||||
DOKU_INC . 'lib/scripts/search.js',
|
||||
DOKU_INC . 'lib/scripts/tree.js',
|
||||
DOKU_INC . 'lib/scripts/index.js',
|
||||
DOKU_INC . 'lib/scripts/textselection.js',
|
||||
DOKU_INC . 'lib/scripts/toolbar.js',
|
||||
DOKU_INC . 'lib/scripts/edit.js',
|
||||
DOKU_INC . 'lib/scripts/editor.js',
|
||||
DOKU_INC . 'lib/scripts/locktimer.js',
|
||||
DOKU_INC . 'lib/scripts/linkwiz.js',
|
||||
DOKU_INC . 'lib/scripts/media.js',
|
||||
DOKU_INC . 'lib/scripts/compatibility.js',
|
||||
# disabled for FS#1958 DOKU_INC.'lib/scripts/hotkeys.js',
|
||||
DOKU_INC.'lib/scripts/behaviour.js',
|
||||
DOKU_INC.'lib/scripts/page.js',
|
||||
tpl_incdir($tpl).'script.js',
|
||||
DOKU_INC . 'lib/scripts/behaviour.js',
|
||||
DOKU_INC . 'lib/scripts/page.js',
|
||||
tpl_incdir($tpl) . 'script.js',
|
||||
];
|
||||
|
||||
// add possible plugin scripts and userscript
|
||||
$files = array_merge($files, js_pluginscripts());
|
||||
if(is_array($config_cascade['userscript']['default'])) {
|
||||
foreach($config_cascade['userscript']['default'] as $userscript) {
|
||||
$files = array_merge($files, js_pluginscripts());
|
||||
if (is_array($config_cascade['userscript']['default'])) {
|
||||
foreach ($config_cascade['userscript']['default'] as $userscript) {
|
||||
$files[] = $userscript;
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +83,7 @@ function js_out()
|
|||
Event::createAndTrigger('JS_SCRIPT_LIST', $files);
|
||||
|
||||
// The generated script depends on some dynamic options
|
||||
$cache = new Cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].md5(serialize($files)), '.js');
|
||||
$cache = new Cache('scripts' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . md5(serialize($files)), '.js');
|
||||
$cache->setEvent('JS_CACHE_USE');
|
||||
|
||||
$cache_files = array_merge($files, getConfigFiles('main'));
|
||||
|
@ -97,49 +98,49 @@ function js_out()
|
|||
ob_start();
|
||||
|
||||
// add some global variables
|
||||
print "var DOKU_BASE = '".DOKU_BASE."';";
|
||||
print "var DOKU_TPL = '".tpl_basedir($tpl)."';";
|
||||
print "var DOKU_BASE = '" . DOKU_BASE . "';";
|
||||
print "var DOKU_TPL = '" . tpl_basedir($tpl) . "';";
|
||||
print "var DOKU_COOKIE_PARAM = " . json_encode([
|
||||
'path' => empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'],
|
||||
'secure' => $conf['securecookie'] && is_ssl()
|
||||
], JSON_THROW_ON_ERROR) . ";";
|
||||
// FIXME: Move those to JSINFO
|
||||
print "Object.defineProperty(window, 'DOKU_UHN', { get: function() {".
|
||||
"console.warn('Using DOKU_UHN is deprecated. Please use JSINFO.useHeadingNavigation instead');".
|
||||
"return JSINFO.useHeadingNavigation; } });";
|
||||
print "Object.defineProperty(window, 'DOKU_UHC', { get: function() {".
|
||||
"console.warn('Using DOKU_UHC is deprecated. Please use JSINFO.useHeadingContent instead');".
|
||||
"return JSINFO.useHeadingContent; } });";
|
||||
print "Object.defineProperty(window, 'DOKU_UHN', { get: function() {" .
|
||||
"console.warn('Using DOKU_UHN is deprecated. Please use JSINFO.useHeadingNavigation instead');" .
|
||||
"return JSINFO.useHeadingNavigation; } });";
|
||||
print "Object.defineProperty(window, 'DOKU_UHC', { get: function() {" .
|
||||
"console.warn('Using DOKU_UHC is deprecated. Please use JSINFO.useHeadingContent instead');" .
|
||||
"return JSINFO.useHeadingContent; } });";
|
||||
|
||||
// load JS specific translations
|
||||
$lang['js']['plugins'] = js_pluginstrings();
|
||||
$templatestrings = js_templatestrings($tpl);
|
||||
if(!empty($templatestrings)) {
|
||||
if (!empty($templatestrings)) {
|
||||
$lang['js']['template'] = $templatestrings;
|
||||
}
|
||||
echo 'LANG = '.json_encode($lang['js'], JSON_THROW_ON_ERROR).";\n";
|
||||
echo 'LANG = ' . json_encode($lang['js'], JSON_THROW_ON_ERROR) . ";\n";
|
||||
|
||||
// load toolbar
|
||||
toolbar_JSdefines('toolbar');
|
||||
|
||||
// load files
|
||||
foreach($files as $file){
|
||||
if(!file_exists($file)) continue;
|
||||
foreach ($files as $file) {
|
||||
if (!file_exists($file)) continue;
|
||||
$ismin = (substr($file, -7) == '.min.js');
|
||||
$debugjs = ($conf['allowdebug'] && strpos($file, DOKU_INC.'lib/scripts/') !== 0);
|
||||
$debugjs = ($conf['allowdebug'] && strpos($file, DOKU_INC . 'lib/scripts/') !== 0);
|
||||
|
||||
echo "\n\n/* XXXXXXXXXX begin of ".str_replace(DOKU_INC, '', $file) ." XXXXXXXXXX */\n\n";
|
||||
if($ismin) echo "\n/* BEGIN NOCOMPRESS */\n";
|
||||
echo "\n\n/* XXXXXXXXXX begin of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";
|
||||
if ($ismin) echo "\n/* BEGIN NOCOMPRESS */\n";
|
||||
if ($debugjs) echo "\ntry {\n";
|
||||
js_load($file);
|
||||
if ($debugjs) echo "\n} catch (e) {\n logError(e, '".str_replace(DOKU_INC, '', $file)."');\n}\n";
|
||||
if($ismin) echo "\n/* END NOCOMPRESS */\n";
|
||||
if ($debugjs) echo "\n} catch (e) {\n logError(e, '" . str_replace(DOKU_INC, '', $file) . "');\n}\n";
|
||||
if ($ismin) echo "\n/* END NOCOMPRESS */\n";
|
||||
echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";
|
||||
}
|
||||
|
||||
// init stuff
|
||||
if($conf['locktime'] != 0){
|
||||
js_runonstart("dw_locktimer.init(".($conf['locktime'] - 60).",".$conf['usedraft'].")");
|
||||
if ($conf['locktime'] != 0) {
|
||||
js_runonstart("dw_locktimer.init(" . ($conf['locktime'] - 60) . "," . $conf['usedraft'] . ")");
|
||||
}
|
||||
// init hotkeys - must have been done after init of toolbar
|
||||
# disabled for FS#1958 js_runonstart('initializeHotkeys()');
|
||||
|
@ -152,11 +153,11 @@ function js_out()
|
|||
stripsourcemaps($js);
|
||||
|
||||
// compress whitespace and comments
|
||||
if($conf['compress']){
|
||||
if ($conf['compress']) {
|
||||
try {
|
||||
$js = (new JSStrip())->compress($js);
|
||||
} catch (JSStripException $e) {
|
||||
$js .= "\nconsole.error(".json_encode($e->getMessage(), JSON_THROW_ON_ERROR).");\n";
|
||||
$js .= "\nconsole.error(" . json_encode($e->getMessage(), JSON_THROW_ON_ERROR) . ");\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,30 +169,30 @@ function js_out()
|
|||
/**
|
||||
* Load the given file, handle include calls and print it
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @param string $file filename path to file
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
function js_load($file)
|
||||
{
|
||||
if(!file_exists($file)) return;
|
||||
if (!file_exists($file)) return;
|
||||
static $loaded = [];
|
||||
|
||||
$data = io_readFile($file);
|
||||
while(preg_match('#/\*\s*DOKUWIKI:include(_once)?\s+([\w\.\-_/]+)\s*\*/#', $data, $match)){
|
||||
while (preg_match('#/\*\s*DOKUWIKI:include(_once)?\s+([\w\.\-_/]+)\s*\*/#', $data, $match)) {
|
||||
$ifile = $match[2];
|
||||
|
||||
// is it a include_once?
|
||||
if($match[1]){
|
||||
if ($match[1]) {
|
||||
$base = PhpString::basename($ifile);
|
||||
if(array_key_exists($base, $loaded) && $loaded[$base] === true){
|
||||
$data = str_replace($match[0], '', $data);
|
||||
if (array_key_exists($base, $loaded) && $loaded[$base] === true) {
|
||||
$data = str_replace($match[0], '', $data);
|
||||
continue;
|
||||
}
|
||||
$loaded[$base] = true;
|
||||
}
|
||||
|
||||
if($ifile[0] != '/') $ifile = dirname($file).'/'.$ifile;
|
||||
if ($ifile[0] != '/') $ifile = dirname($file) . '/' . $ifile;
|
||||
|
||||
$idata = '';
|
||||
if (file_exists($ifile)) {
|
||||
|
@ -200,7 +201,7 @@ function js_load($file)
|
|||
$idata .= io_readFile($ifile);
|
||||
if ($ismin) $idata .= "\n/* END NOCOMPRESS */\n";
|
||||
}
|
||||
$data = str_replace($match[0], $idata, $data);
|
||||
$data = str_replace($match[0], $idata, $data);
|
||||
}
|
||||
echo "$data\n";
|
||||
}
|
||||
|
@ -208,16 +209,16 @@ function js_load($file)
|
|||
/**
|
||||
* Returns a list of possible Plugin Scripts (no existance check here)
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
function js_pluginscripts()
|
||||
{
|
||||
$list = [];
|
||||
$plugins = plugin_list();
|
||||
foreach ($plugins as $p){
|
||||
$list[] = DOKU_PLUGIN."$p/script.js";
|
||||
foreach ($plugins as $p) {
|
||||
$list[] = DOKU_PLUGIN . "$p/script.js";
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
@ -228,39 +229,39 @@ function js_pluginscripts()
|
|||
* - $lang['js'] must be an array.
|
||||
* - Nothing is returned for plugins without an entry for $lang['js']
|
||||
*
|
||||
* @return array
|
||||
* @author Gabriel Birke <birke@d-scribe.de>
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function js_pluginstrings()
|
||||
{
|
||||
global $conf, $config_cascade;
|
||||
$pluginstrings = [];
|
||||
$plugins = plugin_list();
|
||||
foreach($plugins as $p) {
|
||||
foreach ($plugins as $p) {
|
||||
$path = DOKU_PLUGIN . $p . '/lang/';
|
||||
|
||||
if(isset($lang)) unset($lang);
|
||||
if(file_exists($path . "en/lang.php")) {
|
||||
if (isset($lang)) unset($lang);
|
||||
if (file_exists($path . "en/lang.php")) {
|
||||
include $path . "en/lang.php";
|
||||
}
|
||||
foreach($config_cascade['lang']['plugin'] as $config_file) {
|
||||
if(file_exists($config_file . $p . '/en/lang.php')) {
|
||||
foreach ($config_cascade['lang']['plugin'] as $config_file) {
|
||||
if (file_exists($config_file . $p . '/en/lang.php')) {
|
||||
include($config_file . $p . '/en/lang.php');
|
||||
}
|
||||
}
|
||||
if(isset($conf['lang']) && $conf['lang'] != 'en') {
|
||||
if(file_exists($path . $conf['lang'] . "/lang.php")) {
|
||||
if (isset($conf['lang']) && $conf['lang'] != 'en') {
|
||||
if (file_exists($path . $conf['lang'] . "/lang.php")) {
|
||||
include($path . $conf['lang'] . '/lang.php');
|
||||
}
|
||||
foreach($config_cascade['lang']['plugin'] as $config_file) {
|
||||
if(file_exists($config_file . $p . '/' . $conf['lang'] . '/lang.php')) {
|
||||
foreach ($config_cascade['lang']['plugin'] as $config_file) {
|
||||
if (file_exists($config_file . $p . '/' . $conf['lang'] . '/lang.php')) {
|
||||
include($config_file . $p . '/' . $conf['lang'] . '/lang.php');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($lang['js'])) {
|
||||
if (isset($lang['js'])) {
|
||||
$pluginstrings[$p] = $lang['js'];
|
||||
}
|
||||
}
|
||||
|
@ -283,29 +284,29 @@ function js_templatestrings($tpl)
|
|||
$path = tpl_incdir() . 'lang/';
|
||||
|
||||
$templatestrings = [];
|
||||
if(file_exists($path . "en/lang.php")) {
|
||||
if (file_exists($path . "en/lang.php")) {
|
||||
include $path . "en/lang.php";
|
||||
}
|
||||
foreach($config_cascade['lang']['template'] as $config_file) {
|
||||
if(file_exists($config_file . $conf['template'] . '/en/lang.php')) {
|
||||
foreach ($config_cascade['lang']['template'] as $config_file) {
|
||||
if (file_exists($config_file . $conf['template'] . '/en/lang.php')) {
|
||||
include($config_file . $conf['template'] . '/en/lang.php');
|
||||
}
|
||||
}
|
||||
if(isset($conf['lang']) && $conf['lang'] != 'en' && file_exists($path . $conf['lang'] . "/lang.php")) {
|
||||
if (isset($conf['lang']) && $conf['lang'] != 'en' && file_exists($path . $conf['lang'] . "/lang.php")) {
|
||||
include $path . $conf['lang'] . "/lang.php";
|
||||
}
|
||||
if(isset($conf['lang']) && $conf['lang'] != 'en') {
|
||||
if(file_exists($path . $conf['lang'] . "/lang.php")) {
|
||||
if (isset($conf['lang']) && $conf['lang'] != 'en') {
|
||||
if (file_exists($path . $conf['lang'] . "/lang.php")) {
|
||||
include $path . $conf['lang'] . "/lang.php";
|
||||
}
|
||||
foreach($config_cascade['lang']['template'] as $config_file) {
|
||||
if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
|
||||
foreach ($config_cascade['lang']['template'] as $config_file) {
|
||||
if (file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
|
||||
include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($lang['js'])) {
|
||||
if (isset($lang['js'])) {
|
||||
$templatestrings[$tpl] = $lang['js'];
|
||||
}
|
||||
return $templatestrings;
|
||||
|
@ -315,10 +316,10 @@ function js_templatestrings($tpl)
|
|||
* Escapes a String to be embedded in a JavaScript call, keeps \n
|
||||
* as newline
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
function js_escape($string)
|
||||
{
|
||||
|
@ -328,11 +329,11 @@ function js_escape($string)
|
|||
/**
|
||||
* Adds the given JavaScript code to the window.onload() event
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @param string $func
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
function js_runonstart($func)
|
||||
{
|
||||
echo "jQuery(function(){ $func; });".NL;
|
||||
echo "jQuery(function(){ $func; });" . NL;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
<?php
|
||||
|
||||
use dokuwiki\Manifest;
|
||||
|
||||
if (!defined('DOKU_INC')) {
|
||||
define('DOKU_INC', __DIR__ . '/../../');
|
||||
}
|
||||
if(!defined('NOSESSION')) define('NOSESSION', true); // no session or auth required here
|
||||
if (!defined('NOSESSION')) define('NOSESSION', true); // no session or auth required here
|
||||
require_once(DOKU_INC . 'inc/init.php');
|
||||
|
||||
if (!actionOK('manifest')) {
|
||||
|
|
|
@ -8,31 +8,29 @@
|
|||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
|
||||
if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__.'/../../');
|
||||
if(!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
|
||||
if(!defined('NL')) define('NL', "\n");
|
||||
require_once(DOKU_INC.'inc/init.php');
|
||||
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../');
|
||||
if (!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
|
||||
if (!defined('NL')) define('NL', "\n");
|
||||
require_once(DOKU_INC . 'inc/init.php');
|
||||
|
||||
// try to be clever about the favicon location
|
||||
if(file_exists(DOKU_INC.'favicon.ico')){
|
||||
$ico = DOKU_URL.'favicon.ico';
|
||||
}elseif(file_exists(tpl_incdir().'images/favicon.ico')){
|
||||
$ico = DOKU_URL.'lib/tpl/'.$conf['template'].'/images/favicon.ico';
|
||||
}elseif(file_exists(tpl_incdir().'favicon.ico')){
|
||||
$ico = DOKU_URL.'lib/tpl/'.$conf['template'].'/favicon.ico';
|
||||
}else{
|
||||
$ico = DOKU_URL.'lib/tpl/dokuwiki/images/favicon.ico';
|
||||
if (file_exists(DOKU_INC . 'favicon.ico')) {
|
||||
$ico = DOKU_URL . 'favicon.ico';
|
||||
} elseif (file_exists(tpl_incdir() . 'images/favicon.ico')) {
|
||||
$ico = DOKU_URL . 'lib/tpl/' . $conf['template'] . '/images/favicon.ico';
|
||||
} elseif (file_exists(tpl_incdir() . 'favicon.ico')) {
|
||||
$ico = DOKU_URL . 'lib/tpl/' . $conf['template'] . '/favicon.ico';
|
||||
} else {
|
||||
$ico = DOKU_URL . 'lib/tpl/dokuwiki/images/favicon.ico';
|
||||
}
|
||||
|
||||
// output
|
||||
header('Content-Type: application/opensearchdescription+xml; charset=utf-8');
|
||||
echo '<?xml version="1.0"?>'.NL;
|
||||
echo '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">'.NL;
|
||||
echo ' <ShortName>'.hsc($conf['title']).'</ShortName>'.NL;
|
||||
echo ' <Image width="16" height="16" type="image/x-icon">'.$ico.'</Image>'.NL;
|
||||
echo ' <Url type="text/html" template="'.DOKU_URL.DOKU_SCRIPT.'?do=search&id={searchTerms}" />'.NL;
|
||||
echo ' <Url type="application/x-suggestions+json" template="'.
|
||||
DOKU_URL.'lib/exe/ajax.php?call=suggestions&q={searchTerms}" />'.NL;
|
||||
echo '</OpenSearchDescription>'.NL;
|
||||
|
||||
//Setup VIM: ex: et ts=4 :
|
||||
echo '<?xml version="1.0"?>' . NL;
|
||||
echo '<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">' . NL;
|
||||
echo ' <ShortName>' . hsc($conf['title']) . '</ShortName>' . NL;
|
||||
echo ' <Image width="16" height="16" type="image/x-icon">' . $ico . '</Image>' . NL;
|
||||
echo ' <Url type="text/html" template="' . DOKU_URL . DOKU_SCRIPT . '?do=search&id={searchTerms}" />' . NL;
|
||||
echo ' <Url type="application/x-suggestions+json" template="' .
|
||||
DOKU_URL . 'lib/exe/ajax.php?call=suggestions&q={searchTerms}" />' . NL;
|
||||
echo '</OpenSearchDescription>' . NL;
|
||||
|
|
|
@ -12,7 +12,7 @@ if (!defined('DOKU_INC')) {
|
|||
define('DOKU_INC', __DIR__ . '/../../');
|
||||
}
|
||||
define('DOKU_DISABLE_GZIP_OUTPUT', 1);
|
||||
require_once DOKU_INC.'inc/init.php';
|
||||
require_once DOKU_INC . 'inc/init.php';
|
||||
session_write_close(); //close session
|
||||
|
||||
$taskRunner = new TaskRunner();
|
||||
|
|
Loading…
Reference in New Issue