/** * Configure after successfull mount. * * @return void * @author Dmitry (dio) Levashov **/ protected function configure() { // chek thumbnails path if ($this->options['tmbPath']) { $this->options['tmbPath'] = strpos($this->options['tmbPath'], DIRECTORY_SEPARATOR) === false ? $this->root . DIRECTORY_SEPARATOR . $this->options['tmbPath'] : $this->_normpath($this->options['tmbPath']); } parent::configure(); // if no thumbnails url - try detect it if ($this->attr($this->root, 'read') && !$this->tmbURL && $this->URL) { if (strpos($this->tmbPath, $this->root) === 0) { $this->tmbURL = $this->URL . str_replace(DIRECTORY_SEPARATOR, '/', substr($this->tmbPath, strlen($this->root) + 1)); if (preg_match("|[^/?&=]\$|", $this->tmbURL)) { $this->tmbURL .= '/'; } } } $this->aroot = realpath($this->root); }
/** * "Mount" volume. * Return true if volume available for read or write, * false - otherwise * * @return bool * @author Dmitry (dio) Levashov * @author Alexey Sukhotin **/ public function mount(array $opts) { if (empty($opts['path'])) { return false; } $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]); } } // debug($this->attributes); if (!$this->init()) { return false; } $this->today = mktime(0, 0, 0, date('m'), date('d'), date('Y')); $this->yesterday = $this->today - 86400; // 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(); $parts = explode(',', isset($this->options['uploadOrder']) ? $this->options['uploadOrder'] : 'deny,allow'); $this->uploadOrder = array(trim($parts[0]), trim($parts[1])); 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\\+\\+)/'; if (($type == 'finfo' || $type == 'auto') && class_exists('finfo') && preg_match($regexp, array_shift(explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__))))) { $type = 'finfo'; } elseif (($type == 'mime_content_type' || $type == 'auto') && function_exists('mime_content_type') && preg_match($regexp, array_shift(explode(';', mime_content_type(__FILE__))))) { $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]; } else { // echo $mime[$i].' '.$mime[0].'<br>'; } } } } } } // debug(self::$mimetypes); // set root path if (!$this->_isDir($this->root)) { return false; } $read = $this->attr($this->root, 'read'); // echo $this->attr($this->root.'/.tmb', 'hidden'); if (!$read && !$this->attr($this->root, 'write')) { return false; } if ($read) { // check startPath - path to open by default instead of root if ($this->options['startPath']) { $path = $this->_normpath($this->options['startPath']); if ($this->_isDir($path) && $this->attr($path, 'read') && !$this->attr($path, 'hidden') && $this->_inpath($path, $this->root)) { $this->startPath = $path; } } } else { $this->options['URL'] = ''; $this->options['tmbURL'] = ''; $this->options['tmbPath'] = ''; // read only volume array_unshift($this->attributes, array('pattern' => '/.*/', 'read' => false)); } $this->rootName = empty($this->options['alias']) ? $this->_basename($this->root) : $this->options['alias']; $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(); return $this->mounted = true; }