Skip to content

Commit

Permalink
Merge pull request #15 from yii2mod/add_markdown_support
Browse files Browse the repository at this point in the history
add markdown support, create cms module, update README
  • Loading branch information
Igor Chepurnoy committed Apr 17, 2017
2 parents 3993b84 + 1aeee02 commit 0f71d2d
Show file tree
Hide file tree
Showing 18 changed files with 414 additions and 240 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1

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

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

Expand Down
30 changes: 30 additions & 0 deletions Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace yii2mod\cms;

use yii\base\BootstrapInterface;

/**
* Class Bootstrap
*
* @package yii2mod\cms
*/
class Bootstrap implements BootstrapInterface
{
/**
* @inheritdoc
*/
public function bootstrap($app)
{
if (!isset($app->get('i18n')->translations['yii2mod.cms'])) {
$app->get('i18n')->translations['yii2mod.cms'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@yii2mod/cms/messages',
];
}

if ($app->getModule('comment') === null) {
$app->setModule('comment', ['class' => 'yii2mod\comments\Module']);
}
}
}
45 changes: 45 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace yii2mod\cms;

/**
* Class Module
*
* @package yii2mod\cms
*/
class Module extends \yii\base\Module
{
/**
* @var string the namespace that controller classes are in
*/
public $controllerNamespace = 'yii2mod\cms\controllers';

/**
* @var string the default route of this module
*/
public $defaultRoute = 'manage';

/**
* @var array imperavi editor options
*/
public $imperaviEditorOptions = [
'plugins' => ['video', 'fullscreen', 'table'],
'options' => [
'minHeight' => 200,
],
];

/**
* @var bool whether to enable the markdown editor and markdown converter
*/
public $enableMarkdown = false;

/**
* @var array markdown editor options
*
* @see https://github.com/NextStepWebs/simplemde-markdown-editor#configuration
*/
public $markdownEditorOptions = [
'showIcons' => ['code', 'table'],
];
}
234 changes: 113 additions & 121 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CMS Extension
========================
Base content management system for Yii Framework 2.0
This module provides a web interface for content management system and includes following features:

- Allows CRUD operations for pages
- [Support Markdown Editor](https://github.com/yii2mod/yii2-markdown)
- [Support Comments Management System](https://github.com/yii2mod/yii2-comments)
- Integrated with [yii2mod/base](https://github.com/yii2mod/base)

[![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)
[![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)
Expand All @@ -13,13 +18,13 @@ The preferred way to install this extension is through [composer](http://getcomp

Either run

```
```bash
php composer.phar require --prefer-dist yii2mod/yii2-cms "*"
```

or add

```json
```
"yii2mod/yii2-cms": "*"
```

Expand All @@ -28,39 +33,35 @@ to the require section of your composer.json.

CONFIGURATION
------------
> If you use this extension separate from the [base template](https://github.com/yii2mod/base), then you need execute migration by the following command:

**Database Migrations**

Before usage this extension, we'll also need to prepare the database.

```bash
$ php yii migrate --migrationPath=@vendor/yii2mod/yii2-comments/migrations
$ php yii migrate --migrationPath=@vendor/yii2mod/yii2-cms/migrations
```

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:
**Module Setup**

To access the module, you need to configure the modules array in your application configuration:

```php
'modules' => [
'admin' => [
'controllerMap' => [
'cms' => 'yii2mod\cms\controllers\CmsController',
// Also you can override some controller properties in following way:
'cms' => [
'class' => 'yii2mod\cms\controllers\CmsController',
'searchClass' => [
'class' => 'yii2mod\cms\models\search\CmsSearch',
'pageSize' => 25
],
'modelClass' => 'Your own cms model class',
'indexView' => 'custom path to index view file',
'createView' => 'custom path to create view file',
'updateView' => 'custom path to update view file',
],
],
'cms' => [
'class' => 'yii2mod\cms\Module',
],
],
```
> **You can then access to management section through the following URL:**
> http://localhost/path/to/index.php?r=admin/cms/index
> http://localhost/path/to/index.php?r=/cms/manage/index

2) Add new Rule class to the `urlManager` array in your application configuration by the following code:
**Configure Url Manager**

You need to configure the `urlManager` array in your application configuration:

```php
'components' => [
Expand All @@ -72,122 +73,113 @@ $ php yii migrate --migrationPath=@vendor/yii2mod/yii2-cms/migrations
],
```

3) Add to SiteController (or configure via `$route` param in `urlManager`):
**Setup Page Action**

Add to SiteController (or configure via `$route` param in `urlManager`):

```php
public function actions()
{
return [
'page' => [
'class' => 'yii2mod\cms\actions\PageAction',
// Also you can override some action properties in following way:
'layout' => 'your custom layout',
'viewPath' => 'your custom view file',
// You can set parameters that you want to parse before the page is loaded, for example:
'baseTemplateParams' => [
'homeUrl' => Yii::$app->homeUrl,
'siteName' => Yii::$app->name
],
// some comment widget params
'commentWidgetParams' => [
'maxLevel' => 1,
'dataProviderConfig' => [
'pagination' => [
'pageSize' => 5
],
],
]
]
];
}
```
> And now you can create your own pages via admin panel.
**Now you can use this module with all available features.**

## Internationalization

All text and messages introduced in this extension are translatable under category 'yii2mod.cms'.
You may use translations provided within this extension, using following application configuration:
## Features:

1. Markdown Editor support:
```php
return [
'components' => [
'i18n' => [
'translations' => [
'yii2mod.cms' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@yii2mod/cms/messages',
],
// ...
],
'modules' => [
'cms' => [
'class' => 'yii2mod\cms\Module',
'enableMarkdown' => true,
// List of options: https://github.com/NextStepWebs/simplemde-markdown-editor#configuration
'markdownEditorOptions' => [
'showIcons' => ['code', 'table'],
],
// ...
],
// ...
];
],
```

##Additional features:

1. You can insert your own widget on the page by the following steps:
* Create the widget, for example:

```php
<?php

namespace app\widgets;

use yii\base\Widget;

/**
* Class MyWidget
* @package app\widgets
*/
class MyWidget extends Widget
{
/**
* @inheritdoc
*/
public function run()
{
parent::run();

echo 'Text from widget';
}

/**
* This function used for render the widget in the cms pages
*
* @return string
*/
public static function show()
{
return self::widget([
// additional params
]);
}
}
```
* When you create the page via admin panel add the following code to the page content:
2. You can insert your own widget on the page by the following steps:

- Create the widget, for example:

```php
namespace app\widgets;

use yii\base\Widget;

class MyWidget extends Widget
{
/**
* @inheritdoc
*/
public function run()
{
parent::run();

echo 'Text from widget';
}

/**
* This function used for render the widget
*
* @return string
*/
public static function show()
{
return self::widget();
}
}
```

```
[[\app\widgets\MyWidget:show]]
```
2. You can use parameters in your page content, for example: {siteName}, {homeUrl}. For parsing this parameters you can use the `baseTemplateParams` property:
- When you create the page via admin panel add the following code to the page content:

```
[[\app\widgets\MyWidget:show]]
```

3. You can use parameters in your page content, for example: {siteName}, {homeUrl}. For parsing this parameters you can use the `baseTemplateParams` property:

```php
public function actions()
{
return [
'page' => [
'class' => 'yii2mod\cms\actions\PageAction',
'baseTemplateParams' => [
'homeUrl' => 'your site home url',
'siteName' => Yii::$app->name
]
],
];
}
```

4. You can change comments module settings by the following code:

```php
/**
* @return array
*/
public function actions()
{
return [
'page' => [
'class' => 'yii2mod\cms\actions\PageAction',
// You can set parameters that you want to parse before the page is loaded, for example:
'baseTemplateParams' => [
'homeUrl' => 'your site home url',
'siteName' => Yii::$app->name
]
],
];
}
public function actions()
{
return [
'page' => [
'class' => 'yii2mod\cms\actions\PageAction',
'commentWidgetParams' => [
'maxLevel' => 1,
'dataProviderConfig' => [
'pagination' => [
'pageSize' => 10
],
],
]
]
];
}
```

> For detail information about comments module please visit the following [page](https://github.com/yii2mod/yii2-comments)
Loading

0 comments on commit 0f71d2d

Please sign in to comment.