function getattach($pid, $posttime = 0, $aids = '') { global $_G; require_once libfile('function/attachment'); $attachs = $imgattachs = array(); $aids = $aids ? explode('|', $aids) : array(); if ($aids) { $aidsnew = array(); foreach ($aids as $aid) { if ($aid) { $aidsnew[] = intval($aid); } } $aids = "aid IN (" . dimplode($aidsnew) . ") AND"; } else { $aids = ''; } $sqladd1 = $posttime > 0 ? "AND af.dateline>'{$posttime}'" : ''; if (!empty($_G['fid']) && $_G['forum']['attachextensions']) { $allowext = str_replace(' ', '', strtolower($_G['forum']['attachextensions'])); $allowext = explode(',', $allowext); } else { $allowext = ''; } $query = DB::query("SELECT a.*, af.*\r\n\t\tFROM " . DB::table('forum_attachment') . " a\r\n\t\tLEFT JOIN " . DB::table('forum_attachment_unused') . " af USING(aid)\r\n\t\tWHERE {$aids} (af.uid='{$_G['uid']}' AND a.tid='0' {$sqladd1}) ORDER BY a.aid DESC"); while ($attach = DB::fetch($query)) { $attach['filenametitle'] = $attach['filename']; $attach['ext'] = strtolower(fileext($attach['filename'])); if ($allowext && !in_array($attach['ext'], $allowext)) { continue; } getattach_row($attach, $attachs, $imgattachs); } if ($pid > 0) { $query = DB::query("SELECT a.*, af.*\r\n\t\t\tFROM " . DB::table('forum_attachment') . " a\r\n\t\t\tLEFT JOIN " . DB::table(getattachtablebytid($_G['tid'])) . " af USING(aid)\r\n\t\t\tWHERE a.pid='{$pid}' ORDER BY a.aid DESC"); while ($attach = DB::fetch($query)) { $attach['filenametitle'] = $attach['filename']; $attach['ext'] = fileext(strtolower($attach['filename'])); if ($allowext && !in_array($attach['ext'], $allowext)) { continue; } getattach_row($attach, $attachs, $imgattachs); } } return array('attachs' => $attachs, 'imgattachs' => $imgattachs); }
function getattach($pid, $posttime = 0, $aids = '') { global $_G; require_once libfile('function/attachment'); $attachs = $imgattachs = array(); $aids = $aids ? explode('|', $aids) : array(); if ($aids) { $aidsnew = array(); foreach ($aids as $aid) { if ($aid) { $aidsnew[] = intval($aid); } } $aids = "aid IN (" . dimplode($aidsnew) . ") AND"; } else { $aids = ''; } $sqladd1 = $posttime > 0 ? "AND af.dateline>'{$posttime}'" : ''; if (!empty($_G['fid']) && $_G['forum']['attachextensions']) { $allowext = str_replace(' ', '', strtolower($_G['forum']['attachextensions'])); $allowext = explode(',', $allowext); } else { $allowext = ''; } foreach (C::t('forum_attachment')->fetch_all_unused_attachment($_G['uid'], empty($aidsnew) ? null : $aidsnew, $posttime > 0 ? $posttime : null) as $attach) { $attach['filenametitle'] = $attach['filename']; $attach['ext'] = fileext($attach['filename']); if ($allowext && !in_array($attach['ext'], $allowext)) { continue; } getattach_row($attach, $attachs, $imgattachs); } if ($pid > 0) { $attachmentns = C::t('forum_attachment_n')->fetch_all_by_id('tid:' . $_G['tid'], 'pid', $pid); foreach (C::t('forum_attachment')->fetch_all_by_id('pid', $pid, 'aid') as $attach) { $attach = array_merge($attach, $attachmentns[$attach['aid']]); $attach['filenametitle'] = $attach['filename']; $attach['ext'] = fileext($attach['filename']); if ($allowext && !in_array($attach['ext'], $allowext)) { continue; } getattach_row($attach, $attachs, $imgattachs); } } return array('attachs' => $attachs, 'imgattachs' => $imgattachs); }