path_app = BASIC_PATH;
$this->parent = dirname(BASIC_PATH);
$this->path_to = $this->parent.'/release';
$this->zip_to = $this->parent.'/tag/kodexplorer'.KOD_VERSION.'.zip';
parent::__construct();
}
/**
* 首页
*/
public function index() {
echo '';
debug_out(HOST,WEB_ROOT,BASIC_PATH,APPHOST,$config,$_COOKIE,$_SESSION,$_SERVER);
}
function less(){
header("Content-type: text/html; charset=utf-8");
ob_end_clean();
echo str_pad('',1024);
echo '
开始编译less
';flush();
$this->_less();
echo '成功!
';flush();
}
function export(){
header("Content-type: text/html; charset=utf-8");
ob_end_clean(); //在循环输出前,要关闭输出缓冲区
echo str_pad('',1024); //浏览器在接受输出一定长度内容之前不会显示缓冲输出
echo '开始导出!
删除初始文件
';flush();
del_dir($this->path_to);
echo '删除完成!
删除成功,开始编译less
';flush();
//$this->_less();
echo '编译成功!
开始复制文件
';flush();
$this->_fileInit();
echo '复制成功!
删除开发相关文件
';flush();
$this->_remove();
echo '删除成功!
开始替换模板种less相关内容
';flush();
$this->_fileReplace();
echo '替换成功!
打包程序
';flush();
load_class('pclzip');
ini_set('memory_limit', '2028M');//2G;
$archive = new PclZip($this->zip_to);
$v_list = $archive->create($this->path_to,PCLZIP_OPT_REMOVE_PATH,$this->parent.'/kod_export');
echo '打包成功!
初始化配置文件
';flush();
$this->_initUser();
echo '更新成功!
导出处理完成!^_^
';flush();
}
//----------------------------
function _less(){
load_class('lessc.inc');
$path = BASIC_PATH.'static/style/skin/';
$app_theme = array('default','metro','simple');
$app_less = array(
'app_code_edit',
'app_desktop',
'app_editor',
'app_explorer',
'app_setting'
);
$num = count($app_theme)*count($app_less);$i=1;
foreach($app_theme as $theme){
foreach($app_less as $app){
$less = new lessc();
$path_in = $path.$theme.'/'.$app.'.less';
$path_out = $path.$theme.'/'.$app.'.css';
try {
$cache = $less->cachedCompile($path_in);
$out = str_replace(array("{\n",";\n",",\n",' '),
array('{',';',',',' '),$cache["compiled"]);
file_put_contents($path_out,$out);
echo $path_out,' ...成功!('.$i++.'/'.$num.')','
';
unset($less);unset($out);
}catch (exception $e) {
echo "fatal error: " . $e->getMessage(),'
';
}
flush();
}
}
//编译metro多主题
$color_arr = array(
'blue' => '#5db2ff',
'leaf' => '#03B3B2',
'green' => '#008a17',
'grey' => '#444',
'purple' => '#8D3CC4',
'pink' => '#DC4FAD',
'orange' => '#FF8F32'
);
$config = $path.'metro/config.less';
$file = file_get_contents($config);
preg_match('/\/\*replace_start\*\/(.*)\/\*replace_end/isU',$file,$res);
$default = $res[1];
preg_match('/\/\*replace_start_color\*\/(.*)\/\*replace_end_color/isU',$file,$res2);
$new = $res2[1];
foreach ($color_arr as $name => $color) {
$theme = preg_replace('/@main_color:(.*);/isU',"@main_color:".$color.";",$new);
$file_str = preg_replace('/\/\*replace_start\*\/(.*)\/\*replace_end/isU',
"/*replace_start*/".$theme."/*replace_end",$file);
file_put_contents($config,$file_str);
foreach($app_less as $app){
$less = new lessc();
$path_in = $path.'metro/'.$app.'.less';
$path_out = $path.'metro/'.$name.'_'.$app.'.css';
try {
$cache = $less->cachedCompile($path_in);
$out = str_replace(array("{\n",";\n",",\n",' '),
array('{',';',',',' '),$cache["compiled"]);
file_put_contents($path_out,$out);
echo $path_out,' ...成功!('.$i++.'/'.$num.')','
';
}catch (exception $e) {
echo "fatal error: " . $e->getMessage(),'
';
}
flush();
}
}
$file_str = preg_replace('/\/\*replace_start\*\/(.*)\/\*replace_end/isU',
"/*replace_start*/".$default."/*replace_end",$file);
file_put_contents($config,$file_str);
}
function _fileInit(){
mk_dir($this->path_to);
echo '
新建文件夹成功,开始复制文件';flush();
copy_dir($this->path_app, $this->path_to);
echo '
复制文件成功,开始清除调试相关信息
';flush();
echo $this->path_app,'
',$this->path_to;
}
// 删除
function _remove(){
$file_list = array(
$this->path_to.'/controller/debug.class.php',
$this->path_to.'/lib/class/lessc.inc.class.php',
$this->path_to.'/static/style/base.less',
$this->path_to.'/static/js/lib/less-1.4.2.min.js',
$this->path_to.'/static/js/lib/webuploader/webuploader.js',
$this->path_to.'/static/style/skin/common.less',
$this->path_to.'/static/js/Gruntfile.js',
$this->path_to.'/static/js/package.json',
$this->path_to.'/static/js/readme.txt',
$this->path_to.'/todo.txt',
);
$path_list = array(
$this->path_to.'/data/log',
$this->path_to.'/data/User',
$this->path_to.'/data/thumb',
$this->path_to.'/static/js/_dev',
$this->path_to.'/static/js/app/update',
$this->path_to.'/static/js/node_modules'
);
foreach($file_list as $val){
del_file($val);
}
echo '
1.文件删除完成:';flush();
mkdir($this->path_to.'/data/User');
foreach($path_list as $val){
del_dir($val);
}
echo '
2.文件夹删除完成:';flush();
$path = $this->path_to.'/static/style/skin/';
$app_theme = array('default','metro','simple');
$app_less = array(
'app_code_edit','app_desktop','app_editor','app_explorer','app_setting',
'button','config','dialog','filelist','right_menu','tree'
);
foreach($app_theme as $theme){
foreach($app_less as $app){
$temp = $path.$theme.'/'.$app.'.less';
del_file($temp);
}
}
echo '
3.less文件删除完成
';flush();
}
// 删除less相关信息
function _fileReplace(){
$file_list = array(
$this->path_to.'/template/app/index.php',
$this->path_to.'/template/desktop/index.php',
$this->path_to.'/template/editor/edit.php',
$this->path_to.'/template/editor/editor.php',
$this->path_to.'/template/explorer/index.php',
$this->path_to.'/template/setting/index.php'
);
foreach($file_list as $val){
$content = file_get_contents($val);
$content = str_replace("",'',$content);
$content = str_replace("",'app',$content);
$content = preg_replace('/<\?php }else{\/\/less_compare_online \?>.*<\?php } \?>/isU','',$content);
file_put_contents($val,$content);
echo '
处理template文件:'.$val,'成功';flush();
}
$config = $this->path_to.'/config/config.php';
$content = file_get_contents($config);
$content = str_replace('define(\'STATIC_JS\'.*','',$content);
$content = str_replace('define(\'STATIC_LESS\'.*','',$content);
file_put_contents($config,$content);
}
// 默认用户初始化 admin/admin
function _initUser(){
echo '
开始创建用户';flush();
$root = array('home','recycle','data');
$home = array('desktop','doc','download','image','movie','music');
$user = array(
'admin'=>array('admin','root'),
'demo'=>array('demo','default'),
'guest'=>array('guest','guest')
);
foreach ($user as $name => $v) {
$user_path = $this->path_to.'/data/User/'.$name.'/';
mk_dir($user_path);
foreach ($root as $dir) {
mk_dir($user_path.$dir);
}
foreach ($home as $dir) {
mk_dir($user_path.'home/'.$dir);
}
fileCache::save($user_path.'data/config.php',$this->config['setting_default']);
}
$this->_initUserData();
}
function _initUserData(){
echo '
初始化用户数据';flush();
$role = '{"root":{"role":"root","name":"Administrator","path":"","ext_not_allow":""},"default":{"role":"default","name":"default","ext_not_allow":"php|asp|jsp","explorer:mkdir":1,"explorer:mkfile":1,"explorer:pathRname":1,"explorer:pathDelete":1,"explorer:zip":1,"explorer:unzip":1,"explorer:pathCopy":1,"explorer:pathCute":1,"explorer:pathCuteDrag":1,"explorer:clipboard":1,"explorer:pathPast":1,"explorer:pathInfo":1,"explorer:pathInfoMuti":1,"explorer:serverDownload":1,"explorer:fileUpload":1,"explorer:search":1,"app:user_app":1,"editor:fileSave":1},"guest":{"role":"guest","name":"guest","ext_not_allow":"php|asp|jsp"}}';
$user = '{"admin":{"name":"admin","password":"21232f297a57a5a743894a0e4a801fc3","role":"root","status":0},"guest":{"name":"guest","password":"084e0343a0486ff05530df6c705c8bb4","role":"guest","status":0},"demo":{"name":"demo","password":"fe01ce2a7fbac8fafaed7c982a04e229","role":"default","status":0}}';
file_put_contents($this->path_to.'/data/system/group.php',$role);
file_put_contents($this->path_to.'/data/system/member.php',$user);
}
}