Skip to content

Commit 770e4f9

Browse files
authored
Release version 4.1.0 (#92)
Merge pull request #92 from short-pixel-optimizer/updates
2 parents 88d6347 + 35b3451 commit 770e4f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3088
-418
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ So `[file_modified id=870]` would display the last time the file with ID 870 was
2626

2727
If you want more control over the format used to display the time, you can use the format option, so `[file_modified id=870 format=Y-m-d]` would display the file modification date but not the time. The format string uses [standard PHP date() formatting tags](http://php.net/manual/en/function.date.php).
2828

29+
## Disable background removal
30+
If you don't want to utilize the background removal feature, add `add_filter('emr/feature/background', '__return_false' );` to your functions.php
31+
2932
***
3033

3134
See [Enable Media Replace](http://wordpress.org/plugins/enable-media-replace/) at WordPress.org for more information.

build/shortpixel/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"name":"EnableMediaReplace\/shortpixelmodules","description":"ShortPixel submodules","type":"function","autoload":{"psr-4":{"EnableMediaReplace\\ShortPixelLogger":"log\/src","EnableMediaReplace\\Notices":"notices\/src","EnableMediaReplace\\FileSystem":"filesystem\/src"}}}
1+
{"name":"EnableMediaReplace\/shortpixelmodules","description":"ShortPixel submodules","type":"function","autoload":{"psr-4":{"EnableMediaReplace\\ShortPixelLogger":"log\/src","EnableMediaReplace\\Notices":"notices\/src","EnableMediaReplace\\Replacer":"replacer\/src","EnableMediaReplace\\FileSystem":"filesystem\/src"}}}

build/shortpixel/filesystem/src/Model/File/FileModel.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,15 @@ public function getMime()
416416
if ($this->exists() && ! $this->is_virtual() )
417417
{
418418
$this->mime = wp_get_image_mime($this->fullpath);
419+
if (false === $this->mime)
420+
{
421+
$image_data = wp_check_filetype_and_ext($this->getFullPath(), $this->getFileName());
422+
if (is_array($image_data) && isset($image_data['type']) && strlen($image_data['type']) > 0)
423+
{
424+
$this->mime = $image_data['type'];
425+
}
426+
427+
}
419428
}
420429
else
421430
$this->mime = false;
@@ -591,7 +600,7 @@ private function relativeToFullPath($path)
591600
public function getPermissions()
592601
{
593602
if (is_null($this->permissions))
594-
$this->permissions = fileperms($this->fullpath) & 0777;
603+
$this->permissions = fileperms($this->getFullPath()) & 0777;
595604

596605
return $this->permissions;
597606
}

build/shortpixel/notices/src/css/notices.css

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/shortpixel/notices/src/css/notices.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/shortpixel/notices/src/css/notices.scss

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11

22
.shortpixel.shortpixel-notice
33
{
4-
//padding: 18px;
5-
//min-height: 50px;
6-
padding: 8px;
4+
5+
min-height: 75px;
6+
padding: 8px;
7+
display: flex;
8+
align-items: center;
79
background: #fff;
10+
padding: 1px 12px;
11+
box-shadow: 0 1px 1px rgba(0,0,0,0.04);
812
border: 1px solid #c3c4c7;
13+
margin: 15px 0;
914
border-left-width: 4px;
10-
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
11-
margin: 5px 15px 2px;
15+
border-left-color: #72aee6;
1216
position: relative;
1317

18+
span
19+
{
20+
vertical-align: middle;
21+
&.icon {
22+
margin: 0 25px 0 0;
23+
width: 80px;
24+
}
25+
&.content
26+
{
27+
padding: 8px 0;
28+
word-wrap: break-word;
29+
overflow: hidden;
30+
//display: flex; // magically fixes verticality issues
31+
}
32+
}
33+
1434
img
1535
{
1636
display:inline-block;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "shortpixel/replacer",
3+
"description": "Content Replacer",
4+
"version": 1.1,
5+
"type": "library",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Bas",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"minimum-stability": "dev",
14+
"require": {},
15+
"autoload": {
16+
"psr-4": { "ShortPixel\\Replacer\\" : "src" }
17+
}
18+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
namespace EnableMediaReplace\Replacer\Modules;
3+
4+
class Elementor
5+
{
6+
private static $instance;
7+
8+
protected $queryKey = 'elementor';
9+
10+
public static function getInstance()
11+
{
12+
if (is_null(self::$instance))
13+
self::$instance = new Elementor();
14+
15+
return self::$instance;
16+
}
17+
18+
public function __construct()
19+
{
20+
if ($this->elementor_is_active()) // elementor is active
21+
{
22+
add_filter('shortpixel/replacer/custom_replace_query', array($this, 'addElementor'), 10, 4); // custom query for elementor \ // problem
23+
// @todo Fix this for SPIO
24+
//add_action('enable-media-replace-upload-done', array($this, 'removeCache') );
25+
}
26+
}
27+
28+
public function addElementor($items, $base_url, $search_urls, $replace_urls)
29+
{
30+
$base_url = $this->addSlash($base_url);
31+
$el_search_urls = $search_urls; //array_map(array($this, 'addslash'), $search_urls);
32+
$el_replace_urls = $replace_urls; //array_map(array($this, 'addslash'), $replace_urls);
33+
$items[$this->queryKey] = array('base_url' => $base_url, 'search_urls' => $el_search_urls, 'replace_urls' => $el_replace_urls);
34+
return $items;
35+
}
36+
37+
public function addSlash($value)
38+
{
39+
global $wpdb;
40+
$value= ltrim($value, '/'); // for some reason the left / isn't picked up by Mysql.
41+
$value= str_replace('/', '\/', $value);
42+
$value = $wpdb->esc_like(($value)); //(wp_slash) / str_replace('/', '\/', $value);
43+
44+
return $value;
45+
}
46+
47+
protected function elementor_is_active()
48+
{
49+
$bool = false;
50+
51+
if (defined('ELEMENTOR_VERSION'))
52+
$bool = true;
53+
54+
return apply_filters('emr/externals/elementor_is_active', $bool); // manual override
55+
}
56+
57+
public function removeCache()
58+
{
59+
\Elementor\Plugin::$instance->files_manager->clear_cache();
60+
}
61+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
namespace EnableMediaReplace\Replacer\Modules;
3+
// Note! This class doubles as integration for both Visual Composer *and* WP Bakery. They both need URLENCODE.
4+
class WpBakery
5+
{
6+
private static $instance;
7+
8+
protected $queryKey = 'wpbakery';
9+
10+
public static function getInstance()
11+
{
12+
if (is_null(self::$instance))
13+
self::$instance = new WpBakery();
14+
15+
return self::$instance;
16+
}
17+
18+
public function __construct()
19+
{
20+
if ($this->bakery_is_active()) // elementor is active
21+
{
22+
add_filter('shortpixel/replacer/custom_replace_query', array($this, 'addURLEncoded'), 10, 4); // custom query for elementor \ // problem
23+
}
24+
}
25+
26+
public function addUrlEncoded($items, $base_url, $search_urls, $replace_urls)
27+
{
28+
$base_url = $this->addEncode($base_url);
29+
$el_search_urls = array_map(array($this, 'addEncode'), $search_urls);
30+
$el_replace_urls = array_map(array($this, 'addEncode'), $replace_urls);
31+
$items[$this->queryKey] = array('base_url' => $base_url, 'search_urls' => $el_search_urls, 'replace_urls' => $el_replace_urls);
32+
return $items;
33+
}
34+
35+
public function addEncode($value)
36+
{
37+
return urlencode($value);
38+
}
39+
40+
protected function bakery_is_active()
41+
{
42+
$bool = false;
43+
44+
// did_action -> wpbakery , VCV_version -> detect Visual Composer
45+
if (did_action('vc_plugins_loaded') || defined('VCV_VERSION'))
46+
$bool = true;
47+
48+
return apply_filters('emr/externals/urlencode_is_active', $bool); // manual override
49+
}
50+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
namespace EnableMediaReplace\Replacer\Modules;
3+
use EnableMediaReplace\ShortPixelLogger\ShortPixelLogger as Log;
4+
5+
// Integration to reset indexes of Yoast (used for Og:image) when something is converted.
6+
class YoastSeo
7+
{
8+
9+
private $yoastTable;
10+
private static $instance;
11+
12+
public static function getInstance()
13+
{
14+
if (is_null(self::$instance))
15+
self::$instance = new YoastSeo();
16+
17+
return self::$instance;
18+
}
19+
20+
public function __construct()
21+
{
22+
if (true === $this->yoast_is_active()) // elementor is active
23+
{
24+
global $wpdb;
25+
$this->yoastTable = $wpdb->prefix . 'yoast_indexable';
26+
27+
add_action('shortpixel/replacer/replace_urls', array($this, 'removeIndexes'),10,2);
28+
}
29+
}
30+
31+
public function removeIndexes($search_urls, $replace_urls)
32+
{
33+
global $wpdb;
34+
35+
$sql = 'DELETE FROM ' . $this->yoastTable . ' WHERE ';
36+
$prepare = array();
37+
38+
$base = isset($search_urls['base']) ? $search_urls['base'] : null;
39+
$file = isset($search_urls['file']) ? $search_urls['file'] : null;
40+
41+
if (! is_null($base))
42+
{
43+
$querySQL = $sql . ' twitter_image like %s or open_graph_image like %s ';
44+
$querySQL = $wpdb->prepare($querySQL, '%' . $base . '%', '%' . $base . '%');
45+
46+
$wpdb->query($querySQL);
47+
}
48+
49+
if (! is_null($file))
50+
{
51+
$querySQL = $sql . ' twitter_image like %s or open_graph_image like %s ';
52+
$querySQL = $wpdb->prepare($querySQL, '%' . $file . '%', '%' . $file . '%');
53+
54+
$wpdb->query($querySQL);
55+
}
56+
57+
}
58+
59+
protected function yoast_is_active()
60+
{
61+
if (defined('WPSEO_VERSION'))
62+
{
63+
return true;
64+
}
65+
return false;
66+
}
67+
68+
69+
70+
71+
}

0 commit comments

Comments
 (0)