|
楼主 |
发表于 2023-5-20 15:41:03
|
显示全部楼层
已解决 ,处理帖子信息的问题,我一直在找获取附件的问题。
- // 获取帖子内容
- $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid);
- // 获取所有附件的信息
- $attachments = array();
- $used_attachments = array();
- $attachs = C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$post['tid'], 'tid', $post['tid']);
- $attachs = $attachs ? $attachs : array();
- foreach($attachs as $attach) {
- if($attach['isimage']) {
- $attach['url'] = $_G['siteurl'] . 'data/attachment/forum/' . $attach['attachment'];
- $attachments[$attach['aid']] = $attach;
- }
- }
- // 处理帖子内容
- $post['message'] = preg_replace_callback("/\[attach\](\d+)\[\/attach\]/i", function($matches) use ($attachments, &$used_attachments) {
- $aid = $matches[1];
- if(isset($attachments[$aid])) {
- // 记录已经被引用的附件
- $used_attachments[$aid] = $aid;
- return '<img src="'.$attachments[$aid]['url'].'" />'; // 你需要根据你的情况来修改这里的代码,使其返回正确的图片链接
- } else {
- return '';
- }
- }, $post['message']);
- // 附加未被引用的附件到帖子内容的末尾
- foreach ($attachments as $aid => $attachment) {
- if (!isset($used_attachments[$aid])) {
- $post['message'] .= '<img src="'.$attachment['url'].'" />';
- }
- }
复制代码 |
|