3 function attach_init(&$a) {
6 notice( t('Item not available.') . EOL);
10 $item_id = intval($a->argv[1]);
12 $r = q("SELECT * FROM `attach` WHERE `id` = %d LIMIT 1",
16 notice( t('Item was not found.'). EOL);
20 $owner = $r[0]['uid'];
22 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
24 if(local_user() && ($owner == $_SESSION['uid'])) {
26 // Owner can always see his/her photos
30 elseif(remote_user()) {
32 // authenticated visitor - here lie dragons
34 $groups = init_groups_visitor($_SESSION['visitor_id']);
35 $gs = '<<>>'; // should be impossible to match
37 foreach($groups as $g)
38 $gs .= '|<' . intval($g) . '>';
42 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
43 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
44 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
45 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
47 intval($_SESSION['visitor_id']),
48 intval($_SESSION['visitor_id']),
54 // Now we'll see if we can access the attachment
56 $r = q("SELECT * FROM `attach` WHERE `id` = '%d' $sql_extra LIMIT 1",
61 $data = $r[0]['data'];
64 notice( t('Permission denied.') . EOL);
68 header('Content-type: ' . $r[0]['filetype']);
69 header('Content-disposition: attachment; filename=' . $r[0]['filename']);