C:\xampp\htdocs\kptv2\admin\spaw\plugins\spawfm\dialogs\spawfm.inc.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<?php
error_reporting
(E_ALL);
function 
dbg($var) {
  echo 
'<pre>';
  
print_r($var);
  echo 
'</pre>';
}

/////////////////////////////////////

$lang->setModule('spawfm');

// load environment variables
$settings $config->getConfigValue('PG_SPAWFM_SETTINGS');
$filetypes $config->getConfigValue('PG_SPAWFM_FILETYPES');
$dir_list $config->getConfigValue('PG_SPAWFM_DIRECTORIES');
$fm_path $config->getConfigValue('DOCUMENT_ROOT');
if (
preg_match('|[\\/]$|'$fm_path))
  
$fm_path substr($fm_path0, -1);
$imgdir $config->getConfigValue('SPAW_DIR').'plugins/spawfm/lib/theme/'.$theme->name.'/img/';

require_once(
$config->getConfigValue('SPAW_ROOT').'plugins/spawfm/class/spawfm.class.php');
$spawfm = new SpawFm;

$error_msg '';

// set default "global" settings if not set by user
if (!isset($settings['allow_upload']))
  
$settings['allow_upload'] = false;
if (!isset(
$settings['allow_modify']))
  
$settings['allow_modify'] = false;
if (!isset(
$settings['max_upload_filesize']))
  
$settings['max_upload_filesize'] = 0;
if (!isset(
$settings['recursive']))
  
$settings['recursive'] = false;
if (!isset(
$settings['allowed_filetypes']))
  
$settings['allowed_filetypes'] = array('any');
if (!isset(
$settings['recursive']))
  
$settings['recursive'] = false;

// fetch context variables
$curr_dir SpawFm::normalizeDir(SpawVars::getPostVar('dir') ? SpawVars::getPostVar('dir') : SpawVars::getGetVar('dir'), true);

$curr_type SpawVars::getPostVar('type') ? SpawVars::stripSlashes(SpawVars::getPostVar('type')) : SpawVars::stripSlashes(SpawVars::getGetVar('type'));
if (
$curr_type == '*')
  
$curr_type false;
$type_fixed SpawVars::getGetVar('nofilter');

// build directories list, determine selected option
$dirs = array();
$curr_dir_data false;
$curr_dir_valid false;
$all_types = array();
foreach (
$dir_list as $dirdef) {
  if (
is_string($dirdef)) { // simple dir definition
    
$dir $caption $dirdef;
    
$params $settings;
  } elseif (
is_array($dirdef) and isset($dirdef['dir'])) { // advanced dir definition
    
$dir $dirdef['dir'];
    
$caption = (!empty($dirdef['caption'])) ? $dirdef['caption'] : $dir;
    
$params = (!empty($dirdef['params'])) ? array_merge($settings$dirdef['params']) : $settings;
  } else {
    
$dir false
  }
  if (
$dir !== false)
    
$dir SpawFm::normalizeDir($dir);
  if (
$dir and file_exists($fm_path.$dir)) {
    
$dir_data = array(
      
'dir'     => $dir,
      
'caption' => $caption,
      
'params'  => $params,
    );
    
$dirs[] = $dir_data;
    
// set default dir if needed
    
if (!$curr_dir and !empty($params['default_dir'])) {
      
$curr_dir $dir;
    }
    
    
// track filetypes allowed
    
if (is_array($params['allowed_filetypes'])) {
      
$all_types array_merge($all_types$params['allowed_filetypes']);
    } else {
      
$all_types[] = $params['allowed_filetypes'];
    }
    
    
// load current directory data
    
if ($dir == $curr_dir) {
      
$curr_dir_valid true;
      
$curr_dir_data $dir_data;
    }
  }
}

// cleanup filetypes array
$all_types array_unique($all_types);
foreach (
$all_types as $key=>$type) {
  if (
$type{0} == '.' or $type == 'any' or !isset($filetypes[$type])) {
    unset(
$all_types[$key]);
  }
}
// check selected type for validity
if ($curr_type and (!in_array($curr_type$all_types) or !isset($filetypes[$curr_type]))) {
  
$curr_type false;
}

// filter out directories not matching current type, reset $curr_dir if needed
if ($curr_type) {
  
$curr_dir_reset false;
  foreach (
$dirs as $key=>$val) {
    if (empty(
$val['params']['allowed_filetypes']) or 
        (
is_string($val['params']['allowed_filetypes']) and $val['params']['allowed_filetypes'] != 'any' and $val['params']['allowed_filetypes'] != $curr_type) or
        (
is_array($val['params']['allowed_filetypes']) and !in_array($curr_type$val['params']['allowed_filetypes']) and !in_array('any'$val['params']['allowed_filetypes']))) 
    {
      unset(
$dirs[$key]);
      if (
$val['dir'] == $curr_dir) {
        
$curr_dir $curr_dir_valid $curr_dir_data false;
      }
    } elseif (!
$curr_dir or ($curr_dir and $curr_dir_reset and !empty($val['params']['default_dir']))) {
      
$curr_dir_reset true;
      
$curr_dir_valid true;
      
$curr_dir $val['dir'];
      
$curr_dir_data $val;
    }
  }
}

if (!
sizeof($dirs)) {
  
$error_msg $lang->m('error_no_directory_available''spawfm');
}

// set first directory as selected if selected directory is not valid
if (!$curr_dir_valid and sizeof($dirs)) {
  
$curr_dir $dirs[0]['dir'];
  
$curr_dir_valid true;
  
$curr_dir_data $dirs[0];
}

// set plugin class context
if ($curr_dir_valid) {
  
$spawfm->setCurrentDir($fm_path.$curr_dir);
  
$spawfm->setCurrentDirData($curr_dir_data);
  
$spawfm->setCurrentType($curr_type);
  if (!empty(
$curr_dir_data['params']['thumbnails_enabled']) and 
      
$spawfm->isThumbailsModePossible($fm_path.$curr_dir)) 
  {
    
$spawfm->setThumbnailsEnabled(true);
  } else {
    
$spawfm->setThumbnailsEnabled(false);
  }
}

// handle file delete
if ($del_file SpawVars::getPostVar('delete_file')) {
  if (empty(
$curr_dir_data['params']['allow_modify'])) {
    
$error_msg $lang->m('error_delete_forbidden''spawfm');
  } else {
    
$del_file basename($del_file);
    if (!@
unlink($spawfm->getCurrentDir().$del_file)) {
      
$error_msg $lang->m('error_delete_failed''spawfm');
    }
  }
}

// handle file upload
if ($uplfile SpawVars::getFilesVar('upload_file') and !empty($uplfile['size'])) {
  
// check if upload is allowed
  
if (empty($curr_dir_data['params']['allow_upload'])) {
    
$error_msg $lang->m('error_upload_forbidden''spawfm');
  } else {
    if (
is_uploaded_file($uplfile['tmp_name'])) {
      
// check filetype
      
$ext SpawFm::getFileExtension($uplfile['name']);
      
$allowed_ext $spawfm->getAllowedExtensions();
      if (
in_array('.*'$allowed_ext) or in_array($ext$allowed_ext)) {
        
// check filesize
        
if (empty($curr_dir_data['params']['max_upload_filesize']) or 
            
$uplfile['size'] <= $curr_dir_data['params']['max_upload_filesize'])
        {
          
$img_name $uplfile['name'];
          
$i 1;
          while (
file_exists($fm_path.$curr_dir.$img_name)) {
            
$img_name ereg_replace('(.*)(\.[a-zA-Z]+)$''\1_'.$i.'\2'$uplfile['name']);
            
$i++;
          }
          if (!@
move_uploaded_file($uplfile['tmp_name'], $fm_path.$curr_dir.$img_name)) {
            
$error_msg $lang->m('error_upload_failed''spawfm');
          }
        } else {
          
$error_msg $lang->m('error_max_filesize''spawfm').' '.round($curr_dir_data['params']['max_upload_filesize'] / 10242).' KB';
        }
      } else {
        
$error_msg $lang->m('error_bad_filetype''spawfm');
      }
    } else {
      if (
$uplfile['error'] == or $uplfile['error'] == 2) {
        
$error_msg $lang->m('error_upload_file_too_big''spawfm');
      } elseif (
$uplfile['error'] == 3) {
        
$error_msg $lang->m('error_upload_file_incomplete''spawfm');
      } else {
        
$error_msg $lang->m('error_upload_failed''spawfm');
      }
    }    
  }
}

// load current directory contents:
$files = array();
$allowed_ext = array();
if (
$curr_dir_valid) {
  
// read files
  
$files $spawfm->getFilesList();
  if (
$files === false) {
    
$error_msg $lang->m('error_reading_dir''spawfm');
  }

}

?>
<style type="text/css">
#file_list {
  height: 270px;
}

#file_details {
  text-align: left;
  border: 0px solid black;
  padding: 0px 5px 5px 5px;
  width: 180px;
  font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 1em;
    color: #000000;
    overflow: hidden;
    height: 270px;
}


#details_header { 
  display: none;
}
.details_header_col {
  display: inline;
  background-color: #D4D0C8;
  color: #000000; 
  float: left;
  /*margin: 1px;
  /*padding: 2px;*/
}

#details_name { width: 33%; }
#details_size { width: 14%; }
#details_type { width: 26%; }
#details_date { width: 26%; }


.filedescr_title {
  font-weight: bold;
  font-size: 0.8em;
}
.filedescr_br {
  font-size: 0.8em;
  padding-bottom: 5px;
}
.filedescr_common {
  font-size: 0.8em;
}

.filedescr_download {
  font-size: 0.8em;
  font-weight: bold;
  padding-top: 5px;
}

.filedescr_img_preview {
  width: 175px;
  height: 150px;
  padding: 2px;
  border: 1px solid silver;
  background-color: #FFFFFF;
  margin-bottom: 5px;
  text-align:center;
    line-height:150px;
}
.img_preview {
  border: 1px;
  vertical-align: middle;
  padding: 0px;
  margin: 0px;
}

#error {
  color: #FF0000;
  font-size: 0.8em;
  font-weight: bold;
}

</style>

<script type="text/javascript" src="<?php echo $config->getConfigValue('SPAW_DIR'?>plugins/spawfm/dialogs/spawfm.js?<?=time()?>"></script>
<script type="text/javascript">
<?php
foreach ($files as $c => $file) {
  
$fdate date('Y-m-d H:i:s'$file['date']);
  
$fsize $file['size'];
  echo 
'SpawFm.addFile(\''$file['type']."', '".
                            
SpawFm::escJsStr($file['name'])."', '".
                            
$fsize."', '".
                            
$fdate."', '".
                            
SpawFm::escJsStr($file['fdescr'])."', '".
                            
$file['icon']."', '".
                            
$file['icon_big']."', '".
                            
$file['thumb']."', '".
                            
SpawFm::escJsStr($file['other']).
                            
"');\n";
}
?>

SpawFm.setViewMode(1);

SpawFm.txtFileSize = '<?=SpawFm::escJsStr($lang->m('size''file_details'))?>';
SpawFm.txtFileDate = '<?=SpawFm::escJsStr($lang->m('date''file_details'))?>';
SpawFm.txtConfirmDelete = '<?=SpawFm::escJsStr($lang->m('confirm_delete''spawfm'))?>';
SpawFm.txtDownload = '<?=SpawFm::escJsStr($lang->m('download_file''spawfm'))?>';

SpawFm.filePath = '<?=str_replace('\\''/'$curr_dir)?>';
SpawFm.allowModify = <?=$curr_dir_data['params']['allow_modify'] ? 'true' 'false'?>;

</script>
<form name="spawfm_form" method="post" enctype="multipart/form-data">
<input type="hidden" name="delete_file" value="" />
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
  <td nowrap="nowrap" colspan="2" style="border-bottom: 1px solid #000000;">
    <table border="0" cellpadding="2" cellspacing="0" width="550">
    <tr>
      <td valign="middle" nowrap="nowrap" width="350">
        <select name="dir" style="width: 350px;" onchange="document.spawfm_form.submit()">
          <?php
          
foreach ($dirs as $dir) {
            
$st = ($dir['dir'] == $curr_dir) ? ' selected="selected"' '';
            echo 
'<option value="'.htmlentities($dir['dir']).'"'.$st.'>';
            echo 
htmlentities($dir['caption']);
            echo 
'</option>'."\n";
          }
          
?>
        </select>
        <!-- <a href=""><img src="<?=$imgdir?>btn_up.gif" alt="<?=$lang->m('go_up''buttons')?>" title="<?=$lang->m('go_up''buttons')?>" style="border: 0px;" /></a>-->
      </td>
      <td valign="middle" nowrap="nowrap">
        <?php
        
if (!$type_fixed) {
        
?>
        &nbsp;
        <select name="type" style="width: 150px;" onchange="document.spawfm_form.submit()">
          <option value="*"><?=$lang->m('any''filetypes')?></option>
          <?php
          
foreach ($all_types as $type) {
            
$st = ($curr_type == $type) ? ' selected="selected"' '';
            echo 
'<option value="'.htmlentities($type).'"'.$st.'>';
            
$title strlen($lang->m($type'filetypes')) ? $lang->m($type'filetypes') : $type;
            if (isset(
$filetypes[$type])) {
              
$title .= str_replace('.''''('.implode(', '$filetypes[$type]).')');
            }
            echo 
htmlentities($title);
            echo 
'</option>'."\n";
          }
          
?>
        </select>
        <?php
        
}
        
?>
      </td>
      <td valign="middle" align="right" nowrap="nowrap">
        <!-- 
        &nbsp;
        <a href="javascript:SpawFm.applyViewMode(1);"><img src="<?=$imgdir?>btn_view_list.gif" alt="<?=$lang->m('view_list''buttons')?>" title="<?=$lang->m('view_list''buttons')?>" style="border: 0px;" /></a>
        <a href="javascript:SpawFm.applyViewMode(2);"><img src="<?=$imgdir?>btn_view_details.gif" alt="<?=$lang->m('view_details''buttons')?>" title="<?=$lang->m('view_details''buttons')?>" style="border: 0px;" /></a>
        <a href="javascript:SpawFm.applyViewMode(3);"><img src="<?=$imgdir?>btn_view_thumbs.gif" alt="<?=$lang->m('view_thumbs''buttons')?>" title="<?=$lang->m('view_thumbs''buttons')?>" style="border: 0px;" /></a>
        -->
      </td>
    </tr>
    </table>
  </td>
</tr>
<tr>
  <td nowrap="nowrap" style="border-right: 1px solid #000000; border-bottom: 1px solid #000000;" width="90%">
    <div id="file_list">
      <div id="details_header">
        <div id="details_name" class="details_header_col"><?=$lang->m('name''file_details')?></div>
        <div id="details_size" class="details_header_col"><?=$lang->m('size''file_details')?></div>
        <div id="details_type" class="details_header_col"><?=$lang->m('type''file_details')?></div>
        <div id="details_date" class="details_header_col"><?=$lang->m('date''file_details')?></div>
      </div>
      <iframe src="../empty.html" id="dir_cont" onload="SpawFm.initIframe();" name="dir_cont" scrolling="auto" width="100%" height="100%" frameborder="0"></iframe>
    </div>
  </td>
  <td width="180" nowrap="nowrap" valign="top" style="border-bottom: 1px solid #000000;">
    <div id="file_details"></div>
  </td>
</tr>
<tr>
  <td colspan="2" nowrap="nowrap" style="border-bottom: 1px solid #000000;">
    <!-- <a href=""><img src="<?=$imgdir?>btn_rename.gif" alt="<?=$lang->m('rename''buttons')?>" title="<?=$lang->m('rename''buttons')?>" style="border: 0px;" /></a> -->
    <!-- <input type="button" name="rename_button" value="<?php echo $lang->m('rename''buttons')?>" class="bt" /> -->
    <input type="button" name="delete_button" value="<?php echo $lang->m('delete''buttons')?>" class="bt" disabled="disabled" onclick="SpawFm.deleteClick()" />
    <?php
    
if (!is_writeable($fm_path.$curr_dir) or empty($curr_dir_data['params']['allow_upload']))
      
$st ' disabled="disabled"';
    else
      
$st '';
    
?>
    &nbsp;
    <input type="file" name="upload_file" class="input" />
    <input type="submit" name="upload_button" value="<?php echo $lang->m('upload''buttons')?>"<?=$st?> class="bt" />
  </td>
</tr>
<tr>
  <td align="left" valign="top" style="padding: 5px;">
    <div id="error"><?=$error_msg?></div>
  </td>
  <td align="right" valign="bottom" nowrap="nowrap" style="padding: 5px;">
    <input type="button" name="ok_button" value="<?php echo $lang->m('ok''buttons')?>" onClick="SpawFm.okClick()" class="bt" disabled="disabled" />
    <input type="button" name="cancel_button" value="<?php echo $lang->m('cancel''buttons')?>" onClick="SpawFm.cancelClick()" class="bt" />
  </td>
</tr>
</table>
</form>
x

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