2017 © Pedro Peláez
 

yii2-extension yii2-blog

Simple, configurable blog module for Yii2 (post, comment, nested category, tags). + frontend, backend. + SEO! (Opengraph, Schema.org)

image

akiraz2/yii2-blog

Simple, configurable blog module for Yii2 (post, comment, nested category, tags). + frontend, backend. + SEO! (Opengraph, Schema.org)

  • Wednesday, June 6, 2018
  • by akiraz2
  • Repository
  • 3 Watchers
  • 10 Stars
  • 150 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 5 Open issues
  • 9 Versions
  • 114 % Grown

The README.md

Yii2 Super Blog Packagist Version Total Downloads Software License

Yii2 Super Blog is simple, configured yii2 Module with frontend and backend, cloned from unmaintained repo funson86/yii2-blog, fully reorganized and improved., (*1)

Features:

  • Blog Post with image banner, seo tags, imperavi redactor 2 widget
  • Blog Category (nested) with image banner, seo tags
  • Blog Tags
  • Blog Comment (can be disabled), with Math captcha (can be standard yii2-captcha OR ReCaptcha2)
  • email in comments are masked (a*i*a*@bk.ru)
  • all models has Status (_Inactive_, Active, Archive)
  • Inactive comments are truncated (and strip tags)
  • also added semantic OpenGraph (via yii2 component dragonjet/yii2-opengraph), Schema.org
  • backendControllers can be protected by your CustomAccessControl (roles or rbac)
  • frontend and backend are translated (i18n)
  • url rules with slug (for seo)

NOTE: Module is in initial development. Anything may change at any time. Currently develop new version v2.0 with many improvements and for yii2basic template. @develop branch, (*2)

Table of Contents

  1. Installation
  2. Configuration
  3. Usage
  4. TODO
  5. Support
  6. Contributing

Installation

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

php composer.phar require --prefer-dist akiraz2/yii2-blog "~1.3"

or add, (*5)

"akiraz2/yii2-blog": "~1.3"

to the require section of your composer.json file., (*6)

** Note ** If you got composer Error it does not match your minimum-stability, please change your composer settings to "minimum-stability": "dev",, (*7)

Configuration

By default, all images from Imperavi-widget module are uploaded to dir @frontend/web/img/blog/upload. Be sure, this directory is created manually with proper file permissions (chmod)., (*8)

Add 'bootstrap' => [\akiraz2\blog\Bootstrap::class], to your config (common/config/main.php), (*9)

Config common modules in common/config/main.php, (*10)

    'modules' => [
        'blog' => [
            'class' => akiraz2\blog\Module::class,
            'urlManager' => 'urlManager',// 'urlManager' by default, or maybe you can use own component urlManagerFrontend
            'imgFilePath' => '@frontend/web/img/blog/',
            'imgFileUrl' => '/img/blog/',
            'userModel' => \common\models\User::class,
            'userPK' => 'id', //default primary key for {{%user}} table
            'userName' => 'username', //uses in view (may be field `username` or `email` or `login`)
        ],
     ],    

Config url rewrite in common/config/main.php (or separately frontend/backend apps), (*11)

    'timeZone' => 'Europe/Moscow', //time zone affect the formatter datetime format
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [               
            ],
        ],
        'formatter' => [ //for the showing of date datetime
            'dateFormat' => 'yyyy-MM-dd',
            'datetimeFormat' => 'yyyy-MM-dd HH:mm:ss',
            'decimalSeparator' => '.',
            'thousandSeparator' => ' ',
            'currencyCode' => 'EUR',
        ],
    ],

Config backend modules in backend/config/main.php, (*12)

    'modules' => [
        'blog' => [
            'class' => 'akiraz2\blog\Module',
            'controllerNamespace' => 'akiraz2\blog\controllers\backend',
            //'adminAccessControl' => 'common\components\AdminAccessControl', // null - by default 
        ],
    ],

Config frontend modules in frontend/config/main.php, (*13)

    //'defaultRoute' => 'blog', //set blog as default route
    'modules' => [
        'blog' => [
            'class' => 'akiraz2\blog\Module',
            'controllerNamespace' => 'akiraz2\blog\controllers\frontend',
            'blogPostPageCount' => 6,
            'blogCommentPageCount' => 10, //20 by default
            'enableComments' => true, //false by default
            'schemaOrg' => [ // empty array [] by default! 
                'publisher' => [
                    'logo' => '/img/logo.png',
                    'logoWidth' => 191,
                    'logoHeight' => 74,
                    'name' => 'My Company',
                    'phone' => '+1 800 488 80 85',
                    'address' => 'City, street, house'
                ]
            ]
        ],
    ],

NOTE: Module Yii2-Blog use model common\models\User, (*14)

Migration

NOTE: Module uses table {{%user}} with PK id (You can use own user model with table and PK) Make sure you have table before applying these migrations., (*15)

Migration run after config module, (*16)

./yii migrate --migrationPath=@akiraz2/blog/migrations

or full path:, (*17)

./yii migrate --migrationPath=@vendor/akiraz2/yii2-blog/migrations

Access Url

  1. backend : http://backend.you-domain.com/blog (Empty view)
    • Category : http://backend.you-domain.com/blog/blog-category (create first category)
    • Post : http://backend.you-domain.com/blog/blog-post
    • Comment : http://backend.you-domain.com/blog/blog-comment
    • Tag : http://backend.you-domain.com/blog/blog-tag
  2. frontend : http://you-domain.com/blog

Usage

Overriding views

When you start using Yii2-blog you will probably find that you need to override the default views provided by the module. Although view names are not configurable, Yii2 provides a way to override views using themes. To get started you should configure your view application component as follows:, (*18)

...
'components' => [
    'view' => [
        'theme' => [
            'pathMap' => [
                '@akiraz2/yii2-blog/views/frontend/default' => '@app/views/blog'
            ],
        ],
    ],
],
...

In the above pathMap means that every view in @akiraz2/yii2-blog/views/frontend/default will be first searched under @app/views/blog and if a view exists in the theme directory it will be used instead of the original view., (*19)

NOTE: Just copy all necessary views from @akiraz2/yii2-blog/views/frontend/default to @app/views/blog and change!, (*20)

User model

You can use own user model, but need configure it in config.php, (*21)

For example, php 'modules' => [ 'blog' => [ 'class' => akiraz2\blog\Module::class, 'userModel' => \common\models\User::class, 'userPK' => 'id', //default primary key for {{%user}} table 'userName' => 'username', //uses in view (may be field `username` or `email` or `login`) ], ],, (*22)

Imperavi Redactor

How to change upload path Imperavi Redactor widget, (*23)

Yii2 blog module use imperavi redactor 2 Module https://github.com/yiidoc/yii2-redactor with moduleName "redactorBlog"., (*24)

NOTE: Embedded Module redactorBlog use own UploadController with AccessControl! and only in Backend! and only you don`t override default config, (*25)

If you want change default config, you should add redactor module manually, (*26)

Config backend modules in backend/config/main.php, (*27)

php 'modules' => [ 'blog' => [ 'class' => 'akiraz2\blog\Module', 'controllerNamespace' => 'akiraz2\blog\controllers\backend', 'redactorModule' => 'redactor' // 'redactorBlog' - default, maybe you want use standard module 'redactor' with own config ], 'redactor' => [ 'class' => 'yii\redactor\RedactorModule', 'uploadDir' => '@frontend/web/img/upload/', 'uploadUrl' => $params['frontendHost'] . '/img/upload', 'imageAllowExtensions' => ['jpg', 'png', 'gif', 'svg'] ], ],, (*28)

CustomAdminAccessControl for backend

For example, using dektrium/yii2-user, (*29)

php 'modules' => [ 'blog' => [ 'class' => akiraz2\blog\Module::class, ... 'adminAccessControl' => 'common\components\AdminAccessControl', ... ], ],, (*30)

Create file common\components\AdminAccessControl.php, (*31)

```php namespace common\components;, (*32)

use yii\filters\AccessControl;

class AdminAccessControl extends AccessControl
{    
    public function init()
    {
        $this->rules[] =[
            'allow' => true,
            'roles' => ['@'],
            'matchCallback' => function () {
                return \Yii::$app->user->identity->getIsAdmin();
            }
        ];
        parent::init();
    }
}

```, (*33)

Opengraph

Please, add component dragonjet/yii2-opengraph to your project., (*34)

php composer.phar require --prefer-dist dragonjet/yii2-opengraph "dev-master"

Configuration common/config/main.php or frontend/config/main.php, (*35)

php 'components' => [ 'opengraph' => [ 'class' => 'dragonjet\opengraph\OpenGraph', ], //.... ],, (*36)

How to change captcha in Comments, (*37)

Not yet... If you are using Recaptcha2 in your project with my yii2-blog, please PR me! By default, we use Math captcha, (*38)

TODO

  • refactoring code (specially BlogCategory, BlogTag)
  • create widgets (for backend and frontend)
  • translate to many popular languages
  • create multilang models
  • change default design and styles for frontend blog
  • add config Captcha

Support

If you have any questions or problems with Yii2-Blog you can ask them directly by using following email address: akiraz@bk.ru., (*39)

Please translate to your language! Edit config (or copy to your path) @vendor/akiraz2/yii2-blog/src/messages/config.php, add your language and run script:, (*40)

php ./yii message/extract @akiraz2/blog/messages/config.php

translate file will be in @vendor/akiraz2/yii2-blog/src/messages/ or your configured path, (*41)

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome. +PSR-2 style coding. I can apply patch, PR in 2-3 days! If not, please write me akiraz@bk.ru, (*42)

Licensing

Yii2-Blog is released under the MIT License. See the bundled LICENSE.md for details., (*43)

The Versions

06/06 2018

dev-master

9999999-dev

Simple, configurable blog module for Yii2 (post, comment, nested category, tags). + frontend, backend. + SEO! (Opengraph, Schema.org)

  Sources   Download

MIT

The Requires

 

extension yii2 module comments seo tag post blog category yii2-blog

06/06 2018

1.2.3

1.2.3.0

Simple, configurable blog module for Yii2 (post, comment, nested category, tags). + frontend, backend. + SEO! (Opengraph, Schema.org)

  Sources   Download

MIT

The Requires

 

extension yii2 module comments seo tag post blog category yii2-blog

23/04 2018

1.2.2

1.2.2.0

Simple, configurable blog module for Yii2 (post, comment, nested category, tags). + frontend, backend. + SEO! (Opengraph, Schema.org)

  Sources   Download

MIT

The Requires

 

extension yii2 module comments seo tag post blog category yii2-blog

20/04 2018

1.2.1

1.2.1.0

Simple, configurable blog module for Yii2 (post, comment, nested category, tags). + frontend, backend. + SEO! (Opengraph, Schema.org)

  Sources   Download

MIT

The Requires

 

extension yii2 module comments seo tag post blog category yii2-blog

18/04 2018

1.2.0

1.2.0.0

Simple, configurable blog module for Yii2 (post, comment, nested category, tags). + frontend, backend. + SEO! (Opengraph, Schema.org)

  Sources   Download

MIT

The Requires

 

extension yii2 module comments seo tag post blog category yii2-blog

11/04 2018

1.1.3

1.1.3.0

Yii2 Blog for other application. Only for internal using. forked from funson86 and improved.

  Sources   Download

Apache-2.0

The Requires

 

extension yii2 module tag post blog category

10/04 2018

1.1.2

1.1.2.0

Yii2 Blog for other application. Only for internal using. forked from funson86 and improved.

  Sources   Download

Apache-2.0

The Requires

 

extension yii2 module tag post blog category

09/04 2018

1.1.1

1.1.1.0

Yii2 Blog for other application. Only for internal using. forked from funson86 and improved.

  Sources   Download

Apache-2.0

The Requires

 

extension yii2 module tag post blog category

08/04 2018

1.1.0

1.1.0.0

Yii2 Blog for other application. Only for internal using. forked from funson86 and improved.

  Sources   Download

Apache-2.0

The Requires

 

extension yii2 module tag post blog category