3 function photo_init(&$a) {
31 $uid = str_replace('.jpg', '', $person);
33 $r = q("SELECT * FROM `photo` WHERE `scale` = %d AND `uid` = %d AND `profile` = 1 LIMIT 1",
38 $data = $r[0]['data'];
40 if(x($data) === false) {
41 $data = file_get_contents(($resolution == 5)
42 ? 'images/default-profile-sm.jpg'
43 : 'images/default-profile.jpg');
49 $photo = str_replace('.jpg','',$photo);
51 if(substr($photo,-2,1) == '-') {
52 $resolution = intval(substr($photo,-1,1));
53 $photo = substr($photo,0,-2);
56 $r = q("SELECT `uid` FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d LIMIT 1",
62 $owner = $r[0]['uid'];
64 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
66 if(local_user() && ($owner == $_SESSION['uid'])) {
68 // Owner can always see his/her photos
72 elseif(remote_user()) {
74 // authenticated visitor - here lie dragons
76 $groups = init_groups_visitor($_SESSION['visitor_id']);
77 $gs = '<<>>'; // should be impossible to match
79 foreach($groups as $g)
80 $gs .= '|<' . intval($g) . '>';
84 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
85 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
86 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
87 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
89 intval($_SESSION['visitor_id']),
90 intval($_SESSION['visitor_id']),
96 // Now we'll see if we can access the photo
98 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d $sql_extra LIMIT 1",
104 $data = $r[0]['data'];
109 if(x($data) === false) {
111 return; // NOTREACHED
114 header("Content-type: image/jpeg");
115 header('Expires: ' . datetime_convert('UTC','UTC', 'now + 30 minutes', 'D, d M Y H:i:s' . ' GMT'));
116 header('Expires: ' . datetime_convert('UTC','UTC', 'now + 30 minutes', 'D, d M Y H:i:s' . ' GMT'));
117 header("Cache-Control: max-age=3600, must-revalidate");