Skip to content

Commit

Permalink
fix: compatibility when jetpack photon is on, fetch directly the imag…
Browse files Browse the repository at this point in the history
…e source
  • Loading branch information
selul committed Feb 8, 2019
1 parent 2aae664 commit f339dbb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
10 changes: 6 additions & 4 deletions inc/app_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,19 @@ public function set_properties() {
'secret' => $service_data['cdn_secret'],
)
);
$this->site_mappings['//i0.wp.com/'] = '//';
$this->site_mappings['//i1.wp.com/'] = '//';
$this->site_mappings['//i2.wp.com/'] = '//';

if ( defined( 'OPTML_SITE_MIRROR' ) && constant( 'OPTML_SITE_MIRROR' ) ) {
$this->site_mappings = array(
rtrim( get_site_url(), '/' ) => rtrim( constant( 'OPTML_SITE_MIRROR' ), '/' ),
);
$this->site_mappings[ rtrim( get_site_url(), '/' ) ] = rtrim( constant( 'OPTML_SITE_MIRROR' ), '/' );
}

$this->possible_sources = $this->extract_domain_from_urls(
array_merge(
array( get_site_url() ),
array_values( $this->site_mappings )
array_values( $this->site_mappings ),
array_keys( $this->site_mappings )
)
);

Expand Down
17 changes: 17 additions & 0 deletions tests/test-lazyload.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ public function test_lazyload_json_data() {
$this->assertEquals( 4, substr_count( $replaced_content2, '/http:\/\/' ) );
}


public function test_replacement_with_jetpack_photon() {
$content = '<div class="before-footer">
<div class="codeinwp-container">
<p class="featuredon">Featured On</p>
<img src="http://i0.wp.com/www.example.org/wp-content/uploads/2018/05/brands.png"> http://i0.wp.com/www.example.org/wp-content/uploads/2018/05/brands.png
</div>
</div>';

$replaced_content = Optml_Manager::instance()->replace_content( $content );
$this->assertContains( 'i.optimole.com', $replaced_content );
$this->assertNotContains( 'i0.wp.com', $replaced_content );
}

public function test_lazy_dont_lazy_load_headers() {
$replaced_content = Optml_Manager::instance()->process_images_from_content( self::HTML_TAGS_HEADER );

Expand Down Expand Up @@ -103,13 +117,15 @@ public function test_check_no_script() {
$this->assertContains( '<noscript>', $replaced_content );
$this->assertEquals( 1, substr_count( $replaced_content, '<noscript>' ) );
}

public function test_lazy_load_ignore_feed() {
$this->go_to( '/?feed=rss2' );

$replaced_content = Optml_Manager::instance()->process_images_from_content( Test_Replacer::IMG_TAGS_WITH_SRCSET );
$this->assertNotContains( 'i.optimole.com', $replaced_content );
$this->assertNotContains( 'data-opt-src', $replaced_content );
}

public function test_lazy_load_off() {

define( 'OPTML_DISABLE_PNG_LAZYLOAD', true );
Expand All @@ -120,6 +136,7 @@ public function test_lazy_load_off() {
$this->assertEquals( 1, substr_count( $replaced_content, 'data-opt-src' ) );

}

public function test_lazyload_json_data_disabled() {

$some_html_content = [
Expand Down

0 comments on commit f339dbb

Please sign in to comment.