', $matches[1] ); return apply_filters( 'aparat_embed', $output, $matches, $attr, $url, $rawattr ); } public function channel_embed( $matches, $attr, $url, $rawattr ) { $rss = fetch_feed( sprintf( 'http://www.aparat.com/rss/%s', $matches[1] ) ); if( is_wp_error( $rss ) ) { return $url; } $items = 10; if ( !$rss->get_item_quantity() ) { $rss->__destruct(); unset( $rss ); return __( 'Error.', 'aparat-embed' ); } $output = '
'; foreach ( $rss->get_items( 0, $items ) as $item ) { $link = $item->get_link(); while ( stristr( $link, 'http' ) != $link ) { $link = substr( $link, 1 ); } $link = esc_url( strip_tags( $link ) ); $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); if ( empty( $title ) ) { $title = __( 'Untitled' ); } preg_match( '#http://(?:www)\.aparat\.com\/v\/(.*?)\/#i', $link, $matches ); $video = sprintf( '', $matches[1] ); $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); $desc = esc_attr( wp_trim_words( $desc, 55, ' […]' ) ); $date = date_i18n( get_option( 'date_format' ), $item->get_date( 'U' ) ); $output .= sprintf( '
%s

%s

%s %s
', $video, $link, $title, $date, esc_html( $desc ) ); } $output .= '
'; $rss->__destruct(); unset($rss); return apply_filters( 'aparat_channel_embed', $output, $matches, $attr, $url, $rawattr ); } public function wp_enqueue_scripts() { wp_enqueue_style( 'aparat-embed', plugins_url( 'assets/style.css', __FILE__ ) ); } function mce_css( $mce_css ) { if( ! empty( $mce_css ) ) $mce_css .= ','; $mce_css .= plugins_url( 'assets/style.css', __FILE__ ); return $mce_css; } } add_action( 'plugins_loaded', array( 'Aparat_Embed', 'get_instance' ) );