Enable Media Replace - Version 3.3.7

Version Description

Release date: 13th November 2019 * call the hook enable-media-replace-upload-done on both modes * fix JSON compatibility for hostings that don't have JSON module activated * Language 0 new strings added, 0 updated, 0 fuzzied, and 0 obsoleted

Download this release

Release Info

Developer ShortPixel
Plugin Icon 128x128 Enable Media Replace
Version 3.3.7
Comparing to
See all releases

Code changes from version 3.3.6 to 3.3.7

build/shortpixel/autoload.php CHANGED
@@ -1,5 +1,5 @@
1
  <?php
2
- require_once "PackageLoader.php";
3
  $loader = new EnableMediaReplace\Build\PackageLoader();
4
  $loader->load(__DIR__);
5
 
1
  <?php
2
+ require_once (dirname(__FILE__) . "/PackageLoader.php");
3
  $loader = new EnableMediaReplace\Build\PackageLoader();
4
  $loader->load(__DIR__);
5
 
build/shortpixel/log/src/ShortPixelLogger.php CHANGED
@@ -171,7 +171,7 @@ namespace EnableMediaReplace\ShortPixelLogger;
171
  $line = $this->formatLine($items);
172
 
173
  // try to write to file. Don't write if directory doesn't exists (leads to notices)
174
- if ($this->logPath && is_dir(dirname($this->logPath) ))
175
  {
176
  file_put_contents($this->logPath,$line, FILE_APPEND);
177
  }
171
  $line = $this->formatLine($items);
172
 
173
  // try to write to file. Don't write if directory doesn't exists (leads to notices)
174
+ if ($this->logPath && is_dir(dirname($this->logPath)) )
175
  {
176
  file_put_contents($this->logPath,$line, FILE_APPEND);
177
  }
build/shortpixel/notices/composer.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "name": "shortpixel/notices",
3
  "description": "ShortPixel WordPress Notice System",
4
- "version": "1.1",
5
  "type": "library",
6
  "license": "MIT",
7
  "authors": [
1
  {
2
  "name": "shortpixel/notices",
3
  "description": "ShortPixel WordPress Notice System",
4
+ "version": "1.2",
5
  "type": "library",
6
  "license": "MIT",
7
  "authors": [
build/shortpixel/notices/src/NoticeController.php CHANGED
@@ -64,9 +64,18 @@ class NoticeController //extends ShortPixelController
64
  }
65
 
66
 
67
- public function addNotice($message, $code)
68
  {
69
  $notice = new NoticeModel($message, $code);
 
 
 
 
 
 
 
 
 
70
  self::$notices[] = $notice;
71
  $this->countNotices();
72
  Log::addDebug('Adding notice - ', $notice);
@@ -124,38 +133,39 @@ class NoticeController //extends ShortPixelController
124
 
125
  /** Adds a notice, quick and fast method
126
  * @param String $message The Message you want to notify
 
127
  * @param int $code A value of messageType as defined in model
128
  * @returm Object Instance of noticeModel
129
  */
130
 
131
- public static function addNormal($message)
132
  {
133
  $noticeController = self::getInstance();
134
- $notice = $noticeController->addNotice($message, NoticeModel::NOTICE_NORMAL);
135
  return $notice;
136
 
137
  }
138
 
139
- public static function addError($message)
140
  {
141
  $noticeController = self::getInstance();
142
- $notice = $noticeController->addNotice($message, NoticeModel::NOTICE_ERROR);
143
  return $notice;
144
 
145
  }
146
 
147
- public static function addWarning($message)
148
  {
149
  $noticeController = self::getInstance();
150
- $notice = $noticeController->addNotice($message, NoticeModel::NOTICE_WARNING);
151
  return $notice;
152
 
153
  }
154
 
155
- public static function addSuccess($message)
156
  {
157
  $noticeController = self::getInstance();
158
- $notice = $noticeController->addNotice($message, NoticeModel::NOTICE_SUCCESS);
159
  return $notice;
160
 
161
  }
64
  }
65
 
66
 
67
+ public function addNotice($message, $code, $unique)
68
  {
69
  $notice = new NoticeModel($message, $code);
70
+
71
+ if ($unique)
72
+ {
73
+ foreach(self::$notices as $nitem)
74
+ {
75
+ if ($nitem->message == $notice->message && $nitem->code == $notice->code) // same message.
76
+ return false;
77
+ }
78
+ }
79
  self::$notices[] = $notice;
80
  $this->countNotices();
81
  Log::addDebug('Adding notice - ', $notice);
133
 
134
  /** Adds a notice, quick and fast method
135
  * @param String $message The Message you want to notify
136
+ * @param Boolean $unique If unique, check to not repeat notice exact same text in notices. Discard if so
137
  * @param int $code A value of messageType as defined in model
138
  * @returm Object Instance of noticeModel
139
  */
140
 
141
+ public static function addNormal($message, $unique = false)
142
  {
143
  $noticeController = self::getInstance();
144
+ $notice = $noticeController->addNotice($message, NoticeModel::NOTICE_NORMAL, $unique);
145
  return $notice;
146
 
147
  }
148
 
149
+ public static function addError($message, $unique = false)
150
  {
151
  $noticeController = self::getInstance();
152
+ $notice = $noticeController->addNotice($message, NoticeModel::NOTICE_ERROR, $unique);
153
  return $notice;
154
 
155
  }
156
 
157
+ public static function addWarning($message, $unique = false)
158
  {
159
  $noticeController = self::getInstance();
160
+ $notice = $noticeController->addNotice($message, NoticeModel::NOTICE_WARNING, $unique);
161
  return $notice;
162
 
163
  }
164
 
165
+ public static function addSuccess($message, $unique = false)
166
  {
167
  $noticeController = self::getInstance();
168
+ $notice = $noticeController->addNotice($message, NoticeModel::NOTICE_SUCCESS, $unique);
169
  return $notice;
170
 
171
  }
build/shortpixel/notices/src/NoticeModel.php CHANGED
@@ -3,7 +3,7 @@ namespace EnableMediaReplace\Notices;
3
 
4
  class NoticeModel //extends ShortPixelModel
5
  {
6
- protected $message;
7
  public $code;
8
 
9
  protected $viewed = false;
@@ -88,9 +88,6 @@ class NoticeModel //extends ShortPixelModel
88
  break;
89
  }
90
 
91
- /*$image = '<img src="' . plugins_url('/shortpixel-image-optimiser/res/img/robo-' . $icon . '.png') . '"
92
- srcset="' . plugins_url( 'shortpixel-image-optimiser/res/img/robo-' . $icon . '.png' ) . ' 1x, ' . plugins_url( 'shortpixel-image-optimiser/res/img/robo-' . $icon . '@2x.png') . ' 2x" class="short-pixel-notice-icon">';
93
- */
94
 
95
  if ($this->is_removable)
96
  {
@@ -107,10 +104,4 @@ class NoticeModel //extends ShortPixelModel
107
  }
108
 
109
 
110
-
111
- // @todo Transient save, since that is used in some parts.
112
- // save
113
- // load
114
-
115
-
116
  }
3
 
4
  class NoticeModel //extends ShortPixelModel
5
  {
6
+ public $message;
7
  public $code;
8
 
9
  protected $viewed = false;
88
  break;
89
  }
90
 
 
 
 
91
 
92
  if ($this->is_removable)
93
  {
104
  }
105
 
106
 
 
 
 
 
 
 
107
  }
classes/emr-plugin.php CHANGED
@@ -20,6 +20,11 @@ class EnableMediaReplacePlugin
20
  if (is_null(self::$instance))
21
  self::$instance = new EnableMediaReplacePlugin();
22
 
 
 
 
 
 
23
  return self::$instance;
24
  }
25
 
@@ -45,7 +50,7 @@ class EnableMediaReplacePlugin
45
  add_action('network_admin_notices', array($this,'display_network_notices'));
46
  add_action('wp_ajax_emr_dismiss_notices', array($this,'dismiss_notices'));
47
 
48
- // editors
49
  add_action( 'add_meta_boxes', function () { add_meta_box('emr-eplace-box', __('Replace Image', 'enable-media-replace'), array($this, 'replace_meta_box'), 'attachment', 'side', 'low'); } );
50
  add_filter('attachment_fields_to_edit', array($this, 'attachment_editor'), 10, 2);
51
 
20
  if (is_null(self::$instance))
21
  self::$instance = new EnableMediaReplacePlugin();
22
 
23
+ $log = Log::getInstance();
24
+ $uploaddir =wp_upload_dir();
25
+ if (isset($uploaddir['basedir']))
26
+ $log->setLogPath($uploaddir['basedir'] . "/emr_log");
27
+
28
  return self::$instance;
29
  }
30
 
50
  add_action('network_admin_notices', array($this,'display_network_notices'));
51
  add_action('wp_ajax_emr_dismiss_notices', array($this,'dismiss_notices'));
52
 
53
+ // editors
54
  add_action( 'add_meta_boxes', function () { add_meta_box('emr-eplace-box', __('Replace Image', 'enable-media-replace'), array($this, 'replace_meta_box'), 'attachment', 'side', 'low'); } );
55
  add_filter('attachment_fields_to_edit', array($this, 'attachment_editor'), 10, 2);
56
 
classes/file.php CHANGED
@@ -10,7 +10,7 @@ class emrFile
10
  protected $file; // the full file w/ path.
11
  protected $extension;
12
  protected $fileName;
13
- protected $filePath; // with trailing slash!
14
  protected $fileURL;
15
  protected $fileMime;
16
  protected $permissions = 0;
10
  protected $file; // the full file w/ path.
11
  protected $extension;
12
  protected $fileName;
13
+ protected $filePath; // with trailing slash! not the image name.
14
  protected $fileURL;
15
  protected $fileMime;
16
  protected $permissions = 0;
classes/replacer.php CHANGED
@@ -39,7 +39,6 @@ class Replacer
39
  $this->post_id = $post_id;
40
 
41
  $source_file = trim(get_attached_file($post_id, apply_filters( 'emr_unfiltered_get_attached_file', true )));
42
-
43
  $this->sourceFile = new File($source_file);
44
 
45
  $this->source_post = get_post($post_id);
@@ -134,8 +133,9 @@ class Replacer
134
 
135
  if ($this->replaceMode == self::MODE_SEARCHREPLACE)
136
  {
137
- $title = $this->getNewTitle();
138
 
 
 
139
  $update_ar = array('ID' => $this->post_id);
140
  $update_ar['post_title'] = $title;
141
  $update_ar['post_name'] = sanitize_title($title);
@@ -156,8 +156,8 @@ class Replacer
156
  }
157
  }
158
  $this->doSearchReplace();
159
- do_action("enable-media-replace-upload-done", $this->target_url, $this->source_url);
160
- }
161
 
162
  if(wp_attachment_is_image($this->post_id))
163
  {
@@ -180,6 +180,8 @@ class Replacer
180
  $cache = new emrCache();
181
  $cache->flushCache($cache_args);
182
 
 
 
183
  }
184
 
185
  protected function getNewTitle()
39
  $this->post_id = $post_id;
40
 
41
  $source_file = trim(get_attached_file($post_id, apply_filters( 'emr_unfiltered_get_attached_file', true )));
 
42
  $this->sourceFile = new File($source_file);
43
 
44
  $this->source_post = get_post($post_id);
133
 
134
  if ($this->replaceMode == self::MODE_SEARCHREPLACE)
135
  {
 
136
 
137
+ // Write new image title.
138
+ $title = $this->getNewTitle();
139
  $update_ar = array('ID' => $this->post_id);
140
  $update_ar['post_title'] = $title;
141
  $update_ar['post_name'] = sanitize_title($title);
156
  }
157
  }
158
  $this->doSearchReplace();
159
+
160
+ } // SEARCH REPLACE MODE
161
 
162
  if(wp_attachment_is_image($this->post_id))
163
  {
180
  $cache = new emrCache();
181
  $cache->flushCache($cache_args);
182
 
183
+ do_action("enable-media-replace-upload-done", $this->target_url, $this->source_url);
184
+
185
  }
186
 
187
  protected function getNewTitle()
classes/uihelper.php CHANGED
@@ -53,6 +53,18 @@ class UIHelper
53
  $url = admin_url('post.php');
54
  $url = add_query_arg(array('action' => 'edit', 'post' => $post_id, 'emr_replaced' => '1'), $url);
55
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  $url = apply_filters('emr_returnurl', $url);
57
  Log::addDebug('Success URL- ' . $url);
58
 
53
  $url = admin_url('post.php');
54
  $url = add_query_arg(array('action' => 'edit', 'post' => $post_id, 'emr_replaced' => '1'), $url);
55
 
56
+ if (isset($_REQUEST['SHORTPIXEL_DEBUG']))
57
+ {
58
+ $spdebug = $_REQUEST['SHORTPIXEL_DEBUG'];
59
+ if (is_numeric($spdebug))
60
+ $spdebug = intval($spdebug);
61
+ else {
62
+ $spdebug = sanitize_text_field($spdebug);
63
+ }
64
+
65
+ $url = add_query_arg('SHORTPIXEL_DEBUG', $spdebug, $url);
66
+ }
67
+
68
  $url = apply_filters('emr_returnurl', $url);
69
  Log::addDebug('Success URL- ' . $url);
70
 
enable-media-replace.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Enable Media Replace
4
  Plugin URI: https://wordpress.org/plugins/enable-media-replace/
5
  Description: Enable replacing media files by uploading a new file in the "Edit Media" section of the WordPress Media Library.
6
- Version: 3.3.6
7
  Author: ShortPixel
8
  Author URI: https://shortpixel.com
9
  Text Domain: enable-media-replace
3
  Plugin Name: Enable Media Replace
4
  Plugin URI: https://wordpress.org/plugins/enable-media-replace/
5
  Description: Enable replacing media files by uploading a new file in the "Edit Media" section of the WordPress Media Library.
6
+ Version: 3.3.7
7
  Author: ShortPixel
8
  Author URI: https://shortpixel.com
9
  Text Domain: enable-media-replace
js/emr_admin.js CHANGED
@@ -26,7 +26,7 @@ jQuery(document).ready(function($)
26
  var source = $('.image_placeholder').first();
27
  if (typeof( $(source).data('filetype') ) !== 'undefined')
28
  {
29
- source_type = $(source).data('filetype');
30
  this.debug('detected type - ' + source_type);
31
  }
32
  if (source.hasClass('is_image'))
@@ -108,7 +108,7 @@ jQuery(document).ready(function($)
108
  if (file !== null) /// file is null when empty, or error
109
  {
110
  target_is_image = (file.type.indexOf('image') >= 0) ? true : false;
111
- target_type = file.type;
112
  }
113
  // If image, load thumbnail and get dimensions.
114
  if (file && target_is_image)
26
  var source = $('.image_placeholder').first();
27
  if (typeof( $(source).data('filetype') ) !== 'undefined')
28
  {
29
+ source_type = $(source).data('filetype').trim();
30
  this.debug('detected type - ' + source_type);
31
  }
32
  if (source.hasClass('is_image'))
108
  if (file !== null) /// file is null when empty, or error
109
  {
110
  target_is_image = (file.type.indexOf('image') >= 0) ? true : false;
111
+ target_type = file.type.trim();
112
  }
113
  // If image, load thumbnail and get dimensions.
114
  if (file && target_is_image)
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: ShortPixel
3
  Donate link: https://www.paypal.me/resizeImage
4
  Tags: replace, attachment, media, files, replace image, replace jpg, change media, replace media, image, file
5
  Requires at least: 4.2
6
- Tested up to: 5.2
7
  Requires PHP: 5.4
8
  Stable tag: trunk
9
 
@@ -47,6 +47,13 @@ If you want more control over the format used to display the time, you can use t
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
 
 
50
  = 3.3.6 =
51
 
52
  Release date: 5th September 2019
3
  Donate link: https://www.paypal.me/resizeImage
4
  Tags: replace, attachment, media, files, replace image, replace jpg, change media, replace media, image, file
5
  Requires at least: 4.2
6
+ Tested up to: 5.3
7
  Requires PHP: 5.4
8
  Stable tag: trunk
9
 
47
 
48
  == Changelog ==
49
 
50
+ = 3.3.7 =
51
+
52
+ Release date: 13th November 2019
53
+ * call the hook enable-media-replace-upload-done on both modes
54
+ * fix JSON compatibility for hostings that don't have JSON module activated
55
+ * Language – 0 new strings added, 0 updated, 0 fuzzied, and 0 obsoleted
56
+
57
  = 3.3.6 =
58
 
59
  Release date: 5th September 2019
thumbnail_updater.php CHANGED
@@ -100,7 +100,6 @@ class ThumbnailUpdater
100
 
101
  $replace_sql = $wpdb->prepare($sql, $from, $to );
102
  $wpdb->query($replace_sql);
103
-
104
  }
105
  }
106
 
100
 
101
  $replace_sql = $wpdb->prepare($sql, $from, $to );
102
  $wpdb->query($replace_sql);
 
103
  }
104
  }
105