Merge branch 'module_contact_form' into dev
This commit is contained in:
+7
-11
@@ -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
|
||||
|
||||
+2
-2
@@ -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),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => '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,
|
||||
];
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php namespace Modules\Contactform\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContactFormDatabaseSeeder extends Seeder {
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Model::unguard();
|
||||
|
||||
// $this->call("OthersTableSeeder");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
namespace Modules\ContactForm\Handlers;
|
||||
|
||||
use App\Enumerations\ModulesHandlerToId;
|
||||
use App\Handlers\Handler;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content;
|
||||
use App\Models\User;
|
||||
|
||||
class ContactForm extends Handler
|
||||
{
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$content->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 <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()
|
||||
{
|
||||
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.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Modules\ContactForm\Handlers;
|
||||
|
||||
use App\Handlers\History;
|
||||
|
||||
class ContactFormHistory extends History
|
||||
{
|
||||
public static function parseChangedValue($changeset)
|
||||
{
|
||||
switch ($changeset->column) {
|
||||
default:
|
||||
return parent::parseChangedValue($changeset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace Modules\ContactForm\Http\Controllers\Visitor;
|
||||
|
||||
use App\Helpers\Template;
|
||||
use App\Models\Content;
|
||||
use Illuminate\Mail\Message;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Modules\ContactForm\Http\Requests\SendNewEmailRequest;
|
||||
use Pingpong\Modules\Routing\Controller;
|
||||
|
||||
class CreateNewMessage extends Controller
|
||||
{
|
||||
/**
|
||||
* Method for sending emails via contact form
|
||||
*
|
||||
* @param SendNewEmailRequest $request
|
||||
* @param $formId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function postMessage(SendNewEmailRequest $request, $formId)
|
||||
{
|
||||
// load form settings
|
||||
$form = Content::where('module_handler', config('contactform.handler'))
|
||||
->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', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php namespace Modules\ContactForm\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class SendNewEmailRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email',
|
||||
'message' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
Route::group([
|
||||
'middleware' => ['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');
|
||||
});
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php namespace Modules\ContactForm\Providers;
|
||||
|
||||
use App\Handlers\Registrators\TemplateRegistrator;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class ContactFormServiceProvider 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()
|
||||
{
|
||||
$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 ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
return [
|
||||
'contactForm' => 'Contact form',
|
||||
'new' => 'New',
|
||||
'overview' => 'All contact forms',
|
||||
'sentMessages' => 'Messages'
|
||||
];
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
return [
|
||||
'content' => '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'
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
'recaptchaSiteKey' => 'reCAPTCHA site key',
|
||||
'recaptchaSecret' => 'reCAPTCHA application secret key',
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
'name' => 'Contact form',
|
||||
'description' => 'Simple contact form'
|
||||
];
|
||||
@@ -0,0 +1,113 @@
|
||||
<div class="row">
|
||||
<div class="columns large-6">
|
||||
<label>
|
||||
@lang('admin/contents.field_title')
|
||||
|
||||
<input type="text" name="title" placeholder="@lang('admin/contents.field_title')"
|
||||
value="{{old('title', $page->title)}}" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="columns large-6">
|
||||
<label>
|
||||
@lang('admin/contents.field_url')
|
||||
|
||||
<input type="text" name="url" placeholder="@lang('admin/contents.field_url')"
|
||||
value="{{old('url', $page->url)}}" />
|
||||
|
||||
@if (isset($errors) && $errors->has('url'))
|
||||
<div class="callout alert">
|
||||
{{ $errors->first('url') }}
|
||||
</div>
|
||||
@endif
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="columns large-6">
|
||||
<label>
|
||||
<select name="status">
|
||||
@foreach($contentStatuses as $status => $translation)
|
||||
<option value="{{$status}}" @if(old('status', $page->status) == $status) selected @endif>
|
||||
{{$translation}}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
|
||||
@if (isset($errors) && $errors->has('status'))
|
||||
<div class="callout alert">
|
||||
{{ $errors->first('status') }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="column large-6">
|
||||
<label>
|
||||
<select name="parentPage">
|
||||
<option value="">@lang('admin/contents.noParentPage')</option>
|
||||
|
||||
@foreach($rootPages as $rootPage)
|
||||
<option value="{{$rootPage->id}}"
|
||||
@if(old('parent_page', $page->parent_id) == $rootPage->id) selected @endif>
|
||||
{{$rootPage->title}}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
|
||||
@if (isset($errors) && $errors->has('parentPage'))
|
||||
<div class="callout alert">
|
||||
{{ $errors->first('parentPage') }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>@lang('contactform::admin/content.contactInformation')</h2>
|
||||
|
||||
<div class="row">
|
||||
<div class="column large-6">
|
||||
<label>
|
||||
@lang('contactform::admin/content.phone')
|
||||
|
||||
<input type="tel" name="phone" value="{{$page->module_settings->phone or ""}}" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="column large-6">
|
||||
<label>
|
||||
@lang('contactform::admin/content.contactEmail')
|
||||
|
||||
<input type="email" name="email" value="{{$page->module_settings->email or \Auth::user()->email}}" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="column large-6">
|
||||
|
||||
<label>
|
||||
@lang('contactform::admin/content.compName')
|
||||
|
||||
<input type="text" name="companyName" value="{{$page->module_settings->companyName or ""}}" />
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('contactform::admin/content.address')
|
||||
|
||||
<textarea rows="3" name="address">{{$page->module_settings->address or ""}}</textarea>
|
||||
</label>
|
||||
</div>
|
||||
<div class="column large-6">
|
||||
<label>
|
||||
@lang('contactform::admin/content.gpsLat')
|
||||
|
||||
<input type="text" value="{{$page->module_settings->gpsLat or ""}}" name="gpsLat" />
|
||||
</label>
|
||||
<label>
|
||||
@lang('contactform::admin/content.gpsLng')
|
||||
|
||||
<input type="text" value="{{$page->module_settings->gpsLng or ""}}" name="gpsLng" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,10 @@
|
||||
<div class="row">
|
||||
<div class="columns large-12">
|
||||
<label>
|
||||
<textarea name="pageContent" id="pageContent" class="wysiwyg-editor">
|
||||
{{old('pageContent', $page->content)}}
|
||||
</textarea>
|
||||
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,13 @@
|
||||
<label>
|
||||
@lang('contactform::admin/settings.recaptchaSiteKey')
|
||||
|
||||
<input type="text" name="recaptchaSiteKey" value="{{old('recaptchaSiteKey', isset($settings->recaptchaSiteKey) ? $settings->recaptchaSiteKey : null)}}" />
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('contactform::admin/settings.recaptchaSecret')
|
||||
|
||||
<input type="text" name="recaptchaSecret" value="{{old('recaptchaSecret', isset($settings->recaptchaSecret) ? $settings->recaptchaSecret : null)}}" />
|
||||
</label>
|
||||
|
||||
<em><a href="https://www.google.com/recaptcha/admin#list" target="_blank">reCAPTCHA</a></em>
|
||||
@@ -0,0 +1,4 @@
|
||||
<p>
|
||||
<strong>Ahoj {{$data->name}}</strong>
|
||||
</p>
|
||||
<p>Diky za zpravu: <em>{{$data->message}}</em></p>
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "pingpong-modules/contactform",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Pingpong Labs",
|
||||
"email": "pingpong.labs@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\ContactForm\\": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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