| @@ -11,38 +11,52 @@ | ||
| 11 | 11 | public $options = array(); |
| 12 | 12 | |
| 13 | 13 | public function __construct( $options ){ |
| 14 | 14 | |
| 15 | - $this->options = wp_parse_args( $options, SRR_Options::default_options() ); | |
| 15 | + $this->options = wp_parse_args( $options, SRR_Options::defaults() ); | |
| 16 | 16 | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function html(){ |
| 20 | 20 | |
| 21 | - $urls = stripslashes( trim( $this->options['urls'] ) ); | |
| 22 | - $tab_titles = stripslashes( $this->options['tab_titles'] ); | |
| 21 | + $urls = trim( $this->options['urls'] ); | |
| 22 | + $tab_titles = $this->options['tab_titles']; | |
| 23 | 23 | $count = intval( $this->options['count'] ); |
| 24 | 24 | |
| 25 | + $show_title = intval( $this->options['show_title'] ); | |
| 25 | 26 | $show_date = intval( $this->options['show_date'] ); |
| 26 | 27 | $show_desc = intval( $this->options['show_desc'] ); |
| 27 | 28 | $show_author = intval( $this->options['show_author'] ); |
| 28 | - $show_thumb = stripslashes( $this->options['show_thumb'] ); | |
| 29 | + $show_thumb = intval( $this->options['show_thumb'] ); | |
| 29 | 30 | $open_newtab = intval( $this->options['open_newtab'] ); |
| 30 | 31 | $add_nofollow = intval( $this->options['add_nofollow'] ); |
| 31 | 32 | $strip_desc = intval( $this->options['strip_desc'] ); |
| 32 | 33 | $strip_title = intval( $this->options['strip_title'] ); |
| 33 | - $read_more = htmlspecialchars( $this->options['read_more'] ); | |
| 34 | + $offset = intval( $this->options['offset'] ); | |
| 35 | + $date_format = $this->options['date_format']; | |
| 36 | + $date_timezone = $this->options['date_timezone']; | |
| 37 | + $order_by = $this->options['order_by']; | |
| 38 | + $read_more = $this->options['read_more']; | |
| 34 | 39 | $rich_desc = intval( $this->options['rich_desc'] ); |
| 35 | - | |
| 36 | - $color_theme = stripslashes( $this->options['color_style'] ); | |
| 37 | - $display_type = stripslashes( $this->options['display_type'] ); | |
| 40 | + $link_desc = intval( $this->options['link_desc'] ); | |
| 41 | + $desc_type = $this->options['desc_type']; | |
| 42 | + $thumbnail_position = $this->options['thumbnail_position']; | |
| 43 | + $thumbnail_size = $this->options['thumbnail_size']; | |
| 44 | + $thumbnail_default = $this->options['thumbnail_default']; | |
| 45 | + $no_feed_text = $this->options['no_feed_text']; | |
| 46 | + | |
| 47 | + $color_theme = $this->options['color_style']; | |
| 48 | + $display_type = $this->options['display_type']; | |
| 38 | 49 | $visible_items = intval( $this->options['visible_items'] ); |
| 39 | 50 | $ticker_speed = intval( $this->options['ticker_speed'] ) * 1000; |
| 51 | + $scroll_height = $this->options['scroll_height']; | |
| 40 | 52 | |
| 41 | 53 | if( empty( $urls ) ){ |
| 42 | 54 | return ''; |
| 43 | 55 | } |
| 44 | 56 | |
| 57 | + $count = ( $offset > 0 ) ? $count + $offset : $count; | |
| 58 | + | |
| 45 | 59 | $url_delim = strpos( $urls, ',' ) !== false ? ',' : "\n"; |
| 46 | 60 | $tab_title_delim = strpos( $tab_titles, ',' ) !== false ? ',' : "\n"; |
| 47 | 61 | |
| 48 | 62 | $urls = explode( $url_delim, $urls ); |
| @@ -50,18 +64,36 @@ | ||
| 50 | 64 | $url_count = count( $urls ); |
| 51 | 65 | |
| 52 | 66 | $feeds = array(); |
| 53 | 67 | $html = ''; |
| 68 | + $no_feed_html = '<div>' . wp_kses_post( $no_feed_text ) . '</div>'; | |
| 54 | 69 | |
| 70 | + $classes = array( 'srr-wrap', 'srr-style-' . $color_theme ); | |
| 71 | + if( $display_type == 'vertical_ticker' ) array_push( $classes, 'srr-vticker' ); | |
| 72 | + if( $display_type == 'scroll' ) array_push( $classes, 'srr-scroll' ); | |
| 73 | + $class = implode( ' ', $classes ); | |
| 74 | + | |
| 75 | + $style = ''; | |
| 76 | + if( $display_type == 'scroll' ){ | |
| 77 | + $style .= '--srr-height: ' . $scroll_height; | |
| 78 | + } | |
| 79 | + if( !empty( $style ) ) $style = 'style="' . esc_attr( $style ) . '"'; | |
| 80 | + | |
| 55 | 81 | // Fetch the feed |
| 56 | 82 | for( $i=0; $i < $url_count; $i++ ){ |
| 57 | 83 | $feed_url = trim( $urls[$i] ); |
| 84 | + | |
| 85 | + // Skip if the RSS feed URL is same as the site URL | |
| 86 | + if ( in_array( untrailingslashit( $feed_url ), array( site_url(), home_url() ), true ) ) { | |
| 87 | + continue; | |
| 88 | + } | |
| 89 | + | |
| 58 | 90 | $feed = fetch_feed( $feed_url ); |
| 59 | 91 | |
| 60 | 92 | if( is_wp_error( $feed ) ){ |
| 61 | - $feed_title = 'Error'; | |
| 93 | + $feed_title = __( 'Error' ); | |
| 62 | 94 | }else{ |
| 63 | - $feed_title = ( isset( $tab_titles[$i] ) && !empty( $tab_titles[$i] ) ) ? $tab_titles[$i] : esc_attr( strip_tags( $feed->get_title() ) ); | |
| 95 | + $feed_title = ( isset( $tab_titles[$i] ) && !empty( $tab_titles[$i] ) ) ? $tab_titles[$i] : strip_tags( $feed->get_title() ); | |
| 64 | 96 | } |
| 65 | 97 | |
| 66 | 98 | $feeds[ $feed_url ] = array( |
| 67 | 99 | 'id' => rand( 100, 999 ), |
| @@ -71,17 +103,13 @@ | ||
| 71 | 103 | } |
| 72 | 104 | |
| 73 | 105 | // Generate tabs |
| 74 | 106 | if( $url_count > 1 ){ |
| 75 | - $html .= '<ul class="srr-tab-wrap srr-tab-style-' . $color_theme . ' srr-clearfix">'; | |
| 107 | + $html .= '<ul class="srr-tab-wrap srr-tab-style-' . esc_attr( $color_theme ) . ' srr-clearfix">'; | |
| 76 | 108 | foreach( $feeds as $url => $data ){ |
| 77 | 109 | $id = $data[ 'id' ]; |
| 78 | 110 | $feed = $data[ 'feed' ]; |
| 79 | - if( is_wp_error( $feed ) ){ | |
| 80 | - $html .= '<li data-tab="srr-tab-' . $id . '">Error</li>'; | |
| 81 | - }else{ | |
| 82 | - $html .= '<li data-tab="srr-tab-' . $id . '">' . $data[ 'title' ] . '</li>'; | |
| 83 | - } | |
| 111 | + $html .= '<li data-tab="srr-tab-' . esc_attr( $id ) . '">' . wp_kses_post( $data[ 'title' ] ) . '</li>'; | |
| 84 | 112 | } |
| 85 | 113 | $html .= '</ul>'; |
| 86 | 114 | } |
| 87 | 115 | |
| @@ -92,42 +120,51 @@ | ||
| 92 | 120 | $feed = $data[ 'feed' ]; |
| 93 | 121 | |
| 94 | 122 | // Check for feed errors |
| 95 | 123 | if ( is_wp_error( $feed ) ){ |
| 96 | - $html .= '<div class="srr-wrap srr-style-' . $color_theme .'" data-id="srr-tab-' . $id . '"><p>RSS Error: ' . $feed->get_error_message() . '</p></div>'; | |
| 124 | + $html .= '<div class="srr-wrap srr-style-' . esc_attr( $color_theme ) .'" data-id="srr-tab-' . esc_attr( $id ) . '"><p>RSS Error: ' . wp_kses_post( $feed->get_error_message() ) . '</p></div>'; | |
| 97 | 125 | continue; |
| 98 | 126 | } |
| 99 | 127 | |
| 100 | 128 | if( method_exists( $feed, 'enable_order_by_date' ) ){ |
| 101 | - $feed->enable_order_by_date( false ); | |
| 129 | + if( in_array( $order_by, array( 'date', 'date_reverse' ) ) ){ | |
| 130 | + $feed->enable_order_by_date( true ); | |
| 131 | + }else{ | |
| 132 | + $feed->enable_order_by_date( false ); | |
| 133 | + } | |
| 102 | 134 | } |
| 103 | 135 | |
| 104 | - $max_items = $feed->get_item_quantity( $count ); | |
| 105 | - $feed_items = $feed->get_items( 0, $max_items ); | |
| 136 | + // Outer wrap start | |
| 137 | + $html .= '<div class="' . esc_attr( $class ) . '" data-visible="' . esc_attr( $visible_items ) . '" data-speed="' . esc_attr( $ticker_speed ) . '" data-id="srr-tab-' . esc_attr( $id ) . '" ' . $style . '>'; | |
| 138 | + $html .= '<div class="srr-inner">'; | |
| 106 | 139 | |
| 107 | - $classes = array( 'srr-wrap', 'srr-style-' . $color_theme ); | |
| 108 | - if( $display_type == 'vertical_ticker' ) array_push( $classes, 'srr-vticker' ); | |
| 109 | - $class = implode( ' ', $classes ); | |
| 140 | + $max_items = $feed->get_item_quantity(); | |
| 110 | 141 | |
| 111 | - // Outer wrap start | |
| 112 | - $html .= '<div class="' . $class . '" data-visible="' . $visible_items . '" data-speed="' . $ticker_speed . '" data-id="srr-tab-' . $id . '">'; | |
| 113 | - $html .= '<div>'; | |
| 114 | - | |
| 115 | 142 | // Check feed items |
| 116 | 143 | if ( $max_items == 0 ){ |
| 117 | - $html .= '<div>No items.</div>'; | |
| 144 | + $html .= $no_feed_html; | |
| 118 | 145 | }else{ |
| 146 | + | |
| 147 | + $feed_items = $feed->get_items(); | |
| 148 | + $feed_items = $this->process_items( $feed_items, $count, $order_by ); | |
| 119 | 149 | $j=1; |
| 150 | + | |
| 120 | 151 | // Loop through each feed item |
| 121 | 152 | foreach( $feed_items as $item ){ |
| 122 | 153 | |
| 154 | + // Offset items | |
| 155 | + if( $j <= $offset ){ | |
| 156 | + $j++; | |
| 157 | + continue; | |
| 158 | + } | |
| 159 | + | |
| 123 | 160 | // Link |
| 124 | 161 | $link = $item->get_link(); |
| 125 | 162 | while ( stristr( $link, 'http' ) != $link ){ $link = substr( $link, 1 ); } |
| 126 | - $link = esc_url( strip_tags($link) ); | |
| 163 | + $link = strip_tags($link); | |
| 127 | 164 | |
| 128 | 165 | // Title |
| 129 | - $title = esc_attr( strip_tags( $item->get_title() ) ); | |
| 166 | + $title = strip_tags( $item->get_title() ); | |
| 130 | 167 | $title_full = $title; |
| 131 | 168 | |
| 132 | 169 | if ( empty( $title ) ){ |
| 133 | 170 | $title = __( 'No Title', 'super-rss-reader' ); |
| @@ -140,20 +177,52 @@ | ||
| 140 | 177 | // Open links in new tab |
| 141 | 178 | $new_tab = $open_newtab ? ' target="_blank"' : ''; |
| 142 | 179 | |
| 143 | 180 | // Add no follow attribute |
| 144 | - $no_follow = $add_nofollow ? ' rel="nofollow"' : ''; | |
| 181 | + $no_follow = $add_nofollow ? ' rel="nofollow noopener noreferrer"' : ''; | |
| 145 | 182 | |
| 183 | + if( empty( $link ) ){ | |
| 184 | + $link = '#'; | |
| 185 | + $new_tab = ''; | |
| 186 | + } | |
| 187 | + | |
| 146 | 188 | // Date |
| 147 | - $date = $item->get_date( 'j F Y' ); | |
| 148 | - $date_full = esc_attr( $item->get_date() ); | |
| 189 | + $date = ''; | |
| 190 | + $date_full = strip_tags( $item->get_date() ); | |
| 149 | 191 | |
| 192 | + if( strtolower( $date_format ) == 'relative' ){ | |
| 193 | + $item_date = $item->get_date( 'U' ); | |
| 194 | + if( $item_date ){ | |
| 195 | + $date = human_time_diff( $item_date, current_time( 'U' ) ) . ' ' . __( 'ago' ); | |
| 196 | + }else{ | |
| 197 | + $date = __( 'Today' ); | |
| 198 | + } | |
| 199 | + }else{ | |
| 200 | + $date = SRR_Utilities::date_i18n( $date_format, $item->get_date( 'U' ), $date_timezone ); | |
| 201 | + } | |
| 202 | + | |
| 150 | 203 | // Thumbnail |
| 151 | 204 | $thumb = ''; |
| 152 | - if ( $show_thumb == 1 && $enclosure = $item->get_enclosure() ){ | |
| 153 | - $thumb_url = $enclosure->get_thumbnail(); | |
| 205 | + if ( $show_thumb == 1 ){ | |
| 206 | + $thumb_url = $this->get_thumbnail_url( $item, $thumbnail_default ); | |
| 207 | + $thumb_url = apply_filters( 'srr_mod_thumbnail_url', $thumb_url, $item, $feed, $thumbnail_default ); | |
| 154 | 208 | if( !empty( $thumb_url ) ){ |
| 155 | - $thumb = '<img src="' . $thumb_url . '" alt="' . $title_full . '" class="srr-thumb" align="left" />'; | |
| 209 | + if( strpos( $thumbnail_size, ',' ) ){ | |
| 210 | + $thumb_size_split = explode( ',', $thumbnail_size ); | |
| 211 | + $thumb_width = $thumb_size_split[0]; | |
| 212 | + $thumb_height = $thumb_size_split[1]; | |
| 213 | + }else{ | |
| 214 | + $thumb_width = $thumb_height = $thumbnail_size; | |
| 215 | + } | |
| 216 | + $thumb_styles = array( | |
| 217 | + 'width' => $thumb_width, | |
| 218 | + 'height' => $thumb_height | |
| 219 | + ); | |
| 220 | + $thumb_style = ''; | |
| 221 | + foreach( $thumb_styles as $prop => $val ){ | |
| 222 | + $thumb_style .= "$prop:$val;"; | |
| 223 | + } | |
| 224 | + $thumb = '<a href="' . esc_url( $link ) . '" class="srr-thumb srr-thumb-' . esc_attr( $thumbnail_position ) . '" style="' . esc_attr( $thumb_style ) . '" ' . $new_tab . $no_follow . '><img src="' . esc_url( $thumb_url ) . '" alt="' . esc_attr( $title_full ) . '" align="left"' . ( wp_lazy_loading_enabled( 'img', 'srr-thumbnail' ) ? ' loading="lazy"' : '' ) . ' /></a>'; | |
| 156 | 225 | } |
| 157 | 226 | } |
| 158 | 227 | |
| 159 | 228 | // Description |
| @@ -158,75 +227,118 @@ | ||
| 158 | 227 | |
| 159 | 228 | // Description |
| 160 | 229 | $desc = ''; |
| 161 | 230 | if( $show_desc ){ |
| 231 | + $desc_content = ( $desc_type == 'summary' ) ? $item->get_description() : $item->get_content(); | |
| 162 | 232 | if( $rich_desc ){ |
| 163 | - $desc = strip_tags( $item->get_description(), '<p><a><img><em><strong><font><strike><s><u><i>' ); | |
| 233 | + $desc = wp_kses_post( strip_tags( $desc_content, '<p><a><img><em><strong><font><strike><s><u><b><i><br>' ) ); | |
| 164 | 234 | }else{ |
| 235 | + $desc = str_replace( array( "\n", "\r" ), ' ', strip_tags( @html_entity_decode( $desc_content, ENT_QUOTES, get_option('blog_charset') ) ) ); | |
| 165 | 236 | |
| 166 | - $desc = str_replace( array( "\n", "\r" ), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) ); | |
| 167 | - $read_more_link = ''; | |
| 168 | - | |
| 169 | 237 | if( $strip_desc != 0 ){ |
| 170 | 238 | $desc = wp_trim_words( $desc, $strip_desc ); |
| 171 | - $read_more_link = !empty( $read_more ) ? ' <a href="' . $link . '" title="Read more"' . $new_tab . $no_follow . '>' . $read_more . '</a>' : ''; | |
| 172 | - | |
| 173 | 239 | if ( '[...]' == substr( $desc, -5 ) ){ |
| 174 | 240 | $desc = substr( $desc, 0, -5 ); |
| 241 | + }else if ( '…' == substr( $desc, -8 ) ){ | |
| 242 | + $desc = substr( $desc, 0, -8 ); | |
| 243 | + }else if ( '...' == substr( $desc, -3 ) ){ | |
| 244 | + $desc = substr( $desc, 0, -3 ); | |
| 175 | 245 | }elseif ( '[…]' != substr( $desc, -10 ) ){ |
| 176 | 246 | $desc .= ''; |
| 177 | 247 | } |
| 248 | + } | |
| 178 | 249 | |
| 179 | - $desc = esc_html( $desc ); | |
| 250 | + $desc = trim( esc_html( $desc ) ); | |
| 251 | + if( !empty( $desc ) ){ | |
| 252 | + if( $link_desc ){ | |
| 253 | + $desc = '<a href="' . esc_url( $link ) . '"' . $new_tab . $no_follow . ' class="srr-desc-link">' . $desc . '</a>'; | |
| 254 | + } | |
| 255 | + $read_more_link = !empty( $read_more ) ? ' <a href="' . esc_url( $link ) . '" title="' . esc_attr__( 'Read more', 'super-rss-reader' ) . '"' . $new_tab . $no_follow . ' class="srr-read-more">' . esc_html( $read_more ) . '</a>' : ''; | |
| 256 | + $desc = $desc . $read_more_link; | |
| 180 | 257 | } |
| 181 | 258 | |
| 182 | - $desc = $desc . $read_more_link; | |
| 183 | - | |
| 184 | 259 | } |
| 185 | 260 | } |
| 186 | 261 | |
| 187 | 262 | // Author |
| 188 | - $author = $item->get_author(); | |
| 189 | - if ( is_object( $author ) ) { | |
| 190 | - $author = $author->get_name(); | |
| 191 | - $author = esc_html( strip_tags( $author ) ); | |
| 263 | + $author = ''; | |
| 264 | + if( $show_author ){ | |
| 265 | + $author = $item->get_author(); | |
| 266 | + if ( is_object( $author ) && $author->get_name() ) { | |
| 267 | + $author = strip_tags( $author->get_name() ); | |
| 268 | + } | |
| 192 | 269 | } |
| 193 | 270 | |
| 194 | - // Display the feed items | |
| 195 | - $html .= '<div class="srr-item ' . ( ( $j%2 == 0 ) ? 'even' : 'odd') . ' srr-clearfix">'; | |
| 196 | - $html .= '<div class="srr-title"><a href="' . $link . '"' . $new_tab . $no_follow . ' title="' . $title_full . '">' . $title . '</a></div>'; | |
| 271 | + $t_title = ''; | |
| 272 | + $t_meta = ''; | |
| 273 | + $t_thumb = ''; | |
| 274 | + $t_desc = ''; | |
| 197 | 275 | |
| 198 | - $html .= '<div class="srr-meta">'; | |
| 199 | - if( $show_date && !empty( $date ) ){ | |
| 200 | - $html .= '<time class="srr-date" title="' . $date_full . '">' . $date . '</time>'; | |
| 276 | + if( $show_title ){ | |
| 277 | + $t_title .= '<div class="srr-title"><a href="' . esc_url( $link ) . '"' . $new_tab . $no_follow . ' title="' . esc_attr( $title_full ) . '">' . esc_html( $title ) . '</a></div>'; | |
| 201 | 278 | } |
| 202 | 279 | |
| 203 | - if( $show_author && !empty( $author ) ){ | |
| 204 | - $html .= ' - <cite class="srr-author">' . $author . '</cite>'; | |
| 280 | + // Metadata | |
| 281 | + if( $show_date || $show_author ){ | |
| 282 | + $t_meta .= '<div class="srr-meta">'; | |
| 283 | + if( $show_date && !empty( $date ) ){ | |
| 284 | + $t_meta .= '<time class="srr-date" title="' . esc_attr( $date_full ) . ' UTC">' . esc_html( $date ) . '</time>'; | |
| 285 | + } | |
| 286 | + | |
| 287 | + if( $show_author && !empty( $author ) ){ | |
| 288 | + $t_meta .= ' - <cite class="srr-author">' . esc_html( $author ) . '</cite>'; | |
| 289 | + } | |
| 290 | + $t_meta .= '</div>'; // End meta | |
| 205 | 291 | } |
| 206 | - $html .= '</div>'; | |
| 207 | 292 | |
| 208 | 293 | if ( $show_thumb ){ |
| 209 | - $html .= $thumb; | |
| 294 | + $t_thumb .= $thumb; | |
| 210 | 295 | } |
| 211 | 296 | |
| 212 | - if( $show_desc ){ | |
| 213 | - $html .= '<div class="srr-summary srr-clearfix">'; | |
| 214 | - $html .= $rich_desc ? $desc : ( '<p>' . $desc . '</p>' ); | |
| 215 | - $html .= '</div>'; | |
| 297 | + if( $show_desc && !empty( $desc ) ){ | |
| 298 | + $t_desc .= '<div class="srr-summary srr-clearfix">'; | |
| 299 | + $t_desc .= $rich_desc ? $desc : ( '<p>' . $desc . '</p>' ); | |
| 300 | + $t_desc .= '</div>'; // End summary | |
| 216 | 301 | } |
| 217 | 302 | |
| 218 | - $html .= '</div>'; | |
| 219 | - // End display | |
| 303 | + $f_data = apply_filters( 'srr_mod_item_html', array( | |
| 304 | + 'title' => $t_title, | |
| 305 | + 'meta' => $t_meta, | |
| 306 | + 'thumbnail' => $t_thumb, | |
| 307 | + 'description' => $t_desc, | |
| 308 | + 'before' => '', | |
| 309 | + 'after' => '' | |
| 310 | + ), $url, $item ); | |
| 220 | 311 | |
| 312 | + $f_title = !isset( $f_data[ 'title' ] ) ? '' : $f_data[ 'title' ]; | |
| 313 | + $f_meta = !isset( $f_data[ 'meta' ] ) ? '' : $f_data[ 'meta' ]; | |
| 314 | + $f_thumb = !isset( $f_data[ 'thumbnail' ] ) ? '' : $f_data[ 'thumbnail' ]; | |
| 315 | + $f_desc = !isset( $f_data[ 'description' ] ) ? '' : $f_data[ 'description' ]; | |
| 316 | + $f_before = !isset( $f_data[ 'before' ] ) ? '' : $f_data[ 'before' ]; | |
| 317 | + $f_after = !isset( $f_data[ 'after' ] ) ? '' : $f_data[ 'after' ]; | |
| 318 | + | |
| 319 | + // Display the feed items | |
| 320 | + $html .= '<div class="srr-item ' . ( ( $j%2 == 0 ) ? 'srr-stripe' : '') . '">'; | |
| 321 | + $html .= '<div class="srr-item-in srr-clearfix">'; | |
| 322 | + $html .= $f_before; | |
| 323 | + $html .= $f_title . $f_meta . $f_thumb . $f_desc; | |
| 324 | + $html .= $f_after; | |
| 325 | + $html .= '</div>'; // End item inner clearfix | |
| 326 | + $html .= '</div>'; // End feed item | |
| 327 | + | |
| 221 | 328 | $j++; |
| 222 | 329 | } |
| 330 | + | |
| 331 | + if( $j == 1 ){ | |
| 332 | + $html .= $no_feed_html; | |
| 333 | + } | |
| 334 | + | |
| 223 | 335 | } |
| 224 | 336 | |
| 225 | 337 | // Outer wrap end |
| 226 | 338 | $html .= '</div></div>' ; |
| 227 | 339 | |
| 228 | - if ( !is_wp_error( $feed ) ) | |
| 340 | + if( !is_wp_error( $feed ) ) | |
| 229 | 341 | $feed->__destruct(); |
| 230 | 342 | |
| 231 | 343 | unset( $feed ); |
| 232 | 344 | |
| @@ -231,9 +343,68 @@ | ||
| 231 | 343 | unset( $feed ); |
| 232 | 344 | |
| 233 | 345 | } |
| 234 | 346 | |
| 347 | + $html = '<div class="srr-main">' . $html . '</div>'; | |
| 348 | + | |
| 235 | 349 | return $html; |
| 350 | + | |
| 351 | + } | |
| 352 | + | |
| 353 | + function process_items( $items, $count, $order_by ){ | |
| 354 | + | |
| 355 | + if( count( $items ) == 0 ){ | |
| 356 | + return $items; | |
| 357 | + } | |
| 358 | + | |
| 359 | + // For shuffle order - Shuffle first and then slice as per count | |
| 360 | + if( $order_by == 'random' ){ | |
| 361 | + shuffle( $items ); | |
| 362 | + return array_slice( $items, 0, $count ); | |
| 363 | + } | |
| 364 | + | |
| 365 | + // For date based order - slice first and then order | |
| 366 | + $items = array_slice( $items, 0, $count ); | |
| 367 | + | |
| 368 | + if( $order_by == 'date_reverse' ){ | |
| 369 | + $items = array_reverse( $items ); | |
| 370 | + } | |
| 371 | + | |
| 372 | + return $items; | |
| 373 | + | |
| 374 | + } | |
| 375 | + | |
| 376 | + function get_thumbnail_url( $item, $thumbnail_default ){ | |
| 377 | + | |
| 378 | + // Try to get from the item enclosure | |
| 379 | + $enclosure = $item->get_enclosure(); | |
| 380 | + | |
| 381 | + if ( $enclosure->get_thumbnail() ) { | |
| 382 | + return $enclosure->get_thumbnail(); | |
| 383 | + } | |
| 384 | + | |
| 385 | + if ( $enclosure->get_link() ) { | |
| 386 | + return $enclosure->get_link(); | |
| 387 | + } | |
| 388 | + | |
| 389 | + // Try to get from item content | |
| 390 | + $content = $item->get_content(); | |
| 391 | + | |
| 392 | + preg_match_all('~<img.*?src=["\']+(.*?)["\']+~', $content, $urls); | |
| 393 | + $urls = $urls[1]; | |
| 394 | + | |
| 395 | + if( !empty( $urls ) ){ | |
| 396 | + return $urls[0]; | |
| 397 | + } | |
| 398 | + | |
| 399 | + // Try to get the image tag finally if available | |
| 400 | + $image = $item->get_item_tags( '', 'image' ); | |
| 401 | + | |
| 402 | + if( isset( $image[0]['data'] ) ){ | |
| 403 | + return $image[0]['data']; | |
| 404 | + } | |
| 405 | + | |
| 406 | + return trim( $thumbnail_default ); | |
| 236 | 407 | |
| 237 | 408 | } |
| 238 | 409 | |
| 239 | 410 | } |