From bb9ababf981ef58594a914cdf3d436f537588bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Enguehard?= Date: Fri, 4 Oct 2013 12:59:37 +0200 Subject: [PATCH] REG_admin : ajout $sys['base_dir'] : gestion VirtualDocumentRoot & DocumentRoot & gestion lien symbolique reg_librairies --- connectors/php/filemanager.class.php | 1712 +++++++++++++------------ connectors/php/filemanager.php | 305 +++-- scripts/filemanager.config.js.default | 48 +- scripts/filemanager.js | 271 ++-- scripts/filemanager.min.js | 41 +- 5 files changed, 1193 insertions(+), 1184 deletions(-) diff --git a/connectors/php/filemanager.class.php b/connectors/php/filemanager.class.php index 619debe4..e12cf57f 100755 --- a/connectors/php/filemanager.class.php +++ b/connectors/php/filemanager.class.php @@ -1,851 +1,883 @@ - - * @author Simon Georget - * @copyright Authors - */ - -class Filemanager { - - protected $config = array(); - protected $language = array(); - protected $get = array(); - protected $post = array(); - protected $properties = array(); - protected $item = array(); - protected $languages = array(); - protected $root = ''; - protected $doc_root = ''; - protected $dynamic_fileroot = ''; - protected $logger = false; - protected $logfile = '/tmp/filemanager.log'; - protected $cachefolder = '_thumbs/'; - protected $thumbnail_width = 64; - protected $thumbnail_height = 64; - protected $separator = 'userfiles'; // @todo fix keep it or not? - - public function __construct($extraConfig = '') { - - $content = file_get_contents("../../scripts/filemanager.config.js"); - $config = json_decode($content, true); - - $this->config = $config; - - // override config options if needed - if(!empty($extraConfig)) { - $this->setup($extraConfig); - } - - $this->root = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR; - $this->properties = array( - 'Date Created'=>null, - 'Date Modified'=>null, - 'Height'=>null, - 'Width'=>null, - 'Size'=>null - ); - - // Log actions or not? - if ($this->config['options']['logger'] == true ) { - if(isset($this->config['options']['logfile'])) { - $this->logfile = $this->config['options']['logfile']; - } - $this->enableLog(); - } - - // if fileRoot is set manually, $this->doc_root takes fileRoot value - // for security check in isValidPath() method - // else it takes $_SERVER['DOCUMENT_ROOT'] default value - if ($this->config['options']['fileRoot'] !== false ) { - if($this->config['options']['serverRoot'] === true) { - $this->doc_root = $_SERVER['DOCUMENT_ROOT']; - $this->separator = basename($this->config['options']['fileRoot']); - } else { - $this->doc_root = $this->config['options']['fileRoot']; - $this->separator = basename($this->config['options']['fileRoot']); - } - } else { - $this->doc_root = $_SERVER['DOCUMENT_ROOT']; - } - - $this->__log(__METHOD__ . ' $this->doc_root value ' . $this->doc_root); - $this->__log(__METHOD__ . ' $this->separator value ' . $this->separator); - - $this->setParams(); - $this->availableLanguages(); - $this->loadLanguageFile(); - } - - // $extraconfig should be formatted as json config array. - public function setup($extraconfig) { - - $this->config = array_merge_recursive($this->config, $extraconfig); - - } - - // allow Filemanager to be used with dynamic folders - public function setFileRoot($path) { - - if($this->config['options']['serverRoot'] === true) { - $this->doc_root = $_SERVER['DOCUMENT_ROOT']. '/'. $path; - } else { - $this->doc_root = $path; - } - - // necessary for retrieving path when set dynamically with $fm->setFileRoot() method - $this->dynamic_fileroot = str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->doc_root); - $this->separator = basename($this->doc_root); - - $this->__log(__METHOD__ . ' $this->doc_root value overwritten : ' . $this->doc_root); - $this->__log(__METHOD__ . ' $this->dynamic_fileroot value ' . $this->dynamic_fileroot); - $this->__log(__METHOD__ . ' $this->separator value ' . $this->separator); - } - - public function error($string,$textarea=false) { - $array = array( - 'Error'=>$string, - 'Code'=>'-1', - 'Properties'=>$this->properties - ); - - $this->__log( __METHOD__ . ' - error message : ' . $string); - - if($textarea) { - echo ''; - } else { - echo json_encode($array); - } - die(); - } - - public function lang($string) { - if(isset($this->language[$string]) && $this->language[$string]!='') { - return $this->language[$string]; - } else { - return 'Language string error on ' . $string; - } - } - - public function getvar($var) { - if(!isset($_GET[$var]) || $_GET[$var]=='') { - $this->error(sprintf($this->lang('INVALID_VAR'),$var)); - } else { - $this->get[$var] = $this->sanitize($_GET[$var]); - return true; - } - } - public function postvar($var) { - if(!isset($_POST[$var]) || $_POST[$var]=='') { - $this->error(sprintf($this->lang('INVALID_VAR'),$var)); - } else { - $this->post[$var] = $_POST[$var]; - return true; - } - } - - public function getinfo() { - $this->item = array(); - $this->item['properties'] = $this->properties; - $this->get_file_info('', false); - - // handle path when set dynamically with $fm->setFileRoot() method - if($this->dynamic_fileroot != '') { - $path = $this->dynamic_fileroot. $this->get['path']; - $path = preg_replace('~/+~', '/', $path); // remove multiple slashes - } else { - $path = $this->get['path']; - } - - - $array = array( - 'Path'=> $path, - 'Filename'=>$this->item['filename'], - 'File Type'=>$this->item['filetype'], - 'Preview'=>$this->item['preview'], - 'Properties'=>$this->item['properties'], - 'Error'=>"", - 'Code'=>0 - ); - return $array; - } - - public function getfolder() { - $array = array(); - $filesDir = array(); - - $current_path = $this->getFullPath(); - - - if(!$this->isValidPath($current_path)) { - $this->error("No way."); - } - - if(!is_dir($current_path)) { - $this->error(sprintf($this->lang('DIRECTORY_NOT_EXIST'),$this->get['path'])); - } - if(!$handle = opendir($current_path)) { - $this->error(sprintf($this->lang('UNABLE_TO_OPEN_DIRECTORY'),$this->get['path'])); - } else { - while (false !== ($file = readdir($handle))) { - if($file != "." && $file != "..") { - array_push($filesDir, $file); - } - } - closedir($handle); - - // By default - // Sorting files by name ('default' or 'NAME_DESC' cases from $this->config['options']['fileSorting'] - natcasesort($filesDir); - - foreach($filesDir as $file) { - - 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[$this->get['path'] . $file .'/'] = array( - 'Path'=> $this->get['path'] . $file .'/', - 'Filename'=>$file, - 'File Type'=>'dir', - 'Preview'=> $this->config['icons']['path'] . $this->config['icons']['directory'], - 'Properties'=>array( - 'Date Created'=> date($this->config['options']['dateFormat'], filectime($this->getFullPath($this->get['path'] . $file .'/'))), - 'Date Modified'=> date($this->config['options']['dateFormat'], filemtime($this->getFullPath($this->get['path'] . $file .'/'))), - 'filemtime'=> filemtime($this->getFullPath($this->get['path'] . $file .'/')), - 'Height'=>null, - 'Width'=>null, - 'Size'=>null - ), - 'Error'=>"", - 'Code'=>0 - ); - } - } else if (!in_array($file, $this->config['exclude']['unallowed_files']) && !preg_match( $this->config['exclude']['unallowed_files_REGEXP'], $file)) { - $this->item = array(); - $this->item['properties'] = $this->properties; - $this->get_file_info($this->get['path'] . $file, true); - - if(!isset($this->params['type']) || (isset($this->params['type']) && strtolower($this->params['type'])=='images' && in_array(strtolower($this->item['filetype']),$this->config['images']['imagesExt']))) { - if($this->config['upload']['imagesOnly']== false || ($this->config['upload']['imagesOnly']== true && in_array(strtolower($this->item['filetype']),$this->config['images']['imagesExt']))) { - $array[$this->get['path'] . $file] = array( - 'Path'=>$this->get['path'] . $file, - 'Filename'=>$this->item['filename'], - 'File Type'=>$this->item['filetype'], - 'Preview'=>$this->item['preview'], - 'Properties'=>$this->item['properties'], - 'Error'=>"", - 'Code'=>0 - ); - } - } - } - } - } - - $array = $this->sortFiles($array); - - return $array; - } - - public function rename() { - - $suffix=''; - - - if(substr($this->get['old'],-1,1)=='/') { - $this->get['old'] = substr($this->get['old'],0,(strlen($this->get['old'])-1)); - $suffix='/'; - } - $tmp = explode('/',$this->get['old']); - $filename = $tmp[(sizeof($tmp)-1)]; - $path = str_replace('/' . $filename,'',$this->get['old']); - - $new_file = $this->getFullPath($path . '/' . $this->get['new']). $suffix; - $old_file = $this->getFullPath($this->get['old']) . $suffix; - - if(!$this->isValidPath($old_file)) { - $this->error("No way."); - } - - $this->__log(__METHOD__ . ' - renaming '. $old_file. ' to ' . $new_file); - - if(file_exists ($new_file)) { - if($suffix=='/' && is_dir($new_file)) { - $this->error(sprintf($this->lang('DIRECTORY_ALREADY_EXISTS'),$this->get['new'])); - } - if($suffix=='' && is_file($new_file)) { - $this->error(sprintf($this->lang('FILE_ALREADY_EXISTS'),$this->get['new'])); - } - } - - if(!rename($old_file,$new_file)) { - if(is_dir($old_file)) { - $this->error(sprintf($this->lang('ERROR_RENAMING_DIRECTORY'),$filename,$this->get['new'])); - } else { - $this->error(sprintf($this->lang('ERROR_RENAMING_FILE'),$filename,$this->get['new'])); - } - } - $array = array( - 'Error'=>"", - 'Code'=>0, - 'Old Path'=>$this->get['old'], - 'Old Name'=>$filename, - 'New Path'=>$path . '/' . $this->get['new'].$suffix, - 'New Name'=>$this->get['new'] - ); - return $array; - } - - public function delete() { - - $current_path = $this->getFullPath(); - - if(!$this->isValidPath($current_path)) { - $this->error("No way."); - } - - if(is_dir($current_path)) { - $this->unlinkRecursive($current_path); - $array = array( - 'Error'=>"", - 'Code'=>0, - 'Path'=>$this->formatPath($this->get['path']) - ); - - $this->__log(__METHOD__ . ' - deleting folder '. $current_path); - return $array; - - } else if(file_exists($current_path)) { - unlink($current_path); - $array = array( - 'Error'=>"", - 'Code'=>0, - 'Path'=>$this->formatPath($this->get['path']) - ); - - $this->__log(__METHOD__ . ' - deleting file '. $current_path); - return $array; - - } else { - $this->error(sprintf($this->lang('INVALID_DIRECTORY_OR_FILE'))); - } - } - - public function add() { - - $this->setParams(); - - if(!isset($_FILES['newfile']) || !is_uploaded_file($_FILES['newfile']['tmp_name'])) { - $this->error(sprintf($this->lang('INVALID_FILE_UPLOAD')),true); - } - // we determine max upload size if not set - if($this->config['upload']['fileSizeLimit'] == 'auto') { - $this->config['upload']['fileSizeLimit'] = $this->getMaxUploadFileSize(); - } - if($_FILES['newfile']['size'] > ($this->config['upload']['fileSizeLimit'] * 1024 * 1024)) { - $this->error(sprintf($this->lang('UPLOAD_FILES_SMALLER_THAN'),$this->config['upload']['size'] . 'Mb'),true); - } - if($this->config['upload']['imagesOnly'] || (isset($this->params['type']) && strtolower($this->params['type'])=='images')) { - if(!($size = @getimagesize($_FILES['newfile']['tmp_name']))){ - $this->error(sprintf($this->lang('UPLOAD_IMAGES_ONLY')),true); - } - if(!in_array($size[2], array(1, 2, 3, 7, 8))) { - $this->error(sprintf($this->lang('UPLOAD_IMAGES_TYPE_JPEG_GIF_PNG')),true); - } - } - $_FILES['newfile']['name'] = $this->cleanString($_FILES['newfile']['name'],array('.','-')); - - $current_path = $this->getFullPath($this->post['currentpath']); - - if(!$this->isValidPath($current_path)) { - $this->error("No way."); - } - - if(!$this->config['upload']['overwrite']) { - $_FILES['newfile']['name'] = $this->checkFilename($current_path,$_FILES['newfile']['name']); - } - move_uploaded_file($_FILES['newfile']['tmp_name'], $current_path . $_FILES['newfile']['name']); - chmod($current_path . $_FILES['newfile']['name'], 0644); - - $response = array( - 'Path'=>$this->post['currentpath'], - 'Name'=>$_FILES['newfile']['name'], - 'Error'=>"", - 'Code'=>0 - ); - - $this->__log(__METHOD__ . ' - adding file '. $_FILES['newfile']['name']. ' into '. $current_path); - - echo ''; - die(); - } - - public function addfolder() { - - $current_path = $this->getFullPath(); - - if(!$this->isValidPath($current_path)) { - $this->error("No way."); - } - if(is_dir($current_path . $this->get['name'])) { - $this->error(sprintf($this->lang('DIRECTORY_ALREADY_EXISTS'),$this->get['name'])); - - } - $newdir = $this->cleanString($this->get['name']); - if(!mkdir($current_path . $newdir,0755)) { - $this->error(sprintf($this->lang('UNABLE_TO_CREATE_DIRECTORY'),$newdir)); - } - $array = array( - 'Parent'=>$this->get['path'], - 'Name'=>$this->get['name'], - 'Error'=>"", - 'Code'=>0 - ); - $this->__log(__METHOD__ . ' - adding folder '. $current_path . $newdir); - - return $array; - } - - public function download() { - - $current_path = $this->getFullPath(); - - if(!$this->isValidPath($current_path)) { - $this->error("No way."); - } - - if(isset($this->get['path']) && file_exists($current_path)) { - header("Content-type: application/force-download"); - header('Content-Disposition: inline; filename="' . basename($current_path) . '"'); - header("Content-Transfer-Encoding: Binary"); - header("Content-length: ".filesize($current_path)); - header('Content-Type: application/octet-stream'); - header('Content-Disposition: attachment; filename="' . basename($current_path) . '"'); - readfile($current_path); - $this->__log(__METHOD__ . ' - downloading '. $current_path); - exit(); - } else { - $this->error(sprintf($this->lang('FILE_DOES_NOT_EXIST'),$current_path)); - } - } - - public function preview($thumbnail) { - - $current_path = $this->getFullPath(); - - if(isset($this->get['path']) && file_exists($current_path)) { - - // if $thumbnail is set to true we return the thumbnail - if($this->config['options']['generateThumbnails'] == true && $thumbnail == true) { - // get thumbnail (and create it if needed) - $returned_path = $this->get_thumbnail($current_path); - } else { - $returned_path = $current_path; - } - - header("Content-type: image/" .$ext = pathinfo($returned_path, PATHINFO_EXTENSION)); - header("Content-Transfer-Encoding: Binary"); - header("Content-length: ".filesize($returned_path)); - header('Content-Disposition: inline; filename="' . basename($returned_path) . '"'); - readfile($returned_path); - - exit(); - - } else { - $this->error(sprintf($this->lang('FILE_DOES_NOT_EXIST'),$current_path)); - } - } - - public function getMaxUploadFileSize() { - - $max_upload = (int) ini_get('upload_max_filesize'); - $max_post = (int) ini_get('post_max_size'); - $memory_limit = (int) ini_get('memory_limit'); - - $upload_mb = min($max_upload, $max_post, $memory_limit); - - $this->__log(__METHOD__ . ' - max upload file size is '. $upload_mb. 'Mb'); - - return $upload_mb; - } - - private function setParams() { - $tmp = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'); - $tmp = explode('?',$tmp); - $params = array(); - if(isset($tmp[1]) && $tmp[1]!='') { - $params_tmp = explode('&',$tmp[1]); - if(is_array($params_tmp)) { - foreach($params_tmp as $value) { - $tmp = explode('=',$value); - if(isset($tmp[0]) && $tmp[0]!='' && isset($tmp[1]) && $tmp[1]!='') { - $params[$tmp[0]] = $tmp[1]; - } - } - } - } - $this->params = $params; - } - - - private function get_file_info($path='', $thumbnail = false) { - - // DO NOT rawurlencode() since $current_path it - // is used for displaying name file - if($path=='') { - $current_path = $this->get['path']; - } else { - $current_path = $path; - } - $tmp = explode('/',$current_path); - $this->item['filename'] = $tmp[(sizeof($tmp)-1)]; - - $tmp = explode('.',$this->item['filename']); - $this->item['filetype'] = $tmp[(sizeof($tmp)-1)]; - $this->item['filemtime'] = filemtime($this->getFullPath($current_path)); - $this->item['filectime'] = filectime($this->getFullPath($current_path)); - - $this->item['preview'] = $this->config['icons']['path'] . $this->config['icons']['default']; - - if(is_dir($current_path)) { - - $this->item['preview'] = $this->config['icons']['path'] . $this->config['icons']['directory']; - - } else if(in_array(strtolower($this->item['filetype']),$this->config['images']['imagesExt'])) { - - // svg should not be previewed as raster formats images - if($this->item['filetype'] == 'svg') { - $this->item['preview'] = $current_path; - } else { - $this->item['preview'] = 'connectors/php/filemanager.php?mode=preview&path='. rawurlencode($current_path); - if($thumbnail) $this->item['preview'] .= '&thumbnail=true'; - } - //if(isset($get['getsize']) && $get['getsize']=='true') { - $this->item['properties']['Size'] = filesize($this->getFullPath($current_path)); - if ($this->item['properties']['Size']) { - list($width, $height, $type, $attr) = getimagesize($this->getFullPath($current_path)); - } else { - $this->item['properties']['Size'] = 0; - list($width, $height) = array(0, 0); - } - $this->item['properties']['Height'] = $height; - $this->item['properties']['Width'] = $width; - $this->item['properties']['Size'] = filesize($this->getFullPath($current_path)); - //} - - } else if(file_exists($this->root . $this->config['icons']['path'] . strtolower($this->item['filetype']) . '.png')) { - - $this->item['preview'] = $this->config['icons']['path'] . strtolower($this->item['filetype']) . '.png'; - $this->item['properties']['Size'] = filesize($this->getFullPath($current_path)); - if (!$this->item['properties']['Size']) $this->item['properties']['Size'] = 0; - - } - - $this->item['properties']['Date Modified'] = date($this->config['options']['dateFormat'], $this->item['filemtime']); - $this->item['properties']['filemtime'] = filemtime($this->getFullPath($current_path)); - //$return['properties']['Date Created'] = $this->config['options']['dateFormat'], $return['filectime']); // PHP cannot get create timestamp -} - -private function getFullPath($path = '') { - - if($path == '') { - if(isset($this->get['path'])) $path = $this->get['path']; - } - - if($this->config['options']['fileRoot'] !== false) { - $full_path = $this->doc_root . rawurldecode(str_replace ( $this->doc_root , '' , $path)); - if($this->dynamic_fileroot != '') { - $full_path = $this->doc_root . rawurldecode(str_replace ( $this->dynamic_fileroot , '' , $path)); - } - } else { - $full_path = $this->doc_root . rawurldecode($path); - } - - $full_path = str_replace("//", "/", $full_path); - - // $this->__log(__METHOD_. " returned path : " . $full_path); - - return $full_path; - -} - -/** - * format path regarding the initial configuration - * @param string $path - */ + + * @author Simon Georget + * @copyright Authors + */ + +class Filemanager { + + protected $config = array(); + protected $language = array(); + protected $get = array(); + protected $post = array(); + protected $properties = array(); + protected $item = array(); + protected $languages = array(); + protected $root = ''; + protected $doc_root = ''; + protected $dynamic_fileroot = ''; + protected $logger = false; + protected $logfile = '/tmp/filemanager.log'; + protected $cachefolder = '_thumbs/'; + protected $thumbnail_width = 64; + protected $thumbnail_height = 64; + protected $separator = 'userfiles'; // @todo fix keep it or not? + + public function __construct($extraConfig = '') { + + $content = file_get_contents("../../scripts/filemanager.config.js"); + $config = json_decode($content, true); + + $this->config = $config; + + // override config options if needed + if(!empty($extraConfig)) { + $this->setup($extraConfig); + } + + $this->root = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR; + $this->properties = array( + 'Date Created'=>null, + 'Date Modified'=>null, + 'Height'=>null, + 'Width'=>null, + 'Size'=>null + ); + + // Log actions or not? + if ($this->config['options']['logger'] == true ) { + if(isset($this->config['options']['logfile'])) { + $this->logfile = $this->config['options']['logfile']; + } + $this->enableLog(); + } + + // if fileRoot is set manually, $this->doc_root takes fileRoot value + // for security check in isValidPath() method + // else it takes $_SERVER['DOCUMENT_ROOT'] default value + if ($this->config['options']['fileRoot'] !== false ) { + if($this->config['options']['serverRoot'] === true) { + // $this->doc_root = $_SERVER['DOCUMENT_ROOT']; + // global $sys; + if (substr_count($_SERVER['HTTP_HOST'], "ca-dev") > 0 OR $_SERVER['HTTP_HOST'] == 'localhost' OR substr_count($_SERVER['HTTP_HOST'], 'localhost.enguehard.info') > 0) { + $tab = explode('.', $_SERVER['SERVER_NAME']); + if ($_SERVER['HTTP_HOST'] == 'localhost') { + $sys['base_dir'] = $_SERVER["DOCUMENT_ROOT"]; + $sys['documentRoot'] = $_SERVER["DOCUMENT_ROOT"].'../'; + } else { + $sys['base_dir'] = $_SERVER["DOCUMENT_ROOT"].$tab[0].'/www'; + $sys['documentRoot'] = $_SERVER["DOCUMENT_ROOT"].$tab[0]; + } + $sys['env'] = 'dev'; + } else { + $sys['base_dir'] = $_SERVER["DOCUMENT_ROOT"]; + $sys['documentRoot'] = $_SERVER["DOCUMENT_ROOT"].'/../'; + $sys['env'] = 'prod'; + } + $this->doc_root = $sys['base_dir']; + $this->separator = basename($this->config['options']['fileRoot']); + } else { + $this->doc_root = $this->config['options']['fileRoot']; + $this->separator = basename($this->config['options']['fileRoot']); + } + } else { + $this->doc_root = $_SERVER['DOCUMENT_ROOT']; + } + + $this->__log(__METHOD__.' $this->doc_root value ' . $this->doc_root); + $this->__log(__METHOD__.' $this->separator value ' . $this->separator); + $this->__log(__METHOD__.' $this->config[\'options\'][\'fileRoot\'] value ' . $this->config['options']['fileRoot']); + + $this->setParams(); + $this->availableLanguages(); + $this->loadLanguageFile(); + } + + // $extraconfig should be formatted as json config array. + public function setup($extraconfig) { + + $this->config = array_merge_recursive($this->config, $extraconfig); + + } + + // allow Filemanager to be used with dynamic folders + public function setFileRoot($path) { + // global $sys + if (substr_count($_SERVER['HTTP_HOST'], "ca-dev") > 0 OR $_SERVER['HTTP_HOST'] == 'localhost' OR substr_count($_SERVER['HTTP_HOST'], 'localhost.enguehard.info') > 0) { + $tab = explode('.', $_SERVER['SERVER_NAME']); + if ($_SERVER['HTTP_HOST'] == 'localhost') { + $sys['base_dir'] = $_SERVER["DOCUMENT_ROOT"]; + $sys['documentRoot'] = $_SERVER["DOCUMENT_ROOT"].'../'; + } else { + $sys['base_dir'] = $_SERVER["DOCUMENT_ROOT"].$tab[0].'/www'; + $sys['documentRoot'] = $_SERVER["DOCUMENT_ROOT"].$tab[0]; + } + $sys['env'] = 'dev'; + } else { + $sys['base_dir'] = $_SERVER["DOCUMENT_ROOT"]; + $sys['documentRoot'] = $_SERVER["DOCUMENT_ROOT"].'/../'; + $sys['env'] = 'prod'; + } + + if($this->config['options']['serverRoot'] === true) { + // $this->doc_root = $_SERVER['DOCUMENT_ROOT']. $path; + $this->doc_root = $sys['base_dir'].$path; + } else { + $this->doc_root = $path; + } + + // necessary for retrieving path when set dynamically with $fm->setFileRoot() method + // $this->dynamic_fileroot = str_replace($_SERVER['DOCUMENT_ROOT'], '/', $this->doc_root); + $this->dynamic_fileroot = str_replace($sys['base_dir'], '', $this->doc_root); + $this->separator = basename($this->doc_root); + + $this->__log(__METHOD__.' $this->doc_root value overwritten : ' . $this->doc_root); + $this->__log(__METHOD__.' $this->dynamic_fileroot value ' . $this->dynamic_fileroot); + $this->__log(__METHOD__.' $this->separator value ' . $this->separator); + $this->__log(__METHOD__.' $this->config[\'options\'][\'fileRoot\'] value ' . $this->config['options']['fileRoot']); + } + + public function error($string,$textarea=false) { + $array = array( + 'Error'=>$string, + 'Code'=>'-1', + 'Properties'=>$this->properties + ); + + $this->__log( __METHOD__ . ' - error message : ' . $string); + + if($textarea) { + echo ''; + } else { + echo json_encode($array); + } + die(); + } + + public function lang($string) { + if(isset($this->language[$string]) && $this->language[$string]!='') { + return $this->language[$string]; + } else { + return 'Language string error on ' . $string; + } + } + + public function getvar($var) { + if(!isset($_GET[$var]) || $_GET[$var]=='') { + $this->error(sprintf($this->lang('INVALID_VAR'),$var)); + } else { + $this->get[$var] = $this->sanitize($_GET[$var]); + return true; + } + } + public function postvar($var) { + if(!isset($_POST[$var]) || $_POST[$var]=='') { + $this->error(sprintf($this->lang('INVALID_VAR'),$var)); + } else { + $this->post[$var] = $_POST[$var]; + return true; + } + } + + public function getinfo() { + $this->item = array(); + $this->item['properties'] = $this->properties; + $this->get_file_info('', false); + + // handle path when set dynamically with $fm->setFileRoot() method + if($this->dynamic_fileroot != '') { + $path = $this->dynamic_fileroot. $this->get['path']; + $path = preg_replace('~/+~', '/', $path); // remove multiple slashes + } else { + $path = $this->get['path']; + } + + + $array = array( + 'Path'=> $path, + 'Filename'=>$this->item['filename'], + 'File Type'=>$this->item['filetype'], + 'Preview'=>$this->item['preview'], + 'Properties'=>$this->item['properties'], + 'Error'=>"", + 'Code'=>0 + ); + return $array; + } + + public function getfolder() { + $array = array(); + $filesDir = array(); + + $current_path = $this->getFullPath(); + + + if(!$this->isValidPath($current_path)) { + $this->error("No way."); + } + + if(!is_dir($current_path)) { + $this->error(sprintf($this->lang('DIRECTORY_NOT_EXIST'),$this->get['path'])); + } + if(!$handle = opendir($current_path)) { + $this->error(sprintf($this->lang('UNABLE_TO_OPEN_DIRECTORY'),$this->get['path'])); + } else { + while (false !== ($file = readdir($handle))) { + if($file != "." && $file != "..") { + array_push($filesDir, $file); + } + } + closedir($handle); + + // By default + // Sorting files by name ('default' or 'NAME_DESC' cases from $this->config['options']['fileSorting'] + natcasesort($filesDir); + + foreach($filesDir as $file) { + + 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[$this->get['path'] . $file .'/'] = array( + 'Path'=> $this->get['path'] . $file .'/', + 'Filename'=>$file, + 'File Type'=>'dir', + 'Preview'=> $this->config['icons']['path'] . $this->config['icons']['directory'], + 'Properties'=>array( + 'Date Created'=> date($this->config['options']['dateFormat'], filectime($this->getFullPath($this->get['path'] . $file .'/'))), + 'Date Modified'=> date($this->config['options']['dateFormat'], filemtime($this->getFullPath($this->get['path'] . $file .'/'))), + 'filemtime'=> filemtime($this->getFullPath($this->get['path'] . $file .'/')), + 'Height'=>null, + 'Width'=>null, + 'Size'=>null + ), + 'Error'=>"", + 'Code'=>0 + ); + } + } else if (!in_array($file, $this->config['exclude']['unallowed_files']) && !preg_match( $this->config['exclude']['unallowed_files_REGEXP'], $file)) { + $this->item = array(); + $this->item['properties'] = $this->properties; + $this->get_file_info($this->get['path'] . $file, true); + + if(!isset($this->params['type']) || (isset($this->params['type']) && strtolower($this->params['type'])=='images' && in_array(strtolower($this->item['filetype']),$this->config['images']['imagesExt']))) { + if($this->config['upload']['imagesOnly']== false || ($this->config['upload']['imagesOnly']== true && in_array(strtolower($this->item['filetype']),$this->config['images']['imagesExt']))) { + $array[$this->get['path'] . $file] = array( + 'Path'=>$this->get['path'] . $file, + 'Filename'=>$this->item['filename'], + 'File Type'=>$this->item['filetype'], + 'Preview'=>$this->item['preview'], + 'Properties'=>$this->item['properties'], + 'Error'=>"", + 'Code'=>0 + ); + } + } + } + } + } + + $array = $this->sortFiles($array); + + return $array; + } + + public function rename() { + + $suffix=''; + + + if(substr($this->get['old'],-1,1)=='/') { + $this->get['old'] = substr($this->get['old'],0,(strlen($this->get['old'])-1)); + $suffix='/'; + } + $tmp = explode('/',$this->get['old']); + $filename = $tmp[(sizeof($tmp)-1)]; + $path = str_replace('/' . $filename,'',$this->get['old']); + + $new_file = $this->getFullPath($path . '/' . $this->get['new']). $suffix; + $old_file = $this->getFullPath($this->get['old']) . $suffix; + + if(!$this->isValidPath($old_file)) { + $this->error("No way."); + } + + $this->__log(__METHOD__ . ' - renaming '. $old_file. ' to ' . $new_file); + + if(file_exists ($new_file)) { + if($suffix=='/' && is_dir($new_file)) { + $this->error(sprintf($this->lang('DIRECTORY_ALREADY_EXISTS'),$this->get['new'])); + } + if($suffix=='' && is_file($new_file)) { + $this->error(sprintf($this->lang('FILE_ALREADY_EXISTS'),$this->get['new'])); + } + } + + if(!rename($old_file,$new_file)) { + if(is_dir($old_file)) { + $this->error(sprintf($this->lang('ERROR_RENAMING_DIRECTORY'),$filename,$this->get['new'])); + } else { + $this->error(sprintf($this->lang('ERROR_RENAMING_FILE'),$filename,$this->get['new'])); + } + } + $array = array( + 'Error'=>"", + 'Code'=>0, + 'Old Path'=>$this->get['old'], + 'Old Name'=>$filename, + 'New Path'=>$path . '/' . $this->get['new'].$suffix, + 'New Name'=>$this->get['new'] + ); + return $array; + } + + public function delete() { + + $current_path = $this->getFullPath(); + + if(!$this->isValidPath($current_path)) { + $this->error("No way."); + } + + if(is_dir($current_path)) { + $this->unlinkRecursive($current_path); + $array = array( + 'Error'=>"", + 'Code'=>0, + 'Path'=>$this->formatPath($this->get['path']) + ); + + $this->__log(__METHOD__.' - deleting folder '.$current_path); + return $array; + + } else if(file_exists($current_path)) { + unlink($current_path); + $array = array( + 'Error'=>"", + 'Code'=>0, + 'Path'=>$this->formatPath($this->get['path']) + ); + + $this->__log(__METHOD__.' - deleting file '.$current_path); + return $array; + + } else { + $this->error(sprintf($this->lang('INVALID_DIRECTORY_OR_FILE'))); + } + } + + public function add() { + + $this->setParams(); + + if(!isset($_FILES['newfile']) || !is_uploaded_file($_FILES['newfile']['tmp_name'])) { + $this->error(sprintf($this->lang('INVALID_FILE_UPLOAD')),true); + } + // we determine max upload size if not set + if($this->config['upload']['fileSizeLimit'] == 'auto') { + $this->config['upload']['fileSizeLimit'] = $this->getMaxUploadFileSize(); + } + if($_FILES['newfile']['size'] > ($this->config['upload']['fileSizeLimit'] * 1024 * 1024)) { + $this->error(sprintf($this->lang('UPLOAD_FILES_SMALLER_THAN'),$this->config['upload']['size'] . 'Mb'),true); + } + if($this->config['upload']['imagesOnly'] || (isset($this->params['type']) && strtolower($this->params['type'])=='images')) { + if(!($size = @getimagesize($_FILES['newfile']['tmp_name']))){ + $this->error(sprintf($this->lang('UPLOAD_IMAGES_ONLY')),true); + } + if(!in_array($size[2], array(1, 2, 3, 7, 8))) { + $this->error(sprintf($this->lang('UPLOAD_IMAGES_TYPE_JPEG_GIF_PNG')),true); + } + } + $_FILES['newfile']['name'] = $this->cleanString($_FILES['newfile']['name'],array('.','-')); + + $current_path = $this->getFullPath($this->post['currentpath']); + + if(!$this->isValidPath($current_path)) { + $this->error("No way."); + } + + if(!$this->config['upload']['overwrite']) { + $_FILES['newfile']['name'] = $this->checkFilename($current_path,$_FILES['newfile']['name']); + } + move_uploaded_file($_FILES['newfile']['tmp_name'], $current_path . $_FILES['newfile']['name']); + chmod($current_path . $_FILES['newfile']['name'], 0644); + + $response = array( + 'Path'=>$this->post['currentpath'], + 'Name'=>$_FILES['newfile']['name'], + 'Error'=>"", + 'Code'=>0 + ); + + $this->__log(__METHOD__.' - adding file '. $_FILES['newfile']['name'].' into '.$current_path); + + echo ''; + die(); + } + + public function addfolder() { + + $current_path = $this->getFullPath(); + + if(!$this->isValidPath($current_path)) { + $this->error("No way."); + } + if(is_dir($current_path . $this->get['name'])) { + $this->error(sprintf($this->lang('DIRECTORY_ALREADY_EXISTS'),$this->get['name'])); + + } + $newdir = $this->cleanString($this->get['name']); + if(!mkdir($current_path . $newdir,0755)) { + $this->error(sprintf($this->lang('UNABLE_TO_CREATE_DIRECTORY'),$newdir)); + } + $array = array( + 'Parent'=>$this->get['path'], + 'Name'=>$this->get['name'], + 'Error'=>"", + 'Code'=>0 + ); + $this->__log(__METHOD__ . ' - adding folder '. $current_path . $newdir); + + return $array; + } + + public function download() { + + $current_path = $this->getFullPath(); + + if(!$this->isValidPath($current_path)) { + $this->error("No way."); + } + + if(isset($this->get['path']) && file_exists($current_path)) { + header("Content-type: application/force-download"); + header('Content-Disposition: inline; filename="'.basename($current_path).'"'); + header("Content-Transfer-Encoding: Binary"); + header("Content-length: ".filesize($current_path)); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="'.basename($current_path).'"'); + readfile($current_path); + $this->__log(__METHOD__.' - downloading '.$current_path); + exit(); + } else { + $this->error(sprintf($this->lang('FILE_DOES_NOT_EXIST'), $current_path)); + } + } + + public function preview($thumbnail) { + + $current_path = $this->getFullPath(); + + if(isset($this->get['path']) && file_exists($current_path)) { + + // if $thumbnail is set to true we return the thumbnail + if($this->config['options']['generateThumbnails'] == true && $thumbnail == true) { + // get thumbnail (and create it if needed) + $returned_path = $this->get_thumbnail($current_path); + } else { + $returned_path = $current_path; + } + + header("Content-type: image/" .$ext = pathinfo($returned_path, PATHINFO_EXTENSION)); + header("Content-Transfer-Encoding: Binary"); + header("Content-length: ".filesize($returned_path)); + header('Content-Disposition: inline; filename="' . basename($returned_path) . '"'); + readfile($returned_path); + + exit(); + + } else { + $this->error(sprintf($this->lang('FILE_DOES_NOT_EXIST'),$current_path)); + } + } + + public function getMaxUploadFileSize() { + + $max_upload = (int) ini_get('upload_max_filesize'); + $max_post = (int) ini_get('post_max_size'); + $memory_limit = (int) ini_get('memory_limit'); + + $upload_mb = min($max_upload, $max_post, $memory_limit); + + $this->__log(__METHOD__ . ' - max upload file size is '. $upload_mb. 'Mb'); + + return $upload_mb; + } + + private function setParams() { + $tmp = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'); + $tmp = explode('?',$tmp); + $params = array(); + if(isset($tmp[1]) && $tmp[1]!='') { + $params_tmp = explode('&',$tmp[1]); + if(is_array($params_tmp)) { + foreach($params_tmp as $value) { + $tmp = explode('=',$value); + if(isset($tmp[0]) && $tmp[0]!='' && isset($tmp[1]) && $tmp[1]!='') { + $params[$tmp[0]] = $tmp[1]; + } + } + } + } + $this->params = $params; + } + + + private function get_file_info($path='', $thumbnail = false) { + + // DO NOT rawurlencode() since $current_path it + // is used for displaying name file + if($path=='') { + $current_path = $this->get['path']; + } else { + $current_path = $path; + } + $tmp = explode('/',$current_path); + $this->item['filename'] = $tmp[(sizeof($tmp)-1)]; + + $tmp = explode('.',$this->item['filename']); + $this->item['filetype'] = $tmp[(sizeof($tmp)-1)]; + $this->item['filemtime'] = filemtime($this->getFullPath($current_path)); + $this->item['filectime'] = filectime($this->getFullPath($current_path)); + + $this->item['preview'] = $this->config['icons']['path'] . $this->config['icons']['default']; + + if(is_dir($current_path)) { + + $this->item['preview'] = $this->config['icons']['path'] . $this->config['icons']['directory']; + + } else if(in_array(strtolower($this->item['filetype']),$this->config['images']['imagesExt'])) { + + // svg should not be previewed as raster formats images + if($this->item['filetype'] == 'svg') { + $this->item['preview'] = $current_path; + } else { + $this->item['preview'] = 'connectors/php/filemanager.php?mode=preview&path='. rawurlencode($current_path); + if($thumbnail) $this->item['preview'] .= '&thumbnail=true'; + } + //if(isset($get['getsize']) && $get['getsize']=='true') { + $this->item['properties']['Size'] = filesize($this->getFullPath($current_path)); + if ($this->item['properties']['Size']) { + list($width, $height, $type, $attr) = getimagesize($this->getFullPath($current_path)); + } else { + $this->item['properties']['Size'] = 0; + list($width, $height) = array(0, 0); + } + $this->item['properties']['Height'] = $height; + $this->item['properties']['Width'] = $width; + $this->item['properties']['Size'] = filesize($this->getFullPath($current_path)); + //} + + } else if(file_exists($this->root . $this->config['icons']['path'] . strtolower($this->item['filetype']) . '.png')) { + + $this->item['preview'] = $this->config['icons']['path'] . strtolower($this->item['filetype']) . '.png'; + $this->item['properties']['Size'] = filesize($this->getFullPath($current_path)); + if (!$this->item['properties']['Size']) $this->item['properties']['Size'] = 0; + + } + + $this->item['properties']['Date Modified'] = date($this->config['options']['dateFormat'], $this->item['filemtime']); + $this->item['properties']['filemtime'] = filemtime($this->getFullPath($current_path)); + //$return['properties']['Date Created'] = $this->config['options']['dateFormat'], $return['filectime']); // PHP cannot get create timestamp +} + +private function getFullPath($path = '') { + + if($path == '') { + if(isset($this->get['path'])) $path = $this->get['path']; + } + + if($this->config['options']['fileRoot'] !== false) { + $full_path = $this->doc_root.rawurldecode(str_replace($this->doc_root, '', $path)); + if($this->dynamic_fileroot != '') { + $full_path = $this->doc_root.rawurldecode(str_replace($this->dynamic_fileroot, '', $path)); + } + } else { + $full_path = $this->doc_root . rawurldecode($path); + } + + $full_path = str_replace("//", "/", $full_path); + + return $full_path; +} + +/** + * format path regarding the initial configuration + * @param string $path + */ private function formatPath($path) { - - if($this->dynamic_fileroot != '') { - - $a = explode($this->separator, $path); - return end($a); - - } else { - - return $path; - - } - -} - -private function sortFiles($array) { - - // handle 'NAME_ASC' - if($this->config['options']['fileSorting'] == 'NAME_ASC') { - $array = array_reverse($array); - } - - // handle 'TYPE_ASC' and 'TYPE_DESC' - if(strpos($this->config['options']['fileSorting'], 'TYPE_') !== false || $this->config['options']['fileSorting'] == 'default') { - - $a = array(); - $b = array(); - - foreach ($array as $key=>$item){ - if(strcmp($item["File Type"], "dir") == 0) { - $a[$key]=$item; - }else{ - $b[$key]=$item; - } - } - - if($this->config['options']['fileSorting'] == 'TYPE_ASC') { - $array = array_merge($a, $b); - } - - if($this->config['options']['fileSorting'] == 'TYPE_DESC' || $this->config['options']['fileSorting'] == 'default') { - $array = array_merge($b, $a); - } - } - - // handle 'MODIFIED_ASC' and 'MODIFIED_DESC' - if(strpos($this->config['options']['fileSorting'], 'MODIFIED_') !== false) { - - $modified_order_array = array(); // new array as a column to sort collector - - foreach ($array as $item) { - $modified_order_array[] = $item['Properties']['filemtime']; - } - - if($this->config['options']['fileSorting'] == 'MODIFIED_ASC') { - array_multisort($modified_order_array, SORT_ASC, $array); - } - if($this->config['options']['fileSorting'] == 'MODIFIED_DESC') { - array_multisort($modified_order_array, SORT_DESC, $array); - } - return $array; - - } - - return $array; - - -} - -private function isValidPath($path) { - - // @todo remove debug message - // $this->__log('compare : ' .$this->getFullPath(). '($this->getFullPath()) and ' . $path . '(path)'); - // $this->__log('strncmp() retruned value : ' .strncmp($path, $this->getFullPath(), strlen($this->getFullPath()))); - - return !strncmp($path, $this->getFullPath(), strlen($this->getFullPath())); - -} - -private function unlinkRecursive($dir,$deleteRootToo=true) { - if(!$dh = @opendir($dir)) { - return; - } - while (false !== ($obj = readdir($dh))) { - if($obj == '.' || $obj == '..') { - continue; - } - - if (!@unlink($dir . '/' . $obj)) { - $this->unlinkRecursive($dir.'/'.$obj, true); - } - } - - closedir($dh); - - if ($deleteRootToo) { - @rmdir($dir); - } - - return; -} - -private function cleanString($string, $allowed = array()) { - $allow = null; - - if (!empty($allowed)) { - foreach ($allowed as $value) { - $allow .= "\\$value"; - } - } - - $mapping = array( - 'Š'=>'S', 'š'=>'s', 'Đ'=>'Dj', 'đ'=>'dj', 'Ž'=>'Z', 'ž'=>'z', 'Č'=>'C', 'č'=>'c', 'Ć'=>'C', 'ć'=>'c', - 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', - 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', - 'Õ'=>'O', 'Ö'=>'O', 'Ő'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ű'=>'U', 'Ý'=>'Y', - 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', - 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', - 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ő'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'ű'=>'u', - 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r', ' '=>'_', "'"=>'_', '/'=>'' - ); - - if (is_array($string)) { - - $cleaned = array(); - - foreach ($string as $key => $clean) { - $clean = strtr($clean, $mapping); - - if($this->config['options']['chars_only_latin'] == true) { - $clean = preg_replace("/[^{$allow}_a-zA-Z0-9]/u", '', $clean); - // $clean = preg_replace("/[^{$allow}_a-zA-Z0-9\x{0430}-\x{044F}\x{0410}-\x{042F}]/u", '', $clean); // allow only latin alphabet with cyrillic - } - $cleaned[$key] = preg_replace('/[_]+/', '_', $clean); // remove double underscore - } - } else { - $string = strtr($string, $mapping); - if($this->config['options']['chars_only_latin'] == true) { - $clean = preg_replace("/[^{$allow}_a-zA-Z0-9]/u", '', $string); - // $clean = preg_replace("/[^{$allow}_a-zA-Z0-9\x{0430}-\x{044F}\x{0410}-\x{042F}]/u", '', $string); // allow only latin alphabet with cyrillic - } - $cleaned = preg_replace('/[_]+/', '_', $string); // remove double underscore - - } - return $cleaned; -} - -/** - * For debugging just call - * the direct URL http://localhost/Filemanager/connectors/php/filemanager.php?mode=preview&path=%2FFilemanager%2Fuserfiles%2FMy%20folder3%2Fblanches_neiges.jPg&thumbnail=true - * and echo vars below - * @param string $path - */ -private function get_thumbnail($path) { - - require_once('./inc/vendor/wideimage/lib/WideImage.php'); - - - // echo $path.'
'; - $a = explode($this->separator, $path); - + + if($this->dynamic_fileroot != '') { + + $a = explode($this->separator, $path); + return end($a); + + } else { + + return $path; + + } + +} + +private function sortFiles($array) { + + // handle 'NAME_ASC' + if($this->config['options']['fileSorting'] == 'NAME_ASC') { + $array = array_reverse($array); + } + + // handle 'TYPE_ASC' and 'TYPE_DESC' + if(strpos($this->config['options']['fileSorting'], 'TYPE_') !== false || $this->config['options']['fileSorting'] == 'default') { + + $a = array(); + $b = array(); + + foreach ($array as $key=>$item){ + if(strcmp($item["File Type"], "dir") == 0) { + $a[$key]=$item; + }else{ + $b[$key]=$item; + } + } + + if($this->config['options']['fileSorting'] == 'TYPE_ASC') { + $array = array_merge($a, $b); + } + + if($this->config['options']['fileSorting'] == 'TYPE_DESC' || $this->config['options']['fileSorting'] == 'default') { + $array = array_merge($b, $a); + } + } + + // handle 'MODIFIED_ASC' and 'MODIFIED_DESC' + if(strpos($this->config['options']['fileSorting'], 'MODIFIED_') !== false) { + + $modified_order_array = array(); // new array as a column to sort collector + + foreach ($array as $item) { + $modified_order_array[] = $item['Properties']['filemtime']; + } + + if($this->config['options']['fileSorting'] == 'MODIFIED_ASC') { + array_multisort($modified_order_array, SORT_ASC, $array); + } + if($this->config['options']['fileSorting'] == 'MODIFIED_DESC') { + array_multisort($modified_order_array, SORT_DESC, $array); + } + return $array; + + } + + return $array; + + +} + +private function isValidPath($path) { + + // @todo remove debug message + // $this->__log('compare : ' .$this->getFullPath(). '($this->getFullPath()) and ' . $path . '(path)'); + // $this->__log('strncmp() retruned value : ' .strncmp($path, $this->getFullPath(), strlen($this->getFullPath()))); + + return !strncmp($path, $this->getFullPath(), strlen($this->getFullPath())); + +} + +private function unlinkRecursive($dir,$deleteRootToo=true) { + if(!$dh = @opendir($dir)) { + return; + } + while (false !== ($obj = readdir($dh))) { + if($obj == '.' || $obj == '..') { + continue; + } + + if (!@unlink($dir . '/' . $obj)) { + $this->unlinkRecursive($dir.'/'.$obj, true); + } + } + + closedir($dh); + + if ($deleteRootToo) { + @rmdir($dir); + } + + return; +} + +private function cleanString($string, $allowed = array()) { + $allow = null; + + if (!empty($allowed)) { + foreach ($allowed as $value) { + $allow .= "\\$value"; + } + } + + $mapping = array( + 'Š'=>'S', 'š'=>'s', 'Đ'=>'Dj', 'đ'=>'dj', 'Ž'=>'Z', 'ž'=>'z', 'Č'=>'C', 'č'=>'c', 'Ć'=>'C', 'ć'=>'c', + 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', + 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', + 'Õ'=>'O', 'Ö'=>'O', 'Ő'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ű'=>'U', 'Ý'=>'Y', + 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', + 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', + 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ő'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'ű'=>'u', + 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r', ' '=>'_', "'"=>'_', '/'=>'' + ); + + if (is_array($string)) { + + $cleaned = array(); + + foreach ($string as $key => $clean) { + $clean = strtr($clean, $mapping); + + if($this->config['options']['chars_only_latin'] == true) { + $clean = preg_replace("/[^{$allow}_a-zA-Z0-9]/u", '', $clean); + // $clean = preg_replace("/[^{$allow}_a-zA-Z0-9\x{0430}-\x{044F}\x{0410}-\x{042F}]/u", '', $clean); // allow only latin alphabet with cyrillic + } + $cleaned[$key] = preg_replace('/[_]+/', '_', $clean); // remove double underscore + } + } else { + $string = strtr($string, $mapping); + if($this->config['options']['chars_only_latin'] == true) { + $clean = preg_replace("/[^{$allow}_a-zA-Z0-9]/u", '', $string); + // $clean = preg_replace("/[^{$allow}_a-zA-Z0-9\x{0430}-\x{044F}\x{0410}-\x{042F}]/u", '', $string); // allow only latin alphabet with cyrillic + } + $cleaned = preg_replace('/[_]+/', '_', $string); // remove double underscore + + } + return $cleaned; +} + +/** + * For debugging just call + * the direct URL http://localhost/Filemanager/connectors/php/filemanager.php?mode=preview&path=%2FFilemanager%2Fuserfiles%2FMy%20folder3%2Fblanches_neiges.jPg&thumbnail=true + * and echo vars below + * @param string $path + */ +private function get_thumbnail($path) { + + require_once('./inc/vendor/wideimage/lib/WideImage.php'); + + + // echo $path.'
'; + $a = explode($this->separator, $path); + $path_parts = pathinfo($path); - + // $thumbnail_path = $path_parts['dirname'].'/'.$this->cachefolder; $thumbnail_path = $a[0].$this->separator.'/'.$this->cachefolder.dirname(end($a)).'/'; - $thumbnail_name = $path_parts['filename'] . '_' . $this->thumbnail_width . 'x' . $this->thumbnail_height . 'px.' . $path_parts['extension']; - $thumbnail_fullpath = $thumbnail_path.$thumbnail_name; - - // echo $thumbnail_fullpath.'
'; - + $thumbnail_name = $path_parts['filename'] . '_' . $this->thumbnail_width . 'x' . $this->thumbnail_height . 'px.' . $path_parts['extension']; + $thumbnail_fullpath = $thumbnail_path.$thumbnail_name; + + // echo $thumbnail_fullpath.'
'; + // if thumbnail does not exist we generate it - if(!file_exists($thumbnail_fullpath)) { - - // create folder if it does not exist - if(!file_exists($thumbnail_path)) { - mkdir($thumbnail_path, 0755, true); + if(!file_exists($thumbnail_fullpath)) { + + // create folder if it does not exist + if(!file_exists($thumbnail_path)) { + mkdir($thumbnail_path, 0755, true); } $image = WideImage::load($path); $resized = $image->resize($this->thumbnail_width, $this->thumbnail_height, 'outside')->crop('center', 'center', $this->thumbnail_width, $this->thumbnail_height); - $resized->saveToFile($thumbnail_fullpath); - - $this->__log(__METHOD__ . ' - generating thumbnail : '. $thumbnail_fullpath); - + $resized->saveToFile($thumbnail_fullpath); + + $this->__log(__METHOD__ . ' - generating thumbnail : '. $thumbnail_fullpath); + } - + return $thumbnail_fullpath; -} - -private function sanitize($var) { - $sanitized = strip_tags($var); - $sanitized = str_replace('http://', '', $sanitized); - $sanitized = str_replace('https://', '', $sanitized); - $sanitized = str_replace('../', '', $sanitized); - return $sanitized; -} - -private function checkFilename($path,$filename,$i='') { - if(!file_exists($path . $filename)) { - return $filename; - } else { - $_i = $i; - $tmp = explode(/*$this->config['upload']['suffix'] . */$i . '.',$filename); - if($i=='') { - $i=1; - } else { - $i++; - } - $filename = str_replace($_i . '.' . $tmp[(sizeof($tmp)-1)],$i . '.' . $tmp[(sizeof($tmp)-1)],$filename); - return $this->checkFilename($path,$filename,$i); - } -} - -private function loadLanguageFile() { - - // we load langCode var passed into URL if present and if exists - // else, we use default configuration var - $lang = $this->config['options']['culture']; - if(isset($this->params['langCode']) && in_array($this->params['langCode'], $this->languages)) $lang = $this->params['langCode']; - - if(file_exists($this->root. 'scripts/languages/'.$lang.'.js')) { - $stream =file_get_contents($this->root. 'scripts/languages/'.$lang.'.js'); - $this->language = json_decode($stream, true); - } else { - $stream =file_get_contents($this->root. 'scripts/languages/'.$lang.'.js'); - $this->language = json_decode($stream, true); - } -} - -private function availableLanguages() { - - if ($handle = opendir($this->root.'/scripts/languages/')) { - while (false !== ($file = readdir($handle))) { - if ($file != "." && $file != "..") { - array_push($this->languages, pathinfo($file, PATHINFO_FILENAME)); - } - } - closedir($handle); - } -} - -private function __log($msg) { - - if($this->logger == true) { - - $fp = fopen($this->logfile, "a"); - $str = "[" . date("d/m/Y h:i:s", mktime()) . "] " . $msg; - fwrite($fp, $str . PHP_EOL); - fclose($fp); - } - -} - -public function enableLog($logfile = '') { - - $this->logger = true; - - if($logfile != '') { - $this->logfile = $logfile; - } - - $this->__log(__METHOD__ . ' - Log enabled (in '. $this->logfile. ' file)'); - -} - -public function disableLog() { - - $this->logger = false; - - $this->__log(__METHOD__ . ' - Log disabled'); -} -} +} + +private function sanitize($var) { + $sanitized = strip_tags($var); + $sanitized = str_replace('http://', '', $sanitized); + $sanitized = str_replace('https://', '', $sanitized); + $sanitized = str_replace('../', '', $sanitized); + return $sanitized; +} + +private function checkFilename($path,$filename,$i='') { + if(!file_exists($path . $filename)) { + return $filename; + } else { + $_i = $i; + $tmp = explode(/*$this->config['upload']['suffix'] . */$i . '.',$filename); + if($i=='') { + $i=1; + } else { + $i++; + } + $filename = str_replace($_i . '.' . $tmp[(sizeof($tmp)-1)],$i . '.' . $tmp[(sizeof($tmp)-1)],$filename); + return $this->checkFilename($path,$filename,$i); + } +} + +private function loadLanguageFile() { + + // we load langCode var passed into URL if present and if exists + // else, we use default configuration var + $lang = $this->config['options']['culture']; + if(isset($this->params['langCode']) && in_array($this->params['langCode'], $this->languages)) $lang = $this->params['langCode']; + + if(file_exists($this->root. 'scripts/languages/'.$lang.'.js')) { + $stream =file_get_contents($this->root. 'scripts/languages/'.$lang.'.js'); + $this->language = json_decode($stream, true); + } else { + $stream =file_get_contents($this->root. 'scripts/languages/'.$lang.'.js'); + $this->language = json_decode($stream, true); + } +} + +private function availableLanguages() { + + if ($handle = opendir($this->root.'/scripts/languages/')) { + while (false !== ($file = readdir($handle))) { + if ($file != "." && $file != "..") { + array_push($this->languages, pathinfo($file, PATHINFO_FILENAME)); + } + } + closedir($handle); + } +} + +private function __log($msg) { + if($this->logger == true) { + $fp = fopen($this->logfile, "a"); + // $str = "[".date("d/m/Y h:i:s", mktime())."] ".$msg; + $str = "[".date("d/m/Y h:i:s")."] ".$msg; + fwrite($fp, $str.PHP_EOL); + fclose($fp); + } +} + +public function enableLog($logfile = '') { + + $this->logger = true; + + if($logfile != '') { + $this->logfile = $logfile; + } + + $this->__log(__METHOD__.' - Log enabled (in '.$this->logfile.' file)'); + +} + +public function disableLog() { + + $this->logger = false; + + $this->__log(__METHOD__.' - Log disabled'); +} +} ?> \ No newline at end of file diff --git a/connectors/php/filemanager.php b/connectors/php/filemanager.php index 6cfa43d4..45d91887 100755 --- a/connectors/php/filemanager.php +++ b/connectors/php/filemanager.php @@ -1,144 +1,169 @@ - - * @author Simon Georget - * @copyright Authors - */ - + + * @author Simon Georget + * @copyright Authors + */ +session_start(); require_once('./inc/filemanager.inc.php'); -require_once('filemanager.class.php'); - -/** - * Check if user is authorized - * - * @return boolean true is access granted, false if no access - */ -function auth() { - // You can insert your own code over here to check if the user is authorized. - // If you use a session variable, you've got to start the session first (session_start()) - return true; -} - - -// @todo Work on plugins registration -// if (isset($config['plugin']) && !empty($config['plugin'])) { -// $pluginPath = 'plugins' . DIRECTORY_SEPARATOR . $config['plugin'] . DIRECTORY_SEPARATOR; -// require_once($pluginPath . 'filemanager.' . $config['plugin'] . '.config.php'); -// require_once($pluginPath . 'filemanager.' . $config['plugin'] . '.class.php'); -// $className = 'Filemanager'.strtoupper($config['plugin']); -// $fm = new $className($config); -// } else { -// $fm = new Filemanager($config); -// } - -$fm = new Filemanager(); - -$response = ''; - -if(!auth()) { - $fm->error($fm->lang('AUTHORIZATION_REQUIRED')); -} - -if(!isset($_GET)) { - $fm->error($fm->lang('INVALID_ACTION')); -} else { - - if(isset($_GET['mode']) && $_GET['mode']!='') { - - switch($_GET['mode']) { - - default: - - $fm->error($fm->lang('MODE_ERROR')); - break; - - case 'getinfo': - - if($fm->getvar('path')) { - $response = $fm->getinfo(); - } - break; - - case 'getfolder': - - if($fm->getvar('path')) { - $response = $fm->getfolder(); - } - break; - - case 'rename': - - if($fm->getvar('old') && $fm->getvar('new')) { - $response = $fm->rename(); - } - break; - - case 'delete': - - if($fm->getvar('path')) { - $response = $fm->delete(); - } - break; - - case 'addfolder': - - if($fm->getvar('path') && $fm->getvar('name')) { - $response = $fm->addfolder(); - } - break; - - case 'download': - if($fm->getvar('path')) { - $fm->download(); - } - break; - - case 'preview': - if($fm->getvar('path')) { - if(isset($_GET['thumbnail'])) { - $thumbnail = true; - } else { - $thumbnail = false; - } - $fm->preview($thumbnail); - } - break; - +require_once('filemanager.class.php'); + +/** + * Check if user is authorized + * + * @return boolean true is access granted, false if no access + */ +function auth() { + // You can insert your own code over here to check if the user is authorized. + // If you use a session variable, you've got to start the session first (session_start()) + return true; +} + + +// @todo Work on plugins registration +// if (isset($config['plugin']) && !empty($config['plugin'])) { +// $pluginPath = 'plugins' . DIRECTORY_SEPARATOR . $config['plugin'] . DIRECTORY_SEPARATOR; +// require_once($pluginPath . 'filemanager.' . $config['plugin'] . '.config.php'); +// require_once($pluginPath . 'filemanager.' . $config['plugin'] . '.class.php'); +// $className = 'Filemanager'.strtoupper($config['plugin']); +// $fm = new $className($config); +// } else { +// $fm = new Filemanager($config); +// } +if (substr_count($_SERVER['HTTP_HOST'], "ca-dev") > 0 OR $_SERVER['HTTP_HOST'] == 'localhost' OR substr_count($_SERVER['HTTP_HOST'], 'localhost.enguehard.info') > 0) { + $tab = explode('.', $_SERVER['SERVER_NAME']); + if ($_SERVER['HTTP_HOST'] == 'localhost') { + $sys['base_dir'] = $_SERVER["DOCUMENT_ROOT"]; + $sys['documentRoot'] = $_SERVER["DOCUMENT_ROOT"].'../'; + } else { + $sys['base_dir'] = $_SERVER["DOCUMENT_ROOT"].$tab[0].'/www'; + $sys['documentRoot'] = $_SERVER["DOCUMENT_ROOT"].$tab[0]; + } + $sys['env'] = 'dev'; +} else { + $sys['base_dir'] = $_SERVER["DOCUMENT_ROOT"]; + $sys['documentRoot'] = $_SERVER["DOCUMENT_ROOT"].'/../'; + $sys['env'] = 'prod'; +} + +if (isset($_SESSION['userfoldername'])) { + $folderPath = $sys['base_dir'].'/userfiles/image/'.$_SESSION['userfoldername'].'/'; +} else { + $folderPath = $sys['base_dir'].'/userfiles/image/'; +} + + +$fm = new Filemanager(); +$fm->setFileRoot($folderPath); +// $fm->enableLog('/tmp/filemanager.log'); + +$response = ''; + + +if(!auth()) { + $fm->error($fm->lang('AUTHORIZATION_REQUIRED')); +} + +if(!isset($_GET)) { + $fm->error($fm->lang('INVALID_ACTION')); +} else { + + if(isset($_GET['mode']) && $_GET['mode']!='') { + + switch($_GET['mode']) { + + default: + + $fm->error($fm->lang('MODE_ERROR')); + break; + + case 'getinfo': + + if($fm->getvar('path')) { + $response = $fm->getinfo(); + } + break; + + case 'getfolder': + + if($fm->getvar('path')) { + $response = $fm->getfolder(); + } + break; + + case 'rename': + + if($fm->getvar('old') && $fm->getvar('new')) { + $response = $fm->rename(); + } + break; + + case 'delete': + + if($fm->getvar('path')) { + $response = $fm->delete(); + } + break; + + case 'addfolder': + + if($fm->getvar('path') && $fm->getvar('name')) { + $response = $fm->addfolder(); + } + break; + + case 'download': + if($fm->getvar('path')) { + $fm->download(); + } + break; + + case 'preview': + if($fm->getvar('path')) { + if(isset($_GET['thumbnail'])) { + $thumbnail = true; + } else { + $thumbnail = false; + } + $fm->preview($thumbnail); + } + break; + case 'maxuploadfilesize': $fm->getMaxUploadFileSize(); - break; - } - - } else if(isset($_POST['mode']) && $_POST['mode']!='') { - - switch($_POST['mode']) { - - default: - - $fm->error($fm->lang('MODE_ERROR')); - break; - - case 'add': - - if($fm->postvar('currentpath')) { - $fm->add(); - } - break; - - } - - } -} - -echo json_encode($response); -die(); + break; + } + + } else if(isset($_POST['mode']) && $_POST['mode']!='') { + + switch($_POST['mode']) { + + default: + + $fm->error($fm->lang('MODE_ERROR')); + break; + + case 'add': + + if($fm->postvar('currentpath')) { + $fm->add(); + } + break; + + } + + } +} + +echo json_encode($response); +die(); ?> \ No newline at end of file diff --git a/scripts/filemanager.config.js.default b/scripts/filemanager.config.js.default index 72a55c8b..be4195f0 100644 --- a/scripts/filemanager.config.js.default +++ b/scripts/filemanager.config.js.default @@ -1,7 +1,7 @@ { - "_comment": "IMPORTANT : go to the wiki page to know about options configuration https://github.com/simogeo/Filemanager/wiki/Filemanager-configuration-file", + "_comment": "IMPORTANT : go to the wiki page to know about options configuration https://github.com/simogeo/Filemanager/wiki/Filemanager-configuration-file", "options": { - "culture": "en", + "culture": "fr", "lang": "php", "defaultViewMode": "grid", "autoload": true, @@ -15,38 +15,28 @@ "fileSorting": "default", "chars_only_latin": true, "dateFormat": "d M Y H:i", - "serverRoot": true, - "fileRoot": false, - "relPath": false, + "serverRoot": false, + "fileRoot": "/", + "relPath": "/", "logger": false, + "logfile": "/tmp/filemanager.log", "plugins": [] }, "security": { - "uploadPolicy": "DISALLOW_ALL", + "uploadPolicy": "ALLOW_ALL", "uploadRestrictions": [ - "jpg", - "jpeg", - "gif", - "png", - "svg", - "txt", - "pdf", - "odp", - "ods", - "odt", - "rtf", - "doc", - "docx", - "xls", - "xlsx", - "ppt", - "pptx", - "ogv", - "mp4", - "webm", - "ogg", - "mp3", - "wav" + "exe", + "bat", + "com", + "msi", + "bat", + "php", + "phps", + "phtml", + "php3", + "php4", + "cgi", + "pl" ] }, "upload": { diff --git a/scripts/filemanager.js b/scripts/filemanager.js index 55fbffa5..d41bb666 100644 --- a/scripts/filemanager.js +++ b/scripts/filemanager.js @@ -10,12 +10,12 @@ */ (function($) { - + // function to retrieve GET params $.urlParam = function(name){ var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); if (results) - return results[1]; + return results[1]; else return 0; }; @@ -31,7 +31,7 @@ var config = (function () { 'async': false, 'url': './scripts/filemanager.config.js', 'dataType': "json", - cache: false, + cache: false, 'success': function (data) { json = data; } @@ -39,13 +39,12 @@ var config = (function () { return json; })(); - // Sets paths to connectors based on language selection. var fileConnector = config.options.fileConnector || 'connectors/' + config.options.lang + '/filemanager.' + config.options.lang; var capabilities = new Array('select', 'download', 'rename', 'delete'); -// Get localized messages from file +// Get localized messages from file // through culture var or from URL if($.urlParam('langCode') != 0 && file_exists ('scripts/languages/' + $.urlParam('langCode') + '.js')) config.options.culture = $.urlParam('langCode'); @@ -74,16 +73,16 @@ var setDimensions = function(){ if(config.options.searchBox === true) bheight +=33; - var newH = $(window).height() - $('#uploader').height() - bheight; + var newH = $(window).height() - $('#uploader').height() - bheight; $('#splitter, #filetree, #fileinfo, .vsplitbar').height(newH); - + var newW = $('#splitter').width() - 6 - $('#filetree').width(); $('#fileinfo').width(newW); }; // Display Min Path var displayPath = function(path, reduce) { - + reduce = (typeof reduce === "undefined") ? true : false; if(config.options.showFullPath == false) { @@ -123,7 +122,7 @@ function file_exists (url) { // + input by: Jani Hartikainen // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // % note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain. - // % note 1: Synchronous so may lock up browser, mainly here for study purposes. + // % note 1: Synchronous so may lock up browser, mainly here for study purposes. // * example 1: file_exists('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm'); // * returns 1: '123' var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); @@ -158,30 +157,30 @@ var preg_replace = function(array_pattern, array_pattern_replace, str) { var cleanString = function(str) { var cleaned = ""; - var p_search = new Array("Š", "š", "Đ", "đ", "Ž", "ž", "Č", "č", "Ć", "ć", "À", - "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", - "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "Ő", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", - "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", - "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "ő", "ø", "ù", "ú", "û", "ý", + var p_search = new Array("Š", "š", "Đ", "đ", "Ž", "ž", "Č", "č", "Ć", "ć", "À", + "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", + "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "Ő", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", + "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", + "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "ő", "ø", "ù", "ú", "û", "ý", "ý", "þ", "ÿ", "Ŕ", "ŕ", " ", "'", "/" ); - var p_replace = new Array("S", "s", "Dj", "dj", "Z", "z", "C", "c", "C", "c", "A", - "A", "A", "A", "A", "A", "A", "C", "E", "E", "E", "E", "I", "I", "I", "I", - "N", "O", "O", "O", "O", "O", "O", "O", "U", "U", "U", "U", "Y", "B", "Ss", + var p_replace = new Array("S", "s", "Dj", "dj", "Z", "z", "C", "c", "C", "c", "A", + "A", "A", "A", "A", "A", "A", "C", "E", "E", "E", "E", "I", "I", "I", "I", + "N", "O", "O", "O", "O", "O", "O", "O", "U", "U", "U", "U", "Y", "B", "Ss", "a", "a", "a", "a", "a", "a", "a", "c", "e", "e", "e", "e", "i", "i", - "i", "i", "o", "n", "o", "o", "o", "o", "o", "o", "o", "u", "u", "u", "y", + "i", "i", "o", "n", "o", "o", "o", "o", "o", "o", "o", "u", "u", "u", "y", "y", "b", "y", "R", "r", "_", "_", "" ); cleaned = preg_replace(p_search, p_replace, str); - + // allow only latin alphabet if(config.options.chars_only_latin) { cleaned = cleaned.replace(/[^_a-zA-Z0-9]/g, ""); } - + cleaned = cleaned.replace(/[_]+/g, "_"); - + return cleaned; }; @@ -204,7 +203,7 @@ var formatBytes = function(bytes){ var d = parseFloat(1024); var c = 0; var u = [lg.bytes,lg.kb,lg.mb,lg.gb]; - + while(true){ if(n < d){ n = Math.round(n * 100) / 100; @@ -241,7 +240,7 @@ var isAuthorizedFile = function(filename) { if(config.security.uploadPolicy == 'ALLOW_ALL') { if($.inArray(getExtension(filename), config.security.uploadRestrictions) == -1) return true; } - + return false; }; @@ -252,11 +251,11 @@ var basename = function(path, suffix) { if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) { b = b.substr(0, b.length-suffix.length); } - + return b; }; -// return filename extension +// return filename extension var getExtension = function(filename) { if(filename.split('.').length == 1) { return ""; @@ -291,37 +290,37 @@ var isAudioFile = function(filename) { } }; -// Return HTML video player +// Return HTML video player var getVideoPlayer = function(data) { var code = ''; - + $("#fileinfo img").remove(); $('#fileinfo #preview h1').before(code); - + }; -//Return HTML audio player +//Return HTML audio player var getAudioPlayer = function(data) { var code = ''; - + $("#fileinfo img").remove(); $('#fileinfo #preview h1').before(code); - + }; -// Display icons on list view +// Display icons on list view // retrieving them from filetree // Called using SetInterval var display_icons = function(timer) { $('#fileinfo').find('td:first-child').each(function(){ var path = $(this).attr('title'); var treenode = $('#filetree').find('a[rel="' + path + '"]').parent(); - + if (typeof treenode.css('background-image') !== "undefined") { $(this).css('background-image', treenode.css('background-image')); window.clearInterval(timer); @@ -330,8 +329,8 @@ var display_icons = function(timer) { }); }; -// Sets the folder status, upload, and new folder functions -// to the path specified. Called on initial page load and +// Sets the folder status, upload, and new folder functions +// to the path specified. Called on initial page load and // whenever a new directory is selected. var setUploader = function(path){ $('#currentpath').val(path); @@ -340,9 +339,9 @@ var setUploader = function(path){ $('#newfolder').unbind().click(function(){ var foldername = lg.default_foldername; var msg = lg.prompt_foldername + ' : '; - + var getFolderName = function(v, m){ - if(v != 1) return false; + if(v != 1) return false; var fname = m.children('#fname').val(); if(fname != ''){ @@ -357,26 +356,26 @@ var setUploader = function(path){ $('#filetree').find('a[rel="' + result['Parent'] +'/"]').click().click(); } else { $.prompt(result['Error']); - } + } }); } else { $.prompt(lg.no_foldername); } }; - var btns = {}; - btns[lg.create_folder] = true; - btns[lg.cancel] = false; + var btns = {}; + btns[lg.create_folder] = true; + btns[lg.cancel] = false; $.prompt(msg, { callback: getFolderName, - buttons: btns - }); - }); + buttons: btns + }); + }); }; // Binds specific actions to the toolbar in detail views. // Called when detail views are loaded. var bindToolbar = function(data){ - + // this little bit is purely cosmetic $( "#fileinfo button" ).each(function( index ) { // check if span doesn't exist yet, when bindToolbar called from renameItem for example @@ -393,7 +392,7 @@ var bindToolbar = function(data){ $('#preview img').click(function () { selectItem(data); }).css("cursor", "pointer"); } } - + if (!has_capability(data, 'rename')) { $('#fileinfo').find('button#rename').hide(); } else { @@ -421,7 +420,7 @@ var bindToolbar = function(data){ }; //Create FileTree and bind elements -//called during initialization and also when adding a file +//called during initialization and also when adding a file //directly in root folder (via addNode) var createFileTree = function() { // Creates file tree. @@ -461,17 +460,19 @@ var createFileTree = function() { // Calls the SetUrl function for FCKEditor compatibility, // passes file path, dimensions, and alt text back to the -// opening window. Triggered by clicking the "Select" +// opening window. Triggered by clicking the "Select" // button in detail views or choosing the "Select" -// contextual menu option in list views. +// contextual menu option in list views. // NOTE: closes the window when finished. var selectItem = function(data){ if(config.options.relPath != false ) { - var url = relPath + data['Path'].replace(fileRoot,""); + // REG var url = relPath + data['Path'].replace(fileRoot,""); + var url = relPath + data['Path']; } else { var url = relPath + data['Path']; } - + url = url.replace('//', '/'); +// alert(url + "\n"+data['Path']);return; if(window.opener || window.tinyMCEPopup || $.urlParam('field_name')){ if(window.tinyMCEPopup){ // use TinyMCE > 3.0 integration method @@ -492,7 +493,7 @@ var selectItem = function(data){ // tinymce 4 and colorbox if($.urlParam('field_name')){ parent.document.getElementById($.urlParam('field_name')).value = url; - + if(typeof top.tinyMCE !== "undefined") { // parent.tinyMCE.activeEditor.windowManager.close(); it seems parent. does not work with IE9 /IE10 top.tinyMCE.activeEditor.windowManager.close(); @@ -501,7 +502,7 @@ var selectItem = function(data){ parent.$.fn.colorbox.close(); } } - + else if($.urlParam('CKEditor')){ // use CKEditor 3.0 integration method window.opener.CKEDITOR.tools.callFunction($.urlParam('CKEditorFuncNum'), url); @@ -510,11 +511,11 @@ var selectItem = function(data){ if(data['Properties']['Width'] != ''){ var p = url; var w = data['Properties']['Width']; - var h = data['Properties']['Height']; + var h = data['Properties']['Height']; window.opener.SetUrl(p,w,h); } else { window.opener.SetUrl(url); - } + } } window.close(); @@ -525,7 +526,7 @@ var selectItem = function(data){ // Renames the current item and returns the new name. // Called by clicking the "Rename" button in detail views -// or choosing the "Rename" contextual menu option in +// or choosing the "Rename" contextual menu option in // list views. var renameItem = function(data){ var finalName = ''; @@ -534,16 +535,16 @@ var renameItem = function(data){ var getNewName = function(v, m){ if(v != 1) return false; rname = m.children('#rname').val(); - + if(rname != ''){ var givenName = nameFormat(rname); - var suffix = getExtension(data['Filename']); + var suffix = getExtension(data['Filename']); if(suffix.length > 0) { givenName = givenName + '.' + suffix; } - var oldPath = data['Path']; + var oldPath = data['Path']; var connectString = fileConnector + '?mode=rename&old=' + data['Path'] + '&new=' + givenName; - + $.ajax({ type: 'GET', url: connectString, @@ -553,15 +554,15 @@ var renameItem = function(data){ if(result['Code'] == 0){ var newPath = result['New Path']; var newName = result['New Name']; - + updateNode(oldPath, newPath, newName); - + var title = $("#preview h1").attr("title"); if (typeof title !="undefined" && title == oldPath) { $('#preview h1').text(newName); } - + if($('#fileinfo').data('view') == 'grid'){ $('#fileinfo img[alt="' + oldPath + '"]').parent().next('p').text(newName); $('#fileinfo img[alt="' + oldPath + '"]').attr('alt', newPath); @@ -570,33 +571,33 @@ var renameItem = function(data){ $('#fileinfo td[title="' + oldPath + '"]').attr('title', newPath); } $("#preview h1").html(newName); - + // actualized data for binding data['Path']=newPath; data['Filename']=newName; - + // Bind toolbar functions. $('#fileinfo').find('button#rename, button#delete, button#download').unbind(); bindToolbar(data); - + if(config.options.showConfirmation) $.prompt(lg.successful_rename); } else { $.prompt(result['Error']); } - - finalName = result['New Name']; + + finalName = result['New Name']; } - }); + }); } }; - var btns = {}; - btns[lg.rename] = true; - btns[lg.cancel] = false; + var btns = {}; + btns[lg.rename] = true; + btns[lg.cancel] = false; $.prompt(msg, { callback: getNewName, - buttons: btns + buttons: btns }); - + return finalName; }; @@ -606,9 +607,9 @@ var renameItem = function(data){ var deleteItem = function(data){ var isDeleted = false; var msg = lg.confirmation_delete; - + var doDelete = function(v, m){ - if(v != 1) return false; + if(v != 1) return false; var connectString = fileConnector + '?mode=delete&path=' + encodeURIComponent(data['Path']), parent = data['Path'].split('/').reverse().slice(1).reverse().join('/') + '/'; @@ -624,7 +625,7 @@ var deleteItem = function(data){ rootpath = rootpath.substr(0, rootpath.lastIndexOf('/') + 1); $('#uploader h1').text(lg.current_folder + displayPath(rootpath)).attr("title", displayPath(rootpath, false)); isDeleted = true; - + if(config.options.showConfirmation) $.prompt(lg.successful_delete); // seems to be necessary when dealing w/ files located on s3 (need to look into a cleaner solution going forward) @@ -632,18 +633,18 @@ var deleteItem = function(data){ } else { isDeleted = false; $.prompt(result['Error']); - } + } } - }); + }); }; - var btns = {}; - btns[lg.yes] = true; - btns[lg.no] = false; + var btns = {}; + btns[lg.yes] = true; + btns[lg.no] = false; $.prompt(msg, { callback: doDelete, - buttons: btns + buttons: btns }); - + return isDeleted; }; @@ -659,7 +660,7 @@ var addNode = function(path, name){ var thisNode = $('#filetree').find('a[rel="' + path + '"]'); var parentNode = thisNode.parent(); var newNode = '
  • ' + name + '
  • '; - + // if is root folder // TODO optimize if(!parentNode.find('ul').size()) { @@ -667,7 +668,7 @@ var addNode = function(path, name){ parentNode.prepend(newNode); createFileTree(); - + } else { parentNode.find('ul').prepend(newNode); thisNode.click().click(); @@ -688,19 +689,19 @@ var updateNode = function(oldPath, newPath, newName){ }; -// Removes the specified node. Called after a successful +// Removes the specified node. Called after a successful // delete operation. var removeNode = function(path){ $('#filetree') .find('a[rel="' + path + '"]') .parent() - .fadeOut('slow', function(){ + .fadeOut('slow', function(){ $(this).remove(); }); // grid case if($('#fileinfo').data('view') == 'grid'){ $('#contents img[alt="' + path + '"]').parent().parent() - .fadeOut('slow', function(){ + .fadeOut('slow', function(){ $(this).remove(); }); } @@ -709,7 +710,7 @@ var removeNode = function(path){ $('table#contents') .find('td[title="' + path + '"]') .parent() - .fadeOut('slow', function(){ + .fadeOut('slow', function(){ $(this).remove(); }); } @@ -733,7 +734,7 @@ var addFolder = function(parent, name){ getFolderInfo(parent + name + '/'); }).each(function() { $(this).contextMenu( - { menu: getContextMenuOptions($(this)) }, + { menu: getContextMenuOptions($(this)) }, function(action, el, pos){ var path = $(el).attr('rel'); setMenus(action, path); @@ -741,7 +742,7 @@ var addFolder = function(parent, name){ } ); } - + if(config.options.showConfirmation) $.prompt(lg.successful_added_folder); }; @@ -787,20 +788,20 @@ var setMenus = function(action, path){ } else { var item = $('#fileinfo').find('td[title="' + data['Path'] + '"]').parent(); } - + switch(action){ case 'select': selectItem(data); break; - + case 'download': window.location = fileConnector + '?mode=download&path=' + data['Path']; break; - + case 'rename': var newName = renameItem(data); break; - + case 'delete': deleteItem(data); break; @@ -827,10 +828,10 @@ var getFileInfo = function(file){ if(config.options.browseOnly != true) template += ''; template += ''; template += ''; - + $('#fileinfo').html(template); $('#parentfolder').click(function() {getFolderInfo(currentpath);}); - + // Retrieve the data & populate the template. var d = new Date(); // to prevent IE cache issues $.getJSON(fileConnector + '?mode=getinfo&path=' + encodeURIComponent(file) + '&time=' + d.getMilliseconds(), function(data){ @@ -843,21 +844,21 @@ var getFileInfo = function(file){ if(isAudioFile(data['Filename']) && config.audios.showAudioPlayer == true) { getAudioPlayer(data); } - + var properties = ''; - + if(data['Properties']['Width'] && data['Properties']['Width'] != '') properties += '
    ' + lg.dimensions + '
    ' + data['Properties']['Width'] + 'x' + data['Properties']['Height'] + '
    '; if(data['Properties']['Date Created'] && data['Properties']['Date Created'] != '') properties += '
    ' + lg.created + '
    ' + data['Properties']['Date Created'] + '
    '; if(data['Properties']['Date Modified'] && data['Properties']['Date Modified'] != '') properties += '
    ' + lg.modified + '
    ' + data['Properties']['Date Modified'] + '
    '; if(data['Properties']['Size'] || parseInt(data['Properties']['Size'])==0) properties += '
    ' + lg.size + '
    ' + formatBytes(data['Properties']['Size']) + '
    '; $('#fileinfo').find('dl').html(properties); - + // Bind toolbar functions. bindToolbar(data); } else { $.prompt(data['Error']); } - }); + }); }; // Retrieves data for all items within the given folder and @@ -877,17 +878,17 @@ var getFolderInfo = function(path){ if ($.urlParam('type')) url += '&type=' + $.urlParam('type'); $.getJSON(url, function(data){ var result = ''; - + // Is there any error or user is unauthorized? if(data.Code=='-1') { handleError(data.Error); return; }; - + if(data){ if($('#fileinfo').data('view') == 'grid'){ result += '
      '; - + for(key in data){ var props = data[key]['Properties']; var cap_classes = ""; @@ -896,11 +897,11 @@ var getFolderInfo = function(path){ cap_classes += " cap_" + capabilities[cap]; } } - + var scaledWidth = 64; var actualWidth = props['Width']; if(actualWidth > 1 && actualWidth < scaledWidth) scaledWidth = actualWidth; - + result += '
    • ' + data[key]['Path'] + '

      ' + data[key]['Filename'] + '

      '; if(props['Width'] && props['Width'] != '') result += '' + props['Width'] + 'x' + props['Height'] + ''; if(props['Size'] && props['Size'] != '') result += '' + props['Size'] + ''; @@ -908,13 +909,13 @@ var getFolderInfo = function(path){ if(props['Date Modified'] && props['Date Modified'] != '') result += '' + props['Date Modified'] + ''; result += '
    • '; } - + result += '
    '; } else { result += ''; result += ''; result += ''; - + for(key in data){ var path = data[key]['Path']; var props = data[key]['Properties']; @@ -932,32 +933,32 @@ var getFolderInfo = function(path){ } else { result += ''; } - + if(props['Size'] && props['Size'] != ''){ result += ''; } else { result += ''; } - + if(props['Date Modified'] && props['Date Modified'] != ''){ result += ''; } else { result += ''; } - - result += ''; + + result += ''; } - + result += ''; result += '
    ' + lg.name + '' + lg.dimensions + '' + lg.size + '' + lg.modified + '
    ' + formatBytes(props['Size']) + '' + props['Date Modified'] + '
    '; - } + } } else { result += '

    ' + lg.could_not_retrieve_folder + '

    '; } - + // Add the new markup to the DOM. $('#fileinfo').html(result); - + // Bind click events to create detail views and add // contextual menu options. if($('#fileinfo').data('view') == 'grid'){ @@ -976,7 +977,7 @@ var getFolderInfo = function(path){ } else { $('#fileinfo tbody tr').click(function(){ var path = $('td:first-child', this).attr('title'); - getDetailView(path); + getDetailView(path); }).each(function() { $(this).contextMenu( { menu: getContextMenuOptions($(this)) }, @@ -986,12 +987,12 @@ var getFolderInfo = function(path){ } ); }); - + $('#fileinfo').find('table').tablesorter({ - textExtraction: function(node){ + textExtraction: function(node){ if($(node).find('abbr').size()){ return $(node).find('abbr').attr('title'); - } else { + } else { return node.innerHTML; } } @@ -1019,7 +1020,7 @@ var populateFileTree = function(path, callback){ handleError(data.Error); return; }; - + if(data) { result += "
      "; for(key in data) { @@ -1080,7 +1081,7 @@ $(function(){ } else { relPath = config.options.relPath; } - + if($.urlParam('expandedFolder') != 0) { expandedFolder = $.urlParam('expandedFolder'); @@ -1090,7 +1091,7 @@ $(function(){ fullexpandedFolder = null; } - // we finalize the FileManager UI initialization + // we finalize the FileManager UI initialization // with localized text if necessary if(config.options.autoload == true) { $('#upload').append(lg.upload); @@ -1103,14 +1104,14 @@ $(function(){ $('#itemOptions a[href$="#rename"]').append(lg.rename); $('#itemOptions a[href$="#delete"]').append(lg.del); } - + /** Input file Replacement */ $('#browse').append('+'); $('#browse').attr('title', lg.browse); $("#newfile").change(function() { $("#filepath").val($(this).val().replace(/.+[\\\/]/, "")); }); - + /** load searchbox */ if(config.options.searchBox === true) { $.getScript("./scripts/filemanager.liveSearch.min.js"); @@ -1124,7 +1125,7 @@ $(function(){ // Set initial view state. $('#fileinfo').data('view', config.options.defaultViewMode); setViewButtonsFor(config.options.defaultViewMode); - + $('#home').click(function(){ var currentViewMode = $('#fileinfo').data('view'); $('#fileinfo').data('view', currentViewMode); @@ -1138,7 +1139,7 @@ $(function(){ $('#fileinfo').data('view', 'grid'); getFolderInfo($('#currentpath').val()); }); - + $('#list').click(function(){ setViewButtonsFor('list'); $('#fileinfo').data('view', 'list'); @@ -1158,7 +1159,7 @@ $(function(){ return false; } // Check if file extension is allowed - if (!isAuthorizedFile($('#newfile', form).val())) { + if (!isAuthorizedFile($('#newfile', form).val())) { var str = '

      ' + lg.INVALID_FILE_TYPE + '

      '; if(config.security.uploadPolicy == 'DISALLOW_ALL') { str += '

      ' + lg.ALLOWED_FILE_TYPE + config.security.uploadRestrictions.join(', ') + '.

      '; @@ -1167,7 +1168,7 @@ $(function(){ str += '

      ' + lg.DISALLOWED_FILE_TYPE + config.security.uploadRestrictions.join(', ') + '.

      '; } $("#filepath").val(''); - $.prompt(str); + $.prompt(str); return false; } $('#upload').attr('disabled', true); @@ -1194,8 +1195,8 @@ $(function(){ return false; } } - - + + }, error: function (jqXHR, textStatus, errorThrown) { $('#upload').removeAttr('disabled').find("span").removeClass('loading').text(lg.upload); @@ -1219,7 +1220,7 @@ $(function(){ // Creates file tree. createFileTree(); - + // Disable select function if no window.opener if(! (window.opener || window.tinyMCEPopup || $.urlParam('field_name')) ) $('#itemOptions a[href$="#select"]').remove(); // Keep only browseOnly features if needed @@ -1231,11 +1232,11 @@ $(function(){ $('.contextMenu .rename').remove(); $('.contextMenu .delete').remove(); } - + // Adjust layout. setDimensions(); $(window).resize(setDimensions); - + // Provides support for adjustible columns. $('#splitter').splitter({ sizeLeft: 200 diff --git a/scripts/filemanager.min.js b/scripts/filemanager.min.js index 82fbf1d6..0707dba6 100644 --- a/scripts/filemanager.min.js +++ b/scripts/filemanager.min.js @@ -4,43 +4,4 @@ @author Simon Georget @copyright Authors */ -(function(a){function J(a){var e=this.window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest;if(!e)throw Error("XMLHttpRequest not supported");e.open("HEAD",a,!1);e.send(null);return 200==e.status?!0:!1}function n(b,e){return"dir"==b["File Type"]&&"download"==e?!1:"undefined"==typeof b.Capabilities?!0:-1a)return a=Math.round(100*a)/100,a+c[e];a/=1024;e+=1}},D=function(b){a("#fileinfo").html("

      "+b+"

      ");a("#newfile").attr("disabled","disabled");a("#upload").attr("disabled","disabled");a("#newfolder").attr("disabled","disabled")},p=function(a){return 1==a.split(".").length?"":a.split(".").pop().toLowerCase()},L=function(b){a("#fileinfo").find("td:first-child").each(function(){var e=a(this).attr("title"),e=a("#filetree").find('a[rel="'+ -e+'"]').parent();"undefined"!==typeof e.css("background-image")&&(a(this).css("background-image",e.css("background-image")),window.clearInterval(b))})},y=function(b){a("#currentpath").val(b);a("#uploader h1").text(g.current_folder+u(b)).attr("title",u(b,!1));a("#newfolder").unbind().click(function(){var b=g.default_foldername,c=g.prompt_foldername+' : ',d={};d[g.create_folder]=!0;d[g.cancel]=!1;a.prompt(c,{callback:function(d,c){if(1!=d)return!1; -var f=c.children("#fname").val();""!=f?(b=x(f),f=new Date,a.getJSON(l+"?mode=addfolder&path="+a("#currentpath").val()+"&name="+b+"&time="+f.getMilliseconds(),function(b){0==b.Code?(M(b.Parent,b.Name),h(b.Parent),a("#filetree").find('a[rel="'+b.Parent+'/"]').click().click()):a.prompt(b.Error)})):a.prompt(g.no_foldername)},buttons:d})})},G=function(b){a("#fileinfo button").each(function(b){0==a(this).find("span").length&&a(this).wrapInner("")});if(n(b,"select")){if(a("#fileinfo").find("button#select").click(function(){z(b)}).show(), -window.opener||window.tinyMCEPopup)a("#preview img").attr("title",g.select),a("#preview img").click(function(){z(b)}).css("cursor","pointer")}else a("#fileinfo").find("button#select").hide();n(b,"rename")?a("#fileinfo").find("button#rename").click(function(){var e=E(b);e.length&&a("#fileinfo > h1").text(e)}).show():a("#fileinfo").find("button#rename").hide();n(b,"delete")?a("#fileinfo").find("button#delete").click(function(){F(b)&&a("#fileinfo").html("

      "+g.select_from_left+"

      ")}).show():a("#fileinfo").find("button#delete").hide(); -n(b,"download")?a("#fileinfo").find("button#download").click(function(){window.location=l+"?mode=download&path="+encodeURIComponent(b.Path)}).show():a("#fileinfo").find("button#download").hide()},I=function(){a("#filetree").fileTree({root:fileRoot,datafunc:N,multiFolder:!1,folderCallback:function(a){h(a)},expandedFolder:fullexpandedFolder,after:function(b){a("#filetree").find("li a").each(function(){a(this).contextMenu({menu:t(a(this))},function(b,c,d){c=a(c).attr("rel");v(b,c)})});!0==f.options.searchBox&& -(a("#q").liveUpdate("#filetree ul").blur(),a("#search span.q-inactive").html(g.search),a("#search a.q-reset").attr("title",g.search_reset))}},function(a){H(a)})},z=function(b){var e=!1!=f.options.relPath?relPath+b.Path.replace(fileRoot,""):relPath+b.Path;window.opener||window.tinyMCEPopup||a.urlParam("field_name")?window.tinyMCEPopup?(b=tinyMCEPopup.getWindowArg("window"),b.document.getElementById(tinyMCEPopup.getWindowArg("input")).value=e,"undefined"!=typeof b.ImageDialog&&(b.ImageDialog.getImageData&& -b.ImageDialog.getImageData(),b.ImageDialog.showPreviewImage&&b.ImageDialog.showPreviewImage(e)),tinyMCEPopup.close()):(a.urlParam("field_name")?(parent.document.getElementById(a.urlParam("field_name")).value=e,"undefined"!==typeof top.tinyMCE&&top.tinyMCE.activeEditor.windowManager.close(),"undefined"!==typeof parent.$.fn.colorbox&&parent.$.fn.colorbox.close()):a.urlParam("CKEditor")?window.opener.CKEDITOR.tools.callFunction(a.urlParam("CKEditorFuncNum"),e):""!=b.Properties.Width?window.opener.SetUrl(e, -b.Properties.Width,b.Properties.Height):window.opener.SetUrl(e),window.close()):a.prompt(g.fck_select_integration)},E=function(b){var e="",c=g.new_filename+' : ',d={};d[g.rename]=!0;d[g.cancel]=!1;a.prompt(c,{callback:function(d,c){if(1!=d)return!1;rname=c.children("#rname").val();if(""!=rname){var k=K(rname),h=p(b.Filename);0'+e+'
        ', -d=a("#filetree").find('a[rel="'+b+'"]');b!=fileRoot?d.next("ul").prepend(c).prev("a").click().click():(a("#filetree > ul").prepend(c),a("#filetree").find('li a[rel="'+b+e+'/"]').attr("class","cap_rename cap_delete").click(function(){h(b+e+"/")}).each(function(){a(this).contextMenu({menu:t(a(this))},function(b,d,c){d=a(d).attr("rel");v(b,d)})}));f.options.showConfirmation&&a.prompt(g.successful_added_folder)},A=function(b){b.lastIndexOf("/")==b.length-1?(h(b),a("#filetree").find('a[rel="'+b+'"]').click()): -H(b)},v=function(b,e){a.getJSON(l+"?mode=getinfo&path="+e+"&time="+(new Date).getMilliseconds(),function(c){"grid"==a("#fileinfo").data("view")?a("#fileinfo").find('img[alt="'+c.Path+'"]').parent():a("#fileinfo").find('td[title="'+c.Path+'"]').parent();switch(b){case "select":z(c);break;case "download":window.location=l+"?mode=download&path="+c.Path;break;case "rename":E(c);break;case "delete":F(c)}})},H=function(b){var e=b.substr(0,b.lastIndexOf("/")+1);y(e);var c;c='

        '; -if(window.opener||window.tinyMCEPopup||a.urlParam("field_name"))c+='";c+='";!0!=f.options.browseOnly&&(c+='");!0!=f.options.browseOnly&&(c+='");c+='";c+="
        ";a("#fileinfo").html(c);a("#parentfolder").click(function(){h(e)});c=new Date;a.getJSON(l+"?mode=getinfo&path="+encodeURIComponent(b)+"&time="+c.getMilliseconds(),function(d){if(0==d.Code){a("#fileinfo").find("h1").text(d.Filename).attr("title",b);a("#fileinfo").find("img").attr("src",d.Preview);var c;c=-1!=a.inArray(p(d.Filename),f.videos.videosExt)?!0:!1;c&&!0==f.videos.showVideoPlayer&&(c="",a("#fileinfo img").remove(),a("#fileinfo #preview h1").before(c));c=-1!=a.inArray(p(d.Filename),f.audios.audiosExt)?!0:!1;c&&!0==f.audios.showAudioPlayer&&(c='",a("#fileinfo img").remove(),a("#fileinfo #preview h1").before(c));c="";d.Properties.Width&&""!=d.Properties.Width&&(c+="
        "+g.dimensions+"
        "+d.Properties.Width+ -"x"+d.Properties.Height+"
        ");d.Properties["Date Created"]&&""!=d.Properties["Date Created"]&&(c+="
        "+g.created+"
        "+d.Properties["Date Created"]+"
        ");d.Properties["Date Modified"]&&""!=d.Properties["Date Modified"]&&(c+="
        "+g.modified+"
        "+d.Properties["Date Modified"]+"
        ");if(d.Properties.Size||0==parseInt(d.Properties.Size))c+="
        "+g.size+"
        "+C(d.Properties.Size)+"
        ";a("#fileinfo").find("dl").html(c);G(d)}else a.prompt(d.Error)})},h=function(b){y(b); -a("#fileinfo").html('');var e=new Date;b=l+"?path="+encodeURIComponent(b)+"&mode=getfolder&showThumbs="+f.options.showThumbs+"&time="+e.getMilliseconds();a.urlParam("type")&&(b+="&type="+a.urlParam("type"));a.getJSON(b,function(b){var d="";if("-1"==b.Code)D(b.Error);else{if(b)if("grid"==a("#fileinfo").data("view")){d+='
          ';for(key in b){var e=b[key].Properties,f="";for(cap in m)n(b[key],m[cap])&& -(f+=" cap_"+m[cap]);var k=64,h=e.Width;1
          '+b[key].Path+'

          '+b[key].Filename+"

          ";e.Width&&""!=e.Width&&(d+=''+e.Width+"x"+e.Height+"");e.Size&&""!=e.Size&&(d+=''+e.Size+"");e["Date Created"]&&""!=e["Date Created"]&&(d+=''+e["Date Created"]+"");e["Date Modified"]&& -""!=e["Date Modified"]&&(d+=''+e["Date Modified"]+"");d+=""}d+="
        "}else{d=d+''+('");d+="";for(key in b){k=b[key].Path;e=b[key].Properties;f="";for(cap in m)n(b[key],m[cap])&&(f+=" cap_"+m[cap]);d+='';d+='";d=e.Width&&""!=e.Width?d+(""):d+"";d=e.Size&&""!=e.Size?d+('"):d+"";d=e["Date Modified"]&&""!=e["Date Modified"]?d+(""):d+"";d+=""}d+="";d+="
        '+g.name+""+g.dimensions+""+g.size+""+g.modified+"
        '+b[key].Filename+""+e.Width+"x"+e.Height+"'+C(e.Size)+""+e["Date Modified"]+"
        "}else d+="

        "+g.could_not_retrieve_folder+"

        ";a("#fileinfo").html(d);if("grid"==a("#fileinfo").data("view"))a("#fileinfo").find("#contents li").click(function(){var b= -a(this).find("img").attr("alt");A(b)}).each(function(){a(this).contextMenu({menu:t(a(this))},function(b,d,c){d=a(d).find("img").attr("alt");v(b,d)})});else{a("#fileinfo tbody tr").click(function(){var b=a("td:first-child",this).attr("title");A(b)}).each(function(){a(this).contextMenu({menu:t(a(this))},function(b,d,c){d=a("td:first-child",d).attr("title");v(b,d)})});a("#fileinfo").find("table").tablesorter({textExtraction:function(b){return a(b).find("abbr").size()?a(b).find("abbr").attr("title"): -b.innerHTML}});var l=setInterval(function(){L(l)},300)}}})},N=function(b,e){var c=new Date,c=l+"?path="+encodeURIComponent(b)+"&mode=getfolder&showThumbs="+f.options.showThumbs+"&time="+c.getMilliseconds();a.urlParam("type")&&(c+="&type="+a.urlParam("type"));a.getJSON(c,function(a){var b="";if("-1"==a.Code)D(a.Error);else{if(a){b+='"}else b+="

        "+g.could_not_retrieve_folder+"

        ";e(b)}})};a(function(){if(f.extras.extra_js)for(var b=0;b");a("#fileinfo").data("view",f.options.defaultViewMode);w(f.options.defaultViewMode);a("#home").click(function(){var b=a("#fileinfo").data("view");a("#fileinfo").data("view",b);a("#filetree>ul>li.expanded>a").trigger("click");h(fileRoot)});a("#grid").click(function(){w("grid");a("#fileinfo").data("view","grid");h(a("#currentpath").val())});a("#list").click(function(){w("list"); -a("#fileinfo").data("view","list");h(a("#currentpath").val())});y(fileRoot);a("#uploader").attr("action",l);a("#uploader").ajaxForm({target:"#uploadresponse",beforeSubmit:function(b,c,d){if(""==a("#newfile",c).val())return!1;b=a("#newfile",c).val();b="DISALLOW_ALL"==f.security.uploadPolicy&&-1!=a.inArray(p(b),f.security.uploadRestrictions)?!0:"ALLOW_ALL"==f.security.uploadPolicy&&-1==a.inArray(p(b),f.security.uploadRestrictions)?!0:!1;if(!b)return c="

        "+g.INVALID_FILE_TYPE+"

        ","DISALLOW_ALL"== -f.security.uploadPolicy&&(c+="

        "+g.ALLOWED_FILE_TYPE+f.security.uploadRestrictions.join(", ")+".

        "),"ALLOW_ALL"==f.security.uploadPolicy&&(c+="

        "+g.DISALLOWED_FILE_TYPE+f.security.uploadRestrictions.join(", ")+".

        "),a("#filepath").val(""),a.prompt(c),!1;a("#upload").attr("disabled",!0);a("#upload span").addClass("loading").text(g.loading_data);if("images"==a.urlParam("type").toString().toLowerCase()){c=a("#newfile",c).val().toLowerCase().split(".");for(key in f.images.imagesExt)if(f.images.imagesExt[key]== -c[c.length-1])return!0;a.prompt(g.UPLOAD_IMAGES_ONLY);a("#upload").removeAttr("disabled").find("span").removeClass("loading").text(g.upload);return!1}if("undefined"!==typeof FileReader&&"auto"!=typeof f.upload.fileSizeLimit&&a("#newfile",c).get(0).files[0].size>1048576*f.upload.fileSizeLimit)return a.prompt("

        "+g.file_too_big+"

        "+g.file_size_limit+f.upload.fileSizeLimit+" "+g.mb+".

        "),a("#upload").removeAttr("disabled").find("span").removeClass("loading").text(g.upload),!1},error:function(b, -c,d){a("#upload").removeAttr("disabled").find("span").removeClass("loading").text(g.upload);a.prompt("Error uploading file")},success:function(b){b=jQuery.parseJSON(a("#uploadresponse").find("textarea").text());if(0==b.Code){var c=b.Path,d=b.Name,l=p(d),m=a("#filetree").find('a[rel="'+c+'"]'),k=m.parent(),d='
      • '+d+"
      • ";k.find("ul").size()?(k.find("ul").prepend(d),m.click().click()):(k=a("#filetree").find("ul.jqueryFileTree"),k.prepend(d), -I());h(c);f.options.showConfirmation&&a.prompt(g.successful_added_file);a("#filepath, #newfile").val("");a("#filetree").find('a[rel="'+b.Path+'/"]').click().click()}else a.prompt(b.Error);a("#upload").removeAttr("disabled");a("#upload span").removeClass("loading").text(g.upload);a("#filepath").val("")}});I();window.opener||window.tinyMCEPopup||a.urlParam("field_name")||a('#itemOptions a[href$="#select"]').remove();!0==f.options.browseOnly&&(a("#file-input-container").remove(),a("#upload").remove(), -a("#newfolder").remove(),a("#toolbar").remove("#rename"),a(".contextMenu .rename").remove(),a(".contextMenu .delete").remove());B();a(window).resize(B);a("#splitter").splitter({sizeLeft:200});A(fileRoot+expandedFolder)});document.documentElement.setAttribute("data-useragent",navigator.userAgent)})(jQuery); \ No newline at end of file +(function(e){function f(e){var t=this.window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest;if(!t){throw new Error("XMLHttpRequest not supported")}t.open("HEAD",e,false);t.send(null);if(t.status==200){return true}return false}function v(t,n){if(t["File Type"]=="dir"&&n=="download")return false;if(typeof t["Capabilities"]=="undefined")return true;else return e.inArray(n,t["Capabilities"])>-1}function B(t){var n=t.attr("class").replace(/ /g,"_");if(n=="")return"itemOptions";if(!e("#"+n).length){var r=e("#itemOptions").clone().attr("id",n);if(!t.hasClass("cap_select"))e(".select",r).remove();if(!t.hasClass("cap_download"))e(".download",r).remove();if(!t.hasClass("cap_rename"))e(".rename",r).remove();if(!t.hasClass("cap_delete"))e(".delete",r).remove();e("#itemOptions").after(r)}return n}e.urlParam=function(e){var t=(new RegExp("[\\?&]"+e+"=([^&#]*)")).exec(window.location.href);if(t)return t[1];else return 0};var t=function(){var t=null;e.ajax({async:false,url:"./scripts/filemanager.config.js",dataType:"json",cache:false,success:function(e){t=e}});return t}();var n=t.options.fileConnector||"connectors/"+t.options.lang+"/filemanager."+t.options.lang;var r=new Array("select","download","rename","delete");if(e.urlParam("langCode")!=0&&f("scripts/languages/"+e.urlParam("langCode")+".js"))t.options.culture=e.urlParam("langCode");var s=[];e.ajax({url:"scripts/languages/"+t.options.culture+".js",async:false,dataType:"json",success:function(e){s=e}});e.prompt.setDefaults({overlayspeed:"fast",show:"fadeIn",opacity:.4,persistent:false});var o=function(){var n=20;if(t.options.searchBox===true)n+=33;var r=e(window).height()-e("#uploader").height()-n;e("#splitter, #filetree, #fileinfo, .vsplitbar").height(r);var i=e("#splitter").width()-6-e("#filetree").width();e("#fileinfo").width(i)};var u=function(e,n){n=typeof n==="undefined"?true:false;if(t.options.showFullPath==false){if("function"===typeof displayPathDecorator){return displayPathDecorator(e.replace(fileRoot,"/"))}else{e=e.replace(fileRoot,"/");if(e.length>50&&n===true){var r=e.split("/");e="/"+r[1]+"/"+r[2]+"/(...)/"+r[r.length-2]+"/"}return e}}else{return e}};var a=function(t){if(t=="grid"){e("#grid").addClass("ON");e("#list").removeClass("ON")}else{e("#list").addClass("ON");e("#grid").removeClass("ON")}};var l=function(e,t,n){var r=String(n);for(i=0;i"+t+"");e("#newfile").attr("disabled","disabled");e("#upload").attr("disabled","disabled");e("#newfolder").attr("disabled","disabled")};var m=function(n){if(t.security.uploadPolicy=="DISALLOW_ALL"){if(e.inArray(y(n),t.security.uploadRestrictions)!=-1)return true}if(t.security.uploadPolicy=="ALLOW_ALL"){if(e.inArray(y(n),t.security.uploadRestrictions)==-1)return true}return false};var g=function(e,t){var n=e.replace(/^.*[\/\\]/g,"");if(typeof t=="string"&&n.substr(n.length-t.length)==t){n=n.substr(0,n.length-t.length)}return n};var y=function(e){if(e.split(".").length==1){return""}return e.split(".").pop().toLowerCase()};var b=function(e){if(e.lastIndexOf(".")!=-1){return e.substring(0,e.lastIndexOf("."))}else{return e}};var w=function(n){if(e.inArray(y(n),t.videos.videosExt)!=-1){return true}else{return false}};var E=function(n){if(e.inArray(y(n),t.audios.audiosExt)!=-1){return true}else{return false}};var S=function(n){var r="";e("#fileinfo img").remove();e("#fileinfo #preview h1").before(r)};var x=function(t){var n='";e("#fileinfo img").remove();e("#fileinfo #preview h1").before(n)};var T=function(t){e("#fileinfo").find("td:first-child").each(function(){var n=e(this).attr("title");var r=e("#filetree").find('a[rel="'+n+'"]').parent();if(typeof r.css("background-image")!=="undefined"){e(this).css("background-image",r.css("background-image"));window.clearInterval(t)}})};var N=function(t){e("#currentpath").val(t);e("#uploader h1").text(s.current_folder+u(t)).attr("title",u(t,false));e("#newfolder").unbind().click(function(){var t=s.default_foldername;var r=s.prompt_foldername+' : ';var i=function(r,i){if(r!=1)return false;var o=i.children("#fname").val();if(o!=""){t=c(o);var u=new Date;e.getJSON(n+"?mode=addfolder&path="+e("#currentpath").val()+"&name="+t+"&time="+u.getMilliseconds(),function(t){if(t["Code"]==0){P(t["Parent"],t["Name"]);I(t["Parent"]);e("#filetree").find('a[rel="'+t["Parent"]+'/"]').click().click()}else{e.prompt(t["Error"])}})}else{e.prompt(s.no_foldername)}};var o={};o[s.create_folder]=true;o[s.cancel]=false;e.prompt(r,{callback:i,buttons:o})})};var C=function(t){e("#fileinfo button").each(function(t){if(e(this).find("span").length==0)e(this).wrapInner("")});if(!v(t,"select")){e("#fileinfo").find("button#select").hide()}else{e("#fileinfo").find("button#select").click(function(){L(t)}).show();if(window.opener||window.tinyMCEPopup){e("#preview img").attr("title",s.select);e("#preview img").click(function(){L(t)}).css("cursor","pointer")}}if(!v(t,"rename")){e("#fileinfo").find("button#rename").hide()}else{e("#fileinfo").find("button#rename").click(function(){var n=A(t);if(n.length)e("#fileinfo > h1").text(n)}).show()}if(!v(t,"delete")){e("#fileinfo").find("button#delete").hide()}else{e("#fileinfo").find("button#delete").click(function(){if(O(t))e("#fileinfo").html("

        "+s.select_from_left+"

        ")}).show()}if(!v(t,"download")){e("#fileinfo").find("button#download").hide()}else{e("#fileinfo").find("button#download").click(function(){window.location=n+"?mode=download&path="+encodeURIComponent(t["Path"])}).show()}};var k=function(){e("#filetree").fileTree({root:fileRoot,datafunc:q,multiFolder:false,folderCallback:function(e){I(e)},expandedFolder:fullexpandedFolder,after:function(n){e("#filetree").find("li a").each(function(){e(this).contextMenu({menu:B(e(this))},function(t,n,r){var i=e(n).attr("rel");j(t,i)})});if(t.options.searchBox==true){e("#q").liveUpdate("#filetree ul").blur();e("#search span.q-inactive").html(s.search);e("#search a.q-reset").attr("title",s.search_reset)}}},function(e){F(e)})};var L=function(n){if(t.options.relPath!=false){var r=relPath+n["Path"]}else{var r=relPath+n["Path"]}r=r.replace("//","/");if(window.opener||window.tinyMCEPopup||e.urlParam("field_name")){if(window.tinyMCEPopup){var i=tinyMCEPopup.getWindowArg("window");i.document.getElementById(tinyMCEPopup.getWindowArg("input")).value=r;if(typeof i.ImageDialog!="undefined"){if(i.ImageDialog.getImageData)i.ImageDialog.getImageData();if(i.ImageDialog.showPreviewImage)i.ImageDialog.showPreviewImage(r)}tinyMCEPopup.close();return}if(e.urlParam("field_name")){parent.document.getElementById(e.urlParam("field_name")).value=r;if(typeof top.tinyMCE!=="undefined"){top.tinyMCE.activeEditor.windowManager.close()}if(typeof parent.$.fn.colorbox!=="undefined"){parent.$.fn.colorbox.close()}}else if(e.urlParam("CKEditor")){window.opener.CKEDITOR.tools.callFunction(e.urlParam("CKEditorFuncNum"),r)}else{if(n["Properties"]["Width"]!=""){var o=r;var u=n["Properties"]["Width"];var a=n["Properties"]["Height"];window.opener.SetUrl(o,u,a)}else{window.opener.SetUrl(r)}}window.close()}else{e.prompt(s.fck_select_integration)}};var A=function(r){var i="";var o=s.new_filename+' : ';var u=function(o,u){if(o!=1)return false;rname=u.children("#rname").val();if(rname!=""){var a=h(rname);var f=y(r["Filename"]);if(f.length>0){a=a+"."+f}var l=r["Path"];var c=n+"?mode=rename&old="+r["Path"]+"&new="+a;e.ajax({type:"GET",url:c,dataType:"json",async:false,success:function(n){if(n["Code"]==0){var o=n["New Path"];var u=n["New Name"];_(l,o,u);var a=e("#preview h1").attr("title");if(typeof a!="undefined"&&a==l){e("#preview h1").text(u)}if(e("#fileinfo").data("view")=="grid"){e('#fileinfo img[alt="'+l+'"]').parent().next("p").text(u);e('#fileinfo img[alt="'+l+'"]').attr("alt",o)}else{e('#fileinfo td[title="'+l+'"]').text(u);e('#fileinfo td[title="'+l+'"]').attr("title",o)}e("#preview h1").html(u);r["Path"]=o;r["Filename"]=u;e("#fileinfo").find("button#rename, button#delete, button#download").unbind();C(r);if(t.options.showConfirmation)e.prompt(s.successful_rename)}else{e.prompt(n["Error"])}i=n["New Name"]}})}};var a={};a[s.rename]=true;a[s.cancel]=false;e.prompt(o,{callback:u,buttons:a});return i};var O=function(r){var i=false;var o=s.confirmation_delete;var a=function(o,a){if(o!=1)return false;var f=n+"?mode=delete&path="+encodeURIComponent(r["Path"]),l=r["Path"].split("/").reverse().slice(1).reverse().join("/")+"/";e.ajax({type:"GET",url:f,dataType:"json",async:false,success:function(n){if(n["Code"]==0){D(n["Path"]);var r=n["Path"].substring(0,n["Path"].length-1);r=r.substr(0,r.lastIndexOf("/")+1);e("#uploader h1").text(s.current_folder+u(r)).attr("title",u(r,false));i=true;if(t.options.showConfirmation)e.prompt(s.successful_delete);e("#filetree").find('a[rel="'+l+'/"]').click().click()}else{i=false;e.prompt(n["Error"])}}})};var f={};f[s.yes]=true;f[s.no]=false;e.prompt(o,{callback:a,buttons:f});return i};var M=function(n,r){var i=y(r);var o=e("#filetree").find('a[rel="'+n+'"]');var u=o.parent();var a='
      • '+r+"
      • ";if(!u.find("ul").size()){u=e("#filetree").find("ul.jqueryFileTree");u.prepend(a);k()}else{u.find("ul").prepend(a);o.click().click()}I(n);if(t.options.showConfirmation)e.prompt(s.successful_added_file)};var _=function(t,n,r){var i=e("#filetree").find('a[rel="'+t+'"]');var s=i.parent().parent().prev("a");i.attr("rel",n).text(r);s.click().click()};var D=function(t){e("#filetree").find('a[rel="'+t+'"]').parent().fadeOut("slow",function(){e(this).remove()});if(e("#fileinfo").data("view")=="grid"){e('#contents img[alt="'+t+'"]').parent().parent().fadeOut("slow",function(){e(this).remove()})}else{e("table#contents").find('td[title="'+t+'"]').parent().fadeOut("slow",function(){e(this).remove()})}if(e("#preview").length){I(t.substr(0,t.lastIndexOf("/")+1))}};var P=function(n,r){var i='';var o=e("#filetree").find('a[rel="'+n+'"]');if(n!=fileRoot){o.next("ul").prepend(i).prev("a").click().click()}else{e("#filetree > ul").prepend(i);e("#filetree").find('li a[rel="'+n+r+'/"]').attr("class","cap_rename cap_delete").click(function(){I(n+r+"/")}).each(function(){e(this).contextMenu({menu:B(e(this))},function(t,n,r){var i=e(n).attr("rel");j(t,i)})})}if(t.options.showConfirmation)e.prompt(s.successful_added_folder)};var H=function(t){if(t.lastIndexOf("/")==t.length-1){I(t);e("#filetree").find('a[rel="'+t+'"]').click()}else{F(t)}};var j=function(t,r){var i=new Date;e.getJSON(n+"?mode=getinfo&path="+r+"&time="+i.getMilliseconds(),function(r){if(e("#fileinfo").data("view")=="grid"){var i=e("#fileinfo").find('img[alt="'+r["Path"]+'"]').parent()}else{var i=e("#fileinfo").find('td[title="'+r["Path"]+'"]').parent()}switch(t){case"select":L(r);break;case"download":window.location=n+"?mode=download&path="+r["Path"];break;case"rename":var s=A(r);break;case"delete":O(r);break}})};var F=function(r){var i=r.substr(0,r.lastIndexOf("/")+1);N(i);var o='

        ';o+='
        ';if(window.opener||window.tinyMCEPopup||e.urlParam("field_name"))o+='";o+='";if(t.options.browseOnly!=true)o+='";if(t.options.browseOnly!=true)o+='";o+='";o+="
        ";e("#fileinfo").html(o);e("#parentfolder").click(function(){I(i)});var u=new Date;e.getJSON(n+"?mode=getinfo&path="+encodeURIComponent(r)+"&time="+u.getMilliseconds(),function(n){if(n["Code"]==0){e("#fileinfo").find("h1").text(n["Filename"]).attr("title",r);e("#fileinfo").find("img").attr("src",n["Preview"]);if(w(n["Filename"])&&t.videos.showVideoPlayer==true){S(n)}if(E(n["Filename"])&&t.audios.showAudioPlayer==true){x(n)}var i="";if(n["Properties"]["Width"]&&n["Properties"]["Width"]!="")i+="
        "+s.dimensions+"
        "+n["Properties"]["Width"]+"x"+n["Properties"]["Height"]+"
        ";if(n["Properties"]["Date Created"]&&n["Properties"]["Date Created"]!="")i+="
        "+s.created+"
        "+n["Properties"]["Date Created"]+"
        ";if(n["Properties"]["Date Modified"]&&n["Properties"]["Date Modified"]!="")i+="
        "+s.modified+"
        "+n["Properties"]["Date Modified"]+"
        ";if(n["Properties"]["Size"]||parseInt(n["Properties"]["Size"])==0)i+="
        "+s.size+"
        "+p(n["Properties"]["Size"])+"
        ";e("#fileinfo").find("dl").html(i);C(n)}else{e.prompt(n["Error"])}})};var I=function(i){N(i);e("#fileinfo").html('');var o=new Date;var u=n+"?path="+encodeURIComponent(i)+"&mode=getfolder&showThumbs="+t.options.showThumbs+"&time="+o.getMilliseconds();if(e.urlParam("type"))u+="&type="+e.urlParam("type");e.getJSON(u,function(t){var n="";if(t.Code=="-1"){d(t.Error);return}if(t){if(e("#fileinfo").data("view")=="grid"){n+='
          ';for(key in t){var i=t[key]["Properties"];var o="";for(cap in r){if(v(t[key],r[cap])){o+=" cap_"+r[cap]}}var u=64;var a=i["Width"];if(a>1&&a
          '+t[key][

          '+t[key]["Filename"]+"

          ";if(i["Width"]&&i["Width"]!="")n+=''+i["Width"]+"x"+i["Height"]+"";if(i["Size"]&&i["Size"]!="")n+=''+i["Size"]+"";if(i["Date Created"]&&i["Date Created"]!="")n+=''+i["Date Created"]+"";if(i["Date Modified"]&&i["Date Modified"]!="")n+=''+i["Date Modified"]+"";n+=""}n+="
        "}else{n+='';n+='";n+="";for(key in t){var f=t[key]["Path"];var i=t[key]["Properties"];var o="";for(cap in r){if(v(t[key],r[cap])){o+=" cap_"+r[cap]}}n+='';n+='";if(i["Width"]&&i["Width"]!=""){n+=""}else{n+=""}if(i["Size"]&&i["Size"]!=""){n+='"}else{n+=""}if(i["Date Modified"]&&i["Date Modified"]!=""){n+=""}else{n+=""}n+=""}n+="";n+="
        '+s.name+""+s.dimensions+""+s.size+""+s.modified+"
        '+t[key]["Filename"]+""+i["Width"]+"x"+i["Height"]+"'+p(i["Size"])+""+i["Date Modified"]+"
        "}}else{n+="

        "+s.could_not_retrieve_folder+"

        "}e("#fileinfo").html(n);if(e("#fileinfo").data("view")=="grid"){e("#fileinfo").find("#contents li").click(function(){var t=e(this).find("img").attr("alt");H(t)}).each(function(){e(this).contextMenu({menu:B(e(this))},function(t,n,r){var i=e(n).find("img").attr("alt");j(t,i)})})}else{e("#fileinfo tbody tr").click(function(){var t=e("td:first-child",this).attr("title");H(t)}).each(function(){e(this).contextMenu({menu:B(e(this))},function(t,n,r){var i=e("td:first-child",n).attr("title");j(t,i)})});e("#fileinfo").find("table").tablesorter({textExtraction:function(t){if(e(t).find("abbr").size()){return e(t).find("abbr").attr("title")}else{return t.innerHTML}}});var l=setInterval(function(){T(l)},300)}})};var q=function(i,o){var u=new Date;var a=n+"?path="+encodeURIComponent(i)+"&mode=getfolder&showThumbs="+t.options.showThumbs+"&time="+u.getMilliseconds();if(e.urlParam("type"))a+="&type="+e.urlParam("type");e.getJSON(a,function(e){var n="";if(e.Code=="-1"){d(e.Error);return}if(e){n+='"}else{n+="

        "+s.could_not_retrieve_folder+"

        "}o(n)})};e(function(){if(t.extras.extra_js){for(var r=0;r");e("#fileinfo").data("view",t.options.defaultViewMode);a(t.options.defaultViewMode);e("#home").click(function(){var t=e("#fileinfo").data("view");e("#fileinfo").data("view",t);e("#filetree>ul>li.expanded>a").trigger("click");I(fileRoot)});e("#grid").click(function(){a("grid");e("#fileinfo").data("view","grid");I(e("#currentpath").val())});e("#list").click(function(){a("list");e("#fileinfo").data("view","list");I(e("#currentpath").val())});N(fileRoot);e("#uploader").attr("action",n);e("#uploader").ajaxForm({target:"#uploadresponse",beforeSubmit:function(n,r,i){if(e("#newfile",r).val()==""){return false}if(!m(e("#newfile",r).val())){var o="

        "+s.INVALID_FILE_TYPE+"

        ";if(t.security.uploadPolicy=="DISALLOW_ALL"){o+="

        "+s.ALLOWED_FILE_TYPE+t.security.uploadRestrictions.join(", ")+".

        "}if(t.security.uploadPolicy=="ALLOW_ALL"){o+="

        "+s.DISALLOWED_FILE_TYPE+t.security.uploadRestrictions.join(", ")+".

        "}e("#filepath").val("");e.prompt(o);return false}e("#upload").attr("disabled",true);e("#upload span").addClass("loading").text(s.loading_data);if(e.urlParam("type").toString().toLowerCase()=="images"){var u=e("#newfile",r).val().toLowerCase().split(".");for(key in t.images.imagesExt){if(t.images.imagesExt[key]==u[u.length-1]){return true}}e.prompt(s.UPLOAD_IMAGES_ONLY);e("#upload").removeAttr("disabled").find("span").removeClass("loading").text(s.upload);return false}if(typeof FileReader!=="undefined"&&typeof t.upload.fileSizeLimit!="auto"){var a=e("#newfile",r).get(0).files[0].size;if(a>t.upload.fileSizeLimit*1024*1024){e.prompt("

        "+s.file_too_big+"

        "+s.file_size_limit+t.upload.fileSizeLimit+" "+s.mb+".

        ");e("#upload").removeAttr("disabled").find("span").removeClass("loading").text(s.upload);return false}}},error:function(t,n,r){e("#upload").removeAttr("disabled").find("span").removeClass("loading").text(s.upload);e.prompt("Error uploading file")},success:function(t){var n=jQuery.parseJSON(e("#uploadresponse").find("textarea").text());if(n["Code"]==0){M(n["Path"],n["Name"]);e("#filepath, #newfile").val("");e("#filetree").find('a[rel="'+n["Path"]+'/"]').click().click()}else{e.prompt(n["Error"])}e("#upload").removeAttr("disabled");e("#upload span").removeClass("loading").text(s.upload);e("#filepath").val("")}});k();if(!(window.opener||window.tinyMCEPopup||e.urlParam("field_name")))e('#itemOptions a[href$="#select"]').remove();if(t.options.browseOnly==true){e("#file-input-container").remove();e("#upload").remove();e("#newfolder").remove();e("#toolbar").remove("#rename");e(".contextMenu .rename").remove();e(".contextMenu .delete").remove()}o();e(window).resize(o);e("#splitter").splitter({sizeLeft:200});H(fileRoot+expandedFolder)});var R=document.documentElement;R.setAttribute("data-useragent",navigator.userAgent)})(jQuery) \ No newline at end of file