Skip to content

Commit f8cf0af

Browse files
author
Igor Chepurnoy
committed
add markdown support, create cms module, update Readme
1 parent 3993b84 commit f8cf0af

18 files changed

+553
-229
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
language: php
22

33
php:
4-
- 5.5
5-
- 5.6
6-
- 7.0
4+
- 7.1
75

86
# faster builds on new travis setup not using sudo
97
sudo: false
@@ -16,7 +14,7 @@ cache:
1614

1715
install:
1816
- travis_retry composer self-update && composer --version
19-
- travis_retry composer global require "fxp/composer-asset-plugin:~1.1.1"
17+
- travis_retry composer global require "fxp/composer-asset-plugin:^1.2.0"
2018
- export PATH="$HOME/.composer/vendor/bin:$PATH"
2119
- travis_retry composer install --prefer-dist --no-interaction
2220

Bootstrap.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace yii2mod\cms;
4+
5+
use yii\base\BootstrapInterface;
6+
7+
/**
8+
* Class Bootstrap
9+
*
10+
* @package yii2mod\cms
11+
*/
12+
class Bootstrap implements BootstrapInterface
13+
{
14+
/**
15+
* @inheritdoc
16+
*/
17+
public function bootstrap($app)
18+
{
19+
if (!isset($app->get('i18n')->translations['yii2mod.cms'])) {
20+
$app->get('i18n')->translations['yii2mod.cms'] = [
21+
'class' => 'yii\i18n\PhpMessageSource',
22+
'basePath' => '@yii2mod/cms/messages',
23+
];
24+
}
25+
26+
if ($app->getModule('comment') === null) {
27+
$app->setModule('comment', ['class' => 'yii2mod\comments\Module']);
28+
}
29+
}
30+
}

Module.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace yii2mod\cms;
4+
5+
/**
6+
* Class Module
7+
*
8+
* @package yii2mod\cms
9+
*/
10+
class Module extends \yii\base\Module
11+
{
12+
/**
13+
* @var string the namespace that controller classes are in
14+
*/
15+
public $controllerNamespace = 'yii2mod\cms\controllers';
16+
17+
/**
18+
* @var string the default route of this module
19+
*/
20+
public $defaultRoute = 'manage';
21+
22+
/**
23+
* @var array imperavi editor options
24+
*/
25+
public $imperaviEditorOptions = [
26+
'plugins' => ['video', 'fullscreen', 'table'],
27+
'options' => [
28+
'minHeight' => 200,
29+
],
30+
];
31+
32+
/**
33+
* @var bool whether to enable the markdown editor and markdown converter
34+
*/
35+
public $enableMarkdown = false;
36+
37+
/**
38+
* @var array markdown editor options
39+
*/
40+
public $markdownEditorOptions = [
41+
'showIcons' => ['code', 'table'],
42+
];
43+
}

README.md

Lines changed: 82 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CMS Extension
22
========================
3-
Base content management system for Yii Framework 2.0
3+
This module provides a web interface for content management system and includes following features:
4+
5+
- Allows CRUD operations for pages
6+
- [Support Markdown Editor](https://github.com/yii2mod/yii2-markdown)
7+
- [Support Comments Management System](https://github.com/yii2mod/yii2-comments)
8+
- Integrated with [yii2mod/base](https://github.com/yii2mod/base)
49

510
[![Latest Stable Version](https://poser.pugx.org/yii2mod/yii2-cms/v/stable)](https://packagist.org/packages/yii2mod/yii2-cms) [![Total Downloads](https://poser.pugx.org/yii2mod/yii2-cms/downloads)](https://packagist.org/packages/yii2mod/yii2-cms) [![License](https://poser.pugx.org/yii2mod/yii2-cms/license)](https://packagist.org/packages/yii2mod/yii2-cms)
611
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yii2mod/yii2-cms/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yii2mod/yii2-cms/?branch=master) [![Build Status](https://travis-ci.org/yii2mod/yii2-cms.svg?branch=master)](https://travis-ci.org/yii2mod/yii2-cms)
@@ -13,13 +18,13 @@ The preferred way to install this extension is through [composer](http://getcomp
1318

1419
Either run
1520

16-
```
21+
```bash
1722
php composer.phar require --prefer-dist yii2mod/yii2-cms "*"
1823
```
1924

2025
or add
2126

22-
```json
27+
```
2328
"yii2mod/yii2-cms": "*"
2429
```
2530

@@ -28,36 +33,30 @@ to the require section of your composer.json.
2833

2934
CONFIGURATION
3035
------------
31-
> If you use this extension separate from the [base template](https://github.com/yii2mod/base), then you need execute migration by the following command:
36+
37+
**Database Migrations**
38+
39+
Before usage this extension, we'll also need to prepare the database.
40+
3241
```bash
42+
$ php yii migrate --migrationPath=@vendor/yii2mod/yii2-comments/migrations
3343
$ php yii migrate --migrationPath=@vendor/yii2mod/yii2-cms/migrations
3444
```
3545

36-
1) To use this extension first you need to configure the [comments extension](https://github.com/yii2mod/yii2-comments), after that you have to configure the main config in your application:
46+
**Module Setup**
47+
48+
To access the module, you need to configure the modules array in your application configuration:
49+
3750
```php
3851
'modules' => [
39-
'admin' => [
40-
'controllerMap' => [
41-
'cms' => 'yii2mod\cms\controllers\CmsController',
42-
// Also you can override some controller properties in following way:
43-
'cms' => [
44-
'class' => 'yii2mod\cms\controllers\CmsController',
45-
'searchClass' => [
46-
'class' => 'yii2mod\cms\models\search\CmsSearch',
47-
'pageSize' => 25
48-
],
49-
'modelClass' => 'Your own cms model class',
50-
'indexView' => 'custom path to index view file',
51-
'createView' => 'custom path to create view file',
52-
'updateView' => 'custom path to update view file',
53-
],
54-
],
52+
'cms' => [
53+
'class' => 'yii2mod\cms\Module',
5554
],
5655
],
5756
```
5857
> **You can then access to management section through the following URL:**
5958
60-
> http://localhost/path/to/index.php?r=admin/cms/index
59+
> http://localhost/path/to/index.php?r=/cms/manage/index
6160
6261

6362
2) Add new Rule class to the `urlManager` array in your application configuration by the following code:
@@ -79,115 +78,80 @@ public function actions()
7978
return [
8079
'page' => [
8180
'class' => 'yii2mod\cms\actions\PageAction',
82-
// Also you can override some action properties in following way:
83-
'layout' => 'your custom layout',
84-
'viewPath' => 'your custom view file',
85-
// You can set parameters that you want to parse before the page is loaded, for example:
86-
'baseTemplateParams' => [
87-
'homeUrl' => Yii::$app->homeUrl,
88-
'siteName' => Yii::$app->name
89-
],
90-
// some comment widget params
91-
'commentWidgetParams' => [
92-
'maxLevel' => 1,
93-
'dataProviderConfig' => [
94-
'pagination' => [
95-
'pageSize' => 5
96-
],
97-
],
98-
]
9981
]
10082
];
10183
}
10284
```
10385
> And now you can create your own pages via admin panel.
10486
105-
## Internationalization
106-
107-
All text and messages introduced in this extension are translatable under category 'yii2mod.cms'.
108-
You may use translations provided within this extension, using following application configuration:
87+
## Features:
10988

89+
1. Markdown Editor support:
11090
```php
111-
return [
112-
'components' => [
113-
'i18n' => [
114-
'translations' => [
115-
'yii2mod.cms' => [
116-
'class' => 'yii\i18n\PhpMessageSource',
117-
'basePath' => '@yii2mod/cms/messages',
118-
],
119-
// ...
120-
],
91+
'modules' => [
92+
'cms' => [
93+
'class' => 'yii2mod\cms\Module',
94+
'enableMarkdown' => true,
95+
// List of options: https://github.com/NextStepWebs/simplemde-markdown-editor#configuration
96+
'markdownEditorOptions' => [
97+
'showIcons' => ['code', 'table'],
12198
],
122-
// ...
12399
],
124-
// ...
125-
];
100+
],
126101
```
127102

128-
##Additional features:
129-
130-
1. You can insert your own widget on the page by the following steps:
131-
* Create the widget, for example:
132-
133-
```php
134-
<?php
135-
136-
namespace app\widgets;
137-
138-
use yii\base\Widget;
139-
140-
/**
141-
* Class MyWidget
142-
* @package app\widgets
143-
*/
144-
class MyWidget extends Widget
145-
{
146-
/**
147-
* @inheritdoc
148-
*/
149-
public function run()
150-
{
151-
parent::run();
152-
153-
echo 'Text from widget';
154-
}
155-
156-
/**
157-
* This function used for render the widget in the cms pages
158-
*
159-
* @return string
160-
*/
161-
public static function show()
162-
{
163-
return self::widget([
164-
// additional params
165-
]);
166-
}
167-
}
168-
```
169-
* When you create the page via admin panel add the following code to the page content:
103+
2. You can insert your own widget on the page by the following steps:
104+
105+
- Create the widget, for example:
106+
107+
```php
108+
namespace app\widgets;
109+
110+
use yii\base\Widget;
111+
112+
class MyWidget extends Widget
113+
{
114+
/**
115+
* @inheritdoc
116+
*/
117+
public function run()
118+
{
119+
parent::run();
120+
121+
echo 'Text from widget';
122+
}
123+
124+
/**
125+
* This function used for render the widget
126+
*
127+
* @return string
128+
*/
129+
public static function show()
130+
{
131+
return self::widget();
132+
}
133+
}
134+
```
135+
136+
- When you create the page via admin panel add the following code to the page content:
170137

171-
```
172-
[[\app\widgets\MyWidget:show]]
173-
```
174-
2. You can use parameters in your page content, for example: {siteName}, {homeUrl}. For parsing this parameters you can use the `baseTemplateParams` property:
138+
```
139+
[[\app\widgets\MyWidget:show]]
140+
```
141+
142+
3. You can use parameters in your page content, for example: {siteName}, {homeUrl}. For parsing this parameters you can use the `baseTemplateParams` property:
175143

176144
```php
177-
/**
178-
* @return array
179-
*/
180-
public function actions()
181-
{
182-
return [
183-
'page' => [
184-
'class' => 'yii2mod\cms\actions\PageAction',
185-
// You can set parameters that you want to parse before the page is loaded, for example:
186-
'baseTemplateParams' => [
187-
'homeUrl' => 'your site home url',
188-
'siteName' => Yii::$app->name
189-
]
190-
],
191-
];
192-
}
145+
public function actions()
146+
{
147+
return [
148+
'page' => [
149+
'class' => 'yii2mod\cms\actions\PageAction',
150+
'baseTemplateParams' => [
151+
'homeUrl' => 'your site home url',
152+
'siteName' => Yii::$app->name
153+
]
154+
],
155+
];
156+
}
193157
```

composer.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"type": "yii2-extension",
55
"keywords": [
66
"yii2",
7-
"extension"
7+
"yii2-cms",
8+
"yii2-cms-module"
89
],
910
"license": "MIT",
1011
"authors": [
@@ -18,13 +19,14 @@
1819
}
1920
],
2021
"require": {
21-
"php": ">=5.5",
22-
"yiisoft/yii2": "*",
22+
"php": ">=5.6",
23+
"yiisoft/yii2": "~2.0.11",
2324
"yii2mod/yii2-enum": "*",
24-
"asofter/yii2-imperavi-redactor": "*",
2525
"yii2mod/yii2-editable": "*",
26-
"yii2mod/yii2-toggle-column": "*",
27-
"yii2mod/yii2-comments": "*"
26+
"yii2mod/yii2-comments": "*",
27+
"yii2mod/yii2-markdown": "*",
28+
"asofter/yii2-imperavi-redactor": "*",
29+
"cebe/markdown": "~1.1.1"
2830
},
2931
"require-dev": {
3032
"friendsofphp/php-cs-fixer": "~2.0"
@@ -33,5 +35,8 @@
3335
"psr-4": {
3436
"yii2mod\\cms\\": ""
3537
}
38+
},
39+
"extra": {
40+
"bootstrap": "yii2mod\\cms\\Bootstrap"
3641
}
3742
}

0 commit comments

Comments
 (0)