Version Description
Download this release
Release Info
Developer | qqworld |
Plugin | QQWorld Auto Save Images |
Version | 1.4 |
Comparing to | |
See all releases |
Code changes from version 1.3 to 1.4
lang/qqworld_auto_save_images-zh_CN.mo
CHANGED
Binary file
|
lang/qqworld_auto_save_images-zh_CN.po
CHANGED
@@ -3,22 +3,41 @@ msgstr ""
|
|
3 |
"Project-Id-Version: QQworld Auto Save Images\n"
|
4 |
"Report-Msgid-Bugs-To: http://www.qqworld.org\n"
|
5 |
"POT-Creation-Date: 2011-12-10 19:47:15+00:00\n"
|
6 |
-
"PO-Revision-Date: 2014-
|
7 |
-
"Last-Translator: Michael
|
8 |
"Language-Team: QQWorld <admin@qqworld.org>\n"
|
9 |
"Language: zh_CN\n"
|
10 |
"MIME-Version: 1.0\n"
|
11 |
"Content-Type: text/plain; charset=UTF-8\n"
|
12 |
"Content-Transfer-Encoding: 8bit\n"
|
13 |
"Plural-Forms: nplurals=1; plural=0;\n"
|
14 |
-
"X-Generator: Poedit 1.6.
|
15 |
"X-Poedit-SourceCharset: UTF-8\n"
|
16 |
|
17 |
-
msgid "
|
18 |
-
msgstr "
|
|
|
|
|
|
|
19 |
|
20 |
msgid "Save post (Publish, save draft or pedding review)."
|
21 |
msgstr "保存文章时(发布文章,保存草稿和提交审核)。"
|
22 |
|
23 |
msgid "Publish post only."
|
24 |
msgstr "仅发布文章时。"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
"Project-Id-Version: QQworld Auto Save Images\n"
|
4 |
"Report-Msgid-Bugs-To: http://www.qqworld.org\n"
|
5 |
"POT-Creation-Date: 2011-12-10 19:47:15+00:00\n"
|
6 |
+
"PO-Revision-Date: 2014-09-09 15:24+0800\n"
|
7 |
+
"Last-Translator: Michael Wang <admin@qqworld.org>\n"
|
8 |
"Language-Team: QQWorld <admin@qqworld.org>\n"
|
9 |
"Language: zh_CN\n"
|
10 |
"MIME-Version: 1.0\n"
|
11 |
"Content-Type: text/plain; charset=UTF-8\n"
|
12 |
"Content-Transfer-Encoding: 8bit\n"
|
13 |
"Plural-Forms: nplurals=1; plural=0;\n"
|
14 |
+
"X-Generator: Poedit 1.6.9\n"
|
15 |
"X-Poedit-SourceCharset: UTF-8\n"
|
16 |
|
17 |
+
msgid "Save Remote Images"
|
18 |
+
msgstr "保存远程图片"
|
19 |
+
|
20 |
+
msgid "When"
|
21 |
+
msgstr "什么时候"
|
22 |
|
23 |
msgid "Save post (Publish, save draft or pedding review)."
|
24 |
msgstr "保存文章时(发布文章,保存草稿和提交审核)。"
|
25 |
|
26 |
msgid "Publish post only."
|
27 |
msgstr "仅发布文章时。"
|
28 |
+
|
29 |
+
msgid "In Process..."
|
30 |
+
msgstr "正在保存……"
|
31 |
+
|
32 |
+
msgid "Successed save remote images"
|
33 |
+
msgstr "成功保存远程图片"
|
34 |
+
|
35 |
+
msgid ""
|
36 |
+
"Automatically save all remote images to local media libary when you save or "
|
37 |
+
"publish post."
|
38 |
+
msgstr "在保存或发布文章时,自动将所有远程图像保存到本地媒体库。"
|
39 |
+
|
40 |
+
msgid ""
|
41 |
+
"Manually save all remote images to local media libary when you click the "
|
42 |
+
"button on the top of editor."
|
43 |
+
msgstr "当单击编辑器顶部的按钮时,手动将所有远程图像保存到本地媒体库。"
|
qqworld-auto-save-images.php
CHANGED
@@ -3,22 +3,185 @@
|
|
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.
|
7 |
Author: Michael Wang
|
8 |
Author URI: http://www.qqworld.org
|
9 |
*/
|
10 |
|
11 |
class QQWorld_auto_save_images {
|
12 |
var $using_action;
|
|
|
13 |
function __construct() {
|
14 |
$this->using_action = get_option('using_action', 'publish');
|
15 |
-
$this->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
add_action( 'plugins_loaded', array($this, 'load_language') );
|
17 |
add_action( 'admin_menu', array($this, 'admin_menu') );
|
18 |
add_action( 'admin_init', array($this, 'register_settings') );
|
19 |
add_filter( 'plugin_row_meta', array($this, 'registerPluginLinks'),10,2 );
|
20 |
}
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
public function load_language() {
|
23 |
load_plugin_textdomain( 'qqworld_auto_save_images', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
|
24 |
}
|
@@ -45,9 +208,24 @@ class QQWorld_auto_save_images {
|
|
45 |
<table class="form-table">
|
46 |
<tbody>
|
47 |
<tr valign="top">
|
48 |
-
<th scope="row"><label for="blogname"><?php _e('
|
49 |
<td><fieldset>
|
50 |
-
<legend class="screen-reader-text"><span><?php _e('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
<label for="save">
|
52 |
<input name="using_action" type="radio" id="save" value="save" <?php checked('save', $this->using_action); ?> />
|
53 |
<?php _e('Save post (Publish, save draft or pedding review).', 'qqworld_auto_save_images'); ?>
|
@@ -60,36 +238,103 @@ class QQWorld_auto_save_images {
|
|
60 |
</tr>
|
61 |
</tbody>
|
62 |
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
<p class="submit"><input type="submit" value="<?php _e('Save Changes') ?>" class="button-primary" name="Submit" /></p>
|
64 |
</form>
|
65 |
<?php
|
66 |
}
|
67 |
|
68 |
function register_settings() {
|
|
|
69 |
register_setting('qqworld_auto_save_images_settings', 'using_action');
|
70 |
}
|
71 |
|
72 |
function add_actions() {
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
}
|
76 |
|
77 |
function remove_actions() {
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
}
|
81 |
|
82 |
-
function fetch_images($
|
83 |
//Check to make sure function is not executed more than once on save
|
84 |
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
|
85 |
return;
|
86 |
|
87 |
-
if ( !current_user_can('edit_post', $
|
88 |
return;
|
89 |
|
90 |
$this->remove_actions();
|
91 |
|
92 |
-
$post=get_post($
|
93 |
$content=$post->post_content;
|
94 |
$preg=preg_match_all('/<img.*?src="(.*?)(\?.*?)?"/',stripslashes($content),$matches);
|
95 |
if($preg){
|
@@ -105,7 +350,7 @@ class QQWorld_auto_save_images {
|
|
105 |
}
|
106 |
}
|
107 |
//Replace the image in the post
|
108 |
-
wp_update_post(array('ID' => $
|
109 |
$this->add_actions();
|
110 |
}
|
111 |
|
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 |
*/
|
10 |
|
11 |
class QQWorld_auto_save_images {
|
12 |
var $using_action;
|
13 |
+
var $type;
|
14 |
function __construct() {
|
15 |
$this->using_action = get_option('using_action', 'publish');
|
16 |
+
$this->type = get_option('qqworld_auto_save_imagess_type', 'auto');
|
17 |
+
switch ($this->type) {
|
18 |
+
case 'auto':
|
19 |
+
$this->add_actions();
|
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;
|
30 |
+
}
|
31 |
+
|
32 |
add_action( 'plugins_loaded', array($this, 'load_language') );
|
33 |
add_action( 'admin_menu', array($this, 'admin_menu') );
|
34 |
add_action( 'admin_init', array($this, 'register_settings') );
|
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 |
+
?>
|
136 |
+
<style>
|
137 |
+
.button.save_remote_images span.wp-media-buttons-icon:before {
|
138 |
+
font: 400 18px/1 dashicons;
|
139 |
+
speak: none;
|
140 |
+
-webkit-font-smoothing: antialiased;
|
141 |
+
-moz-osx-font-smoothing: grayscale;
|
142 |
+
content: '\f161';
|
143 |
+
}
|
144 |
+
#save-remote-images-button {
|
145 |
+
-webkit-transition: all .25s;
|
146 |
+
-moz-transition: all .25s;
|
147 |
+
-o-transition: all .25s;
|
148 |
+
-ms-transition: all .25s;
|
149 |
+
transition: all .25s;
|
150 |
+
}
|
151 |
+
#save-remote-images-button.success {
|
152 |
+
-webkit-transform: scale(1.1);
|
153 |
+
-moz-transform: scale(1.1);
|
154 |
+
-o-transform: scale(1.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>
|
165 |
+
var QQWorld_auto_save_images = {};
|
166 |
+
QQWorld_auto_save_images.post_id = <?php echo $post->ID; ?>;
|
167 |
+
QQWorld_auto_save_images.text = {
|
168 |
+
save_remote_images: '<?php _e('Save Remote Images', 'qqworld_auto_save_images'); ?>',
|
169 |
+
in_process: '<?php _e('In Process...', 'qqworld_auto_save_images'); ?>',
|
170 |
+
succesed_save_remote_images: '<?php _e('Successed save remote images', 'qqworld_auto_save_images'); ?>'
|
171 |
+
}
|
172 |
+
jQuery(function($) {
|
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 |
+
$('#qt_content_qqworld_auto_save_images').click();
|
177 |
+
$('.mce-i-save_remote_images').click();
|
178 |
+
});
|
179 |
+
})
|
180 |
+
});
|
181 |
+
</script>
|
182 |
+
<?php
|
183 |
+
}
|
184 |
+
|
185 |
public function load_language() {
|
186 |
load_plugin_textdomain( 'qqworld_auto_save_images', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
|
187 |
}
|
208 |
<table class="form-table">
|
209 |
<tbody>
|
210 |
<tr valign="top">
|
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="save">
|
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="publish">
|
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>
|
222 |
+
</fieldset></td>
|
223 |
+
</tr>
|
224 |
+
|
225 |
+
<tr id="second_level" valign="top"<?php if ($this->type != 'auto') echo ' style="display: none;"'; ?>>
|
226 |
+
<th scope="row"><label for="blogname"><?php _e('When', 'qqworld_auto_save_images'); ?></label></th>
|
227 |
+
<td><fieldset>
|
228 |
+
<legend class="screen-reader-text"><span><?php _e('When', 'qqworld_auto_save_images'); ?></span></legend>
|
229 |
<label for="save">
|
230 |
<input name="using_action" type="radio" id="save" value="save" <?php checked('save', $this->using_action); ?> />
|
231 |
<?php _e('Save post (Publish, save draft or pedding review).', 'qqworld_auto_save_images'); ?>
|
238 |
</tr>
|
239 |
</tbody>
|
240 |
</table>
|
241 |
+
<script>
|
242 |
+
jQuery('#auto').on('click', function() {
|
243 |
+
jQuery('#second_level').fadeIn('fast');
|
244 |
+
});
|
245 |
+
jQuery('#manual').on('click', function() {
|
246 |
+
jQuery('#second_level').fadeOut('fast');
|
247 |
+
});
|
248 |
+
</script>
|
249 |
<p class="submit"><input type="submit" value="<?php _e('Save Changes') ?>" class="button-primary" name="Submit" /></p>
|
250 |
</form>
|
251 |
<?php
|
252 |
}
|
253 |
|
254 |
function register_settings() {
|
255 |
+
register_setting('qqworld_auto_save_images_settings', 'qqworld_auto_save_imagess_type');
|
256 |
register_setting('qqworld_auto_save_images_settings', 'using_action');
|
257 |
}
|
258 |
|
259 |
function add_actions() {
|
260 |
+
switch ($this->using_action) {
|
261 |
+
case 'publish':
|
262 |
+
add_action('publish_post', array($this, 'fetch_images') );
|
263 |
+
break;
|
264 |
+
case 'save':
|
265 |
+
add_action('save_post', array($this, 'fetch_images') );
|
266 |
+
break;
|
267 |
+
}
|
268 |
}
|
269 |
|
270 |
function remove_actions() {
|
271 |
+
switch ($this->using_action) {
|
272 |
+
case 'publish':
|
273 |
+
remove_action('publish_post', array($this, 'fetch_images') );
|
274 |
+
break;
|
275 |
+
case 'save':
|
276 |
+
remove_action('save_post', array($this, 'fetch_images') );
|
277 |
+
break;
|
278 |
+
}
|
279 |
+
}
|
280 |
+
|
281 |
+
function js_unescape($str) { // ucseacape escape content via js
|
282 |
+
$ret = '';
|
283 |
+
$len = strlen($str);
|
284 |
+
for ($i = 0; $i < $len; $i++) {
|
285 |
+
if ($str[$i] == '%' && $str[$i+1] == 'u') {
|
286 |
+
$val = hexdec(substr($str, $i+2, 4));
|
287 |
+
if ($val < 0x7f) $ret .= chr($val);
|
288 |
+
else if($val < 0x800) $ret .= chr(0xc0|($val>>6)).chr(0x80|($val&0x3f));
|
289 |
+
else $ret .= chr(0xe0|($val>>12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f));
|
290 |
+
$i += 5;
|
291 |
+
} else if ($str[$i] == '%') {
|
292 |
+
$ret .= urldecode(substr($str, $i, 3));
|
293 |
+
$i += 2;
|
294 |
+
} else $ret .= $str[$i];
|
295 |
+
}
|
296 |
+
return $ret;
|
297 |
+
}
|
298 |
+
|
299 |
+
function save_remote_images() {
|
300 |
+
//Check to make sure function is not executed more than once on save
|
301 |
+
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
|
302 |
+
return;
|
303 |
+
|
304 |
+
if ( !current_user_can('edit_post', $post_id) )
|
305 |
+
return;
|
306 |
+
|
307 |
+
$post_id = $_POST['post_id'];
|
308 |
+
$content = $this->js_unescape($_POST['content']);
|
309 |
+
|
310 |
+
$preg=preg_match_all('/<img.*?src="(.*?)(\?.*?)?"/',stripslashes($content),$matches);
|
311 |
+
if($preg){
|
312 |
+
foreach($matches[1] as $image_url){
|
313 |
+
if(empty($image_url)) continue;
|
314 |
+
$pos=strpos($image_url,get_bloginfo('url'));
|
315 |
+
if($pos===false){
|
316 |
+
if ($res=$this->save_images($image_url,$post_id)) {
|
317 |
+
$replace=$res['url'];
|
318 |
+
$content=str_replace($image_url,$replace,$content);
|
319 |
+
}
|
320 |
+
}
|
321 |
+
}
|
322 |
+
}
|
323 |
+
echo $content;
|
324 |
+
exit;
|
325 |
}
|
326 |
|
327 |
+
function fetch_images($post_id) {
|
328 |
//Check to make sure function is not executed more than once on save
|
329 |
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
|
330 |
return;
|
331 |
|
332 |
+
if ( !current_user_can('edit_post', $post_id) )
|
333 |
return;
|
334 |
|
335 |
$this->remove_actions();
|
336 |
|
337 |
+
$post=get_post($post_id);
|
338 |
$content=$post->post_content;
|
339 |
$preg=preg_match_all('/<img.*?src="(.*?)(\?.*?)?"/',stripslashes($content),$matches);
|
340 |
if($preg){
|
350 |
}
|
351 |
}
|
352 |
//Replace the image in the post
|
353 |
+
wp_update_post(array('ID' => $post_id, 'post_content' => $content));
|
354 |
$this->add_actions();
|
355 |
}
|
356 |
|