port sharing by publiclink fully to the 2.0 codebase and provide a simple gui for it

This commit is contained in:
Robin Appelman 2011-06-02 02:45:35 +02:00
parent 6c6871336d
commit 8c5a06028a
15 changed files with 196 additions and 22 deletions

View File

@ -0,0 +1,55 @@
<?php
/**
* ownCloud - ajax frontend
*
* @author Robin Appelman
* @copyright 2010 Robin Appelman icewind1991@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/>.
*
*/
// 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();
?>

View File

@ -0,0 +1,11 @@
<?php
$RUNTIME_NOAPPS=true; //no need to load the apps
require_once '../../../lib/base.php';
require_once '../lib_public.php';
$token=$_GET['token'];
OC_PublicLink::delete($token);
?>

View File

@ -1,12 +1,18 @@
<?php
$RUNTIME_NOAPPS=true; //no need to load the apps
require_once '../../lib/base.php';
require_once '../../../lib/base.php';
require_once 'lib_public.php';
require_once '../lib_public.php';
$path=$_GET['path'];
$expire=(isset($_GET['expire']))?$_GET['expire']:0;
if($expire!==0){
$expire=strtotime($expire);
}
// echo $expire;
// die();
$link=new OC_PublicLink($path,$expire);
echo $link->getToken();

View File

@ -0,0 +1,6 @@
<?php
OC_APP::addSettingsPage( array( "id" => "files_publiclink_administration", "order" => 1, "href" => OC_HELPER::linkTo( "files_publiclink", "admin.php" ), "name" => "Public Links", "icon" => OC_HELPER::imagePath( "files_publiclink", "share.png" )));
?>

View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<info>
<id>files_publiclink</id>
<name>Share by Publiclink</name>
<description>Simple file sharing by creating a public link to a file</description>
<version>0.2</version>
<licence>AGPL</licence>
<author>Robin Appelman</author>
<require>2</require>
</info>

View File

@ -0,0 +1,2 @@
td.path{min-width:200px}
td.expire{width:120px}

View File

@ -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();

View File

@ -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="<tr class='link' id='"+token+"'>";
html+="<td class='path'>"+path+"</td>";
var expire=($('#expire').val())?$('#expire').val():'Never'
html+="<td class='expire'>"+expire+"</td>"
html+="<td class='link'><a href='get.php?token="+token+"'>"+$('#baseUrl').val()+"?token="+token+"</a></td>"
html+="<td><button class='delete fancybutton' data-token='"+token+"'>Delete</button></td>"
html+="</tr>"
$(html).insertBefore($('#newlink_row'));
$('#expire').val('');
$('#expire_time').val('');
$('#path').val('');
}
}
});
})
});

View File

@ -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;
}
?>

View File

@ -0,0 +1,28 @@
<input type='hidden' id='baseUrl' value='<?php echo $_['baseUrl'];?>'/>
<table id='linklist'>
<thead>
<tr>
<td class='path'>Path</td>
<td class='expire'>Expires</td>
<td class='link'>Link</td>
</tr>
</thead>
<tbody>
<?php foreach($_['links'] as $link):?>
<tr class='link' id='<?php echo $link['token'];?>'>
<td class='path'><?php echo $link['path'];?></td>
<td class='expire'><?php echo ($link['expire_time']==0)?'Never':OC_UTIL::formatdate($link['expire_time'],true);?></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>

View File

@ -1,17 +0,0 @@
<?xml version="1.0"?>
<plugin version="1.0">
<info>
<id>publiclink</id>
<name>Simple file sharing by creating a public link to a file</name>
<version>0.1</version>
<licence>AGPL</licence>
<author>Robin Appelman</author>
<require>1.1</require>
</info>
<runtime>
<include>lib_public.php</include>
</runtime>
<install>
<database>db_structure.xml</database>
</install>
</plugin>