@@ -897,6 +897,19 @@ public function add_feedzy_post_type_metaboxes() {
897897 'low '
898898 );
899899 }
900+
901+ if ( 'publish ' === get_post_status () ) {
902+ add_meta_box (
903+ 'feedzy_category_feeds_preview ' ,
904+ __ ( 'Feed Preview ' , 'feedzy-rss-feeds ' ),
905+ array (
906+ $ this ,
907+ 'render_feed_preview ' ,
908+ ),
909+ 'feedzy_categories ' ,
910+ 'side '
911+ );
912+ }
900913 }
901914
902915 /**
@@ -939,12 +952,106 @@ public function feedzy_category_feed() {
939952 )
940953 . '</strong><br/><br/> '
941954 . $ invalid
942- . '<textarea name="feedzy_category_feed" rows="15" class="widefat" placeholder=" ' . __ ( 'Place your URL \'s here followed by a comma. ' , 'feedzy-rss-feeds ' ) . '" > ' . $ feed . '</textarea>
943- <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>
955+ . '<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>
956+ <div class="validate-feeds-actions">
957+ <span class="spinner"></span>
958+ <button class="button validate-feeds" ' . esc_attr ( empty ( $ feed ) ? 'disabled ' : '' ) . '> ' . __ ( 'Validate & Remove Invalid Feeds ' , 'feedzy-rss-feeds ' ) . '</button>
959+ </div>
944960 ' ;
945961 echo wp_kses ( $ output , apply_filters ( 'feedzy_wp_kses_allowed_html ' , array () ) );
946962 }
947963
964+ /**
965+ * Render the feed preview metabox.
966+ *
967+ * @return void
968+ */
969+ public function render_feed_preview () {
970+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended
971+ if ( isset ( $ _GET ['action ' ] ) && 'edit ' !== $ _GET ['action ' ] ) {
972+ return ;
973+ }
974+ $ feeds = get_post_meta ( get_the_ID (), 'feedzy_category_feed ' , true );
975+ $ feed_urls = $ this ->normalize_urls ( $ feeds );
976+ if ( empty ( $ feed_urls ) ) {
977+ echo '<p> ' . esc_html__ ( 'No feeds available for preview. ' , 'feedzy-rss-feeds ' ) . '</p> ' ;
978+ return ;
979+ }
980+ $ shortcode = array (
981+ 'sort ' => 'date_desc ' ,
982+ 'thumb ' => 'no ' ,
983+ 'max ' => 0 ,
984+ );
985+ $ atts = $ this ->get_short_code_attributes ( $ shortcode );
986+ $ atts = $ this ->sanitize_attr ( $ atts , $ feed_urls );
987+ $ sizes = array (
988+ 'width ' => 0 ,
989+ 'height ' => 0 ,
990+ );
991+ $ feed = $ this ->fetch_feed ( $ feed_urls , $ atts ['refresh ' ], $ atts );
992+ $ feed_items = apply_filters ( 'feedzy_get_feed_array ' , array (), $ atts , $ feed , $ feed_urls , $ sizes );
993+ $ total_items = count ( $ feed_items );
994+
995+ $ max_items_preview_count = 5 ;
996+ $ preview_feed_items = array_slice ( $ feed_items , 0 , $ max_items_preview_count );
997+ ?>
998+ <strong>
999+ <?php
1000+ echo esc_html (
1001+ sprintf (
1002+ // translators: %1$s the number of maximum displayed items, %2$s is the total number of items available in the feed.
1003+ __ ( 'Latest %1$s feed items out of %2$s available from ' , 'feedzy-rss-feeds ' ),
1004+ $ max_items_preview_count ,
1005+ $ total_items
1006+ )
1007+ );
1008+ ?>
1009+ </strong>
1010+ <div>
1011+ <ul class="feedzy-preview-list">
1012+ <?php
1013+ foreach ( $ preview_feed_items as $ item ) {
1014+ $ datetime = date_i18n ( 'c ' , $ item ['item_date ' ] );
1015+ $ time_content = date_i18n ( 'Y-m-d ' , $ item ['item_date ' ] );
1016+ ?>
1017+ <li <?php echo esc_attr ( $ item ['itemAttr ' ] ); ?> >
1018+ <a href="<?php echo esc_url ( $ item ['item_url ' ] ); ?> " target="_blank">
1019+ <?php echo esc_html ( $ item ['item_title ' ] ); ?>
1020+ </a>
1021+ <br/>
1022+ <time
1023+ datetime="<?php echo esc_attr ( $ datetime ); ?> "
1024+ content="<?php echo esc_attr ( $ time_content ); ?> "
1025+ >
1026+ <?php echo esc_html ( $ this ->get_humman_readable_time_diff ( $ item ['item_date ' ] ) ); ?>
1027+ </time>
1028+ </li>
1029+ <?php
1030+ }
1031+ ?>
1032+ </ul>
1033+ </div>
1034+ <?php
1035+ }
1036+
1037+ /**
1038+ * Get human readable time difference.
1039+ *
1040+ * @param int $item_publish_time The item publish time.
1041+ *
1042+ * @return string
1043+ */
1044+ private function get_humman_readable_time_diff ( $ item_publish_time ) {
1045+ $ array = current_datetime ();
1046+ $ localtime = $ array ->getTimestamp () + $ array ->getOffset ();
1047+
1048+ return sprintf (
1049+ // translators: %s is the time difference.
1050+ __ ( '%s ago ' , 'feedzy-rss-feeds ' ),
1051+ human_time_diff ( $ item_publish_time , $ localtime )
1052+ );
1053+ }
1054+
9481055 /**
9491056 * Utility method to save metabox data to
9501057 * custom post type.
@@ -1030,6 +1137,8 @@ public function feedzy_category_columns( $columns ) {
10301137 $ columns ['actions ' ] = __ ( 'Actions ' , 'feedzy-rss-feeds ' );
10311138 }
10321139
1140+ $ new_columns = $ this ->array_insert_before ( 'slug ' , $ columns , 'source ' , __ ( 'Source ' , 'feedzy-rss-feeds ' ) );
1141+
10331142 return $ columns ;
10341143 }
10351144
@@ -1074,6 +1183,33 @@ public function manage_feedzy_category_columns( $column, $post_id ) {
10741183 case 'actions ' :
10751184 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 ' ) ) );
10761185 break ;
1186+ case 'source ' :
1187+ $ src = get_post_meta ( $ post_id , 'feedzy_category_feed ' , true );
1188+ if ( empty ( $ src ) ) {
1189+ $ src = __ ( 'No Source Configured ' , 'feedzy-rss-feeds ' );
1190+ } else {
1191+ $ urls = $ this ->normalize_urls ( $ src );
1192+ $ src = '' ;
1193+ if ( is_array ( $ urls ) ) {
1194+
1195+ foreach ( $ urls as $ key => $ url ) {
1196+ $ too_long = 130 ;
1197+ if ( strlen ( $ src ) > $ too_long ) {
1198+ $ src .= '... ' ;
1199+ break ;
1200+ } else {
1201+ $ src .= '<a href=" ' . $ url . '" target="_blank" title=" ' . __ ( 'Click to view ' , 'feedzy-rss-feeds ' ) . '"> ' . $ url . '</a> ' ;
1202+ if ( count ( $ urls ) > $ key + 1 ) {
1203+ $ src .= ', ' ;
1204+ }
1205+ }
1206+ }
1207+ } else {
1208+ $ src .= '<a href=" ' . esc_url ( $ urls ) . '" target="_blank" title=" ' . __ ( 'Click to view ' , 'feedzy-rss-feeds ' ) . '"> ' . esc_html ( $ urls ) . '</a> ' ;
1209+ }
1210+ }
1211+ echo wp_kses_post ( $ src );
1212+ break ;
10771213 default :
10781214 break ;
10791215 }
@@ -1709,6 +1845,23 @@ public function ajax() {
17091845 }
17101846 wp_send_json_success ( array ( 'invalid ' => count ( $ invalid ) ) );
17111847 break ;
1848+ case 'validate_feeds_group ' :
1849+ $ feeds = isset ( $ _POST ['feeds ' ] ) ? sanitize_text_field ( wp_unslash ( $ _POST ['feeds ' ] ) ) : '' ;
1850+ if ( empty ( $ feeds ) ) {
1851+ wp_send_json_error ( __ ( 'No feeds provided for validation. ' , 'feedzy-rss-feeds ' ) );
1852+ }
1853+ $ feeds = $ this ->normalize_urls ( $ feeds );
1854+ if ( ! is_array ( $ feeds ) ) {
1855+ $ feeds = array ( $ feeds );
1856+ }
1857+ $ valid = $ this ->get_valid_source_urls ( $ feeds , '1_mins ' , false );
1858+ $ invalid = array_diff ( $ feeds , $ valid );
1859+ wp_send_json_success (
1860+ array (
1861+ 'valid ' => $ valid ,
1862+ 'invalid ' => $ invalid ,
1863+ )
1864+ );
17121865 }
17131866 }
17141867
0 commit comments