2011-09-02 12:56:40 +00:00
|
|
|
<?php
|
|
|
|
|
2011-10-04 08:07:46 +00:00
|
|
|
class OC_remoteStorage {
|
2011-12-07 14:51:47 +00:00
|
|
|
public static function getValidTokens($ownCloudUser, $category) {
|
2012-02-22 18:05:52 +00:00
|
|
|
$query=OC_DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100");
|
|
|
|
$result=$query->execute(array($ownCloudUser));
|
2011-09-02 12:56:40 +00:00
|
|
|
$ret = array();
|
|
|
|
while($row=$result->fetchRow()){
|
2012-02-22 18:05:52 +00:00
|
|
|
if(in_array($category, explode(',', $row['category']))) {
|
|
|
|
$ret[$row['token']]=true;
|
|
|
|
}
|
2011-09-02 12:56:40 +00:00
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getAllTokens() {
|
|
|
|
$user=OC_User::getUser();
|
2011-12-07 14:51:47 +00:00
|
|
|
$query=OC_DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100");
|
2011-09-02 12:56:40 +00:00
|
|
|
$result=$query->execute(array($user));
|
|
|
|
$ret = array();
|
|
|
|
while($row=$result->fetchRow()){
|
|
|
|
$ret[$row['token']] = array(
|
|
|
|
'appUrl' => $row['appurl'],
|
2012-02-22 18:05:52 +00:00
|
|
|
'categories' => $row['category'],
|
2011-09-02 12:56:40 +00: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));
|
|
|
|
}
|
2012-02-22 18:05:52 +00:00
|
|
|
private static function addToken($token, $appUrl, $categories){
|
2011-09-02 12:56:40 +00:00
|
|
|
$user=OC_User::getUser();
|
2011-12-07 14:51:47 +00:00
|
|
|
$query=OC_DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)");
|
2012-02-22 18:05:52 +00:00
|
|
|
$result=$query->execute(array($token,$appUrl,$user,$categories));
|
2011-09-02 12:56:40 +00:00
|
|
|
}
|
2012-02-22 18:05:52 +00:00
|
|
|
public static function createCategories($appUrl, $categories) {
|
2011-09-02 12:56:40 +00:00
|
|
|
$token=uniqid();
|
|
|
|
OC_Util::setupFS(OC_User::getUser());
|
2012-02-22 18:05:52 +00:00
|
|
|
self::addToken($token, $appUrl, $categories);
|
|
|
|
foreach($categories as $category) {
|
|
|
|
//TODO: input checking on $category
|
|
|
|
$scopePathParts = array('remoteStorage', $category);
|
|
|
|
for($i=0;$i<=count($scopePathParts);$i++){
|
|
|
|
$thisPath = '/'.implode('/', array_slice($scopePathParts, 0, $i));
|
|
|
|
if(!OC_Filesystem::file_exists($thisPath)) {
|
|
|
|
OC_Filesystem::mkdir($thisPath);
|
|
|
|
}
|
2011-09-02 12:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-07 14:51:47 +00:00
|
|
|
return base64_encode('remoteStorage:'.$token);
|
2011-09-02 12:56:40 +00:00
|
|
|
}
|
|
|
|
}
|