Skip to content

Commit 2b8fe4f

Browse files
refactor: feed preview html
1 parent ecc3509 commit 2b8fe4f

File tree

1 file changed

+39
-51
lines changed

1 file changed

+39
-51
lines changed

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

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -802,59 +802,47 @@ public function render_feed_preview() {
802802
$feed = $this->fetch_feed( $feed_urls, $atts['refresh'], $atts );
803803
$feed_items = apply_filters( 'feedzy_get_feed_array', array(), $atts, $feed, $feed_urls, $sizes );
804804
$total_items = count( $feed_items );
805-
$count = 0;
806805

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;
806+
$max_items_preview_count = 5;
807+
$preview_feed_items = array_slice( $feed_items, 0, $max_items_preview_count );
808+
?>
809+
<strong>
810+
<?php
811+
echo esc_html(
812+
sprintf(
813+
// translators: %1$s the number of maximum displayed items, %2$s is the total number of items available in the feed.
814+
__( 'Latest %1$s feed items out of %2$s available from', 'feedzy-rss-feeds' ),
815+
$max_items_preview_count,
816+
$total_items
817+
)
818+
);
819+
?>
820+
</strong>
821+
<div>
822+
<ul class="feedzy-preview-list">
823+
<?php
824+
foreach ( $preview_feed_items as $item ) {
825+
$datetime = date_i18n( 'c', $item['item_date'] );
826+
$time_content = date_i18n( 'Y-m-d', $item['item_date'] );
827+
?>
828+
<li <?php echo esc_attr( $item['itemAttr'] ); ?>>
829+
<a href="<?php echo esc_url( $item['item_url'] ); ?>" target="_blank">
830+
<?php echo esc_html( $item['item_title'] ); ?>
831+
</a>
832+
<br/>
833+
<time
834+
datetime="<?php echo esc_attr( $datetime ); ?>"
835+
content="<?php echo esc_attr( $time_content ); ?>"
836+
>
837+
<?php echo esc_html( $this->get_humman_readable_time_diff( $item['item_date'] ) ); ?>
838+
</time>
839+
</li>
840+
<?php
824841
}
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>';
842+
?>
843+
</ul>
844+
</div>
845+
<?php
858846
}
859847

860848
/**

0 commit comments

Comments
 (0)