【即将关站通知●已关闭注册功能】,倒计时剩余:计算中...

discuz x帖子内容[attach]转html


之前用过
{echo discuzcode($value['message'], 0, 0, 0, 1, 1, 0, 0, 0, 0, 0);}
或者
require_once libfile('function/discuzcode');
{echo discuzcode($value['message']);}

能转大部分UBB,但是[attach]转不了。

下面是来自网络的代码,针对attach。
我用的时候做了一些修改。

  1. <?php

  2. $thread_info = DB::fetch_first ( "select a.`tid`, a.`authorid`, a.`author`,a.`dateline`, a.`subject`, b.`message`,b.`pid`, c.`attachment` as thumb, c.`remote` from " . DB::table ( 'forum_thread' ) . " a left join " . DB::table ( 'forum_post' ) . " b on b.tid=a.tid left join " . DB::table ( 'forum_threadimage' ) . " c on c.tid=a.tid where b.pid=$pid");
  3. require_once libfile ( 'function/discuzcode' );
  4. $thread_info ['dateline'] = date ( "Y-m-d H:i:s", $thread_info ['dateline'] );
  5. $thread_info ['message'] = discuzcode ( $thread_info ['message'] );
  6. if (preg_match_all ( "/\[attach\](\d+)\[\/attach\]/i", $thread_info ['message'], $matchaids )) {
  7. $attach_ids = $matchaids [1];
  8. }
  9. $attach_list = array ();
  10. foreach ( $attach_ids as $aid ) {
  11. $find = "/\[attach\]$aid\[\/attach\]/i";
  12. $thread_info ['message'] = preg_replace ( $find, get_lw_attach_path ( $aid ), $thread_info ['message'], 1 );
  13. $thread_info ['message'] = preg_replace ( $find, '', $thread_info ['message'] );
  14. }
  15. function get_lw_attach_path($aid) {
  16. global $_G;
  17. $return = $filename = '';
  18. if ($attach = C::t ( 'forum_attachment_n' )->fetch ( 'aid:' . $aid, $aid, array (1,- 1) )) {
  19. return get_lw_attach_path_str ( $attach );
  20. }
  21. return $filename;
  22. }
  23. function get_lw_attach_path_str($attach) {
  24. global $_G;
  25. if (! $attach ['isimage']) {
  26. return '<a href="' . $_G ['siteurl'] . 'forum.php?mod=attachment&aid=' . aidencode ( $attach ['aid'] ) . '">' . $attach ['filename'] . '</a>';
  27. }
  28. if ($attach ['remote']) {
  29. $imgurl = $_G ['setting'] ['ftp'] ['attachurl'] . 'forum/' . $attach ['attachment'];
  30. return '<p><img onclick="viewimage(this);" src="' . $imgurl . '" style="max-width:834px"/></p>';
  31. } else {
  32. if (preg_match ( '/^(?!http:)/', $attach ['url'] )) {
  33. $attach ['url'] = $_G ['siteurl'] . 'data/attachment/forum/' . $attach ['url'];
  34. }
  35. $imgurl = $attach ['url'] . $attach ['attachment'] . ($_G ['gp_width'] ? '&width=' . $_G ['gp_width'] : '') . ($_G ['gp_height'] ? '&height=' . $_G ['gp_height'] : '');
  36. return '<p><a href="' . $imgurl . '" target="_blank"><img height="320" width="320" src="' . $imgurl . '" /></a></p>';
  37. }
  38. }

  39. ?>
复制代码

条件where b.pid=$pid,如果只调用主题帖内容,改为where a.tid=$tid and b.first=1。
$pid或$tid使用时需要先获得。

在调用帖子内容时,另外涉及到权限问题,如密码、隐藏内容、查看权限、主题售价等等。
收藏 邀请

路过

雷人

握手

鲜花

鸡蛋


最新评论

在线支持
关闭
欢迎来到魔趣吧
如果你有建站技术问题、仿站需求、模板插件修改需求,请联系我们的技术支持!高效率,低价格的帮你搞定!
请认准魔趣吧唯一官网:www.moqu8.com,谨防假冒网站!

一般问题请到【求助区】发帖咨询(免费)!

邮箱咨询:
winkill2012@qq.com

邮箱咨询需注明:资源地址+本站用户名+具体问题,三者缺一不做处理。非本站资源不处理!
在线支持

关于魔趣吧|魔趣建站

魔趣吧,志在打造全国最大的建站资源共享平台。 本站提供海量免费的建站资源,包括WordPress模板、Discuz精仿模板、PHPWind模板、phpcms模板、Discuz精仿插件、帝国cms模板、织梦模板等上万精品模板!同时,提供各种建站素材、JS特效、整站程序源码!
服务中文站长,传播分享精神!建站,就来魔趣吧!!
2015-2024 魔趣吧 ( 豫ICP备2021024354号 )   豫公网安备41030402000182号 百度统计
HTTPS安全认证
|网站地图 | 已运行:天 
温馨提示:本站所有资源、教程、源码,不得用于非法站点及用途,否则,本站将终止提供任何服务! Powered by Discuz! Licensed