Skip to content

Commit e398392

Browse files
committed
[wip] Import Conditions
1 parent af6df21 commit e398392

11 files changed

+879
-312
lines changed

css/settings.css

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
.mb-20{margin-bottom: 20px;}
9090
.mb-30{margin-bottom: 30px;}
9191
.mb-24{margin-bottom: 24px;}
92+
.mt-24{margin-top: 24px;}
9293
.mx-320{
9394
max-width: 320px;
9495
}
@@ -2358,4 +2359,93 @@ li.draggable-item .components-panel__body-toggle.components-button{
23582359
.feedzy-optimole-upsell .pro-label.free-label {
23592360
color: #4268CF;
23602361
background: rgba(66, 104, 207, 0.20);
2361-
}
2362+
}
2363+
2364+
.fz-condition-control {
2365+
padding: 24px 0;
2366+
}
2367+
2368+
.fz-conditions .components-disabled {
2369+
opacity: 0.5;
2370+
}
2371+
2372+
.fz-condition-control .components-button {
2373+
width: 100%;
2374+
margin: 0;
2375+
padding: 6px 12px;
2376+
justify-content: center;
2377+
}
2378+
2379+
.fz-panel-tab {
2380+
z-index: 999999;
2381+
margin: 24px 0;
2382+
}
2383+
2384+
.fz-panel-tab .fz-panel-tab__header {
2385+
display: flex;
2386+
background: #fff;
2387+
border: 1px solid #d5dadf;
2388+
}
2389+
2390+
.fz-panel-tab .fz-panel-tab__header .fz-panel-tab__header__label {
2391+
cursor: pointer;
2392+
flex-basis: 90%;
2393+
display: flex;
2394+
align-items: center;
2395+
padding-left: 15px;
2396+
}
2397+
2398+
.fz-panel-tab .fz-panel-tab__header .fz-panel-tab__header__label::selection {
2399+
background: none;
2400+
}
2401+
2402+
.fz-panel-tab .fz-panel-tab__header .components-button {
2403+
height: auto;
2404+
flex-basis: 10%;
2405+
justify-content: center;
2406+
padding: 10px 5px;
2407+
border-left: 1px solid #d5dadf;
2408+
border-radius: 0;
2409+
}
2410+
2411+
.fz-panel-tab .fz-panel-tab__header .components-button .dashicon {
2412+
margin: 2px;
2413+
}
2414+
2415+
.fz-panel-tab .fz-panel-tab__header:hover {
2416+
background: #fafafb;
2417+
}
2418+
2419+
.fz-panel-tab .fz-panel-tab__content {
2420+
background: #fff;
2421+
border: 1px solid #d5dadf;
2422+
border-top: none;
2423+
padding: 10px 15px;
2424+
}
2425+
2426+
.fz-panel-tab .fz-panel-tab__content .components-select-control label {
2427+
overflow: visible;
2428+
white-space: normal;
2429+
}
2430+
2431+
.fz-panel-tab .fz-panel-tab__content .components-base-control {
2432+
margin: 12px 0;
2433+
}
2434+
2435+
.fz-panel-tab .fz-panel-tab__content .components-base-control .components-dropdown {
2436+
width: 100%;
2437+
}
2438+
2439+
.fz-panel-tab .fz-panel-tab__content .components-base-control .components-dropdown .components-button {
2440+
display: flex;
2441+
justify-content: center;
2442+
width: 100%;
2443+
}
2444+
2445+
.fz-panel-tab .fz-panel-tab__content .components-base-control .components-datetime__time-field-hours-input {
2446+
min-width: 60px;
2447+
}
2448+
2449+
.fz-panel-tab .fz-panel-tab__content .components-base-control .components-datetime__timezone {
2450+
display: inline-block;
2451+
}

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

Lines changed: 33 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -301,78 +301,6 @@ public function feedzy_summary_input_filter( $description, $content, $feed_url )
301301
return $description;
302302
}
303303

304-
/**
305-
* Check title for keywords
306-
*
307-
* @since 3.0.0
308-
* @access public
309-
*
310-
* @param boolean $continue A boolean to stop the script.
311-
* @param array $sc The shortcode attributes.
312-
* @param object $item The feed item.
313-
* @param string $feed_url The feed URL.
314-
*
315-
* @return boolean
316-
*/
317-
public function feedzy_feed_item_keywords_title( $continue, $sc, $item, $feed_url ) {
318-
if ( feedzy_is_new() && ! feedzy_is_pro() ) {
319-
return true;
320-
}
321-
322-
$inc_on = ! empty( $sc['keywords_inc_on'] ) ? $sc['keywords_inc_on'] : 'title';
323-
$exc_on = ! empty( $sc['keywords_exc_on'] ) ? $sc['keywords_exc_on'] : 'title';
324-
325-
if ( isset( $sc['keywords_inc'] ) && ! empty( $sc['keywords_inc'] ) ) {
326-
$keywords = $sc['keywords_inc'];
327-
if ( ! empty( $keywords ) ) {
328-
$continue = false;
329-
if ( ! empty( $inc_on ) ) {
330-
$continue = $this->feedzy_feed_item_keywords_by( $item, $inc_on, $keywords, $sc );
331-
} elseif ( preg_match( "/^$keywords.*$/i", $item->get_title() ) || preg_match( "/^$keywords.*$/i", $item->get_description() ) ) {
332-
$continue = true;
333-
}
334-
}
335-
} elseif ( isset( $sc['keywords_title'] ) && ! empty( $sc['keywords_title'] ) ) {
336-
$keywords = $sc['keywords_title'];
337-
if ( ! empty( $keywords ) ) {
338-
$continue = false;
339-
if ( ! empty( $inc_on ) ) {
340-
$continue = $this->feedzy_feed_item_keywords_by( $item, $inc_on, $keywords, $sc );
341-
} elseif ( preg_match( "/^$keywords.*$/i", $item->get_title() ) ) {
342-
$continue = true;
343-
}
344-
}
345-
}
346-
347-
if ( isset( $sc['keywords_exc'] ) && ! empty( $sc['keywords_exc'] ) ) {
348-
$keywords = $sc['keywords_exc'];
349-
if ( ! empty( $keywords ) ) {
350-
if ( ! empty( $exc_on ) ) {
351-
$exc_item = $this->feedzy_feed_item_keywords_by( $item, $exc_on, $keywords, $sc );
352-
if ( $exc_item ) {
353-
$continue = false;
354-
}
355-
} elseif ( ! preg_match( "/^$keywords.*$/i", $item->get_title() ) || ! preg_match( "/^$keywords.*$/i", $item->get_description() ) ) {
356-
$continue = false;
357-
}
358-
}
359-
} elseif ( isset( $sc['keywords_ban'] ) && ! empty( $sc['keywords_ban'] ) ) {
360-
$keywords = $sc['keywords_ban'];
361-
if ( ! empty( $keywords ) ) {
362-
if ( ! empty( $exc_on ) ) {
363-
$keywords_ban = $this->feedzy_feed_item_keywords_by( $item, $exc_on, $keywords, $sc );
364-
if ( $keywords_ban ) {
365-
$continue = false;
366-
}
367-
} elseif ( preg_match( "/^$keywords.*$/i", $item->get_title() ) ) {
368-
$continue = false;
369-
}
370-
}
371-
}
372-
373-
return $continue;
374-
}
375-
376304
/**
377305
* Include cover picture (medium) to rss feed enclosure
378306
* and media:content
@@ -514,6 +442,22 @@ public function feedzy_rss( $atts, $content = '' ) {
514442
}
515443
}
516444

445+
$sc['filters'] = apply_filters( 'feedzy_filter_conditions_migration', $sc );
446+
447+
$sc = array_diff_key(
448+
$sc,
449+
array(
450+
'keywords_title' => '',
451+
'keywords_inc' => '',
452+
'keywords_inc_on' => '',
453+
'keywords_exc' => '',
454+
'keywords_exc_on' => '',
455+
'keywords_ban' => '',
456+
'from_datetime' => '',
457+
'to_datetime' => '',
458+
)
459+
);
460+
517461
$feed = $this->fetch_feed( $feed_url, $cache, $sc );
518462
if ( is_string( $feed ) ) {
519463
return $feed;
@@ -560,6 +504,23 @@ public function feedzy_lazy_load( $data ) {
560504
$atts = $data['args'];
561505
$sc = $this->get_short_code_attributes( $atts );
562506
$feed_url = $this->normalize_urls( $sc['feeds'] );
507+
508+
$sc['filters'] = apply_filters( 'feedzy_filter_conditions_migration', $sc );
509+
510+
$sc = array_diff_key(
511+
$sc,
512+
array(
513+
'keywords_title' => '',
514+
'keywords_inc' => '',
515+
'keywords_inc_on' => '',
516+
'keywords_exc' => '',
517+
'keywords_exc_on' => '',
518+
'keywords_ban' => '',
519+
'from_datetime' => '',
520+
'to_datetime' => '',
521+
)
522+
);
523+
563524
$feed = $this->fetch_feed( $feed_url, $sc['refresh'], $sc );
564525
if ( is_string( $feed ) ) {
565526
return $feed;
@@ -1087,30 +1048,6 @@ public function sanitize_attr( $sc, $feed_url ) {
10871048
if ( empty( $sc['size'] ) || ! ctype_digit( (string) $sc['size'] ) ) {
10881049
$sc['size'] = '150';
10891050
}
1090-
if ( ! empty( $sc['keywords_title'] ) ) {
1091-
if ( is_array( $sc['keywords_title'] ) ) {
1092-
$sc['keywords_title'] = implode( ',', $sc['keywords_title'] );
1093-
}
1094-
$sc['keywords_title'] = feedzy_filter_custom_pattern( $sc['keywords_title'] );
1095-
}
1096-
if ( ! empty( $sc['keywords_inc'] ) ) {
1097-
if ( is_array( $sc['keywords_inc'] ) ) {
1098-
$sc['keywords_inc'] = implode( ',', $sc['keywords_inc'] );
1099-
}
1100-
$sc['keywords_inc'] = feedzy_filter_custom_pattern( $sc['keywords_inc'] );
1101-
}
1102-
if ( ! empty( $sc['keywords_ban'] ) ) {
1103-
if ( is_array( $sc['keywords_ban'] ) ) {
1104-
$sc['keywords_ban'] = implode( ',', $sc['keywords_ban'] );
1105-
}
1106-
$sc['keywords_ban'] = feedzy_filter_custom_pattern( $sc['keywords_ban'] );
1107-
}
1108-
if ( ! empty( $sc['keywords_exc'] ) ) {
1109-
if ( is_array( $sc['keywords_exc'] ) ) {
1110-
$sc['keywords_exc'] = implode( ',', $sc['keywords_exc'] );
1111-
}
1112-
$sc['keywords_exc'] = feedzy_filter_custom_pattern( $sc['keywords_exc'] );
1113-
}
11141051
if ( empty( $sc['summarylength'] ) || ! is_numeric( $sc['summarylength'] ) ) {
11151052
$sc['summarylength'] = '';
11161053
}
@@ -1937,60 +1874,6 @@ protected function array_insert_before( $key, &$array, $new_key, $new_value ) {
19371874
return false;
19381875
}
19391876

1940-
/**
1941-
* Keyword filter in multiple fields.
1942-
*
1943-
* @param object $item The feed item.
1944-
* @param string $filter_by Filter by.
1945-
* @param string $keywords Keywords.
1946-
*
1947-
* @return bool
1948-
*/
1949-
public function feedzy_feed_item_keywords_by( $item, $filter_by = '', $keywords = '', $sc = array() ) {
1950-
$is_valid = false;
1951-
1952-
if ( empty( $filter_by ) ) {
1953-
return $is_valid;
1954-
}
1955-
1956-
if ( 'title' === $filter_by ) {
1957-
$item_title = wp_strip_all_tags( $item->get_title(), true );
1958-
if ( ! empty( $item_title ) && preg_match( "/^$keywords.*$/i", $item_title ) ) {
1959-
$is_valid = true;
1960-
}
1961-
} elseif ( 'description' === $filter_by ) {
1962-
$description = wp_strip_all_tags( $item->get_content(), true );
1963-
if ( ! empty( $description ) && preg_match( "/^$keywords.*$/i", $description ) ) {
1964-
$is_valid = true;
1965-
}
1966-
} elseif ( 'author' === $filter_by ) {
1967-
$author = $item->get_author();
1968-
$author_name = '';
1969-
if ( $author ) {
1970-
$author_name = $author->get_name();
1971-
}
1972-
if ( ! empty( $author_name ) && preg_match( "/^$keywords.*$/i", $author_name ) ) {
1973-
$is_valid = true;
1974-
}
1975-
} elseif ( 'fullcontent' === $filter_by ) {
1976-
$content = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'full-content' );
1977-
$content = ! empty( $content[0]['data'] ) ? $content[0]['data'] : '';
1978-
$content = wp_strip_all_tags( $content, true );
1979-
if ( ! empty( $content ) && preg_match( "/^$keywords.*$/i", $content ) ) {
1980-
$is_valid = true;
1981-
}
1982-
}
1983-
1984-
// Date filter.
1985-
if ( $is_valid && ( ! empty( $sc['from_datetime'] ) && ! empty( $sc['to_datetime'] ) ) ) {
1986-
$from_datetime = strtotime( $sc['from_datetime'] );
1987-
$to_datetime = strtotime( $sc['to_datetime'] );
1988-
$item_date = strtotime( $item->get_date() );
1989-
$is_valid = ( ( $from_datetime <= $item_date ) && ( $item_date <= $to_datetime ) );
1990-
}
1991-
return $is_valid;
1992-
}
1993-
19941877
/**
19951878
* Init amazon API.
19961879
*

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,27 @@ public function enqueue_styles_admin() {
212212
'languageList' => $this->get_lang_list(),
213213
)
214214
);
215+
216+
$asset_file = include FEEDZY_ABSPATH . '/js/build/conditions.asset.php';
217+
wp_enqueue_script( $this->plugin_name . '_conditions', FEEDZY_ABSURL . 'js/build/conditions.js', array_merge( $asset_file['dependencies'], array( 'wp-editor', 'wp-api' ) ), $asset_file['version'], true );
218+
219+
// Add wp_localize_script to pass variables to the JS file with a filter over the data.
220+
wp_localize_script(
221+
$this->plugin_name . '_conditions',
222+
'feedzyConditionsData',
223+
apply_filters(
224+
'feedzy_conditions_data',
225+
array(
226+
'isPro' => feedzy_is_pro(),
227+
'isBusinessPlan' => apply_filters( 'feedzy_is_license_of_type', false, 'business' ),
228+
'isAgencyPlan' => apply_filters( 'feedzy_is_license_of_type', false, 'agency' ),
229+
'apiLicenseStatus' => $this->api_license_status(),
230+
'isHighPrivileges' => current_user_can( 'manage_options' ),
231+
'operators' => Feedzy_Rss_Feeds_Conditions::get_operators(),
232+
)
233+
)
234+
);
235+
215236
wp_enqueue_style( 'wp-block-editor' );
216237

217238
$this->register_survey();

0 commit comments

Comments
 (0)