Skip to content

Commit

Permalink
Merge pull request #20 from ZNick1982/saveToServer
Browse files Browse the repository at this point in the history
Save to server
  • Loading branch information
ZNick1982 committed Dec 18, 2017
2 parents cf901a2 + ed3877d commit 0985131
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Changelog


### 2.5.0
### 2.5.0 ([Download](http://downloads.wordpress.org/plugin/uploadcare.2.5.0.zip))
- Test up to Wordpress 4.9.1
- Uploadcare widget updated to version 3.x
- Added In-browser image editing and filters
- Added storing Uploadcare images localy on your WordPress host


### 2.4.1 ([Download](http://downloads.wordpress.org/plugin/uploadcare.2.4.1.zip))
Expand Down
11 changes: 10 additions & 1 deletion inc/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function uploadcare_attach($file) {

if (get_option('uploadcare_download_to_server')) {
$attached_file = uploadcare_download($file);
add_post_meta($attachment_id, '_uc_is_local_file', true, true);
} else {
$attached_file = $file->data['original_file_url'];
add_post_meta($attachment_id, 'uploadcare_url', $attached_file, true);
Expand Down Expand Up @@ -164,7 +165,15 @@ function uploadcare_handle() {
}
$file->store();
$attachment_id = uploadcare_attach($file);
echo "{\"attach_id\": $attachment_id}";
$fileUrl = get_post_meta($attachment_id, '_wp_attached_file', true);
$isLocal = "false";
if(get_post_meta($attachment_id, '_uc_is_local_file', true)) {
$isLocal = "true";
$uploadBaseUrl = wp_upload_dir(false, false, false)["baseurl"];
$fileUrl = "$uploadBaseUrl/$fileUrl";
}

echo "{\"attach_id\": $attachment_id, \"fileUrl\": \"$fileUrl\", \"isLocal\": $isLocal}";
die;
}

Expand Down
17 changes: 8 additions & 9 deletions inc/uploadcare_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
update_option('uploadcare_original', $uploadcare_original);
$uploadcare_multiupload = $_POST['uploadcare_multiupload'];
update_option('uploadcare_multiupload', $uploadcare_multiupload);
// $uploadcare_download_to_server = $_POST['uploadcare_download_to_server'];
// update_option('uploadcare_download_to_server', $uploadcare_download_to_server);
$uploadcare_download_to_server = $_POST['uploadcare_download_to_server'];
update_option('uploadcare_download_to_server', $uploadcare_download_to_server);
$uploadcare_finetuning = $_POST['uploadcare_finetuning'];
update_option('uploadcare_finetuning', $uploadcare_finetuning);
$uploadcare_source_tabs = $_POST['uploadcare_source_tabs'];
Expand All @@ -71,7 +71,7 @@
$uploadcare_secret = get_option('uploadcare_secret');
$uploadcare_original = get_option('uploadcare_original');
$uploadcare_multiupload = get_option('uploadcare_multiupload');
// $uploadcare_download_to_server = get_option('uploadcare_download_to_server');
$uploadcare_download_to_server = get_option('uploadcare_download_to_server');
$uploadcare_finetuning = get_option('uploadcare_finetuning');
$uploadcare_source_tabs = get_option('uploadcare_source_tabs', $tab_defaults);
$uploadcare_tab_effects = get_option('uploadcare_tab_effects', $effects_defaults);
Expand Down Expand Up @@ -105,6 +105,10 @@
<input type="checkbox" name="uploadcare_multiupload" <?php if ($uploadcare_multiupload): ?>checked="checked"<?php endif; ?>
/>&nbsp;<?php _e('Allow multiupload in Uploadcare widget'); ?>
</p>
<p>
<input type="checkbox" name="uploadcare_download_to_server" <?php if ($uploadcare_download_to_server): ?>checked="checked"<?php endif; ?>
/>&nbsp;<?php _e('Download images to server from Uploadcare before publish'); ?>
</p>
<h3>Tab effects</h3>
<select name="uploadcare_tab_effects[]" multiple="" size="12" style="width: 120px;">
<?php
Expand All @@ -116,12 +120,7 @@
}
?>
</select>

<!-- <p>
<input type="checkbox" name="uploadcare_download_to_server" <?php if ($uploadcare_download_to_server): ?>checked="checked"<?php endif; ?>
/>&nbsp;<?php _e('Download images to server from Uploadcare before publish'); ?>
</p>
--> <h3>Upload Sources</h3>
<h3>Upload Sources</h3>
<select name="uploadcare_source_tabs[]" multiple="" size="12" style="width: 120px;">
<?php
$selected = in_array('all', $uploadcare_source_tabs) ? 'selected="selected"' : '';
Expand Down
20 changes: 11 additions & 9 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ function ucStoreImg(fileInfo, callback) {

function ucAddImg(fileInfo) {
ucStoreImg(fileInfo, function(response) {
console.log(response);
var obj = uploadcare.jQuery.parseJSON(response);
var fileUrl = obj.fileUrl;
if (fileInfo.isImage) {
var $img = '<img src="' + fileInfo.cdnUrl + '" alt="' + fileInfo.name + '"/>';
var $img = '<img src="' + fileUrl + '" alt="' + fileInfo.name + '"/>';
if(UPLOADCARE_CONF.original) {
window.send_to_editor('<a href="' + fileInfo.cdnUrl + '">' + $img + '</a>');
window.send_to_editor('<a href="' + fileUrl + '">' + $img + '</a>');
} else {
window.send_to_editor($img);
}
} else {
window.send_to_editor('<a href="' + fileInfo.cdnUrl + '">' + fileInfo.name + '</a>');
window.send_to_editor('<a href="' + fileUrl + '">' + fileInfo.name + '</a>');
}
window.send_to_editor('\n');
});
Expand All @@ -61,10 +64,10 @@ function ucFileDone(data) {
} else {
var file = data;
file.done(ucAddImg)
.always(function() {
uploadcare.jQuery('#content').prop('disabled', false);
uploadcare.jQuery('.uploadcare-loading-screen').addClass('uploadcare-hidden');
});
.always(function() {
uploadcare.jQuery('#content').prop('disabled', false);
uploadcare.jQuery('.uploadcare-loading-screen').addClass('uploadcare-hidden');
});
}
}

Expand Down Expand Up @@ -113,13 +116,11 @@ function ucPostUploadUiBtn() {
}
stored++;
if(stored == files.length) {
// all files are stored
// TODO: disable everything until now

if(wp.media) {
// switch to attachment browser
wp.media.frame.content.mode('browse');

// refresh attachment collection
// no need for WP 4.7.2 but kept for older WP versions
try {
Expand All @@ -129,6 +130,7 @@ function ucPostUploadUiBtn() {
} else if (adminpage == 'media-new-php') {
location = 'upload.php';
}

}
});
});
Expand Down
6 changes: 6 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ Access all files in your Uploadcare account via Media Library.

== Changelog ==

= 2.5.0 =
- Test up to Wordpress 4.9.1
- Uploadcare widget updated to version 3.x
- Added In-browser image editing and filters
- Added storing Uploadcare images localy on your WordPress host

= 2.4.1 =
* Minor bug fix for usage jQuery.
* Test up to Wordpress 4.7.3
Expand Down

0 comments on commit 0985131

Please sign in to comment.