<?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;
}

class DeDeTitle
{
	var $id;
    var $text;
    var $font;
    var $path;
    function __csetruct($t,$id)
    {
        if($t)
        {
            $this->text = $t;
            $this->id = $id;
        }
        $this->font = DEDEINC.'/data/fonts/STXINGKA.TTF';
    }
    function DeDeTitle($t)
    {
        $this->__csetruct($t);
    }

    function TextConv()
    {
        global $cfg_soft_lang;
        if($cfg_soft_lang!='utf-8')
        {
            return gb2utf8($this->text);
        }
        return $this->text;
    }
    function C($color,$rgb)
    {   
        if(strlen($color)==4)
        {
            for($i=1;$i<4;$i++)
            {
                $str .= str_repeat($color[$i],2);
            }
            $color = '#'.$str;
        }
        switch($rgb)
        {
            case 'R':    return hexdec(substr($color, 1, 2));
            case 'B':    return hexdec(substr($color, 3, 2));
            case 'G':    return hexdec(substr($color, 5, 2));
        }
    }
    function Titlepath()
    {
        global $cfg_medias_dir;
        $name = strtotime(date('y-m-d H:i:s')).'.gif';
        //$name = $this->text.'.gif';
        $path = '/uploads/title/';
        if(!is_dir($path))
        {
            CreateDir($path);
        }
        return $path.$name;
    }
    function Show()
    {
        if(!file_exists(DEDEROOT.$this->Titlepath()))
        {
            $this->Make();
        }
        global $cfg_cmsurl;
        return  '<img src="'.$cfg_cmsurl.$this->Titlepath().'" alt="'.$this->text.'" />';
    }
    function Make()
    {
        $image = imagecreatetruecolor($this->width,$this->height);
        $bg = ImageColorAllocate($image,$this->C($this->bg,'R'),$this->C($this->bg,'B'),$this->C($this->bg,'G'));
        $color = ImageColorAllocate($image,$this->C($this->color,'R'),$this->C($this->color,'B'),$this->C($this->color,'G'));
        ImageFilledRectangle($image,0,0,$this->width,$this->height,$bg);
        imagettftext($image,$this->size, 0, $this->size/2, ($this->height+$this->size)/2, $color, $this->font,$this->TextConv());
        imagegif($image,DEDEROOT.$this->Titlepath());
        imagedestroy($image);
    }
}


function getarctag($aid){
	global $dsql;
	$contnum=0;
	$tags = '';
	$dsql->SetQuery("Select i.tag From `#@__taglist` t left join  `#@__tagindex` i on i.id=t.tid where t.aid='$aid' limit 0,9");
	$dsql->Execute('tag',$query);
	while($row = $dsql->GetArray('tag',MYSQL_ASSOC)){
	if(!empty($row['tag']))$contnum++;
	$tags .= "<a href='/tags/".urlencode($row['tag']).".html' target='_blank'>".$row['tag']."</a>";
	}
	if($contnum>0)$tags =$tags;
	return $tags;
	
}

//转换手机版路径
function wapurl($pcurl){
	global $cfg_basehost,$cfg_weburl;
	return str_replace($cfg_basehost,$cfg_weburl,$pcurl);
}
