Commit 55bd0bb9f0db81fb629eed7df86c1e19c95bdd35

Authored by Yarik
1 parent 282b6e56

Commit

common/behaviors/ShowImage.php
1 <?php 1 <?php
2 - 2 +
3 namespace common\behaviors; 3 namespace common\behaviors;
4 - 4 +
5 use common\modules\file\components\UploaderComponent; 5 use common\modules\file\components\UploaderComponent;
6 use yii; 6 use yii;
7 use yii\base\Behavior; 7 use yii\base\Behavior;
8 - 8 + use yii\imagine\Image;
  9 +
9 class ShowImage extends Behavior 10 class ShowImage extends Behavior
10 { 11 {
11 - 12 +
12 /** 13 /**
13 * Resize image and return its path. 14 * Resize image and return its path.
14 * 15 *
@@ -24,14 +25,14 @@ @@ -24,14 +25,14 @@
24 if(empty( $dir )) { 25 if(empty( $dir )) {
25 return '/images/imageNotFound.jpg'; 26 return '/images/imageNotFound.jpg';
26 } 27 }
27 - 28 +
28 if($width == 'original') { 29 if($width == 'original') {
29 $preg = '/\/(.[^\/]*)$/'; 30 $preg = '/\/(.[^\/]*)$/';
30 preg_match('/\.(.[^.]*)$/', $dir, $type); 31 preg_match('/\.(.[^.]*)$/', $dir, $type);
31 if(isset( $type[ 1 ] )) { 32 if(isset( $type[ 1 ] )) {
32 $dir = preg_replace($preg, '/original.' . $type[ 1 ], $dir); 33 $dir = preg_replace($preg, '/original.' . $type[ 1 ], $dir);
33 } 34 }
34 - 35 +
35 } else { 36 } else {
36 $preg = '/\/(.[^\/]*)$/'; 37 $preg = '/\/(.[^\/]*)$/';
37 preg_match('/\.(.[^.]*)$/', $dir, $type); 38 preg_match('/\.(.[^.]*)$/', $dir, $type);
@@ -40,32 +41,27 @@ @@ -40,32 +41,27 @@
40 $storage = dirname(yii\helpers\Url::to('@storage')); 41 $storage = dirname(yii\helpers\Url::to('@storage'));
41 $filename = $storage . $dir; 42 $filename = $storage . $dir;
42 if(!file_exists($filename)) { 43 if(!file_exists($filename)) {
43 - 44 +
44 $original = $storage . dirname($dir) . '/original.' . $type[ 1 ]; 45 $original = $storage . dirname($dir) . '/original.' . $type[ 1 ];
45 $resizer = new UploaderComponent(); 46 $resizer = new UploaderComponent();
46 if(file_exists($original)) { 47 if(file_exists($original)) {
47 $resizer->resizeImg($width, $height, $original, $filename); 48 $resizer->resizeImg($width, $height, $original, $filename);
48 } else { 49 } else {
49 -  
50 - $imageNotFound = yii\helpers\Url::to('@storage')."/imageNotFound".$width."x".$height.".jpg";  
51 - if(!file_exists($imageNotFound)){  
52 - $resizer->resizeImg($width, $height, yii\helpers\Url::to('@storage')."/imageNotFound.jpg", $imageNotFound ); 50 + $imageNotFound = yii\helpers\Url::to('@storage') . "/imageNotFound" . $width . "x" . $height . ".jpg";
  51 + if(!file_exists($imageNotFound)) {
  52 + $resizer->resizeImg($width, $height, yii\helpers\Url::to('@storage') . "/imageNotFound.jpg", $imageNotFound);
53 } 53 }
54 - return "/storage/imageNotFound".$width."x".$height.".jpg";  
55 -  
56 - 54 + return "/storage/imageNotFound" . $width . "x" . $height . ".jpg";
57 } 55 }
58 - 56 +
59 } 57 }
60 - 58 +
61 } 59 }
62 - 60 +
63 } 61 }
64 -  
65 return $dir; 62 return $dir;
66 -  
67 } 63 }
68 - 64 +
69 /** 65 /**
70 * @param string $array String to split 66 * @param string $array String to split
71 * 67 *
@@ -73,23 +69,71 @@ @@ -73,23 +69,71 @@
73 */ 69 */
74 function ShowGallery($array) 70 function ShowGallery($array)
75 { 71 {
76 - 72 +
77 $gallery = explode(',', $array); 73 $gallery = explode(',', $array);
78 if(is_array($gallery)) { 74 if(is_array($gallery)) {
79 array_splice($gallery, -1); 75 array_splice($gallery, -1);
80 return $gallery; 76 return $gallery;
81 } else { 77 } else {
82 - return [ ]; 78 + return [];
83 } 79 }
84 - 80 +
85 } 81 }
86 -  
87 - public function ShowAvatar($dir, $width, $height = NULL) {  
88 - if(empty($dir)) { 82 +
  83 + public function ShowAvatar($dir, $width, $height = NULL)
  84 + {
  85 + if(empty( $dir )) {
89 return '/images/avatar-bg.png'; 86 return '/images/avatar-bg.png';
90 } else { 87 } else {
91 return $this->minImg($dir, $width, $height); 88 return $this->minImg($dir, $width, $height);
92 } 89 }
93 } 90 }
94 - 91 +
  92 + /**
  93 + * Add watermark to image
  94 + *
  95 + * @param string $path image path
  96 + *
  97 + * @return yii\base\Component
  98 + */
  99 + public function watermark($path)
  100 + {
  101 + $watermark_path = Yii::getAlias('@webroot/images/watermark.png');
  102 + $image = Image::getImagine()
  103 + ->open($path);
  104 + $watermark = Image::getImagine()
  105 + ->open($watermark_path);
  106 + $image_size = $image->getSize();
  107 + $watermark_size = $watermark->getSize();
  108 + if($image_size->getWidth() < ($watermark_size->getWidth() + 20) || ($image_size->getHeight() + 20) < $watermark_size->getHeight()) {
  109 + return $this->owner;
  110 + }
  111 + $position_left = $image_size->getWidth() - ($watermark_size->getWidth() + 10);
  112 + Image::watermark($path, $watermark_path, [$position_left, 10])->save(preg_replace('/^(.*)(\.\w+)$/', '${1}_watermark${2}', $path));
  113 + return $this->owner;
  114 + }
  115 +
  116 + function getWatermark($path, $width, $height = NULL)
  117 + {
  118 + if($width == 'original') {
  119 + $path_original = $this->minImg($path, 'original');
  120 + $path_watermark = str_replace('original', 'original_watermark', $path_original);
  121 + if(!file_exists(Yii::getAlias('@documentRoot').$path_watermark)) {
  122 + $this->watermark(Yii::getAlias('@documentRoot').$path_original);
  123 + }
  124 + return $path_watermark;
  125 + } else {
  126 + $path_original = $this->minImg($path, $width, $height);
  127 + preg_match('/^.*(\.\w+)$/', $path_original, $extension);
  128 + $path_watermark = $path_original;
  129 + if(isset($extension[1])) {
  130 + $path_watermark = str_replace($extension[1], '_watermark'.$extension[1], $path_original);
  131 + }
  132 + if(!file_exists(Yii::getAlias('@documentRoot').$path_watermark)) {
  133 + $this->watermark(Yii::getAlias('@documentRoot').$path_original);
  134 + }
  135 + return $path_watermark;
  136 + }
  137 + }
  138 +
95 } 139 }
96 \ No newline at end of file 140 \ No newline at end of file
common/models/Portfolio.php
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 use yii\behaviors\TimestampBehavior; 10 use yii\behaviors\TimestampBehavior;
11 use yii\db\ActiveQuery; 11 use yii\db\ActiveQuery;
12 use yii\db\Expression; 12 use yii\db\Expression;
  13 + use yii\base\Component;
13 14
14 /** 15 /**
15 * This is the model class for table "portfolio". 16 * This is the model class for table "portfolio".
@@ -34,6 +35,8 @@ @@ -34,6 +35,8 @@
34 * @property Rating[] $rating 35 * @property Rating[] $rating
35 * @property string $ratingValue 36 * @property string $ratingValue
36 * @method string minImg( string $dir, $width, $height = NULL ) Resizes image 37 * @method string minImg( string $dir, $width, $height = NULL ) Resizes image
  38 + * @method Component watermark(string $path) Add watermark to image
  39 + * @method string getWatermark(string $path, mixed $width, mixed $height) Get watermarked image
37 * @method array ShowGallery( string $array ) Splits string to image paths array 40 * @method array ShowGallery( string $array ) Splits string to image paths array
38 */ 41 */
39 class Portfolio extends \yii\db\ActiveRecord 42 class Portfolio extends \yii\db\ActiveRecord
frontend/views/company/portfolio-view.php
@@ -40,7 +40,7 @@ @@ -40,7 +40,7 @@
40 if(!empty( $portfolio_user )) { 40 if(!empty( $portfolio_user )) {
41 echo Html::img($portfolio->minImg(ArrayHelper::getValue($portfolio_user_gallery, 0, ''), '720', '280')); 41 echo Html::img($portfolio->minImg(ArrayHelper::getValue($portfolio_user_gallery, 0, ''), '720', '280'));
42 } else { 42 } else {
43 - echo Html::img($portfolio->minImg($portfolio->cover, '720', '280')); 43 + echo Html::img($portfolio->getWatermark($portfolio->cover, '720', '280'));
44 } 44 }
45 ?> 45 ?>
46 </div> 46 </div>
@@ -122,7 +122,7 @@ @@ -122,7 +122,7 @@
122 foreach($portfolio->ShowGallery($portfolio->gallery->photo) as $one_photo) { 122 foreach($portfolio->ShowGallery($portfolio->gallery->photo) as $one_photo) {
123 ?> 123 ?>
124 <li> 124 <li>
125 - <img src="<?= $portfolio->minImg($one_photo, 210, 150) ?>" alt=""/> 125 + <img src="<?= $portfolio->getWatermark($one_photo, 210, 150) ?>" data-original="<?=$portfolio->getWatermark($one_photo, 720, 280)?>" alt=""/>
126 </li> 126 </li>
127 <?php 127 <?php
128 } 128 }
frontend/views/performer/blog-view.php
@@ -4,9 +4,11 @@ @@ -4,9 +4,11 @@
4 * @var Blog $article 4 * @var Blog $article
5 */ 5 */
6 use common\models\Blog; 6 use common\models\Blog;
7 - 7 + use yii\helpers\Html;
  8 + use yii\helpers\Url;
  9 +
8 $this->params[ 'user' ] = $user; 10 $this->params[ 'user' ] = $user;
9 - 11 +
10 $this->title = $article->name; 12 $this->title = $article->name;
11 ?> 13 ?>
12 <div class="performer-vacancy-vacant-title-reclam-wr style"> 14 <div class="performer-vacancy-vacant-title-reclam-wr style">
@@ -29,6 +31,22 @@ @@ -29,6 +31,22 @@
29 <div class="blog-post-content style"> 31 <div class="blog-post-content style">
30 <?= $article->description ?> 32 <?= $article->description ?>
31 </div> 33 </div>
  34 + <div class="share-buttons-new">
  35 + <p class="share-buttons-new-title">Поделиться</p>
  36 + <p class="share-buttons-new-link">
  37 + <?php
  38 + echo Html::a(Html::img('/images/ico-vk.png'), 'http://vk.com/share.php?url=' . Url::current([], true), [
  39 + 'target' => '_blank',
  40 + ]);
  41 + echo Html::a(Html::img('/images/ico-fb.png'), 'http://www.facebook.com/sharer/sharer.php?u=' . Url::current([], true), [
  42 + 'target' => '_blank',
  43 + ]);
  44 + echo Html::a(Html::img('/images/ico-google.png'), 'https://plus.google.com/share?url=' . Url::current([], true), [
  45 + 'target' => '_blank',
  46 + ]);
  47 + ?>
  48 + </p>
  49 + </div>
32 </div> 50 </div>
33 </div> 51 </div>
34 <?php 52 <?php
frontend/views/performer/portfolio-view.php
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 use yii\helpers\ArrayHelper; 7 use yii\helpers\ArrayHelper;
8 use yii\helpers\Html; 8 use yii\helpers\Html;
9 use yii\helpers\Url; 9 use yii\helpers\Url;
  10 + use yii\imagine\Image;
10 use yii\web\ViewAction; 11 use yii\web\ViewAction;
11 use yii\web\View; 12 use yii\web\View;
12 use yii\widgets\Pjax; 13 use yii\widgets\Pjax;
@@ -42,7 +43,7 @@ @@ -42,7 +43,7 @@
42 if(!empty( $portfolio_user )) { 43 if(!empty( $portfolio_user )) {
43 echo Html::img($portfolio->minImg(ArrayHelper::getValue($portfolio_user_gallery, 0, ''), '720', '280')); 44 echo Html::img($portfolio->minImg(ArrayHelper::getValue($portfolio_user_gallery, 0, ''), '720', '280'));
44 } else { 45 } else {
45 - echo Html::img($portfolio->minImg($portfolio->cover, '720', '280')); 46 + echo Html::img($portfolio->getWatermark($portfolio->cover, '720', '280'));
46 } 47 }
47 ?> 48 ?>
48 </div> 49 </div>
@@ -124,7 +125,7 @@ @@ -124,7 +125,7 @@
124 foreach($portfolio->ShowGallery($portfolio->gallery->photo) as $one_photo) { 125 foreach($portfolio->ShowGallery($portfolio->gallery->photo) as $one_photo) {
125 ?> 126 ?>
126 <li> 127 <li>
127 - <img src="<?= $portfolio->minImg($one_photo, 210, 150) ?>" alt="" data-original="<?=$portfolio->minImg($one_photo, 720, 280)?>"/> 128 + <img src="<?= $portfolio->getWatermark($one_photo, 210, 150) ?>" alt="" data-original="<?=$portfolio->getWatermark($one_photo, 720, 280)?>"/>
128 </li> 129 </li>
129 <?php 130 <?php
130 } 131 }
@@ -141,7 +142,6 @@ @@ -141,7 +142,6 @@
141 } 142 }
142 ?> 143 ?>
143 </div> 144 </div>
144 -  
145 <div class="new-portfolio-txt-wrapper style"> 145 <div class="new-portfolio-txt-wrapper style">
146 <div class="new-portfolio-excerpt style"> 146 <div class="new-portfolio-excerpt style">
147 <?php 147 <?php
frontend/web/css/style.css
@@ -12623,4 +12623,17 @@ li.active-menu-admin:hover a .ico_num { @@ -12623,4 +12623,17 @@ li.active-menu-admin:hover a .ico_num {
12623 12623
12624 .left-search-work .admin-specialization-selected ul li:before { 12624 .left-search-work .admin-specialization-selected ul li:before {
12625 right: 8px; 12625 right: 8px;
  12626 +}
  12627 +.share-buttons-new {
  12628 + margin-top: 10px;
  12629 + float: left;
  12630 +}
  12631 +.share-buttons-new .share-buttons-new-title {
  12632 + text-transform: uppercase;
  12633 + font-size: 15px;
  12634 + font-weight: bold;
  12635 +}
  12636 +.share-buttons-new .share-buttons-new-link a {
  12637 + margin-top: 5px;
  12638 + margin-right: 10px;
12626 } 12639 }
12627 \ No newline at end of file 12640 \ No newline at end of file
frontend/web/images/ico-google.png 0 → 100644

2.52 KB

frontend/web/images/watermark.png 0 → 100755

4.27 KB

1 -RewriteEngine on  
2 -RewriteBase /  
3 -RewriteCond %{REQUEST_FILENAME} !-f  
4 -RewriteCond %{REQUEST_FILENAME} !-d  
5 -  
6 -RewriteRule . index.php 1 +RewriteEngine on
  2 +RewriteBase /
  3 +RewriteCond %{REQUEST_FILENAME} !-f
  4 +RewriteCond %{REQUEST_FILENAME} !-d
  5 +
  6 +RewriteRule . index.php