public function edit(Request $request, ThemeHandler $themeHandler)
 {
     $editable = session('theme.editable');
     if (!$editable) {
         return \XePresenter::make('theme.edit-auth');
     }
     $themeId = $request->get('theme');
     $fileName = $request->get('file');
     // TODO: validate themeid, fileName
     if ($themeId === null) {
         $e = new InvalidArgumentHttpException();
         $e->setMessage('잘못된 요청입니다.');
         throw $e;
     }
     $theme = \XeTheme::getTheme($themeId);
     /** @var ThemeEntityInterface $theme */
     $files = $theme->getEditFiles();
     if (empty($files)) {
         return \XePresenter::make('theme.edit', ['theme' => $theme, 'files' => $files]);
     }
     if ($fileName === null) {
         $fileName = key($files);
     }
     $filePath = realpath($files[$fileName]);
     $editFile = ['fileName' => $fileName, 'path' => $filePath];
     if ($themeHandler->hasCache($filePath)) {
         $editFile['hasCache'] = true;
         $fileContent = file_get_contents($themeHandler->getCachePath($filePath));
     } else {
         $editFile['hasCache'] = false;
         $fileContent = file_get_contents($filePath);
     }
     $editFile['content'] = $fileContent;
     return \XePresenter::make('theme.edit', ['theme' => $theme, 'files' => $files, 'editFile' => $editFile]);
 }
Esempio n. 2
0
 public function edit(Request $request)
 {
     $themeId = $request->get('theme');
     $fileName = $request->get('file');
     $type = $request->get('type', 'views');
     // TODO: validate themeid, fileName
     if ($themeId === null) {
         $e = new InvalidArgumentHttpException();
         $e->setMessage('잘못된 요청입니다.');
         throw $e;
     }
     $theme = \XeTheme::getTheme($themeId);
     /** @var ThemeEntityInterface $theme */
     $files = $theme->getEditFiles();
     if (empty($files)) {
         return \XePresenter::make('theme.edit', ['theme' => $theme, 'files' => $files]);
     }
     if ($fileName === null) {
         $fileName = key($files[$type]);
     }
     if (!is_writable($files[$type][$fileName])) {
         \View::share('_alert', ['type' => 'danger', 'message' => '파일을 수정할 권한이 없습니다. 웹서버의 계정이 편집할 파일의 쓰기(w)권한을 가지고 있어야 합니다.']);
     }
     $fileContent = file_get_contents($files[$type][$fileName]);
     $editFile = ['fileName' => $fileName, 'path' => $files[$type][$fileName], 'content' => $fileContent];
     return \XePresenter::make('theme.edit', ['theme' => $theme, 'files' => $files, 'editFile' => $editFile, 'type' => $type]);
 }