Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modify links action #974

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
52 changes: 52 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,55 @@ 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;
}
// converts all special characters to utf-8.
$content = mb_convert_encoding( $content, 'HTML-ENTITIES', 'UTF-8' );

$dom = new DOMDocument( '1.0', 'utf-8' );
libxml_use_internal_errors( true );
$dom->loadHTML( $content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
$xpath = new DOMXPath( $dom );
libxml_clear_errors();
// Get all anchors tags.
$nodes = $xpath->query( '//a' );

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' );
}
}
if ( ! empty( $this->current_job->data->follow ) && 'yes' === $this->current_job->data->follow ) {
add_filter(
'wp_targeted_link_rel',
function() {
return 'nofollow';
}
);
}
return $dom->saveHTML();
}
}
}
80 changes: 79 additions & 1 deletion js/ActionPopup/SortableItem.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';

Check failure on line 1 in js/ActionPopup/SortableItem.js

View workflow job for this annotation

GitHub Actions / npm (18.x)

'react' should be listed in the project's dependencies. Run 'npm i -S react' to add it
import { SortableElement, sortableHandle } from 'react-sortable-hoc';
import { __ } from '@wordpress/i18n';
import { unescape } from 'lodash';
import {
Icon,
dragHandle,
close,

Check failure on line 8 in js/ActionPopup/SortableItem.js

View workflow job for this annotation

GitHub Actions / npm (18.x)

'close' is defined but never used
plus,
trash,
external
Expand All @@ -23,9 +23,10 @@
TextareaControl,
Notice,
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 @@
</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
Loading