|
|
@@ -80,31 +80,6 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
/* INIT AND CONFIGURE */
|
|
|
/*********************************************************************/
|
|
|
|
|
|
- /**
|
|
|
- * Close connection
|
|
|
- *
|
|
|
- * @return void
|
|
|
- * @author Dmitry (dio) Levashov
|
|
|
- **/
|
|
|
- public function umount() {
|
|
|
- $this->db->close();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Return debug info for client
|
|
|
- *
|
|
|
- * @return array
|
|
|
- * @author Dmitry (dio) Levashov
|
|
|
- **/
|
|
|
- public function debug() {
|
|
|
- $debug = parent::debug();
|
|
|
- $debug['sqlCount'] = $this->sqlCnt;
|
|
|
- if ($this->dbError) {
|
|
|
- $debug['dbError'] = $this->dbError;
|
|
|
- }
|
|
|
- return $debug;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Prepare driver before mount volume.
|
|
|
* Connect to db, check required tables and fetch root path
|
|
|
@@ -113,22 +88,22 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
* @author Dmitry (dio) Levashov
|
|
|
**/
|
|
|
protected function init() {
|
|
|
-
|
|
|
+
|
|
|
if (!($this->options['host'] || $this->options['socket'])
|
|
|
- || !$this->options['user']
|
|
|
- || !$this->options['pass']
|
|
|
+ || !$this->options['user']
|
|
|
+ || !$this->options['pass']
|
|
|
|| !$this->options['db']
|
|
|
|| !$this->options['path']
|
|
|
|| !$this->options['files_table']) {
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
$this->db = new mysqli($this->options['host'], $this->options['user'], $this->options['pass'], $this->options['db'], $this->options['port'], $this->options['socket']);
|
|
|
if ($this->db->connect_error || mysqli_connect_error()) {
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$this->db->set_charset('utf8');
|
|
|
|
|
|
if ($res = $this->db->query('SHOW TABLES')) {
|
|
|
@@ -148,56 +123,62 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
- * Return stat for given path.
|
|
|
- * Stat contains following fields:
|
|
|
- * - (int) size file size in b. required
|
|
|
- * - (int) ts file modification time in unix time. required
|
|
|
- * - (string) mime mimetype. required for folders, others - optionally
|
|
|
- * - (bool) read read permissions. required
|
|
|
- * - (bool) write write permissions. required
|
|
|
- * - (bool) locked is object locked. optionally
|
|
|
- * - (bool) hidden is object hidden. optionally
|
|
|
- * - (string) alias for symlinks - link target path relative to root path. optionally
|
|
|
- * - (string) target for symlinks - link target path. optionally
|
|
|
- *
|
|
|
- * If file does not exists - returns empty array or false.
|
|
|
+ * Set tmp path
|
|
|
*
|
|
|
- * @param string $path file path
|
|
|
- * @return array|false
|
|
|
+ * @return void
|
|
|
* @author Dmitry (dio) Levashov
|
|
|
**/
|
|
|
- protected function _stat($path) {
|
|
|
- $sql = 'SELECT f.id, f.parent_id, f.name, f.size, f.mtime AS ts, f.mime, f.read, f.write, f.locked, f.hidden, f.width, f.height, IF(ch.id, 1, 0) AS dirs
|
|
|
- FROM '.$this->tbf.' AS f
|
|
|
- LEFT JOIN '.$this->tbf.' AS ch ON ch.parent_id=f.id AND ch.mime=\'directory\'
|
|
|
- WHERE f.id=\''.$path.'\'
|
|
|
- GROUP BY f.id, ch.id';
|
|
|
-
|
|
|
- $res = $this->query($sql);
|
|
|
+ protected function configure() {
|
|
|
+ parent::configure();
|
|
|
|
|
|
- if ($res) {
|
|
|
- $stat = $res->fetch_assoc();
|
|
|
- if ($stat['parent_id']) {
|
|
|
- $stat['phash'] = $this->encode($stat['parent_id']);
|
|
|
- }
|
|
|
- if ($stat['mime'] == 'directory') {
|
|
|
- unset($stat['width']);
|
|
|
- unset($stat['height']);
|
|
|
- $stat['size'] = 0;
|
|
|
- } else {
|
|
|
- if (!$stat['mime']) {
|
|
|
- unset($stat['mime']);
|
|
|
+ if (($tmp = $this->options['tmpPath'])) {
|
|
|
+ if (!file_exists($tmp)) {
|
|
|
+ if (mkdir($tmp)) {
|
|
|
+ chmod($tmp, $this->options['tmbPathMode']);
|
|
|
}
|
|
|
- unset($stat['dirs']);
|
|
|
}
|
|
|
- unset($stat['id']);
|
|
|
- unset($stat['parent_id']);
|
|
|
- return $stat;
|
|
|
+
|
|
|
+ $this->tmpPath = is_dir($tmp) && is_writable($tmp) ? $tmp : false;
|
|
|
+ }
|
|
|
+ if (!$this->tmpPath && ($tmp = elFinder::getStaticVar('commonTempPath'))) {
|
|
|
+ $this->tmpPath = $tmp;
|
|
|
+ }
|
|
|
+
|
|
|
+ // fallback of $this->tmp
|
|
|
+ if (!$this->tmpPath && $this->tmbPathWritable) {
|
|
|
+ $this->tmpPath = $this->tmbPath;
|
|
|
+ }
|
|
|
|
|
|
+ $this->mimeDetect = 'internal';
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Close connection
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ * @author Dmitry (dio) Levashov
|
|
|
+ **/
|
|
|
+ public function umount() {
|
|
|
+ $this->db->close();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Return debug info for client
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ * @author Dmitry (dio) Levashov
|
|
|
+ **/
|
|
|
+ public function debug() {
|
|
|
+ $debug = parent::debug();
|
|
|
+ $debug['sqlCount'] = $this->sqlCnt;
|
|
|
+ if ($this->dbError) {
|
|
|
+ $debug['dbError'] = $this->dbError;
|
|
|
}
|
|
|
- return array();
|
|
|
+ return $debug;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -218,39 +199,109 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Set tmp path
|
|
|
+ * Create empty object with required mimetype
|
|
|
*
|
|
|
- * @return void
|
|
|
+ * @param string $path parent dir path
|
|
|
+ * @param string $name object name
|
|
|
+ * @param string $mime mime type
|
|
|
+ * @return bool
|
|
|
* @author Dmitry (dio) Levashov
|
|
|
**/
|
|
|
- protected function configure() {
|
|
|
- parent::configure();
|
|
|
+ protected function make($path, $name, $mime) {
|
|
|
+ $sql = 'INSERT INTO %s (`parent_id`, `name`, `size`, `mtime`, `mime`, `content`, `read`, `write`, `locked`, `hidden`, `width`, `height`) VALUES (\'%s\', \'%s\', 0, %d, \'%s\', \'\', \'%d\', \'%d\', \'%d\', \'%d\', 0, 0)';
|
|
|
+ $sql = sprintf($sql, $this->tbf, $path, $this->db->real_escape_string($name), time(), $mime, $this->defaults['read'], $this->defaults['write'], $this->defaults['locked'], $this->defaults['hidden']);
|
|
|
+ // echo $sql;
|
|
|
+ return $this->query($sql) && $this->db->affected_rows > 0;
|
|
|
+ }
|
|
|
|
|
|
- if (($tmp = $this->options['tmpPath'])) {
|
|
|
- if (!file_exists($tmp)) {
|
|
|
- if (mkdir($tmp)) {
|
|
|
- chmod($tmp, $this->options['tmbPathMode']);
|
|
|
+ /*********************************************************************/
|
|
|
+ /* FS API */
|
|
|
+ /*********************************************************************/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Cache dir contents
|
|
|
+ *
|
|
|
+ * @param string $path dir path
|
|
|
+ * @return string
|
|
|
+ * @author Dmitry Levashov
|
|
|
+ **/
|
|
|
+ protected function cacheDir($path) {
|
|
|
+ $this->dirsCache[$path] = array();
|
|
|
+
|
|
|
+ $sql = 'SELECT f.id, f.parent_id, f.name, f.size, f.mtime AS ts, f.mime, f.read, f.write, f.locked, f.hidden, f.width, f.height, IF(ch.id, 1, 0) AS dirs
|
|
|
+ FROM '.$this->tbf.' AS f
|
|
|
+ LEFT JOIN '.$this->tbf.' AS ch ON ch.parent_id=f.id AND ch.mime=\'directory\'
|
|
|
+ WHERE f.parent_id=\''.$path.'\'
|
|
|
+ GROUP BY f.id, ch.id';
|
|
|
+
|
|
|
+ $res = $this->query($sql);
|
|
|
+ if ($res) {
|
|
|
+ while ($row = $res->fetch_assoc()) {
|
|
|
+ $id = $row['id'];
|
|
|
+ if ($row['parent_id']) {
|
|
|
+ $row['phash'] = $this->encode($row['parent_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($row['mime'] == 'directory') {
|
|
|
+ unset($row['width']);
|
|
|
+ unset($row['height']);
|
|
|
+ $row['size'] = 0;
|
|
|
+ } else {
|
|
|
+ unset($row['dirs']);
|
|
|
+ }
|
|
|
+
|
|
|
+ unset($row['id']);
|
|
|
+ unset($row['parent_id']);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (($stat = $this->updateCache($id, $row)) && empty($stat['hidden'])) {
|
|
|
+ $this->dirsCache[$path][] = $id;
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->dirsCache[$path];
|
|
|
+ }
|
|
|
|
|
|
- $this->tmpPath = is_dir($tmp) && is_writable($tmp) ? $tmp : false;
|
|
|
+ /**
|
|
|
+ * Return array of parents paths (ids)
|
|
|
+ *
|
|
|
+ * @param int $path file path (id)
|
|
|
+ * @return array
|
|
|
+ * @author Dmitry (dio) Levashov
|
|
|
+ **/
|
|
|
+ protected function getParents($path) {
|
|
|
+ $parents = array();
|
|
|
+
|
|
|
+ while ($path) {
|
|
|
+ if ($file = $this->stat($path)) {
|
|
|
+ array_unshift($parents, $path);
|
|
|
+ $path = isset($file['phash']) ? $this->decode($file['phash']) : false;
|
|
|
+ }
|
|
|
}
|
|
|
- if (!$this->tmpPath && ($tmp = elFinder::getStaticVar('commonTempPath'))) {
|
|
|
- $this->tmpPath = $tmp;
|
|
|
+
|
|
|
+ if (count($parents)) {
|
|
|
+ array_pop($parents);
|
|
|
}
|
|
|
+ return $parents;
|
|
|
+ }
|
|
|
|
|
|
- // fallback of $this->tmp
|
|
|
- if (!$this->tmpPath && $this->tmbPathWritable) {
|
|
|
- $this->tmpPath = $this->tmbPath;
|
|
|
+ /**
|
|
|
+ * Return correct file path for LOAD_FILE method
|
|
|
+ *
|
|
|
+ * @param string $path file path (id)
|
|
|
+ * @return string
|
|
|
+ * @author Troex Nevelin
|
|
|
+ **/
|
|
|
+ protected function loadFilePath($path) {
|
|
|
+ $realPath = realpath($path);
|
|
|
+ if (DIRECTORY_SEPARATOR == '\\') { // windows
|
|
|
+ $realPath = str_replace('\\', '\\\\', $realPath);
|
|
|
}
|
|
|
-
|
|
|
- $this->mimeDetect = 'internal';
|
|
|
+ return $this->db->real_escape_string($realPath);
|
|
|
}
|
|
|
|
|
|
- /*********************************************************************/
|
|
|
- /* FS API */
|
|
|
- /*********************************************************************/
|
|
|
-
|
|
|
/**
|
|
|
* Recursive files search
|
|
|
*
|
|
|
@@ -263,7 +314,7 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
protected function doSearch($path, $q, $mimes) {
|
|
|
$dirs = array();
|
|
|
$timeout = $this->options['searchTimeout']? $this->searchStart + $this->options['searchTimeout'] : 0;
|
|
|
-
|
|
|
+
|
|
|
if ($path != $this->root) {
|
|
|
$dirs = $inpath = array(intval($path));
|
|
|
while($inpath) {
|
|
|
@@ -282,7 +333,7 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
}
|
|
|
|
|
|
$result = array();
|
|
|
-
|
|
|
+
|
|
|
if ($mimes) {
|
|
|
$whrs = array();
|
|
|
foreach($mimes as $mime) {
|
|
|
@@ -299,27 +350,27 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
if ($dirs) {
|
|
|
$whr = '(' . $whr . ') AND (`parent_id` IN (' . join(',', $dirs) . '))';
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$sql = 'SELECT f.id, f.parent_id, f.name, f.size, f.mtime AS ts, f.mime, f.read, f.write, f.locked, f.hidden, f.width, f.height, 0 AS dirs
|
|
|
FROM %s AS f
|
|
|
WHERE %s';
|
|
|
-
|
|
|
+
|
|
|
$sql = sprintf($sql, $this->tbf, $whr);
|
|
|
-
|
|
|
+
|
|
|
if (($res = $this->query($sql))) {
|
|
|
while ($row = $res->fetch_assoc()) {
|
|
|
if ($timeout && $timeout < time()) {
|
|
|
$this->setError(elFinder::ERROR_SEARCH_TIMEOUT, $this->path($this->encode($path)));
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (!$this->mimeAccepted($row['mime'], $mimes)) {
|
|
|
continue;
|
|
|
}
|
|
|
$id = $row['id'];
|
|
|
if ($row['parent_id']) {
|
|
|
$row['phash'] = $this->encode($row['parent_id']);
|
|
|
- }
|
|
|
+ }
|
|
|
$row['path'] = $this->_path($id);
|
|
|
|
|
|
if ($row['mime'] == 'directory') {
|
|
|
@@ -337,52 +388,22 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Return fake path started from root dir
|
|
|
- *
|
|
|
- * @param string $path file path
|
|
|
- * @return string
|
|
|
- * @author Dmitry (dio) Levashov
|
|
|
- **/
|
|
|
- protected function _path($path) {
|
|
|
- if (($file = $this->stat($path)) == false) {
|
|
|
- return '';
|
|
|
- }
|
|
|
-
|
|
|
- $parentsIds = $this->getParents($path);
|
|
|
- $path = '';
|
|
|
- foreach ($parentsIds as $id) {
|
|
|
- $dir = $this->stat($id);
|
|
|
- $path .= $dir['name'].$this->separator;
|
|
|
- }
|
|
|
- return $path.$file['name'];
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Return array of parents paths (ids)
|
|
|
- *
|
|
|
- * @param int $path file path (id)
|
|
|
- * @return array
|
|
|
- * @author Dmitry (dio) Levashov
|
|
|
- **/
|
|
|
- protected function getParents($path) {
|
|
|
- $parents = array();
|
|
|
|
|
|
- while ($path) {
|
|
|
- if ($file = $this->stat($path)) {
|
|
|
- array_unshift($parents, $path);
|
|
|
- $path = isset($file['phash']) ? $this->decode($file['phash']) : false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (count($parents)) {
|
|
|
- array_pop($parents);
|
|
|
- }
|
|
|
- return $parents;
|
|
|
+ /*********************** paths/urls *************************/
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Return parent directory path
|
|
|
+ *
|
|
|
+ * @param string $path file path
|
|
|
+ * @return string
|
|
|
+ * @author Dmitry (dio) Levashov
|
|
|
+ **/
|
|
|
+ protected function _dirname($path) {
|
|
|
+ return ($stat = $this->stat($path)) ? (!empty($stat['phash']) ? $this->decode($stat['phash']) : $this->root) : false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -396,8 +417,23 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
return ($stat = $this->stat($path)) ? $stat['name'] : false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Join dir name and file name and return full path
|
|
|
+ *
|
|
|
+ * @param string $dir
|
|
|
+ * @param string $name
|
|
|
+ * @return string
|
|
|
+ * @author Dmitry (dio) Levashov
|
|
|
+ **/
|
|
|
+ protected function _joinPath($dir, $name) {
|
|
|
+ $sql = 'SELECT id FROM '.$this->tbf.' WHERE parent_id=\''.$dir.'\' AND name=\''.$this->db->real_escape_string($name).'\'';
|
|
|
|
|
|
- /*********************** paths/urls *************************/
|
|
|
+ if (($res = $this->query($sql)) && ($r = $res->fetch_assoc())) {
|
|
|
+ $this->updateCache($r['id'], $this->_stat($r['id']));
|
|
|
+ return $r['id'];
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Return normalized path, this works the same as os.path.normpath() in Python
|
|
|
@@ -409,7 +445,7 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
protected function _normpath($path) {
|
|
|
return $path;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Return file path related to root dir
|
|
|
*
|
|
|
@@ -420,7 +456,7 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
protected function _relpath($path) {
|
|
|
return $path;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Convert path related to root dir into real path
|
|
|
*
|
|
|
@@ -432,6 +468,27 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
return $path;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Return fake path started from root dir
|
|
|
+ *
|
|
|
+ * @param string $path file path
|
|
|
+ * @return string
|
|
|
+ * @author Dmitry (dio) Levashov
|
|
|
+ **/
|
|
|
+ protected function _path($path) {
|
|
|
+ if (($file = $this->stat($path)) == false) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ $parentsIds = $this->getParents($path);
|
|
|
+ $path = '';
|
|
|
+ foreach ($parentsIds as $id) {
|
|
|
+ $dir = $this->stat($id);
|
|
|
+ $path .= $dir['name'].$this->separator;
|
|
|
+ }
|
|
|
+ return $path.$file['name'];
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Return true if $path is children of $parent
|
|
|
*
|
|
|
@@ -446,6 +503,58 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
: in_array($parent, $this->getParents($path));
|
|
|
}
|
|
|
|
|
|
+ /***************** file stat ********************/
|
|
|
+ /**
|
|
|
+ * Return stat for given path.
|
|
|
+ * Stat contains following fields:
|
|
|
+ * - (int) size file size in b. required
|
|
|
+ * - (int) ts file modification time in unix time. required
|
|
|
+ * - (string) mime mimetype. required for folders, others - optionally
|
|
|
+ * - (bool) read read permissions. required
|
|
|
+ * - (bool) write write permissions. required
|
|
|
+ * - (bool) locked is object locked. optionally
|
|
|
+ * - (bool) hidden is object hidden. optionally
|
|
|
+ * - (string) alias for symlinks - link target path relative to root path. optionally
|
|
|
+ * - (string) target for symlinks - link target path. optionally
|
|
|
+ *
|
|
|
+ * If file does not exists - returns empty array or false.
|
|
|
+ *
|
|
|
+ * @param string $path file path
|
|
|
+ * @return array|false
|
|
|
+ * @author Dmitry (dio) Levashov
|
|
|
+ **/
|
|
|
+ protected function _stat($path) {
|
|
|
+ $sql = 'SELECT f.id, f.parent_id, f.name, f.size, f.mtime AS ts, f.mime, f.read, f.write, f.locked, f.hidden, f.width, f.height, IF(ch.id, 1, 0) AS dirs
|
|
|
+ FROM '.$this->tbf.' AS f
|
|
|
+ LEFT JOIN '.$this->tbf.' AS ch ON ch.parent_id=f.id AND ch.mime=\'directory\'
|
|
|
+ WHERE f.id=\''.$path.'\'
|
|
|
+ GROUP BY f.id, ch.id';
|
|
|
+
|
|
|
+ $res = $this->query($sql);
|
|
|
+
|
|
|
+ if ($res) {
|
|
|
+ $stat = $res->fetch_assoc();
|
|
|
+ if ($stat['parent_id']) {
|
|
|
+ $stat['phash'] = $this->encode($stat['parent_id']);
|
|
|
+ }
|
|
|
+ if ($stat['mime'] == 'directory') {
|
|
|
+ unset($stat['width']);
|
|
|
+ unset($stat['height']);
|
|
|
+ $stat['size'] = 0;
|
|
|
+ } else {
|
|
|
+ if (!$stat['mime']) {
|
|
|
+ unset($stat['mime']);
|
|
|
+ }
|
|
|
+ unset($stat['dirs']);
|
|
|
+ }
|
|
|
+ unset($stat['id']);
|
|
|
+ unset($stat['parent_id']);
|
|
|
+ return $stat;
|
|
|
+
|
|
|
+ }
|
|
|
+ return array();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Return true if path is dir and has at least one childs directory
|
|
|
*
|
|
|
@@ -470,6 +579,8 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
return ($stat = $this->stat($path)) && isset($stat['width']) && isset($stat['height']) ? $stat['width'].'x'.$stat['height'] : '';
|
|
|
}
|
|
|
|
|
|
+ /******************** file/dir content *********************/
|
|
|
+
|
|
|
/**
|
|
|
* Return files list in directory.
|
|
|
*
|
|
|
@@ -482,55 +593,7 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
? $this->dirsCache[$path]
|
|
|
: $this->cacheDir($path);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Cache dir contents
|
|
|
- *
|
|
|
- * @param string $path dir path
|
|
|
- * @return string
|
|
|
- * @author Dmitry Levashov
|
|
|
- **/
|
|
|
- protected function cacheDir($path) {
|
|
|
- $this->dirsCache[$path] = array();
|
|
|
-
|
|
|
- $sql = 'SELECT f.id, f.parent_id, f.name, f.size, f.mtime AS ts, f.mime, f.read, f.write, f.locked, f.hidden, f.width, f.height, IF(ch.id, 1, 0) AS dirs
|
|
|
- FROM '.$this->tbf.' AS f
|
|
|
- LEFT JOIN '.$this->tbf.' AS ch ON ch.parent_id=f.id AND ch.mime=\'directory\'
|
|
|
- WHERE f.parent_id=\''.$path.'\'
|
|
|
- GROUP BY f.id, ch.id';
|
|
|
-
|
|
|
- $res = $this->query($sql);
|
|
|
- if ($res) {
|
|
|
- while ($row = $res->fetch_assoc()) {
|
|
|
- $id = $row['id'];
|
|
|
- if ($row['parent_id']) {
|
|
|
- $row['phash'] = $this->encode($row['parent_id']);
|
|
|
- }
|
|
|
-
|
|
|
- if ($row['mime'] == 'directory') {
|
|
|
- unset($row['width']);
|
|
|
- unset($row['height']);
|
|
|
- $row['size'] = 0;
|
|
|
- } else {
|
|
|
- unset($row['dirs']);
|
|
|
- }
|
|
|
-
|
|
|
- unset($row['id']);
|
|
|
- unset($row['parent_id']);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (($stat = $this->updateCache($id, $row)) && empty($stat['hidden'])) {
|
|
|
- $this->dirsCache[$path][] = $id;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $this->dirsCache[$path];
|
|
|
- }
|
|
|
-
|
|
|
- /***************** file stat ********************/
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Open file and return file pointer
|
|
|
*
|
|
|
@@ -543,8 +606,8 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
$fp = $this->tmbPath
|
|
|
? fopen($this->getTempFile($path), 'w+')
|
|
|
: $this->tmpfile();
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
if ($fp) {
|
|
|
if (($res = $this->query('SELECT content FROM '.$this->tbf.' WHERE id=\''.$path.'\''))
|
|
|
&& ($r = $res->fetch_assoc())) {
|
|
|
@@ -555,10 +618,10 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
$this->_fclose($fp, $path);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Close opened file
|
|
|
*
|
|
|
@@ -574,6 +637,8 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /******************** file/dir manipulations *************************/
|
|
|
+
|
|
|
/**
|
|
|
* Create dir and return created dir path or false on failed
|
|
|
*
|
|
|
@@ -586,42 +651,6 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
return $this->make($path, $name, 'directory') ? $this->_joinPath($path, $name) : false;
|
|
|
}
|
|
|
|
|
|
- /******************** file/dir content *********************/
|
|
|
-
|
|
|
- /**
|
|
|
- * Create empty object with required mimetype
|
|
|
- *
|
|
|
- * @param string $path parent dir path
|
|
|
- * @param string $name object name
|
|
|
- * @param string $mime mime type
|
|
|
- * @return bool
|
|
|
- * @author Dmitry (dio) Levashov
|
|
|
- **/
|
|
|
- protected function make($path, $name, $mime) {
|
|
|
- $sql = 'INSERT INTO %s (`parent_id`, `name`, `size`, `mtime`, `mime`, `content`, `read`, `write`, `locked`, `hidden`, `width`, `height`) VALUES (\'%s\', \'%s\', 0, %d, \'%s\', \'\', \'%d\', \'%d\', \'%d\', \'%d\', 0, 0)';
|
|
|
- $sql = sprintf($sql, $this->tbf, $path, $this->db->real_escape_string($name), time(), $mime, $this->defaults['read'], $this->defaults['write'], $this->defaults['locked'], $this->defaults['hidden']);
|
|
|
- // echo $sql;
|
|
|
- return $this->query($sql) && $this->db->affected_rows > 0;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Join dir name and file name and return full path
|
|
|
- *
|
|
|
- * @param string $dir
|
|
|
- * @param string $name
|
|
|
- * @return string
|
|
|
- * @author Dmitry (dio) Levashov
|
|
|
- **/
|
|
|
- protected function _joinPath($dir, $name) {
|
|
|
- $sql = 'SELECT id FROM '.$this->tbf.' WHERE parent_id=\''.$dir.'\' AND name=\''.$this->db->real_escape_string($name).'\'';
|
|
|
-
|
|
|
- if (($res = $this->query($sql)) && ($r = $res->fetch_assoc())) {
|
|
|
- $this->updateCache($r['id'], $this->_stat($r['id']));
|
|
|
- return $r['id'];
|
|
|
- }
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Create file and return it's path or false on failed
|
|
|
*
|
|
|
@@ -633,9 +662,7 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
protected function _mkfile($path, $name) {
|
|
|
return $this->make($path, $name, '') ? $this->_joinPath($path, $name) : false;
|
|
|
}
|
|
|
-
|
|
|
- /******************** file/dir manipulations *************************/
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Create symlink. FTP driver does not support symlinks.
|
|
|
*
|
|
|
@@ -669,17 +696,6 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
return $this->query($sql);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Return parent directory path
|
|
|
- *
|
|
|
- * @param string $path file path
|
|
|
- * @return string
|
|
|
- * @author Dmitry (dio) Levashov
|
|
|
- **/
|
|
|
- protected function _dirname($path) {
|
|
|
- return ($stat = $this->stat($path)) ? (!empty($stat['phash']) ? $this->decode($stat['phash']) : $this->root) : false;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Move file into another parent dir.
|
|
|
* Return new file path or false.
|
|
|
@@ -696,7 +712,7 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
$sql = sprintf($sql, $this->tbf, $targetDir, $this->db->real_escape_string($name), $source);
|
|
|
return $this->query($sql) && $this->db->affected_rows > 0 ? $source : false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Remove file
|
|
|
*
|
|
|
@@ -707,7 +723,7 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
protected function _unlink($path) {
|
|
|
return $this->query(sprintf('DELETE FROM %s WHERE id=%d AND mime!=\'directory\' LIMIT 1', $this->tbf, $path)) && $this->db->affected_rows;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Remove dir
|
|
|
*
|
|
|
@@ -730,10 +746,10 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
elFinder::rewind($fp);
|
|
|
$fstat = fstat($fp);
|
|
|
$size = $fstat['size'];
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Create new file and write into it from file pointer.
|
|
|
* Return new file path or false on error.
|
|
|
@@ -747,16 +763,16 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
**/
|
|
|
protected function _save($fp, $dir, $name, $stat) {
|
|
|
$this->clearcache();
|
|
|
-
|
|
|
+
|
|
|
$mime = $stat['mime'];
|
|
|
$w = !empty($stat['width']) ? $stat['width'] : 0;
|
|
|
$h = !empty($stat['height']) ? $stat['height'] : 0;
|
|
|
-
|
|
|
+
|
|
|
$id = $this->_joinPath($dir, $name);
|
|
|
elFinder::rewind($fp);
|
|
|
$stat = fstat($fp);
|
|
|
$size = $stat['size'];
|
|
|
-
|
|
|
+
|
|
|
if (($tmpfile = tempnam($this->tmpPath, $this->id))) {
|
|
|
if (($trgfp = fopen($tmpfile, 'wb')) == false) {
|
|
|
unlink($tmpfile);
|
|
|
@@ -766,7 +782,7 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
}
|
|
|
fclose($trgfp);
|
|
|
chmod($tmpfile, 0644);
|
|
|
-
|
|
|
+
|
|
|
$sql = $id > 0
|
|
|
? 'REPLACE INTO %s (id, parent_id, name, content, size, mtime, mime, width, height) VALUES ('.$id.', %d, \'%s\', LOAD_FILE(\'%s\'), %d, %d, \'%s\', %d, %d)'
|
|
|
: 'INSERT INTO %s (parent_id, name, content, size, mtime, mime, width, height) VALUES (%d, \'%s\', LOAD_FILE(\'%s\'), %d, %d, \'%s\', %d, %d)';
|
|
|
@@ -774,49 +790,34 @@ class elFinderVolumeMySQL extends elFinderVolumeDriver {
|
|
|
|
|
|
$res = $this->query($sql);
|
|
|
unlink($tmpfile);
|
|
|
-
|
|
|
+
|
|
|
if ($res) {
|
|
|
return $id > 0 ? $id : $this->db->insert_id;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
$content = '';
|
|
|
elFinder::rewind($fp);
|
|
|
while (!feof($fp)) {
|
|
|
$content .= fread($fp, 8192);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$sql = $id > 0
|
|
|
? 'REPLACE INTO %s (id, parent_id, name, content, size, mtime, mime, width, height) VALUES ('.$id.', %d, \'%s\', \'%s\', %d, %d, \'%s\', %d, %d)'
|
|
|
: 'INSERT INTO %s (parent_id, name, content, size, mtime, mime, width, height) VALUES (%d, \'%s\', \'%s\', %d, %d, \'%s\', %d, %d)';
|
|
|
$sql = sprintf($sql, $this->tbf, $dir, $this->db->real_escape_string($name), $this->db->real_escape_string($content), $size, time(), $mime, $w, $h);
|
|
|
-
|
|
|
+
|
|
|
unset($content);
|
|
|
|
|
|
if ($this->query($sql)) {
|
|
|
return $id > 0 ? $id : $this->db->insert_id;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Return correct file path for LOAD_FILE method
|
|
|
- *
|
|
|
- * @param string $path file path (id)
|
|
|
- * @return string
|
|
|
- * @author Troex Nevelin
|
|
|
- **/
|
|
|
- protected function loadFilePath($path) {
|
|
|
- $realPath = realpath($path);
|
|
|
- if (DIRECTORY_SEPARATOR == '\\') { // windows
|
|
|
- $realPath = str_replace('\\', '\\\\', $realPath);
|
|
|
- }
|
|
|
- return $this->db->real_escape_string($realPath);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Get file contents
|
|
|
*
|