<?php
function litimgurls($imgid=0)
{
    global $lit_imglist,$dsql;
    //获取附加表
    $row = $dsql->GetOne("SELECT c.addtable FROM #@__archives AS a LEFT JOIN #@__channeltype AS c 
                                                            ON a.channel=c.id where a.id='$imgid'");
    $addtable = trim($row['addtable']);
    
    //获取图片附加表imgurls字段内容进行处理
    $row = $dsql->GetOne("Select imgurls From `$addtable` where aid='$imgid'");
    
    //调用inc_channel_unit.php中ChannelUnit类
    $ChannelUnit = new ChannelUnit(2,$imgid);
    
    //调用ChannelUnit类中GetlitImgLinks方法处理缩略图
    $lit_imglist = $ChannelUnit->GetlitImgLinks($row['imgurls']);
    
    //返回结果
    return $lit_imglist;
}
   // 提取图集第一张大图，为arclist用
	
function Get_firstbigimg($aid){
	global$dsql;
	$imgurls='';
	$row=$dsql->getone("Select imgurls From #@__addonimages where aid='$aid' ");
	$imgurls=$row['imgurls']; 
	preg_match_all("/{dede:img[^>]+}(.*){\/dede:img/isU",$imgurls,$imgurlsed);
    $get_firestimg = $imgurlsed[1][0]; //
    return $get_firestimg;
	} 
// 提取文章第一张大图，为arclist用
function Get_bodyimg($aid){
	global$dsql;
	$imgurls='';
	$row=$dsql->getone("Select * From `#@__addonarticle` where aid='$aid' ");
	$body=$row['body']; 
	preg_match_all("/(src)=[\"|'| ]{0,}([^>]*\.(gif|jpg|bmp|png))/isU",$body,$img_array);
	$img_array = array_unique($img_array[2]);
	if(count($img_array)>0)
    {
        $picname = preg_replace("/[\"|'| ]{1,}/", '', $img_array[0]);
    }
    return $picname;
	} 		
//图集总数
function Getimgnum($aid){
	global$dsql;
	$imgurls='';
	$row=$dsql->getone("Select imgurls From #@__addonimages where aid='$aid' ");
	   $imgurls=$row['imgurls'];  
	    preg_match_all("/{dede:img (.*){\/dede:img/isU",$imgurls,$wordcount);
		$count=count($wordcount[1]);
		return$count;
	} 

//自定义缩略图大小
function thumb($imgurl, $width, $height, $bg = true)
{
global $cfg_mainsite,$cfg_multi_site;
 $thumb = eregi("http://",$imgurl)?str_replace($cfg_mainsite,'',$imgurl):$imgurl;
 list($thumbname,$extname) = explode('.',$thumb);
 $newthumb = $thumbname.'_L.'.$extname;
 if(!$thumbname || !$extname || !file_exists(DEDEROOT.$thumb)) return $imgurl;
 if(!file_exists(DEDEROOT.$newthumb))
 {
 include_once DEDEINC.'/image.func.php';
 if($bg==true)
 {
 ImageResize(DEDEROOT.$thumb, $width, $height, DEDEROOT.$newthumb);
}
 else
{
ImageResize(DEDEROOT.$thumb, $width, $height, DEDEROOT.$newthumb);
 }
 }
 return $cfg_multi_site=='Y'?$cfg_mainsite.$newthumb:$newthumb;
 }
 //头文件函数调用
 function pasterTempletDiy($path)
{
  require_once(DEDEINC."/arc.partview.class.php");
  global $cfg_basedir,$cfg_templets_dir;
  $tmpfile = $cfg_basedir.$cfg_templets_dir."/".$path;//模版文件的路径
  $dtp = new PartView();
  $dtp->SetTemplet($tmpfile);
  $dtp->Display();
}