Skip to content

Commit 1689c6f

Browse files
Merge pull request #7 from ExpressTech/dev-1.0.2
Show tree from the drop directory
2 parents 5975c93 + 357831b commit 1689c6f

2 files changed

Lines changed: 94 additions & 57 deletions

File tree

assets/admin/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ul.tree-list li {
4242
li.tree-file:hover{
4343
background: #f1f1f1;
4444
}
45-
li.tree-file:hover .file-actions{display:inline-block;}
45+
.tree-file:hover .file-actions{display:inline-block;}
4646
.file-actions{
4747
position: absolute;
4848
top: 0;

includes/post-types/contentsView.php

Lines changed: 93 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -113,66 +113,103 @@ public function flatToTree($flat)
113113
return $tree_list;
114114
}
115115

116-
/**
116+
function listFolderFiles($dir, $url = '') {
117+
$ffs = scandir($dir);
118+
119+
unset($ffs[array_search('.', $ffs, true)]);
120+
unset($ffs[array_search('..', $ffs, true)]);
121+
122+
if (count($ffs) < 1) {
123+
return;
124+
}
125+
$output = '';
126+
foreach ($ffs as $ff) {
127+
$output .= '<li>';
128+
129+
$file_path = str_replace(ABSPATH, '', $dir);
130+
$file_url = site_url('/') . $file_path . '/' . $ff;
131+
if (is_dir($dir . '/' . $ff)) {
132+
$output .= '<strong>' . $ff . '/</strong>';
133+
} else {
134+
$output .= '<div class="tree-file">' . $ff;
135+
$output .= '<div class="file-actions">';
136+
$output .= '<a href="' . $file_url . '" target="_blank">' . __('Preview', 'drophtml') . '</a>';
137+
//$output .= '<a href="#">'. __( 'Edit', 'drophtml' ) . '</a>';
138+
$output .= '<a href="javascript:void(0)" class="delete-tree-file" data-path="' . $file_path . '" data-file="' . $ff . '">' . __('Delete', 'drophtml') . '</a>';
139+
$output .= '</div>';
140+
$output .= '</div>';
141+
}
142+
if (is_dir($dir . '/' . $ff)) {
143+
$output .= '<ul class="folder">';
144+
$output .= $this->listFolderFiles($dir . '/' . $ff, $url);
145+
$output .= '</ul>';
146+
}
147+
$output .= '</li>';
148+
}
149+
150+
return $output;
151+
}
152+
153+
/**
117154
* List or show upload form
118155
*/
119-
function showFileList($id)
120-
{
121-
if (!$this->isValidPostType()) {
122-
return false;
123-
}
156+
function showFileList($id) {
157+
if (!$this->isValidPostType()) {
158+
return false;
159+
}
124160

125-
$file = get_post_meta($id, 'wp_custom_attachment', true);
161+
$file = get_post_meta($id, 'wp_custom_attachment', true);
126162
$drop_url = get_post_meta($id, 'drop_preview_url', true);
127-
128-
if ($file) {
129-
130-
mbstring_binary_safe_encoding();
131-
132-
//get the url
133-
$url = $file['url'];
134-
135-
//Replace url to directory path
136-
$path = str_replace(site_url('/'), ABSPATH, esc_url($url));
137-
138-
if (is_file($path)) {
139-
$filesize = size_format(filesize($path));
140-
$filename = basename($path);
141-
142-
$html = '<div>' . __('Name:', 'drophtml') . ' ' . $filename . '</div>';
143-
$html .= '<div>' . __('Size:', 'drophtml') . ' ' . $filesize . '</div>';
144-
$html .= '<div>' . __('Files:', 'drophtml') . '</div>';
145-
146-
$zip = new PclZip($path);
147-
$fileStructure = $this->flatToTree($zip->listContent());
148-
149-
$html .= '<pre class="file-list">';
150-
$html .= '<ul id="tree-list" class="tree-list" role="tree" aria-labelledby="plugin-files-label">';
151-
if ($fileStructure) {
152-
$html .= $this->recursiveFileStructure($fileStructure, $drop_url);
153-
}
154-
$html .= '</ul>';
155-
$html .= '<input type="hidden" id="zip-file-url" value="'.$path.'">';
156-
$html .= '</pre>';
157-
}
158-
159-
reset_mbstring_encoding();
160-
} else {
161-
wp_nonce_field(plugin_basename(__FILE__), 'wp_custom_attachment_nonce');
162-
$html = '<p class="description">';
163-
$html .= __('Upload your ZIP here.', 'drophtml');
164-
$html .= '</p>';
165-
$html .= '<input type="file" id="wp_custom_attachment" name="wp_custom_attachment" value="" size="25">';
166-
}
167-
168-
$output = '<div class="drophtml-file-view">';
169-
$output .= $html;
170-
$output .= '</div>';
171-
172-
return $output;
173-
}
174-
175-
function frontend_template($template)
163+
$drop_path = str_replace(site_url('/'), ABSPATH, esc_url($drop_url));
164+
165+
$html = '';
166+
if ($file) {
167+
mbstring_binary_safe_encoding();
168+
169+
//get the url
170+
$url = $file['url'];
171+
172+
//Replace url to directory path
173+
$path = str_replace(site_url('/'), ABSPATH, esc_url($url));
174+
175+
if (is_file($path)) {
176+
$filesize = size_format(filesize($path));
177+
$filename = basename($path);
178+
179+
$html = '<div>' . __('Name:', 'drophtml') . ' ' . $filename . '</div>';
180+
$html .= '<div>' . __('Size:', 'drophtml') . ' ' . $filesize . '</div>';
181+
$html .= '<div>' . __('Files:', 'drophtml') . '</div>';
182+
183+
$html .= '<pre class="file-list">';
184+
$html .= '<ul id="tree-list" class="tree-list" role="tree" aria-labelledby="plugin-files-label">';
185+
$html .= $this->listFolderFiles($drop_path, $drop_url);
186+
/*$zip = new PclZip($path);
187+
$fileStructure = $this->flatToTree($zip->listContent());
188+
if ($fileStructure) {
189+
$html .= $this->recursiveFileStructure($fileStructure, $drop_url);
190+
}*/
191+
$html .= '</ul>';
192+
$html .= '<input type="hidden" id="zip-file-url" value="' . $path . '">';
193+
$html .= '</pre>';
194+
}
195+
196+
reset_mbstring_encoding();
197+
} else {
198+
wp_nonce_field(plugin_basename(__FILE__), 'wp_custom_attachment_nonce');
199+
$html = '<p class="description">';
200+
$html .= __('Upload your ZIP here.', 'drophtml');
201+
$html .= '</p>';
202+
$html .= '<input type="file" id="wp_custom_attachment" name="wp_custom_attachment" value="" size="25">';
203+
}
204+
205+
$output = '<div class="drophtml-file-view">';
206+
$output .= $html;
207+
$output .= '</div>';
208+
209+
return $output;
210+
}
211+
212+
function frontend_template($template)
176213
{
177214
global $post;
178215

0 commit comments

Comments
 (0)