今天一位站长找到我,希望修改下dz的批量重建封面功能,默认情况下,dz的批量设置封面不是选择的第一张图,而是根据图片的宽度,图片最宽的会选为封面图。
但是实际情况,更多的是站长希望把第一张图设置为封面,今天我就来解决这个问题:
直接上代码吧:
} 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);
// 获取最小的aid
$attachs = C::t('forum_attachment_n')->fetch_all_by_id('pid:' . $pid, 'pid', $pid, 'aid asc', true);
$attachs = array_values($attachs);
if($attachs[0]) {
setthreadcover($pid, 0, $attachs[0]['aid']);
} else {
setthreadcover($pid);
}
}
if($processed) {
cpmsg("$lang[counter_thread_cover]: ".cplang('counter_processing', array('current' => $current, 'next' => $next)), $nextlink, 'loading');
} else {
cpmsg('counter_thread_cover_succeed', 'action=counter', 'succeed');
}
}
上面代码就是重建主题封面的代码,定义在admincp_counter.php文件里。加粗部分就是我添加的代码,默认情况下系统调用的是setthreadcover($pid),而我们改成根据pid获取第一个图片附件的aid,然后传入setthreadcover函数,这个函数的第三个参数是决定用哪个附件来做封面的,如果为空则根据图片width来获取了。
有关PHP系统、Discuz或网站等各种问题,可以联系QQ1069971363寻求付费支持
|