Skip to content

Commit 34b9dab

Browse files
merge openAI actions
1 parent 351fb88 commit 34b9dab

File tree

5 files changed

+68
-41
lines changed

5 files changed

+68
-41
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
@@ -2358,4 +2358,12 @@ li.draggable-item .components-panel__body-toggle.components-button{
23582358
.feedzy-optimole-upsell .pro-label.free-label {
23592359
color: #4268CF;
23602360
background: rgba(66, 104, 207, 0.20);
2361+
}
2362+
.fz-prompt-button {
2363+
gap: 7px;
2364+
display: flex;
2365+
margin-top: 10px;
2366+
}
2367+
.fz-prompt-button button.components-button {
2368+
height: 28px;
23612369
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,12 @@ private function summarize_content() {
494494
if ( ! class_exists( '\Feedzy_Rss_Feeds_Pro_Openai' ) ) {
495495
return $content;
496496
}
497-
$openai = new \Feedzy_Rss_Feeds_Pro_Openai();
498-
$content = $openai->call_api( $this->settings, $content, 'summarize', array() );
499-
return $content;
497+
if ( isset( $this->current_job->data->fz_summarize ) ) {
498+
unset( $this->current_job->data->fz_summarize );
499+
}
500+
// Summarizes the content using the `Rewrite with AI` action, ensuring backward compatibility.
501+
$this->current_job->data->ChatGPT = 'Summarize this article {content} for better SEO.';
502+
return $this->chat_gpt_rewrite();
500503
}
501504

502505
/**

js/ActionPopup/SortableItem.js

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,14 @@ const SortableItem = ({ propRef, loopIndex, item }) => {
169169
<li className="fz-action-control fz-chat-cpt-action" data-counter={counter}>
170170
<div className="fz-action-event">
171171
{feedzyData.isPro && (feedzyData.isBusinessPlan || feedzyData.isAgencyPlan) && !feedzyData.apiLicenseStatus.openaiStatus && (feedzyData.isHighPrivileges ? <span className="error-message">{__( 'Invalid API Key', 'feedzy-rss-feeds' )} <ExternalLink href="admin.php?page=feedzy-integration&tab=openai"><Icon icon={external} size={16} fill="#F00"/></ExternalLink></span> : <span className="error-message">{__( 'Invalid API Key, Please contact the administrator', 'feedzy-rss-feeds' )}</span> )}
172-
<PanelBody title={ __( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' ) } icon={ DragHandle } initialOpen={ false }>
172+
<PanelBody title={ __( 'Rewrite with AI', 'feedzy-rss-feeds' ) } icon={ DragHandle } initialOpen={ false }>
173173
<PanelRow>
174174
<UpgradeNotice higherPlanNotice={!feedzyData.isBusinessPlan && !feedzyData.isAgencyPlan} utmCampaign="action-paraphrase-chatgpt"/>
175-
<BaseControl>
175+
<BaseControl
176+
__nextHasNoMarginBottom
177+
>
176178
<TextareaControl
179+
__nextHasNoMarginBottom
177180
label={ __( 'Main Prompt', 'feedzy-rss-feeds' ) }
178181
help={
179182
sprintf(
@@ -186,6 +189,11 @@ const SortableItem = ({ propRef, loopIndex, item }) => {
186189
onChange={ ( currentValue ) => propRef.onChangeHandler( { 'index': loopIndex, 'ChatGPT': currentValue ?? '' } ) }
187190
disabled={!feedzyData.isPro || !feedzyData.apiLicenseStatus.openaiStatus}
188191
/>
192+
<div className="fz-prompt-button">
193+
<Button variant="secondary" onClick={ () => propRef.updatePromptText( { 'index': loopIndex, 'type': 'summarize' } ) }>{ __( 'Summarize', 'feedzy-rss-feeds' ) }</Button>
194+
<Button variant="secondary" onClick={ () => propRef.updatePromptText( { 'index': loopIndex, 'type': 'paraphase' } ) }>{ __( 'Paraphase', 'feedzy-rss-feeds' ) }</Button>
195+
<Button variant="secondary" onClick={ () => propRef.updatePromptText( { 'index': loopIndex, 'type': 'change_tone' } ) }>{ __( 'Change tone', 'feedzy-rss-feeds' ) }</Button>
196+
</div>
189197
</BaseControl>
190198
</PanelRow>
191199
</PanelBody>
@@ -201,26 +209,6 @@ const SortableItem = ({ propRef, loopIndex, item }) => {
201209
);
202210
}
203211

204-
if ( 'fz_summarize' === item.id ) {
205-
return(
206-
<li className="fz-action-control" data-counter={counter}>
207-
<div className="fz-action-event">
208-
{feedzyData.isPro && (feedzyData.isBusinessPlan || feedzyData.isAgencyPlan) && !feedzyData.apiLicenseStatus.openaiStatus && (feedzyData.isHighPrivileges ? <span className="error-message">{__( 'Invalid API Key', 'feedzy-rss-feeds' )} <ExternalLink href="admin.php?page=feedzy-integration&tab=openai"><Icon icon={external} size={16} fill="#F00"/></ExternalLink></span> : <span className="error-message">{__( 'Invalid API Key, Please contact the administrator', 'feedzy-rss-feeds' )}</span> )}
209-
<PanelBody title={ __( 'Summarize with ChatGPT', 'feedzy-rss-feeds' ) } icon={ DragHandle } initialOpen={ false } className="fz-hide-icon">
210-
<UpgradeNotice higherPlanNotice={!feedzyData.isBusinessPlan && !feedzyData.isAgencyPlan} utmCampaign="action-summarize-chatgpt"/>
211-
</PanelBody>
212-
</div>
213-
<div className="fz-trash-action">
214-
<button type="button" onClick={() => { propRef.removeCallback(loopIndex) }}>
215-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
216-
<path d="M20 5.0002H14.3C14.3 3.7002 13.3 2.7002 12 2.7002C10.7 2.7002 9.7 3.7002 9.7 5.0002H4V7.0002H5.5V7.3002L7.2 18.4002C7.3 19.4002 8.2 20.1002 9.2 20.1002H14.9C15.9 20.1002 16.7 19.4002 16.9 18.4002L18.6 7.3002V7.0002H20V5.0002ZM16.8 7.0002L15.1 18.1002C15.1 18.2002 15 18.3002 14.8 18.3002H9.1C9 18.3002 8.8 18.2002 8.8 18.1002L7.2 7.0002H16.8Z" fill="black"/>
217-
</svg>
218-
</button>
219-
</div>
220-
</li>
221-
);
222-
}
223-
224212
if ( 'fz_translate' === item.id ) {
225213
return(
226214
<li className="fz-action-control fz-translate-action" data-counter={counter}>
@@ -311,8 +299,11 @@ const SortableItem = ({ propRef, loopIndex, item }) => {
311299
disabled={!feedzyData.isPro || !feedzyData.apiLicenseStatus.openaiStatus}
312300
/>
313301
</BaseControl>
314-
<BaseControl>
302+
<BaseControl
303+
__nextHasNoMarginBottom
304+
>
315305
<TextareaControl
306+
__nextHasNoMarginBottom
316307
label={ __( 'Additional Prompt', 'feedzy-rss-feeds' ) }
317308
value={ item.data.generateImagePrompt ? unescape(item.data.generateImagePrompt.replaceAll('&#039;', '\'')) : '' }
318309
onChange={ ( currentValue ) => propRef.onChangeHandler( { 'index': loopIndex, 'generateImagePrompt': currentValue ?? '' } ) }

js/ActionPopup/index.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ const ActionModal = () => {
7575

7676
};
7777

78+
const demoPromptText = (args) => {
79+
let id = args.index;
80+
let type = args.type;
81+
delete args.index;
82+
delete args.type;
83+
let prevState = action[id].data || {};
84+
let updatedState = {...prevState, ...args};
85+
if ( 'summarize' === type ) {
86+
updatedState['ChatGPT'] = 'Summarize this article {content} for better SEO.';
87+
} else if ( 'paraphase' === type ) {
88+
updatedState['ChatGPT'] = 'Rephrase my {content} for better SEO.';
89+
} else if ( 'change_tone' === type ) {
90+
updatedState['ChatGPT'] = 'Change tone of my {content} for a more friendly approach.';
91+
}
92+
action[id]['data'] = updatedState;
93+
setAction( () => ([...action.filter((e)=>{return e})]));
94+
};
95+
7896
const openModal = () => {
7997
setLoading(true);
8098
setOpen(true);
@@ -241,7 +259,21 @@ const ActionModal = () => {
241259
let editAction = event.target.getAttribute( 'data-actions' ) || '';
242260
let fieldId = event.target.getAttribute( 'data-field_id' ) || '';
243261
editAction = JSON.parse( decodeURIComponent( editAction ) );
244-
setAction( () => ([...editAction.filter((e)=>{return e.id !== ''})]));
262+
setAction(() => (
263+
editAction
264+
.filter((e) => e.id !== '')
265+
.map((e) => {
266+
// Replace 'fz_summarize' with 'chat_gpt_rewrite' for backward compatible.
267+
if (e.id === 'fz_summarize') {
268+
return {
269+
...e,
270+
id: 'chat_gpt_rewrite',
271+
data: { ChatGPT: "Summarize this article {content} for better SEO." }
272+
};
273+
}
274+
return e;
275+
})
276+
));
245277
let magicTag = editAction[0] || {};
246278
let tag = magicTag.tag;
247279
setEditModeTag(event.target.parentNode);
@@ -280,7 +312,7 @@ const ActionModal = () => {
280312
</div>
281313
) }
282314

283-
{action.length > 0 && ( <Actions data={action} removeCallback={removeAction} onChangeHandler={handleChange} onSortEnd={onSortEnd} useDragHandle lockAxis="y" helperClass="draggable-item" distance={1} lockToContainerEdges={true} lockOffset="0%"/> )}
315+
{action.length > 0 && ( <Actions data={action} removeCallback={removeAction} onChangeHandler={handleChange} updatePromptText={demoPromptText} onSortEnd={onSortEnd} useDragHandle lockAxis="y" helperClass="draggable-item" distance={1} lockToContainerEdges={true} lockOffset="0%"/> )}
284316

285317
<div className="fz-action-btn">
286318
<div className="fz-action-relative">
@@ -346,18 +378,9 @@ const ActionModal = () => {
346378
(
347379
'item_categories' !== shortCode && (
348380
feedzyData.isPro && ( feedzyData.isBusinessPlan || feedzyData.isAgencyPlan ) ? (
349-
<li key="action-9" onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' )}</li>
350-
) : (
351-
<li key="action-9" onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
352-
)
353-
)
354-
),
355-
(
356-
'item_categories' !== shortCode && (
357-
feedzyData.isPro && ( feedzyData.isBusinessPlan || feedzyData.isAgencyPlan ) ? (
358-
<li key="action-10" onClick={ () => addAction('fz_summarize') }>{__( 'Summarize with ChatGPT', 'feedzy-rss-feeds' )}</li>
381+
<li key="action-9" onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Rewrite with AI', 'feedzy-rss-feeds' )}</li>
359382
) : (
360-
<li key="action-10" onClick={ () => addAction('fz_summarize') }>{__( 'Summarize with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
383+
<li key="action-9" onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Rewrite with AI', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
361384
)
362385
)
363386
)

0 commit comments

Comments
 (0)