QQWorld Auto Save Images - Version 1.7.6

Version Description

Download this release

Release Info

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

Code changes from version 1.7.5 to 1.7.6

Files changed (2) hide show
  1. js/manual.js +9 -0
  2. qqworld-auto-save-images.php +8 -7
js/manual.js CHANGED
@@ -15,6 +15,14 @@ jQuery(function($) {
15
  console.log(XMLHttpRequest);
16
  console.log('textStatus: ' + textStatus);
17
  console.log('errorThrown: ' + errorThrown);
 
 
 
 
 
 
 
 
18
  };
19
  switch (mode) {
20
  case 'text':
@@ -81,6 +89,7 @@ jQuery(function($) {
81
  content: encodeURI(encodeURI(tinyMCE.activeEditor.getContent()))
82
  },
83
  success: function(respond) {
 
84
  switch (respond.type) {
85
  case 1: var type = 'warning'; break;
86
  case 2: var type = 'success'; break;
15
  console.log(XMLHttpRequest);
16
  console.log('textStatus: ' + textStatus);
17
  console.log('errorThrown: ' + errorThrown);
18
+ $('#save-remote-images-button').data('noty').close();
19
+ noty({
20
+ text: QASI.error,
21
+ type: 'error',
22
+ layout: 'center',
23
+ modal: true,
24
+ theme: noty_theme
25
+ });
26
  };
27
  switch (mode) {
28
  case 'text':
89
  content: encodeURI(encodeURI(tinyMCE.activeEditor.getContent()))
90
  },
91
  success: function(respond) {
92
+ console.log(respond)
93
  switch (respond.type) {
94
  case 1: var type = 'warning'; break;
95
  case 2: var type = 'success'; break;
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.7.5
7
  Author: Michael Wang
8
  Author URI: http://www.qqworld.org
9
  Text Domain: qqworld_auto_save_images
@@ -127,7 +127,8 @@ class QQWorld_auto_save_images {
127
  wp_enqueue_script('qqworld-auto-save-images-script-post');
128
  $translation_array = array(
129
  'post_id' => $post->ID,
130
- 'in_process' => __('In Process...', 'qqworld_auto_save_images')
 
131
  );
132
  wp_localize_script('qqworld-auto-save-images-script-post', 'QASI', $translation_array, '3.0.0');
133
  }
@@ -875,7 +876,7 @@ class QQWorld_auto_save_images {
875
  }
876
 
877
  public function content_save_pre($content, $post_id=null, $action='save') {
878
- $preg = preg_match_all('/<img.*?src=[\"\']((?![\"\']).*?)[\"\']/i', stripslashes($content), $matches);
879
  if($preg){
880
  foreach($matches[1] as $image_url) {
881
  if(empty($image_url)) continue;
@@ -927,11 +928,11 @@ class QQWorld_auto_save_images {
927
  $height = $res['sizes'][$size]['height'];
928
  }
929
  $pattern_image_url = $this->encode_pattern($image_url);
930
- $pattern = '/<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>?<img.*?src=[\"|\\\']'.$pattern_image_url.'[\"|\\\'].*?>?<\/a>/i';
931
  if ( preg_match($pattern, $content, $matches) ) {
932
  $args = $this->set_img_metadata($matches[0], $attachment_id);
933
  } else {
934
- $pattern = '/<img.*?src=[\"|\\\']'.$pattern_image_url.'[\"|\\\'].*?>/i';
935
  if ( preg_match($pattern, $content, $matches) ) {
936
  $args = $this->set_img_metadata($matches[0], $attachment_id);
937
  } else {
@@ -957,10 +958,10 @@ class QQWorld_auto_save_images {
957
  }
958
 
959
  public function set_img_metadata($img, $attachment_id) {
960
- $pattern = '/<img.*?alt=[\"|\\\'](.*?)[\"|\\\'].*?>/i';
961
  $alt = preg_match($pattern, $img, $matches) ? $matches[1] : null;
962
  if ($alt) update_post_meta($attachment_id, '_wp_attachment_image_alt', $alt);
963
- $pattern = '/<img.*?title=[\"|\\\'](.*?)[\"|\\\'].*?>/i';
964
  $title = preg_match($pattern, $img, $matches)? $matches[1] : null;
965
  if ($title) {
966
  $attachment = array(
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.6
7
  Author: Michael Wang
8
  Author URI: http://www.qqworld.org
9
  Text Domain: qqworld_auto_save_images
127
  wp_enqueue_script('qqworld-auto-save-images-script-post');
128
  $translation_array = array(
129
  'post_id' => $post->ID,
130
+ 'in_process' => __('In Process...', 'qqworld_auto_save_images'),
131
+ 'error' => __('Something error, please check.', 'qqworld_auto_save_images')
132
  );
133
  wp_localize_script('qqworld-auto-save-images-script-post', 'QASI', $translation_array, '3.0.0');
134
  }
876
  }
877
 
878
  public function content_save_pre($content, $post_id=null, $action='save') {
879
+ $preg = preg_match_all('/<img\s[^>]*src=[\"|\']((?![\"|\'])[\s\S]*?)[\"|\'][\s\S]*?>/i', stripslashes($content), $matches);
880
  if($preg){
881
  foreach($matches[1] as $image_url) {
882
  if(empty($image_url)) continue;
928
  $height = $res['sizes'][$size]['height'];
929
  }
930
  $pattern_image_url = $this->encode_pattern($image_url);
931
+ $pattern = '/<a[^<]+><img\s[^>]*'.$pattern_image_url.'.*?>?<[^>]+a>/i';
932
  if ( preg_match($pattern, $content, $matches) ) {
933
  $args = $this->set_img_metadata($matches[0], $attachment_id);
934
  } else {
935
+ $pattern = '/<img\s[^>]*'.$pattern_image_url.'.*?>/i';
936
  if ( preg_match($pattern, $content, $matches) ) {
937
  $args = $this->set_img_metadata($matches[0], $attachment_id);
938
  } else {
958
  }
959
 
960
  public function set_img_metadata($img, $attachment_id) {
961
+ $pattern = '/<img\s[^>]*alt=[\"|\\\'](.*?)[\"|\\\'].*?>/i';
962
  $alt = preg_match($pattern, $img, $matches) ? $matches[1] : null;
963
  if ($alt) update_post_meta($attachment_id, '_wp_attachment_image_alt', $alt);
964
+ $pattern = '/<img\s[^>]*title=[\"|\\\'](.*?)[\"|\\\'].*?>/i';
965
  $title = preg_match($pattern, $img, $matches)? $matches[1] : null;
966
  if ($title) {
967
  $attachment = array(