request->param('activepath') ?? DIRECTORY_SEPARATOR . "skin"; $activepath = replaceSymbol($activepath); if (!(stripos($activepath, "skin") != false)) { $activepath = DIRECTORY_SEPARATOR . "skin"; } $basePath = root_path() . DIRECTORY_SEPARATOR . 'templates' . $activepath; $fArr = array(); $arr_file = getDirFile($basePath, $activepath, $fArr, $this->template['template']); $filenameList = []; //文件目录 $r_file = []; //返回文件 foreach ($arr_file as $key => $file) { if (str_ends_with($file['filename'], ".css")) { $file['intro'] = "样式文件"; } elseif (str_ends_with($file['filename'], ".js")) { $file['intro'] = "JS脚本文件"; } else { $filenameArr = explode(".", $file['filename']); $suffix = $filenameArr[sizeof($filenameArr) - 1]; if (in_array($suffix, $this->fontArr)) { //字体文件 $file['intro'] = "字体文件"; } elseif (in_array($suffix, $this->allowImages)) { $file['intro'] = "图片文件"; } else { if (!($file['filetype'] == "dir2" || $file['filetype'] == "dir")) { $file['intro'] = "其它文件"; } } } if ($file['filemine'] == "file") { array_push($filenameList, $file['filename']); } else { array_push($r_file, $file); } $arr_file[$key] = $file; } sort($filenameList); foreach ($filenameList as $key => $filename) { foreach ($arr_file as $kk => $af) { if ($af['filename'] == $filename) { array_push($r_file, $af); break; } } } View::assign("arrFile", $r_file); View::assign("activepath", $activepath); return view('index'); } // 新增文件 public function addFile() { $activepath = $this->request->param("activepath") ?? DIRECTORY_SEPARATOR . "skin"; if ($this->request->isAjax()) { $columnId = $this->request->param("columnId"); $fileName = input("fileName", '', null); if (empty($fileName)) { $this->error("文件名称为空"); } foreach ($this->filters as $filter) { if ((strpos($fileName, $filter) != false)) { $fileName = str_replace($filter, "", $fileName); } } if (!(strpos($fileName, ".css") != false)) { $fileName = $fileName . ".css"; } $content = input("content", '', null); $file = root_path() . DIRECTORY_SEPARATOR . 'templates' . $activepath . DIRECTORY_SEPARATOR . $fileName; if (!is_writable(dirname($file))) { return "请把模板文件目录设置为可写入权限!"; } if (preg_match('#<([^?]*)\?php#i', $content) || (preg_match('#<\?#i', $content) && preg_match( '#\?>#i', $content )) || preg_match('#\{fox\:php([^\}]*)\}#i', $content) || preg_match('#\{php([^\}]*)\}#i', $content)) { return "模板里不允许有php语法,为了安全考虑,请通过FTP工具进行编辑上传。"; } $fp = fopen($file, "w"); fputs($fp, $content); fclose($fp); $this->success('操作成功!', url( '/' . config('adminconfig.admin_path') . '/TemplateStyle/index?columnId=' . $columnId, array('activepath' => $activepath) )); } View::assign('filePosition', $activepath); return view("add_file"); } // 删除文件 public function deleteFile() { $filePath = $this->request->param("filePath"); $file = root_path() . DIRECTORY_SEPARATOR . 'templates' . $filePath; if (!unlink($file)) { $this->error('操作失败!'); } else { $this->success('操作成功!'); } } // 编辑文件 public function editFile() { $activepath = $this->request->param("activepath"); $file = root_path() . DIRECTORY_SEPARATOR . 'templates' . $activepath; $arr = explode("/", $activepath); $fileName = $arr[count($arr) - 1]; if ($this->request->isAjax()) { if (!(str_ends_with($fileName, ".css"))) { $this->error("{$fileName}不能被修改"); } $content = input("content", '', null); if (!is_writable(dirname($file))) { return "请把模板文件目录设置为可写入权限!"; } if ( preg_match('#<([^?]*)\?php#i', $content) || (preg_match('#<\?#i', $content) && preg_match('#\?>#i', $content)) || preg_match('#\{fox\:php([^\}]*)\}#i', $content) || preg_match('#\{php([^\}]*)\}#i', $content) ) { return "模板里不允许有php语法,为了安全考虑,请通过FTP工具进行编辑上传。"; } $fp = fopen($file, "w"); fputs($fp, $content); fclose($fp); $this->success('操作成功!'); } /*读取文件内容*/ $content = ""; if (is_file($file)) { $filesize = filesize($file); if (0 < $filesize) { $fp = fopen($file, "r"); $content = fread($fp, $filesize); fclose($fp); } } View::assign('fileName', $fileName); View::assign('filePosition', $activepath); View::assign( 'content', $content ); return view('edit_file'); } }