久久久久av_欧美日韩一区二区在线_国产精品三区四区_日韩中字在线

如何獲取discuz帖子的所有附件信息?

3921 1 1提示:支持鍵盤翻頁<-左 右-> qzuser1212 發(fā)表于 2023-5-20 15:01 帖子模式

最近在做discuz的api插件,用來對接小程序和app。目前有個問題,就是插入帖子的圖片能顯示,但是沒有插入的附件無法顯示,獲取附件的代碼如下,請教下怎么才能獲取到發(fā)帖時所有上傳的圖片附件(包括沒有插入帖子 ... 查看全文

    組圖打開中,請稍候......

評論1個評論

qzuser1212發(fā)表于  2023-5-20 15:41:03
已解決 ,處理帖子信息的問題,我一直在找獲取附件的問題。
  1. // 獲取帖子內容
  2. $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid);

  3. // 獲取所有附件的信息
  4. $attachments = array();
  5. $used_attachments = array();
  6. $attachs = C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$post['tid'], 'tid', $post['tid']);
  7. $attachs = $attachs ? $attachs : array();
  8. foreach($attachs as $attach) {
  9.     if($attach['isimage']) {
  10.         $attach['url'] = $_G['siteurl'] . 'data/attachment/forum/' . $attach['attachment'];

  11.         $attachments[$attach['aid']] = $attach;
  12.     }
  13. }

  14. // 處理帖子內容
  15. $post['message'] = preg_replace_callback("/\[attach\](\d+)\[\/attach\]/i", function($matches) use ($attachments, &$used_attachments) {
  16.     $aid = $matches[1];
  17.     if(isset($attachments[$aid])) {
  18.         // 記錄已經(jīng)被引用的附件
  19.         $used_attachments[$aid] = $aid;
  20.         return '<img src="'.$attachments[$aid]['url'].'" />'; // 你需要根據(jù)你的情況來修改這里的代碼,使其返回正確的圖片鏈接
  21.     } else {
  22.         return '';
  23.     }
  24. }, $post['message']);

  25. // 附加未被引用的附件到帖子內容的末尾
  26. foreach ($attachments as $aid => $attachment) {
  27.     if (!isset($used_attachments[$aid])) {
  28.         $post['message'] .= '<img src="'.$attachment['url'].'" />';
  29.     }
  30. }
復制代碼
  • 關注公眾號
  • 有償服務微信
  • 有償服務QQ

手機版|小黑屋|Discuz! 官方交流社區(qū) ( 皖ICP備16010102號 |皖公網(wǎng)安備34010302002376號 )|網(wǎng)站地圖|star

GMT+8, 2025-9-19 02:44 , Processed in 0.071073 second(s), 33 queries .

Powered by Discuz! W1.0 Licensed

Copyright © 2001-2025 Discuz! Team.

關燈 在本版發(fā)帖
有償服務QQ
有償服務微信
返回頂部
快速回復 返回頂部 返回列表