@@ -708,6 +708,19 @@ public function add_feedzy_post_type_metaboxes() {
708
708
'low '
709
709
);
710
710
}
711
+
712
+ if ( 'publish ' === get_post_status () ) {
713
+ add_meta_box (
714
+ 'feedzy_category_feeds_preview ' ,
715
+ __ ( 'Feed Preview ' , 'feedzy-rss-feeds ' ),
716
+ array (
717
+ $ this ,
718
+ 'render_feed_preview ' ,
719
+ ),
720
+ 'feedzy_categories ' ,
721
+ 'side '
722
+ );
723
+ }
711
724
}
712
725
713
726
/**
@@ -750,12 +763,118 @@ public function feedzy_category_feed() {
750
763
)
751
764
. '</strong><br/><br/> '
752
765
. $ invalid
753
- . '<textarea name="feedzy_category_feed" rows="15" class="widefat" placeholder=" ' . __ ( 'Place your URL \'s here followed by a comma. ' , 'feedzy-rss-feeds ' ) . '" > ' . $ feed . '</textarea>
754
- <p><a href=" ' . esc_url ( 'https://docs.themeisle.com/article/1119-feedzy-rss-feeds-documentation#categories ' ) . '" target="_blank"> ' . __ ( 'Learn how to organize feeds in Groups ' , 'feedzy-rss-feeds ' ) . '</a></p>
766
+ . '<textarea name="feedzy_category_feed" rows="10" class="widefat" placeholder="themeisle.com/blog/feed/, https://wptavern.com/feed/, https://www.wpbeginner.com/feed/, https://wpshout.com/feed/, https://planet.wordpress.org/feed/" > ' . $ feed . '</textarea>
767
+ <div class="validate-feeds-actions">
768
+ <span class="spinner"></span>
769
+ <button class="button validate-feeds" ' . esc_attr ( empty ( $ feed ) ? 'disabled ' : '' ) . '> ' . __ ( 'Validate & Remove Invalid Feeds ' , 'feedzy-rss-feeds ' ) . '</button>
770
+ </div>
755
771
' ;
756
772
echo wp_kses ( $ output , apply_filters ( 'feedzy_wp_kses_allowed_html ' , array () ) );
757
773
}
758
774
775
+ /**
776
+ * Render the feed preview metabox.
777
+ *
778
+ * @return void
779
+ */
780
+ public function render_feed_preview () {
781
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended
782
+ if ( isset ( $ _GET ['action ' ] ) && 'edit ' !== $ _GET ['action ' ] ) {
783
+ return ;
784
+ }
785
+ $ feeds = get_post_meta ( get_the_ID (), 'feedzy_category_feed ' , true );
786
+ $ feed_urls = $ this ->normalize_urls ( $ feeds );
787
+ if ( empty ( $ feed_urls ) ) {
788
+ echo '<p> ' . esc_html__ ( 'No feeds available for preview. ' , 'feedzy-rss-feeds ' ) . '</p> ' ;
789
+ return ;
790
+ }
791
+ $ shortcode = array (
792
+ 'sort ' => 'date_desc ' ,
793
+ 'thumb ' => 'no ' ,
794
+ 'max ' => 0 ,
795
+ );
796
+ $ atts = $ this ->get_short_code_attributes ( $ shortcode );
797
+ $ atts = $ this ->sanitize_attr ( $ atts , $ feed_urls );
798
+ $ sizes = array (
799
+ 'width ' => 0 ,
800
+ 'height ' => 0 ,
801
+ );
802
+ $ feed = $ this ->fetch_feed ( $ feed_urls , $ atts ['refresh ' ], $ atts );
803
+ $ feed_items = apply_filters ( 'feedzy_get_feed_array ' , array (), $ atts , $ feed , $ feed_urls , $ sizes );
804
+ $ total_items = count ( $ feed_items );
805
+ $ count = 0 ;
806
+
807
+ echo wp_kses (
808
+ sprintf (
809
+ // translators: %s is the total number of items available in the feed.
810
+ '<strong> ' . __ ( 'Latest 5 feed items out of %s available from ' , 'feedzy-rss-feeds ' ) . '</strong> ' ,
811
+ $ total_items
812
+ ),
813
+ array (
814
+ 'strong ' => array (),
815
+ )
816
+ );
817
+
818
+ echo '<div class="feedzy-preview"> ' ;
819
+ $ content = '<ul class="feedzy-preview-list"> ' ;
820
+
821
+ foreach ( $ feed_items as $ item ) {
822
+ if ( $ count > 4 ) {
823
+ break ;
824
+ }
825
+ $ content .= sprintf (
826
+ '<li %s><a href="%s" target="_blank">%s</a><br/><time datetime="%s" content="%s">%s</time></li> ' ,
827
+ esc_attr ( $ item ['itemAttr ' ] ),
828
+ esc_attr ( $ item ['item_url ' ] ),
829
+ esc_html ( $ item ['item_title ' ] ),
830
+ esc_attr ( date_i18n ( 'c ' , $ item ['item_date ' ] ) ),
831
+ esc_attr ( date_i18n ( 'Y-m-d ' , $ item ['item_date ' ] ) ),
832
+ esc_html ( $ this ->get_humman_readable_time_diff ( $ item ['item_date ' ] ) )
833
+ );
834
+ ++$ count ;
835
+ }
836
+ $ content .= '</ul> ' ;
837
+ echo wp_kses (
838
+ $ content ,
839
+ array (
840
+ 'ul ' => array (
841
+ 'class ' => array (),
842
+ ),
843
+ 'li ' => array (
844
+ 'class ' => array (),
845
+ ),
846
+ 'a ' => array (
847
+ 'href ' => array (),
848
+ 'target ' => array (),
849
+ ),
850
+ 'time ' => array (
851
+ 'datetime ' => array (),
852
+ 'content ' => array (),
853
+ ),
854
+ 'br ' => array (),
855
+ )
856
+ );
857
+ echo '</div> ' ;
858
+ }
859
+
860
+ /**
861
+ * Get human readable time difference.
862
+ *
863
+ * @param int $item_publish_time The item publish time.
864
+ *
865
+ * @return string
866
+ */
867
+ private function get_humman_readable_time_diff ( $ item_publish_time ) {
868
+ $ array = current_datetime ();
869
+ $ localtime = $ array ->getTimestamp () + $ array ->getOffset ();
870
+
871
+ return sprintf (
872
+ // translators: %s is the time difference.
873
+ __ ( '%s ago ' , 'feedzy-rss-feeds ' ),
874
+ human_time_diff ( $ item_publish_time , $ localtime )
875
+ );
876
+ }
877
+
759
878
/**
760
879
* Utility method to save metabox data to
761
880
* custom post type.
@@ -841,6 +960,13 @@ public function feedzy_category_columns( $columns ) {
841
960
$ columns ['actions ' ] = __ ( 'Actions ' , 'feedzy-rss-feeds ' );
842
961
}
843
962
963
+ $ new_columns = $ this ->array_insert_before ( 'slug ' , $ columns , 'source ' , __ ( 'Source ' , 'feedzy-rss-feeds ' ) );
964
+ if ( $ new_columns ) {
965
+ $ columns = $ new_columns ;
966
+ } else {
967
+ $ columns ['Source ' ] = __ ( 'source ' , 'feedzy-rss-feeds ' );
968
+ }
969
+
844
970
return $ columns ;
845
971
}
846
972
@@ -885,6 +1011,33 @@ public function manage_feedzy_category_columns( $column, $post_id ) {
885
1011
case 'actions ' :
886
1012
echo wp_kses_post ( sprintf ( '<button class="button button-primary validate-category" title="%s" data-category-id="%d">%s</button> ' , __ ( 'Click to remove invalid URLs from this category ' , 'feedzy-rss-feeds ' ), $ post_id , __ ( 'Validate & Clean ' , 'feedzy-rss-feeds ' ) ) );
887
1013
break ;
1014
+ case 'source ' :
1015
+ $ src = get_post_meta ( $ post_id , 'feedzy_category_feed ' , true );
1016
+ if ( empty ( $ src ) ) {
1017
+ $ src = __ ( 'No Source Configured ' , 'feedzy-rss-feeds ' );
1018
+ } else {
1019
+ $ urls = $ this ->normalize_urls ( $ src );
1020
+ $ src = '' ;
1021
+ if ( is_array ( $ urls ) ) {
1022
+
1023
+ foreach ( $ urls as $ key => $ url ) {
1024
+ $ too_long = 130 ;
1025
+ if ( strlen ( $ src ) > $ too_long ) {
1026
+ $ src .= '... ' ;
1027
+ break ;
1028
+ } else {
1029
+ $ src .= '<a href=" ' . $ url . '" target="_blank" title=" ' . __ ( 'Click to view ' , 'feedzy-rss-feeds ' ) . '"> ' . $ url . '</a> ' ;
1030
+ if ( count ( $ urls ) > $ key + 1 ) {
1031
+ $ src .= ', ' ;
1032
+ }
1033
+ }
1034
+ }
1035
+ } else {
1036
+ $ src .= '<a href=" ' . esc_url ( $ urls ) . '" target="_blank" title=" ' . __ ( 'Click to view ' , 'feedzy-rss-feeds ' ) . '"> ' . esc_html ( $ urls ) . '</a> ' ;
1037
+ }
1038
+ }
1039
+ echo wp_kses_post ( $ src );
1040
+ break ;
888
1041
default :
889
1042
break ;
890
1043
}
@@ -1477,6 +1630,23 @@ public function ajax() {
1477
1630
}
1478
1631
wp_send_json_success ( array ( 'invalid ' => count ( $ invalid ) ) );
1479
1632
break ;
1633
+ case 'validate_feeds_group ' :
1634
+ $ feeds = isset ( $ _POST ['feeds ' ] ) ? sanitize_text_field ( wp_unslash ( $ _POST ['feeds ' ] ) ) : '' ;
1635
+ if ( empty ( $ feeds ) ) {
1636
+ wp_send_json_error ( __ ( 'No feeds provided for validation. ' , 'feedzy-rss-feeds ' ) );
1637
+ }
1638
+ $ feeds = $ this ->normalize_urls ( $ feeds );
1639
+ if ( ! is_array ( $ feeds ) ) {
1640
+ $ feeds = array ( $ feeds );
1641
+ }
1642
+ $ valid = $ this ->get_valid_source_urls ( $ feeds , '1_mins ' , false );
1643
+ $ invalid = array_diff ( $ feeds , $ valid );
1644
+ wp_send_json_success (
1645
+ array (
1646
+ 'valid ' => $ valid ,
1647
+ 'invalid ' => $ invalid ,
1648
+ )
1649
+ );
1480
1650
}
1481
1651
}
1482
1652
0 commit comments