这个插件呢,是仿贴吧的,在帖子列表显示缩略图,是我很喜欢的一种风格,适用于x3.0,但是为了客户端,我只能用x2.5版本,这个插件在x2.5不工作,无法生成缩略图我就是想改一改代码,让其在x2.5环境下工作,自用,不商用。
在x3.0下,是能生成一个存放缩略图的文件夹,里面存放有缩略图。但是在2.5下,没有发现这个文件夹,所以感觉在build这一步出了问题。
下面贴出thumbbuilder.class.php这个文件的代码,请高手分析一下,为什么没有在data/attachment/下生成tiebalist这个文件夹。
basedir=!$_g['setting']['attachdir'] ? (discuz_root.'data/attachment/'):$_g['setting']['attachdir']; $this->baseurl=!$_g['setting']['attachurl'] ? ('data/attachment/'):$_g['setting']['attachurl']; } private function getcoverpath($tid){ return 'tiebalist/'.substr(md5($tid), 0, 2).'/'.substr(md5($tid), 2, 2).'/'; } public function getthreadcovers($tid,$aids){ $coverpath=$this->getcoverpath($tid); $fullpath=$this->basedir.$coverpath; $fullurl=$this->baseurl.$coverpath; $images=array(); foreach($aids as $aid){ if (file_exists($fullpath.$aid.'.jpg')) $images[]=array('aid'=>$aid,'thumbfile'=>$fullurl.$aid.'.jpg'); } return $images; } public function createthreadcovers($tid,$images,$force=0){ $path=$this->basedir.$this->getcoverpath($tid); dmkdir($path); global $_g; $setting=&$_g['cache']['plugin']['chs_tiebalist']; $thumbheight=$setting['thumbheight']?$setting['thumbheight']:80; $thumbmaxwidth=$setting['thumbmaxwidth']?$setting['thumbmaxwidth']:300; foreach($images as $aid=>$image){ $target=$path.$aid.'.jpg'; if (file_exists($target)&&(!$force)) continue; try { $thumb = phpthumbfactory::create($image,array('resizeup'=>true)); $dimensions=$thumb->getcurrentdimensions(); $newwidth=$thumbheight*$dimensions['width']/$dimensions['height']; if ($newwidth>$thumbmaxwidth) { $thumb->adaptiveresize($thumbmaxwidth,$thumbheight); }else { $thumb->resize(0,$thumbheight);//封面不限定宽度 } $thumb->save($target); }catch(exception $oex){//捕获生成缩略图可能抛出的异常,防止中断 writelog('tiebalistlog',$oex->getmessage()); continue; } } if ($force) { $thumbfiles=$this->getfiles($path,'jpg'); $aids=array_keys($images); foreach($thumbfiles as $filename){ $aid=intval(substr($filename,0,strpos($filename,'.'))); if (!in_array($aid,$aids)) unlink($path.$filename); } } } private function getfiles($dir,$mask=''){ $filearray=array(); if (false != ($handle = opendir ($dir))) { while (false!==($file=readdir($handle))){ if ($file == '.' || $file == '..') continue; if (empty($mask)) $filearray[]=$file; else if (substr(strrchr($file, '.'), 1)==$mask) $filearray[]=$file; } } return $filearray; }}?>
回复讨论(解决方案) buildthumb.inc.php内的内容,好像也有用处呢
$value){ $position=($value['special']==2)?2:1;//商品主题的首帖在第二楼,回复从第3楼开始 $firstpost=c::t('forum_post')->fetch_all_by_tid_position('tid:'.$value['tid'],$value['tid'],$position); if (count($firstpost)>0&&$firstpost[0]['invisible']>=0){ $post=&$firstpost[0]; $message=messagecutstr($post['message'],$messagelength); $tiebalist[$key] = ''.$message.'
'; $attachs=c::t('forum_attachment_n')->fetch_all_by_id('pid:'.$post['pid'],'pid',$post['pid'],false,true,false,false,$picturenum); $aids=array_keys($attachs); if ($aids){ $imagelist=$otb->getthreadcovers($value['tid'],$aids); if (count($imagelist)>0) { $tiebalist[$key].=''; foreach($imagelist as $ii=>$image){ $attach=$attachs[$image['aid']]; $forumimg=($attach['remote'] ? $_g['setting']['ftp']['attachurl'] : $_g['setting']['attachurl']).'forum/'.$attach['attachment']; $tiebalist[$key].=''; } $tiebalist[$key].=''; $tiebalist[$key].= ' 收起 | 查看帖子 | 左转 | 右转
'; } } } } return $tiebalist; } } function forumdisplay_threadlist_bottom() { global $_g; $setting=&$_g['cache']['plugin']['chs_tiebalist']; if (!$setting['enabled']) return; $fid = intval($_g['fid']); $forumselected=unserialize($setting['forumselected']); if(!in_array($fid,$forumselected)) return; $echo = ''; $echo .= ''; $picturemaxwidth=$setting['picturemaxwidth']?$setting['picturemaxwidth']:600; $echo .=''; return $echo; } function post_chs_tiebalist_message($params) { global $_g, $tid, $pid, $modthread, $isfirstpost; $setting=&$_g['cache']['plugin']['chs_tiebalist']; if (!$setting['enabled']) return; $fid = intval($_g['fid']); $forumselected=unserialize($setting['forumselected']); if(!in_array($fid,$forumselected)) return; list($msg, $url_forward, $values, $extraparam) = $params['param']; if (($msg == 'post_newthread_succeed')||($msg == 'post_newthread_mod_succeed')) { $pid = $modthread->pid; $this->create_covers($pid,$tid); dshowmessage($msg, $url_forward, $values, $extraparam); }else if (($msg == 'post_edit_succeed')&&$isfirstpost) { $tid=$_g['tid']; $this->create_covers($pid,$tid); dshowmessage($msg, $url_forward, $values, $extraparam); } } private function create_covers($pid,$tid){ global $_g; $setting=&$_g['cache']['plugin']['chs_tiebalist']; $picturenum=$setting['$picturenum']?$setting['$picturenum']:3; //获取帖子的图片 $attachs=c::t('forum_attachment_n')->fetch_all_by_id('pid:'.$pid,'pid',$pid,false,true,false,false,$picturenum); $images=array(); foreach($attachs as $attach){ $images[$attach['aid']]=($attach['remote'] ? $_g['setting']['ftp']['attachdir'] : $_g['setting']['attachdir']).'forum/'.$attach['attachment']; } if ($images){ require_once(thumbbuilder.class.php); $otb=new thumbbuilder(); $otb->createthreadcovers($tid,$images); } }}?>
这个你找原插件作者去瞅瞅吧!