debug(getAttachs('uid', ['23389'], false));
dd(getAttachs('tid', 14524177, false));
dd(getAttachs('pid', $pid, true));
/**
* 根据相应的类型获取附件列表地址
* @param $idtype 类型 tid|pid|aid|uid
* @param $ids 目标ID列表 支持数组
* @param bool $direct_link 是否读取直链地址 不带域名 true 直链 false token链
* @return boolean|array
*/
function getAttachs($idtype, $ids, $direct_link = true)
{
global $_G;
if (!in_array($idtype, ['tid', 'pid', 'aid', 'uid'])) {
return false;
}
if (!is_array($ids)) {
$ids = explode(",", $ids);
}
$ids = array_map(function ($v) {
return intval($v);
}, $ids);
$requestmode = !empty($_GET['request']) && empty($_G['uid']);
$data = array_values(C::t('forum_attachment')->fetch_all_by_id($idtype, $ids));
$list = [];
foreach ($data as $v) {
$attach = C::t('forum_attachment_n')->fetch($v['tableid'], $v['aid'], false);
if (!$attach){
continue;
}
if ($direct_link) {
$attach['link'] = "/data/attachment/forum/{$attach['attachment']}";
} else {
//获取token请求附件
$token = [
$v['aid'],
!$requestmode ? substr(md5($v['aid'] . md5($_G['config']['security']['authkey']) . TIMESTAMP . $_G['uid']), 0, 8) : md5($v['aid'] . md5($_G['config']['security']['authkey']) . TIMESTAMP),
TIMESTAMP,
$_G['uid'],
$v['tableid']
];
$token = base64_encode(implode("|", $token));
$attach['link'] = "/forum.php?mod=attachment&aid=" . $token;
}
$list[] = $attach;
}
return $list;
}