Commit 29b842c05b17a12a5b7a692c577d0537dff440fe
1 parent
3d163909
add field v.1
Showing
10 changed files
with
770 additions
and
12 deletions
Show diff stats
common/config/main-local.php
@@ -3,9 +3,9 @@ return [ | @@ -3,9 +3,9 @@ return [ | ||
3 | 'components' => [ | 3 | 'components' => [ |
4 | 'db' => [ | 4 | 'db' => [ |
5 | 'class' => 'yii\db\Connection', | 5 | 'class' => 'yii\db\Connection', |
6 | - 'dsn' => 'pgsql:host=127.0.0.1;port=5432;dbname=mfp_local', | ||
7 | - 'username' => 'postgres', | ||
8 | - 'password' => '', | 6 | + 'dsn' => 'pgsql:host=195.248.225.149;port=5432;dbname=mfp', |
7 | + 'username' => 'test33', | ||
8 | + 'password' => 'E4q2N7i9', | ||
9 | 'schemaMap' => [ | 9 | 'schemaMap' => [ |
10 | 'pgsql'=> [ | 10 | 'pgsql'=> [ |
11 | 'class'=>'yii\db\pgsql\Schema', | 11 | 'class'=>'yii\db\pgsql\Schema', |
1 | +<?php | ||
2 | +namespace backend\models; | ||
3 | + | ||
4 | +use yii\base\Model; | ||
5 | +use yii\web\UploadedFile; | ||
6 | + | ||
7 | +/** | ||
8 | + * UploadForm is the model behind the upload form. | ||
9 | + */ | ||
10 | +class ImageSizerForm extends Model | ||
11 | +{ | ||
12 | + /** | ||
13 | + * @var UploadedFile file attribute | ||
14 | + */ | ||
15 | + public $file; | ||
16 | + public $width; | ||
17 | + public $height; | ||
18 | + public $field; | ||
19 | + public $model; | ||
20 | + public $form; | ||
21 | + public $multi; | ||
22 | + public $old_img; | ||
23 | + public $img; | ||
24 | + public $price_list; | ||
25 | + | ||
26 | + /** | ||
27 | + * @return array the validation rules. | ||
28 | + */ | ||
29 | + public function rules() | ||
30 | + { | ||
31 | + return [ | ||
32 | + [['width', 'height'], 'integer'], | ||
33 | + [['field', 'multi','old_img'], 'string', 'max' => 255], | ||
34 | + [['model', 'form',], 'string'], | ||
35 | + [['file','img','price_list'], 'file'], | ||
36 | + ]; | ||
37 | + } | ||
38 | +} | ||
0 | \ No newline at end of file | 39 | \ No newline at end of file |
1 | +<?php | ||
2 | +namespace backend\components; | ||
3 | + | ||
4 | +use yii\web\UploadedFile; | ||
5 | +use backend\models\ImageSizerForm; | ||
6 | +use yii\base\Widget; | ||
7 | +use Imagine\Image\Box; | ||
8 | +use yii\imagine\Image; | ||
9 | +use Yii; | ||
10 | +use Imagine\Gd\Imagine; | ||
11 | + | ||
12 | +class ImageResizer extends Widget | ||
13 | +{ | ||
14 | + | ||
15 | + public $height; | ||
16 | + public $width; | ||
17 | + | ||
18 | + public function init(){ | ||
19 | + | ||
20 | + parent::init(); | ||
21 | + | ||
22 | + } | ||
23 | + | ||
24 | + public function run(){ | ||
25 | + | ||
26 | + $model = new ImageSizerForm(); | ||
27 | + | ||
28 | + $request = Yii::$app->request->post(); | ||
29 | + | ||
30 | + if ($request) { | ||
31 | + | ||
32 | + if(isset($request['old_img'])){ | ||
33 | + $this->deleteImages($request['old_img']); | ||
34 | + } | ||
35 | + | ||
36 | + | ||
37 | + $model->file = UploadedFile::getInstance($model, 'file'); | ||
38 | + | ||
39 | + if(!$model->file){ | ||
40 | + return json_encode(["error"=>"Не указан файл"]); | ||
41 | + } | ||
42 | + | ||
43 | + $md5_file = md5_file($model->file->tempName); | ||
44 | + | ||
45 | + $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); | ||
46 | + | ||
47 | + $imageOrigAlias = Yii::getAlias($imgDir.'original'.'.'.$model->file->extension); | ||
48 | + | ||
49 | + if(!is_dir($imgDir)) { | ||
50 | + mkdir($imgDir, 0755, true); | ||
51 | + } | ||
52 | + | ||
53 | + $model->file->saveAs($imageOrigAlias); | ||
54 | + | ||
55 | + if($request['width'] && $request['height']){ | ||
56 | + | ||
57 | + $imageAlias = Yii::getAlias($imgDir.$request['width'].'x'.$request['height'].'.'.$model->file->extension); | ||
58 | + | ||
59 | + $imageLink = '/storage/'.$md5_file.'/'.$request['width'].'x'.$request['height'].'.'.$model->file->extension; | ||
60 | + | ||
61 | + $this->resizeImg($request['width'],$request['height'], $imageOrigAlias,$imageAlias); | ||
62 | + | ||
63 | + } else { | ||
64 | + | ||
65 | + $imageLink = '/storage/'.$md5_file.'/'.'original'.'.'.$model->file->extension; | ||
66 | + | ||
67 | + } | ||
68 | + | ||
69 | + | ||
70 | + if($model->multi){ | ||
71 | +// $view = $this->renderPartial('@app/components/views/_gallery_item', [ | ||
72 | +// 'item' => ['image'=>$imageLink], | ||
73 | +// ]); | ||
74 | +// | ||
75 | +// return json_encode(['link'=>$imageLink, 'view' =>$view]); | ||
76 | + | ||
77 | + | ||
78 | + } else { | ||
79 | + $p1[0] = "<img style='height:160px' src='$imageLink' class='file-preview-image'>"; | ||
80 | + return json_encode(['success','initialPreview' => $p1, 'append' => false, 'name' =>$imageLink,]); | ||
81 | + } | ||
82 | + | ||
83 | + | ||
84 | + } else { | ||
85 | + return json_encode(['error']); | ||
86 | + } | ||
87 | + | ||
88 | + | ||
89 | + | ||
90 | + | ||
91 | + } | ||
92 | + | ||
93 | + | ||
94 | + public function isBigger($width,$height,$w,$h) | ||
95 | + { | ||
96 | + if($width>$w){ | ||
97 | + return true; | ||
98 | + }else if($height >$h) { | ||
99 | + return true; | ||
100 | + } | ||
101 | + return false; | ||
102 | + } | ||
103 | + | ||
104 | + | ||
105 | + | ||
106 | + | ||
107 | + | ||
108 | + public function resizeImg($w, $h, $imageAlias,$imageAliasSave) | ||
109 | + { | ||
110 | + $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); | ||
111 | + | ||
112 | + $size = $img->getSize(); | ||
113 | + | ||
114 | + $width = $size->getWidth(); | ||
115 | + $height = $size->getHeight(); | ||
116 | + | ||
117 | + $e_width = $w/$h; | ||
118 | + $e_height = $h/$w; | ||
119 | + | ||
120 | + $e1_width = $width/$height; | ||
121 | + $e1_height = $height/$width; | ||
122 | + | ||
123 | + if($this->isBigger($width,$height,$w,$h)){ | ||
124 | + if($e_width<$e1_width){ | ||
125 | + $new_width = $width*($e_width/$e1_width); | ||
126 | + $width = $new_width; | ||
127 | + }else { | ||
128 | + $new_height = $height*($e_height/$e1_height); | ||
129 | + $height = $new_height; | ||
130 | + } | ||
131 | + | ||
132 | + | ||
133 | + } else { | ||
134 | + $img->save($imageAliasSave, array('flatten' => false)); | ||
135 | + return true; | ||
136 | + } | ||
137 | + | ||
138 | + | ||
139 | + Image::crop($imageAlias, $width, $height,[0,0]) | ||
140 | + ->save(Yii::getAlias($imageAliasSave), ['quality' => | ||
141 | + 100]); | ||
142 | + | ||
143 | + | ||
144 | + $imagine = new Imagine(); | ||
145 | + $imagine->open($imageAliasSave) | ||
146 | + ->resize(new Box($w, $h)) | ||
147 | + ->save($imageAliasSave, array('flatten' => false)); | ||
148 | + | ||
149 | + | ||
150 | + | ||
151 | + } | ||
152 | + | ||
153 | + | ||
154 | + private function deleteImages($old_img){ | ||
155 | + | ||
156 | + if(!empty($old_img) && file_exists($_SERVER['DOCUMENT_ROOT'].$old_img)){ | ||
157 | + | ||
158 | + $rootDir = explode("/", $old_img); | ||
159 | + | ||
160 | + $row = $_SERVER['DOCUMENT_ROOT'].'/'.$rootDir[1].'/'.$rootDir[2].'/'; | ||
161 | + | ||
162 | + $allFiles = scandir($row); | ||
163 | + | ||
164 | + $allFiles = array_slice($allFiles, 2); | ||
165 | + | ||
166 | + foreach($allFiles as $oldFile){ | ||
167 | + | ||
168 | + unlink($row.$oldFile); | ||
169 | + | ||
170 | + } | ||
171 | + | ||
172 | + } | ||
173 | + } | ||
174 | + | ||
175 | + public function actionDeleteImage(){ | ||
176 | + $old_img = Yii::$app->request->post('old_img'); | ||
177 | + | ||
178 | + if ($old_img) { | ||
179 | + $this->deleteImages($old_img); | ||
180 | + } | ||
181 | + } | ||
182 | + | ||
183 | + | ||
184 | + | ||
185 | +} | ||
0 | \ No newline at end of file | 186 | \ No newline at end of file |
1 | +<?php | ||
2 | +use yii\helpers\Html; | ||
3 | + | ||
4 | +?> | ||
5 | +<div class="gallery_image"> | ||
6 | + <?= Html::img($item['image'])?> | ||
7 | + <span data-url="<?=$item['image']?>" title="удалить изображение" class="glyphicon glyphicon-trash delete-gallery-item"></span> | ||
8 | +</div> | ||
0 | \ No newline at end of file | 9 | \ No newline at end of file |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: vitaliy | ||
5 | + * Date: 05.10.15 | ||
6 | + * Time: 16:20 | ||
7 | + */ | ||
8 | +use yii\helpers\Html; | ||
9 | +$this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/vendor/jquery.ui.widget.js'); | ||
10 | +$this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.iframe-transport.js'); | ||
11 | +$this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupload.js'); | ||
12 | +$this->registerCssFile('@web/js/vendor/bower/jquery-file-upload/css/jquery.fileupload.css'); | ||
13 | + | ||
14 | +?> | ||
15 | +<div class="file-uploader-block"> | ||
16 | + <?php if(!$multi):?> | ||
17 | + <span class="btn btn-success fileinput-button uploader-button"> | ||
18 | + <i class="glyphicon glyphicon-plus"></i> | ||
19 | + <span><?=$name?></span> | ||
20 | + | ||
21 | + <?= Html::activeFileInput( new \backend\models\ImageSizerForm(),'file',['id'=>$field, 'data-url'=>"/admin/site/download-photo" ]);?> | ||
22 | + </span> | ||
23 | + | ||
24 | + <?= Html::activeHiddenInput( $model,$field,['id' => "{$field}_picture_link"]) ?> | ||
25 | + <input type="hidden" id="<?=$field?>_old_img" name="ImageSizerForm[old_img]" value="<?=$model->$field?>"/> | ||
26 | + <input type="hidden" id="<?=$field?>_new_img" name="ImageSizerForm[new_img]" value=""/> | ||
27 | + <input type="hidden" id="<?=$field?>_row_id" name="ImageSizerForm[new_img]" value="<?=$model->id?>"/> | ||
28 | + <div id="<?= $field?>_img_block"> | ||
29 | + <?= $model->$field ? Html::img($model->$field): '' ?> | ||
30 | + </div> | ||
31 | + | ||
32 | + <script> | ||
33 | + $(function(){ | ||
34 | + | ||
35 | + $("#<?= $field?>").fileupload({ | ||
36 | + dataType: 'json', | ||
37 | + formData: {width: <?=$width?>,height:<?=$height?>}, | ||
38 | + done: function (e, data) { | ||
39 | + if($("#<?=$field?>_buttons_block").length){ | ||
40 | + $("#<?=$field?>_buttons_block").remove() | ||
41 | + } | ||
42 | + var host = window.location.host.toString(); | ||
43 | + var img = '<img src="http://'+host+data.result.link+'">'+ | ||
44 | + '<div id="<?=$field?>_buttons_block">'+ | ||
45 | + '<button type="button" id="<?=$field?>_save_img" class="btn btn-success img-action-buttons" >Сохранить</button>'+ | ||
46 | + '<button type="button" id="<?=$field?>_remove_img" class="btn btn-danger img-action-buttons" >Отмена</button>'+ | ||
47 | + '</div>'; | ||
48 | + var block = $("#<?= $field?>_img_block"); | ||
49 | + block.find('img').remove(); | ||
50 | + block.append(img); | ||
51 | + $("#<?=$field?>_picture_link").val(data.result.link); | ||
52 | + $("#<?=$field?>_new_img").val(data.result.link); | ||
53 | + } | ||
54 | + }); | ||
55 | + | ||
56 | + | ||
57 | + $('body').on('click', '#<?=$field?>_save_img',function(){ | ||
58 | + $("#<?=$field?>_buttons_block").remove(); | ||
59 | + var old_url = $('#<?=$field?>_old_img').val(); | ||
60 | + var new_url = $('#<?=$field?>_new_img').val(); | ||
61 | + var model = '<?=str_replace('\\', '-',$model::className());?>'; | ||
62 | + $.post( "/admin/site/delete-image",{new_url:new_url,old_img: old_url,model:model,field:"<?= $field?>", id:"<?=$model->id?>",action:'save'}, function() { | ||
63 | + }); | ||
64 | + $("#<?=$field?>_picture_link").val(new_url); | ||
65 | + }); | ||
66 | + | ||
67 | + $('body').on('click', '#<?=$field?>_remove_img',function(){ | ||
68 | + $("#<?=$field?>_buttons_block").remove(); | ||
69 | + $("#<?=$field?>_buttons_block").remove(); | ||
70 | + var old_url = $('#<?=$field?>_old_img').val(); | ||
71 | + var new_url = $('#<?=$field?>_new_img').val(); | ||
72 | + $.post( "/admin/site/delete-image",{old_img: new_url}, function() { | ||
73 | + }); | ||
74 | + $("#<?=$field?>_picture_link").val(old_url); | ||
75 | + $('#<?= $field?>_img_block').find('img').attr('src',old_url); | ||
76 | + }); | ||
77 | + | ||
78 | + | ||
79 | + }) | ||
80 | +</script> | ||
81 | + | ||
82 | +<?php else:?> | ||
83 | + | ||
84 | + <span class="btn btn-success fileinput-button uploader-button"> | ||
85 | + <i class="glyphicon glyphicon-plus"></i> | ||
86 | + <span><?=$name?></span> | ||
87 | + | ||
88 | + <?= Html::activeFileInput( new \backend\models\ImageSizerForm(),'file',['id'=>$field, 'data-url'=>"/admin/site/download-photo", 'multiple'=> 'multiple' ]);?> | ||
89 | + </span> | ||
90 | + | ||
91 | + <?= Html::activeHiddenInput( $model,$field,['id' => "{$field}_picture_link"]) ?> | ||
92 | + | ||
93 | + | ||
94 | + <input type="hidden" name="ImageSizerForm[multi]" value="<?=$multi?>"/> | ||
95 | + | ||
96 | + <div id="<?= $field?>_img_block"> | ||
97 | + <?php | ||
98 | + | ||
99 | + foreach($this->context->getGallery() as $image){ | ||
100 | + echo $this->render('_gallery_item', [ 'item' => ['image'=>$image]]); | ||
101 | + } | ||
102 | + ?> | ||
103 | + </div> | ||
104 | + <script> | ||
105 | + $(function(){ | ||
106 | + | ||
107 | + $("#<?= $field?>").fileupload({ | ||
108 | + dataType: 'json', | ||
109 | + formData: {width: <?=$width?>,height:<?=$height?>}, | ||
110 | + done: function (e, data) { | ||
111 | + | ||
112 | + var img = data.result.view; | ||
113 | + var block = $("#<?= $field?>_img_block"); | ||
114 | + block.append(img); | ||
115 | + var gallery = $("#<?= $field?>_picture_link"); | ||
116 | + gallery.val(gallery.val()+data.result.link+','); | ||
117 | + } | ||
118 | + }); | ||
119 | + $('body').on('click','.delete-gallery-item', function(){ | ||
120 | + var url = $(this).data('url'); | ||
121 | + $(this).parent('.gallery_image').remove(); | ||
122 | + var gallery = $("#<?= $field?>_picture_link"); | ||
123 | + var urls = gallery.val(); | ||
124 | + gallery.val(urls.replace(url+',', "")); | ||
125 | + $.post( "/admin/site/delete-image",{old_img: url}, function( data ) { | ||
126 | + $( ".result" ).html( data ); | ||
127 | + }); | ||
128 | + }) | ||
129 | + | ||
130 | + }) | ||
131 | + </script> | ||
132 | + | ||
133 | +<?php endif;?> | ||
134 | +</div> | ||
0 | \ No newline at end of file | 135 | \ No newline at end of file |
composer.json
@@ -23,7 +23,9 @@ | @@ -23,7 +23,9 @@ | ||
23 | "kartik-v/yii2-widget-select2": "@dev", | 23 | "kartik-v/yii2-widget-select2": "@dev", |
24 | "mihaildev/yii2-ckeditor": "*", | 24 | "mihaildev/yii2-ckeditor": "*", |
25 | "developeruz/yii2-db-rbac": "*", | 25 | "developeruz/yii2-db-rbac": "*", |
26 | - "nodge/yii2-eauth": "*" | 26 | + "nodge/yii2-eauth": "*", |
27 | + "yiisoft/yii2-imagine": "^2.0", | ||
28 | + "mihaildev/yii2-elfinder": "^1.1" | ||
27 | }, | 29 | }, |
28 | "require-dev": { | 30 | "require-dev": { |
29 | "yiisoft/yii2-codeception": "*", | 31 | "yiisoft/yii2-codeception": "*", |
composer.lock
@@ -4,8 +4,8 @@ | @@ -4,8 +4,8 @@ | ||
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", | 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", |
5 | "This file is @generated automatically" | 5 | "This file is @generated automatically" |
6 | ], | 6 | ], |
7 | - "hash": "e9b955ba46cc8543c15ffcde1924e173", | ||
8 | - "content-hash": "269319a9b7db2499c82b3ac2409e9b8d", | 7 | + "hash": "d07e2c10b604fb6b814d10b2de6dcd2f", |
8 | + "content-hash": "2d0acd792b2e28f03338a962c2923bbe", | ||
9 | "packages": [ | 9 | "packages": [ |
10 | { | 10 | { |
11 | "name": "almasaeed2010/adminlte", | 11 | "name": "almasaeed2010/adminlte", |
@@ -557,6 +557,63 @@ | @@ -557,6 +557,63 @@ | ||
557 | "time": "2013-11-30 08:25:19" | 557 | "time": "2013-11-30 08:25:19" |
558 | }, | 558 | }, |
559 | { | 559 | { |
560 | + "name": "imagine/imagine", | ||
561 | + "version": "0.5.x-dev", | ||
562 | + "source": { | ||
563 | + "type": "git", | ||
564 | + "url": "https://github.com/avalanche123/Imagine.git", | ||
565 | + "reference": "343580fceed1f89220481ac98480e92f47d91e6c" | ||
566 | + }, | ||
567 | + "dist": { | ||
568 | + "type": "zip", | ||
569 | + "url": "https://api.github.com/repos/avalanche123/Imagine/zipball/343580fceed1f89220481ac98480e92f47d91e6c", | ||
570 | + "reference": "343580fceed1f89220481ac98480e92f47d91e6c", | ||
571 | + "shasum": "" | ||
572 | + }, | ||
573 | + "require": { | ||
574 | + "php": ">=5.3.2" | ||
575 | + }, | ||
576 | + "require-dev": { | ||
577 | + "sami/sami": "dev-master" | ||
578 | + }, | ||
579 | + "suggest": { | ||
580 | + "ext-gd": "to use the GD implementation", | ||
581 | + "ext-gmagick": "to use the Gmagick implementation", | ||
582 | + "ext-imagick": "to use the Imagick implementation" | ||
583 | + }, | ||
584 | + "type": "library", | ||
585 | + "extra": { | ||
586 | + "branch-alias": { | ||
587 | + "dev-develop": "0.5-dev" | ||
588 | + } | ||
589 | + }, | ||
590 | + "autoload": { | ||
591 | + "psr-0": { | ||
592 | + "Imagine": "lib/" | ||
593 | + } | ||
594 | + }, | ||
595 | + "notification-url": "https://packagist.org/downloads/", | ||
596 | + "license": [ | ||
597 | + "MIT" | ||
598 | + ], | ||
599 | + "authors": [ | ||
600 | + { | ||
601 | + "name": "Bulat Shakirzyanov", | ||
602 | + "email": "mallluhuct@gmail.com", | ||
603 | + "homepage": "http://avalanche123.com" | ||
604 | + } | ||
605 | + ], | ||
606 | + "description": "Image processing for PHP 5.3", | ||
607 | + "homepage": "http://imagine.readthedocs.org/", | ||
608 | + "keywords": [ | ||
609 | + "drawing", | ||
610 | + "graphics", | ||
611 | + "image manipulation", | ||
612 | + "image processing" | ||
613 | + ], | ||
614 | + "time": "2014-06-13 10:54:04" | ||
615 | + }, | ||
616 | + { | ||
560 | "name": "kartik-v/yii2-krajee-base", | 617 | "name": "kartik-v/yii2-krajee-base", |
561 | "version": "v1.7.9", | 618 | "version": "v1.7.9", |
562 | "source": { | 619 | "source": { |
@@ -612,7 +669,7 @@ | @@ -612,7 +669,7 @@ | ||
612 | }, | 669 | }, |
613 | "dist": { | 670 | "dist": { |
614 | "type": "zip", | 671 | "type": "zip", |
615 | - "url": "https://api.github.com/repos/kartik-v/yii2-widget-select2/zipball/701bf8069a85fafbac1ced54dcd00e579e60471b", | 672 | + "url": "https://api.github.com/repos/kartik-v/yii2-widget-select2/zipball/519241c7360a0470624f24d872741e1ea880de75", |
616 | "reference": "701bf8069a85fafbac1ced54dcd00e579e60471b", | 673 | "reference": "701bf8069a85fafbac1ced54dcd00e579e60471b", |
617 | "shasum": "" | 674 | "shasum": "" |
618 | }, | 675 | }, |
@@ -764,6 +821,56 @@ | @@ -764,6 +821,56 @@ | ||
764 | "time": "2014-11-19 22:04:08" | 821 | "time": "2014-11-19 22:04:08" |
765 | }, | 822 | }, |
766 | { | 823 | { |
824 | + "name": "mihaildev/yii2-elfinder", | ||
825 | + "version": "1.1.3", | ||
826 | + "source": { | ||
827 | + "type": "git", | ||
828 | + "url": "https://github.com/MihailDev/yii2-elfinder.git", | ||
829 | + "reference": "64b42572dec94e5c2d0d1630bce8292848a98f4b" | ||
830 | + }, | ||
831 | + "dist": { | ||
832 | + "type": "zip", | ||
833 | + "url": "https://api.github.com/repos/MihailDev/yii2-elfinder/zipball/64b42572dec94e5c2d0d1630bce8292848a98f4b", | ||
834 | + "reference": "64b42572dec94e5c2d0d1630bce8292848a98f4b", | ||
835 | + "shasum": "" | ||
836 | + }, | ||
837 | + "require": { | ||
838 | + "yiisoft/yii2-jui": "*" | ||
839 | + }, | ||
840 | + "type": "yii2-extension", | ||
841 | + "extra": { | ||
842 | + "asset-installer-paths": { | ||
843 | + "npm-asset-library": "vendor/npm", | ||
844 | + "bower-asset-library": "vendor/bower" | ||
845 | + } | ||
846 | + }, | ||
847 | + "autoload": { | ||
848 | + "psr-4": { | ||
849 | + "mihaildev\\elfinder\\": "" | ||
850 | + } | ||
851 | + }, | ||
852 | + "notification-url": "https://packagist.org/downloads/", | ||
853 | + "license": [ | ||
854 | + "BSD-3-Clause" | ||
855 | + ], | ||
856 | + "authors": [ | ||
857 | + { | ||
858 | + "name": "Mihail", | ||
859 | + "email": "mihail.kucher@gmail.com", | ||
860 | + "homepage": "https://github.com/MihailDev", | ||
861 | + "role": "Developer" | ||
862 | + } | ||
863 | + ], | ||
864 | + "description": "Yii2 ElFinder", | ||
865 | + "homepage": "https://github.com/MihailDev/yii2-elfinder", | ||
866 | + "keywords": [ | ||
867 | + "elfinder", | ||
868 | + "filemanager", | ||
869 | + "yii" | ||
870 | + ], | ||
871 | + "time": "2015-07-03 07:08:52" | ||
872 | + }, | ||
873 | + { | ||
767 | "name": "nodge/lightopenid", | 874 | "name": "nodge/lightopenid", |
768 | "version": "1.1.2", | 875 | "version": "1.1.2", |
769 | "source": { | 876 | "source": { |
@@ -977,7 +1084,7 @@ | @@ -977,7 +1084,7 @@ | ||
977 | }, | 1084 | }, |
978 | "dist": { | 1085 | "dist": { |
979 | "type": "zip", | 1086 | "type": "zip", |
980 | - "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/e4359f68b70caede1e09ecefb56e9435f7d140af", | 1087 | + "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/7ccbfdf4cfb0ce025e27455dc3e516af23eb2800", |
981 | "reference": "e4359f68b70caede1e09ecefb56e9435f7d140af", | 1088 | "reference": "e4359f68b70caede1e09ecefb56e9435f7d140af", |
982 | "shasum": "" | 1089 | "shasum": "" |
983 | }, | 1090 | }, |
@@ -1159,6 +1266,54 @@ | @@ -1159,6 +1266,54 @@ | ||
1159 | "time": "2015-12-01 20:06:03" | 1266 | "time": "2015-12-01 20:06:03" |
1160 | }, | 1267 | }, |
1161 | { | 1268 | { |
1269 | + "name": "yiisoft/yii2-imagine", | ||
1270 | + "version": "dev-master", | ||
1271 | + "source": { | ||
1272 | + "type": "git", | ||
1273 | + "url": "https://github.com/yiisoft/yii2-imagine.git", | ||
1274 | + "reference": "586c9c99cb541ec4d4d2ec2a206b08a6fd6de888" | ||
1275 | + }, | ||
1276 | + "dist": { | ||
1277 | + "type": "zip", | ||
1278 | + "url": "https://api.github.com/repos/yiisoft/yii2-imagine/zipball/586c9c99cb541ec4d4d2ec2a206b08a6fd6de888", | ||
1279 | + "reference": "586c9c99cb541ec4d4d2ec2a206b08a6fd6de888", | ||
1280 | + "shasum": "" | ||
1281 | + }, | ||
1282 | + "require": { | ||
1283 | + "imagine/imagine": "0.5.*", | ||
1284 | + "yiisoft/yii2": "*" | ||
1285 | + }, | ||
1286 | + "type": "yii2-extension", | ||
1287 | + "extra": { | ||
1288 | + "branch-alias": { | ||
1289 | + "dev-master": "2.0.x-dev" | ||
1290 | + } | ||
1291 | + }, | ||
1292 | + "autoload": { | ||
1293 | + "psr-4": { | ||
1294 | + "yii\\imagine\\": "" | ||
1295 | + } | ||
1296 | + }, | ||
1297 | + "notification-url": "https://packagist.org/downloads/", | ||
1298 | + "license": [ | ||
1299 | + "BSD-3-Clause" | ||
1300 | + ], | ||
1301 | + "authors": [ | ||
1302 | + { | ||
1303 | + "name": "Antonio Ramirez", | ||
1304 | + "email": "amigo.cobos@gmail.com" | ||
1305 | + } | ||
1306 | + ], | ||
1307 | + "description": "The Imagine integration for the Yii framework", | ||
1308 | + "keywords": [ | ||
1309 | + "helper", | ||
1310 | + "image", | ||
1311 | + "imagine", | ||
1312 | + "yii2" | ||
1313 | + ], | ||
1314 | + "time": "2015-09-29 10:49:20" | ||
1315 | + }, | ||
1316 | + { | ||
1162 | "name": "yiisoft/yii2-jui", | 1317 | "name": "yiisoft/yii2-jui", |
1163 | "version": "dev-master", | 1318 | "version": "dev-master", |
1164 | "source": { | 1319 | "source": { |
@@ -1168,7 +1323,7 @@ | @@ -1168,7 +1323,7 @@ | ||
1168 | }, | 1323 | }, |
1169 | "dist": { | 1324 | "dist": { |
1170 | "type": "zip", | 1325 | "type": "zip", |
1171 | - "url": "https://api.github.com/repos/yiisoft/yii2-jui/zipball/7ab7ff56bd54500212523e38f5fe3b9210325041", | 1326 | + "url": "https://api.github.com/repos/yiisoft/yii2-jui/zipball/1425ab29929dd195f468d3c4eb340ab509f28b83", |
1172 | "reference": "7ab7ff56bd54500212523e38f5fe3b9210325041", | 1327 | "reference": "7ab7ff56bd54500212523e38f5fe3b9210325041", |
1173 | "shasum": "" | 1328 | "shasum": "" |
1174 | }, | 1329 | }, |
@@ -1297,7 +1452,7 @@ | @@ -1297,7 +1452,7 @@ | ||
1297 | }, | 1452 | }, |
1298 | "dist": { | 1453 | "dist": { |
1299 | "type": "zip", | 1454 | "type": "zip", |
1300 | - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/de2ed3bbe68254efeff68db60092fc8ed5298055", | 1455 | + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/e493d3dc48d15a6d44e213d02c729ad61cc758a9", |
1301 | "reference": "de2ed3bbe68254efeff68db60092fc8ed5298055", | 1456 | "reference": "de2ed3bbe68254efeff68db60092fc8ed5298055", |
1302 | "shasum": "" | 1457 | "shasum": "" |
1303 | }, | 1458 | }, |
1 | +<?php | ||
2 | +/** | ||
3 | + * Created by PhpStorm. | ||
4 | + * User: Cibermag | ||
5 | + * Date: 31.08.2015 | ||
6 | + * Time: 9:58 | ||
7 | + */ | ||
8 | +namespace frontend\controllers; | ||
9 | + | ||
10 | +use Yii; | ||
11 | +use yii\web\UploadedFile; | ||
12 | +use backend\models\ImageSizerForm; | ||
13 | +use yii\web\Controller; | ||
14 | +use Imagine\Gd\Imagine; | ||
15 | +use Imagine\Image\Box; | ||
16 | +use yii\imagine\Image; | ||
17 | + | ||
18 | +class FileController extends Controller { | ||
19 | + | ||
20 | + public function isBigger($width,$height,$w,$h) | ||
21 | + { | ||
22 | + if($width>$w){ | ||
23 | + return true; | ||
24 | + }else if($height >$h) { | ||
25 | + return true; | ||
26 | + } | ||
27 | + return false; | ||
28 | + } | ||
29 | + | ||
30 | + | ||
31 | + private function resizeImg($w, $h, $imageAlias,$imageAliasSave){ | ||
32 | + $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); | ||
33 | + | ||
34 | + $size = $img->getSize(); | ||
35 | + | ||
36 | + $width = $size->getWidth(); | ||
37 | + $height = $size->getHeight(); | ||
38 | + | ||
39 | + $e_width = $w/$h; | ||
40 | + $e_height = $h/$w; | ||
41 | + | ||
42 | + $e1_width = $width/$height; | ||
43 | + $e1_height = $height/$width; | ||
44 | + | ||
45 | + | ||
46 | + if($this->isBigger($width,$height,$w,$h)){ | ||
47 | + if($e_width<$e1_width){ | ||
48 | + | ||
49 | + $new_width = $width*($e_width/$e1_width); | ||
50 | + | ||
51 | + $y = 0; | ||
52 | + $x = $width/ 2-($new_width/2); | ||
53 | + $width = $new_width; | ||
54 | + | ||
55 | + }else { | ||
56 | + | ||
57 | + $new_height = $height*($e_height/$e1_height); | ||
58 | + $x = 0; | ||
59 | + $y = $height/2-($new_height/2); | ||
60 | + $height = $new_height; | ||
61 | + } | ||
62 | + | ||
63 | + | ||
64 | + } else { | ||
65 | + $img->save($imageAliasSave, array('flatten' => false)); | ||
66 | + return true; | ||
67 | + } | ||
68 | + | ||
69 | + | ||
70 | + Image::crop($imageAlias, $width, $height,[$x,$y]) | ||
71 | + ->save(Yii::getAlias($imageAliasSave), ['quality' => | ||
72 | + 100]); | ||
73 | + | ||
74 | + | ||
75 | + $imagine = new Imagine(); | ||
76 | + $imagine->open($imageAliasSave) | ||
77 | + ->resize(new Box($w, $h)) | ||
78 | + ->save($imageAliasSave, array('flatten' => false)); | ||
79 | + | ||
80 | + | ||
81 | + | ||
82 | + } | ||
83 | + | ||
84 | + private function deleteImages($old_img){ | ||
85 | + | ||
86 | + if(!empty($old_img) && file_exists($_SERVER['DOCUMENT_ROOT'].$old_img)){ | ||
87 | + | ||
88 | +// $rootDir = explode("/", $old_img); | ||
89 | +// | ||
90 | +// $row = $_SERVER['DOCUMENT_ROOT'].'/'.$rootDir[1].'/'.$rootDir[2].'/'; | ||
91 | +// | ||
92 | +// $allFiles = scandir($row); | ||
93 | +// | ||
94 | +// $allFiles = array_slice($allFiles, 2); | ||
95 | +// | ||
96 | +// foreach($allFiles as $oldFile){ | ||
97 | +// | ||
98 | +// unlink($row.$oldFile); | ||
99 | +// | ||
100 | +// } | ||
101 | + | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + public function actionDeleteImage(){ | ||
106 | + | ||
107 | + $request = Yii::$app->request->post(); | ||
108 | + | ||
109 | + if($request){ | ||
110 | + if ($request['old_img']) { | ||
111 | + $this->deleteImages($request['old_img']); | ||
112 | + } | ||
113 | + if(isset($request['action']) && $request['action']=='save'){ | ||
114 | + $object = str_replace('-', '\\',$request['model']); | ||
115 | + $model = new $object; | ||
116 | + $model = $model->findOne($request['id']); | ||
117 | + $model->$request['field'] = $request['new_url']; | ||
118 | +// print_r($model->validate()); | ||
119 | +// print_r($model->getErrors()); | ||
120 | +// die(var_dump($model->save())); | ||
121 | + $model->save(); | ||
122 | + } | ||
123 | + } | ||
124 | + | ||
125 | + } | ||
126 | + | ||
127 | + | ||
128 | + public function actionDownloadPhoto() | ||
129 | + { | ||
130 | + | ||
131 | + $model = new ImageSizerForm(); | ||
132 | + | ||
133 | + $request = Yii::$app->request->post(); | ||
134 | + if ($request) { | ||
135 | + | ||
136 | + $model->file = UploadedFile::getInstance($model, 'file'); | ||
137 | + | ||
138 | + $md5_file = md5_file($model->file->tempName); | ||
139 | + | ||
140 | + $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); | ||
141 | + | ||
142 | + $imageOrigAlias = Yii::getAlias($imgDir.'original'.'.'.$model->file->extension); | ||
143 | + | ||
144 | + if(!is_dir($imgDir)) { | ||
145 | + mkdir($imgDir, 0755, true); | ||
146 | + } | ||
147 | + | ||
148 | + $model->file->saveAs($imageOrigAlias); | ||
149 | + | ||
150 | + if($request['width'] && $request['height']){ | ||
151 | + | ||
152 | + $imageAlias = Yii::getAlias($imgDir.$request['width'].'x'.$request['height'].'.'.$model->file->extension); | ||
153 | + | ||
154 | + $imageLink = '/storage/'.$md5_file.'/'.$request['width'].'x'.$request['height'].'.'.$model->file->extension; | ||
155 | + | ||
156 | + $this->resizeImg($request['width'], $request['height'], $imageOrigAlias,$imageAlias); | ||
157 | + | ||
158 | + } else { | ||
159 | + | ||
160 | + $imageLink = '/storage/'.$md5_file.'/'.'original'.'.'.$model->file->extension; | ||
161 | + | ||
162 | + } | ||
163 | + | ||
164 | + | ||
165 | + if($model->multi){ | ||
166 | + $view = $this->renderPartial('@app/components/views/_gallery_item', [ | ||
167 | + 'item' => ['image'=>$imageLink], | ||
168 | + ]); | ||
169 | + | ||
170 | + return json_encode(['link'=>$imageLink, 'view' =>$view]); | ||
171 | + | ||
172 | + | ||
173 | + } else { | ||
174 | + return json_encode(['link'=>$imageLink]); | ||
175 | + } | ||
176 | + | ||
177 | + | ||
178 | + } | ||
179 | + } | ||
180 | + | ||
181 | + | ||
182 | + public function getex($filename) { | ||
183 | + return end(explode(".", $filename)); | ||
184 | + } | ||
185 | + | ||
186 | + | ||
187 | + public function actionImagesUpload(){ | ||
188 | + if($_FILES['upload']) | ||
189 | + { | ||
190 | + if (($_FILES['upload'] == "none") OR (empty($_FILES['upload']['name'])) ) | ||
191 | + { | ||
192 | + $message = "Вы не выбрали файл"; | ||
193 | + } | ||
194 | + else if ($_FILES['upload']["size"] == 0 OR $_FILES['upload']["size"] > 2050000) | ||
195 | + { | ||
196 | + $message = "Размер файла не соответствует нормам"; | ||
197 | + } | ||
198 | + else if (($_FILES['upload']["type"] != "image/jpeg") AND ($_FILES['upload']["type"] != "image/jpeg") AND ($_FILES['upload']["type"] != "image/png") AND ($_FILES['upload']['type'] != 'image/gif')) | ||
199 | + { | ||
200 | + $message = "Допускается загрузка только картинок JPG и PNG."; | ||
201 | + } | ||
202 | + else if (!is_uploaded_file($_FILES['upload']["tmp_name"])) | ||
203 | + { | ||
204 | + $message = "Что-то пошло не так. Попытайтесь загрузить файл ещё раз."; | ||
205 | + } | ||
206 | + else{ | ||
207 | + $name =rand(1, 1000).md5($_FILES['upload']['name']).'.'.$this->getex($_FILES['upload']['name']); | ||
208 | + move_uploaded_file($_FILES['upload']['tmp_name'], "../../storage/images/".$name); | ||
209 | + $full_path = '/storage/images/'.$name; | ||
210 | + $message = "Файл ".$_FILES['upload']['name']." загружен"; | ||
211 | + $size=@getimagesize('images/'.$name); | ||
212 | + | ||
213 | + } | ||
214 | + $callback = $_REQUEST['CKEditorFuncNum']; | ||
215 | + echo '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction("'.$callback.'", "'.$full_path.'", "'.$message.'" );</script>'; | ||
216 | + } | ||
217 | + } | ||
218 | + | ||
219 | + | ||
220 | +} | ||
0 | \ No newline at end of file | 221 | \ No newline at end of file |
frontend/views/accounts/_form.php
@@ -2,7 +2,8 @@ | @@ -2,7 +2,8 @@ | ||
2 | 2 | ||
3 | use yii\helpers\Html; | 3 | use yii\helpers\Html; |
4 | use yii\widgets\ActiveForm; | 4 | use yii\widgets\ActiveForm; |
5 | - | 5 | +use mihaildev\ckeditor\CKEditor; |
6 | +use mihaildev\elfinder\ElFinder; | ||
6 | ?> | 7 | ?> |
7 | 8 | ||
8 | <?php $form = ActiveForm::begin(); ?> | 9 | <?php $form = ActiveForm::begin(); ?> |
@@ -41,7 +42,14 @@ use yii\widgets\ActiveForm; | @@ -41,7 +42,14 @@ use yii\widgets\ActiveForm; | ||
41 | 42 | ||
42 | <?= $form->field($user_info, 'prepayment')->textInput() ?> | 43 | <?= $form->field($user_info, 'prepayment')->textInput() ?> |
43 | 44 | ||
44 | -<?= $form->field($user_info, 'about')->textarea(['rows' => 6]) ?> | 45 | +<?= $form->field($user_info, 'about')->widget(CKEditor::className(),[ |
46 | + 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ | ||
47 | + 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать | ||
48 | + 'inline' => false, //по умолчанию false]), | ||
49 | + 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/images-upload') | ||
50 | + ] | ||
51 | + ) | ||
52 | +]); ?> | ||
45 | 53 | ||
46 | <?= \common\widgets\FieldEditor::widget([ | 54 | <?= \common\widgets\FieldEditor::widget([ |
47 | 'template'=>'education', | 55 | 'template'=>'education', |