Discuz后台批量重建主题封面功能修改
我们知道,dz默认的主题中如果发布图片2个以上的图片是在其中选择一张(据观察是取图片的宽度最大的作为封面)作为主题的封面,以供前台相应调用,对于某些情况,我们可能需要特定某个图片作为封面,显然默认的就不能实现这个效果,下面做出修改,实现第一张作为主题封面。1、找到admincp_counter.php,搜索
} elseif(submitcheck('setthreadcover', 1)) {
$fid = intval($_GET['fid']);
$allthread = intval($_GET['allthread']);
if(empty($fid)) {
cpmsg('counter_thread_cover_fiderror', 'action=counter', 'error');
}
$nextlink = "action=counter¤t=$next&pertask=$pertask&setthreadcover=yes&fid=$fid&allthread=$allthread";
$starttime = strtotime($_GET['starttime']);
$endtime = strtotime($_GET['endtime']);
$timesql = '';
if($starttime) {
$timesql .= " AND lastpost > $starttime";
$nextlink .= '&starttime='.$_GET['starttime'];
}
if($endtime) {
$timesql .= " AND lastpost < $endtime";
$nextlink .= '&endtime='.$_GET['endtime'];
}
$processed = 0;
$foruminfo = C::t('forum_forum')->fetch_info_by_fid($fid);
if(empty($foruminfo['picstyle'])) {
cpmsg('counter_thread_cover_fidnopicstyle', 'action=counter', 'error');
}
if($_G['setting']['forumpicstyle']) {
$_G['setting']['forumpicstyle'] = dunserialize($_G['setting']['forumpicstyle']);
empty($_G['setting']['forumpicstyle']['thumbwidth']) && $_G['setting']['forumpicstyle']['thumbwidth'] = 214;
empty($_G['setting']['forumpicstyle']['thumbheight']) && $_G['setting']['forumpicstyle']['thumbheight'] = 160;
} else {
$_G['setting']['forumpicstyle'] = array('thumbwidth' => 214, 'thumbheight' => 160);
}
require_once libfile('function/post');
$coversql = empty($allthread) ? 'AND cover=\'0\'' : '';
$cover = empty($allthread) ? 0 : null;
$_G['forum']['ismoderator'] = 1;
foreach(C::t('forum_thread')->fetch_all_by_fid_cover_lastpost($fid, $cover, $starttime, $endtime, $current, $pertask) as $thread) {
$processed = 1;
$pid = C::t('forum_post')->fetch_threadpost_by_tid_invisible($thread['tid'], 0);
$pid = $pid['pid'];
//setthreadcover($pid);在下面添加如下代码:
$attachs = C::t('forum_attachment_n')->fetch_all_by_id('pid:' . $pid, 'pid', $pid, 'aid asc', true);
$attachs = array_values($attachs);
if($attachs) {
setthreadcover($pid, 0, $attachs['aid']);
} else {
setthreadcover($pid);
}上传更新即可。
原理:系统默认调用的是setthreadcover($pid),而我们改成根据pid获取第一个图片附件的aid,然后传入setthreadcover函数,这个函数的第三个参数是决定用哪个附件来做封面的,如果为空则根据图片width来获取了。
页:
[1]