nextcloud/apps/remoteStorage/lib_remoteStorage.php

53 lines
1.7 KiB
PHP
Raw Normal View History

2011-09-02 16:56:40 +04:00
<?php
class OC_remoteStorage {
public static function getValidTokens($ownCloudUser, $category) {
$query=OC_DB::prepare("SELECT token,appUrl FROM *PREFIX*authtoken WHERE user=? AND category=? LIMIT 100");
$result=$query->execute(array($ownCloudUser,$category));
2011-09-02 16:56:40 +04:00
$ret = array();
while($row=$result->fetchRow()){
$ret[$row['token']]=true;
2011-09-02 16:56:40 +04:00
}
return $ret;
}
public static function getAllTokens() {
$user=OC_User::getUser();
$query=OC_DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100");
2011-09-02 16:56:40 +04:00
$result=$query->execute(array($user));
$ret = array();
while($row=$result->fetchRow()){
$ret[$row['token']] = array(
'appUrl' => $row['appurl'],
'category' => $row['category'],
2011-09-02 16:56:40 +04:00
);
}
return $ret;
}
public static function deleteToken($token) {
$user=OC_User::getUser();
$query=OC_DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?");
$result=$query->execute(array($token,$user));
}
private static function addToken($token, $appUrl, $category){
2011-09-02 16:56:40 +04:00
$user=OC_User::getUser();
$query=OC_DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)");
$result=$query->execute(array($token,$appUrl,$user,$category));
2011-09-02 16:56:40 +04:00
}
public static function createCategory($appUrl, $category) {
2011-09-02 16:56:40 +04:00
$token=uniqid();
self::addToken($token, $appUrl, $category);
//TODO: input checking on $category
2011-09-02 16:56:40 +04:00
OC_Util::setupFS(OC_User::getUser());
$scopePathParts = array('remoteStorage', $category);
2011-09-02 16:56:40 +04:00
for($i=0;$i<=count($scopePathParts);$i++){
$thisPath = '/'.implode('/', array_slice($scopePathParts, 0, $i));
if(!OC_Filesystem::file_exists($thisPath)) {
OC_Filesystem::mkdir($thisPath);
}
}
return base64_encode('remoteStorage:'.$token);
2011-09-02 16:56:40 +04:00
}
}