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