From 8c5a06028aa4bf7a29d79d63a713361ce2f50633 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 2 Jun 2011 02:45:35 +0200 Subject: [PATCH] port sharing by publiclink fully to the 2.0 codebase and provide a simple gui for it --- apps/files_publiclink/admin.php | 55 +++++++++++++++++++ apps/files_publiclink/ajax/deletelink.php | 11 ++++ .../files_publiclink/ajax}/makelink.php | 10 +++- apps/files_publiclink/appinfo/app.php | 6 ++ .../files_publiclink/appinfo/database.xml | 0 apps/files_publiclink/appinfo/info.xml | 10 ++++ apps/files_publiclink/css/admin.css | 2 + .../files_publiclink}/get.php | 6 +- apps/files_publiclink/js/admin.js | 52 ++++++++++++++++++ .../files_publiclink}/lib_public.php | 21 +++++++ apps/files_publiclink/templates/admin.php | 28 ++++++++++ .../templates/breadcrumb.php | 0 .../files_publiclink}/templates/files.php | 0 .../files_publiclink}/templates/index.php | 0 plugins/publiclink/plugin.xml | 17 ------ 15 files changed, 196 insertions(+), 22 deletions(-) create mode 100644 apps/files_publiclink/admin.php create mode 100644 apps/files_publiclink/ajax/deletelink.php rename {plugins/publiclink => apps/files_publiclink/ajax}/makelink.php (56%) create mode 100644 apps/files_publiclink/appinfo/app.php rename plugins/publiclink/db_structure.xml => apps/files_publiclink/appinfo/database.xml (100%) create mode 100644 apps/files_publiclink/appinfo/info.xml create mode 100644 apps/files_publiclink/css/admin.css rename {plugins/publiclink => apps/files_publiclink}/get.php (91%) create mode 100644 apps/files_publiclink/js/admin.js rename {plugins/publiclink => apps/files_publiclink}/lib_public.php (70%) create mode 100644 apps/files_publiclink/templates/admin.php rename {plugins/publiclink => apps/files_publiclink}/templates/breadcrumb.php (100%) rename {plugins/publiclink => apps/files_publiclink}/templates/files.php (100%) rename {plugins/publiclink => apps/files_publiclink}/templates/index.php (100%) delete mode 100644 plugins/publiclink/plugin.xml diff --git a/apps/files_publiclink/admin.php b/apps/files_publiclink/admin.php new file mode 100644 index 0000000000..a48076b4d4 --- /dev/null +++ b/apps/files_publiclink/admin.php @@ -0,0 +1,55 @@ +. +* +*/ + + +// Init owncloud +require_once('../../lib/base.php'); +require_once( 'lib_public.php' ); +require( 'template.php' ); + + +// Check if we are a user +if( !OC_USER::isLoggedIn() || !OC_GROUP::inGroup( $_SESSION['user_id'], 'admin' )){ + header( "Location: ".OC_HELPER::linkTo( "index.php" )); + exit(); +} + +OC_APP::setActiveNavigationEntry( "files_publiclink_administration" ); + +OC_UTIL::addStyle( 'files_publiclink', 'admin' ); +OC_UTIL::addScript( 'files_publiclink', 'admin' ); + +if(isset($_SERVER['HTTPS'])) { + $baseUrl= "https://". $_SERVER['SERVER_NAME'] . OC_HELPER::linkTo('files_publiclink','get.php'); +}else{ + $baseUrl= "http://". $_SERVER['SERVER_NAME'] . OC_HELPER::linkTo('files_publiclink','get.php'); +} + + +// return template +$tmpl = new OC_TEMPLATE( "files_publiclink", "admin", "admin" ); +$tmpl->assign( 'links', OC_PublicLink::getLinks()); +$tmpl->assign('baseUrl',$baseUrl); +$tmpl->printPage(); + +?> diff --git a/apps/files_publiclink/ajax/deletelink.php b/apps/files_publiclink/ajax/deletelink.php new file mode 100644 index 0000000000..e2e4ff944a --- /dev/null +++ b/apps/files_publiclink/ajax/deletelink.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/plugins/publiclink/makelink.php b/apps/files_publiclink/ajax/makelink.php similarity index 56% rename from plugins/publiclink/makelink.php rename to apps/files_publiclink/ajax/makelink.php index 1de65e7ec6..5abd1e829c 100644 --- a/plugins/publiclink/makelink.php +++ b/apps/files_publiclink/ajax/makelink.php @@ -1,12 +1,18 @@ getToken(); diff --git a/apps/files_publiclink/appinfo/app.php b/apps/files_publiclink/appinfo/app.php new file mode 100644 index 0000000000..894327e83d --- /dev/null +++ b/apps/files_publiclink/appinfo/app.php @@ -0,0 +1,6 @@ + "files_publiclink_administration", "order" => 1, "href" => OC_HELPER::linkTo( "files_publiclink", "admin.php" ), "name" => "Public Links", "icon" => OC_HELPER::imagePath( "files_publiclink", "share.png" ))); + + +?> diff --git a/plugins/publiclink/db_structure.xml b/apps/files_publiclink/appinfo/database.xml similarity index 100% rename from plugins/publiclink/db_structure.xml rename to apps/files_publiclink/appinfo/database.xml diff --git a/apps/files_publiclink/appinfo/info.xml b/apps/files_publiclink/appinfo/info.xml new file mode 100644 index 0000000000..1d41ea9666 --- /dev/null +++ b/apps/files_publiclink/appinfo/info.xml @@ -0,0 +1,10 @@ + + + files_publiclink + Share by Publiclink + Simple file sharing by creating a public link to a file + 0.2 + AGPL + Robin Appelman + 2 + \ No newline at end of file diff --git a/apps/files_publiclink/css/admin.css b/apps/files_publiclink/css/admin.css new file mode 100644 index 0000000000..f21b289f04 --- /dev/null +++ b/apps/files_publiclink/css/admin.css @@ -0,0 +1,2 @@ +td.path{min-width:200px} +td.expire{width:120px} \ No newline at end of file diff --git a/plugins/publiclink/get.php b/apps/files_publiclink/get.php similarity index 91% rename from plugins/publiclink/get.php rename to apps/files_publiclink/get.php index 41b10484f9..60570ac224 100644 --- a/plugins/publiclink/get.php +++ b/apps/files_publiclink/get.php @@ -48,15 +48,15 @@ if($path!==false){ } } - $breadcrumbNav = new OC_TEMPLATE( "plugins/publiclink", "breadcrumb", "" ); + $breadcrumbNav = new OC_TEMPLATE( "files_publiclink", "breadcrumb", "" ); $breadcrumbNav->assign( "breadcrumb", $breadcrumb ); $breadcrumbNav->assign('token',$token); - $list = new OC_TEMPLATE( 'plugins/publiclink', 'files', '' ); + $list = new OC_TEMPLATE( 'files_publiclink', 'files', '' ); $list->assign( 'files', $files ); $list->assign('token',$token); - $tmpl = new OC_TEMPLATE( 'plugins/publiclink', 'index', 'user' ); + $tmpl = new OC_TEMPLATE( 'files_publiclink', 'index', 'user' ); $tmpl->assign('fileList', $list->fetchPage()); $tmpl->assign( "breadcrumb", $breadcrumbNav->fetchPage() ); $tmpl->printPage(); diff --git a/apps/files_publiclink/js/admin.js b/apps/files_publiclink/js/admin.js new file mode 100644 index 0000000000..017c62cb42 --- /dev/null +++ b/apps/files_publiclink/js/admin.js @@ -0,0 +1,52 @@ +$(document).ready(function() { + $( "#expire" ).datepicker({ + dateFormat:'MM d, yy', + altField: "#expire_time", + altFormat: "yy-mm-dd" + }); + $( "#path" ).autocomplete({ + source: "../../files/ajax/autocomplete.php", + minLength: 1 + }); + $("button.delete").live('click', function() { + event.preventDefault(); + var token=$(this).attr('data-token'); + var data="token="+token; + $.ajax({ + type: 'GET', + url: 'ajax/deletelink.php', + cache: false, + data: data, + success: function(){ + $('#'+token).remove(); + } + }); + }); + $('#newlink').submit(function(){ + event.preventDefault(); + var path=$('#path').val(); + var expire=$('#expire_time').val()||0; + var data='path='+path+'&expire='+expire; + $.ajax({ + type: 'GET', + url: 'ajax/makelink.php', + cache: false, + data: data, + success: function(token){ + if(token){ + var html=""; + html+=""+path+""; + var expire=($('#expire').val())?$('#expire').val():'Never' + html+=""+expire+"" + html+=""+$('#baseUrl').val()+"?token="+token+"" + html+="" + html+="" + $(html).insertBefore($('#newlink_row')); + $('#expire').val(''); + $('#expire_time').val(''); + $('#path').val(''); + } + } + }); + }) +}); \ No newline at end of file diff --git a/plugins/publiclink/lib_public.php b/apps/files_publiclink/lib_public.php similarity index 70% rename from plugins/publiclink/lib_public.php rename to apps/files_publiclink/lib_public.php index 20b538d3ac..aeef921237 100644 --- a/plugins/publiclink/lib_public.php +++ b/apps/files_publiclink/lib_public.php @@ -54,6 +54,27 @@ class OC_PublicLink{ return $this->token; } + /** + * gets all public links + * @return array + */ + static public function getLinks(){ + $query=OC_DB::prepare("SELECT * FROM *PREFIX*publiclink WHERE user=?"); + return $query->execute(array($_SESSION['user_id']))->fetchAll(); + } + + /** + * delete a public link + */ + static public function delete($token){ + $query=OC_DB::prepare("SELECT user,path FROM *PREFIX*publiclink WHERE token=?"); + $result=$query->execute(array($token))->fetchAll(); + if(count($result)>0 and $result[0]['user']==$_SESSION['user_id']){ + $query=OC_DB::prepare("DELETE FROM *PREFIX*publiclink WHERE token=?"); + $query->execute(array($token)); + } + } + private $token; } ?> \ No newline at end of file diff --git a/apps/files_publiclink/templates/admin.php b/apps/files_publiclink/templates/admin.php new file mode 100644 index 0000000000..2483eef321 --- /dev/null +++ b/apps/files_publiclink/templates/admin.php @@ -0,0 +1,28 @@ +'/> + + + + + + + + + + + '> + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/publiclink/templates/breadcrumb.php b/apps/files_publiclink/templates/breadcrumb.php similarity index 100% rename from plugins/publiclink/templates/breadcrumb.php rename to apps/files_publiclink/templates/breadcrumb.php diff --git a/plugins/publiclink/templates/files.php b/apps/files_publiclink/templates/files.php similarity index 100% rename from plugins/publiclink/templates/files.php rename to apps/files_publiclink/templates/files.php diff --git a/plugins/publiclink/templates/index.php b/apps/files_publiclink/templates/index.php similarity index 100% rename from plugins/publiclink/templates/index.php rename to apps/files_publiclink/templates/index.php diff --git a/plugins/publiclink/plugin.xml b/plugins/publiclink/plugin.xml deleted file mode 100644 index 75abed6cf0..0000000000 --- a/plugins/publiclink/plugin.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - publiclink - Simple file sharing by creating a public link to a file - 0.1 - AGPL - Robin Appelman - 1.1 - - - lib_public.php - - - db_structure.xml - -