QQWorld Auto Save Images - Version 1.5.4

Version Description

Download this release

Release Info

Developer qqworld
Plugin Icon 128x128 QQWorld Auto Save Images
Version 1.5.4
Comparing to
See all releases

Code changes from version 1.5.3 to 1.5.4

lang/qqworld_auto_save_images-zh_CN.mo CHANGED
Binary file
lang/qqworld_auto_save_images-zh_CN.po CHANGED
@@ -3,7 +3,7 @@ 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-29 22:36+0800\n"
7
  "Last-Translator: Michael Wang <admin@qqworld.org>\n"
8
  "Language-Team: QQWorld <admin@qqworld.org>\n"
9
  "Language: zh_CN\n"
@@ -76,19 +76,18 @@ msgstr "全部完成。"
76
  msgid "Post Type"
77
  msgstr "文章类型"
78
 
79
- msgid "Return"
80
- msgstr "返回"
81
-
82
  msgid "Please select the post type you want to scan."
83
  msgstr "请选择要扫描的文章类型。"
84
 
85
  msgid "Filter:"
86
- msgstr "过滤器:"
87
 
88
  msgid "Start from %s Scan"
89
  msgstr "从 %s 开始扫描"
90
 
91
  msgid ""
92
- "If you want to scan 50-150 posts, please type 50 in the textfield and choose "
93
- "100 in the select."
94
- msgstr "如果想扫描50-100篇文章,请在文本框中输入50并在下拉菜单中选择100"
 
 
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-30 11:43+0800\n"
7
  "Last-Translator: Michael Wang <admin@qqworld.org>\n"
8
  "Language-Team: QQWorld <admin@qqworld.org>\n"
9
  "Language: zh_CN\n"
76
  msgid "Post Type"
77
  msgstr "文章类型"
78
 
 
 
 
79
  msgid "Please select the post type you want to scan."
80
  msgstr "请选择要扫描的文章类型。"
81
 
82
  msgid "Filter:"
83
+ msgstr "筛选:"
84
 
85
  msgid "Start from %s Scan"
86
  msgstr "从 %s 开始扫描"
87
 
88
  msgid ""
89
+ "If you want to scan 50-150 posts, please type \"50\" in the textfield and "
90
+ "choose \"100\" in the select, and do not choose \"all\"."
91
+ msgstr ""
92
+ "如果想扫描50-150篇文章,请在文本框中输入“50”并在下拉菜单中选择“100”,不能"
93
+ "选“全部”。"
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.5.3
7
  Author: Michael Wang
8
  Author URI: http://www.qqworld.org
9
  */
@@ -27,6 +27,11 @@ class QQWorld_auto_save_images {
27
  add_action( 'wp_ajax_nopriv_save_remote_images', array($this, 'save_remote_images') );
28
  break;
29
  }
 
 
 
 
 
30
 
31
  add_action( 'plugins_loaded', array($this, 'load_language') );
32
  add_action( 'admin_menu', array($this, 'admin_menu') );
@@ -34,6 +39,54 @@ class QQWorld_auto_save_images {
34
  add_filter( 'plugin_row_meta', array($this, 'registerPluginLinks'),10,2 );
35
  }
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  public function media_buttons() {
38
  global $post;
39
  ?>
@@ -167,7 +220,6 @@ class QQWorld_auto_save_images {
167
  <?php if ($_GET['updated']=='true') { ?><div class="updated settings-error" id="setting-error-settings_updated"><p><strong><?php _e('Settings saved.'); ?></strong></p></div><?php }; ?>
168
  <script src="<?php echo QQWORLD_AUTO_SAVE_IMAGES_URL; ?>js/jquery.noty.packaged.min.js"></script>
169
  <link rel='stylesheet' href='<?php echo QQWORLD_AUTO_SAVE_IMAGES_URL; ?>css/style.css' type='text/css' media='all' />
170
- <?php if (empty($_POST)) : ?>
171
  <form action="options.php" method="post" id="form">
172
  <?php settings_fields('qqworld_auto_save_images_settings'); ?>
173
  <img src="https://ps.w.org/qqworld-auto-save-images/assets/banner-772x250.png" width="772" height="250" id="banner" />
@@ -221,15 +273,14 @@ class QQWorld_auto_save_images {
221
  <tr valign="top">
222
  <th scope="row"><label><?php _e('Scan Old Posts', 'qqworld_auto_save_images'); ?></label></th>
223
  <td>
224
- <p><?php _e('Select post types you want to scan:', 'qqworld_auto_save_images'); ?></p>
225
  <div id="post_types_list">
226
- <p><?php
227
  $post_types = get_post_types('', 'objects');
228
  foreach ($post_types as $name => $post_type) : ?>
229
  <label><input name="qqworld_auto_save_imagess_post_types[]" type="checkbox" value="<?php echo $name; ?>" /> <?php echo $post_type->labels->name; ?></label>
230
  <?php endforeach;
231
  ?></p>
232
- <p><?php _e('Filter:', 'qqworld_auto_save_images'); ?> <?php printf(__('Start from %s Scan', 'qqworld_auto_save_images'), '<input type="number" name="offset" value="0" />'); ?>
233
  <select name="posts_per_page">
234
  <option value="-1"><?php _e('All'); ?></option>
235
  <?php for ($i=1; $i<=10; $i++) : ?>
@@ -237,24 +288,58 @@ class QQWorld_auto_save_images {
237
  <?php endfor; ?>
238
  </select> <?php _e('Posts'); ?>
239
  </p>
240
- <p class="description"><?php _e('If you want to scan 50-150 posts, please type 50 in the textfield and choose 100 in the select.', 'qqworld_auto_save_images'); ?></p>
241
  </div>
242
 
243
  <fieldset>
244
  <legend class="screen-reader-text"><span><?php _e('Scan Old Posts', 'qqworld_auto_save_images'); ?></span></legend>
245
  <label for="scan_old_posts">
246
- <input name="scan_old_posts" type="submit" class="button-primary" id="scan_old_posts" value="<?php _e('Scan', 'qqworld_auto_save_images'); ?>" />
247
  </label>
248
  <p class="description"><?php _e('Scan posts and keep remote images in all posts to local media library. Maybe take a long time.', 'qqworld_auto_save_images'); ?></p>
249
- </fieldset></td>
 
250
  </tr>
251
  </tbody>
252
  </table>
253
  <script>
254
  if (!QQWorld_auto_save_images) var QQWorld_auto_save_images = {};
255
  QQWorld_auto_save_images.are_your_sure = '<?php _e('Are you sure? Before you click the yes button, I recommend you backup the website database.', 'qqworld_auto_save_images'); ?>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  QQWorld_auto_save_images.events = function() {
257
  var $ = jQuery;
 
 
 
 
258
  $('#auto').on('click', function() {
259
  $('#second_level').fadeIn('fast');
260
  });
@@ -275,7 +360,33 @@ class QQWorld_auto_save_images {
275
  text: '<?php _e('Yes'); ?>',
276
  onClick: function ($noty) {
277
  $noty.close();
278
- $('#form').attr('action', '').submit();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  }
280
  },
281
  {
@@ -296,82 +407,13 @@ class QQWorld_auto_save_images {
296
  timeout: 3000
297
  });
298
  }
299
- return false;
300
  });
301
  };
302
  QQWorld_auto_save_images.events();
303
  </script>
304
  <p class="submit"><input type="submit" value="<?php _e('Save Changes') ?>" class="button-primary" name="Submit" /></p>
305
  </form>
306
- <?php elseif ( isset($_POST['qqworld_auto_save_imagess_post_types']) ): ?>
307
- <script>
308
- var n = noty({
309
- text: '<?php _e('Scanning...', 'qqworld_auto_save_images'); ?>',
310
- type: 'notification',
311
- layout: 'topCenter'
312
- });
313
- </script>
314
- <?php
315
- set_time_limit(0);
316
- $post_types = $_POST['qqworld_auto_save_imagess_post_types'];
317
- $offset = empty($_POST['offset']) ? 0 : $_POST['offset'];
318
- $posts_per_page = $_POST['posts_per_page'];
319
- $args = array(
320
- 'posts_per_page' => $posts_per_page,
321
- 'offset' => $offset,
322
- 'order' => 'ASC',
323
- 'post_type' => $post_types
324
- );
325
- $posts = get_posts($args);
326
- if (!empty($posts)) : ?>
327
- <p><?php _e('Scan posts and keep remote images in all posts to local media library. Maybe take a long time.', 'qqworld_auto_save_images'); ?></p>
328
- <table id="scan_old_post_list">
329
- <thead>
330
- <th><?php _e('ID'); ?></th>
331
- <th><?php _e('Post Type', 'qqworld_auto_save_images'); ?></th>
332
- <th><?php _e('Title'); ?></th>
333
- <th><?php _e('Status'); ?></th>
334
- </thead>
335
- <tbody>
336
- <?php foreach ($posts as $post) :
337
- $post_id = $post->ID;
338
- $post_type = $post->post_type;
339
- $content = $post->post_content;
340
- $title = $post->post_title;
341
- $preg=preg_match_all('/<img.*?src="((?![\"\']).*?)((?![\"\'])\?.*?)?"/',stripslashes($content),$matches);
342
- if($preg){
343
- foreach($matches[1] as $image_url){
344
- if(empty($image_url)) continue;
345
- $pos=strpos($image_url,get_bloginfo('url'));
346
- if($pos===false){
347
- if ($res=$this->save_images($image_url,$post_id)) {
348
- $replace=$res['url'];
349
- $content=str_replace($image_url,$replace,$content);
350
- }
351
- }
352
- }
353
- }
354
- wp_update_post(array('ID' => $post_id, 'post_content' => $content)); ?>
355
- <tr>
356
- <td><?php echo $post_id; ?></td>
357
- <td><?php echo $post_type; ?></td>
358
- <td><a href="<?php echo get_edit_post_link($post_id); ?>" target="_blank"><?php echo $title; ?></a></td>
359
- <td><?php _e('Done'); ?></td></tr>
360
- <?php endforeach; ?>
361
- </tbody>
362
- </table>
363
- <script>
364
- n.close();
365
- noty({
366
- text: '<?php _e('All done.', 'qqworld_auto_save_images'); ?>',
367
- type: 'success',
368
- layout: 'topCenter',
369
- timeout: 3000
370
- });
371
- </script>
372
- <?php endif; ?>
373
- <p><a href="<?php echo menu_page_url( 'qqworld-auto-save-images', 0 ); ?>" class="button button-primary"><?php _e('Return', 'qqworld_auto_save_images') ?></a></p>
374
- <?php endif; ?>
375
  <?php
376
  }
377
 
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.5.4
7
  Author: Michael Wang
8
  Author URI: http://www.qqworld.org
9
  */
27
  add_action( 'wp_ajax_nopriv_save_remote_images', array($this, 'save_remote_images') );
28
  break;
29
  }
30
+
31
+ add_action( 'wp_ajax_get_scan_list', array($this, 'get_scan_list') );
32
+ add_action( 'wp_ajax_nopriv_get_scan_list', array($this, 'get_scan_list') );
33
+ add_action( 'wp_ajax_save_remote_images_after_scan', array($this, 'save_remote_images_after_scan') );
34
+ add_action( 'wp_ajax_nopriv_save_remote_images_after_scan', array($this, 'save_remote_images_after_scan') );
35
 
36
  add_action( 'plugins_loaded', array($this, 'load_language') );
37
  add_action( 'admin_menu', array($this, 'admin_menu') );
39
  add_filter( 'plugin_row_meta', array($this, 'registerPluginLinks'),10,2 );
40
  }
41
 
42
+ public function get_scan_list() {
43
+ if ( !current_user_can( 'manage_options' ) ) return;
44
+ $post_types = isset($_REQUEST['qqworld_auto_save_imagess_post_types']) ? $_REQUEST['qqworld_auto_save_imagess_post_types'] : 'post';
45
+ $offset = empty($_REQUEST['offset']) ? 0 : $_POST['offset'];
46
+ $posts_per_page = $_REQUEST['posts_per_page'];
47
+ $args = array(
48
+ 'posts_per_page' => $posts_per_page,
49
+ 'offset' => $offset,
50
+ 'order' => 'ASC',
51
+ 'post_type' => $post_types
52
+ );
53
+ $posts = get_posts($args);
54
+ echo json_encode($posts);
55
+ exit;
56
+ }
57
+
58
+ public function save_remote_images_after_scan() {
59
+ if ( !current_user_can( 'manage_options' ) ) return;
60
+ $post_id = $_POST['post_id'];
61
+ $post = get_post($post_id);
62
+ $post_id = $post->ID;
63
+ $post_type = $post->post_type;
64
+ $content = $post->post_content;
65
+ $title = $post->post_title;
66
+ $preg=preg_match_all('/<img.*?src="((?![\"\']).*?)((?![\"\'])\?.*?)?"/',stripslashes($content),$matches);
67
+ if($preg){
68
+ foreach($matches[1] as $image_url){
69
+ if(empty($image_url)) continue;
70
+ $pos=strpos($image_url,get_bloginfo('url'));
71
+ if($pos===false){
72
+ if ($res=$this->save_images($image_url,$post_id)) {
73
+ $replace=$res['url'];
74
+ $content=str_replace($image_url,$replace,$content);
75
+ }
76
+ }
77
+ }
78
+ }
79
+ wp_update_post(array('ID' => $post_id, 'post_content' => $content)); ?>
80
+ <tr>
81
+ <td><?php echo $post_id; ?></td>
82
+ <td><?php echo $post_type; ?></td>
83
+ <td><a href="<?php echo get_edit_post_link($post_id); ?>" target="_blank"><?php echo $title; ?></a></td>
84
+ <td><?php _e('Done'); ?></td>
85
+ </tr>
86
+ <?php
87
+ exit;
88
+ }
89
+
90
  public function media_buttons() {
91
  global $post;
92
  ?>
220
  <?php if ($_GET['updated']=='true') { ?><div class="updated settings-error" id="setting-error-settings_updated"><p><strong><?php _e('Settings saved.'); ?></strong></p></div><?php }; ?>
221
  <script src="<?php echo QQWORLD_AUTO_SAVE_IMAGES_URL; ?>js/jquery.noty.packaged.min.js"></script>
222
  <link rel='stylesheet' href='<?php echo QQWORLD_AUTO_SAVE_IMAGES_URL; ?>css/style.css' type='text/css' media='all' />
 
223
  <form action="options.php" method="post" id="form">
224
  <?php settings_fields('qqworld_auto_save_images_settings'); ?>
225
  <img src="https://ps.w.org/qqworld-auto-save-images/assets/banner-772x250.png" width="772" height="250" id="banner" />
273
  <tr valign="top">
274
  <th scope="row"><label><?php _e('Scan Old Posts', 'qqworld_auto_save_images'); ?></label></th>
275
  <td>
 
276
  <div id="post_types_list">
277
+ <p><?php _e('Select post types you want to scan:', 'qqworld_auto_save_images'); ?> <?php
278
  $post_types = get_post_types('', 'objects');
279
  foreach ($post_types as $name => $post_type) : ?>
280
  <label><input name="qqworld_auto_save_imagess_post_types[]" type="checkbox" value="<?php echo $name; ?>" /> <?php echo $post_type->labels->name; ?></label>
281
  <?php endforeach;
282
  ?></p>
283
+ <p><?php _e('Filter:', 'qqworld_auto_save_images'); ?> <?php printf(__('Start from %s Scan', 'qqworld_auto_save_images'), '<input type="number" name="offset" value="0" disabled />'); ?>
284
  <select name="posts_per_page">
285
  <option value="-1"><?php _e('All'); ?></option>
286
  <?php for ($i=1; $i<=10; $i++) : ?>
288
  <?php endfor; ?>
289
  </select> <?php _e('Posts'); ?>
290
  </p>
291
+ <p class="description"><?php _e("If you want to scan 50-150 posts, please type \"50\" in the textfield and choose \"100\" in the select, and do not choose \"all\".", 'qqworld_auto_save_images'); ?></p>
292
  </div>
293
 
294
  <fieldset>
295
  <legend class="screen-reader-text"><span><?php _e('Scan Old Posts', 'qqworld_auto_save_images'); ?></span></legend>
296
  <label for="scan_old_posts">
297
+ <input name="scan_old_posts" type="button" class="button-primary" id="scan_old_posts" value="<?php _e('Scan', 'qqworld_auto_save_images'); ?>" />
298
  </label>
299
  <p class="description"><?php _e('Scan posts and keep remote images in all posts to local media library. Maybe take a long time.', 'qqworld_auto_save_images'); ?></p>
300
+ </fieldset>
301
+ </td>
302
  </tr>
303
  </tbody>
304
  </table>
305
  <script>
306
  if (!QQWorld_auto_save_images) var QQWorld_auto_save_images = {};
307
  QQWorld_auto_save_images.are_your_sure = '<?php _e('Are you sure? Before you click the yes button, I recommend you backup the website database.', 'qqworld_auto_save_images'); ?>';
308
+ QQWorld_auto_save_images.scan = function(respond, r) {
309
+ var $ = jQuery;
310
+ if (typeof respond[r] == 'undefined') {
311
+ $('body').data('noty').close();
312
+ noty({
313
+ text: '<?php _e('All done.', 'qqworld_auto_save_images'); ?>',
314
+ type: 'success',
315
+ layout: 'bottomCenter',
316
+ dismissQueue: true,
317
+ timeout: 3000
318
+ });
319
+ $('#scan_old_posts').removeAttr('disabled');
320
+ return;
321
+ }
322
+ var data = {
323
+ action: 'save_remote_images_after_scan',
324
+ post_id: respond[r]['ID']
325
+ };
326
+ $.ajax({
327
+ type: 'POST',
328
+ url: ajaxurl,
329
+ data: data,
330
+ success: function(data) {
331
+ $('#scan_old_post_list tbody').append(data);
332
+ r++;
333
+ QQWorld_auto_save_images.scan(respond, r);
334
+ }
335
+ });
336
+ };
337
  QQWorld_auto_save_images.events = function() {
338
  var $ = jQuery;
339
+ $('select[name="posts_per_page"]').on('change', function() {
340
+ if ($(this).val() == '-1') $('input[name="offset"]').attr('disabled', true);
341
+ else $('input[name="offset"]').removeAttr('disabled', true);
342
+ });
343
  $('#auto').on('click', function() {
344
  $('#second_level').fadeIn('fast');
345
  });
360
  text: '<?php _e('Yes'); ?>',
361
  onClick: function ($noty) {
362
  $noty.close();
363
+ $('#scan_old_posts').attr('disabled', true);
364
+ var data = $('#form').serialize()+'&action=get_scan_list';
365
+ $.ajax({
366
+ type: 'POST',
367
+ url: ajaxurl,
368
+ data: data,
369
+ dataType: 'json',
370
+ success: function(respond) {
371
+ $('#scan-result').html('<table id="scan_old_post_list">\
372
+ \ <thead>\
373
+ \ <th><?php _e('ID'); ?></th>\
374
+ \ <th><?php _e('Post Type', 'qqworld_auto_save_images'); ?></th>\
375
+ \ <th><?php _e('Title'); ?></th>\
376
+ \ <th><?php _e('Status'); ?></th>\
377
+ \ </thead>\
378
+ \ <tbody>\
379
+ \ </tbody>\
380
+ \</table>');
381
+ $('body').data('noty', noty({
382
+ text: '<?php _e('Scanning...', 'qqworld_auto_save_images'); ?>',
383
+ type: 'notification',
384
+ layout: 'bottomCenter',
385
+ dismissQueue: true
386
+ }) );
387
+ QQWorld_auto_save_images.scan(respond, 0);
388
+ }
389
+ });
390
  }
391
  },
392
  {
407
  timeout: 3000
408
  });
409
  }
 
410
  });
411
  };
412
  QQWorld_auto_save_images.events();
413
  </script>
414
  <p class="submit"><input type="submit" value="<?php _e('Save Changes') ?>" class="button-primary" name="Submit" /></p>
415
  </form>
416
+ <div id="scan-result"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
  <?php
418
  }
419