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