First version of shared storage provider - not functional
This commit is contained in:
parent
8603b0973f
commit
bf66563cda
|
@ -24,7 +24,7 @@ require_once('../../lib/base.php');
|
|||
require_once( 'lib_share.php' );
|
||||
require( 'template.php' );
|
||||
|
||||
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
|
||||
if (!OC_USER::isLoggedIn()){
|
||||
header( "Location: ".OC_HELPER::linkTo( "index.php" ));
|
||||
exit();
|
||||
}
|
||||
|
|
|
@ -72,10 +72,20 @@ class OC_SHARE {
|
|||
public static function unshare($item, $uid_shared_with) {
|
||||
$query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE item = ? AND uid_shared_with = ? AND uid_owner = ?");
|
||||
foreach ($uid_shared_with as $uid) {
|
||||
$query->execute(array($item, $uid, $_SESSION['user_id']))->fetchAll();
|
||||
$query->execute(array($item, $uid, $_SESSION['user_id']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source location of the target item
|
||||
* @return source path
|
||||
*/
|
||||
public static function getSource($target) {
|
||||
$query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?");
|
||||
$result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll();
|
||||
return $result[0]['source'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all items the user is sharing
|
||||
* @return array
|
||||
|
|
|
@ -20,8 +20,273 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class OC_FILESTORAGE_SHARE {
|
||||
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) {
|
||||
|
||||
}
|
||||
|
||||
// TODO OC_SHARE::getPermissions()
|
||||
public function mkdir($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->mkdir(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO OC_SHARE::getPermissions()
|
||||
public function rmdir($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->is_file(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function opendir($path) {
|
||||
//$source = OC_SHARE::getSource($path);
|
||||
//if ($source) {
|
||||
//$storage = OC_FILESYSTEM::getStorage($source);
|
||||
//return $storage->opendir(OC_FILESYSTEM::getInternalPath($source));
|
||||
//}
|
||||
global $FAKEDIRS;
|
||||
$FAKEDIRS['shared'] = array(0 => 'test.txt');
|
||||
return opendir('fakedir://shared');
|
||||
}
|
||||
|
||||
public function is_dir($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->is_dir(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function is_file($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->is_file(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
public function stat($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->stat(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function filetype($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->filetype(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function filesize($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->filesize(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO OC_SHARE::getPermissions()
|
||||
public function is_readable($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->is_readable(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO OC_SHARE::getPermissions()
|
||||
public function is_writeable($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->is_writeable(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function file_exists($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->file_exists(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function readfile($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->readfile(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function filectime($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->filectime(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function filemtime($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->filemtime(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function fileatime($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->fileatime(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function file_get_contents($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->file_get_contents(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO OC_SHARE::getPermissions()
|
||||
public function file_put_contents($path, $data) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->file_put_contents(OC_FILESYSTEM::getInternalPath($source), $data);
|
||||
}
|
||||
}
|
||||
|
||||
public function unlink($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->unlink(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
return $storage->rename(OC_FILESYSTEM::getInternalPath($source), $path2);
|
||||
}
|
||||
}
|
||||
|
||||
public function copy($path1, $path2) {
|
||||
$source = OC_SHARE::getSource($path1);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->copy(OC_FILESYSTEM::getInternalPath($source), $path2);
|
||||
}
|
||||
}
|
||||
|
||||
public function fopen($path, $mode) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->fopen(OC_FILESYSTEM::getInternalPath($source), $mode);
|
||||
}
|
||||
}
|
||||
|
||||
public function toTmpFile($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->toTmpFile(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function fromTmpFile($tmpPath, $path) {
|
||||
$source = OC_SHARE::getSource($tmpPath);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->fromTmpFile(OC_FILESYSTEM::getInternalPath($source), $path);
|
||||
}
|
||||
}
|
||||
|
||||
public function fromUploadedFile($tmpPath, $path) {
|
||||
$source = OC_SHARE::getSource($tmpPath);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->fromUploadedFile(OC_FILESYSTEM::getInternalPath($source), $path);
|
||||
}
|
||||
}
|
||||
|
||||
public function getMimeType($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->getMimeType(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function delTree($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->delTree(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function find($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->find(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function getTree($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->getTree(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
public function hash($type, $path, $raw) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->hash($type, OC_FILESYSTEM::getInternalPath($source), $raw);
|
||||
}
|
||||
}
|
||||
|
||||
public function free_space($path) {
|
||||
$source = OC_SHARE::getSource($path);
|
||||
if ($source) {
|
||||
$storage = OC_FILESYSTEM::getStorage($source);
|
||||
return $storage->free_space(OC_FILESYSTEM::getInternalPath($source));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO query all shared files?
|
||||
public function search($query) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,25 +2,26 @@
|
|||
<table id='itemlist'>
|
||||
<thead>
|
||||
<tr>
|
||||
<td class='item'>Item</td>
|
||||
<td class='uid_shared_with'>Shared With</td>
|
||||
<td class='link'>Link</td>
|
||||
<th>Item</th>
|
||||
<th>Shared With</th>
|
||||
<th>Permissions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($_['shared_items'] as $item):?>
|
||||
<tr class='link' id='<?php echo $item['id'];?>'>
|
||||
<td class='item'><?php echo $link['item'];?></td>
|
||||
<td class='item'><?php echo $item['item'];?></td>
|
||||
<td class='uid_shared_with'><?php echo $item['uid_shared_with'];?></td>
|
||||
<td class='link'><a href='get.php?token=<?php echo $link['token'];?>'><?php echo $_['baseUrl'];?>?token=<?php echo $link['token'];?></a></td>
|
||||
<td class='permissions'><?php echo $item['permissions'];?></td>
|
||||
<td><button class='delete fancybutton' data-token='<?php echo $link['token'];?>'>Delete</button></td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
<tr id='newlink_row'>
|
||||
<form action='#' id='newlink'>
|
||||
<input type='hidden' id='expire_time'/>
|
||||
<td class='path'><input placeholder='Path' id='path'/></td>
|
||||
<td class='expire'><input placeholder='Expires' id='expire'/></td>
|
||||
<td class='path'><input placeholder='Item' id='path'/></td>
|
||||
<td class='expire'><input placeholder='Share With' id='expire'/></td>
|
||||
<td class='permissions'><input placeholder='Permissions' id='expire'/></td>
|
||||
<td><input type='submit' value='Share'/></td>
|
||||
</form>
|
||||
</tr>
|
||||
|
|
|
@ -80,6 +80,7 @@ require_once('appconfig.php');
|
|||
require_once('files.php');
|
||||
require_once('filesystem.php');
|
||||
require_once('filestorage.php');
|
||||
require_once('apps/files_sharing/sharedstorage.php');
|
||||
require_once('log.php');
|
||||
require_once('user.php');
|
||||
require_once('group.php');
|
||||
|
@ -157,6 +158,9 @@ class OC_UTIL {
|
|||
// }
|
||||
OC_FILESYSTEM::mount($rootStorage,'/');
|
||||
|
||||
$sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>$CONFIG_DATADIRECTORY));
|
||||
OC_FILESYSTEM::mount($sharedStorage,'MTGap/files/Test/');
|
||||
|
||||
$CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root";
|
||||
if( !is_dir( $CONFIG_DATADIRECTORY )){
|
||||
mkdir( $CONFIG_DATADIRECTORY, 0755, true );
|
||||
|
|
|
@ -155,7 +155,7 @@ class OC_FILESYSTEM{
|
|||
* @param string path
|
||||
* @return OC_FILESTORAGE
|
||||
*/
|
||||
static private function getStorage($path){
|
||||
static public function getStorage($path){
|
||||
$mountpoint=self::getMountPoint($path);
|
||||
if($mountpoint){
|
||||
return self::$storages[$mountpoint];
|
||||
|
|
Loading…
Reference in New Issue