diff --git a/common/config/main-local.php b/common/config/main-local.php index fc2943b..f47e800 100755 --- a/common/config/main-local.php +++ b/common/config/main-local.php @@ -3,9 +3,9 @@ return [ 'components' => [ 'db' => [ 'class' => 'yii\db\Connection', - 'dsn' => 'pgsql:host=127.0.0.1;port=5432;dbname=mfp_local', - 'username' => 'postgres', - 'password' => '', + 'dsn' => 'pgsql:host=195.248.225.149;port=5432;dbname=mfp', + 'username' => 'test33', + 'password' => 'E4q2N7i9', 'schemaMap' => [ 'pgsql'=> [ 'class'=>'yii\db\pgsql\Schema', diff --git a/common/models/ImageSizerForm.php b/common/models/ImageSizerForm.php new file mode 100755 index 0000000..278d1e2 --- /dev/null +++ b/common/models/ImageSizerForm.php @@ -0,0 +1,38 @@ + 255], + [['model', 'form',], 'string'], + [['file','img','price_list'], 'file'], + ]; + } +} \ No newline at end of file diff --git a/common/widgets/ImageResizer.php b/common/widgets/ImageResizer.php new file mode 100755 index 0000000..dc8fa57 --- /dev/null +++ b/common/widgets/ImageResizer.php @@ -0,0 +1,185 @@ +request->post(); + + if ($request) { + + if(isset($request['old_img'])){ + $this->deleteImages($request['old_img']); + } + + + $model->file = UploadedFile::getInstance($model, 'file'); + + if(!$model->file){ + return json_encode(["error"=>"Не указан файл"]); + } + + $md5_file = md5_file($model->file->tempName); + + $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); + + $imageOrigAlias = Yii::getAlias($imgDir.'original'.'.'.$model->file->extension); + + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + + $model->file->saveAs($imageOrigAlias); + + if($request['width'] && $request['height']){ + + $imageAlias = Yii::getAlias($imgDir.$request['width'].'x'.$request['height'].'.'.$model->file->extension); + + $imageLink = '/storage/'.$md5_file.'/'.$request['width'].'x'.$request['height'].'.'.$model->file->extension; + + $this->resizeImg($request['width'],$request['height'], $imageOrigAlias,$imageAlias); + + } else { + + $imageLink = '/storage/'.$md5_file.'/'.'original'.'.'.$model->file->extension; + + } + + + if($model->multi){ +// $view = $this->renderPartial('@app/components/views/_gallery_item', [ +// 'item' => ['image'=>$imageLink], +// ]); +// +// return json_encode(['link'=>$imageLink, 'view' =>$view]); + + + } else { + $p1[0] = ""; + return json_encode(['success','initialPreview' => $p1, 'append' => false, 'name' =>$imageLink,]); + } + + + } else { + return json_encode(['error']); + } + + + + + } + + + public function isBigger($width,$height,$w,$h) + { + if($width>$w){ + return true; + }else if($height >$h) { + return true; + } + return false; + } + + + + + + public function resizeImg($w, $h, $imageAlias,$imageAliasSave) + { + $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); + + $size = $img->getSize(); + + $width = $size->getWidth(); + $height = $size->getHeight(); + + $e_width = $w/$h; + $e_height = $h/$w; + + $e1_width = $width/$height; + $e1_height = $height/$width; + + if($this->isBigger($width,$height,$w,$h)){ + if($e_width<$e1_width){ + $new_width = $width*($e_width/$e1_width); + $width = $new_width; + }else { + $new_height = $height*($e_height/$e1_height); + $height = $new_height; + } + + + } else { + $img->save($imageAliasSave, array('flatten' => false)); + return true; + } + + + Image::crop($imageAlias, $width, $height,[0,0]) + ->save(Yii::getAlias($imageAliasSave), ['quality' => + 100]); + + + $imagine = new Imagine(); + $imagine->open($imageAliasSave) + ->resize(new Box($w, $h)) + ->save($imageAliasSave, array('flatten' => false)); + + + + } + + + private function deleteImages($old_img){ + + if(!empty($old_img) && file_exists($_SERVER['DOCUMENT_ROOT'].$old_img)){ + + $rootDir = explode("/", $old_img); + + $row = $_SERVER['DOCUMENT_ROOT'].'/'.$rootDir[1].'/'.$rootDir[2].'/'; + + $allFiles = scandir($row); + + $allFiles = array_slice($allFiles, 2); + + foreach($allFiles as $oldFile){ + + unlink($row.$oldFile); + + } + + } + } + + public function actionDeleteImage(){ + $old_img = Yii::$app->request->post('old_img'); + + if ($old_img) { + $this->deleteImages($old_img); + } + } + + + +} \ No newline at end of file diff --git a/common/widgets/views/_gallery_item.php b/common/widgets/views/_gallery_item.php new file mode 100755 index 0000000..e8febd9 --- /dev/null +++ b/common/widgets/views/_gallery_item.php @@ -0,0 +1,8 @@ + + \ No newline at end of file diff --git a/common/widgets/views/image_sizer.php b/common/widgets/views/image_sizer.php new file mode 100755 index 0000000..4b9cb0d --- /dev/null +++ b/common/widgets/views/image_sizer.php @@ -0,0 +1,134 @@ +registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/vendor/jquery.ui.widget.js'); +$this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.iframe-transport.js'); +$this->registerJsFile('@web/js/vendor/bower/jquery-file-upload/js/jquery.fileupload.js'); +$this->registerCssFile('@web/js/vendor/bower/jquery-file-upload/css/jquery.fileupload.css'); + +?> +
+ + + + + + $field, 'data-url'=>"/admin/site/download-photo" ]);?> + + + "{$field}_picture_link"]) ?> + + + +
+ $field ? Html::img($model->$field): '' ?> +
+ + + + + + + + + + $field, 'data-url'=>"/admin/site/download-photo", 'multiple'=> 'multiple' ]);?> + + + "{$field}_picture_link"]) ?> + + + + +
+ context->getGallery() as $image){ + echo $this->render('_gallery_item', [ 'item' => ['image'=>$image]]); + } + ?> +
+ + + +
\ No newline at end of file diff --git a/composer.json b/composer.json index ca01b54..ea847ea 100755 --- a/composer.json +++ b/composer.json @@ -23,7 +23,9 @@ "kartik-v/yii2-widget-select2": "@dev", "mihaildev/yii2-ckeditor": "*", "developeruz/yii2-db-rbac": "*", - "nodge/yii2-eauth": "*" + "nodge/yii2-eauth": "*", + "yiisoft/yii2-imagine": "^2.0", + "mihaildev/yii2-elfinder": "^1.1" }, "require-dev": { "yiisoft/yii2-codeception": "*", diff --git a/composer.lock b/composer.lock index 42b0876..7ec940f 100755 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "e9b955ba46cc8543c15ffcde1924e173", - "content-hash": "269319a9b7db2499c82b3ac2409e9b8d", + "hash": "d07e2c10b604fb6b814d10b2de6dcd2f", + "content-hash": "2d0acd792b2e28f03338a962c2923bbe", "packages": [ { "name": "almasaeed2010/adminlte", @@ -557,6 +557,63 @@ "time": "2013-11-30 08:25:19" }, { + "name": "imagine/imagine", + "version": "0.5.x-dev", + "source": { + "type": "git", + "url": "https://github.com/avalanche123/Imagine.git", + "reference": "343580fceed1f89220481ac98480e92f47d91e6c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/avalanche123/Imagine/zipball/343580fceed1f89220481ac98480e92f47d91e6c", + "reference": "343580fceed1f89220481ac98480e92f47d91e6c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "sami/sami": "dev-master" + }, + "suggest": { + "ext-gd": "to use the GD implementation", + "ext-gmagick": "to use the Gmagick implementation", + "ext-imagick": "to use the Imagick implementation" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-develop": "0.5-dev" + } + }, + "autoload": { + "psr-0": { + "Imagine": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bulat Shakirzyanov", + "email": "mallluhuct@gmail.com", + "homepage": "http://avalanche123.com" + } + ], + "description": "Image processing for PHP 5.3", + "homepage": "http://imagine.readthedocs.org/", + "keywords": [ + "drawing", + "graphics", + "image manipulation", + "image processing" + ], + "time": "2014-06-13 10:54:04" + }, + { "name": "kartik-v/yii2-krajee-base", "version": "v1.7.9", "source": { @@ -612,7 +669,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/kartik-v/yii2-widget-select2/zipball/701bf8069a85fafbac1ced54dcd00e579e60471b", + "url": "https://api.github.com/repos/kartik-v/yii2-widget-select2/zipball/519241c7360a0470624f24d872741e1ea880de75", "reference": "701bf8069a85fafbac1ced54dcd00e579e60471b", "shasum": "" }, @@ -764,6 +821,56 @@ "time": "2014-11-19 22:04:08" }, { + "name": "mihaildev/yii2-elfinder", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/MihailDev/yii2-elfinder.git", + "reference": "64b42572dec94e5c2d0d1630bce8292848a98f4b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/MihailDev/yii2-elfinder/zipball/64b42572dec94e5c2d0d1630bce8292848a98f4b", + "reference": "64b42572dec94e5c2d0d1630bce8292848a98f4b", + "shasum": "" + }, + "require": { + "yiisoft/yii2-jui": "*" + }, + "type": "yii2-extension", + "extra": { + "asset-installer-paths": { + "npm-asset-library": "vendor/npm", + "bower-asset-library": "vendor/bower" + } + }, + "autoload": { + "psr-4": { + "mihaildev\\elfinder\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Mihail", + "email": "mihail.kucher@gmail.com", + "homepage": "https://github.com/MihailDev", + "role": "Developer" + } + ], + "description": "Yii2 ElFinder", + "homepage": "https://github.com/MihailDev/yii2-elfinder", + "keywords": [ + "elfinder", + "filemanager", + "yii" + ], + "time": "2015-07-03 07:08:52" + }, + { "name": "nodge/lightopenid", "version": "1.1.2", "source": { @@ -977,7 +1084,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/e4359f68b70caede1e09ecefb56e9435f7d140af", + "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/7ccbfdf4cfb0ce025e27455dc3e516af23eb2800", "reference": "e4359f68b70caede1e09ecefb56e9435f7d140af", "shasum": "" }, @@ -1159,6 +1266,54 @@ "time": "2015-12-01 20:06:03" }, { + "name": "yiisoft/yii2-imagine", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/yiisoft/yii2-imagine.git", + "reference": "586c9c99cb541ec4d4d2ec2a206b08a6fd6de888" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yiisoft/yii2-imagine/zipball/586c9c99cb541ec4d4d2ec2a206b08a6fd6de888", + "reference": "586c9c99cb541ec4d4d2ec2a206b08a6fd6de888", + "shasum": "" + }, + "require": { + "imagine/imagine": "0.5.*", + "yiisoft/yii2": "*" + }, + "type": "yii2-extension", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "yii\\imagine\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Antonio Ramirez", + "email": "amigo.cobos@gmail.com" + } + ], + "description": "The Imagine integration for the Yii framework", + "keywords": [ + "helper", + "image", + "imagine", + "yii2" + ], + "time": "2015-09-29 10:49:20" + }, + { "name": "yiisoft/yii2-jui", "version": "dev-master", "source": { @@ -1168,7 +1323,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-jui/zipball/7ab7ff56bd54500212523e38f5fe3b9210325041", + "url": "https://api.github.com/repos/yiisoft/yii2-jui/zipball/1425ab29929dd195f468d3c4eb340ab509f28b83", "reference": "7ab7ff56bd54500212523e38f5fe3b9210325041", "shasum": "" }, @@ -1297,7 +1452,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/de2ed3bbe68254efeff68db60092fc8ed5298055", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/e493d3dc48d15a6d44e213d02c729ad61cc758a9", "reference": "de2ed3bbe68254efeff68db60092fc8ed5298055", "shasum": "" }, diff --git a/frontend/controllers/FileController.php b/frontend/controllers/FileController.php new file mode 100644 index 0000000..534057c --- /dev/null +++ b/frontend/controllers/FileController.php @@ -0,0 +1,220 @@ +$w){ + return true; + }else if($height >$h) { + return true; + } + return false; + } + + + private function resizeImg($w, $h, $imageAlias,$imageAliasSave){ + $img = Image::getImagine()->open(Yii::getAlias($imageAlias)); + + $size = $img->getSize(); + + $width = $size->getWidth(); + $height = $size->getHeight(); + + $e_width = $w/$h; + $e_height = $h/$w; + + $e1_width = $width/$height; + $e1_height = $height/$width; + + + if($this->isBigger($width,$height,$w,$h)){ + if($e_width<$e1_width){ + + $new_width = $width*($e_width/$e1_width); + + $y = 0; + $x = $width/ 2-($new_width/2); + $width = $new_width; + + }else { + + $new_height = $height*($e_height/$e1_height); + $x = 0; + $y = $height/2-($new_height/2); + $height = $new_height; + } + + + } else { + $img->save($imageAliasSave, array('flatten' => false)); + return true; + } + + + Image::crop($imageAlias, $width, $height,[$x,$y]) + ->save(Yii::getAlias($imageAliasSave), ['quality' => + 100]); + + + $imagine = new Imagine(); + $imagine->open($imageAliasSave) + ->resize(new Box($w, $h)) + ->save($imageAliasSave, array('flatten' => false)); + + + + } + + private function deleteImages($old_img){ + + if(!empty($old_img) && file_exists($_SERVER['DOCUMENT_ROOT'].$old_img)){ + +// $rootDir = explode("/", $old_img); +// +// $row = $_SERVER['DOCUMENT_ROOT'].'/'.$rootDir[1].'/'.$rootDir[2].'/'; +// +// $allFiles = scandir($row); +// +// $allFiles = array_slice($allFiles, 2); +// +// foreach($allFiles as $oldFile){ +// +// unlink($row.$oldFile); +// +// } + + } + } + + public function actionDeleteImage(){ + + $request = Yii::$app->request->post(); + + if($request){ + if ($request['old_img']) { + $this->deleteImages($request['old_img']); + } + if(isset($request['action']) && $request['action']=='save'){ + $object = str_replace('-', '\\',$request['model']); + $model = new $object; + $model = $model->findOne($request['id']); + $model->$request['field'] = $request['new_url']; +// print_r($model->validate()); +// print_r($model->getErrors()); +// die(var_dump($model->save())); + $model->save(); + } + } + + } + + + public function actionDownloadPhoto() + { + + $model = new ImageSizerForm(); + + $request = Yii::$app->request->post(); + if ($request) { + + $model->file = UploadedFile::getInstance($model, 'file'); + + $md5_file = md5_file($model->file->tempName); + + $imgDir = Yii::getAlias('@storage/'.$md5_file.'/'); + + $imageOrigAlias = Yii::getAlias($imgDir.'original'.'.'.$model->file->extension); + + if(!is_dir($imgDir)) { + mkdir($imgDir, 0755, true); + } + + $model->file->saveAs($imageOrigAlias); + + if($request['width'] && $request['height']){ + + $imageAlias = Yii::getAlias($imgDir.$request['width'].'x'.$request['height'].'.'.$model->file->extension); + + $imageLink = '/storage/'.$md5_file.'/'.$request['width'].'x'.$request['height'].'.'.$model->file->extension; + + $this->resizeImg($request['width'], $request['height'], $imageOrigAlias,$imageAlias); + + } else { + + $imageLink = '/storage/'.$md5_file.'/'.'original'.'.'.$model->file->extension; + + } + + + if($model->multi){ + $view = $this->renderPartial('@app/components/views/_gallery_item', [ + 'item' => ['image'=>$imageLink], + ]); + + return json_encode(['link'=>$imageLink, 'view' =>$view]); + + + } else { + return json_encode(['link'=>$imageLink]); + } + + + } + } + + + public function getex($filename) { + return end(explode(".", $filename)); + } + + + public function actionImagesUpload(){ + if($_FILES['upload']) + { + if (($_FILES['upload'] == "none") OR (empty($_FILES['upload']['name'])) ) + { + $message = "Вы не выбрали файл"; + } + else if ($_FILES['upload']["size"] == 0 OR $_FILES['upload']["size"] > 2050000) + { + $message = "Размер файла не соответствует нормам"; + } + 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')) + { + $message = "Допускается загрузка только картинок JPG и PNG."; + } + else if (!is_uploaded_file($_FILES['upload']["tmp_name"])) + { + $message = "Что-то пошло не так. Попытайтесь загрузить файл ещё раз."; + } + else{ + $name =rand(1, 1000).md5($_FILES['upload']['name']).'.'.$this->getex($_FILES['upload']['name']); + move_uploaded_file($_FILES['upload']['tmp_name'], "../../storage/images/".$name); + $full_path = '/storage/images/'.$name; + $message = "Файл ".$_FILES['upload']['name']." загружен"; + $size=@getimagesize('images/'.$name); + + } + $callback = $_REQUEST['CKEditorFuncNum']; + echo ''; + } + } + + +} \ No newline at end of file diff --git a/frontend/views/accounts/_form.php b/frontend/views/accounts/_form.php index e98f755..2ac8c36 100644 --- a/frontend/views/accounts/_form.php +++ b/frontend/views/accounts/_form.php @@ -2,7 +2,8 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; - +use mihaildev\ckeditor\CKEditor; +use mihaildev\elfinder\ElFinder; ?> @@ -41,7 +42,14 @@ use yii\widgets\ActiveForm; field($user_info, 'prepayment')->textInput() ?> -field($user_info, 'about')->textarea(['rows' => 6]) ?> +field($user_info, 'about')->widget(CKEditor::className(),[ + 'editorOptions' => ElFinder::ckeditorOptions('elfinder',[ + 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать + 'inline' => false, //по умолчанию false]), + 'filebrowserUploadUrl'=>Yii::$app->getUrlManager()->createUrl('file/images-upload') + ] + ) +]); ?> 'education', diff --git a/storage/index.php b/storage/index.php new file mode 100644 index 0000000..0681616 --- /dev/null +++ b/storage/index.php @@ -0,0 +1,8 @@ +