From 85dcf29c4158947ae81ac2945183b239d5d3bdea Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 4 Apr 2016 11:13:11 +0200 Subject: [PATCH 1/4] FIX: returned back .env.example --- .env.example | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..69a303d4 --- /dev/null +++ b/.env.example @@ -0,0 +1,20 @@ +APP_ENV=testing +APP_DEBUG=true +APP_KEY=ZKZAzM23wQ6BPji6zffBjaTzZ3yW7zKQ + +DB_HOST=localhost +DB_DATABASE= +DB_USERNAME= +DB_PASSWORD= + +CACHE_DRIVER=file +SESSION_DRIVER=file +QUEUE_DRIVER=sync + +MAIL_USERNAME=@binarity.cz +MAIL_PASSWORD= + +SITE_URL=/ +UPLOAD_URL=/public/uploads +THUMBNAILS_URL=/uploads/thumbnails +THEME= \ No newline at end of file From f27ad7c421f70833314aae006cdffb46f4ca6e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Mon, 4 Apr 2016 20:20:33 +0200 Subject: [PATCH 2/4] FIX: fix theme:set command. This command did not set theme properly, when THEME was in .env file, but with no value (THEME= only - as default in .env.example). --- app/Console/Commands/SetTheme.php | 25 +++++++++++++---- app/Providers/AppServiceProvider.php | 40 ++++++++++++++-------------- config/app.php | 8 +++--- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/app/Console/Commands/SetTheme.php b/app/Console/Commands/SetTheme.php index 943602bf..dd788a79 100644 --- a/app/Console/Commands/SetTheme.php +++ b/app/Console/Commands/SetTheme.php @@ -40,16 +40,31 @@ class SetTheme extends Command throw new NotFoundHttpException('Invalid theme ' . $theme . '!'); } - $env = file_get_contents(base_path('.env')); + // load .env file + $envFile = base_path('.env'); + $env = file_get_contents($envFile); - $env = preg_replace('/THEME=(.+)/i', 'THEME=' . $theme, $env); - - if (!Str::contains($env, 'THEME')) { + if (!Str::contains($env, 'THEME=')) { $env = sprintf("%s\nTHEME=%s\n", $env, $theme); + } else { + $env = preg_replace('/THEME=(.*)/i', 'THEME=' . $theme, $env, -1, $cnt); } - file_put_contents(base_path('.env'), $env); + // try to write content + $bytesWritten = file_put_contents($envFile, $env); + // check if write was successfull + if (!$bytesWritten) { + throw new \Exception('Cannot write to ' . base_path('.env') . '. Add THEME=' . $theme . ' to your .env file manualy.'); + } + + // theme written $this->line('Theme successfully setup.'); + $this->line(''); + $this->line(' ** PUBLISHING ASSETS AND VIEWS **'); + // publish assets and views for module and theme + $this->call('vendor:publish', ['--tag' => ['public-assets'], '--force' => true]); + $this->call('vendor:publish', ['--tag' => ['module-views'], '--force' => true]); + $this->call('vendor:publish'); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3ee85967..1f1933e7 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -13,12 +13,12 @@ use App\Handlers\Search\Presenters\AdminContent as AdminContentPresenter; use App\Handlers\Search\Presenters\AdminFiles; use App\Models\Template; use App\Widgets\HtmlCode\HtmlCode; -use App\Widgets\Menu\Extensions\URL; use App\Widgets\Menu\Menu; use App\Widgets\OrbitSlider\OrbitSlider; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\File; use Illuminate\Support\ServiceProvider; +use Symfony\Component\Process\Exception\InvalidArgumentException; class AppServiceProvider extends ServiceProvider { @@ -39,6 +39,13 @@ class AppServiceProvider extends ServiceProvider $this->registerTemplates(); $this->registerSettings(); $this->registerSearch(); + + // check if given template is valid + $theme = config('app.theme'); + $themeDir = resource_path('views/visitor/' . $theme); + if (!$theme || empty($theme) || !is_dir($themeDir)) { + throw new InvalidArgumentException('No or invalid theme set! Use artisan theme:set or edit .env file manually and include THEME option, please'); + } } /** @@ -95,8 +102,8 @@ class AppServiceProvider extends ServiceProvider $registrator->register(OrbitSlider::class); // register some menu extensions -// $menuExtensions = $this->app->make('registerMenuExtension'); -// $menuExtensions->register(new URL()); + // $menuExtensions = $this->app->make('registerMenuExtension'); + // $menuExtensions->register(new URL()); } /** @@ -140,35 +147,28 @@ class AppServiceProvider extends ServiceProvider */ private function publishViewResources() { - $themes = File::directories(resource_path('views/visitor')); + $theme = config('app.theme'); + $themeDir = resource_path('views/visitor/' . $theme); - $assets = []; - foreach ($themes as $theme) { - $themeName = basename($theme); - - if (is_dir($theme . '/'.Template::ASSETS_DIRECTORY)) { - $assets[$theme . '/'.Template::ASSETS_DIRECTORY] = public_path('assets/' . $themeName); - } - - if (is_dir($theme . '/'.Template::MODULES_DIRECTORY)) { - $this->publishModuleViews($theme . '/'.Template::MODULES_DIRECTORY, $themeName); - } + // publish assets if exists for current theme + if (is_dir($themeDir . '/' . Template::ASSETS_DIRECTORY)) { + $this->publishes([$themeDir . '/' . Template::ASSETS_DIRECTORY => public_path('assets/' . $theme)], 'public-assets'); } - if (!empty($assets)) { - $this->publishes($assets, 'public-assets'); + if (is_dir($themeDir . '/' . Template::MODULES_DIRECTORY)) { +// $this->publishModuleViews($themeDir . '/' . Template::MODULES_DIRECTORY); } } - private function publishModuleViews($themeModules, $themeName) + private function publishModuleViews($themeModules) { + $theme = config('app.theme'); $modules = File::directories($themeModules); $moduleViews = []; foreach ($modules as $module) { $moduleName = strtolower(basename($module)); - - $moduleViews[$module] = resource_path('views/modules/' . $moduleName . '/visitor/' . $themeName); + $moduleViews[$module] = resource_path('views/modules/' . $moduleName . '/visitor/' . $theme); } if (!empty($moduleViews)) { diff --git a/config/app.php b/config/app.php index 57525eed..7fdee8dd 100644 --- a/config/app.php +++ b/config/app.php @@ -37,7 +37,7 @@ return [ | */ - 'url' => 'http://localhost', + 'url' => env('SITE_URL', 'http://localhost'), /* |-------------------------------------------------------------------------- | Application Timezone @@ -49,7 +49,7 @@ return [ | */ - 'timezone' => 'UTC', + 'timezone' => env('TIMEZONE', 'UTC'), /* |-------------------------------------------------------------------------- | Application Locale Configuration @@ -61,7 +61,7 @@ return [ | */ - 'locale' => 'en', + 'locale' => env('LOCALES', 'en'), /* |-------------------------------------------------------------------------- | Application Fallback Locale @@ -97,7 +97,7 @@ return [ */ 'upload_url' => env('UPLOAD_URL', PHP_SAPI === 'cli' ? '' : url('uploads')), 'thumbnail_url' => env('THUMBNAIL_URL', PHP_SAPI === 'cli' ? '' : url('uploads/thumbnails')), - 'theme' => env('THEME', 'default_theme'), + 'theme' => env('THEME'), /* |-------------------------------------------------------------------------- | Logging Configuration From 0f18b6361e32217fc47487b7655c41bc18482f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Mon, 4 Apr 2016 20:26:25 +0200 Subject: [PATCH 3/4] FEATURE: add ajax response to contact form --- .../Controllers/Visitor/CreateNewMessage.php | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/modules/ContactForm/Http/Controllers/Visitor/CreateNewMessage.php b/modules/ContactForm/Http/Controllers/Visitor/CreateNewMessage.php index 1a466551..0afb95f3 100644 --- a/modules/ContactForm/Http/Controllers/Visitor/CreateNewMessage.php +++ b/modules/ContactForm/Http/Controllers/Visitor/CreateNewMessage.php @@ -12,7 +12,7 @@ class CreateNewMessage extends Controller { /** * Method for sending emails via contact form - * + * * @param SendNewEmailRequest $request * @param $formId * @@ -33,18 +33,26 @@ class CreateNewMessage extends Controller $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!'); + ->subject('Nejaky predmet - nastavovat v administraci, nebo nechavat vyplnovat uzivatele?'); }); // inform user about success or failure - if ($status) { - return redirect() - ->route('page.content', ['url' => $form->url]) - ->with('success', ''); + $this->sendResponse($status, $request, $form); + } + + private function sendResponse($status, SendNewEmailRequest $request, $form) + { + // send response for ajax + if ($request->ajax()) { + return response()->json([ + 'status' => $status ? 'success' : 'failed', + 'redirectUrl' => $form->url + ]); } else { - return redirect() - ->route('page.content', ['url' => $form->url]) - ->with('error', ''); + // redirect user to previous form + $response = redirect()->route('page.content', ['url' => $form->url]); + + return $status ? $response->with('success', '') : $response->with('error', ''); } } } From 2d25e00d762147e7d286cfa11f6eb265d71ec363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Mon, 4 Apr 2016 20:26:51 +0200 Subject: [PATCH 4/4] FEATURE: add second email into contact form This commit adds second email into contact form - this one may be different from email used for delivering messages. --- modules/ContactForm/Handlers/ContactForm.php | 28 ++++++----- .../Providers/ContactFormServiceProvider.php | 2 +- .../Resources/lang/en/admin/content.php | 1 + .../Resources/lang/en/admin/history.php | 1 + .../views/admin/form/basicInfo.blade.php | 47 +++++++++++-------- 5 files changed, 45 insertions(+), 34 deletions(-) diff --git a/modules/ContactForm/Handlers/ContactForm.php b/modules/ContactForm/Handlers/ContactForm.php index 4cf594ae..f2316480 100644 --- a/modules/ContactForm/Handlers/ContactForm.php +++ b/modules/ContactForm/Handlers/ContactForm.php @@ -43,12 +43,13 @@ class ContactForm extends Handler 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, + 'phone' => $request->phone, + 'email' => $request->email, + 'contactEmail' => $request->ContactEmail, + 'companyName' => $request->companyName, + 'address' => $request->address, + 'gpsLat' => $request->gpsLat, + 'gpsLng' => $request->gpsLng, ]; // save settings @@ -70,12 +71,13 @@ class ContactForm extends Handler public static function edit(Content &$content, Request $request, $revisionID) { $fields = [ - 'phone' => 'phone', - 'email' => 'email', - 'companyName' => 'companyName', - 'address' => 'address', - 'gpsLat' => 'gpsLat', - 'gpsLng' => 'gpsLng', + 'phone' => 'phone', + 'email' => 'email', + 'contactEmail' => 'contactEmail', + 'companyName' => 'companyName', + 'address' => 'address', + 'gpsLat' => 'gpsLat', + 'gpsLng' => 'gpsLng', ]; // get data and try to save them @@ -146,7 +148,7 @@ class ContactForm extends Handler $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']); + // $submenu->route('emails.sent', trans('contactform::admin/adminMenu.sentMessages'), [], 30, ['icon' => 'fa fa-send']); }, 25, ['icon' => 'fa fa-envelope-o']); } diff --git a/modules/ContactForm/Providers/ContactFormServiceProvider.php b/modules/ContactForm/Providers/ContactFormServiceProvider.php index 395675b3..88beeaae 100644 --- a/modules/ContactForm/Providers/ContactFormServiceProvider.php +++ b/modules/ContactForm/Providers/ContactFormServiceProvider.php @@ -61,7 +61,7 @@ class ContactFormServiceProvider extends ServiceProvider $sourcePath = __DIR__ . '/../Resources/views'; - $this->publishes([$sourcePath => $viewPath]); + $this->publishes([$sourcePath => $viewPath], 'module-views'); $this->loadViewsFrom(array_merge(array_map(function ($path) { return $path . '/modules/contactform'; diff --git a/modules/ContactForm/Resources/lang/en/admin/content.php b/modules/ContactForm/Resources/lang/en/admin/content.php index bf6a8e02..ec01d7fc 100644 --- a/modules/ContactForm/Resources/lang/en/admin/content.php +++ b/modules/ContactForm/Resources/lang/en/admin/content.php @@ -7,6 +7,7 @@ return [ 'gpsLng' => 'GPS longitude', 'compName' => 'Name displayed above address', 'phone' => 'Contact phone', + 'email' => 'E-mail', '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/history.php b/modules/ContactForm/Resources/lang/en/admin/history.php index 59a94453..87225107 100644 --- a/modules/ContactForm/Resources/lang/en/admin/history.php +++ b/modules/ContactForm/Resources/lang/en/admin/history.php @@ -3,6 +3,7 @@ return [ 'columnPhone' => 'Phone', 'columnAddress' => 'Address', 'columnEmail' => 'E-mail', + 'columnContactEmail' => 'Contact E-mail', 'columnCompanyName' => 'Company name', 'columnGpsLat' => 'GPS Latitude', 'columnGpsLng' => 'Gps Longitude', diff --git a/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php b/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php index 50a32f3d..dc7d4a8f 100644 --- a/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php +++ b/modules/ContactForm/Resources/views/admin/form/basicInfo.blade.php @@ -67,24 +67,18 @@
+ + + -
- -
- -
-
- -
-
+
- +
+
+ +
+
+ +
+
-
\ No newline at end of file +