PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 6.11
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v6.11
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
wp-database-backup / includes / admin / lib / php_file_tree.php

php_file_tree.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 6.11, at includes/admin/lib/php_file_tree.php

93 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /* == DOCUMENTATION ==
3 For documentation and updates, visit http://abeautifulsite.net/notebook.php?article=21
4 */
5
6 function php_file_tree($directory, $return_link, $extensions = array()) {
7 // Generates a valid XHTML list of all directories, sub-directories, and files in $directory
8 // Remove trailing slash
9 $siteURL = $directory . '/';
10 $code = "";
11 if (substr($directory, -1) == "/")
12 $directory = substr($directory, 0, strlen($directory) - 1);
13 $code .= php_file_tree_dir($siteURL, $directory, $return_link, $extensions);
14 return $code;
15 }
16
17 function php_file_tree_dir($siteURL, $directory, $return_link, $extensions = array(), $first_call = true) {
18 // Recursive function called by php_file_tree() to list directories/files
19 $php_file_tree = "";
20
21 $wp_all_backup_exclude_dir = explode("|", get_option('wp_all_backup_exclude_dir'));
22
23 // Get and sort directories/files
24 if (function_exists("scandir"))
25 $file = scandir($directory);
26 else
27 $file = php4_scandir($directory);
28 natcasesort($file);
29 // Make directories first
30 $files = $dirs = array();
31 foreach ($file as $this_file) {
32 if (is_dir("$directory/$this_file"))
33 $dirs[] = $this_file;
34 else
35 $files[] = $this_file;
36 }
37 $file = array_merge($dirs, $files);
38
39 // Filter unwanted extensions
40 if (!empty($extensions)) {
41 foreach (array_keys($file) as $key) {
42 if (!is_dir("$directory/$file[$key]")) {
43 $ext = substr($file[$key], strrpos($file[$key], ".") + 1);
44 if (!in_array($ext, $extensions))
45 unset($file[$key]);
46 }
47 }
48 }
49
50 if (count($file) > 2) { // Use 2 instead of 0 to account for . and .. "directories"
51 $php_file_tree = "<ul";
52 if ($first_call) {
53 $php_file_tree .= " class=\"php-file-tree\"";
54 $first_call = false;
55 }
56 $php_file_tree .= ">";
57 foreach ($file as $this_file) {
58 if ($this_file != "." && $this_file != "..") {
59 $exclude_dir_file = str_replace($siteURL, '', "$directory/$this_file");
60 if (in_array($exclude_dir_file, $wp_all_backup_exclude_dir)) {
61 $exclude_file = 'checked';
62 } else {
63 $exclude_file = '';
64 }
65
66 if (is_dir("$directory/$this_file")) {
67 // Directory
68 $php_file_tree .= "<li class=\"pft-directory\"><input type='checkbox' name='wpall_exclude[]' $exclude_file value='$exclude_dir_file'><a >" . htmlspecialchars($this_file) . "</a>";
69 $php_file_tree .= php_file_tree_dir($siteURL, "$directory/$this_file", $return_link, $extensions, false);
70 $php_file_tree .= "</li>";
71 } else {
72 // File
73 // Get extension (prepend 'ext-' to prevent invalid classes from extensions that begin with numbers)
74 $ext = "ext-" . substr($this_file, strrpos($this_file, ".") + 1);
75 $link = str_replace("[link]", "$directory/" . urlencode($this_file), $return_link);
76 $php_file_tree .= "<li class=\"pft-file " . strtolower($ext) . "\"><input type='checkbox' name='wpall_exclude[]' $exclude_file value='$exclude_dir_file'> <a>" . htmlspecialchars($this_file) . "</a></li>";
77 }
78 }
79 }
80 $php_file_tree .= "</ul>";
81 }
82 return $php_file_tree;
83 }
84
85 // For PHP4 compatibility
86 function php4_scandir($dir) {
87 $dh = opendir($dir);
88 while (false !== ($filename = readdir($dh))) {
89 $files[] = $filename;
90 }
91 sort($files);
92 return($files);
93 }