lib_remoteStorage.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. class OC_remoteStorage {
  3. public static function getValidTokens($ownCloudUser, $category) {
  4. $query=OC_DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100");
  5. $result=$query->execute(array($ownCloudUser));
  6. $ret = array();
  7. while($row=$result->fetchRow()){
  8. if(in_array($category, explode(',', $row['category']))) {
  9. $ret[$row['token']]=true;
  10. }
  11. }
  12. return $ret;
  13. }
  14. public static function getAllTokens() {
  15. $user=OC_User::getUser();
  16. $query=OC_DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100");
  17. $result=$query->execute(array($user));
  18. $ret = array();
  19. while($row=$result->fetchRow()){
  20. $ret[$row['token']] = array(
  21. 'appUrl' => $row['appUrl'],
  22. 'categories' => $row['category'],
  23. );
  24. }
  25. return $ret;
  26. }
  27. public static function deleteToken($token) {
  28. $user=OC_User::getUser();
  29. $query=OC_DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?");
  30. $result=$query->execute(array($token,$user));
  31. return 'unknown';//how can we see if any rows were affected?
  32. }
  33. private static function addToken($token, $appUrl, $categories){
  34. $user=OC_User::getUser();
  35. $query=OC_DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)");
  36. $result=$query->execute(array($token,$appUrl,$user,$categories));
  37. }
  38. public static function createCategories($appUrl, $categories) {
  39. $token=uniqid();
  40. OC_Util::setupFS(OC_User::getUser());
  41. self::addToken($token, $appUrl, $categories);
  42. foreach(explode(',', $categories) as $category) {
  43. //TODO: input checking on $category
  44. $scopePathParts = array('remoteStorage', $category);
  45. for($i=0;$i<=count($scopePathParts);$i++){
  46. $thisPath = '/'.implode('/', array_slice($scopePathParts, 0, $i));
  47. if(!OC_Filesystem::file_exists($thisPath)) {
  48. OC_Filesystem::mkdir($thisPath);
  49. }
  50. }
  51. }
  52. return base64_encode('remoteStorage:'.$token);
  53. }
  54. }