123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?
-
- class Decorator {
-
- static function CategoryFormula ($dbObject, $config = array())
- {
- $encodedId = $config['id'];
- $categroy = array();
- $category['id'] = $encodedId ? $encodedId : 'category_'.$dbObject['id'];
- $category['name'] = $dbObject['name'];
- $category['hidden'] = $dbObject['hidden'];
- return $category;
- }
-
- static function AlbumFormula($dbObject, $config = array())
- {
- $allowComment = $config['allowComment'];
- $showAlbumHit = $config['showAlbumHit'];
- $id = $config['id'];
- $param = $config['param'];
- $needThumbSize = isset($config['needThumbSize']) ? $config['needThumbSize'] : in_array('thumb_size', $param['additional']);
-
- $sharepath = $dbObject['sharename'];
- $item_info = AlbumAPIUtil::FormAlbum($dbObject, $allowComment, $showAlbumHit);
- if (!in_array('thumbnail', $param['ignore'])) {
- $result = csSYNOPhotoAlbum::GetAlbumInstance()->GetAlbumCover($sharepath);
- $coverPath = $result['coverPath'];
- }
- list($orig_resolutionx, $orig_resolutiony, $blThumbRotated) = AlbumAPIUtil::GetCoverResolutionRotation($coverPath);
-
- // replace conversion with the first layer album's
- $item_info['conversion'] = csSYNOPhotoMisc::IsAlbumAllowConversion($sharepath);
- $item = array(
- 'info' => $item_info,
- 'id' => $id ? $id : self::EncodeItemId($sharepath, 'album_'),
- 'type' => 'album',
- 'additional' => AlbumAPIUtil::FormAdditional('album', $dbObject, $param)
- );
-
- AlbumAPIUtil::FillThumbStatus($item, $coverPath, $needThumbSize, $orig_resolutionx, $orig_resolutiony, $blThumbRotated, $item_info['conversion']);
- return $item;
- }
-
- static function SmartFormula($dbObject, $config = array())
- {
- $param = $config['param'];
- $id = $config['id'];
- $needThumbSize = isset($config['needThumbSize']) ? $config['needThumbSize'] : in_array('thumb_size', $param['additional']);
-
- $smartAlbum['id'] = $id ? $id : self::EncodeItemId($dbObject['name'], 'smart_');
- $smartAlbum['type'] = 'smart';
- $album = SmartAlbum::GetSmartAlbumInstance()->GetCoverOfSmartAlbumByName($dbObject['name']);
- $smartAlbum['thumbnail_status'] = 'default';
-
- if (false === $album['success'] && !isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user'])) {
- return -1;
- }
-
- $coverPath = '';
- if ($album['success'] && isset($album['cover']['dbPath'])) {
- $coverPath = $album['cover']['dbPath'];
- $relativePath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
- $dirname = dirname($relativePath);
- $sharename = in_array($dirname, array('.', ''), true) ? '/' : $dirname;
- }
-
- $smartAlbum['name'] = $dbObject['name'];
- if (in_array('smart_condition', $param['additional'])) {
- $smartAlbumCond = SmartAlbum::GetSmartAlbumInstance()->GetSmartCondition($dbObject['name']);
- $smartAlbum['additional']['smart_condition'] = $smartAlbumCond;
- }
-
- $blConversion = csSYNOPhotoMisc::IsAlbumAllowConversion($sharename);
- list($orig_resolutionx, $orig_resolutiony, $blThumbRotated) = AlbumAPIUtil::GetCoverResolutionRotation($coverPath);
- AlbumAPIUtil::FillThumbStatus($smartAlbum, $coverPath, $needThumbSize, $orig_resolutionx, $orig_resolutiony, $blThumbRotated, $blConversion);
-
- return $smartAlbum;
- }
-
- static function TagFormula($dbObject, $config = array())
- {
- $param = $config['param'];
- $needThumbSize = isset($config['needThumbSize']) ? $config['needThumbSize'] : in_array('thumb_size', $param['additional']);
- $id = $config['id'];
-
- $tag['id'] = $id ? $id : 'tag_'.$dbObject['id'];
- $tag['type'] = 'tag';
- $tag['tag_type'] = Label::GetCategoryName($dbObject['category']);
- $tag['name'] = $dbObject['name'];
-
- $additional = self::TagAdditional($dbObject, $param);
- if (null !== $additional) {
- $tag['additional'] = $additional;
- }
- if ('true' === $param['thumbnail_status']) {
- $result = csSYNOPhotoAlbum::GetAlbumInstance()->GetLabelAlbumCoverFromDB($dbObject['id']);
- $coverPath = $result['dbPath'];
- $relativePath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
- $dirname = dirname($relativePath);
- $sharename = in_array($dirname, array('.', ''), true) ? '/' : $dirname;
-
- $blConversion = csSYNOPhotoMisc::IsAlbumAllowConversion($sharename);
- list($orig_resolutionx, $orig_resolutiony, $blThumbRotated) = AlbumAPIUtil::GetCoverResolutionRotation($coverPath);
- AlbumAPIUtil::FillThumbStatus($tag, $coverPath, $needThumbSize, $orig_resolutionx, $orig_resolutiony, $blThumbRotated, $blConversion);
- }
- return $tag;
- }
-
- private static function TagAdditional($data, $params)
- {
- if (in_array('info', $params['additional'])) {
- if (Label::PEOPLE === $data['category']) {
- $people['name'] = $data['name'];
- $additional['info'] = $people;
- } elseif (Label::GEO === $data['category']) {
- $geo['name'] = $data['name'];
- if (false !== ($extra = json_decode($data['info'], true))) {
- $geo['lat'] = $extra['lat'];
- $geo['lng'] = $extra['lng'];
- $geo['place_id'] = $extra['placeId'];
- $geo['address'] = (null === $extra['address']) ? '' : $extra['address'];
- }
- $additional['info'] = $geo;
- } elseif (Label::DESC === $data['category']) {
- $desc['name'] = $data['name'];
- $additional['info'] = $desc;
- }
- }
- if (in_array('extra', $params['additional'])) {
- $additional['extra'] = $data['info'];
- }
- if (in_array('count', $params['additional'])) {
- $total = ItemLabel::GetCountByLabelId($data['id']);
- $additional['count'] = (int)$total;
- }
- return $additional;
- }
-
- static function VideoFormula($dbObject, $config = array())
- {
- $params = $config['param'];
- $needThumbSize = $config['needThumbSize'] ? $config['needThumbSize'] : in_array('thumb_size', $params['additional']);
- $item = array(
- 'id' => $config['id'] ? $config['id'] : self::EncodeItemId($dbObject['path'], "video_"),
- 'type' => 'video'
- );
- $customTitleDesc = csSYNOPhotoDB::GetDBInstance()->GetVideoCustomizedTitleDescription($dbObject['path']);
-
- $item_info = array(
- 'name' => $dbObject['name'],
- 'title' => empty($customTitleDesc['title']) ? $dbObject['name'] : $customTitleDesc['title'],
- 'description' => $customTitleDesc['description'],
- 'createdate' => $dbObject['date'],
- 'takendate' => $dbObject['mdate'],
- 'size' => $dbObject['filesize'],
- 'duration' => (int)$dbObject['duration'],
- 'gps' => json_decode($dbObject['gps']),
- 'rotation' => (int)$dbObject['rotation']
- );
- if (isset($dbObject['pos'])) {
- $item['pos'] = (int) $dbObject['pos'];
- }
-
- $coverPath = $dbObject['path'];
- $sharepath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
- $dir = in_array(dirname($sharepath), array('.', ''), true) ? '/' : dirname($sharepath);
- // additional handler
- $item['info'] = $item_info;
- $item['additional'] = AlbumAPIUtil::FormAdditional('video', $dbObject, $params);
-
- $isConversion = csSYNOPhotoMisc::IsAlbumAllowConversion($dir);
-
- AlbumAPIUtil::FillThumbStatus($item, $coverPath, $needThumbSize, $dbObject['resolutionx'], $dbObject['resolutiony'], false, $isConversion);
- return $item;
- }
-
- static function PhotoFormula($dbObject, $config = array())
- {
- $params = $config['param'];
- $needThumbSize = $config['needThumbSize'] ? $config['needThumbSize'] : in_array('thumb_size', $params['additional']);
- $item = array(
- 'id' => $config['id'] ? $config['id'] : self::EncodeItemId($dbObject['path'], "photo_"),
- 'type' => 'photo'
- );
-
- $item_info = array(
- 'name' => $dbObject['name'],
- 'title' => $dbObject['title'],
- 'description' => $dbObject['description'],
- 'createdate' => $dbObject['createdate'],
- 'takendate' => $dbObject['timetaken'],
- 'size' => $dbObject['size'],
- 'resolutionx' => (int)$dbObject['resolutionx'],
- 'resolutiony' => (int)$dbObject['resolutiony'],
- 'rotated' => (0 === (int)$dbObject['version'] % 2) ? false : true,
- 'rotate_version'=> (int)$dbObject['version'],
- 'rotation' => (int)$dbObject['rotation'],
- 'lat' => $dbObject['lat'],
- 'lng' => $dbObject['lng']
- );
- if (isset($dbObject['pos'])) {
- $item['pos'] = (int) $dbObject['pos'];
- }
-
- if (isset($dbObject['gps_idx'])) {
- $item['gps_idx'] = $dbObject['gps_idx'];
- }
-
- $coverPath = $dbObject['path'];
- $blThumbRotated = (0 === (int)$dbObject['version'] % 2) ? false : true;
-
- $sharepath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
- $dir = in_array(dirname($sharepath), array('.', ''), true) ? '/' : dirname($sharepath);
- // additional handler
- $item['info'] = $item_info;
- $item['additional'] = AlbumAPIUtil::FormAdditional('photo', $dbObject, $params);
-
- $isConversion = csSYNOPhotoMisc::IsAlbumAllowConversion($dir);
-
- AlbumAPIUtil::FillThumbStatus($item, $coverPath, $needThumbSize, $dbObject['resolutionx'], $dbObject['resolutiony'], $blThumbRotated, $isConversion);
- return $item;
- }
-
- static function EncodeItemId($id, $prefix) {
- if (!in_array($prefix, array('photo_', 'video_'))) {
- return $prefix.bin2hex($id);
- }
-
- $sharepath = substr($id, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
- $fileName = basename($sharepath);
- $sharename = dirname($sharepath);
- if ('.' === $sharename || '' === $sharename) {
- $sharename = '/';
- }
- return $prefix.bin2hex($sharename)."_".bin2hex($fileName);
- }
- }
-
- ?>
|