diff --git a/.styleci.yml b/.styleci.yml index 837286d..6400542 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,4 +1,4 @@ -# Styleci for WebDevEtc. +# Styleci for binshops. preset: laravel diff --git a/LICENSE.txt b/LICENSE.txt index 00f04a7..bac0ded 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Hessam. +Copyright (c) 2020 Binshops. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 0f4ff7c..009eaf6 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,122 @@ -

+

Laravel Blog Package

- - Latest Stable Version - - - - License - +

-# Complete Laravel CMS Package -- ### Multi-level Categories -- ### Full text search -- ### Multi-language support (coming soon) - - See the progress for multi-lang in `multi-lang` branch +### Lightweight and Easy to Install + +Incredible features with a lightweight laravel blog package. +- Quick installation (<3 minutes) +- It's very easy to extend +- Included great features out-of-box +- Its simplicity allows to be easily made compatible with latest laravel +- No additional concept except laravel knowledge +- Compatible with other Laravel platforms like Bagisto + +## Outstanding Features +- Fulltext Search - search throughout all blog posts +- Multi Level Category - nested sets using Baum +- Multi Language Support + +### Quick and easy installation (Multi-lang version) +1- Install via composer + +`composer require binshops/laravel-blog` + +For a fresh Laravel installation run the following too: + +``` +composer require laravel/ui +php artisan ui vue --auth +``` + +2- Scaffold + +``` +npm install && npm run build +``` + +3- Run the following two commands to copy config file, migration files, and view files + +`php artisan vendor:publish --provider="BinshopsBlog\BinshopsBlogServiceProvider"` + +4- Execute migrations to create tables + +`php artisan migrate;` + +5- You must add one method to your \App\User (in laravel 8 \App\Models\User) model. As the name of this method shows it determines which user can manage posts. Place your logic there + +``` + /** + * Enter your own logic (e.g. if ($this->id === 1) to + * enable this user to be able to add/edit blog posts + * + * @return bool - true = they can edit / manage blog posts, + * false = they have no access to the blog admin panel + */ + public function canManageBinshopsBlogPosts() + { + // Enter the logic needed for your app. + // Maybe you can just hardcode in a user id that you + // know is always an admin ID? + + if ( $this->id === 1 + && $this->email === "your_admin_user@your_site.com" + ){ + + // return true so this user CAN edit/post/delete + // blog posts (and post any HTML/JS) + + return true; + } + + // otherwise return false, so they have no access + // to the admin panel (but can still view posts) + + return false; + } +``` + +6- Create a directory in `public/` named `blog_images` -## [Let's try it - Online Demo](https://cms.binshops.com/login) -You can try Hessam CMS online: [https://cms.binshops.com](https://cms.binshops.com/login) +7- Start the server -### Quick and easy installation +``` +php artisan serve +``` -Install with following command and follow the instructions. +8- Login as admin and setup your package: `/blog_admin/setup` - composer require hessam/laravel-blogger +Congrats! Your blog is ready to use. (URLs are customizable in the config file) -### For Complete Setup Instructions (with video guide), please Visit [The Install Guide](https://hessam.binshops.com/laravel-blog-package#setup) + Admin panel URI: `/blog_admin` + Front URI: `/en/blog` -To see package on Packagist click this [Link](https://packagist.org/packages/hessam/laravel-blogger) +To see package on Packagist click this [Link](https://packagist.org/packages/binshops/laravel-blog) + +### Single Language Version +To install the single language version of the package use version v8.1x: + +1- `composer require binshops/laravel-blog:v8.2.0` + +2- `php artisan vendor:publish --provider="BinshopsBlog\BinshopsBlogServiceProvider"` + +3- `php artisan vendor:publish --tag=laravel-fulltext` + +4- `php artisan migrate;` + +You can see the single version in "single-lang" branch. The major difference with multi-language version is the database structure. ## Important Notes -- For laravel 8.x's default auth User model, change user model in `blogetc.php` to: `\App\Models\User::class` +- For laravel 8.x's default auth User model, change user model in `binshopsblog.php` to: `\App\Models\User::class` ## Features - Compatible with latest laravel version (laravel 8.x) - Backward-compatibility with previous laravel versions - Full text search - searching throughout the blog posts - Multi-level category support -- fully configurable via its `config/blogetc.php` config file +- fully configurable via its `config/binshopsblog.php` config file - Ready to use admin panel - Full customizability of admin views and front views - Paginated views @@ -46,56 +125,34 @@ To see package on Packagist click this [Link](https://packagist.org/packages/hes - Managing comments and comment approval - Other options include using Disqus comments or disabling comments -## Recent Changes -- **8.0.x** Compatibility with Laravel 8.x - -## Screen Shots - -

- -

-

- Add post -

- -

- -

-

- All posts -

- -

- -

-

- Add category -

- +## Recent Changes +- **9.1.x** Multi language support +- 8.0.x Compatibility with Laravel 8.x + ## What/who this package is for: - For websites running Laravel - - Who wants to have a site blog, and have an easy to use interface to write blog posts/assign categories/manage existing posts + - Anyone, who wants to have a site blog. This laravel blog gives an easy to use interface to write blog posts/assign categories/manage existing posts - Where only admin users can edit/manage the blog (this is not suitable for every user on your site to be able to manage posts) - - For anyone who likes to add a wordpress-like CMS to her/his web app + - For anyone who likes to add a wordpress-like laravel blog to laravel website ## How to customise the blog views/templates -After doing the correct `vendor:publish`, all of the default template files will be found in /resources/views/vendor/blogetc/ and are easy to edit to match your needs. +After doing the correct `vendor:publish`, all of the default template files will be found in /resources/views/vendor/binshopsblog/ and are easy to edit to match your needs. ### Customizing admin views If you need to customize the admin view, just copy the files from -`vendor/webdevetc/blogetc/src/Views/blogetc_admin` +`vendor/binshopsblog/src/Views/binshopsblog_admin` to -`resources/views/vendor/blogetc_admin` +`resources/views/vendor/binshopsblog_admin` Then you can modify them just like any other view file. ## Routes -It will auto set all required routes (both public facing, and admin backend). There are some config options (such as changing the /blog/ url to something else), which can be done in the blogetc.php file. +It will auto set all required routes (both public facing, and admin backend). There are some config options (such as changing the /blog/ url to something else), which can be done in the binshopsblog.php file. ## Config options -All config options have comments which describe what they do. Please just refer to the `blogetc.php` file in your /config/ dir. +All config options have comments which describe what they do. Please just refer to the `binshopsblog.php` file in your /config/ dir. ### Custom User Model You can change the default user model through the config file. @@ -108,9 +165,31 @@ Add these (and an Event Listener) to your `EventServiceProvider.php` file to mak ## Built in CAPTCHA / anti spam -There is a built in captcha (anti spam comment) system built in, which will be easy for you to replace with your own implementation. +There is a built-in captcha (anti-spam comment) system built in, which will be easy for you to replace with your own implementation. + +There is a basic anti-spam captcha function built-in. + +See the config/binshops.php captcha section. There is a built in system (basic!) that will prevent most automated spam attempts. +Writing your own captcha system: + +I wrote the captcha system simple on purpose, so you can add your own captcha options. It should be easy to add any other captcha system to this. - Please see [this Captcha docs](https://hessam.binshops.com/laravel-blog-package#captcha) for more details. +If you want to write your own implementation then create your own class that implements \BinshopsBlog\Interfaces\CaptchaInterface, then update the config/binshopsblog.php file (change the captcha_type option). + +There are three methods you need to implement: +public function captcha_field_name() : string + +Return a string such as "captcha". It is used for the form validation and . +public function view() : string + +What view file should the binshops::partials.add_comment_form view include? You can set this to whatever you need, and then create your own view file. The default included basic captcha class will return "binshops::captcha.basic". +public function rules() : array + +Return an array for the rules (which are just the standard Laravel validation rules. This is where you can check if the captcha was successful or not. +Optional: +public function runCaptchaBeforeShowingPosts() : null + +This isn't part of the interface, it isn't required. By default it does nothing. But you can put some code in this method and it'll be run in the BinshopsReaderController::viewSinglePost method. ## Image upload errors @@ -123,41 +202,13 @@ Try adding this to config/app.php: - You might need to set a higher memory limit, or upload smaller image files. This will depend on your server. I've used it to upload huge (10mb+) jpg images without problem, once the server was set up correctly to handle larger file uploads. ## Version History -- **8.0.x** Compatibility with Laravel 8 -- 7.3.2 Some bug fixes +- **9.3.x** Stable version of package +- 9.0.x Multi-language support beta release +- 8.0.x Compatibility with Laravel 8 - 7.3.0 New Admin UI -- 7.2.2 - - bug fix: do not show search bar when it's disabled - - feature: configure to show full text post or preview -- 7.2.1 - adds logout button at admin panel -- 7.2.0 - - adds sub-category functionality to blog - - adds reading progress bar feature (if you upgrade, re-publish config file and view files) -- 7.1.8 - ability to remove images from posts (this feature does not work for old posts) -- 7.1.7 - updates CKEditor -- 7.1.5 - minor fix for recent posts -- 7.1.4 - updates fulltext search package which solves the search issue -- 7.1.2 - shows categories on blog home page - minor fix (if you upgrade try to re-publish view files) -- 7.1.1 - minor fix and some admin panel text changes -- 7.1.0 - Adds support for custom user model (if you upgrade, try to publish new config) -- 7.0.2 - Bug fix for listing posts and search page -- 7.0.1 - made compatible with Laravel 6.x & 7.x -- 3.1 - minor fixes -- 3.0.3 - fixed RSS feed cache issue -- 3.0.2 - fixed default medium image size (changed to 600x400) - 3.0.1 - replaced all short tags (create('laravel_fulltext', function (Blueprint $table) { + $table->increments('id'); + $table->integer('indexable_id'); + $table->string('indexable_type'); + $table->text('indexed_title'); + $table->text('indexed_content'); + + $table->unique(['indexable_type', 'indexable_id']); + + $table->timestamps(); + }); + + DB::connection(config('laravel-fulltext.db_connection'))->statement('ALTER TABLE laravel_fulltext ADD FULLTEXT fulltext_title(indexed_title)'); + DB::connection(config('laravel-fulltext.db_connection'))->statement('ALTER TABLE laravel_fulltext ADD FULLTEXT fulltext_title_content(indexed_title, indexed_content)'); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::connection(config('laravel-fulltext.db_connection'))->drop('laravel_fulltext'); + } +} diff --git a/migrations/2018_05_28_224023_create_blog_etc_posts_table.php b/migrations/2018_05_28_224023_create_blog_etc_posts_table.php deleted file mode 100755 index 683a076..0000000 --- a/migrations/2018_05_28_224023_create_blog_etc_posts_table.php +++ /dev/null @@ -1,92 +0,0 @@ -increments('id'); - $table->unsignedInteger("user_id")->index()->nullable(); - $table->string("slug")->unique(); - - $table->string("title")->nullable()->default("New blog post"); - $table->string("subtitle")->nullable()->default(""); - $table->text("meta_desc")->nullable(); - $table->mediumText("post_body")->nullable(); - - $table->string("use_view_file")->nullable()->comment("should refer to a blade file in /views/"); - - $table->dateTime("posted_at")->index()->nullable()->comment("Public posted at time, if this is in future then it wont appear yet"); - $table->boolean("is_published")->default(true); - - $table->string('image_large')->nullable(); - $table->string('image_medium')->nullable(); - $table->string('image_thumbnail')->nullable(); - - $table->timestamps(); - }); - - Schema::create('blog_etc_categories', function (Blueprint $table) { - $table->increments('id'); - - $table->string("category_name")->nullable(); - $table->string("slug")->unique(); - $table->mediumText("category_description")->nullable(); - - $table->unsignedInteger("created_by")->nullable()->index()->comment("user id"); - - $table->timestamps(); - }); - - Schema::create('blog_etc_post_categories', function (Blueprint $table) { - $table->increments('id'); - - $table->unsignedInteger("blog_etc_post_id")->index(); - $table->foreign('blog_etc_post_id')->references('id')->on('blog_etc_posts')->onDelete("cascade"); - - $table->unsignedInteger("blog_etc_category_id")->index(); - $table->foreign('blog_etc_category_id')->references('id')->on('blog_etc_categories')->onDelete("cascade"); - }); - - - Schema::create('blog_etc_comments', function (Blueprint $table) { - $table->increments('id'); - - $table->unsignedInteger("blog_etc_post_id")->index(); - $table->foreign('blog_etc_post_id')->references('id')->on('blog_etc_posts')->onDelete("cascade"); - $table->unsignedInteger("user_id")->nullable()->index()->comment("if user was logged in"); - - $table->string("ip")->nullable()->comment("if enabled in the config file"); - $table->string("author_name")->nullable()->comment("if not logged in"); - - $table->text("comment")->comment("the comment body"); - - $table->boolean("approved")->default(true); - - $table->timestamps(); - }); - - - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('blog_etc_post_categories'); - Schema::dropIfExists('blog_etc_categories'); - Schema::dropIfExists('blog_etc_posts'); - } -} diff --git a/migrations/2018_09_16_224023_add_author_and_url_blog_etc_posts_table.php b/migrations/2018_09_16_224023_add_author_and_url_blog_etc_posts_table.php deleted file mode 100644 index 67cec73..0000000 --- a/migrations/2018_09_16_224023_add_author_and_url_blog_etc_posts_table.php +++ /dev/null @@ -1,37 +0,0 @@ -string("author_email")->nullable(); - $table->string("author_website")->nullable(); - }); - - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - - Schema::table('blog_etc_comments', function (Blueprint $table) { - $table->dropColumn("author_email"); - $table->dropColumn("author_website"); - }); - } -} - diff --git a/migrations/2020_10_16_004241_create_binshops_languages_table.php b/migrations/2020_10_16_004241_create_binshops_languages_table.php new file mode 100644 index 0000000..cbf41a9 --- /dev/null +++ b/migrations/2020_10_16_004241_create_binshops_languages_table.php @@ -0,0 +1,39 @@ +increments('id'); + + $table->string("name")->unique(); + $table->string("locale")->unique(); + $table->string("iso_code")->unique(); + $table->string("date_format"); + $table->boolean("active")->default(true); + $table->boolean("rtl")->default(false); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('binshops_languages'); + } +} diff --git a/migrations/2020_05_27_104123_add_parameters_blog_etc_categories_table.php b/migrations/2020_10_16_005400_create_binshops_categories_table.php similarity index 52% rename from migrations/2020_05_27_104123_add_parameters_blog_etc_categories_table.php rename to migrations/2020_10_16_005400_create_binshops_categories_table.php index 1fc8255..1e1c566 100644 --- a/migrations/2020_05_27_104123_add_parameters_blog_etc_categories_table.php +++ b/migrations/2020_10_16_005400_create_binshops_categories_table.php @@ -4,7 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddParametersBlogEtcCategoriesTable extends Migration +class CreateBinshopsCategoriesTable extends Migration { /** * Run the migrations. @@ -13,12 +13,20 @@ class AddParametersBlogEtcCategoriesTable extends Migration */ public function up() { - Schema::table('blog_etc_categories', function (Blueprint $table) { - $table->integer('parent_id')->nullable()->default(0); + Schema::create('binshops_categories', function (Blueprint $table) { + $table->increments('id'); + + $table->unsignedInteger("created_by")->nullable()->index()->comment("user id"); + + //columns related to multi-level categories + $table->integer('parent_id')->nullable(); $table->integer('lft')->nullable(); $table->integer('rgt')->nullable(); $table->integer('depth')->nullable(); + + $table->timestamps(); }); + } /** @@ -28,8 +36,6 @@ public function up() */ public function down() { - Schema::table('blog_etc_categories', function (Blueprint $table) { - // - }); + Schema::dropIfExists('binshops_categories'); } } diff --git a/migrations/2020_10_16_005425_create_binshops_category_translations_table.php b/migrations/2020_10_16_005425_create_binshops_category_translations_table.php new file mode 100644 index 0000000..713197b --- /dev/null +++ b/migrations/2020_10_16_005425_create_binshops_category_translations_table.php @@ -0,0 +1,41 @@ +increments('id'); + + $table->unsignedInteger('category_id')->nullable(); + + $table->string("category_name")->nullable(); + $table->string("slug")->unique(); + $table->mediumText("category_description")->nullable(); + + $table->unsignedInteger("lang_id")->index(); + $table->foreign('lang_id')->references('id')->on('binshops_languages'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('binshops_category_translations'); + } +} diff --git a/migrations/2020_10_16_010039_create_binshops_posts_table.php b/migrations/2020_10_16_010039_create_binshops_posts_table.php new file mode 100644 index 0000000..398b44e --- /dev/null +++ b/migrations/2020_10_16_010039_create_binshops_posts_table.php @@ -0,0 +1,46 @@ +increments('id'); + $table->unsignedInteger("user_id")->index()->nullable(); + + $table->dateTime("posted_at")->index()->nullable()->comment("Public posted at time, if this is in future then it wont appear yet"); + $table->boolean("is_published")->default(true); + + $table->timestamps(); + }); + + Schema::create('binshops_post_categories', function (Blueprint $table) { + $table->increments('id'); + + $table->unsignedInteger("post_id")->index(); + $table->foreign('post_id')->references('id')->on('binshops_posts')->onDelete("cascade"); + + $table->unsignedInteger("category_id")->index(); + $table->foreign('category_id')->references('id')->on('binshops_categories')->onDelete("cascade"); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('binshops_posts'); + } +} diff --git a/migrations/2020_10_16_010049_create_binshops_post_translations_table.php b/migrations/2020_10_16_010049_create_binshops_post_translations_table.php new file mode 100644 index 0000000..3c52d9f --- /dev/null +++ b/migrations/2020_10_16_010049_create_binshops_post_translations_table.php @@ -0,0 +1,51 @@ +increments('id'); + + $table->unsignedInteger('post_id')->nullable(); + + $table->string("slug"); + $table->string("title")->nullable()->default("New blog post"); + $table->string("subtitle")->nullable()->default(""); + $table->text("meta_desc")->nullable(); + $table->string("seo_title")->nullable(); + $table->mediumText("post_body")->nullable(); + $table->text("short_description")->nullable(); + + $table->string("use_view_file")->nullable()->comment("should refer to a blade file in /views/"); + + $table->string('image_large')->nullable(); + $table->string('image_medium')->nullable(); + $table->string('image_thumbnail')->nullable(); + + $table->unsignedInteger("lang_id")->index(); + $table->foreign('lang_id')->references('id')->on('binshops_languages'); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('binshops_post_translations'); + } +} diff --git a/migrations/2020_10_16_121230_create_binshops_comments_table.php b/migrations/2020_10_16_121230_create_binshops_comments_table.php new file mode 100644 index 0000000..91091d8 --- /dev/null +++ b/migrations/2020_10_16_121230_create_binshops_comments_table.php @@ -0,0 +1,45 @@ +increments('id'); + + $table->unsignedInteger("post_id")->index(); + $table->unsignedInteger("user_id")->nullable()->index()->comment("if user was logged in"); + + $table->string("ip")->nullable()->comment("if enabled in the config file"); + $table->string("author_name")->nullable()->comment("if not logged in"); + + $table->text("comment")->comment("the comment body"); + + $table->boolean("approved")->default(true); + + $table->string("author_email")->nullable(); + $table->string("author_website")->nullable(); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('binshops_comments'); + } +} diff --git a/migrations/2018_09_27_122627_create_blog_etc_uploaded_photos_table.php b/migrations/2020_10_16_121728_create_binshops_uploaded_photos_table.php similarity index 61% rename from migrations/2018_09_27_122627_create_blog_etc_uploaded_photos_table.php rename to migrations/2020_10_16_121728_create_binshops_uploaded_photos_table.php index 5098b13..9485997 100644 --- a/migrations/2018_09_27_122627_create_blog_etc_uploaded_photos_table.php +++ b/migrations/2020_10_16_121728_create_binshops_uploaded_photos_table.php @@ -1,10 +1,10 @@ increments('id'); $table->text("uploaded_images")->nullable(); $table->string("image_title")->nullable(); @@ -21,9 +21,6 @@ public function up() $table->unsignedInteger("uploader_id")->nullable()->index(); $table->timestamps(); }); - Schema::table("blog_etc_posts",function(Blueprint $table) { - $table->string("seo_title")->nullable(); - }); } /** @@ -33,10 +30,6 @@ public function up() */ public function down() { - Schema::dropIfExists('blog_etc_uploaded_photos'); - - Schema::table("blog_etc_posts",function(Blueprint $table) { - $table->dropColumn("seo_title"); - }); + Schema::dropIfExists('binshops_uploaded_photos'); } } diff --git a/migrations/2018_09_26_085711_add_short_desc_textrea_to_blog_etc.php b/migrations/2020_10_22_132005_create_binshops_configurations_table.php similarity index 53% rename from migrations/2018_09_26_085711_add_short_desc_textrea_to_blog_etc.php rename to migrations/2020_10_22_132005_create_binshops_configurations_table.php index e24feed..b62c443 100644 --- a/migrations/2018_09_26_085711_add_short_desc_textrea_to_blog_etc.php +++ b/migrations/2020_10_22_132005_create_binshops_configurations_table.php @@ -1,10 +1,10 @@ text("short_description")->nullable(); + Schema::create('binshops_configurations', function (Blueprint $table) { + $table->string("key")->primary(); + $table->string("value"); + $table->timestamps(); }); - } /** @@ -26,9 +27,6 @@ public function up() */ public function down() { - - Schema::table('blog_etc_posts', function (Blueprint $table) { - $table->dropColumn("short_description"); - }); + Schema::dropIfExists('binshops_configurations'); } } diff --git a/src/Baum/Extensions/Eloquent/Collection.php b/src/Baum/Extensions/Eloquent/Collection.php index 41884af..5fb8a4a 100644 --- a/src/Baum/Extensions/Eloquent/Collection.php +++ b/src/Baum/Extensions/Eloquent/Collection.php @@ -1,5 +1,5 @@ getDictionary(); - // Enforce sorting by $orderColumn setting in WebDevEtc\BlogEtc\Baum\Node instance + // Enforce sorting by $orderColumn setting in BinshopsBlog\Baum\Node instance uasort($dict, function($a, $b){ return ($a->getOrder() >= $b->getOrder()) ? 1 : -1; }); diff --git a/src/Baum/Extensions/Eloquent/Model.php b/src/Baum/Extensions/Eloquent/Model.php index 66fb0c5..2a2cb2b 100644 --- a/src/Baum/Extensions/Eloquent/Model.php +++ b/src/Baum/Extensions/Eloquent/Model.php @@ -1,10 +1,10 @@ guardAgainstImpossibleMove(); @@ -176,14 +176,14 @@ public function updateStructure() { /** * Resolves suplied node. Basically returns the node unchanged if - * supplied parameter is an instance of \WebDevEtc\BlogEtc\Baum\Node. Otherwise it will try + * supplied parameter is an instance of \BinshopsBlog\Baum\Node. Otherwise it will try * to find the node in the database. * - * @param \WebDevEtc\BlogEtc\Baum\node|int - * @return \WebDevEtc\BlogEtc\Baum\Node + * @param \BinshopsBlog\Baum\node|int + * @return \BinshopsBlog\Baum\Node */ protected function resolveNode($node) { - if ( $node instanceof \WebDevEtc\BlogEtc\Baum\Node ) return $node->reload(); + if ( $node instanceof \BinshopsBlog\Baum\Node ) return $node->reload(); return $this->node->newNestedSetQuery()->find($node); } diff --git a/src/Baum/MoveNotPossibleException.php b/src/Baum/MoveNotPossibleException.php index a05c4b2..8056c90 100644 --- a/src/Baum/MoveNotPossibleException.php +++ b/src/Baum/MoveNotPossibleException.php @@ -1,4 +1,4 @@ moveToLeftOf($this->getLeftSibling()); @@ -896,7 +896,7 @@ public function moveLeft() { /** * Find the right sibling and move to the right of it. * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function moveRight() { return $this->moveToRightOf($this->getRightSibling()); @@ -905,7 +905,7 @@ public function moveRight() { /** * Move to the node to the left of ... * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function moveToLeftOf($node) { return $this->moveTo($node, 'left'); @@ -914,7 +914,7 @@ public function moveToLeftOf($node) { /** * Move to the node to the right of ... * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function moveToRightOf($node) { return $this->moveTo($node, 'right'); @@ -923,7 +923,7 @@ public function moveToRightOf($node) { /** * Alias for moveToRightOf * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function makeNextSiblingOf($node) { return $this->moveToRightOf($node); @@ -932,7 +932,7 @@ public function makeNextSiblingOf($node) { /** * Alias for moveToRightOf * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function makeSiblingOf($node) { return $this->moveToRightOf($node); @@ -941,7 +941,7 @@ public function makeSiblingOf($node) { /** * Alias for moveToLeftOf * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function makePreviousSiblingOf($node) { return $this->moveToLeftOf($node); @@ -950,7 +950,7 @@ public function makePreviousSiblingOf($node) { /** * Make the node a child of ... * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function makeChildOf($node) { return $this->moveTo($node, 'child'); @@ -959,7 +959,7 @@ public function makeChildOf($node) { /** * Make the node the first child of ... * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function makeFirstChildOf($node) { if ( $node->children()->count() == 0 ) @@ -971,7 +971,7 @@ public function makeFirstChildOf($node) { /** * Make the node the last child of ... * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function makeLastChildOf($node) { return $this->makeChildOf($node); @@ -980,7 +980,7 @@ public function makeLastChildOf($node) { /** * Make current node a root node. * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function makeRoot() { return $this->moveTo($this, 'root'); @@ -989,7 +989,7 @@ public function makeRoot() { /** * Equals? * - * @param \WebDevEtc\BlogEtc\Baum\Node + * @param \BinshopsBlog\Baum\Node * @return boolean */ public function equals($node) { @@ -999,7 +999,7 @@ public function equals($node) { /** * Checkes if the given node is in the same scope as the current one. * - * @param \WebDevEtc\BlogEtc\Baum\Node + * @param \BinshopsBlog\Baum\Node * @return boolean */ public function inSameScope($other) { @@ -1014,7 +1014,7 @@ public function inSameScope($other) { * Checks wether the given node is a descendant of itself. Basically, whether * its in the subtree defined by the left and right indices. * - * @param \WebDevEtc\BlogEtc\Baum\Node + * @param \BinshopsBlog\Baum\Node * @return boolean */ public function insideSubtree($node) { @@ -1071,7 +1071,7 @@ public function moveToNewParent() { /** * Sets the depth attribute * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function setDepth() { $self = $this; @@ -1091,7 +1091,7 @@ public function setDepth() { /** * Sets the depth attribute for the current node and all of its descendants. * - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ public function setDepthWithSubtree() { $self = $this; @@ -1232,9 +1232,9 @@ public function makeTree($nodeList) { * Main move method. Here we handle all node movements with the corresponding * lft/rgt index updates. * - * @param WebDevEtc\BlogEtc\Baum\Node|int $target + * @param BinshopsBlog\Baum\Node|int $target * @param string $position - * @return \WebDevEtc\BlogEtc\Baum\Node + * @return \BinshopsBlog\Baum\Node */ protected function moveTo($target, $position) { return Move::to($this, $target, $position); @@ -1259,7 +1259,7 @@ protected function computeLevel() { /** * Return an array with the last node we could reach and its nesting level * - * @param WebDevEtc\BlogEtc\Baum\Node $node + * @param BinshopsBlog\Baum\Node $node * @param integer $nesting * @return array */ diff --git a/src/Baum/SetBuilder.php b/src/Baum/SetBuilder.php index e3b57bb..0374ddc 100644 --- a/src/Baum/SetBuilder.php +++ b/src/Baum/SetBuilder.php @@ -1,15 +1,15 @@ publishes([ + __DIR__ . '/../migrations/' . $file => database_path('migrations/' . $file) + ]); + + } + + $this->publishes([ + __DIR__ . '/Views/binshopsblog' => base_path('resources/views/vendor/binshopsblog'), + __DIR__ . '/Config/binshopsblog.php' => config_path('binshopsblog.php'), + __DIR__ . '/css/binshopsblog_admin_css.css' => public_path('binshopsblog_admin_css.css'), + __DIR__ . '/css/binshops-blog.css' => public_path('binshops-blog.css'), + __DIR__ . '/css/admin-setup.css' => public_path('admin-setup.css'), + __DIR__ . '/js/binshops-blog.js' => public_path('binshops-blog.js'), + ]); + + + } + + /** + * Register services. + * + * @return void + */ + public function register() + { + $this->app->bind( + SearchInterface::class, + Search::class + ); + + // for the admin backend views ( view("binshopsblog_admin::BLADEFILE") ) + $this->loadViewsFrom(__DIR__ . "/Views/binshopsblog_admin", 'binshopsblog_admin'); + + // for public facing views (view("binshopsblog::BLADEFILE")): + // if you do the vendor:publish, these will be copied to /resources/views/vendor/binshopsblog anyway + $this->loadViewsFrom(__DIR__ . "/Views/binshopsblog", 'binshopsblog'); + } + +} diff --git a/src/BlogEtcServiceProvider.php b/src/BlogEtcServiceProvider.php deleted file mode 100755 index a8ed524..0000000 --- a/src/BlogEtcServiceProvider.php +++ /dev/null @@ -1,70 +0,0 @@ -publishes([ - __DIR__ . '/../migrations/' . $file => database_path('migrations/' . $file) - ]); - - } - - $this->publishes([ - __DIR__ . '/Views/blogetc' => base_path('resources/views/vendor/blogetc'), - __DIR__ . '/Config/blogetc.php' => config_path('blogetc.php'), - __DIR__ . '/css/blogetc_admin_css.css' => public_path('blogetc_admin_css.css'), - __DIR__ . '/css/hessam-blog.css' => public_path('hessam-blog.css'), - __DIR__ . '/js/hessam-blog.js' => public_path('hessam-blog.js'), - ]); - - - } - - /** - * Register services. - * - * @return void - */ - public function register() - { - - // for the admin backend views ( view("blogetc_admin::BLADEFILE") ) - $this->loadViewsFrom(__DIR__ . "/Views/blogetc_admin", 'blogetc_admin'); - - // for public facing views (view("blogetc::BLADEFILE")): - // if you do the vendor:publish, these will be copied to /resources/views/vendor/blogetc anyway - $this->loadViewsFrom(__DIR__ . "/Views/blogetc", 'blogetc'); - } - -} diff --git a/src/Captcha/Basic.php b/src/Captcha/Basic.php index c98c380..f65694e 100644 --- a/src/Captcha/Basic.php +++ b/src/Captcha/Basic.php @@ -1,15 +1,15 @@ -\App\User::class, + //Change it to \App\User::class for previous laravel versions + 'user_model'=>\App\Models\User::class, // reading progress bar is the bar which shows on top of your post when you are scrolling down the page. You can disable this feature if you want 'reading_progress_bar' => true, - 'include_default_routes' => true, // set to false to not include routes.php for BlogEtcReaderController and admin related routes. Default: true. If you disable this, you will have to manually copy over the data from routes.php and add it to your web.php. + 'include_default_routes' => true, // set to false to not include routes.php for BinshopsReaderController and admin related routes. Default: true. If you disable this, you will have to manually copy over the data from routes.php and add it to your web.php. 'blog_prefix' => "blog", // used in routes.php. If you want to your http://yoursite.com/latest-news (or anything else), then enter that here. Default: blog 'admin_prefix' => "blog_admin", // similar to above, but used for the admin panel for the blog. Default: blog_admin @@ -26,7 +25,7 @@ 'memory_limit' => '2048M', // This is used when uploading images : - // @ini_set('memory_limit', config("blogetc.memory_limit")); + // @ini_set('memory_limit', config("binshopsblog.memory_limit")); // See PHP.net for detailso // Set to false to not set any value. @@ -89,7 +88,7 @@ ], // you can add more fields here, but make sure that you create the relevant database columns too! - // They must be in the same format as the default ones - image_xxxxx (and this db column must exist on the blog_etc_posts table) + // They must be in the same format as the default ones - image_xxxxx (and this db column must exist on the binshops_posts table) /* 'image_custom_example_size' => [ // << MAKE A DB COLUM WITH THIS NAME. @@ -103,7 +102,7 @@ ], */ // Create the custom db table by doing - // php artisan make:migration --table=blog_etc_posts AddCustomBlogImageSize + // php artisan make:migration --table=binshops_posts AddCustomBlogImageSize // then adding in the up() method: // $table->string("image_custom_example_size")->nullable(); // and in the down() method: @@ -115,23 +114,11 @@ 'captcha' => [ 'captcha_enabled' => true, // true = we should use a captcha, false = turn it off. If comments are disabled this makes no difference. - 'captcha_type' => \WebDevEtc\BlogEtc\Captcha\Basic::class, // this should be a class that implements the \WebDevEtc\BlogEtc\Interfaces\CaptchaInterface interface + 'captcha_type' => \BinshopsBlog\Captcha\Basic::class, // this should be a class that implements the \BinshopsBlog\Interfaces\CaptchaInterface interface 'basic_question' => "What is the opposite of white?", // a simple captcha question to always ask (if captcha_type is set to 'basic' 'basic_answers' => "black,dark", // comma separated list of possible answers. Don't worry about case. ], - ////////// RSS FEED - - 'rssfeed' => [ - - 'should_shorten_text' => true, // boolean. Default: true. Should we shorten the text in rss feed? - 'text_limit' => 100, // max length of description text in the rss feed - 'posts_to_show_in_rss_feed' => 10, // how many posts should we show in the rss feed - 'cache_in_minutes' => 60, // how long (in minutes) to cache the RSS blog feed for. - 'description' => "Our blog post RSS feed", //description for the RSS feed - 'language' => "en", // see https://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes - ], - ////////// comments: 'comments' => [ @@ -141,7 +128,7 @@ // options: // 'built_in' (default, uses own database for comments), // 'disqus' (uses https://disqus.com/, please enter further config options below), - // 'custom' (will load blogetc::partials.custom_comments, which you can copy to your vendor view dir to customise + // 'custom' (will load binshopsblog::partials.custom_comments, which you can copy to your vendor view dir to customise // 'disabled' (turn comments off) 'type_of_comments_to_show' => 'built_in', // default: built_in @@ -177,6 +164,13 @@ 'search' => [ 'search_enabled' => true, //you can easily turn off search functionality + + 'limit-results'=> 50, + 'enable_wildcards' => true, + 'weight' => [ + 'title' => 1.5, + 'content' => 1, + ], ], //Shows full text of post in listing pages like search result page or category page. Now it shows a preview diff --git a/src/Controllers/BinshopsAdminController.php b/src/Controllers/BinshopsAdminController.php new file mode 100755 index 0000000..34c3ef1 --- /dev/null +++ b/src/Controllers/BinshopsAdminController.php @@ -0,0 +1,503 @@ +middleware(UserCanManageBlogPosts::class); + $this->middleware(LoadLanguage::class); + $this->middleware(PackageSetup::class); + + if (!is_array(config("binshopsblog"))) { + throw new \RuntimeException('The config/binshopsblog.php does not exist. Publish the vendor files for the BinshopsBlog package by running the php artisan publish:vendor command'); + } + } + + /** + * View all posts + * + * @return mixed + */ + public function index(Request $request) + { + $language_id = $request->get('language_id'); + $posts = BinshopsPostTranslation::orderBy("post_id", "desc")->where('lang_id', $language_id) + ->paginate(10); + + return view("binshopsblog_admin::index", [ + 'post_translations'=>$posts, + 'language_id' => $language_id + ]); + } + + /** + * Show form for creating new post + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function create_post(Request $request) + { + $language_id = $request->get('language_id'); + $language_list = BinshopsLanguage::where('active',true)->get(); + $ts = BinshopsCategoryTranslation::where("lang_id",$language_id)->limit(1000)->get(); + + $new_post = new BinshopsPost(); + $new_post->is_published = true; + + return view("binshopsblog_admin::posts.add_post", [ + 'cat_ts' => $ts, + 'language_list' => $language_list, + 'selected_lang' => $language_id, + 'post' => $new_post, + 'post_translation' => new \BinshopsBlog\Models\BinshopsPostTranslation(), + 'post_id' => -1 + ]); + } + + /** + * Save a new post - this method is called whenever add post button is clicked + * + * @param CreateBinshopsBlogPostRequest $request + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @throws \Exception + */ + public function store_post(CreateBinshopsBlogPostRequest $request) + { + $new_blog_post = null; + $translation = BinshopsPostTranslation::where( + [ + ['post_id','=',$request['post_id']], + ['lang_id', '=', $request['lang_id']] + ] + )->first(); + + if (!$translation){ + $translation = new BinshopsPostTranslation(); + } + + if ($request['post_id'] == -1 || $request['post_id'] == null){ + //cretes new post + $new_blog_post = new BinshopsPost(); + $translation = new BinshopsPostTranslation(); + + $new_blog_post->posted_at = Carbon::now(); + }else{ + //edits post + $new_blog_post = BinshopsPost::findOrFail($request['post_id']); + } + + $post_exists = $this->check_if_same_post_exists($request['slug'] , $request['lang_id'], $request['post_id']); + if ($post_exists){ + Helpers::flash_message("Post already exists - try to change the slug for this language"); + }else { + $new_blog_post->is_published = $request['is_published']; + $new_blog_post->user_id = \Auth::user()->id; + $new_blog_post->save(); + + $translation->title = $request['title']; + $translation->subtitle = $request['subtitle']; + $translation->short_description = $request['short_description']; + $translation->post_body = $request['post_body']; + $translation->seo_title = $request['seo_title']; + $translation->meta_desc = $request['meta_desc']; + $translation->slug = $request['slug']; + $translation->use_view_file = $request['use_view_file']; + + $translation->lang_id = $request['lang_id']; + $translation->post_id = $new_blog_post->id; + + $this->processUploadedImages($request, $translation); + $translation->save(); + + $new_blog_post->categories()->sync($request->categories()); + Helpers::flash_message("Added post"); + event(new BlogPostAdded($new_blog_post)); + } + + return redirect( route('binshopsblog.admin.index') ); + } + + /** + * This method is called whenever a language is selected + */ + public function store_post_toggle(CreateBinshopsPostToggleRequest $request){ + $new_blog_post = null; + $translation = BinshopsPostTranslation::where( + [ + ['post_id','=',$request['post_id']], + ['lang_id', '=', $request['lang_id']] + ] + )->first(); + + if (!$translation){ + $translation = new BinshopsPostTranslation(); + } + + if ($request['post_id'] == -1 || $request['post_id'] == null){ + //cretes new post + $new_blog_post = new BinshopsPost(); + $new_blog_post->is_published = true; + $new_blog_post->posted_at = Carbon::now(); + }else{ + //edits post + $new_blog_post = BinshopsPost::findOrFail($request['post_id']); + } + + if ($request['slug']){ + $post_exists = $this->check_if_same_post_exists($request['slug'] , $request['lang_id'], $new_blog_post->id); + if ($post_exists){ + Helpers::flash_message("Post already exists - try to change the slug for this language"); + }else{ + $new_blog_post->is_published = $request['is_published']; + $new_blog_post->user_id = \Auth::user()->id; + $new_blog_post->save(); + + $translation->title = $request['title']; + $translation->subtitle = $request['subtitle']; + $translation->short_description = $request['short_description']; + $translation->post_body = $request['post_body']; + $translation->seo_title = $request['seo_title']; + $translation->meta_desc = $request['meta_desc']; + $translation->slug = $request['slug']; + $translation->use_view_file = $request['use_view_file']; + + $translation->lang_id = $request['lang_id']; + $translation->post_id = $new_blog_post->id; + + $this->processUploadedImages($request, $translation); + $translation->save(); + + $new_blog_post->categories()->sync($request->categories()); + + event(new BlogPostAdded($new_blog_post)); + } + } + + //todo: generate event + + $language_id = $request->get('language_id'); + $language_list = BinshopsLanguage::where('active',true)->get(); + $ts = BinshopsCategoryTranslation::where("lang_id",$language_id)->limit(1000)->get(); + + $translation = BinshopsPostTranslation::where( + [ + ['post_id','=',$request['post_id']], + ['lang_id', '=', $request['selected_lang']] + ] + )->first(); + if (!$translation){ + $translation = new BinshopsPostTranslation(); + } + + return view("binshopsblog_admin::posts.add_post", [ + 'cat_ts' => $ts, + 'language_list' => $language_list, + 'selected_lang' => $request['selected_lang'], + 'post_translation' => $translation, + 'post' => $new_blog_post, + 'post_id' => $new_blog_post->id + ]); + } + + /** + * Show form to edit post + * + * @param $blogPostId + * @return mixed + */ + public function edit_post( $blogPostId , Request $request) + { + $language_id = $request->get('language_id'); + + $post_translation = BinshopsPostTranslation::where( + [ + ['lang_id', '=', $language_id], + ['post_id', '=', $blogPostId] + ] + )->first(); + + $post = BinshopsPost::findOrFail($blogPostId); + $language_list = BinshopsLanguage::where('active',true)->get(); + $ts = BinshopsCategoryTranslation::where("lang_id",$language_id)->limit(1000)->get(); + + return view("binshopsblog_admin::posts.edit_post", [ + 'cat_ts' => $ts, + 'language_list' => $language_list, + 'selected_lang' => $language_id, + 'selected_locale' => BinshopsLanguage::where('id', $language_id)->first()->locale, + 'post' => $post, + 'post_translation' => $post_translation + ]); + } + + /** + * Show form to edit post + * + * @param $blogPostId + * @return mixed + */ + public function edit_post_toggle( $blogPostId , Request $request) + { + $post_translation = BinshopsPostTranslation::where( + [ + ['lang_id', '=', $request['selected_lang']], + ['post_id', '=', $blogPostId] + ] + )->first(); + if (!$post_translation){ + $post_translation = new BinshopsPostTranslation(); + } + + $post = BinshopsPost::findOrFail($blogPostId); + $language_list = BinshopsLanguage::where('active',true)->get(); + $ts = BinshopsCategoryTranslation::where("lang_id", $request['selected_lang'])->limit(1000)->get(); + + return view("binshopsblog_admin::posts.edit_post", [ + 'cat_ts' => $ts, + 'language_list' => $language_list, + 'selected_lang' => $request['selected_lang'], + 'selected_locale' => BinshopsLanguage::where('id', $request['selected_lang'])->first()->locale, + 'post' => $post, + 'post_translation' => $post_translation + ]); + } + + /** + * Save changes to a post + * + * @param UpdateBinshopsBlogPostRequest $request + * @param $blogPostId + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @throws \Exception + */ + public function update_post(UpdateBinshopsBlogPostRequest $request, $blogPostId) + { + $new_blog_post = BinshopsPost::findOrFail($blogPostId); + $translation = BinshopsPostTranslation::where( + [ + ['post_id','=', $new_blog_post->id], + ['lang_id', '=', $request['lang_id']] + ] + )->first(); + + if (!$translation){ + $translation = new BinshopsPostTranslation(); + $new_blog_post->posted_at = Carbon::now(); + } + + $post_exists = $this->check_if_same_post_exists($request['slug'] , $request['lang_id'], $blogPostId); + if ($post_exists){ + Helpers::flash_message("Post already exists - try to change the slug for this language"); + }else { + $new_blog_post->is_published = $request['is_published']; + $new_blog_post->user_id = \Auth::user()->id; + $new_blog_post->save(); + + $translation->title = $request['title']; + $translation->subtitle = $request['subtitle']; + $translation->short_description = $request['short_description']; + $translation->post_body = $request['post_body']; + $translation->seo_title = $request['seo_title']; + $translation->meta_desc = $request['meta_desc']; + $translation->slug = $request['slug']; + $translation->use_view_file = $request['use_view_file']; + + $translation->lang_id = $request['lang_id']; + $translation->post_id = $new_blog_post->id; + + $this->processUploadedImages($request, $translation); + $translation->save(); + + $new_blog_post->categories()->sync($request->categories()); + Helpers::flash_message("Post Updated"); + event(new BlogPostAdded($new_blog_post)); + } + + return redirect( route('binshopsblog.admin.index') ); + } + + public function remove_photo($postSlug, $lang_id) + { + $post = BinshopsPostTranslation::where([ + ["slug", '=', $postSlug], + ['lang_id', '=', $lang_id] + ])->firstOrFail(); + + $path = public_path('/' . config("binshopsblog.blog_upload_dir")); + if (!$this->checked_blog_image_dir_is_writable) { + if (!is_writable($path)) { + throw new \RuntimeException("Image destination path is not writable ($path)"); + } + } + + $destinationPath = $this->image_destination_path(); + + if (file_exists($destinationPath.'/'.$post->image_large)) { + unlink($destinationPath.'/'.$post->image_large); + } + + if (file_exists($destinationPath.'/'.$post->image_medium)) { + unlink($destinationPath.'/'.$post->image_medium); + } + + if (file_exists($destinationPath.'/'.$post->image_thumbnail)) { + unlink($destinationPath.'/'.$post->image_thumbnail); + } + + $post->image_large = null; + $post->image_medium = null; + $post->image_thumbnail = null; + $post->save(); + + Helpers::flash_message("Photo removed"); + + return redirect($post->edit_url()); + } + + /** + * Delete a post + * + * @param DeleteBinshopsBlogPostRequest $request + * @param $blogPostId + * @return mixed + */ + public function destroy_post(DeleteBinshopsBlogPostRequest $request, $blogPostId) + { + $post = BinshopsPost::findOrFail($blogPostId); + //archive deleted post + + $post->delete(); + event(new BlogPostWillBeDeleted($post)); + + // todo - delete the featured images? + // At the moment it just issues a warning saying the images are still on the server. + + Helpers::flash_message("Post successfully deleted!"); + + return redirect( route('binshopsblog.admin.index') ); + } + + /** + * Process any uploaded images (for featured image) + * + * @param BaseRequestInterface $request + * @param $new_blog_post + * @throws \Exception + * @todo - next full release, tidy this up! + */ + protected function processUploadedImages(BaseRequestInterface $request, BinshopsPostTranslation $new_blog_post) + { + if (!config("binshopsblog.image_upload_enabled")) { + // image upload was disabled + return; + } + + $this->increaseMemoryLimit(); + + // to save in db later + $uploaded_image_details = []; + + + foreach ((array)config('binshopsblog.image_sizes') as $size => $image_size_details) { + + if ($image_size_details['enabled'] && $photo = $request->get_image_file($size)) { + // this image size is enabled, and + // we have an uploaded image that we can use + + $uploaded_image = $this->UploadAndResize($new_blog_post, $new_blog_post->slug, $image_size_details, $photo); + + $new_blog_post->$size = $uploaded_image['filename']; + $uploaded_image_details[$size] = $uploaded_image; + } + } + + // store the image upload. + // todo: link this to the binshopsblog_post row. + if (count(array_filter($uploaded_image_details))>0) { + BinshopsUploadedPhoto::create([ + 'source' => "BlogFeaturedImage", + 'uploaded_images' => $uploaded_image_details, + ]); + } + } + + //translations for the same psots are ignored + protected function check_if_same_post_exists($slug, $lang_id, $post_id){ + $slg = BinshopsPostTranslation::where( + [ + ['slug','=', $slug], + ['lang_id', '=', $lang_id], + ['post_id', '<>', $post_id] + ] + )->first(); + if ($slg){ + return true; + }else{ + return false; + } + } + + /** + * Show the search results for $_GET['s'] + * + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @throws \Exception + */ + public function searchBlog(Request $request) + { + if (!config("binshopsblog.search.search_enabled")) { + throw new \Exception("Search is disabled"); + } + $query = $request->get("s"); + $search = new Search(); + $search_results = $search->run($query); + + \View::share("title", "Search results for " . e($query)); + + $rootList = BinshopsCategory::roots()->get(); + BinshopsCategory::loadSiblingsWithList($rootList); + + $language_id = $request->get('language_id'); + + return view("binshopsblog_admin::index", [ + 'search' => true, + 'post_translations'=>$search_results, + 'language_id' => $language_id + ]); + } +} diff --git a/src/Controllers/BinshopsAdminSetupController.php b/src/Controllers/BinshopsAdminSetupController.php new file mode 100644 index 0000000..8612907 --- /dev/null +++ b/src/Controllers/BinshopsAdminSetupController.php @@ -0,0 +1,59 @@ +middleware(UserCanManageBlogPosts::class); + + if (!is_array(config("binshopsblog"))) { + throw new \RuntimeException('The config/binshopsblog.php does not exist. Publish the vendor files for the BinshopsBlog package by running the php artisan publish:vendor command'); + } + } + + /** + * View all posts + * + * @return mixed + */ + public function setup(Request $request) + { + return view("binshopsblog_admin::setup.setup"); + } + + public function setup_submit(Request $request){ + if ($request['locale'] == null){ + return redirect( route('binshopsblog.admin.setup_submit') ); + } + $language = new BinshopsLanguage(); + $language->active = $request['active']; + $language->iso_code = $request['iso_code']; + $language->locale = $request['locale']; + $language->name = $request['name']; + $language->date_format = $request['date_format']; + + $language->save(); + if (!BinshopsConfiguration::get('INITIAL_SETUP')){ + BinshopsConfiguration::set('INITIAL_SETUP', true); + BinshopsConfiguration::set('DEFAULT_LANGUAGE_LOCALE', $request['locale']); + } + + return redirect( route('binshopsblog.admin.index') ); + } +} diff --git a/src/Controllers/BinshopsCategoryAdminController.php b/src/Controllers/BinshopsCategoryAdminController.php new file mode 100755 index 0000000..6fb33c0 --- /dev/null +++ b/src/Controllers/BinshopsCategoryAdminController.php @@ -0,0 +1,210 @@ +middleware(UserCanManageBlogPosts::class); + $this->middleware(LoadLanguage::class); + + } + + /** + * Show list of categories + * + * @return mixed + */ + public function index(Request $request){ + $language_id = $request->get('language_id'); + $categories = BinshopsCategoryTranslation::orderBy("category_id")->where('lang_id', $language_id)->paginate(25); + return view("binshopsblog_admin::categories.index",[ + 'categories' => $categories, + 'language_id' => $language_id + ]); + } + + /** + * Show the form for creating new category + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function create_category(Request $request){ + $language_id = $request->get('language_id'); + $language_list = BinshopsLanguage::where('active',true)->get(); + + $cat_list = BinshopsCategory::whereHas('categoryTranslations', function ($query) use ($language_id) { + return $query->where('lang_id', '=', $language_id); + })->get(); + + $rootList = BinshopsCategory::roots()->get(); + BinshopsCategory::loadSiblingsWithList($rootList); + + + return view("binshopsblog_admin::categories.add_category",[ + 'category' => new \BinshopsBlog\Models\BinshopsCategory(), + 'category_translation' => new \BinshopsBlog\Models\BinshopsCategoryTranslation(), + 'category_tree' => $cat_list, + 'cat_roots' => $rootList, + 'language_id' => $language_id, + 'language_list' => $language_list + ]); + } + + /** + * Store a new category + * + * @param StoreBinshopsBlogCategoryRequest $request + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * + * This controller is totally REST controller + */ + public function store_category(Request $request){ + $language_id = $request->get('language_id'); + $language_list = $request['data']; + + if ($request['parent_id']== 0){ + $request['parent_id'] = null; + } + $new_category = BinshopsCategory::create([ + 'parent_id' => $request['parent_id'] + ]); + + foreach ($language_list as $key => $value) { + if ($value['lang_id'] != -1 && $value['category_name'] !== null){ + //check for slug availability + $obj = BinshopsCategoryTranslation::where('slug',$value['slug'])->first(); + if ($obj){ + BinshopsCategory::destroy($new_category->id); + return response()->json([ + 'code' => 403, + 'message' => "slug is already taken", + 'data' => $value['lang_id'] + ]); + } + $new_category_translation = $new_category->categoryTranslations()->create([ + 'category_name' => $value['category_name'], + 'slug' => $value['slug'], + 'category_description' => $value['category_description'], + 'lang_id' => $value['lang_id'], + 'category_id' => $new_category->id + ]); + } + } + + event(new CategoryAdded($new_category, $new_category_translation)); + Helpers::flash_message("Saved new category"); + return response()->json([ + 'code' => 200, + 'message' => "category successfully aaded" + ]); + } + + /** + * Show the edit form for category + * @param $categoryId + * @return mixed + */ + public function edit_category($categoryId, Request $request){ + $language_id = $request->get('language_id'); + $language_list = BinshopsLanguage::where('active',true)->get(); + + $category = BinshopsCategory::findOrFail($categoryId); + $cat_trans = BinshopsCategoryTranslation::where( + [ + ['lang_id', '=', $language_id], + ['category_id', '=', $categoryId] + ] + )->first(); + + return view("binshopsblog_admin::categories.edit_category",[ + 'category' => $category, + 'category_translation' => $cat_trans, + 'categories_list' => BinshopsCategoryTranslation::orderBy("category_id")->where('lang_id', $language_id)->get(), + 'language_id' => $language_id, + 'language_list' => $language_list + ]); + } + + /** + * Save submitted changes + * + * @param UpdateBinshopsBlogCategoryRequest $request + * @param $categoryId + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + */ + public function update_category(UpdateBinshopsBlogCategoryRequest $request, $categoryId){ + /** @var BinshopsCategory $category */ + $category = BinshopsCategory::findOrFail($categoryId); + $language_id = $request->get('language_id'); + $translation = BinshopsCategoryTranslation::where( + [ + ['lang_id', '=', $language_id], + ['category_id', '=', $categoryId] + ] + )->first(); + $category->fill($request->all()); + $translation->fill($request->all()); + + // if the parent_id is passed in as 0 it will create an error + if ($category->parent_id <= 0) { + $category->parent_id = null; + } + + $category->save(); + $translation->save(); + + Helpers::flash_message("Saved category changes"); + event(new CategoryEdited($category)); + return redirect($translation->edit_url()); + } + + /** + * Delete the category + * + * @param DeleteBinshopsBlogCategoryRequest $request + * @param $categoryId + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function destroy_category(DeleteBinshopsBlogCategoryRequest $request, $categoryId){ + + /* Please keep this in, so code inspectiwons don't say $request was unused. Of course it might now get marked as left/right parts are equal */ + $request=$request; + + $category = BinshopsCategory::findOrFail($categoryId); + $children = $category->children()->get(); + if (sizeof($children) > 0) { + Helpers::flash_message("This category could not be deleted it has some sub-categories. First try to change parent category of subs."); + return redirect(route('binshopsblog.admin.categories.index')); + } + + event(new CategoryWillBeDeleted($category)); + $category->delete(); + + Helpers::flash_message("Category successfully deleted!"); + return redirect( route('binshopsblog.admin.categories.index') ); + } + +} diff --git a/src/Controllers/BinshopsCommentWriterController.php b/src/Controllers/BinshopsCommentWriterController.php new file mode 100755 index 0000000..5cf3fad --- /dev/null +++ b/src/Controllers/BinshopsCommentWriterController.php @@ -0,0 +1,100 @@ +middleware(UserCanManageBlogPosts::class); + $this->middleware(LoadLanguage::class); + + } + + /** + * Let a guest (or logged in user) submit a new comment for a blog post + * + * @param AddNewCommentRequest $request + * @param $blog_post_slug + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @throws \Exception + */ + public function addNewComment(AddNewCommentRequest $request, $locale, $blog_post_slug) + { + + if (config("binshopsblog.comments.type_of_comments_to_show", "built_in") !== 'built_in') { + throw new \RuntimeException("Built in comments are disabled"); + } + + $post_translation = BinshopsPostTranslation::where("slug", $blog_post_slug) + ->with('post') + ->firstOrFail(); + $blog_post = $post_translation->post; + + /** @var CaptchaAbstract $captcha */ + $captcha = $this->getCaptchaObject(); + if ($captcha) { + $captcha->runCaptchaBeforeAddingComment($request, $blog_post); + } + + $new_comment = $this->createNewComment($request, $blog_post); + + return view("binshopsblog::saved_comment", [ + 'captcha' => $captcha, + 'blog_post' => $post_translation, + 'new_comment' => $new_comment + ]); + + } + + /** + * @param AddNewCommentRequest $request + * @param $blog_post + * @return BinshopsComment + */ + protected function createNewComment(AddNewCommentRequest $request, $blog_post) + { + $new_comment = new BinshopsComment($request->all()); + + if (config("binshopsblog.comments.save_ip_address")) { + $new_comment->ip = $request->ip(); + } + if (config("binshopsblog.comments.ask_for_author_website")) { + $new_comment->author_website = $request->get('author_website'); + } + if (config("binshopsblog.comments.ask_for_author_email")) { + $new_comment->author_email = $request->get('author_email'); + } + if (config("binshopsblog.comments.save_user_id_if_logged_in", true) && Auth::check()) { + $new_comment->user_id = Auth::user()->id; + } + + $new_comment->approved = config("binshopsblog.comments.auto_approve_comments", true) ? true : false; + + $blog_post->comments()->save($new_comment); + + event(new CommentAdded($blog_post, $new_comment)); + + return $new_comment; + } + +} diff --git a/src/Controllers/BlogEtcCommentsAdminController.php b/src/Controllers/BinshopsCommentsAdminController.php similarity index 61% rename from src/Controllers/BlogEtcCommentsAdminController.php rename to src/Controllers/BinshopsCommentsAdminController.php index 3557aed..6574900 100755 --- a/src/Controllers/BlogEtcCommentsAdminController.php +++ b/src/Controllers/BinshopsCommentsAdminController.php @@ -1,27 +1,30 @@ middleware(UserCanManageBlogPosts::class); + $this->middleware(LoadLanguage::class); + } /** @@ -32,7 +35,7 @@ public function __construct() */ public function index(Request $request) { - $comments = BlogEtcComment::withoutGlobalScopes()->orderBy("created_at", "desc") + $comments = BinshopsComment::withoutGlobalScopes()->orderBy("created_at", "desc") ->with("post"); if ($request->get("waiting_for_approval")) { @@ -40,7 +43,7 @@ public function index(Request $request) } $comments = $comments->paginate(100); - return view("blogetc_admin::comments.index") + return view("binshopsblog_admin::comments.index") ->withComments($comments ); } @@ -54,7 +57,7 @@ public function index(Request $request) */ public function approve($blogCommentId) { - $comment = BlogEtcComment::withoutGlobalScopes()->findOrFail($blogCommentId); + $comment = BinshopsComment::withoutGlobalScopes()->findOrFail($blogCommentId); $comment->approved = true; $comment->save(); @@ -73,7 +76,7 @@ public function approve($blogCommentId) */ public function destroy($blogCommentId) { - $comment = BlogEtcComment::withoutGlobalScopes()->findOrFail($blogCommentId); + $comment = BinshopsComment::withoutGlobalScopes()->findOrFail($blogCommentId); event(new CommentWillBeDeleted($comment)); $comment->delete(); diff --git a/src/Controllers/BlogEtcImageUploadController.php b/src/Controllers/BinshopsImageUploadController.php similarity index 59% rename from src/Controllers/BlogEtcImageUploadController.php rename to src/Controllers/BinshopsImageUploadController.php index de80e75..eaa4b2d 100755 --- a/src/Controllers/BlogEtcImageUploadController.php +++ b/src/Controllers/BinshopsImageUploadController.php @@ -1,38 +1,40 @@ middleware(UserCanManageBlogPosts::class); + $this->middleware(LoadLanguage::class); - if (!is_array(config("blogetc"))) { - throw new \RuntimeException('The config/blogetc.php does not exist. Publish the vendor files for the BlogEtc package by running the php artisan publish:vendor command'); + if (!is_array(config("binshopsblog"))) { + throw new \RuntimeException('The config/binshopsblog.php does not exist. Publish the vendor files for the BinshopsBlog package by running the php artisan publish:vendor command'); } - if (!config("blogetc.image_upload_enabled")) { - throw new \RuntimeException("The blogetc.php config option has not enabled image uploading"); + if (!config("binshopsblog.image_upload_enabled")) { + throw new \RuntimeException("The binshopsblog.php config option has not enabled image uploading"); } @@ -46,7 +48,7 @@ public function __construct() public function index() { - return view("blogetc_admin::imageupload.index", ['uploaded_photos' => BlogEtcUploadedPhoto::orderBy("id", "desc")->paginate(10)]); + return view("binshopsblog_admin::imageupload.index", ['uploaded_photos' => BinshopsUploadedPhoto::orderBy("id", "desc")->paginate(10)]); } /** @@ -56,7 +58,7 @@ public function index() */ public function create() { - return view("blogetc_admin::imageupload.create", []); + return view("binshopsblog_admin::imageupload.create", []); } /** @@ -70,7 +72,7 @@ public function store(UploadImageRequest $request) { $processed_images = $this->processUploadedImages($request); - return view("blogetc_admin::imageupload.uploaded", ['images' => $processed_images]); + return view("binshopsblog_admin::imageupload.uploaded", ['images' => $processed_images]); } /** @@ -80,7 +82,7 @@ public function store(UploadImageRequest $request) * * @return array returns an array of details about each file resized. * @throws \Exception - * @todo - This class was added after the other main features, so this duplicates some code from the main blog post admin controller (BlogEtcAdminController). For next full release this should be tided up. + * @todo - This class was added after the other main features, so this duplicates some code from the main blog post admin controller (BinshopsAdminController). For next full release this should be tided up. */ protected function processUploadedImages(UploadImageRequest $request) { @@ -93,13 +95,13 @@ protected function processUploadedImages(UploadImageRequest $request) $sizes_to_upload = $request->get("sizes_to_upload"); // now upload a full size - this is a special case, not in the config file. We only store full size images in this class, not as part of the featured blog image uploads. - if (isset($sizes_to_upload['blogetc_full_size']) && $sizes_to_upload['blogetc_full_size'] === 'true') { + if (isset($sizes_to_upload['binshopsblog_full_size']) && $sizes_to_upload['binshopsblog_full_size'] === 'true') { - $uploaded_image_details['blogetc_full_size'] = $this->UploadAndResize(null, $request->get("image_title"), 'fullsize', $photo); + $uploaded_image_details['binshopsblog_full_size'] = $this->UploadAndResize(null, $request->get("image_title"), 'fullsize', $photo); } - foreach ((array)config('blogetc.image_sizes') as $size => $image_size_details) { + foreach ((array)config('binshopsblog.image_sizes') as $size => $image_size_details) { if (!isset($sizes_to_upload[$size]) || !$sizes_to_upload[$size] || !$image_size_details['enabled']) { continue; @@ -112,7 +114,7 @@ protected function processUploadedImages(UploadImageRequest $request) // store the image upload. - BlogEtcUploadedPhoto::create([ + BinshopsUploadedPhoto::create([ 'image_title' => $request->get("image_title"), 'source' => "ImageUpload", 'uploader_id' => optional(\Auth::user())->id, diff --git a/src/Controllers/BinshopsLanguageAdminController.php b/src/Controllers/BinshopsLanguageAdminController.php new file mode 100644 index 0000000..6f6addc --- /dev/null +++ b/src/Controllers/BinshopsLanguageAdminController.php @@ -0,0 +1,91 @@ +middleware(UserCanManageBlogPosts::class); + $this->middleware(LoadLanguage::class); + + } + + public function index(){ + $language_list = BinshopsLanguage::all(); + return view("binshopsblog_admin::languages.index",[ + 'language_list' => $language_list + ]); + } + + public function create_language(){ + return view("binshopsblog_admin::languages.add_language"); + } + + public function store_language(Request $request){ + if ($request['locale'] == null){ + Helpers::flash_message("Select a language!"); + return view("binshopsblog_admin::languages.add_language"); + } + $language = new BinshopsLanguage(); + $language->active = $request['active']; + $language->iso_code = $request['iso_code']; + $language->locale = $request['locale']; + $language->name = $request['name']; + $language->date_format = $request['date_format']; + $language->rtl = $request['rtl']; + + $language->save(); + + Helpers::flash_message("Language: " . $language->name . " has been added."); + return redirect( route('binshopsblog.admin.languages.index') ); + } + + public function destroy_language(Request $request, $languageId){ + $lang = BinshopsLanguage::where('locale', BinshopsConfiguration::get('DEFAULT_LANGUAGE_LOCALE'))->first(); + if ($languageId == $lang->id){ + Helpers::flash_message("The default language can not be deleted!"); + return redirect( route('binshopsblog.admin.languages.index') ); + } + + try { + $language = BinshopsLanguage::findOrFail($languageId); + //todo +// event(new CategoryWillBeDeleted($category)); + $language->delete(); + Helpers::flash_message("The language is successfully deleted!"); + return redirect( route('binshopsblog.admin.languages.index') ); + } catch (\Illuminate\Database\QueryException $e) { + Helpers::flash_message("You can not delete this language, because it's used in posts or categoies."); + return redirect( route('binshopsblog.admin.languages.index') ); + } + } + + public function toggle_language(Request $request, $languageId){ + $language = BinshopsLanguage::findOrFail($languageId); + if ($language->active == 1){ + $language->active = 0; + }else if ($language->active == 0){ + $language->active = 1; + } + + $language->save(); + //todo + //event + + Helpers::flash_message("Language: " . $language->name . " has been disabled."); + return redirect( route('binshopsblog.admin.languages.index') ); + } +} diff --git a/src/Controllers/BinshopsReaderController.php b/src/Controllers/BinshopsReaderController.php new file mode 100755 index 0000000..3386ca2 --- /dev/null +++ b/src/Controllers/BinshopsReaderController.php @@ -0,0 +1,176 @@ +middleware(DetectLanguage::class); + } + + /** + * Show blog posts + * If category_slug is set, then only show from that category + * + * @param null $category_slug + * @return mixed + */ + public function index($locale = null, Request $request, $category_slug = null) + { + // the published_at + is_published are handled by BinshopsBlogPublishedScope, and don't take effect if the logged in user can manageb log posts + + //todo + $title = 'Blog Page'; // default title... + + $categoryChain = null; + $posts = array(); + if ($category_slug) { + $category = BinshopsCategoryTranslation::where("slug", $category_slug)->with('category')->firstOrFail()->category; + $categoryChain = $category->getAncestorsAndSelf(); + $posts = $category->posts()->where("binshops_post_categories.category_id", $category->id)->with([ 'postTranslations' => function($query) use ($request){ + $query->where("lang_id" , '=' , $request->get("lang_id")); + } + ])->get(); + + $posts = BinshopsPostTranslation::join('binshops_posts', 'binshops_post_translations.post_id', '=', 'binshops_posts.id') + ->where('lang_id', $request->get("lang_id")) + ->where("is_published" , '=' , true) + ->where('posted_at', '<', Carbon::now()->format('Y-m-d H:i:s')) + ->orderBy("posted_at", "desc") + ->whereIn('binshops_posts.id', $posts->pluck('id')) + ->paginate(config("binshopsblog.per_page", 10)); + + // at the moment we handle this special case (viewing a category) by hard coding in the following two lines. + // You can easily override this in the view files. + \View::share('binshopsblog_category', $category); // so the view can say "You are viewing $CATEGORYNAME category posts" + $title = 'Posts in ' . $category->category_name . " category"; // hardcode title here... + } else { + $posts = BinshopsPostTranslation::join('binshops_posts', 'binshops_post_translations.post_id', '=', 'binshops_posts.id') + ->where('lang_id', $request->get("lang_id")) + ->where("is_published" , '=' , true) + ->where('posted_at', '<', Carbon::now()->format('Y-m-d H:i:s')) + ->orderBy("posted_at", "desc") + ->paginate(config("binshopsblog.per_page", 10)); + } + + //load category hierarchy + $rootList = BinshopsCategory::roots()->get(); + BinshopsCategory::loadSiblingsWithList($rootList); + + return view("binshopsblog::index", [ + 'lang_list' => BinshopsLanguage::all('locale','name'), + 'locale' => $request->get("locale"), + 'lang_id' => $request->get('lang_id'), + 'category_chain' => $categoryChain, + 'categories' => $rootList, + 'posts' => $posts, + 'title' => $title, + 'routeWithoutLocale' => $request->get("routeWithoutLocale") + ]); + } + + /** + * Show the search results for $_GET['s'] + * + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @throws \Exception + */ + public function search(Request $request) + { + if (!config("binshopsblog.search.search_enabled")) { + throw new \Exception("Search is disabled"); + } + $query = $request->get("s"); + $search = new Search(); + $search_results = $search->run($query); + + \View::share("title", "Search results for " . e($query)); + + $rootList = BinshopsCategory::roots()->get(); + BinshopsCategory::loadSiblingsWithList($rootList); + + return view("binshopsblog::search", [ + 'lang_id' => $request->get('lang_id'), + 'locale' => $request->get("locale"), + 'categories' => $rootList, + 'query' => $query, + 'search_results' => $search_results, + 'routeWithoutLocale' => $request->get("routeWithoutLocale") + ] + ); + } + + /** + * View all posts in $category_slug category + * + * @param Request $request + * @param $category_slug + * @return mixed + */ + public function view_category(Request $request) + { + $hierarchy = $request->route('subcategories'); + + $categories = explode('/', $hierarchy); + return $this->index($request->get('locale'), $request, end($categories)); + } + + /** + * View a single post and (if enabled) it's comments + * + * @param Request $request + * @param $blogPostSlug + * @return mixed + */ + public function viewSinglePost(Request $request) + { + $blogPostSlug = $request->route('blogPostSlug'); + + // the published_at + is_published are handled by BinshopsBlogPublishedScope, and don't take effect if the logged in user can manage log posts + $blog_post = BinshopsPostTranslation::where([ + ["slug", "=", $blogPostSlug], + ['lang_id', "=" , $request->get("lang_id")] + ])->firstOrFail(); + + if ($captcha = $this->getCaptchaObject()) { + $captcha->runCaptchaBeforeShowingPosts($request, $blog_post); + } + + $categories = $blog_post->post->categories()->with([ 'categoryTranslations' => function($query) use ($request){ + $query->where("lang_id" , '=' , $request->get("lang_id")); + } + ])->get(); + return view("binshopsblog::single_post", [ + 'post' => $blog_post, + // the default scope only selects approved comments, ordered by id + 'comments' => $blog_post->post->comments() + ->with("user") + ->get(), + 'captcha' => $captcha, + 'categories' => $categories, + 'locale' => $request->get("locale"), + 'routeWithoutLocale' => $request->get("routeWithoutLocale") + ]); + } +} diff --git a/src/Controllers/BlogEtcAdminController.php b/src/Controllers/BlogEtcAdminController.php deleted file mode 100755 index 9f93a30..0000000 --- a/src/Controllers/BlogEtcAdminController.php +++ /dev/null @@ -1,230 +0,0 @@ -middleware(UserCanManageBlogPosts::class); - - if (!is_array(config("blogetc"))) { - throw new \RuntimeException('The config/blogetc.php does not exist. Publish the vendor files for the BlogEtc package by running the php artisan publish:vendor command'); - } - } - - - /** - * View all posts - * - * @return mixed - */ - public function index() - { - $posts = BlogEtcPost::orderBy("posted_at", "desc") - ->paginate(10); - - return view("blogetc_admin::index", ['posts'=>$posts]); - } - - /** - * Show form for creating new post - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - */ - public function create_post() - { - return view("blogetc_admin::posts.add_post"); - } - - /** - * Save a new post - * - * @param CreateBlogEtcPostRequest $request - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector - * @throws \Exception - */ - public function store_post(CreateBlogEtcPostRequest $request) - { - $new_blog_post = new BlogEtcPost($request->all()); - - $this->processUploadedImages($request, $new_blog_post); - - if (!$new_blog_post->posted_at) { - $new_blog_post->posted_at = Carbon::now(); - } - - $new_blog_post->user_id = \Auth::user()->id; - $new_blog_post->save(); - - $new_blog_post->categories()->sync($request->categories()); - - Helpers::flash_message("Added post"); - event(new BlogPostAdded($new_blog_post)); - return redirect($new_blog_post->edit_url()); - } - - /** - * Show form to edit post - * - * @param $blogPostId - * @return mixed - */ - public function edit_post( $blogPostId) - { - $post = BlogEtcPost::findOrFail($blogPostId); - return view("blogetc_admin::posts.edit_post")->withPost($post); - } - - /** - * Save changes to a post - * - * @param UpdateBlogEtcPostRequest $request - * @param $blogPostId - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector - * @throws \Exception - */ - public function update_post(UpdateBlogEtcPostRequest $request, $blogPostId) - { - /** @var BlogEtcPost $post */ - $post = BlogEtcPost::findOrFail($blogPostId); - $post->fill($request->all()); - - $this->processUploadedImages($request, $post); - - $post->save(); - $post->categories()->sync($request->categories()); - - Helpers::flash_message("Updated post"); - event(new BlogPostEdited($post)); - - return redirect($post->edit_url()); - - } - - public function remove_photo($postSlug) - { - $post = BlogEtcPost::where("slug", $postSlug)->firstOrFail(); - - $path = public_path('/' . config("blogetc.blog_upload_dir")); - if (!$this->checked_blog_image_dir_is_writable) { - if (!is_writable($path)) { - throw new \RuntimeException("Image destination path is not writable ($path)"); - } - } - - $destinationPath = $this->image_destination_path(); - - if (file_exists($destinationPath.'/'.$post->image_large)) { - unlink($destinationPath.'/'.$post->image_large); - } - - if (file_exists($destinationPath.'/'.$post->image_medium)) { - unlink($destinationPath.'/'.$post->image_medium); - } - - if (file_exists($destinationPath.'/'.$post->image_thumbnail)) { - unlink($destinationPath.'/'.$post->image_thumbnail); - } - - $post->image_large = null; - $post->image_medium = null; - $post->image_thumbnail = null; - $post->save(); - - Helpers::flash_message("Photo removed"); - - return redirect($post->edit_url()); - } - - /** - * Delete a post - * - * @param DeleteBlogEtcPostRequest $request - * @param $blogPostId - * @return mixed - */ - public function destroy_post(DeleteBlogEtcPostRequest $request, $blogPostId) - { - - $post = BlogEtcPost::findOrFail($blogPostId); - event(new BlogPostWillBeDeleted($post)); - - $post->delete(); - - // todo - delete the featured images? - // At the moment it just issues a warning saying the images are still on the server. - - return view("blogetc_admin::posts.deleted_post") - ->withDeletedPost($post); - - } - - /** - * Process any uploaded images (for featured image) - * - * @param BaseRequestInterface $request - * @param $new_blog_post - * @throws \Exception - * @todo - next full release, tidy this up! - */ - protected function processUploadedImages(BaseRequestInterface $request, BlogEtcPost $new_blog_post) - { - if (!config("blogetc.image_upload_enabled")) { - // image upload was disabled - return; - } - - $this->increaseMemoryLimit(); - - // to save in db later - $uploaded_image_details = []; - - - foreach ((array)config('blogetc.image_sizes') as $size => $image_size_details) { - - if ($image_size_details['enabled'] && $photo = $request->get_image_file($size)) { - // this image size is enabled, and - // we have an uploaded image that we can use - - $uploaded_image = $this->UploadAndResize($new_blog_post, $new_blog_post->slug, $image_size_details, $photo); - - $new_blog_post->$size = $uploaded_image['filename']; - $uploaded_image_details[$size] = $uploaded_image; - } - } - - // store the image upload. - // todo: link this to the blogetc_post row. - if (count(array_filter($uploaded_image_details))>0) { - BlogEtcUploadedPhoto::create([ - 'source' => "BlogFeaturedImage", - 'uploaded_images' => $uploaded_image_details, - ]); - } - } -} diff --git a/src/Controllers/BlogEtcCategoryAdminController.php b/src/Controllers/BlogEtcCategoryAdminController.php deleted file mode 100755 index 827222c..0000000 --- a/src/Controllers/BlogEtcCategoryAdminController.php +++ /dev/null @@ -1,122 +0,0 @@ -middleware(UserCanManageBlogPosts::class); - } - - /** - * Show list of categories - * - * @return mixed - */ - public function index(){ - - $categories = BlogEtcCategory::orderBy("category_name")->paginate(25); - return view("blogetc_admin::categories.index")->withCategories($categories); - } - - /** - * Show the form for creating new category - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - */ - public function create_category(){ - - return view("blogetc_admin::categories.add_category",[ - 'category' => new \WebDevEtc\BlogEtc\Models\BlogEtcCategory(), - 'categories_list' => BlogEtcCategory::orderBy("category_name")->get() - ]); - - } - - /** - * Store a new category - * - * @param StoreBlogEtcCategoryRequest $request - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector - */ - public function store_category(StoreBlogEtcCategoryRequest $request){ - if ($request['parent_id']== 0){ - $request['parent_id'] = null; - } - $new_category = BlogEtcCategory::create($request->all()); - - Helpers::flash_message("Saved new category"); - - event(new CategoryAdded($new_category)); - return redirect( route('blogetc.admin.categories.index') ); - } - - /** - * Show the edit form for category - * @param $categoryId - * @return mixed - */ - public function edit_category($categoryId){ - $category = BlogEtcCategory::findOrFail($categoryId); - return view("blogetc_admin::categories.edit_category",[ - 'categories_list' => BlogEtcCategory::orderBy("category_name")->get() - ])->withCategory($category); - } - - /** - * Save submitted changes - * - * @param UpdateBlogEtcCategoryRequest $request - * @param $categoryId - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector - */ - public function update_category(UpdateBlogEtcCategoryRequest $request, $categoryId){ - /** @var BlogEtcCategory $category */ - $category = BlogEtcCategory::findOrFail($categoryId); - $category->fill($request->all()); - $category->save(); - - Helpers::flash_message("Saved category changes"); - event(new CategoryEdited($category)); - return redirect($category->edit_url()); - } - - /** - * Delete the category - * - * @param DeleteBlogEtcCategoryRequest $request - * @param $categoryId - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - */ - public function destroy_category(DeleteBlogEtcCategoryRequest $request, $categoryId){ - - /* Please keep this in, so code inspections don't say $request was unused. Of course it might now get marked as left/right parts are equal */ - $request=$request; - - $category = BlogEtcCategory::findOrFail($categoryId); - event(new CategoryWillBeDeleted($category)); - $category->delete(); - - return view ("blogetc_admin::categories.deleted_category"); - - } - -} diff --git a/src/Controllers/BlogEtcCommentWriterController.php b/src/Controllers/BlogEtcCommentWriterController.php deleted file mode 100755 index d033439..0000000 --- a/src/Controllers/BlogEtcCommentWriterController.php +++ /dev/null @@ -1,88 +0,0 @@ -firstOrFail(); - - /** @var CaptchaAbstract $captcha */ - $captcha = $this->getCaptchaObject(); - if ($captcha) { - $captcha->runCaptchaBeforeAddingComment($request, $blog_post); - } - - $new_comment = $this->createNewComment($request, $blog_post); - - return view("blogetc::saved_comment", [ - 'captcha' => $captcha, - 'blog_post' => $blog_post, - 'new_comment' => $new_comment - ]); - - } - - /** - * @param AddNewCommentRequest $request - * @param $blog_post - * @return BlogEtcComment - */ - protected function createNewComment(AddNewCommentRequest $request, $blog_post) - { - $new_comment = new BlogEtcComment($request->all()); - - if (config("blogetc.comments.save_ip_address")) { - $new_comment->ip = $request->ip(); - } - if (config("blogetc.comments.ask_for_author_website")) { - $new_comment->author_website = $request->get('author_website'); - } - if (config("blogetc.comments.ask_for_author_website")) { - $new_comment->author_email = $request->get('author_email'); - } - if (config("blogetc.comments.save_user_id_if_logged_in", true) && Auth::check()) { - $new_comment->user_id = Auth::user()->id; - } - - $new_comment->approved = config("blogetc.comments.auto_approve_comments", true) ? true : false; - - $blog_post->comments()->save($new_comment); - - event(new CommentAdded($blog_post, $new_comment)); - - return $new_comment; - } - -} diff --git a/src/Controllers/BlogEtcReaderController.php b/src/Controllers/BlogEtcReaderController.php deleted file mode 100755 index 242a437..0000000 --- a/src/Controllers/BlogEtcReaderController.php +++ /dev/null @@ -1,135 +0,0 @@ -firstOrFail(); - $categoryChain = $category->getAncestorsAndSelf(); - $posts = $category->posts()->where("blog_etc_post_categories.blog_etc_category_id", $category->id); - - // at the moment we handle this special case (viewing a category) by hard coding in the following two lines. - // You can easily override this in the view files. - \View::share('blogetc_category', $category); // so the view can say "You are viewing $CATEGORYNAME category posts" - $title = 'Posts in ' . $category->category_name . " category"; // hardcode title here... - } else { - $posts = BlogEtcPost::query(); - } - - $posts = $posts->where('is_published', '=', 1)->where('posted_at', '<', Carbon::now()->format('Y-m-d H:i:s'))->orderBy("posted_at", "desc")->paginate(config("blogetc.per_page", 10)); - - //load categories in 3 levels - $rootList = BlogEtcCategory::where('parent_id' ,'=' , null)->get(); - for($i = 0 ; sizeof($rootList) > $i ; $i++){ - $rootList[$i]->loadSiblings(); - for ($j = 0 ; sizeof($rootList[$i]->siblings) > $j; $j++){ - $rootList[$i]->siblings[$j]->loadSiblings(); - } - } - - return view("blogetc::index", [ - 'category_chain' => $categoryChain, - 'categories' => $rootList, - 'posts' => $posts, - 'title' => $title, - ]); - } - - /** - * Show the search results for $_GET['s'] - * - * @param Request $request - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - * @throws \Exception - */ - public function search(Request $request) - { - if (!config("blogetc.search.search_enabled")) { - throw new \Exception("Search is disabled"); - } - $query = $request->get("s"); - $search = new Search(); - $search_results = $search->run($query); - - \View::share("title", "Search results for " . e($query)); - - $categories = BlogEtcCategory::all(); - - return view("blogetc::search", [ - 'categories' => $categories, - 'query' => $query, - 'search_results' => $search_results] - ); - - } - - /** - * View all posts in $category_slug category - * - * @param Request $request - * @param $category_slug - * @return mixed - */ - public function view_category($hierarchy) - { - $categories = explode('/', $hierarchy); - return $this->index(end($categories)); - } - - /** - * View a single post and (if enabled) it's comments - * - * @param Request $request - * @param $blogPostSlug - * @return mixed - */ - public function viewSinglePost(Request $request, $blogPostSlug) - { - // the published_at + is_published are handled by BlogEtcPublishedScope, and don't take effect if the logged in user can manage log posts - $blog_post = BlogEtcPost::where("slug", $blogPostSlug) - ->firstOrFail(); - - if ($captcha = $this->getCaptchaObject()) { - $captcha->runCaptchaBeforeShowingPosts($request, $blog_post); - } - - return view("blogetc::single_post", [ - 'post' => $blog_post, - // the default scope only selects approved comments, ordered by id - 'comments' => $blog_post->comments() - ->with("user") - ->get(), - 'captcha' => $captcha, - ]); - } - -} diff --git a/src/Controllers/BlogEtcRssFeedController.php b/src/Controllers/BlogEtcRssFeedController.php deleted file mode 100755 index 2b0ada9..0000000 --- a/src/Controllers/BlogEtcRssFeedController.php +++ /dev/null @@ -1,88 +0,0 @@ -title = config("app.name") . ' Blog'; - $feed->description = config("blogetc.rssfeed.description", "Our blog RSS feed"); - $feed->link = route('blogetc.index'); - $feed->setDateFormat('carbon'); - $feed->pubdate = isset($posts[0]) ? $posts[0]->posted_at : Carbon::now()->subYear(10); - $feed->lang = config("blogetc.rssfeed.language", "en"); - $feed->setShortening(config("blogetc.rssfeed.should_shorten_text", true)); // true or false - $feed->setTextLimit(config("blogetc.rssfeed.text_limit", 100)); - } - - - /** - * @param $feed - */ - protected function makeFreshFeed(Feed $feed) - { - $posts = BlogEtcPost::orderBy("posted_at", "desc") - ->limit(config("blogetc.rssfeed.posts_to_show_in_rss_feed", 10)) - ->with("author") - ->get(); - - $this->setupFeed($feed, $posts); - - /** @var BlogEtcPost $post */ - foreach ($posts as $post) { - $feed->add($post->title, - $post->author_string(), - $post->url(), - $post->posted_at, - $post->short_description, - $post->generate_introduction() - ); - } - } - - /** - * RSS Feed - * This is a long (but quite simple) method to show an RSS feed - * It makes use of Laravelium\Feed\Feed. - * - * @param FeedRequest $request - * @param Feed $feed - * @return mixed - */ - public function feed(FeedRequest $request, Feed $feed) - { - - // if a logged in user views the RSS feed it will get cached, and if they are an admin user then it'll show all posts (even if it is not set as published) - $user_or_guest = \Auth::check() ? \Auth::user()->id : 'guest'; - - $feed->setCache( - config("blogetc.rssfeed.cache_in_minutes", 60), - "blogetc-" . $request->getFeedType() . $user_or_guest - ); - - if (!$feed->isCached()) { - $this->makeFreshFeed($feed); - } - - return $feed->render($request->getFeedType()); - } - - -} diff --git a/src/Events/BlogPostAdded.php b/src/Events/BlogPostAdded.php index d0bfb21..4aef3b5 100644 --- a/src/Events/BlogPostAdded.php +++ b/src/Events/BlogPostAdded.php @@ -1,30 +1,30 @@ blogEtcPost=$blogEtcPost; + $this->binshopsBlogPost=$binshopsBlogPost; } } diff --git a/src/Events/BlogPostEdited.php b/src/Events/BlogPostEdited.php index 3bade22..94d4b13 100644 --- a/src/Events/BlogPostEdited.php +++ b/src/Events/BlogPostEdited.php @@ -1,30 +1,30 @@ blogEtcPost=$blogEtcPost; + $this->binshopsBlogPost=$binshopsBlogPost; } } diff --git a/src/Events/BlogPostWillBeDeleted.php b/src/Events/BlogPostWillBeDeleted.php index 3e1f332..07c473e 100644 --- a/src/Events/BlogPostWillBeDeleted.php +++ b/src/Events/BlogPostWillBeDeleted.php @@ -1,30 +1,30 @@ blogEtcPost=$blogEtcPost; + $this->binshopsBlogPost=$binshopsBlogPost; } } diff --git a/src/Events/CategoryAdded.php b/src/Events/CategoryAdded.php index 825339e..a090f31 100644 --- a/src/Events/CategoryAdded.php +++ b/src/Events/CategoryAdded.php @@ -1,30 +1,33 @@ blogEtcCategory=$blogEtcCategory; + $this->binshopsCategory=$binshopsCategory; + $this->binshopsCategoryTranslation = $binshopsCategoryTranslation; } } diff --git a/src/Events/CategoryEdited.php b/src/Events/CategoryEdited.php index 9fe3ef6..f8cbf19 100644 --- a/src/Events/CategoryEdited.php +++ b/src/Events/CategoryEdited.php @@ -1,30 +1,30 @@ blogEtcCategory=$blogEtcCategory; + $this->binshopsBlogCategory=$binshopsBlogCategory; } } diff --git a/src/Events/CategoryWillBeDeleted.php b/src/Events/CategoryWillBeDeleted.php index 980d233..f831fa7 100644 --- a/src/Events/CategoryWillBeDeleted.php +++ b/src/Events/CategoryWillBeDeleted.php @@ -1,30 +1,30 @@ blogEtcCategory=$blogEtcCategory; + $this->binshopsBlogCategory=$binshopsBlogCategory; } } diff --git a/src/Events/CommentAdded.php b/src/Events/CommentAdded.php index dcb383c..e0332f3 100644 --- a/src/Events/CommentAdded.php +++ b/src/Events/CommentAdded.php @@ -1,34 +1,34 @@ blogEtcPost=$blogEtcPost; + $this->binshopsBlogPost=$binshopsBlogPost; $this->newComment=$newComment; } diff --git a/src/Events/CommentApproved.php b/src/Events/CommentApproved.php index 43c9351..8c4555e 100644 --- a/src/Events/CommentApproved.php +++ b/src/Events/CommentApproved.php @@ -1,28 +1,28 @@ comment=$comment; // you can get the blog post via $comment->post diff --git a/src/Events/CommentWillBeDeleted.php b/src/Events/CommentWillBeDeleted.php index 7947eb5..25ba513 100644 --- a/src/Events/CommentWillBeDeleted.php +++ b/src/Events/CommentWillBeDeleted.php @@ -1,28 +1,28 @@ comment=$comment; } diff --git a/src/Events/UploadedImage.php b/src/Events/UploadedImage.php index 1feb61d..cb3ac03 100644 --- a/src/Events/UploadedImage.php +++ b/src/Events/UploadedImage.php @@ -1,22 +1,23 @@ image_filename = $image_filename; - $this->blogEtcPost=$blogEtcPost; + $this->binshopsBlogPost=$binshopsBlogPost; $this->image=$image; $this->source=$source; } diff --git a/src/FulltextSearch/src/Commands/Index.php b/src/FulltextSearch/src/Commands/Index.php new file mode 100644 index 0000000..def85d8 --- /dev/null +++ b/src/FulltextSearch/src/Commands/Index.php @@ -0,0 +1,29 @@ +indexAllByClass($this->argument('model_class')); + } +} diff --git a/src/FulltextSearch/src/Commands/IndexOne.php b/src/FulltextSearch/src/Commands/IndexOne.php new file mode 100644 index 0000000..564bbe6 --- /dev/null +++ b/src/FulltextSearch/src/Commands/IndexOne.php @@ -0,0 +1,29 @@ +indexOneByClass($this->argument('model_class'), $this->argument('id')); + } +} diff --git a/src/FulltextSearch/src/Commands/UnindexOne.php b/src/FulltextSearch/src/Commands/UnindexOne.php new file mode 100644 index 0000000..a8b69fe --- /dev/null +++ b/src/FulltextSearch/src/Commands/UnindexOne.php @@ -0,0 +1,29 @@ +unIndexOneByClass($this->argument('model_class'), $this->argument('id')); + } +} diff --git a/src/FulltextSearch/src/Indexable.php b/src/FulltextSearch/src/Indexable.php new file mode 100644 index 0000000..438a451 --- /dev/null +++ b/src/FulltextSearch/src/Indexable.php @@ -0,0 +1,95 @@ +getIndexDataFromColumns($this->indexContentColumns); + } + + public function getIndexTitle() + { + return $this->getIndexDataFromColumns($this->indexTitleColumns); + } + + public function indexedRecord() + { + return $this->morphOne(IndexedRecord::class, 'indexable'); + } + + public function indexRecord() + { + if (null === $this->indexedRecord) { + $this->indexedRecord = new IndexedRecord(); + $this->indexedRecord->indexable()->associate($this); + } + $this->indexedRecord->updateIndex(); + } + + public function unIndexRecord() + { + if (null !== $this->indexedRecord) { + $this->indexedRecord->delete(); + } + } + + protected function getIndexDataFromColumns($columns) + { + $indexData = []; + foreach ($columns as $column) { + if ($this->indexDataIsRelation($column)) { + $indexData[] = $this->getIndexValueFromRelation($column); + } else { + $indexData[] = trim($this->{$column}); + } + } + + return implode(' ', array_filter($indexData)); + } + + /** + * @param $column + * + * @return bool + */ + protected function indexDataIsRelation($column) + { + return (int) strpos($column, '.') > 0; + } + + /** + * @param $column + * + * @return string + */ + protected function getIndexValueFromRelation($column) + { + list($relation, $column) = explode('.', $column); + if (is_null($this->{$relation})) { + return ''; + } + + $relationship = $this->{$relation}(); + if ($relationship instanceof BelongsTo || $relationship instanceof HasOne) { + return $this->{$relation}->{$column}; + } + + return $this->{$relation}->pluck($column)->implode(', '); + } +} diff --git a/src/FulltextSearch/src/IndexedRecord.php b/src/FulltextSearch/src/IndexedRecord.php new file mode 100644 index 0000000..4c572ab --- /dev/null +++ b/src/FulltextSearch/src/IndexedRecord.php @@ -0,0 +1,29 @@ +connection = config('binshopsblog.search.db_connection'); + + parent::__construct($attributes); + } + + public function indexable() + { + return $this->morphTo(); + } + + public function updateIndex() + { + $this->setAttribute('indexed_title', $this->indexable->getIndexTitle()); + $this->setAttribute('indexed_content', $this->indexable->getIndexContent()); + $this->save(); + } +} diff --git a/src/FulltextSearch/src/Indexer.php b/src/FulltextSearch/src/Indexer.php new file mode 100644 index 0000000..394c493 --- /dev/null +++ b/src/FulltextSearch/src/Indexer.php @@ -0,0 +1,42 @@ +indexRecord(); + } + + public function unIndexOneByClass($class, $id) + { + $record = IndexedRecord::where('indexable_id', $id)->where('indexable_type', $class); + if ($record->exists) { + $record->delete(); + } + } + + public function indexOneByClass($class, $id) + { + $model = call_user_func([$class, 'find'], $id); + if (in_array(Indexable::class, class_uses($model), true)) { + $this->indexModel($model); + } + } + + public function indexAllByClass($class) + { + $model = new $class(); + $self = $this; + if (in_array(Indexable::class, class_uses($model), true)) { + $model->chunk(100, function ($chunk) use ($self) { + foreach ($chunk as $modelRecord) { + $self->indexModel($modelRecord); + } + }); + } + } +} diff --git a/src/FulltextSearch/src/ModelObserver.php b/src/FulltextSearch/src/ModelObserver.php new file mode 100644 index 0000000..8cc3d88 --- /dev/null +++ b/src/FulltextSearch/src/ModelObserver.php @@ -0,0 +1,95 @@ +indexRecord(); + } + + /** + * Handle the updated event for the model. + * + * @param \Illuminate\Database\Eloquent\Model $model + */ + public function updated($model) + { + $this->created($model); + } + + /** + * Handle the deleted event for the model. + * + * @param \Illuminate\Database\Eloquent\Model $model + */ + public function deleted($model) + { + if (static::syncingDisabledFor($model)) { + return; + } + + $model->unIndexRecord(); + } + + /** + * Handle the restored event for the model. + * + * @param \Illuminate\Database\Eloquent\Model $model + */ + public function restored($model) + { + $this->created($model); + } +} diff --git a/src/FulltextSearch/src/Search.php b/src/FulltextSearch/src/Search.php new file mode 100644 index 0000000..01a95d0 --- /dev/null +++ b/src/FulltextSearch/src/Search.php @@ -0,0 +1,72 @@ +searchQuery($search); + + return $query->get(); + } + + /** + * @param $search + * @param $class + * + * @return \Illuminate\Database\Eloquent\Collection|\BinshopsBlog\Laravel\Fulltext\IndexedRecord[] + */ + public function runForClass($search, $class) + { + $query = $this->searchQuery($search); + $query->where('indexable_type', $class); + + return $query->get(); + } + + /** + * @param string $search + * + * This search query is designed for post queries - todo: + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function searchQuery($search) + { + $termsBool = ''; + $termsMatch = ''; + + if ($search) { + $terms = TermBuilder::terms($search); + + $termsBool = '+'.$terms->implode(' +'); + $termsMatch = ''.$terms->implode(' '); + } + + $titleWeight = str_replace(',', '.', (float) config('binshopsblog.search.weight.title', 1.5)); + $contentWeight = str_replace(',', '.', (float) config('binshopsblog.search.weight.content', 1.0)); + + $query = IndexedRecord::query() + ->whereRaw('MATCH (indexed_title, indexed_content) AGAINST (? IN BOOLEAN MODE)', [$termsBool]) + ->orderByRaw( + '('.$titleWeight.' * (MATCH (indexed_title) AGAINST (?)) + + '.$contentWeight.' * (MATCH (indexed_title, indexed_content) AGAINST (?)) + ) DESC', + [$termsMatch, $termsMatch]) + ->limit(config('binshopsblog.search.limit-results')); + + $query->with(['indexable' => function ($query) { + $query->with(['post' => function($query){ + $query->where('is_published', '=', true); + }]); + }]); + + return $query; + } +} diff --git a/src/FulltextSearch/src/SearchInterface.php b/src/FulltextSearch/src/SearchInterface.php new file mode 100644 index 0000000..22e0ae2 --- /dev/null +++ b/src/FulltextSearch/src/SearchInterface.php @@ -0,0 +1,12 @@ + <, ( ), ~, *, ", @distance) from the search query + // else we will break the MySQL query. + $search = trim(preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $search)); + + $terms = collect(preg_split('/[\s,]+/', $search)); + + if ($wildcards === true) { + $terms->transform(function ($term) { + return $term.'*'; + }); + } + + return $terms; + } +} diff --git a/src/Helpers.php b/src/Helpers.php index 3fd7c47..6ff1435 100755 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -1,18 +1,18 @@ - * to auto insert the links to rss feed - * @return string - */ - public static function rss_html_tag() - { - - - return ' - - '; - - - } - /** * This method is depreciated. Just use the config() directly. * @return array * @deprecated */ public static function image_sizes(){ - return config("blogetc.image_sizes"); + return config("binshopsblog.image_sizes"); } } diff --git a/src/Interfaces/BaseRequestInterface.php b/src/Interfaces/BaseRequestInterface.php index 6ddd97d..c45580a 100755 --- a/src/Interfaces/BaseRequestInterface.php +++ b/src/Interfaces/BaseRequestInterface.php @@ -1,4 +1,4 @@ -route('locale'); + $routeWithoutLocale = false; + + if (!$request->route('locale')){ + $routeWithoutLocale = true; + $locale = BinshopsConfiguration::get('DEFAULT_LANGUAGE_LOCALE'); + } + + $lang = BinshopsLanguage::where('locale', $locale) + ->where('active', true) + ->first(); + + if (!$lang){ + return abort(404); + } + + $request->attributes->add([ + 'lang_id' => $lang->id, + 'locale' => $lang->locale, + 'routeWithoutLocale' => $routeWithoutLocale + ]); + + return $next($request); + } +} diff --git a/src/Middleware/LoadLanguage.php b/src/Middleware/LoadLanguage.php new file mode 100644 index 0000000..08c7479 --- /dev/null +++ b/src/Middleware/LoadLanguage.php @@ -0,0 +1,25 @@ +first(); + + $request->attributes->add([ + 'locale' => $lang->locale, + 'language_id' => $lang->id + ]); + + return $next($request); + } +} diff --git a/src/Middleware/PackageSetup.php b/src/Middleware/PackageSetup.php new file mode 100644 index 0000000..fe71282 --- /dev/null +++ b/src/Middleware/PackageSetup.php @@ -0,0 +1,20 @@ +canManageBlogEtcPosts() == false + * Show 401 error if \Auth::user()->canManageBinshopsBlogPosts() == false * @param $request * @param Closure $next * @return mixed @@ -21,8 +21,9 @@ public function handle($request, Closure $next) { if (!\Auth::check()) { abort(401,"User not authorised to manage blog posts: You are not logged in"); + return redirect('/login'); } - if (!\Auth::user()->canManageBlogEtcPosts()) { + if (!\Auth::user()->canManageBinshopsBlogPosts()) { abort(401,"User not authorised to manage blog posts: Your account is not authorised to edit blog posts"); } return $next($request); diff --git a/src/Models/BinshopsCategory.php b/src/Models/BinshopsCategory.php new file mode 100755 index 0000000..e7d400a --- /dev/null +++ b/src/Models/BinshopsCategory.php @@ -0,0 +1,79 @@ +categoryTranslations()->delete(); + }); + } + + /** + * The associated category translations + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function categoryTranslations() + { + return $this->hasMany(BinshopsCategoryTranslation::class,"category_id"); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function posts() + { + return $this->belongsToMany(BinshopsPost::class, 'binshops_post_categories','category_id', 'post_id'); + } + + public function loadSiblings(){ + $this->siblings = $this->children()->get(); + } + + public static function loadSiblingsWithList($node_list){ + for($i = 0 ; sizeof($node_list) > $i ; $i++){ + $node_list[$i]->loadSiblings(); + if (sizeof($node_list[$i]->siblings) > 0){ + self::loadSiblingsWithList($node_list[$i]->siblings); + } + } + } + +// public function parent() +// { +// return $this->belongsTo('BinshopsBlog\Models\BinshopsCategory', 'parent_id'); +// } +// +// public function children() +// { +// return $this->hasMany('BinshopsBlog\Models\BinshopsCategory', 'parent_id'); +// } +// +// // recursive, loads all descendants +// private function childrenRecursive() +// { +// return $this->children()->with('children')->get(); +// } +// +// public function loadChildren(){ +// $this->childrenCat = $this->childrenRecursive(); +// } + +// public function scopeApproved($query) +// { +// dd("A"); +// return $query->where("approved", true); +// } +} diff --git a/src/Models/BinshopsCategoryTranslation.php b/src/Models/BinshopsCategoryTranslation.php new file mode 100644 index 0000000..f4450d5 --- /dev/null +++ b/src/Models/BinshopsCategoryTranslation.php @@ -0,0 +1,58 @@ +belongsTo(BinshopsCategory::class, 'category_id'); + } + + /** + * The associated Language + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function language() + { + return $this->hasOne(BinshopsLanguage::class,"lang_id"); + } + + /** + * Returns the public facing URL of showing blog posts in this category + * @return string + */ + public function url($locale, $routeWithoutLocale = false) + { + $theChainString = ""; + $cat = $this->category()->get(); + $chain = $cat[0]->getAncestorsAndSelf(); + foreach ($chain as $category){ + $theChainString .= "/" . $category->categoryTranslations()->where('lang_id' , $this->lang_id)->first()->slug; + } + + return $routeWithoutLocale ? route("binshopsblog.view_category",["", $theChainString]) : route("binshopsblog.view_category",[$locale, $theChainString]); + } + + /** + * Returns the URL for an admin user to edit this category + * @return string + */ + public function edit_url() + { + return route("binshopsblog.admin.categories.edit_category", $this->category_id); + } +} diff --git a/src/Models/BlogEtcComment.php b/src/Models/BinshopsComment.php similarity index 70% rename from src/Models/BlogEtcComment.php rename to src/Models/BinshopsComment.php index 680bb1c..b621d0e 100755 --- a/src/Models/BlogEtcComment.php +++ b/src/Models/BinshopsComment.php @@ -1,12 +1,12 @@ 'boolean', @@ -28,7 +28,7 @@ protected static function boot() { parent::boot(); - /* If user is logged in and \Auth::user()->canManageBlogEtcPosts() == true, show any/all posts. + /* If user is logged in and \Auth::user()->canManageBinshopsBlogPosts() == true, show any/all posts. otherwise (which will be for most users) it should only show published posts that have a posted_at time <= Carbon::now(). This sets it up: */ static::addGlobalScope(new BlogCommentApprovedAndDefaultOrderScope()); @@ -37,12 +37,12 @@ protected static function boot() /** - * The associated BlogEtcPost + * The associated BinshopsPost * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function post() { - return $this->belongsTo(BlogEtcPost::class,"blog_etc_post_id"); + return $this->belongsTo(BinshopsPost::class,"post_id"); } /** @@ -51,7 +51,7 @@ public function post() */ public function user() { - return $this->belongsTo(config("blogetc.user_model"), 'user_id'); + return $this->belongsTo(config("binshopsblog.user_model"), 'user_id'); } /** @@ -62,7 +62,7 @@ public function user() public function author() { if ($this->user_id) { - $field = config("blogetc.comments.user_field_for_author_name","name"); + $field = config("binshopsblog.comments.user_field_for_author_name","name"); return optional($this->user)->$field; } diff --git a/src/Models/BinshopsConfiguration.php b/src/Models/BinshopsConfiguration.php new file mode 100644 index 0000000..59a583e --- /dev/null +++ b/src/Models/BinshopsConfiguration.php @@ -0,0 +1,37 @@ +first(); + if ($obj){ + return $obj->value; + } + else{ + return null; + } + } + + public static function set($key, $value){ + $config = new BinshopsConfiguration(); + $config->key = $key; + $config->value = $value; + $config->save(); + } +} diff --git a/src/Models/BinshopsLanguage.php b/src/Models/BinshopsLanguage.php new file mode 100644 index 0000000..1ba7a87 --- /dev/null +++ b/src/Models/BinshopsLanguage.php @@ -0,0 +1,37 @@ +belongsTo(BinshopsPost::class, 'post_id'); + } + + /** + * The associated author (if category_id) is set + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function category() + { + return $this->belongsTo(BinshopsCategory::class, 'category_id'); + } + +} \ No newline at end of file diff --git a/src/Models/BinshopsPost.php b/src/Models/BinshopsPost.php new file mode 100755 index 0000000..ebebb77 --- /dev/null +++ b/src/Models/BinshopsPost.php @@ -0,0 +1,107 @@ + 'boolean', + 'posted_at' => 'date' + ]; + + /** + * @var array + */ + public $dates = [ + 'posted_at' + ]; + + /** + * @var array + */ + public $fillable = [ + 'is_published', + 'posted_at', + ]; + + /** + * The associated post translations + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function postTranslations() + { + return $this->hasMany(BinshopsPostTranslation::class,"post_id"); + } + + /** + * The "booting" method of the model. + * + * @return void + */ + protected static function boot() + { + parent::boot(); + + /* If user is logged in and \Auth::user()->canManageBinshopsBlogPosts() == true, show any/all posts. + otherwise (which will be for most users) it should only show published posts that have a posted_at + time <= Carbon::now(). This sets it up: */ + static::addGlobalScope(new BinshopsBlogPublishedScope()); + + static::deleting(function($post) { // before delete() method call this + $post->postTranslations()->delete(); + }); + } + + /** + * The associated author (if user_id) is set + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function author() + { + return $this->belongsTo(config("binshopsblog.user_model"), 'user_id'); + } + + /** + * Return author string (either from the User (via ->user_id), or the submitted author_name value + * @return string + */ + public function author_string() + { + if ($this->author) { + return optional($this->author)->name; + } else { + return 'Unknown Author'; + } + } + + /** + * The associated categories for this blog post + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function categories() + { + return $this->belongsToMany(BinshopsCategory::class, 'binshops_post_categories','post_id','category_id'); + } + + /** + * Comments for this post + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function comments() + { + return $this->hasMany(BinshopsComment::class, 'post_id'); + } + +} diff --git a/src/Models/BlogEtcPost.php b/src/Models/BinshopsPostTranslation.php old mode 100755 new mode 100644 similarity index 60% rename from src/Models/BlogEtcPost.php rename to src/Models/BinshopsPostTranslation.php index 12d97f5..856de2f --- a/src/Models/BlogEtcPost.php +++ b/src/Models/BinshopsPostTranslation.php @@ -1,45 +1,21 @@ 'boolean', - ]; - - /** - * @var array - */ - public $dates = [ - 'posted_at' - ]; - - /** - * @var array - */ public $fillable = [ - 'title', 'subtitle', 'short_description', @@ -48,17 +24,31 @@ class BlogEtcPost extends Model implements SearchResultInterface 'meta_desc', 'slug', 'use_view_file', - - 'is_published', - 'posted_at', ]; + /** + * Get the user that owns the phone. + */ + public function post() + { + return $this->belongsTo(BinshopsPost::class, 'post_id'); + } + + /** + * The associated Language + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function language() + { + return $this->hasOne(BinshopsLanguage::class,"lang_id"); + } + /** * Return the sluggable configuration array for this model. * * @return array */ - public function sluggable() + public function sluggable(): array { return [ 'slug' => [ @@ -77,82 +67,6 @@ public function search_result_page_title() return $this->title; } - /** - * The "booting" method of the model. - * - * @return void - */ - protected static function boot() - { - parent::boot(); - - /* If user is logged in and \Auth::user()->canManageBlogEtcPosts() == true, show any/all posts. - otherwise (which will be for most users) it should only show published posts that have a posted_at - time <= Carbon::now(). This sets it up: */ - static::addGlobalScope(new BlogEtcPublishedScope()); - } - - /** - * The associated author (if user_id) is set - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function author() - { - return $this->belongsTo(config("blogetc.user_model"), 'user_id'); - } - - /** - * Return author string (either from the User (via ->user_id), or the submitted author_name value - * @return string - */ - public function author_string() - { - if ($this->author) { - return optional($this->author)->name; - } else { - return 'Unknown Author'; - } - } - - /** - * The associated categories for this blog post - * - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany - */ - public function categories() - { - return $this->belongsToMany(BlogEtcCategory::class, 'blog_etc_post_categories'); - } - - /** - * Comments for this post - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function comments() - { - return $this->hasMany(BlogEtcComment::class); - } - - /** - * Returns the public facing URL to view this blog post - * - * @return string - */ - public function url() - { - return route("blogetc.single", $this->slug); - } - - /** - * Return the URL for editing the post (used for admin users) - * @return string - */ - public function edit_url() - { - return route("blogetc.admin.edit_post", $this->id); - } - /** * If $this->user_view_file is not empty, then it'll return the dot syntax location of the blade file it should look for * @return string @@ -190,7 +104,7 @@ public function image_url($size = 'medium') { $this->check_valid_image_size($size); $filename = $this->{"image_" . $size}; - return asset(config("blogetc.blog_upload_dir", "blog_images") . "/" . $filename); + return asset(config("binshopsblog.blog_upload_dir", "blog_images") . "/" . $filename); } /** @@ -211,7 +125,7 @@ public function image_tag($size = 'medium', $auto_link = true, $img_class = null $url = e($this->image_url($size)); $alt = e($this->title); $img = "$alt"; - return $auto_link ? "$img" : $img; + return $auto_link ? "$img" : $img; } @@ -229,23 +143,23 @@ public function generate_introduction($max_len = 500) public function post_body_output() { - if (config("blogetc.use_custom_view_files") && $this->use_view_file) { + if (config("binshopsblog.use_custom_view_files") && $this->use_view_file) { // using custom view files is enabled, and this post has a use_view_file set, so render it: - $return = view("blogetc::partials.use_view_file", ['post' => $this])->render(); + $return = view("binshopsblog::partials.use_view_file", ['post' => $this])->render(); } else { // just use the plain ->post_body $return = $this->post_body; } - if (!config("blogetc.echo_html")) { + if (!config("binshopsblog.echo_html")) { // if this is not true, then we should escape the output - if (config("blogetc.strip_html")) { + if (config("binshopsblog.strip_html")) { $return = strip_tags($return); } $return = e($return); - if (config("blogetc.auto_nl2br")) { + if (config("binshopsblog.auto_nl2br")) { $return = nl2br($return); } } @@ -265,7 +179,7 @@ protected function check_valid_image_size(string $size = 'medium') { - if (array_key_exists("image_" . $size, config("blogetc.image_sizes"))) { + if (array_key_exists("image_" . $size, config("binshopsblog.image_sizes"))) { return true; } @@ -273,22 +187,20 @@ protected function check_valid_image_size(string $size = 'medium') if (starts_with($size, "image_")) { // $size starts with image_, which is an error - /* the config/blogetc.php and the DB columns SHOULD have keys that start with image_$size + /* the config/binshopsblog.php and the DB columns SHOULD have keys that start with image_$size however when using methods such as image_url() or has_image() it SHOULD NOT start with 'image_' To put another way: : - in the config/blogetc.php : config("blogetc.image_sizes.image_medium") - in the database table: : blogetc_posts.image_medium + in the config/binshopsblog.php : config("binshopsblog.image_sizes.image_medium") + in the database table: : binshopsblog_posts.image_medium when calling image_url() : image_url("medium") */ - throw new \InvalidArgumentException("Invalid image size ($size). BlogEtcPost image size should not begin with 'image_'. Remove this from the start of $size. It *should* be in the blogetc.image_sizes config though!"); + throw new \InvalidArgumentException("Invalid image size ($size). BinshopsPost image size should not begin with 'image_'. Remove this from the start of $size. It *should* be in the binshopsblog.image_sizes config though!"); } - - throw new \InvalidArgumentException("BlogEtcPost image size should be 'large','medium','thumbnail' or another field as defined in config/blogetc.php. Provided size ($size) is not valid"); + throw new \InvalidArgumentException("BinshopsPost image size should be 'large','medium','thumbnail' or another field as defined in config/binshopsblog.php. Provided size ($size) is not valid"); } - /** * * If $this->seo_title was set, return that. @@ -304,4 +216,23 @@ public function gen_seo_title() } return $this->title; } + + /** + * Returns the public facing URL to view this blog post + * + * @return string + */ + public function url($loacle, $routeWithoutLocale = false) + { + return $routeWithoutLocale ? route("binshopsblog.single", ["", $this->slug]) : route("binshopsblog.single", [$loacle, $this->slug]); + } + + /** + * Return the URL for editing the post (used for admin users) + * @return string + */ + public function edit_url() + { + return route("binshopsblog.admin.edit_post", $this->post_id); + } } diff --git a/src/Models/BlogEtcUploadedPhoto.php b/src/Models/BinshopsUploadedPhoto.php similarity index 65% rename from src/Models/BlogEtcUploadedPhoto.php rename to src/Models/BinshopsUploadedPhoto.php index 50aa787..dfe1916 100644 --- a/src/Models/BlogEtcUploadedPhoto.php +++ b/src/Models/BinshopsUploadedPhoto.php @@ -1,12 +1,12 @@ 'array', ]; diff --git a/src/Models/BlogEtcCategory.php b/src/Models/BlogEtcCategory.php deleted file mode 100755 index af32277..0000000 --- a/src/Models/BlogEtcCategory.php +++ /dev/null @@ -1,80 +0,0 @@ -belongsToMany(BlogEtcPost::class, 'blog_etc_post_categories'); - } - - /** - * Returns the public facing URL of showing blog posts in this category - * @return string - */ - public function url() - { - $theChainString = ""; - $chain = $this->getAncestorsAndSelf(); - foreach ($chain as $category){ - $theChainString .= "/" . $category->slug; - } - return route("blogetc.view_category", $theChainString); - } - - /** - * Returns the URL for an admin user to edit this category - * @return string - */ - public function edit_url() - { - return route("blogetc.admin.categories.edit_category", $this->id); - } - - public function loadSiblings(){ - $this->siblings = $this->children()->get(); - } - -// public function parent() -// { -// return $this->belongsTo('WebDevEtc\BlogEtc\Models\BlogEtcCategory', 'parent_id'); -// } -// -// public function children() -// { -// return $this->hasMany('WebDevEtc\BlogEtc\Models\BlogEtcCategory', 'parent_id'); -// } -// -// // recursive, loads all descendants -// private function childrenRecursive() -// { -// return $this->children()->with('children')->get(); -// } -// -// public function loadChildren(){ -// $this->childrenCat = $this->childrenRecursive(); -// } - -// public function scopeApproved($query) -// { -// dd("A"); -// return $query->where("approved", true); -// } -} diff --git a/src/Requests/AddNewCommentRequest.php b/src/Requests/AddNewCommentRequest.php index 35587de..bc46526 100755 --- a/src/Requests/AddNewCommentRequest.php +++ b/src/Requests/AddNewCommentRequest.php @@ -1,6 +1,6 @@ captcha_field_name()] = $captcha->rules(); } // in case you need to implement something custom, you can use this... - if (config("blogetc.comments.rules") && is_callable(config("blogetc.comments.rules"))) { + if (config("binshopsblog.comments.rules") && is_callable(config("binshopsblog.comments.rules"))) { /** @var callable $func */ - $func = config('blogetc.comments.rules'); + $func = config('binshopsblog.comments.rules'); $return = $func($return); } - if (config("blogetc.comments.require_author_email")) { + if (config("binshopsblog.comments.require_author_email")) { $return['author_email'][] = 'required'; } diff --git a/src/Requests/BaseBlogEtcCategoryRequest.php b/src/Requests/BaseBinshopsBlogCategoryRequest.php similarity index 82% rename from src/Requests/BaseBlogEtcCategoryRequest.php rename to src/Requests/BaseBinshopsBlogCategoryRequest.php index 26e441e..4e5f8e8 100755 --- a/src/Requests/BaseBlogEtcCategoryRequest.php +++ b/src/Requests/BaseBinshopsBlogCategoryRequest.php @@ -1,8 +1,8 @@ $image_detail) { - if ($image_detail['enabled'] && config("blogetc.image_upload_enabled")) { + foreach ((array)config('binshopsblog.image_sizes') as $size => $image_detail) { + if ($image_detail['enabled'] && config("binshopsblog.image_upload_enabled")) { $return[$size] = ['nullable', 'image',]; } else { // was not enabled (or all images are disabled), so show an error if it was submitted: diff --git a/src/Requests/BaseRequest.php b/src/Requests/BaseRequest.php index 4412332..5d3b9b4 100755 --- a/src/Requests/BaseRequest.php +++ b/src/Requests/BaseRequest.php @@ -1,13 +1,13 @@ canManageBlogEtcPosts(); + return \Auth::check() && \Auth::user()->canManageBinshopsBlogPosts(); } } diff --git a/src/Requests/CreateBlogEtcPostRequest.php b/src/Requests/CreateBinshopsBlogPostRequest.php similarity index 52% rename from src/Requests/CreateBlogEtcPostRequest.php rename to src/Requests/CreateBinshopsBlogPostRequest.php index 0a012ff..f874d6a 100755 --- a/src/Requests/CreateBlogEtcPostRequest.php +++ b/src/Requests/CreateBinshopsBlogPostRequest.php @@ -1,13 +1,13 @@ baseBlogPostRules(); - $return['slug'] [] = Rule::unique("blog_etc_posts", "slug"); return $return; } diff --git a/src/Requests/CreateBinshopsPostToggleRequest.php b/src/Requests/CreateBinshopsPostToggleRequest.php new file mode 100755 index 0000000..f5cc5ba --- /dev/null +++ b/src/Requests/CreateBinshopsPostToggleRequest.php @@ -0,0 +1,25 @@ + [Rule::in(['rss','atom'])], - ]; - } - - /** - * Is this request for an RSS feed or Atom feed? defaults to atom. - * @return string - */ - public function getFeedType() - { - return $this->get("type") === 'rss' ? 'rss' : 'atom'; - } -} diff --git a/src/Requests/SearchRequest.php b/src/Requests/SearchRequest.php index 5b0c046..8bbd716 100755 --- a/src/Requests/SearchRequest.php +++ b/src/Requests/SearchRequest.php @@ -1,6 +1,6 @@ get("category")))->select("id")->limit(1000)->get(); + $vals = BinshopsCategory::whereIn("id", array_keys($this->get("category")))->select("id")->limit(1000)->get(); $vals = array_values($vals->pluck("id")->toArray()); return $vals; diff --git a/src/Requests/Traits/HasImageUploadTrait.php b/src/Requests/Traits/HasImageUploadTrait.php index b561ca5..e25f12a 100755 --- a/src/Requests/Traits/HasImageUploadTrait.php +++ b/src/Requests/Traits/HasImageUploadTrait.php @@ -1,4 +1,4 @@ - $image_size_info) { + foreach (config("binshopsblog.image_sizes") as $image_size_name => $image_size_info) { if ($this->file($image_size_name)) { return $this->file($image_size_name); } diff --git a/src/Requests/StoreBlogEtcCategoryRequest.php b/src/Requests/UpdateBinshopsBlogCategoryRequest.php similarity index 58% rename from src/Requests/StoreBlogEtcCategoryRequest.php rename to src/Requests/UpdateBinshopsBlogCategoryRequest.php index d274275..8674045 100755 --- a/src/Requests/StoreBlogEtcCategoryRequest.php +++ b/src/Requests/UpdateBinshopsBlogCategoryRequest.php @@ -1,12 +1,15 @@ baseCategoryRules(); - $return['slug'] [] = Rule::unique("blog_etc_categories", "slug"); return $return; + } } diff --git a/src/Requests/UpdateBinshopsBlogPostRequest.php b/src/Requests/UpdateBinshopsBlogPostRequest.php new file mode 100755 index 0000000..4f30db2 --- /dev/null +++ b/src/Requests/UpdateBinshopsBlogPostRequest.php @@ -0,0 +1,27 @@ +baseBlogPostRules(); +// $return['slug'] [] = Rule::unique("binshops_post_translations", "slug")->ignore($this->route()->parameter("blogPostId")); + return $return; + } +} diff --git a/src/Requests/UpdateBlogEtcCategoryRequest.php b/src/Requests/UpdateBlogEtcCategoryRequest.php deleted file mode 100755 index 45af4d0..0000000 --- a/src/Requests/UpdateBlogEtcCategoryRequest.php +++ /dev/null @@ -1,25 +0,0 @@ -baseCategoryRules(); - $return['slug'] [] = Rule::unique("blog_etc_categories", "slug")->ignore($this->route()->parameter("categoryId")); - return $return; - - } -} diff --git a/src/Requests/UpdateBlogEtcPostRequest.php b/src/Requests/UpdateBlogEtcPostRequest.php deleted file mode 100755 index d59ed70..0000000 --- a/src/Requests/UpdateBlogEtcPostRequest.php +++ /dev/null @@ -1,27 +0,0 @@ -baseBlogPostRules(); - $return['slug'] [] = Rule::unique("blog_etc_posts", "slug")->ignore($this->route()->parameter("blogPostId")); - return $return; - } -} diff --git a/src/Requests/UploadImageRequest.php b/src/Requests/UploadImageRequest.php index 422e9aa..6128b4e 100755 --- a/src/Requests/UploadImageRequest.php +++ b/src/Requests/UploadImageRequest.php @@ -1,13 +1,13 @@ canManageBlogEtcPosts()) { + if (!\Auth::check() || ! \Auth::user()->canManageBinshopsBlogPosts()) { // user is a guest, or if logged in they can't manage blog posts $builder->where("is_published", true); $builder->where("posted_at", "<=", Carbon::now()); diff --git a/src/Scopes/BlogCommentApprovedAndDefaultOrderScope.php b/src/Scopes/BlogCommentApprovedAndDefaultOrderScope.php index 77f16e2..70615f4 100755 --- a/src/Scopes/BlogCommentApprovedAndDefaultOrderScope.php +++ b/src/Scopes/BlogCommentApprovedAndDefaultOrderScope.php @@ -1,6 +1,6 @@ orderBy("id", 'asc'); // set a sane limit on num of comments. No pagination. Maybe a feature in the future. - $builder->limit(config("blogetc.comments.max_num_of_comments_to_show", 500)); + $builder->limit(config("binshopsblog.comments.max_num_of_comments_to_show", 500)); $builder->where("approved", true); } } \ No newline at end of file diff --git a/src/Traits/UploadFileTrait.php b/src/Traits/UploadFileTrait.php index 1b11f28..a1c793c 100644 --- a/src/Traits/UploadFileTrait.php +++ b/src/Traits/UploadFileTrait.php @@ -1,11 +1,12 @@ check_image_destination_path_is_writable($path); return $path; } /** - * @param BlogEtcPost $new_blog_post + * @param BinshopsPost $new_blog_post * @param $suggested_title - used to help generate the filename * @param $image_size_details - either an array (with 'w' and 'h') or a string (and it'll be uploaded at full size, no size reduction, but will use this string to generate the filename) * @param $photo * @return array * @throws \Exception */ - protected function UploadAndResize(BlogEtcPost $new_blog_post = null, $suggested_title, $image_size_details, $photo) + protected function UploadAndResize(BinshopsPostTranslation $new_blog_post = null, $suggested_title, $image_size_details, $photo) { // get the filename/filepath $image_filename = $this->getImageFilename($suggested_title, $image_size_details, $photo); @@ -122,7 +123,7 @@ protected function UploadAndResize(BlogEtcPost $new_blog_post = null, $suggested } // save image - $resizedImage->save($destinationPath . '/' . $image_filename, config("blogetc.image_quality", 80)); + $resizedImage->save($destinationPath . '/' . $image_filename, config("binshopsblog.image_quality", 80)); // fireevent event(new UploadedImage($image_filename, $resizedImage, $new_blog_post, __METHOD__)); diff --git a/src/Views/blogetc/captcha/basic.blade.php b/src/Views/binshopsblog/captcha/basic.blade.php similarity index 59% rename from src/Views/blogetc/captcha/basic.blade.php rename to src/Views/binshopsblog/captcha/basic.blade.php index 976ebe4..e3b9f79 100644 --- a/src/Views/blogetc/captcha/basic.blade.php +++ b/src/Views/binshopsblog/captcha/basic.blade.php @@ -1,6 +1,6 @@
+ for="captcha">Captcha: {{ config("binshopsblog.captcha.basic_question", "[error - undefined captcha question]" )}}
\ No newline at end of file diff --git a/src/Views/blogetc/index.blade.php b/src/Views/binshopsblog/index.blade.php similarity index 50% rename from src/Views/blogetc/index.blade.php rename to src/Views/binshopsblog/index.blade.php index 75a254c..0483be3 100755 --- a/src/Views/blogetc/index.blade.php +++ b/src/Views/binshopsblog/index.blade.php @@ -1,17 +1,17 @@ @extends("layouts.app",['title'=>$title]) @section('blog-custom-css') - + @endsection @section("content") -
- @if(\Auth::check() && \Auth::user()->canManageBlogEtcPosts()) +
+ @if(\Auth::check() && \Auth::user()->canManageBinshopsBlogPosts())

You are logged in as a blog admin user.
- Go To Blog Admin Panel @@ -27,8 +27,8 @@ class='btn border btn-outline-primary btn-sm '>

@@ -36,11 +36,11 @@ class='btn border btn-outline-primary btn-sm '>
@endif - @if(isset($blogetc_category) && $blogetc_category) -

{{$blogetc_category->category_name}}

+ @if(isset($binshopsblog_category) && $binshopsblog_category) +

{{$binshopsblog_category->category_name}}

- @if($blogetc_category->category_description) -

{{$blogetc_category->category_description}}

+ @if($binshopsblog_category->category_description) +

{{$binshopsblog_category->category_description}}

@endif @endif @@ -48,7 +48,7 @@ class='btn border btn-outline-primary btn-sm '>
@forelse($posts as $post) - @include("blogetc::partials.index_loop") + @include("binshopsblog::partials.index_loop") @empty
No posts!
@@ -59,24 +59,32 @@ class='btn border btn-outline-primary btn-sm '>
Blog Categories
- @forelse($categories as $category) - -
{{$category->category_name}}
-
- @empty - -
No Categories
-
- @endforelse +
    + @if($categories) + @include("binshopsblog::partials._category_partial", [ + 'category_tree' => $categories, + 'name_chain' => $nameChain = "", + 'routeWithoutLocale' => $routeWithoutLocale + ]) + @else + No Categories + @endif +
-
- {{$posts->appends( [] )->links()}} -
- @if (config('blogetc.search.search_enabled') ) - @include('blogetc::sitewide.search_form') + @if (config('binshopsblog.search.search_enabled') ) + @include('binshopsblog::sitewide.search_form') @endif +
+
+ @foreach($lang_list as $lang) + locale)}}"> + {{$lang->name}} + + @endforeach +
+
@endsection diff --git a/src/Views/binshopsblog/partials/_category_partial.blade.php b/src/Views/binshopsblog/partials/_category_partial.blade.php new file mode 100644 index 0000000..7cb577f --- /dev/null +++ b/src/Views/binshopsblog/partials/_category_partial.blade.php @@ -0,0 +1,24 @@ +@foreach($category_tree as $category) + @php $trans = $category->categoryTranslations->where('lang_id',$lang_id)->first();@endphp + @if($trans != null) +
  • + @php $nameChain = $nameChain .'/'. $trans->slug @endphp + + + + {{$trans->category_name}} + + @if( count($category->siblings) > 0) +
      + @include("binshopsblog::partials._category_partial", [ + 'category_tree' => $category->siblings, + 'name_chain' => $nameChain, + 'routeWithoutLocale' => $routeWithoutLocale + ]) +
    + @endif +
    +
    +
  • + @endif +@endforeach diff --git a/src/Views/blogetc/partials/add_comment_form.blade.php b/src/Views/binshopsblog/partials/add_comment_form.blade.php similarity index 89% rename from src/Views/blogetc/partials/add_comment_form.blade.php rename to src/Views/binshopsblog/partials/add_comment_form.blade.php index 7b045b0..97a49f2 100644 --- a/src/Views/blogetc/partials/add_comment_form.blade.php +++ b/src/Views/binshopsblog/partials/add_comment_form.blade.php @@ -1,6 +1,6 @@
    Add a comment
    -
    + get('locale'),$post->slug])}}'> @csrf @@ -21,7 +21,7 @@ class="form-control"
    - @if(config("blogetc.comments.save_user_id_if_logged_in", true) == false || !\Auth::check()) + @if(config("binshopsblog.comments.save_user_id_if_logged_in", true) == false || !\Auth::check())
    @@ -37,7 +37,7 @@ class="form-control"
    - @if(config("blogetc.comments.ask_for_author_email")) + @if(config("binshopsblog.comments.ask_for_author_email"))
    -@endsection \ No newline at end of file +@endsection diff --git a/src/Views/binshopsblog/single_post.blade.php b/src/Views/binshopsblog/single_post.blade.php new file mode 100755 index 0000000..2e3f5a1 --- /dev/null +++ b/src/Views/binshopsblog/single_post.blade.php @@ -0,0 +1,43 @@ +@extends("layouts.app",['title'=>$post->gen_seo_title()]) + +@section('blog-custom-css') + +@endsection + +@section("content") + + @if(config("binshopsblog.reading_progress_bar")) +
    +
    +
    + @endif + + {{--https://github.com/binshops/laravel-blog--}} + +
    +
    +
    + + @include("binshopsblog::partials.show_errors") + @include("binshopsblog::partials.full_post_details") + + + @if(config("binshopsblog.comments.type_of_comments_to_show","built_in") !== 'disabled') +
    +

    Comments

    + @include("binshopsblog::partials.show_comments") +
    + @else + {{--Comments are disabled--}} + @endif + + +
    +
    +
    + +@endsection + +@section('blog-custom-js') + +@endsection diff --git a/src/Views/blogetc/sitewide/random_posts.blade.php b/src/Views/binshopsblog/sitewide/random_posts.blade.php similarity index 65% rename from src/Views/blogetc/sitewide/random_posts.blade.php rename to src/Views/binshopsblog/sitewide/random_posts.blade.php index 505781b..cd5a0c2 100644 --- a/src/Views/blogetc/sitewide/random_posts.blade.php +++ b/src/Views/binshopsblog/sitewide/random_posts.blade.php @@ -1,6 +1,6 @@
    Random Posts
    $image_size_info) { + foreach ((array) config("binshopsblog.image_sizes") as $image_size => $image_size_info) { if (!$deletedPost->$image_size) { continue; } @@ -32,25 +32,25 @@ view - {{$deletedPost->$image_size}} {{--check filesize returns something, so we don't divide by 0--}} - @if(filesize(public_path(config("blogetc.blog_upload_dir","blog_images")."/".$deletedPost->$image_size))) + @if(filesize(public_path(config("binshopsblog.blog_upload_dir","blog_images")."/".$deletedPost->$image_size))) - ({{ (round(filesize(public_path(config("blogetc.blog_upload_dir","blog_images")."/".$deletedPost->$image_size)) / 1000 ,1)). " kb"}}) + ({{ (round(filesize(public_path(config("binshopsblog.blog_upload_dir","blog_images")."/".$deletedPost->$image_size)) / 1000 ,1)). " kb"}}) @endif - {{ public_path(config("blogetc.blog_upload_dir","blog_images")."/".$deletedPost->$image_size) }} + {{ public_path(config("binshopsblog.blog_upload_dir","blog_images")."/".$deletedPost->$image_size) }} diff --git a/src/Views/binshopsblog_admin/posts/edit_post.blade.php b/src/Views/binshopsblog_admin/posts/edit_post.blade.php new file mode 100755 index 0000000..f9a4572 --- /dev/null +++ b/src/Views/binshopsblog_admin/posts/edit_post.blade.php @@ -0,0 +1,42 @@ +@extends("binshopsblog_admin::layouts.admin_layout") +@section("content") + + +
    Admin - Editing post + @if($post_translation->slug) + View post + @endif +
    + +
    + +

    + To apply changes, click save changes for each language. +

    + + @csrf + @include("binshopsblog_admin::posts.form", [ + 'post' => $post, + 'post_translation' => $post_translation + ]) + + + +
    + + + +@endsection diff --git a/src/Views/blogetc_admin/posts/form.blade.php b/src/Views/binshopsblog_admin/posts/form.blade.php similarity index 62% rename from src/Views/blogetc_admin/posts/form.blade.php rename to src/Views/binshopsblog_admin/posts/form.blade.php index 0179dfe..a37ff4f 100755 --- a/src/Views/blogetc_admin/posts/form.blade.php +++ b/src/Views/binshopsblog_admin/posts/form.blade.php @@ -1,14 +1,26 @@ +
    + + +
    +
    title)}}"> + value="{{old("title",$post_translation->title)}}" oninput="populate_slug_field();" + > The title of the blog post
    + value='{{old("subtitle",$post_translation->subtitle)}}'> The subtitle of the blog post (optional)
    @@ -22,9 +34,8 @@
    slug)}}"> - The slug (leave blank to auto generate) - - i.e. {{route("blogetc.single","")}}/this_part + value="{{old("slug",$post_translation->slug)}}"> + The slug (leave blank to auto generate) - i.e.{{route("binshopsblog.single", [app('request')->get('locale'), "your-slug"])}}
    @@ -73,7 +84,7 @@
    + name='post_body'>{{old("post_body",$post_translation->post_body)}}
    @@ -90,12 +101,12 @@
    -@if(config("blogetc.use_custom_view_files",true)) +@if(config("binshopsblog.use_custom_view_files",true))
    + value='{{old("use_view_file",$post_translation->use_view_file)}}'> Optional - if anything is entered here, then it will attempt to load view("custom_blog_posts." . $use_view_file). You must create the file in /resources/views/custom_blog_posts/FILENAME.blade.php. @@ -108,25 +119,25 @@
    + + +
    + + + + + + + + + + + + + + + + diff --git a/src/Views/blogetc/partials/categories.blade.php b/src/Views/blogetc/partials/categories.blade.php deleted file mode 100644 index c001136..0000000 --- a/src/Views/blogetc/partials/categories.blade.php +++ /dev/null @@ -1,7 +0,0 @@ -
    - @foreach($post->categories as $category) - - {{$category->category_name}} - - @endforeach -
    \ No newline at end of file diff --git a/src/Views/blogetc/single_post.blade.php b/src/Views/blogetc/single_post.blade.php deleted file mode 100755 index 856f364..0000000 --- a/src/Views/blogetc/single_post.blade.php +++ /dev/null @@ -1,43 +0,0 @@ -@extends("layouts.app",['title'=>$post->gen_seo_title()]) - -@section('blog-custom-css') - -@endsection - -@section("content") - - @if(config("blogetc.reading_progress_bar")) -
    -
    -
    - @endif - - {{--https://webdevetc.com/laravel/packages/blogetc-blog-system-for-your-laravel-app/help-documentation/laravel-blog-package-blogetc#guide_to_views--}} - -
    -
    -
    - - @include("blogetc::partials.show_errors") - @include("blogetc::partials.full_post_details") - - - @if(config("blogetc.comments.type_of_comments_to_show","built_in") !== 'disabled') -
    -

    Comments

    - @include("blogetc::partials.show_comments") -
    - @else - {{--Comments are disabled--}} - @endif - - -
    -
    -
    - -@endsection - -@section('blog-custom-js') - -@endsection \ No newline at end of file diff --git a/src/Views/blogetc_admin/categories/add_category.blade.php b/src/Views/blogetc_admin/categories/add_category.blade.php deleted file mode 100755 index 2ecdc64..0000000 --- a/src/Views/blogetc_admin/categories/add_category.blade.php +++ /dev/null @@ -1,113 +0,0 @@ -@extends("blogetc_admin::layouts.admin_layout") -@section("content") - - -
    Admin - Add Category
    - -
    - - @csrf - - -
    - - - category_name)}}" - > - - The name of the category -
    - - -
    - - slug)}}" - > - - - Letters, numbers, dash only. The slug - i.e. {{route("blogetc.view_category","")}}/this_part. This must be unique (two categories can't - share the same slug). - - -
    - -
    - - -
    - - -
    - - - -
    - - - - - - -
    - -@endsection diff --git a/src/Views/blogetc_admin/categories/deleted_category.blade.php b/src/Views/blogetc_admin/categories/deleted_category.blade.php deleted file mode 100755 index 64030de..0000000 --- a/src/Views/blogetc_admin/categories/deleted_category.blade.php +++ /dev/null @@ -1,7 +0,0 @@ -@extends("blogetc_admin::layouts.admin_layout") -@section("content") - - -
    Deleted that category
    - -@endsection \ No newline at end of file diff --git a/src/Views/blogetc_admin/posts/add_post.blade.php b/src/Views/blogetc_admin/posts/add_post.blade.php deleted file mode 100755 index 9bf2090..0000000 --- a/src/Views/blogetc_admin/posts/add_post.blade.php +++ /dev/null @@ -1,16 +0,0 @@ -@extends("blogetc_admin::layouts.admin_layout") -@section("content") - - -
    Admin - Add post
    - -
    - - @csrf - @include("blogetc_admin::posts.form", ['post' => new \WebDevEtc\BlogEtc\Models\BlogEtcPost()]) - - - -
    - -@endsection diff --git a/src/Views/blogetc_admin/posts/edit_post.blade.php b/src/Views/blogetc_admin/posts/edit_post.blade.php deleted file mode 100755 index e3e337c..0000000 --- a/src/Views/blogetc_admin/posts/edit_post.blade.php +++ /dev/null @@ -1,19 +0,0 @@ -@extends("blogetc_admin::layouts.admin_layout") -@section("content") - - -
    Admin - Editing post - View post -
    - -
    - - @csrf - @method("patch") - @include("blogetc_admin::posts.form", ['post' => $post]) - - - -
    - -@endsection \ No newline at end of file diff --git a/src/css/admin-setup.css b/src/css/admin-setup.css new file mode 100644 index 0000000..4f34ba9 --- /dev/null +++ b/src/css/admin-setup.css @@ -0,0 +1,954 @@ +a { + color: #2CA8FF; +} + +a:hover, a:focus { + color: #109CFF; +} + +a:focus, a:active, +button::-moz-focus-inner, +input[type="reset"]::-moz-focus-inner, +input[type="button"]::-moz-focus-inner, +input[type="submit"]::-moz-focus-inner, +select::-moz-focus-inner, +input[type="file"] > input[type="button"]::-moz-focus-inner, +input[type="button"]:focus { + outline: 0 !important; +} + +.btn:focus, +.btn:hover, +.btn:active { + outline: 0; +} + +/* Animations */ +.form-control, .input-group-addon { + -webkit-transition: all 300ms linear; + -moz-transition: all 300ms linear; + -o-transition: all 300ms linear; + -ms-transition: all 300ms linear; + transition: all 300ms linear; +} + +.image-container { + min-height: 100vh; + background-position: center center; + background-size: cover; +} + +.wizard-container { + padding-top: 100px; + z-index: 3; +} + +.wizard-navigation { + position: relative; +} + +.made-with-mk { + width: 50px; + height: 50px; + display: block; + position: fixed; + z-index: 555; + bottom: 40px; + right: 40px; + border-radius: 30px; + background-color: rgba(16, 16, 16, 0.35); + border: 1px solid rgba(255, 255, 255, 0.15); + color: #FFFFFF; + cursor: pointer; + padding: 10px 12px; + white-space: nowrap; + overflow: hidden; + -webkit-transition: 0.55s cubic-bezier(0.6, 0, 0.4, 1); + -moz-transition: 0.55s cubic-bezier(0.6, 0, 0.4, 1); + -o-transition: 0.55s cubic-bezier(0.6, 0, 0.4, 1); + transition: 0.55s cubic-bezier(0.6, 0, 0.4, 1); +} +.made-with-mk:hover, .made-with-mk:active, .made-with-mk:focus { + width: 218px; + color: #FFFFFF; + transition-duration: .55s; + padding: 10px 30px; +} +.made-with-mk:hover .made-with, .made-with-mk:active .made-with, .made-with-mk:focus .made-with { + opacity: 1; +} +.made-with-mk:hover .brand, .made-with-mk:active .brand, .made-with-mk:focus .brand { + left: 0; +} +.made-with-mk .brand, +.made-with-mk .made-with { + float: left; +} +.made-with-mk .brand { + position: relative; + top: 3px; + left: -1px; + letter-spacing: 1px; + vertical-align: middle; + font-size: 16px; + font-weight: 600; +} +.made-with-mk .made-with { + color: rgba(255, 255, 255, 0.6); + position: absolute; + left: 75px; + top: 15px; + opacity: 0; + margin: 0; + -webkit-transition: 0.55s cubic-bezier(0.6, 0, 0.4, 1); + -moz-transition: 0.55s cubic-bezier(0.6, 0, 0.4, 1); + -o-transition: 0.55s cubic-bezier(0.6, 0, 0.4, 1); + transition: 0.55s cubic-bezier(0.6, 0, 0.4, 1); +} +.made-with-mk .made-with strong { + font-weight: 400; + color: rgba(255, 255, 255, 0.9); + letter-spacing: 1px; +} + +/* Font Smoothing */ +h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6, p, .navbar, .brand, .btn-simple { + -moz-osx-font-smoothing: grayscale; + -webkit-font-smoothing: antialiased; +} + +/* Typography */ +h1, .h1, h2, .h2, h3, .h3, h4, .h4 { + font-weight: 400; + margin: 30px 0 15px; +} + +h1, .h1 { + font-size: 52px; +} + +h2, .h2 { + font-size: 36px; +} + +h3, .h3 { + font-size: 28px; + margin: 20px 0 10px; +} + +h4, .h4 { + font-size: 22px; +} + +h5, .h5 { + font-size: 16px; +} + +h6, .h6 { + font-size: 14px; + font-weight: bold; + text-transform: uppercase; +} + +p { + font-size: 16px; + line-height: 1.6180em; +} + +h1 small, h2 small, h3 small, h4 small, h5 small, h6 small, .h1 small, .h2 small, .h3 small, .h4 small, .h5 small, .h6 small, h1 .small, h2 .small, h3 .small, h4 .small, h5 .small, h6 .small, .h1 .small, .h2 .small, .h3 .small, .h4 .small, .h5 .small, .h6 .small { + color: #999999; + font-weight: 300; + line-height: 1; +} + +h1 small, h2 small, h3 small, h1 .small, h2 .small, h3 .small { + font-size: 60%; +} + +h1 .subtitle { + display: block; + font-family: 'Grand Hotel',cursive; + line-height: 40px; + margin: 15px 0 30px; +} + +.card { + background-color: #FFFFFF; + padding: 10px 0 20px; + width: 100%; +} + +.wizard-card { + min-height: 410px; + background-color: #FFFFFF; + box-shadow: 0 0 15px rgba(0, 0, 0, 0.15), 0 0 1px 1px rgba(0, 0, 0, 0.1); + border-radius: 10px; + padding: 10px 0; +} +.wizard-card .picture-container { + position: relative; + cursor: pointer; + text-align: center; +} +.wizard-card .picture { + width: 106px; + height: 106px; + background-color: #999999; + border: 4px solid #CCCCCC; + color: #FFFFFF; + border-radius: 50%; + margin: 5px auto; + overflow: hidden; + transition: all 0.2s; + -webkit-transition: all 0.2s; +} +.wizard-card .picture:hover { + border-color: #2ca8ff; +} +.wizard-card .picture input[type="file"] { + cursor: pointer; + display: block; + height: 100%; + left: 0; + opacity: 0 !important; + position: absolute; + top: 0; + width: 100%; +} +.wizard-card .picture-src { + width: 100%; +} +.wizard-card .tab-content { + min-height: 340px; + padding: 20px 10px; +} +.wizard-card .wizard-footer { + padding: 0 10px; +} +.wizard-card .disabled { + display: none; +} +.wizard-card .wizard-header h3 { + font-weight: 200; + text-align: center; +} +.wizard-card[data-color="green"] .choice:hover .icon, .wizard-card[data-color="green"] .choice.active .icon { + border-color: #2787AC; +} +.wizard-card[data-color="green"] .picture:hover { + border-color: #2787AC; +} +.wizard-card[data-color="green"] .moving-tab { + position: absolute; + text-align: center; + padding: 10px; + font-size: 12px; + text-transform: uppercase; + -webkit-font-smoothing: subpixel-antialiased; + background-color: #2787AC; + top: 0px; + left: 0px; + color: #FFFFFF; + cursor: pointer; + font-weight: 500; +} +.wizard-card[data-color="azzure"] .choice:hover .icon, .wizard-card[data-color="azzure"] .choice.active .icon { + border-color: #2CA8FF; +} +.wizard-card[data-color="azzure"] .picture:hover { + border-color: #2CA8FF; +} +.wizard-card[data-color="azzure"] .moving-tab { + position: absolute; + text-align: center; + padding: 10px; + font-size: 12px; + text-transform: uppercase; + -webkit-font-smoothing: subpixel-antialiased; + background-color: #2CA8FF; + top: 0px; + left: 0px; + color: #FFFFFF; + cursor: pointer; + font-weight: 500; +} +.wizard-card[data-color="blue"] .choice:hover .icon, .wizard-card[data-color="blue"] .choice.active .icon { + border-color: #3472F7; +} +.wizard-card[data-color="blue"] .picture:hover { + border-color: #3472F7; +} +.wizard-card[data-color="blue"] .moving-tab { + position: absolute; + text-align: center; + padding: 10px; + font-size: 12px; + text-transform: uppercase; + -webkit-font-smoothing: subpixel-antialiased; + background-color: #3472F7; + top: 0px; + left: 0px; + color: #FFFFFF; + cursor: pointer; + font-weight: 500; +} +.wizard-card[data-color="orange"] .choice:hover .icon, .wizard-card[data-color="orange"] .choice.active .icon { + border-color: #FF9500; +} +.wizard-card[data-color="orange"] .picture:hover { + border-color: #FF9500; +} +.wizard-card[data-color="orange"] .moving-tab { + position: absolute; + text-align: center; + padding: 10px; + font-size: 12px; + text-transform: uppercase; + -webkit-font-smoothing: subpixel-antialiased; + background-color: #FF9500; + top: 0px; + left: 0px; + color: #FFFFFF; + cursor: pointer; + font-weight: 500; +} +.wizard-card[data-color="red"] .choice:hover .icon, .wizard-card[data-color="red"] .choice.active .icon { + border-color: #FF3B30; +} +.wizard-card[data-color="red"] .picture:hover { + border-color: #FF3B30; +} +.wizard-card[data-color="red"] .moving-tab { + position: absolute; + text-align: center; + padding: 10px; + font-size: 12px; + text-transform: uppercase; + -webkit-font-smoothing: subpixel-antialiased; + background-color: #FF3B30; + top: 0px; + left: 0px; + color: #FFFFFF; + cursor: pointer; + font-weight: 500; +} +.wizard-card .btn { + text-transform: uppercase; +} +.wizard-card .info-text { + text-align: center; + font-weight: 300; + margin: 10px 0 30px; +} +.wizard-card .choice { + text-align: center; + cursor: pointer; + margin-top: 20px; +} +.wizard-card .choice .icon { + text-align: center; + vertical-align: middle; + height: 116px; + width: 116px; + border-radius: 50%; + background-color: #999999; + color: #FFFFFF; + margin: 0 auto 20px; + border: 4px solid #CCCCCC; + transition: all 0.2s; + -webkit-transition: all 0.2s; +} +.wizard-card .choice i { + font-size: 30px; + line-height: 111px; +} +.wizard-card .choice:hover .icon, .wizard-card .choice.active .icon { + border-color: #2ca8ff; +} +.wizard-card .choice input[type="radio"], +.wizard-card .choice input[type="checkbox"] { + position: absolute; + left: -10000px; + z-index: -1; +} +.wizard-card .btn-finish { + display: none; +} +.wizard-card .description { + color: #999999; + font-size: 14px; +} + +/* Inputs */ +.form-control { + background-color: #FFFFFF; + border: 1px solid #E3E3E3; + border-radius: 4px; + box-shadow: none; + color: #444444; + height: 38px; + padding: 6px 16px; +} +.form-control:focus { + background-color: #FFFFFF; + border: 1px solid #9A9A9A; + box-shadow: none; + outline: 0 none; +} +.form-control + .form-control-feedback { + border-radius: 6px; + font-size: 14px; + padding: 0 12px 0 0; + position: absolute; + right: 25px; + top: 13px; + vertical-align: middle; +} +.has-success .form-control, .has-error .form-control, .has-success .form-control:focus, .has-error .form-control:focus { + border-color: #E3E3E3; + box-shadow: none; +} +.has-success .form-control, +.form-control .has-success .form-control-feedback, .form-control.valid:focus { + border-color: #2787AC; + color: #2787AC; +} +.has-error .form-control, +.form-control .has-error .form-control-feedback, .form-control.error { + color: #FF3B30; + border-color: #FF3B30; +} +.form-control:focus + .input-group-addon, .form-control:focus ~ .input-group-addon { + background-color: #FFFFFF; + border-color: #9A9A9A; +} +.form-control ::-moz-placeholder { + color: #DDDDDD; + opacity: 1; +} +.form-control ::-moz-placeholder { + color: #DDDDDD; + opacity: 1; +} +.form-control ::-webkit-input-placeholder { + color: #DDDDDD; + opacity: 1; +} +.form-control ::-ms-input-placeholder { + color: #DDDDDD; + opacity: 1; +} +.form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control { + background-color: #EEEEEE; + color: #999999; + cursor: not-allowed; +} + +.input-lg { + height: 56px; + padding: 10px 16px; +} + +.input-group-addon { + background-color: #FFFFFF; + border: 1px solid #E3E3E3; + border-radius: 4px; +} + +.input-group .form-control:first-child, .input-group-addon:first-child, .input-group-btn:first-child > .btn, .input-group-btn:first-child > .dropdown-toggle, .input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle) { + border-right: 0 none; +} + +.input-group .form-control:last-child, .input-group-addon:last-child, .input-group-btn:last-child > .btn, .input-group-btn:last-child > .dropdown-toggle, .input-group-btn:first-child > .btn:not(:first-child) { + border-left: 0 none; +} + +.btn { + border-width: 2px; + background-color: transparent; + font-weight: 400; + opacity: 0.8; + padding: 8px 16px; +} +.btn:active, .btn.active { + background-image: none; + box-shadow: none; +} +.btn.disabled, .btn[disabled], fieldset[disabled] .btn { + opacity: 0.45; +} + +.btn-round { + border-width: 1px; + border-radius: 30px !important; + opacity: 0.79; + padding: 9px 18px; +} + +.btn-sm, .btn-xs { + border-radius: 3px; + font-size: 12px; + padding: 5px 10px; +} + +.btn-xs { + padding: 1px 5px; +} + +.btn-lg { + border-radius: 6px; + font-size: 18px; + font-weight: 400; + padding: 14px 30px; +} + +.btn-wd { + min-width: 100px; +} + +.btn-default { + color: #777777; + border-color: #999999; +} + +.btn-primary { + color: #3472F7; + border-color: #3472F7; +} + +.btn-info { + color: #2CA8FF; + border-color: #2CA8FF; +} + +.btn-success { + color: #2787AC; + border-color: #2787AC; +} + +.btn-warning { + color: #FF9500; + border-color: #FF9500; +} + +.btn-danger { + color: #FF3B30; + border-color: #FF3B30; +} + +.btn:hover { + background-color: transparent; + opacity: 1; +} + +.btn-primary:hover, .btn-primary:focus, .btn-primary:active, .btn-primary.active, .open .dropdown-toggle .btn-primary { + color: #1D62F0; + border-color: #1D62F0; + background-color: transparent; +} + +.btn-info:hover, .btn-info:focus, .btn-info:active, .btn-info.active, .open .dropdown-toggle .btn-info { + color: #109CFF; + border-color: #109CFF; + background-color: transparent; +} + +.btn-success:hover, .btn-success:focus, .btn-success:active, .btn-success.active, .open .dropdown-toggle .btn-success { + color: #049F0C; + border-color: #049F0C; + background-color: transparent; +} + +.btn-warning:hover, .btn-warning:focus, .btn-warning:active, .btn-warning.active, .open .dropdown-toggle .btn-warning { + color: #ED8D00; + border-color: #ED8D00; + background-color: transparent; +} + +.btn-danger:hover, .btn-danger:focus, .btn-danger:active, .btn-danger.active, .open .dropdown-toggle .btn-danger { + color: #EE2D20; + border-color: #EE2D20; + background-color: transparent; +} + +.btn-default:hover, .btn-default:focus, .btn-default.active, .open .dropdown-toggle .btn-default { + color: #666666; + border-color: #888888; + background-color: transparent; +} + +.btn-primary.disabled, .btn-primary[disabled], fieldset[disabled] .btn-primary, .btn-primary.disabled:hover, .btn-primary[disabled]:hover, fieldset[disabled] .btn-primary:hover, .btn-primary.disabled:focus, .btn-primary[disabled]:focus, fieldset[disabled] .btn-primary:focus, .btn-primary.disabled:active, .btn-primary[disabled]:active, fieldset[disabled] .btn-primary:active, .btn-primary.disabled.active, .btn-primary.active[disabled], fieldset[disabled] .btn-primary.active { + background-color: transparent; + border-color: #3472F7; +} + +.btn-info.disabled, .btn-info[disabled], fieldset[disabled] .btn-info, .btn-info.disabled:hover, .btn-info[disabled]:hover, fieldset[disabled] .btn-info:hover, .btn-info.disabled:focus, .btn-info[disabled]:focus, fieldset[disabled] .btn-info:focus, .btn-info.disabled:active, .btn-info[disabled]:active, fieldset[disabled] .btn-info:active, .btn-info.disabled.active, .btn-info.active[disabled], fieldset[disabled] .btn-info.active { + background-color: transparent; + border-color: #2CA8FF; +} + +.btn-success.disabled, .btn-success[disabled], fieldset[disabled] .btn-success, .btn-success.disabled:hover, .btn-success[disabled]:hover, fieldset[disabled] .btn-success:hover, .btn-success.disabled:focus, .btn-success[disabled]:focus, fieldset[disabled] .btn-success:focus, .btn-success.disabled:active, .btn-success[disabled]:active, fieldset[disabled] .btn-success:active, .btn-success.disabled.active, .btn-success.active[disabled], fieldset[disabled] .btn-success.active { + background-color: transparent; + border-color: #2787AC; +} + +.btn-danger.disabled, .btn-danger[disabled], fieldset[disabled] .btn-danger, .btn-danger.disabled:hover, .btn-danger[disabled]:hover, fieldset[disabled] .btn-danger:hover, .btn-danger.disabled:focus, .btn-danger[disabled]:focus, fieldset[disabled] .btn-danger:focus, .btn-danger.disabled:active, .btn-danger[disabled]:active, fieldset[disabled] .btn-danger:active, .btn-danger.disabled.active, .btn-danger.active[disabled], fieldset[disabled] .btn-danger.active { + background-color: transparent; + border-color: #FF3B30; +} + +.btn-warning.disabled, .btn-warning[disabled], fieldset[disabled] .btn-warning, .btn-warning.disabled:hover, .btn-warning[disabled]:hover, fieldset[disabled] .btn-warning:hover, .btn-warning.disabled:focus, .btn-warning[disabled]:focus, fieldset[disabled] .btn-warning:focus, .btn-warning.disabled:active, .btn-warning[disabled]:active, fieldset[disabled] .btn-warning:active, .btn-warning.disabled.active, .btn-warning.active[disabled], fieldset[disabled] .btn-warning.active { + background-color: transparent; + border-color: #FF9500; +} + +/* Buttons fill .btn-fill */ +.btn-fill { + color: #FFFFFF; + opacity: 1; +} +.btn-fill:hover, .btn-fill:active, .btn-fill:focus { + color: #FFFFFF; +} +.btn-fill.btn-default { + background-color: #999999; + border-color: #999999; +} +.btn-fill.btn-default:hover, .btn-fill.btn-default:focus, .btn-fill.btn-default:active, .btn-fill.btn-default.active, .open .dropdown-toggle .btn-fill.btn-default { + background-color: #888888; + border-color: #888888; +} +.btn-fill.btn-primary { + background-color: #3472F7; + border-color: #3472F7; +} +.btn-fill.btn-primary:hover, .btn-fill.btn-primary:focus, .btn-fill.btn-primary:active, .btn-fill.btn-primary.active, .open .dropdown-toggle .btn-fill.btn-primary { + border-color: #1D62F0; + background-color: #1D62F0; +} +.btn-fill.btn-info { + background-color: #2CA8FF; + border-color: #2CA8FF; +} +.btn-fill.btn-info:hover, .btn-fill.btn-info:focus, .btn-fill.btn-info:active, .btn-fill.btn-info.active, .open .dropdown-toggle .btn-fill.btn-info { + background-color: #109CFF; + border-color: #109CFF; +} +.btn-fill.btn-success { + background-color: #2787AC; + border-color: #2787AC; +} +.btn-fill.btn-warning { + background-color: #FF9500; + border-color: #FF9500; +} +.btn-fill.btn-warning:hover, .btn-fill.btn-warning:focus, .btn-fill.btn-warning:active, .btn-fill.btn-warning.active, .open .dropdown-toggle .btn-fill.btn-warning { + background-color: #ED8D00; + border-color: #ED8D00; +} +.btn-fill.btn-danger { + background-color: #FF3B30; + border-color: #FF3B30; +} +.btn-fill.btn-danger:hover, .btn-fill.btn-danger:focus, .btn-fill.btn-danger:active, .btn-fill.btn-danger.active, .open .dropdown-toggle .btn-fill.btn-danger { + background-color: #EE2D20; + border-color: #EE2D20; +} + +/* End Buttons fill */ +.btn-simple { + font-weight: 600; + border: 0; + padding: 10px 18px; +} +.btn-simple.btn-xs { + padding: 3px 5px; +} +.btn-simple.btn-sm { + padding: 7px 10px; +} +.btn-simple.btn-lg { + padding: 16px 60px; +} + +.btn-round.btn-xs { + padding: 2px 5px; +} +.btn-round.btn-sm { + padding: 6px 10px; +} +.btn-round.btn-lg { + padding: 15px 30px; +} + +/* Navigation menu */ +.nav-pills { + background-color: #999999; +} +.nav-pills > li + li { + margin-left: 0; +} +.nav-pills > li > a { + border: 1px solid #2CA8FF; + border-radius: 0; + color: #2CA8FF; + border: 0 !important; + text-transform: uppercase; + background-color: #999999; + text-align: center; + color: #FFFFFF !important; + font-size: 12px; + cursor: pointer; +} +.nav-pills > li > a:focus, .nav-pills > li > a:hover { + background-color: #999999; +} +.nav-pills > li.active > a, +.nav-pills > li.active > a:focus, +.nav-pills > li.active > a:hover { + background-color: inherit; +} + +.text-primary, .text-primary:hover { + color: #3472F7; +} + +.text-info, .text-info:hover { + color: #2CA8FF; +} + +.text-success, .text-success:hover { + color: #2787AC; +} + +.text-warning, .text-warning:hover { + color: #FF9500; +} + +.text-danger, .text-danger:hover { + color: #FF3B30; +} + +/* Labels & Progress-bar */ +.label { + padding: 0.2em 0.6em 0.2em; + border: 1px solid #999999; + border-radius: 3px; + color: #999999; + background-color: #FFFFFF; + font-weight: 500; + font-size: 11px; + text-transform: uppercase; +} +.label.label-fill { + color: #FFFFFF; +} + +.label-primary { + border-color: #3472F7; + color: #3472F7; +} + +.label-info { + border-color: #2CA8FF; + color: #2CA8FF; +} + +.label-success { + border-color: #2787AC; + color: #2787AC; +} + +.label-warning { + border-color: #FF9500; + color: #FF9500; +} + +.label-danger { + border-color: #FF3B30; + color: #FF3B30; +} + +label { + font-weight: 400; +} + +label.error { + color: #FF3B30; + margin-top: 5px; + margin-bottom: 0; +} + +label small { + color: #999999; +} + +.label-primary.label-fill, .progress-bar, .progress-bar-primary { + background-color: #3472F7; +} + +.label-info.label-fill, .progress-bar-info { + background-color: #2CA8FF; +} + +.label-success.label-fill, .progress-bar-success { + background-color: #2787AC; +} + +.label-warning.label-fill, .progress-bar-warning { + background-color: #FF9500; +} + +.label-danger.label-fill, .progress-bar-danger { + background-color: #FF3B30; +} + +.label-default.label-fill { + background-color: #999999; +} + +.tooltip { + font-size: 14px; + font-weight: bold; +} + +.tooltip-arrow { + display: none; + opacity: 0; +} + +.tooltip-inner { + background-color: #FAE6A4; + border-radius: 4px; + box-shadow: 0 1px 13px rgba(0, 0, 0, 0.14), 0 0 0 1px rgba(115, 71, 38, 0.23); + color: #734726; + max-width: 200px; + padding: 6px 10px; + text-align: center; + text-decoration: none; +} +.tooltip-inner:after { + content: ""; + display: inline-block; + left: 100%; + margin-left: -56%; + position: absolute; +} +.tooltip-inner:before { + content: ""; + display: inline-block; + left: 100%; + margin-left: -56%; + position: absolute; +} + +.tooltip.top { + margin-top: -11px; + padding: 0; +} +.tooltip.top .tooltip-inner:after { + border-top: 11px solid #FAE6A4; + border-left: 11px solid transparent; + border-right: 11px solid transparent; + bottom: -10px; +} +.tooltip.top .tooltip-inner:before { + border-top: 11px solid rgba(0, 0, 0, 0.2); + border-left: 11px solid transparent; + border-right: 11px solid transparent; + bottom: -11px; +} + +.tooltip.bottom { + margin-top: 11px; + padding: 0; +} +.tooltip.bottom .tooltip-inner:after { + border-bottom: 11px solid #FAE6A4; + border-left: 11px solid transparent; + border-right: 11px solid transparent; + top: -10px; +} +.tooltip.bottom .tooltip-inner:before { + border-bottom: 11px solid rgba(0, 0, 0, 0.2); + border-left: 11px solid transparent; + border-right: 11px solid transparent; + top: -11px; +} + +.tooltip.left { + margin-left: -11px; + padding: 0; +} +.tooltip.left .tooltip-inner:after { + border-left: 11px solid #FAE6A4; + border-top: 11px solid transparent; + border-bottom: 11px solid transparent; + right: -10px; + left: auto; + margin-left: 0; +} +.tooltip.left .tooltip-inner:before { + border-left: 11px solid rgba(0, 0, 0, 0.2); + border-top: 11px solid transparent; + border-bottom: 11px solid transparent; + right: -11px; + left: auto; + margin-left: 0; +} + +.tooltip.right { + margin-left: 11px; + padding: 0; +} +.tooltip.right .tooltip-inner:after { + border-right: 11px solid #FAE6A4; + border-top: 11px solid transparent; + border-bottom: 11px solid transparent; + left: -10px; + top: 0; + margin-left: 0; +} +.tooltip.right .tooltip-inner:before { + border-right: 11px solid rgba(0, 0, 0, 0.2); + border-top: 11px solid transparent; + border-bottom: 11px solid transparent; + left: -11px; + top: 0; + margin-left: 0; +} + +.footer { + position: relative; + bottom: 20px; + right: 0px; + width: 100%; + color: #706f6f; + z-index: 4; + text-align: center; + margin-top: 60px; +} +.footer a { + color: #FFFFFF; +} +.footer .heart { + color: #FF3B30; +} + +@media (max-width: 768px) { + .main .container { + margin-bottom: 50px; + } +} +@media (min-width: 768px) { + .navbar-form { + margin-top: 21px; + margin-bottom: 21px; + padding-left: 5px; + padding-right: 5px; + } + + .btn-wd { + min-width: 140px; + } +} diff --git a/src/css/hessam-blog.css b/src/css/binshops-blog.css similarity index 83% rename from src/css/hessam-blog.css rename to src/css/binshops-blog.css index 585188e..e8edc54 100644 --- a/src/css/hessam-blog.css +++ b/src/css/binshops-blog.css @@ -23,4 +23,8 @@ width: 100%; height: 100%; background-color: #E16036; -} \ No newline at end of file +} + +.binshops-cat-hierarchy { + list-style-type: none !important; +} diff --git a/src/css/blogetc_admin_css.css b/src/css/binshopsblog_admin_css.css similarity index 99% rename from src/css/blogetc_admin_css.css rename to src/css/binshopsblog_admin_css.css index 77dd7da..48562d3 100644 --- a/src/css/blogetc_admin_css.css +++ b/src/css/binshopsblog_admin_css.css @@ -22,7 +22,7 @@ From laravel 5.6 background-color: #212529 !important; } -.hessam-version{ +.binshops-version{ margin: 0px !important; padding: 10px; } @@ -31,7 +31,7 @@ From laravel 5.6 color: #212529 !important; } -.hessam-blog-title{ +.binshops-blog-title{ position: absolute; left: 20px; } @@ -43,3 +43,53 @@ body{ .nav-bar-full{ height: 100% !important; } + +.wtree li { + list-style-type: none; + margin: 10px 0 10px 10px; + position: relative; +} +.wtree li:before { + content: ""; + position: absolute; + top: -10px; + left: -20px; + border-left: 1px solid #ddd; + border-bottom: 1px solid #ddd; + width: 20px; + height: 15px; +} +.wtree li:after { + position: absolute; + content: ""; + top: 5px; + left: -20px; + border-left: 1px solid #ddd; + border-top: 1px solid #ddd; + width: 20px; + height: 100%; +} +.wtree li:last-child:after { + display: none; +} +.wtree li span { + display: block; + border: 1px solid #ddd; + padding: 5px; + color: #888; + text-decoration: none; +} + +.wtree li span:hover, .wtree li span:focus { + background: #eee; + color: #000; + border: 1px solid #aaa; +} +.wtree li span:hover + ul li span, .wtree li span:focus + ul li span { + background: #eee; + color: #000; + border: 1px solid #aaa; +} +.wtree li span:hover + ul li:after, .wtree li span:hover + ul li:before, .wtree li span:focus + ul li:after, .wtree li span:focus + ul li:before { + border-color: #aaa; +} diff --git a/src/js/hessam-blog.js b/src/js/binshops-blog.js similarity index 100% rename from src/js/hessam-blog.js rename to src/js/binshops-blog.js diff --git a/src/routes.php b/src/routes.php index dec1d93..3d78ad5 100755 --- a/src/routes.php +++ b/src/routes.php @@ -1,128 +1,171 @@ ['web'], 'namespace' => '\WebDevEtc\BlogEtc\Controllers'], function () { +Route::group(['middleware' => ['web'], 'namespace' => '\BinshopsBlog\Controllers'], function () { + /** The main public facing blog routes - show all posts, view a category, view a single post, also the add comment route */ + Route::group(['prefix' => "/{locale}/".config('binshopsblog.blog_prefix', 'blog')], function () { - /** The main public facing blog routes - show all posts, view a category, rss feed, view a single post, also the add comment route */ - Route::group(['prefix' => config('blogetc.blog_prefix', 'blog')], function () { + Route::get('/', 'BinshopsReaderController@index') + ->name('binshopsblog.index'); - Route::get('/', 'BlogEtcReaderController@index') - ->name('blogetc.index'); + Route::get('/search', 'BinshopsReaderController@search') + ->name('binshopsblog.search'); - Route::get('/search', 'BlogEtcReaderController@search') - ->name('blogetc.search'); + Route::get('/category{subcategories}', 'BinshopsReaderController@view_category')->where('subcategories', '^[a-zA-Z0-9-_\/]+$')->name('binshopsblog.view_category'); - Route::get('/feed', 'BlogEtcRssFeedController@feed') - ->name('blogetc.feed'); //RSS feed + Route::get('/{blogPostSlug}', + 'BinshopsReaderController@viewSinglePost') + ->name('binshopsblog.single'); - Route::get('/category{subcategories}', 'BlogEtcReaderController@view_category')->where('subcategories', '^[a-zA-Z0-9-_\/]+$')->name('blogetc.view_category'); + // throttle to a max of 10 attempts in 3 minutes: + Route::group(['middleware' => 'throttle:10,3'], function () { + Route::post('save_comment/{blogPostSlug}', + 'BinshopsCommentWriterController@addNewComment') + ->name('binshopsblog.comments.add_new_comment'); + }); + }); -// Route::get('/category/{categorySlug}', -// 'BlogEtcReaderController@view_category') -// ->name('blogetc.view_category'); + Route::group(['prefix' => config('binshopsblog.blog_prefix', 'blog')], function () { - Route::get('/{blogPostSlug}', - 'BlogEtcReaderController@viewSinglePost') - ->name('blogetc.single'); + Route::get('/', 'BinshopsReaderController@index') + ->name('binshopsblognolocale.index'); + Route::get('/search', 'BinshopsReaderController@search') + ->name('binshopsblognolocale.search'); + + Route::get('/category{subcategories}', 'BinshopsReaderController@view_category')->where('subcategories', '^[a-zA-Z0-9-_\/]+$')->name('binshopsblognolocale.view_category'); + + Route::get('/{blogPostSlug}', + 'BinshopsReaderController@viewSinglePost') + ->name('binshopsblognolocale.single'); // throttle to a max of 10 attempts in 3 minutes: Route::group(['middleware' => 'throttle:10,3'], function () { - Route::post('save_comment/{blogPostSlug}', - 'BlogEtcCommentWriterController@addNewComment') - ->name('blogetc.comments.add_new_comment'); - - + 'BinshopsCommentWriterController@addNewComment') + ->name('binshopsblognolocale.comments.add_new_comment'); }); - }); - /* Admin backend routes - CRUD for posts, categories, and approving/deleting submitted comments */ - Route::group(['prefix' => config('blogetc.admin_prefix', 'blog_admin')], function () { + Route::group(['prefix' => config('binshopsblog.admin_prefix', 'blog_admin')], function () { + + Route::get('/search', + 'BinshopsAdminController@searchBlog') + ->name('binshopsblog.admin.searchblog'); - Route::get('/', 'BlogEtcAdminController@index') - ->name('blogetc.admin.index'); + Route::get('/setup', 'BinshopsAdminSetupController@setup') + ->name('binshopsblog.admin.setup'); + + Route::post('/setup-submit', 'BinshopsAdminSetupController@setup_submit') + ->name('binshopsblog.admin.setup_submit'); + + Route::get('/', 'BinshopsAdminController@index') + ->name('binshopsblog.admin.index'); Route::get('/add_post', - 'BlogEtcAdminController@create_post') - ->name('blogetc.admin.create_post'); + 'BinshopsAdminController@create_post') + ->name('binshopsblog.admin.create_post'); Route::post('/add_post', - 'BlogEtcAdminController@store_post') - ->name('blogetc.admin.store_post'); + 'BinshopsAdminController@store_post') + ->name('binshopsblog.admin.store_post'); + Route::post('/add_post_toggle', + 'BinshopsAdminController@store_post_toggle') + ->name('binshopsblog.admin.store_post_toggle'); Route::get('/edit_post/{blogPostId}', - 'BlogEtcAdminController@edit_post') - ->name('blogetc.admin.edit_post'); + 'BinshopsAdminController@edit_post') + ->name('binshopsblog.admin.edit_post'); + + Route::post('/edit_post_toggle/{blogPostId}', + 'BinshopsAdminController@edit_post_toggle') + ->name('binshopsblog.admin.edit_post_toggle'); - Route::patch('/edit_post/{blogPostId}', - 'BlogEtcAdminController@update_post') - ->name('blogetc.admin.update_post'); + Route::post('/edit_post/{blogPostId}', + 'BinshopsAdminController@update_post') + ->name('binshopsblog.admin.update_post'); //Removes post's photo - Route::get('/remove_photo/{slug}', - 'BlogEtcAdminController@remove_photo') - ->name('blogetc.admin.remove_photo'); + Route::get('/remove_photo/{slug}/{lang_id}', + 'BinshopsAdminController@remove_photo') + ->name('binshopsblog.admin.remove_photo'); Route::group(['prefix' => "image_uploads",], function () { - Route::get("/", "BlogEtcImageUploadController@index")->name("blogetc.admin.images.all"); - - Route::get("/upload", "BlogEtcImageUploadController@create")->name("blogetc.admin.images.upload"); - Route::post("/upload", "BlogEtcImageUploadController@store")->name("blogetc.admin.images.store"); + Route::get("/", "BinshopsImageUploadController@index")->name("binshopsblog.admin.images.all"); + Route::get("/upload", "BinshopsImageUploadController@create")->name("binshopsblog.admin.images.upload"); + Route::post("/upload", "BinshopsImageUploadController@store")->name("binshopsblog.admin.images.store"); }); - Route::delete('/delete_post/{blogPostId}', - 'BlogEtcAdminController@destroy_post') - ->name('blogetc.admin.destroy_post'); + 'BinshopsAdminController@destroy_post') + ->name('binshopsblog.admin.destroy_post'); Route::group(['prefix' => 'comments',], function () { Route::get('/', - 'BlogEtcCommentsAdminController@index') - ->name('blogetc.admin.comments.index'); + 'BinshopsCommentsAdminController@index') + ->name('binshopsblog.admin.comments.index'); Route::patch('/{commentId}', - 'BlogEtcCommentsAdminController@approve') - ->name('blogetc.admin.comments.approve'); + 'BinshopsCommentsAdminController@approve') + ->name('binshopsblog.admin.comments.approve'); Route::delete('/{commentId}', - 'BlogEtcCommentsAdminController@destroy') - ->name('blogetc.admin.comments.delete'); + 'BinshopsCommentsAdminController@destroy') + ->name('binshopsblog.admin.comments.delete'); }); Route::group(['prefix' => 'categories'], function () { Route::get('/', - 'BlogEtcCategoryAdminController@index') - ->name('blogetc.admin.categories.index'); + 'BinshopsCategoryAdminController@index') + ->name('binshopsblog.admin.categories.index'); Route::get('/add_category', - 'BlogEtcCategoryAdminController@create_category') - ->name('blogetc.admin.categories.create_category'); - Route::post('/add_category', - 'BlogEtcCategoryAdminController@store_category') - ->name('blogetc.admin.categories.store_category'); + 'BinshopsCategoryAdminController@create_category') + ->name('binshopsblog.admin.categories.create_category'); + Route::post('/store_category', + 'BinshopsCategoryAdminController@store_category') + ->name('binshopsblog.admin.categories.store_category'); Route::get('/edit_category/{categoryId}', - 'BlogEtcCategoryAdminController@edit_category') - ->name('blogetc.admin.categories.edit_category'); + 'BinshopsCategoryAdminController@edit_category') + ->name('binshopsblog.admin.categories.edit_category'); Route::patch('/edit_category/{categoryId}', - 'BlogEtcCategoryAdminController@update_category') - ->name('blogetc.admin.categories.update_category'); + 'BinshopsCategoryAdminController@update_category') + ->name('binshopsblog.admin.categories.update_category'); Route::delete('/delete_category/{categoryId}', - 'BlogEtcCategoryAdminController@destroy_category') - ->name('blogetc.admin.categories.destroy_category'); - + 'BinshopsCategoryAdminController@destroy_category') + ->name('binshopsblog.admin.categories.destroy_category'); }); + Route::group(['prefix' => 'languages'], function () { + + Route::get('/', + 'BinshopsLanguageAdminController@index') + ->name('binshopsblog.admin.languages.index'); + + Route::get('/add_language', + 'BinshopsLanguageAdminController@create_language') + ->name('binshopsblog.admin.languages.create_language'); + Route::post('/add_language', + 'BinshopsLanguageAdminController@store_language') + ->name('binshopsblog.admin.languages.store_language'); + + Route::delete('/delete_language/{languageId}', + 'BinshopsLanguageAdminController@destroy_language') + ->name('binshopsblog.admin.languages.destroy_language'); + + Route::post('/toggle_language/{languageId}', + 'BinshopsLanguageAdminController@toggle_language') + ->name('binshopsblog.admin.languages.toggle_language'); + }); }); }); diff --git a/tests/CaptchaTest.php b/tests/CaptchaTest.php index 649adb3..dfa7f34 100644 --- a/tests/CaptchaTest.php +++ b/tests/CaptchaTest.php @@ -6,7 +6,7 @@ class CaptchaTest extends \Tests\TestCase public function testBasicCaptchaMethodsReturnCorrectType() { - $captcha = new \WebDevEtc\BlogEtc\Captcha\Basic(); + $captcha = new \BinshopsBlog\Captcha\Basic(); $this->assertEquals(gettype($captcha->captcha_field_name()), "string"); $this->assertEquals(gettype($captcha->view()), "string"); $this->assertEquals(gettype($captcha->rules()), "array"); @@ -16,7 +16,7 @@ public function testBasicCaptchaMethodsReturnCorrectType() public function testRuleCustomValidationFunctionReturnsCorrectly() { - $captcha = new \WebDevEtc\BlogEtc\Captcha\Basic(); + $captcha = new \BinshopsBlog\Captcha\Basic(); foreach ($captcha->rules() as $rule) { @@ -31,32 +31,32 @@ public function testRuleCustomValidationFunctionReturnsCorrectly() // testing CORRECT answer (should return null) - \Config::set('blogetc.captcha.basic_answers', "ignoreme,dark,ignoreme2"); + \Config::set('binshopsblog.captcha.basic_answers', "ignoreme,dark,ignoreme2"); $this->assertNull($rule('correct1', 'dark', function () { return "lookingforthis"; })); // testing WRONG answer - \Config::set('blogetc.captcha.basic_answers', "ignoreme,dark,ignoreme2"); + \Config::set('binshopsblog.captcha.basic_answers', "ignoreme,dark,ignoreme2"); $this->assertEquals($rule('wrong1', 'light', function () { return "lookingforthis"; }), "lookingforthis"); // testing CORRECT answer - \Config::set('blogetc.captcha.basic_answers', "bLAcK"); + \Config::set('binshopsblog.captcha.basic_answers', "bLAcK"); $this->assertNull($rule('wrong1', 'black', function () { return "lookingforthis"; })); // testing CORRECT answer - \Config::set('blogetc.captcha.basic_answers', "bLAcK"); + \Config::set('binshopsblog.captcha.basic_answers', "bLAcK"); $this->assertNull($rule('wrong1', ' black', function () { return "lookingforthis"; })); // testing CORRECT answer - \Config::set('blogetc.captcha.basic_answers', "ignoreme, BLACK , jgnoreme2"); + \Config::set('binshopsblog.captcha.basic_answers', "ignoreme, BLACK , jgnoreme2"); $this->assertNull($rule('wrong1', ' black', function () { return "lookingforthis"; })); diff --git a/tests/MainTest.php b/tests/MainTest.php index e436964..9d08a2f 100644 --- a/tests/MainTest.php +++ b/tests/MainTest.php @@ -20,11 +20,10 @@ class MainTest extends \Tests\TestCase Testing the author_email, author_website. /blog/... - blogetc.index YES - blogetc.feed YES - blogetc.view_category no - but this is basically blogetc.index - blogetc.single YES - blogetc.comments.add_new_comment YES - tested multiple times with/without basic captcha on/off/correct/incorrect. + binshopsblog.index YES + binshopsblog.view_category no - but this is basically binshopsblog.index + binshopsblog.single YES + binshopsblog.comments.add_new_comment YES - tested multiple times with/without basic captcha on/off/correct/incorrect. Also tested with diff configs for comment form: disabled built_in @@ -32,27 +31,27 @@ class MainTest extends \Tests\TestCase custom /blog_admin/... - blogetc.admin.index YES - blogetc.admin.create_post no - but is just a form - blogetc.admin.store_post YES - blogetc.admin.edit_post YES - but no extra checks - blogetc.admin.update_post YES - blogetc.admin.destroy_post YES + binshopsblog.admin.index YES + binshopsblog.admin.create_post no - but is just a form + binshopsblog.admin.store_post YES + binshopsblog.admin.edit_post YES - but no extra checks + binshopsblog.admin.update_post YES + binshopsblog.admin.destroy_post YES /blog_admin/comments/... - blogetc.admin.comments.index YES - blogetc.admin.comments.approve YES - blogetc.admin.comments.delete YES + binshopsblog.admin.comments.index YES + binshopsblog.admin.comments.approve YES + binshopsblog.admin.comments.delete YES /blog_admin/categories/... - blogetc.admin.categories.index - blogetc.admin.categories.create_category no - but is just a form - blogetc.admin.categories.store_category YES - blogetc.admin.categories.edit_category no - but is just a form - blogetc.admin.categories.update_category - blogetc.admin.categories.destroy_category YES + binshopsblog.admin.categories.index + binshopsblog.admin.categories.create_category no - but is just a form + binshopsblog.admin.categories.store_category YES + binshopsblog.admin.categories.edit_category no - but is just a form + binshopsblog.admin.categories.update_category + binshopsblog.admin.categories.destroy_category YES @@ -63,16 +62,16 @@ class MainTest extends \Tests\TestCase public function testFilesArePresent() { - $this->assertFileExists(config_path("blogetc.php"), "/config/blogetc.php should exist - currently no file with that filename is found"); - $this->assertTrue(is_array(include(config_path("blogetc.php"))), "/config/blogetc.php should exist - currently no file with that filename is found"); + $this->assertFileExists(config_path("binshopsblog.php"), "/config/binshopsblog.php should exist - currently no file with that filename is found"); + $this->assertTrue(is_array(include(config_path("binshopsblog.php"))), "/config/binshopsblog.php should exist - currently no file with that filename is found"); } public function testImageSizesAreSane() { - $this->assertTrue(count(config("blogetc.image_sizes")) >= 3); + $this->assertTrue(count(config("binshopsblog.image_sizes")) >= 3); - foreach (config("blogetc.image_sizes") as $image_key => $image_info) { + foreach (config("binshopsblog.image_sizes") as $image_key => $image_info) { $this->assertArrayHasKey("w", $image_info); $this->assertArrayHasKey("h", $image_info); @@ -94,13 +93,13 @@ public function testImageSizesAreSane() } - public function testUserHasNanManageBlogEtcPostsMethod() + public function testUserHasNanManageBinshopsBlogPostsMethod() { - $this->assertTrue(method_exists(\App\User::class, "canManageBlogEtcPosts"), "Your User model must have the canManageBlogEtcPosts method"); + $this->assertTrue(method_exists(\App\User::class, "canManageBinshopsBlogPosts"), "Your User model must have the canManageBinshopsBlogPosts method"); $user = new \App\User(); - $this->assertTrue(is_bool($user->canManageBlogEtcPosts())); + $this->assertTrue(is_bool($user->canManageBinshopsBlogPosts())); } @@ -109,7 +108,7 @@ public function testUserHasNanManageBlogEtcPostsMethod() public function testCanSeeAdminPanel() { - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); \Auth::logout(); // without a logged in user, should give error @@ -126,7 +125,7 @@ public function testCanSeeAdminPanel() $response->assertStatus(200); // check user can see admin area: - $this->assertTrue($user->canManageBlogEtcPosts()); + $this->assertTrue($user->canManageBinshopsBlogPosts()); $response = $this->get($admin_panel_url); // check if we can see the admin panel correctly @@ -138,10 +137,10 @@ public function testCanSeeAdminPanel() $response->assertSee("Add Category"); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); // $user=$this->create_admin_user(); - $this->assertTrue($user->canManageBlogEtcPosts()); + $this->assertTrue($user->canManageBinshopsBlogPosts()); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); @@ -155,7 +154,7 @@ public function testCanSeeAdminPanel() $new_object_vals['_token'] = csrf_token(); - $this->assertDatabaseMissing('blog_etc_posts', $search_for_obj); + $this->assertDatabaseMissing('binshops_posts', $search_for_obj); $response = $this->post($admin_panel_url . "/add_post", $new_object_vals); $response->assertSessionHasNoErrors(); @@ -163,7 +162,7 @@ public function testCanSeeAdminPanel() $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); } @@ -174,9 +173,9 @@ public function testCanCreatePost() $user = $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); - $this->assertTrue($user->canManageBlogEtcPosts()); + $this->assertTrue($user->canManageBinshopsBlogPosts()); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); @@ -188,13 +187,13 @@ public function testCanCreatePost() $new_object_vals['_token'] = csrf_token(); - $this->assertDatabaseMissing('blog_etc_posts', $search_for_obj); + $this->assertDatabaseMissing('binshops_posts', $search_for_obj); $response = $this->post($admin_panel_url . "/add_post", $new_object_vals); $response->assertSessionHasNoErrors(); $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); } @@ -206,9 +205,9 @@ public function testCanCreatePostThenEditIt() $user = $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); - $this->assertTrue($user->canManageBlogEtcPosts()); + $this->assertTrue($user->canManageBinshopsBlogPosts()); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); @@ -221,20 +220,20 @@ public function testCanCreatePostThenEditIt() $new_object_vals['_token'] = csrf_token(); - $this->assertDatabaseMissing('blog_etc_posts', $search_for_obj); + $this->assertDatabaseMissing('binshops_posts', $search_for_obj); $response = $this->post($admin_panel_url . "/add_post", $new_object_vals); $response->assertSessionHasNoErrors(); $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); - $justCreatedRow = \WebDevEtc\BlogEtc\Models\BlogEtcPost::where("slug", $new_object_vals['slug'])->firstOrFail(); + $justCreatedRow = \BinshopsBlog\Models\BinshopsPost::where("slug", $new_object_vals['slug'])->firstOrFail(); $new_object_vals['title'] = "New title " . str_random(); - $this->assertDatabaseMissing('blog_etc_posts', ['title' => $new_object_vals['title']]); + $this->assertDatabaseMissing('binshops_posts', ['title' => $new_object_vals['title']]); $response = $this->patch($admin_panel_url . "/edit_post/" . $justCreatedRow->id, $new_object_vals); $response->assertStatus(302); - $this->assertDatabaseHas('blog_etc_posts', ['title' => $new_object_vals['title']]); + $this->assertDatabaseHas('binshops_posts', ['title' => $new_object_vals['title']]); } @@ -246,9 +245,9 @@ public function testCreatePostThenCheckIsViewableToPublic() $user = $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); - $this->assertTrue($user->canManageBlogEtcPosts()); + $this->assertTrue($user->canManageBinshopsBlogPosts()); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); @@ -263,17 +262,16 @@ public function testCreatePostThenCheckIsViewableToPublic() $new_object_vals['_token'] = csrf_token(); - $this->assertDatabaseMissing('blog_etc_posts', $search_for_obj); + $this->assertDatabaseMissing('binshops_posts', $search_for_obj); // check we don't see it at moment - $response = $this->get(config("blogetc.blog_prefix", "blog")); + $response = $this->get(config("binshopsblog.blog_prefix", "blog")); $response->assertDontSee($new_object_vals['slug']); - // must clear the cache, as the /feed is cached + // must clear the cache \Artisan::call('cache:clear'); - $response = $this->get(config("blogetc.blog_prefix", "blog") . "/feed"); $response->assertDontSee($new_object_vals['slug']); $response = $this->post($admin_panel_url . "/add_post", $new_object_vals); @@ -281,26 +279,25 @@ public function testCreatePostThenCheckIsViewableToPublic() $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); // logout - so we are guest user \Auth::logout(); - $response = $this->get(config("blogetc.blog_prefix", "blog")); + $response = $this->get(config("binshopsblog.blog_prefix", "blog")); // if we see the slug (which is str_random()) we can safely assume that there was a link to the post, so it is working ok. of course it would depend a bit on your template but this should work. $response->assertSee($new_object_vals['slug']); - // must clear the cache, as the /feed is cached + // must clear the cache \Artisan::call('cache:clear'); - $response = $this->get(config("blogetc.blog_prefix", "blog") . "/feed"); $response->assertSee($new_object_vals['slug']); $response->assertSee($new_object_vals['title']); // now check single post is viewable - $response = $this->get(route("blogetc.single", $new_object_vals['slug'])); + $response = $this->get(route("binshopsblog.single", $new_object_vals['slug'])); $response->assertStatus(200); $response->assertSee($new_object_vals['slug']); $response->assertSee($new_object_vals['title']); @@ -313,7 +310,7 @@ public function testCreatePostWithNotPublishedThenCheckIsNotViewableToPublic() { - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); list($new_object_vals, $search_for_obj) = $this->prepare_post_creation(); $new_object_vals['is_published'] = false; @@ -323,19 +320,19 @@ public function testCreatePostWithNotPublishedThenCheckIsNotViewableToPublic() $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); // must log out, as the admin user can see posts dated in future \Auth::logout(); - $response = $this->get(config("blogetc.blog_prefix", "blog")); + $response = $this->get(config("binshopsblog.blog_prefix", "blog")); // if we see the slug (which is str_random()) we can safely assume that there was a link to the post, so it is working ok. of course it would depend a bit on your template but this should work. $response->assertDontSee($new_object_vals['slug']); // now check single post is viewable - $response = $this->get(config("blogetc.blog_prefix", "blog") . "/" . $new_object_vals['slug']); + $response = $this->get(config("binshopsblog.blog_prefix", "blog") . "/" . $new_object_vals['slug']); $response->assertStatus(404); $response->assertDontSee($new_object_vals['slug']); $response->assertDontSee($new_object_vals['title']); @@ -348,7 +345,7 @@ public function testCreatePostWithFuturePostedAtThenCheckIsNotViewableToPublic() { - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); list($new_object_vals, $search_for_obj) = $this->prepare_post_creation(); $new_object_vals['posted_at'] = \Carbon\Carbon::now()->addMonths(12); @@ -358,19 +355,19 @@ public function testCreatePostWithFuturePostedAtThenCheckIsNotViewableToPublic() $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); // must log out, as the admin user can see posts dated in future \Auth::logout(); - $response = $this->get(config("blogetc.blog_prefix", "blog")); + $response = $this->get(config("binshopsblog.blog_prefix", "blog")); // if we see the slug (which is str_random()) we can safely assume that there was a link to the post, so it is working ok. of course it would depend a bit on your template but this should work. $response->assertDontSee($new_object_vals['slug']); // now check single post is viewable - $response = $this->get(config("blogetc.blog_prefix", "blog") . "/" . $new_object_vals['slug']); + $response = $this->get(config("binshopsblog.blog_prefix", "blog") . "/" . $new_object_vals['slug']); $response->assertStatus(404); $response->assertDontSee($new_object_vals['slug']); $response->assertDontSee($new_object_vals['title']); @@ -383,16 +380,16 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveCommentWithBas { - \Config::set('blogetc.comments.auto_approve_comments', false); - \Config::set('blogetc.captcha.captcha_enabled', true); - \Config::set('blogetc.captcha.captcha_type', \WebDevEtc\BlogEtc\Captcha\Basic::class); - $captcha = new \WebDevEtc\BlogEtc\Captcha\Basic(); - \Config::set('blogetc.captcha.basic_question', "a test question"); - \Config::set('blogetc.captcha.basic_answers', "answer1,answer2"); + \Config::set('binshopsblog.comments.auto_approve_comments', false); + \Config::set('binshopsblog.captcha.captcha_enabled', true); + \Config::set('binshopsblog.captcha.captcha_type', \BinshopsBlog\Captcha\Basic::class); + $captcha = new \BinshopsBlog\Captcha\Basic(); + \Config::set('binshopsblog.captcha.basic_question', "a test question"); + \Config::set('binshopsblog.captcha.basic_answers', "answer1,answer2"); $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); // to verify this was added to database. Use a different variable, so we can add things (like _token) and still be able to assertDatabaseHas later. @@ -409,10 +406,10 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveCommentWithBas $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); - \Config::set('blogetc.comments.type_of_comments_to_show', 'built_in'); + \Config::set('binshopsblog.comments.type_of_comments_to_show', 'built_in'); $comment_detail = [ @@ -421,11 +418,11 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveCommentWithBas 'comment' => str_random(), $captcha->captcha_field_name() => "wronganswer1", // << WRONG CAPTCHA ]; - $this->assertDatabaseMissing('blog_etc_comments', ['author_name' => $comment_detail['author_name']]); - $response = $this->post(config("blogetc.blog_prefix", "blog") . "/save_comment/" . $new_object_vals['slug'], $comment_detail); + $this->assertDatabaseMissing('binshops_comments', ['author_name' => $comment_detail['author_name']]); + $response = $this->post(config("binshopsblog.blog_prefix", "blog") . "/save_comment/" . $new_object_vals['slug'], $comment_detail); $response->assertStatus(302); - $this->assertDatabaseMissing('blog_etc_comments', ['author_name' => $comment_detail['author_name']]); + $this->assertDatabaseMissing('binshops_comments', ['author_name' => $comment_detail['author_name']]); $comment_detail = [ @@ -434,11 +431,11 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveCommentWithBas 'comment' => str_random(), // << NO CAPTCHA FIELD ]; - $this->assertDatabaseMissing('blog_etc_comments', ['author_name' => $comment_detail['author_name']]); - $response = $this->post(config("blogetc.blog_prefix", "blog") . "/save_comment/" . $new_object_vals['slug'], $comment_detail); + $this->assertDatabaseMissing('binshops_comments', ['author_name' => $comment_detail['author_name']]); + $response = $this->post(config("binshopsblog.blog_prefix", "blog") . "/save_comment/" . $new_object_vals['slug'], $comment_detail); $response->assertStatus(302); - $this->assertDatabaseMissing('blog_etc_comments', ['author_name' => $comment_detail['author_name']]); + $this->assertDatabaseMissing('binshops_comments', ['author_name' => $comment_detail['author_name']]); } @@ -448,14 +445,14 @@ public function testCreatePostThenSetCommentsToDisabledAndCheckNoneShow() { - \Config::set('blogetc.comments.type_of_comments_to_show', "disabled"); + \Config::set('binshopsblog.comments.type_of_comments_to_show', "disabled"); $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); - $newblogpost = new \WebDevEtc\BlogEtc\Models\BlogEtcPost; + $newblogpost = new \BinshopsBlog\Models\BinshopsPost; $newblogpost->title=__METHOD__ . " " . time(); @@ -480,14 +477,14 @@ public function testCreatePostThenSetCommentsToDisabledAndCheckNoneShow() } public function testCreatePostThenSetCommentsToDisqusAndCheckDisqusJSIsShown() { - \Config::set('blogetc.comments.type_of_comments_to_show', "disqus"); + \Config::set('binshopsblog.comments.type_of_comments_to_show', "disqus"); $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); - $newblogpost = new \WebDevEtc\BlogEtc\Models\BlogEtcPost; + $newblogpost = new \BinshopsBlog\Models\BinshopsPost; $newblogpost->title=__METHOD__ . " " . time(); @@ -510,14 +507,14 @@ public function testCreatePostThenSetCommentsToCustomAndCheckCustomErrorShows() { - \Config::set('blogetc.comments.type_of_comments_to_show', "custom"); + \Config::set('binshopsblog.comments.type_of_comments_to_show', "custom"); $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); - $newblogpost = new \WebDevEtc\BlogEtc\Models\BlogEtcPost; + $newblogpost = new \BinshopsBlog\Models\BinshopsPost; $newblogpost->title=__METHOD__ . " " . time(); @@ -541,16 +538,16 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveCommentWithBas { - \Config::set('blogetc.comments.auto_approve_comments', false); - \Config::set('blogetc.captcha.captcha_enabled', true); - \Config::set('blogetc.captcha.captcha_type', \WebDevEtc\BlogEtc\Captcha\Basic::class); - $captcha = new \WebDevEtc\BlogEtc\Captcha\Basic(); - \Config::set('blogetc.captcha.basic_question', "a test question"); - \Config::set('blogetc.captcha.basic_answers', "answer1,answer2"); + \Config::set('binshopsblog.comments.auto_approve_comments', false); + \Config::set('binshopsblog.captcha.captcha_enabled', true); + \Config::set('binshopsblog.captcha.captcha_type', \BinshopsBlog\Captcha\Basic::class); + $captcha = new \BinshopsBlog\Captcha\Basic(); + \Config::set('binshopsblog.captcha.basic_question', "a test question"); + \Config::set('binshopsblog.captcha.basic_answers', "answer1,answer2"); $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); // to verify this was added to database. Use a different variable, so we can add things (like _token) and still be able to assertDatabaseHas later. @@ -566,10 +563,10 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveCommentWithBas $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); - \Config::set('blogetc.comments.type_of_comments_to_show', 'built_in'); + \Config::set('binshopsblog.comments.type_of_comments_to_show', 'built_in'); $comment_detail = [ @@ -578,28 +575,28 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveCommentWithBas 'comment' => str_random(), $captcha->captcha_field_name() => "AnsWer2", ]; - $this->assertDatabaseMissing('blog_etc_comments', ['author_name' => $comment_detail['author_name']]); - $response = $this->post(config("blogetc.blog_prefix", "blog") . "/save_comment/" . $new_object_vals['slug'], $comment_detail); + $this->assertDatabaseMissing('binshops_comments', ['author_name' => $comment_detail['author_name']]); + $response = $this->post(config("binshopsblog.blog_prefix", "blog") . "/save_comment/" . $new_object_vals['slug'], $comment_detail); $response->assertStatus(200); - \Config::set('blogetc.captcha.auto_approve_comments', false); + \Config::set('binshopsblog.captcha.auto_approve_comments', false); - $this->assertDatabaseHas('blog_etc_comments', ['approved' => false, 'author_name' => $comment_detail['author_name']]); + $this->assertDatabaseHas('binshops_comments', ['approved' => false, 'author_name' => $comment_detail['author_name']]); - $justAddedRow = \WebDevEtc\BlogEtc\Models\BlogEtcComment::withoutGlobalScopes()->where('author_name', $comment_detail['author_name'])->firstOrFail(); + $justAddedRow = \BinshopsBlog\Models\BinshopsComment::withoutGlobalScopes()->where('author_name', $comment_detail['author_name'])->firstOrFail(); - $response = $this->get(route("blogetc.admin.comments.index")); + $response = $this->get(route("binshopsblog.admin.comments.index")); $response->assertSee($justAddedRow->author_name); // approve it: - $response = $this->patch(route("blogetc.admin.comments.approve", $justAddedRow->id), [ + $response = $this->patch(route("binshopsblog.admin.comments.approve", $justAddedRow->id), [ '_token' => csrf_token(), ]); // check it was approved $response->assertStatus(302); - $this->assertDatabaseHas('blog_etc_comments', ['approved' => 1, 'author_name' => $justAddedRow->author_name]); + $this->assertDatabaseHas('binshops_comments', ['approved' => 1, 'author_name' => $justAddedRow->author_name]); } @@ -607,12 +604,12 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveCommentWithBas public function testCreatePostThenCheckCanCreateCommentThenApproveComment() { - \Config::set('blogetc.comments.auto_approve_comments', false); - \Config::set('blogetc.captcha.captcha_enabled', false); + \Config::set('binshopsblog.comments.auto_approve_comments', false); + \Config::set('binshopsblog.captcha.captcha_enabled', false); $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); // to verify this was added to database. Use a different variable, so we can add things (like _token) and still be able to assertDatabaseHas later. @@ -628,11 +625,11 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveComment() $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); - \Config::set('blogetc.comments.type_of_comments_to_show', 'built_in'); - \Config::set('blogetc.captcha.captcha_enabled', false); + \Config::set('binshopsblog.comments.type_of_comments_to_show', 'built_in'); + \Config::set('binshopsblog.captcha.captcha_enabled', false); $comment_detail = [ @@ -640,29 +637,29 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveComment() 'author_name' => str_random(), 'comment' => str_random(), ]; - $this->assertDatabaseMissing('blog_etc_comments', ['author_name' => $comment_detail['author_name']]); - $response = $this->post(config("blogetc.blog_prefix", "blog") . "/save_comment/" . $new_object_vals['slug'], $comment_detail); + $this->assertDatabaseMissing('binshops_comments', ['author_name' => $comment_detail['author_name']]); + $response = $this->post(config("binshopsblog.blog_prefix", "blog") . "/save_comment/" . $new_object_vals['slug'], $comment_detail); $response->assertStatus(200); - \Config::set('blogetc.captcha.auto_approve_comments', false); + \Config::set('binshopsblog.captcha.auto_approve_comments', false); - $this->assertDatabaseHas('blog_etc_comments', ['approved' => false, 'author_name' => $comment_detail['author_name']]); + $this->assertDatabaseHas('binshops_comments', ['approved' => false, 'author_name' => $comment_detail['author_name']]); - $justAddedRow = \WebDevEtc\BlogEtc\Models\BlogEtcComment::withoutGlobalScopes()->where('author_name', $comment_detail['author_name'])->firstOrFail(); + $justAddedRow = \BinshopsBlog\Models\BinshopsComment::withoutGlobalScopes()->where('author_name', $comment_detail['author_name'])->firstOrFail(); - $response = $this->get(route("blogetc.admin.comments.index")); + $response = $this->get(route("binshopsblog.admin.comments.index")); $response->assertSee($justAddedRow->author_name); // approve it: - $response = $this->patch(route("blogetc.admin.comments.approve", $justAddedRow->id), [ + $response = $this->patch(route("binshopsblog.admin.comments.approve", $justAddedRow->id), [ '_token' => csrf_token(), ]); // check it was approved $response->assertStatus(302); - $this->assertDatabaseHas('blog_etc_comments', ['approved' => 1, 'author_name' => $justAddedRow->author_name]); + $this->assertDatabaseHas('binshops_comments', ['approved' => 1, 'author_name' => $justAddedRow->author_name]); } @@ -670,12 +667,12 @@ public function testCreatePostThenCheckCanCreateCommentThenApproveComment() public function testCreatePostThenCheckCanCreateCommentThenDeleteComment() { - \Config::set('blogetc.comments.auto_approve_comments', false); - \Config::set('blogetc.captcha.captcha_enabled', false); + \Config::set('binshopsblog.comments.auto_approve_comments', false); + \Config::set('binshopsblog.captcha.captcha_enabled', false); $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); // to verify this was added to database. Use a different variable, so we can add things (like _token) and still be able to assertDatabaseHas later. @@ -691,43 +688,43 @@ public function testCreatePostThenCheckCanCreateCommentThenDeleteComment() $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); - if (config("blogetc.comments.type_of_comments_to_show") === 'built_in') { + if (config("binshopsblog.comments.type_of_comments_to_show") === 'built_in') { $comment_detail = [ '_token' => csrf_token(), 'author_name' => str_random(), 'comment' => str_random(), ]; - $this->assertDatabaseMissing('blog_etc_comments', ['author_name' => $comment_detail['author_name']]); - $response = $this->post(config("blogetc.blog_prefix", "blog") . "/save_comment/" . $new_object_vals['slug'], $comment_detail); + $this->assertDatabaseMissing('binshops_comments', ['author_name' => $comment_detail['author_name']]); + $response = $this->post(config("binshopsblog.blog_prefix", "blog") . "/save_comment/" . $new_object_vals['slug'], $comment_detail); $response->assertSessionHasNoErrors(); $response->assertStatus(200); - $this->assertDatabaseHas('blog_etc_comments', ['author_name' => $comment_detail['author_name']]); + $this->assertDatabaseHas('binshops_comments', ['author_name' => $comment_detail['author_name']]); - $justAddedRow = \WebDevEtc\BlogEtc\Models\BlogEtcComment::withoutGlobalScopes()->where('author_name', $comment_detail['author_name'])->firstOrFail(); + $justAddedRow = \BinshopsBlog\Models\BinshopsComment::withoutGlobalScopes()->where('author_name', $comment_detail['author_name'])->firstOrFail(); // check the just added row exists... - $response = $this->get(route("blogetc.admin.comments.index")); + $response = $this->get(route("binshopsblog.admin.comments.index")); $response->assertSee($justAddedRow->author_name); // delete it: - $response = $this->delete(route("blogetc.admin.comments.delete", $justAddedRow->id), [ + $response = $this->delete(route("binshopsblog.admin.comments.delete", $justAddedRow->id), [ '_token' => csrf_token(), ]); // check it was deleted (it will deleted if approved) $response->assertStatus(302); //check it doesnt exist in database - $this->assertDatabaseMissing('blog_etc_comments', ['id' => $justAddedRow->id,]); + $this->assertDatabaseMissing('binshops_comments', ['id' => $justAddedRow->id,]); } else { - dump("NOT TESTING COMMENT FEATURE, as config(\"blogetc.comments.type_of_comments_to_show\") is not set to 'built_in')"); + dump("NOT TESTING COMMENT FEATURE, as config(\"binshopsblog.comments.type_of_comments_to_show\") is not set to 'built_in')"); } } @@ -739,9 +736,9 @@ public function testCanCreateThenDeletePost() $user = $this->create_admin_user(); - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); - $this->assertTrue($user->canManageBlogEtcPosts()); + $this->assertTrue($user->canManageBinshopsBlogPosts()); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); @@ -754,30 +751,30 @@ public function testCanCreateThenDeletePost() $new_object_vals['_token'] = csrf_token(); - $this->assertDatabaseMissing('blog_etc_posts', $search_for_obj); + $this->assertDatabaseMissing('binshops_posts', $search_for_obj); $response = $this->post($admin_panel_url . "/add_post", $new_object_vals); $response->assertSessionHasNoErrors(); $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_posts', $search_for_obj); + $this->assertDatabaseHas('binshops_posts', $search_for_obj); - $justCreatedRow = \WebDevEtc\BlogEtc\Models\BlogEtcPost::where("slug", $new_object_vals['slug'])->firstOrFail(); + $justCreatedRow = \BinshopsBlog\Models\BinshopsPost::where("slug", $new_object_vals['slug'])->firstOrFail(); $id = $justCreatedRow->id; $delete_url = $admin_panel_url . "/delete_post/" . $id; $response = $this->delete($delete_url, ['_token' => csrf_token()]); $response->assertStatus(200); - $this->assertDatabaseMissing('blog_etc_posts', $search_for_obj); + $this->assertDatabaseMissing('binshops_posts', $search_for_obj); } public function testCanCreateCategory() { - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); $this->create_admin_user(); // now lets create a category $new_cat_vals = [ @@ -786,11 +783,11 @@ public function testCanCreateCategory() ]; $search_for_new_cat = $new_cat_vals; $new_cat_vals['_token'] = csrf_token(); - $this->assertDatabaseMissing('blog_etc_categories', $search_for_new_cat); + $this->assertDatabaseMissing('binshops_categories', $search_for_new_cat); $response = $this->post($admin_panel_url . "/categories/add_category", $new_cat_vals); $response->assertSessionHasNoErrors(); $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_categories', $search_for_new_cat); + $this->assertDatabaseHas('binshops_categories', $search_for_new_cat); } @@ -800,7 +797,7 @@ public function testCanCreateCategoryThenEditIt() { - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); $this->create_admin_user(); @@ -814,15 +811,15 @@ public function testCanCreateCategoryThenEditIt() // create a post so we can edit it later $search_for_new_cat = $new_cat_vals; $new_cat_vals['_token'] = csrf_token(); - $this->assertDatabaseMissing('blog_etc_categories', $search_for_new_cat); + $this->assertDatabaseMissing('binshops_categories', $search_for_new_cat); $response = $this->post($admin_panel_url . "/categories/add_category", $new_cat_vals); $response->assertSessionHasNoErrors(); $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_categories', $search_for_new_cat); + $this->assertDatabaseHas('binshops_categories', $search_for_new_cat); // get the just inserted row - $justCreatedRow = \WebDevEtc\BlogEtc\Models\BlogEtcCategory::where("slug", $new_cat_vals['slug'])->firstOrFail(); + $justCreatedRow = \BinshopsBlog\Models\BinshopsCategory::where("slug", $new_cat_vals['slug'])->firstOrFail(); // get the edit page (form) @@ -837,12 +834,12 @@ public function testCanCreateCategoryThenEditIt() $new_object_vals['_token'] = csrf_token(); - $this->assertDatabaseMissing('blog_etc_categories', ['category_name' => $new_object_vals['category_name']]); + $this->assertDatabaseMissing('binshops_categories', ['category_name' => $new_object_vals['category_name']]); // send the request to save the changes $response = $this->patch( - route("blogetc.admin.categories.update_category", $justCreatedRow->id), + route("binshopsblog.admin.categories.update_category", $justCreatedRow->id), $new_object_vals ); @@ -850,7 +847,7 @@ public function testCanCreateCategoryThenEditIt() $response->assertStatus(302); // check it was a redirect // check that the edited category name is in the database. - $this->assertDatabaseHas('blog_etc_categories', ['slug' => $new_object_vals['slug'], 'category_name' => $new_object_vals['category_name']]); + $this->assertDatabaseHas('binshops_categories', ['slug' => $new_object_vals['slug'], 'category_name' => $new_object_vals['category_name']]); } @@ -858,7 +855,7 @@ public function testCanCreateCategoryThenEditIt() public function testCanDeleteCategory() { - $admin_panel_url = config("blogetc.admin_prefix", "blog_admin"); + $admin_panel_url = config("binshopsblog.admin_prefix", "blog_admin"); $this->create_admin_user(); // now lets create a category $new_cat_vals = [ @@ -867,21 +864,21 @@ public function testCanDeleteCategory() ]; $search_for_new_cat = $new_cat_vals; $new_cat_vals['_token'] = csrf_token(); - $this->assertDatabaseMissing('blog_etc_categories', $search_for_new_cat); + $this->assertDatabaseMissing('binshops_categories', $search_for_new_cat); $response = $this->post($admin_panel_url . "/categories/add_category", $new_cat_vals); $response->assertSessionHasNoErrors(); $response->assertStatus(302); // redirect - $this->assertDatabaseHas('blog_etc_categories', $search_for_new_cat); + $this->assertDatabaseHas('binshops_categories', $search_for_new_cat); - $justCreatedRow = \WebDevEtc\BlogEtc\Models\BlogEtcCategory::where("slug", $new_cat_vals['slug'])->firstOrFail(); + $justCreatedRow = \BinshopsBlog\Models\BinshopsCategory::where("slug", $new_cat_vals['slug'])->firstOrFail(); $id = $justCreatedRow->id; $delete_url = $admin_panel_url . "/categories/delete_category/$id"; $response = $this->delete($delete_url, ['_token' => csrf_token()]); $response->assertStatus(200); - $this->assertDatabaseMissing('blog_etc_categories', $search_for_new_cat); + $this->assertDatabaseMissing('binshops_categories', $search_for_new_cat); } @@ -914,7 +911,7 @@ protected function create_admin_user() $user = $this->getMockBuilder(\App\User::class) ->getMock(); // make sure the user can see admin panel - $user->method("canManageBlogEtcPosts") + $user->method("canManageBinshopsBlogPosts") ->will($this->returnCallback(function () { return true; })); @@ -942,7 +939,7 @@ protected function prepare_post_creation() { $user = $this->create_admin_user(); - $this->assertTrue($user->canManageBlogEtcPosts()); + $this->assertTrue($user->canManageBinshopsBlogPosts()); $new_object_vals = $this->generate_basic_blog_post_with_random_data(); @@ -955,30 +952,30 @@ protected function prepare_post_creation() $new_object_vals['_token'] = csrf_token(); - $this->assertDatabaseMissing('blog_etc_posts', $search_for_obj); + $this->assertDatabaseMissing('binshops_posts', $search_for_obj); // check we don't see it at moment - $response = $this->get(config("blogetc.blog_prefix", "blog")); + $response = $this->get(config("binshopsblog.blog_prefix", "blog")); $response->assertDontSee($new_object_vals['slug']); return array($new_object_vals, $search_for_obj); } - public function testUserModelHasCanManageBlogEtcPostsMethod() + public function testUserModelHasCanManageBinshopsBlogPostsMethod() { $u = new \App\User(); - $this->assertTrue(method_exists($u,"canManageBlogEtcPosts"),"canManageBlogEtcPosts() must be added to User model. Please see WebDevEtc BlogEtc docs for details. It should return true ONLY for the admin users"); + $this->assertTrue(method_exists($u,"canManageBinshopsBlogPosts"),"canManageBinshopsBlogPosts() must be added to User model. Please see binshops BinshopsBlog docs for details. It should return true ONLY for the admin users"); } - public function testUserModelCanManageBlogEtcPostsMethodDoesntAlwaysReturnTrue() + public function testUserModelCanManageBinshopsBlogPostsMethodDoesntAlwaysReturnTrue() { $u = new \App\User(); - $u->id = 9999999; // in case the logic on canManageBlogEtcPosts() checks for a low ID + $u->id = 9999999; // in case the logic on canManageBinshopsBlogPosts() checks for a low ID $u->email = str_random(); // in case the logic looks for a certain email or something. - $this->assertTrue(method_exists($u,"canManageBlogEtcPosts")); + $this->assertTrue(method_exists($u,"canManageBinshopsBlogPosts")); // because this user is just a randomly made one, it probably should not be allowed to edit blog posts. - $this->assertFalse($u->canManageBlogEtcPosts(), "User::canManageBlogEtcPosts() returns true, but it PROBABLY should return false! Otherwise every single user on your site has access to the blog admin panel! This might not be an error though, if your system doesn't allow public registration. But you should look into this. I know this isn't a good way to handle this test, but it seems to make sense."); + $this->assertFalse($u->canManageBinshopsBlogPosts(), "User::canManageBinshopsBlogPosts() returns true, but it PROBABLY should return false! Otherwise every single user on your site has access to the blog admin panel! This might not be an error though, if your system doesn't allow public registration. But you should look into this. I know this isn't a good way to handle this test, but it seems to make sense."); }