Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
selul authored Jan 14, 2020
2 parents 9f4bc17 + 46323f9 commit f8778c4
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 62 deletions.
4 changes: 3 additions & 1 deletion assets/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

@import "~bulma/bulma";

.select:not(.is-multiple):not(.is-loading)::after{
display: none;
}
.card {
transition: all 750ms ease-in-out;
border: 0;
Expand Down Expand Up @@ -206,7 +209,6 @@ th.optml-image-ratio-heading {
-ms-flex-negative: 1;
flex-shrink: 1;
}

.tabs .icon {
margin-left: 0.5em;
}
Expand Down
10 changes: 5 additions & 5 deletions assets/js/bundle.min.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions assets/vue/components/connect-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
v-html="strings.account_needed_subtitle_2"></p>
</div>
</div>
<div class="columns is-vcentered">
<div class=" is-narrow is-hidden-touch column">
<span class="dashicons icon dashicons-format-aside is-size-4 "></span>
</div>
<div class="column">
<p class="subtitle column is-size-6 is-vcentered has-text-left"
v-html="strings.account_needed_subtitle_3"></p>
</div>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion assets/vue/components/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
</div>
<div class="card-footer ">
<div class="card-footer-item">
<a href="https://optimole.com#pricing" target="_blank"
<a href="https://optimole.com/pricing" target="_blank"
class="button is-centered is-small is-success"><span
class="dashicons dashicons-external"></span>{{strings.upgrade.cta}}</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion cypress/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.2'
services:
cypress:
ipc: host
image: "cypress/included:3.4.0"
image: "cypress/included:3.6.1"
environment:
- CYPRESS_RECORD_KEY
working_dir: /e2e
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/test_amp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe( 'Check amp page', function () {
} );

it( 'AMP body has Optimole no script class', function () {
cy.get( 'body' ).should( 'have.attr', 'class' ).and( 'include', 'optimole-no-script' );
cy.get( 'body' ).not( '.optimole-no-script' );
} );

it( 'AMP images should have replaced srcs', function () {
Expand Down
17 changes: 17 additions & 0 deletions cypress/integration/test_ss_pintereset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe( 'Sassy Social Share', function () {
it( 'successfully loads', function () {
cy.visit( '/sassy-social-share/' )
} );
it( 'click on button', function () {
cy.get( '.heateorSssSharing.heateorSssPinterestBackground' ).click( { multiple: true } )
} );
it( 'images should not have quality:eco', function () {
cy.get( 'img' ).should( ( $imgs ) => {
expect( $imgs ).to.have.length( 5 )
expect( $imgs.eq( 0 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' )
expect( $imgs.eq( 1 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' )
expect( $imgs.eq( 2 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' )
expect( $imgs.eq( 3 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' )
} );
} );
} );
54 changes: 29 additions & 25 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ public function __construct() {
*/
public function register_public_actions() {
add_action( 'wp_head', array( $this, 'generator' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch' ), 10, 2 );

if ( $this->settings->use_lazyload() ) {
add_filter( 'body_class', array( $this, 'adds_body_classes' ) );
add_action( 'wp_head', array( $this, 'inline_bootstrap_script' ) );
if ( ! $this->settings->use_lazyload() ) {
return;
}
if ( Optml_Manager::should_ignore_image_tags() ) {
return;
}
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_filter( 'body_class', array( $this, 'adds_body_classes' ) );
add_action( 'wp_head', array( $this, 'inline_bootstrap_script' ) );

}

/**
Expand Down Expand Up @@ -85,7 +90,15 @@ public function inline_bootstrap_script() {
-o-transition: .2s filter linear, .2s opacity linear, .2s border-radius linear;
}
img[data-opt-src]:not([data-opt-lazy-loaded]) {
opacity: .75;
opacity: .75;
-webkit-filter: blur(8px);
-moz-filter: blur(8px);
-o-filter: blur(8px);
-ms-filter: blur(8px);
filter: blur(8px);
transform: scale(1.04);
animation: 0.1s ease-in;
-webkit-transform: translate3d(0, 0, 0);
}
</style>
Expand Down Expand Up @@ -226,7 +239,7 @@ public function add_notice_upgrade() {
<div class="notice notice-warning optml-notice-optin">
<p> <?php printf( __( 'It seems your are close to the %1$s5.0000%2$s visits limit with %3$sOptiMole%4$s for this month. You might want to check the upgrade plans for a larger quota. %5$s %6$s What happens if i exceed the quota ?%7$s We will need to deliver back your original %8$sun-optimized%9$s images which might decrease your site speed perfomance.', 'optimole-wp' ), '<strong>', '</strong>', '<strong>', '</strong>', '<br/><br/>', '<i>', '</i >', '<strong>', '</strong>' ); ?></p>
<p>
<a href="https://optimole.com/#pricing" target="_blank" class="button button-primary"><span
<a href="https://optimole.com/pricing" target="_blank" class="button button-primary"><span
class="dashicons dashicons-external"></span><?php _e( 'Check upgrade plans', 'optimole-wp' ); ?>
</a>
<a class="button"
Expand Down Expand Up @@ -318,10 +331,6 @@ protected function get_background_lazy_css() {
* Enqueue frontend scripts.
*/
public function frontend_scripts() {

if ( ! $this->settings->use_lazyload() ) {
return;
}
$bg_css = $this->get_background_lazy_css();

wp_register_style( 'optm_lazyload_noscript_style', false );
Expand Down Expand Up @@ -374,16 +383,6 @@ public function generator() {
return;
}
echo '<meta name="generator" content="Optimole ' . esc_attr( OPTML_VERSION ) . '">';

if ( ! current_theme_supports( 'custom-logo' ) ) {
return;
}
$custom_logo_id = get_theme_mod( 'custom_logo' );
$image = wp_get_attachment_image_src( $custom_logo_id, 'full' );
if ( empty( $image ) ) {
return;
}
echo '<link rel="preload" href="' . esc_url( $image[0] ) . '" as="image">';
}

/**
Expand Down Expand Up @@ -428,7 +427,7 @@ public function add_dns_prefetch( $hints, $relation_type ) {
}
$hints[] = sprintf( 'https://%s', $this->settings->get_cdn_url() );

if ( $this->settings->use_lazyload() ) {
if ( ! $this->settings->use_lazyload() && ! Optml_Manager::should_ignore_image_tags() ) {
$hints[] = sprintf( 'https://%s', OPTML_JS_CDN );
}

Expand Down Expand Up @@ -559,6 +558,11 @@ private function get_dashboard_strings() {
'<a href="https://docs.optimole.com/article/1134-how-optimole-counts-the-number-of-visitors" target="_blank">',
'</a>'
),
'account_needed_subtitle_3' => sprintf(
__( 'Here’s %1$show%2$s to install Optimole on your WordPress site in 3 steps.', 'optimole-wp' ),
'<a target="_blank" href="https://docs.optimole.com/article/1173-how-to-get-started-with-optimole-in-just-3-steps">',
'</a>'
),
'account_needed_subtitle_2' => sprintf(
__( 'Bonus, if you dont use a CDN, we got you covered, we will serve the images using CloudFront CDN.', 'optimole-wp' )
),
Expand Down Expand Up @@ -588,10 +592,10 @@ private function get_dashboard_strings() {
),
'upgrade' => array(
'title' => __( 'Upgrade to Pro', 'optimole-wp' ),
'reason_1' => __( 'Faster CDN ( 180+ locations )', 'optimole-wp' ),
'reason_2' => __( 'Larger traffic bandwidth', 'optimole-wp' ),
'reason_3' => __( 'Optimize more images', 'optimole-wp' ),
'reason_4' => __( 'Custom domain', 'optimole-wp' ),
'reason_1' => __( 'More CDN locations( 200+ locations )', 'optimole-wp' ),
'reason_4' => __( 'Starting at $4.99 per month.', 'optimole-wp' ),
'reason_2' => __( 'Optimize more images', 'optimole-wp' ),
'reason_3' => __( 'Custom domain', 'optimole-wp' ),
'cta' => __( 'View plans', 'optimole-wp' ),
),
'options_strings' => array(
Expand Down
2 changes: 1 addition & 1 deletion inc/app_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static function possible_lazyload_flags() {
return self::$ignore_lazyload_strings;
}

self::$possible_src_attributes = apply_filters( 'optml_possible_lazyload_flags', [ 'skip-lazy' ] );
self::$possible_src_attributes = apply_filters( 'optml_possible_lazyload_flags', [ 'skip-lazy', 'data-skip-lazy' ] );

return array_merge( self::$possible_src_attributes, [ '<noscript' ] );
}
Expand Down
48 changes: 48 additions & 0 deletions inc/cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* CLI class.
*
* Author: Bogdan Preda <[email protected]>
* Created on: 19/07/2018
*
* @package \Optimole\Inc
* @author Optimole <[email protected]>
*/

/**
* Class Optml_Cli
*/
class Optml_Cli {

/**
* Api version.
*
* @var string Version string.
*/
const CLI_NAMESPACE = 'optimole';

/**
* CLI controllers
*
* @var array List of CLI controllers.
*/
private $commands = array(
'setting',
);

/**
* Optml_Cli constructor.
*/
public function __construct() {
foreach ( $this->commands as $command ) {
$class_name = 'Optml_Cli_' . ucfirst( $command );
$controller = new $class_name();
try {
\WP_CLI::add_command( self::CLI_NAMESPACE . ' ' . $command, $controller );
} catch ( \Exception $e ) {
// TODO Log this exception.
}
}
}
}
144 changes: 144 additions & 0 deletions inc/cli/cli_setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php
/**
* CLI commands responsible for the Optimole settings.
*/

if ( ! class_exists( 'WP_CLI' ) ) {
return;
}

/**
* Class Optml_Cli_Setting
*/
class Optml_Cli_Setting extends WP_CLI_Command {
/**
* Holds an array of possible settings to alter.
*
* @var array Whitelisted settings.
*/
public static $whitelisted_settings = [
'image_replacer' => 'bool',
'quality' => 'int',
'lazyload' => 'bool',
'lazyload_placeholder' => 'bool',
];

/**
* Connect to service
* <apikey>
* : The api key to use.
*/
public function connect( $args ) {
if ( empty( $args ) || ! isset( $args[0] ) || $args[0] === '' ) {
return \WP_CLI::error( 'No argument passed. Required one argument ( api key )' );
}

if ( sizeof( $args ) > 1 ) {
return \WP_CLI::error( 'To many arguments passed' );
}

$api_key = $args[0];

$request = new Optml_Api();
$data = $request->get_user_data( $api_key );
if ( $data === false || is_wp_error( $data ) ) {
$extra = '';
if ( is_wp_error( $data ) ) {
/**
* Error from api.
*
* @var WP_Error $data Error object.
*/
$extra = sprintf( __( '. ERROR details: %s', 'optimole-wp' ), $data->get_error_message() );
}

return \WP_CLI::error( __( 'Can not connect to Optimole service', 'optimole-wp' ) . $extra );
}
$settings = new Optml_Settings();
$settings->update( 'service_data', $data );
$settings->update( 'api_key', $api_key );

\WP_CLI::success( sprintf( 'Connected API key %s to Optimole Service', $args[0] ) );
}

/**
* Disconnect from service.
*/
public function disconnect() {
$settings = new Optml_Settings();
$settings->reset();
\WP_CLI::success( 'Disconnected from Optimole Service' );
}

/**
* Update settings.
*
* <setting_name>
* : The setting name to update.
*
* <setting_value>
* : The setting value to update.
*/
public function update( $args ) {
if ( empty( $args ) || ! isset( self::$whitelisted_settings[ $args[0] ] ) ) {
\WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( self::$whitelisted_settings ) ) ) );

return false;
}

if ( self::$whitelisted_settings[ $args[0] ] === 'bool' && ( empty( $args ) || ! isset( $args[1] ) || $args[1] === '' || ! in_array(
$args[1],
array(
'on',
'off',
)
) ) ) {
return \WP_CLI::error( 'No argument passed. Required one argument ( on/off )' );
}

if ( self::$whitelisted_settings[ $args[0] ] === 'int' && ( empty( $args ) || ! isset( $args[1] ) || $args[1] === '' || (int) $args[1] > 100 || (int) $args[1] < 0 ) ) {
return \WP_CLI::error( 'Invalid argument, must be between 0 and 100.' );
}

$value = ( self::$whitelisted_settings[ $args[0] ] === 'bool' ) ? ( $args[1] === 'on' ? 'enabled' : 'disabled' ) : (int) $args[1];

$new_value = $this->update_setting( array( $args[0] => $value ) );
\WP_CLI::success( sprintf( 'Setting %s updated to: %s', $args[0], $new_value[ $args[0] ] ) );
}

/**
* Check settings.
*
* <setting_name>
* : The setting name to check.
*/
public function get( $args ) {
if ( empty( $args ) || ! isset( self::$whitelisted_settings[ $args[0] ] ) ) {
\WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( self::$whitelisted_settings ) ) ) );

return false;
}

$value = ( new Optml_Settings() )->get( $args[0] );

\WP_CLI::success( sprintf( 'Setting %s is set to: %s', $args[0], $value ) );
}


/**
* Utility method to update setting
*
* @param mixed $new_setting The setting to parse.
*
* @return array
*/
private function update_setting( $new_setting ) {
if ( empty( $new_setting ) ) {
\WP_CLI::error( __( 'No setting to update', 'optimole-wp' ) );
}
$settings = new Optml_Settings();

return $settings->parse_settings( $new_setting );
}

}
Loading

0 comments on commit f8778c4

Please sign in to comment.