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/app/Handlers/Handler.php b/app/Handlers/Handler.php index b3ebca89..d7e318ac 100644 --- a/app/Handlers/Handler.php +++ b/app/Handlers/Handler.php @@ -65,7 +65,7 @@ abstract class Handler implements AppHandler // create instance of main menu \Menu::create('mainMenu', function ($menu) { - $menu->route('admin.dashboard', trans('admin/mainMenu.dashboard'), [], 10, ['icon' => 'fa fa-dashboard']); +// $menu->route('admin.dashboard', trans('admin/mainMenu.dashboard'), [], 10, ['icon' => 'fa fa-dashboard']); $menu->dropdown(trans('admin/mainMenu.userManagement'), function ($sub) { $sub->route('users.new', trans('admin/mainMenu.newUser'), [], 10, ['icon' => 'fa fa-user-plus']); $sub->route('users.detail', trans('admin/mainMenu.userDetail'), [], 20, ['icon' => 'fa fa-user']); @@ -118,10 +118,10 @@ abstract class Handler implements AppHandler } }, 29, ['icon' => 'fa fa-folder-open']); } - $menu->dropdown(trans('admin/mainMenu.customFields'), function ($sub) { - $sub->route('customfields.new', trans('admin/mainMenu.customFieldsNew'), [], 10, ['icon' => 'fa fa-code']); - $sub->route('customfields.overview', trans('admin/mainMenu.customFieldsOverview'), [], 50, ['icon' => 'fa fa-code-fork']); - }, 30, ['icon' => 'fa fa-code']); +// $menu->dropdown(trans('admin/mainMenu.customFields'), function ($sub) { +// $sub->route('customfields.new', trans('admin/mainMenu.customFieldsNew'), [], 10, ['icon' => 'fa fa-code']); +// $sub->route('customfields.overview', trans('admin/mainMenu.customFieldsOverview'), [], 50, ['icon' => 'fa fa-code-fork']); +// }, 30, ['icon' => 'fa fa-code']); $menu->route('log.overview', trans('admin/mainMenu.actionLog'), [], 40, ['icon' => 'fa fa-history']); $menu->route('settings.overview', trans('admin/mainMenu.settings'), [], 50, ['icon' => 'fa fa-gear']); }); diff --git a/app/Handlers/Registrators/WidgetRegistrator.php b/app/Handlers/Registrators/WidgetRegistrator.php index 36814493..e70cf9ee 100644 --- a/app/Handlers/Registrators/WidgetRegistrator.php +++ b/app/Handlers/Registrators/WidgetRegistrator.php @@ -38,9 +38,9 @@ class WidgetRegistrator 'name' => $widgetName, 'description' => $widgetDescription ]); - } - // install widget (if neccessary) - call_user_func($classname . '::install'); + // install widget (if neccessary) + call_user_func($classname . '::install'); + } } } diff --git a/app/Http/Controllers/Admin/CreateNewContent.php b/app/Http/Controllers/Admin/CreateNewContent.php index 10e1c17e..48697d0e 100644 --- a/app/Http/Controllers/Admin/CreateNewContent.php +++ b/app/Http/Controllers/Admin/CreateNewContent.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Enumerations\ActiveContentStatuses; use App\Http\Requests\CreateNewContentRequest; use App\Models\Content; +use App\Models\File; use App\Models\Module; use App\Models\Template; use Illuminate\Support\Str; @@ -11,6 +12,22 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class CreateNewContent extends Controller { + /** + * @var File + */ + private $file; + /** + * @var Content + */ + private $content; + + public function __construct(File $file, Content $content) + { + parent::__construct(); + $this->file = $file; + $this->content = $content; + } + /** * Display form for new content page * @@ -29,16 +46,15 @@ class CreateNewContent extends Controller ->get(); // create default content object - $page = new Content(); - $page->status = Content::STATUS_DRAFT; + $this->content->status = Content::STATUS_DRAFT; // render view return view('admin.content.new', [ 'contentStatuses' => $statuses, 'templates' => $templates, 'moduleId' => $moduleId, - 'page' => $page, - 'rootPages' => $page->rootPages(), + 'page' => $this->content, + 'rootPages' => $this->content->rootPages(), 'moduleName' => trans($module->name), 'formSectionNames' => call_user_func([$module->handler, 'getExtendedFormSections']), 'formSections' => call_user_func([$module->handler, 'getExtendedFormInputsCreate']), @@ -82,6 +98,13 @@ class CreateNewContent extends Controller $page->parent_id = $request->parentPage; } + // upload file - if provided + if ($request->hasFile('titlePhoto')) { + $file = $this->file->upload($request->file('titlePhoto'), $request); + + $page->title_photo = $file['filename']; + } + // save module-specific stuff call_user_func_array([$module->handler, 'createNew'], [&$page, $request]); diff --git a/app/Http/Controllers/Admin/Dashboard.php b/app/Http/Controllers/Admin/Dashboard.php index 9c09ce42..24ad8649 100644 --- a/app/Http/Controllers/Admin/Dashboard.php +++ b/app/Http/Controllers/Admin/Dashboard.php @@ -9,6 +9,9 @@ use Illuminate\Support\Facades\Session; class Dashboard extends Controller { public function getIndex(Request $request) { - return view('admin.dashboard'); + + return redirect()->route('content.overview'); + +// return view('admin.dashboard'); } } diff --git a/app/Http/Controllers/Admin/EditContent.php b/app/Http/Controllers/Admin/EditContent.php index c6e22d7d..dd6c3e49 100644 --- a/app/Http/Controllers/Admin/EditContent.php +++ b/app/Http/Controllers/Admin/EditContent.php @@ -6,9 +6,9 @@ use App\Enumerations\ModulesHandlerToId; use App\Http\Requests\EditContentRequest; use App\Models\Content; use App\Models\ContentHistory; +use App\Models\File; use App\Models\Template; use Illuminate\Support\Str; -use Modules\StaticPages\Http\Requests\EditStaticPageRequest; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class EditContent extends Controller @@ -17,10 +17,15 @@ class EditContent extends Controller * @var ContentHistory */ private $history; + /** + * @var File + */ + private $file; - public function __construct(ContentHistory $history) + public function __construct(ContentHistory $history, File $file) { $this->history = $history; + $this->file = $file; } /** @@ -36,11 +41,11 @@ class EditContent extends Controller $statuses = ContentStatuses::getWithTranslations(); // try to find requested page - $page = Content::where('module_handler', config('staticpages.handler')) - ->findOrFail($id); + $page = Content::findOrFail($id); + $page->module_settings = json_decode($page->module_settings); $allModules = ModulesHandlerToId::getWithTranslations(); - $moduleId = $allModules[config('staticpages.handler')]; + $moduleId = $allModules[$page->module_handler]; $templates = Template::where('module_id', $moduleId) ->select(['template_name', 'name', 'description']) ->get(); @@ -81,6 +86,14 @@ class EditContent extends Controller $request->url = Str::slug($request->url); $request->parentPage = $request->parentPage ? $request->parentPage : null; + $request->titlePhotoFilename = $page->title_photo; + + // upload file - if provided + if ($request->hasFile('titlePhoto')) { + $file = $this->file->upload($request->file('titlePhoto'), $request); + + $request->titlePhotoFilename = $file['filename']; + } // array of fields in database and fields from request $fields = [ @@ -93,7 +106,8 @@ class EditContent extends Controller 'meta_description' => 'metaDescription', 'content' => 'pageContent', 'parent_id' => 'parentPage', - 'status' => 'status' + 'status' => 'status', + 'title_photo' => 'titlePhotoFilename' ]; // save new values with history diff --git a/app/Http/Controllers/Admin/EditUploadedFile.php b/app/Http/Controllers/Admin/EditUploadedFile.php index 99443df7..cac6bf5c 100644 --- a/app/Http/Controllers/Admin/EditUploadedFile.php +++ b/app/Http/Controllers/Admin/EditUploadedFile.php @@ -55,6 +55,7 @@ class EditUploadedFile extends Controller } // set values from form + $file->name = $request->name; $file->keywords = $request->keywords; $file->description = $request->description; $file->save(); diff --git a/app/Http/Controllers/Admin/EditWidget.php b/app/Http/Controllers/Admin/EditWidget.php index 7c407faf..34c0936e 100644 --- a/app/Http/Controllers/Admin/EditWidget.php +++ b/app/Http/Controllers/Admin/EditWidget.php @@ -12,12 +12,6 @@ class EditWidget extends Controller { $widget = Widget::findOrFail($id); - // decompose widget settings - $settings = json_decode($widget->settings); - - $widget->containerClass = $settings->containerClass; - $widget->code = $settings->code; - $presenter = call_user_func([$widget->widget_type_handler, 'getPresenter']); return call_user_func([$presenter, 'renderEditForm'], $widget); diff --git a/app/Http/Controllers/Admin/Settings.php b/app/Http/Controllers/Admin/Settings.php index 91033c9e..cb935bd1 100644 --- a/app/Http/Controllers/Admin/Settings.php +++ b/app/Http/Controllers/Admin/Settings.php @@ -43,18 +43,27 @@ class Settings extends Controller $settings = $this->settings->getAll(); $updated = 0; - foreach($data as $key => $value) { - if ($settings->$key != $value) { - $updated ++; - \App\Models\Settings::where('key', $key)->update(['value' => $value]); + foreach ($data as $key => $value) { + if (isset($settings->$key)) { + if ($settings->$key != $value) { + $updated++; + \App\Models\Settings::where('key', $key) + ->update(['value' => $value]); + } + } else { + \App\Models\Settings::create(['key' => $key, 'value' => $value]); + $updated++; } } if ($updated > 0) { - return redirect()->route('settings.overview')->with('success', trans('admin/settings.successfullySaved')); + return redirect() + ->route('settings.overview') + ->with('success', trans('admin/settings.successfullySaved')); } else { - return redirect()->route('settings.overview')->with('error', trans('admin/settings.nothingToSave')); + return redirect() + ->route('settings.overview') + ->with('error', trans('admin/settings.nothingToSave')); } - } } diff --git a/app/Http/Requests/CreateNewContentRequest.php b/app/Http/Requests/CreateNewContentRequest.php index 3d995ba6..7284b6ae 100644 --- a/app/Http/Requests/CreateNewContentRequest.php +++ b/app/Http/Requests/CreateNewContentRequest.php @@ -12,15 +12,15 @@ class CreateNewContentRequest extends Request public function rules() { return [ - 'title' => 'required', - 'url' => 'required|unique:contents,url', - 'template' => 'required|exists:templates,template_name', - 'published_from' => 'date', - 'published_to' => 'date', - 'title_photo' => 'exists:files,id', - 'module_settings' => 'json', - 'status' => 'required|in:draft,protected,public', - 'parentPage' => 'exists:contents,id' + 'titlePhoto' => 'image', + 'title' => 'required', + 'url' => 'required|unique:contents,url', + 'template' => 'required|exists:templates,template_name', + 'status' => 'required|in:draft,protected,public', + 'title_photo' => 'exists:files,id', + 'parentPage' => 'exists:contents,id', + 'published_from' => 'date', + 'published_to' => 'date', ]; } } diff --git a/app/Models/File.php b/app/Models/File.php index 447950ff..6ca591cd 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -3,7 +3,7 @@ namespace App\Models; use App\Events\UploadFile; -use App\Http\Requests\UploadRequest; +use App\Http\Requests\Request; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Event; @@ -49,13 +49,13 @@ class File extends Model /** * Saves file into FS and creates new record in database * - * @param UploadedFile $file - * @param UploadRequest $request + * @param UploadedFile $file + * @param Request $request * * @return array associative array - key 'file' is type of SymphonyFile and contains info about real file, key 'id' * is ID of row in files table */ - public function upload(UploadedFile $file, UploadRequest $request) + public function upload(UploadedFile $file, Request $request) { $destination = config('app.upload_path'); $filename = $this->getFilename($file); @@ -70,8 +70,9 @@ class File extends Model Event::fire(new UploadFile($uploadedFile, $id)); return [ - 'file' => $file, - 'id' => $id + 'filename' => $filename, + 'file' => $file, + 'id' => $id ]; } @@ -81,12 +82,12 @@ class File extends Model * This file saves new record into database. It also calculates hash of given file, obtains MIME type etc. * * @param SymphonyFile $file - * @param UploadRequest $request + * @param Request $request * @param $originalFilename * * @return mixed */ - protected function saveIntoDatabase(SymphonyFile $file, UploadRequest $request, $originalFilename) + protected function saveIntoDatabase(SymphonyFile $file, Request $request, $originalFilename) { // get path and hash of uploaded file $path = config('app.upload_path') . DIRECTORY_SEPARATOR . $file->getFilename(); @@ -101,13 +102,14 @@ class File extends Model $newFile->hash_algorithm = self::HASH_ALGORITHM; $newFile->mime_type = $file->getMimeType(); $newFile->file_size = $file->getSize(); - $newFile->directory_id = $request->directoryId; // save optional fields - $optionalFields = ['description', 'keywords']; + $optionalFields = ['name', 'description', 'keywords', 'directoryId']; foreach ($optionalFields as $field) { if ($request->has($field)) { - $newFile->$field = $request->$field; + + $snakeField = snake_case($field); + $newFile->$snakeField = $request->$field; } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 8cddb90f..2be6d206 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -12,6 +12,7 @@ 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\OrbitSlider\OrbitSlider; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\File; use Illuminate\Support\ServiceProvider; @@ -83,6 +84,7 @@ class AppServiceProvider extends ServiceProvider // register all available widgets $registrator->register(HtmlCode::class); + $registrator->register(OrbitSlider::class); } /** diff --git a/app/Providers/ModuleManager.php b/app/Providers/ModuleManager.php index 1ab0f42a..82edb11a 100644 --- a/app/Providers/ModuleManager.php +++ b/app/Providers/ModuleManager.php @@ -56,7 +56,7 @@ class ModuleManager extends ServiceProvider $path = config('modules.paths.modules') . DIRECTORY_SEPARATOR . $config->staticName . DIRECTORY_SEPARATOR . 'module.json'; // check if module config is writable - if (!is_writable($path)) { + if (!is_writable(dirname($path))) { return; } diff --git a/app/Widgets/Exceptions/WidgetExistsException.php b/app/Widgets/Exceptions/WidgetExistsException.php new file mode 100644 index 00000000..2cfa503a --- /dev/null +++ b/app/Widgets/Exceptions/WidgetExistsException.php @@ -0,0 +1,14 @@ + $message]); + + parent::__construct($message, $code, $previous); + } +} \ No newline at end of file diff --git a/app/Widgets/HtmlCode/Presenters/HtmlCode.php b/app/Widgets/HtmlCode/Presenters/HtmlCode.php index 71040ddf..1fa62590 100644 --- a/app/Widgets/HtmlCode/Presenters/HtmlCode.php +++ b/app/Widgets/HtmlCode/Presenters/HtmlCode.php @@ -47,6 +47,7 @@ class HtmlCode implements WidgetRenderer */ public static function renderEditForm(Widget $widget) { - return view('admin.widgets.htmlCode.edit', ['widget' => $widget]); + $settings = json_decode($widget->settings); + return view('admin.widgets.htmlCode.edit', ['widget' => $widget, 'settings' => $settings]); } } \ No newline at end of file diff --git a/app/Widgets/OrbitSlider/OrbitSlider.php b/app/Widgets/OrbitSlider/OrbitSlider.php new file mode 100644 index 00000000..0e065e4d --- /dev/null +++ b/app/Widgets/OrbitSlider/OrbitSlider.php @@ -0,0 +1,129 @@ +settings); + $parentDirectoryId = Storage::get(self::CONFIG_FILENAME); + $directoryId = isset($settings->directoryId) ? $settings->directoryId : null; + $edit = false; + + // check if directory does not exists + $exists = Directory::where('name', $request->name) + ->where('parent_id', $parentDirectoryId); + + if ($directoryId) { + $edit = true; + $exists = $exists->where('id', '!=', $directoryId); + } + + $exists = $exists->exists(); + + if ($exists) { + throw new WidgetExistsException($request->name); + } + + $directory = new Directory; + + if ($edit) { + $directory = Directory::find($directoryId); + } + + // setup some information about directory + $directory->user_id = Auth::user()->id; + $directory->parent_id = $parentDirectoryId; + $directory->name = $request->name; + $directory->description = $request->description; + $directory->save(); + + $settings = [ + 'directoryId' => $directory->id, + 'sliderClass' => isset($request->containerClass) ? $request->containerClass : '', + 'code' => $request->code + ]; + + $widget->settings = json_encode($settings); + + return $widget; + } + + /** + * Getter for presenter/renderer of this widget + * + * @return WidgetRenderer + */ + public static function getPresenter() + { + return Presenters\OrbitSlider::class; + } + + /** + * Function for installing given widget + * + * @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); + } + + /** + * Function for uninstalling widget + */ + public static function uninstall() + { + // TODO: Implement uninstall() method. + } +} \ No newline at end of file diff --git a/app/Widgets/OrbitSlider/Presenters/OrbitSlider.php b/app/Widgets/OrbitSlider/Presenters/OrbitSlider.php new file mode 100644 index 00000000..5adb81d6 --- /dev/null +++ b/app/Widgets/OrbitSlider/Presenters/OrbitSlider.php @@ -0,0 +1,56 @@ +directoryId; + + $images = File::where('directory_id', $directoryId) + ->where('mime_type', 'LIKE', 'image%') + ->get(); + + return view('widgets.orbitSlider.element', ['images' => $images, 'settings' => $settings]); + } + + /** + * Display form for creating new instance of widget + * + * @param WidgetType $type + * + * @return mixed + */ + public static function renderAddForm(WidgetType $type) + { + return view('admin.widgets.orbitSlider.new', ['type' => $type]); + } + + /** + * Display form for editing already existing widget + * + * @param Widget $widget + * + * @return mixed + */ + public static function renderEditForm(Widget $widget) + { + $settings = json_decode($widget->settings); + + return view('admin.widgets.orbitSlider.edit', ['widget' => $widget, 'settings' => $settings]); + } +} \ No newline at end of file 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/database/migrations/2016_03_31_192238_ChangeContentTitleImageIdForFilename.php b/database/migrations/2016_03_31_192238_ChangeContentTitleImageIdForFilename.php new file mode 100644 index 00000000..2d04429b --- /dev/null +++ b/database/migrations/2016_03_31_192238_ChangeContentTitleImageIdForFilename.php @@ -0,0 +1,86 @@ +dropForeign('fk_content_file1'); + }); + } catch (\Illuminate\Database\QueryException $e) { + // probably foreign does not exist, try to remove one from migration + + try { + Schema::table('contents', function (Blueprint $table) { + $table->dropForeign('contents_title_photo_foreign'); + }); + } catch (\Illuminate\Database\QueryException $ex) { + // ignore this error + } + } + + // force Doctrine to consider enum type as string + $platform = Schema::getConnection() + ->getDoctrineSchemaManager() + ->getDatabasePlatform(); + $platform->registerDoctrineTypeMapping('enum', 'string'); + + Schema::table('contents', function (Blueprint $table) { + $table->string('title_photo', 128) + ->nullable() + ->default(null) + ->comment('This photo is supposed to be displayed e.g. on list of all pages.') + ->change(); + + $table->foreign('title_photo') + ->references('filename') + ->on('files') + ->onUpdate('cascade') + ->onDelete('set null'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // force Doctrine to consider enum type as string + $platform = Schema::getConnection() + ->getDoctrineSchemaManager() + ->getDatabasePlatform(); + $platform->registerDoctrineTypeMapping('enum', 'string'); + + // delete all title photos + DB::statement('UPDATE contents SET title_photo = NULL'); + + Schema::table('contents', function (Blueprint $table) { + $table->dropForeign('contents_title_photo_foreign'); + }); + + Schema::table('contents', function (Blueprint $table) { + $table->integer('title_photo', false) + ->change(); + }); + + Schema::table('contents', function (Blueprint $table) { + $table->foreign('title_photo') + ->references('id') + ->on('files'); + }); + } +} diff --git a/database/migrations/2016_03_31_214730_MakeUserIdNotMandatoryInDirectories.php b/database/migrations/2016_03_31_214730_MakeUserIdNotMandatoryInDirectories.php new file mode 100644 index 00000000..7c719df2 --- /dev/null +++ b/database/migrations/2016_03_31_214730_MakeUserIdNotMandatoryInDirectories.php @@ -0,0 +1,37 @@ +integer('user_id', false) + ->nullable() + ->default(null) + ->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('directories', function (Blueprint $table) { + $table->integer('user_id', false) + ->nullable(false) + ->change(); + }); + } +} diff --git a/database/migrations/2016_03_31_225203_AddNameForFiles.php b/database/migrations/2016_03_31_225203_AddNameForFiles.php new file mode 100644 index 00000000..a4701e65 --- /dev/null +++ b/database/migrations/2016_03_31_225203_AddNameForFiles.php @@ -0,0 +1,34 @@ +string('name') + ->after('file_size') + ->comment('Some human readable name of file. May be used in different ways'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('files', function (Blueprint $table) { + $table->dropColumn('name'); + }); + } +} diff --git a/install b/install index c33ea689..d0491df4 100644 --- a/install +++ b/install @@ -179,6 +179,10 @@ if [ ! -e $THEME_SET_FILE ]; then echo $THEME_NAME > $THEME_SET_FILE fi +# publish assets and views +php artisan vendor:publish --tag=module-views +php artisan vendor:publish --tag=public-assets + if [ ! -e $ADMIN_CREATED_FILE ]; then echo "" echo " ------------------------------ " 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 @@ + 'List of all content pages', 'homepageSetup' => 'Homepage successfully set up.', 'setHomepage' => 'Set page as homepage', - 'noParentPage' => ' -- No parent page -- ' + 'noParentPage' => ' -- No parent page -- ', + 'uploadTitleImage' => 'Upload title image' ]; \ No newline at end of file diff --git a/resources/lang/en/admin/fileManager.php b/resources/lang/en/admin/fileManager.php index 79d9adce..ad5c0b2d 100644 --- a/resources/lang/en/admin/fileManager.php +++ b/resources/lang/en/admin/fileManager.php @@ -20,6 +20,7 @@ return [ 'noFileSpecified' => 'You have not specified any file for upload', 'uploadSuccessfull' => 'Your file was successfully uploaded', 'selectFile' => 'Select file for upload', + 'name' => 'Name', 'keywords' => 'Keywords (comma separated)', 'description' => 'File description', 'noFiles' => 'No files were found. Try to upload some.', diff --git a/resources/lang/en/admin/history.php b/resources/lang/en/admin/history.php index 0f40784e..09632f62 100644 --- a/resources/lang/en/admin/history.php +++ b/resources/lang/en/admin/history.php @@ -1,22 +1,23 @@ 'History of :name', - 'columnPageContent' => 'Page content', - 'columnUrl' => 'URL', - 'columnTitle' => 'Title', - 'columnMetaKeywords' => 'Meta keywords', - 'columnMetaDescription' => 'Description', - 'columnStatus' => 'Page visibility', - 'columnTemplate' => 'Template', - 'columnIs_homepage' => 'Homepage', - 'columnParentPage' => 'Parent page', - 'emptyValue' => 'none', - 'changedFromTo' => 'Changed from :from to :to', - 'numOfChanges' => 'One change|:count changes', - 'diff' => 'Difference', - 'diffPageName' => 'Difference of :column', - 'backToOverview' => 'Back to history overview', - 'backToEdit' => 'Back to editation form', - 'setupAsHomepage' => 'Setup as homepage' + 'pageName' => 'History of :name', + 'columnPageContent' => 'Page content', + 'columnUrl' => 'URL', + 'columnTitle' => 'Title', + 'columnMetaKeywords' => 'Meta keywords', + 'columnMetaDescription' => 'Description', + 'columnStatus' => 'Page visibility', + 'columnTemplate' => 'Template', + 'columnIs_homepage' => 'Homepage', + 'columnParentPage' => 'Parent page', + 'columnTitlePhotoFilename' => 'Title photo', + 'emptyValue' => 'none', + 'changedFromTo' => 'Changed from :from to :to', + 'numOfChanges' => 'One change|:count changes', + 'diff' => 'Difference', + 'diffPageName' => 'Difference of :column', + 'backToOverview' => 'Back to history overview', + 'backToEdit' => 'Back to editation form', + 'setupAsHomepage' => 'Setup as homepage' ]; \ No newline at end of file diff --git a/resources/lang/en/admin/widgets.php b/resources/lang/en/admin/widgets.php index f72053eb..b64cd259 100644 --- a/resources/lang/en/admin/widgets.php +++ b/resources/lang/en/admin/widgets.php @@ -21,5 +21,6 @@ return [ 'successfullyAssociated' => 'Association successfull', 'associationDoesNotExists' => 'This association does not exist', 'successfullyDeassociated' => 'Successfully removed from widget area', + 'widgetExists' => 'Widget :id already exists.' ]; \ No newline at end of file diff --git a/resources/lang/en/widgets/orbitSlider.php b/resources/lang/en/widgets/orbitSlider.php new file mode 100644 index 00000000..e9d1583b --- /dev/null +++ b/resources/lang/en/widgets/orbitSlider.php @@ -0,0 +1,15 @@ + 'Orbit slider', + 'widgetDescription' => 'Slider for images. Uses Foundation framework.', + 'name' => 'Slider name', + 'description' => 'Slider description', + 'containerClass' => 'Extra HTML class for slider', + 'createNew' => 'Create new', + 'new' => 'Create new orbit slider', + 'edit' => 'Edit slider :name', + 'editExisting' => 'Save', + 'preview' => 'Slider preview', + 'upload' => 'Add photos into slider', + 'code' => 'Some extra HTML/JS code for slider' +]; \ No newline at end of file diff --git a/resources/views/admin/content/editForm.blade.php b/resources/views/admin/content/editForm.blade.php index c2b46270..f0319dd6 100644 --- a/resources/views/admin/content/editForm.blade.php +++ b/resources/views/admin/content/editForm.blade.php @@ -10,7 +10,7 @@ @endif -
+ {!! csrf_field() !!} @include('admin.content.formInputs') diff --git a/resources/views/admin/content/formParts/appearance.blade.php b/resources/views/admin/content/formParts/appearance.blade.php index 4bab3aca..a3598d9c 100644 --- a/resources/views/admin/content/formParts/appearance.blade.php +++ b/resources/views/admin/content/formParts/appearance.blade.php @@ -1,3 +1,26 @@ +@if($page->title_photo) +
+
+ +
+
+@endif + + +
+
+ + @if (isset($errors) && $errors->has('titlePhoto')) +
+ {{ $errors->first('titlePhoto') }} +
+ @endif +
+
+
- @if (isset($errors) && $errors->has('status')) + @if (isset($errors) && $errors->has('parentPage'))
- {{ $errors->first('status') }} + {{ $errors->first('parentPage') }}
@endif
-
diff --git a/resources/views/admin/content/newForm.blade.php b/resources/views/admin/content/newForm.blade.php index 67efbec1..e7d516b6 100644 --- a/resources/views/admin/content/newForm.blade.php +++ b/resources/views/admin/content/newForm.blade.php @@ -10,7 +10,7 @@
@endif - + {!! csrf_field() !!} @include('admin.content.formInputs') diff --git a/resources/views/admin/content/overviewTiles.blade.php b/resources/views/admin/content/overviewTiles.blade.php index f353ac78..76f90c11 100644 --- a/resources/views/admin/content/overviewTiles.blade.php +++ b/resources/views/admin/content/overviewTiles.blade.php @@ -1,7 +1,12 @@ -
+
@forelse($pages as $page)
+ @if ($page->title_photo) + + @endif + +

{{$page->title}}

{{date('d.m.Y', strtotime($page->created_at))}} {{$page->author_name}} @@ -24,22 +29,36 @@ @if($page->is_homepage) @else - + @endif - + @if($page->status == \App\Models\Content::STATUS_DRAFT) - - + + @else - - + + @endif - +

-
@empty diff --git a/resources/views/admin/fileManager/editForm.blade.php b/resources/views/admin/fileManager/editForm.blade.php index 999e4e0a..534ce58f 100644 --- a/resources/views/admin/fileManager/editForm.blade.php +++ b/resources/views/admin/fileManager/editForm.blade.php @@ -14,6 +14,18 @@ {!! csrf_field() !!} + +
@endif + + + - @if (\Auth::user()->role == \App\Models\User::ROLE_ADMIN) + @if (\Auth::user()->role == \App\Models\User::ROLE_ADMIN && \Auth::user()->id != $user->id)