Skip to content

Commit cbd9e0a

Browse files
authored
Merge pull request #1022 from Codeinwp/feat/pro/792
Improvement in AI API integration
2 parents 2132158 + 0b75455 commit cbd9e0a

19 files changed

+393
-89
lines changed

css/feedzy-rss-feed-import.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@
5454
float: none;
5555
}
5656
.feedzy_page_feedzy-settings #wpcontent,
57-
.feedzy_page_feedzy-support #wpcontent{
57+
.feedzy_page_feedzy-support #wpcontent,
58+
.feedzy_page_feedzy-integration #wpcontent{
5859
padding-left: 0;
5960
}
6061
.feedzy_page_feedzy-settings .feedzy-header,
61-
.feedzy_page_feedzy-support .feedzy-header{
62+
.feedzy_page_feedzy-support .feedzy-header,
63+
.feedzy_page_feedzy-integration .feedzy-header{
6264
margin-bottom: 40px;
6365
}
6466
.feedzy-api-error,

css/settings.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,4 +2367,12 @@ li.draggable-item .components-panel__body-toggle.components-button{
23672367
.feedzy-optimole-upsell .pro-label.free-label {
23682368
color: #4268CF;
23692369
background: rgba(66, 104, 207, 0.20);
2370+
}
2371+
.fz-prompt-button {
2372+
gap: 7px;
2373+
display: flex;
2374+
margin-top: 10px;
2375+
}
2376+
.fz-prompt-button button.components-button {
2377+
height: 28px;
23702378
}

feedzy-rss-feed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ function feedzy_themeisle_log_event( $name, $msg, $type, $file, $line ) {
253253
'nice_name' => 'Feedzy',
254254
'logo' => FEEDZY_ABSURL . 'img/feedzy.svg',
255255
'primary_color' => '#4268CF',
256-
'pages' => array( 'feedzy_imports', 'edit-feedzy_imports', 'edit-feedzy_categories', 'feedzy_page_feedzy-settings', 'feedzy_page_feedzy-support' ),
256+
'pages' => array( 'feedzy_imports', 'edit-feedzy_imports', 'edit-feedzy_categories', 'feedzy_page_feedzy-settings', 'feedzy_page_feedzy-support', 'feedzy_page_feedzy-integration' ),
257257
'has_upgrade_menu' => ! feedzy_is_pro(),
258258
'upgrade_link' => tsdk_translate_link( tsdk_utmify( FEEDZY_UPSELL_LINK, 'floatWidget' ), 'query' ),
259259
'documentation_link' => tsdk_translate_link( tsdk_utmify( 'https://docs.themeisle.com/collection/1569-feedzy-rss-feeds', 'floatWidget' ), 'query' ),

includes/admin/feedzy-rss-feeds-actions.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,17 @@ private function chat_gpt_rewrite() {
472472
return $this->current_job->data->ChatGPT;
473473
}
474474

475-
$content = call_user_func( array( $this, $this->current_job->tag ) );
476-
$content = wp_strip_all_tags( $content );
477-
$content = substr( $content, 0, apply_filters( 'feedzy_chat_gpt_content_limit', 3000 ) );
478-
$prompt_content = $this->current_job->data->ChatGPT;
475+
$content = call_user_func( array( $this, $this->current_job->tag ) );
476+
$content = wp_strip_all_tags( $content );
477+
$content = substr( $content, 0, apply_filters( 'feedzy_chat_gpt_content_limit', 3000 ) );
478+
$prompt_content = $this->current_job->data->ChatGPT;
479+
$ai_provider = 'openai';
480+
if ( isset( $this->current_job->data ) && isset( $this->current_job->data->aiProvider ) ) {
481+
$ai_provider = $this->current_job->data->aiProvider;
482+
}
479483
$content = str_replace( array( '{content}' ), array( $content ), $prompt_content );
480484
$openai = new \Feedzy_Rss_Feeds_Pro_Openai();
481-
$rewrite_content = $openai->call_api( $this->settings, $content, '', array() );
485+
$rewrite_content = $openai->call_api( $this->settings, $content, '', array( 'ai_provider' => $ai_provider ) );
482486
// Replace prompt content string for specific cases.
483487
$rewrite_content = str_replace( explode( '{content}', $prompt_content ), '', trim( $rewrite_content, '"' ) );
484488
return $rewrite_content;
@@ -494,9 +498,12 @@ private function summarize_content() {
494498
if ( ! class_exists( '\Feedzy_Rss_Feeds_Pro_Openai' ) ) {
495499
return $content;
496500
}
497-
$openai = new \Feedzy_Rss_Feeds_Pro_Openai();
498-
$content = $openai->call_api( $this->settings, $content, 'summarize', array() );
499-
return $content;
501+
if ( isset( $this->current_job->data->fz_summarize ) ) {
502+
unset( $this->current_job->data->fz_summarize );
503+
}
504+
// Summarizes the content using the `Rewrite with AI` action, ensuring backward compatibility.
505+
$this->current_job->data->ChatGPT = 'Summarize this article {content} for better SEO.';
506+
return $this->chat_gpt_rewrite();
500507
}
501508

502509
/**
@@ -517,6 +524,9 @@ private function generate_image() {
517524
}
518525

519526
$prompt = call_user_func( array( $this, 'item_title' ) );
527+
if ( ! empty( $this->current_job->data->generateImagePrompt ) ) {
528+
$prompt .= "\r\n" . $this->current_job->data->generateImagePrompt;
529+
}
520530
$openai = new \Feedzy_Rss_Feeds_Pro_Openai();
521531
return $openai->call_api( $this->settings, $prompt, 'image', array() );
522532
}

includes/admin/feedzy-rss-feeds-admin.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ public function enqueue_styles_admin() {
162162
$this->add_banner_anchor();
163163
}
164164

165-
if ( 'feedzy_page_feedzy-settings' === $screen->base ) {
166-
if ( ! did_action( 'wp_enqueue_media' ) ) {
165+
if ( 'feedzy_page_feedzy-settings' === $screen->base || 'feedzy_page_feedzy-integration' === $screen->base ) {
166+
if ( ! did_action( 'wp_enqueue_media' ) && 'feedzy_page_feedzy-settings' === $screen->base ) {
167167
wp_enqueue_media();
168168
}
169169
wp_enqueue_script( $this->plugin_name . '_setting', FEEDZY_ABSURL . 'js/feedzy-setting.js', array( 'jquery' ), $this->version, true );
@@ -618,6 +618,17 @@ public function feedzy_menu_pages() {
618618
'feedzy_settings_page',
619619
)
620620
);
621+
add_submenu_page(
622+
'feedzy-admin-menu',
623+
__( 'Integration', 'feedzy-rss-feeds' ),
624+
__( 'Integration', 'feedzy-rss-feeds' ),
625+
'manage_options',
626+
'feedzy-integration',
627+
array(
628+
$this,
629+
'feedzy_integration_page',
630+
)
631+
);
621632
add_submenu_page(
622633
'feedzy-admin-menu',
623634
__( 'Support', 'feedzy-rss-feeds' ),
@@ -662,6 +673,21 @@ public function feedzy_settings_page() {
662673
include FEEDZY_ABSPATH . '/includes/layouts/settings.php';
663674
}
664675

676+
/**
677+
* Method to register the integration page.
678+
*
679+
* @access public
680+
*/
681+
public function feedzy_integration_page() {
682+
if ( isset( $_POST['feedzy-integration-submit'] ) && isset( $_POST['tab'] ) && wp_verify_nonce( filter_input( INPUT_POST, 'nonce', FILTER_UNSAFE_RAW ), filter_input( INPUT_POST, 'tab', FILTER_UNSAFE_RAW ) ) ) {
683+
$this->save_settings();
684+
$this->notice = __( 'Your settings were saved.', 'feedzy-rss-feeds' );
685+
}
686+
687+
$settings = apply_filters( 'feedzy_get_settings', array() );
688+
include FEEDZY_ABSPATH . '/includes/layouts/integration.php';
689+
}
690+
665691
/**
666692
* Method to save the settings.
667693
*
@@ -1619,6 +1645,7 @@ public function api_license_status() {
16191645
'wordaiStatus' => false,
16201646
'openaiStatus' => false,
16211647
'amazonStatus' => false,
1648+
'openRouterStatus' => false,
16221649
);
16231650

16241651
if ( ! feedzy_is_pro() ) {
@@ -1640,6 +1667,12 @@ public function api_license_status() {
16401667
}
16411668
}
16421669

1670+
if ( isset( $pro_options['openrouter_licence'] ) && 'yes' === $pro_options['openrouter_licence'] ) {
1671+
if ( apply_filters( 'feedzy_is_license_of_type', false, 'business' ) || apply_filters( 'feedzy_is_license_of_type', false, 'agency' ) ) {
1672+
$data['openRouterStatus'] = true;
1673+
}
1674+
}
1675+
16431676
if ( ! empty( $pro_options['amazon_access_key'] ) && ! empty( $pro_options['amazon_secret_key'] ) ) {
16441677
$data['amazonStatus'] = true;
16451678
}

includes/admin/feedzy-rss-feeds-import.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ public function get_cron_execution( $execution, $offset = 0 ) {
24262426
*/
24272427
public function admin_notices() {
24282428
$screen = get_current_screen();
2429-
$allowed = array( 'edit-feedzy_categories', 'edit-feedzy_imports', 'feedzy-rss_page_feedzy-settings' );
2429+
$allowed = array( 'edit-feedzy_categories', 'edit-feedzy_imports', 'feedzy-rss_page_feedzy-settings', 'feedzy-rss_page_feedzy-integration' );
24302430
// only show in the feedzy screens.
24312431
if ( ! in_array( $screen->id, $allowed, true ) ) {
24322432
return;
@@ -2549,15 +2549,30 @@ private function save_settings() {
25492549
* @access public
25502550
*/
25512551
public function settings_tabs( $tabs ) {
2552-
$tabs['misc'] = __( 'Miscellaneous', 'feedzy-rss-feeds' );
2552+
$tabs['misc'] = __( 'Miscellaneous', 'feedzy-rss-feeds' );
2553+
2554+
return $tabs;
2555+
}
2556+
2557+
/**
2558+
* Add integration tab.
2559+
*
2560+
* @since 3.0.0
2561+
* @access public
2562+
*/
2563+
public function integration_tabs( $tabs ) {
25532564
if ( $this->feedzy_is_business() || $this->feedzy_is_agency() ) {
2554-
$tabs['openai'] = __( 'OpenAI', 'feedzy-rss-feeds' );
2565+
$tabs['openai'] = __( 'OpenAI', 'feedzy-rss-feeds' );
2566+
$tabs['openrouter'] = __( 'OpenRouter', 'feedzy-rss-feeds' );
25552567
}
2556-
if ( ! feedzy_is_pro() ) {
2557-
$tabs['wordai'] = sprintf( '%s <span class="pro-label">PRO</span>', __( 'WordAi', 'feedzy-rss-feeds' ) );
2568+
if ( ! feedzy_is_pro() || ! apply_filters( 'feedzy_is_license_of_type', false, 'business' ) ) {
2569+
$tabs['openai'] = sprintf( '%s <span class="pro-label">PRO</span>', __( 'OpenAI', 'feedzy-rss-feeds' ) );
2570+
if ( ! isset( $tabs['openrouter'] ) ) {
2571+
$tabs['openrouter'] = sprintf( '%s <span class="pro-label">PRO</span>', __( 'OpenRouter', 'feedzy-rss-feeds' ) );
2572+
}
25582573
$tabs['spinnerchief'] = sprintf( '%s <span class="pro-label">PRO</span>', __( 'SpinnerChief', 'feedzy-rss-feeds' ) );
25592574
$tabs['amazon-product-advertising'] = sprintf( '%s <span class="pro-label">PRO</span>', __( 'Amazon Product Advertising', 'feedzy-rss-feeds' ) );
2560-
$tabs['openai'] = sprintf( '%s <span class="pro-label">PRO</span>', __( 'OpenAI', 'feedzy-rss-feeds' ) );
2575+
$tabs['wordai'] = sprintf( '%s <span class="pro-label">PRO</span>', __( 'WordAi', 'feedzy-rss-feeds' ) );
25612576
}
25622577

25632578
return $tabs;
@@ -2600,7 +2615,8 @@ private function render_view( $name ) {
26002615
case 'spinnerchief':
26012616
case 'amazon-product-advertising':
26022617
case 'openai':
2603-
if ( ! feedzy_is_pro() ) {
2618+
case 'openrouter':
2619+
if ( ! feedzy_is_pro() || ! apply_filters( 'feedzy_is_license_of_type', false, 'business' ) ) {
26042620
$file = FEEDZY_ABSPATH . '/includes/views/' . $name . '-view.php';
26052621
} else {
26062622
$file = apply_filters( 'feedzy_render_view', $file, $name );

includes/feedzy-rss-feeds-limited-offers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function render_notice() {
177177
$screen = get_current_screen();
178178
if (
179179
( $screen->base === 'edit' && ( $screen->post_type === 'feedzy_imports' || $screen->post_type === 'feedzy_categories' ) ) ||
180-
'feedzy_page_feedzy-settings' === $screen->id
180+
'feedzy_page_feedzy-settings' === $screen->id || 'feedzy_page_feedzy-integration' === $screen->id
181181
) {
182182
return;
183183
}
@@ -285,7 +285,7 @@ public function add_priority( $products ) {
285285
$screen = get_current_screen();
286286
if (
287287
( $screen->base === 'edit' && ( $screen->post_type === 'feedzy_imports' || $screen->post_type === 'feedzy_categories' ) ) ||
288-
'feedzy_page_feedzy-settings' === $screen->id
288+
'feedzy_page_feedzy-settings' === $screen->id || 'feedzy_page_feedzy-integration' === $screen->id
289289
) {
290290
// Small hack to supress rendering of other notices in those pages.
291291
$products['feedzy'] = -2;

includes/feedzy-rss-feeds.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ function () {
239239

240240
self::$instance->loader->add_filter( 'feedzy_items_limit', $plugin_import, 'items_limit', 10, 2 );
241241
self::$instance->loader->add_filter( 'feedzy_settings_tabs', $plugin_import, 'settings_tabs', 10, 1 );
242+
self::$instance->loader->add_filter( 'feedzy_integration_tabs', $plugin_import, 'integration_tabs', 10, 1 );
242243
self::$instance->loader->add_filter( 'redirect_post_location', $plugin_import, 'redirect_post_location', 10, 2 );
243244
self::$instance->loader->add_filter( 'manage_feedzy_imports_posts_columns', $plugin_import, 'feedzy_import_columns' );
244245
self::$instance->loader->add_action( 'admin_notices', $plugin_import, 'admin_notices' );

includes/layouts/header.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
88
*/
99

10-
// phpcs:ignore WordPress.Security.NonceVerification
11-
$page_title = isset( $_GET['page'] ) && 'feedzy-support' === $_GET['page'] ? __( 'Support', 'feedzy-rss-feeds' ) : __( 'Settings', 'feedzy-rss-feeds' );
10+
// phpcs:disable WordPress.Security.NonceVerification
11+
$page_title = __( 'Settings', 'feedzy-rss-feeds' );
12+
if ( isset( $_GET['page'] ) && 'feedzy-support' === $_GET['page'] ) {
13+
$page_title = __( 'Support', 'feedzy-rss-feeds' );
14+
} elseif ( isset( $_GET['page'] ) && 'feedzy-integration' === $_GET['page'] ) {
15+
$page_title = __( 'Integration', 'feedzy-rss-feeds' );
16+
}
1217
?>
1318
<div class="feedzy-header">
1419
<div class="feedzy-container">

includes/layouts/integration.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<div id="fz-features" class="feedzy-wrap">
2+
3+
<?php load_template( FEEDZY_ABSPATH . '/includes/layouts/header.php' ); ?>
4+
5+
<?php
6+
$active_tab = isset( $_REQUEST['tab'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ) : 'openai';// phpcs:ignore WordPress.Security.NonceVerification
7+
$show_button = true;
8+
9+
$help_btn_url = 'https://docs.themeisle.com/category/712-feedzy';
10+
11+
if ( 'wordai' === $active_tab ) {
12+
$help_btn_url = 'https://docs.themeisle.com/article/746-how-to-use-wordai-to-rephrase-rss-content-in-feedzy#wordai';
13+
} elseif ( 'spinnerchief' === $active_tab ) {
14+
$help_btn_url = 'https://docs.themeisle.com/article/746-how-to-use-wordai-to-rephrase-rss-content-in-feedzy#spinner';
15+
}
16+
?>
17+
<?php if ( $this->notice ) { ?>
18+
<div class="fz-snackbar-notice updated"><p><?php echo wp_kses_post( $this->notice ); ?></p></div>
19+
<?php } ?>
20+
21+
<?php if ( $this->error ) { ?>
22+
<div class="fz-snackbar-notice error"><p><?php echo wp_kses_post( $this->error ); ?></p></div>
23+
<?php } ?>
24+
25+
<div id="tsdk_banner" class="feedzy-banner"></div>
26+
27+
<div class="feedzy-container">
28+
<?php if ( ! empty( $offer_data['active'] ) ) { ?>
29+
<div class="feedzy-sale">
30+
<a href="<?php echo esc_url( $offer_data['bannerStoreUrl'] ); ?>">
31+
<img src="<?php echo esc_url( $offer_data['bannerUrl'] ); ?>" alt="<?php echo esc_html( $offer_data['bannerAlt'] ); ?>">
32+
<div class="feedzy-urgency"><?php echo esc_html( $offer_data['urgencyText'] ); ?></div>
33+
</a>
34+
</div>
35+
<?php } ?>
36+
<div class="feedzy-accordion-item">
37+
<div class="feedzy-accordion-item__title">
38+
<div class="feedzy-accordion-item__button">
39+
<div class="feedzy-accordion__step-title h2">
40+
<?php
41+
switch ( $active_tab ) {
42+
case 'spinnerchief':
43+
esc_html_e( 'SpinnerChief', 'feedzy-rss-feeds' );
44+
break;
45+
case 'wordai':
46+
esc_html_e( 'WordAI', 'feedzy-rss-feeds' );
47+
break;
48+
case 'openai':
49+
esc_html_e( 'OpenAI', 'feedzy-rss-feeds' );
50+
break;
51+
case 'openrouter':
52+
esc_html_e( 'OpenRouter', 'feedzy-rss-feeds' );
53+
break;
54+
default:
55+
echo esc_html( ucwords( str_replace( array( '-', '_' ), ' ', $active_tab ) ) );
56+
break;
57+
}
58+
?>
59+
</div>
60+
</div>
61+
</div>
62+
<div class="feedzy-accordion-item__content">
63+
<div class="fz-tabs-menu">
64+
<ul>
65+
<?php
66+
$_tabs = apply_filters( 'feedzy_integration_tabs', array() );
67+
if ( $_tabs ) {
68+
foreach ( $_tabs as $_tab => $label ) {
69+
?>
70+
<li>
71+
<a href="<?php echo esc_url( admin_url( 'admin.php?page=feedzy-integration&tab=' . $_tab ) ); ?>"
72+
class="<?php echo $_tab === $active_tab ? esc_attr( 'active' ) : ''; ?>"><?php echo wp_kses_post( $label ); ?></a>
73+
</li>
74+
<?php
75+
}
76+
}
77+
?>
78+
</ul>
79+
</div>
80+
81+
<form method="post" action="">
82+
<?php
83+
$fields = apply_filters( 'feedzy_display_tab_settings', array(), $active_tab );
84+
if ( $fields ) {
85+
86+
foreach ( $fields as $field ) {
87+
if ( ! empty( $field['content'] ) ) {
88+
echo wp_kses( $field['content'], apply_filters( 'feedzy_wp_kses_allowed_html', array() ) );
89+
}
90+
if ( isset( $field['ajax'] ) && $field['ajax'] ) {
91+
$show_button = false;
92+
}
93+
}
94+
}
95+
?>
96+
97+
<input type="hidden" name="tab" value="<?php echo esc_attr( $active_tab ); ?>">
98+
99+
<?php
100+
wp_nonce_field( $active_tab, 'nonce' );
101+
if ( $show_button ) {
102+
$disable_button = ! feedzy_is_pro() && in_array( $active_tab, array( 'spinnerchief', 'wordai', 'amazon-product-advertising', 'openai' ), true ) ? ' disabled' : '';
103+
?>
104+
<div class="mb-24">
105+
<button type="submit" class="btn btn-primary<?php echo esc_attr( $disable_button ); ?>" id="feedzy-settings-submit" name="feedzy-settings-submit" onclick="return ajaxUpdate(this);"><?php esc_html_e( 'Validate & Save', 'feedzy-rss-feeds' ); ?></button>
106+
</div>
107+
<?php
108+
}
109+
?>
110+
</form>
111+
112+
</div>
113+
</div>
114+
115+
<div class="cta pt-30">
116+
<a href="<?php echo esc_url( $help_btn_url ); ?>" class="btn btn-ghost" target="_blank"><?php esc_html_e( 'Need help?', 'feedzy-rss-feeds' ); ?></a>
117+
</div>
118+
</div>
119+
</div>

0 commit comments

Comments
 (0)