Skip to content

Commit

Permalink
Add modify links action
Browse files Browse the repository at this point in the history
  • Loading branch information
girishpanchal30 committed Aug 29, 2024
1 parent 4a46f97 commit 8151cf8
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 21 deletions.
9 changes: 6 additions & 3 deletions css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,7 @@ span.error-message .components-external-link .components-visually-hidden{
margin-left: auto;
padding: 0;
height: auto;
box-shadow: none !important;
}
.fz-action-btn button {
display: flex;
Expand Down Expand Up @@ -1765,7 +1766,7 @@ span.error-message .components-external-link .components-visually-hidden{
position: relative;
}
.popover-action-list{
width: 250px;
width: 270px;
position: absolute;
left: 100%;
bottom: 0;
Expand Down Expand Up @@ -2020,7 +2021,8 @@ li.draggable-item .components-panel__body-toggle.components-button{
.fz-action-panel .fz-chat-cpt-action .components-notice {
width: 100%;
}
.fz-action-panel .fz-chat-cpt-action .components-panel__row {
.fz-action-panel .fz-chat-cpt-action .components-panel__row,
.fz-action-panel .fz-modify-links .components-panel__row {
display: block;
}
.fz-action-panel .fz-upgrade-notice {
Expand Down Expand Up @@ -2090,7 +2092,8 @@ li.draggable-item .components-panel__body-toggle.components-button{
cursor: not-allowed !important;
}

.fz-action-panel .fz-chat-cpt-action .fz-notice-wrap {
.fz-action-panel .fz-chat-cpt-action .fz-notice-wrap,
.fz-action-panel .fz-modify-links .fz-notice-wrap {
padding: 0;
}

Expand Down
44 changes: 44 additions & 0 deletions includes/admin/feedzy-rss-feeds-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ public function action_process() {
return $this->summarize_content();
case 'fz_image':
return $this->generate_image();
case 'modify_links':
return $this->modify_links();
default:
return $this->default_content();
}
Expand Down Expand Up @@ -505,5 +507,47 @@ private function generate_image() {
$openai = new \Feedzy_Rss_Feeds_Pro_Openai();
return $openai->call_api( $this->settings, $prompt, 'image', array() );
}

/**
* Modify links.
*
* @return string Item content.
*/
private function modify_links() {
$content = call_user_func( array( $this, $this->current_job->tag ) );
// Returns item content because it has no HTML tags
if ( $content === wp_strip_all_tags( $content ) ) {
return $content;
}
// Pro version is required to perform this action.
if ( ! feedzy_is_pro() ) {
return $content;
}

$dom = new DOMDocument();
libxml_use_internal_errors( true );
$dom->loadHTML( $content );
$xpath = new DOMXPath( $dom );
libxml_clear_errors();
// Get all anchors tags.
$nodes = $xpath->query( '//a' );

if ( ! empty( $this->current_job->data->remove_links ) ) {
foreach ( $nodes as $node ) {
if ( ! empty( $this->current_job->data->remove_links ) ) {
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$node->parentNode->removeChild( $node );
continue;
}
if ( ! empty( $this->current_job->data->target ) ) {
$node->setAttribute( 'target', $this->current_job->data->target );
}
if ( ! empty( $this->current_job->data->follow ) && 'yes' === $this->current_job->data->follow ) {
$node->setAttribute( 'rel', 'nofollow' );
}
}
}
return $dom->saveHTML();
}
}
}
80 changes: 79 additions & 1 deletion js/ActionPopup/SortableItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
Popover,
ItemGroup,

Check warning on line 26 in js/ActionPopup/SortableItem.js

View workflow job for this annotation

GitHub Actions / npm (18.x)

ItemGroup not found in '@wordpress/components'
Item,

Check warning on line 27 in js/ActionPopup/SortableItem.js

View workflow job for this annotation

GitHub Actions / npm (18.x)

Item not found in '@wordpress/components'
ToggleControl
ToggleControl,
SelectControl
} from '@wordpress/components';

const DragHandle = sortableHandle(() => <Icon icon={dragHandle} size={18} className="components-panel__icon" />);
Expand Down Expand Up @@ -297,6 +298,83 @@ const SortableItem = ({ propRef, loopIndex, item }) => {
</li>
);
}

if ( 'modify_links' === item.id ) {
return(
<li className="fz-action-control fz-modify-links" data-counter={counter}>
<div className="fz-action-event">
<PanelBody title={ __( 'Modify Links', 'feedzy-rss-feeds' ) } icon={ DragHandle } initialOpen={ false }>
<PanelRow>
<UpgradeNotice higherPlanNotice={false} utmCampaign="action-modify-links"/>
<BaseControl className="mb-20">
<ToggleControl
checked={ item.data.remove_links ?? false }
label={ __( 'Remove links from the content?', 'feedzy-rss-feeds' ) }
onChange={ ( currentValue ) => propRef.onChangeHandler( { 'index': loopIndex, 'remove_links': currentValue ?? '' } ) }
disabled={!feedzyData.isPro}
/>
</BaseControl>
{ true !== item.data.remove_links &&
<BaseControl className="mb-20">
<SelectControl
label={__('Open Links In', 'feedzy-rss-feeds')}
value={ item.data.target || '' }
options={[
{
label: __('Default', 'feedzy-rss-feeds'),
value: '',
},
{
label: __('New Tab'),
value: '_blank',
},
{
label: __('Same Tab'),
value: '_self',
},
]}
onChange={ ( currentValue ) => propRef.onChangeHandler( { 'index': loopIndex, 'target': currentValue ?? '' } ) }
disabled={!feedzyData.isPro}
/>
</BaseControl>
}
{ true !== item.data.remove_links &&
<BaseControl>
<SelectControl
label={__( 'Make this link a "nofollow" link?', 'feedzy-rss-feeds' )}
value={ item.data.follow || '' }
onChange={ ( currentValue ) => propRef.onChangeHandler( { 'index': loopIndex, 'follow': currentValue ?? '' } ) }
options={[
{
label: __('Default', 'feedzy-rss-feeds'),
value: '',
},
{
label: __('No', 'feedzy-rss-feeds'),
value: 'no',
},
{
label: __('Yes', 'feedzy-rss-feeds'),
value: 'yes',
},
]}
disabled={!feedzyData.isPro}
/>
</BaseControl>
}
</PanelRow>
</PanelBody>
</div>
<div className="fz-trash-action">
<button type="button" onClick={() => { propRef.removeCallback(loopIndex) }}>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<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"/>
</svg>
</button>
</div>
</li>
);
}
}

export default SortableElement(SortableItem);
42 changes: 25 additions & 17 deletions js/ActionPopup/action-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
const ActionModal = () => {
// useRef
const userRef = useRef(null);
const feedzyImportRef = useRef(null);
// State
const [ isOpen, setOpen ] = useState(false);
const [ isHideMsg, setHideMeg ] = useState(false);
Expand Down Expand Up @@ -288,62 +287,71 @@ const ActionModal = () => {
{
'item_image' === shortCode ? ([
feedzyData.isPro && ( feedzyData.isBusinessPlan || feedzyData.isAgencyPlan ) ? (
<li onClick={ () => addAction('fz_image') }>{__( 'Generate with ChatGPT', 'feedzy-rss-feeds' )}</li>
<li key="action-1" onClick={ () => addAction('fz_image') }>{__( 'Generate with ChatGPT', 'feedzy-rss-feeds' )}</li>
) : (
<li onClick={ () => addAction('fz_image') }>{__( 'Generate with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
<li key="action-1" onClick={ () => addAction('fz_image') }>{__( 'Generate with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
)]
) : ([
<li onClick={ () => addAction('trim') }>{__( 'Trim Content', 'feedzy-rss-feeds' )}</li>,
<li key="action-2" onClick={ () => addAction('trim') }>{__( 'Trim Content', 'feedzy-rss-feeds' )}</li>,
(
feedzyData.isPro && feedzyData.isAgencyPlan ? (
<li onClick={ () => addAction('fz_translate') }>{__( 'Translate with Feedzy', 'feedzy-rss-feeds' )}</li>
<li key="action-3" onClick={ () => addAction('fz_translate') }>{__( 'Translate with Feedzy', 'feedzy-rss-feeds' )}</li>
) : (
<li onClick={ () => addAction('fz_translate') }>{__( 'Translate with Feedzy', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
<li key="action-3" onClick={ () => addAction('fz_translate') }>{__( 'Translate with Feedzy', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
)
),
<li key="action-4" onClick={ () => addAction('search_replace') }>{__( 'Search / Replace', 'feedzy-rss-feeds' )}</li>,
(
'item_categories' !== shortCode && (
feedzyData.isPro ? (
<li key="action-5" onClick={ () => addAction('modify_links') }>{__( 'Modify Links', 'feedzy-rss-feeds' )}</li>
) : (
<li key="action-5" onClick={ () => addAction('modify_links') }>{__( 'Modify Links', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
)
)
),
<li onClick={ () => addAction('search_replace') }>{__( 'Search / Replace', 'feedzy-rss-feeds' )}</li>,
(
'item_categories' !== shortCode && (
feedzyData.isPro && ( feedzyData.isBusinessPlan || feedzyData.isAgencyPlan ) ? (
<li onClick={ () => addAction('fz_paraphrase') }>{__( 'Paraphrase with Feedzy', 'feedzy-rss-feeds' )}</li>
<li key="action-6" onClick={ () => addAction('fz_paraphrase') }>{__( 'Paraphrase with Feedzy', 'feedzy-rss-feeds' )}</li>
) : (
<li onClick={ () => addAction('fz_paraphrase') }>{__( 'Paraphrase with Feedzy', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
<li key="action-6" onClick={ () => addAction('fz_paraphrase') }>{__( 'Paraphrase with Feedzy', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
)
)
),
(
'item_categories' !== shortCode && (
feedzyData.isPro && feedzyData.isAgencyPlan ? (
<li onClick={ () => addAction('spinnerchief') }>{__( 'Spin using SpinnerChief', 'feedzy-rss-feeds' )}</li>
<li key="action-7" onClick={ () => addAction('spinnerchief') }>{__( 'Spin using SpinnerChief', 'feedzy-rss-feeds' )}</li>
) : (
<li onClick={ () => addAction('spinnerchief') }>{__( 'Spin using SpinnerChief', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
<li key="action-7" onClick={ () => addAction('spinnerchief') }>{__( 'Spin using SpinnerChief', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
)
)
),
(
'item_categories' !== shortCode && (
feedzyData.isPro && feedzyData.isAgencyPlan ? (
<li onClick={ () => addAction('wordAI') }>{__( 'Spin using WordAI', 'feedzy-rss-feeds' )}</li>
<li key="action-8" onClick={ () => addAction('wordAI') }>{__( 'Spin using WordAI', 'feedzy-rss-feeds' )}</li>
) : (
<li onClick={ () => addAction('wordAI') }>{__( 'Spin using WordAI', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
<li key="action-8" onClick={ () => addAction('wordAI') }>{__( 'Spin using WordAI', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
)
)
),
(
'item_categories' !== shortCode && (
feedzyData.isPro && ( feedzyData.isBusinessPlan || feedzyData.isAgencyPlan ) ? (
<li onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' )}</li>
<li key="action-9" onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' )}</li>
) : (
<li onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
<li key="action-9" onClick={ () => addAction('chat_gpt_rewrite') }>{__( 'Paraphrase with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
)
)
),
(
'item_categories' !== shortCode && (
feedzyData.isPro && ( feedzyData.isBusinessPlan || feedzyData.isAgencyPlan ) ? (
<li onClick={ () => addAction('fz_summarize') }>{__( 'Summarize with ChatGPT', 'feedzy-rss-feeds' )}</li>
<li key="action-10" onClick={ () => addAction('fz_summarize') }>{__( 'Summarize with ChatGPT', 'feedzy-rss-feeds' )}</li>
) : (
<li onClick={ () => addAction('fz_summarize') }>{__( 'Summarize with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
<li key="action-10" onClick={ () => addAction('fz_summarize') }>{__( 'Summarize with ChatGPT', 'feedzy-rss-feeds' )} <span className="pro-label">PRO</span></li>
)
)
)
Expand Down

0 comments on commit 8151cf8

Please sign in to comment.