AndroidPonsel - Berita HP Android, Aplikasi & Tips Teknologi Terbaru

Latest Post

View All
get_item_quantity( 7 ); // 1 hero + 4 grid $rss_items = $rss->get_items( 0, $maxitems ); } // Namespace MRSS if ( ! defined('AP_MRSS_NS') ) { define( 'AP_MRSS_NS', 'http://search.yahoo.com/mrss/' ); } /** Ambil thumbnail (MRSS -> oEmbed -> OG/Twitter), cache 6 jam */ function ap_get_item_thumb( $item ) { $permalink = $item->get_permalink(); $key = 'ap_thumb_' . md5( $permalink ); if ( $cached = get_transient( $key ) ) return $cached; // 1) MRSS media:content / thumbnail $m = $item->get_item_tags( AP_MRSS_NS, 'content' ); if ( ! empty( $m[0]['attribs']['']["url"] ) ) { $thumb = $m[0]['attribs']['']["url"]; set_transient( $key, $thumb, 6 * HOUR_IN_SECONDS ); return $thumb; } $t = $item->get_item_tags( AP_MRSS_NS, 'thumbnail' ); if ( ! empty( $t[0]['attribs']['']["url"] ) ) { $thumb = $t[0]['attribs']['']["url"]; set_transient( $key, $thumb, 6 * HOUR_IN_SECONDS ); return $thumb; } // 2) oEmbed (featured image) $oembed_url = add_query_arg( ['url' => rawurlencode($permalink), 'format' => 'json'], 'https://www.androidponsel.com/wp-json/oembed/1.0/embed' ); $resp = wp_remote_get( $oembed_url, [ 'timeout' => 6, 'redirection' => 3 ] ); if ( ! is_wp_error( $resp ) ) { $body = wp_remote_retrieve_body( $resp ); if ( $body ) { $data = json_decode( $body, true ); if ( ! empty( $data['thumbnail_url'] ) ) { $thumb = $data['thumbnail_url']; set_transient( $key, $thumb, 6 * HOUR_IN_SECONDS ); return $thumb; } } } // 3) OG/Twitter image $resp2 = wp_remote_get( $permalink, [ 'timeout' => 6, 'redirection' => 3 ] ); if ( ! is_wp_error( $resp2 ) ) { $html = wp_remote_retrieve_body( $resp2 ); $thumb = ''; if ( preg_match( '/]+property=[\'"]og:image[\'"][^>]+content=[\'"]([^\'"]+)[\'"]/i', $html, $m1 ) ) $thumb = $m1[1]; elseif ( preg_match( '/]+name=[\'"]twitter:image[\'"][^>]+content=[\'"]([^\'"]+)[\'"]/i', $html, $m2 ) ) $thumb = $m2[1]; if ( $thumb ) { set_transient( $key, $thumb, 6 * HOUR_IN_SECONDS ); return $thumb; } } set_transient( $key, '', 30 * MINUTE_IN_SECONDS ); // negatif cache return ''; } ?>

HP Android Terbaru

Lihat Semua →
$item ) : $thumb = ap_get_item_thumb( $item ); ?>