Skip to content

Commit

Permalink
Merge pull request #190 from AdTechMedia/dev
Browse files Browse the repository at this point in the history
Add localization and multiple currencies per countries
  • Loading branch information
AlexanderC authored Aug 9, 2017
2 parents 17bde8f + 4fcaaef commit 94b1292
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 103 deletions.
8 changes: 4 additions & 4 deletions src/adtechmedia-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ class Adtechmedia_Config {
'tpl_mgmt_js_url' => 'https://manage.adtechmedia.io/atm-admin/atm-build/atmTplManager.js',
'terms_url' => 'https://www.adtechmedia.io/terms/dialog.html',
'register_url_tpl' => 'https://manage.adtechmedia.io/accounts/signup/%s',
'price' => 5,
'price' => 0.05,
'content_offset' => 2,
'payment_pledged' => 2,
'ads_video' => 'https://manage.adtechmedia.io/atm-admin/atm-build/demo-vast.xml',
'content_lock' => 'blur+scramble',
'revenue_method' => 'advertising+micropayments',
'revenue_method' => 'advertising+micropayments', // @todo change it to 'micropayments+subscriptions' when subscriptions implemented
'price_currency' => 'usd',
'content_paywall' => 'transactions',
'content_offset_type' => 'paragraphs',
'country' => 'United States',
'platform_id' => 'Wordpress',
'updated_appearance' => '0',
'platform_id' => 'Wordpress',
'updated_appearance' => '0',
'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 Down
4 changes: 2 additions & 2 deletions src/adtechmedia-lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ protected function ensure_database_tables() {
`option_value` LONGTEXT NOT NULL ,
PRIMARY KEY (`id`),
UNIQUE INDEX `option_name` (`option_name`)
)"
) DEFAULT CHARSET=utf8 DEFAULT COLLATE utf8_unicode_ci"
);
// @codingStandardsIgnoreEnd
$table_name = $this->prefix_table_name( Adtechmedia_Config::get( 'plugin_cache_table_name' ) );
Expand All @@ -282,7 +282,7 @@ protected function ensure_database_tables() {
`value` LONGTEXT NOT NULL ,
PRIMARY KEY (`id`),
UNIQUE INDEX `item_id` (`item_id`)
)"
) DEFAULT CHARSET=utf8 DEFAULT COLLATE utf8_unicode_ci"
);
// @codingStandardsIgnoreEnd
}
Expand Down
39 changes: 0 additions & 39 deletions src/adtechmedia-optionsmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,49 +534,10 @@ public function settings_page() {
$main_data_class = get_class( $this ) . '-main-settings-group';
$plugin_meta_data_class = get_class( $this ) . '-data-settings-group';

// Save Posted Options.
if ( isset( $_POST['option_page'] )
&& isset( $_POST['_wpnonce'] )
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), $main_data_class . '-options' )
&& sanitize_text_field( wp_unslash( $_POST['option_page'] ) ) == $main_data_class
) {
$this->try_to_save_post( $main_data, $_POST );
Adtechmedia_Request::property_update(
$this->get_plugin_option( 'id' ),
$this->get_plugin_option( 'support_email' ),
$this->get_plugin_option( 'country' ),
$this->get_plugin_option( 'key' )
);
$this->update_prop();
} elseif ( isset( $_POST['option_page'] )
&& isset( $_POST['_wpnonce'] )
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), $plugin_meta_data_class . '-options' )
&& sanitize_text_field( wp_unslash( $_POST['option_page'] ) ) == $plugin_meta_data_class
) {
$this->try_to_save_post( $plugin_meta_data, $_POST );
$this->update_prop();
}

Adtechmedia_Plugin::api_to_plugin_options();
require_once 'views/admin.php';
}

/**
* Try to save data from request
*
* @param array $options request data.
* @param array $post request data.
*/
public function try_to_save_post( $options, $post ) {
if ( null != $options ) {
foreach ( $options as $a_option_key => $a_option_meta ) {
if ( isset( $post[ $a_option_key ] ) ) {
$this->update_plugin_option( $a_option_key, $post[ $a_option_key ] );
}
}
}
}

/**
* Helper-function outputs the correct form element (input tag, select tag) for the given item
*
Expand Down
87 changes: 41 additions & 46 deletions src/adtechmedia-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ public function api_to_plugin_options() {
$this->update_from_api_option( 'price_currency', $api_result['Config']['defaults']['payment']['currency'] );
$this->update_from_api_option( 'content_paywall', $pleded_types[ $api_result['Config']['defaults']['payment']['pledgedType'] ] );
$this->update_from_api_option( 'content_offset_type', $api_result['Config']['defaults']['content']['offsetType'] );

$plugin_dir = plugin_dir_path( __FILE__ );
$file = $plugin_dir . '/js/atm.min.js';
// @codingStandardsIgnoreStart
@unlink( $file );
// @codingStandardsIgnoreEnd

}
}

Expand Down Expand Up @@ -261,14 +268,6 @@ public function add_actions_and_filters() {

$property_check = $this->check_prop();

if ( ! $key_check ) {
add_action( 'admin_notices',
array(
&$this,
'key_not_exists_error',
)
);
}
if ( ! $property_check ) {
add_action( 'admin_notices',
array(
Expand Down Expand Up @@ -340,17 +339,6 @@ public function add_actions_and_filters() {
);
}

/**
* Call function update_appearance after activation
*/
public function one_update_appearance() {
if ( ! empty( $this->get_plugin_option( 'key' ) ) ) {
$this->update_appearance();
$this->add_plugin_option( 'updated_appearance', 1 );
}
wp_die();
}

/**
* The first init function Adtechmedia_AB
*/
Expand Down Expand Up @@ -461,10 +449,6 @@ public function ajax_save_template() {
if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'adtechmedia-nonce' ) ) {
// @codingStandardsIgnoreStart
if ( isset( $_POST['revenueMethod'], $_POST['country'] ) ) {
$plugin_dir = plugin_dir_path( __FILE__ );
$file = $plugin_dir . '/js/atm.min.js';
@unlink( $file );

$revenue_method = sanitize_text_field( wp_unslash( $_POST['revenueMethod'] ) );
$this->update_plugin_option( 'revenue_method', $revenue_method );

Expand All @@ -474,20 +458,24 @@ public function ajax_save_template() {
$country = sanitize_text_field( wp_unslash( $_POST['country'] ) );
$this->update_plugin_option( 'country', $country );

Adtechmedia_Request::property_update_config_by_array(
$this->get_plugin_option( 'id' ),
$this->get_plugin_option( 'key' ),
[
'revenueMethod' => $revenue_method,
]
);
$currency = sanitize_text_field( wp_unslash( $_POST['currency'] ) );
$this->update_plugin_option( 'price_currency', $currency );

// Adtechmedia_Request::property_update_config_by_array(
// $this->get_plugin_option( 'id' ),
// $this->get_plugin_option( 'key' ),
// [
// 'revenueMethod' => $revenue_method,
// ]
// );
Adtechmedia_Request::property_update(
$this->get_plugin_option( 'id' ),
$this->get_plugin_option( 'support_email' ),
$this->country_full_to_UN( $country ),
$this->get_plugin_option( 'key' )
);
Adtechmedia_ContentManager::clear_all_content();
$this->update_prop();
// Adtechmedia_ContentManager::clear_all_content();
} else if ( isset( $_POST['contentConfig'] ) ) {
$content_config = json_decode( wp_unslash( $_POST['contentConfig'] ), true );
foreach ( $content_config as $a_option_key => $a_option_meta ) {
Expand All @@ -503,7 +491,18 @@ public function ajax_save_template() {
// @codingStandardsIgnoreEnd
echo 'ok';
}
die();
wp_die();
}

/**
* Call function update_appearance after activation
*/
public function one_update_appearance() {
if ( ! empty( $this->get_plugin_option( 'key' ) ) ) {
$this->update_appearance();
$this->add_plugin_option( 'updated_appearance', 1 );
}
wp_die();
}

/**
Expand Down Expand Up @@ -726,6 +725,15 @@ public function content_wrapper( $content ) {
$content_id = (string) get_the_ID();
$author_name = get_the_author();
$author_avatar = get_avatar_url( get_the_author_meta( 'user_email' ) );
$country = $this->get_plugin_option( 'country' );
$locale = null;
switch ( $country ) {
case 'Romania':
$locale = 'ro';
break;
default:
$locale = 'en';
}
$script = "<script>
window.ATM_FORCE_NOT_LOCALHOST = true;
window.ATM_PROPERTY_ID = '$property_id';
Expand All @@ -734,6 +742,7 @@ public function content_wrapper( $content ) {
window.WP_ATM_AUTHOR_NAME = '$author_name';
window.WP_ATM_AUTHOR_AVATAR = '$author_avatar';
window.ATM_SERVICE_WORKER = '/sw.min.js';
window.ATM_LOCALE = '$locale';
</script>";

return "<span id='content-for-atm-modal'>&nbsp;</span><span id='content-for-atm'>$content</span>" . $script;
Expand All @@ -754,18 +763,4 @@ public function property_id_not_exists_error() {
// @codingStandardsIgnoreEnd
}

/**
* Show error if API key not exists
*/
public function key_not_exists_error() {
// @codingStandardsIgnoreStart
?>
<div class="error notice">
<p><?php echo $this->key_error ?: __( 'An error occurred. API key has not been created, please reload the page or contact support service at <a href="mailto:[email protected]">[email protected]</a>.',
'adtechmedia-plugin'
); ?></p>
</div>
<?php
// @codingStandardsIgnoreEnd
}
}
3 changes: 2 additions & 1 deletion src/adtechmedia-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ private static function get_pledged_type( $pledged_type ) {
private static function get_offset_type( $offset_type ) {
$types = [
'words' => 'words',
'paragraphs' => 'elements',
'paragraphs' => 'elements', // legacy...
'elements' => 'elements',
];
return $types[ $offset_type ];
}
Expand Down
2 changes: 1 addition & 1 deletion src/adtechmedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: AdTechMedia
* Plugin URI: https://wordpress.org/plugins/adtechmedia/
* Version: 0.10.8
* Version: 0.12.0
* Author: AdTechMedia.io
* Description: AdTechMedia is an advertising platform with micropayments capabilities for media content monetization. We help publishers and content providers to generate complimentary revenue streams that are immune to ad blocking software (e.g. native advertising or native micropayments). Our solutions are white labeled, data driven and realtime. To learn more, contact [email protected] or visit www.adtechmedia.io.
* Text Domain: adtechmedia
Expand Down
3 changes: 1 addition & 2 deletions src/css/main.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@charset "UTF-8";
@font-face {
font-family: FuturaICG;
src: url(../fonts/FuturaICG.ttf);
src: url(../fonts/FuturaICG.woff);
}

.flex-item-1 {
Expand Down Expand Up @@ -1578,7 +1578,6 @@ select {
}
}

/*# sourceMappingURL=main.css.map */
.btn.disabled, .disabled.btn-large, .btn-floating.disabled, .btn-large.disabled, .btn-flat.disabled, .btn:disabled, .btn-large:disabled, .btn-floating:disabled, .btn-large:disabled, .btn-flat:disabled, .btn[disabled], .btn-large[disabled], .btn-floating[disabled], .btn-large[disabled], .btn-flat[disabled] {
background-color: #dfdfdf !important;
box-shadow: none;
Expand Down
Binary file removed src/fonts/FuturaICG.ttf
Binary file not shown.
Binary file added src/fonts/FuturaICG.woff
Binary file not shown.
74 changes: 70 additions & 4 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Created by yama_gs on 21.10.2016.
*/

/*eslint no-useless-concat: 0, no-undef: 0, no-unused-expressions: 0*/
/*eslint no-useless-concat: 0, no-undef: 0, no-unused-expressions: 0, complexity: [2, 10] */

function throttle(func, ms) {
var isThrottled = false,
Expand Down Expand Up @@ -160,6 +160,15 @@ function addValidate(form, rules, messages) {
});
}

jQuery.validator.addMethod(
'regex',
function(value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
'Please check your input.'
);

function showError() {
notify(
'error',
Expand Down Expand Up @@ -216,7 +225,8 @@ jQuery().ready(function() {
nonce: save_template.nonce,
revenueMethod: jQuery('select[name="revenue_method"]').val(),
abPercentage: jQuery('input[name="ab_percentage"]').val(),
country: jQuery('select[name="country"]').val()
country: jQuery('select[name="country"]').val(),
currency: jQuery('#price_currency').val()
},
success: function(response) {
removeLoader(btn);
Expand Down Expand Up @@ -244,14 +254,70 @@ jQuery().ready(function() {
.attr('value', value).text(value));
});
});

$price = jQuery('#price');
$price.keypress(function(event) {
var $this = jQuery(this);
var text = $this.val();

if ((event.which !== 46 || text.indexOf('.') !== -1)
&& ((event.which < 48 || event.which > 57)
&& (event.which !== 0 && event.which !== 8))) {
event.preventDefault();
}
if (parseInt(text) > 9999999) {
event.preventDefault();
}
if ((text.split('.')[0].length === 0) && ((event.which === 46) || (event.which === 47))) {
$this.val('0.');
event.preventDefault();
}
if ((event.which === 46) && (text.indexOf('.') === -1)) {
setTimeout(function() {
if ($this.val().substring(text.indexOf('.')).length > 3) {
$this.val($this.val().substring(0, $this.val().indexOf('.') + 3));
}
}, 1);
}
if ((text.indexOf('.') !== -1) &&
(text.substring(text.indexOf('.')).length > 2) &&
(event.which !== 0 && event.which !== 8) &&
(jQuery(this)[0].selectionStart >= text.length - 2)) {
event.preventDefault();
}
});

$price.bind('paste', function(e) {
var text = e.originalEvent.clipboardData.getData('Text');
if (jQuery.isNumeric(text)) {
if ((text.substring(text.indexOf('.')).length > 3) && (text.indexOf('.') > -1)) {
e.preventDefault();
jQuery(this).val(text.substring(0, text.indexOf('.') + 3));
}
}
else {
e.preventDefault();
}
});

$pristine = jQuery('#payment_pledged, #content_offset');
$pristine.keyup(function(event) {
var $this = jQuery(this);
var text = $this.val();
if (text.length > 7) { event.preventDefault(); }
if ((text.indexOf('.') !== -1) || (text.length > 7)) {
$this.val($this.val().replace('.','').substring(0,7));
event.preventDefault();
}
});

jQuery('#content-config button').bind('click', function(e) {
var btn = jQuery(this);

var valid = addValidate(jQuery('#content-config'), {
price: {
required: true,
digits: true,
min: 1
regex: '^([0-9]{1,7})?(\.|,)?([0-9]{1,2})$'
},
payment_pledged: {
required: true,
Expand Down
Loading

0 comments on commit 94b1292

Please sign in to comment.