C:\xampp\htdocs\kptv\admin\spaw\plugins\spawfm\class\spawfm.class.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
error_reporting
(E_ALL);
class 
SpawFm
{
  var 
$thumbnails_enabled false;
  var 
$current_dir false;
  var 
$current_dir_data false;
  var 
$current_type false;
  var 
$image_ext = array('.gif''.png''.jpg''.jpeg');
  
  function 
SpawFm()
  {
  }
  
  
  function 
normalizeDir($dir$stripslashes false)
  {
    if (!
strlen($dir))
      return 
false;
    
$dir str_replace('\\''/'$dir);
    
$dir preg_replace('|^/*(.*)|''/$1'$dir);
    
$dir preg_replace('|/*$|'''$dir).'/';
    if (
$stripslashes
      return 
SpawVars::stripSlashes($dir);
    return 
$dir;
  }
  
  
  function 
getFileIcon($filename)
  {
    
$icons SpawFm::getFileIconsDefinition($filename);
    return 
$icons['icon'];
  }
  
  function 
getFileIconBig($filename)
  {
    
$icons SpawFm::getFileIconsDefinition($filename);
    return 
$icons['icon_big'];
  }
  
  function 
getFileIconsDefinition($filename
  {
    global 
$config;
    static 
$spawfm_ftypes_icons;
    
$icons false;
    
$ext SpawFm::getFileExtension($filename);
    if (!isset(
$spawfm_ftypes_icons[$ext])) {
      
// search for icon definition for this extension 
      
$icons_def $config->getConfigValue('PG_SPAWFM_FILETYPES_ICONS');
      foreach (
$icons_def as $definition) {
        if (
in_array($ext$definition['extensions'])) {
          
$icons = array(
            
'icon'      => $definition['icon'],
            
'icon_big'  => $definition['icon_big'],
          );
          break;
        }
      }
      
      
// set default icon if definition not found
      
if (!$icons) {
        
$icons $config->getConfigValue('PG_SPAWFM_FILETYPES_ICON_DEFAULT');
      }
      
$spawfm_ftypes_icons[$ext] = $icons;
    } else {
      
$icons $spawfm_ftypes_icons[$ext];
    }
    return 
$icons;
  }
  
  function 
getFileThumbnail($filename)
  {
    
$icons SpawFm::getFileIconsDefinition($filename);
    return 
'plugins/spawfm/img/'.$icons['icon_big'];
  }
  
  function 
getFileSize($file)
  {
    
$fsize = @filesize($this->getCurrentDir().$file);
    if (!
$fsize)
      
$fsize 0;
    return 
$fsize;
  }
   
  function 
getFileDate($file)
  {
    
$fdate = @filemtime($this->getCurrentDir().$file);
    if (!
$fdate)
      
$fdate 0;
    return 
$fdate;
  }
  
  function 
isImage($file)
  {
    
$ext $this->getFileExtension($filename);
    if (
in_array($ext$this->image_ext)) {
      return 
true;
    }
    return 
false;
  }
  
  function 
isThumbailsModePossible($dir_path)
  {
    
// check required system tools for image resizing
    // check if current directory is writable
    
return true;
  }
  
  function 
setCurrentDir($dir_path)
  {
    
$this->current_dir $dir_path;
  }
  function 
getCurrentDir()
  {
    return 
$this->current_dir;
  }
  
  function 
setCurrentDirData($dir_data)
  {
    
$this->current_dir_data $dir_data;
  }
  function 
getCurrentDirData()
  {
    return 
$this->current_dir_data;
  }
  
  function 
setCurrentType($type)
  {
    
$this->current_type $type;
  }
  function 
getCurrentType()
  {
    return 
$this->current_type;
  }
  
  
// returns allowed extensions for selected directory and type
  
function getAllowedExtensions()
  {
    global 
$config;
    
$allowed_ext = array();
    if (!
$curr_dir $this->getCurrentDir() or !$curr_dir_data $this->getCurrentDirData()) {
      return 
$allowed_ext;
    }
    
    
$filetypes $config->getConfigValue('PG_SPAWFM_FILETYPES');
    
    if (
$curr_type $this->getCurrentType()) {
      
$allowed_ext $filetypes[$curr_type];
    } elseif (!empty(
$curr_dir_data['params']['allowed_filetypes'])) {
      if (!
is_array($curr_dir_data['params']['allowed_filetypes'])) {
        
$curr_dir_data['params']['allowed_filetypes'] = array($curr_dir_data['params']['allowed_filetypes']);
      }
      if (
sizeof($curr_dir_data['params']['allowed_filetypes'])) {
        foreach (
$curr_dir_data['params']['allowed_filetypes'] as $ftype) {
          if (
strlen($ftype) and $ftype{0} == '.') { // extension specified
            
$allowed_ext[] = $ftype;
          } elseif (isset(
$filetypes[$ftype])) { // filetype group specified
            
$allowed_ext array_merge($allowed_ext$filetypes[$ftype]);
          }
        }
      }
    }
    return 
$allowed_ext;
  }
  
  
// returns list of files in current directory
  
function getFilesList()
  {
    global 
$lang;
    
$files = array();
    
    if (!
$curr_dir $this->getCurrentDir() or !$curr_dir_data $this->getCurrentDirData()) {
      return 
$files;
    }

    
$allowed_ext $this->getAllowedExtensions();
    if (
$dh = @opendir($curr_dir)) {
      while (
false !== ($file readdir($dh))) {
        if (
is_dir($curr_dir.$file)) 
        {
          
// TO DO
        
} else {
          
          
$ext SpawFm::getFileExtension($file);
          if (
in_array('.*'$allowed_ext) or in_array($ext$allowed_ext)) {
            if (!
strlen($fdescr $lang->m($ext'filetypes'))) {
              
$fdescr strtoupper(substr($ext1)).' '.
                        
$lang->m('filetype_suffix''file_details');
            }
            
            
// additional info
            
if ($imgsize = @getimagesize($curr_dir.$file)) {
              
$other $lang->m('img_dimensions''file_details').': '.$imgsize[0].'x'.$imgsize[1];
            } else {
              
$other '';
            }
            
            
$files[] = array(
              
'type'      => 'F',
              
'name'      => $file,
              
'size'      => $this->getFileSize($file),
              
'date'      => $this->getFileDate($file),
              
'fdescr'    => $fdescr,
              
'icon'      => 'plugins/spawfm/img/'.$this->getFileIcon($file),
              
'icon_big'  => 'plugins/spawfm/img/'.$this->getFileIconBig($file),
              
'thumb'     => $this->getFileThumbnail($file),
              
'other'     => $other
            
);
            
            
// get thumbail
            // TO DO
          
}
        }
      }
      
closedir($dh);
    } else {
      return 
false;
    }
    return 
$files;
  }
  
  function 
setThumbnailsEnabled($status false)
  {
    
$this->thumbnails_enabled $status;
  }
  
  function 
getThumbnailsEnabled()
  {
    return 
$this->thumbnails_enabled;
  }
  
  
// static helper methods
  
function getFileExtension($filename)
  {
    return 
strtolower(strrchr($filename'.'));
  }
  
  
// adds slashes before single quotes
  
function escJsStr($str)
  {
    return 
addcslashes($str'\'');
  }
  
  
// strip leading slash
  
function stripLeadSlash($dir)
  {
    if (
strlen($dir) and ($dir{0} == '/' or $dir{0} == '\\')) {
      return 
substr($dir1);
    }
    return 
$dir;
  }
}
?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586