<?php
/**
 * TMBLOG 首页文件
 * ============================================================================
 * 版权所有 2008-2009 梧州腾马网络服务中心，并保留所有权利。
 * 网站地址: http://php.tmacn.cn；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: tm $
*/

function get_site_info()
{
    $sql = 'SELECT * ' .
            'FROM tm_php_info where id=1';
    $res = mysql_fetch_object(mysql_query($sql));

        $arr = array();
        $arr['title']= $res->title;
        $arr['cont']= $res->cont;
        $arr['foot'] = $res->foot;
		    $arr['bah'] = $res->bah;
		    $arr['url']= "http://".$_SERVER['SERVER_NAME'];
        return $arr;
}

function request_uri() 
{ 
if (isset($_SERVER['REQUEST_URI'])) 
{ 
$uri = $_SERVER['REQUEST_URI'];
} 
else 
{ 
if (isset($_SERVER['argv']))
{ 
$uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0]; 
} 
else 
{ 
$uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
} 
} 
$temp=array();
$temp=explode("/",$uri);
$uri="";
for($i=0;$i<(count($temp)-1);$i++)
    $uri.=$temp[$i]."/";
return $uri;
} 

function get_foot_info()
{
    $sql = 'SELECT * ' .
            'FROM tm_help_a order by id asc';
    $rsql = mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
        $arr[$i]['id']= $res->id;
        $arr[$i]['title']= $res->title;
		$i++;
		}
    return $arr;
}

function get_gree_info()
{
    $sql = 'SELECT * ' .
            'FROM tm_mune order by px asc';
    $rsql = mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
        $arr[$i]['url']= $res->url;
        $arr[$i]['title']= $res->title;
        $arr[$i]['id']= $res->id;
		$i++;
		}
		$rs=mysql_fetch_object(mysql_query("select * from tm_bq_setup where id=1"));
		if($rs->retsh==1)
		  {
        $arr[$i]['url']= "http://".$_SERVER['SERVER_NAME'].request_uri()."tmbq.php";
        $arr[$i]['title']= "博群";
		    $i++;
      }
    return $arr;
}

function get_category()
{
    $sql = 'SELECT * ' .
            'FROM tm_art_class order by px asc';
    $rsql = mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
        $arr[$i]['url']= "artlist.php?id=".$res->art_id;
        $arr[$i]['title']= $res->art_name;
		    $i++;
		}
    return $arr;
}


function get_pic_category()
{
$arr = array();
    $rs=mysql_fetch_object(mysql_query("select * from tm_pic_setup where id=1"));
    if($rs->retsh==1)
       {
    $sql = 'SELECT * ' .
            'FROM tm_pic_class order by px asc';
    $rsql = mysql_query($sql);
 
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
        $arr[$i]['url']= "pic.php?id=".$res->id;
        $arr[$i]['title']= $res->title;
        if($res->password<>"")
        $arr[$i]['title'].=" ( 密 )";
        $rs=mysql_fetch_object(mysql_query("select * from tm_pic_list where cid='$res->id'"));
		    if($rs)
		      $arr[$i]['img']=$rs->imgs;
		    else
		      $arr[$i]['img']="themes/default/images/nopic.jpg";
		    if($res->password<>"")
		      $arr[$i]['img']="themes/default/images/pass.jpg";
		    $i++;
		}
		}
    return $arr;
}

function get_user_px()
{
    $sql="select re_name,count(re_name) as name_num from tm_art_re group by re_name order by name_num DESC limit 30";
$rsql=mysql_query($sql);
while($rs=mysql_fetch_object($rsql))
{
        $arr[$i]['name']= $rs->re_name;
        $arr[$i]['num']= $rs->name_num;
		$i++;
		}
    return $arr;
}
function get_adtop_list()
{
    $sql = 'SELECT * ' .
            'FROM tm_ad_list  where adacer =0 order by id desc';
    $rsql = mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
	     if($res->adtype==0)
          $arr[$i]['code']= '<a href="'.$res->url.'" title="'.$res->name.'" target="_blank"><img src="'."http://".$_SERVER['SERVER_NAME'].request_uri().$res->img.'" alt="'.$res->name.'" /></a>';
		   else
		      $arr[$i]['code']= $res->adcode;
    $i++;
		}
    return $arr;
}
function get_adflash_list()
{
    $sql = 'SELECT * ' .
            'FROM tm_ad_list  where adacer =1 and adtype=0 order by id desc';
    $rsql = mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
          $arr[$i]['img']= $res->img;
          $arr[$i]['url']= $res->url;
          $arr[$i]['name']= $res->name;
    $i++;
		}
    return $arr;
}

function get_adright_list()
{
    $sql = 'SELECT * ' .
            'FROM tm_ad_list  where adacer =2 order by id desc';
    $rsql = mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
	     if($res->adtype==0)
          $arr[$i]['code']= '<a href="'.$res->url.'" target="_blank"><img src="'."http://".$_SERVER['SERVER_NAME'].request_uri().$res->img.'" borer=0 alt="'.$res->name.'"></a>';
		   else
		      $arr[$i]['code']= $res->adcode;
    $i++;
		}
    return $arr;
}

function get_gg_list()
{
    $sql = 'SELECT * ' .
            'FROM tm_about where tj=1 order by id desc limit 3';
    $rsql = mysql_query($sql);

   	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
		      $arr[$i]['title']= $res->title;
		      $arr[$i]['id']= $res->id;
		      $arr[$i]['date']= $res->date;
          $i++;
		    }
    return $arr;
}

function get_date_list()
{
    $arr = array();
	$sql="select art_date from tm_art order by art_date";
   $rsql=mysql_query($sql);
				 $art_gd=array();
				 $art_gdnum=array();
				 $i=0;
				 while($rs=mysql_fetch_object($rsql))
				    {
					 if($i==0) 
					   {
					   $art_gd[$i]=date("Y-m",strtotime($rs->art_date));
					   $art_gdnum[$i]=1;
					   $i++;
					   }
					 else
					   {
					   for($j=0;$j<count($art_gd);$j++)
					       if(date("Y-m",strtotime($rs->art_date))==$art_gd[$j])
						      {
							  $art_gdnum[$j]+=1;
							  break;
							  }
						if($j>=count($art_gd))
						   {
						   $art_gd[$i]=date("Y-m",strtotime($rs->art_date));
					   	   $art_gdnum[$i]=1;
						   $i++;
						   }
					   }
					}
				for($i=0;$i<count($art_gd);$i++)
				   {
				    $arr[$i]['url']= "date.php?sdate=".$art_gd[$i];
					$arr[$i]['title']= $art_gd[$i];
					$arr[$i]['tmblognum']=$art_gdnum[$i];
				   }
    return $arr;
}


function get_link_list()
{
    $sql="select * from tm_link where link_show=1 order by link_id desc";
		  $rsql=mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
        $arr[$i]['url']= $res->link_url;
        $arr[$i]['title']= $res->link_name;
		$i++;
		}
    return $arr;
}

function get_tag_list()
{

    $sql="select * from tm_tag where tag_show=1 order by num desc";
		  $rsql=mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
        $arr[$i]['id']= $res->tag_id;
        $arr[$i]['title']= $res->tag_name;
        $sql="select count(*) from tm_art where art_tag='$res->tag_id'";
$resultc=mysql_query($sql) or die(mysql_error());
$rsc=mysql_fetch_array($resultc);
$num=$rsc[0];
		    $arr[$i]['num']= $num;
		    $arr[$i]['fontnum']= rand(12,24);
		    $i++;
		}
    return $arr;
}


function get_art_tj()
{

    $sql="select tm_art.art_title,tm_art.art_date,tm_art.art_id,tm_art_class.filename from tm_art left join tm_art_class on tm_art.art_class=tm_art_class.art_id where tm_art.show1=1 and tj=1 order by tm_art.art_id DESC limit 20";
		  $rsql=mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
    $arr[$i]['url']= $res->filename."/".substr(ereg_replace('-',"",$res->art_date),0,6)."/".ereg_replace('-',"",$res->art_date).$res->art_id.".html";
    $arr[$i]['title']= $res->art_title;
		$i++;
		}
    return $arr;
}

function get_ret_list()
{
$i=0;
$sql="select tm_art_re.*,tm_art.art_class,tm_art.art_date from tm_art_re left join tm_art on tm_art_re.re_artid=tm_art.art_id order by tm_art_re.re_id desc limit 10";
$rsql=mysql_query($sql);
while($rs=mysql_fetch_object($rsql))
      {
    $rst=mysql_fetch_object(mysql_query("select filename from tm_art_class where art_id='$rs->art_class'"));
    $filename=$rst->filename;
    $arr[$i]['url']= $filename."/".substr(ereg_replace('-',"",$rs->art_date),0,6)."/".ereg_replace('-',"",$rs->art_date).$rs->re_artid.".html#comments";
    $arr[$i]['title']= mb_substr($rs->re_cont,0,20,"utf-8");
		$i++;
		}
    return $arr;
}

function get_art_info()
{
$sql="select count(*) from tm_art where show1=1";
$resultc=mysql_query($sql) or die(mysql_error());
$rsc=mysql_fetch_array($resultc);
$num=$rsc[0];
$size = 10;
if(isset($_GET['tm_page']))
   {
   $tm_page=trim($_GET['tm_page'])-1;
   if($tm_page<0)$tm_page=0;
   if($tm_page>(intval($num/$size)))$tm_page=intval($num/$size);
   }
else
	$tm_page=0;


    $sql="select tm_art.*,tm_art_class.art_name as cart_name,tm_art_class.filename from tm_art left join tm_art_class on tm_art.art_class=tm_art_class.art_id where tm_art.show1=1 order by tm_art.art_id DESC limit ".$size*$tm_page.",".$size;
		  $rsql=mysql_query($sql);

    $arr = array();
	$i=0;
	while($res=mysql_fetch_object($rsql))
	     {
    $arr[$i]['url']= $res->filename."/".substr(ereg_replace('-',"",$res->art_date),0,6)."/".ereg_replace('-',"",$res->art_date).$res->art_id.".html";
    if(!file_exists($arr[$i]['url']))
    $arr[$i]['url']="art.php?id=".$res->art_id;
    $arr[$i]['title']= $res->art_title;
    $arr[$i]['art_id']= $res->art_id;
    $arr[$i]['name']=$res->art_name;
    $arr[$i]['inname']=$res->art_zt;
		$arr[$i]['date']= $res->art_date;
		$arr[$i]['year']= substr($res->art_date,0,7);
		$arr[$i]['day']= substr($res->art_date,8,2);
		$arr[$i]['cid']=$res->art_class;
		$arr[$i]['cname']=$res->cart_name;
		$arr[$i]['curl']= "artlist.php?id=".$res->art_class;
		$arr[$i]['num']=$res->art_rq;
		$arr[$i]['img']=$res->img;
		if(!file_exists($arr[$i]['img']))
		   $arr[$i]['img']="themes/default/images/nopic.jpg";
		$arr[$i]['cont']=$res->art_key;
		$sql="select count(*) from tm_art_re where re_artid='$res->art_id'";
		$resultc=mysql_query($sql) or die(mysql_error());
		$rsc=mysql_fetch_array($resultc);
		$arr[$i]['rnum']=$rsc[0];
    $sql="select * from tm_tag where tag_id='$res->art_tag'";
		$resultc=mysql_query($sql) or die(mysql_error());
		$rsc=mysql_fetch_object($resultc);
		$arr[$i]['tag']=$rsc->tag_name;	
    $arr[$i]['tag_id']=$res->art_tag;	
		$i++;
		}
    return $arr;
}



function get_page_info()
{
$sql="select count(*) from tm_art where show1=1";
$resultc=mysql_query($sql) or die(mysql_error());
$rsc=mysql_fetch_array($resultc);
$num=$rsc[0];
$size = 10;
if(isset($_GET['tm_page']))
   {
   $tm_page=trim($_GET['tm_page'])-1;
   if($tm_page<0)$tm_page=0;
   if($tm_page>(intval($num/$size)))$tm_page=intval($num/$size);
   }
else
	$tm_page=0;
    $arr = array();
	$j=0;
	for($i=($tm_page>4?($tm_page-3):1);$i<=(ceil($num/$size)<9?ceil($num/$size):(ceil($num/$size)>($tm_page+5)?($tm_page+($tm_page>5?5:(9-$tm_page))):ceil($num/$size)));$i++)
	     {
		 $arr[0]['sum']=$num;
		 $arr[0]['num']=ceil($num/$size);
		 $arr[0]['page']=$size;
		 $arr[0]['nowpage']=$tm_page+1;
		 $arr[0]['fpage']="<a href='index.php?tm_page=1'>首页</a>";
		 if($tm_page>0)
		    $arr[0]['upage']="<a href=index.php?tm_page=".$tm_page.">上一页</a>";
		 if($tm_page<ceil($num/$size)-1)
		    $arr[0]['dpage']="<a href='index.php?tm_page=".($tm_page+2)."'>下一页</a> ";
		 $arr[0]['lpage']="<a href='index.php?tm_page=".round(ceil($num/$size))."'>末页</a>";
		 if(($tm_page+1)==($i))
           $arr[$j]['url']= '<span class="this-page">'.$i.'</span>';
		 else
		    $arr[$j]['url']="<a href='index.php?tm_page=".$i."'>".($i)."</a>";
		$j++;
		}
    return $arr;
}
function _get($str){  
$val = !empty($_GET[$str]) ? $_GET[$str] : null;  
return $val;  
}
function _post($str){  
$val = !empty($_POST[$str]) ? $_POST[$str] : null;  
return $val;  
}
?>