时间:2021-07-01 10:21:17 帮助过:4人阅读
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].='
这个你找原插件作者去瞅瞅吧!