Skip to content

Commit 0f71d2d

Browse files
author
Igor Chepurnoy
authored
Merge pull request #15 from yii2mod/add_markdown_support
add markdown support, create cms module, update README
2 parents 3993b84 + 1aeee02 commit 0f71d2d

18 files changed

+414
-240
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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
* @see https://github.com/NextStepWebs/simplemde-markdown-editor#configuration
41+
*/
42+
public $markdownEditorOptions = [
43+
'showIcons' => ['code', 'table'],
44+
];
45+
}

README.md

Lines changed: 113 additions & 121 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,39 +33,35 @@ 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

63-
2) Add new Rule class to the `urlManager` array in your application configuration by the following code:
62+
**Configure Url Manager**
63+
64+
You need to configure the `urlManager` array in your application configuration:
6465

6566
```php
6667
'components' => [
@@ -72,122 +73,113 @@ $ php yii migrate --migrationPath=@vendor/yii2mod/yii2-cms/migrations
7273
],
7374
```
7475

75-
3) Add to SiteController (or configure via `$route` param in `urlManager`):
76+
**Setup Page Action**
77+
78+
Add to SiteController (or configure via `$route` param in `urlManager`):
79+
7680
```php
7781
public function actions()
7882
{
7983
return [
8084
'page' => [
8185
'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-
]
9986
]
10087
];
10188
}
10289
```
103-
> And now you can create your own pages via admin panel.
90+
**Now you can use this module with all available features.**
10491

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:
92+
## Features:
10993

94+
1. Markdown Editor support:
11095
```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-
],
96+
'modules' => [
97+
'cms' => [
98+
'class' => 'yii2mod\cms\Module',
99+
'enableMarkdown' => true,
100+
// List of options: https://github.com/NextStepWebs/simplemde-markdown-editor#configuration
101+
'markdownEditorOptions' => [
102+
'showIcons' => ['code', 'table'],
121103
],
122-
// ...
123104
],
124-
// ...
125-
];
105+
],
126106
```
127107

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:
108+
2. You can insert your own widget on the page by the following steps:
109+
110+
- Create the widget, for example:
111+
112+
```php
113+
namespace app\widgets;
114+
115+
use yii\base\Widget;
116+
117+
class MyWidget extends Widget
118+
{
119+
/**
120+
* @inheritdoc
121+
*/
122+
public function run()
123+
{
124+
parent::run();
125+
126+
echo 'Text from widget';
127+
}
128+
129+
/**
130+
* This function used for render the widget
131+
*
132+
* @return string
133+
*/
134+
public static function show()
135+
{
136+
return self::widget();
137+
}
138+
}
139+
```
170140

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:
141+
- When you create the page via admin panel add the following code to the page content:
142+
143+
```
144+
[[\app\widgets\MyWidget:show]]
145+
```
146+
147+
3. You can use parameters in your page content, for example: {siteName}, {homeUrl}. For parsing this parameters you can use the `baseTemplateParams` property:
148+
149+
```php
150+
public function actions()
151+
{
152+
return [
153+
'page' => [
154+
'class' => 'yii2mod\cms\actions\PageAction',
155+
'baseTemplateParams' => [
156+
'homeUrl' => 'your site home url',
157+
'siteName' => Yii::$app->name
158+
]
159+
],
160+
];
161+
}
162+
```
163+
164+
4. You can change comments module settings by the following code:
175165

176166
```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-
}
167+
public function actions()
168+
{
169+
return [
170+
'page' => [
171+
'class' => 'yii2mod\cms\actions\PageAction',
172+
'commentWidgetParams' => [
173+
'maxLevel' => 1,
174+
'dataProviderConfig' => [
175+
'pagination' => [
176+
'pageSize' => 10
177+
],
178+
],
179+
]
180+
]
181+
];
182+
}
193183
```
184+
185+
> For detail information about comments module please visit the following [page](https://github.com/yii2mod/yii2-comments)

0 commit comments

Comments
 (0)