public function render() { $this->loadFiles(); $args = $this->arguments; $seq = $this->seq(); // set default file upload options $fileuploadOptions = ['previewMaxWidth' => 280, 'previewMaxHeight' => 120, 'previewCrop' => false, 'autoUpload' => false, 'acceptFileTypes' => "(\\.|\\/)(.*)\$", 'maxFileSize' => 5000000, 'replaceFileInput' => false, 'disableImageResize' => true, 'imageCrop' => false, 'imageMaxWidth' => 480, 'imageMaxHeight' => 240]; // set file if (isset($args['file'])) { $file = File::find($args['file']); if ($file === null) { unset($args['file']); } else { $filename = $file->clientname; $args['file'] = $filename; } } // resolve arguments $fileuploadOptions = array_merge($fileuploadOptions, array_get($args, 'fileuploadOptions', [])); $args = array_add($args, 'width', 420); $args = array_add($args, 'height', 240); array_set($fileuploadOptions, 'previewMaxWidth', $args['width']); array_set($fileuploadOptions, 'previewMaxHeight', $args['height']); $types = array_get($args, 'types'); if ($types !== null) { array_set($fileuploadOptions, 'acceptFileTypes', '(\\.|\\/)(' . implode('|', (array) $types) . ')$'); } array_set($args, 'fileuploadOptions', $fileuploadOptions); // render template $this->template = \View::make($this->view, ['args' => $args, 'seq' => $seq])->render(); return parent::render(); }
/** * 회원의 프로필 이미지를 등록한다. * * @param UserInterface $user 프로필 이미지를 등록할 회원 * @param UploadedFile $profileFile 프로필 이미지 파일 * * @return string 등록한 프로필이미지 ID */ public function updateUserProfileImage(UserInterface $user, UploadedFile $profileFile) { $disk = array_get($this->profileImgConfig, 'storage.disk'); $path = array_get($this->profileImgConfig, 'storage.path'); $size = array_get($this->profileImgConfig, 'size'); // make fitted image /** @var ImageManager $imageManager */ $imageManager = call_user_func($this->imageManagerResolver); $image = $imageManager->make($profileFile->getRealPath()); $image = $image->fit($size['width'], $size['height']); // remove old profile image if (!empty($user->profileImageId)) { $file = File::find($user->profileImageId); if ($file !== null) { try { $this->storage->remove($file); } catch (\Exception $e) { } } } // save image to storage $id = $user->getId(); $file = $this->storage->create($image->encode()->getEncoded(), $path . "/{$id}", $id, $disk); return $file->id; }
public function updateSetting(SiteHandler $siteHandler, ThemeHandler $themeHandler, Request $request) { $newConfig = $request->only(['site_title', 'favicon']); $oldConfig = $siteHandler->getSiteConfig(); /* resolve site_title */ $oldConfig['site_title'] = $newConfig['site_title']; /* resolve favicon */ $uploaded = array_get($newConfig, 'favicon'); if ($uploaded !== null) { // remove old favicon file if ($oldId = $oldConfig->get('favicon.id')) { $oldId = $oldConfig->get('favicon.id'); if ($oldId !== null) { $oldFile = File::find($oldId); if ($oldFile !== null) { app('xe.storage')->remove($oldFile); } } } $saved = app('xe.storage')->upload($uploaded, 'filebox'); $favicon = ['id' => $saved->id, 'filename' => $saved->clientname]; $media = app('xe.media'); $mediaFile = null; if ($media->is($saved)) { $mediaFile = $media->make($saved); $favicon['path'] = $mediaFile->url(); } $oldConfig['favicon'] = $favicon; } $siteHandler->putSiteConfig($oldConfig); // resolve index instance $indexInstance = $request->get('indexInstance'); $siteHandler->setHomeInstanceId($indexInstance); return \Redirect::back()->with('alert', ['type' => 'success', 'message' => '저장되었습니다.']); }
/** * Get the instance as an array. * * @return array */ public function toArray() { $array = $this->meta->toArray(); $array['file'] = $this->file->toArray(); $array['url'] = $this->url(); return $array; }
public function getKeyFile() { if (!$this->file && $this->get('uuid')) { $files = File::getByFileable($this->get('uuid')); $this->file = $files->first(); } return $this->file; }
private function setProfileImageResolverOfUser() { $default = $this->app['config']['xe.user.profileImage.default']; $storage = $this->app['xe.storage']; $media = $this->app['xe.media']; User::setProfileImageResolver(function ($imageId) use($default, $storage, $media) { try { if ($imageId !== null) { /** @var Storage $storage */ $file = File::find($imageId); if ($file !== null) { /** @var MediaManager $media */ $mediaFile = $media->make($file); return asset($mediaFile->url()); } } } catch (\Exception $e) { } return asset($default); }); }
/** * Scope for derives * * @param Builder $query query builder instance * @param File $file file instance * @return Builder */ public function scopeDerives(Builder $query, File $file) { return $query->where('originId', $file->getKey()); }
/** * check exists a file * * @param File $file file instance * @return bool */ public function exists(File $file) { return $this->getDisk($file->disk)->exists($file->getPathname()); }
/** * setting 과정에서 upload되는 파일을 저장한다. * * @param string $configId config id * @param string $key config field key * @param UploadedFile $file file * * @return array */ protected function saveFile($configId, $key, UploadedFile $file) { $oldSetting = $this->setting(); $oldFileId = $oldSetting->get("{$key}.id"); // remove old file if ($oldFileId !== null) { $oldFile = File::find($oldFileId); if ($oldFile) { app('xe.storage')->remove($oldFile); } } // save new file $file = app('xe.storage')->upload($file, config('xe.theme.storage.path') . $configId, config('xe.theme.storage.disk')); $saved = ['id' => $file->id, 'filename' => $file->clientname]; $mediaFile = null; if (app('xe.media')->is($file)) { $mediaFile = app('xe.media')->make($file); $saved['path'] = $mediaFile->url(); } return $saved; }
/** * Extract file meta data * * @param File $file file instance * @return Meta */ protected function extractInformation(File $file) { $meta = new Meta(); $meta->id = $file->getId(); $meta->originId = $file->getOriginId(false); $tmpPathname = $this->temp->getTempPathname(); $this->temp->createFile($tmpPathname, $this->storage->read($file)); $info = $this->reader->analyze($tmpPathname); $this->temp->remove($tmpPathname); if (isset($info['audio']['streams'])) { unset($info['audio']['streams']); } $meta->audio = $info['audio']; $meta->video = $info['video']; $meta->playtime = $info['playtime_seconds']; $meta->bitrate = $info['bitrate']; return $meta; }
/** * 파일이 미디어 파일인지 확인 * * @param File $file file instance * @return bool */ public function is(File $file) { foreach ($this->handlers as $type => $handler) { if ($handler->isAvailable($file->getMime()) === true) { return true; } } return false; }
public function file($id) { $file = File::find($id); header('Content-type: ' . $file->mime); echo $file->getContent(); }
/** * update query * * @param File $file file instance * @return File */ public function update(File $file) { $diff = $file->diff(); if (count($diff) > 0) { $this->conn->table($this->table)->where('id', $file->id)->update($diff); } return $this->createFile(array_merge($file->getOriginal(), $diff)); }
/** * Returns image url list * * @return array */ public function getImages() { $files = File::getByFileable($this->getKey()); /** @var MediaManager $mediaManager */ $mediaManager = app('xe.media'); $imageHandler = $mediaManager->getHandler(Media::TYPE_IMAGE); $images = []; foreach ($files as $file) { if ($mediaManager->getFileType($file) === Media::TYPE_IMAGE) { $images[] = $imageHandler->make($file); } } return $images; }
/** * set the target be not have a file * * @param string $fileableId fileable identifier * @param File $file file instance * @param bool $remove remove file when given true * @return void */ public function unBind($fileableId, File $file, $remove = false) { $file->getConnection()->table($file->getFileableTable())->where('fileId', $file->getKey())->where('fileableId', $fileableId)->delete(); $file->useCount--; if ($remove === true && $file->useCount < 1) { $this->remove($file); } else { $file->save(); } }
protected static function bindGalleryThumb($item) { /** @var \Xpressengine\Media\MediaManager $mediaManager */ $mediaManager = \App::make('xe.media'); // board gallery thumbnails 에 항목이 없는 경우 if ($item->boardThumbnailFileId === null && $item->boardThumbnailPath === null) { // find file by document id $files = File::getByFileable($item->id); $fileId = ''; $externalPath = ''; $thumbnailPath = ''; if (count($files) == 0) { // find file by contents link or path $externalPath = static::getImagePathFromContent($item->content); // make thumbnail $thumbnailPath = $externalPath; } else { foreach ($files as $file) { if ($mediaManager->is($file) !== true) { continue; } // 어떤 크기의 썸네일을 사용할 것인지 스킨 설정을 통해 결정(두배 이미지가 좋다함) $dimension = 'L'; $media = Image::getThumbnail($mediaManager->make($file), BoardModule::THUMBNAIL_TYPE, $dimension); if ($media === null) { continue; } $fileId = $file->id; $thumbnailPath = $media->url(); break; } } $item->boardThumbnailFileId = $fileId; $item->boardThumbnailExternalPath = $externalPath; $item->boardThumbnailPath = $thumbnailPath; $model = new BoardGalleryThumb(); $model->fill(['targetId' => $item->id, 'boardThumbnailFileId' => $fileId, 'boardThumbnailExternalPath' => $externalPath, 'boardThumbnailPath' => $thumbnailPath]); $model->save(); } // 없을 경우 출력될 디폴트 이미지 (스킨의 설정으로 뺄 수 있을것 같음) if ($item->boardThumbnailPath == '') { $item->boardThumbnailPath = 'http://placehold.it/300x200'; } }
/** * setting 과정에서 upload되는 파일을 저장한다. * * @param $oldSetting * @param string $key config field key * @param UploadedFile $file file * @param string $path * @param string $disk * * @return array * @internal param string $configId config id */ protected function saveFile($oldSetting, $key, UploadedFile $file, $path, $disk = 'local') { $oldFileId = $oldSetting->get("{$key}.id"); // remove old file if ($oldFileId !== null) { $oldFile = File::find($oldFileId); if ($oldFile && file_exists($oldFile->getPathname())) { app('xe.storage')->remove($oldFile); } } // save new file $file = app('xe.storage')->upload($file, $path, $disk); $saved = ['id' => $file->id, 'filename' => $file->clientname]; $mediaFile = null; if (app('xe.media')->is($file)) { $mediaFile = app('xe.media')->make($file); $saved['path'] = $mediaFile->url(); } return $saved; }
/** * set files * * @param File $file file entity * @return void */ public function setFile(File $file) { $this->files[$file->getId()] = $file; }
/** * file destory * * @param Storage $storage * @param string $instanceId * @param string $id * @return RendererInterface */ public function fileDestroy(Storage $storage, $instanceId, $id) { if (empty($id) || !($file = File::find($id))) { throw new InvalidArgumentException(); } if ($file->userId !== Auth::id()) { throw new AccessDeniedHttpException(); } try { $result = $storage->remove($file); } catch (\Exception $e) { $result = false; } return XePresenter::makeApi(['deleted' => $result]); }
/** * 문서 삭제 * * @param Board $board board model * @param ConfigEntity $config board config entity * @return void * @throws \Exception */ public function remove(Board $board, ConfigEntity $config) { $board->getConnection()->beginTransaction(); // 덧글이 있다면 덧글들을 모두 삭제 if ($config->get('recursiveDelete') === true) { $query = Board::where('head', $board->head); if ($board->reply !== '' && $board->reply !== null) { $query->where('reply', 'like', $board->reply . '%'); } $items = $query->get(); foreach ($items as $item) { $this->setModelConfig($item, $config); if ($item->boardSlug !== null) { $item->boardSlug->delete(); } if ($item->boardCategory !== null) { $item->boardCategory->delete(); } $files = File::whereIn('id', $item->getFileIds())->get(); foreach ($files as $file) { $this->storage->unBind($item->id, $file, true); } $tags = Tag::getByTaggable($item->id); foreach ($tags as $tag) { $tag->delete(); } $item->delete(); } } else { if ($board->slug !== null) { $board->slug->delete(); } $files = File::whereIn('id', $board->getFileIds())->get(); foreach ($files as $file) { $this->storage->unBind($board->id, $file, true); } $tags = Tag::getByTaggable($board->id); foreach ($tags as $tag) { $tag->delete(); } $board->delete(); } $board->getConnection()->commit(); }
/** * destroyItem * 메뉴 아이템 삭제 처리 메소드 * * @param MenuHandler $handler menu handler * @param string $menuId menu id * @param string $itemId item id * * @return RedirectResponse * @throws Exception */ public function destroyItem(MenuHandler $handler, $menuId, $itemId) { $item = $handler->getItem($itemId); $menu = $item->menu; if ($menu->getKey() !== $menuId) { throw new InvalidArgumentHttpException(400); } XeDB::beginTransaction(); try { $handler->removeItem($item); foreach (File::getByFileable($item->getKey()) as $file) { XeStorage::unBind($item->getKey(), $file); } $handler->deleteMenuItemTheme($item); $this->permissionUnregister($handler->permKeyString($item)); } catch (Exception $e) { XeDB::rollback(); return Redirect::back()->with('alert', ['type' => 'danger', 'message' => $e->getMessage()]); } XeDB::commit(); return Redirect::route('settings.menu.index')->with('alert', ['type' => 'success', 'message' => 'MenuItem deleted']); }
/** * Get the instance as an array. * * @return array */ public function toArray() { $array = parent::toArray(); $array['url'] = $this->url(); if (!isset($array['meta'])) { $array['meta'] = $this->getRelationValue('meta'); } return $array; }
/** * get file's source * * @param string $url url * @param string $id id * * @return void */ public function fileSource($url, $id) { $file = File::find($id); /** @var \Xpressengine\Media\MediaManager $mediaManager */ $mediaManager = \App::make('xe.media'); if ($mediaManager->is($file) === true) { $dimension = 'L'; if (\Agent::isMobile() === true) { $dimension = 'M'; } $media = Image::getThumbnail($mediaManager->make($file), PageModule::THUMBNAIL_TYPE, $dimension); } header('Content-type: ' . $media->mime); echo $media->getContent(); }
/** * media 객체로 반환 * * @param File $file file instance * @param array $addInfo additional information * @return Image * @throws NotAvailableException */ public function make(File $file, array $addInfo = []) { if ($this->isAvailable($file->getMime()) !== true) { throw new NotAvailableException(); } if (!($meta = $this->repo->find($file->getId()))) { $meta = $this->extractInformation($file); foreach ($addInfo as $key => $value) { $meta->{$key} = $value; } $meta = $this->repo->insert($meta); } return $this->createModel($file, $meta); }
/** * Bootstrap the application events. * * @return void */ public function boot() { File::setContentReader($this->app['xe.storage']->getFilesystemHandler()); File::setUrlMaker($this->app['xe.storage.url']); }
/** * get file url path * * @param File $file file instance * @return string */ protected function getUrl(File $file) { $config = $this->getConfig($file->disk); if (isset($config['url']) === true) { return rtrim($config['url'], '/') . '/' . ltrim($file->getPathname(), '/'); } return null; }