123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887 |
- <?php
-
- require_once('album.inc.php');
-
- class AlbumAPIUtil {
-
- /**
- * @param $parentAlbumName
- * @param $data
- * @return
- * id - success
- * -1 - general fail
- * -2 - no upload right
- * -3 - not admin
- * -4 - album hsa exist
- */
- static function SYNOPHOTO_ADMIN_AddAlbum($parentAlbumName = '', $params)
- {
- if (null !== $params['sort_by'] || null !== $params['sort_direction'] || null !== $params['conversion'] ||
- null !== $params['allow_comment'] || null !== $params['type'] || null !== $params['password']) {
- if (!isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user'])) {
- return -3;
- }
- } else {
- if (!csSynoPhotoMisc::CheckAlbumUploadable(('' === $parentAlbumName) ? '/' : $parentAlbumName)) {
- return -2;
- }
- }
-
-
- $album_data = array();
- // only 1st level share can set 'allow_comment' and 'allow conversion'
- if ('' === $parentAlbumName) {
- if (null === $params['allow_comment']) {
- $album_data['comment'] = ('on' === csSYNOPhotoMisc::GetConfigDB("photo", "album_def_allow_comment", "photo_config")) ? 't' : 'f';
- } else {
- $album_data['comment'] = ('true' === $params['allow_comment']) ? 't' : 'f';
- }
- if (null === $params['conversion']) {
- $album_data['conversion'] = ('on' === csSYNOPhotoMisc::GetConfigDB("photo", "def_album_disable_conversion", "photo_config")) ? 'f' : 't';
- } else {
- $album_data['conversion'] = ('true' === $params['conversion']) ? 't' : 'f';
- }
- } else {
- $album_data['comment'] = 'f';
- $album_data['conversion'] = 't';
- }
-
- $album_name = stripcslashes($params['name']);
- $album_data['sharename'] = ($parentAlbumName == '') ? $album_name : $parentAlbumName.'/'.$album_name;
- $album_data['title'] = stripcslashes($params['title']);
- $album_data['description'] = stripcslashes($params['description']);
-
- $default_album_public = 'f';
- if (isSet($_SESSION[SYNOPHOTO_ADMIN_USER]['system_config']['pkgCfg']['albumdefpublic']) &&
- 'yes' == $_SESSION[SYNOPHOTO_ADMIN_USER]['system_config']['pkgCfg']['albumdefpublic']) {
- $default_album_public = 't';
- }
- $album_data['public'] = null === $params['type'] ? $default_album_public : (('public' === $params['type']) ? 't' : 'f');
- $album_data['is_subdir'] = ($parentAlbumName == '') ? 'f' : 't';
- $album_data['password'] = (null !== $params['password']) ? md5($params['password']) : '';
- $inherit = ('' === $album_data['password']) ? $params['inheritParent'] : false;
-
- $path = SYNOPHOTO_SERVICE_REAL_DIR.'/'.$album_data['sharename'];
-
- //3rd param is true while create album but not assign permission so that inheriting permission of parent album
- //4th param is true while the album creator is not admin so that it need to inherit the 'public' column of parent album,
- // althought 3rd param is false, AddAlbumToDB still call inherit because of creator is not admin.
- $createID = SYNOPHOTO_ADMIN_AddAlbumToDB($album_data, $path, $inherit, !$inherit);
- if ('album existed' === $createID) {
- return -4;
- }
-
- //sort
- $data = array();
- $data['type'] = (null !== $params['sort_by']) ? self::ConvertToSortCode($params['sort_by']) : -1;
- $data['order'] = (null !== $params['sort_by']) ? self::ConvertToSortDirectionCode($params['sort_direction']) : 0;
- csSYNOPhotoAlbum::GetAlbumInstance()->SaveAlbumThumbSortType($album_data['sharename'], $data);
-
- csSYNOPhotoDB::GetDBInstance()->SetSessionCache(true);
- return $createID;
- }
-
- /**
- * @param $shareName
- * @param $params
- * @return
- * 0 - success
- * -1 - general fail
- * -2 - no manage right
- * -3 - not admin
- */
- static function SYNOPHOTO_ADMIN_UpdateAlbum($shareName, $params)
- {
- // description, title - manage right
- if ((null !== $params['description'] || null !== $params['title']) && null === $params['sort_by'] && null === $params['sort_direction'] &&
- null === $params['allow_comment'] && null === $params['type'] && null === $params['password'] && null === $params['conversion']) {
- if (!csSynoPhotoMisc::CheckAlbumManageable(('' === $shareName) ? '/' : $shareName)) {
- return -2;
- }
- // not changed
- } elseif (null === $params['description'] && null === $params['title'] && null === $params['sort_by'] && null === $params['sort_direction'] &&
- null === $params['allow_comment'] && null === $params['type'] && null === $params['password'] && null === $params['conversion']) {
- return 0;
- } else {
- // title, sort_by, sort_direction, allow_comment, type, password, conversion - admin
- if (!isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user'])) {
- return -3;
- }
- }
-
- if ('' === $shareName) {
- $shareName = '/';
- }
-
-
- $setCondition = array();
- $setQueryParam = array();
- if (null !== $params['title']) {
- $setValue = "title = ? ";
- array_push($setCondition, $setValue);
- $setQueryParam[] = stripcslashes($params['title']);
- }
- if (null !== $params['description']) {
- $setValue = "description = ?";
- array_push($setCondition, $setValue);
- $setQueryParam[] = stripcslashes($params['description']);
- }
-
- $objs = Album::GetBySharename(array($shareName), true);
- $share = $objs[$shareName];
- if ($share) {
- $shareid = $share['shareid'];
- } else {
- return -1;
- }
-
- if ('public' === $params['type']) {
- $setValue = "public = 't', password = ''";
- array_push($setCondition, $setValue);
-
- /* clear access right table if album is public */
- PHOTO_DB_Query("DELETE FROM " . PHOTO_ACCESS_RIGHT_TABLE . " WHERE shareid = ".$shareid);
- } else if ('private' === $params['type']) {
- $setValue = "public = 'f', password = ''";
- array_push($setCondition, $setValue);
-
- /* remove all permissions if album is password */
- PHOTO_DB_Query("DELETE FROM " . PHOTO_ACCESS_RIGHT_TABLE . " WHERE shareid = ".$shareid);
- PHOTO_DB_Query("DELETE FROM " . PHOTO_UPLOAD_RIGHT_TABLE . " WHERE shareid = ".$shareid);
- PHOTO_DB_Query("DELETE FROM " . PHOTO_MANAGE_RIGHT_TABLE . " WHERE shareid = ".$shareid);
-
- } else if ('password' === $params['type'] && $params['password'] !== '') {
- $setValue = "public = 'f',password='".md5($params['password'])."'";
- array_push($setCondition, $setValue);
-
- /* remove all permissions if album is password */
- PHOTO_DB_Query("DeLETE FROM " . PHOTO_ACCESS_RIGHT_TABLE . " WHERE shareid = ".$shareid);
- PHOTO_DB_Query("DELETE FROM " . PHOTO_UPLOAD_RIGHT_TABLE . " WHERE shareid = ".$shareid);
- PHOTO_DB_Query("DELETE FROM " . PHOTO_MANAGE_RIGHT_TABLE . " WHERE shareid = ".$shareid);
- }
-
- if (null !== $params['allow_comment']) {
- if($params['allow_comment'] == 'true') {
- $setValue = "comment = 't'";
- } else {
- $setValue = "comment = 'f'";
- }
- array_push($setCondition, $setValue);
- }
-
- if (null !== $params['conversion']) {
- if ($params['conversion'] === 'true' && !$share['conversion']) {
- $needReindex = true;
- $setValue = "conversion = 't'";
- array_push($setCondition, $setValue);
- } elseif ($params['conversion'] !=='true' && $share['conversion']) {
- $setValue = "conversion = 'f'";
- array_push($setCondition, $setValue);
- }
- }
-
- $setString = implode(',', $setCondition);
- $query = "UPDATE photo_share SET {$setString} WHERE sharename = ?";
- $setQueryParam[] = $shareName;
- $db_result = PHOTO_DB_Query($query, $setQueryParam);
-
- //sort
- $data = array();
- if (null !== $params['sort_by']) {
- $data['type'] = self::ConvertToSortCode($params['sort_by']);
- }
- if (null !== $params['sort_direction']) {
- $data['order'] = self::ConvertToSortDirectionCode($params['sort_direction']);
- }
- if ('/' !== $shareName) {
- csSYNOPhotoAlbum::GetAlbumInstance()->SaveAlbumThumbSortType($shareName, $data);
- }
- csSYNOPhotoDB::GetDBInstance()->SetSessionCache(true);
-
- if ($needReindex) {
- @exec("/usr/syno/bin/synoindex -P PhotoStation -R " . escapeshellarg(SYNOPHOTO_SERVICE_REAL_DIR . "/" . $shareName));
- }
-
- return 0;
- }
-
- static function ConvertToTypeName($type) {
- switch ($type) {
- case 0:
- $typeName = 'album';
- break;
- case 1:
- $typeName = 'photo';
- break;
- case 2:
- $typeName = 'video';
- break;
- default:
- break;
- }
- return $typeName;
- }
-
- static function ConvertToSortDirection($value) {
- switch ($value) {
- case -1:
- $sortDirection = 'default';
- break;
- case 0:
- $sortDirection = 'asc';
- break;
- case 1:
- $sortDirection = 'desc';
- break;
- default:
- break;
- }
- return $sortDirection;
- }
-
- static function ConvertToSortDirectionCode($name) {
- switch ($name) {
- case 'default':
- $sortCode = -1;
- break;
- case 'asc':
- $sortCode = 0;
- break;
- case 'desc':
- $sortCode = 1;
- break;
- default:
- break;
- }
- return $sortCode;
- }
-
- static function ConvertToSortName($type) {
- switch ($type) {
- case -1:
- $sortBy = 'default';
- break;
- case 0:
- $sortBy = 'filename';
- break;
- case 1:
- $sortBy = 'takendate';
- break;
- case 2:
- $sortBy = 'createdate';
- break;
- case 3:
- $sortBy = 'preference';
- break;
- default:
- break;
- }
- return $sortBy;
- }
-
- static function ConvertToSortCode($name) {
- switch ($name) {
- case 'default':
- $sortCode = -1;
- break;
- case 'filename':
- $sortCode = 0;
- break;
- case 'takendate':
- $sortCode = 1;
- break;
- case 'createdate':
- $sortCode = 2;
- break;
- case 'preference':
- $sortCode = 3;
- break;
- default:
- break;
- }
- return $sortCode;
- }
-
- static function FilterByType($items, $type)
- {
- $filterItems = array();
- foreach ($items as $item) {
- $typeName = self::ConvertToTypeName($item['itemType']);
- if (in_array($typeName, $type)) {
- array_push($filterItems, $item);
- }
- }
- return $filterItems;
- }
-
- static function SortItem($photo_video_items, $sortBy, $sortDirection, $offset, $limit) {
- $itemsSort = array();
-
- // sort by photo, video
- if ('filename' === $sortBy) {
- if ('asc' === $sortDirection) {
- usort($photo_video_items, 'self::SortFilename_ASC');
- } else {
- usort($photo_video_items, 'self::SortFilename_DESC');
- }
- } elseif ('takendate' === $sortBy) {
- if ('asc' === $sortDirection) {
- usort($photo_video_items, 'self::SortTakendate_ASC');
- } else {
- usort($photo_video_items, 'self::SortTakendate_DESC');
- }
- } elseif ('createdate' === $sortBy) {
- if ('asc' === $sortDirection) {
- usort($photo_video_items, 'self::SortCreatedate_ASC');
- } else {
- usort($photo_video_items, 'self::SortCreatedate_DESC');
- }
- }
-
- if (false === $offset && false === $limit) {
- return $photo_video_items;
- }
- // set offset and limit
- $cutItemsSort = array();
- if (0 > (int)$limit) {
- $cutItemsSort = array_slice($photo_video_items, $offset);
- } else {
- $cutItemsSort = array_slice($photo_video_items, $offset, $limit);
- }
-
- return $cutItemsSort;
- }
-
- private function ExtractItem($items, &$albumItems, &$photo_video_items) {
- $index = count($items);
- foreach ($items as $key => $item) {
- if ('album' !== self::ConvertToTypeName($item['itemType'])) {
- $index = $key;
- break;
- }
- }
- $albumItems = array_slice($items, 0, $index);
- $photo_video_items = array_slice($items, $index);
- }
-
- static function SortFilename_ASC($a, $b) {
- if ($a['name'] == $b['name']) {
- return 0;
- }
- return ($a['name'] < $b['name']) ? -1 : 1;
- }
-
- static function SortFilename_DESC($a, $b) {
- if ($a['name'] == $b['name']) {
- return 0;
- }
- return ($a['name'] > $b['name']) ? -1 : 1;
- }
-
- static function SortTakendate_ASC($a, $b) {
- if ($a['takendate'] == $b['takendate']) {
- return ($a['name'] < $b['name']) ? -1 : 1;
- }
- return ($a['takendate'] < $b['takendate']) ? -1 : 1;
- }
-
- static function SortTakendate_DESC($a, $b) {
- if ($a['takendate'] == $b['takendate']) {
- return ($a['name'] > $b['name']) ? -1 : 1;
- }
- return ($a['takendate'] > $b['takendate']) ? -1 : 1;
- }
-
- static function SortCreatedate_ASC($a, $b) {
- if ($a['createdate'] == $b['createdate']) {
- return ($a['name'] < $b['name']) ? -1 : 1;
- }
- return ($a['createdate'] < $b['createdate']) ? -1 : 1;
- }
-
- static function SortCreatedate_DESC($a, $b) {
- if ($a['createdate'] == $b['createdate']) {
- return ($a['name'] > $b['name']) ? -1 : 1;
- }
- return ($a['createdate'] > $b['createdate']) ? -1 : 1;
- }
-
- static function SortPreference($items, $sharePath) {
- $sort = csSYNOPhotoAlbum::GetAlbumThumbSortType($sharePath);
- $list = array();
- $result = array();
- if (!empty($sort['list'])) {
- $list = $sort['list'];
- $preArr = array();
- foreach ($list as $key) {
- foreach ($items as $item) {
- if ($key === $item['name']) {
- array_push($result, $item);
- }
- }
- }
-
- // rest photo and video item
- foreach ($items as $item) {
- if (!in_array($item, $result)) {
- array_push($result, $item);
- }
- }
-
- } else {
- $result = $items;
- }
-
- return $result;
- }
-
- /*
- * @return [string] broken / small, large
- */
- static function GetThumbStatus($dbPath, $needSize, $orig_resolutionx, $orig_resolutiony, $blThumbRotated, $blConversion) {
- /* special case for gif, return original file */
- $path = SYNOPHOTO_SERVICE_REAL_DIR_PREFIX.$dbPath;
- $info = pathinfo($path);
- if ('gif' === strtolower($info['extension'])) {
- $ret['status'] = 'small,large';
- if ($needSize) {
- $imgInfo = @getImageSize($path);
- $mtime = @filemtime($path);
- $ret['size']['preview']['resolutionx'] = $imgInfo[0];
- $ret['size']['preview']['resolutiony'] = $imgInfo[1];
- $ret['size']['preview']['mtime'] = $mtime;
- $ret['size']['small']['resolutionx'] = $imgInfo[0];
- $ret['size']['small']['resolutiony'] = $imgInfo[1];
- $ret['size']['small']['mtime'] = $mtime;
- $ret['size']['large']['resolutionx'] = $imgInfo[0];
- $ret['size']['large']['resolutiony'] = $imgInfo[1];
- $ret['size']['large']['mtime'] = $mtime;
- }
- return $ret;
- }
-
- if ($needSize) {
- $ret['size']['preview']['resolutionx'] = 0;
- $ret['size']['preview']['resolutiony'] = 0;
- $ret['size']['small']['resolutionx'] = 0;
- $ret['size']['small']['resolutiony'] = 0;
- $ret['size']['large']['resolutionx'] = 0;
- $ret['size']['large']['resolutiony'] = 0;
- }
-
- $file_name = basename($path);
- $dir = dirname($path);
-
- if (SYNOPhotoEA::checkFilePathByDirFile($dir, $file_name, SYNOPhotoEA::FILE_THUMB_M_FAIL, $thumbSmallBroken) &&
- SYNOPhotoEA::checkFilePathByDirFile($dir, $file_name, SYNOPhotoEA::FILE_THUMB_XL_FAIL, $thumbLargeBroken)) {
- $ret['status'] = 'broken';
- } else {
- $thumbStatus = array();
- $hasSmall = $hasLarge = false;
- if (!$blConversion) {
- $thumbStatus[] = 'disable';
- }
- if (SYNOPhotoEA::checkFilePathByDirFile($dir, $file_name, SYNOPhotoEA::FILE_THUMB_M, $thumbSmallPath)) {
- $hasSmall = true;
- if ($needSize) {
- $ret['size']['small'] = self::CalculateThumbSize($orig_resolutionx, $orig_resolutiony, $blThumbRotated, SYNOPHOTO_THUMBMEDIUM_WIDTH);
- $ret['size']['small']['mtime'] = @filemtime($thumbSmallPath);
- }
- }
- if (SYNOPhotoEA::checkFilePathByDirFile($dir, $file_name, SYNOPhotoEA::FILE_THUMB_PREVIEW, $thumbPreviewPath)) {
- $thumbStatus[] = 'preview';
- if ($needSize) {
- if ($hasSmall) {
- $ret['size']['preview'] = self::CalculateThumbSize($orig_resolutionx, $orig_resolutiony, $blThumbRotated, SYNOPHOTO_THUMBPREVIEW_WIDTH);
- } else {
- $ret['size']['preview'] = self::GetThumbSize($path, $thumbPreviewPath);
- }
- $ret['size']['preview']['mtime'] = @filemtime($thumbPreviewPath);
- }
-
- //use preview-thumb as small-thumb in thumbnail-less browsing
- if (!$blConversion && !$hasSmall) {
- $hasSmall = true;
- if ($needSize) {
- $ret['size']['small'] = $ret['size']['preview'];
- $ret['size']['small']['mtime'] = $ret['size']['preview']['mtime'];
- }
- }
- }
- if (SYNOPhotoEA::checkFilePathByDirFile($dir, $file_name, SYNOPhotoEA::FILE_THUMB_XL, $thumbLargePath)) {
- $hasLarge = true;
- if ($needSize) {
- $ret['size']['large'] = self::CalculateThumbSize($orig_resolutionx, $orig_resolutiony, $blThumbRotated, SYNOPHOTO_THUMBXLARGE_WIDTH);
- $ret['size']['large']['mtime'] = @filemtime($thumbLargePath);
- }
- }
-
- if (!$hasLarge && SYNOPhotoEA::checkFilePathByDirFile($dir, $file_name, SYNOPhotoEA::FILE_THUMB_LARGE_PREVIEW, $thumbLargePreviewPath)) {
- $thumbStatus[] = 'large';
- if ($needSize) {
- $ret['size']['large'] = self::GetThumbSize($path, $thumbLargePreviewPath);
- $ret['size']['large']['mtime'] = @filemtime($thumbLargePreviewPath);
- }
- }
-
- //use original file as large thumb in thumbnail-less browsing
- if (!$blConversion && !$hasLarge && in_array(strtolower($info['extension']), array('jpeg', 'bmp', 'png', 'jpg', 'jpe'/*, 'image/tiff'*/))) {
- $hasLarge = true;
- if ($needSize) {
- $ret['size']['large']['resolutionx'] = $orig_resolutionx;
- $ret['size']['large']['resolutiony'] = $orig_resolutiony;
- $ret['size']['large']['mtime'] = @filemtime($path);
- }
- $thumbStatus[] = "large_original";
- }
-
- if ($hasSmall) {
- $thumbStatus[] = 'small';
- }
- if ($hasLarge) {
- $thumbStatus[] = 'large';
- }
-
- $ret['status'] = implode(',', $thumbStatus);
- }
-
- return $ret;
- }
-
- static function CalculateThumbSize($orig_resolutionx, $orig_resolutiony, $blThumbRotated, $thumbSize)
- {
- $thumb['resolutionx'] = $thumb['resolutiony'] = 0;
-
- if (0 >= $orig_resolutionx || 0 >= $orig_resolutiony || 0 >= $thumbSize) {
- goto End;
- }
-
- $ratio = $orig_resolutionx / $orig_resolutiony;
- if (0 >= $ratio) {
- goto End;
- }
-
- $thumb['resolutionx'] = $orig_resolutionx;
- $thumb['resolutiony'] = $orig_resolutiony;
-
- if ($thumbSize < $orig_resolutionx && $thumbSize < $orig_resolutiony) {
- if ($orig_resolutionx >= $orig_resolutiony) {
- $thumb['resolutionx'] = ceil($thumbSize * $ratio);
- $thumb['resolutiony'] = $thumbSize;
- } else {
- $thumb['resolutionx'] = $thumbSize;
- $thumb['resolutiony'] = ceil($thumbSize / $ratio);
- }
- }
-
- if ($blThumbRotated) {
- $tmp = $thumb['resolutionx'];
- $thumb['resolutionx'] = $thumb['resolutiony'];
- $thumb['resolutiony'] = $tmp;
- }
- End:
- return $thumb;
- }
-
- static function GetThumbSize($imgPath, $thumbPath) {
- $thumbInfo = @getImageSize($thumbPath);
- $ret = array(
- 'resolutionx' => $thumbInfo[0],
- 'resolutiony' => $thumbInfo[1]
- );
-
- $info = pathinfo($imgPath);
- if (!in_array(strtolower($info['extension']), array('jpeg', 'bmp', 'png', 'jpg', 'jpe'/*, 'image/tiff'*/))) {
- goto END;
- }
-
- $imgInfo = @getImageSize($imgPath);
- $rotated = ($thumbInfo[0] > $thumbInfo[1] && $imgInfo[0] <= $imgInfo[1]) || ($thumbInfo[0] <= $thumbInfo[1] && $imgInfo[0] > $imgInfo[1]);
-
- if ($rotated && $thumbInfo[0] > $imgInfo[1]) {
- $ret['resolutionx'] = $imgInfo[1];
- $ret['resolutiony'] = $imgInfo[0];
- } else if (!$rotated && $thumbInfo[0] > $imgInfo[0]) {
- $ret['resolutionx'] = $imgInfo[0];
- $ret['resolutiony'] = $imgInfo[1];
- }
-
- END:
- return $ret;
- }
-
- static function FillThumbStatus(&$item, $coverDBPath, $needThumbSize, $orig_resolutionx, $orig_resolutiony, $blThumbRotated, $blConversion)
- {
- if ('' !== $coverDBPath) {
- $thumbnail = self::GetThumbStatus($coverDBPath, $needThumbSize, $orig_resolutionx, $orig_resolutiony, $blThumbRotated, $blConversion);
- } else {
- $thumbnail = array('status' => 'default');
- if (!$blConversion) {
- $thumbnail['status'] .= ',disable';
- }
- if ($needThumbSize) {
- $thumbnail['size'] = array(
- 'preview' => array('resolutionx' => 0, 'resolutiony' => 0),
- 'small' => array('resolutionx' => 0, 'resolutiony' => 0),
- 'large' => array('resolutionx' => 0, 'resolutiony' => 0)
- );
- }
- }
-
- $item['thumbnail_status'] = $thumbnail['status'];
- if ($needThumbSize) {
- if (!is_array($item['additional'])) {
- $item['additional'] = array();
- }
- $item['additional']['thumb_size'] = $thumbnail['size'];
- $item['additional']['thumb_size']['sig'] = bin2hex($coverDBPath);
- }
- }
-
- static function GetCoverResolutionRotation($coverPath) {
- if ('' === $coverPath) {
- return array(0, 0, false);
- }
- $file = csSYNOPhotoMisc::IsPhotoFile($coverPath) ?
- File::GetPhotoByDBPath(array($coverPath)) : File::GetVideoByDBPath(array($coverPath));
-
- $info = $file[$coverPath];
-
- return array((int)$info['resolutionx'], (int)$info['resolutiony'], 0 !== (int)$info['version'] % 2);
- }
-
- static function GetAlbumPermission($sharePath) {
- $permission['browse'] = csSYNOPhotoMisc::CheckAlbumAccessible($sharePath);
- $permission['upload'] = csSYNOPhotoMisc::CheckAlbumUploadable($sharePath);
- $permission['manage'] = csSYNOPhotoMisc::CheckAlbumManageable($sharePath);
- return $permission;
- }
-
- static function GetUnConfirmItemList($limit=false, $offset=false)
- {
- $result = array();
-
- $limitOffsetString = PHOTO_DB_GetLimitOffsetString($limit, $offset);
-
- $query = "SELECT photo_image.path FROM photo_image_label LEFT JOIN photo_image ON photo_image_label.image_id=photo_image.id WHERE status='f'";
- $queryCount = "SELECT COUNT(DISTINCT photo_image.path) FROM photo_image_label LEFT JOIN photo_image ON photo_image_label.image_id=photo_image.id WHERE status='f'";
- $albumCondition = csSYNOPhotoMisc::GetAccessibleAlbumQueryConditionWithExcludeFormat();
-
- if(!$albumCondition['albumCond']) {
- return $result;
- }
-
- $query .= " AND {$albumCondition['albumCond']}";
- $query .= " ORDER BY photo_image.create_time DESC ";
- $query .= $limitOffsetString;
- $queryCount .= " AND {$albumCondition['albumCond']}";
- $db_result = PHOTO_DB_Query($query, $albumCondition['sqlParam']);
-
- while (false !== ($row = PHOTO_DB_FetchRow($db_result))) {
- if ($row['path']) {
- $result[SYNOPHOTO_SERVICE_REAL_DIR_PREFIX.$row['path']] = SYNOPHOTO_ITEM_TYPE_PHOTO;
- }
- }
- $db_result = PHOTO_DB_Query($queryCount, $sqlParam);
- $row = PHOTO_DB_FetchRow($db_result);
- $result['total'] = $row[0];
- return $result;
- }
-
- /*
- * @param $videoPath video db path
- */
- static function GetConvertedVideoInfo($dPath)
- {
- $query = "SELECT * FROM video_convert WHERE video_path = ?";
- $sqlParam = array($dPath);
- $db_result = PHOTO_DB_Query($query, $sqlParam);
- $videoArr = array();
- while ($videoInfo = PHOTO_DB_FetchRow($db_result)) {
- $videoQuality['id'] = bin2hex(SYNOPHOTO_SERVICE_REAL_DIR_PREFIX.$videoInfo['convert_file_path']);
- $videoQuality['container'] = $videoInfo['container_type'];
- $videoQuality['vcodec'] = $videoInfo['vcodec'];
- $videoQuality['acodec'] = $videoInfo['acodec'];
- $videoQuality['filesize'] = (int)$videoInfo['filesize'];
- $videoQuality['resolutionx'] = (int)$videoInfo['resolutionx'];
- $videoQuality['resolutiony'] = (int)$videoInfo['resolutiony'];
- $videoQuality['video_bitrate'] = (int)$videoInfo['video_bitrate'];
- $videoQuality['audio_bitrate'] = (int)$videoInfo['audio_bitrate'];
- $videoQuality['video_profile'] = (int)$videoInfo['video_profile'];
- $videoQuality['video_level'] = (int)$videoInfo['video_level'];
- $videoQuality['profile_name'] = self::GetConvertedName($videoInfo['convert_file_path']);
- array_push($videoArr, $videoQuality);
- }
- return $videoArr;
- }
-
- static function GetConvertedName($convertPath)
- {
- $fileName = basename($convertPath);
- $pool = array(SYNOPhotoEA::FILE_FILM_FLV, SYNOPhotoEA::FILE_FILM_H264_MP4, SYNOPhotoEA::FILE_FILM_H_MP4, SYNOPhotoEA::FILE_FILM_M_MP4, SYNOPhotoEA::FILE_FILM_L_MP4,
- SYNOPhotoEA::FILE_FILM_MOBILE_MP4, SYNOPhotoEA::FILE_FILM_MOBILE_IPHONE, SYNOPhotoEA::FILE_FILM_MOBILE_ANDROID);
- foreach ($pool as $name) {
- $oldName = SYNOPhotoEA::SYNO_PHOTO_PREFIX_OLD.$name;
- $newName = SYNOPhotoEA::SYNO_PHOTO_PREFIX.$name;
- if ($oldName === $fileName || $newName === $fileName) {
- if (SYNOPhotoEA::FILE_FILM_FLV === $name) {
- $ret = 'flv';
- } elseif (SYNOPhotoEA::FILE_FILM_H264_MP4 === $name) {
- $ret = 'orig_h264';
- } elseif (SYNOPhotoEA::FILE_FILM_MPEG4_MP4 === $name) {
- $ret = 'orig_mp4';
- } elseif (SYNOPhotoEA::FILE_FILM_H_MP4 === $name) {
- $ret = 'high';
- } elseif (SYNOPhotoEA::FILE_FILM_M_MP4 === $name) {
- $ret = 'medium';
- } elseif (SYNOPhotoEA::FILE_FILM_L_MP4 === $name) {
- $ret = 'low';
- } elseif (SYNOPhotoEA::FILE_FILM_MOBILE_MP4 === $name) {
- $ret = 'mobile';
- } elseif (SYNOPhotoEA::FILE_FILM_MOBILE_IPHONE === $name) {
- $ret = 'orig_iphone';
- } elseif (SYNOPhotoEA::FILE_FILM_MOBILE_ANDROID === $name) {
- $ret = 'orig_android';
- } elseif (SYNOPhotoEA::FILE_FILM_CONVERT_MPEG4_MP4 === $name) {
- $ret = 'convert_mp4';
- }
- break;
- }
- }
- return $ret;
- }
-
- static function IsAlbumCommentalbGlobal($checkSession = false)
- {
- $blAllowUserComment = ('on' === csSYNOPhotoMisc::GetConfigDB("photo", "allow_user_comment", "photo_config"));
- $blAllowGuestComment = ('on' === csSYNOPhotoMisc::GetConfigDB("photo", "allow_guest_comment", "photo_config"));
-
- if ($blAllowGuestComment) {
- return true;
- } elseif ($blAllowUserComment) {
- if ($checkSession) {
- csSYNOPhotoMisc::CheckSessionTimeOut(true);
- return true;
- } else {
- if (isset($_SESSION[SYNOPHOTO_ADMIN_USER]['reg_syno_user']) || isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user'])) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- static function IsShowAlbumHit() {
- $value = csSYNOPhotoMisc::GetConfigDB("photo", "show_album_hit", "photo_config");
- $show_album_hit = 'off' === $value ? false : true ;
- return $show_album_hit;
- }
-
- static function FormAlbum($album_db_object, $global_allow_comment, $show_hits) {
- $name = pathinfo($album_db_object['sharename'], PATHINFO_BASENAME);
- $res = array(
- 'sharepath' => $album_db_object['sharename'],
- 'name' => $name,
- 'title' => $album_db_object['title'] ? $album_db_object['title'] : $name,
- 'description' => $album_db_object['description'],
- 'hits' => $show_hits ? $album_db_object['hits'] : 0,
- 'type' => $album_db_object['public'] ? 'public' : ($album_db_object['password'] ? 'password' : 'private'),
- 'conversion' => $album_db_object['conversion'],
- 'allow_comment' => $global_allow_comment
- );
-
- return $res;
- }
-
- static function FormAdditional($type, $item, $params) {
- if ('album' === $type) {
- $sharePath = $item['sharename'];
- $shareid = $item['shareid'];
- if (in_array('album_sorting', $params['additional'])) {
- $sortData = csSYNOPhotoAlbum::GetAlbumInstance()->GetAlbumThumbSortType($sharePath);
- $sortBy = AlbumAPIUtil::ConvertToSortName($sortData['type']);
- $additional['album_sorting']['sort_by'] = $sortBy;
- $additional['album_sorting']['sort_direction'] = AlbumAPIUtil::ConvertToSortDirection($sortData['order']);
- $additional['album_sorting']['has_preference_sort'] = !empty($sortData);
- }
- if (in_array('album_permission', $params['additional'])) {
- // here
- $additional['album_permission'] = AlbumAPIUtil::GetAlbumPermission($sharePath);
- }
- if (in_array('item_count', $params['additional'])) {
- $additional['item_count'] = array(
- 'photo' => Album::GetPhotoCount($item['shareid']),
- 'video' => Album::GetVideoCount($item['shareid'])
- );
- }
- } elseif ('photo' === $type) {
- if (in_array('photo_exif', $params['additional'])) {
- $photoInfo = $item;
- $additional['photo_exif']['takendate'] = $photoInfo['timetaken'];
- $additional['photo_exif']['camera'] = $photoInfo['camera_make'];
- $additional['photo_exif']['camera_model'] = $photoInfo['camera_model'];
- $additional['photo_exif']['exposure'] = $photoInfo['exposure'];
- $additional['photo_exif']['aperture'] = $photoInfo['aperture'];
- $additional['photo_exif']['iso'] = (int)$photoInfo['iso'];
- $additional['photo_exif']['gps'] = json_decode($photoInfo['gps'], true);
- $additional['photo_exif']['focal_length'] = $photoInfo['focal_length_v2'];
- $additional['photo_exif']['lens'] = $photoInfo['lens_v2'];
- $additional['photo_exif']['flash'] = $photoInfo['flash_v2'];
- }
- } elseif ('video' === $type) {
- if (in_array('video_codec', $params['additional'])) {
- $videoInfo = $item;
- $additional['video_codec']['container'] = $videoInfo['container_type'];
- $additional['video_codec']['vcodec'] = $videoInfo['video_codec'];
- $additional['video_codec']['acodec'] = $videoInfo['audio_codec'];
- $additional['video_codec']['resolutionx'] = (int)$videoInfo['resolutionx'];
- $additional['video_codec']['resolutiony'] = (int)$videoInfo['resolutiony'];
- $additional['video_codec']['frame_bitrate'] = (int)$videoInfo['frame_bitrate'];
- $additional['video_codec']['video_bitrate'] = (int)$videoInfo['video_bitrate'];
- $additional['video_codec']['audio_bitrate'] = (int)$videoInfo['audio_bitrate'];
- }
- if (in_array('video_quality', $params['additional'])) {
- $additional['video_quality'] = AlbumAPIUtil::GetConvertedVideoInfo($item['path']);
- }
- }
-
- if (in_array('file_location', $params['additional'])) {
- $additional['file_location'] = 'album' === $type ?
- $sharePath : substr($item['path'], strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
- }
- return $additional;
- }
-
- static function GetRootAlbumInfo($params){
- $info['description'] = '';
- $info['sharepath'] = '/';
- $info['name'] = '/';
- $info['title'] = csSYNOPhotoMisc::GetConfigDB("photo", "photo_page_title", "photo_config");
- $info['hits'] = null;
- $info['allow_comment'] = ('on' === csSYNOPhotoMisc::GetConfigDB("photo", "album_def_allow_comment", "photo_config")) ? true : false;
- $info['type'] = 'public';
- $info['conversion'] = csSYNOPhotoMisc::IsAlbumAllowConversion('/');
-
- $item['id'] = null;
- $item['info'] = $info;
- if (in_array('album_sorting', $params['additional'])) {
- $value = csSYNOPhotoMisc::GetConfigDB("album", "album_order_type", "photo_config");
- $additional['album_sorting']['sort_by'] = ('1' === $value) ? 'preference' : 'filename';
- $value = csSYNOPhotoMisc::GetConfigDB("album", "album_order_type_is_desc", "photo_config");
- $additional['album_sorting']['sort_direction'] = ('1' === $value) ? 'desc' : 'asc';
- $value = csSYNOPhotoAlbum::GetAlbumThumbSortType($info['sharepath']);
- $additional['album_sorting']['has_preference_sort'] = !empty($value);
- }
- if (in_array('album_permission', $params['additional'])) {
- $permission = self::GetAlbumPermission('/');
- $additional['album_permission'] = $permission;
- }
- if (null !== $additional) {
- $item['additional'] = $additional;
- }
- return $item;
- }
- }
-
- ?>
|