From fada6c4ff1f8f1b8d908c78e1d37494b10543107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Tue, 22 Aug 2017 20:18:46 +0200 Subject: [PATCH] FEATURE: move gallery into own repository --- Config/config.php | 12 + Handlers/Gallery.php | 254 ++++++++++++++++++ Providers/GalleryServiceProvider.php | 16 ++ Resources/lang/cs/admin/adminMenu.php | 6 + Resources/lang/cs/admin/content.php | 11 + Resources/lang/cs/module.php | 5 + Resources/lang/en/admin/adminMenu.php | 6 + Resources/lang/en/admin/content.php | 11 + Resources/lang/en/module.php | 6 + Resources/lang/sk/admin/adminMenu.php | 6 + Resources/lang/sk/admin/content.php | 11 + Resources/lang/sk/module.php | 5 + .../views/admin/content/editUpload.blade.php | 12 + .../views/admin/content/newUpload.blade.php | 3 + start.php | 2 + 15 files changed, 366 insertions(+) create mode 100755 Config/config.php create mode 100644 Handlers/Gallery.php create mode 100644 Providers/GalleryServiceProvider.php create mode 100755 Resources/lang/cs/admin/adminMenu.php create mode 100755 Resources/lang/cs/admin/content.php create mode 100755 Resources/lang/cs/module.php create mode 100755 Resources/lang/en/admin/adminMenu.php create mode 100755 Resources/lang/en/admin/content.php create mode 100755 Resources/lang/en/module.php create mode 100755 Resources/lang/sk/admin/adminMenu.php create mode 100755 Resources/lang/sk/admin/content.php create mode 100755 Resources/lang/sk/module.php create mode 100755 Resources/views/admin/content/editUpload.blade.php create mode 100755 Resources/views/admin/content/newUpload.blade.php create mode 100755 start.php diff --git a/Config/config.php b/Config/config.php new file mode 100755 index 0000000..2a2b723 --- /dev/null +++ b/Config/config.php @@ -0,0 +1,12 @@ + 'Gallery', + 'translatedName' => 'gallery::module.name', + 'translatedDescription' => 'gallery::module.description', + 'alias' => 'gallery', + 'handler' => '\\Modules\\Gallery\\Handlers\\Gallery', + 'providers' => [\Modules\Gallery\Providers\GalleryServiceProvider::class], + 'files' => ['start.php'], + 'order' => 0, +]; \ No newline at end of file diff --git a/Handlers/Gallery.php b/Handlers/Gallery.php new file mode 100644 index 0000000..48e203e --- /dev/null +++ b/Handlers/Gallery.php @@ -0,0 +1,254 @@ +moduleSettings->directoryId; + + // get all images in given directory + $images = File::where('directory_id', $directoryId) + ->where('mime_type', 'LIKE', 'image%') + ->get(); + + // render content + return Controller::visitorsView($content->template, [ + 'images' => $images, + 'page' => $content, + 'extra' => $parameters + ]); + } + + public static function getHistoryHandler() + { + return History::class; + } + + /** + * @param Content $content + * + * @return array + */ + public static function loadExtraData(Content $content) + { + if (is_string($content->moduleSettings)) { + $content->moduleSettings = json_decode($content->moduleSettings); + } + + $extra = [ + 'slider' => isset($content->moduleSettings->slider) ? $content->moduleSettings->slider : false + ]; + + return $extra; + } + + /** + * Save module-specific values into database + * + * @param Content $content + * @param Request $request + * + * @return mixed + * @internal param Widget $widget + */ + public static function createNew(Content &$content, Request $request) + { + $parentDirectoryId = Storage::get(self::CONFIG_FILENAME); + + // create new directory for images + $directory = Directory::create([ + 'name' => $content->id . '_' . $request->title, + 'description' => $request->description, + 'parent_id' => $parentDirectoryId + ]); + + // save id into module_config array + $settings = ['directoryId' => $directory->id]; + + // save settings + $content->moduleSettings = json_encode($settings); + } + + /** + * Method used for editing existing content page. + * + * Reason why it is separated from createNew() method is simple - we need to save history of changes. + * + * @param Content $content + * @param Request $request + * + * @param $revisionID string ID of revision used + * + * @return int number of edited fields + */ + public static function edit(Content &$content, Request $request, $revisionID) + { + // nothing to edit + } + + /** + * Does given module manage content? Or is it just module with widgets/something internal/something absolutely else? + * + * @return bool + */ + public static function managesContent() + { + return true; + } + + public static function getModuleId() + { + $handler = config('gallery.handler'); + $allModules = ModulesHandlerToId::getWithTranslations(); + $moduleId = isset($allModules[$handler]) ? $allModules[$handler] : null; + + return $moduleId; + } + + /** + * Getter for section names in creating/editing content resource + * + * @return mixed + */ + public static function getExtendedFormSections() + { + $sections = AdminHandler::getExtendedFormSections(); + + $sections['upload'] = trans('gallery::admin/content.upload'); + + return $sections; + } + + /** + * Getter for views used in extended part of form for creating new content + * + * This method should return pairs . View is returned only as name in plain text + * + * @return array of views/templates/html codes divided into section + */ + public static function getExtendedFormInputsCreate() + { + $parts = AdminHandler::getExtendedFormInputsCreate(); + $parts['upload'] = 'gallery::admin.content.newUpload'; + + return $parts; + } + + /** + * Getter for extended part of form for editing existing content + * + * Basically, this method may be + * + * @return array of views/templates/html codes divided into section + */ + public static function getExtendedFormInputsEdit() + { + $parts = AdminHandler::getExtendedFormInputsCreate(); + $parts['upload'] = 'gallery::admin.content.editUpload'; + + return $parts; + } + + /** + * Register admin menu (or multiple ones) + * + * This cannot be in ServiceProvider because Session is started at middleware. And ServiceProvider is called before + * starting any middleware.. + * + * @param User $user model of logged user + */ + public static function registerAdminMenu(User $user) + { + $menu = \Menu::instance('mainMenu'); + $submenu = $menu->whereTitle(trans('admin/mainMenu.contentPages')); + $submenu->dropdown(trans('gallery::module.name'), function ($submenu) use ($user) { + $submenu->route('content.new', trans('gallery::admin/adminMenu.new'), ['module' => 'gallery'], 10, ['icon' => 'fa fa-plus']); + $submenu->route('content.overview', trans('gallery::admin/adminMenu.overview'), ['module' => 'gallery'], 20, ['icon' => 'fa fa-list']); + }, 25, ['icon' => 'fa fa-camera']); + } + + /** + * Install module + * + * @return mixed + */ + public static function install() + { + $directory = Directory::where('name', self::DIRECTORY_NAME) + ->first(); + + if (!count($directory)) { + $directory = Directory::create([ + 'name' => self::DIRECTORY_NAME, + 'hidden' => true + ]); + } + + Storage::put(self::CONFIG_FILENAME, $directory->id); + } + + /** + * Method called right after content page is marked as deleted + * + * This method is supposed to clean after "deleted" page. + * + * @param Content $content + * + * @return mixed + */ + public static function delete(Content $content) + { + // try to convert moduleSettings into something more accessible + if (is_string($content->moduleSettings)) { + $content->moduleSettings = json_decode($content->moduleSettings); + } + + // get directory id + $directoryId = $content->moduleSettings->directoryId; + + $directory = Directory::find($directoryId); + + // check if gallery exists + if (!$directory) { + return; + } + + // delete directory used as photogallery + $directory->delete(); + } + + /** + * Does this module support categories? + * + * @return boolean + */ + public static function supportCategories() + { + return true; + } +} \ No newline at end of file diff --git a/Providers/GalleryServiceProvider.php b/Providers/GalleryServiceProvider.php new file mode 100644 index 0000000..0e675e8 --- /dev/null +++ b/Providers/GalleryServiceProvider.php @@ -0,0 +1,16 @@ +alias = 'gallery'; + } + + protected function setModulePath() + { + $this->path = __DIR__; + } +} diff --git a/Resources/lang/cs/admin/adminMenu.php b/Resources/lang/cs/admin/adminMenu.php new file mode 100755 index 0000000..9129972 --- /dev/null +++ b/Resources/lang/cs/admin/adminMenu.php @@ -0,0 +1,6 @@ + "Nová galerie", +"overview" => "Všechny galerie", +"templatePath" => "Šablony galerie", +]; diff --git a/Resources/lang/cs/admin/content.php b/Resources/lang/cs/admin/content.php new file mode 100755 index 0000000..ac72921 --- /dev/null +++ b/Resources/lang/cs/admin/content.php @@ -0,0 +1,11 @@ + "Tato stránka není platnou fotogalerií.", +"makeSlider" => "Vytvořit slider z této fotogalerie", +"orbitSliderMissing" => "Nelze vytvořit slider. Widget pro zobrazení slideru není nainstalován.", +"sliderCreated" => "Slider úspěšně vytvořen.", +"sliderEdit" => "Nastavení slideru", +"sliderFailed" => "Slider nemohl být vytvořen. Zpráva: :message", +"upload" => "Nahrát fotografie", +"uploadAfterSavingGallery" => "Nahrávání do této galerie zatím není dostupné. Uložte galerii a nahrávejte fotografie až v rámci editace.", +]; diff --git a/Resources/lang/cs/module.php b/Resources/lang/cs/module.php new file mode 100755 index 0000000..337dd6d --- /dev/null +++ b/Resources/lang/cs/module.php @@ -0,0 +1,5 @@ + "Jednoduchá galerie zobrazující fotografie/grafiku v jednoduchém lightboxu. Tento modul nenabízí žádné speciální zobrazení pro fotografie.", +"name" => "Galerie", +]; diff --git a/Resources/lang/en/admin/adminMenu.php b/Resources/lang/en/admin/adminMenu.php new file mode 100755 index 0000000..099f852 --- /dev/null +++ b/Resources/lang/en/admin/adminMenu.php @@ -0,0 +1,6 @@ + 'Gallery templates', + 'new' => 'New gallery', + 'overview' => 'All galleries' +]; \ No newline at end of file diff --git a/Resources/lang/en/admin/content.php b/Resources/lang/en/admin/content.php new file mode 100755 index 0000000..c7741f2 --- /dev/null +++ b/Resources/lang/en/admin/content.php @@ -0,0 +1,11 @@ + 'Upload photos', + 'uploadAfterSavingGallery' => 'Uploading for this gallery is not available yet. You must create the gallery first and upload later.', + 'makeSlider' => 'Make slider from this photogallery', + 'orbitSliderMissing' => 'Cannot create slider. Widget for slider is not installed.', + 'invalidGallery' => 'This content page is not a valid gallery page.', + 'sliderFailed' => 'Slider could not be created. Reason: :message', + 'sliderCreated' => 'Slider successfully created.', + 'sliderEdit' => 'Slider settings', +]; \ No newline at end of file diff --git a/Resources/lang/en/module.php b/Resources/lang/en/module.php new file mode 100755 index 0000000..6b0048a --- /dev/null +++ b/Resources/lang/en/module.php @@ -0,0 +1,6 @@ + 'Gallery', + 'description' => 'Simple photogallery', + +]; \ No newline at end of file diff --git a/Resources/lang/sk/admin/adminMenu.php b/Resources/lang/sk/admin/adminMenu.php new file mode 100755 index 0000000..bd54160 --- /dev/null +++ b/Resources/lang/sk/admin/adminMenu.php @@ -0,0 +1,6 @@ + "Nová galéria", +"overview" => "Všetky galérie", +"templatePath" => "Šablóny galérie", +]; diff --git a/Resources/lang/sk/admin/content.php b/Resources/lang/sk/admin/content.php new file mode 100755 index 0000000..41ffac6 --- /dev/null +++ b/Resources/lang/sk/admin/content.php @@ -0,0 +1,11 @@ + "Táto stránka nie je platná fotogaléria.", + "makeSlider" => "Vytvoriť slider z tejto fotogalérie", + "orbitSliderMissing" => "Nie je možné vytvoriť slider. Widget pre zobrazenie slideru nie je nainštalovaný.", + "sliderCreated" => "Slider úspešne vytvorený.", + "sliderEdit" => "Nastavenie slideru", + "sliderFailed" => "Slider nemohol byť vytvorený. Správa: :message", + "upload" => "Nahrať fotografie", + "uploadAfterSavingGallery" => "Nahrávanie do tejto galérie nie je dostupné. Najprv uložte galériu a fotografie nahrávajte až v rámci editácie.", +]; diff --git a/Resources/lang/sk/module.php b/Resources/lang/sk/module.php new file mode 100755 index 0000000..0153298 --- /dev/null +++ b/Resources/lang/sk/module.php @@ -0,0 +1,5 @@ + "Jednoduchá galéria zobrazujúca fotografie/grafiku v jednoduchom lightboxe. Tento modul neponúka žiadne špeciálne zobrazovanie fotografií.", + "name" => "Galéria", +]; diff --git a/Resources/views/admin/content/editUpload.blade.php b/Resources/views/admin/content/editUpload.blade.php new file mode 100755 index 0000000..75f0366 --- /dev/null +++ b/Resources/views/admin/content/editUpload.blade.php @@ -0,0 +1,12 @@ + + + +
\ No newline at end of file diff --git a/Resources/views/admin/content/newUpload.blade.php b/Resources/views/admin/content/newUpload.blade.php new file mode 100755 index 0000000..8d84eda --- /dev/null +++ b/Resources/views/admin/content/newUpload.blade.php @@ -0,0 +1,3 @@ +
+ @lang('gallery::admin/content.uploadAfterSavingGallery') +
\ No newline at end of file diff --git a/start.php b/start.php new file mode 100755 index 0000000..a4abe2d --- /dev/null +++ b/start.php @@ -0,0 +1,2 @@ +