Blame view

common/behaviors/ShowImage.php 1013 Bytes
9217ef8e   Administrator   09.02.16
1
2
3
4
5
6
7
8
9
10
  <?php
  
  namespace common\behaviors;
  
  use yii;
  use yii\base\Behavior;
  
  class ShowImage extends Behavior
  {
      function minImg($dir, $width, $height=null){
1aca8918   Administrator   09.02.16
11
          if(empty($dir)){
0eb4e7fc   Yarik   test
12
              return '/images/avatar-bg.png';
1aca8918   Administrator   09.02.16
13
14
          }
  
9217ef8e   Administrator   09.02.16
15
16
17
          if($width=='original'){
              $preg = '/\/(.[^\/]*)$/';
              preg_match('/\.(.[^.]*)$/', $dir, $type);
df799956   Administrator   16.03.16
18
19
20
21
              if(isset($type[1])){
                  $dir = preg_replace( $preg, '/original.'.$type[1],  $dir);
              }
  
9217ef8e   Administrator   09.02.16
22
23
24
          } else {
              $preg = '/\/(.[^\/]*)$/';
              preg_match('/\.(.[^.]*)$/', $dir, $type);
df799956   Administrator   16.03.16
25
26
27
28
              if(isset($type[1])){
                  $dir =  preg_replace( $preg, '/'.$width.'x'.$height.'.'.$type[1],  $dir);
              }
  
9217ef8e   Administrator   09.02.16
29
30
          }
          
df799956   Administrator   16.03.16
31
          return $dir;
9217ef8e   Administrator   09.02.16
32
33
34
35
  
  
      }
  
34e7b1a4   Administrator   15.02.16
36
37
38
39
40
41
42
43
44
45
46
47
      function ShowGallery($array){
  
          $gallery = explode(',', $array );
          if(is_array($gallery)){
              array_splice($gallery,-1);
              return $gallery;
          } else {
              return [];
          }
  
      }
  
1a7bb1e7   Administrator   09.02.16
48
  
9217ef8e   Administrator   09.02.16
49
  }