Skip to content

Commit

Permalink
reduce vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
yidashi committed Dec 7, 2016
1 parent db14f04 commit ad73091
Show file tree
Hide file tree
Showing 96 changed files with 206 additions and 1,918 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ console 控制台
database 数据库(迁移 填充)
frontend 前台
plugins 插件
tests 测试
vendor 扩展
web web统一入口(web服务器可只开放该目录,保证安全)
wechat 微信
Expand Down
15 changes: 15 additions & 0 deletions common/actions/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ public function actions()
'path' => Yii::$app->storage->basePath,
'modelClass' => 'common\models\Attachment'
],
'md-image-upload' => [
'class' => 'common\actions\UploadAction',
'url' => Yii::$app->storage->baseUrl,
'path' => Yii::$app->storage->basePath,
'modelClass' => 'common\models\Attachment',
'callback' => function($result) {
return !isset($result['files'][0]['error']) ? [
'success' => 1,
'url' => $result['files'][0]['url']
] : [
'success' => 0,
'message' => $result['files'][0]['error']
];
}
],
];
}

Expand Down
9 changes: 5 additions & 4 deletions common/widgets/EditorWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
namespace common\widgets;


use common\widgets\editormd\Editormd;
use vova07\imperavi\Widget;
use yidashi\markdown\Markdown;
use yii\base\InvalidParamException;
use yii\helpers\Url;
use yii\widgets\InputWidget;
use yii\helpers\Url;

class EditorWidget extends InputWidget
{
Expand Down Expand Up @@ -43,13 +43,13 @@ public function run()
public function markdown()
{
if ($this->hasModel()) {
return Markdown::widget([
return Editormd::widget([
'model' => $this->model,
'attribute' => $this->attribute,
'options' => $this->options
]);
} else {
return Markdown::widget([
return Editormd::widget([
'name' => $this->name,
'value' => $this->value,
'options' => $this->options
Expand All @@ -66,6 +66,7 @@ public function redactor()
'fileManagerJson' => Url::to(['/upload/redactor-files-get']),
'fileUpload' => Url::to(['/upload/redactor-file-upload']),
'plugins' => [
'clips',
'fullscreen',
'imagemanager',
'filemanager'
Expand Down
68 changes: 68 additions & 0 deletions common/widgets/editormd/Editormd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Created by PhpStorm.
* Author: ljt
* DateTime: 2016/12/7 9:51
* Description:
*/

namespace common\widgets\editormd;

use yii\helpers\Html;
use yii\helpers\Json;
use yii\widgets\InputWidget;

class Editormd extends InputWidget
{
/**
* @var array the HTML attributes for the widget container tag.
*/
public $options = [];
/**
* editor options
*/
public $clientOptions = [];

public $imageUploadRoute = [
'/upload/md-image-upload',
'fileparam' => 'editormd-image-file'
];
public function init()
{
parent::init();
$this->options = array_merge([
'height' => '300',
'emoji' => true,
'watch' => false,
'placeholder' => '本编辑器支持Markdown编辑,左边编写,右边预览',
'syncScrolling' => 'single',
'imageUpload' => true,
'imageFormats' => ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"],
'imageUploadURL' => \yii\helpers\Url::to($this->imageUploadRoute)
], $this->options);
}

public function run()
{
if ($this->hasModel()) {
$this->name = empty($this->options['name']) ? Html::getInputName($this->model, $this->attribute) :
$this->options['name'];
$this->value = Html::getAttributeValue($this->model, $this->attribute);
}
echo Html::tag('div', '', $this->options);
$this->registerClientScript();
}

protected function registerClientScript()
{
$view = $this->getView();
$editormd = EditormdAsset::register($view);
$id = $this->options['id'];
$this->options['value'] = $this->value ? $this->value : '';
$this->options['name'] = $this->name;
$this->options['path'] = $editormd->baseUrl . '/lib/';
$options = Json::encode($this->options);
$js = 'var editor = editormd("' . $id . '", ' . $options . ');';
$view->registerJs($js);
}
}
31 changes: 31 additions & 0 deletions common/widgets/editormd/EditormdAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Created by PhpStorm.
* Author: ljt
* DateTime: 2016/12/7 9:51
* Description:
*/

namespace common\widgets\editormd;

use yii\web\AssetBundle;

class EditormdAsset extends AssetBundle
{
public $sourcePath = '@bower/editor.md';

public $js = [
'editormd.min.js'
];

public $css = [
'css/editormd.css',
'css/editormd.logo.css',
'css/editormd.preview.css'
];

public $depends = [
'yii\web\JqueryAsset',
'common\assets\FontAwesomeAsset'
];
}
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,26 @@
"yiisoft/yii2-swiftmailer": "*",
"yiisoft/yii2-authclient": "^2.0",
"yiisoft/yii2-redis": "*",
"yiisoft/yii2-composer": "2.0.4",
"yiisoft/yii2-imagine": "^2.0",
"yidashi/yii2-bootstrap-markdown": "2.0.3",
"yidashi/yii2-webuploader": "^1.4.2",
"aferrandini/PHPQRCode": "1.0.1",
"mobiledetect/mobiledetectlib": "^2.8",
"mihaildev/yii2-elfinder": "^1.0",
"omnilight/yii2-scheduling": "*",
"vlucas/phpdotenv": "^2.0",
"vova07/yii2-imperavi-widget": "*",
"bower-asset/blueimp-file-upload" : "*",
"bower-asset/font-awesome": "^4.0",
"2amigos/yii2-editable-widget": "0.1.*",
"raulfraile/distill": "@stable",
"fabpot/goutte": "^3.1",
"kartik-v/yii2-widget-select2": "*",
"kartik-v/yii2-widget-datetimepicker": "^1.4",
"kartik-v/yii2-widget-datepicker": "^1.3",
"udokmeci/yii2-beanstalk": "dev-master",
"hightman/xunsearch": "*@beta"
"hightman/xunsearch": "*@beta",
"bower-asset/blueimp-file-upload" : "*",
"bower-asset/font-awesome": "^4.0",
"bower-asset/editor.md": "*"
},
"require-dev": {
"yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*",
"yiisoft/yii2-faker": "*"
Expand Down
Loading

0 comments on commit ad73091

Please sign in to comment.