2011-04-16 10:35:21 +00:00
|
|
|
<?php
|
|
|
|
class OC_PublicLink{
|
|
|
|
/**
|
|
|
|
* create a new public link
|
|
|
|
* @param string path
|
|
|
|
* @param int (optional) expiretime time the link expires, as timestamp
|
|
|
|
*/
|
|
|
|
public function __construct($path,$expiretime=0){
|
2011-04-18 08:31:20 +00:00
|
|
|
if($path and OC_FILESYSTEM::file_exists($path) and OC_FILESYSTEM::is_readable($path)){
|
2011-06-22 10:50:57 +00:00
|
|
|
$user=OC_USER::getUser();
|
2011-04-18 08:31:20 +00:00
|
|
|
$token=sha1("$user-$path-$expiretime");
|
2011-04-16 10:35:21 +00:00
|
|
|
$query=OC_DB::prepare("INSERT INTO *PREFIX*publiclink VALUES(?,?,?,?)");
|
|
|
|
$result=$query->execute(array($token,$path,$user,$expiretime));
|
|
|
|
if( PEAR::isError($result)) {
|
|
|
|
$entry = 'DB Error: "'.$result->getMessage().'"<br />';
|
|
|
|
$entry .= 'Offending command was: '.$result->getDebugInfo().'<br />';
|
|
|
|
error_log( $entry );
|
|
|
|
die( $entry );
|
|
|
|
}
|
|
|
|
$this->token=$token;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-18 08:19:50 +00:00
|
|
|
* get the path of that shared file
|
2011-04-16 10:35:21 +00:00
|
|
|
*/
|
2011-04-18 08:19:50 +00:00
|
|
|
public static function getPath($token){
|
2011-04-16 10:35:21 +00:00
|
|
|
//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
|
2011-04-18 07:25:50 +00:00
|
|
|
OC_UTIL::setupFS($user);
|
2011-04-16 10:35:21 +00:00
|
|
|
|
2011-04-18 08:19:50 +00:00
|
|
|
return $path;
|
2011-04-16 10:35:21 +00:00
|
|
|
}else{
|
2011-04-18 08:19:50 +00:00
|
|
|
return false;
|
2011-04-16 10:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the token for the public link
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getToken(){
|
|
|
|
return $this->token;
|
|
|
|
}
|
|
|
|
|
2011-06-02 00:45:35 +00:00
|
|
|
/**
|
|
|
|
* gets all public links
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
static public function getLinks(){
|
|
|
|
$query=OC_DB::prepare("SELECT * FROM *PREFIX*publiclink WHERE user=?");
|
2011-06-22 10:50:57 +00:00
|
|
|
return $query->execute(array(OC_USER::getUser()))->fetchAll();
|
2011-06-02 00:45:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
2011-06-22 10:50:57 +00:00
|
|
|
if(count($result)>0 and $result[0]['user']==OC_USER::getUser()){
|
2011-06-02 00:45:35 +00:00
|
|
|
$query=OC_DB::prepare("DELETE FROM *PREFIX*publiclink WHERE token=?");
|
|
|
|
$query->execute(array($token));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-16 10:35:21 +00:00
|
|
|
private $token;
|
|
|
|
}
|
|
|
|
?>
|