sharing.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * ownCloud - gallery application
  4. *
  5. * @author Bartek Przybylski
  6. * @copyright 2012 Bartek Przybylski bartek@alefzero.eu
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. class OC_Gallery_Sharing {
  23. private static function getEntries($token) {
  24. $sql = 'SELECT * FROM *PREFIX*gallery_sharing WHERE token = ?';
  25. $stmt = OCP\DB::prepare($sql);
  26. return $stmt->execute(array($token));
  27. }
  28. public static function isTokenValid($token) {
  29. $r = self::getEntries($token);
  30. $row = $r->fetchRow();
  31. return $row != null;
  32. }
  33. public static function isRecursive($token) {
  34. $r = self::getEntries($token);
  35. if ($row = $r->fetchRow()) return $row['recursive'] == 1;
  36. return false;
  37. }
  38. public static function getTokenOwner($token) {
  39. $r = self::getEntries($token);
  40. if ($row = $r->fetchRow()) {
  41. $galleryId = $row['gallery_id'];
  42. $sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE album_id = ?';
  43. $stmt = OCP\DB::prepare($sql);
  44. $r = $stmt->execute(array($galleryId));
  45. if ($row = $r->fetchRow())
  46. return $row['uid_owner'];
  47. }
  48. return false;
  49. }
  50. public static function getPath($token) {
  51. $r = self::getEntries($token);
  52. if ($row = $r->fetchRow()) {
  53. $galleryId = $row['gallery_id'];
  54. $sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE album_id = ?';
  55. $stmt = OCP\DB::prepare($sql);
  56. $r = $stmt->execute(array($galleryId));
  57. if ($row = $r->fetchRow())
  58. return $row['album_path'];
  59. }
  60. }
  61. public static function updateSharingByToken($token, $recursive) {
  62. $stmt = OCP\DB::prepare('UPDATE *PREFIX*gallery_sharing SET recursive = ? WHERE token = ?');
  63. $stmt->execute(array($recursive, $token));
  64. }
  65. public static function getEntryByAlbumId($album_id) {
  66. $stmt = OCP\DB::prepare('SELECT * FROM *PREFIX*gallery_sharing WHERE gallery_id = ?');
  67. return $stmt->execute(array($album_id));
  68. }
  69. public static function addShared($token, $albumId, $recursive) {
  70. $sql = 'INSERT INTO *PREFIX*gallery_sharing (token, gallery_id, recursive) VALUES (?, ?, ?)';
  71. $stmt = OCP\DB::prepare($sql);
  72. $stmt->execute(array($token, $albumId, $recursive));
  73. }
  74. public static function remove($albumId) {
  75. $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*gallery_sharing WHERE gallery_id = ?');
  76. $stmt->execute(array($albumId));
  77. }
  78. }