@@ -26,6 +26,12 @@ abstract class Optml_App_Replacer {
2626 * @var array
2727 */
2828 protected static $ possible_src_attributes = null ;
29+ /**
30+ * Holds possible lazyload flags where we should ignore our lazyload.
31+ *
32+ * @var array
33+ */
34+ protected static $ ignore_lazyload_strings = null ;
2935 /**
3036 * Settings handler.
3137 *
@@ -84,7 +90,7 @@ abstract class Optml_App_Replacer {
8490 *
8591 * @var array Integrations classes.
8692 */
87- private $ compatibilities = array ( 'shortcode_ultimate ' , 'foogallery ' );
93+ private $ compatibilities = array ( 'shortcode_ultimate ' , 'foogallery ' , ' envira ' );
8894
8995 /**
9096 * Returns possible src attributes.
@@ -102,6 +108,22 @@ public static function possible_src_attributes() {
102108 return self ::$ possible_src_attributes ;
103109 }
104110
111+ /**
112+ * Returns possible src attributes.
113+ *
114+ * @return array
115+ */
116+ public static function possible_lazyload_flags () {
117+
118+ if ( null != self ::$ ignore_lazyload_strings && is_array ( self ::$ ignore_lazyload_strings ) ) {
119+ return self ::$ ignore_lazyload_strings ;
120+ }
121+
122+ self ::$ possible_src_attributes = apply_filters ( 'optml_possible_lazyload_flags ' , [] );
123+
124+ return array_merge ( self ::$ possible_src_attributes , [ '<noscript ' ] );
125+ }
126+
105127 /**
106128 * Size to crop maping.
107129 *
@@ -269,6 +291,7 @@ public function set_properties() {
269291 $ compatibility ->register ();
270292 }
271293 }
294+ add_filter ( 'optml_strip_image_size_from_url ' , [ $ this , 'strip_image_size_from_url ' ], 10 , 1 );
272295 }
273296
274297 /**
@@ -322,6 +345,7 @@ public function can_replace_url( $url ) {
322345 if ( ! isset ( $ url ['host ' ] ) ) {
323346 return false ;
324347 }
348+
325349 return isset ( $ this ->possible_sources [ $ url ['host ' ] ] ) || isset ( $ this ->allowed_sources [ $ url ['host ' ] ] );
326350 }
327351
@@ -332,9 +356,9 @@ public function can_replace_url( $url ) {
332356 *
333357 * @return string
334358 **/
335- protected function strip_image_size_from_url ( $ url ) {
359+ public function strip_image_size_from_url ( $ url ) {
336360
337- if ( preg_match ( '#(-\d+x\d+)\.( ' . implode ( '| ' , array_keys ( Optml_Config::$ extensions ) ) . '){1}$#i ' , $ url , $ src_parts ) ) {
361+ if ( preg_match ( '#(-\d+x\d+(?:_c)? )\.( ' . implode ( '| ' , array_keys ( Optml_Config::$ extensions ) ) . '){1}$#i ' , $ url , $ src_parts ) ) {
338362 $ stripped_url = str_replace ( $ src_parts [1 ], '' , $ url );
339363 // Extracts the file path to the image minus the base url
340364 $ file_path = substr ( $ stripped_url , strpos ( $ stripped_url , $ this ->upload_resource ['url ' ] ) + $ this ->upload_resource ['url_length ' ] );
@@ -356,15 +380,15 @@ protected function strip_image_size_from_url( $url ) {
356380 protected function parse_dimensions_from_filename ( $ src ) {
357381 $ width_height_string = array ();
358382 $ extensions = array_keys ( Optml_Config::$ extensions );
359- if ( preg_match ( '#-(\d+)x(\d+)\.(?: ' . implode ( '| ' , $ extensions ) . '){1}$#i ' , $ src , $ width_height_string ) ) {
383+ if ( preg_match ( '#-(\d+)x(\d+)(:?_c)? \.(?: ' . implode ( '| ' , $ extensions ) . '){1}$#i ' , $ src , $ width_height_string ) ) {
360384 $ width = (int ) $ width_height_string [1 ];
361385 $ height = (int ) $ width_height_string [2 ];
362-
386+ $ crop = ( isset ( $ width_height_string [ 3 ] ) && $ width_height_string [ 3 ] === ' _c ' );
363387 if ( $ width && $ height ) {
364- return array ( $ width , $ height );
388+ return array ( $ width , $ height, $ crop );
365389 }
366390 }
367391
368- return array ( false , false );
392+ return array ( false , false , false );
369393 }
370394}
0 commit comments