Skip to content

Commit d97ea40

Browse files
release: fixes
- Fixed issue with HTML tags not working in the description field - Fixed duplicate data names error - Fixed input label escaping issue - Updated dependencies
2 parents c7d86ac + 3766722 commit d97ea40

16 files changed

+91
-105
lines changed

backend/settings-panel.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,8 @@ public function load_scripts() {
812812
PPOM_SCRIPTS::enqueue_script( 'nmsf-settings-panel' );
813813

814814
$this->set_localize_data( 'nmsf-settings-panel', 'nmsf_vars' );
815+
816+
do_action( 'themeisle_internal_page', PPOM_PRODUCT_SLUG, 'settings' );
815817
}
816818

817819

classes/fields.class.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ function load_script( $hook ) {
201201
// localize ppom_vars
202202
wp_localize_script( 'ppom-field', 'ppom_vars', $ppom_admin_meta );
203203
wp_localize_script( 'ppom-meta-table', 'ppom_vars', $ppom_admin_meta );
204+
205+
$action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
206+
$page_slug = 'fields';
207+
208+
if ( 'new' === $action ) {
209+
$page_slug = 'new-field';
210+
} elseif( 'edit' === $action ) {
211+
$page_slug = 'edit-field';
212+
}
213+
214+
do_action( 'themeisle_internal_page', PPOM_PRODUCT_SLUG, $page_slug );
204215
}
205216

206217

classes/input-meta.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function field_label( $tooltip = true, $desc = true, $asterisk = true ) {
155155

156156
$asterisk_symbol = ( ! empty( $this->required() ) && $this->title() != '' ) ? '<span class="show_required"> *</span>' : '';
157157

158-
$show_desc = ( ! empty( $this->desc() ) ) ? '<span class="show_description ppom-input-desc">' . wp_strip_all_tags( html_entity_decode( $this->desc() ) ) . '</span>' : '';
158+
$show_desc = ( ! empty( $this->desc() ) ) ? '<span class="show_description ppom-input-desc">' . $this->desc() . '</span>' : '';
159159

160160
if ( $desc ) {
161161
$show_desc = apply_filters( 'ppom_field_description', $show_desc, self::$input_meta );

classes/plugin.class.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,24 @@ function get_product_meta_all() {
623623
return $res;
624624
}
625625

626+
/**
627+
* Get the count of all the created PPOM Group fields.
628+
*
629+
* @param int $limit Optional limit on number of results to count
630+
* @return int - The number of group fields in the database.
631+
*/
632+
public static function get_product_meta_count( $limit = null ) {
633+
global $wpdb;
634+
635+
$qry = 'SELECT COUNT(*) FROM ' . $wpdb->prefix . PPOM_TABLE_META;
636+
if ($limit !== null) {
637+
$qry .= ' LIMIT ' . intval($limit);
638+
}
639+
$count = $wpdb->get_var($qry);
640+
641+
return intval($count);
642+
}
643+
626644
function get_product_meta( $meta_id ) {
627645

628646
if ( ! $meta_id ) {

classes/ppom.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function get_meta_id( $product_id ) {
204204
}
205205
}
206206

207-
return apply_filters( 'ppom_product_meta_id', $ppom_product_id, $product_id );
207+
return apply_filters( 'ppom_product_meta_id', is_array( $ppom_product_id ) ? array_unique( $ppom_product_id ) : $ppom_product_id, $product_id );
208208
}
209209

210210
// Properties functions

classes/survey.class.php

Lines changed: 34 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
*/
1515
class PPOM_Survey {
1616

17+
/**
18+
* The maximum limit of created groups to count. Used in the duration of the cached value.
19+
*
20+
* @var int
21+
*/
22+
public const GROUPS_COUNT_LIMIT = 100;
23+
1724
/**
1825
* Reference to singleton insance.
1926
*
@@ -25,7 +32,7 @@ class PPOM_Survey {
2532
* Init hooks.
2633
*/
2734
public function init() {
28-
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
35+
add_filter( 'themeisle-sdk/survey/' . PPOM_PRODUCT_SLUG, array( $this, 'get_survey_metadata' ), 10, 2 );
2936
}
3037

3138
/**
@@ -44,91 +51,46 @@ public static function get_instance() {
4451
* @return array
4552
* @see survey.js
4653
*/
47-
public function get_survey_metadata() {
48-
$license_data = get_option( 'ppom_pro_license_data', array() );
49-
$attributes = array();
50-
$user_id = 'ppom_' . ( ! empty( $license_data->key ) ? $license_data->key : preg_replace( '/[^\w\d]*/', '', get_site_url() ) ); // Use a normalized version of the site URL as a user ID for free users.
51-
52-
$days_since_install = round( ( time() - get_option( 'woocommerce_product_addon_install', 0 ) ) / DAY_IN_SECONDS );
53-
$install_category = 0; // Normalized value.
54-
if ( 0 === $days_since_install || 1 === $days_since_install ) {
55-
$install_category = 0;
56-
} elseif ( 1 < $days_since_install && 8 > $days_since_install ) {
57-
$install_category = 7;
58-
} elseif ( 8 <= $days_since_install && 31 > $days_since_install ) {
59-
$install_category = 30;
60-
} elseif ( 30 < $days_since_install && 90 > $days_since_install ) {
61-
$install_category = 90;
62-
} elseif ( 90 <= $days_since_install ) {
63-
$install_category = 91;
54+
public function get_survey_metadata( $data, $page_slug ) {
55+
if ( defined( 'CYPRESS_TESTING' ) ) {
56+
return $data;
6457
}
6558

66-
$attributes['days_since_install'] = strval( $install_category );
67-
$attributes['license_status'] = ! empty( $license_data->license ) ? $license_data->license : 'invalid';
68-
$attributes['free_version'] = PPOM_VERSION;
59+
$license_status = apply_filters( 'product_ppom_license_status', 'invalid' );
60+
$license_plan = intval( apply_filters( 'product_ppom_license_plan', -1 ) );
61+
$license_key = apply_filters( 'product_ppom_license_key', '' );
62+
$group_fields_count = get_transient( PPOM_GROUPS_COUNT_CACHE_KEY );
6963

70-
if ( ! empty( $license_data->plan ) ) {
71-
$attributes['plan'] = $this->plan_category( $license_data );
64+
if ( false === $group_fields_count ) {
65+
$group_fields_count = NM_PersonalizedProduct::get_product_meta_count( self::GROUPS_COUNT_LIMIT );
66+
set_transient( PPOM_GROUPS_COUNT_CACHE_KEY, $group_fields_count, self::GROUPS_COUNT_LIMIT === $group_fields_count ? WEEK_IN_SECONDS : 12 * HOUR_IN_SECONDS );
7267
}
7368

74-
if ( defined( 'PPOM_PRO_VERSION' ) ) {
75-
$attributes['pro_version'] = PPOM_PRO_VERSION;
76-
}
69+
$install_days_number = intval( ( time() - get_option( 'woocommerce_product_addon_install', time() ) ) / DAY_IN_SECONDS );
7770

78-
return array(
79-
'userId' => $user_id,
80-
'attributes' => $attributes,
71+
$data = array(
72+
'environmentId' => 'clza3s4zm000h10km1699nlli',
73+
'attributes' => array(
74+
'install_days_number' => $install_days_number,
75+
'free_version' => PPOM_VERSION,
76+
'license_status' => $license_status,
77+
'field_groups_count' => intval( $group_fields_count )
78+
)
8179
);
82-
}
83-
84-
/**
85-
* Enqueue scripts.
86-
*/
87-
public function enqueue_scripts() {
88-
89-
if ( defined( 'CYPRESS_TESTING' ) ) {
90-
return;
91-
}
9280

93-
$survey_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'survey' );
94-
if ( empty( $survey_handler ) ) {
95-
return;
81+
if ( 1 <= $license_plan ) {
82+
$data['attributes']['plan'] = NM_PersonalizedProduct::get_license_category( $license_plan );
9683
}
9784

98-
do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' );
99-
wp_enqueue_script( 'ppom_survey', PPOM_URL . '/js/survey.js', array( $survey_handler ), PPOM_VERSION, true );
100-
wp_localize_script( 'ppom_survey', 'PPOMSurveyData', $this->get_survey_metadata() );
101-
}
102-
103-
/**
104-
* Get the plan category for the product plan ID.
105-
*
106-
* @param object $license_data The license data.
107-
* @return int
108-
*/
109-
private static function plan_category( $license_data ) {
110-
111-
if ( ! isset( $license_data->plan ) || ! is_numeric( $license_data->plan ) ) {
112-
return 0; // Free.
85+
if ( ! empty( $license_key ) ) {
86+
$data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', $license_key );
11387
}
11488

115-
$plan = (int) $license_data->plan;
116-
$current_category = -1;
117-
118-
$categories = array(
119-
'1' => array( 1, 4, 9 ), // Personal.
120-
'2' => array( 2, 5, 8 ), // Business/Developer.
121-
'3' => array( 3, 6, 7, 10 ), // Agency.
122-
);
123-
124-
foreach ( $categories as $category => $plans ) {
125-
if ( in_array( $plan, $plans, true ) ) {
126-
$current_category = (int) $category;
127-
break;
128-
}
89+
if ( defined( 'PPOM_PRO_VERSION' ) ) {
90+
$data['attributes']['pro_version'] = PPOM_PRO_VERSION;
12991
}
13092

131-
return $current_category;
93+
return $data;
13294
}
13395
}
13496
}

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inc/nmInput.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function Regular( $args, $default_value = '' ) {
155155
$html = '<div class="' . $input_wrapper_class . '">';
156156
if ( $label ) {
157157
$html .= '<label class="' . $this->get_default_setting_value( 'global', 'label_class', $id ) . '" for="' . $id . '">';
158-
$html .= esc_html( $label ) . '</label>';
158+
$html .= wp_kses( $label, array( 'span' => array( 'class' => true, 'data-*' => true, 'title' => true ) ) ) . '</label>';
159159
}
160160

161161
if ( $price !== '' ) {
@@ -235,7 +235,7 @@ public function Measure( $args, $default_value = '' ) {
235235
$html = '<div class="' . esc_attr( $input_wrapper_class ) . '">';
236236
if ( $label ) {
237237
$html .= '<label class="' . $this->get_default_setting_value( 'global', 'label_class', $id ) . '" for="' . $id . '">';
238-
$html .= esc_html( $label ) . '</label>';
238+
$html .= wp_kses( $label, array( 'span' => array( 'class' => true, 'data-*' => true, 'title' => true ) ) ) . '</label>';
239239
}
240240

241241
$classes .= ' ppom-measure-input';
@@ -1596,7 +1596,7 @@ public function Custom( $args, $default_value = '' ) {
15961596
$html = '<div class="' . $input_wrapper_class . '">';
15971597
if ( $label ) {
15981598
$html .= '<label class="' . $this->get_default_setting_value( 'global', 'label_class', $id ) . '" for="' . $id . '">';
1599-
$html .= esc_html( $label ) . '</label>';
1599+
$html .= wp_kses( $label, array( 'span' => array( 'class' => true, 'data-*' => true, 'title' => true ) ) ) . '</label>';
16001600
}
16011601

16021602
$html .= apply_filters( 'nmform_custom_input', $html, $args, $default_value );

inc/validation.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ function ppom_esc_html( $content ) {
3737
'onclick' => array(),
3838
'onchange' => array(),
3939
'onkeyup' => array(),
40+
'data-*' => array(),
41+
'style' => array(),
4042
);
4143
$allowedposttags['form'] = $allowed_atts;
4244
$allowedposttags['label'] = $allowed_atts;
@@ -72,6 +74,7 @@ function ppom_esc_html( $content ) {
7274
$allowedposttags['a'] = $allowed_atts;
7375
$allowedposttags['b'] = $allowed_atts;
7476
$allowedposttags['i'] = $allowed_atts;
77+
$allowedposttags['br'] = $allowed_atts;
7578
$allowed_tags = wp_kses_allowed_html( 'post' );
7679

7780
return wp_kses( stripslashes_deep( $content ), $allowed_tags );

js/survey.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)