Advertisement
retesere20

Untitled

Feb 8th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. <?php
  2. require_once('../../path/to/wp-load.php');
  3. add_action('init', function(){ if(is_user_logged_in()) { main_filebrowser();} } );
  4.  
  5.  
  6.  
  7. function main_filebrowser() {
  8. $args = &$_GET;
  9. $_GET["s"]='';
  10. if (empty($_GET["s"])) {
  11. $uri = $_SERVER["REQUEST_URI"];
  12. if (($pos = strpos($uri, "?")) !== false) {
  13. parse_str(substr($uri, $pos + 1), $a);
  14. $args = &$a;
  15. }
  16. }
  17.  
  18. $_GET["p"]= './';
  19. $path = !empty($_GET["p"]) ? "./{$_GET["p"]}" : "./";
  20. //$sort = !empty($args["s"]) && in_array($args["s"], array("n", "s", "m")) ? $args["s"] : "n";
  21. $sort="n";
  22. $direction = SORT_ASC;
  23.  
  24. header("Content-Type: text/html; charset=utf-8");
  25. {
  26. ?>
  27. <!DOCTYPE html>
  28. <html>
  29. <head>
  30. <title>Index of <?php echo currentPath(); ?></title>
  31. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  32. <meta name="generator" content="Simple Index v0.1 - http://jomppa.net/projects/sindex/">
  33. <style type="text/css">body { margin: 20px; padding: 0; background: #cccccc; } a { color: #0088ff; } a:visited { color: #8800aa; } a img { border: none; } body, td, th { font-family: sans-serif; font-size: 12pt; text-align: left; vertical-align: top; color: #333333; } h1 { font-size: 16pt; text-align: center; } h1 a { color: #000000 !important; text-decoration: none; } p { text-align: center; font-size: 9pt; } p a { color: #666666 !important; } table { margin: 0 auto; border-collapse: collapse; border: 5px solid #ffffff; min-width: 400px; } th, td { padding: 5px 10px; } th { background: #888888; color: #ffffff; } th a { color: #ffffff !important; text-decoration: none; } th img { position: relative; top: -3px; left: 2px; } td { border-bottom: 1px dotted #cccccc; background: #ffffff; } tr.odd td { background: #f5f5f5; } small { font-size: 9pt; } </style>
  34. </head>
  35. <body>
  36. <?php
  37. }
  38.  
  39. printFileListing($path, "*", array(basename(__FILE__)), $sort, $direction );
  40. ?>
  41. </body>
  42. </html>
  43. <?php
  44. }
  45.  
  46.  
  47. function currentPath() { return rtrim(dirname($_SERVER["SCRIPT_NAME"]) . "/" . ltrim($_GET["p"], "/"), "/"); }
  48.  
  49. function parentDirectory() {
  50. $path = currentPath();
  51. $path = substr($path, 0, strrpos($path, "/"));
  52.  
  53. return $path == "" ? "/" : $path;
  54. }
  55.  
  56. function formatSize($size) {
  57. $units = array("B", "K", "M", "G", "T");
  58. for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
  59. return round($size, 2) . " " . $units[$i];
  60. }
  61.  
  62. function printFileListing($path = "./", $pattern = "*", $excluded = array(), $sort = "n", $direction = SORT_ASC) {
  63. $files = glob("$path$pattern");
  64.  
  65. $sizes = array();
  66. $timestamps = array();
  67.  
  68. if (!is_array($files)) $files = array();
  69.  
  70. foreach ($files as $index => $file) {
  71. foreach ($excluded as $regexPattern) {
  72. if (preg_match("@$regexPattern@", $file)) {
  73. unset($files[$index]);
  74. continue 2;
  75. }
  76. }
  77.  
  78. $sizes[] = filesize($file);
  79. $timestamps[] = filemtime($file);
  80. }
  81.  
  82. switch ($sort) {
  83. // size
  84. case "s": array_multisort($sizes, $direction, $files, $timestamps); break;
  85. // modified
  86. case "m": array_multisort($timestamps, $direction, $files, $sizes); break;
  87. // name
  88. case "n":
  89. default: array_multisort($files, $direction, $sizes, $timestamps); break;
  90. }
  91.  
  92. $iconFile = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA9QTFRFAAAA5PX6yez1/////////SHUhAAAAAV0Uk5T/////wD7tg5TAAAAQUlEQVR42mJgQQMMIAwFCAEmJkZGRgZmBnQBsAhEAKieEaoJoQKkCLcAxBZGyrQwoWuBiDCg+QXuMAzfogCAAAMAPGcCZJ/5Pw0AAAAASUVORK5CYII=";
  93. $iconDir = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABJQTFRF//IAAAAA8ucA////ysAA////eQEvdgAAAAZ0Uk5T//////8As7+kvwAAADtJREFUeNpiYEUDDKyMyAAswMLExAAFzIyMDCgKGJmBAkgKGOgrwIQsAHYpTAjkUlS/gAQwfIsGAAIMAN7QAc8Ckh4aAAAAAElFTkSuQmCC";
  94. $iconAsc = "iVBORw0KGgoAAAANSUhEUgAAAAcAAAAECAMAAAB1GNVPAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////////VXz1bAAAAAJ0Uk5T/wDltzBKAAAAGklEQVR42mJgZGRkgGAGBhABohigJBAABBgAATAADUnnWMkAAAAASUVORK5CYII=";
  95. $iconDesc = "iVBORw0KGgoAAAANSUhEUgAAAAcAAAAECAMAAAB1GNVPAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////////VXz1bAAAAAJ0Uk5T/wDltzBKAAAAF0lEQVR42mJggAJGKMkIYjCCaDAGCDAAAJAADcpaiWkAAAAASUVORK5CYII=";
  96.  
  97. $parent = explode("/", currentPath());
  98. echo "<table>\n";
  99. //echo "\t<tr>\n\t\t<th></th>\n";
  100. $labels = array(
  101. "n" => "Name",
  102. //"s" => "Size",
  103. "m" => "Modified"
  104. );
  105.  
  106. foreach ($labels as $key => $label) {
  107. $link = "?s=$key";
  108. $image = "";
  109.  
  110. if ($sort == $key) {
  111. $d = $direction == SORT_DESC ? "a" : "d";
  112. $link .= "&amp;d=$d";
  113. $icon = $d == "a" ? $iconDesc : $iconAsc;
  114. $image = " <img src=\"data:image/png;base64,$icon\" alt=\"\" />";
  115. }
  116.  
  117. //echo "\t\t<th><a href=\"$link\">$label$image</a></th>\n";
  118. }
  119.  
  120. //echo "\t</tr>\n";
  121.  
  122. $class ='odd';
  123. foreach ($files as $index => $file) {
  124. $name = basename($file);
  125. $url = currentPath() . "/" . rawurlencode($name);
  126. $isDir = is_dir($file);
  127. $type = $isDir ? "Directory" : "File";
  128. $icon = $isDir ? $iconDir : $iconFile;
  129. $size = $isDir ? "-" : formatSize($sizes[$index]);
  130. $modified = date("Y-m-d H:i:s", $timestamps[$index]);
  131. $class = $class == "even" ? "odd" : "even";
  132.  
  133. echo "\t<tr class=\"$class\">\n" .
  134. "\t\t<td><img src=\"data:image/png;base64,$icon\" title=\"$type\" alt=\"$type\" /></td>\n" .
  135. "\t\t<td><a href=\"$url\">$name</a></td>\n" .
  136. // "\t\t<td><small>$size</small></td>\n" .
  137. "\t\t<td><small>$modified</small></td>\n" .
  138. "\t</tr>\n";
  139. }
  140.  
  141. echo "</table>\n";
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement