From: Robin Appelman Date: Thu, 2 Jun 2011 00:45:35 +0000 (+0200) Subject: port sharing by publiclink fully to the 2.0 codebase and provide a simple gui for it X-Git-Tag: v3.0~267^2~558^2~4 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8c5a06028aa4bf7a29d79d63a713361ce2f50633;p=nextcloud-server.git port sharing by publiclink fully to the 2.0 codebase and provide a simple gui for it --- diff --git a/apps/files_publiclink/admin.php b/apps/files_publiclink/admin.php new file mode 100644 index 00000000000..a48076b4d42 --- /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 00000000000..e2e4ff944a6 --- /dev/null +++ b/apps/files_publiclink/ajax/deletelink.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/apps/files_publiclink/ajax/makelink.php b/apps/files_publiclink/ajax/makelink.php new file mode 100644 index 00000000000..5abd1e829c5 --- /dev/null +++ b/apps/files_publiclink/ajax/makelink.php @@ -0,0 +1,19 @@ +getToken(); +?> \ No newline at end of file diff --git a/apps/files_publiclink/appinfo/app.php b/apps/files_publiclink/appinfo/app.php new file mode 100644 index 00000000000..894327e83d3 --- /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/apps/files_publiclink/appinfo/database.xml b/apps/files_publiclink/appinfo/database.xml new file mode 100644 index 00000000000..de63b03f445 --- /dev/null +++ b/apps/files_publiclink/appinfo/database.xml @@ -0,0 +1,47 @@ + + + *dbname* + true + false + latin1 + + *dbprefix*publiclink + + + token + text + + true + 40 + + + path + text + + true + 128 + + + user + text + + + true + 64 + + + expire_time + timestamp + true + + + token + true + + token + ascending + + + +
+
diff --git a/apps/files_publiclink/appinfo/info.xml b/apps/files_publiclink/appinfo/info.xml new file mode 100644 index 00000000000..1d41ea96662 --- /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 00000000000..f21b289f043 --- /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/apps/files_publiclink/get.php b/apps/files_publiclink/get.php new file mode 100644 index 00000000000..60570ac2249 --- /dev/null +++ b/apps/files_publiclink/get.php @@ -0,0 +1,84 @@ +assign('file',$subPath); + $tmpl->printPage(); + exit; + } + if(OC_FILESYSTEM::is_dir($path)){ + $files = array(); + $rootLength=strlen($root); + foreach( OC_FILES::getdirectorycontent( $path ) as $i ){ + $i['date'] = OC_UTIL::formatDate($i['mtime'] ); + $i['directory']=substr($i['directory'],$rootLength); + if($i['directory']=='/'){ + $i['directory']=''; + } + $files[] = $i; + } + + // Make breadcrumb + $breadcrumb = array(); + $pathtohere = "/"; + foreach( explode( "/", $subPath ) as $i ){ + if( $i != "" ){ + $pathtohere .= "$i/"; + $breadcrumb[] = array( "dir" => $pathtohere, "name" => $i ); + } + } + + $breadcrumbNav = new OC_TEMPLATE( "files_publiclink", "breadcrumb", "" ); + $breadcrumbNav->assign( "breadcrumb", $breadcrumb ); + $breadcrumbNav->assign('token',$token); + + $list = new OC_TEMPLATE( 'files_publiclink', 'files', '' ); + $list->assign( 'files', $files ); + $list->assign('token',$token); + + $tmpl = new OC_TEMPLATE( 'files_publiclink', 'index', 'user' ); + $tmpl->assign('fileList', $list->fetchPage()); + $tmpl->assign( "breadcrumb", $breadcrumbNav->fetchPage() ); + $tmpl->printPage(); + }else{ + //get time mimetype and set the headers + $mimetype=OC_FILESYSTEM::getMimeType($path); + header('Content-Transfer-Encoding: binary'); + header('Content-Disposition: attachment; filename="'.basename($path).'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + header('Content-Type: ' . $mimetype); + header('Content-Length: ' . OC_FILESYSTEM::filesize($path)); + + //download the file + ob_clean(); + OC_FILESYSTEM::readfile($path); + } +}else{ + header("HTTP/1.0 404 Not Found"); + $tmpl = new OC_TEMPLATE( '', '404', 'guest' ); + $tmpl->printPage(); + die(); +} +?> \ No newline at end of file diff --git a/apps/files_publiclink/js/admin.js b/apps/files_publiclink/js/admin.js new file mode 100644 index 00000000000..017c62cb42a --- /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/apps/files_publiclink/lib_public.php b/apps/files_publiclink/lib_public.php new file mode 100644 index 00000000000..aeef9212377 --- /dev/null +++ b/apps/files_publiclink/lib_public.php @@ -0,0 +1,80 @@ +execute(array($token,$path,$user,$expiretime)); + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"
'; + $entry .= 'Offending command was: '.$result->getDebugInfo().'
'; + error_log( $entry ); + die( $entry ); + } + $this->token=$token; + } + } + + /** + * get the path of that shared file + */ + public static function getPath($token){ + //remove expired links + $query=OC_DB::prepare("DELETE FROM *PREFIX*publiclink WHERE expire_time < NOW() AND expire_time!=0"); + $query->execute(); + + //get the path and the user + $query=OC_DB::prepare("SELECT user,path FROM *PREFIX*publiclink WHERE token=?"); + $result=$query->execute(array($token)); + $data=$result->fetchAll(); + if(count($data)>0){ + $path=$data[0]['path']; + $user=$data[0]['user']; + + //prepare the filesystem + OC_UTIL::setupFS($user); + + return $path; + }else{ + return false; + } + } + + /** + * get the token for the public link + * @return string + */ + public function getToken(){ + 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 00000000000..2483eef321a --- /dev/null +++ b/apps/files_publiclink/templates/admin.php @@ -0,0 +1,28 @@ +'/> + + + + + + + + + + + '> + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/files_publiclink/templates/breadcrumb.php b/apps/files_publiclink/templates/breadcrumb.php new file mode 100644 index 00000000000..3f4ae863ee0 --- /dev/null +++ b/apps/files_publiclink/templates/breadcrumb.php @@ -0,0 +1,4 @@ + " alt="Root" /> + + "> + \ No newline at end of file diff --git a/apps/files_publiclink/templates/files.php b/apps/files_publiclink/templates/files.php new file mode 100644 index 00000000000..6473ad4c5c8 --- /dev/null +++ b/apps/files_publiclink/templates/files.php @@ -0,0 +1,9 @@ + + + + )" href="" title=""> + + + + + + \ No newline at end of file diff --git a/apps/files_publiclink/templates/index.php b/apps/files_publiclink/templates/index.php new file mode 100644 index 00000000000..9e238452603 --- /dev/null +++ b/apps/files_publiclink/templates/index.php @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + +
NameSizeModified
\ No newline at end of file diff --git a/plugins/publiclink/db_structure.xml b/plugins/publiclink/db_structure.xml deleted file mode 100644 index de63b03f445..00000000000 --- a/plugins/publiclink/db_structure.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - *dbname* - true - false - latin1 - - *dbprefix*publiclink - - - token - text - - true - 40 - - - path - text - - true - 128 - - - user - text - - - true - 64 - - - expire_time - timestamp - true - - - token - true - - token - ascending - - - -
-
diff --git a/plugins/publiclink/get.php b/plugins/publiclink/get.php deleted file mode 100644 index 41b10484f9b..00000000000 --- a/plugins/publiclink/get.php +++ /dev/null @@ -1,84 +0,0 @@ -assign('file',$subPath); - $tmpl->printPage(); - exit; - } - if(OC_FILESYSTEM::is_dir($path)){ - $files = array(); - $rootLength=strlen($root); - foreach( OC_FILES::getdirectorycontent( $path ) as $i ){ - $i['date'] = OC_UTIL::formatDate($i['mtime'] ); - $i['directory']=substr($i['directory'],$rootLength); - if($i['directory']=='/'){ - $i['directory']=''; - } - $files[] = $i; - } - - // Make breadcrumb - $breadcrumb = array(); - $pathtohere = "/"; - foreach( explode( "/", $subPath ) as $i ){ - if( $i != "" ){ - $pathtohere .= "$i/"; - $breadcrumb[] = array( "dir" => $pathtohere, "name" => $i ); - } - } - - $breadcrumbNav = new OC_TEMPLATE( "plugins/publiclink", "breadcrumb", "" ); - $breadcrumbNav->assign( "breadcrumb", $breadcrumb ); - $breadcrumbNav->assign('token',$token); - - $list = new OC_TEMPLATE( 'plugins/publiclink', 'files', '' ); - $list->assign( 'files', $files ); - $list->assign('token',$token); - - $tmpl = new OC_TEMPLATE( 'plugins/publiclink', 'index', 'user' ); - $tmpl->assign('fileList', $list->fetchPage()); - $tmpl->assign( "breadcrumb", $breadcrumbNav->fetchPage() ); - $tmpl->printPage(); - }else{ - //get time mimetype and set the headers - $mimetype=OC_FILESYSTEM::getMimeType($path); - header('Content-Transfer-Encoding: binary'); - header('Content-Disposition: attachment; filename="'.basename($path).'"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - header('Content-Type: ' . $mimetype); - header('Content-Length: ' . OC_FILESYSTEM::filesize($path)); - - //download the file - ob_clean(); - OC_FILESYSTEM::readfile($path); - } -}else{ - header("HTTP/1.0 404 Not Found"); - $tmpl = new OC_TEMPLATE( '', '404', 'guest' ); - $tmpl->printPage(); - die(); -} -?> \ No newline at end of file diff --git a/plugins/publiclink/lib_public.php b/plugins/publiclink/lib_public.php deleted file mode 100644 index 20b538d3ac9..00000000000 --- a/plugins/publiclink/lib_public.php +++ /dev/null @@ -1,59 +0,0 @@ -execute(array($token,$path,$user,$expiretime)); - if( PEAR::isError($result)) { - $entry = 'DB Error: "'.$result->getMessage().'"
'; - $entry .= 'Offending command was: '.$result->getDebugInfo().'
'; - error_log( $entry ); - die( $entry ); - } - $this->token=$token; - } - } - - /** - * get the path of that shared file - */ - public static function getPath($token){ - //remove expired links - $query=OC_DB::prepare("DELETE FROM *PREFIX*publiclink WHERE expire_time < NOW() AND expire_time!=0"); - $query->execute(); - - //get the path and the user - $query=OC_DB::prepare("SELECT user,path FROM *PREFIX*publiclink WHERE token=?"); - $result=$query->execute(array($token)); - $data=$result->fetchAll(); - if(count($data)>0){ - $path=$data[0]['path']; - $user=$data[0]['user']; - - //prepare the filesystem - OC_UTIL::setupFS($user); - - return $path; - }else{ - return false; - } - } - - /** - * get the token for the public link - * @return string - */ - public function getToken(){ - return $this->token; - } - - private $token; -} -?> \ No newline at end of file diff --git a/plugins/publiclink/makelink.php b/plugins/publiclink/makelink.php deleted file mode 100644 index 1de65e7ec6f..00000000000 --- a/plugins/publiclink/makelink.php +++ /dev/null @@ -1,13 +0,0 @@ -getToken(); -?> \ No newline at end of file diff --git a/plugins/publiclink/plugin.xml b/plugins/publiclink/plugin.xml deleted file mode 100644 index 75abed6cf08..00000000000 --- 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 - - diff --git a/plugins/publiclink/templates/breadcrumb.php b/plugins/publiclink/templates/breadcrumb.php deleted file mode 100644 index 3f4ae863ee0..00000000000 --- a/plugins/publiclink/templates/breadcrumb.php +++ /dev/null @@ -1,4 +0,0 @@ - " alt="Root" /> - - "> - \ No newline at end of file diff --git a/plugins/publiclink/templates/files.php b/plugins/publiclink/templates/files.php deleted file mode 100644 index 6473ad4c5c8..00000000000 --- a/plugins/publiclink/templates/files.php +++ /dev/null @@ -1,9 +0,0 @@ - - - - )" href="" title=""> - - - + - - \ No newline at end of file diff --git a/plugins/publiclink/templates/index.php b/plugins/publiclink/templates/index.php deleted file mode 100644 index 9e238452603..00000000000 --- a/plugins/publiclink/templates/index.php +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - -
NameSizeModified
\ No newline at end of file