Skip to content

Commit 8151cf8

Browse files
Add modify links action
1 parent 4a46f97 commit 8151cf8

File tree

4 files changed

+154
-21
lines changed

4 files changed

+154
-21
lines changed

css/settings.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,7 @@ span.error-message .components-external-link .components-visually-hidden{
17191719
margin-left: auto;
17201720
padding: 0;
17211721
height: auto;
1722+
box-shadow: none !important;
17221723
}
17231724
.fz-action-btn button {
17241725
display: flex;
@@ -1765,7 +1766,7 @@ span.error-message .components-external-link .components-visually-hidden{
17651766
position: relative;
17661767
}
17671768
.popover-action-list{
1768-
width: 250px;
1769+
width: 270px;
17691770
position: absolute;
17701771
left: 100%;
17711772
bottom: 0;
@@ -2020,7 +2021,8 @@ li.draggable-item .components-panel__body-toggle.components-button{
20202021
.fz-action-panel .fz-chat-cpt-action .components-notice {
20212022
width: 100%;
20222023
}
2023-
.fz-action-panel .fz-chat-cpt-action .components-panel__row {
2024+
.fz-action-panel .fz-chat-cpt-action .components-panel__row,
2025+
.fz-action-panel .fz-modify-links .components-panel__row {
20242026
display: block;
20252027
}
20262028
.fz-action-panel .fz-upgrade-notice {
@@ -2090,7 +2092,8 @@ li.draggable-item .components-panel__body-toggle.components-button{
20902092
cursor: not-allowed !important;
20912093
}
20922094

2093-
.fz-action-panel .fz-chat-cpt-action .fz-notice-wrap {
2095+
.fz-action-panel .fz-chat-cpt-action .fz-notice-wrap,
2096+
.fz-action-panel .fz-modify-links .fz-notice-wrap {
20942097
padding: 0;
20952098
}
20962099

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ public function action_process() {
313313
return $this->summarize_content();
314314
case 'fz_image':
315315
return $this->generate_image();
316+
case 'modify_links':
317+
return $this->modify_links();
316318
default:
317319
return $this->default_content();
318320
}
@@ -505,5 +507,47 @@ private function generate_image() {
505507
$openai = new \Feedzy_Rss_Feeds_Pro_Openai();
506508
return $openai->call_api( $this->settings, $prompt, 'image', array() );
507509
}
510+
511+
/**
512+
* Modify links.
513+
*
514+
* @return string Item content.
515+
*/
516+
private function modify_links() {
517+
$content = call_user_func( array( $this, $this->current_job->tag ) );
518+
// Returns item content because it has no HTML tags
519+
if ( $content === wp_strip_all_tags( $content ) ) {
520+
return $content;
521+
}
522+
// Pro version is required to perform this action.
523+
if ( ! feedzy_is_pro() ) {
524+
return $content;
525+
}
526+
527+
$dom = new DOMDocument();
528+
libxml_use_internal_errors( true );
529+
$dom->loadHTML( $content );
530+
$xpath = new DOMXPath( $dom );
531+
libxml_clear_errors();
532+
// Get all anchors tags.
533+
$nodes = $xpath->query( '//a' );
534+
535+
if ( ! empty( $this->current_job->data->remove_links ) ) {
536+
foreach ( $nodes as $node ) {
537+
if ( ! empty( $this->current_job->data->remove_links ) ) {
538+
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
539+
$node->parentNode->removeChild( $node );
540+
continue;
541+
}
542+
if ( ! empty( $this->current_job->data->target ) ) {
543+
$node->setAttribute( 'target', $this->current_job->data->target );
544+
}
545+
if ( ! empty( $this->current_job->data->follow ) && 'yes' === $this->current_job->data->follow ) {
546+
$node->setAttribute( 'rel', 'nofollow' );
547+
}
548+
}
549+
}
550+
return $dom->saveHTML();
551+
}
508552
}
509553
}

js/ActionPopup/SortableItem.js

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525
Popover,
2626
ItemGroup,
2727
Item,
28-
ToggleControl
28+
ToggleControl,
29+
SelectControl
2930
} from '@wordpress/components';
3031

3132
const DragHandle = sortableHandle(() => <Icon icon={dragHandle} size={18} className="components-panel__icon" />);
@@ -297,6 +298,83 @@ const SortableItem = ({ propRef, loopIndex, item }) => {
297298
</li>
298299
);
299300
}
301+
302+
if ( 'modify_links' === item.id ) {
303+
return(
304+
<li className="fz-action-control fz-modify-links" data-counter={counter}>
305+
<div className="fz-action-event">
306+
<PanelBody title={ __( 'Modify Links', 'feedzy-rss-feeds' ) } icon={ DragHandle } initialOpen={ false }>
307+
<PanelRow>
308+
<UpgradeNotice higherPlanNotice={false} utmCampaign="action-modify-links"/>
309+
<BaseControl className="mb-20">
310+
<ToggleControl
311+
checked={ item.data.remove_links ?? false }
312+
label={ __( 'Remove links from the content?', 'feedzy-rss-feeds' ) }
313+
onChange={ ( currentValue ) => propRef.onChangeHandler( { 'index': loopIndex, 'remove_links': currentValue ?? '' } ) }
314+
disabled={!feedzyData.isPro}
315+
/>
316+
</BaseControl>
317+
{ true !== item.data.remove_links &&
318+
<BaseControl className="mb-20">
319+
<SelectControl
320+
label={__('Open Links In', 'feedzy-rss-feeds')}
321+
value={ item.data.target || '' }
322+
options={[
323+
{
324+
label: __('Default', 'feedzy-rss-feeds'),
325+
value: '',
326+
},
327+
{
328+
label: __('New Tab'),
329+
value: '_blank',
330+
},
331+
{
332+
label: __('Same Tab'),
333+
value: '_self',
334+
},
335+
]}
336+
onChange={ ( currentValue ) => propRef.onChangeHandler( { 'index': loopIndex, 'target': currentValue ?? '' } ) }
337+
disabled={!feedzyData.isPro}
338+
/>
339+
</BaseControl>
340+
}
341+
{ true !== item.data.remove_links &&
342+
<BaseControl>
343+
<SelectControl
344+
label={__( 'Make this link a "nofollow" link?', 'feedzy-rss-feeds' )}
345+
value={ item.data.follow || '' }
346+
onChange={ ( currentValue ) => propRef.onChangeHandler( { 'index': loopIndex, 'follow': currentValue ?? '' } ) }
347+
options={[
348+
{
349+
label: __('Default', 'feedzy-rss-feeds'),
350+
value: '',
351+
},
352+
{
353+
label: __('No', 'feedzy-rss-feeds'),
354+
value: 'no',
355+
},
356+
{
357+
label: __('Yes', 'feedzy-rss-feeds'),
358+
value: 'yes',
359+
},
360+
]}
361+
disabled={!feedzyData.isPro}
362+
/>
363+
</BaseControl>
364+
}
365+
</PanelRow>
366+
</PanelBody>
367+
</div>
368+
<div className="fz-trash-action">
369+
<button type="button" onClick={() => { propRef.removeCallback(loopIndex) }}>
370+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
371+
<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"/>
372+
</svg>
373+
</button>
374+
</div>
375+
</li>
376+
);
377+
}
300378
}
301379

302380
export default SortableElement(SortableItem);

js/ActionPopup/action-popup.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
const ActionModal = () => {
3232
// useRef
3333
const userRef = useRef(null);
34-
const feedzyImportRef = useRef(null);
3534
// State
3635
const [ isOpen, setOpen ] = useState(false);
3736
const [ isHideMsg, setHideMeg ] = useState(false);
@@ -288,62 +287,71 @@ const ActionModal = () => {
288287
{
289288
'item_image' === shortCode ? ([
290289
feedzyData.isPro && ( feedzyData.isBusinessPlan || feedzyData.isAgencyPlan ) ? (
291-
<li onClick={ () => addAction('fz_image') }>{__( 'Generate with ChatGPT', 'feedzy-rss-feeds' )}</li>
290+
<li key="action-1" onClick={ () => addAction('fz_image') }>{__( 'Generate with ChatGPT', 'feedzy-rss-feeds' )}</li>
292291
) : (
293-
<li onClick={ () => addAction('fz_image') }>{__( 'Generate with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
292+
<li key="action-1" onClick={ () => addAction('fz_image') }>{__( 'Generate with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
294293
)]
295294
) : ([
296-
<li onClick={ () => addAction('trim') }>{__( 'Trim Content', 'feedzy-rss-feeds' )}</li>,
295+
<li key="action-2" onClick={ () => addAction('trim') }>{__( 'Trim Content', 'feedzy-rss-feeds' )}</li>,
297296
(
298297
feedzyData.isPro && feedzyData.isAgencyPlan ? (
299-
<li onClick={ () => addAction('fz_translate') }>{__( 'Translate with Feedzy', 'feedzy-rss-feeds' )}</li>
298+
<li key="action-3" onClick={ () => addAction('fz_translate') }>{__( 'Translate with Feedzy', 'feedzy-rss-feeds' )}</li>
300299
) : (
301-
<li onClick={ () => addAction('fz_translate') }>{__( 'Translate with Feedzy', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
300+
<li key="action-3" onClick={ () => addAction('fz_translate') }>{__( 'Translate with Feedzy', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
301+
)
302+
),
303+
<li key="action-4" onClick={ () => addAction('search_replace') }>{__( 'Search / Replace', 'feedzy-rss-feeds' )}</li>,
304+
(
305+
'item_categories' !== shortCode && (
306+
feedzyData.isPro ? (
307+
<li key="action-5" onClick={ () => addAction('modify_links') }>{__( 'Modify Links', 'feedzy-rss-feeds' )}</li>
308+
) : (
309+
<li key="action-5" onClick={ () => addAction('modify_links') }>{__( 'Modify Links', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
310+
)
302311
)
303312
),
304-
<li onClick={ () => addAction('search_replace') }>{__( 'Search / Replace', 'feedzy-rss-feeds' )}</li>,
305313
(
306314
'item_categories' !== shortCode && (
307315
feedzyData.isPro && ( feedzyData.isBusinessPlan || feedzyData.isAgencyPlan ) ? (
308-
<li onClick={ () => addAction('fz_paraphrase') }>{__( 'Paraphrase with Feedzy', 'feedzy-rss-feeds' )}</li>
316+
<li key="action-6" onClick={ () => addAction('fz_paraphrase') }>{__( 'Paraphrase with Feedzy', 'feedzy-rss-feeds' )}</li>
309317
) : (
310-
<li onClick={ () => addAction('fz_paraphrase') }>{__( 'Paraphrase with Feedzy', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
318+
<li key="action-6" onClick={ () => addAction('fz_paraphrase') }>{__( 'Paraphrase with Feedzy', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
311319
)
312320
)
313321
),
314322
(
315323
'item_categories' !== shortCode && (
316324
feedzyData.isPro && feedzyData.isAgencyPlan ? (
317-
<li onClick={ () => addAction('spinnerchief') }>{__( 'Spin using SpinnerChief', 'feedzy-rss-feeds' )}</li>
325+
<li key="action-7" onClick={ () => addAction('spinnerchief') }>{__( 'Spin using SpinnerChief', 'feedzy-rss-feeds' )}</li>
318326
) : (
319-
<li onClick={ () => addAction('spinnerchief') }>{__( 'Spin using SpinnerChief', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
327+
<li key="action-7" onClick={ () => addAction('spinnerchief') }>{__( 'Spin using SpinnerChief', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
320328
)
321329
)
322330
),
323331
(
324332
'item_categories' !== shortCode && (
325333
feedzyData.isPro && feedzyData.isAgencyPlan ? (
326-
<li onClick={ () => addAction('wordAI') }>{__( 'Spin using WordAI', 'feedzy-rss-feeds' )}</li>
334+
<li key="action-8" onClick={ () => addAction('wordAI') }>{__( 'Spin using WordAI', 'feedzy-rss-feeds' )}</li>
327335
) : (
328-
<li onClick={ () => addAction('wordAI') }>{__( 'Spin using WordAI', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
336+
<li key="action-8" onClick={ () => addAction('wordAI') }>{__( 'Spin using WordAI', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
329337
)
330338
)
331339
),
332340
(
333341
'item_categories' !== shortCode && (
334342
feedzyData.isPro && ( feedzyData.isBusinessPlan || feedzyData.isAgencyPlan ) ? (
335-
<li onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' )}</li>
343+
<li key="action-9" onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' )}</li>
336344
) : (
337-
<li onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
345+
<li key="action-9" onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
338346
)
339347
)
340348
),
341349
(
342350
'item_categories' !== shortCode && (
343351
feedzyData.isPro && ( feedzyData.isBusinessPlan || feedzyData.isAgencyPlan ) ? (
344-
<li onClick={ () => addAction('fz_summarize') }>{__( 'Summarize with ChatGPT', 'feedzy-rss-feeds' )}</li>
352+
<li key="action-10" onClick={ () => addAction('fz_summarize') }>{__( 'Summarize with ChatGPT', 'feedzy-rss-feeds' )}</li>
345353
) : (
346-
<li onClick={ () => addAction('fz_summarize') }>{__( 'Summarize with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
354+
<li key="action-10" onClick={ () => addAction('fz_summarize') }>{__( 'Summarize with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
347355
)
348356
)
349357
)

0 commit comments

Comments
 (0)