PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-filemanager/incl/functions.inc.php

https://gitlab.com/gentotech/evotennissg
PHP | 263 lines | 238 code | 25 blank | 0 comment | 61 complexity | b20697aeeacbbcddec2a8494c7c93f81 MD5 | raw file
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) )
  3. die();
  4. function wp_fileman_remove_directory($directory) ## Remove a directory recursively
  5. {
  6. $list_sub = array();
  7. $list_files = array();
  8. if (!($open = @opendir($directory)))
  9. return FALSE;
  10. while(($index = @readdir($open)) != FALSE)
  11. {
  12. if (is_dir($directory.$index) && $index != "." && $index != "..")
  13. $list_sub[] = $index."/";
  14. else if (is_file($directory.$index))
  15. $list_files[] = $index;
  16. }
  17. closedir($open);
  18. foreach($list_files as $file)
  19. if (!@unlink($directory.$file))
  20. return FALSE;
  21. foreach($list_sub as $sub)
  22. {
  23. wp_fileman_remove_directory($directory.$sub);
  24. if (!@rmdir($directory.$sub))
  25. return FALSE;
  26. }
  27. return TRUE;
  28. }
  29. function wp_fileman_get_icon($filename) ## Get the icon from the filename
  30. {
  31. global $IconArray;
  32. @reset($IconArray);
  33. $extension = strtolower(substr(strrchr($filename, "."),1));
  34. if ($extension == "")
  35. return "unknown.gif";
  36. while (list($icon, $types) = each($IconArray))
  37. foreach (explode(" ", $types) as $type)
  38. if ($extension == $type)
  39. return $icon;
  40. return "unknown.gif";
  41. }
  42. function wp_fileman_compare_filedata ($a, $b) ## Compare filedata (used to sort)
  43. {
  44. if (is_int($a[$_GET['sortby']]) && is_int($b[$_GET['sortby']]))
  45. {
  46. if ($a[$_GET['sortby']]==$b[$_GET['sortby']]) return 0;
  47. if ($_GET['order'] == "asc")
  48. {
  49. if ($a[$_GET['sortby']] > $b[$_GET['sortby']]) return 1;
  50. else return -1;
  51. }
  52. else if ($_GET['order'] == "desc")
  53. {
  54. if ($a[$_GET['sortby']] < $b[$_GET['sortby']]) return 1;
  55. else return -1;
  56. }
  57. }
  58. else if (is_string($a[$_GET['sortby']]) && is_string($b[$_GET['sortby']]) && $_GET['order'] == "asc")
  59. return strcmp($a[$_GET['sortby']], $b[$_GET['sortby']]);
  60. else if (is_string($a[$_GET['sortby']]) && is_string($b[$_GET['sortby']]) && $_GET['order'] == "desc")
  61. return -strcmp($a[$_GET['sortby']], $b[$_GET['sortby']]);
  62. }
  63. function wp_fileman_get_opposite_order($input, $order) ## Get opposite order
  64. {
  65. if ($_GET['sortby'] == $input)
  66. {
  67. if ($order == "asc")
  68. return "desc";
  69. else if ($order == "desc")
  70. return "asc";
  71. }
  72. else
  73. return "asc";
  74. }
  75. function wp_fileman_is_editable_file($filename) ## Checks whether a file is editable
  76. {
  77. global $EditableFiles;
  78. $extension = strtolower(substr(strrchr($filename, "."),1));
  79. foreach(explode(",", $EditableFiles) as $type)
  80. if ($extension == $type)
  81. return TRUE;
  82. return FALSE;
  83. }
  84. function wp_fileman_is_viewable_file($filename) ## Checks whether a file is viewable
  85. {
  86. global $ViewableFiles;
  87. $extension = strtolower(substr(strrchr($filename, "."),1));
  88. foreach(explode(",", $ViewableFiles) as $type)
  89. if ($extension == $type)
  90. return TRUE;
  91. return FALSE;
  92. }
  93. function wp_fileman_is_valid_name($input) ## Checks whether the directory- or filename is valid
  94. {
  95. if (strstr($input, "\\"))
  96. return FALSE;
  97. else if (strstr($input, "/"))
  98. return FALSE;
  99. else if (strstr($input, ":"))
  100. return FALSE;
  101. else if (strstr($input, "?"))
  102. return FALSE;
  103. else if (strstr($input, "*"))
  104. return FALSE;
  105. else if (strstr($input, "\""))
  106. return FALSE;
  107. else if (strstr($input, "<"))
  108. return FALSE;
  109. else if (strstr($input, ">"))
  110. return FALSE;
  111. else if (strstr($input, "|"))
  112. return FALSE;
  113. else
  114. return TRUE;
  115. }
  116. function wp_fileman_get_better_filesize($filesize) ## Converts filesize to KB/MB/GB/TB
  117. {
  118. $kilobyte = 1024;
  119. $megabyte = 1048576;
  120. $gigabyte = 1073741824;
  121. $terabyte = 1099511627776;
  122. if ($filesize >= $terabyte)
  123. return number_format($filesize/$terabyte, 2, ',', '.')."&nbsp;TB";
  124. else if ($filesize >= $gigabyte)
  125. return number_format($filesize/$gigabyte, 2, ',', '.')."&nbsp;GB";
  126. else if ($filesize >= $megabyte)
  127. return number_format($filesize/$megabyte, 2, ',', '.')."&nbsp;MB";
  128. else if ($filesize >= $kilobyte)
  129. return number_format($filesize/$kilobyte, 2, ',', '.')."&nbsp;KB";
  130. else
  131. return number_format($filesize, 0, ',', '.')."&nbsp;B";
  132. }
  133. function wp_fileman_get_current_zoom_level($current_zoom_level, $zoom) ## Get current zoom level
  134. {
  135. global $ZoomArray;
  136. @reset($ZoomArray);
  137. while(list($number, $zoom_level) = each($ZoomArray))
  138. if ($zoom_level == $current_zoom_level)
  139. if (($number+$zoom) < 0) return $number;
  140. else if (($number+$zoom) >= count($ZoomArray)) return $number;
  141. else return $number+$zoom;
  142. }
  143. function wp_fileman_validate_path($wp_fileman_path) ## Validate path
  144. {
  145. global $StrAccessDenied;
  146. if (stristr($wp_fileman_path, "../") || stristr($wp_fileman_path, "..\\"))
  147. return TRUE;
  148. else
  149. return stripslashes($wp_fileman_path);
  150. }
  151. function wp_fileman_authenticate_user() ## Authenticate user using cookies
  152. {
  153. global $username, $password;
  154. if (isset($_COOKIE['cookie_username']) && $_COOKIE['cookie_username'] == $username && isset($_COOKIE['cookie_password']) && $_COOKIE['cookie_password'] == md5($password))
  155. return TRUE;
  156. else
  157. return FALSE;
  158. }
  159. function wp_fileman_is_hidden_file($wp_fileman_path) ## Checks whether the file is hidden.
  160. {
  161. global $hide_file_extension, $hide_file_string, $hide_directory_string;
  162. $extension = strtolower(substr(strrchr($wp_fileman_path, "."),1));
  163. if (is_array($hide_file_extension))
  164. {
  165. foreach ($hide_file_extension as $hidden_extension)
  166. {
  167. if ($hidden_extension == $extension)
  168. {
  169. return TRUE;
  170. }
  171. }
  172. }
  173. if (is_array($hide_file_string))
  174. {
  175. foreach ($hide_file_string as $hidden_string)
  176. {
  177. if ($hidden_string != "" && stristr(basename($wp_fileman_path), $hidden_string))
  178. {
  179. return TRUE;
  180. }
  181. }
  182. }
  183. return FALSE;
  184. }
  185. function wp_fileman_is_hidden_directory($wp_fileman_path) ## Checks whether the directory is hidden.
  186. {
  187. global $hide_directory_string;
  188. if (is_array($hide_directory_string))
  189. foreach ($hide_directory_string as $hidden_string)
  190. if ($hidden_string != "" && stristr($wp_fileman_path, $hidden_string))
  191. return TRUE;
  192. return FALSE;
  193. }
  194. function wp_fileman_get_mimetype($filename) ## Get MIME-type for file
  195. {
  196. global $MIMEtypes;
  197. @reset($MIMEtypes);
  198. $extension = strtolower(substr(strrchr($filename, "."),1));
  199. if ($extension == "")
  200. return "Unknown/Unknown";
  201. while (list($mimetype, $file_extensions) = each($MIMEtypes))
  202. foreach (explode(" ", $file_extensions) as $file_extension)
  203. if ($extension == $file_extension)
  204. return $mimetype;
  205. return "Unknown/Unknown";
  206. }
  207. function wp_fileman_get_linked_path($wp_fileman_path,$base_url) ## Get path with links to each folder
  208. {
  209. $string = "<a href='$base_url'>.</a> / ";
  210. $array = explode("/",htmlentities($wp_fileman_path));
  211. unset($array[count($array)-1]);
  212. foreach ($array as $entry)
  213. {
  214. @$temppath .= $entry."/";
  215. $string .= "<a href='$base_url&amp;path=".htmlentities(rawurlencode($temppath))."'>$entry</a> / ";
  216. }
  217. return $string;
  218. }
  219. ?>