<?php if(!defined('ONGPHP'))exit('Error ONGSOFT');


$RUKU = 50;

function coedjison( $start = 200 , $SHUJU ){

        ob_clean();
        header('HTTP/1.1 '. $start);
        exit(json_encode( $SHUJU ));
}

function suijitype( $Mem ){

        $HASH = 'cjitype';
        $DATA = $Mem -> g( $HASH );
        if($DATA)return $DATA;

        $Ds = db('type');

        $shuju = $Ds ->where( array( 'leixin' => 1))-> select();
        $naeee = $zhengli = array();

        if( $shuju ){

            foreach($shuju as $ong ){

                $zhengli[$ong['cid']][$ong['id']] = $ong['name'];

            }
        }


        foreach($zhengli['0'] as $kk => $woqu){

            if( ! isset($zhengli[$kk]) )$naeee[]=$kk;
        }

        unset($zhengli['0']);

        foreach($zhengli as $woqu){
        
              if(is_array($woqu)){


                  foreach($woqu as $k => $ttt){

                      $naeee[]= $k;
                  
                  }
              
              
              
              
              }
        }

        $Mem -> s( $HASH ,$naeee, 20);

        return $naeee;




}

$ACTION = array(
                'baidu' => '百度地图',
               'google' => '谷歌地图',
                  'rss' => 'rss 订阅',
                  'map' => '网站地图',
                 'code' => '验证码',
               'liuyan' => '留言数据',
                 'type' => '获取分类',
                'caiji' => '采集数据',
                'suiji' => '随机数据',
                'ceshi' => '测试数据',
                'renqi' => '人气记录',
            );
$Y = isset($_GET['y']) ? $_GET['y']:'map';



if( isset( $ACTION[$Y] )){

    if( $Y == 'renqi'){
        header( 'Content-type:application/json;charset=UTF-8');

        $LX = (float)(isset( $_GET['lx'] ) ? $_GET['lx'] : 1 );
        $ID = (float)( isset( $_GET['id'] ) ?  $_GET['id'] : 1);

        $HASH = 'renqi/'.mima($LX.'_'.$ID);

        $DATA = $Mem -> g( $HASH );

        if( !$DATA ){

            if( $LX == 1){
                /*分类*/
                $DB  = db('type');

            }else{
                /*内容*/
                $DB = db('center');
            }

            $neir = $DB ->where( array( 'id' => $ID ) ) -> find();
            if( ! $neir ) $DATA = 1;
            else $DATA = $neir['renqi'];
            $Mem -> s( $HASH , $DATA );


        }

        $DATA = $Mem -> ja( $HASH , 1 );

        if( $DATA % $RUKU == 0 ){

            if( $LX == 1){
                /*分类*/
                $DB  = db('type');

            }else{
                /*内容*/
                $DB = db('center');
            }

            $DB ->where( array( 'id' => $ID ) )-> update( array( 'renqi' => $DATA ));
        
        
        
        }
        
        exit(json_encode(array('renqi' => $DATA )));


 
    }else if( $Y == 'code'){

        setsession( $CONN['sessiontime'] );
        echo vcode('3','0123456789',4,130,40);

        exit();
    }else if( $Y == 'liuyan'){


        $LANG = include QTLANG;


        setsession( $CONN['sessiontime'] );

        if( !yzcode( 'code' , $CONN['sicode'] , 160 )  ) msgbox( $LANG['lyyzm'].$LANG['cuowu'] );

        $LIUHAHS = 'liuyan/'.mima(ip());

        $YANZE = $Mem ->g( $LIUHAHS );

        if( $YANZE  ){

            msgbox( $LANG['lyyfbu']);

           

        }


        $title = anquanqu( isset( $_POST['title'] ) ? $_POST['title'] : '' );
        $name = anquanqu( isset( $_POST['name'] ) ? $_POST['name'] : '' );
        $tel = anquanqu( isset( $_POST['tel'] ) ? $_POST['tel'] : '' );
        $email = ( isset( $_POST['email'] ) ? $_POST['email'] : '' );
        $add = ( isset( $_POST['add'] ) ? $_POST['add'] : '' );

        $contents = anquanqu( isset( $_POST['contents'] ) ? $_POST['contents'] : '' );

        if( strlen( $title ) < 2 ||  strlen( $title ) > 30 )msgbox( $LANG['lybt'].$LANG['cuowu']);
        if( strlen( $name ) < 2 ||  strlen( $name ) > 30 )msgbox( $LANG['lyxm'].$LANG['cuowu']);
        if( strlen( $add ) > 100 ) msgbox( $LANG['lydz'].$LANG['cuowu'] );
        if( strlen( $tel ) < 8 ||  strlen( $tel ) > 13 )msgbox( $LANG['lydh'].$LANG['cuowu'] );
        if( strlen( $contents ) < 20 ||  strlen( $contents ) > 500 )msgbox(  $LANG['lynr'].$LANG['cuowu']);
        $D = db('pinglun');



        $kuozan = serialize( array( 'name' =>  $name,
                              'tel' => $tel ,
                            'email' => $email,
                              'add' => $add
                     ));

     

         

        $FAN = $D -> insert( array( 'name' => $title,
                               'kuozan' => $kuozan,
                              'neirong' => $contents,
                             'atime' => time(),
            
        
        ));

      

        if( $FAN ){

             $Mem ->s( $LIUHAHS , 1 ,120 );

            msgbox(  $LANG['lyok']);
            
 
        
        
        }else msgbox( $LANG['lyno']);
        
      







    
    
  
    }else if( $Y == 'ceshi'){

        if( !isset($_GET['mima']) || !isset($CONN['mima'])  ||  $CONN['mima']==''  ||  $CONN['mima'] != $_GET['mima']) exit('NO pass');

        $DD = db('center');

        $data = $DD  ->where( array('tupian LIKE' => '%ys137%'))-> find();

        if($data ){

            $tupian  = fenjieimg($data['neirong']);

            $tpic = '';

            if($tupian){
               $tpic = trim( str_ireplace( array("'",'"'),array('',''),$tupian['bbao']['0']));
               if( strpos( $tpic , 'ys137') !== false) $tpic = '';
            
            }

            $DD  ->where(array('id' => $data['id']))-> update(array('tupian' => $tpic ));

            p($tpic,array('id' => $data['id']));

            //sleep(1);

            msgbox('','?'.getarray($_GET));

           


        
        
        }else exit('ok');


    
    
  
    }else if( $Y == 'type'){

         if( !isset($_GET['mima']) || !isset($CONN['mima'])  ||  $CONN['mima']==''  ||  $CONN['mima'] != $_GET['mima']) exit('NO pass');
        /*分类获取*/
        $DD = db('type');

        $x = '<type><select>';

        $shuju = $DD ->where( array( 'leixin' => 1))-> select();
        $naeee = $zhengli = array();

        if( $shuju ){

            foreach($shuju as $ong ){

                $zhengli[$ong['cid']][$ong['id']] = $ong['name'];
                $naeee[$ong['id']] = $ong['name'];

            }
        }

        foreach($zhengli['0'] as $kk => $zhijian){

            $x .='<opton value="'.$kk.'">'.$zhijian.'</option>';
            if(isset($zhengli[$kk]) && is_array( $zhengli[$kk] ) ){

                    foreach($zhengli[$kk] as $dd=> $shen){

                    $x .='<opton value="'.$dd.'">　'.$shen.'</option>';
                            
                            if(isset($zhengli[$dd]) && is_array( $zhengli[$dd] ) ){

                                                foreach($zhengli[$dd] as $ddd=> $shend){

                                                     $x .='<opton value="'.$ddd.'">　　'.$shend.'</option>';

                                                }

                            }

                    }
             }

        }

  

        $x .= '</select><type>';
     


    
        exit( $x );

    }else if( $Y == 'caiji'){

        /*录入数据*/
        if( !isset($_GET['mima']) || !isset($CONN['mima'])  ||  $CONN['mima']==''  ||  $CONN['mima'] != $_GET['mima']) exit('NO pass');

        $NAME = array();


        if( $_POST ){

            foreach($_POST as $K => $V){

                if( strpos( $V , 'db:') !== false ) unset( $_POST[ $K]) ;
            }
        }





        if( ! isset( $_POST['name'] ) || $_POST['name'] == '')exit('no');
        if( ! isset($_POST['neirong'] ) || $_POST['neirong'] == '')exit('no');
        if( ! isset($_POST['cid'] ) || $_POST['cid'] < 0 )exit('no');

        if( $_POST['cid'] < 1){


            $shuju = suijitype( $Mem );
            $_POST['cid'] = ( $shuju[array_rand($shuju,1)]);

        }


        $tupianji = '';

        if( isset( $_POST['tupianij'] ) ){



            if( is_array( $_POST['tupianij'] ) )
                $tupianji  = serialize( $_POST['tupianij'] );
            else
                $tupianji  = serialize( explode( '<',$_POST['tupianij']) );


        }

        $NAME = array( 'name' => anquanqu( $_POST['name'] ),
                    'neirong' => $_POST['neirong'],
                      'atime' => time() - rand(1000,99999),
                        'cid' => (float)$_POST['cid'],
                        'off' => 2,
                     'tupian' => isset( $_POST['tupian'] )? $_POST['tupian'] : '' ,
                   'tupianji' => $tupianji,
                     'miaoshu' =>  anquanqu( $_POST['miaoshu'] ),
             'guanjian' =>  anquanqu( $_POST['guanjian'] ),
        
            );


        $NAME['url'] = scurl( $_POST['name'] , 2 , 1 , $_POST['cid'] );

        $D = db('center');

        $fan = $D  -> insert($NAME);

        if( ! $fan ) exit( 'no' );

        chaurl(  $NAME['url'] , 1 , $D );


        exit('yes');
    }




    $wenjianxi= Txpath.mima($CONN['qtpl'].$Y).'.xml';

    if($CONN['huanchun'] > 0 ){
                
        if(file_exists($wenjianxi)){ 
            clearstatcache();
            $guoqitime = filemtime($wenjianxi)+$CONN['huanchun']; //过期世家
            $dangqtime = time();

            if( $dangqtime < $guoqitime){
                $fp=qfopen($wenjianxi,'utf-8');

                echo $fp;

                die;
            }
        }
    }

    $SUZU= array();

    $urldtype = db('type'); //分类
    $sydat = $urldtype ->where(array('off' => 2))->order("id DESC") -> select();
    if( $sydat ){
        foreach($sydat as $k){
              $SUZU[]=array( mourl(strtolower($k['url'])),date('Y-m-d',$k['atime']),$k['name'],qsubstr(quchuk(htmlspecialchars($k['neirong'])),0,200));
             

        }
    }

    $sydat = $urldtype ->setbiao('center')->where(array('off' => 2))->order("id DESC")->limit(1000) -> select();
    if( $sydat ){
        foreach($sydat as $k){
              $SUZU[]=array( mourl(strtolower($k['url'])),date('Y-m-d',$k['atime']),$k['name'],qsubstr(quchuk(htmlspecialchars($k['neirong'])),0,200));
             

        }
    }

    $x='';

    if($Y == 'baidu'){

        $x.='<?xml version="1.0" encoding="UTF-8"?>'."\n";
        $x.='<urlset>'."\n";
        $x.='<url>'."\n".'<loc>'.WZHOST.'</loc>'."\n".'<lastmod>'.date('Y-m-d',time()).'</lastmod>'."\n".'<changefreq>daily</changefreq>'."\n".'<priority>1.0</priority>'."\n".'</url>'."\n";

        foreach($SUZU as $k){
            $x.='<url>'."\n".'<loc>'.$k['0'].'</loc>'."\n".'<lastmod>'.$k['1'].'</lastmod>'."\n".'<changefreq>daily</changefreq>'."\n".'<priority>0.9</priority>'."\n".'</url>'."\n";
        }

        $x.= '</urlset>'."\n";


    }else if($Y == 'google'){

        $x.='<?xml version="1.0" encoding="UTF-8"?>'."\n";
        $x.='<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
            <url>
            <loc>'.WZHOST.'</loc>
            <lastmod>'.date('Y-m-d',time()).'</lastmod>
            <changefreq>hourly</changefreq>
            <priority>1.0</priority>
            </url>'."\n";
        foreach($SUZU as $k){
            $x.='<url>'."\n".'<loc>'.$k['0'].'</loc>'."\n".'<lastmod>'.$k['1'].'</lastmod>'."\n".'<changefreq>daily</changefreq>'."\n".'<priority>0.9</priority>'."\n".'</url>'."\n";
        }

        $x.= '</urlset>';

    }else if($Y == 'suiji'){


        $x = '<script>';
        $z = array();
        foreach($SUZU as $zufu)$z[]= $zufu['0'];
        $x .= 'var url = '.json_encode($z).';';
        $x .='window.location =( url[Math.floor(Math.random()*url.length)] );</script>';

    
    
    }else if($Y == 'rss'){


        $x.='<?xml version="1.0" encoding="UTF-8" ?>
        <rss version="2.0">
        <channel>
        <title>'.$CONN['title'].'</title> 
        <description>'.$CONN['miaoshu'].'</description> 
        <link>'.WZHOST.'</link> 
        <language>zh-cn</language> 
        <docs>'.$CONN['title'].'</docs> 
        <generator>Rss Powered By '.WZHOST.'</generator> 
        <image>
        <url>'."http://".$_SERVER ['HTTP_HOST'].$CONN['logo'].'</url> 
        </image>';

        foreach($SUZU as $k){

            $x.='<item>
            <title>'.$k['2'].'</title> 
            <link>'.$k['0'].'</link>
            <author>'.WZHOST.'</author>
            <pubDate>'.$k['1'].'</pubDate>
            <description><![CDATA["'.$k['3'].'"]]></description> 
            </item>';

        }

        $x.='</channel></rss>';



    }else if($Y == 'map'){

        if(file_exists( QTPL.'map.php')){
            $LANG = include QTLANG;
            $HTTP = 'index';
            $PAGE = 1;

            include QTPL.'map.php';
            $x = ob_get_contents();
            ob_end_clean();

        }else{

            $x='<h1><a href="'.WZHOST.'">'.$CONN['title'].'</a></h1>';

            foreach($SUZU as $k){

                $x.='<a href="'.$k['0'].'" title="'.$k['2'].'" target="_blank">'.$k['2'].'</a><br />';
            }
        }

    }

    echo $x;

    if($CONN['huanchun'] > 0){

        $fp=fopen($wenjianxi,"w+");
        fputs($fp,$x);
        fclose($fp);
    }



}else{

    Header("Location: ".WZHOST);
    exit();
}