function handleGetGallery($token, $path) { $owner = OC_Gallery_Sharing::getTokenOwner($token); $apath = OC_Gallery_Sharing::getPath($token); if ($path == false) { $root = $apath; } else { $root = rtrim($apath, '/') . $path; } $r = OC_Gallery_Album::find($owner, null, $root); $albums = array(); $photos = array(); $albumId = -1; if ($row = $r->fetchRow()) { $albumId = $row['album_id']; } if ($albumId != -1) { if (OC_Gallery_Sharing::isRecursive($token)) { $r = OC_Gallery_Album::find($owner, null, null, $root); while ($row = $r->fetchRow()) { $albums[] = $row['album_name']; } } $r = OC_Gallery_Photo::find($albumId); while ($row = $r->fetchRow()) { $photos[] = $row['file_path']; } } OCP\JSON::success(array('albums' => $albums, 'photos' => $photos)); }
public static function scan($eventSource) { $paths = self::findPaths(); $eventSource->send('count', count($paths) + 1); $owner = OCP\USER::getUser(); foreach ($paths as $path) { $name = self::createName($path); $images = self::findFiles($path); $result = OC_Gallery_Album::find($owner, null, $path); // don't duplicate galleries with same path if (!($albumId = $result->fetchRow())) { OC_Gallery_Album::create($owner, $name, $path); $result = OC_Gallery_Album::find($owner, $name, $path); $albumId = $result->fetchRow(); } $albumId = $albumId['album_id']; foreach ($images as $img) { $result = OC_Gallery_Photo::find($albumId, $img); if (!$result->fetchRow()) { OC_Gallery_Photo::create($albumId, $img); } } if (count($images)) { self::createThumbnails($name, $images); } $eventSource->send('scanned', ''); } self::createIntermediateAlbums(); $eventSource->send('scanned', ''); $eventSource->send('done', 1); }
function handleGetGallery($path) { $a = array(); $root = OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '/'); $path = utf8_decode(rtrim($root . $path, '/')); if ($path == '') { $path = '/'; } $pathLen = strlen($path); $result = OC_Gallery_Album::find(OCP\USER::getUser(), null, $path); $album_details = $result->fetchRow(); $result = OC_Gallery_Album::find(OCP\USER::getUser(), null, null, $path); while ($r = $result->fetchRow()) { $album_name = $r['album_name']; $size = OC_Gallery_Album::getAlbumSize($r['album_id']); // this is a fallback mechanism and seems expensive if ($size == 0) { $size = OC_Gallery_Album::getIntermediateGallerySize($r['album_path']); } $a[] = array('name' => utf8_encode($album_name), 'numOfItems' => min($size, 10), 'path' => substr($r['album_path'], $pathLen)); } $result = OC_Gallery_Photo::find($album_details['album_id']); $p = array(); while ($r = $result->fetchRow()) { $p[] = utf8_encode($r['file_path']); } $r = OC_Gallery_Sharing::getEntryByAlbumId($album_details['album_id']); $shared = false; $recursive = false; $token = ''; if ($row = $r->fetchRow()) { $shared = true; $recursive = $row['recursive'] == 1 ? true : false; $token = $row['token']; } OCP\JSON::success(array('albums' => $a, 'photos' => $p, 'shared' => $shared, 'recursive' => $recursive, 'token' => $token)); }