Skip to content

Commit

Permalink
release: fixes
Browse files Browse the repository at this point in the history
### Fixes
- Reuse existing generated images before trying to generate new ones on import [PRO]
- Updated dependencies
- NPS Survey added
- Preparation for future BF campaign
  • Loading branch information
vytisbulkevicius authored Feb 27, 2024
2 parents 62a743b + 4524895 commit e9c80c6
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 126 deletions.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified img/black-friday-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
124 changes: 124 additions & 0 deletions includes/admin/feedzy-rss-feeds-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public function enqueue_styles_admin() {
wp_enqueue_script( $this->plugin_name . '_telemetry', FEEDZY_ABSURL . 'js/telemetry.js', array(), $this->version, true );
}

if ( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base ) {
$this->register_survey();
}

if ( 'feedzy_categories' === $screen->post_type ) {
wp_enqueue_script(
$this->plugin_name . '_categories',
Expand All @@ -152,6 +156,8 @@ public function enqueue_styles_admin() {
),
)
);

$this->register_survey();
}

if ( 'feedzy_page_feedzy-settings' === $screen->base ) {
Expand All @@ -171,6 +177,8 @@ public function enqueue_styles_admin() {
),
)
);

$this->register_survey();
}

$upsell_screens = array( 'feedzy-rss_page_feedzy-settings', 'feedzy-rss_page_feedzy-admin-menu-pro-upsell' );
Expand All @@ -195,6 +203,8 @@ public function enqueue_styles_admin() {
)
);
wp_enqueue_style( 'wp-block-editor' );

$this->register_survey();
}
if ( ! defined( 'TI_CYPRESS_TESTING' ) && ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type && feedzy_show_import_tour() ) ) {
wp_enqueue_script( $this->plugin_name . '_on_boarding', FEEDZY_ABSURL . 'js/Onboarding/import-onboarding.min.js', array( 'react', 'react-dom', 'wp-editor', 'wp-api', 'lodash' ), $this->version, true );
Expand All @@ -205,6 +215,9 @@ public function enqueue_styles_admin() {
}

if ( 'feedzy_page_feedzy-support' === $screen->base || ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type ) ) {

$this->register_survey();

wp_enqueue_script( $this->plugin_name . '_feedback', FEEDZY_ABSURL . 'js/FeedBack/feedback.min.js', array( 'react', 'react-dom', 'wp-editor', 'wp-api', 'lodash' ), $this->version, true );
wp_enqueue_style( 'wp-block-editor' );

Expand Down Expand Up @@ -1565,10 +1578,13 @@ public function api_license_status() {
'spinnerChiefStatus' => false,
'wordaiStatus' => false,
'openaiStatus' => false,
'amazonStatus' => false,
);

if ( ! feedzy_is_pro() ) {
return $data;
}

if ( apply_filters( 'feedzy_is_license_of_type', false, 'agency' ) ) {
if ( isset( $pro_options['spinnerchief_licence'] ) && 'yes' === $pro_options['spinnerchief_licence'] ) {
$data['spinnerChiefStatus'] = true;
Expand All @@ -1577,11 +1593,119 @@ public function api_license_status() {
$data['wordaiStatus'] = true;
}
}

if ( isset( $pro_options['openai_licence'] ) && 'yes' === $pro_options['openai_licence'] ) {
if ( apply_filters( 'feedzy_is_license_of_type', false, 'business' ) || apply_filters( 'feedzy_is_license_of_type', false, 'agency' ) ) {
$data['openaiStatus'] = true;
}
}

if ( ! empty( $pro_options['amazon_access_key'] ) && ! empty( $pro_options['amazon_secret_key'] ) ) {
$data['amazonStatus'] = true;
}
return $data;
}

/**
* Get the plan category for the product plan ID.
*
* @param object $license_data The license data.
* @return int
*/
private static function plan_category( $license_data ) {

if ( ! isset( $license_data->plan ) || ! is_numeric( $license_data->plan ) ) {
return 0; // Free
}

$plan = (int) $license_data->plan;
$current_category = -1;

$categories = array(
'1' => array(1, 4, 9), // Personal
'2' => array(2, 5, 8), // Business/Developer
'3' => array(3, 6, 7, 10), // Agency
);

foreach ( $categories as $category => $plans ) {
if ( in_array( $plan, $plans, true ) ) {
$current_category = (int) $category;
break;
}
}

return $current_category;
}

/**
* Get the data used for the survey.
*
* @return array
* @see survey.js
*/
public function get_survery_metadata() {

$user_id = 'feedzy_';
$license_data = get_option( 'feedzy_rss_feeds_pro_license_data', array() );

if ( ! empty( $license_data->key ) ) {
$user_id .= $license_data->key;
} else {
$user_id .= preg_replace( '/[^\w\d]*/', '', get_site_url() ); // Use a normalized version of the site URL as a user ID for free users.
}

$integration_status = $this->api_license_status();

$days_since_install = round( ( time() - get_option( 'feedzy_rss_feeds_install', 0 ) ) / DAY_IN_SECONDS );
$install_category = 0;
if ( 0 === $days_since_install || 1 === $days_since_install ) {
$install_category = 0;
} elseif ( 1 < $days_since_install && 8 > $days_since_install ) {
$install_category = 7;
} elseif ( 8 <= $days_since_install && 31 > $days_since_install ) {
$install_category = 30;
} elseif ( 30 < $days_since_install && 90 > $days_since_install ) {
$install_category = 90;
} elseif ( 90 <= $days_since_install ) {
$install_category = 91;
}

return array(
'userId' => $user_id,
'attributes' => array(
'free_version' => $this->version,
'pro_version' => defined( 'FEEDZY_PRO_VERSION' ) ? FEEDZY_PRO_VERSION : '',
'openai' => $integration_status['openaiStatus'] ? 'valid' : 'invalid',
'amazon' => $integration_status['amazonStatus'] ? 'valid' : 'invalid',
'spinnerchief' => $integration_status['spinnerChiefStatus'] ? 'valid' : 'invalid',
'wordai' => $integration_status['wordaiStatus'] ? 'valid' : 'invalid',
'plan' => $this->plan_category( $license_data ),
'days_since_install' => $install_category,
'license_status' => ! empty( $license_data->license ) ? $license_data->license : 'invalid',
),
);
}

/**
* Register the survey script.
*
* It does register if we are in CI environment.
*
* @return void
*/
public function register_survey() {

if ( defined( 'CYPRESS_TESTING' ) ) {
return;
}

$survey_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'survey' );
if ( empty( $survey_handler ) ) {
return;
}

do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' );
wp_enqueue_script( $this->plugin_name . '_survey', FEEDZY_ABSURL . 'js/survey.js', array( $survey_handler ), $this->version, true );
wp_localize_script( $this->plugin_name . '_survey', 'feedzySurveyData', $this->get_survery_metadata() );
}
}
55 changes: 41 additions & 14 deletions includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -1818,22 +1818,25 @@ function( $term ) {
}
}

// Item image action.
$import_featured_img = rawurldecode( $import_featured_img );
$import_featured_img = trim( $import_featured_img );
$img_action = $this->handle_content_actions( $import_featured_img, 'item_image' );
// Item image action process.
$image_url = $img_action->run_action_job( $import_featured_img, $import_translation_lang, $job, $language_code, $item, $image_url );

if ( ! empty( $image_url ) ) {
if ( 'yes' === $import_item_img_url ) {
// Set external image URL.
update_post_meta( $new_post_id, 'feedzy_item_external_url', $image_url );
} else {
// if import_featured_img is a tag.
$img_success = $this->generate_featured_image( $image_url, $new_post_id, $item['item_title'], $import_errors, $import_info );
if ( 'yes' === $import_item_img_url || ! $this->tryReuseExistingFeaturedImage( $img_success, $item['item_title'], $new_post_id ) ) {
// Item image action.
$import_featured_img = rawurldecode( $import_featured_img );
$import_featured_img = trim( $import_featured_img );
$img_action = $this->handle_content_actions( $import_featured_img, 'item_image' );
// Item image action process.
$image_url = $img_action->run_action_job( $import_featured_img, $import_translation_lang, $job, $language_code, $item, $image_url );

if ( ! empty( $image_url ) ) {
if ( 'yes' === $import_item_img_url ) {
// Set external image URL.
update_post_meta( $new_post_id, 'feedzy_item_external_url', $image_url );
} else {
// if import_featured_img is a tag.
$img_success = $this->generate_featured_image( $image_url, $new_post_id, $item['item_title'], $import_errors, $import_info );
}
}
}

// Set default thumbnail image.
if ( ! $img_success && ! empty( $default_thumbnail ) ) {
$img_success = set_post_thumbnail( $new_post_id, $default_thumbnail );
Expand Down Expand Up @@ -1940,6 +1943,30 @@ public function get_job_feed( $options, $import_content = null, $raw_feed_also =
return $feed_items;
}

/**
* Reuses an existing featured image if possible.
*
* @param int|bool $result The result of the operation. It can be a boolean or an attachment ID.
* @param string $title_feed The title of the feed.
* @param int $post_id The post ID.
*
* @return bool
*/
public function tryReuseExistingFeaturedImage( &$result, $title_feed, $post_id = 0 ) {
if ( ! function_exists( 'post_exists' ) ) {
require_once ABSPATH . 'wp-admin/includes/post.php';
}
// Find existing attachment by feed title.
$attachment_id = post_exists( $title_feed, '', '', 'attachment' );

if ( ! $attachment_id ) {
return false;
}

$result = set_post_thumbnail( $post_id, $attachment_id );
return true;
}

/**
* Downloads and sets a post featured image if possible.
*
Expand Down
Loading

0 comments on commit e9c80c6

Please sign in to comment.