/** * Return network volumes config. * * @return array * @author Dmitry (dio) Levashov */ protected function getNetVolumes() { if ($data = $this->session->get('netvolume', array())) { return $data; } return array(); }
/** * Return network volumes config. * * @return array * * @author Dmitry (dio) Levashov */ protected function getNetVolumes() { if ($data = $this->session->get('netvolume', [])) { return $data; } return []; }
/** * "Mount" volume. * Return true if volume available for read or write, * false - otherwise * * @param array $opts * @return bool * @author Dmitry (dio) Levashov * @author Alexey Sukhotin */ public function mount(array $opts) { if (!isset($opts['path']) || $opts['path'] === '') { return $this->setError('Path undefined.'); } if (!$this->session) { return $this->setError('Session wrapper dose not set. Need to `$volume->setSession(elFinderSessionInterface);` before mount.'); } if (!$this->session instanceof elFinderSessionInterface) { return $this->setError('Session wrapper instance must be "elFinderSessionInterface".'); } $this->options = array_merge($this->options, $opts); $this->id = $this->driverId . (!empty($this->options['id']) ? $this->options['id'] : elFinder::$volumesCnt++) . '_'; $this->root = $this->normpathCE($this->options['path']); $this->separator = isset($this->options['separator']) ? $this->options['separator'] : DIRECTORY_SEPARATOR; $this->systemRoot = isset($this->options['systemRoot']) ? $this->options['systemRoot'] : $this->separator; // set server encoding if (!empty($this->options['encoding']) && strtoupper($this->options['encoding']) !== 'UTF-8') { $this->encoding = $this->options['encoding']; } else { $this->encoding = null; } $argInit = !empty($this->ARGS['init']); // session cache if ($argInit) { $this->session->set($this->id, array()); } $this->sessionCache = $this->session->get($this->id, array()); // 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' => isset($this->options['defaults']['locked']) ? !!$this->options['defaults']['locked'] : false, 'hidden' => isset($this->options['defaults']['hidden']) ? !!$this->options['defaults']['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']) && is_callable($this->options['accessControl'])) { $this->access = $this->options['accessControl']; } $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; } // Set maximum to PHP_INT_MAX if (!defined('PHP_INT_MAX')) { define('PHP_INT_MAX', 2147483647); } if ($this->uploadMaxSize < 1 || $this->uploadMaxSize > PHP_INT_MAX) { $this->uploadMaxSize = PHP_INT_MAX; } $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\\+\\+)/'; if (($type == 'finfo' || $type == 'auto') && class_exists('finfo', false)) { $tmpFileInfo = @explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__)); } else { $tmpFileInfo = false; } $type = 'internal'; if ($tmpFileInfo && preg_match($regexp, array_shift($tmpFileInfo))) { $type = 'finfo'; $this->finfo = finfo_open(FILEINFO_MIME); } elseif (($type == 'mime_content_type' || $type == 'auto') && function_exists('mime_content_type')) { $_mimetypes = explode(';', mime_content_type(__FILE__)); if (preg_match($regexp, array_shift($_mimetypes))) { $type = 'mime_content_type'; } } $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 (elFinder::$defaultMimefile && file_exists(elFinder::$defaultMimefile)) { $file = elFinder::$defaultMimefile; } 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->basenameCE($this->root) : $this->options['alias']; // This get's triggered if $this->root == '/' and alias is empty. // Maybe modify _basename instead? if ($this->rootName === '') { $this->rootName = $this->separator; } $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 $startPath = $this->options['startPath'] ? $this->normpathCE($this->options['startPath']) : ''; if ($startPath) { $start = $this->stat($startPath); if (!empty($start) && $start['mime'] == 'directory' && $start['read'] && empty($start['hidden']) && $this->inpathCE($startPath, $this->root)) { $this->startPath = $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 = !empty($this->options['acceptedName']) && (is_string($this->options['acceptedName']) || is_callable($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 (strpos($mime, 'application/') === 0 && !empty($conf['cmd']) && isset($conf['argc']) && !empty($conf['ext']) && !isset($this->archivers['extract'][$mime])) { $this->archivers['extract'][$mime] = $conf; } } } $this->configure(); // Normarize disabled (array_merge`for type array of JSON) $this->disabled = array_merge(array_unique($this->disabled)); // fix sync interval if ($this->options['syncMinMs'] !== 0) { $this->options['syncMinMs'] = max($this->options[$this->options['syncChkAsTs'] ? 'tsPlSleep' : 'lsPlSleep'] * 1000, intval($this->options['syncMinMs'])); } return $this->mounted = true; }