<?php /** * 源码查看器 * @author rains31@gmail.com */ define('RAINS_ROOT',dirname(__FILE__)); $page_id = 10; require RAINS_ROOT.'/bootstrap.php'; require INCLUDE_PATH.'/header.php'; $file=isset($_REQUEST['file'])?$_REQUEST['file']:$_SERVER['PHP_SELF']; ?> <div id="main"> <fieldset> <legend> Source of <?php echo $file; ?> </legend> <code> <ol> <?php $allowed_dir = array(SITE_PATH.'/',SITE_PATH.'/include',SITE_PATH.'/data'); $allowed_type = array('.php'); $dir = strtr(dirname($file), DS, '/'); $type = strrchr($file,'.'); if(in_array($dir,$allowed_dir) && in_array($type,$allowed_type) && strpos($file,'..')===false && file_exists($_SERVER['DOCUMENT_ROOT'].$file)) { $contents = file_get_contents($_SERVER['DOCUMENT_ROOT'].$file); $contents = highlight_string($contents,true); $contents = str_replace('','',$contents); $contents = str_replace('','',$contents); $contents = str_replace('<code>','',$contents); $contents = str_replace('</code>','',$contents); $contents = preg_replace('/(require.*?)(INCLUDE_PATH)(.*?\'\/)([^\']*?\.php)(\')/','\\1\\2\\3<a href="source.php?file='.SITE_PATH.'/include/\\4">\\4</a>\\5',$contents); $contents = preg_replace('/(require.*?)(RAINS_ROOT)(.*?\'\/)([^\']*?\.php)(\')/','\\1\\2\\3<a href="source.php?file='.SITE_PATH.'/\\4">\\4</a>\\5',$contents); //$contents = preg_replace('/(require.*?)(.*?\')([^\']*?\.php)(\')/','\\1\\2<a href="source.php?file='.$dir.'/\\3">\\3</a>\\4',$contents); echo '<li />'.str_replace('<br />','<li />',$contents); } else { echo $file.'是不可查看的文件'; } ?> </ol> </code> </fieldset> </div> <?php require INCLUDE_PATH.'/footer.php'; ?>