<?php

/*

'**************************************************************************************************

' 软件名称: 黑色幻想舞曲管理系统CMS2.0

' 版本编号: hshxsdj 2.0

' 官方网站: http://www..hshxs.com

' 官方论坛：http://bbs.hshxs.com

' 版权所有: 黑色幻想开发团队    噬己翼(QQ:532917920)

' 郑重声明:

'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；

'    2、黑色幻想网络事业部保留此软件的法律追究权利

'**************************************************************************************************

*/

@session_start();

date_default_timezone_set('PRC');

function ss_timing_start ($name = 'default') {

   global $ss_timing_start_times;

   $ss_timing_start_times[$name] = explode(' ',microtime());

}

function ss_timing_stop ($name = 'default') {

   global $ss_timing_stop_times;

   $ss_timing_stop_times[$name] = explode(' ',microtime());

}

function ss_timing_current ($name = 'default') {

   global $ss_timing_start_times,$ss_timing_stop_times;

   if (!isset($ss_timing_start_times[$name])) {

     return 0;

   }

   if (!isset($ss_timing_stop_times[$name])) {

     $stop_time = explode(' ',microtime());

   }else {

     $stop_time = $ss_timing_stop_times[$name];

   }

  $current = $stop_time[1] -$ss_timing_start_times[$name][1];

  $current += $stop_time[0] -$ss_timing_start_times[$name][0];

 return $current;

}

function IsNum($str){

   if( is_numeric($str) ){

     return true;

  }else{

    return false;

  }

}

function IsNul($str){

   if (!is_string($str)) return false;

   if (empty($str)) return false;

   if ($str=='') return false;

 return true;

}

function str_encode($str){

   $str=ReplaceStr($str,"<","&lt;");

   $str=ReplaceStr($str,">","&gt;");

   $str=ReplaceStr($str,"'","&apos;");

   $str=ReplaceStr($str," ","&nbsp;");

   $str=ReplaceStr($str,"\r\n","<br>");

   $str=ReplaceStr($str,"\"","&quot;");

   $str=ReplaceStr($str,"&","&amp;");

 return $str;

}

function str_decode($str){

   $str=ReplaceStr($str,"&lt;","<");

   $str=ReplaceStr($str,"&gt;",">");

   $str=ReplaceStr($str,"&apos;","'");

   $str=ReplaceStr($str,"&nbsp;"," ");

   $str=ReplaceStr($str,"<br>","\r\n");

   $str=ReplaceStr($str,"&quot;","\"");

   $str=ReplaceStr($str,"&amp;","&");

 return $str;

}

function SafeRequest($key,$mode,$isfilter=''){

    set_magic_quotes_runtime(0);

    $magic= get_magic_quotes_gpc();

    switch ($mode){

         case 'post':

             $value=isset($_POST[$key]) ?$magic?trim($_POST[$key]):addslashes(trim($_POST[$key])) : '';

         break;

         case 'get':

             $value=isset($_GET[$key]) ?$magic?trim($_GET[$key]):addslashes(trim($_GET[$key])) : '';

         break;

         default:

             $value=isset($_POST[$key]) ?$magic?trim($_POST[$key]):addslashes(trim($_POST[$key])) : '';

             if($value==""){

                  $value=isset($_GET[$key]) ?$magic?trim($_GET[$key]):addslashes(trim($_GET[$key])) : '';

             }

         break;

    }

       if($isfilter!=''){

          $value=lib_replace_end_tag($value);

       }

  return $value;

}

function RequestBox($key){

     $array =isset($_POST[$key]) ?$_POST[$key] : '';

        if($array==""){

          $value="0";

        }else{

           for($i=0;$i<count($array);$i++){

               $value=implode(',',$array);

           }

        }

 return $value;

}

function ReplaceStr($text,$search,$replace){

   if(empty($text)) $text="";

        $result_text=str_replace($search,$replace,$text);

  return $result_text;

}

function spandir($dir){

   $spandirpos=strrpos($dir,'/');

   $spandir=substr($dir,0,$spandirpos+1);

     if(!file_exists("../../".$spandir)){

        mkdir("../../".$spandir,0777,true);

     }

}

function cnsubstr($str,$strlen=10) {

    if(empty($str)||!is_numeric($strlen)){

        $strlen=10;

    }

    $strlen=intval($strlen*2);

    if(strlen($str)<=$strlen){

       return $str;

    }

    $last_word_needed=substr($str,$strlen-1,1);

    if(!ord($last_word_needed)>128){

      $needed_sub_sentence=substr($str,0,$strlen);

      return $needed_sub_sentence;

    }else{

       for($i=0;$i<$strlen;$i++){

            if(ord($str[$i])>128){

               $i++;

            }

       }

    $needed_sub_sentence=substr($str,0,$i);

    return $needed_sub_sentence;

    }

}

function DateDiff($d1,$d2=""){

   if(is_string($d1))$d1=strtotime($d1);

   if(is_string($d2))$d2=strtotime($d2);

 return ($d2-$d1);

}

function getpagerow($mysql,$pagesize){

   global $db;

   $url=$_SERVER["QUERY_STRING"];

   if(stristr($url,'&pages')){

      $url=preg_replace('/&pages=([\S]+?)$/','',$url);

   }

   if(stristr($url,'pages')){

      $url=preg_replace('/&pages=([\S]+?)$/','',$url);

   }

   if(stristr($url,'pages')){

      $url=preg_replace('/pages=([\S]+?)$/','',$url);

   }

   if(IsNul($url)) $url.="&";

   $pages=SafeRequest("pages","get");

   $pagesok=$pagesize;

   if (!isset($pages)||$pages==""||!is_numeric($pages)||$pages<=0){

      $pages=1;

   }

      $sqlstr=$mysql;

         $res=$db ->query($sqlstr);

         $nums= $db ->num_rows($res);

      if($nums==0) $nums=1;

      $str="总<font color=red>".$nums."</font>条记录&nbsp;";

      $pagejs=ceil($nums/$pagesok);

         if($pages>$pagejs){

            $pages=$pagejs;

         }

      $sql=$sqlstr." LIMIT ".$pagesok*($pages-1).",".$pagesok;

      $str.="当前<font color=red>".$pages."/</font>".$pagejs."页&nbsp;";;

      $result = $db ->query($sql);

         $str.= "<a href=?".$url."pages=1>第一页</a>";

         if($pagejs<=10){

            for($i=1;$i<=$pagejs;$i++){

               $str.="<a href='?".$url."pages=".$i."'>".$i."</a>&nbsp;";

            }

         }else{

            if($pages>=12){

               for($i=$pages-5;$i<=$pages+6;$i++){

                   if($i<=$pagejs){

                       $str.="<a href='?".$url."pages=".$i."'>".$i."</a>&nbsp;";

                   }

               }

               if($i<=$pagejs){

                   $str.="....";

                   $str.="<a href='?".$url."pages=".$pagejs." '>".$pagejs."</a>&nbsp;";

               }

            }else{

               for($i=1;$i<=12;$i++){

                   $str.="<a href='?".$url."pages=".$i." '>".$i."</a>&nbsp;";

               }

                   if($i<=$pagejs){

                   $str.="....";

                   $str.="<a href='?".$url."pages=".$pagejs." '>".$pagejs."</a>&nbsp;";

                   }

            }

         }

    $str.="<a href=?".$url."pages=".($pages+1).">下一页</a>&nbsp;";

    $str.="<a href=?".$url."pages=".$pagejs.">最后页</a>&nbsp;";

    $str.="转<input type=text size=4 name='gopage' style='margin-top:4px;' value='".$pages."'/>&nbsp;<a style='cursor:pointer;' onclick=window.location='?".$url."pages='+gopage.value+''>GO>></a>&nbsp;";

      //while ($row = $db ->fetch_array($result) ){}

    $arr=array($str,$result,$sql,$pagejs);

 return $arr;

}

class iFile {

 private $Fp;

 private $Pipe;

 private $File;

 private $OpenMode;

 private $Data;

 function iFile($File,$Mode = 'r',$Data4Write='',$Pipe = 'f'){

      $this ->File = $File;

      $this ->Pipe = $Pipe;

            if($Mode == 'dr'){

                  $this ->OpenMode = 'r';

                  $this ->OpenFile();

                  $this ->getFileData();

            }else{

                  $this ->OpenMode = $Mode;

                  $this ->OpenFile();

            }

            if($this->OpenMode=='w'&$Data4Write!=''){

                  $this ->WriteFile($Data4Write,$Mode = 3);

            }

 }

 function OpenFile(){

      if ($this ->OpenMode == 'r'||$this ->OpenMode == 'r+'){

            if($this->CheckFile()){

                  if ($this ->Pipe == 'f') {

                        $this->Fp = fopen($this ->File,$this ->OpenMode);

                  }elseif ($Pipe == 'p') {

                        $this->Fp = popen($this ->File,$this ->OpenMode);

                  }else{

                        Die("请检查文件打开参数3,f:fopen()");

                  }

            }else {

                        Die("文件访问错误,请检查文件是否存在!");

            }

      }else {

            if ($this ->Pipe == 'f') {

                  $this->Fp = fopen($this ->File,$this ->OpenMode);

            }elseif ($Pipe == 'p') {

                  $this->Fp = popen($this ->File,$this ->OpenMode);

            }else {

                  Die("请检查文件打开参数3,f:fopen()");

            }

      }

 }

 function CloseFile(){

      if ($this->Pipe == 'f'){

         @fclose($this->Fp);

      }else {

         @pclose($this->Fp);

      }

 }

 function getFileData(){

      @flock($this->Fp,1);

      $Content = fread($this->Fp,filesize($this->File));

      $this->Data = $Content;

 }

 function CheckFile(){

    if (file_exists($this ->File)) {return true;}else {return false;}

 }

 function WriteFile($Data4Write,$Mode = 3){

      @flock($this->Fp,$Mode);

      fwrite($this->Fp,$Data4Write);

      $this->CloseFile();

    return true;

 }

}

function escape($str){

     preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r);

     $ar=$r[0];

         foreach($ar as $k=>$v){

           if(ord($v[0]) <128)

             $ar[$k] = rawurlencode($v);

           else

             $ar[$k] = "%u".bin2hex(iconv("GBK","UCS-2",$v));

         }

 return join("",$ar);

}

function playadd($type= ''){

    $xmlpath=_CHSHDJ_ROOT_.'include/play.xml';

    $doc = new DOMDocument();

    $doc->load($xmlpath);

    $player = $doc->getElementsByTagName( "play");

    $str="";

    foreach( $player as $player ){

        $marks = $player->getElementsByTagName( "mark");

                if(function_exists("mb_convert_encoding")){

                        $mark =  mb_convert_encoding($marks->item(0)->nodeValue,"GBK","UTF-8");

                }else{

                        $mark = iconv( "UTF-8","GBK//IGNORE",$marks->item(0)->nodeValue);

                }

        $dess = $player->getElementsByTagName( "des");

                if(function_exists("mb_convert_encoding")){

                        $des = mb_convert_encoding($dess->item(0)->nodeValue,"GBK","UTF-8");

                }else{

                        $des = iconv( "UTF-8","GBK//IGNORE",$dess->item(0)->nodeValue);

                }

        $playfroms = $player->getElementsByTagName( "playfrom");

        $playfrom = $playfroms->item(0)->nodeValue;

        $str.="$mark--$des--$playfrom|";

    }

        $playarr=explode("|",$str);

  return $playarr;

}

function playaddshow($playadd,$playfrom){

     $playarr=explode('$$',$playfrom);

      for($j=0;$j<count($playarr);$j++){

          for($i=0;$i<count($playadd)-1;$i++){

               $playfromarr=explode("--",$playadd[$i]);

                if($playfromarr[2]==$playarr[$j]){

                   return  $playfromarr[0]."&nbsp;";

                }

          }

      }

}

function playselect($playadd,$play){

    $str="";

    for($i=0;$i<count($playadd)-1;$i++){

           $playfromarr=explode("--",$playadd[$i]);

           if($play==$playfromarr[2]){

                  $str.="<option value='".$playfromarr[2]."' selected='selected'>".$playfromarr[0]."--".$playfromarr[1]."</option>";

           }else{

                  $str.="<option value='".$playfromarr[2]."'>".$playfromarr[0]."--".$playfromarr[1]."</option>";

           }

    }

 return $str;

}

function playselect2($playadd,$play){

    $str="";

    for($i=0;$i<count($playadd)-1;$i++){

         $playfromarr=explode("--",$playadd[$i]);

         if($play==$playfromarr[2]){

             $str.="<option value='?action=orderbyplay&source=".$playfromarr[2]."' selected='selected'>".$playfromarr[0]."</option>";

         }else{

             $str.="<option value='?action=orderbyplay&source=".$playfromarr[2]."'>".$playfromarr[0]."</option>";

         }

    }

 return $str;

}

function ymurl($Url) {

$url1 =explode("p://",$Url);

$url2 = $url1[1];

if($url2=="127.0.0.1"){ $str=$url2;}else{

$domain =explode(".",$url2);

$str="";

if(count($domain)<3){

$str.=$url2;

}else{

for($i=1;$i<count($domain);$i++){

$str.=$domain[$i];

if($i<(count($domain)-1)){

$str.=".";

}

}

}

}

return $str;

}

function piclink($Table,$Url,$dx='') {

$url1=substr($Url,0,6);

if($Table=='logo'){

if($Url==""){

$piclink = S_SiteDomain.S_SitePath."user/images/avatar/noface_small.gif";

}else{

if($dx=="big"){

if($url1=="http:/"){

$piclink = $Url;

}else{

$piclink = S_SiteDomain.S_SitePath."upload/userlogo/big".$Url;

}

}else{

if($url1=="http:/"){

$piclink = $Url;

}else{

$piclink = S_SiteDomain.S_SitePath."upload/userlogo/small".$Url;

}

}

}

}else{

if($Url==""){

$piclink = S_SiteDomain.S_SitePath."images/nopic.gif";

}else{

$piclink = S_SiteDomain.S_SitePath.$Url;

}

}

return $piclink;

}

function getuserpic($User,$id){

if(S_Uymmode==0){

if(S_Usermode==0){

$uclassurl="http://".$User.".".S_Uymurl."/picgo---".$id.".html";

}else{

$uclassurl="http://".$User.".".S_Uymurl."/?op=picgo&id=".$id;

}

}else{

if(S_Usermode==0){

$uclassurl=S_SiteDomain.S_SitePath."user/".$User."---picgo---".$id.".html";

}else{

$uclassurl=S_SiteDomain.S_SitePath."user/i.php?u=".$User."&op=picgo&id=".$id;

}

}

return $uclassurl;

}

function linkweburl($UserID,$UserName){

if($UserID==0){

$linkweburl="http:///";

}else{

if(S_Uymmode==0){

$linkweburl="http://".$UserName.".".S_Uymurl;

}else{

if(S_Usermode==0){

$linkweburl=S_SiteDomain.S_SitePath."user/".$UserName."----index.html";

}else{

$linkweburl=S_SiteDomain.S_SitePath."user/i.php?u=".$UserName;

}

}

}

return $linkweburl;

}

function userlink($Classid,$User){

if(S_Usermode==0){

if(S_Uymmode==0){

if($Classid=='index'){

$userlink="http://".$User.".".S_Uymurl."";

}else{

$userlink="http://".$User.".".S_Uymurl."/".$Classid."----1.html";

}

}else{

if($Classid=='index'){

$userlink=S_SiteDomain.S_SitePath."user/".$User."----index.html";

}else{

$userlink=S_SiteDomain.S_SitePath."user/".$User."----".$Classid.".html";

}

}

}else{

if(S_Uymmode==0){

if($Classid=='index'){

$userlink="http://".$User.".".S_Uymurl."";

}else{

$userlink="http://".$User.".".S_Uymurl."/?op=".$Classid;

}

}else{

if($Classid=='index'){

$userlink=S_SiteDomain.S_SitePath."user/i.php?u=".$User;

}else{

$userlink=S_SiteDomain.S_SitePath."user/i.php?u=".$User."&op=".$Classid;

}

}

}

return $userlink;

}

function LinkUrl($Table,$ClassID,$SystemID,$ID){

$Table=strtolower($Table);

switch(S_Webmode){

//动态模式

case '1':

$AliasName=GetAlias("s_class",$ID);

if($Table=='s_video'){

if(S_Dvmode==1){

$linkurl=S_SitePath.S_Dvname."/?".S_UrlContent.$ID.".".S_Dvsuffix;

}else{

$linkurl=S_SitePath."p----".$ID.".".S_Dvsuffix;

}

}elseif($Table=='s_article'){

if(S_Dnmode==1){

$linkurl=S_SitePath.S_Dnname."/?".S_Urlshow.$ID.".".S_Dnsuffix;

}else{

$linkurl=S_SitePath."k----".$ID.".".S_Dnsuffix;

}

}elseif($Table=='s_topic'){

$AliasName=GetAlias("s_topic",$ID);

if(S_Dtmode==1){

$linkurl=S_SitePath.S_Dtname."/?".S_UrlContent.$ID.".".S_Dtsuffix;

}else{

$linkurl=S_SitePath."zj---".$ID."---1.".S_Dtsuffix;

}

}elseif($Table=='s_class'){

if($SystemID==1){

if(S_Dvmode==1){

$linkurl=S_SitePath.S_Dvname."/?".S_UrlList.$ID.".".S_Dvsuffix;

}else{

$linkurl=S_SitePath.$AliasName."----".$ClassID."----".$ID.".".S_Dvsuffix;

}

}elseif($SystemID==2){

if(S_Dnmode==1){

$linkurl=S_SitePath.S_Dnname."/?".S_UrlList.$ID.".".S_Dnsuffix;

}else{

$linkurl=S_SitePath."art".$AliasName."----".$ClassID."-----".$ID.".".S_Dnsuffix;

}

}

}

break;

case '0':

if($Table=='s_class'){

if($SystemID==1){

$folder=S_Svlistfolder;

$suffix=S_Svcontentsuffix;

}elseif($SystemID==2){

$folder = S_Sncontentfolder;

$suffix = S_Sncontentsuffix;

}

}elseif($Table=='s_video'){

$folder = S_Svcontentfolder;

$suffix= S_Svcontentsuffix;

$SystemID=1;

}elseif($Table=='s_article'){

$folder = S_Sncontentfolder;

$suffix = S_Sncontentsuffix;

$SystemID=2;

}elseif($Table=='s_topic'){

$folder = S_Stlistfolder;

$suffix= S_Stcontentsuffix ;

}

$linkurl=LinkContent($SystemID,$folder,$ClassID,$suffix,$ID,$Table);

}

return $linkurl;

}

function LinkContent($SystemID,$folder,$ClassID,$suffix,$ID,$Table){

     $Table=strtolower($Table);

         $ID2=$ID;

         if(S_Createid==2){

              $ID=md5($ID);

         }elseif(S_Createid==3){

              $ID=ShuZiPingyin($ID);

         }

     switch(S_Getcreate){

           case '1':

                $linkcontent=S_SitePath.$folder."/".$ID.".".$suffix;

           break;

           case '2':

                if($Table=="s_topic"){

                     $AliasName=GetAlias("s_topic",$ClassID);

                }elseif($Table=='s_video'){

                     $AliasName=GetAlias("s_class",$ClassID);

                }elseif($Table=='s_article'){

                     $AliasName=GetAlias("s_class",$ClassID);

                }elseif($Table=='s_class'){

                     if($SystemID==1)  $AliasName=GetAlias("s_class",$ClassID);

                     if($SystemID==2)  $AliasName=GetAlias("s_class",$ClassID);

                }

                $linkcontent=S_SitePath.$folder."/".$AliasName.$ID.".".$suffix;

           break;

           case '3':

                if($Table=='s_topic'){

                     $AliasName=GetAlias("s_topic",$ClassID);

                }elseif($Table=='s_video'){

                     $AliasName=GetAlias("s_class",$ClassID);

                }elseif($Table=='s_article'){

                     $AliasName=GetAlias("s_class",$ClassID);

                }elseif($Table=='s_class'){

                     if($SystemID==1)  $AliasName=GetAlias("s_class",$ClassID);

                     if($SystemID==2)  $AliasName=GetAlias("s_class",$ClassID);

                }

                $linkcontent=S_SitePath.$folder."/".$AliasName."/".$ID.".".$suffix;

           break;

           case '4':

                $linkcontent=S_SitePath.$folder."/".$ID2."/".$ID.".".$suffix;

           break;

           }

   return $linkcontent;

}

function LinkClassUrl($Table,$ID,$SystemID,$Page,$Lists=''){

    $Table=strtolower($Table);

    $PageMD=$Page;

       switch(S_Webmode){

               //静态模式

               case '0':

                  if($Lists=='1'){  //列表动态

                       if(!IsNum($Page)) $Page=1;

                       if($Table=="s_class"){

                              if($SystemID==1){

                                      if(S_Dvmode==1){

                                           $linkclassurl=S_SitePath.S_Dvname."/?".S_UrlList.$ID.".".S_Dvsuffix;

                                      }else{

                                           $linkclassurl=S_SitePath.S_Dvname."/list-".$ID."-1.".S_Dvsuffix;

                                      }

                              }elseif($SystemID==2){

                                      if(S_Dnmode==1){

                                           $linkclassurl=S_SitePath.S_Dnname."/?".S_UrlList.$ID.".".S_Dnsuffix;

                                      }else{

                                           $linkclassurl=S_SitePath.S_Dnname."/list-".$ID."-1.".S_Dnsuffix;

                                      }

                              }

                       }elseif($Table=="s_video"){

                                      if(S_Dvmode==1){

                                          $linkclassurl=S_SitePath.S_Dvname."/?".S_UrlList.$ID.".".S_Dvsuffix;

                                      }else{

                                          $linkclassurl=S_SitePath.S_Dvname."/list-".$ID.".".S_Dvsuffix;

                                      }

                       }elseif($Table=="s_article"){

                                      if(S_Dnname==1){

                                          $linkclassurl=S_SitePath.S_Dnname."/?".S_UrlList.$ID.".".S_Dnsuffix;

                                      }else{

                                          $linkclassurl=S_SitePath.S_Dnname."/list-".$ID.".".S_Dnsuffix;

                                      }

                       }elseif($Table=="s_topic"){

                                      if(S_Dtmode==1){

                                          $linkclassurl=S_SitePath.S_Dtname."/?".S_UrlList.$ID.".".S_Dtsuffix;

                                      }else{

                                          $linkclassurl=S_SitePath.S_Dtname."/".$ID.".".S_Dtsuffix;

                                      }

                       }

                  }else{  //列表静态

                       if($Table=="s_class"or $Table=="s_video" or $Table=="s_article"){

                                      if($SystemID==1){

                                              $folder=S_Svlistfolder;

                                              $suffix= S_Svcontentsuffix;

                                      }elseif($SystemID==2){

                                              $folder=S_Snlistfolder;

                                              $suffix= S_Stcontentsuffix;

                                      }

                       }elseif($Table=="s_topic"){

                                              $folder=S_Stlistfolder;

                                              $suffix= S_Sncontentsuffix;

                       }

                       $linkclassurl=LinkClassContent($SystemID,$folder,$ID,$PageMD,$suffix,$Table);

                  }

       break;

       //动态模式

       case '1':

              $AliasName=GetAlias("s_class",$ID);

                       if(!IsNum($Page)) $Page=1;

                       if($Table=="s_class"){

                               if($SystemID==1){

                                      if(S_Dvmode==1){

                                            $linkclassurl=S_SitePath.S_Dvname."/?".S_UrlList.$ID.".".S_Dvsuffix;

                                      }else{

                                            $linkclassurl=S_SitePath.$AliasName."----".$ID."----".$Page.".".S_Dvsuffix;

                                      }

                               }elseif($SystemID==2){

                                      if(S_Dnmode==1){

                                            $linkclassurl=S_SitePath.S_Dnname."/?".S_UrlList.$ID.".".S_Dnsuffix;

                                      }else{

                                            $linkclassurl=S_SitePath."art".$AliasName."----".$ID."----".$Page.".".S_Dnsuffix;

                                      }

                               }

                       }elseif($Table=="s_video"){

                                      if(S_Dvmode==1){

                                            $linkclassurl=S_SitePath.S_Dvname."/?".S_UrlList.$ID.".".S_Dvsuffix;

                                      }else{

                                            $linkclassurl=S_SitePath.$AliasName."----".$ID."----".$Page.".".S_Dvsuffix;

                                      }

                       }elseif($Table=="s_article"){

                                      if(S_Dnname==1){

                                            $linkclassurl=S_SitePath.S_Dnname."/?".S_UrlList.$ID.".".S_Dnsuffix;

                                      }else{

                                            $linkclassurl=S_SitePath."art".S_Dnname."----".$ID."----".$Page.".".S_Dnsuffix;

                                      }

                       }elseif($Table=="s_topic"){

                                      $AliasName=GetAlias("s_topic",$ID);

                                      if(S_Dtmode==1){

                                            $linkclassurl=S_SitePath.S_Dtname."/?".S_UrlList.$ID.".".S_Dtsuffix;

                                      }else{

                                            $linkclassurl=S_SitePath."zj---".$ID."---".$Page.".".S_Dtsuffix;

                                      }

                       }

       }

       return $linkclassurl;

}

function LinkClassContent($SystemID,$folder,$ID,$Page,$suffix,$Table){

  $AliasName="";

  switch(S_Getcreate){

       case '1':

           if($ID=='0'){

              $linkclasscontent=S_SitePath.$folder."/".$Page.".".$suffix;

           }else{

              $linkclasscontent=S_SitePath.$folder."/".$ID."_".$Page.".".$suffix;

           }

        break;

        case '2':

           if($Table=="s_topic"){

              $AliasName=GetAlias("s_topic",$ID);

           }elseif($Table=="s_video"or $SystemID==1){

              $AliasName=GetAlias("s_class",$ID);

           }elseif($Table=="s_article"or $SystemID==2){

              $AliasName=GetAlias("s_class",$ID);

           }

              $linkclasscontent=S_SitePath.$folder."/".$AliasName."_".$Page.".".$suffix;

        break;

        case '3':	

           if($Table=='s_topic'){

               $AliasName=GetAlias("s_topic",$ID);

           }elseif($Table=='s_video'or $SystemID==1){

               $AliasName=GetAlias("s_class",$ID);

           }elseif($Table=="s_article"or $SystemID==2){

               $AliasName=GetAlias("s_class",$ID);

           }

              if($Table=='s_topic'and $ID==0){

                   $linkclasscontent=S_SitePath.$folder."/".$Page.".".$suffix;

              }else{

                   $linkclasscontent=S_SitePath.$folder."/".$AliasName."/".$ID."_".$Page.".".$suffix;

              }

         break;

         case '4':	

            if($Table=='s_topic'){

                 $AliasName=GetAlias("s_topic",$ID);

            }elseif($Table=='s_video'or $SystemID==1){

                 $AliasName=GetAlias("s_class",$ID);

            }elseif($Table=="s_article"or $SystemID==2){

                 $AliasName=GetAlias("s_class",$ID);

            }

               if($Table=='s_topic'and $ID==0){

                    $linkclasscontent=S_SitePath.$folder."/".$Page.".".$suffix;

               }else{

                    $linkclasscontent=S_SitePath.$folder."/".$AliasName."/".$Page.".".$suffix;

               }

          break;

    }

  return $linkclasscontent;

}

function GetAlias($Table,$ClassID){

global $db;

$sql="select S_AliasName from ".$Table." where S_ID=".$ClassID."";

$row=$db->getrow($sql);

if($row){

$aliasname=$row['S_AliasName'];

}else{

if($Table=='s_topic'){

$aliasname="topic";

}else{

$aliasname="unknow";

}

}

return $aliasname;

}

function SpanShow($Table,$ClassID,$SystemID,$ID,$Url){

if(S_Webmode==0){

$SpanShow="<img src='images/span.gif' style='cursor:hand' id='span".$ID."' onclick='spango(".$ID.",\"".$Url."&cid=".$ClassID."\")'>";

$spanurl=substr(LinkUrl($Table,$ClassID,$SystemID,$ID,$Url),strlen(S_SitePath));

if(file_exists("../".$spanurl)){

$SpanShow="";

}

return $SpanShow;

}

}

function getvdisk($url){

$urldown = "http://www.vdisk.cn/down/index/".$url;

$dydb = @file_get_contents($urldown);

$dyurls = fetch_match_contents('<META name="httpfileurl" content="', '">', $dydb);

return $dyurls;

}

function fetch_match_contents( $dykgdlsrrr, $dykgddelrrr, $dykgdlshigdb ){

$dykgdlsrrr = change_match_string( $dykgdlsrrr );

$dykgddelrrr = change_match_string( $dykgddelrrr );

if ( @preg_match( "/".$dykgdlsrrr."(.*?){$dykgddelrrr}/i", $dykgdlshigdb, $dyqjvgdqss ) ){

return $dyqjvgdqss[1];

}

return "";

}

function change_match_string( $dykgdkggg ){

$dykggdkggw = array( "/", "\$" );

$dykggdkxxw = array( "\\/", "\$" );

$dykgdkggg = str_replace( $dykggdkggw, $dykggdkxxw, $dykgdkggg );

return $dykgdkggg;

}

function getrayfile($url,$names){

$CHshdjcms_a=explode('http://www.rayfile.com/files/',$url);

$CHshdjcms_a=$CHshdjcms_a[1];

$CHshdjcms_b=explode('/',$CHshdjcms_a);

$CHshdjcms_c=$CHshdjcms_b[0];

$playurl="http://rf.chshcms.com/m/?l=".$CHshdjcms_c."&type=".$names.".mp3";

return $playurl;

}

function  remote_file_exists($url_file){

$url_file = trim($url_file);

if (empty($url_file)) {return false;}

$url_arr = parse_url($url_file);

if (!is_array($url_arr) ||empty($url_arr)){return false;}

$host = $url_arr['host'];

$path = $url_arr['path'];

$port = isset($url_arr['port']) ?$url_arr['port'] : "80";

$fp = fsockopen($host,$port,$err_no,$err_str,30);

if (!$fp){return false;}

$request_str = "GET ".$path." HTTP/1.1\r\n";

$request_str .= "Host: ".$host."\r\n";

$request_str .= "Connection: Close\r\n\r\n";

fwrite($fp,$request_str);

$first_header = fgets($fp,1024);

fclose($fp);

if (trim($first_header) == ""){return false;}

if (!preg_match("/200/",$first_header)){

return false;

}

return true;

}

function convert_encoding($str,$nfate,$ofate){

if(function_exists("mb_convert_encoding")){

$str=mb_convert_encoding($str,$nfate,$ofate);

}else{

if($nfate=="GBK") $nfate="GBK//IGNORE";

$str=iconv($ofate,$nfate ,$str);

}

return $str;

}

function passport_encrypt($txt, $key) {

srand((double)microtime() * 1000000);

$encrypt_key = md5(rand(0, 32000));

$ctr = 0;

$tmp = '';

for($i = 0;$i < strlen($txt); $i++) {

$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;

$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);

}

return base64_encode(passport_key($tmp, $key));

}

function passport_decrypt($txt, $key) {

$txt = passport_key(base64_decode($txt), $key);

$tmp = '';

for($i = 0;$i < strlen($txt); $i++) {

$md5 = $txt[$i];

$tmp .= $txt[++$i] ^ $md5;

}

return $tmp;

}

function passport_key($txt, $encrypt_key) {

$encrypt_key = md5($encrypt_key);

$ctr = 0;

$tmp = '';

for($i = 0; $i < strlen($txt); $i++) {

$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;

$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];

}

return $tmp;

}

function HotSearch($Search_Key,$type="0"){

$Search_List="";

$Search_Key1="";

$Search_Key=trim($Search_Key);

$Str=" @,@|@_";

$StrArr=explode('@',$Str);

for($i=0;$i<=3;$i++){

if(stristr($Search_Key,$StrArr[$i])){

$Search_Key1=explode($StrArr[$i],$Search_Key);

break;

}

}

if(is_array($Search_Key1)){

for($j=0;$j<count($Search_Key1);$j++){

if($type==1){

$Search_List= $Search_List."<A class=\"tg_".($j+1)."\" HREF=\"".S_SiteDomain.S_SitePath."search.php?keyword=".urlencode(convert_encoding($Search_Key1[$j],'UTF-8','GBK'))."&type=1\">".$Search_Key1[$j]."</A> ";

}else{

$Search_List= $Search_List."<A class=\"tg_".($j+1)."\" HREF=\"".S_SiteDomain.S_SitePath."search.php?keyword=".urlencode(convert_encoding($Search_Key1[$j],'UTF-8','GBK'))."\">".$Search_Key1[$j]."</A> ";

}

}

}else{

$Search_List=$Search_Key;

}

return $Search_List;

}

function getChild($ClassID){

if($ClassID!=""){

global $db;

$ClassArr=explode(',',$ClassID);

for($i=0;$i<count($ClassArr);$i++){

$sql="select S_ID from s_class where S_FatherID=$ClassArr[$i]";

$result=$db->query($sql);

if($result){

while($row=$db->fetch_array($result)){

$ClassArr[]=$row['S_ID'];

}

}

}

$ClassID=implode(',',$ClassArr);

}

return $ClassID;

}

function geturl($url){

if(function_exists('curl_init')){

$ch = curl_init();

$timeout = 30;

curl_setopt ($ch,CURLOPT_URL,$url);

curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1);

curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,$timeout);

$handles = curl_exec($ch);

curl_close($ch);

return $handles;

}

}

function dateDifff($startTime, $endTime) {

$start = strtotime($startTime);

$end = strtotime($endTime);

$timeDiff = $end - $start;

return floor($timeDiff / (60 * 60 * 24));

} 

function datetime($TimeTime){

$limit=time()-strtotime($TimeTime);

if ($limit <5) {$show_t = "刚刚";}

if ($limit >= 5 and $limit <60) {$show_t = $limit."秒前";}

if ($limit >= 60 and $limit <3600) {$show_t = sprintf("%01.0f",$limit/60)."分钟前";}

if ($limit >= 3600 and $limit <86400) {$show_t = sprintf("%01.0f",$limit/3600)."小时前";}

if ($limit >= 86400 and $limit <2592000) {$show_t = sprintf("%01.0f",$limit/86400)."天前";}

if ($limit >= 2592000 and $limit <31104000) {$show_t = sprintf("%01.0f",$limit/2592000)."个月前";}

if ($limit >= 31104000) {$show_t = $TimeTime;}

return $show_t;

}

function facehtml($str)  

 {  

 if (empty($str)) return false;  

 $str = htmlspecialchars($str); 

 $str = str_replace( '[em:1]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/1.gif border=0>", $str); 

 $str = str_replace( '[em:2]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/2.gif border=0>", $str); 

 $str = str_replace( '[em:3]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/3.gif border=0>", $str); 

 $str = str_replace( '[em:4]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/4.gif border=0>", $str); 

 $str = str_replace( '[em:5]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/5.gif border=0>", $str); 

 $str = str_replace( '[em:6]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/6.gif border=0>", $str); 

 $str = str_replace( '[em:7]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/7.gif border=0>", $str); 

 $str = str_replace( '[em:8]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/8.gif border=0>", $str); 

 $str = str_replace( '[em:9]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/9.gif border=0>", $str); 

 $str = str_replace( '[em:10]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/10.gif border=0>", $str); 

 $str = str_replace( '[em:11]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/11.gif border=0>", $str); 

 $str = str_replace( '[em:12]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/12.gif border=0>", $str); 

 $str = str_replace( '[em:13]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/13.gif border=0>", $str); 

 $str = str_replace( '[em:14]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/14.gif border=0>", $str); 

 $str = str_replace( '[em:15]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/15.gif border=0>", $str); 

 $str = str_replace( '[em:16]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/16.gif border=0>", $str); 

 $str = str_replace( '[em:17]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/17.gif border=0>", $str); 

 $str = str_replace( '[em:18]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/18.gif border=0>", $str); 

 $str = str_replace( '[em:19]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/19.gif border=0>", $str); 

 $str = str_replace( '[em:20]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/20.gif border=0>", $str); 

 $str = str_replace( '[em:21]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/21.gif border=0>", $str); 

 $str = str_replace( '[em:22]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/22.gif border=0>", $str); 

 $str = str_replace( '[em:23]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/23.gif border=0>", $str); 

 $str = str_replace( '[em:24]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/24.gif border=0>", $str); 

 $str = str_replace( '[em:25]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/25.gif border=0>", $str); 

 $str = str_replace( '[em:26]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/26.gif border=0>", $str); 

 $str = str_replace( '[em:27]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/27.gif border=0>", $str); 

 $str = str_replace( '[em:28]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/28.gif border=0>", $str); 

 $str = str_replace( '[em:29]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/29.gif border=0>", $str); 

 $str = str_replace( '[em:30]', "<img src=".S_SiteDomain.S_SitePath."user/images/face/30.gif border=0>", $str); 

 return $str;  

 }  

function lib_replace_end_tag($str)  

 {  

 if (empty($str)) return false;  

 $str = htmlspecialchars($str);  

 $str = str_replace( '/', "", $str);  

 $str = str_replace("\\", "", $str);  

 $str = str_replace("&gt", "", $str);  

 $str = str_replace("&lt", "", $str);  

 $str = str_replace("SCRIPT", "", $str);  

 $str = str_replace("script", "", $str);  

 $str = str_replace(";", "；", $str);  

 $str = str_replace("and", "", $str);  

 $str = str_replace("or", "", $str);  

 $str=str_replace("select","select",$str);  

 $str=str_replace("join","join",$str);  

 $str=str_replace("union","union",$str);  

 $str=str_replace("where","where",$str);  

 $str=str_replace("insert","insert",$str);  

 $str=str_replace("delete","delete",$str);  

 $str=str_replace("update","update",$str);  

 $str=str_replace("like","like",$str);  

 $str=str_replace("drop","drop",$str);  

 $str=str_replace("create","create",$str);  

 $str=str_replace("modify","modify",$str);  

 $str=str_replace("rename","rename",$str);  

 $str=str_replace("alter","alter",$str);  

 $str=str_replace("cas","cast",$str);  

 $str=str_replace("&","",$str);  

 $str=str_replace(">","",$str);  

 $str=str_replace("<","",$str);  

 $str=str_replace(" ",chr(32),$str);  

 $str=str_replace(" ",chr(9),$str);  

 $str=str_replace("    ",chr(9),$str);  

 $str=str_replace("&",chr(34),$str);  

 $str=str_replace("'",chr(39),$str);  

 $str=str_replace("<br />",chr(13),$str);  

 $str=str_replace("''","",$str);  

 $str=str_replace("css","",$str);  

 $str=str_replace("CSS","",$str);  

 $str=str_replace("'","",$str);

 return $str;  

 } 

function GetTime($Gtime){

          $StrArr=explode(' ',$Gtime);

          $StrArr=$StrArr[0];

	return $StrArr;

}

?>