diff --git a/inc/shortcodes/class-facebook.php b/inc/shortcodes/class-facebook.php index ab2cf3c..f73edb3 100644 --- a/inc/shortcodes/class-facebook.php +++ b/inc/shortcodes/class-facebook.php @@ -4,6 +4,17 @@ class Facebook extends Shortcode { + // Our matching URL patterns for Facebook + private static $url_patterns = array( + '#https?://(www)?\.facebook\.com/[^/]+/posts/[\d]+#', + '#https?://(www)?\.facebook\.com\/video\.php\?v=[\d]+#', + '#https?:\/\/www?\.facebook\.com\/+.*?\/videos\/[\d]+\/#', + '#https?://(www)?\.facebook\.com\/permalink\.php\?story_fbid=[\d]+&id=[\d]+#', + '#https?:\/\/www?\.facebook\.com\/.*?\/photos\/([^/]+)/([\d])+/#', + '#https?:\/\/www?\.facebook\.com\/.*?\/videos\/([^/]+)/([\d])+/#', + '#https?:\/\/www?\.facebook\.com\/groups\/([\d])+\/permalink/([\d])+/?#', + ); + public static function get_shortcode_ui_args() { return array( 'label' => esc_html__( 'Facebook', 'shortcake-bakery' ), @@ -52,29 +63,43 @@ public static function action_wp_footer() { public static function reversal( $content ) { - if ( false === stripos( $content, '
]+href=[\'\"]([^\'\"]+)[\'\"].+
()?#', $content, $matches ) ) { - $replacements = array(); - $shortcode_tag = self::get_shortcode_tag(); - foreach ( $matches[0] as $key => $value ) { - $replacements[ $value ] = '[' . $shortcode_tag . ' url="' . esc_url_raw( $matches[1][ $key ] ) . '"]'; + /* Pattern for normal Facebook embeds */ + if ( preg_match_all( '#
]+href=[\'\"]([^\'\"]+)[\'\"].+
()?#', $content, $matches ) ) { + $replacements = array(); + $shortcode_tag = self::get_shortcode_tag(); + foreach ( $matches[0] as $key => $value ) { + $replacements[ $value ] = '[' . $shortcode_tag . ' url="' . esc_url_raw( $matches[1][ $key ] ) . '"]'; + } + $content = self::make_replacements_to_content( $content, $replacements ); + } + + /* Pattern for Facebook video embeds */ + if ( preg_match_all( '#
<\/div>

Here's the free styling he put on lol Brent John Janis Franklin Sioux Bob Nate Badmilk

Posted by Corey James on Saturday, June 27, 2015
+https://www.facebook.com/coreycf/videos/953479961370562/ bananas after EOT; $transformed_content = wp_filter_post_kses( $old_content ); @@ -99,4 +100,25 @@ public function test_photo_embed_reversal() { } + public function test_oembed_reversals() { + + $old_content = <<assertContains( '[facebook url="https://www.facebook.com/RichardBranson/photos/a.10151193550160872.451061.31325960871/10151193550380872/?type=1"]', $transformed_content ); + $this->assertContains( '[facebook url="https://www.facebook.com/coreycf/videos/953479961370562/"]', $transformed_content ); + $this->assertContains( 'apples before', $transformed_content ); + $this->assertContains( 'bananas after', $transformed_content ); + } + }