PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/sitemanager/spaw/plugins/spawfm/dialogs/spawfm.inc.php

https://bitbucket.org/itoxable/chiron-gaming
PHP | 508 lines | 429 code | 42 blank | 37 comment | 65 complexity | 090597144b2903361479691815c6133c MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. error_reporting(E_ALL);
  3. function dbg($var) {
  4. echo '<pre>';
  5. print_r($var);
  6. echo '</pre>';
  7. }
  8. /////////////////////////////////////
  9. $lang->setModule('spawfm');
  10. // load environment variables
  11. $settings = $config->getConfigValue('PG_SPAWFM_SETTINGS');
  12. $filetypes = $config->getConfigValue('PG_SPAWFM_FILETYPES');
  13. $dir_list = $config->getConfigValue('PG_SPAWFM_DIRECTORIES');
  14. $doc_root = $config->getConfigValue('DOCUMENT_ROOT');
  15. if (preg_match('|[\\/]$|', $doc_root))
  16. $doc_root = substr($doc_root, 0, -1);
  17. $imgdir = $config->getConfigValue('SPAW_DIR').'plugins/spawfm/lib/theme/'.$theme->name.'/img/';
  18. require_once($config->getConfigValue('SPAW_ROOT').'plugins/spawfm/class/spawfm.class.php');
  19. $spawfm = new SpawFm();
  20. $error_msg = '';
  21. // set default "global" settings if not set by user
  22. if (!isset($settings['allow_upload']))
  23. $settings['allow_upload'] = false;
  24. if (!isset($settings['allow_modify']))
  25. $settings['allow_modify'] = false;
  26. if (!isset($settings['max_upload_filesize']))
  27. $settings['max_upload_filesize'] = 0;
  28. if (!isset($settings['allowed_filetypes']))
  29. $settings['allowed_filetypes'] = array('any');
  30. if (!isset($settings['chmod_to']))
  31. $settings['chmod_to'] = false;
  32. if (!isset($settings['max_img_width']))
  33. $settings['max_img_width'] = 0;
  34. if (!isset($settings['max_img_height']))
  35. $settings['max_img_height'] = 0;
  36. if (!isset($settings['recursive']))
  37. $settings['recursive'] = false;
  38. if (!isset($settings['allow_modify_subdirectories']))
  39. $settings['allow_modify_subdirectories'] = false;
  40. if (!isset($settings['allow_create_subdirectories']))
  41. $settings['allow_create_subdirectories'] = false;
  42. // fetch context variables
  43. $tmp = explode($config->getConfigValue('spawfm_path_separator'), SpawVars::getPostVar('dir') ? SpawVars::getPostVar('dir') : SpawVars::getGetVar('dir'));
  44. $curr_dir = SpawFm::normalizeDir($tmp[0], true);
  45. $curr_dir_subdir = isset($tmp[1]) ? $tmp[1] : false;
  46. $curr_type = SpawVars::getPostVar('type') ? SpawVars::stripSlashes(SpawVars::getPostVar('type')) : SpawVars::stripSlashes(SpawVars::getGetVar('type'));
  47. if ($curr_type == '*')
  48. $curr_type = false;
  49. $type_fixed = SpawVars::getGetVar('nofilter');
  50. // build directories list, determine selected option
  51. $dirs = array();
  52. $curr_dir_pos = false;
  53. $all_types = array();
  54. foreach ($dir_list as $dirpos=>$dirdef) {
  55. if (is_string($dirdef)) { // simple dir definition
  56. $dir = $caption = $dirdef;
  57. $dir = SpawFm::normalizeDir($dir);
  58. $fsdir = $doc_root.$dir;
  59. $params = $settings;
  60. } elseif (is_array($dirdef) and isset($dirdef['dir'])) { // advanced dir definition
  61. $dir = $dirdef['dir'];
  62. $caption = (!empty($dirdef['caption'])) ? $dirdef['caption'] : $dir;
  63. $params = (!empty($dirdef['params'])) ? array_merge($settings, $dirdef['params']) : $settings;
  64. $dir = SpawFm::normalizeDir($dir);
  65. if (empty($dirdef['fsdir'])) {
  66. $fsdir = $doc_root.$dir;
  67. } else {
  68. $fsdir = SpawFm::normalizeDir($dirdef['fsdir'], false, true);
  69. }
  70. } else {
  71. $dir = false;
  72. }
  73. if ($dir and file_exists($fsdir)) {
  74. $dir_data = array(
  75. 'dir' => $dir,
  76. 'fsdir' => $fsdir,
  77. 'caption' => $caption,
  78. 'params' => $params,
  79. );
  80. $dirs[] = $dir_data;
  81. // set default dir if needed
  82. if (!$curr_dir and !empty($params['default_dir'])) {
  83. $curr_dir = $dir;
  84. }
  85. // track filetypes allowed
  86. if (is_array($params['allowed_filetypes'])) {
  87. $all_types = array_merge($all_types, $params['allowed_filetypes']);
  88. } else {
  89. $all_types[] = $params['allowed_filetypes'];
  90. }
  91. // load current directory data
  92. if ($dir == $curr_dir) {
  93. $spawfm->setCurrentDirData($dir_data);
  94. $curr_dir_pos = $dirpos;
  95. }
  96. }
  97. }
  98. // cleanup filetypes array
  99. $all_types = array_unique($all_types);
  100. foreach ($all_types as $key=>$type) {
  101. if ($type{0} == '.' or $type == 'any' or !isset($filetypes[$type])) {
  102. unset($all_types[$key]);
  103. }
  104. }
  105. // check selected type for validity
  106. if ($curr_type and (!in_array($curr_type, $all_types) or !isset($filetypes[$curr_type]))) {
  107. $curr_type = false;
  108. } else {
  109. $spawfm->setCurrentType($curr_type);
  110. }
  111. // filter out directories not matching current type, reset $curr_dir if needed
  112. if ($curr_type) {
  113. $curr_dir_reset = false;
  114. foreach ($dirs as $key=>$val) {
  115. if (empty($val['params']['allowed_filetypes']) or
  116. (is_string($val['params']['allowed_filetypes']) and $val['params']['allowed_filetypes'] != 'any' and $val['params']['allowed_filetypes'] != $curr_type) or
  117. (is_array($val['params']['allowed_filetypes']) and !in_array($curr_type, $val['params']['allowed_filetypes']) and !in_array('any', $val['params']['allowed_filetypes'])))
  118. {
  119. unset($dirs[$key]);
  120. if ($val['dir'] == $curr_dir) {
  121. $curr_dir = false;
  122. $spawfm->unsetCurrentDirData();
  123. }
  124. } elseif (!$curr_dir or ($curr_dir and $curr_dir_reset and !empty($val['params']['default_dir']))) {
  125. $curr_dir_reset = true;
  126. $spawfm->setCurrentDirData($val);
  127. $curr_dir_pos = $key;
  128. }
  129. }
  130. }
  131. if (!sizeof($dirs)) {
  132. $error_msg = $lang->m('error_no_directory_available', 'spawfm');
  133. }
  134. // set first directory as selected if selected directory is not valid
  135. if ($spawfm->getCurrentDirData() === false and sizeof($dirs)) {
  136. $keys = array_keys($dirs);
  137. $curr_dir_pos = $keys[0];
  138. $curr_dir = $dirs[$curr_dir_pos]['dir'];
  139. $spawfm->setCurrentDirData($dirs[$curr_dir_pos]);
  140. }
  141. // process subdirectories if selected and allowed
  142. if ($spawfm->getCurrentDirSetting('recursive') and !empty($curr_dir_subdir)) {
  143. // filter subdir variable for validity
  144. $arr = explode('/', $curr_dir_subdir);
  145. $str = '';
  146. foreach ($arr as $val) {
  147. if (!empty($val) and $val != '..') {
  148. $str .= $val.'/';
  149. }
  150. }
  151. $curr_dir_subdir = $str;
  152. // add subdirectories to list if exist and parent dir matched
  153. if ($spawfm->getCurrentFsDir() and file_exists($spawfm->getCurrentFsDir().$curr_dir_subdir)) {
  154. $dirs_new = array();
  155. foreach ($dirs as $pos=>$dir) {
  156. $dirs_new[] = $dir;
  157. if ($pos == $curr_dir_pos and preg_match_all('|([^/]*)/|', $curr_dir_subdir, $subdirs)) {
  158. // insert all subdirectories
  159. $subdir_path = '';
  160. foreach ($subdirs[1] as $cnt=>$subdir) {
  161. $subdir_path .= $subdir.'/';
  162. $subdir_data = $dir;
  163. $subdir_data['dir'] = $subdir_data['dir'] . $subdir_path;
  164. $subdir_data['caption'] = str_repeat('&nbsp;', ($cnt+1)*2).$subdir;
  165. $subdir_data['value'] = $spawfm->getCurrentDir() . $config->getConfigValue('spawfm_path_separator') . $subdir_path;
  166. $dirs_new[] = $subdir_data;
  167. }
  168. }
  169. }
  170. $dirs = $dirs_new;
  171. // set dir vars to subdir
  172. $curr_dir_data = $spawfm->getCurrentDirData();
  173. $curr_dir_data['dir'] = $spawfm->getCurrentDir().$curr_dir_subdir;
  174. $curr_dir_data['fsdir'] = $spawfm->getCurrentFsDir().$curr_dir_subdir;
  175. $spawfm->setCurrentDirData($curr_dir_data);
  176. }
  177. }
  178. // handle file delete
  179. if ($del_file = SpawVars::getPostVar('delete_file') and !$spawfm->deleteFile($del_file)) {
  180. $error_msg = $spawfm->getError();
  181. }
  182. // handle file rename
  183. if ($ren_old_name = SpawVars::getPostVar('rename_from') and
  184. $ren_new_name = SpawVars::getPostVar('rename_to') and
  185. !$spawfm->renameFile($ren_old_name, $ren_new_name))
  186. {
  187. $error_msg = $spawfm->getError();
  188. }
  189. // handle new directory creation
  190. if ($dir_name = SpawVars::getPostVar('new_folder')) {
  191. if (!$spawfm->createDirectory($dir_name)) {
  192. $error_msg = $spawfm->getError();
  193. } else {
  194. $onload_select = $dir_name;
  195. }
  196. }
  197. // handle file upload
  198. if ($uplfile = SpawVars::getFilesVar('upload_file') and !empty($uplfile['size'])) {
  199. if (!$uplfile_name = $spawfm->uploadFile($uplfile)) {
  200. $error_msg = $spawfm->getError();
  201. } else {
  202. $onload_select = $uplfile_name;
  203. }
  204. }
  205. // load current directory contents:
  206. $files = $directories = array();
  207. $allowed_ext = array();
  208. if ($spawfm->getCurrentFsDir()) {
  209. // read files
  210. $files = $spawfm->getFilesList();
  211. if ($files === false) {
  212. $error_msg = $lang->m('error_reading_dir', 'spawfm');
  213. }
  214. // read directories if allowed
  215. if ($spawfm->getCurrentDirSetting('recursive')) {
  216. $directories = $spawfm->getDirectoriesList();
  217. }
  218. }
  219. ?>
  220. <style type="text/css">
  221. #file_list {
  222. height: 270px;
  223. }
  224. #file_details {
  225. text-align: left;
  226. border: 0px solid black;
  227. padding: 0px 5px 5px 5px;
  228. width: 180px;
  229. font-family: Verdana, Arial, Helvetica, sans-serif;
  230. font-size: 1em;
  231. color: #000000;
  232. overflow: hidden;
  233. height: 270px;
  234. }
  235. #details_header {
  236. display: none;
  237. }
  238. .details_header_col {
  239. display: inline;
  240. background-color: #D4D0C8;
  241. color: #000000;
  242. float: left;
  243. /*margin: 1px;
  244. /*padding: 2px;*/
  245. }
  246. #details_name { width: 33%; }
  247. #details_size { width: 14%; }
  248. #details_type { width: 26%; }
  249. #details_date { width: 26%; }
  250. .filedescr_title {
  251. font-weight: bold;
  252. font-size: 0.8em;
  253. }
  254. .filedescr_br {
  255. font-size: 0.8em;
  256. padding-bottom: 5px;
  257. }
  258. .filedescr_common {
  259. font-size: 0.8em;
  260. }
  261. .filedescr_download {
  262. font-size: 0.8em;
  263. font-weight: bold;
  264. padding-top: 5px;
  265. }
  266. .filedescr_img_preview {
  267. width: 175px;
  268. height: 150px;
  269. padding: 2px;
  270. border: 1px solid silver;
  271. background-color: #FFFFFF;
  272. margin-bottom: 5px;
  273. text-align:center;
  274. line-height:150px;
  275. }
  276. .img_preview {
  277. border: 1px;
  278. vertical-align: middle;
  279. padding: 0px;
  280. margin: 0px;
  281. }
  282. #error {
  283. color: #FF0000;
  284. font-size: 0.8em;
  285. font-weight: bold;
  286. }
  287. </style>
  288. <script type="text/javascript" src="<?php echo $config->getConfigValue('SPAW_DIR') ?>plugins/spawfm/dialogs/spawfm.js?<?php echo time(); ?>"></script>
  289. <script type="text/javascript">
  290. <?php
  291. // populate directories list
  292. $c = 0;
  293. foreach ($directories as $directory) {
  294. echo 'SpawFm.addDirectory(\''.SpawFm::escJsStr($directory['name'])."', '".
  295. $directory['size']."', '".
  296. date('Y-m-d H:i:s', $directory['date'])."', '".
  297. SpawFm::escJsStr($directory['descr'])."', '".
  298. $directory['icon']."', '".
  299. $directory['icon_big']."', '".
  300. $directory['thumb']."', '".
  301. SpawFm::escJsStr($directory['other']).
  302. "');\n";
  303. if (!empty($onload_select) and $directory['name'] == $onload_select) {
  304. $onload_select = $c;
  305. }
  306. $c++;
  307. }
  308. // populate files list
  309. $c = 0;
  310. foreach ($files as $file) {
  311. echo 'SpawFm.addFile(\''.SpawFm::escJsStr($file['name'])."', '".
  312. $file['size']."', '".
  313. date('Y-m-d H:i:s', $file['date'])."', '".
  314. SpawFm::escJsStr($file['fdescr'])."', '".
  315. $file['icon']."', '".
  316. $file['icon_big']."', '".
  317. $file['thumb']."', '".
  318. SpawFm::escJsStr($file['other']).
  319. "');\n";
  320. // check whick file was uploaded
  321. if (!empty($onload_select) and $file['name'] == $onload_select) {
  322. $onload_select = sizeof($directories) + $c;
  323. }
  324. $c++;
  325. }
  326. ?>
  327. SpawFm.setViewMode(1);
  328. SpawFm.txtFileSize = '<?php echo SpawFm::escJsStr($lang->m('size', 'file_details')); ?>';
  329. SpawFm.txtFileDate = '<?php echo SpawFm::escJsStr($lang->m('date', 'file_details')); ?>';
  330. SpawFm.txtConfirmDelete = '<?php echo SpawFm::escJsStr($lang->m('confirm_delete', 'spawfm')); ?>';
  331. SpawFm.txtDownload = '<?php echo SpawFm::escJsStr($lang->m('download_file', 'spawfm')); ?>';
  332. SpawFm.txtRename = '<?php echo SpawFm::escJsStr($lang->m('rename_text', 'spawfm')); ?>';
  333. SpawFm.txtCreateDirectory = '<?php echo SpawFm::escJsStr($lang->m('newdirectory_text', 'spawfm')); ?>';
  334. SpawFm.txtConfirmDeleteDir = '<?php echo SpawFm::escJsStr($lang->m('confirmdeletedir_text', 'spawfm')); ?>';
  335. SpawFm.filePath = '<?php echo addslashes($spawfm->getCurrentDir()); ?>';
  336. SpawFm.allowModify = <?php echo $spawfm->getCurrentDirSetting('allow_modify') ? 'true' : 'false'; ?>;
  337. SpawFm.allowModifySubdirectories = <?php echo $spawfm->getCurrentDirSetting('allow_modify_subdirectories') ? 'true' : 'false'; ?>;
  338. <?php
  339. // select uploaded file
  340. if (!empty($onload_select)) {
  341. ?>
  342. SpawFm.onloadSelectFile = <?php echo $onload_select; ?>;
  343. <?php
  344. }
  345. ?>
  346. </script>
  347. <form name="spawfm_form" method="post" enctype="multipart/form-data">
  348. <input type="hidden" name="delete_file" value="" />
  349. <input type="hidden" name="new_folder" value="" />
  350. <input type="hidden" name="rename_from" value="" />
  351. <input type="hidden" name="rename_to" value="" />
  352. <input type="hidden" name="subdir" value="<?php echo isset($curr_dir_pos) and $curr_dir_pos !== false ? $curr_dir_pos : ''; ?>" />
  353. <table border="0" cellpadding="2" cellspacing="0" width="100%">
  354. <tr>
  355. <td nowrap="nowrap" colspan="2" style="border-bottom: 1px solid #000000;">
  356. <table border="0" cellpadding="2" cellspacing="0" width="550">
  357. <tr>
  358. <td valign="middle" nowrap="nowrap" width="350">
  359. <select name="dir" style="width: 350px;" onchange="document.spawfm_form.submit()">
  360. <?php
  361. foreach ($dirs as $dir) {
  362. $st = ($dir['dir'] == $spawfm->getCurrentDir()) ? ' selected="selected"' : '';
  363. $val = isset($dir['value']) ? $dir['value'] : $dir['dir'];
  364. $val = SpawFm::escapeHtml($val);
  365. echo '<option value="'.$val.'"'.$st.'>';
  366. echo SpawFm::escapeHtml($dir['caption']);
  367. echo '</option>'."\n";
  368. }
  369. ?>
  370. </select>
  371. </td>
  372. <td valign="middle" nowrap="nowrap">
  373. <?php
  374. if (!empty($curr_dir_subdir)) {
  375. echo '<input type="image" onclick="SpawFm.goUpClick();" src="../plugins/spawfm/img/btn_up.gif" title="'.$lang->m('go_up', 'buttons').'" class="bt" style="width: 24px; height: 24px; margin: 1px;" />';
  376. } else {
  377. echo '<input type="image" src="../plugins/spawfm/img/btn_up_off.gif" title="'.$lang->m('go_up', 'buttons').'" class="bt" style="width: 24px; height: 24px; margin: 1px;" disabled="disabled" />';
  378. }
  379. if (!$spawfm->getCurrentDirSetting('recursive') or
  380. !$spawfm->getCurrentDirSetting('allow_create_subdirectories'))
  381. {
  382. echo '<input type="image" src="../plugins/spawfm/img/btn_new_folder_off.gif" title="'.$lang->m('create_directory', 'buttons').'" class="bt" style="width: 24px; height: 24px; margin: 1px;" disabled="disabled" />';
  383. } else {
  384. echo '<input type="image" onclick="SpawFm.createDirectoryClick();" src="../plugins/spawfm/img/btn_new_folder.gif" title="'.$lang->m('create_directory', 'buttons').'" class="bt" style="width: 24px; height: 24px; margin: 1px;" />';
  385. }
  386. ?>
  387. </td>
  388. <td valign="middle" nowrap="nowrap" align="right">
  389. <?php
  390. if (!$type_fixed) {
  391. ?>
  392. &nbsp;
  393. <select name="type" style="width: 150px;" onchange="document.spawfm_form.submit()">
  394. <option value="*"><?php echo $lang->m('any', 'filetypes'); ?></option>
  395. <?php
  396. foreach ($all_types as $type) {
  397. $st = ($curr_type == $type) ? ' selected="selected"' : '';
  398. echo '<option value="'.SpawFm::escapeHtml($type).'"'.$st.'>';
  399. $title = strlen($lang->m($type, 'filetypes')) ? $lang->m($type, 'filetypes') : $type;
  400. if (isset($filetypes[$type])) {
  401. $title .= str_replace('.', '', '('.implode(', ', $filetypes[$type]).')');
  402. }
  403. echo SpawFm::escapeHtml($title);
  404. echo '</option>'."\n";
  405. }
  406. ?>
  407. </select>
  408. <?php
  409. }
  410. ?>
  411. </td>
  412. <td valign="middle" align="right" nowrap="nowrap">
  413. <!--
  414. &nbsp;
  415. <a href="javascript:SpawFm.applyViewMode(1);"><img src="<?php echo $imgdir; ?>btn_view_list.gif" alt="<?php echo $lang->m('view_list', 'buttons'); ?>" title="<?php echo $lang->m('view_list', 'buttons'); ?>" style="border: 0px;" /></a>
  416. <a href="javascript:SpawFm.applyViewMode(2);"><img src="<?php echo $imgdir; ?>btn_view_details.gif" alt="<?php echo $lang->m('view_details', 'buttons'); ?>" title="<?php echo $lang->m('view_details', 'buttons'); ?>" style="border: 0px;" /></a>
  417. <a href="javascript:SpawFm.applyViewMode(3);"><img src="<?php echo $imgdir; ?>btn_view_thumbs.gif" alt="<?php echo $lang->m('view_thumbs', 'buttons'); ?>" title="<?php echo $lang->m('view_thumbs', 'buttons'); ?>" style="border: 0px;" /></a>
  418. -->
  419. </td>
  420. </tr>
  421. </table>
  422. </td>
  423. </tr>
  424. <tr>
  425. <td nowrap="nowrap" style="border-right: 1px solid #000000; border-bottom: 1px solid #000000;" width="90%">
  426. <div id="file_list">
  427. <div id="details_header">
  428. <div id="details_name" class="details_header_col"><?php echo $lang->m('name', 'file_details'); ?></div>
  429. <div id="details_size" class="details_header_col"><?php echo $lang->m('size', 'file_details'); ?></div>
  430. <div id="details_type" class="details_header_col"><?php echo $lang->m('type', 'file_details'); ?></div>
  431. <div id="details_date" class="details_header_col"><?php echo $lang->m('date', 'file_details'); ?></div>
  432. </div>
  433. <iframe src="../empty/empty.html?<?php echo microtime(); ?>" id="dir_cont" onload="SpawFm.initIframe();" name="dir_cont" scrolling="auto" width="100%" height="100%" frameborder="0"></iframe>
  434. </div>
  435. </td>
  436. <td width="180" nowrap="nowrap" valign="top" style="border-bottom: 1px solid #000000;">
  437. <div id="file_details"></div>
  438. </td>
  439. </tr>
  440. <tr>
  441. <td colspan="2" nowrap="nowrap" style="border-bottom: 1px solid #000000;">
  442. <input type="button" name="delete_button" value="<?php echo $lang->m('delete', 'buttons')?>" class="bt" disabled="disabled" onclick="SpawFm.deleteClick()" />
  443. <input type="button" name="rename_button" value="<?php echo $lang->m('rename', 'buttons')?>" class="bt" disabled="disabled" onclick="SpawFm.renameClick()" />
  444. <?php
  445. if (!is_writeable($spawfm->getCurrentFsDir()) or !$spawfm->getCurrentDirSetting('allow_upload'))
  446. $st = ' disabled="disabled"';
  447. else
  448. $st = '';
  449. ?>
  450. &nbsp;
  451. <input type="file" name="upload_file" class="input" />
  452. <input type="submit" name="upload_button" value="<?php echo $lang->m('upload', 'buttons')?>"<?php echo $st; ?> class="bt" />
  453. </td>
  454. </tr>
  455. <tr>
  456. <td align="left" valign="top" style="padding: 5px;">
  457. <div id="error"><?php echo $error_msg; ?></div>
  458. </td>
  459. <td align="right" valign="bottom" nowrap="nowrap" style="padding: 5px;">
  460. <input type="button" name="ok_button" value="<?php echo $lang->m('ok', 'buttons')?>" onClick="SpawFm.okClick()" class="bt" disabled="disabled" />
  461. <input type="button" name="cancel_button" value="<?php echo $lang->m('cancel', 'buttons')?>" onClick="SpawFm.cancelClick()" class="bt" />
  462. </td>
  463. </tr>
  464. </table>
  465. </form>