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

function GetMemberInfos($fields,$mid){
global $dsql;          if($mid <= 0){
$revalue =  "Error";          }        
else{            
$row=$dsql->GetOne("select * from dede_member where mid = '{$mid}'");            
if(!is_array($row)){
$revalue = "Not user";            
}              else{
$revalue = $row[$fields];            
}        
}        
return $revalue;    
}
//自定义缩略图大小
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.'_'.$width.'_'.$height.'.'.$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 Get_firstbigimg($aid){
	global $dsql;
	$imgurls='';
	$row1=$dsql->getone("Select channel From `#@__archives` where id='$aid'");
	$channel_type=$row1['channel']; 
  if($channel_type==2)
	{
  	   $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]; //
  	   $get_firestimg=trim($get_firestimg);

	} 
  elseif($channel_type==1)
    {
	   $imgurls='';
	   $row=$dsql->getone("Select body From `#@__addonarticle` where aid='$aid' ");
	   $string=$row['body']; 
	   preg_match ("<img.*src=[\"](.*?)[\"].*?>",$string,$match);
	   $get_firestimg=$match[1];
	   $get_firestimg=trim($get_firestimg);
	}
	$get_firestimg='http://www.u18a.com'.trim($get_firestimg);//改为你自己的域名就ok了，返回的是一个绝对地址。二级域名绑定也没问题
	return $get_firestimg;
   }
//用户信息提取
//$fields要提取的信息
//$mid用户id
function GetMember_Infos($fields,$mid){
  global $dsql;  
  if($mid <= 0){
      $revalue =  "Error";  
	 }         
  else{             
      $row=$dsql->GetOne("select * from dede_member where mid = '$mid'");    
      if(!is_array($row)){
         $revalue = "Not user";             
        }            
	  else{
		  if($row[$fields]=='')
		     $revalue='/member/templets/images/dfboy.png';
		  else
             $revalue = $row[$fields];             
        }         
      }         
   return $revalue;     
}

function GetMember_article($num,$mid)
{
	global $dsql; 
	$sql="select * from dede_archives where mid = '$mid' and arcrank=0 limit ".$num;
	$dsql->SetQuery($sql);
    $dsql->Execute(); 
	while($row = $dsql->GetArray()){ 
	$row1=$dsql->getone("Select * From `#@__arctype` where id='".$row['typeid']."'");
        $arr[]=$row['title']; 
		$aid[]=$row['id'];
		$litpic[]=$row['litpic'];
		$arturl[]=GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],$row['arcrank'],$row1['namerule'],$row1['typedir'],$row['money'],$row['filename'],$row1['moresite'],$row1['siteurl'],$row1['sitepath']);
     } 
    for($i=0;$i<count($aid);$i++)
      {
	    $str.='<a href="'.$arturl[$i].'" class="m-thumb"><img src="'.$litpic[$i].'" width="60" height="60" title='.$arr[$i].'></a>';
	  }
        return $str;
	}
function get_articl_feedback($aid)
{
	/*global $dsql;
	$dsql->SetQuery("Select count(id) as c from  #@__member_stow where aid=".$aid);
	$row = $dsql -> getone();
	$str= $row['c'];*/
	return "ghj";
	}
function get_tagid($tag)
{
	global $dsql; 
	$TagInfos = $dsql->GetOne("Select * From `#@__tagindex` where tag like '$tag' ");
	return $TagInfos["id"];
	}
	
if ( ! function_exists('getheight'))  

{  

 function getheight($litpic){  

 $litpicc = $GLOBALS['cfg_basehost'].$litpic;  

 $arr  = getimagesize($litpicc);  

 $resault = $arr[1];   // 此为高度  

 //$resault = $arr[0];    //此为宽度  

 return $resault;  

 }  

}


//获取TAG静态地址，  by NIC QQ:2384419
function nic_tag_url($tid)
{
	global $dsql;
	$sql = "select * from #@__tagindex  where id='$tid' ";
    if ($arcRow = $dsql->GetOne($sql)){     
	   
	   //$str = $GLOBALS['cfg_cmspath']."/tag/".ceil($tid/100)."/".Getpinyin($arcRow["tag"])."_".$tid."_1.html";  //目录结构为：每100个ID为一个目录，从 /tag/1/ 开始
       
	   $pinyin_title = GetPinyin(stripslashes($arcRow["tag"]));
       $pinyin_title = str_replace("?","",$pinyin_title);
	   $pinyin_title = str_replace(":","",$pinyin_title);
	   $str = $GLOBALS['cfg_cmspath']."/tag/".$pinyin_title."_".$tid."_1.html";  //目录结构为：/tag/拼音_ID_1.html 开始
	}else $str="ID为$tid的TAG已被删除！";

	return $str;
}


//获取指定文章的TAG到相关TAG列表页的地址，  by NIC QQ:2384419
function nic_arc_tag_link($aid)
{
	global $dsql;
	$sql = "select tid from #@__taglist  where aid='$aid' group by tid ";
    $dsql->Execute('ala',$sql);
	while($row=$dsql->GetObject('ala')){ 
	   $url=nic_tag_url($row->tid);
       if ($arcRow = $dsql->GetOne("select * from #@__tagindex  where id='".$row->tid."' ")) $tag=$arcRow["tag"];
	   else $tag="";
	   $str.=" <a href='".$url."' target=_blank><b>".$tag."</b></a> ";
	}
	return $str;
}

//通过文章栏目获得匹配的TAG静态地址，  by NIC QQ:2384419
function typename_tag_url($tag)
{
	global $dsql;
	$sql = "select * from #@__tagindex  where tag='$tag' ";
    if ($arcRow = $dsql->GetOne($sql)){     
	   //$str = $GLOBALS['cfg_cmspath']."/tag/".ceil($tid/100)."/".Getpinyin($arcRow["tag"])."_".$tid."_1.html";  //目录结构为：每100个ID为一个目录，从 /tag/1/ 开始
	   $pinyin_title = GetPinyin(stripslashes($arcRow["tag"]));
       $pinyin_title = str_replace("?","",$pinyin_title);
	   $pinyin_title = str_replace(":","",$pinyin_title);
	   $str = $GLOBALS['cfg_cmspath']."/tag/".$pinyin_title."_".$arcRow["id"]."_1.html";  //目录结构为：/tag/拼音_ID_1.html 开始
	}else $str = "";
	return $str;
}
//根据频道标签id获得这个tag分类下所有的tag标签
function nic_type_tag_link($typeid,$dqtag)
{
	global $dsql;
	$sql = "select typename from #@__arctype  where reid='$typeid' group by id ";
    $dsql->Execute('ala',$sql);
	while($row=$dsql->GetObject('ala')){ 
		   $url=typename_tag_url($row->typename);
      if($url!='')
	  {
		   if($row->typename==$dqtag)
		   {
			 $str.="<a href='#' class='tag cur'><span>".$row->typename."</span></a>";  
			   }
		   else
		   {
			 $str.="<a href='$url' class='tag '><span>".$row->typename."</span></a>";  
			   }
	  }
	}	
	
	return $str;
}
//根据顶级栏目或是当前tag获得该频道下所有的tag
function nic_top_tag_link($topid,$dqtag)
{
	global $dsql;
	if($topid!='')
	{
		$sql = "select id from #@__arctype where topid='$topid' and typename='tag'";
        if ($tagRow = $dsql->GetOne($sql))
	    {
			$sql = "select * from #@__arctype  where reid=".$tagRow["id"]." group by id ";
    		$dsql->Execute('ala1',$sql);
			while($row1=$dsql->GetObject('ala1'))
			{ 
		  		$str.="<div class='tag-group-name'>".$row1->typename."</div>";
				$str.=" <div class='tag-list clearfix'>".nic_type_tag_link($row1->id,$dqtag)."</div>";   
		    	$str.="<div class='tag-group-line'></div>";
	    	}
   		}
	}

return $str;
}

function get_dqtag_tag_link($dqtag)
{
	global $dsql;
	$sql = "select typeid from #@__tagindex  where tag='$dqtag' ";
    if ($dqtagRow = $dsql->GetOne($sql))
		{
			$sql = "select topid from #@__arctype where id='".$dqtagRow['typeid']."'";
       		if ($tagRow = $dsql->GetOne($sql))
			 {
				$str=nic_top_tag_link($tagRow["topid"],$dqtag);
				 }

			}
	return $str;
}

//通过文档id获取文档所属会员分类或专辑
function get_archyfl($id)
{
	global $dsql;
	$sql="select typeid,mtype from dede_archives where id = '$id'";
    if ($arcflRow = $dsql->GetOne($sql))     
	{
		if($arcflRow['mtype']=='0')
		{
			$str=nic_arc_tag_link($id);
		}
		else
		{
			$sql = "select mtypename from #@__mtypes where mtypeid='".$arcflRow['mtype']."'";
       		if ($tagRow = $dsql->GetOne($sql))
			 {
				$str=$tagRow["mtypename"];
				 }
			}
		
	}
	
	return $str;
	
	}
//获取指定专辑的前几条文档缩略图
function getalbum_litpic($mtypeid,$num)
{
	global $dsql; 
	$str="";
	$sql="select * from dede_archives where mtype = '$mtypeid' limit ".$num;
	$dsql->Execute('ala1',$sql);
	while($row1=$dsql->GetObject('ala1')){
		if($str=="") 
	  		$str="\"".thumb($row1->litpic,72,72)."\"";
		else
			$str=$str.","."\"".thumb($row1->litpic,72,72)."\"";
	}
	return $str;
	}
//获取指定专辑的前几条文档缩略图
function getalbum_litpic_db($mtypeid,$num)
{
	global $dsql; 
	$str="";
	$sql="select * from dede_archives where mtype = '$mtypeid' order by id desc limit ".$num;
	$dsql->Execute('ala1',$sql);
	$j=0;
	while($row1=$dsql->GetObject('ala1')){
		$j++;
		if($j==3)
		{
			$str=$str."<span class='last'><img src='".thumb($row1->litpic,72,72)."' width='72' height='72'></span>";
		}
		else
		{
			$str=$str."<span><img src='".thumb($row1->litpic,72,72)."' width='72' height='72'></span>";
			}
	}
	return $str;
	}
//获取指定文档收藏数量
function get_stow_count($aid)
{
	global $dsql;
	$dsql->SetQuery("Select count(id) as c from  #@__member_stow where aid=".$aid);
	$row = $dsql -> getone();
	return $row['c'];
	
	}
//获取指定文档评论数量
function get_feedback_count($aid)
{
	global $dsql;
	$dsql->SetQuery("Select count(id) as c from  #@__feedback where aid=".$aid);
	$row = $dsql -> getone();
	return $row['c'];
	}
function check_arcrank($arcrank)
{
	$str="";
	if($arcrank=='-1')
		$str='<span class="sc" title="正在审核中"></span>';
	return $str;
	}
?>