request->domain(); $site->AddItem($domain, 0); $site->AddItem(url_rewrite('product', [], $domain), 1); $productcategory = Loader::model('ProductCategory')->getList(['stat' => ['eq', '0']], ['sort' => 'asc', 'id' => 'desc'], array('id', 'name')); foreach ($productcategory as $pc) { $site->AddItem(url_rewrite('product', ['id' => $pc['id']], $domain), 1); } $product = Loader::model('Product')->getList(['stat' => ['eq', '0']], ['sort' => 'asc', 'id' => 'desc'], array('id', 'name')); foreach ($product as $p) { $site->AddItem(url_rewrite('productdetail', ['id' => $p['id']], $domain), 1); } $res = $site->SaveToFile('sitemap.xml'); if ($res) { return $this->success(Lang::get('operation successed'), url('/admin/index/index')); } else { return $this->error(Lang::get('operation failed')); } } public function icon() { $iconName = $this->request->get('iconName', 'undefined'); $value = ['iconName' => $iconName]; $this->assign($value); Config::set('default_ajax_return', 'html'); $this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]); return $this->fetch(); } public function getajaxctrl() { $module = $this->request->get('module', 'index'); if ($this->request->isGet() && $module) { $html = get_ctrl_names($module); echo $html; exit; } else { echo Lang::get('operation failed'); exit; } } public function getajaxaction() { $ctrl = $this->request->get('controller', ''); $module = $this->request->get('module', 'index'); if ($this->request->isGet() && $ctrl) { $html = get_action_names($ctrl, 'app\\' . $module . '\\controller\\'); echo $html; exit; } else { echo Lang::get('operation failed'); exit; } } public function show() { Config::set('url_common_param', true); header("Content-Type: text/html; charset=utf-8"); if (Config::get('template.index.view_base')) { $this->basePath = Config::get('template.index.view_base') . DS; } else { $this->basePath = Config::get('template.index.view_path'); if (empty($this->basePath)) { $this->basePath = APP_PATH . 'index' . DS . 'view' . DS; } } $this->basePath = rtrim($this->basePath, '\/\\'); $filter_name = $this->request->get('filter_name', '', 'urldecode'); if (!empty($filter_name)) { $filter_name = trim(str_replace(['/../', '../', '*'], '', $filter_name), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F"); } $relativepath = $this->request->get('directory', '', 'urldecode'); if (!empty($relativepath)) { $relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F"); $directory = $this->basePath . '/' . $relativepath; } else { $directory = $this->basePath; } $type = $this->request->get('type', 'file'); $target = $this->request->get('target', ''); $func = $this->request->get('func', 'undefined'); $url = array(); $url['target'] = $target; $data['target'] = $target; $url['type'] = $type; $data['type'] = $type; $url['func'] = $func; $data['func'] = $func; //Config::set('url_common_param', true); //$config = Config::get('paginate'); $page = $this->request->request('page/d', 1); $page = $page < 1 ? 1 : $page; $directories = array(); $files = array(); $data['images'] = array(); if (substr($directory . '/' . $filter_name, 0, strlen($this->basePath)) == $this->basePath) { // Get directories $directories = glob($directory . '/' . $filter_name . '*', GLOB_ONLYDIR); if (!$directories) { $directories = array(); } switch ($type) { case 'image': // Get files $files = glob($directory . '/' . $filter_name . '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}', GLOB_BRACE); break; case 'file': // Get files $files = glob($directory . '/' . $filter_name . '*.*', GLOB_BRACE); break; default: // Get files $files = glob($directory . '/' . $filter_name . '*', GLOB_BRACE); break; } if (!$files) { $files = array(); } } // Merge directories and files $images = array_merge($directories, $files); // Get total number of files and directories $image_total = count($images); // Split the array based on current page number and max number of items per page of 10 $images = array_splice($images, ($page - 1) * 16, 16); foreach ($images as $image) { $name = basename($image); if (is_dir($image)) { $path = substr($image, strlen($this->basePath)); $url['directory'] = urlencode(substr($image, strlen($this->basePath))); $data['images'][] = array( 'name' => $name, 'type' => 'directory', 'path' => $path, 'href' => url('/admin/tool/show', array_filter($url), true) ); } elseif (is_file($image)) { $path = substr($image, strlen($this->basePath)); $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION)); switch ($ext) { case 'jpg': case 'png': case 'gif': case 'bmp': case 'jpeg': $data['images'][] = array( 'name' => $name, 'type' => 'image', 'path' => $path, 'href' => $this->request->domain() . $path ); break; case 'html': case 'phtml': case 'php': case 'htm': case 'js': case 'css': case 'txt': $data['images'][] = array( 'name' => $name, 'type' => 'text', 'path' => $path, 'href' => 'javascript:void(0);' ); break; case 'avi': case 'mp4': case 'rmvb': case 'mkv': case 'wmv': $data['images'][] = array( 'name' => $name, 'type' => 'video', 'path' => $path, 'href' => 'javascript:void(0);' ); break; case 'zip': case 'rar': case 'gz': case 'tar': case 'tgz': case 'gz': case 'iso': $data['images'][] = array( 'name' => $name, 'type' => 'archive', 'path' => $path, 'href' => 'javascript:void(0);' ); break; default: $data['images'][] = array( 'name' => $name, 'type' => 'other', 'path' => $path, 'href' => 'javascript:void(0);' ); break; } } } $data['filter_name'] = $filter_name; $url['directory'] = urlencode($relativepath); $data['directory'] = urlencode($relativepath); // Refresh $data['refresh'] = url('/admin/tool/show', array_filter($url), true); if (!empty($relativepath)) { $pos = strrpos($relativepath, '/'); if ($pos) { $url['directory'] = urlencode(substr($relativepath, 0, $pos)); } else { $url['directory'] = ''; } } // Parent if (!empty($relativepath)) { $pos = strrpos($relativepath, '/'); if ($pos) { $url['directory'] = urlencode(substr($relativepath, 0, $pos)); } else { $url['directory'] = ''; } } $data['parent'] = url('/admin/tool/show', array_filter($url), true); //Pagination if (!empty($relativepath)) { $url['directory'] = urlencode($relativepath); } if (!empty($filter_name)) { $url['filter_name'] = urlencode($filter_name); } $url['page'] = '{page}'; $pagination = new Pagination(); $pagination->total = $image_total; $pagination->page = $page; $pagination->limit = 16; $pagination->url = url('/admin/tool/show', array_filter($url), true); $data['pagination'] = $pagination->render(); $this->assign($data); Config::set('default_ajax_return', 'html'); $this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]); return $this->fetch(); } public function showcontent() { Config::set('url_common_param', true); header("Content-Type: text/html; charset=utf-8"); if (Config::get('template.index.view_base')) { $this->basePath = Config::get('template.index.view_base') . '/'; } else { $this->basePath = Config::get('template.index.view_path'); if (empty($this->basePath)) { $this->basePath = APP_PATH . 'index' . '/' . 'view' . '/'; } } $this->basePath = rtrim($this->basePath, '\/\\'); $filename = $this->request->get('filename', '', 'urldecode'); if (!empty($filename)) { $filename = trim(str_replace(['/../', '../', '*'], '', $filename), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F"); $file = $this->basePath . '/' . $filename; //print_r(is_file($file));exit; if (is_file($file)) { $data['filename'] = '/' . $filename; $data['content'] = file_get_contents($file); $this->assign($data); } } Config::set('default_ajax_return', 'html'); $this->view->engine(['type' => 'php', 'view_suffix' => 'html', 'tpl_replace_string' => [],]); return $this->fetch(); } public function updatecontent() { if (Config::get('template.index.view_base')) { $this->basePath = Config::get('template.index.view_base') . '/'; } else { $this->basePath = Config::get('template.index.view_path'); if (empty($this->basePath)) { $this->basePath = APP_PATH . 'index' . '/' . 'view' . '/'; } } $this->basePath = rtrim($this->basePath, '\/\\'); $content = $this->request->param('filecontent', '', 'urldecode'); $filename = $this->request->param('filename', '', 'urldecode'); if (!empty($filename)) { $filename = trim(str_replace(['/../', '../', '*'], '', $filename), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F"); $file = $this->basePath . '/' . $filename; //print_r(is_file($file));exit; if (is_file($file)) { $result = file_put_contents($file, $content); return $this->result([], $result, '更新成功'); } } return $this->result([], false, '未知错误'); } public function rename() { if (Config::get('template.index.view_base')) { $this->basePath = Config::get('template.index.view_base') . DS; } else { $this->basePath = Config::get('template.index.view_path'); if (empty($this->basePath)) { $this->basePath = APP_PATH . 'index' . DS . 'view' . DS; } } $this->basePath = rtrim($this->basePath, '\/\\'); $json = array(); // Make sure we have the correct directory $relativepath = $this->request->get('directory', '', 'urldecode'); if (isset($relativepath)) { $relativepath = trim(str_replace(['/../', '../', '*'], '', $relativepath), "\x20\x09\x0A\x0D\x00\x0B\x2E\x2F"); $directory = $this->basePath . '/' . $relativepath; } else { $directory = $this->basePath; } // Check its a directory if (!is_dir($directory) || substr($directory, 0, strlen($this->basePath)) != $this->basePath) { $json['error'] = '路径错误'; echo json_encode($json); exit; } if ($this->request->isPost()) { // Sanitize the folder name $path = $this->request->post('path', '', 'urldecode'); $pathinfo = pathinfo($path); $filenewname = $this->request->post('filenewname', '', 'urldecode'); // Validate the filename length if (!preg_match('/^[0-9a-zA-Z_-]+$/', $filenewname)) { $json['error'] = $filenewname . '文件名称不是由数字字母下划线组成'; echo json_encode($json); exit; } // Validate the filename length if ((strlen($filenewname) < 3) || (strlen($filenewname) > 128)) { $json['error'] = $filenewname . '文件名长度错误,至少3个字符以上'; echo json_encode($json); exit; } // Check if directory already exists or not if (!file_exists($directory . '/' . $pathinfo['basename']) || !(file_exists($this->basePath . $path))) { $json['error'] = $pathinfo['filename'] . '文件不存在'; echo json_encode($json); exit; } if (!isset($json['error'])) { rename($this->basePath . $path, $directory . '/' . $filenewname . ($pathinfo['extension'] ? '.' . $pathinfo['extension'] : '')); $json['success'] = '文件重命名成功'; } } echo json_encode($json); exit; } }