Skip to content

Commit

Permalink
Merge pull request #108 from AdTechMedia/dev
Browse files Browse the repository at this point in the history
Release 0.10
  • Loading branch information
AlexanderC authored Jun 26, 2017
2 parents 7e6e4df + 2ade3e8 commit 6fe0b36
Show file tree
Hide file tree
Showing 13 changed files with 502 additions and 4,488 deletions.
22 changes: 11 additions & 11 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
eslintConfig:
root: true

ecmaFeatures:
modules: true
jsx: true
arrowFunctions: true
blockBindings: true
classes: true
defaultParams: true
# eslintConfig:
# root: true
#
# ecmaFeatures:
# modules: true
# jsx: true
# arrowFunctions: true
# blockBindings: true
# classes: true
# defaultParams: true

env:
amd: true
Expand Down Expand Up @@ -227,4 +227,4 @@ rules:
globals:
DeepFramework: true
Stripe: true
angular: true
angular: true
23 changes: 15 additions & 8 deletions src/adtechmedia-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ class Adtechmedia_Config {
'minDelay' => 150000,
'factor' => 1.7,
'atm_js_cache_time' => 86400,
'template_position' => '{"sticky":true,"width":"600px","offset_top":"20px","offset_left":"-60px","scrolling_offset_top":"100px"}',
'template_overall_styles_patch' => '@media (max-width: 991px) { .atm-targeted-container { width: 90% !important; left: 5% !important; transform: none !important; } } @media (max-width: 600px) { .atm-targeted-container { top: 0 !important; } }', /* @todo Replace responsive hotfix with smth sustainable and reliable */
'template_overall_styles' => '.atm-base-modal {background-color: #ffffff;}.atm-targeted-modal .atm-head-modal .atm-modal-heading {background-color: #ffffff;}.atm-targeted-modal{border: 1px solid #d3d3d3;}.atm-targeted-modal{box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1);}.atm-base-modal .atm-footer{background-color: #fafafa;}.atm-base-modal .atm-footer{border: 1px solid #e3e3e3;}.atm-targeted-container .mood-block-info,.atm-targeted-modal,.atm-targeted-modal .atm-head-modal .atm-modal-body p,.atm-unlock-line .unlock-btn {font-family: \'Merriweather\', sans-serif;}',
'template_overall_styles_inputs' => '{"background-color":"#ffffff","border":"1px solid #d3d3d3","font-family":"\'Merriweather\', sans-serif","box-shadow":"0 1px 2px 0 rgba(0, 0, 0, 0.1)","footer-background-color":"#fafafa","footer-border":"1px solid #e3e3e3"}',
'template_overall_styles_patch' => '@media (max-width: 991px) { .atm-targeted-container { width: 90% !important; left: 5% !important; transform: none !important; } } @media (max-width: 600px) { .atm-targeted-container { top: 0 !important; } }',
'sw_js_url' => 'https://www.adtechmedia.io/atm-admin/atm-build/sw.min.js',
'tpl_js_url' => 'https://www.adtechmedia.io/atm-core/atm-build/atmTpl.js',
'tpl_mgmt_js_url' => 'https://www.adtechmedia.io/atm-core/atm-build/atmTplManager.js',
'terms_url' => 'https://www.adtechmedia.io/terms/dialog.html',
'register_url_tpl' => 'https://www.adtechmedia.io/admin/accounts/signup/%s',
'price' => 5,
'content_offset' => 2,
'payment_pledged' => 2,
Expand All @@ -41,6 +42,8 @@ class Adtechmedia_Config {
'content_paywall' => 'transactions',
'content_offset_type' => 'paragraphs',
'country' => 'United States',
'platform_id' => 'Wordpress',
'appearance_settings' => '{"model":{"main":{"sticky":true,"width":"600px","offset":{"top":"20px","fromCenter":"-60px","scrollTop":"100"}},"body":{"backgroundColor":"#ffffff","border":"1px solid #d3d3d3","fontFamily":"\'Merriweather\', sans-serif","boxShadow":"0 1px 2px 0 rgba(0, 0, 0, 0.1)"},"footer":{"backgroundColor":"#fafafa","border":"1px solid #e3e3e3"}}}',
];

/**
Expand All @@ -57,10 +60,14 @@ public static function get( $name ) {
/**
* Set API end point for localhost
*/
public static function set_api_end_point() {
public static function setup_endpoints() {
if ( self::is_localhost() ) {
self::$conf['api_end_point'] = 'https://api-dev.adtechmedia.io/v1/';
self::$conf['sw_js_url'] = 'https://www-dev.adtechmedia.io/atm-admin/atm-build/sw.min.js';
self::$conf['api_end_point'] = 'https://api-dev.adtechmedia.io/v1/';
self::$conf['sw_js_url'] = 'https://www-dev.adtechmedia.io/atm-admin/atm-build/sw.min.js';
self::$conf['register_url_tpl'] = 'https://www-dev.adtechmedia.io/admin/accounts/signup/%s';
self::$conf['tpl_js_url'] = 'https://www-dev.adtechmedia.io/atm-core/atm-build/atmTpl.js';
self::$conf['tpl_mgmt_js_url'] = 'https://www-dev.adtechmedia.io/atm-core/atm-build/atmTplManager.js';
self::$conf['terms_url'] = 'https://www-dev.adtechmedia.io/terms/dialog.html';
}
}

Expand All @@ -77,4 +84,4 @@ public static function is_localhost() {
}
}

Adtechmedia_Config::set_api_end_point();
Adtechmedia_Config::setup_endpoints();
96 changes: 85 additions & 11 deletions src/adtechmedia-lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function install() {
$this->init_options();

// Initialize DB Tables used by the plugin.
$this->install_database_tables();
$this->ensure_database_tables();

// Other Plugin initialization - for the plugin writer to override as needed.
$this->other_install();
Expand All @@ -55,7 +55,7 @@ public function install() {
*/
public function uninstall() {
$this->other_uninstall();
$this->un_install_database_tables();
$this->un_ensure_database_tables();
$this->delete_saved_options();
$this->mark_as_un_installed();
}
Expand All @@ -75,6 +75,7 @@ public function upgrade() {
* @return void
*/
public function activate() {
$this->ensure_database_tables();
delete_transient( 'adtechmedia-supported-countries-new' );
$website = get_home_url();
$name = preg_replace( '/https?:\/\//', '', $website );
Expand All @@ -96,17 +97,16 @@ public function activate() {
$this->add_plugin_option( 'price_currency', Adtechmedia_Config::get( 'price_currency' ) );
$this->add_plugin_option( 'content_paywall', Adtechmedia_Config::get( 'content_paywall' ) );
$this->add_plugin_option( 'content_offset_type', Adtechmedia_Config::get( 'content_offset_type' ) );
$this->add_plugin_option( 'template_position', Adtechmedia_Config::get( 'template_position' ) );
$this->add_plugin_option( 'template_overall_styles_patch', Adtechmedia_Config::get( 'template_overall_styles_patch' ) );
$this->add_plugin_option( 'template_overall_styles', Adtechmedia_Config::get( 'template_overall_styles' ) );
$this->add_plugin_option( 'template_overall_styles_inputs', Adtechmedia_Config::get( 'template_overall_styles_inputs' ) );
$this->add_plugin_option( 'theme_config_id', 'default' );
$this->add_plugin_option( 'theme_config_name', '' );
$this->add_plugin_option( 'appearance_settings', Adtechmedia_Config::get( 'appearance_settings' ) );
try {
$this->check_api_key_exists();
$this->check_prop();

Adtechmedia_ThemeManager::init_theme_config_model();
if ( ! empty( $this->get_plugin_option( 'key' ) ) ) {
$this->update_prop();
$this->update_appearance();
}
} catch ( Error $error ) {
$this->activation_error = $error->getMessage();

Expand All @@ -123,6 +123,40 @@ public function activate() {
wp_schedule_event( time(), 'daily', 'adtechmedia_update_event' );
}

/**
* Update appearance settings
*/
public function update_appearance() {
$plugin_dir = plugin_dir_path( __FILE__ );
$file = $plugin_dir . '/js/atm.min.js';
// @codingStandardsIgnoreStart
@unlink( $file );
// @codingStandardsIgnoreEnd

$appearance_settings = json_decode( $this->get_plugin_option( 'appearance_settings' ), true );

$this->add_plugin_option( 'template_overall_styles', $this->get_template_overall_styles( $appearance_settings ) );

$data = [
'targetModal' => [
'targetCb' => $this->get_target_cb_js( $appearance_settings ),
'toggleCb' => $this->get_toggle_cb_js( $appearance_settings ),
],
'styles' => [
'main' => base64_encode(
$this->get_plugin_option( 'template_overall_styles' ) .
$this->get_plugin_option( 'template_overall_styles_patch' )
),
],
];
Adtechmedia_Request::property_update_config_by_array(
$this->get_plugin_option( 'id' ),
$this->get_plugin_option( 'key' ),
$data
);
Adtechmedia_ContentManager::clear_all_content();
}

/**
* Show error if activation failed
*/
Expand All @@ -144,12 +178,14 @@ public function activation_error() {
public function check_api_key_exists() {
$key = $this->get_plugin_option( 'key' );
if ( empty( $key ) ) {
$key = Adtechmedia_Request::api_key_create(
$key_response = Adtechmedia_Request::api_key_create(
$this->get_plugin_option( 'support_email' )
);
$key = $key_response['apiKey'];
if ( empty( $key ) ) {
return false;
} else {
$this->add_plugin_option( 'client-id', $key_response['clientId'] );
$this->add_plugin_option( 'key', $key );
}
}
Expand Down Expand Up @@ -223,7 +259,32 @@ public function add_actions_and_filters() {
*
* @return void
*/
protected function install_database_tables() {
protected function ensure_database_tables() {
global $wpdb;
$table_name = $this->prefix_table_name( Adtechmedia_Config::get( 'plugin_table_name' ) );
// @codingStandardsIgnoreStart
$wpdb->query(
"CREATE TABLE IF NOT EXISTS `$table_name` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`option_name` VARCHAR(191) NOT NULL DEFAULT '',
`option_value` LONGTEXT NOT NULL ,
PRIMARY KEY (`id`),
UNIQUE INDEX `option_name` (`option_name`)
)"
);
// @codingStandardsIgnoreEnd
$table_name = $this->prefix_table_name( Adtechmedia_Config::get( 'plugin_cache_table_name' ) );
// @codingStandardsIgnoreStart
$wpdb->query(
"CREATE TABLE IF NOT EXISTS `$table_name` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`item_id` VARCHAR(191) NOT NULL DEFAULT '',
`value` LONGTEXT NOT NULL ,
PRIMARY KEY (`id`),
UNIQUE INDEX `item_id` (`item_id`)
)"
);
// @codingStandardsIgnoreEnd
}

/**
Expand All @@ -232,7 +293,20 @@ protected function install_database_tables() {
*
* @return void
*/
protected function un_install_database_tables() {
protected function un_ensure_database_tables() {
global $wpdb;
$table_name = $this->prefix_table_name( Adtechmedia_Config::get( 'plugin_table_name' ) );
// @codingStandardsIgnoreStart
$wpdb->query(
"DROP TABLE IF EXISTS `$table_name`"
);
// @codingStandardsIgnoreEnd
$table_name = $this->prefix_table_name( Adtechmedia_Config::get( 'plugin_cache_table_name' ) );
// @codingStandardsIgnoreStart
$wpdb->query(
"DROP TABLE IF EXISTS `$table_name`"
);
// @codingStandardsIgnoreEnd
}

/**
Expand Down
51 changes: 41 additions & 10 deletions src/adtechmedia-optionsmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,24 +419,53 @@ public function update_prop() {
$this->get_plugin_option( 'payment_pledged' ),
$this->get_plugin_option( 'content_offset_type' ),
$this->get_plugin_option( 'price_currency' ),
$this->get_plugin_option( 'content_paywall' ),
$this->get_target_cb_js( json_decode( stripslashes( $this->get_plugin_option( 'template_position' ) ), true ) ),
$this->get_toggle_cb_js( json_decode( stripslashes( $this->get_plugin_option( 'template_position' ) ), true ) )
$this->get_plugin_option( 'content_paywall' )
);
Adtechmedia_ContentManager::clear_all_content();
}

/**
* Get overall styles
*
* @param array $appearance_settings array of position properties.
* @return string
*/
public function get_template_overall_styles( $appearance_settings ) {
return "
.atm-base-modal {
background-color: {$appearance_settings['model']['body']['backgroundColor']};
}
.atm-targeted-modal .atm-head-modal .atm-modal-heading {
background-color: {$appearance_settings['model']['body']['backgroundColor']};
}
.atm-targeted-modal {
position: relative;
border: {$appearance_settings['model']['body']['border']};
box-shadow: {$appearance_settings['model']['body']['boxShadow']};
}
.atm-base-modal .atm-footer {
background-color: {$appearance_settings['model']['footer']['backgroundColor']};
border: {$appearance_settings['model']['footer']['border']};
}
.atm-targeted-container .mood-block-info,.atm-targeted-modal,.atm-targeted-modal .atm-head-modal .atm-modal-body p,.atm-unlock-line .unlock-btn {
font-family: {$appearance_settings['model']['body']['fontFamily']};
}";
}

/**
* Get JS to targetCb function
*
* @param array $position array of position properties.
* @param array $appearance_settings array of position properties.
* @return string
*/
public function get_target_cb_js( $position ) {
public function get_target_cb_js( $appearance_settings ) {
$position = $appearance_settings['model']['main'];
$width = ! empty( $position['width'] ) ? $position['width'] : '600px';
$offset_top = ! empty( $position['offset_top'] ) ? $position['offset_top'] : '0px';
$offset_left = ! empty( $position['offset_left'] ) ? $position['offset_left'] : '0px';
$offset_top = ! empty( $position['offset']['top'] ) ? $position['offset']['top'] : '0px';
$offset_left = ! empty( $position['offset']['fromCenter'] ) ? $position['offset']['fromCenter'] : '0px';

$content = '';

if ( ! empty( $position['sticky'] ) ) {
$content .= "mainModal.rootNode.style.position = 'fixed';\n";
$content .= "mainModal.rootNode.style.top = '$offset_top';\n";
Expand Down Expand Up @@ -465,11 +494,13 @@ public function get_target_cb_js( $position ) {
/**
* Get JS to toggleCb function
*
* @param array $position array of position properties.
* @param array $appearance_settings array of position properties.
* @return string
*/
public function get_toggle_cb_js( $position ) {
$scrolling_offset_top = ! empty( $position['scrolling_offset_top'] ) ? (int) $position['scrolling_offset_top'] : 0;
public function get_toggle_cb_js( $appearance_settings ) {
$position = $appearance_settings['model']['main'];
$scrolling_offset_top = ! empty( $position['offset']['scrollTop'] ) ? (int) $position['offset']['scrollTop'] : 0;

if ( empty( $position['sticky'] ) ) {
$scrolling_offset_top = -10;
}
Expand Down
Loading

0 comments on commit 6fe0b36

Please sign in to comment.