之前用过
{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。
我用的时分做了一些修正。

<?php

$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");
require_once libfile ( 'function/discuzcode' );
$thread_info ['dateline'] = date ( "Y-m-d H:i:s", $thread_info ['dateline'] );
$thread_info ['message'] = discuzcode ( $thread_info ['message'] );
if (preg_match_all ( "/\[attach\](\d+)\[\/attach\]/i", $thread_info ['message'], $matchaids )) {
$attach_ids = $matchaids [1];
}
$attach_list = array ();
foreach ( $attach_ids as $aid ) {
$find = "/\[attach\]$aid\[\/attach\]/i";
$thread_info ['message'] = preg_replace ( $find, get_lw_attach_path ( $aid ), $thread_info ['message'], 1 );
$thread_info ['message'] = preg_replace ( $find, '', $thread_info ['message'] );
}
function get_lw_attach_path($aid) {
global $_G;
$return = $filename = '';
if ($attach = C::t ( 'forum_attachment_n' )->fetch ( 'aid:' . $aid, $aid, array (1,- 1) )) {
return get_lw_attach_path_str ( $attach );
}
return $filename;
}
function get_lw_attach_path_str($attach) {
global $_G;
if (! $attach ['isimage']) {
return '<a href="' . $_G ['siteurl'] . 'forum.php?mod=attachment&aid=' . aidencode ( $attach ['aid'] ) . '">' . $attach ['filename'] . '</a>';
}
if ($attach ['remote']) {
$imgurl = $_G ['setting'] ['ftp'] ['attachurl'] . 'forum/' . $attach ['attachment'];
return '<p><img onclick="viewimage(this);" src="' . $imgurl . '" style="max-width:834px"/></p>';
} else {
if (preg_match ( '/^(?!http:)/', $attach ['url'] )) {
$attach ['url'] = $_G ['siteurl'] . 'data/attachment/forum/' . $attach ['url'];
}
$imgurl = $attach ['url'] . $attach ['attachment'] . ($_G ['gp_width'] ? '&width=' . $_G ['gp_width'] : '') . ($_G ['gp_height'] ? '&height=' . $_G ['gp_height'] : '');
return '<p><a href="' . $imgurl . '" target="_blank"><img height="320" width="320" src="' . $imgurl . '" /></a></p>';
}
}

?>


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

在调用帖子内容时,别的涉及到权限问题,如暗码、躲藏内容、检查权限、主题价格等等。

声明:有的资源均来自网络转载,版权归原作者所有,如有侵犯到您的权益 请联系邮箱:123456@qq.com 我们将配合处理!

原文地址:discuz x帖子内容[attach]转html发布于2023-02-16 16:17:49

相关推荐