diff --git a/.env.example b/.env.example index 475ed7eb..92ebd2f8 100644 --- a/.env.example +++ b/.env.example @@ -1,22 +1,18 @@ -APP_ENV=local +APP_ENV=testing APP_DEBUG=true -APP_KEY=SomeRandomString +APP_KEY= DB_HOST=localhost -DB_DATABASE=homestead -DB_USERNAME=homestead -DB_PASSWORD=secret +DB_DATABASE= +DB_USERNAME= +DB_PASSWORD= CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync -MAIL_DRIVER=smtp -MAIL_HOST=mailtrap.io -MAIL_PORT=2525 -MAIL_USERNAME=null -MAIL_PASSWORD=null -MAIL_ENCRYPTION=null +MAIL_USERNAME=@binarity.cz +MAIL_PASSWORD= SITE_URL=/ UPLOAD_URL=/public/uploads diff --git a/config/mail.php b/config/mail.php index cb783c90..56cc97fd 100644 --- a/config/mail.php +++ b/config/mail.php @@ -28,7 +28,7 @@ return [ | */ - 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), + 'host' => env('MAIL_HOST', 'mail.binarity.cz'), /* |-------------------------------------------------------------------------- @@ -41,7 +41,7 @@ return [ | */ - 'port' => env('MAIL_PORT', 587), + 'port' => env('MAIL_PORT', 25), /* |-------------------------------------------------------------------------- diff --git a/modules/ContactForm/Assets/.gitkeep b/modules/ContactForm/Assets/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/ContactForm/Config/.gitkeep b/modules/ContactForm/Config/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/ContactForm/Config/config.php b/modules/ContactForm/Config/config.php new file mode 100644 index 00000000..c4bbdcdb --- /dev/null +++ b/modules/ContactForm/Config/config.php @@ -0,0 +1,12 @@ + 'ContactForm', + 'translatedName' => 'contactform::module.name', + 'translatedDescription' => 'contactform::module.description', + 'alias' => 'contactform', + 'handler' => '\\Modules\\ContactForm\\Handlers\\ContactForm', + 'providers' => [\Modules\ContactForm\Providers\ContactFormServiceProvider::class], + 'files' => ['start.php'], + 'order' => 0, +]; \ No newline at end of file diff --git a/modules/ContactForm/Console/.gitkeep b/modules/ContactForm/Console/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/ContactForm/Database/Migrations/.gitkeep b/modules/ContactForm/Database/Migrations/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/ContactForm/Database/Seeders/.gitkeep b/modules/ContactForm/Database/Seeders/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/ContactForm/Database/Seeders/ContactFormDatabaseSeeder.php b/modules/ContactForm/Database/Seeders/ContactFormDatabaseSeeder.php new file mode 100644 index 00000000..0376613e --- /dev/null +++ b/modules/ContactForm/Database/Seeders/ContactFormDatabaseSeeder.php @@ -0,0 +1,20 @@ +call("OthersTableSeeder"); + } + +} \ No newline at end of file diff --git a/modules/ContactForm/Entities/.gitkeep b/modules/ContactForm/Entities/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/ContactForm/Handlers/ContactForm.php b/modules/ContactForm/Handlers/ContactForm.php new file mode 100644 index 00000000..a6df90f4 --- /dev/null +++ b/modules/ContactForm/Handlers/ContactForm.php @@ -0,0 +1,153 @@ +module_settings = json_decode($content->module_settings); + + return Controller::VisitorsView($content->template, ['page' => $content]); + } + + public static function getHistoryHandler() + { + return ContactFormHistory::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) + { + + $settings = [ + 'phone' => $request->phone, + 'email' => $request->email, + 'companyName' => $request->companyName, + 'address' => $request->address, + 'gpsLat' => $request->gpsLat, + 'gpsLng' => $request->gpsLng, + ]; + + // 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) + { + // TODO: Implement edit() method. + } + + public static function getModuleId() + { + $handler = config('contactform.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 = parent::getExtendedFormSections(); + $sections['content'] = trans('contactform::admin/content.content'); + + 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() + { + return [ + 'basicInfo' => 'contactform::admin.form.basicInfo', + 'meta' => 'admin.content.formParts.metaInformation', + 'appearance' => 'admin.content.formParts.appearance', + 'publication' => 'admin.content.formParts.publicationSetup', + 'content' => 'contactform::admin.form.content', + ]; + } + + /** + * 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) + { + // register links in admin menu + $menu = \Menu::instance('mainMenu'); + $menu->dropdown(trans('contactform::admin/adminMenu.contactForm'), function ($submenu) use ($user) { + $submenu->route('content.new', trans('contactform::admin/adminMenu.new'), ['moduleId' => self::getModuleId()], 10, ['icon' => 'fa fa-plus']); + $submenu->route('content.overview', trans('contactform::admin/adminMenu.overview'), ['moduleId' => self::getModuleId()], 20, ['icon' => 'fa fa-list']); + $submenu->route('emails.sent', trans('contactform::admin/adminMenu.sentMessages'), [], 30, ['icon' => 'fa fa-send']); + }, 25, ['icon' => 'fa fa-envelope-o']); + } + + /** + * 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; + } + + /** + * Install module + * + * @return mixed + */ + public static function install() + { + // TODO: Implement install() method. + } +} \ No newline at end of file diff --git a/modules/ContactForm/Handlers/ContactFormHistory.php b/modules/ContactForm/Handlers/ContactFormHistory.php new file mode 100644 index 00000000..e5a33a37 --- /dev/null +++ b/modules/ContactForm/Handlers/ContactFormHistory.php @@ -0,0 +1,16 @@ +column) { + default: + return parent::parseChangedValue($changeset); + break; + } + } +} \ No newline at end of file diff --git a/modules/ContactForm/Http/Controllers/Visitor/CreateNewMessage.php b/modules/ContactForm/Http/Controllers/Visitor/CreateNewMessage.php new file mode 100644 index 00000000..1a466551 --- /dev/null +++ b/modules/ContactForm/Http/Controllers/Visitor/CreateNewMessage.php @@ -0,0 +1,50 @@ +findOrFail($formId); + + $form->module_settings = json_decode($form->module_settings); + + // select template + $template = isset($form->module_settings->emailTemplate) ? $form->module_settings->emailTemplate : 'contactform::emails.default'; + + // send email + $status = Mail::send(Template::name($template), ['data' => $request], function (Message $message) use ($request, $form) { + $message->from($request->email, $request->name); + $message->to($form->module_settings->email) + ->subject('Your Reminder!'); + }); + + // inform user about success or failure + if ($status) { + return redirect() + ->route('page.content', ['url' => $form->url]) + ->with('success', ''); + } else { + return redirect() + ->route('page.content', ['url' => $form->url]) + ->with('error', ''); + } + } +} diff --git a/modules/ContactForm/Http/Middleware/.gitkeep b/modules/ContactForm/Http/Middleware/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/ContactForm/Http/Requests/.gitkeep b/modules/ContactForm/Http/Requests/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/ContactForm/Http/Requests/SendNewEmailRequest.php b/modules/ContactForm/Http/Requests/SendNewEmailRequest.php new file mode 100644 index 00000000..e1a84208 --- /dev/null +++ b/modules/ContactForm/Http/Requests/SendNewEmailRequest.php @@ -0,0 +1,20 @@ + 'required', + 'email' => 'required|email', + 'message' => 'required', + ]; + } +} diff --git a/modules/ContactForm/Http/routes.php b/modules/ContactForm/Http/routes.php new file mode 100644 index 00000000..8387a5db --- /dev/null +++ b/modules/ContactForm/Http/routes.php @@ -0,0 +1,24 @@ + ['web', 'auth', 'adminMenu'], + 'namespace' => '\Modules\ContactForm\Http\Controllers\Admin', + 'prefix' => 'admin/contactform' + ], function () { + Route::get('messsages/sent', 'SentMessagesOverview@getList') + ->name('emails.sent'); +}); + +Route::group([ + 'middleware' => ['web'], + 'namespace' => '\Modules\ContactForm\Http\Controllers\Visitor', + 'prefix' => 'contactform' + ], function () { + + + // method for sending new message + + Route::post('/message/{formId}', 'CreateNewMessage@postMessage') + ->name('email.send'); +}); \ No newline at end of file diff --git a/modules/ContactForm/Providers/ContactFormServiceProvider.php b/modules/ContactForm/Providers/ContactFormServiceProvider.php new file mode 100644 index 00000000..1cc4cbc2 --- /dev/null +++ b/modules/ContactForm/Providers/ContactFormServiceProvider.php @@ -0,0 +1,108 @@ +registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $registrator = $this->app->make('registerSettingsExtension'); + $registrator->register('contactForm', 'contactform::module.name', 'contactform::admin.settings.form'); + } + + /** + * Register config. + * + * @return void + */ + protected function registerConfig() + { + $this->publishes([ + __DIR__ . '/../Config/config.php' => config_path('contactform.php'), + ]); + $this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'contactform'); + } + + /** + * Register views. + * + * @return void + */ + public function registerViews() + { + $viewPath = base_path('resources/views/modules/contactform'); + + $sourcePath = __DIR__ . '/../Resources/views'; + + $this->publishes([ + $sourcePath => $viewPath + ]); + + $this->loadViewsFrom(array_merge(array_map(function ($path) { + return $path . '/modules/contactform'; + }, \Config::get('view.paths')), [$sourcePath]), 'contactform'); + + /** + * @var $registrator TemplateRegistrator + */ + $registrator = $this->app->make('registerTemplateDir'); + try { + // setup some global variables + $registrator->setBaseDirectory('resources/views/modules/contactform/visitor'); + $registrator->setNamespace('contactform'); + $registrator->setModuleId(call_user_func([config('contactform.handler'), 'getModuleId'])); + + // register path with current template name + $registrator->register(config('app.theme'), 'contactform::admin.templatePath'); + } catch (InvalidArgumentException $e) { + // ignore this exception + } + } + + /** + * Register translations. + * + * @return void + */ + public function registerTranslations() + { + $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'contactform'); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array (); + } +} diff --git a/modules/ContactForm/Repositories/.gitkeep b/modules/ContactForm/Repositories/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/ContactForm/Resources/lang/en/admin/adminMenu.php b/modules/ContactForm/Resources/lang/en/admin/adminMenu.php new file mode 100644 index 00000000..3f827bce --- /dev/null +++ b/modules/ContactForm/Resources/lang/en/admin/adminMenu.php @@ -0,0 +1,7 @@ + 'Contact form', + 'new' => 'New', + 'overview' => 'All contact forms', + 'sentMessages' => 'Messages' +]; \ No newline at end of file diff --git a/modules/ContactForm/Resources/lang/en/admin/content.php b/modules/ContactForm/Resources/lang/en/admin/content.php new file mode 100644 index 00000000..bf6a8e02 --- /dev/null +++ b/modules/ContactForm/Resources/lang/en/admin/content.php @@ -0,0 +1,12 @@ + 'Contact form content', + 'address' => 'Address', + 'emailList' => 'Send emails to these addresses', + 'gpsLat' => 'GPS latitude', + 'gpsLng' => 'GPS longitude', + 'compName' => 'Name displayed above address', + 'phone' => 'Contact phone', + 'contactEmail' => 'E-mail, where messages from this form will be delivered', + 'contactInformation' => 'Contact information' +]; \ No newline at end of file diff --git a/modules/ContactForm/Resources/lang/en/admin/settings.php b/modules/ContactForm/Resources/lang/en/admin/settings.php new file mode 100644 index 00000000..7bd1d2f4 --- /dev/null +++ b/modules/ContactForm/Resources/lang/en/admin/settings.php @@ -0,0 +1,5 @@ + 'reCAPTCHA site key', + 'recaptchaSecret' => 'reCAPTCHA application secret key', +]; \ No newline at end of file diff --git a/modules/ContactForm/Resources/lang/en/module.php b/modules/ContactForm/Resources/lang/en/module.php new file mode 100644 index 00000000..63e4708e --- /dev/null +++ b/modules/ContactForm/Resources/lang/en/module.php @@ -0,0 +1,5 @@ + 'Contact form', + 'description' => 'Simple contact form' +]; \ No newline at end of file diff --git a/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php b/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php new file mode 100644 index 00000000..50a32f3d --- /dev/null +++ b/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php @@ -0,0 +1,113 @@ +
+
+ +
+
+ +
+
+ +
+
+ + + @if (isset($errors) && $errors->has('status')) +
+ {{ $errors->first('status') }} +
+ @endif +
+
+ + + @if (isset($errors) && $errors->has('parentPage')) +
+ {{ $errors->first('parentPage') }} +
+ @endif +
+
+ +

@lang('contactform::admin/content.contactInformation')

+ +
+
+ +
+ +
+ +
+
+ +
+
+ + + + +
+
+ + +
+
\ No newline at end of file diff --git a/modules/ContactForm/Resources/views/admin/form/content.blade.php b/modules/ContactForm/Resources/views/admin/form/content.blade.php new file mode 100644 index 00000000..2a0678b8 --- /dev/null +++ b/modules/ContactForm/Resources/views/admin/form/content.blade.php @@ -0,0 +1,10 @@ +
+
+ +
+
\ No newline at end of file diff --git a/modules/ContactForm/Resources/views/admin/settings/form.blade.php b/modules/ContactForm/Resources/views/admin/settings/form.blade.php new file mode 100644 index 00000000..d1f0ffb7 --- /dev/null +++ b/modules/ContactForm/Resources/views/admin/settings/form.blade.php @@ -0,0 +1,13 @@ + + + + +reCAPTCHA \ No newline at end of file diff --git a/modules/ContactForm/Resources/views/visitor/emails/default.blade.php b/modules/ContactForm/Resources/views/visitor/emails/default.blade.php new file mode 100644 index 00000000..ffcda34d --- /dev/null +++ b/modules/ContactForm/Resources/views/visitor/emails/default.blade.php @@ -0,0 +1,4 @@ +

+Ahoj {{$data->name}} +

+

Diky za zpravu: {{$data->message}}

\ No newline at end of file diff --git a/modules/ContactForm/Tests/.gitkeep b/modules/ContactForm/Tests/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/modules/ContactForm/composer.json b/modules/ContactForm/composer.json new file mode 100644 index 00000000..6fe0e828 --- /dev/null +++ b/modules/ContactForm/composer.json @@ -0,0 +1,15 @@ +{ + "name": "pingpong-modules/contactform", + "description": "", + "authors": [ + { + "name": "Pingpong Labs", + "email": "pingpong.labs@gmail.com" + } + ], + "autoload": { + "psr-4": { + "Modules\\ContactForm\\": "" + } + } +} \ No newline at end of file diff --git a/modules/ContactForm/start.php b/modules/ContactForm/start.php new file mode 100644 index 00000000..7be329cb --- /dev/null +++ b/modules/ContactForm/start.php @@ -0,0 +1,15 @@ +