PageRenderTime 418ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/manager/actions/files.dynamic.php

https://github.com/good-web-master/modx.evo.custom
PHP | 612 lines | 518 code | 63 blank | 31 comment | 88 complexity | 0290e794d953e7091923faf7a76d39d9 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0, MIT, BSD-3-Clause
  1. <?php
  2. if(IN_MANAGER_MODE!="true") die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the MODx Content Manager instead of accessing this file directly.");
  3. if(!$modx->hasPermission('file_manager')) {
  4. $e->setError(3);
  5. $e->dumpError();
  6. }
  7. if ($manager_theme)
  8. $manager_theme .= '/';
  9. else $manager_theme = '';
  10. // settings
  11. $excludes = array('.', '..', 'cgi-bin', 'manager', '.svn');
  12. $editablefiles = array('.txt', '.php', '.shtml', '.html', '.htm', '.xml', '.js', '.css', '.pageCache', $friendly_url_suffix);
  13. $inlineviewablefiles = array('.txt', '.php', '.html', '.htm', '.xml', '.js', '.css', '.pageCache', $friendly_url_suffix);
  14. $viewablefiles = array('.jpg', '.gif', '.png', '.ico');
  15. // Mod added by Raymond
  16. $enablefileunzip = true;
  17. $enablefiledownload = true;
  18. $new_file_permissions = octdec($new_file_permissions);
  19. $newfolderaccessmode = $new_folder_permissions ? octdec($new_folder_permissions) : 0777;
  20. // End Mod - by Raymond
  21. // make arrays from the file upload settings
  22. $upload_files = explode(',',$upload_files);
  23. $upload_images = explode(',',$upload_images);
  24. $upload_media = explode(',',$upload_media);
  25. $upload_flash = explode(',',$upload_flash);
  26. // now merge them
  27. $uploadablefiles = array_merge($upload_files,$upload_images,$upload_media,$upload_flash);
  28. $count = count($uploadablefiles);
  29. for($i=0; $i<$count; $i++) {
  30. $uploadablefiles[$i] = ".".$uploadablefiles[$i]; // add a dot :)
  31. }
  32. // end settings
  33. function ufilesize($size) {
  34. $a = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
  35. $pos = 0;
  36. while ($size >= 1024) {
  37. $size /= 1024;
  38. $pos++;
  39. }
  40. return round($size,2)." ".$a[$pos];
  41. }
  42. function removeLastPath($string) {
  43. $pos = false;
  44. $search = "/";
  45. if (is_int(strpos($string, $search))) {
  46. $endPos = strlen($string);
  47. while ($endPos > 0) {
  48. $endPos = $endPos - 1;
  49. $pos = strpos($string, $search, $endPos);
  50. if (is_int($pos)) {
  51. break;
  52. }
  53. }
  54. }
  55. if (is_int($pos)) {
  56. $len = strlen($search);
  57. return substr($string, 0, $pos);
  58. }
  59. return $string;
  60. }
  61. function getExtension($string) {
  62. $pos = false;
  63. $search = ".";
  64. if (is_int(strpos($string, $search))) {
  65. $endPos = strlen($string);
  66. while ($endPos > 0) {
  67. $endPos = $endPos - 1;
  68. $pos = strpos($string, $search, $endPos);
  69. if (is_int($pos)) {
  70. break;
  71. }
  72. }
  73. }
  74. if (is_int($pos)) {
  75. $len = strlen($search);
  76. return substr($string, $pos);
  77. }
  78. return $string;
  79. }
  80. function fsize($file) {
  81. $a = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
  82. $pos = 0;
  83. $size = filesize($file);
  84. while ($size >= 1024) {
  85. $size /= 1024;
  86. $pos++;
  87. }
  88. return round($size,2)." ".$a[$pos];
  89. }
  90. function mkdirs($strPath, $mode){ // recursive mkdir function
  91. if (is_dir($strPath)) return true;
  92. $pStrPath = dirname($strPath);
  93. if (!mkdirs($pStrPath, $mode)) return false;
  94. return @mkdir($strPath);
  95. }
  96. function logFileChange($type, $filename) {
  97. //global $_lang;
  98. include_once('log.class.inc.php');
  99. $log = new logHandler();
  100. switch ($type) {
  101. case 'upload': $string = 'Uploaded File'; break;
  102. case 'delete': $string = 'Deleted File'; break;
  103. case 'modify': $string = 'Modified File'; break;
  104. default: $string = 'Viewing File'; break;
  105. }
  106. $string = sprintf($string, $filename);
  107. $log->initAndWriteLog($string, '', '', '', $type, $filename);
  108. // HACK: change the global action to prevent double logging
  109. // @see manager/index.php @ 915
  110. global $action; $action = 1;
  111. }
  112. // get the current work directory
  113. if(isset($_REQUEST['path']) && !empty($_REQUEST['path'])) {
  114. $_REQUEST['path'] = str_replace('..','',$_REQUEST['path']);
  115. $startpath = is_dir($_REQUEST['path']) ? $_REQUEST['path'] : removeLastPath($_REQUEST['path']) ;
  116. } else {
  117. $startpath = $filemanager_path;
  118. }
  119. $len = strlen($filemanager_path);
  120. // Raymond: get web start path for showing pictures
  121. $rf = realpath($filemanager_path);
  122. $rw = realpath('../');
  123. $webstart_path = str_replace('\\','/',str_replace($rw,'',$rf));
  124. if(substr($webstart_path,0,1)=='/') $webstart_path = '..'.$webstart_path;
  125. else $webstart_path = '../'.$webstart_path;
  126. ?>
  127. <h1><?php echo $_lang['files_files']?></h1>
  128. <div class="sectionBody">
  129. <script type="text/javascript" src="media/script/multifile.js"></script>
  130. <script type="text/javascript">
  131. var current_path = '<?php echo $startpath;?>';
  132. function viewfile(url) {
  133. document.getElementById('imageviewer').style.border="1px solid #000080";
  134. document.getElementById('imageviewer').src=url;
  135. }
  136. function setColor(o,state){
  137. if (!o) return;
  138. if(state && o.style) o.style.backgroundColor='#eeeeee';
  139. else if (o.style) o.style.backgroundColor='transparent';
  140. }
  141. function confirmDelete() {
  142. return confirm("<?php echo $_lang['confirm_delete_file'] ?>");
  143. }
  144. function confirmDeleteFolder() {
  145. return confirm("<?php echo str_replace('file','folder',$_lang['confirm_delete_file']) ?>");
  146. }
  147. function confirmUnzip() {
  148. return confirm("<?php echo $_lang['confirm_unzip_file'] ?>");
  149. }
  150. function getFolderName(a){
  151. var f;
  152. f=window.prompt('Enter New Folder Name:','')
  153. if (f) a.href+=escape(f);
  154. return (f) ? true:false;
  155. }
  156. function deleteFolder (folder) {
  157. if (confirmDeleteFolder())
  158. window.location.href="index.php?a=31&mode=deletefolder&path="+current_path+"&folderpath="+current_path+'/'+folder;
  159. return false;
  160. }
  161. function deleteFile(file) {
  162. if (confirmDelete())
  163. window.location.href="index.php?a=31&mode=delete&path="+current_path+'/'+file;
  164. return false;
  165. }
  166. </script>
  167. <?php
  168. if(!empty($_FILES['userfile'])) {
  169. for ($i = 0; $i <= count($_FILES['userfile']['tmp_name']); $i++) {
  170. if(!empty($_FILES['userfile']['tmp_name'][$i])) {
  171. $userfiles[$i]['tmp_name'] = $_FILES['userfile']['tmp_name'][$i];
  172. $userfiles[$i]['error'] = $_FILES['userfile']['error'][$i];
  173. $name = $_FILES['userfile']['name'][$i];
  174. if($modx->config['clean_uploaded_filename']) {
  175. $nameparts = explode('.', $name);
  176. $nameparts = array_map(array($modx, 'stripAlias'), $nameparts);
  177. $name = implode('.', $nameparts);
  178. }
  179. $userfiles[$i]['name'] = $name;
  180. $userfiles[$i]['type'] = $_FILES['userfile']['type'][$i];
  181. }
  182. }
  183. foreach((array)$userfiles as $userfile) {
  184. // this seems to be an upload action.
  185. printf("<p>".$_lang['files_uploading']."</p>", $userfile['name'], substr($startpath, $len, strlen($startpath)));
  186. echo $userfile['error']==0 ? "<p>".$_lang['files_file_type'].$userfile['type'].", ".fsize($userfile['tmp_name']).'</p>' : '';
  187. $userfilename = $userfile['tmp_name'];
  188. if (is_uploaded_file($userfilename)) {
  189. // file is uploaded file, process it!
  190. if(!in_array(getExtension($userfile['name']), $uploadablefiles)) {
  191. echo '<p><span class="warning">'.$_lang['files_filetype_notok'].'</span></p>';
  192. } else {
  193. if(@move_uploaded_file($userfile['tmp_name'], $_POST['path'].'/'.$userfile['name'])) {
  194. // Ryan: Repair broken permissions issue with file manager
  195. if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN')
  196. @chmod($_POST['path']."/".$userfile['name'], $new_file_permissions);
  197. // Ryan: End
  198. echo '<p><span class="success">'.$_lang['files_upload_ok'].'</span></p>';
  199. // invoke OnFileManagerUpload event
  200. $modx->invokeEvent('OnFileManagerUpload',
  201. array(
  202. 'filepath' => $_POST['path'],
  203. 'filename' => $userfile['name']
  204. ));
  205. // Log the change
  206. logFileChange('upload', $_POST['path'].'/'.$userfile['name']);
  207. } else {
  208. echo '<p><span class="warning">'.$_lang['files_upload_copyfailed'].'</span> '.$_lang["files_upload_permissions_error"].'</p>';
  209. }
  210. }
  211. } else {
  212. echo '<br /><span class="warning"><b>'.$_lang['files_upload_error'].':</b>';
  213. switch($userfile['error']){
  214. case 0: //no error; possible file attack!
  215. echo $_lang['files_upload_error0'];
  216. break;
  217. case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
  218. echo $_lang['files_upload_error1'];
  219. break;
  220. case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
  221. echo $_lang['files_upload_error2'];
  222. break;
  223. case 3: //uploaded file was only partially uploaded
  224. echo $_lang['files_upload_error3'];
  225. break;
  226. case 4: //no file was uploaded
  227. echo $_lang['files_upload_error4'];
  228. break;
  229. default: //a default error, just in case! :)
  230. echo $_lang['files_upload_error5'];
  231. break;
  232. }
  233. echo '</span><br />';
  234. }
  235. echo '<hr/>';
  236. }
  237. }
  238. if($_POST['mode']=='save') {
  239. echo $_lang['editing_file'];
  240. $filename = $_POST['path'];
  241. $content = $_POST['content'];
  242. if (!$handle = fopen($filename, 'w')) {
  243. echo 'Cannot open file (',$filename,')';
  244. exit;
  245. }
  246. // Write $content to our opened file.
  247. if (fwrite($handle, $content) === FALSE) {
  248. echo '<span class="warning"><b>'.$_lang['file_not_saved'].'</b></span><br /><br />';
  249. } else {
  250. echo '<span class="success"><b>'.$_lang['file_saved'].'</b></span><br /><br />';
  251. $_REQUEST['mode'] = 'edit';
  252. }
  253. fclose($handle);
  254. // Log the change
  255. logFileChange('modify', $filename);
  256. }
  257. if($_REQUEST['mode']=='delete') {
  258. printf($_lang['deleting_file'], str_replace('\\', '/', $_REQUEST['path']));
  259. $file = $_REQUEST['path'];
  260. if (!@unlink($file)) {
  261. echo '<span class="warning"><b>'.$_lang['file_not_deleted'].'</b></span><br /><br />';
  262. } else {
  263. echo '<span class="success"><b>'.$_lang['file_deleted'].'</b></span><br /><br />';
  264. }
  265. // Log the change
  266. logFileChange('delete', $file);
  267. }
  268. echo $_lang['files_dir_listing']?><b><?php echo substr($startpath, $len, strlen($startpath))=='' ? '/' : substr($startpath, $len, strlen($startpath))?></b><br /><br />
  269. <?php
  270. // check to see user isn't trying to move below the document_root
  271. if(substr(strtolower(str_replace('//','/',$startpath."/")), 0, $len)!=strtolower(str_replace('//','/',$filemanager_path.'/'))) {
  272. echo $_lang['files_access_denied']?>
  273. </div>
  274. <?php
  275. exit;
  276. }
  277. // Unzip .zip files - by Raymond
  278. if ($enablefileunzip && $_REQUEST['mode']=='unzip' && is_writable($startpath)){
  279. // by patrick_allaert - php user notes
  280. function unzip($file, $path) {
  281. global $newfolderaccessmode;
  282. // added by Raymond
  283. $r = substr($path,strlen($path)-1,1);
  284. if ($r!='\\'||$r!='/') $path .='/';
  285. if (!extension_loaded('zip')) {
  286. return 0;
  287. }
  288. // end mod
  289. $zip = zip_open($file);
  290. if ($zip) {
  291. $old_umask = umask(0);
  292. while ($zip_entry = zip_read($zip)) {
  293. if (zip_entry_filesize($zip_entry) > 0) {
  294. // str_replace must be used under windows to convert "/" into "\"
  295. $complete_path = $path.str_replace('/','\\',dirname(zip_entry_name($zip_entry)));
  296. $complete_name = $path.str_replace ('/','\\',zip_entry_name($zip_entry));
  297. if(!file_exists($complete_path)) {
  298. $tmp = '';
  299. foreach(explode('\\',$complete_path) AS $k) {
  300. $tmp .= $k.'\\';
  301. if(!file_exists($tmp)) {
  302. @mkdir($tmp, $newfolderaccessmode);
  303. }
  304. }
  305. }
  306. if (zip_entry_open($zip, $zip_entry, 'r')) {
  307. $fd = fopen($complete_name, 'w');
  308. fwrite($fd, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
  309. fclose($fd);
  310. zip_entry_close($zip_entry);
  311. }
  312. }
  313. }
  314. umask($old_umask);
  315. zip_close($zip);
  316. return true;
  317. }
  318. zip_close($zip);
  319. }
  320. if(!$err=@unzip(realpath("$startpath/".$_REQUEST['file']),realpath($startpath))) {
  321. echo '<span class="warning"><b>'.$_lang['file_unzip_fail'].($err===0? 'Missing zip library (php_zip.dll / zip.so)':'').'</b></span><br /><br />';
  322. } else {
  323. echo '<span class="success"><b>'.$_lang['file_unzip'].'</b></span><br /><br />';
  324. }
  325. }
  326. // End Unzip - Raymond
  327. // New Folder & Delete Folder option - Raymond
  328. if (is_writable($startpath)){
  329. // Delete Folder
  330. if($_REQUEST['mode']=='deletefolder') {
  331. $folder = $_REQUEST['folderpath'];
  332. if(!@rmdir($folder)) {
  333. echo '<span class="warning"><b>'.$_lang['file_folder_not_deleted'].'</b></span><br /><br />';
  334. } else {
  335. echo '<span class="success"><b>'.$_lang['file_folder_deleted'].'</b></span><br /><br />';
  336. }
  337. }
  338. // Create folder here
  339. if($_REQUEST['mode']=='newfolder') {
  340. $old_umask = umask(0);
  341. $foldername = str_replace('..\\','',str_replace('../','',$_REQUEST['name']));
  342. if(!mkdirs($startpath."/$foldername",$newfolderaccessmode)) {
  343. echo '<span class="warning"><b>',$_lang['file_folder_not_created'],'</b></span><br /><br />';
  344. } else {
  345. if (!@chmod($startpath.'/'.$foldername,$newfolderaccessmode)) {
  346. echo '<span class="warning"><b>'.$_lang['file_folder_chmod_error'].'</b></span><br /><br />';
  347. } else {
  348. echo '<span class="success"><b>'.$_lang['file_folder_created'].'</b></span><br /><br />';
  349. }
  350. }
  351. umask($old_umask);
  352. }
  353. echo '<img src="media/style/'.$manager_theme.'images/tree/folder.gif" border="0" align="absmiddle" alt="" /> <a href="index.php?a=31&mode=newfolder&path='.urlencode($startpath).'&name=" onclick="return getFolderName(this);"><b>'.$_lang['add_folder'].'</b></a><br />';
  354. }
  355. // End New Folder - Raymond
  356. $uponelevel = removeLastPath($startpath);
  357. // To Top Level with folder icon to the left
  358. if($startpath==$filemanager_path || $startpath.'/' == $filemanager_path) {
  359. echo '<img src="media/style/',$manager_theme,'images/tree/deletedfolder.gif" border="0" align="absmiddle" alt="" /><span style="color:#bbb;cursor:default;"> <b>',$_lang['files_top_level'],'</b></span><br />';
  360. } else {
  361. echo '<img src="media/style/',$manager_theme,'images/tree/folder.gif" border="0" align="absmiddle" alt="" /> <a href="index.php?a=31&mode=drill&path=',$filemanager_path,'"><b>',$_lang['files_top_level'],'</b></a><br />';
  362. }
  363. // Up One level with folder icon to the left
  364. if($startpath == $filemanager_path || $startpath.'/' == $filemanager_path) {
  365. echo '<img src="media/style/',$manager_theme,'images/tree/deletedfolder.gif" border="0" align="absmiddle" alt="" /><span style="color:#bbb;cursor:default;"> <b>'.$_lang['files_up_level'].'</b></span><br />';
  366. } else {
  367. echo '<a href="index.php?a=31&mode=drill&path=',urlencode($uponelevel),'"><img src="media/style/',$manager_theme,'images/tree/folder.gif" border="0" align="absmiddle" alt="" /> <b>',$_lang['files_up_level'],'</b></a><br />';
  368. }
  369. echo '<br />';
  370. $filesize = 0;
  371. $files = 0;
  372. $folders = 0;
  373. $dirs_array = array();
  374. $files_array = array();
  375. if(strlen(MODX_BASE_PATH) < strlen($filemanager_path)) $len--;
  376. function ls($curpath) {
  377. global $_lang;
  378. global $excludes, $editablefiles, $inlineviewablefiles, $viewablefiles, $enablefileunzip, $enablefiledownload, $uploadablefiles, $folders, $files, $filesizes, $len, $dirs_array, $files_array, $webstart_path, $manager_theme, $modx;
  379. $dircounter = 0;
  380. $filecounter = 0;
  381. $curpath = str_replace('//','/',$curpath.'/');
  382. if (!is_dir($curpath)) {
  383. echo 'Invalid path "',$curpath,'"<br />';
  384. return;
  385. }
  386. $dir = dir($curpath);
  387. // first, get info
  388. while ($file = $dir->read()) {
  389. if(!in_array($file, $excludes)) {
  390. $newpath = $curpath.$file;
  391. if(is_dir($newpath)) {
  392. $dirs_array[$dircounter]['dir'] = $newpath;
  393. $dirs_array[$dircounter]['stats'] = lstat($newpath);
  394. $dirs_array[$dircounter]['text'] = '<img src="media/style/'.$manager_theme.'images/tree/folder.gif" border="0" align="absmiddle" alt="" /> <a href="index.php?a=31&mode=drill&path='.urlencode($newpath).'"><b>'.$file.'</b></a>';
  395. $dirs_array[$dircounter]['delete'] = is_writable($curpath) ? '<span style="width:20px"><a href="javascript: deleteFolder(\''.urlencode($file).'\');"><img src="media/style/'.$manager_theme.'images/icons/delete.gif" alt="'.$_lang['file_delete_folder'].'" title="'.$_lang['file_delete_folder'].'" /></a></span>' : '';
  396. // increment the counter
  397. $dircounter++;
  398. } else {
  399. $type=getExtension($newpath);
  400. $files_array[$filecounter]['file'] = $newpath;
  401. $files_array[$filecounter]['stats'] = lstat($newpath);
  402. $files_array[$filecounter]['text'] = '<img src="media/style/'.$manager_theme.'images/tree/page-html.gif" border="0" align="absmiddle" alt="" />'.$file;
  403. $files_array[$filecounter]['view'] = (in_array($type, $viewablefiles)) ?
  404. '<span style="cursor:pointer; width:20px;" onclick="viewfile(\''.$webstart_path.substr($newpath, $len, strlen($newpath)).'\');"><img src="media/style/'.$manager_theme.'images/icons/context_view.gif" border="0" align="absmiddle" alt="'.$_lang['files_viewfile'].'" title="'.$_lang['files_viewfile'].'" /></span>' : (($enablefiledownload && in_array($type, $uploadablefiles))? '<a href="'.$webstart_path.implode('/', array_map('rawurlencode', explode('/', substr($newpath, $len, strlen($newpath))))).'" style="cursor:pointer; width:20px;"><img src="media/style/'.$manager_theme.'images/misc/ed_save.gif" border="0" align="absmiddle" alt="'.$_lang['file_download_file'].'" title="'.$_lang['file_download_file'].'" /></a>':'<span class="disabledImage"><img src="media/style/'.$manager_theme.'images/icons/context_view.gif" border="0" align="absmiddle" alt="'.$_lang['files_viewfile'].'" title="'.$_lang['files_viewfile'].'" /></span>');
  405. $files_array[$filecounter]['view'] = (in_array($type, $inlineviewablefiles)) ? '<span style="width:20px;"><a href="index.php?a=31&mode=view&path='.urlencode($newpath).'"><img src="media/style/'.$manager_theme.'images/icons/context_view.gif" border="0" align="absmiddle" alt="'.$_lang['files_viewfile'].'" title="'.$_lang['files_viewfile'].'" /></a></span>' : $files_array[$filecounter]['view'] ;
  406. $files_array[$filecounter]['unzip'] = ($enablefileunzip && $type=='.zip') ? '<span style="width:20px;"><a href="index.php?a=31&mode=unzip&path='.$curpath.'&file='.urlencode($file).'" onclick="return confirmUnzip();"><img src="media/style/'.$manager_theme.'images/icons/unzip.gif" border="0" align="absmiddle" alt="'.$_lang['file_download_unzip'].'" title="'.$_lang['file_download_unzip'].'" /></a></span>' : '' ;
  407. $files_array[$filecounter]['edit'] = (in_array($type, $editablefiles) && is_writable($curpath) && is_writable($newpath)) ? '<span style="width:20px;"><a href="index.php?a=31&mode=edit&path='.urlencode($newpath).'#file_editfile"><img src="media/style/'.$manager_theme.'images/icons/save.png" border="0" align="absmiddle" alt="'.$_lang['files_editfile'].'" title="'.$_lang['files_editfile'].'" /></a></span>' : '<span class="disabledImage"><img src="media/style/'.$manager_theme.'images/icons/save.png" border="0" align="absmiddle" alt="'.$_lang['files_editfile'].'" title="'.$_lang['files_editfile'].'" /></span>';
  408. $files_array[$filecounter]['delete'] = is_writable($curpath) && is_writable($newpath) ? '<span style="width:20px;"><a href="javascript:deleteFile(\''.urlencode($file).'\');"><img src="media/style/'.$manager_theme.'images/icons/delete.gif" border="0" align="absmiddle" alt="'.$_lang['file_delete_file'].'" title="'.$_lang['file_delete_file'].'" /></a></span>' : '<span class="disabledImage"><img src="media/style/'.$manager_theme.'images/icons/delete.gif" border="0" align="absmiddle" alt="'.$_lang['file_delete_file'].'" title="'.$_lang['file_delete_file'].'" /></span>';
  409. // increment the counter
  410. $filecounter++;
  411. }
  412. }
  413. }
  414. $dir->close();
  415. // dump array entries for directories
  416. $folders = count($dirs_array);
  417. sort($dirs_array); // sorting the array alphabetically (Thanks pxl8r!)
  418. for($i=0; $i<$folders; $i++) {
  419. $filesizes += $dirs_array[$i]['stats']['7'];
  420. echo '<tr style="cursor:default;" onmouseout="setColor(this,0)" onmouseover="setColor(this,1)">';
  421. echo '<td>',$dirs_array[$i]['text'],'</td>';
  422. echo '<td>',$modx->toDateFormat($dirs_array[$i]['stats']['9']),'</td>';
  423. echo '<td dir="ltr">',ufilesize($dirs_array[$i]['stats']['7']),'</td>';
  424. echo '<td>';
  425. echo $dirs_array[$i]['delete'];
  426. echo '</td>';
  427. echo '</tr>';
  428. }
  429. // dump array entries for files
  430. $files = count($files_array);
  431. sort($files_array); // sorting the array alphabetically (Thanks pxl8r!)
  432. for($i=0; $i<$files; $i++) {
  433. $filesizes += $files_array[$i]['stats']['7'];
  434. echo '<tr onmouseout="setColor(this,0)" onmouseover="setColor(this,1)">';
  435. echo '<td>',$files_array[$i]['text'],'</td>';
  436. echo '<td>',$modx->toDateFormat($files_array[$i]['stats']['9']),'</td>';
  437. echo '<td dir="ltr">',ufilesize($files_array[$i]['stats']['7']),'</td>';
  438. echo '<td>';
  439. echo $files_array[$i]['unzip'];
  440. echo $files_array[$i]['view'];
  441. echo $files_array[$i]['edit'];
  442. echo $files_array[$i]['delete'];
  443. echo '</td>';
  444. echo '</tr>';
  445. }
  446. return;
  447. }
  448. echo '<br /><br />';
  449. ?>
  450. <table>
  451. <tr>
  452. <td style="width:300px;"><b><?php echo $_lang['files_filename']?></b></td>
  453. <td><b><?php echo $_lang['files_modified']?></b></td>
  454. <td><b><?php echo $_lang['files_filesize']?></b></td>
  455. <td><b><?php echo $_lang['files_fileoptions']?></b></td>
  456. </tr>
  457. <?php
  458. ls($startpath);
  459. echo "\n\n\n\n\n\n\n";
  460. if($folders==0 && $files==0) {
  461. echo '<tr><td colspan="4"><img src="media/style/',$manager_theme,'images/tree/deletedfolder.gif" border="0" /><span style="color:#888;cursor:default;"> This directory is empty.</span></td></tr>';
  462. }
  463. ?></table><?php
  464. echo $_lang['files_directories'],': <b>',$folders,'</b><br />';
  465. echo $_lang['files_files'],': <b>',$files,'</b><br />';
  466. echo $_lang['files_data'],': <b><span dir="ltr">',ufilesize($filesizes),'</span></b><br />';
  467. echo $_lang['files_dirwritable'],' <b>',is_writable($startpath)==1 ? $_lang['yes'].'.' : $_lang['no'].'.'
  468. ?></b><br />
  469. <div align="center">
  470. <img src="<?php echo $_style['tx']; ?>" id="imageviewer" />
  471. </div>
  472. <br /><hr />
  473. <?php
  474. if (((@ini_get("file_uploads") == true) || get_cfg_var("file_uploads") == 1) && is_writable($startpath)) {
  475. @ini_set("upload_max_filesize", $upload_maxsize); // modified by raymond
  476. ?>
  477. <form enctype="multipart/form-data" action="index.php?a=31" method="post">
  478. <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo isset($upload_maxsize)? $upload_maxsize:1048576; ?>">
  479. <input type="hidden" name="path" value="<?php echo $startpath?>">
  480. <span style="width:300px;"><?php echo $_lang['files_uploadfile_msg']?></span>
  481. <input id="file_elem" type="file" name="bogus" style="height: 19px;">
  482. <div id="files_list"></div>
  483. <script type="text/javascript">
  484. var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), 10 );
  485. multi_selector.addElement( document.getElementById( 'file_elem' ) );
  486. </script>
  487. <input type="submit" value="<?php echo $_lang['files_uploadfile']?>">
  488. </form>
  489. <?php
  490. } else {
  491. echo "<p>".$_lang['files_upload_inhibited_msg']."</p>";
  492. }
  493. ?>
  494. </div>
  495. <?php
  496. if($_REQUEST['mode']=="edit" || $_REQUEST['mode']=="view") {
  497. ?>
  498. <div class="sectionHeader" id="file_editfile"><?php echo $_REQUEST['mode']=="edit" ? $_lang['files_editfile'] : $_lang['files_viewfile']?></div>
  499. <div class="sectionBody">
  500. <?php
  501. $filename=$_REQUEST['path'];
  502. $handle = @fopen($filename, "r");
  503. // Log the change
  504. logFileChange('view', $filename);
  505. if(!$handle) {
  506. echo 'Error opening file for reading.';
  507. exit;
  508. } else {
  509. while (!feof($handle)) {
  510. $buffer .= fgets($handle, 4096);
  511. }
  512. fclose ($handle);
  513. }
  514. ?>
  515. <form action="index.php" method="post" name="editFile">
  516. <input type="hidden" name="a" value="31" />
  517. <input type="hidden" name="mode" value="save" />
  518. <input type="hidden" name="path" value="<?php echo $_REQUEST['path']?>" />
  519. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  520. <tr>
  521. <td><textarea dir="ltr" style="width:100%; height:370px;" name="content"><?php echo htmlentities($buffer,ENT_COMPAT,$modx_manager_charset)?></textarea></td>
  522. </tr>
  523. </table>
  524. </form>
  525. <?php
  526. if($_REQUEST['mode']=="edit") {
  527. ?>
  528. <br />
  529. <ul class="actionButtons">
  530. <li><a href="#" onclick="document.editFile.submit();"><img src="<?php echo $_style["icons_save"] ?>" /> <?php echo $_lang['save']?></a></li>
  531. <li><a href="index.php?a=31&path=<?php echo urlencode($_REQUEST['path'])?>"><img src="<?php echo $_style["icons_cancel"] ?>" /> <?php echo $_lang['cancel']?></a></li>
  532. </ul>
  533. <?php } ?>
  534. </div>
  535. <?php
  536. }
  537. ?>