Skip to content

Commit

Permalink
reformat code, add FA, category urls
Browse files Browse the repository at this point in the history
  • Loading branch information
akiraz2 committed Sep 21, 2018
1 parent f0c6953 commit d295366
Show file tree
Hide file tree
Showing 58 changed files with 297 additions and 366 deletions.
15 changes: 8 additions & 7 deletions Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,35 @@ public function bootstrap($app)
// Add module URL rules.
$app->getUrlManager()->addRules(
[
'<_m:blog>' => '<_m>/default/index',
'<_m:blog>/cat/<category_id:\d+>-<slug:[a-zA-Z0-9_-]{1,100}+>' => '<_m>/default/index',
'<_m:blog>/<id:\d+>-<slug:[a-zA-Z0-9_-]{1,100}+>' => '<_m>/default/view',
'<_m:blog>' => '<_m>/default/index',
]
);

// Add module I18N category.
if (!isset($app->i18n->translations['akiraz2/blog'])) {
$app->i18n->translations['akiraz2/blog'] = [
'class' => PhpMessageSource::class,
'basePath' => __DIR__ .'/messages',
'basePath' => __DIR__ . '/messages',
'forceTranslation' => true,
'fileMap' => [
'akiraz2/blog' => 'blog.php',
]
];
}
// Add redactor module if not exist (in my case - only in backend)
$redactorModule= $this->getModule()->redactorModule;
if($this->getModule()->getIsBackend() && !$app->hasModule($redactorModule)) {
$app->setModule($redactorModule,[
$redactorModule = $this->getModule()->redactorModule;
if ($this->getModule()->getIsBackend() && !$app->hasModule($redactorModule)) {
$app->setModule($redactorModule, [
'class' => 'yii\redactor\RedactorModule',
'imageUploadRoute' => ['/blog/upload/image'],
'uploadDir' => $this->getModule()->imgFilePath .'/upload/',
'uploadDir' => $this->getModule()->imgFilePath . '/upload/',
'uploadUrl' => $this->getModule()->getImgFullPathUrl() . '/upload',
'imageAllowExtensions' => ['jpg', 'png', 'gif', 'svg']
]);
}

\Yii::setAlias('@akiraz2', \Yii::getAlias('@vendor') . '/akiraz2');
}
}
14 changes: 7 additions & 7 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

namespace akiraz2\blog;

use Yii;
use yii\i18n\PhpMessageSource;

class Module extends \yii\base\Module
{
Expand All @@ -30,7 +30,7 @@ class Module extends \yii\base\Module
public $schemaOrg = [];

/** @var string Name of Component for editing posts */
public $redactorModule= 'redactorBlog';
public $redactorModule = 'redactorBlog';

/** @var linked user (for example, 'common\models\User::class' */
public $userModel;// = \common\models\User::class;
Expand All @@ -41,6 +41,8 @@ class Module extends \yii\base\Module
/** @var string username uses in view (may be field `username` or `email` or `login`) */
public $userName = 'username';

public $blogTheme;

protected $_isBackend;

/**
Expand All @@ -52,9 +54,6 @@ public function init()

if ($this->getIsBackend() === true) {
$this->setViewPath('@akiraz2/blog/views/backend');
} elseif (isset(Yii::$app->params['blogTheme'])) {
$this->setViewPath('@frontend/themes/blog');
$this->setLayoutPath('@frontend/themes/blog/layouts');
} else {
$this->setViewPath('@akiraz2/blog/views/frontend');
$this->setLayoutPath('@akiraz2/blog/views/frontend/layouts');
Expand Down Expand Up @@ -111,7 +110,8 @@ public function getIsBackend()
*
* @return string
*/
public function getImgFullPathUrl() {
return \Yii::$app->get($this->urlManager)->getHostInfo().$this->imgFileUrl;
public function getImgFullPathUrl()
{
return \Yii::$app->get($this->urlManager)->getHostInfo() . $this->imgFileUrl;
}
}
70 changes: 37 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Config *common* modules in `common/config/main.php`
'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`)
'userPK' => 'id', //default primary key for {{%user}} table
'userName' => 'username', //uses in view (may be field `username` or `email` or `login`)
],
],
```
Expand Down Expand Up @@ -115,7 +115,7 @@ Config *frontend modules* in `frontend/config/main.php`
'controllerNamespace' => 'akiraz2\blog\controllers\frontend',
'blogPostPageCount' => 6,
'blogCommentPageCount' => 10, //20 by default
'enableComments' => true, //true by default
'enableComments' => true, //false by default
'schemaOrg' => [ // empty array [] by default!
'publisher' => [
'logo' => '/img/logo.png',
Expand All @@ -133,7 +133,7 @@ Config *frontend modules* in `frontend/config/main.php`
### Migration

> **NOTE:** Module uses table `{{%user}}` with PK `id`. Make sure you have table before applying these migrations.
> **NOTE:** Module uses table `{{%user}}` with PK `id` (You can use [own user model](#user-model) with table and PK) Make sure you have table before applying these migrations.
Migration run after config module

Expand All @@ -157,9 +157,10 @@ or full path:
2. frontend : http://you-domain.com/blog



## Usage

**Overriding views**
### 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
Expand All @@ -185,12 +186,29 @@ if a view exists in the theme directory it will be used instead of the original
> **NOTE:** Just copy all necessary views from `@akiraz2/yii2-blog/views/frontend/default` to `@app/views/blog` and change!

### User model

You can use own user model, but need configure it in config.php

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`)
],
],
```

### Imperavi Redactor

**How to change upload path Imperavi Redactor widget**

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

> **NOTE:** Embedded Module `redactorBlog` use own UploadController with AccessControl! and only in Backend! and only you dont override default config
> **NOTE:** Embedded Module `redactorBlog` use own UploadController with AccessControl! and only in Backend! and only you don`t override default config
If you want change default config, you should add redactor module manually

Expand All @@ -213,28 +231,7 @@ Config backend modules in backend/config/main.php
```


**How to change captcha in Comments**

Not yet... If you are using Recaptcha2 in your project with my yii2-blog, please PR me!

**User model**

Module Yii2-Blog use `common\models\User`, so if you use custom user component or Module like
[dektrium/yii2-user](https://github.com/dektrium/yii2-user), you should create model under path `common\models\User` with overriding your user-model.

For example,
```php
namespace common\models;

use dektrium\user\models\User as BaseUser;

class User extends BaseUser
{

}
```

**CustomAdminAccessControl for backend**
### CustomAdminAccessControl for backend

For example, using [dektrium/yii2-user](https://github.com/dektrium/yii2-user)

Expand Down Expand Up @@ -272,7 +269,7 @@ Create file `common\components\AdminAccessControl.php`
}
```

**Opengraph**
### Opengraph

Please, add component [dragonjet/yii2-opengraph](https://packagist.org/packages/dragonjet/yii2-opengraph) to your project.
```
Expand All @@ -289,14 +286,21 @@ Configuration `common/config/main.php` or `frontend/config/main.php`
//....
],
```



**How to change captcha in Comments**

Not yet... If you are using Recaptcha2 in your project with my yii2-blog, please PR me!
By default, we use [Math captcha](https://github.com/lesha724/yii2-math-captcha)

## TODO

* refactoring code (specially BlogCategory, BlogTag)
* create widgets
* translate to languages
* 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

Expand Down
1 change: 1 addition & 0 deletions assets/AppAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ class AppAsset extends AssetBundle
];
public $depends = [
'yii\bootstrap\BootstrapAsset',
'\rmrevin\yii\fontawesome\AssetBundle'
];
}
5 changes: 1 addition & 4 deletions assets/default/css/blog-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
max-width: initial;*/
}
.blog-brief__img::after {
content:'';
content: '';
position: absolute;
top: 0;
left: 0;
Expand Down Expand Up @@ -226,9 +226,6 @@
border-radius: 2px;
padding: 35px 35px;




}
.blog-comments__header {
border-bottom: 1px solid #eee;
Expand Down
55 changes: 5 additions & 50 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,60 +23,15 @@
],
"require": {
"yiisoft/yii2": "*",
"mihaildev/yii2-ckeditor": "*",
"yiidoc/yii2-redactor": "*",
"yii-dream-team/yii2-upload-behavior": "*",
"lesha724/yii2-math-captcha": "*"
"yii-dream-team/yii2-upload-behavior": "dev-master",
"lesha724/yii2-math-captcha": "*",
"rmrevin/yii2-fontawesome": "~2.17"
},
"repositories": [
{
"type": "package",
"package": {
"name": "yii-dream-team/yii2-upload-behavior",
"type": "yii2-extension",
"description": "Yii2 file/image upload behavior for ActiveRecord",
"keywords": [
"file",
"image",
"upload",
"behavior",
"resize",
"thumb"
],
"license": "MIT",
"homepage": "http://yiidreamteam.com/yii2/upload-behavior",
"authors": [
{
"name": "Alexey Samoylov",
"email": "alexey.samoylov@gmail.com",
"homepage": "http://yiidreamteam.com/team/alexey",
"role": "Developer"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=7.1.0",
"yiisoft/yii2": "*",
"masterexploder/phpthumb": "*"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/yii-dream-team/PHPThumb"
}
],
"autoload": {
"psr-4": {
"yiidreamteam\\upload\\": "./src"
}
},
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/akiraz2/yii2-upload-behavior",
"reference": "master"
}
}
"type": "vcs",
"url": "https://github.com/akiraz2/yii2-translateable"
}
],
"autoload": {
Expand Down
14 changes: 7 additions & 7 deletions controllers/backend/BaseAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
namespace akiraz2\blog\controllers\backend;

use akiraz2\blog\traits\ModuleTrait;
use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use dektrium\user\filters\AccessRule;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;

class BaseAdminController extends Controller {
class BaseAdminController extends Controller
{

use ModuleTrait;

/**
* @inheritdoc
*/
public function behaviors() {
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::class,
Expand All @@ -35,7 +35,7 @@ public function behaviors() {

public function init()
{
if($this->module->adminAccessControl) {
if ($this->module->adminAccessControl) {
$this->attachBehavior('access', [
'class' => $this->module->adminAccessControl,
]);
Expand Down
2 changes: 1 addition & 1 deletion controllers/backend/BlogCategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function actionCreate()
{
$model = new BlogCategory();

if (Yii::$app->request->get('parent_id')>0) {
if (Yii::$app->request->get('parent_id') > 0) {
$model->parent_id = Yii::$app->request->get('parent_id');
}

Expand Down
5 changes: 1 addition & 4 deletions controllers/backend/BlogPostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
use akiraz2\blog\models\Status;
use akiraz2\blog\traits\IActiveStatus;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\NotFoundHttpException;

/**
Expand All @@ -29,7 +26,7 @@ class BlogPostController extends BaseAdminController
public function actionIndex()
{
$searchModel = new BlogPostSearch();
$searchModel->scenario= BlogPostSearch::SCENARIO_ADMIN;
$searchModel->scenario = BlogPostSearch::SCENARIO_ADMIN;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$arrayCategory = BlogPost::getArrayCategory();

Expand Down
4 changes: 0 additions & 4 deletions controllers/backend/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

namespace akiraz2\blog\controllers\backend;

use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\web\Controller;

class DefaultController extends BaseAdminController
{
public function actionIndex()
Expand Down
Loading

0 comments on commit d295366

Please sign in to comment.