]> git.mxchange.org Git - friendica.git/blob - include/photos.php
02d1b174039f4a1956b03cfb7459c08ff79120e0
[friendica.git] / include / photos.php
1 <?php
2 /**
3  * @file include/photos.php
4  * @brief Functions related to photo handling.
5  */
6
7 use \Friendica\Core\Config;
8 use \Friendica\Core\PConfig;
9
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;
14
15         $flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
16
17         return floatval($flip * ($degrees + ($minutes / 60) + ($seconds / 3600)));
18 }
19
20 function gps2Num($coordPart) {
21         $parts = explode('/', $coordPart);
22
23         if (count($parts) <= 0)
24                 return 0;
25
26         if (count($parts) == 1)
27                 return $parts[0];
28
29         return floatval($parts[0]) / floatval($parts[1]);
30 }
31
32 /**
33  * @brief Fetch the photo albums that are available for a viewer
34  *
35  * The query in this function is cost intensive, so it is cached.
36  *
37  * @param int $uid User id of the photos
38  * @param bool $update Update the cache
39  *
40  * @return array Returns array of the photo albums
41  */
42 function photo_albums($uid, $update = false) {
43         $sql_extra = permissions_sql($uid);
44
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`
52                                 FROM `photo`
53                                 WHERE `uid` = %d  AND `album` != '%s' AND `album` != '%s' $sql_extra
54                                 GROUP BY `album`, `created` ORDER BY `created` DESC",
55                                 intval($uid),
56                                 dbesc('Contact Photos'),
57                                 dbesc(t('Contact Photos'))
58                         );
59                 } else {
60                         // This query doesn't do the count and is much faster
61                         $albums = qu("SELECT DISTINCT(`album`), '' AS `total`
62                                 FROM `photo`
63                                 WHERE `uid` = %d  AND `album` != '%s' AND `album` != '%s' $sql_extra
64                                 GROUP BY `album`, `created` ORDER BY `created` DESC",
65                                 intval($uid),
66                                 dbesc('Contact Photos'),
67                                 dbesc(t('Contact Photos'))
68                         );
69                 }
70                 Cache::set($key, $albums, CACHE_DAY);
71         }
72         return $albums;
73 }