Play images and video from Synology PhotoStation server

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?
  2. class Decorator {
  3. static function CategoryFormula ($dbObject, $config = array())
  4. {
  5. $encodedId = $config['id'];
  6. $categroy = array();
  7. $category['id'] = $encodedId ? $encodedId : 'category_'.$dbObject['id'];
  8. $category['name'] = $dbObject['name'];
  9. $category['hidden'] = $dbObject['hidden'];
  10. return $category;
  11. }
  12. static function AlbumFormula($dbObject, $config = array())
  13. {
  14. $allowComment = $config['allowComment'];
  15. $showAlbumHit = $config['showAlbumHit'];
  16. $id = $config['id'];
  17. $param = $config['param'];
  18. $needThumbSize = isset($config['needThumbSize']) ? $config['needThumbSize'] : in_array('thumb_size', $param['additional']);
  19. $sharepath = $dbObject['sharename'];
  20. $item_info = AlbumAPIUtil::FormAlbum($dbObject, $allowComment, $showAlbumHit);
  21. if (!in_array('thumbnail', $param['ignore'])) {
  22. $result = csSYNOPhotoAlbum::GetAlbumInstance()->GetAlbumCover($sharepath);
  23. $coverPath = $result['coverPath'];
  24. }
  25. list($orig_resolutionx, $orig_resolutiony, $blThumbRotated) = AlbumAPIUtil::GetCoverResolutionRotation($coverPath);
  26. // replace conversion with the first layer album's
  27. $item_info['conversion'] = csSYNOPhotoMisc::IsAlbumAllowConversion($sharepath);
  28. $item = array(
  29. 'info' => $item_info,
  30. 'id' => $id ? $id : self::EncodeItemId($sharepath, 'album_'),
  31. 'type' => 'album',
  32. 'additional' => AlbumAPIUtil::FormAdditional('album', $dbObject, $param)
  33. );
  34. AlbumAPIUtil::FillThumbStatus($item, $coverPath, $needThumbSize, $orig_resolutionx, $orig_resolutiony, $blThumbRotated, $item_info['conversion']);
  35. return $item;
  36. }
  37. static function SmartFormula($dbObject, $config = array())
  38. {
  39. $param = $config['param'];
  40. $id = $config['id'];
  41. $needThumbSize = isset($config['needThumbSize']) ? $config['needThumbSize'] : in_array('thumb_size', $param['additional']);
  42. $smartAlbum['id'] = $id ? $id : self::EncodeItemId($dbObject['name'], 'smart_');
  43. $smartAlbum['type'] = 'smart';
  44. $album = SmartAlbum::GetSmartAlbumInstance()->GetCoverOfSmartAlbumByName($dbObject['name']);
  45. $smartAlbum['thumbnail_status'] = 'default';
  46. if (false === $album['success'] && !isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user'])) {
  47. return -1;
  48. }
  49. $coverPath = '';
  50. if ($album['success'] && isset($album['cover']['dbPath'])) {
  51. $coverPath = $album['cover']['dbPath'];
  52. $relativePath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
  53. $dirname = dirname($relativePath);
  54. $sharename = in_array($dirname, array('.', ''), true) ? '/' : $dirname;
  55. }
  56. $smartAlbum['name'] = $dbObject['name'];
  57. if (in_array('smart_condition', $param['additional'])) {
  58. $smartAlbumCond = SmartAlbum::GetSmartAlbumInstance()->GetSmartCondition($dbObject['name']);
  59. $smartAlbum['additional']['smart_condition'] = $smartAlbumCond;
  60. }
  61. $blConversion = csSYNOPhotoMisc::IsAlbumAllowConversion($sharename);
  62. list($orig_resolutionx, $orig_resolutiony, $blThumbRotated) = AlbumAPIUtil::GetCoverResolutionRotation($coverPath);
  63. AlbumAPIUtil::FillThumbStatus($smartAlbum, $coverPath, $needThumbSize, $orig_resolutionx, $orig_resolutiony, $blThumbRotated, $blConversion);
  64. return $smartAlbum;
  65. }
  66. static function TagFormula($dbObject, $config = array())
  67. {
  68. $param = $config['param'];
  69. $needThumbSize = isset($config['needThumbSize']) ? $config['needThumbSize'] : in_array('thumb_size', $param['additional']);
  70. $id = $config['id'];
  71. $tag['id'] = $id ? $id : 'tag_'.$dbObject['id'];
  72. $tag['type'] = 'tag';
  73. $tag['tag_type'] = Label::GetCategoryName($dbObject['category']);
  74. $tag['name'] = $dbObject['name'];
  75. $additional = self::TagAdditional($dbObject, $param);
  76. if (null !== $additional) {
  77. $tag['additional'] = $additional;
  78. }
  79. if ('true' === $param['thumbnail_status']) {
  80. $result = csSYNOPhotoAlbum::GetAlbumInstance()->GetLabelAlbumCoverFromDB($dbObject['id']);
  81. $coverPath = $result['dbPath'];
  82. $relativePath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
  83. $dirname = dirname($relativePath);
  84. $sharename = in_array($dirname, array('.', ''), true) ? '/' : $dirname;
  85. $blConversion = csSYNOPhotoMisc::IsAlbumAllowConversion($sharename);
  86. list($orig_resolutionx, $orig_resolutiony, $blThumbRotated) = AlbumAPIUtil::GetCoverResolutionRotation($coverPath);
  87. AlbumAPIUtil::FillThumbStatus($tag, $coverPath, $needThumbSize, $orig_resolutionx, $orig_resolutiony, $blThumbRotated, $blConversion);
  88. }
  89. return $tag;
  90. }
  91. private static function TagAdditional($data, $params)
  92. {
  93. if (in_array('info', $params['additional'])) {
  94. if (Label::PEOPLE === $data['category']) {
  95. $people['name'] = $data['name'];
  96. $additional['info'] = $people;
  97. } elseif (Label::GEO === $data['category']) {
  98. $geo['name'] = $data['name'];
  99. if (false !== ($extra = json_decode($data['info'], true))) {
  100. $geo['lat'] = $extra['lat'];
  101. $geo['lng'] = $extra['lng'];
  102. $geo['place_id'] = $extra['placeId'];
  103. $geo['address'] = (null === $extra['address']) ? '' : $extra['address'];
  104. }
  105. $additional['info'] = $geo;
  106. } elseif (Label::DESC === $data['category']) {
  107. $desc['name'] = $data['name'];
  108. $additional['info'] = $desc;
  109. }
  110. }
  111. if (in_array('extra', $params['additional'])) {
  112. $additional['extra'] = $data['info'];
  113. }
  114. if (in_array('count', $params['additional'])) {
  115. $total = ItemLabel::GetCountByLabelId($data['id']);
  116. $additional['count'] = (int)$total;
  117. }
  118. return $additional;
  119. }
  120. static function VideoFormula($dbObject, $config = array())
  121. {
  122. $params = $config['param'];
  123. $needThumbSize = $config['needThumbSize'] ? $config['needThumbSize'] : in_array('thumb_size', $params['additional']);
  124. $item = array(
  125. 'id' => $config['id'] ? $config['id'] : self::EncodeItemId($dbObject['path'], "video_"),
  126. 'type' => 'video'
  127. );
  128. $customTitleDesc = csSYNOPhotoDB::GetDBInstance()->GetVideoCustomizedTitleDescription($dbObject['path']);
  129. $item_info = array(
  130. 'name' => $dbObject['name'],
  131. 'title' => empty($customTitleDesc['title']) ? $dbObject['name'] : $customTitleDesc['title'],
  132. 'description' => $customTitleDesc['description'],
  133. 'createdate' => $dbObject['date'],
  134. 'takendate' => $dbObject['mdate'],
  135. 'size' => $dbObject['filesize'],
  136. 'duration' => (int)$dbObject['duration'],
  137. 'gps' => json_decode($dbObject['gps']),
  138. 'rotation' => (int)$dbObject['rotation']
  139. );
  140. if (isset($dbObject['pos'])) {
  141. $item['pos'] = (int) $dbObject['pos'];
  142. }
  143. $coverPath = $dbObject['path'];
  144. $sharepath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
  145. $dir = in_array(dirname($sharepath), array('.', ''), true) ? '/' : dirname($sharepath);
  146. // additional handler
  147. $item['info'] = $item_info;
  148. $item['additional'] = AlbumAPIUtil::FormAdditional('video', $dbObject, $params);
  149. $isConversion = csSYNOPhotoMisc::IsAlbumAllowConversion($dir);
  150. AlbumAPIUtil::FillThumbStatus($item, $coverPath, $needThumbSize, $dbObject['resolutionx'], $dbObject['resolutiony'], false, $isConversion);
  151. return $item;
  152. }
  153. static function PhotoFormula($dbObject, $config = array())
  154. {
  155. $params = $config['param'];
  156. $needThumbSize = $config['needThumbSize'] ? $config['needThumbSize'] : in_array('thumb_size', $params['additional']);
  157. $item = array(
  158. 'id' => $config['id'] ? $config['id'] : self::EncodeItemId($dbObject['path'], "photo_"),
  159. 'type' => 'photo'
  160. );
  161. $item_info = array(
  162. 'name' => $dbObject['name'],
  163. 'title' => $dbObject['title'],
  164. 'description' => $dbObject['description'],
  165. 'createdate' => $dbObject['createdate'],
  166. 'takendate' => $dbObject['timetaken'],
  167. 'size' => $dbObject['size'],
  168. 'resolutionx' => (int)$dbObject['resolutionx'],
  169. 'resolutiony' => (int)$dbObject['resolutiony'],
  170. 'rotated' => (0 === (int)$dbObject['version'] % 2) ? false : true,
  171. 'rotate_version'=> (int)$dbObject['version'],
  172. 'rotation' => (int)$dbObject['rotation'],
  173. 'lat' => $dbObject['lat'],
  174. 'lng' => $dbObject['lng']
  175. );
  176. if (isset($dbObject['pos'])) {
  177. $item['pos'] = (int) $dbObject['pos'];
  178. }
  179. if (isset($dbObject['gps_idx'])) {
  180. $item['gps_idx'] = $dbObject['gps_idx'];
  181. }
  182. $coverPath = $dbObject['path'];
  183. $blThumbRotated = (0 === (int)$dbObject['version'] % 2) ? false : true;
  184. $sharepath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
  185. $dir = in_array(dirname($sharepath), array('.', ''), true) ? '/' : dirname($sharepath);
  186. // additional handler
  187. $item['info'] = $item_info;
  188. $item['additional'] = AlbumAPIUtil::FormAdditional('photo', $dbObject, $params);
  189. $isConversion = csSYNOPhotoMisc::IsAlbumAllowConversion($dir);
  190. AlbumAPIUtil::FillThumbStatus($item, $coverPath, $needThumbSize, $dbObject['resolutionx'], $dbObject['resolutiony'], $blThumbRotated, $isConversion);
  191. return $item;
  192. }
  193. static function EncodeItemId($id, $prefix) {
  194. if (!in_array($prefix, array('photo_', 'video_'))) {
  195. return $prefix.bin2hex($id);
  196. }
  197. $sharepath = substr($id, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
  198. $fileName = basename($sharepath);
  199. $sharename = dirname($sharepath);
  200. if ('.' === $sharename || '' === $sharename) {
  201. $sharename = '/';
  202. }
  203. return $prefix.bin2hex($sharename)."_".bin2hex($fileName);
  204. }
  205. }
  206. ?>