Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The final changes - issu18 #23

Merged
merged 2 commits into from
Aug 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions connectors/php/LocalFilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ public function getfolder()

if(is_dir($current_path . $file)) {
if(!in_array($file, $this->config['exclude']['unallowed_dirs']) && !preg_match($this->config['exclude']['unallowed_dirs_REGEXP'], $file)) {
$array[$file_path . '/'] = $this->get_file_info($file_path . '/', true);
$array[$file_path . '/'] = $this->get_file_info($file_path . '/');
}
} else if (!in_array($file, $this->config['exclude']['unallowed_files']) && !preg_match($this->config['exclude']['unallowed_files_REGEXP'], $file)) {
$item = $this->get_file_info($file_path, true);
$item = $this->get_file_info($file_path);

if(!isset($this->refParams['type']) || (isset($this->refParams['type']) && strtolower($this->refParams['type']) === 'images' && in_array(strtolower($item['File Type']), array_map('strtolower', $this->config['images']['imagesExt'])))) {
if($this->config['upload']['imagesOnly']== false || ($this->config['upload']['imagesOnly'] === true && in_array(strtolower($item['File Type']), array_map('strtolower', $this->config['images']['imagesExt'])))) {
Expand Down Expand Up @@ -186,7 +186,7 @@ public function getinfo()
$this->error(sprintf($this->lang('NOT_ALLOWED')));
}

return $this->get_file_info($path, false);
return $this->get_file_info($path);
}

/**
Expand Down Expand Up @@ -826,13 +826,12 @@ protected function has_system_permission($filepath, $permissions)
return true;
}

/**
* Create array with file properties
* @param string $relative_path
* @param bool $thumbnail
* @return array|void
*/
protected function get_file_info($relative_path, $thumbnail = false)
/**
* Create array with file properties
* @param string $relative_path
* @return array|void
*/
protected function get_file_info($relative_path)
{
$current_path = $this->getFullPath($relative_path);
$dynamic_path = $this->getDynamicPath($current_path);
Expand All @@ -842,33 +841,41 @@ protected function get_file_info($relative_path, $thumbnail = false)
$filemtime = filemtime($current_path);
$iconsFolder = $this->getFmUrl($this->config['icons']['path']);

// tell if we serve the files directly or if we should pass through the connector
$beyondDocRoot = stripos(realpath($this->path_to_files), realpath($this->doc_root)) !== 0;
$getImageMode = $this->connector_script_url . '?mode=getimage&path=' . rawurlencode($relative_path) . '&time=' . time();
$readFileMode = $this->connector_script_url . '?mode=readfile&path=' . rawurlencode($relative_path) . '&time=' . time();

// check if file is writable and readable
$protected = $this->has_system_permission($current_path, array('w', 'r')) ? 0 : 1;
$preview = $beyondDocRoot ? $readFileMode : $dynamic_path;

if(is_dir($current_path)) {
$fileType = self::FILE_TYPE_DIR;
$imagePath = $iconsFolder . ($protected ? 'locked_' : '') . $this->config['icons']['directory'];
$thumbPath = $iconsFolder . ($protected ? 'locked_' : '') . $this->config['icons']['directory'];
} else {
$fileType = $pathInfo['extension'];
if($protected == 1) {
$imagePath = $iconsFolder . 'locked_' . $this->config['icons']['default'];
$thumbPath = $iconsFolder . 'locked_' . $this->config['icons']['default'];
} else {
$imagePath = $iconsFolder . $this->config['icons']['default'];
$item['Properties']['Size'] = $this->get_real_filesize($current_path);
$thumbPath = $iconsFolder . $this->config['icons']['default'];

if(in_array(strtolower($fileType), array_map('strtolower', $this->config['images']['imagesExt']))) {
$isAllowedImage = in_array(strtolower($fileType), array_map('strtolower', $this->config['images']['imagesExt']));
$isImageWithThumb = $isAllowedImage && $this->config['options']['showThumbs'] ;
$useImageThumb = $this->config['options']['showThumbs'];

// svg should not be previewed as raster formats images
if($fileType === 'svg') {
$imagePath = $beyondDocRoot ? $readFileMode : $dynamic_path;
} else if($thumbnail && $this->config['options']['showThumbs']) {
$imagePath = $getImageMode . '&thumbnail=true';
} else {
$imagePath = $beyondDocRoot ? $getImageMode : $dynamic_path;
if(!$isImageWithThumb && file_exists($this->fm_path . '/' . $this->config['icons']['path'] . strtolower($fileType) . '.png')) {
$thumbPath = $iconsFolder . strtolower($fileType) . '.png';
}

if($isAllowedImage){
// svg don't need to generate a thumb
if($useImageThumb && $fileType === 'svg'){
$thumbPath = $preview;
} else{
$preview = $beyondDocRoot ? $getImageMode : $dynamic_path;
if($useImageThumb) $thumbPath = $beyondDocRoot ? $getImageMode . '&thumbnail=true' : $this->getDynamicPath($this->get_thumbnail($current_path));
}

if($item['Properties']['Size']) {
Expand All @@ -879,8 +886,6 @@ protected function get_file_info($relative_path, $thumbnail = false)

$item['Properties']['Height'] = $height;
$item['Properties']['Width'] = $width;
} else if(file_exists($this->fm_path . '/' . $this->config['icons']['path'] . strtolower($fileType) . '.png')) {
$imagePath = $iconsFolder . strtolower($fileType) . '.png';
}
}
}
Expand All @@ -889,8 +894,8 @@ protected function get_file_info($relative_path, $thumbnail = false)
$item['Filename'] = $pathInfo['basename'];
$item['File Type'] = $fileType;
$item['Protected'] = $protected;
$item['Image Path'] = $imagePath;
$item['Dynamic Path'] = $beyondDocRoot ? $readFileMode : $dynamic_path;
$item['Thumbnail'] = $thumbPath;
$item['Preview'] = $beyondDocRoot ? $readFileMode : $dynamic_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 @@ -1266,10 +1271,10 @@ protected function get_thumbnail($path)

/**
* Creates thumbnail from the original image
* @param $imagePath
* @param $thumbPath
* @param $thumbnailPath
*/
protected function createThumbnail($imagePath, $thumbnailPath)
protected function createThumbnail($thumbPath, $thumbnailPath)
{
if($this->config['images']['thumbnail']['enabled'] === true) {
$this->__log('generating thumbnail "' . $thumbnailPath . '"');
Expand All @@ -1280,9 +1285,9 @@ protected function createThumbnail($imagePath, $thumbnailPath)
}

$this->initUploader(array(
'upload_dir' => dirname($imagePath) . '/',
))->create_thumbnail_image($imagePath);
'upload_dir' => dirname($thumbPath) . '/',
))->create_thumbnail_image($thumbPath);
}
}

}
}
21 changes: 11 additions & 10 deletions scripts/filemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ var createPreviewUrl = function(path, encode) {

// Return HTML video player
var getVideoPlayer = function(data) {
var url = createPreviewUrl(data['Dynamic Path'], true);
var url = createPreviewUrl(data['Preview'], true);
var code = '<video src="' + url + '" width=' + config.videos.videosPlayerWidth + ' height=' + config.videos.videosPlayerHeight + ' controls="controls"></video>';

$fileinfo.find('img').remove();
Expand All @@ -549,7 +549,7 @@ var getVideoPlayer = function(data) {

// Return HTML audio player
var getAudioPlayer = function(data) {
var url = createPreviewUrl(data['Dynamic Path'], true);
var url = createPreviewUrl(data['Preview'], true);
var code = '<audio src="' + url + '" controls="controls"></audio>';

$fileinfo.find('img').remove();
Expand All @@ -558,7 +558,7 @@ var getAudioPlayer = function(data) {

// Return PDF Reader
var getPdfReader = function(data) {
var url = createPreviewUrl(data['Dynamic Path'], true);
var url = createPreviewUrl(data['Preview'], true);
var code = '<iframe id="fm-pdf-viewer" src="' + config.globals.pluginPath + '/scripts/ViewerJS/index.html#' + url + '" width="' + config.pdfs.pdfsReaderWidth + '" height="' + config.pdfs.pdfsReaderHeight + '" allowfullscreen webkitallowfullscreen></iframe>';

$fileinfo.find('img').remove();
Expand All @@ -567,7 +567,7 @@ var getPdfReader = function(data) {

// Return Google Viewer
var getGoogleViewer = function(data) {
var url = encodeURIComponent(createPreviewUrl(data['Dynamic Path']));
var url = encodeURIComponent(createPreviewUrl(data['Preview']));
var code = '<iframe id="fm-google-viewer" src="http://docs.google.com/viewer?url=' + url + '&embedded=true" width="' + config.docs.docsReaderWidth + '" height="' + config.docs.docsReaderHeight + '" allowfullscreen webkitallowfullscreen></iframe>';

$fileinfo.find('img').remove();
Expand Down Expand Up @@ -876,7 +876,7 @@ var createFileTree = function() {
// contextual menu option in list views.
// NOTE: closes the window when finished.
var selectItem = function(data) {
var url = createPreviewUrl(data['Dynamic Path']);
var url = createPreviewUrl(data['Preview']);
if(window.opener || window.tinyMCEPopup || $.urlParam('field_name') || $.urlParam('CKEditorCleanUpFuncNum') || $.urlParam('CKEditor') || $.urlParam('ImperaviElementId')) {
if(window.tinyMCEPopup) {
// use TinyMCE > 3.0 integration method
Expand Down Expand Up @@ -1853,7 +1853,8 @@ var getFileInfo = function(file) {

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

$fileinfo.find('img').attr('src', createPreviewUrl(data['Image Path']));
// if file is an image we display the preview
$fileinfo.find('img').attr('src', isImageFile(data['Filename']) ? createPreviewUrl(data['Preview']) : createPreviewUrl(data['Thumbnail']));
if(isVideoFile(data['Filename']) && config.videos.showVideoPlayer == true) {
getVideoPlayer(data);
}
Expand All @@ -1870,7 +1871,7 @@ var getFileInfo = function(file) {
editItem(data);
}

var url = createPreviewUrl(data['Dynamic 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 Expand Up @@ -1907,7 +1908,7 @@ var getFileInfo = function(file) {
// Clean up unnecessary item data
var prepareItemInfo = function(item) {
var data = $.extend({}, item);
delete data['Image Path'];
delete data['Thumbnail'];
delete data['Error'];
delete data['Code'];
return data;
Expand Down Expand Up @@ -1967,7 +1968,7 @@ var getFolderInfo = function(path) {
'data-path': item['Path']
}).data('itemdata', prepareItemInfo(item));

node = '<div class="clip"><img src="' + createPreviewUrl(item['Image Path']) + '" width="' + scaledWidth + '" alt="' + item['Path'] + '" /></div>';
node = '<div class="clip"><img src="' + createPreviewUrl(item['Thumbnail']) + '" width="' + scaledWidth + '" alt="' + item['Path'] + '" /></div>';
node += '<p>' + item['Filename'] + '</p>';
if(props['Width'] && props['Width'] != '') node += '<span class="meta dimensions">' + props['Width'] + 'x' + props['Height'] + '</span>';
if(props['Size'] && props['Size'] != '') node += '<span class="meta size">' + props['Size'] + '</span>';
Expand Down Expand Up @@ -2895,4 +2896,4 @@ if (!window.location.origin) {

$(window).load(function() {
$('#fileinfo').css({'left':$('#splitter .vsplitbar').width() + $('#filetree').width()});
});
});
Loading