Skip to content

Commit

Permalink
minor ui fixes
Browse files Browse the repository at this point in the history
add cleanup temp dir function
  • Loading branch information
michelegiorgi committed Mar 24, 2021
1 parent add39db commit 0381b74
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
Binary file modified assets/images/source/blockpreview.sketch
Binary file not shown.
4 changes: 4 additions & 0 deletions assets/styles/admin/editor_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
}
}
}
&.formality__field--upload .formality__input .formality__upload {
padding-left: 0;
padding-right: 0;
}
}
}
&.conversational {
Expand Down
3 changes: 0 additions & 3 deletions assets/styles/public/components/_fields.scss
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,6 @@
}
}
&--upload {
> .formality__label {
//
}
.formality__input {
cursor: pointer;
min-height: 7.5rem;
Expand Down
5 changes: 4 additions & 1 deletion assets/styles/public/modifiers/_line.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@
&--upload {
.formality__input {
.formality__upload {
padding: 0.7em 0;
padding: 0.7em 0 1em;
.formality__upload__toggle p {
margin-bottom: 1rem
}
}
}
}
Expand Down
26 changes: 25 additions & 1 deletion public/class-formality-upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,33 @@ public function create_upload_dir() {
*/
public function delete_temp_file($filename) {
$directory = $this->get_upload_dir(true, 'path');
$filepath = $directory . '/' . $this->decode_filename('decrypt', $filename);
$filepath = trailingslashit($directory) . $this->decode_filename('decrypt', $filename);
wp_delete_file_from_directory($filepath, $directory);
}

/**
* Cleanup temp directory
*
* @since 1.3.0
*/
public function cleanup_temp_dir($expire=3600, $limit=99) {
$directory = trailingslashit($this->get_upload_dir(true, 'path'));
if(!is_dir($directory) || !is_readable($directory) || !wp_is_writable($directory)) { return; }
$count = 0;

if($handle = opendir($directory)) {
while(false !== ($file = readdir($handle))) {
$filepath = path_join($directory, $file);
$mtime = @filemtime($filepath);
if($mtime && time() < $mtime + $expire) { continue; }
wp_delete_file($filepath);
$count++;
if($limit <= $count) { break; }
}
closedir($handle);
}
}

/**
* Encode/decode filename
*
Expand Down Expand Up @@ -130,6 +153,7 @@ public function upload_temp_file() {
if (wp_verify_nonce( $nonce, 'formality_async' ) && !empty($_FILES)) {

$this->create_upload_dir();
$this->cleanup_temp_dir();
if($old) { $this->delete_temp_file($old); }

//get form and field informations
Expand Down

0 comments on commit 0381b74

Please sign in to comment.