]> git.mxchange.org Git - friendica.git/blob - include/photos.php
Merge pull request #3044 from rabuzarus/20161224_-_update_perfect_scrollbar
[friendica.git] / include / photos.php
1 <?php
2 /**
3  * @file include/photos.php
4  * @brief Functions related to photo handling.
5  */
6
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;
11
12         $flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
13
14         return floatval($flip * ($degrees + ($minutes / 60) + ($seconds / 3600)));
15 }
16
17 function gps2Num($coordPart) {
18         $parts = explode('/', $coordPart);
19
20         if (count($parts) <= 0)
21                 return 0;
22
23         if (count($parts) == 1)
24                 return $parts[0];
25
26         return floatval($parts[0]) / floatval($parts[1]);
27 }
28
29 /**
30  * @brief Fetch the photo albums that are available for a viewer
31  *
32  * The query in this function is cost intensive, so it is cached.
33  *
34  * @param int $uid User id of the photos
35  * @param bool $update Update the cache
36  *
37  * @return array Returns array of the photo albums
38  */
39 function photo_albums($uid, $update = false) {
40         $sql_extra = permissions_sql($uid);
41
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",
51                         intval($uid),
52                         dbesc('Contact Photos'),
53                         dbesc(t('Contact Photos'))
54                 );
55                 Cache::set($key, $albums, CACHE_DAY);
56         }
57         return $albums;
58 }