Skip to content

Commit

Permalink
Merge pull request #20 from fabriceci/issue-18
Browse files Browse the repository at this point in the history
PR - Issue 18
  • Loading branch information
Pavel Solomienko authored Aug 6, 2016
2 parents 3721025 + 5946ad4 commit c866e93
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
15 changes: 4 additions & 11 deletions connectors/php/LocalFilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -846,11 +846,8 @@ protected function get_file_info($relative_path, $thumbnail = false)

if($this->config['options']['showThumbs'] && in_array(strtolower($fileType), array_map('strtolower', $this->config['images']['imagesExt']))) {
// svg should not be previewed as raster formats images
if($fileType === 'svg') {
$thumbPath = $relative_path;
} else {
$thumbPath = $this->connector_script_url . '?mode=getimage&path=' . rawurlencode($relative_path) . '&time=' . time();
if($thumbnail) $thumbPath .= '&thumbnail=true';
if($thumbnail && $fileType !== 'svg'){
$thumbPath = $this->connector_script_url . '?mode=getimage&path=' . rawurlencode($relative_path) . '&time=' . time() . '&thumbnail=true' ;
}

if($item['Properties']['Size']) {
Expand All @@ -872,11 +869,7 @@ protected function get_file_info($relative_path, $thumbnail = false)
$item['File Type'] = $fileType;
$item['Protected'] = $protected;
$item['Thumbnail'] = $thumbPath;
// for preview mode only
if($thumbnail === false) {
$item['Preview'] = $this->getDynamicPath($current_path);
}

$item['Preview'] = $this->getDynamicPath($current_path);
$item['Properties']['Date Modified'] = $this->formatDate($filemtime);
//$item['Properties']['Date Created'] = $this->formatDate(filectime($current_path)); // PHP cannot get create timestamp
$item['Properties']['filemtime'] = $filemtime;
Expand Down Expand Up @@ -1271,4 +1264,4 @@ protected function createThumbnail($imagePath, $thumbnailPath)
}
}

}
}
42 changes: 34 additions & 8 deletions scripts/filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ $.urlParam = function(name) {
}
};

// function to normalize a path (source: https://github.com/dfkaye/simple-path-normalize)
var normalizePath = function(path){
var BLANK = ''; var SLASH = '/'; var DOT = '.';var DOTS = DOT.concat(DOT);
if (!path || path === SLASH) {
return SLASH;
}

var src = path.split(SLASH);
var target = (path[0] === SLASH || path[0] === DOT) ? [BLANK] : [];
var i, len, token;
for (i = 0, len = src.length; i < len; ++i) {
token = src[i] || BLANK;
if (token === DOTS) {
if (target.length > 1) {
target.pop();
}
} else if (token !== BLANK && token !== DOT) {
target.push(token);
}
}
return target.join(SLASH).replace(/[\/]{2, }/g, SLASH) || SLASH;
};

/*---------------------------------------------------------
Setup, Layout, and Status Functions
---------------------------------------------------------*/
Expand Down Expand Up @@ -514,9 +537,13 @@ var isDocumentFile = function(filename) {
}
};

// Build url to preview office and media files
// Build url to preview files
var createPreviewUrl = function(path) {
return location.origin + location.pathname + path;
// already an absolute path
if(path.substr(0,4) === 'http' || path.substr(0,3) === 'ftp')
return path;

return location.origin + normalizePath(location.pathname + path);
};

// Return HTML video player
Expand Down Expand Up @@ -843,7 +870,6 @@ var createFileTree = function() {
});
};


/*---------------------------------------------------------
Item Actions
---------------------------------------------------------*/
Expand All @@ -856,9 +882,9 @@ var createFileTree = function() {
// NOTE: closes the window when finished.
var selectItem = function(data) {
if(config.options.baseUrl !== false ) {
var url = smartPath(baseUrl, data['Path'].replace(fileRoot, ""));
var url = smartPath(baseUrl, data['Preview'].replace(fileRoot, ""));
} else {
var url = data['Path'];
var url = createPreviewUrl(data['Preview']);
}

if(window.opener || window.tinyMCEPopup || $.urlParam('field_name') || $.urlParam('CKEditorCleanUpFuncNum') || $.urlParam('CKEditor') || $.urlParam('ImperaviElementId')) {
Expand Down Expand Up @@ -1837,7 +1863,7 @@ var getFileInfo = function(file) {

$fileinfo.find('#main-title > h1').text(data['Filename']).attr('title', file);

$fileinfo.find('img').attr('src', data['Thumbnail']);
$fileinfo.find('img').attr('src', createPreviewUrl(data["Preview"]));
if(isVideoFile(data['Filename']) && config.videos.showVideoPlayer == true) {
getVideoPlayer(data);
}
Expand All @@ -1855,9 +1881,9 @@ var getFileInfo = function(file) {
}

if(config.options.baseUrl !== false ) {
var url = smartPath(baseUrl, data['Path'].replace(fileRoot, ""));
var url = smartPath(baseUrl, data['Preview'].replace(fileRoot, ""));
} else {
var url = data['Path'];
var url = createPreviewUrl(data['Preview']);
}
if(data['Protected']==0) {
$fileinfo.find('div#tools').append(' <a id="copy-button" data-clipboard-text="'+ url + '" title="' + lg.copy_to_clipboard + '" href="#"><span>' + lg.copy_to_clipboard + '</span></a>');
Expand Down
Loading

0 comments on commit c866e93

Please sign in to comment.