QQWorld Auto Save Images - Version 1.7.15

Version Description

Download this release

Release Info

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

Code changes from version 1.7.14.1 to 1.7.15

Files changed (1) hide show
  1. qqworld-auto-save-images.php +33 -15
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.14.1
7
  Author: Michael Wang
8
  Author URI: http://www.qqworld.org
9
  Text Domain: qqworld_auto_save_images
@@ -14,6 +14,7 @@ define('QQWORLD_AUTO_SAVE_IMAGES_URL', plugin_dir_url(__FILE__));
14
  class QQWorld_auto_save_images {
15
  var $mode;
16
  var $when;
 
17
  var $remote_publishing;
18
  var $current_post_id; // for xmlrpc
19
  var $change_image_name;
@@ -1019,10 +1020,13 @@ function save_outside_link($content, $link) {
1019
  set_time_limit(0);
1020
  //Check to make sure function is not executed more than once on save
1021
  if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
1022
- return;
1023
-
1024
- if ( !current_user_can('edit_post', $post_id) )
1025
- return;
 
 
 
1026
 
1027
  $this->current_post_id = $post_id;
1028
 
@@ -1037,7 +1041,9 @@ function save_outside_link($content, $link) {
1037
  $post = get_post($post_id);
1038
  $content = $this->content_save_pre($post->post_content, $post_id);
1039
  //Replace the image in the post
 
1040
  wp_update_post(array('ID' => $post_id, 'post_content' => $content));
 
1041
 
1042
  if ($this->mode=='auto') $this->add_actions();
1043
  if ($this->remote_publishing) add_action('xmlrpc_publish_post', array($this, 'fetch_images') );
@@ -1047,7 +1053,7 @@ function save_outside_link($content, $link) {
1047
  $params = @getimagesize($image_url);
1048
  $width = $params[0];
1049
  $height = $params[1];
1050
- $type = $params['mime'];
1051
  if ($width==null) {
1052
  $file = @file_get_contents( $image_url );
1053
  if ($file) {
@@ -1057,21 +1063,21 @@ function save_outside_link($content, $link) {
1057
  $params = getimagesizefromstring($file);
1058
  $width = $params[0];
1059
  $height = $params[1];
1060
- $type = $params['mime'];
1061
  }
1062
  }
1063
  } else {
1064
  $width = $params[0];
1065
  $height = $params[1];
1066
- $type = $params['mime'];
1067
  }
1068
- return array($width, $height, $type);
1069
  }
1070
 
1071
  public function convert_space_from_content($content) {
1072
- $preg = preg_match_all('/[src|href]=\"((?!\").*?)\"/i', stripslashes($content), $matches);
1073
  if ($preg) {
1074
- foreach ($matches[0] as $match) {
1075
  if (preg_match("/ /", $match)) {
1076
  $new_str = str_replace(' ', '%20', $match);
1077
  $content = str_replace($match, $new_str, $content);
@@ -1082,6 +1088,9 @@ function save_outside_link($content, $link) {
1082
  }
1083
 
1084
  public function content_save_pre($content, $post_id=null, $action='save') {
 
 
 
1085
  $this->count = 1;
1086
  $content = $this->convert_space_from_content($content);
1087
  $this->change_attachment_url_to_permalink($content);
@@ -1377,9 +1386,9 @@ function save_outside_link($content, $link) {
1377
  // GD
1378
  $img = @imagecreatefromstring($file);
1379
  if (!$img && function_exists('fsockopen')) {
1380
- $type = @$this->fsockopen_image_header($image_url);
1381
- if ($type && in_array($type, array('image/jpeg', 'image/gif', 'image/png'))) {
1382
- $type = substr($type, 6);
1383
  $img = @call_user_func("imagecreatefrom{$type}", $image_url);
1384
  if ($img) {
1385
  ob_start();
@@ -1409,11 +1418,20 @@ function save_outside_link($content, $link) {
1409
  $img_name = $this->change_images_filename($img_name, '.'.$filetype);
1410
  } else return false;
1411
  } else {
 
 
1412
  $img_name = $this->change_images_filename($match[1], $match[2]);
1413
  }
1414
  // Automatic reduction pictures size
1415
  list($file, $width, $height) = $this->automatic_reduction($file, $image_url);
1416
-
 
 
 
 
 
 
 
1417
  $res=wp_upload_bits($img_name,'',$file);
1418
  if (isset( $res['error'] ) && !empty($res['error'])) return false;
1419
  $attachment_id = $this->insert_attachment($res['file'], $post_id);
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.15
7
  Author: Michael Wang
8
  Author URI: http://www.qqworld.org
9
  Text Domain: qqworld_auto_save_images
14
  class QQWorld_auto_save_images {
15
  var $mode;
16
  var $when;
17
+ var $type;
18
  var $remote_publishing;
19
  var $current_post_id; // for xmlrpc
20
  var $change_image_name;
1020
  set_time_limit(0);
1021
  //Check to make sure function is not executed more than once on save
1022
  if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
1023
+ return;
1024
+ // AJAX? Not used here
1025
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
1026
+ return;
1027
+ // Check user permissions
1028
+ if ( ! current_user_can( 'edit_post', $post_id ) )
1029
+ return;
1030
 
1031
  $this->current_post_id = $post_id;
1032
 
1041
  $post = get_post($post_id);
1042
  $content = $this->content_save_pre($post->post_content, $post_id);
1043
  //Replace the image in the post
1044
+ remove_action( 'post_updated', 'wp_save_post_revision' );
1045
  wp_update_post(array('ID' => $post_id, 'post_content' => $content));
1046
+ add_action( 'post_updated', 'wp_save_post_revision', 10, 1 );
1047
 
1048
  if ($this->mode=='auto') $this->add_actions();
1049
  if ($this->remote_publishing) add_action('xmlrpc_publish_post', array($this, 'fetch_images') );
1053
  $params = @getimagesize($image_url);
1054
  $width = $params[0];
1055
  $height = $params[1];
1056
+ $this->type = $params['mime'];
1057
  if ($width==null) {
1058
  $file = @file_get_contents( $image_url );
1059
  if ($file) {
1063
  $params = getimagesizefromstring($file);
1064
  $width = $params[0];
1065
  $height = $params[1];
1066
+ $this->type = $params['mime'];
1067
  }
1068
  }
1069
  } else {
1070
  $width = $params[0];
1071
  $height = $params[1];
1072
+ $this->type = $params['mime'];
1073
  }
1074
+ return array($width, $height, $this->type);
1075
  }
1076
 
1077
  public function convert_space_from_content($content) {
1078
+ $preg = preg_match_all('/(src|href)=\"((?!\").*?)\"/i', stripslashes($content), $matches);
1079
  if ($preg) {
1080
+ foreach ($matches[2] as $match) {
1081
  if (preg_match("/ /", $match)) {
1082
  $new_str = str_replace(' ', '%20', $match);
1083
  $content = str_replace($match, $new_str, $content);
1088
  }
1089
 
1090
  public function content_save_pre($content, $post_id=null, $action='save') {
1091
+ $post = get_post($post_id);
1092
+ if ($post->post_type == 'revision') return;
1093
+
1094
  $this->count = 1;
1095
  $content = $this->convert_space_from_content($content);
1096
  $this->change_attachment_url_to_permalink($content);
1386
  // GD
1387
  $img = @imagecreatefromstring($file);
1388
  if (!$img && function_exists('fsockopen')) {
1389
+ $this->type = @$this->fsockopen_image_header($image_url);
1390
+ if ($this->type && in_array($type, array('image/jpeg', 'image/gif', 'image/png'))) {
1391
+ $type = substr($this->type, 6);
1392
  $img = @call_user_func("imagecreatefrom{$type}", $image_url);
1393
  if ($img) {
1394
  ob_start();
1418
  $img_name = $this->change_images_filename($img_name, '.'.$filetype);
1419
  } else return false;
1420
  } else {
1421
+ $img_name = $match[1];
1422
+ $filetype = preg_replace('/^./', '', $match[2]);
1423
  $img_name = $this->change_images_filename($match[1], $match[2]);
1424
  }
1425
  // Automatic reduction pictures size
1426
  list($file, $width, $height) = $this->automatic_reduction($file, $image_url);
1427
+ /* fit to custom-upload-dir - start */
1428
+ if (function_exists('cud_custom_upload_dir')) {
1429
+ global $cud_file_ext, $cud_file_type;
1430
+ $cud_file_type = $this->type;
1431
+ $cud_file_ext = $filetype;
1432
+ add_filter('upload_dir', 'cud_custom_upload_dir', 1);
1433
+ }
1434
+ /* fit to custom-upload-dir - end */
1435
  $res=wp_upload_bits($img_name,'',$file);
1436
  if (isset( $res['error'] ) && !empty($res['error'])) return false;
1437
  $attachment_id = $this->insert_attachment($res['file'], $post_id);