3 function photo_init(&$a) {
19 $default = 'images/default-profile.jpg';
34 $default = 'images/default-profile-mm.jpg';
39 $default = 'images/default-profile-sm.jpg';
43 $uid = str_replace('.jpg', '', $person);
45 $r = q("SELECT * FROM `photo` WHERE `scale` = %d AND `uid` = %d AND `profile` = 1 LIMIT 1",
50 $data = $r[0]['data'];
53 $data = file_get_contents($default);
63 $photo = str_replace('.jpg','',$photo);
65 if(substr($photo,-2,1) == '-') {
66 $resolution = intval(substr($photo,-1,1));
67 $photo = substr($photo,0,-2);
70 $r = q("SELECT `uid` FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
76 $owner = $r[0]['uid'];
78 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
80 if(local_user() && ($owner == $_SESSION['uid'])) {
82 // Owner can always see his/her photos
86 elseif(remote_user()) {
88 // authenticated visitor - here lie dragons
90 $groups = init_groups_visitor($_SESSION['visitor_id']);
91 $gs = '<<>>'; // should be impossible to match
93 foreach($groups as $g)
94 $gs .= '|<' . intval($g) . '>';
98 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
99 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
100 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
101 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
103 intval($_SESSION['visitor_id']),
104 intval($_SESSION['visitor_id']),
110 // Now we'll see if we can access the photo
112 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d $sql_extra LIMIT 1",
118 $data = $r[0]['data'];
122 // Does the picture exist? It may be a remote person with no credentials,
123 // but who should otherwise be able to view it. Show a default image to let
124 // them know permissions was denied. It may be possible to view the image
125 // through an authenticated profile visit.
126 // There won't be many completely unauthorised people seeing this because
127 // they won't have the photo link, so there's a reasonable chance that the person
128 // might be able to obtain permission to view it.
130 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
135 $data = file_get_contents('images/nosign.jpg');
146 header("Content-type: image/jpeg");