public function mount(array $opts)
{
if (!isset($opts['path']) || $opts['path'] === '') {
return $this->setError('Path undefined.');
}
$this->options = array_merge($this->options, $opts);
$this->id = $this->driverId . (!empty($this->options['id']) ? $this->options['id'] : elFinder::$volumesCnt++) . '_';
$this->root = $this->_normpath($this->options['path']);
$this->separator = isset($this->options['separator']) ? $this->options['separator'] : DIRECTORY_SEPARATOR;
// default file attribute
$this->defaults = array('read' => isset($this->options['defaults']['read']) ? !!$this->options['defaults']['read'] : true, 'write' => isset($this->options['defaults']['write']) ? !!$this->options['defaults']['write'] : true, 'locked' => false, 'hidden' => false);
// root attributes
$this->attributes[] = array('pattern' => '~^' . preg_quote(DIRECTORY_SEPARATOR) . '$~', 'locked' => true, 'hidden' => false);
// set files attributes
if (!empty($this->options['attributes']) && is_array($this->options['attributes'])) {
foreach ($this->options['attributes'] as $a) {
// attributes must contain pattern and at least one rule
if (!empty($a['pattern']) || count($a) > 1) {
$this->attributes[] = $a;
}
}
}
if (!empty($this->options['accessControl'])) {
if (is_string($this->options['accessControl']) && function_exists($this->options['accessControl'])) {
$this->access = $this->options['accessControl'];
} elseif (is_array($this->options['accessControl']) && count($this->options['accessControl']) > 1 && is_object($this->options['accessControl'][0]) && method_exists($this->options['accessControl'][0], $this->options['accessControl'][1])) {
$this->access = array($this->options['accessControl'][0], $this->options['accessControl'][1]);
}
}
$this->today = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$this->yesterday = $this->today - 86400;
// debug($this->attributes);
if (!$this->init()) {
return false;
}
// check some options is arrays
$this->uploadAllow = isset($this->options['uploadAllow']) && is_array($this->options['uploadAllow']) ? $this->options['uploadAllow'] : array();
$this->uploadDeny = isset($this->options['uploadDeny']) && is_array($this->options['uploadDeny']) ? $this->options['uploadDeny'] : array();
if (is_string($this->options['uploadOrder'])) {
// telephat_mode on, compatibility with 1.x
$parts = explode(',', isset($this->options['uploadOrder']) ? $this->options['uploadOrder'] : 'deny,allow');
$this->uploadOrder = array(trim($parts[0]), trim($parts[1]));
} else {
// telephat_mode off
$this->uploadOrder = $this->options['uploadOrder'];
}
if (!empty($this->options['uploadMaxSize'])) {
$size = '' . $this->options['uploadMaxSize'];
$unit = strtolower(substr($size, strlen($size) - 1));
$n = 1;
switch ($unit) {
case 'k':
$n = 1024;
break;
case 'm':
$n = 1048576;
break;
case 'g':
$n = 1073741824;
}
$this->uploadMaxSize = intval($size) * $n;
}
$this->disabled = isset($this->options['disabled']) && is_array($this->options['disabled']) ? $this->options['disabled'] : array();
$this->cryptLib = $this->options['cryptLib'];
$this->mimeDetect = $this->options['mimeDetect'];
// find available mimetype detect method
$type = strtolower($this->options['mimeDetect']);
$type = preg_match('/^(finfo|mime_content_type|internal|auto)$/i', $type) ? $type : 'auto';
$regexp = '/text\\/x\\-(php|c\\+\\+)/';
$data = $tmp = explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__));
$match_mime_content_type = array_shift($data);
$exploded_data = explode(';', mime_content_type(__FILE__));
$match_mime_content_type2 = array_shift($exploded_data);
if (($type == 'finfo' || $type == 'auto') && class_exists('finfo') && preg_match($regexp, $match_mime_content_type)) {
$type = 'finfo';
$this->finfo = finfo_open(FILEINFO_MIME);
} elseif (($type == 'mime_content_type' || $type == 'auto') && function_exists('mime_content_type') && preg_match($regexp, $match_mime_content_type2)) {
$type = 'mime_content_type';
} else {
$type = 'internal';
}
$this->mimeDetect = $type;
// load mimes from external file for mimeDetect == 'internal'
// based on Alexey Sukhotin idea and patch: http://elrte.org/redmine/issues/163
// file must be in file directory or in parent one
if ($this->mimeDetect == 'internal' && !self::$mimetypesLoaded) {
self::$mimetypesLoaded = true;
$this->mimeDetect = 'internal';
$file = false;
if (!empty($this->options['mimefile']) && file_exists($this->options['mimefile'])) {
$file = $this->options['mimefile'];
} elseif (file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mime.types')) {
$file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mime.types';
} elseif (file_exists(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'mime.types')) {
$file = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'mime.types';
}
if ($file && file_exists($file)) {
$mimecf = file($file);
foreach ($mimecf as $line_num => $line) {
if (!preg_match('/^\\s*#/', $line)) {
$mime = preg_split('/\\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
for ($i = 1, $size = count($mime); $i < $size; $i++) {
if (!isset(self::$mimetypes[$mime[$i]])) {
self::$mimetypes[$mime[$i]] = $mime[0];
}
}
}
}
}
}
$this->rootName = empty($this->options['alias']) ? $this->_basename($this->root) : $this->options['alias'];
$root = $this->stat($this->root);
if (!$root) {
return $this->setError('Root folder does not exists.');
}
if (!$root['read'] && !$root['write']) {
return $this->setError('Root folder has not read and write permissions.');
}
// debug($root);
if ($root['read']) {
// check startPath - path to open by default instead of root
if ($this->options['startPath']) {
$start = $this->stat($this->options['startPath']);
if (!empty($start) && $start['mime'] == 'directory' && $start['read'] && empty($start['hidden']) && $this->_inpath($this->options['startPath'], $this->root)) {
$this->startPath = $this->options['startPath'];
if (substr($this->startPath, -1, 1) == $this->options['separator']) {
$this->startPath = substr($this->startPath, 0, -1);
}
}
}
} else {
$this->options['URL'] = '';
$this->options['tmbURL'] = '';
$this->options['tmbPath'] = '';
// read only volume
array_unshift($this->attributes, array('pattern' => '/.*/', 'read' => false));
}
$this->treeDeep = $this->options['treeDeep'] > 0 ? (int) $this->options['treeDeep'] : 1;
$this->tmbSize = $this->options['tmbSize'] > 0 ? (int) $this->options['tmbSize'] : 48;
$this->URL = $this->options['URL'];
if ($this->URL && preg_match("|[^/?&=]\$|", $this->URL)) {
$this->URL .= '/';
}
$this->tmbURL = !empty($this->options['tmbURL']) ? $this->options['tmbURL'] : '';
if ($this->tmbURL && preg_match("|[^/?&=]\$|", $this->tmbURL)) {
$this->tmbURL .= '/';
}
$this->nameValidator = is_string($this->options['acceptedName']) && !empty($this->options['acceptedName']) ? $this->options['acceptedName'] : '';
$this->_checkArchivers();
// manual control archive types to create
if (!empty($this->options['archiveMimes']) && is_array($this->options['archiveMimes'])) {
foreach ($this->archivers['create'] as $mime => $v) {
if (!in_array($mime, $this->options['archiveMimes'])) {
unset($this->archivers['create'][$mime]);
}
}
}
// manualy add archivers
if (!empty($this->options['archivers']['create']) && is_array($this->options['archivers']['create'])) {
foreach ($this->options['archivers']['create'] as $mime => $conf) {
if (strpos($mime, 'application/') === 0 && !empty($conf['cmd']) && isset($conf['argc']) && !empty($conf['ext']) && !isset($this->archivers['create'][$mime])) {
$this->archivers['create'][$mime] = $conf;
}
}
}
if (!empty($this->options['archivers']['extract']) && is_array($this->options['archivers']['extract'])) {
foreach ($this->options['archivers']['extract'] as $mime => $conf) {
if (substr($mime, 'application/') === 0 && !empty($cons['cmd']) && isset($conf['argc']) && !empty($conf['ext']) && !isset($this->archivers['extract'][$mime])) {
$this->archivers['extract'][$mime] = $conf;
}
}
}
$this->configure();
// echo $this->uploadMaxSize;
// echo $this->options['uploadMaxSize'];
return $this->mounted = true;
}