Version Description
Download this release
Release Info
Developer | qqworld |
Plugin | QQWorld Auto Save Images |
Version | 1.4.1 |
Comparing to | |
See all releases |
Code changes from version 1.4 to 1.4.1
- qqworld-auto-save-images.php +52 -108
qqworld-auto-save-images.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: QQWorld Auto Save Images
|
4 |
Plugin URI: https://wordpress.org/plugins/qqworld-auto-save-images/
|
5 |
Description: Automatically keep the all remote picture to the local, and automatically set featured image. 自动保存远程图片到本地,自动设置特色图片,并且支持机器人采集软件从外部提交。
|
6 |
-
Version: 1.4
|
7 |
Author: Michael Wang
|
8 |
Author URI: http://www.qqworld.org
|
9 |
*/
|
@@ -20,10 +20,6 @@ class QQWorld_auto_save_images {
|
|
20 |
break;
|
21 |
case 'manual':
|
22 |
add_action( 'media_buttons', array($this, 'media_buttons' ), 11 );
|
23 |
-
add_action( 'admin_init', array($this, 'add_buttons_in_visualmode') );
|
24 |
-
add_action( 'admin_print_footer_scripts', array($this, 'add_buttons_in_textmode') );
|
25 |
-
add_action( 'wp_ajax_get_ajax_editor_button_plugin', array($this, 'get_ajax_editor_button') );
|
26 |
-
add_action( 'wp_ajax_nopriv_get_ajax_editor_button_plugin', array($this, 'get_ajax_editor_button') );
|
27 |
add_action( 'wp_ajax_save_remote_images', array($this, 'save_remote_images') );
|
28 |
add_action( 'wp_ajax_nopriv_save_remote_images', array($this, 'save_remote_images') );
|
29 |
break;
|
@@ -35,101 +31,6 @@ class QQWorld_auto_save_images {
|
|
35 |
add_filter( 'plugin_row_meta', array($this, 'registerPluginLinks'),10,2 );
|
36 |
}
|
37 |
|
38 |
-
public function add_buttons_in_textmode() {
|
39 |
-
if (wp_script_is('quicktags')) : ?>
|
40 |
-
<script>
|
41 |
-
QTags.addButton('qqworld_auto_save_images', '<?php _e('Save Remote Images', 'qqworld_auto_save_images'); ?>', function(el, canvas) {
|
42 |
-
console.log(1)
|
43 |
-
var $ = jQuery;
|
44 |
-
var icon = '<span class="wp-media-buttons-icon"></span>';
|
45 |
-
jQuery('.button.save_remote_images').html(icon+QQWorld_auto_save_images.text.in_process);
|
46 |
-
jQuery.ajax({
|
47 |
-
type: "POST",
|
48 |
-
url: ajaxurl,
|
49 |
-
data: {
|
50 |
-
action: 'save_remote_images',
|
51 |
-
post_id: QQWorld_auto_save_images.post_id,
|
52 |
-
content: escape($('#content').val())
|
53 |
-
},
|
54 |
-
success: function(respond) {
|
55 |
-
jQuery('.button.save_remote_images').addClass('success').html(icon+QQWorld_auto_save_images.text.succesed_save_remote_images);
|
56 |
-
var init = function() {
|
57 |
-
jQuery('.button.save_remote_images').removeClass('success').html(icon+QQWorld_auto_save_images.text.save_remote_images);
|
58 |
-
}
|
59 |
-
//console.log(respond)
|
60 |
-
$('#content').val(respond)
|
61 |
-
setTimeout(init, 3000);
|
62 |
-
}
|
63 |
-
});
|
64 |
-
});
|
65 |
-
</script>
|
66 |
-
<?php endif;
|
67 |
-
}
|
68 |
-
|
69 |
-
public function get_ajax_editor_button() {
|
70 |
-
header("Content-type: application/x-javascript");
|
71 |
-
?>
|
72 |
-
(function() {
|
73 |
-
tinymce.create('tinymce.plugins.save_remote_images', {
|
74 |
-
init: function(ed, url) {
|
75 |
-
ed.addButton('save_remote_images', {
|
76 |
-
title: '<?php _e('Save Remote Images', 'qqworld_auto_save_images'); ?>',
|
77 |
-
onclick: function() {
|
78 |
-
var icon = '<span class="wp-media-buttons-icon"></span>';
|
79 |
-
jQuery('.button.save_remote_images').html(icon+QQWorld_auto_save_images.text.in_process);
|
80 |
-
jQuery.ajax({
|
81 |
-
type: "POST",
|
82 |
-
url: ajaxurl,
|
83 |
-
data: {
|
84 |
-
action: 'save_remote_images',
|
85 |
-
post_id: QQWorld_auto_save_images.post_id,
|
86 |
-
content: escape(ed.getContent())
|
87 |
-
},
|
88 |
-
success: function(respond) {
|
89 |
-
jQuery('.button.save_remote_images').addClass('success').html(icon+QQWorld_auto_save_images.text.succesed_save_remote_images);
|
90 |
-
var init = function() {
|
91 |
-
jQuery('.button.save_remote_images').removeClass('success').html(icon+QQWorld_auto_save_images.text.save_remote_images);
|
92 |
-
}
|
93 |
-
//console.log(respond)
|
94 |
-
ed.setContent(respond);
|
95 |
-
setTimeout(init, 3000);
|
96 |
-
}
|
97 |
-
});
|
98 |
-
}
|
99 |
-
});
|
100 |
-
},
|
101 |
-
createControl: function(n, cm) {
|
102 |
-
return null;
|
103 |
-
},
|
104 |
-
});
|
105 |
-
tinymce.PluginManager.add('save_remote_images', tinymce.plugins.save_remote_images);
|
106 |
-
})();
|
107 |
-
<?php
|
108 |
-
exit;
|
109 |
-
}
|
110 |
-
|
111 |
-
public function add_buttons_in_visualmode() {
|
112 |
-
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {
|
113 |
-
return;
|
114 |
-
}
|
115 |
-
if ( get_user_option('rich_editing') == 'true' ) {
|
116 |
-
add_filter( 'mce_external_plugins', array($this, 'add_tinymce_plugin') );
|
117 |
-
add_filter( 'mce_buttons', array($this, 'register_button') );
|
118 |
-
}
|
119 |
-
}
|
120 |
-
public function add_tinymce_plugin( $plugin_array ) {
|
121 |
-
$data = array(
|
122 |
-
'action' => 'get_ajax_editor_button_plugin',
|
123 |
-
'data' => $button['virtual']
|
124 |
-
);
|
125 |
-
$plugin_array['save_remote_images'] = admin_url( 'admin-ajax.php?'.http_build_query($data), 'relative' );
|
126 |
-
return $plugin_array;
|
127 |
-
}
|
128 |
-
public function register_button( $buttons ) {
|
129 |
-
array_push( $buttons, 'save_remote_images' );
|
130 |
-
return $buttons;
|
131 |
-
}
|
132 |
-
|
133 |
public function media_buttons() {
|
134 |
global $post;
|
135 |
?>
|
@@ -155,10 +56,6 @@ console.log(1)
|
|
155 |
-ms-transform: scale(1.1);
|
156 |
transform: scale(1.1);
|
157 |
}
|
158 |
-
#qt_content_qqworld_auto_save_images {
|
159 |
-
position: absolute;
|
160 |
-
z-index: -10;
|
161 |
-
}
|
162 |
</style>
|
163 |
<a href="javascript:" id="save-remote-images-button" class="button save_remote_images" title="<?php _e('Save Remote Images', 'qqworld_auto_save_images'); ?>"><span class="wp-media-buttons-icon"></span><?php _e('Save Remote Images', 'qqworld_auto_save_images'); ?></a>
|
164 |
<script>
|
@@ -173,11 +70,58 @@ console.log(1)
|
|
173 |
$(window).on('load', function() {
|
174 |
$('.mce-i-save_remote_images').closest('.mce-widget').hide();
|
175 |
$(document).on('click', '#save-remote-images-button', function() {
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
});
|
179 |
})
|
180 |
});
|
|
|
181 |
</script>
|
182 |
<?php
|
183 |
}
|
@@ -211,11 +155,11 @@ console.log(1)
|
|
211 |
<th scope="row"><label for="blogname"><?php _e('Type'); ?></label></th>
|
212 |
<td><fieldset>
|
213 |
<legend class="screen-reader-text"><span><?php _e('Type'); ?></span></legend>
|
214 |
-
<label for="
|
215 |
<input name="qqworld_auto_save_imagess_type" type="radio" id="auto" value="auto" <?php checked('auto', $this->type); ?> />
|
216 |
<?php _e('Automatically save all remote images to local media libary when you save or publish post.', 'qqworld_auto_save_images'); ?>
|
217 |
</label><br />
|
218 |
-
<label for="
|
219 |
<input name="qqworld_auto_save_imagess_type" type="radio" id="manual" value="manual" <?php checked('manual', $this->type); ?> />
|
220 |
<?php _e('Manually save all remote images to local media libary when you click the button on the top of editor.', 'qqworld_auto_save_images'); ?>
|
221 |
</label>
|
3 |
Plugin Name: QQWorld Auto Save Images
|
4 |
Plugin URI: https://wordpress.org/plugins/qqworld-auto-save-images/
|
5 |
Description: Automatically keep the all remote picture to the local, and automatically set featured image. 自动保存远程图片到本地,自动设置特色图片,并且支持机器人采集软件从外部提交。
|
6 |
+
Version: 1.4.1
|
7 |
Author: Michael Wang
|
8 |
Author URI: http://www.qqworld.org
|
9 |
*/
|
20 |
break;
|
21 |
case 'manual':
|
22 |
add_action( 'media_buttons', array($this, 'media_buttons' ), 11 );
|
|
|
|
|
|
|
|
|
23 |
add_action( 'wp_ajax_save_remote_images', array($this, 'save_remote_images') );
|
24 |
add_action( 'wp_ajax_nopriv_save_remote_images', array($this, 'save_remote_images') );
|
25 |
break;
|
31 |
add_filter( 'plugin_row_meta', array($this, 'registerPluginLinks'),10,2 );
|
32 |
}
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
public function media_buttons() {
|
35 |
global $post;
|
36 |
?>
|
56 |
-ms-transform: scale(1.1);
|
57 |
transform: scale(1.1);
|
58 |
}
|
|
|
|
|
|
|
|
|
59 |
</style>
|
60 |
<a href="javascript:" id="save-remote-images-button" class="button save_remote_images" title="<?php _e('Save Remote Images', 'qqworld_auto_save_images'); ?>"><span class="wp-media-buttons-icon"></span><?php _e('Save Remote Images', 'qqworld_auto_save_images'); ?></a>
|
61 |
<script>
|
70 |
$(window).on('load', function() {
|
71 |
$('.mce-i-save_remote_images').closest('.mce-widget').hide();
|
72 |
$(document).on('click', '#save-remote-images-button', function() {
|
73 |
+
var icon = '<span class="wp-media-buttons-icon"></span>',
|
74 |
+
mode = 'text';
|
75 |
+
if (tinyMCE.activeEditor) {
|
76 |
+
var id = tinyMCE.activeEditor.id;
|
77 |
+
mode = $('#'+id).is(':visible') ? 'text' : 'virtual';
|
78 |
+
}
|
79 |
+
switch (mode) {
|
80 |
+
case 'text':
|
81 |
+
$('.button.save_remote_images').html(icon+QQWorld_auto_save_images.text.in_process);
|
82 |
+
$.ajax({
|
83 |
+
type: "POST",
|
84 |
+
url: ajaxurl,
|
85 |
+
data: {
|
86 |
+
action: 'save_remote_images',
|
87 |
+
post_id: QQWorld_auto_save_images.post_id,
|
88 |
+
content: escape($('#content').val())
|
89 |
+
},
|
90 |
+
success: function(respond) {
|
91 |
+
$('.button.save_remote_images').addClass('success').html(icon+QQWorld_auto_save_images.text.succesed_save_remote_images);
|
92 |
+
var init = function() {
|
93 |
+
$('.button.save_remote_images').removeClass('success').html(icon+QQWorld_auto_save_images.text.save_remote_images);
|
94 |
+
}
|
95 |
+
$('#content').val(respond)
|
96 |
+
setTimeout(init, 3000);
|
97 |
+
}
|
98 |
+
});
|
99 |
+
break;
|
100 |
+
case 'virtual':
|
101 |
+
$('.button.save_remote_images').html(icon+QQWorld_auto_save_images.text.in_process);
|
102 |
+
$.ajax({
|
103 |
+
type: "POST",
|
104 |
+
url: ajaxurl,
|
105 |
+
data: {
|
106 |
+
action: 'save_remote_images',
|
107 |
+
post_id: QQWorld_auto_save_images.post_id,
|
108 |
+
content: escape(tinyMCE.activeEditor.getContent())
|
109 |
+
},
|
110 |
+
success: function(respond) {
|
111 |
+
$('.button.save_remote_images').addClass('success').html(icon+QQWorld_auto_save_images.text.succesed_save_remote_images);
|
112 |
+
var init = function() {
|
113 |
+
$('.button.save_remote_images').removeClass('success').html(icon+QQWorld_auto_save_images.text.save_remote_images);
|
114 |
+
}
|
115 |
+
tinyMCE.activeEditor.setContent(respond);
|
116 |
+
setTimeout(init, 3000);
|
117 |
+
}
|
118 |
+
});
|
119 |
+
break;
|
120 |
+
}
|
121 |
});
|
122 |
})
|
123 |
});
|
124 |
+
|
125 |
</script>
|
126 |
<?php
|
127 |
}
|
155 |
<th scope="row"><label for="blogname"><?php _e('Type'); ?></label></th>
|
156 |
<td><fieldset>
|
157 |
<legend class="screen-reader-text"><span><?php _e('Type'); ?></span></legend>
|
158 |
+
<label for="auto">
|
159 |
<input name="qqworld_auto_save_imagess_type" type="radio" id="auto" value="auto" <?php checked('auto', $this->type); ?> />
|
160 |
<?php _e('Automatically save all remote images to local media libary when you save or publish post.', 'qqworld_auto_save_images'); ?>
|
161 |
</label><br />
|
162 |
+
<label for="manual">
|
163 |
<input name="qqworld_auto_save_imagess_type" type="radio" id="manual" value="manual" <?php checked('manual', $this->type); ?> />
|
164 |
<?php _e('Manually save all remote images to local media libary when you click the button on the top of editor.', 'qqworld_auto_save_images'); ?>
|
165 |
</label>
|