summaryrefslogtreecommitdiff
path: root/lib/exe
diff options
context:
space:
mode:
Diffstat (limited to 'lib/exe')
-rw-r--r--lib/exe/ajax.php58
-rw-r--r--lib/exe/css.php48
-rw-r--r--lib/exe/fetch.php6
-rw-r--r--lib/exe/js.php16
-rw-r--r--lib/exe/mediamanager.php4
5 files changed, 87 insertions, 45 deletions
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php
index 6e2011cd9..1000094bc 100644
--- a/lib/exe/ajax.php
+++ b/lib/exe/ajax.php
@@ -41,7 +41,6 @@ if(function_exists($callfn)){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function ajax_qsearch(){
- global $conf;
global $lang;
global $INPUT;
@@ -89,15 +88,12 @@ function ajax_qsearch(){
* @author Mike Frysinger <vapier@gentoo.org>
*/
function ajax_suggestions() {
- global $conf;
- global $lang;
global $INPUT;
$query = cleanID($INPUT->post->str('q'));
if(empty($query)) $query = cleanID($INPUT->get->str('q'));
if(empty($query)) return;
- $data = array();
$data = ft_pageLookup($query);
if(!count($data)) return;
$data = array_keys($data);
@@ -214,7 +210,6 @@ function ajax_medians(){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function ajax_medialist(){
- global $conf;
global $NS;
global $INPUT;
@@ -234,13 +229,15 @@ function ajax_medialist(){
* @author Kate Arzamastseva <pshns@ukr.net>
*/
function ajax_mediadetails(){
- global $DEL, $NS, $IMG, $AUTH, $JUMPTO, $REV, $lang, $fullscreen, $conf, $INPUT;
+ global $IMG, $JUMPTO, $REV, $fullscreen, $INPUT;
$fullscreen = true;
require_once(DOKU_INC.'lib/exe/mediamanager.php');
+ $image = '';
if ($INPUT->has('image')) $image = cleanID($INPUT->str('image'));
if (isset($IMG)) $image = $IMG;
if (isset($JUMPTO)) $image = $JUMPTO;
+ $rev = false;
if (isset($REV) && !$JUMPTO) $rev = $REV;
html_msgarea();
@@ -255,6 +252,7 @@ function ajax_mediadiff(){
global $NS;
global $INPUT;
+ $image = '';
if ($INPUT->has('image')) $image = cleanID($INPUT->str('image'));
$NS = $INPUT->post->str('ns');
$auth = auth_quickaclcheck("$NS:*");
@@ -264,6 +262,7 @@ function ajax_mediadiff(){
function ajax_mediaupload(){
global $NS, $MSG, $INPUT;
+ $id = '';
if ($_FILES['qqfile']['tmp_name']) {
$id = $INPUT->post->str('mediaid', $_FILES['qqfile']['name']);
} elseif ($INPUT->get->has('qqfile')) {
@@ -280,44 +279,33 @@ function ajax_mediaupload(){
if ($_FILES['qqfile']['error']) unset($_FILES['qqfile']);
+ $res = false;
if ($_FILES['qqfile']['tmp_name']) $res = media_upload($NS, $AUTH, $_FILES['qqfile']);
if ($INPUT->get->has('qqfile')) $res = media_upload_xhr($NS, $AUTH);
- if ($res) $result = array('success' => true,
- 'link' => media_managerURL(array('ns' => $ns, 'image' => $NS.':'.$id), '&'),
- 'id' => $NS.':'.$id, 'ns' => $NS);
-
- if (!$result) {
+ if($res) {
+ $result = array(
+ 'success' => true,
+ 'link' => media_managerURL(array('ns' => $ns, 'image' => $NS . ':' . $id), '&'),
+ 'id' => $NS . ':' . $id,
+ 'ns' => $NS
+ );
+ } else {
$error = '';
- if (isset($MSG)) {
- foreach($MSG as $msg) $error .= $msg['msg'];
+ if(isset($MSG)) {
+ foreach($MSG as $msg) {
+ $error .= $msg['msg'];
+ }
}
- $result = array('error' => $msg['msg'], 'ns' => $NS);
+ $result = array(
+ 'error' => $error,
+ 'ns' => $NS
+ );
}
$json = new JSON;
echo htmlspecialchars($json->encode($result), ENT_NOQUOTES);
}
-function dir_delete($path) {
- if (!is_string($path) || $path == "") return false;
-
- if (is_dir($path) && !is_link($path)) {
- if (!$dh = @opendir($path)) return false;
-
- while ($f = readdir($dh)) {
- if ($f == '..' || $f == '.') continue;
- dir_delete("$path/$f");
- }
-
- closedir($dh);
- return @rmdir($path);
- } else {
- return @unlink($path);
- }
-
- return false;
-}
-
/**
* Return sub index for index view
*
@@ -359,13 +347,11 @@ function ajax_linkwiz(){
$id = cleanID($id);
$nsd = utf8_encodeFN(str_replace(':','/',$ns));
- $idd = utf8_encodeFN(str_replace(':','/',$id));
$data = array();
if($q && !$ns){
// use index to lookup matching pages
- $pages = array();
$pages = ft_pageLookup($id,true);
// result contains matches in pages and namespaces
diff --git a/lib/exe/css.php b/lib/exe/css.php
index c96dedd37..30d0d18c5 100644
--- a/lib/exe/css.php
+++ b/lib/exe/css.php
@@ -56,7 +56,7 @@ function css_out(){
}
// cache influencers
- $tplinc = tpl_basedir($tpl);
+ $tplinc = tpl_incdir($tpl);
$cache_files = getConfigFiles('main');
$cache_files[] = $tplinc.'style.ini';
$cache_files[] = $tplinc.'style.local.ini'; // @deprecated
@@ -70,6 +70,7 @@ function css_out(){
$files[$mediatype] = array();
// load core styles
$files[$mediatype][DOKU_INC.'lib/styles/'.$mediatype.'.css'] = DOKU_BASE.'lib/styles/';
+
// load jQuery-UI theme
if ($mediatype == 'screen') {
$files[$mediatype][DOKU_INC.'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE.'lib/scripts/jquery/jquery-ui-theme/';
@@ -132,6 +133,9 @@ function css_out(){
$css = ob_get_contents();
ob_end_clean();
+ // strip any source maps
+ stripsourcemaps($css);
+
// apply style replacements
$css = css_applystyle($css, $styleini['replacements']);
@@ -456,8 +460,9 @@ class DokuCssFile {
if (defined('DOKU_UNITTEST')) {
$basedir[] = realpath(TMP_DIR);
}
- $regex = '#^('.join('|',$basedir).')#';
+ $basedir = array_map('preg_quote_cb', $basedir);
+ $regex = '/^('.join('|',$basedir).')/';
$this->relative_path = preg_replace($regex, '', dirname($this->filepath));
}
@@ -550,7 +555,7 @@ function css_compress($css){
$css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css);
//strip (incorrect but common) one line comments
- $css = preg_replace('/(?<!:)\/\/.*$/m','',$css);
+ $css = preg_replace_callback('/^.*\/\/.*$/m','css_onelinecomment_cb',$css);
// strip whitespaces
$css = preg_replace('![\r\n\t ]+!',' ',$css);
@@ -586,4 +591,41 @@ function css_comment_cb($matches){
return $matches[0];
}
+/**
+ * Callback for css_compress()
+ *
+ * Strips one line comments but makes sure it will not destroy url() constructs with slashes
+ *
+ * @param $matches
+ * @return string
+ */
+function css_onelinecomment_cb($matches) {
+ $line = $matches[0];
+
+ $out = '';
+ $i = 0;
+ $len = strlen($line);
+ while ($i< $len){
+ $nextcom = strpos($line, '//', $i);
+ $nexturl = stripos($line, 'url(', $i);
+
+ if($nextcom === false) {
+ // no more comments, we're done
+ $out .= substr($line, $i, $len-$i);
+ break;
+ }
+ if($nexturl === false || $nextcom < $nexturl) {
+ // no url anymore, strip comment and be done
+ $out .= substr($line, $i, $nextcom-$i);
+ break;
+ }
+ // we have an upcoming url
+ $urlclose = strpos($line, ')', $nexturl);
+ $out .= substr($line, $i, $urlclose-$i);
+ $i = $urlclose;
+ }
+
+ return $out;
+}
+
//Setup VIM: ex: et ts=4 :
diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php
index 5967494bf..933367e35 100644
--- a/lib/exe/fetch.php
+++ b/lib/exe/fetch.php
@@ -78,8 +78,8 @@ if (defined('SIMPLE_TEST')) {
unset($evt);
//handle image resizing/cropping
- if((substr($MIME, 0, 5) == 'image') && $WIDTH) {
- if($HEIGHT) {
+ if((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);
@@ -89,7 +89,7 @@ if (defined('SIMPLE_TEST')) {
// finally send the file to the client
$evt = new Doku_Event('MEDIA_SENDFILE', $data);
if($evt->advise_before()) {
- sendFile($data['file'], $data['mime'], $data['download'], $data['cache'], $data['ispublic']);
+ sendFile($data['file'], $data['mime'], $data['download'], $data['cache'], $data['ispublic'], $data['orig']);
}
// Do something after the download finished.
$evt->advise_after(); // will not be emitted on 304 or x-sendfile
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 040b8874d..bec12ef7a 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -44,6 +44,7 @@ function js_out(){
DOKU_INC.'lib/scripts/jquery/jquery.cookie.js',
DOKU_INC."lib/scripts/jquery/jquery-ui$min.js",
DOKU_INC."lib/scripts/jquery/jquery-migrate$min.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',
@@ -112,6 +113,7 @@ function js_out(){
// load files
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);
@@ -135,6 +137,9 @@ function js_out(){
$js = ob_get_contents();
ob_end_clean();
+ // strip any source maps
+ stripsourcemaps($js);
+
// compress whitespace and comments
if($conf['compress']){
$js = js_compress($js);
@@ -161,7 +166,10 @@ function js_load($file){
// is it a include_once?
if($match[1]){
$base = utf8_basename($ifile);
- if($loaded[$base]) continue;
+ if($loaded[$base]){
+ $data = str_replace($match[0], '' ,$data);
+ continue;
+ }
$loaded[$base] = true;
}
@@ -218,6 +226,12 @@ function js_pluginstrings() {
return $pluginstrings;
}
+/**
+ * Return an two-dimensional array with strings from the language file of current active template.
+ *
+ * - $lang['js'] must be an array.
+ * - Nothing is returned for template without an entry for $lang['js']
+ */
function js_templatestrings() {
global $conf;
$templatestrings = array();
diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php
index d94a24c74..7044232ce 100644
--- a/lib/exe/mediamanager.php
+++ b/lib/exe/mediamanager.php
@@ -57,7 +57,7 @@
}
// give info on PHP caught upload errors
- if($_FILES['upload']['error']){
+ if(!empty($_FILES['upload']['error'])){
switch($_FILES['upload']['error']){
case 1:
case 2:
@@ -71,7 +71,7 @@
}
// handle upload
- if($_FILES['upload']['tmp_name']){
+ if(!empty($_FILES['upload']['tmp_name'])){
$JUMPTO = media_upload($NS,$AUTH);
if($JUMPTO) $NS = getNS($JUMPTO);
}