コード例 #1
0
 public function mount(array $veb4112b6a6b76c8a84808a40baa94769)
 {
     if (empty($veb4112b6a6b76c8a84808a40baa94769['path'])) {
         return false;
     }
     $this->options = array_merge($this->options, $veb4112b6a6b76c8a84808a40baa94769);
     $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;
     $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);
     $this->attributes[] = array('pattern' => '~^' . preg_quote(DIRECTORY_SEPARATOR) . '$~', 'locked' => true, 'hidden' => false);
     if (!empty($this->options['attributes']) && is_array($this->options['attributes'])) {
         foreach ($this->options['attributes'] as $v0cc175b9c0f1b6a831c399e269772661) {
             if (!empty($v0cc175b9c0f1b6a831c399e269772661['pattern']) || count($v0cc175b9c0f1b6a831c399e269772661) > 1) {
                 $this->attributes[] = $v0cc175b9c0f1b6a831c399e269772661;
             }
         }
     }
     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]);
         }
     }
     if (!$this->init()) {
         return false;
     }
     $this->today = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
     $this->yesterday = $this->today - 86400;
     $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();
     $v78f0805fa8ffadabda721fdaf85b3ca9 = explode(',', isset($this->options['uploadOrder']) ? $this->options['uploadOrder'] : 'deny,allow');
     $this->uploadOrder = array(trim($v78f0805fa8ffadabda721fdaf85b3ca9[0]), trim($v78f0805fa8ffadabda721fdaf85b3ca9[1]));
     if (!empty($this->options['uploadMaxSize'])) {
         $vf7bd60b75b29d79b660a2859395c1a24 = '' . $this->options['uploadMaxSize'];
         $v3e34bdebd9bd5edda27e8728904a2552 = strtolower(substr($vf7bd60b75b29d79b660a2859395c1a24, strlen($vf7bd60b75b29d79b660a2859395c1a24) - 1));
         $v7b8b965ad4bca0e41ab51de7b31363a1 = 1;
         switch ($v3e34bdebd9bd5edda27e8728904a2552) {
             case 'k':
                 $v7b8b965ad4bca0e41ab51de7b31363a1 = 1024;
                 break;
             case 'm':
                 $v7b8b965ad4bca0e41ab51de7b31363a1 = 1048576;
                 break;
             case 'g':
                 $v7b8b965ad4bca0e41ab51de7b31363a1 = 1073741824;
         }
         $this->uploadMaxSize = intval($vf7bd60b75b29d79b660a2859395c1a24) * $v7b8b965ad4bca0e41ab51de7b31363a1;
     }
     $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'];
     $v599dcce2998a6b40b1e38e8c6006cb0a = strtolower($this->options['mimeDetect']);
     $v599dcce2998a6b40b1e38e8c6006cb0a = preg_match('/^(finfo|mime_content_type|internal|auto)$/i', $v599dcce2998a6b40b1e38e8c6006cb0a) ? $v599dcce2998a6b40b1e38e8c6006cb0a : 'auto';
     $v2f0056df010e0231e4cca0e382df44fc = '/text\\/x\\-(php|c\\+\\+)/';
     if (($v599dcce2998a6b40b1e38e8c6006cb0a == 'finfo' || $v599dcce2998a6b40b1e38e8c6006cb0a == 'auto') && class_exists('finfo') && preg_match($v2f0056df010e0231e4cca0e382df44fc, array_shift(explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__))))) {
         $v599dcce2998a6b40b1e38e8c6006cb0a = 'finfo';
     } elseif (($v599dcce2998a6b40b1e38e8c6006cb0a == 'mime_content_type' || $v599dcce2998a6b40b1e38e8c6006cb0a == 'auto') && function_exists('mime_content_type') && preg_match($v2f0056df010e0231e4cca0e382df44fc, array_shift(explode(';', mime_content_type(__FILE__))))) {
         $v599dcce2998a6b40b1e38e8c6006cb0a = 'mime_content_type';
     } else {
         $v599dcce2998a6b40b1e38e8c6006cb0a = 'internal';
     }
     $this->mimeDetect = $v599dcce2998a6b40b1e38e8c6006cb0a;
     if ($this->mimeDetect == 'internal' && !self::$mimetypesLoaded) {
         self::$mimetypesLoaded = true;
         $this->mimeDetect = 'internal';
         $v8c7dd922ad47494fc02c388e12c00eac = false;
         if (!empty($this->options['mimefile']) && file_exists($this->options['mimefile'])) {
             $v8c7dd922ad47494fc02c388e12c00eac = $this->options['mimefile'];
         } elseif (file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mime.types')) {
             $v8c7dd922ad47494fc02c388e12c00eac = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mime.types';
         } elseif (file_exists(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'mime.types')) {
             $v8c7dd922ad47494fc02c388e12c00eac = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'mime.types';
         }
         if ($v8c7dd922ad47494fc02c388e12c00eac && file_exists($v8c7dd922ad47494fc02c388e12c00eac)) {
             $v9e7553e4134fc3598a792415f7cd7b6b = file($v8c7dd922ad47494fc02c388e12c00eac);
             foreach ($v9e7553e4134fc3598a792415f7cd7b6b as $v2aa6fb0f7ebb71c0ba782d04b2a8f167 => $v6438c669e0d0de98e6929c2cc0fac474) {
                 if (!preg_match('/^\\s*#/', $v6438c669e0d0de98e6929c2cc0fac474)) {
                     $vd02a169f33469c888396a24dd9d9f1c6 = preg_split('/\\s+/', $v6438c669e0d0de98e6929c2cc0fac474, -1, PREG_SPLIT_NO_EMPTY);
                     for ($v865c0c0b4ab0e063e5caa3387c1a8741 = 1, $vf7bd60b75b29d79b660a2859395c1a24 = count($vd02a169f33469c888396a24dd9d9f1c6); $v865c0c0b4ab0e063e5caa3387c1a8741 < $vf7bd60b75b29d79b660a2859395c1a24; $v865c0c0b4ab0e063e5caa3387c1a8741++) {
                         if (!isset(self::$mimetypes[$vd02a169f33469c888396a24dd9d9f1c6[$v865c0c0b4ab0e063e5caa3387c1a8741]])) {
                             self::$mimetypes[$vd02a169f33469c888396a24dd9d9f1c6[$v865c0c0b4ab0e063e5caa3387c1a8741]] = $vd02a169f33469c888396a24dd9d9f1c6[0];
                         } else {
                         }
                     }
                 }
             }
         }
     }
     if (!$this->_isDir($this->root)) {
         return false;
     }
     $vecae13117d6f0584c25a9da6c8f8415e = $this->attr($this->root, 'read');
     if (!$vecae13117d6f0584c25a9da6c8f8415e && !$this->attr($this->root, 'write')) {
         return false;
     }
     if ($vecae13117d6f0584c25a9da6c8f8415e) {
         if ($this->options['startPath']) {
             $vd6fe1d0be6347b8ef2427fa629c04485 = $this->_normpath($this->options['startPath']);
             if ($this->_isDir($vd6fe1d0be6347b8ef2427fa629c04485) && $this->attr($vd6fe1d0be6347b8ef2427fa629c04485, 'read') && !$this->attr($vd6fe1d0be6347b8ef2427fa629c04485, 'hidden') && $this->_inpath($vd6fe1d0be6347b8ef2427fa629c04485, $this->root)) {
                 $this->startPath = $vd6fe1d0be6347b8ef2427fa629c04485;
             }
         }
     } else {
         $this->options['URL'] = '';
         $this->options['tmbURL'] = '';
         $this->options['tmbPath'] = '';
         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();
     if (!empty($this->options['archiveMimes']) && is_array($this->options['archiveMimes'])) {
         foreach ($this->archivers['create'] as $vd02a169f33469c888396a24dd9d9f1c6 => $v9e3669d19b675bd57058fd4664205d2a) {
             if (!in_array($vd02a169f33469c888396a24dd9d9f1c6, $this->options['archiveMimes'])) {
                 unset($this->archivers['create'][$vd02a169f33469c888396a24dd9d9f1c6]);
             }
         }
     }
     if (!empty($this->options['archivers']['create']) && is_array($this->options['archivers']['create'])) {
         foreach ($this->options['archivers']['create'] as $vd02a169f33469c888396a24dd9d9f1c6 => $v3a8e4c06e471595f6eb262bb9b5582d9) {
             if (strpos($vd02a169f33469c888396a24dd9d9f1c6, 'application/') === 0 && !empty($v3a8e4c06e471595f6eb262bb9b5582d9['cmd']) && isset($v3a8e4c06e471595f6eb262bb9b5582d9['argc']) && !empty($v3a8e4c06e471595f6eb262bb9b5582d9['ext']) && !isset($this->archivers['create'][$vd02a169f33469c888396a24dd9d9f1c6])) {
                 $this->archivers['create'][$vd02a169f33469c888396a24dd9d9f1c6] = $v3a8e4c06e471595f6eb262bb9b5582d9;
             }
         }
     }
     if (!empty($this->options['archivers']['extract']) && is_array($this->options['archivers']['extract'])) {
         foreach ($this->options['archivers']['extract'] as $vd02a169f33469c888396a24dd9d9f1c6 => $v3a8e4c06e471595f6eb262bb9b5582d9) {
             if (substr($vd02a169f33469c888396a24dd9d9f1c6, 'application/') === 0 && !empty($veec38a6d10735a91d1247a80b5e213a6['cmd']) && isset($v3a8e4c06e471595f6eb262bb9b5582d9['argc']) && !empty($v3a8e4c06e471595f6eb262bb9b5582d9['ext']) && !isset($this->archivers['extract'][$vd02a169f33469c888396a24dd9d9f1c6])) {
                 $this->archivers['extract'][$vd02a169f33469c888396a24dd9d9f1c6] = $v3a8e4c06e471595f6eb262bb9b5582d9;
             }
         }
     }
     $this->configure();
     return $this->mounted = true;
 }
コード例 #2
0
 /**
  * "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 (!isset($opts['path']) || $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]);
         }
     }
     $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\\+\\+)/';
     if (($type == 'finfo' || $type == 'auto') && class_exists('finfo') && preg_match($regexp, array_shift(explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__))))) {
         $type = 'finfo';
         $this->finfo = finfo_open(FILEINFO_MIME);
     } 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];
                         }
                     }
                 }
             }
         }
     }
     $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;
 }
コード例 #3
0
 /**
  * Detect file mimetype using "internal" method or Loading mime.types with $path = ''
  *
  * @param  string  $path  file path
  * @return string
  * @author Dmitry (dio) Levashov
  **/
 protected static function mimetypeInternalDetect($path = '')
 {
     // load default MIME table file "mime.types"
     if (!elFinderVolumeDriver::$mimetypesLoaded) {
         elFinderVolumeDriver::$mimetypesLoaded = true;
         $file = elFinder::$defaultMimefile;
         if ($file === '' || !is_readable($file)) {
             $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mime.types';
         }
         if (is_readable($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(elFinderVolumeDriver::$mimetypes[$mime[$i]])) {
                             elFinderVolumeDriver::$mimetypes[$mime[$i]] = $mime[0];
                         }
                     }
                 }
             }
         }
     }
     $ext = '';
     if ($path) {
         $pinfo = pathinfo($path);
         $ext = isset($pinfo['extension']) ? strtolower($pinfo['extension']) : '';
     }
     return $ext && isset(elFinderVolumeDriver::$mimetypes[$ext]) ? elFinderVolumeDriver::$mimetypes[$ext] : 'unknown';
 }