phpwind8.7修改图库模式为直接用外链

时间: 2012-09-12 / 分类: phpwind / 浏览次数: 2,312 views / 0个评论 发表评论

首先我找到了74行$threadBehavior = getThreadFactory($cyid, $search, $topicsearch);

发现这个函数是根据传入的参数生成一个类名,比如图库帖子就是imgThread,普通帖子就是commonThread,并对他实例化

在1001行发现了这个类class imgThread extends baseThread {扩展自基本帖子类

然后大刀阔斧地修改把

因为我的帖子全是采集的,图片也全是外链的,所以我的想法是:直接读取帖子的第一张图片作为图库贴的封面图片

所以就做了下面的修改

 

class imgThread extends baseThread {
 
 function getThreadCount() {
  //return $this->db->get_value('SELECT COUNT(*) AS count FROM pw_threads_img WHERE fid=' . S::sqlEscape($this->fid) . ' AND ifcheck=1');
  return $this->db->get_value('SELECT COUNT(*) AS count FROM pw_threads WHERE fid=' . S::sqlEscape($this->fid) . ' AND ifcheck=1');
 }

 function getThread($start, $allowtop) {
  list($offset, $limit2, $tpcdb, $R) = $this->getThreadSortWithToppedThread(true, $start);
  //$query = $this->db->query("SELECT t.*,ti.cover,ti.totalnum,ti.collectnum,ti.ifthumb FROM pw_threads_img ti LEFT JOIN pw_threads t ON ti.tid=t.tid WHERE ti.fid=" . S::sqlEscape($this->fid) . " AND ti.ifcheck=1 AND ti.topped=0 ORDER BY {$this->threadSearch->order} {$this->threadSearch->asc} " . S::sqlLimit($offset, $limit2));
$query = $this->db->query("SELECT t.*,m.content FROM  pw_threads t left join pw_tmsgs m on t.tid=m.tid  WHERE t.fid=" . S::sqlEscape($this->fid) . " AND t.ifcheck=1 AND t.topped=0 ORDER BY t.tid {$this->threadSearch->asc} " . S::sqlLimit($offset, $limit2));//获取帖子内容
  while ($thread = $this->db->fetch_array($query)) {
   preg_match_all("/<img.*src\s*=\s*[\"|\']?\s*([^>\"\'\s]*)/i", $thread['content'], $matches);//匹配图片
$thread['cover']=$matches[1][0];//把图片网址赋值给数组

   $tpcdb[] = $thread;
  }
  $this->db->free_result($query);
  $R && $tpcdb = array_reverse($tpcdb);
  return $this->parseThread($tpcdb);
 }

 function setWhere() {
  global $search,$type;
  $this->threadSearch->setType($type);
  $this->threadSearch->setImg($search);
  $this->threadSearch->setOrder();
 }

 function getThreadSortWithToppedThread($allowtop, $start) {
  global $count;
  $R = 0;
  $tpcdb = array();
  $asc = $this->threadSearch->asc;
  if ($allowtop) {
   global $foruminfo,$db_perpage;
   $toptids = trim($foruminfo['topthreads'], ',');

   //$rows = !$toptids ? 0 : (int)$this->db->get_value("SELECT COUNT(*) FROM pw_threads_img WHERE tid IN($toptids) LIMIT 1");;
   $rows = !$toptids ? 0 : (int)$this->db->get_value("SELECT COUNT(*) FROM pw_threads WHERE tid IN($toptids) LIMIT 1");;
   if ($start < $rows) {
    $L = (int)min($rows – $start, $db_perpage);
    $limit  = S::sqlLimit($start,$L);
    $offset = 0;
    $limit2 = $L == $db_perpage ? '' : $db_perpage – $L;
    if ($toptids) {
     $query = $this->db->query("SELECT * FROM pw_threads  WHERE tid IN($toptids) ORDER BY topped DESC,tid DESC $limit");
     while ($rt = $this->db->fetch_array($query)) {
      $tpcdb[] = $rt;
     }
     $this->db->free_result($query);
    }
    unset($toptids,$L,$limit);
   } else {
    list($offset,$limit2,$asc,$R) = getstart($start – $rows, $asc, $count);
   }
  } else {
   list($offset,$limit2,$asc,$R) = getstart($start, $asc, $count);
  }
  $this->threadSearch->asc = $asc;
  return array($offset, $limit2, $tpcdb, $R);
 }
}

 

然后发现图库贴的封面图是经过模板处理的,把处理步骤去掉,直接用原图网址

打开模板\template\wind\thread_maintucool.htm

大概72行去掉处理

$attachImg =$thread['cover']; //$attachsService->getThreadAttachMini($thread['cover'],$thread['ifthumb']);

顺便把图库的图片统计也去掉了

<span class="imgNum" title="共有{$thread[totalnum]}张图片" style="display:none; ">{$thread[totalnum]}</span>

OK了~

当然,有一些不完美的地方,比如不能乱分表了,不然会出错,不过我的是小站,一般不分

发现个比较好的地方,如果外链图片失效,一下子就可以找到那个帖子了

修改后的例子:http://www.netroquality.com/thread-htm-fid-5-search-img.html#tabA

发表评论

你必须 登录后 才能留言!