Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.1KB

  1. <?php
  2. /**
  3. * @file include/photos.php
  4. * @brief Functions related to photo handling.
  5. */
  6. use Friendica\Core\Config;
  7. use Friendica\Core\PConfig;
  8. function getGps($exifCoord, $hemi) {
  9. $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
  10. $minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
  11. $seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
  12. $flip = ($hemi == 'W' || $hemi == 'S') ? -1 : 1;
  13. return floatval($flip * ($degrees + ($minutes / 60) + ($seconds / 3600)));
  14. }
  15. function gps2Num($coordPart) {
  16. $parts = explode('/', $coordPart);
  17. if (count($parts) <= 0)
  18. return 0;
  19. if (count($parts) == 1)
  20. return $parts[0];
  21. return floatval($parts[0]) / floatval($parts[1]);
  22. }
  23. /**
  24. * @brief Fetch the photo albums that are available for a viewer
  25. *
  26. * The query in this function is cost intensive, so it is cached.
  27. *
  28. * @param int $uid User id of the photos
  29. * @param bool $update Update the cache
  30. *
  31. * @return array Returns array of the photo albums
  32. */
  33. function photo_albums($uid, $update = false) {
  34. $sql_extra = permissions_sql($uid);
  35. $key = "photo_albums:".$uid.":".local_user().":".remote_user();
  36. $albums = Cache::get($key);
  37. if (is_null($albums) || $update) {
  38. if (!Config::get('system', 'no_count', false)) {
  39. /// @todo This query needs to be renewed. It is really slow
  40. // At this time we just store the data in the cache
  41. $albums = qu("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`, ANY_VALUE(`created`) AS `created`
  42. FROM `photo`
  43. WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra
  44. GROUP BY `album` ORDER BY `created` DESC",
  45. intval($uid),
  46. dbesc('Contact Photos'),
  47. dbesc(t('Contact Photos'))
  48. );
  49. } else {
  50. // This query doesn't do the count and is much faster
  51. $albums = qu("SELECT DISTINCT(`album`), '' AS `total`
  52. FROM `photo` USE INDEX (`uid_album_scale_created`)
  53. WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra",
  54. intval($uid),
  55. dbesc('Contact Photos'),
  56. dbesc(t('Contact Photos'))
  57. );
  58. }
  59. Cache::set($key, $albums, CACHE_DAY);
  60. }
  61. return $albums;
  62. }