<?php
@ini_set('display_errors', false);
@error_reporting(E_ERROR | E_WARNING | E_PARSE);
$_GET = array_map('htmlspecialchars', preg_replace('/[\r\n]+/', '', $_GET));


if (empty($_GET['xml_id']) || empty($_GET['xml_file'])){
  die('&#x53C2;&#x6570;&#x7F3A;&#x5931;&#x6216;&#x9519;&#x8BEF;&#xFF01;');
}

$err = '';

if (!function_exists('err')) {
  function err($text) {
    die('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>'.$text.'</body></html>');
  }
}

if ($xfile = $_GET['xml_file']) {
  $xfile = strtolower(base64_decode($xfile));
  $xfile = preg_replace('/(\.+\/)+/i', '', $xfile);

  $safe_pages = array(
'class_page.php',
'more.php',
'readonly/weather/getweather.php',
'readonly/run/post_member_collection_show.php',
'readonly/run/get_newinfo.php',
'writable/require/newsite10.txt',
);

  if (file_exists($xfile) && in_array($xfile, $safe_pages)) {
    @ob_start();
    @ include ($xfile);
    $content_t = @ob_get_contents();
    @ob_end_clean();
  } else {
    if ($_GET['xml_id']=='site_text' && preg_match('/^https?\:\/\//i', $xfile)) {
      @ require 'readonly/function/read_file.php';
      @ require 'readonly/function/filter.php';

      if ($f=read_file($xfile)){

        if (function_exists('mb_detect_encoding')) {
          $cha=mb_detect_encoding($f, array('EUC-CN','GB2312','GBK','UTF-8','ASCII','CP936','BIG-5'));
        }
        if (!$cha) {
          if(preg_match('/<meta [^>]*charset[\s\r\n]*=[\s\r\n\'\"]*([\w\-]+)[^\>]*>/i',$f,$m)){
            $cha=$m[1];
          }  
        }
        if ($cha) {
          $cha=strtolower($cha);
          preg_match('/<meta [^>]*description[^>]+content[\s\r\n]*=[\s\r\n\"\']*([^>\"\']+)[^>]*>/i', $f, $mm) || preg_match('/<meta [^>]*content[\s\r\n]*=[\s\r\n\"\']*([^>\"\']+)[^>]+description[^>]*>/i', $f, $mm);
          if (empty($mm[1])) {
            if (preg_match('/<meta [^>]*keywords[^>]+content[\s\r\n]*=[\s\r\n\"\']*([^>\"\']+)[^>]*>/i', $f, $mm) || preg_match('/<meta [^>]*content[\s\r\n]*=[\s\r\n\"\']*([^>\"\']+)[^>]+keywords[^>]*>/i', $f, $mm)) {
              $mmmm = 1;
            }
          }
          if ($mm[1]) {
            if($cha!='utf-8'){
              if ($cha == 'gb2312' || $cha == 'euc-cn') {
                $cha = 'gbk';
              }
              $mm[1]=iconv($cha,'utf-8//IGNORE',$mm[1]);
            }
            $content_t = preg_replace('/<script.+\/script>/isU','',$mm[1]);
            $content_t = strip_tags($content_t);
            $content_t = preg_replace('/[\n\r\s]+/','',$content_t);
            $content_t = filter1($content_t);
            if (isset($mmmm)) {
              $content_t .= '<div class="grayword">└ 没有抓到description（简介），用替代方案，抓到的是keywords（关键词）</div>';
            }
          }
        }
      }
    } else {
      $err = '<br>&#x8BF7;&#x540E;&#x53F0;&#x5173;&#x95ED;&#x6B64;&#x6A21;&#x5757;&#x518D;&#x5F00;&#x542F;&#x8BD5;&#x8BD5;';
    }
  }
}




?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>加载内容</title>
</head>
<body>
<code id="fr">
<!--<?php echo preg_replace('/<\!\-\-.*\-\->/sU', '', $content_t); ?>-->
</code>
<script type="text/javascript" language="JavaScript">
<!--
function addOther(){
  if (parent && parent!=self) {
    var par=parent.document.getElementById('<?php echo $_GET['xml_id']; ?>');
    var a=<?php echo isset($_GET['xml_a'])&&$_GET['xml_a']==1?1:0;?>;
    if(par!=null){
      var text=document.getElementById('fr').innerHTML.replace(/^[\s\n\r]*<\!\-\-|\-\->[\s\n\r]*$/g, '');
      text=text!=''?text:'&#x52A0;&#x8F7D;&#x5931;&#x8D25;&#xFF01;&#x6CA1;&#x53D6;&#x5230;&#x6570;&#x636E;&#x3002;<?php echo $err; ?>';
      if(a==1){
        par.innerHTML+=text;
        var pp = parent.document.getElementById('<?php echo $_GET['xml_id']; ?>_pageload');
        if (pp != null) {
          pp.value = 'over';
        }
        //parent.Sort(document.getElementById('<?php echo $_GET['xml_id']; ?>'));
      }else{
        par.innerHTML=text;
      }
    }
  }
}
if(document.all){
  window.attachEvent('onload',addOther);
}else{
  window.addEventListener('load',addOther,false);
}
-->
</script>
</body>
</html>