2011-06-11 20:14:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Michael Gapczynski
|
|
|
|
* @copyright 2011 Michael Gapczynski GapczynskiM@gmail.com
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-06-16 18:40:21 +00:00
|
|
|
require_once( 'lib_share.php' );
|
|
|
|
|
|
|
|
OC_FILESYSTEM::registerStorageType('shared','OC_FILESTORAGE_SHARED',array('datadir'=>'string'));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert target path to source path and pass the function call to the correct storage provider
|
|
|
|
*/
|
|
|
|
class OC_FILESTORAGE_SHARED {
|
|
|
|
|
|
|
|
// TODO uh... I don't know what to do here
|
|
|
|
public function __construct($parameters) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-06-22 23:47:57 +00:00
|
|
|
public function getInternalPath($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
$mountPoint = OC_FILESYSTEM::getMountPoint($path);
|
|
|
|
$internalPath = substr($path,strlen($mountPoint));
|
|
|
|
return $internalPath;
|
|
|
|
}
|
|
|
|
|
2011-06-16 18:40:21 +00:00
|
|
|
// TODO OC_SHARE::getPermissions()
|
|
|
|
public function mkdir($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->mkdir($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO OC_SHARE::getPermissions()
|
|
|
|
public function rmdir($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->rmdir($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-22 15:40:09 +00:00
|
|
|
// TODO add all files from db in array
|
2011-06-16 18:40:21 +00:00
|
|
|
public function opendir($path) {
|
|
|
|
global $FAKEDIRS;
|
2011-06-22 15:40:09 +00:00
|
|
|
$sharedItems = OC_SHARE::getItemsSharedWith();
|
|
|
|
foreach ($sharedItems as $item) {
|
|
|
|
$files[] = $item['target'];
|
|
|
|
}
|
|
|
|
$FAKEDIRS['shared'] = $files;
|
2011-06-16 18:40:21 +00:00
|
|
|
return opendir('fakedir://shared');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function is_dir($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->is_dir($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function is_file($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->is_file($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-22 15:40:09 +00:00
|
|
|
|
|
|
|
// TODO fill in other components of array
|
2011-06-16 18:40:21 +00:00
|
|
|
public function stat($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
$stat["dev"] = "";
|
|
|
|
$stat["ino"] = "";
|
|
|
|
$stat["mode"] = "";
|
|
|
|
$stat["nlink"] = "";
|
|
|
|
$stat["uid"] = "";
|
|
|
|
$stat["gid"] = "";
|
|
|
|
$stat["rdev"] = "";
|
2011-06-22 23:47:57 +00:00
|
|
|
$stat["size"] = $this->filesize($path);
|
|
|
|
$stat["atime"] = $this->fileatime($path);
|
|
|
|
$stat["mtime"] = $this->filemtime($path);
|
|
|
|
$stat["ctime"] = $this->filectime($path);
|
2011-06-18 17:29:16 +00:00
|
|
|
$stat["blksize"] = "";
|
|
|
|
$stat["blocks"] = "";
|
|
|
|
return $stat;
|
|
|
|
} else {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->stat($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filetype($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-06-22 15:40:09 +00:00
|
|
|
return "dir";
|
2011-06-18 17:29:16 +00:00
|
|
|
} else {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->filetype($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
2011-06-18 17:29:16 +00:00
|
|
|
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function filesize($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-06-22 21:55:07 +00:00
|
|
|
$size = 0;
|
2011-06-22 23:47:57 +00:00
|
|
|
$dir = $this->opendir($path);
|
2011-06-22 21:55:07 +00:00
|
|
|
while (($filename = readdir($dir)) != false) {
|
2011-06-22 23:47:57 +00:00
|
|
|
$size += $this->filesize($filename);
|
2011-06-22 21:55:07 +00:00
|
|
|
}
|
|
|
|
return $size;
|
2011-06-18 17:29:16 +00:00
|
|
|
} else {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->filesize($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO OC_SHARE::getPermissions()
|
|
|
|
public function is_readable($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->is_readable($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO OC_SHARE::getPermissions()
|
|
|
|
public function is_writeable($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->is_writeable($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function file_exists($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->file_exists($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function readfile($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->readfile($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filectime($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-06-22 22:16:41 +00:00
|
|
|
$ctime = 0;
|
2011-06-22 23:47:57 +00:00
|
|
|
$dir = $this->opendir($path);
|
2011-06-22 22:16:41 +00:00
|
|
|
while (($filename = readdir($dir)) != false) {
|
2011-06-22 23:47:57 +00:00
|
|
|
$tempctime = $this->filectime($filename);
|
2011-06-22 23:17:31 +00:00
|
|
|
if ($tempctime < $ctime) {
|
2011-06-22 22:16:41 +00:00
|
|
|
$ctime = $tempctime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ctime;
|
2011-06-18 17:29:16 +00:00
|
|
|
} else {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->filectime($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filemtime($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-06-22 22:16:41 +00:00
|
|
|
$mtime = 0;
|
2011-06-22 23:47:57 +00:00
|
|
|
$dir = $this->opendir($path);
|
2011-06-22 22:16:41 +00:00
|
|
|
while (($filename = readdir($dir)) != false) {
|
2011-06-22 23:47:57 +00:00
|
|
|
$tempmtime = $this->filemtime($filename);
|
2011-06-22 22:16:41 +00:00
|
|
|
if ($tempmtime > $mtime) {
|
|
|
|
$mtime = $tempmtime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $mtime;
|
2011-06-18 17:29:16 +00:00
|
|
|
} else {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->filemtime($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fileatime($path) {
|
2011-06-18 17:29:16 +00:00
|
|
|
if ($path == "" || $path == "/") {
|
2011-06-22 22:16:41 +00:00
|
|
|
$atime = 0;
|
2011-06-22 23:47:57 +00:00
|
|
|
$dir = $this->opendir($path);
|
2011-06-22 22:16:41 +00:00
|
|
|
while (($filename = readdir($dir)) != false) {
|
2011-06-22 23:47:57 +00:00
|
|
|
$tempatime = $this->fileatime($filename);
|
2011-06-22 22:16:41 +00:00
|
|
|
if ($tempatime > $atime) {
|
|
|
|
$atime = $tempatime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $atime;
|
2011-06-18 17:29:16 +00:00
|
|
|
} else {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->fileatime($this->getInternalPath($source));
|
2011-06-18 17:29:16 +00:00
|
|
|
}
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function file_get_contents($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->file_get_contents($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO OC_SHARE::getPermissions()
|
|
|
|
public function file_put_contents($path, $data) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->file_put_contents($this->getInternalPath($source), $data);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unlink($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->unlink($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO OC_SHARE::getPermissions()
|
|
|
|
// TODO Update shared item location
|
|
|
|
public function rename($path1, $path2) {
|
|
|
|
$source = OC_SHARE::getSource($path1);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->rename($this->getInternalPath($source), $path2);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function copy($path1, $path2) {
|
|
|
|
$source = OC_SHARE::getSource($path1);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->copy($this->getInternalPath($source), $path2);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fopen($path, $mode) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->fopen($this->getInternalPath($source), $mode);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toTmpFile($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->toTmpFile($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fromTmpFile($tmpPath, $path) {
|
|
|
|
$source = OC_SHARE::getSource($tmpPath);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->fromTmpFile($this->getInternalPath($source), $path);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fromUploadedFile($tmpPath, $path) {
|
|
|
|
$source = OC_SHARE::getSource($tmpPath);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->fromUploadedFile($this->getInternalPath($source), $path);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMimeType($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->getMimeType($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delTree($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->delTree($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function find($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->find($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTree($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->getTree($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hash($type, $path, $raw) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->hash($type, $this->getInternalPath($source), $raw);
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function free_space($path) {
|
|
|
|
$source = OC_SHARE::getSource($path);
|
|
|
|
if ($source) {
|
|
|
|
$storage = OC_FILESYSTEM::getStorage($source);
|
2011-06-22 23:47:57 +00:00
|
|
|
return $storage->free_space($this->getInternalPath($source));
|
2011-06-16 18:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-11 20:14:24 +00:00
|
|
|
|
2011-06-16 18:40:21 +00:00
|
|
|
// TODO query all shared files?
|
|
|
|
public function search($query) {
|
|
|
|
|
|
|
|
}
|
2011-06-11 20:14:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|