已解決 ,處理帖子信息的問題,我一直在找獲取附件的問題。
- // 獲取帖子內容
- $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'].'" />';
- }
- }
復制代碼 |