FEATURE #1526: add simple photogallery
Photogallery currently works with directories, UI is terrible, but it works.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => '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,
|
||||
];
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php namespace Modules\Gallery\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class GalleryDatabaseSeeder extends Seeder {
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Model::unguard();
|
||||
|
||||
// $this->call("OthersTableSeeder");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
namespace Modules\Gallery\Handlers;
|
||||
|
||||
use App\Enumerations\ModulesHandlerToId;
|
||||
use App\Handlers\Contracts\AppHandler;
|
||||
use App\Handlers\Handler;
|
||||
use App\Handlers\History;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content;
|
||||
use App\Models\Directory;
|
||||
use App\Models\File;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Gallery implements AppHandler
|
||||
{
|
||||
const CONFIG_FILENAME = 'photogallery-config';
|
||||
const DIRECTORY_NAME = 'photogallery-data';
|
||||
|
||||
/**
|
||||
* Render given module into visitor area.
|
||||
*
|
||||
* @param Content $content DB model from table contents
|
||||
* @param array $parameters parameters used for modifications/custom settings of given model
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function render(Content $content, $parameters)
|
||||
{
|
||||
// if settings is still string, convert it into object
|
||||
if (is_string($content->module_settings)) {
|
||||
$content->module_settings = json_decode($content->module_settings);
|
||||
}
|
||||
|
||||
// get directory ID
|
||||
$directoryId = $content->module_settings->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]);
|
||||
}
|
||||
|
||||
public static function getHistoryHandler()
|
||||
{
|
||||
return History::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' => $request->title,
|
||||
'description' => $request->description,
|
||||
'parent_id' => $parentDirectoryId
|
||||
]);
|
||||
|
||||
// save id into module_config array
|
||||
$settings = [
|
||||
'directoryId' => $directory->id
|
||||
];
|
||||
|
||||
// save settings
|
||||
$content->module_settings = 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 = Handler::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 <section, view-name>. View is returned only as name in plain text
|
||||
*
|
||||
* @return array of views/templates/html codes divided into section
|
||||
*/
|
||||
public static function getExtendedFormInputsCreate()
|
||||
{
|
||||
$parts = Handler::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 = Handler::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)
|
||||
{
|
||||
// nothing to register
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<?php
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php namespace Modules\Gallery\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class GalleryServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerConfig()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__ . '/../Config/config.php' => config_path('gallery.php'),
|
||||
]);
|
||||
$this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'gallery');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerViews()
|
||||
{
|
||||
$viewPath = base_path('resources/views/modules/gallery');
|
||||
|
||||
$sourcePath = __DIR__ . '/../Resources/views';
|
||||
|
||||
$this->publishes([
|
||||
$sourcePath => $viewPath
|
||||
]);
|
||||
|
||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||
return $path . '/modules/gallery';
|
||||
}, \Config::get('view.paths')), [$sourcePath]), 'gallery');
|
||||
|
||||
/**
|
||||
* @var $registrator TemplateRegistrator
|
||||
*/
|
||||
$registrator = $this->app->make('registerTemplateDir');
|
||||
try {
|
||||
// setup some global variables
|
||||
$registrator->setBaseDirectory('resources/views/modules/gallery/visitor');
|
||||
$registrator->setNamespace('gallery');
|
||||
$registrator->setModuleId(call_user_func([config('gallery.handler'), 'getModuleId']));
|
||||
|
||||
// register path with current template name
|
||||
$registrator->register(config('app.theme'), 'gallery::admin.templatePath');
|
||||
} catch (InvalidArgumentException $e) {
|
||||
// ignore this exception
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerTranslations()
|
||||
{
|
||||
$langPath = base_path('resources/lang/modules/gallery');
|
||||
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, 'gallery');
|
||||
} else {
|
||||
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'gallery');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
'upload' => 'Upload photos',
|
||||
'uploadAfterSavingGallery' => 'Uploading for this gallery is not available yet. You must create the gallery first and upload later.'
|
||||
];
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'name' => 'Gallery',
|
||||
'description' => 'Simple photogallery',
|
||||
|
||||
];
|
||||
@@ -0,0 +1,3 @@
|
||||
<div class="row column">
|
||||
<a href="{{route('upload.overview', ['id' => $page->module_settings->directoryId])}}" class="button large expanded success">@lang('gallery::admin/content.upload')</a>
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
<div class="row column">
|
||||
<em>@lang('gallery::admin/content.uploadAfterSavingGallery')</em>
|
||||
</div>
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "pingpong-modules/gallery",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Pingpong Labs",
|
||||
"email": "pingpong.labs@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\Gallery\\": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Namespaces And Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When a module starting, this file will executed automatically. This helps
|
||||
| to register some namespaces like translator or view. Also this file
|
||||
| will load the routes file for each module. You may also modify
|
||||
| this file as you want.
|
||||
|
|
||||
*/
|
||||
|
||||
require __DIR__ . '/Http/routes.php';
|
||||
Reference in New Issue
Block a user