From 337d7faa3947df8f5b7b8f612707ed7bb0683e43 Mon Sep 17 00:00:00 2001 From: Marius Cristea Date: Sun, 10 Mar 2019 16:08:48 +0200 Subject: [PATCH] feat(api): adds filter for restricting watermark based on image source urls --- inc/image.php | 8 ++++---- inc/url_replacer.php | 11 +++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/inc/image.php b/inc/image.php index eedff64d..8b5c6707 100644 --- a/inc/image.php +++ b/inc/image.php @@ -93,11 +93,11 @@ private function set_defaults() { /** * Return transformed url. * - * @param bool $signed Either will be signed or not. + * @param array $params Either will be signed or not. * * @return string Transformed image url. */ - public function get_url( $signed = false ) { + public function get_url( $params = [] ) { $path_parts = array(); $path_parts[] = $this->width->toString(); @@ -108,7 +108,7 @@ public function get_url( $signed = false ) { $path_parts[] = $this->resize->toString(); } - if ( is_array( self::$watermark->get() ) && isset( self::$watermark->get()['id'] ) && self::$watermark->get()['id'] > 0 ) { + if ( isset( $params['apply_watermark'] ) && $params['apply_watermark'] && is_array( self::$watermark->get() ) && isset( self::$watermark->get()['id'] ) && self::$watermark->get()['id'] > 0 ) { $path_parts[] = self::$watermark->toString(); } @@ -116,7 +116,7 @@ public function get_url( $signed = false ) { $path = sprintf( '/%s%s', implode( '/', $path_parts ), $path ); - if ( $signed ) { + if ( isset( $params['signed'] ) && $params['signed'] ) { $path = sprintf( '/%s%s', $this->get_signature( $path ), $path ); } diff --git a/inc/url_replacer.php b/inc/url_replacer.php index 78458e96..abf5017b 100644 --- a/inc/url_replacer.php +++ b/inc/url_replacer.php @@ -128,9 +128,9 @@ public function init() { */ public function build_image_url( $url, $args = array( - 'width' => 'auto', - 'height' => 'auto', - ) + 'width' => 'auto', + 'height' => 'auto', + ) ) { if ( apply_filters( 'optml_dont_replace_url', false, $url ) ) { @@ -184,7 +184,10 @@ public function build_image_url( $args['height'] = $args['height'] > $this->max_height ? $this->max_height : $args['height']; } - $new_url = ( new Optml_Image( $url, $args ) )->get_url( $this->settings->use_lazyload() ? false : $this->is_allowed_site ); + $new_url = ( new Optml_Image( $url, $args ) )->get_url( [ + 'signed' => $this->settings->use_lazyload() ? false : $this->is_allowed_site, + 'apply_watermark' => apply_filters( 'optml_apply_watermark_for', true, $url ) + ] ); return $is_slashed ? addcslashes( $new_url, '/' ) : $new_url; }