3 * @file include/photos.php
4 * @brief Functions related to photo handling.
9 * @brief Get the permissions for the photos page
11 * @param int $owner_uid Owner of the photos page
12 * @param bool $community_page If it's an forum account
22 function photos_permissions($owner_uid, $community_page = 0) {
26 if((local_user()) && (local_user() == $owner_uid))
27 $arr['can_post'] = true;
29 if($community_page && remote_user()) {
30 if(is_array($_SESSION['remote'])) {
31 foreach($_SESSION['remote'] as $v) {
32 if($v['uid'] == $owner_uid) {
33 $arr['contact_id'] = $v['cid'];
38 if($arr['contact_id']) {
40 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
41 intval($arr['contact_id']),
45 $arr['can_post'] = true;
46 $arr['contact'] = $r[0];
47 $arr['remote_contact'] = true;
48 $arr['visitor'] = $cid;
54 // perhaps they're visiting - but not a community page, so they wouldn't have write access
56 if(remote_user() && (! $arr['visitor'])) {
57 $arr['contact_id'] = 0;
58 if(is_array($_SESSION['remote'])) {
59 foreach($_SESSION['remote'] as $v) {
60 if($v['uid'] == $owner_uid) {
61 $arr['contact_id'] = $v['cid'];
66 if($arr['contact_id']) {
67 $arr['groups'] = init_groups_visitor($arr['contact_id']);
68 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
69 intval($arr['contact_id']),
73 $arr['contact'] = $r[0];
74 $arr['remote_contact'] = true;
79 if(! $arr['remote_contact']) {
81 $arr['contact_id'] = $_SESSION['cid'];
82 $arr['contact'] = $a->contact;
90 * @brief Construnct a widget with last uploaded photos
92 * It displays the last 9 photos
94 * @param array $profile_data
95 *......'profile_uid'...=> The user.id of the profile (owner of the hotos)
96 *......'nickname'......=> Nick of the owner of the profile
97 *......'page-flags'....=> Account type of the profile
100 *......formatted html
102 * @template widget_photos.tpl
104 function widget_photos($profile_data) {
106 $community_page = (($profile_data['page-flags'] == PAGE_COMMUNITY) ? true : false);
107 $nickname = $profile_data['nickname'];
108 $owner_id = $profile_data['profile_uid'];
110 $phototypes = Photo::supportedTypes();
111 $photos_perms = photos_permissions($owner_id, $community_page);
113 $sql_extra = permissions_sql($owner_id, $photos_perms['remote_contact'], $photos_perms['groups']);
115 $r = q("SELECT `resource-id`, `id`, `filename`, `type`, max(`scale`) AS `scale` FROM `photo`
116 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' AND `album` != '%s'
117 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT 9",
119 dbesc('Contact Photos'),
120 dbesc( t('Contact Photos')),
121 dbesc( t('Profile Photos'))
127 $ext = $phototypes[$rr['type']];
131 'src' => z_root() . '/photos/' . $nickname . '/image/' . $rr['resource-id'],
132 'photo' => z_root() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
133 'alt_text' => $rr['filename'],
137 $tpl = get_markup_template('widget_photos.tpl');
138 $o .= replace_macros($tpl, array(
139 '$title' => t('Photos'),
140 '$photos' => $photos,
141 '$photo_albums_page' => z_root() . '/photos/' . $nickname,
142 '$photo_albums_page_title' => t('Vist the Photo Albums'),
149 function getGps($exifCoord, $hemi) {
150 $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
151 $minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
152 $seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
154 $flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
156 return floatval($flip * ($degrees + ($minutes / 60) + ($seconds / 3600)));
159 function gps2Num($coordPart) {
160 $parts = explode('/', $coordPart);
162 if (count($parts) <= 0)
165 if (count($parts) == 1)
168 return floatval($parts[0]) / floatval($parts[1]);