/** * 数据库备份导入 * * @param string $path 目录 * @param int $step 步骤,也是第几个文件 * @return array $rs_row 返回数组形式的查询结果 */ public function import($path, $step = 1) { $dir = BASE_ROOT_PATH . DS . 'sql_back' . DS . $path; $file_list = array(); uk86_readFileList($dir, $file_list); /** * 过滤文件 */ if (!empty($file_list) && is_array($file_list)) { foreach ($file_list as $key => $file_name) { if (strtolower(substr($file_name, -4)) == '.sql') { $tmp_list[] = $file_name; } } $file_list = $tmp_list; } foreach ($file_list as $k => $v) { $varr = explode('_', $v); $file_list[$k] = $varr['0'] . '_' . $varr['1'] . '_' . $varr['2'] . '_' . $varr['3'] . '_' . ($k + 1) . '_' . $varr['5']; } $file_name = $file_list[$step - 1]; //此处使用is_file来判断该sql文件是否存在,不使用file_exists if (is_file($file_name)) { $handle = @fopen($file_name, "r"); $tmp_sql = ''; if ($handle) { while (!feof($handle)) { $buffer = fgets($handle); if (trim($buffer) != '') { $tmp_sql .= $buffer; if (substr(rtrim($buffer), -1) == ';') { if (preg_match('/^(CREATE|ALTER|DROP)\\s+(VIEW|TABLE|DATABASE|SCHEMA)\\s+/i', ltrim($tmp_sql))) { //标准的SQL语句,将被执行 } else { if (preg_match('/^(INSERT)\\s+(INTO)\\s+/i', ltrim($tmp_sql)) && substr(rtrim($buffer), -2) == ');') { //标准的SQL语句,将被执行 } else { if (preg_match('/^(SET)\\s+SQL_MODE=/i', ltrim($tmp_sql))) { //SET SQL_MODE 设置,将被执行 } else { //不能组成标准的SQL语句,继续向下一行取内容,直到组成合法的SQL为止 continue; } } } if (!empty($tmp_sql)) { /** * 销毁当前用户Session信息 */ if (strpos($tmp_sql, uk86_cookie('sess_id')) !== false) { unset($tmp_sql); continue; } Db::query($tmp_sql, 'slave'); unset($tmp_sql); } } } } @fclose($handle); } /** * 判断是否还有下个文件 */ if (empty($file_list[$step])) { return 'succ'; } else { return 'continue'; } } else { return false; } }
/** * 水印管理 */ public function store_watermarkOp() { /** * 读取语言包 */ Uk86Language::uk86_read('member_store_index'); $model_store_wm = Model('store_watermark'); /** * 获取会员水印设置 */ $store_wm_info = $model_store_wm->getOneStoreWMByStoreId($_SESSION['store_id']); /** * 保存水印配置信息 */ if (uk86_chksubmit()) { $param = array(); $param['wm_image_pos'] = $_POST['image_pos']; $param['wm_image_transition'] = $_POST['image_transition']; $param['wm_text'] = $_POST['wm_text']; $param['wm_text_size'] = $_POST['wm_text_size']; $param['wm_text_angle'] = $_POST['wm_text_angle']; $param['wm_text_font'] = $_POST['wm_text_font']; $param['wm_text_pos'] = $_POST['wm_text_pos']; $param['wm_text_color'] = $_POST['wm_text_color']; $param['jpeg_quality'] = $_POST['image_quality']; if (!empty($_FILES['image']['name'])) { $upload = new Uk86UploadFile(); $upload->uk86_set('default_dir', ATTACH_WATERMARK); $result = $upload->uk86_upfile('image'); if ($result) { $param['wm_image_name'] = $upload->file_name; /** * 删除旧水印 */ if (!empty($store_wm_info['wm_image_name'])) { @unlink(BASE_UPLOAD_PATH . DS . ATTACH_WATERMARK . DS . $store_wm_info['wm_image_name']); } } else { showDialog($upload->error); } } elseif ($_POST['is_del_image'] == 'ok') { /** * 删除水印 */ if (!empty($store_wm_info['wm_image_name'])) { $param['wm_image_name'] = ''; @unlink(BASE_UPLOAD_PATH . DS . ATTACH_WATERMARK . DS . $store_wm_info['wm_image_name']); } } $param['wm_id'] = $store_wm_info['wm_id']; $result = $model_store_wm->updateStoreWM($param); if ($result) { showDialog(Uk86Language::uk86_get('store_watermark_congfig_success'), 'reload', 'succ'); } else { showDialog(Uk86Language::uk86_get('store_watermark_congfig_fail')); } } /** * 获取水印字体 */ $dir_list = array(); uk86_readFileList(BASE_RESOURCE_PATH . DS . 'font', $dir_list); if (!empty($dir_list) && is_array($dir_list)) { $fontInfo = array(); include BASE_RESOURCE_PATH . DS . 'font' . DS . 'font.info.php'; foreach ($dir_list as $value) { $d_array = explode('.', $value); if (strtolower(end($d_array)) == 'ttf' && file_exists($value)) { $dir_array = explode('/', $value); $value = array_pop($dir_array); $tmp = explode('.', $value); $file_list[$tmp[0]] = $fontInfo[$tmp[0]]; } } /** * 转码 */ if (strtoupper(CHARSET) == 'GBK') { $file_list = Uk86Language::uk86_getGBK($file_list); } Tpl::output('file_list', $file_list); } if (empty($store_wm_info)) { /** * 新建店铺水印设置信息 */ $model_store_wm->addStoreWM(array('wm_text_font' => 'default', 'store_id' => $_SESSION['store_id'])); $store_wm_info = $model_store_wm->getOneStoreWMByStoreId($_SESSION['store_id']); } self::profile_menu('album', 'watermark'); Tpl::output('store_wm_info', $store_wm_info); Tpl::showpage('store_watermark.form'); }
/** * ajax操作 */ public function ajaxOp() { switch ($_GET['branch']) { /** * 数据库 sql列表 */ case 'db_file': if ($_GET['dir_name'] != '.' && $_GET['dir_name'] != '..' && is_dir(BASE_ROOT_PATH . DS . 'sql_back' . DS . $_GET['dir_name'])) { $dir = BASE_ROOT_PATH . DS . 'sql_back' . DS . $_GET['dir_name']; $tmp = array(); uk86_readFileList($dir, $tmp); /** * 整理内容 */ if (is_array($tmp)) { $file_list = array(); foreach ($tmp as $k => $v) { $file_list[$k]['name'] = $v; $file_list[$k]['make_time'] = date('Y-m-d H:i:s', filemtime($dir . DS . $v)); $file_list[$k]['size'] = number_format(filesize($dir . DS . $v) / 1024, 2) . 'KB'; } $output = json_encode($file_list); print_r($output); } exit; } else { echo 'false'; exit; } break; } }
/** * 水印字体 * * @param * @return */ public function fontOp() { //获取水印字体 $dir_list = array(); uk86_readFileList(BASE_RESOURCE_PATH . DS . 'font', $dir_list); if (!empty($dir_list) && is_array($dir_list)) { $fontInfo = array(); include BASE_RESOURCE_PATH . DS . 'font' . DS . 'font.info.php'; foreach ($dir_list as $value) { $file_ext_array = explode('.', $value); if (strtolower(end($file_ext_array)) == 'ttf' && file_exists($value)) { $file_path_array = explode('/', $value); $value = array_pop($file_path_array); $tmp = explode('.', $value); $file_list[$value] = $fontInfo[$tmp[0]]; } } //转码 if (strtoupper(CHARSET) == 'GBK') { $file_list = Uk86Language::uk86_getGBK($file_list); } Tpl::output('file_list', $file_list); } Tpl::output('top_link', $this->sublink($this->links, 'font')); Tpl::showpage('upload.font'); }
/** * 获取文件列表(所有子目录文件) * * @param string $path 目录 * @param array $file_list 存放所有子文件的数组 * @param array $ignore_dir 需要忽略的目录或文件 * @return array 数据格式的返回结果 */ function uk86_readFileList($path, &$file_list, $ignore_dir = array()) { $path = rtrim($path, '/'); if (is_dir($path)) { $handle = @opendir($path); if ($handle) { while (false !== ($dir = readdir($handle))) { if ($dir != '.' && $dir != '..') { if (!in_array($dir, $ignore_dir)) { if (is_file($path . DS . $dir)) { $file_list[] = $path . DS . $dir; } elseif (is_dir($path . DS . $dir)) { uk86_readFileList($path . DS . $dir, $file_list, $ignore_dir); } } } } @closedir($handle); // return $file_list; } else { return false; } } else { return false; } }