public static function getJson($code, $path = '/', $type = 'arr') { import('ORG.Net.FileSystem'); $sys = new FileSystem(); //main $basepath = RUNTIME_PATH . 'Data/Json/' . $path; $filename = '/' . $code . '_data.json'; $json = $sys->getFile($basepath . $filename); if ($type == 'obj') { return json_decode($json); } elseif ($type == 'arr') { return json_decode($json, true); } }
/** * 显示备份、还原数据库流 *@param $act bak为备份、re为还原 *@param $total 传入表总数 *@param $go 为1时,获取post *@examlpe */ public function show($act, $total = NULL, $go = -1, $page = -1) { $Public = A('Index', 'Public'); $Public->check('Backup', array('c')); $sql = A('Sql', 'Public'); //实例化sql类 //实例化文件系统操作类 import('ORG.Net.FileSystem'); $path = new FileSystem(); $path->root = ITEM; $path->charset = C('CFG_CHARSET'); set_time_limit(1000); //main if ($go >= 0) { if ($act == 'bak') { $str_table = $path->getFile(RUNTIME_PATH . '/database.tmp'); $arr_table = unserialize($str_table); if ($go == count($arr_table['table'])) { cookie('badate', NULL); $path->delFile(RUNTIME_PATH . '/database.tmp'); $path->delFile(RUNTIME_PATH . '/backup.tmp'); cookie('info_step', NULL); cookie('info_page', NULL); echo '所有表已完成备份!|0|0'; exit; } if (cookie('badate')) { $badate = cookie('badate'); } else { $badate = date("Y-m-d_His"); cookie('badate', $badate); } $bak_dir = ROOT . '/Conf/Backup/' . $badate; if (!file_exists($bak_dir)) { $path->putDir($bak_dir, 0777); } $strfile = ''; $table = $arr_table['table'][$go]; $tb = str_replace(C('DB_PREFIX'), '#@_', $table); $result = M(); $str_info = $path->getFile(RUNTIME_PATH . '/backup.tmp'); if ($str_info) { $str_info = slashes($str_info); $info = unserialize($str_info); $page = cookie('info_page') ? cookie('info_page') : 0; $p = cookie('info_step') ? cookie('info_step') : 1; } else { $count = $result->table($table)->count(); $total = ceil($count / 10000); if (cookie('info_page')) { $page = cookie('info_page'); } else { $page = 0; } if ($count > 10000) { $info = $result->table($table)->limit($page * 10000, 10000)->select(); if ($page < $total) { if ($page == 0) { $p = 1; } else { $p = cookie('info_step') ? cookie('info_step') : 1; } $page++; cookie('info_page', $page); if ($p == 1) { $strfile .= "DROP TABLE IF EXISTS `" . $tb . "`;\r\n"; $table_field = $sql->getField($table); //获取表结构 //替换数据表名 $mysql = mysql_get_server_info(); $get_field = preg_replace("/AUTO_INCREMENT=[0-9]+\\s+/", "", $table_field); if ($arr_table['version'] == 4.1 && $mysql > 4.1) { $get_field = preg_replace("/ENGINE=\\b.{2,}\\b DEFAULT CHARSET=\\S+/", 'ENGINE=MyISAM DEFAULT CHARSET=' . $arr_table['charset'], $get_field); } elseif ($arr_table['version'] == 4.1 && $mysql < 4.1) { $get_field = preg_replace("TYPE=\\b.{2,}\\b", 'ENGINE=MyISAM DEFAULT CHARSET=' . $arr_table['charset'], $get_field); } elseif ($arr_table['version'] == 4.0 && $mysql > 4.1) { $get_field = preg_replace("/ENGINE=\\b.{2,}\\b DEFAULT CHARSET=\\S+/", 'TYPE=MyISAM', $get_field); } $strfile .= str_replace('CREATE TABLE `' . C('DB_PREFIX'), 'CREATE TABLE `#@_', $get_field . ";\r\n"); } } else { $page = 0; cookie('info_page', NULL); $p = cookie('info_step') ? cookie('info_step') : 1; } } else { $strfile .= "DROP TABLE IF EXISTS `" . $tb . "`;\r\n"; $table_field = $sql->getField($table); //获取表结构 //替换数据表名 $mysql = mysql_get_server_info(); $get_field = preg_replace("/AUTO_INCREMENT=[0-9]+\\s+/", "", $table_field); if ($arr_table['version'] == 4.1 && $mysql > 4.1) { $get_field = preg_replace("/ENGINE=\\b.{2,}\\b DEFAULT CHARSET=\\S+/", 'ENGINE=MyISAM DEFAULT CHARSET=' . $arr_table['charset'], $get_field); } elseif ($arr_table['version'] == 4.1 && $mysql < 4.1) { $get_field = preg_replace("TYPE=\\b.{2,}\\b", 'ENGINE=MyISAM DEFAULT CHARSET=' . $arr_table['charset'], $get_field); } elseif ($arr_table['version'] == 4.0 && $mysql > 4.1) { $get_field = preg_replace("/ENGINE=\\b.{2,}\\b DEFAULT CHARSET=\\S+/", 'TYPE=MyISAM', $get_field); } $strfile .= str_replace('CREATE TABLE `' . C('DB_PREFIX'), 'CREATE TABLE `#@_', $get_field . ";\r\n"); $info = $result->table($table)->select(); cookie('info_page', NULL); cookie('info_step', NULL); $page = 0; $p = 1; } } if ($info) { while (true) { $t = array_shift($info); $strfile .= $sql->getData($table, $t); if (strlen($strfile) >= $arr_table['filesize'] * 1024) { $filename = $tb . '_' . str_pad($p, 5, "0", STR_PAD_LEFT) . '.bak'; $fie_path = $bak_dir . '/' . $filename; $path->putFile($fie_path, $strfile); $p++; $strfile = ''; cookie('info_step', $p); $path->putFile(RUNTIME_PATH . '/backup.tmp', serialize($info)); echo '<p>表“' . $table . '_' . str_pad($p - 1, 5, "0", STR_PAD_LEFT) . '”备份成功!</p>|1|' . $page; exit; } else { if (count($info)) { continue; } else { break; } } } } if ($p == 1) { $filename = $tb . '.bak'; $fie_path = $bak_dir . '/' . $filename; $path->putFile($fie_path, $strfile); $path->delFile(RUNTIME_PATH . '/backup.tmp'); echo '<p>表“' . $table . '”备份成功!</p>|0|0'; exit; } else { if ($strfile) { $filename = $tb . '_' . str_pad($p, 5, "0", STR_PAD_LEFT) . '.bak'; $fie_path = $bak_dir . '/' . $filename; $path->putFile($fie_path, $strfile); } $path->delFile(RUNTIME_PATH . '/backup.tmp'); if ($page > 0) { cookie('info_step', $p + 1); } echo '<p>表“' . $table . '_' . str_pad($p, 5, "0", STR_PAD_LEFT) . '”备份成功!</p>|0|' . $page; exit; } } elseif ($act == 're') { $str_table = $path->getFile(RUNTIME_PATH . '/database.tmp'); $arr_table = unserialize($str_table); if ($go == count($arr_table['table'])) { $path->delFile(RUNTIME_PATH . '/database.tmp'); echo '所有表已完成还原!|0|0'; exit; } $table = str_replace('#@_', C('DB_PREFIX'), $arr_table['table'][$go]); $tb = str_replace('.bak', '', $table); $tablefile = $arr_table['path'] . '/' . $arr_table['table'][$go]; $info = $path->getFile($tablefile); $arr_info = explode(";\r\n", $info); $result = M(); foreach ($arr_info as $t) { $t = preg_replace("/`#@_(.+)?`/iu", '`' . C('DB_PREFIX') . '$1`', $t); $t = str_replace(';', ';', $t); $char = C('CFG_CHARSET'); if ($char == 'UTF-8') { $char = 'utf8'; } else { $char = 'gb2312'; } $t = preg_replace("/ENGINE=\\b.{2,}\\b DEFAULT CHARSET=\\S+/", 'ENGINE=MyISAM DEFAULT CHARSET=' . $char, $t); $result->execute($t); } echo '<p>表“' . $tb . '”还原成功!</p>|0|0'; exit; } } else { $this->assign('act', $act); $this->assign('total', $total); $this->display(); } }
/** * 升级检查 *@examlpe */ public function upver() { $nowtime = time(); import('ORG.Net.FileSystem'); $sys = new FileSystem(); $sys->root = ITEM; $sys->charset = C('CFG_CHARSET'); $App = A('App', 'Public'); //main $nowdate = date("Y-m-d H:i:s", $nowtime); $path = CONF_PATH . 'version.txt'; $ver = $sys->getFile($path); $arr_ver = explode(";\r\n", $ver); $arr_ver = array_filter($arr_ver); $content = $arr_ver[0] . ";\r\n" . $nowdate . ";\r\n" . $arr_ver[2] . ";\r\n"; $sys->putFile($path, $content); echo "当前版本:{$arr_ver['0']} 最后检测时间:{$nowdate}"; }
/** * 编辑权限配置文件 *@param $id 传入的数据ID *@examlpe */ public function role($id, $go = 0) { import('ORG.Net.FileSystem'); $sys = new FileSystem(); $Public = A('Index', 'Public'); //main $id = intval($id); if ($go == 0) { $menu = M('Menu'); $code = $menu->where('id=' . $id)->getField('code'); $path = CONF_PATH . '/Role/' . $code . 'Role.php'; $file = $sys->getFile($path); $this->assign('file', $file); $this->assign('code', $code); $this->assign('uniqid', uniqid()); $this->assign('id', $id); $this->assign('path', '/Conf/Role/' . $code . 'Role.php'); $this->display(); } else { $role = $Public->check('Menu', array('u')); if ($role < 0) { echo $role; exit; } $code = I('code'); $data = I('file', '', false); if (!preg_match("/^\\<\\?php/i", $data)) { $data = "<?php\r\n" . $data; } $path = $path = CONF_PATH . '/Role/' . $code . 'Role.php'; if ($code) { $edit = $sys->putFile($path, $data); if ($edit == 1) { echo 1; } else { echo 0; } } else { echo 2; } } }