Initial setup of sharing app

This commit is contained in:
Michael Gapczynski 2011-06-11 16:14:24 -04:00
parent 016a892a78
commit 8603b0973f
8 changed files with 256 additions and 0 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ CVS/*
RCS/*
.kdev
*.kdev4
.project

View File

@ -0,0 +1,38 @@
<?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/>.
*
*/
require_once('../../lib/base.php');
require_once( 'lib_share.php' );
require( 'template.php' );
if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){
header( "Location: ".OC_HELPER::linkTo( "index.php" ));
exit();
}
OC_APP::setActiveNavigationEntry( "files_sharing_administration" );
$tmpl = new OC_TEMPLATE( "files_sharing", "admin", "admin" );
$tmpl->assign( 'shared_items', OC_SHARE::getSharedItems());
$tmpl->printPage();
?>

View File

@ -0,0 +1,10 @@
<?php
OC_APP::addSettingsPage( array(
"id" => "files_sharing_administration",
"order" => 10,
"href" => OC_HELPER::linkTo( "files_sharing", "admin.php" ),
"name" => "Share",
"icon" => OC_HELPER::imagePath( "files_sharing", "share.png" )));
?>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<database>
<name>*dbname*</name>
<create>true</create>
<overwrite>false</overwrite>
<charset>latin1</charset>
<table>
<name>*dbprefix*sharing</name>
<declaration>
<field>
<name>item</name>
<type>text</type>
<notnull>true</notnull>
<length>128</length>
</field>
<field>
<name>uid_owner</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>uid_shared_with</name>
<type>text</type>
<default>
</default>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>permissions</name>
<type>text</type>
<default>
</default>
<notnull>true</notnull>
<length>3</length>
</field>
</declaration>
</table>
</database>

View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<info>
<id>files_sharing</id>
<name>Share Files</name>
<description>File sharing between users</description>
<version>0.1</version>
<licence>AGPL</licence>
<author>Michael Gapczynski</author>
<require>2</require>
</info>

View File

@ -0,0 +1,99 @@
<?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/>.
*
*/
/**
* This class manages shared items within the database.
*/
class OC_SHARE {
/**
* TODO notify user a file is being shared with them?
* Share an item, adds an entry into the database
* @param string $item
* @param user item shared with $uid_shared_with
*/
public function __construct($item, $public = false, $uid_shared_with) {
if ($item && OC_FILESYSTEM::file_exists($item) && OC_FILESYSTEM::is_readable($item)) {
$uid_owner = $_SESSION['user_id'];
if ($public) {
// TODO create token for public file
$token = sha1("$uid_owner-$item");
} else {
$query = OC_DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?)");
foreach ($uid_shared_with as $uid) {
$query->execute(array($uid_owner, $uid, $item));
}
}
}
}
/**
* TODO complete lib_permissions
* Change the permissions of the specified item
* @param permissions $permissions
*/
public static function setPermissions($item, $uid_shared_with, $permissions) {
$query = OC_DB::prepare("UPDATE *PREFIX*sharing SET permissions = ? WHERE item = ? AND uid_shared_with = ? AND uid_owner = ?");
$query->execute(array($permissions, $item, $uid_shared_with, $_SESSION['user_id']));
}
/**
* Get the permissions for the specified item
* @param unknown_type $item
*/
public static function getPermissions($item, $uid_shared_with) {
$query = OC_DB::prepare("SELECT permissions FROM *PREFIX*sharing WHERE item = ? AND uid_shared_with = ? AND uid_owner = ? ");
return $query->execute(array($item, $uid_shared_with, $_SESSION['user_id']))->fetchAll();
}
/**
* Unshare the item, removes it from all users specified
* @param array $uid_shared_with
*/
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();
}
}
/**
* Get all items the user is sharing
* @return array
*/
public static function getSharedItems() {
$query = OC_DB::prepare("SELECT * FROM *PREFIX*sharing WHERE uid_owner = ?");
return $query->execute(array($_SESSION['user_id']))->fetchAll();
}
/**
* Get all items shared with the user
* @return array
*/
public static function getItemsSharedWith() {
$query = OC_DB::prepare("SELECT * FROM *PREFIX*sharing WHERE uid_shared_with = ?");
return $query->execute(array($_SESSION['user_id']))->fetchAll();
}
}
?>

View File

@ -0,0 +1,28 @@
<?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/>.
*
*/
class OC_FILESTORAGE_SHARE {
}
?>

View File

@ -0,0 +1,29 @@
<?php if ($_['shared_items'] == null) {echo "You are not sharing any of your files";} else {?>
<table id='itemlist'>
<thead>
<tr>
<td class='item'>Item</td>
<td class='uid_shared_with'>Shared With</td>
<td class='link'>Link</td>
</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='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><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><input type='submit' value='Share'/></td>
</form>
</tr>
</tbody>
</table>
<?php } ?>