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

/admin/filebrowser.php

http://get-simple-cms.googlecode.com/
PHP | 201 lines | 168 code | 17 blank | 16 comment | 40 complexity | 05dbf1486b230623f4a0980123c7ea67 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Basic File Browser for CKEditor
  4. *
  5. * Displays and selects file link to insert into CKEditor
  6. *
  7. * @package GetSimple
  8. * @subpackage Files
  9. *
  10. * Version: 1.1 (2011-03-12)
  11. */
  12. // Setup inclusions
  13. include('inc/common.php');
  14. login_cookie_check();
  15. $filesSorted=null;$dirsSorted=null;
  16. $path = (isset($_GET['path'])) ? "../data/uploads/".$_GET['path'] : "../data/uploads/";
  17. $subPath = (isset($_GET['path'])) ? $_GET['path'] : "";
  18. $returnid = (isset($_GET['returnid'])) ? $_GET['returnid'] : "";
  19. $func = (isset($_GET['func'])) ? $_GET['func'] : "";
  20. $path = tsl($path);
  21. // check if host uses Linux (used for displaying permissions
  22. $isUnixHost = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? false : true);
  23. $CKEditorFuncNum = $_GET['CKEditorFuncNum'];
  24. $sitepath = suggest_site_path();
  25. $fullPath = $sitepath . "data/uploads/";
  26. $type = $_GET['type'];
  27. if(!defined('IN_GS')){ die('you cannot load this page directly.'); }
  28. global $LANG;
  29. $LANG_header = preg_replace('/(?:(?<=([a-z]{2}))).*/', '', $LANG);
  30. ?>
  31. <!DOCTYPE html>
  32. <html lang="<?php echo $LANG_header; ?>">
  33. <head>
  34. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  35. <title><?php echo i18n_r('FILE_BROWSER'); ?></title>
  36. <link rel="shortcut icon" href="favicon.png" type="image/x-icon" />
  37. <link rel="stylesheet" type="text/css" href="template/style.php?v=<?php echo GSVERSION; ?>" media="screen" />
  38. <style>
  39. .wrapper, #maincontent, #imageTable { width: 100% }
  40. </style>
  41. <script type='text/javascript'>
  42. function submitLink($funcNum, $url) {
  43. <?php if (isset($_GET['returnid'])){ ?>
  44. if(window.opener){
  45. window.opener.document.getElementById('<?php echo $returnid; ?>').focus();
  46. window.opener.document.getElementById('<?php echo $returnid; ?>').value=$url;
  47. }
  48. <?php
  49. if (isset($_GET['func'])){
  50. $func = @$_GET['func'];
  51. ?>
  52. if(window.opener){
  53. if(typeof window.opener.<?php echo $func; ?> == 'function') {
  54. window.opener.<?php echo $func; ?>('<?php echo $returnid; ?>');
  55. }
  56. }
  57. <?php
  58. }
  59. }
  60. else { ?>
  61. if(window.opener){
  62. window.opener.CKEDITOR.tools.callFunction($funcNum, $url);
  63. }
  64. <?php } ?>
  65. window.close();
  66. }
  67. </script>
  68. </head>
  69. <body id="filebrowser" >
  70. <div class="wrapper">
  71. <div id="maincontent">
  72. <div class="main" style="border:none;">
  73. <h3><?php echo i18n('UPLOADED_FILES'); ?><span id="filetypetoggle">&nbsp;&nbsp;/&nbsp;&nbsp;<?php echo ($type == 'images' ? i18n('IMAGES') : i18n('SHOW_ALL') ); ?></span></h3>
  74. <?php
  75. $count="0";
  76. $dircount="0";
  77. $counter = "0";
  78. $totalsize = 0;
  79. $filesArray = array();
  80. $dirsArray = array();
  81. $filenames = getFiles($path);
  82. if (count($filenames) != 0) {
  83. foreach ($filenames as $file) {
  84. if ($file == "." || $file == ".." || $file == ".htaccess" ){
  85. // not a upload file
  86. } elseif (is_dir($path . $file)) {
  87. $dirsArray[$dircount]['name'] = $file;
  88. $dircount++;
  89. } else {
  90. $filesArray[$count]['name'] = $file;
  91. $ext = substr($file, strrpos($file, '.') + 1);
  92. $extention = get_FileType($ext);
  93. $filesArray[$count]['type'] = $extention;
  94. clearstatcache();
  95. $ss = @stat($path . $file);
  96. $filesArray[$count]['date'] = @date('M j, Y',$ss['ctime']);
  97. $filesArray[$count]['size'] = fSize($ss['size']);
  98. $totalsize = $totalsize + $ss['size'];
  99. $count++;
  100. }
  101. }
  102. $filesSorted = subval_sort($filesArray,'name');
  103. $dirsSorted = subval_sort($dirsArray,'name');
  104. }
  105. $pathParts=explode("/",$subPath);
  106. $urlPath="";
  107. echo '<div class="h5">/ <a href="?CKEditorFuncNum='.$CKEditorFuncNum.'&amp;type='.$type.'">uploads</a> / ';
  108. foreach ($pathParts as $pathPart){
  109. if ($pathPart!=''){
  110. $urlPath.=$pathPart."/";
  111. echo '<a href="?path='.$urlPath.'&amp;CKEditorFuncNum='.$CKEditorFuncNum.'&amp;type='.$type.'&amp;func='.$func.'">'.$pathPart.'</a> / ';
  112. }
  113. }
  114. echo "</div>";
  115. echo '<table class="highlight" id="imageTable">';
  116. if (count($dirsSorted) != 0) {
  117. foreach ($dirsSorted as $upload) {
  118. echo '<tr class="All" >';
  119. echo '<td class="" colspan="5">';
  120. $adm = substr($path . $upload['name'] , 16);
  121. if ($returnid!='') {
  122. $returnlink = '&returnid='.$returnid;
  123. } else {
  124. $returnlink='';
  125. }
  126. if ($func!='') {
  127. $funct = '&func='.$func;
  128. } else {
  129. $funct='';
  130. }
  131. echo '<img src="template/images/folder.png" width="11" /> <a href="filebrowser.php?path='.$adm.'&amp;CKEditorFuncNum='.$CKEditorFuncNum.'&amp;type='.$type.$returnlink.'&amp;'.$funct.'" title="'. $upload['name'] .'" ><strong>'.$upload['name'].'</strong></a>';
  132. echo '</td>';
  133. echo '</tr>';
  134. }
  135. }
  136. if (count($filesSorted) != 0) {
  137. foreach ($filesSorted as $upload) {
  138. $upload['name'] = rawurlencode($upload['name']);
  139. $thumb = null; $thumbnailLink = null;
  140. $subDir = ($subPath == '' ? '' : $subPath.'/');
  141. $selectLink = 'title="'.i18n_r('SELECT_FILE').': '. htmlspecialchars($upload['name']) .'" href="javascript:void(0)" onclick="submitLink('.$CKEditorFuncNum.',\''.$fullPath.$subDir.$upload['name'].'\')"';
  142. if ($type == 'images') {
  143. if ($upload['type'] == i18n_r('IMAGES') .' Images') {
  144. # get internal thumbnail to show beside link in table
  145. $thumb = '<td class="imgthumb" style="display:table-cell" >';
  146. $thumbLink = $urlPath.'thumbsm.'.$upload['name'];
  147. if (file_exists('../data/thumbs/'.$thumbLink)) {
  148. $imgSrc='<img src="../data/thumbs/'. $thumbLink .'" />';
  149. } else {
  150. $imgSrc='<img src="inc/thumb.php?src='. $urlPath . $upload['name'] .'&amp;dest='. $thumbLink .'&amp;x=65&amp;f=1" />';
  151. }
  152. $thumb .= '<a '.$selectLink.' >'.$imgSrc.'</a>';
  153. $thumb .= '</td>';
  154. # get external thumbnail link
  155. $thumbLinkExternal = 'data/thumbs/'.$urlPath.'thumbnail.'.$upload['name'];
  156. if (file_exists('../'.$thumbLinkExternal)) {
  157. $thumbnailLink = '<span>&nbsp;&ndash;&nbsp;&nbsp;</span><a href="javascript:void(0)" onclick="submitLink('.$CKEditorFuncNum.',\''.$sitepath.$thumbLinkExternal.'\')">'.i18n_r('THUMBNAIL').'</a>';
  158. }
  159. }
  160. else { continue; }
  161. }
  162. $counter++;
  163. echo '<tr class="All '.$upload['type'].'" >';
  164. echo ($thumb=='' ? '<td style="display: none"></td>' : $thumb);
  165. echo '<td><a '.$selectLink.' class="primarylink">'.htmlspecialchars($upload['name']) .'</a>'.$thumbnailLink.'</td>';
  166. echo '<td style="width:80px;text-align:right;" ><span>'. $upload['size'] .'</span></td>';
  167. // get the file permissions.
  168. if ($isUnixHost && defined('GSDEBUG') && function_exists('posix_getpwuid')) {
  169. $filePerms = substr(sprintf('%o', fileperms($path.$upload['name'])), -4);
  170. $fileOwner = posix_getpwuid(fileowner($path.$upload['name']));
  171. echo '<td style="width:70px;text-align:right;"><span>'.$fileOwner['name'].'/'.$filePerms.'</span></td>';
  172. }
  173. echo '<td style="width:85px;text-align:right;" ><span>'. shtDate($upload['date']) .'</span></td>';
  174. echo '</tr>';
  175. }
  176. }
  177. echo '</table>';
  178. echo '<p><em><b>'. $counter .'</b> '.i18n_r('TOTAL_FILES').' ('. fSize($totalsize) .')</em></p>';
  179. ?>
  180. </div>
  181. </div>
  182. </div>
  183. </body>
  184. </html>