<?php
require ('authentication_manager.php');
?>
<?php

/* 在线修改文件 */
/* 162100源码 - 162100.com */


//遍历
function dirtree($path) {
  $text_d = $text_f = array();
  $text = '';
  if ($fp = @opendir($path)) {
    while (false !== ($file = @readdir($fp))) {
      $cf = '';
      if ($file == '.' || $file == '..' || $file == 'images' || $file == 'cert') continue;
      if (is_dir($path.'/'.$file)) {
        if ($file == 'css')             $cf = '<span style="color:#CCCCCC">（风格文件库）</span>';
		elseif ($file == '__temp__')        $cf = '<span style="color:#CCCCCC">（再生/临时数据文件库）</span>';
		elseif ($file == 'login_key')        $cf = '<span style="color:#CCCCCC">（登录接口）</span>';
		elseif ($file == 'pay')        $cf = '<span style="color:#CCCCCC">（支付宝收款接口）</span>';
        elseif ($file == 'run')         $cf = '<span style="color:#CCCCCC">（执行文件库）</span>';
        elseif ($file == 'images')      $cf = '<span style="color:#CCCCCC">（图片目录，不能编辑）</span>';
		elseif ($file == 'function')    $cf = '<span style="color:#CCCCCC">（函数文件库）</span>';
		elseif ($file == 'font')    $cf = '<span style="color:#CCCCCC">（水印字体）</span>';
        elseif ($file == 'ad')          $cf = '<span style="color:#CCCCCC">（广告文件库）</span>';
        elseif ($file == 'sql')          $cf = '<span style="color:#CCCCCC">（mysql备份文件库）</span>';
        elseif ($file == 'set')         $cf = '<span style="color:#CCCCCC">（重要！配置文件库）</span>';

        $text_d[] = '<a href="?get=modify&otherfile='.get_en_url(ltrim($path.'/'.$file, './')).'" class="greenword">目录：'.ltrim($path.'/'.$file, './').''.$cf.'</a><br />';
      }
      if (is_file($path.'/'.$file)) {
        if ($file == 'set.php')         $cf = '<span style="color:#CCCCCC">（系统参数文件）</span>';
		elseif ($file == 'set_sql.php') $cf = '<span style="color:#CCCCCC">（数据库参数文件）</span>';
        elseif ($file == 'index.php')   $cf = '<span style="color:#CCCCCC">（首页）</span>';
        $text_f[] = '<a href="?get=modify&otherfile='.get_en_url(ltrim($path.'/'.$file, './')).'">文件：'.ltrim($path.'/'.$file, './').''.$cf.'</a><br />';
      }
    }
    @closedir($fp);
  }

  if (is_array($text_d) && count($text_d) > 0) {
    @natcasesort($text_d);
    $text .= @implode('', $text_d);
  }
  if (is_array($text_f) && count($text_f) > 0) {
    @natcasesort($text_f);
    $text .= @implode('', $text_f);
  }
  
  return $text != '' ? $text : '空的查询！可能目录或文件不存在';
}
?>
<div class="column redword"><b>提示：</b>在此在线修改文件请务必谨慎，这将关系到网站能否正常运行；或本地手动修改该文件，然后上传。</div>
<?php
$text = '';
$thefile = base64_decode($_GET['otherfile']);
if ($thefile && is_file($thefile)):
  if (file_exists($thefile)) {
    $file = @file_get_contents($thefile);
	if(function_exists('mb_detect_encoding')) {
	  $cha = mb_detect_encoding($file, array("UTF-8","GB2312","GBK","BIG-5","ASCII","EUC-CN","CP936"));
	}
    if (!$cha) {
      if(preg_match("/charset[\s\r\n]*=[\s\r\n\'\"]*([\w\-]+)[^\>]*>/i", $file, $m_cha)){
	    $cha = $m_cha[1];
      }
    }
    if (isset($cha) && $cha != "") {
      if(strtolower($cha) != "utf-8"){
        $file = @iconv($cha, "utf-8", $file);
      }
    }
?>
  &lt;<a href="?get=modify&otherfile=<?php echo get_en_url(dirname($thefile)); ?>">上级目录</a>&gt;<br />
  <span class="redword">编辑：</span> <?php echo $thefile; ?> <?php echo preg_match('/\.js$/i', $thefile) ? '<span class="redword">（此文件为JS文件，请用javascript语言编写）</span>' : ''; ?><br />


<?php
if (isset($_GET['type']) && $_GET['type'] == 'editor') {

  @ require ('inc/function/filter.php');

?>
<iframe id="lastFrame" name="lastFrame" frameborder="0" style="display:none"></iframe>
<script type="text/javascript">
<!--
var uploadPower = "yes";
var liMaxCount = <?php echo $web['list_wordcount']; ?>;
//var eXSize = 588;       //编辑器宽度，最小宽度限588px
var formU = '?post=modify';
var formT='<input type="hidden" name="thefile" value="<?php echo $thefile; ?>" />\
<div class="column">提示：如果加入含&lt;script&gt;标签的代码，如广告联盟代码或直接的源代码，务必点选下面“不用过滤…”，否则代码会被安全过滤掉，你期待的效果将失效。<br /><input type="radio" class="radio" name="filter" value="yes" checked />请系统自动过滤代码<span class="grayword">（点选此项可能会过滤掉不希望过滤的代码，否则请点选下面的。）</span><br /><input type="radio" class="radio" name="filter" value="no" />不用过滤，我相信自己所写的代码规范（填写JS等代码如统计代码时）。<b>注意此项每次提交前要仔细校对代码</b><br /><b class="redword">提交前请确定<?php echo dirname($thefile); ?>目录具备写权限</b></div>\
程序检测该文件编码为：<input type="text" size="10" name="charset" value="<?php echo $cha; ?>" />';
var contT = '<?php echo str_replace("'", "\'", preg_replace('/[\r\n]+/', '', $file)); ?>';
document.write('<'+'sc'+'ript language="javascript" src="inc/js/editor.js?'+new Date().getTime()+'" type="text/javascript"></'+'sc'+'ript>');
-->
</script>
<br />
<script language="javascript" type="text/javascript">
<!--
function toCodeMode() {
  toMode('c162100','f_c162100');
}

if (document.all) {
  window.attachEvent('onload', toCodeMode);//对于IE
} else {
  window.addEventListener('load', toCodeMode, false);//对于FireFox
}

-->
</script>
<?php

} else {
    $file = str_replace('&', '&amp;', $file);
    $file = str_replace('<', '&lt;', $file);
    $file = str_replace('>', '&gt;', $file);
?>


<form action="?post=modify" method="post" id="Zmodifyform" onsubmit="addSubmitSafe()">
  <textarea name="content" id="content" rows="30" style="width:98%;" wrap="off"><?php echo $file; ?></textarea>
  <br />
<div class="red_err">提交前请确定<?php echo dirname($thefile)=='.'?'根':dirname($thefile); ?>目录具备写权限</div>
  程序检测该文件编码为：<input type="text" size="10" name="charset" value="<?php echo $cha; ?>" />
  <input type="hidden" name="thefile" value="<?php echo $thefile; ?>" />
  <br />
  <button class="large" name="submit" type="submit" onclick="return confirm('提交吗？请确定无误后再执行');"><b>修改完必，确定提交</b></button>
  <button class="large" name="button" type="button" onclick="$('content').rows += 10;"><b>↓</b></button>
  <button class="large" type="button" onclick="$('content').wrap = 'soft';" title="换行显示"><b>┘</b></button>
</form>



<?php
}


  } else {
    echo '文件不存在！';
  }
else:
echo ($thefile && file_exists($thefile) && $thefile != '.') ? '&lt;<a href="?get=modify&otherfile='.get_en_url(dirname($thefile)).'">上级目录</a>&gt;<br />' : '';
echo '<div class="text">'.dirtree($thefile ? $thefile : '.').'</div>';
endif;

?>
