summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--apps/files_sharing/admin.php38
-rw-r--r--apps/files_sharing/appinfo/app.php10
-rw-r--r--apps/files_sharing/appinfo/database.xml41
-rw-r--r--apps/files_sharing/appinfo/info.xml10
-rw-r--r--apps/files_sharing/lib_share.php99
-rw-r--r--apps/files_sharing/sharedstorage.php28
-rw-r--r--apps/files_sharing/templates/admin.php29
8 files changed, 256 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 9cfb7a5861e..fd29bd8c1d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,4 @@ CVS/*
RCS/*
.kdev
*.kdev4
+.project \ No newline at end of file
diff --git a/apps/files_sharing/admin.php b/apps/files_sharing/admin.php
new file mode 100644
index 00000000000..8d668c8329f
--- /dev/null
+++ b/apps/files_sharing/admin.php
@@ -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();
+
+?> \ No newline at end of file
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
new file mode 100644
index 00000000000..359e26b16f1
--- /dev/null
+++ b/apps/files_sharing/appinfo/app.php
@@ -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" )));
+
+?> \ No newline at end of file
diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml
new file mode 100644
index 00000000000..fa56dbe803d
--- /dev/null
+++ b/apps/files_sharing/appinfo/database.xml
@@ -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>
diff --git a/apps/files_sharing/appinfo/info.xml b/apps/files_sharing/appinfo/info.xml
new file mode 100644
index 00000000000..2fbb3300f69
--- /dev/null
+++ b/apps/files_sharing/appinfo/info.xml
@@ -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> \ No newline at end of file
diff --git a/apps/files_sharing/lib_share.php b/apps/files_sharing/lib_share.php
new file mode 100644
index 00000000000..c53059b2ec8
--- /dev/null
+++ b/apps/files_sharing/lib_share.php
@@ -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();
+ }
+
+}
+
+?>
diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
new file mode 100644
index 00000000000..25824f2779d
--- /dev/null
+++ b/apps/files_sharing/sharedstorage.php
@@ -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 {
+
+
+}
+
+?> \ No newline at end of file
diff --git a/apps/files_sharing/templates/admin.php b/apps/files_sharing/templates/admin.php
new file mode 100644
index 00000000000..764aee00b49
--- /dev/null
+++ b/apps/files_sharing/templates/admin.php
@@ -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 } ?> \ No newline at end of file