3 * @file include/photos.php
4 * @brief Functions related to photo handling.
7 function getGps($exifCoord, $hemi) {
8 $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
9 $minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
10 $seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
12 $flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
14 return floatval($flip * ($degrees + ($minutes / 60) + ($seconds / 3600)));
17 function gps2Num($coordPart) {
18 $parts = explode('/', $coordPart);
20 if (count($parts) <= 0)
23 if (count($parts) == 1)
26 return floatval($parts[0]) / floatval($parts[1]);
30 * @brief Fetch the photo albums that are available for a viewer
32 * The query in this function is cost intensive, so it is cached.
34 * @param int $uid User id of the photos
35 * @param bool $update Update the cache
37 * @return array Returns array of the photo albums
39 function photo_albums($uid, $update = false) {
40 $sql_extra = permissions_sql($uid);
42 $key = "photo_albums:".$uid.":".local_user().":".remote_user();
43 $albums = Cache::get($key);
44 if (is_null($albums) OR $update) {
45 /// @todo This query needs to be renewed. It is really slow
46 // At this time we just store the data in the cache
47 $albums = qu("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`
48 FROM `photo` USE INDEX (`uid_album_created`)
49 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra
50 GROUP BY `album` ORDER BY `created` DESC",
52 dbesc('Contact Photos'),
53 dbesc(t('Contact Photos'))
55 Cache::set($key, $albums, CACHE_DAY);