Skip to content

Commit

Permalink
build: various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Jul 10, 2019
1 parent 03f8527 commit 0859f70
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ composer.lock
assets/js/bundle.js
npm-debug.log
bin
key.enc
cypress
cypress.json
node_modules
logs
grunt
Expand Down
4 changes: 2 additions & 2 deletions assets/vue/components/filter-control.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
<span v-if="this.selected_filter===this.FILTER_TYPES.EXT" class="select is-small">
<select v-model="selected_value">
<option value="svg">.SVG</option>
<option value="png">.JPG</option>
<option value="jpg">.PNG</option>
<option value="jpg">.JPG</option>
<option value="png">.PNG</option>
</select>
</span>
<input v-else v-model="selected_value" class="input is-small" type="text" placeholder="word">
Expand Down
13 changes: 10 additions & 3 deletions inc/app_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,20 @@ public function can_replace_url( $url ) {
if ( ! is_string( $url ) ) {
return false; // @codeCoverageIgnore
}
$url = parse_url( $url );
$url_parts = parse_url( $url );

if ( ! isset( $url['host'] ) ) {
if ( ! isset( $url_parts['host'] ) ) {
return false;
}
if ( false === ( isset( $this->possible_sources[ $url_parts['host'] ] ) || isset( $this->allowed_sources[ $url_parts['host'] ] ) ) ) {
return false;
}

if ( false === Optml_Filters::should_do_image( $url, self::$filters[ Optml_Settings::FILTER_TYPE_OPTIMIZE ][ Optml_Settings::FILTER_FILENAME ] ) ) {
return false;
}

return isset( $this->possible_sources[ $url['host'] ] ) || isset( $this->allowed_sources[ $url['host'] ] );
return true;
}

/**
Expand Down
17 changes: 9 additions & 8 deletions inc/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ final class Optml_Filters {
* @return bool Should do action on page?
*/
public static function should_do_page( $flags ) {
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
foreach ( $flags as $rule_flag => $status ) {
if ( strpos( $_SERVER['REQUEST_URI'], $rule_flag ) !== false ) {
return false;
}
if ( $rule_flag === 'home' && is_front_page() ) {
return false;
}
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
return true;
}
foreach ( $flags as $rule_flag => $status ) {
if ( strpos( $_SERVER['REQUEST_URI'], $rule_flag ) !== false ) {
return false;
}
if ( $rule_flag === 'home' && ( empty( $_SERVER['REQUEST_URI'] ) || $_SERVER['REQUEST_URI'] === '/' ) ) {
return false;
}
}

Expand Down
11 changes: 10 additions & 1 deletion inc/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,15 @@ public function should_replace() {
if ( array_key_exists( 'context', $_GET ) && $_GET['context'] == 'edit' ) {
return false; // @codeCoverageIgnore
}
if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] === 'POST' && is_user_logged_in() ) {
/**
* Disable replacement on POST request and when user is logged in, but allows for sample image call widget in dashboard
*/
if (
isset( $_SERVER['REQUEST_METHOD'] ) &&
$_SERVER['REQUEST_METHOD'] === 'POST' &&
is_user_logged_in()
&& ( ! isset( $_GET['quality'] ) || ! current_user_can( 'manage_options' ) )
) {
return false; // @codeCoverageIgnore
}
if ( class_exists( 'FLBuilderModel', false ) ) {
Expand Down Expand Up @@ -189,6 +197,7 @@ public static function is_ajax_request() {
* Register frontend replacer hooks.
*/
public function register_hooks() {

do_action( 'optml_replacer_setup' );
add_filter( 'the_content', array( $this, 'process_images_from_content' ), PHP_INT_MAX );
/**
Expand Down
3 changes: 1 addition & 2 deletions inc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function __construct() {
$this->namespace = OPTML_NAMESPACE . '_settings';
$this->default_schema = apply_filters( 'optml_default_settings', $this->default_schema );
$this->options = wp_parse_args( get_option( $this->namespace, $this->default_schema ), $this->default_schema );

if ( defined( 'OPTIML_ENABLED_MU' ) && defined( 'OPTIML_MU_SITE_ID' ) && $this->to_boolean( constant( 'OPTIML_ENABLED_MU' ) ) && constant( 'OPTIML_MU_SITE_ID' ) ) {
switch_to_blog( constant( 'OPTIML_MU_SITE_ID' ) );
$this->options = wp_parse_args( get_option( $this->namespace, $this->default_schema ), $this->default_schema );
Expand All @@ -69,7 +70,6 @@ public function __construct() {
public function get_filters() {

$filters = $this->get( 'filters' );

if ( ! isset( $filters[ self::FILTER_TYPE_LAZYLOAD ] ) ) {
$filters[ self::FILTER_TYPE_LAZYLOAD ] = [];
}
Expand All @@ -87,7 +87,6 @@ public function get_filters() {
$filters[ $filter_key ][ self::FILTER_URL ] = [];
}
}

return $filters;
}

Expand Down
5 changes: 0 additions & 5 deletions inc/url_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,12 @@ public function build_image_url(
'height' => 'auto',
)
) {

if ( apply_filters( 'optml_dont_replace_url', false, $url ) ) {
return $url;
}

$original_url = $url;

if ( Optml_Filters::should_do_image( $original_url, self::$filters[ Optml_Settings::FILTER_TYPE_OPTIMIZE ][ Optml_Settings::FILTER_FILENAME ] ) === false ) {
return false;
}

$is_slashed = strpos( $url, '\/' ) !== false;

$url = $is_slashed ? stripslashes( $url ) : $url;
Expand Down

0 comments on commit 0859f70

Please sign in to comment.